misc.c 7.5 KB

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