misc_64.c 8.9 KB

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