misc.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. /*
  2. * misc.c: Miscellaneous prom functions that don't belong
  3. * anywhere else.
  4. *
  5. * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
  6. * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
  7. */
  8. #include <linux/types.h>
  9. #include <linux/kernel.h>
  10. #include <linux/sched.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/delay.h>
  13. #include <asm/openprom.h>
  14. #include <asm/oplib.h>
  15. #include <asm/system.h>
  16. #include <asm/ldc.h>
  17. int prom_service_exists(const char *service_name)
  18. {
  19. int err = p1275_cmd("test", P1275_ARG(0, P1275_ARG_IN_STRING) |
  20. P1275_INOUT(1, 1), service_name);
  21. if (err)
  22. return 0;
  23. return 1;
  24. }
  25. void prom_sun4v_guest_soft_state(void)
  26. {
  27. const char *svc = "SUNW,soft-state-supported";
  28. if (!prom_service_exists(svc))
  29. return;
  30. p1275_cmd(svc, P1275_INOUT(0, 0));
  31. }
  32. /* Reset and reboot the machine with the command 'bcommand'. */
  33. void prom_reboot(const char *bcommand)
  34. {
  35. #ifdef CONFIG_SUN_LDOMS
  36. if (ldom_domaining_enabled)
  37. ldom_reboot(bcommand);
  38. #endif
  39. p1275_cmd("boot", P1275_ARG(0, P1275_ARG_IN_STRING) |
  40. P1275_INOUT(1, 0), bcommand);
  41. }
  42. /* Forth evaluate the expression contained in 'fstring'. */
  43. void prom_feval(const char *fstring)
  44. {
  45. if (!fstring || fstring[0] == 0)
  46. return;
  47. p1275_cmd("interpret", P1275_ARG(0, P1275_ARG_IN_STRING) |
  48. P1275_INOUT(1, 1), fstring);
  49. }
  50. #ifdef CONFIG_SMP
  51. extern void smp_capture(void);
  52. extern void smp_release(void);
  53. #endif
  54. /* Drop into the prom, with the chance to continue with the 'go'
  55. * prom command.
  56. */
  57. void prom_cmdline(void)
  58. {
  59. unsigned long flags;
  60. local_irq_save(flags);
  61. #ifdef CONFIG_SMP
  62. smp_capture();
  63. #endif
  64. p1275_cmd("enter", P1275_INOUT(0, 0));
  65. #ifdef CONFIG_SMP
  66. smp_release();
  67. #endif
  68. local_irq_restore(flags);
  69. }
  70. /* Drop into the prom, but completely terminate the program.
  71. * No chance of continuing.
  72. */
  73. void prom_halt(void)
  74. {
  75. #ifdef CONFIG_SUN_LDOMS
  76. if (ldom_domaining_enabled)
  77. ldom_power_off();
  78. #endif
  79. again:
  80. p1275_cmd("exit", P1275_INOUT(0, 0));
  81. goto again; /* PROM is out to get me -DaveM */
  82. }
  83. void prom_halt_power_off(void)
  84. {
  85. #ifdef CONFIG_SUN_LDOMS
  86. if (ldom_domaining_enabled)
  87. ldom_power_off();
  88. #endif
  89. p1275_cmd("SUNW,power-off", P1275_INOUT(0, 0));
  90. /* if nothing else helps, we just halt */
  91. prom_halt();
  92. }
  93. /* Set prom sync handler to call function 'funcp'. */
  94. void prom_setcallback(callback_func_t funcp)
  95. {
  96. if (!funcp)
  97. return;
  98. p1275_cmd("set-callback", P1275_ARG(0, P1275_ARG_IN_FUNCTION) |
  99. P1275_INOUT(1, 1), funcp);
  100. }
  101. /* Get the idprom and stuff it into buffer 'idbuf'. Returns the
  102. * format type. 'num_bytes' is the number of bytes that your idbuf
  103. * has space for. Returns 0xff on error.
  104. */
  105. unsigned char prom_get_idprom(char *idbuf, int num_bytes)
  106. {
  107. int len;
  108. len = prom_getproplen(prom_root_node, "idprom");
  109. if ((len >num_bytes) || (len == -1))
  110. return 0xff;
  111. if (!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes))
  112. return idbuf[0];
  113. return 0xff;
  114. }
  115. int prom_get_mmu_ihandle(void)
  116. {
  117. int node, ret;
  118. if (prom_mmu_ihandle_cache != 0)
  119. return prom_mmu_ihandle_cache;
  120. node = prom_finddevice(prom_chosen_path);
  121. ret = prom_getint(node, prom_mmu_name);
  122. if (ret == -1 || ret == 0)
  123. prom_mmu_ihandle_cache = -1;
  124. else
  125. prom_mmu_ihandle_cache = ret;
  126. return ret;
  127. }
  128. static int prom_get_memory_ihandle(void)
  129. {
  130. static int memory_ihandle_cache;
  131. int node, ret;
  132. if (memory_ihandle_cache != 0)
  133. return memory_ihandle_cache;
  134. node = prom_finddevice("/chosen");
  135. ret = prom_getint(node, "memory");
  136. if (ret == -1 || ret == 0)
  137. memory_ihandle_cache = -1;
  138. else
  139. memory_ihandle_cache = ret;
  140. return ret;
  141. }
  142. /* Load explicit I/D TLB entries. */
  143. long prom_itlb_load(unsigned long index,
  144. unsigned long tte_data,
  145. unsigned long vaddr)
  146. {
  147. return p1275_cmd(prom_callmethod_name,
  148. (P1275_ARG(0, P1275_ARG_IN_STRING) |
  149. P1275_ARG(2, P1275_ARG_IN_64B) |
  150. P1275_ARG(3, P1275_ARG_IN_64B) |
  151. P1275_INOUT(5, 1)),
  152. "SUNW,itlb-load",
  153. prom_get_mmu_ihandle(),
  154. /* And then our actual args are pushed backwards. */
  155. vaddr,
  156. tte_data,
  157. index);
  158. }
  159. long prom_dtlb_load(unsigned long index,
  160. unsigned long tte_data,
  161. unsigned long vaddr)
  162. {
  163. return p1275_cmd(prom_callmethod_name,
  164. (P1275_ARG(0, P1275_ARG_IN_STRING) |
  165. P1275_ARG(2, P1275_ARG_IN_64B) |
  166. P1275_ARG(3, P1275_ARG_IN_64B) |
  167. P1275_INOUT(5, 1)),
  168. "SUNW,dtlb-load",
  169. prom_get_mmu_ihandle(),
  170. /* And then our actual args are pushed backwards. */
  171. vaddr,
  172. tte_data,
  173. index);
  174. }
  175. int prom_map(int mode, unsigned long size,
  176. unsigned long vaddr, unsigned long paddr)
  177. {
  178. int ret = p1275_cmd(prom_callmethod_name,
  179. (P1275_ARG(0, P1275_ARG_IN_STRING) |
  180. P1275_ARG(3, P1275_ARG_IN_64B) |
  181. P1275_ARG(4, P1275_ARG_IN_64B) |
  182. P1275_ARG(6, P1275_ARG_IN_64B) |
  183. P1275_INOUT(7, 1)),
  184. prom_map_name,
  185. prom_get_mmu_ihandle(),
  186. mode,
  187. size,
  188. vaddr,
  189. 0,
  190. paddr);
  191. if (ret == 0)
  192. ret = -1;
  193. return ret;
  194. }
  195. void prom_unmap(unsigned long size, unsigned long vaddr)
  196. {
  197. p1275_cmd(prom_callmethod_name,
  198. (P1275_ARG(0, P1275_ARG_IN_STRING) |
  199. P1275_ARG(2, P1275_ARG_IN_64B) |
  200. P1275_ARG(3, P1275_ARG_IN_64B) |
  201. P1275_INOUT(4, 0)),
  202. prom_unmap_name,
  203. prom_get_mmu_ihandle(),
  204. size,
  205. vaddr);
  206. }
  207. /* Set aside physical memory which is not touched or modified
  208. * across soft resets.
  209. */
  210. unsigned long prom_retain(const char *name,
  211. unsigned long pa_low, unsigned long pa_high,
  212. long size, long align)
  213. {
  214. /* XXX I don't think we return multiple values correctly.
  215. * XXX OBP supposedly returns pa_low/pa_high here, how does
  216. * XXX it work?
  217. */
  218. /* If align is zero, the pa_low/pa_high args are passed,
  219. * else they are not.
  220. */
  221. if (align == 0)
  222. return p1275_cmd("SUNW,retain",
  223. (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(5, 2)),
  224. name, pa_low, pa_high, size, align);
  225. else
  226. return p1275_cmd("SUNW,retain",
  227. (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(3, 2)),
  228. name, size, align);
  229. }
  230. /* Get "Unumber" string for the SIMM at the given
  231. * memory address. Usually this will be of the form
  232. * "Uxxxx" where xxxx is a decimal number which is
  233. * etched into the motherboard next to the SIMM slot
  234. * in question.
  235. */
  236. int prom_getunumber(int syndrome_code,
  237. unsigned long phys_addr,
  238. char *buf, int buflen)
  239. {
  240. return p1275_cmd(prom_callmethod_name,
  241. (P1275_ARG(0, P1275_ARG_IN_STRING) |
  242. P1275_ARG(3, P1275_ARG_OUT_BUF) |
  243. P1275_ARG(6, P1275_ARG_IN_64B) |
  244. P1275_INOUT(8, 2)),
  245. "SUNW,get-unumber", prom_get_memory_ihandle(),
  246. buflen, buf, P1275_SIZE(buflen),
  247. 0, phys_addr, syndrome_code);
  248. }
  249. /* Power management extensions. */
  250. void prom_sleepself(void)
  251. {
  252. p1275_cmd("SUNW,sleep-self", P1275_INOUT(0, 0));
  253. }
  254. int prom_sleepsystem(void)
  255. {
  256. return p1275_cmd("SUNW,sleep-system", P1275_INOUT(0, 1));
  257. }
  258. int prom_wakeupsystem(void)
  259. {
  260. return p1275_cmd("SUNW,wakeup-system", P1275_INOUT(0, 1));
  261. }
  262. #ifdef CONFIG_SMP
  263. void prom_startcpu(int cpunode, unsigned long pc, unsigned long arg)
  264. {
  265. p1275_cmd("SUNW,start-cpu", P1275_INOUT(3, 0), cpunode, pc, arg);
  266. }
  267. void prom_startcpu_cpuid(int cpuid, unsigned long pc, unsigned long arg)
  268. {
  269. p1275_cmd("SUNW,start-cpu-by-cpuid", P1275_INOUT(3, 0),
  270. cpuid, pc, arg);
  271. }
  272. void prom_stopcpu_cpuid(int cpuid)
  273. {
  274. p1275_cmd("SUNW,stop-cpu-by-cpuid", P1275_INOUT(1, 0),
  275. cpuid);
  276. }
  277. void prom_stopself(void)
  278. {
  279. p1275_cmd("SUNW,stop-self", P1275_INOUT(0, 0));
  280. }
  281. void prom_idleself(void)
  282. {
  283. p1275_cmd("SUNW,idle-self", P1275_INOUT(0, 0));
  284. }
  285. void prom_resumecpu(int cpunode)
  286. {
  287. p1275_cmd("SUNW,resume-cpu", P1275_INOUT(1, 0), cpunode);
  288. }
  289. #endif