misc_64.c 7.5 KB

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