misc_64.c 8.9 KB

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