misc.c 8.0 KB

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