misc_64.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  1. /*
  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 <linux/module.h>
  14. #include <asm/openprom.h>
  15. #include <asm/oplib.h>
  16. #include <asm/ldc.h>
  17. static int prom_service_exists(const char *service_name)
  18. {
  19. unsigned long args[5];
  20. args[0] = (unsigned long) "test";
  21. args[1] = 1;
  22. args[2] = 1;
  23. args[3] = (unsigned long) service_name;
  24. args[4] = (unsigned long) -1;
  25. p1275_cmd_direct(args);
  26. if (args[4])
  27. return 0;
  28. return 1;
  29. }
  30. void prom_sun4v_guest_soft_state(void)
  31. {
  32. const char *svc = "SUNW,soft-state-supported";
  33. unsigned long args[3];
  34. if (!prom_service_exists(svc))
  35. return;
  36. args[0] = (unsigned long) svc;
  37. args[1] = 0;
  38. args[2] = 0;
  39. p1275_cmd_direct(args);
  40. }
  41. /* Reset and reboot the machine with the command 'bcommand'. */
  42. void prom_reboot(const char *bcommand)
  43. {
  44. unsigned long args[4];
  45. #ifdef CONFIG_SUN_LDOMS
  46. if (ldom_domaining_enabled)
  47. ldom_reboot(bcommand);
  48. #endif
  49. args[0] = (unsigned long) "boot";
  50. args[1] = 1;
  51. args[2] = 0;
  52. args[3] = (unsigned long) bcommand;
  53. p1275_cmd_direct(args);
  54. }
  55. /* Forth evaluate the expression contained in 'fstring'. */
  56. void prom_feval(const char *fstring)
  57. {
  58. unsigned long args[5];
  59. if (!fstring || fstring[0] == 0)
  60. return;
  61. args[0] = (unsigned long) "interpret";
  62. args[1] = 1;
  63. args[2] = 1;
  64. args[3] = (unsigned long) fstring;
  65. args[4] = (unsigned long) -1;
  66. p1275_cmd_direct(args);
  67. }
  68. EXPORT_SYMBOL(prom_feval);
  69. /* Drop into the prom, with the chance to continue with the 'go'
  70. * prom command.
  71. */
  72. void prom_cmdline(void)
  73. {
  74. unsigned long args[3];
  75. unsigned long flags;
  76. local_irq_save(flags);
  77. #ifdef CONFIG_SMP
  78. smp_capture();
  79. #endif
  80. args[0] = (unsigned long) "enter";
  81. args[1] = 0;
  82. args[2] = 0;
  83. p1275_cmd_direct(args);
  84. #ifdef CONFIG_SMP
  85. smp_release();
  86. #endif
  87. local_irq_restore(flags);
  88. }
  89. /* Drop into the prom, but completely terminate the program.
  90. * No chance of continuing.
  91. */
  92. void notrace prom_halt(void)
  93. {
  94. unsigned long args[3];
  95. #ifdef CONFIG_SUN_LDOMS
  96. if (ldom_domaining_enabled)
  97. ldom_power_off();
  98. #endif
  99. again:
  100. args[0] = (unsigned long) "exit";
  101. args[1] = 0;
  102. args[2] = 0;
  103. p1275_cmd_direct(args);
  104. goto again; /* PROM is out to get me -DaveM */
  105. }
  106. void prom_halt_power_off(void)
  107. {
  108. unsigned long args[3];
  109. #ifdef CONFIG_SUN_LDOMS
  110. if (ldom_domaining_enabled)
  111. ldom_power_off();
  112. #endif
  113. args[0] = (unsigned long) "SUNW,power-off";
  114. args[1] = 0;
  115. args[2] = 0;
  116. p1275_cmd_direct(args);
  117. /* if nothing else helps, we just halt */
  118. prom_halt();
  119. }
  120. /* Get the idprom and stuff it into buffer 'idbuf'. Returns the
  121. * format type. 'num_bytes' is the number of bytes that your idbuf
  122. * has space for. Returns 0xff on error.
  123. */
  124. unsigned char prom_get_idprom(char *idbuf, int num_bytes)
  125. {
  126. int len;
  127. len = prom_getproplen(prom_root_node, "idprom");
  128. if ((len >num_bytes) || (len == -1))
  129. return 0xff;
  130. if (!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes))
  131. return idbuf[0];
  132. return 0xff;
  133. }
  134. int prom_get_mmu_ihandle(void)
  135. {
  136. phandle node;
  137. int ret;
  138. if (prom_mmu_ihandle_cache != 0)
  139. return prom_mmu_ihandle_cache;
  140. node = prom_finddevice(prom_chosen_path);
  141. ret = prom_getint(node, prom_mmu_name);
  142. if (ret == -1 || ret == 0)
  143. prom_mmu_ihandle_cache = -1;
  144. else
  145. prom_mmu_ihandle_cache = ret;
  146. return ret;
  147. }
  148. static int prom_get_memory_ihandle(void)
  149. {
  150. static int memory_ihandle_cache;
  151. phandle node;
  152. int ret;
  153. if (memory_ihandle_cache != 0)
  154. return memory_ihandle_cache;
  155. node = prom_finddevice("/chosen");
  156. ret = prom_getint(node, "memory");
  157. if (ret == -1 || ret == 0)
  158. memory_ihandle_cache = -1;
  159. else
  160. memory_ihandle_cache = ret;
  161. return ret;
  162. }
  163. /* Load explicit I/D TLB entries. */
  164. static long tlb_load(const char *type, unsigned long index,
  165. unsigned long tte_data, unsigned long vaddr)
  166. {
  167. unsigned long args[9];
  168. args[0] = (unsigned long) prom_callmethod_name;
  169. args[1] = 5;
  170. args[2] = 1;
  171. args[3] = (unsigned long) type;
  172. args[4] = (unsigned int) prom_get_mmu_ihandle();
  173. args[5] = vaddr;
  174. args[6] = tte_data;
  175. args[7] = index;
  176. args[8] = (unsigned long) -1;
  177. p1275_cmd_direct(args);
  178. return (long) args[8];
  179. }
  180. long prom_itlb_load(unsigned long index,
  181. unsigned long tte_data,
  182. unsigned long vaddr)
  183. {
  184. return tlb_load("SUNW,itlb-load", index, tte_data, vaddr);
  185. }
  186. long prom_dtlb_load(unsigned long index,
  187. unsigned long tte_data,
  188. unsigned long vaddr)
  189. {
  190. return tlb_load("SUNW,dtlb-load", index, tte_data, vaddr);
  191. }
  192. int prom_map(int mode, unsigned long size,
  193. unsigned long vaddr, unsigned long paddr)
  194. {
  195. unsigned long args[11];
  196. int ret;
  197. args[0] = (unsigned long) prom_callmethod_name;
  198. args[1] = 7;
  199. args[2] = 1;
  200. args[3] = (unsigned long) prom_map_name;
  201. args[4] = (unsigned int) prom_get_mmu_ihandle();
  202. args[5] = (unsigned int) mode;
  203. args[6] = size;
  204. args[7] = vaddr;
  205. args[8] = 0;
  206. args[9] = paddr;
  207. args[10] = (unsigned long) -1;
  208. p1275_cmd_direct(args);
  209. ret = (int) args[10];
  210. if (ret == 0)
  211. ret = -1;
  212. return ret;
  213. }
  214. void prom_unmap(unsigned long size, unsigned long vaddr)
  215. {
  216. unsigned long args[7];
  217. args[0] = (unsigned long) prom_callmethod_name;
  218. args[1] = 4;
  219. args[2] = 0;
  220. args[3] = (unsigned long) prom_unmap_name;
  221. args[4] = (unsigned int) prom_get_mmu_ihandle();
  222. args[5] = size;
  223. args[6] = vaddr;
  224. p1275_cmd_direct(args);
  225. }
  226. /* Set aside physical memory which is not touched or modified
  227. * across soft resets.
  228. */
  229. int prom_retain(const char *name, unsigned long size,
  230. unsigned long align, unsigned long *paddr)
  231. {
  232. unsigned long args[11];
  233. args[0] = (unsigned long) prom_callmethod_name;
  234. args[1] = 5;
  235. args[2] = 3;
  236. args[3] = (unsigned long) "SUNW,retain";
  237. args[4] = (unsigned int) prom_get_memory_ihandle();
  238. args[5] = align;
  239. args[6] = size;
  240. args[7] = (unsigned long) name;
  241. args[8] = (unsigned long) -1;
  242. args[9] = (unsigned long) -1;
  243. args[10] = (unsigned long) -1;
  244. p1275_cmd_direct(args);
  245. if (args[8])
  246. return (int) args[8];
  247. /* Next we get "phys_high" then "phys_low". On 64-bit
  248. * the phys_high cell is don't care since the phys_low
  249. * cell has the full value.
  250. */
  251. *paddr = args[10];
  252. return 0;
  253. }
  254. /* Get "Unumber" string for the SIMM at the given
  255. * memory address. Usually this will be of the form
  256. * "Uxxxx" where xxxx is a decimal number which is
  257. * etched into the motherboard next to the SIMM slot
  258. * in question.
  259. */
  260. int prom_getunumber(int syndrome_code,
  261. unsigned long phys_addr,
  262. char *buf, int buflen)
  263. {
  264. unsigned long args[12];
  265. args[0] = (unsigned long) prom_callmethod_name;
  266. args[1] = 7;
  267. args[2] = 2;
  268. args[3] = (unsigned long) "SUNW,get-unumber";
  269. args[4] = (unsigned int) prom_get_memory_ihandle();
  270. args[5] = buflen;
  271. args[6] = (unsigned long) buf;
  272. args[7] = 0;
  273. args[8] = phys_addr;
  274. args[9] = (unsigned int) syndrome_code;
  275. args[10] = (unsigned long) -1;
  276. args[11] = (unsigned long) -1;
  277. p1275_cmd_direct(args);
  278. return (int) args[10];
  279. }
  280. /* Power management extensions. */
  281. void prom_sleepself(void)
  282. {
  283. unsigned long args[3];
  284. args[0] = (unsigned long) "SUNW,sleep-self";
  285. args[1] = 0;
  286. args[2] = 0;
  287. p1275_cmd_direct(args);
  288. }
  289. int prom_sleepsystem(void)
  290. {
  291. unsigned long args[4];
  292. args[0] = (unsigned long) "SUNW,sleep-system";
  293. args[1] = 0;
  294. args[2] = 1;
  295. args[3] = (unsigned long) -1;
  296. p1275_cmd_direct(args);
  297. return (int) args[3];
  298. }
  299. int prom_wakeupsystem(void)
  300. {
  301. unsigned long args[4];
  302. args[0] = (unsigned long) "SUNW,wakeup-system";
  303. args[1] = 0;
  304. args[2] = 1;
  305. args[3] = (unsigned long) -1;
  306. p1275_cmd_direct(args);
  307. return (int) args[3];
  308. }
  309. #ifdef CONFIG_SMP
  310. void prom_startcpu(int cpunode, unsigned long pc, unsigned long arg)
  311. {
  312. unsigned long args[6];
  313. args[0] = (unsigned long) "SUNW,start-cpu";
  314. args[1] = 3;
  315. args[2] = 0;
  316. args[3] = (unsigned int) cpunode;
  317. args[4] = pc;
  318. args[5] = arg;
  319. p1275_cmd_direct(args);
  320. }
  321. void prom_startcpu_cpuid(int cpuid, unsigned long pc, unsigned long arg)
  322. {
  323. unsigned long args[6];
  324. args[0] = (unsigned long) "SUNW,start-cpu-by-cpuid";
  325. args[1] = 3;
  326. args[2] = 0;
  327. args[3] = (unsigned int) cpuid;
  328. args[4] = pc;
  329. args[5] = arg;
  330. p1275_cmd_direct(args);
  331. }
  332. void prom_stopcpu_cpuid(int cpuid)
  333. {
  334. unsigned long args[4];
  335. args[0] = (unsigned long) "SUNW,stop-cpu-by-cpuid";
  336. args[1] = 1;
  337. args[2] = 0;
  338. args[3] = (unsigned int) cpuid;
  339. p1275_cmd_direct(args);
  340. }
  341. void prom_stopself(void)
  342. {
  343. unsigned long args[3];
  344. args[0] = (unsigned long) "SUNW,stop-self";
  345. args[1] = 0;
  346. args[2] = 0;
  347. p1275_cmd_direct(args);
  348. }
  349. void prom_idleself(void)
  350. {
  351. unsigned long args[3];
  352. args[0] = (unsigned long) "SUNW,idle-self";
  353. args[1] = 0;
  354. args[2] = 0;
  355. p1275_cmd_direct(args);
  356. }
  357. void prom_resumecpu(int cpunode)
  358. {
  359. unsigned long args[4];
  360. args[0] = (unsigned long) "SUNW,resume-cpu";
  361. args[1] = 1;
  362. args[2] = 0;
  363. args[3] = (unsigned int) cpunode;
  364. p1275_cmd_direct(args);
  365. }
  366. #endif