misc.c 7.4 KB

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