misc.c 7.3 KB

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