misc.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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(const 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(const 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 prom_get_mmu_ihandle(void)
  126. {
  127. int node, ret;
  128. if (prom_mmu_ihandle_cache != 0)
  129. return prom_mmu_ihandle_cache;
  130. node = prom_finddevice(prom_chosen_path);
  131. ret = prom_getint(node, prom_mmu_name);
  132. if (ret == -1 || ret == 0)
  133. prom_mmu_ihandle_cache = -1;
  134. else
  135. prom_mmu_ihandle_cache = ret;
  136. return ret;
  137. }
  138. static int prom_get_memory_ihandle(void)
  139. {
  140. static int memory_ihandle_cache;
  141. int node, ret;
  142. if (memory_ihandle_cache != 0)
  143. return memory_ihandle_cache;
  144. node = prom_finddevice("/chosen");
  145. ret = prom_getint(node, "memory");
  146. if (ret == -1 || ret == 0)
  147. memory_ihandle_cache = -1;
  148. else
  149. memory_ihandle_cache = ret;
  150. return ret;
  151. }
  152. /* Load explicit I/D TLB entries. */
  153. long prom_itlb_load(unsigned long index,
  154. unsigned long tte_data,
  155. unsigned long vaddr)
  156. {
  157. return p1275_cmd(prom_callmethod_name,
  158. (P1275_ARG(0, P1275_ARG_IN_STRING) |
  159. P1275_ARG(2, P1275_ARG_IN_64B) |
  160. P1275_ARG(3, P1275_ARG_IN_64B) |
  161. P1275_INOUT(5, 1)),
  162. "SUNW,itlb-load",
  163. prom_get_mmu_ihandle(),
  164. /* And then our actual args are pushed backwards. */
  165. vaddr,
  166. tte_data,
  167. index);
  168. }
  169. long prom_dtlb_load(unsigned long index,
  170. unsigned long tte_data,
  171. unsigned long vaddr)
  172. {
  173. return p1275_cmd(prom_callmethod_name,
  174. (P1275_ARG(0, P1275_ARG_IN_STRING) |
  175. P1275_ARG(2, P1275_ARG_IN_64B) |
  176. P1275_ARG(3, P1275_ARG_IN_64B) |
  177. P1275_INOUT(5, 1)),
  178. "SUNW,dtlb-load",
  179. prom_get_mmu_ihandle(),
  180. /* And then our actual args are pushed backwards. */
  181. vaddr,
  182. tte_data,
  183. index);
  184. }
  185. int prom_map(int mode, unsigned long size,
  186. unsigned long vaddr, unsigned long paddr)
  187. {
  188. int ret = p1275_cmd(prom_callmethod_name,
  189. (P1275_ARG(0, P1275_ARG_IN_STRING) |
  190. P1275_ARG(3, P1275_ARG_IN_64B) |
  191. P1275_ARG(4, P1275_ARG_IN_64B) |
  192. P1275_ARG(6, P1275_ARG_IN_64B) |
  193. P1275_INOUT(7, 1)),
  194. prom_map_name,
  195. prom_get_mmu_ihandle(),
  196. mode,
  197. size,
  198. vaddr,
  199. 0,
  200. paddr);
  201. if (ret == 0)
  202. ret = -1;
  203. return ret;
  204. }
  205. void prom_unmap(unsigned long size, unsigned long vaddr)
  206. {
  207. p1275_cmd(prom_callmethod_name,
  208. (P1275_ARG(0, P1275_ARG_IN_STRING) |
  209. P1275_ARG(2, P1275_ARG_IN_64B) |
  210. P1275_ARG(3, P1275_ARG_IN_64B) |
  211. P1275_INOUT(4, 0)),
  212. prom_unmap_name,
  213. prom_get_mmu_ihandle(),
  214. size,
  215. vaddr);
  216. }
  217. /* Set aside physical memory which is not touched or modified
  218. * across soft resets.
  219. */
  220. unsigned long prom_retain(const char *name,
  221. unsigned long pa_low, unsigned long pa_high,
  222. long size, long align)
  223. {
  224. /* XXX I don't think we return multiple values correctly.
  225. * XXX OBP supposedly returns pa_low/pa_high here, how does
  226. * XXX it work?
  227. */
  228. /* If align is zero, the pa_low/pa_high args are passed,
  229. * else they are not.
  230. */
  231. if (align == 0)
  232. return p1275_cmd("SUNW,retain",
  233. (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(5, 2)),
  234. name, pa_low, pa_high, size, align);
  235. else
  236. return p1275_cmd("SUNW,retain",
  237. (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(3, 2)),
  238. name, size, align);
  239. }
  240. /* Get "Unumber" string for the SIMM at the given
  241. * memory address. Usually this will be of the form
  242. * "Uxxxx" where xxxx is a decimal number which is
  243. * etched into the motherboard next to the SIMM slot
  244. * in question.
  245. */
  246. int prom_getunumber(int syndrome_code,
  247. unsigned long phys_addr,
  248. char *buf, int buflen)
  249. {
  250. return p1275_cmd(prom_callmethod_name,
  251. (P1275_ARG(0, P1275_ARG_IN_STRING) |
  252. P1275_ARG(3, P1275_ARG_OUT_BUF) |
  253. P1275_ARG(6, P1275_ARG_IN_64B) |
  254. P1275_INOUT(8, 2)),
  255. "SUNW,get-unumber", prom_get_memory_ihandle(),
  256. buflen, buf, P1275_SIZE(buflen),
  257. 0, phys_addr, syndrome_code);
  258. }
  259. /* Power management extensions. */
  260. void prom_sleepself(void)
  261. {
  262. p1275_cmd("SUNW,sleep-self", P1275_INOUT(0, 0));
  263. }
  264. int prom_sleepsystem(void)
  265. {
  266. return p1275_cmd("SUNW,sleep-system", P1275_INOUT(0, 1));
  267. }
  268. int prom_wakeupsystem(void)
  269. {
  270. return p1275_cmd("SUNW,wakeup-system", P1275_INOUT(0, 1));
  271. }
  272. #ifdef CONFIG_SMP
  273. void prom_startcpu(int cpunode, unsigned long pc, unsigned long o0)
  274. {
  275. p1275_cmd("SUNW,start-cpu", P1275_INOUT(3, 0), cpunode, pc, o0);
  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