misc.c 7.9 KB

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