misc.c 7.5 KB

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