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