misc.c 7.7 KB

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