misc.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /* $Id: misc.c,v 1.20 2001/09/21 03:17:07 kanoj Exp $
  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. /* We want to do this more nicely some day. */
  51. extern void (*prom_palette)(int);
  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. if (!serial_console && prom_palette)
  64. prom_palette(1);
  65. #ifdef CONFIG_SMP
  66. smp_capture();
  67. #endif
  68. p1275_cmd("enter", P1275_INOUT(0, 0));
  69. #ifdef CONFIG_SMP
  70. smp_release();
  71. #endif
  72. if (!serial_console && prom_palette)
  73. prom_palette(0);
  74. local_irq_restore(flags);
  75. }
  76. /* Drop into the prom, but completely terminate the program.
  77. * No chance of continuing.
  78. */
  79. void prom_halt(void)
  80. {
  81. #ifdef CONFIG_SUN_LDOMS
  82. if (ldom_domaining_enabled)
  83. ldom_power_off();
  84. #endif
  85. again:
  86. p1275_cmd("exit", P1275_INOUT(0, 0));
  87. goto again; /* PROM is out to get me -DaveM */
  88. }
  89. void prom_halt_power_off(void)
  90. {
  91. #ifdef CONFIG_SUN_LDOMS
  92. if (ldom_domaining_enabled)
  93. ldom_power_off();
  94. #endif
  95. p1275_cmd("SUNW,power-off", P1275_INOUT(0, 0));
  96. /* if nothing else helps, we just halt */
  97. prom_halt();
  98. }
  99. /* Set prom sync handler to call function 'funcp'. */
  100. void prom_setcallback(callback_func_t funcp)
  101. {
  102. if (!funcp)
  103. return;
  104. p1275_cmd("set-callback", P1275_ARG(0, P1275_ARG_IN_FUNCTION) |
  105. P1275_INOUT(1, 1), funcp);
  106. }
  107. /* Get the idprom and stuff it into buffer 'idbuf'. Returns the
  108. * format type. 'num_bytes' is the number of bytes that your idbuf
  109. * has space for. Returns 0xff on error.
  110. */
  111. unsigned char prom_get_idprom(char *idbuf, int num_bytes)
  112. {
  113. int len;
  114. len = prom_getproplen(prom_root_node, "idprom");
  115. if ((len >num_bytes) || (len == -1))
  116. return 0xff;
  117. if (!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes))
  118. return idbuf[0];
  119. return 0xff;
  120. }
  121. /* Install Linux trap table so PROM uses that instead of its own. */
  122. void prom_set_trap_table(unsigned long tba)
  123. {
  124. p1275_cmd("SUNW,set-trap-table",
  125. (P1275_ARG(0, P1275_ARG_IN_64B) |
  126. P1275_INOUT(1, 0)), tba);
  127. }
  128. void prom_set_trap_table_sun4v(unsigned long tba, unsigned long mmfsa)
  129. {
  130. p1275_cmd("SUNW,set-trap-table",
  131. (P1275_ARG(0, P1275_ARG_IN_64B) |
  132. P1275_ARG(1, P1275_ARG_IN_64B) |
  133. P1275_INOUT(2, 0)), tba, mmfsa);
  134. }
  135. int prom_get_mmu_ihandle(void)
  136. {
  137. int node, ret;
  138. if (prom_mmu_ihandle_cache != 0)
  139. return prom_mmu_ihandle_cache;
  140. node = prom_finddevice(prom_chosen_path);
  141. ret = prom_getint(node, prom_mmu_name);
  142. if (ret == -1 || ret == 0)
  143. prom_mmu_ihandle_cache = -1;
  144. else
  145. prom_mmu_ihandle_cache = ret;
  146. return ret;
  147. }
  148. static int prom_get_memory_ihandle(void)
  149. {
  150. static int memory_ihandle_cache;
  151. int node, ret;
  152. if (memory_ihandle_cache != 0)
  153. return memory_ihandle_cache;
  154. node = prom_finddevice("/chosen");
  155. ret = prom_getint(node, "memory");
  156. if (ret == -1 || ret == 0)
  157. memory_ihandle_cache = -1;
  158. else
  159. memory_ihandle_cache = ret;
  160. return ret;
  161. }
  162. /* Load explicit I/D TLB entries. */
  163. long prom_itlb_load(unsigned long index,
  164. unsigned long tte_data,
  165. unsigned long vaddr)
  166. {
  167. return p1275_cmd(prom_callmethod_name,
  168. (P1275_ARG(0, P1275_ARG_IN_STRING) |
  169. P1275_ARG(2, P1275_ARG_IN_64B) |
  170. P1275_ARG(3, P1275_ARG_IN_64B) |
  171. P1275_INOUT(5, 1)),
  172. "SUNW,itlb-load",
  173. prom_get_mmu_ihandle(),
  174. /* And then our actual args are pushed backwards. */
  175. vaddr,
  176. tte_data,
  177. index);
  178. }
  179. long prom_dtlb_load(unsigned long index,
  180. unsigned long tte_data,
  181. unsigned long vaddr)
  182. {
  183. return p1275_cmd(prom_callmethod_name,
  184. (P1275_ARG(0, P1275_ARG_IN_STRING) |
  185. P1275_ARG(2, P1275_ARG_IN_64B) |
  186. P1275_ARG(3, P1275_ARG_IN_64B) |
  187. P1275_INOUT(5, 1)),
  188. "SUNW,dtlb-load",
  189. prom_get_mmu_ihandle(),
  190. /* And then our actual args are pushed backwards. */
  191. vaddr,
  192. tte_data,
  193. index);
  194. }
  195. int prom_map(int mode, unsigned long size,
  196. unsigned long vaddr, unsigned long paddr)
  197. {
  198. int ret = p1275_cmd(prom_callmethod_name,
  199. (P1275_ARG(0, P1275_ARG_IN_STRING) |
  200. P1275_ARG(3, P1275_ARG_IN_64B) |
  201. P1275_ARG(4, P1275_ARG_IN_64B) |
  202. P1275_ARG(6, P1275_ARG_IN_64B) |
  203. P1275_INOUT(7, 1)),
  204. prom_map_name,
  205. prom_get_mmu_ihandle(),
  206. mode,
  207. size,
  208. vaddr,
  209. 0,
  210. paddr);
  211. if (ret == 0)
  212. ret = -1;
  213. return ret;
  214. }
  215. void prom_unmap(unsigned long size, unsigned long vaddr)
  216. {
  217. p1275_cmd(prom_callmethod_name,
  218. (P1275_ARG(0, P1275_ARG_IN_STRING) |
  219. P1275_ARG(2, P1275_ARG_IN_64B) |
  220. P1275_ARG(3, P1275_ARG_IN_64B) |
  221. P1275_INOUT(4, 0)),
  222. prom_unmap_name,
  223. prom_get_mmu_ihandle(),
  224. size,
  225. vaddr);
  226. }
  227. /* Set aside physical memory which is not touched or modified
  228. * across soft resets.
  229. */
  230. unsigned long prom_retain(const char *name,
  231. unsigned long pa_low, unsigned long pa_high,
  232. long size, long align)
  233. {
  234. /* XXX I don't think we return multiple values correctly.
  235. * XXX OBP supposedly returns pa_low/pa_high here, how does
  236. * XXX it work?
  237. */
  238. /* If align is zero, the pa_low/pa_high args are passed,
  239. * else they are not.
  240. */
  241. if (align == 0)
  242. return p1275_cmd("SUNW,retain",
  243. (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(5, 2)),
  244. name, pa_low, pa_high, size, align);
  245. else
  246. return p1275_cmd("SUNW,retain",
  247. (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(3, 2)),
  248. name, size, align);
  249. }
  250. /* Get "Unumber" string for the SIMM at the given
  251. * memory address. Usually this will be of the form
  252. * "Uxxxx" where xxxx is a decimal number which is
  253. * etched into the motherboard next to the SIMM slot
  254. * in question.
  255. */
  256. int prom_getunumber(int syndrome_code,
  257. unsigned long phys_addr,
  258. char *buf, int buflen)
  259. {
  260. return p1275_cmd(prom_callmethod_name,
  261. (P1275_ARG(0, P1275_ARG_IN_STRING) |
  262. P1275_ARG(3, P1275_ARG_OUT_BUF) |
  263. P1275_ARG(6, P1275_ARG_IN_64B) |
  264. P1275_INOUT(8, 2)),
  265. "SUNW,get-unumber", prom_get_memory_ihandle(),
  266. buflen, buf, P1275_SIZE(buflen),
  267. 0, phys_addr, syndrome_code);
  268. }
  269. /* Power management extensions. */
  270. void prom_sleepself(void)
  271. {
  272. p1275_cmd("SUNW,sleep-self", P1275_INOUT(0, 0));
  273. }
  274. int prom_sleepsystem(void)
  275. {
  276. return p1275_cmd("SUNW,sleep-system", P1275_INOUT(0, 1));
  277. }
  278. int prom_wakeupsystem(void)
  279. {
  280. return p1275_cmd("SUNW,wakeup-system", P1275_INOUT(0, 1));
  281. }
  282. #ifdef CONFIG_SMP
  283. void prom_startcpu(int cpunode, unsigned long pc, unsigned long arg)
  284. {
  285. p1275_cmd("SUNW,start-cpu", P1275_INOUT(3, 0), cpunode, pc, arg);
  286. }
  287. void prom_startcpu_cpuid(int cpuid, unsigned long pc, unsigned long arg)
  288. {
  289. p1275_cmd("SUNW,start-cpu-by-cpuid", P1275_INOUT(3, 0),
  290. cpuid, pc, arg);
  291. }
  292. void prom_stopcpu_cpuid(int cpuid)
  293. {
  294. p1275_cmd("SUNW,stop-cpu-by-cpuid", P1275_INOUT(1, 0),
  295. cpuid);
  296. }
  297. void prom_stopself(void)
  298. {
  299. p1275_cmd("SUNW,stop-self", P1275_INOUT(0, 0));
  300. }
  301. void prom_idleself(void)
  302. {
  303. p1275_cmd("SUNW,idle-self", P1275_INOUT(0, 0));
  304. }
  305. void prom_resumecpu(int cpunode)
  306. {
  307. p1275_cmd("SUNW,resume-cpu", P1275_INOUT(1, 0), cpunode);
  308. }
  309. #endif