misc_64.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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. 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. /* Set prom sync handler to call function 'funcp'. */
  126. void prom_setcallback(callback_func_t funcp)
  127. {
  128. unsigned long args[5];
  129. if (!funcp)
  130. return;
  131. args[0] = (unsigned long) "set-callback";
  132. args[1] = 1;
  133. args[2] = 1;
  134. args[3] = (unsigned long) funcp;
  135. args[4] = (unsigned long) -1;
  136. p1275_cmd_direct(args);
  137. }
  138. /* Get the idprom and stuff it into buffer 'idbuf'. Returns the
  139. * format type. 'num_bytes' is the number of bytes that your idbuf
  140. * has space for. Returns 0xff on error.
  141. */
  142. unsigned char prom_get_idprom(char *idbuf, int num_bytes)
  143. {
  144. int len;
  145. len = prom_getproplen(prom_root_node, "idprom");
  146. if ((len >num_bytes) || (len == -1))
  147. return 0xff;
  148. if (!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes))
  149. return idbuf[0];
  150. return 0xff;
  151. }
  152. int prom_get_mmu_ihandle(void)
  153. {
  154. phandle node;
  155. int ret;
  156. if (prom_mmu_ihandle_cache != 0)
  157. return prom_mmu_ihandle_cache;
  158. node = prom_finddevice(prom_chosen_path);
  159. ret = prom_getint(node, prom_mmu_name);
  160. if (ret == -1 || ret == 0)
  161. prom_mmu_ihandle_cache = -1;
  162. else
  163. prom_mmu_ihandle_cache = ret;
  164. return ret;
  165. }
  166. static int prom_get_memory_ihandle(void)
  167. {
  168. static int memory_ihandle_cache;
  169. phandle node;
  170. int ret;
  171. if (memory_ihandle_cache != 0)
  172. return memory_ihandle_cache;
  173. node = prom_finddevice("/chosen");
  174. ret = prom_getint(node, "memory");
  175. if (ret == -1 || ret == 0)
  176. memory_ihandle_cache = -1;
  177. else
  178. memory_ihandle_cache = ret;
  179. return ret;
  180. }
  181. /* Load explicit I/D TLB entries. */
  182. static long tlb_load(const char *type, unsigned long index,
  183. unsigned long tte_data, unsigned long vaddr)
  184. {
  185. unsigned long args[9];
  186. args[0] = (unsigned long) prom_callmethod_name;
  187. args[1] = 5;
  188. args[2] = 1;
  189. args[3] = (unsigned long) type;
  190. args[4] = (unsigned int) prom_get_mmu_ihandle();
  191. args[5] = vaddr;
  192. args[6] = tte_data;
  193. args[7] = index;
  194. args[8] = (unsigned long) -1;
  195. p1275_cmd_direct(args);
  196. return (long) args[8];
  197. }
  198. long prom_itlb_load(unsigned long index,
  199. unsigned long tte_data,
  200. unsigned long vaddr)
  201. {
  202. return tlb_load("SUNW,itlb-load", index, tte_data, vaddr);
  203. }
  204. long prom_dtlb_load(unsigned long index,
  205. unsigned long tte_data,
  206. unsigned long vaddr)
  207. {
  208. return tlb_load("SUNW,dtlb-load", index, tte_data, vaddr);
  209. }
  210. int prom_map(int mode, unsigned long size,
  211. unsigned long vaddr, unsigned long paddr)
  212. {
  213. unsigned long args[11];
  214. int ret;
  215. args[0] = (unsigned long) prom_callmethod_name;
  216. args[1] = 7;
  217. args[2] = 1;
  218. args[3] = (unsigned long) prom_map_name;
  219. args[4] = (unsigned int) prom_get_mmu_ihandle();
  220. args[5] = (unsigned int) mode;
  221. args[6] = size;
  222. args[7] = vaddr;
  223. args[8] = 0;
  224. args[9] = paddr;
  225. args[10] = (unsigned long) -1;
  226. p1275_cmd_direct(args);
  227. ret = (int) args[10];
  228. if (ret == 0)
  229. ret = -1;
  230. return ret;
  231. }
  232. void prom_unmap(unsigned long size, unsigned long vaddr)
  233. {
  234. unsigned long args[7];
  235. args[0] = (unsigned long) prom_callmethod_name;
  236. args[1] = 4;
  237. args[2] = 0;
  238. args[3] = (unsigned long) prom_unmap_name;
  239. args[4] = (unsigned int) prom_get_mmu_ihandle();
  240. args[5] = size;
  241. args[6] = vaddr;
  242. p1275_cmd_direct(args);
  243. }
  244. /* Set aside physical memory which is not touched or modified
  245. * across soft resets.
  246. */
  247. int prom_retain(const char *name, unsigned long size,
  248. unsigned long align, unsigned long *paddr)
  249. {
  250. unsigned long args[11];
  251. args[0] = (unsigned long) prom_callmethod_name;
  252. args[1] = 5;
  253. args[2] = 3;
  254. args[3] = (unsigned long) "SUNW,retain";
  255. args[4] = (unsigned int) prom_get_memory_ihandle();
  256. args[5] = align;
  257. args[6] = size;
  258. args[7] = (unsigned long) name;
  259. args[8] = (unsigned long) -1;
  260. args[9] = (unsigned long) -1;
  261. args[10] = (unsigned long) -1;
  262. p1275_cmd_direct(args);
  263. if (args[8])
  264. return (int) args[8];
  265. /* Next we get "phys_high" then "phys_low". On 64-bit
  266. * the phys_high cell is don't care since the phys_low
  267. * cell has the full value.
  268. */
  269. *paddr = args[10];
  270. return 0;
  271. }
  272. /* Get "Unumber" string for the SIMM at the given
  273. * memory address. Usually this will be of the form
  274. * "Uxxxx" where xxxx is a decimal number which is
  275. * etched into the motherboard next to the SIMM slot
  276. * in question.
  277. */
  278. int prom_getunumber(int syndrome_code,
  279. unsigned long phys_addr,
  280. char *buf, int buflen)
  281. {
  282. unsigned long args[12];
  283. args[0] = (unsigned long) prom_callmethod_name;
  284. args[1] = 7;
  285. args[2] = 2;
  286. args[3] = (unsigned long) "SUNW,get-unumber";
  287. args[4] = (unsigned int) prom_get_memory_ihandle();
  288. args[5] = buflen;
  289. args[6] = (unsigned long) buf;
  290. args[7] = 0;
  291. args[8] = phys_addr;
  292. args[9] = (unsigned int) syndrome_code;
  293. args[10] = (unsigned long) -1;
  294. args[11] = (unsigned long) -1;
  295. p1275_cmd_direct(args);
  296. return (int) args[10];
  297. }
  298. /* Power management extensions. */
  299. void prom_sleepself(void)
  300. {
  301. unsigned long args[3];
  302. args[0] = (unsigned long) "SUNW,sleep-self";
  303. args[1] = 0;
  304. args[2] = 0;
  305. p1275_cmd_direct(args);
  306. }
  307. int prom_sleepsystem(void)
  308. {
  309. unsigned long args[4];
  310. args[0] = (unsigned long) "SUNW,sleep-system";
  311. args[1] = 0;
  312. args[2] = 1;
  313. args[3] = (unsigned long) -1;
  314. p1275_cmd_direct(args);
  315. return (int) args[3];
  316. }
  317. int prom_wakeupsystem(void)
  318. {
  319. unsigned long args[4];
  320. args[0] = (unsigned long) "SUNW,wakeup-system";
  321. args[1] = 0;
  322. args[2] = 1;
  323. args[3] = (unsigned long) -1;
  324. p1275_cmd_direct(args);
  325. return (int) args[3];
  326. }
  327. #ifdef CONFIG_SMP
  328. void prom_startcpu(int cpunode, unsigned long pc, unsigned long arg)
  329. {
  330. unsigned long args[6];
  331. args[0] = (unsigned long) "SUNW,start-cpu";
  332. args[1] = 3;
  333. args[2] = 0;
  334. args[3] = (unsigned int) cpunode;
  335. args[4] = pc;
  336. args[5] = arg;
  337. p1275_cmd_direct(args);
  338. }
  339. void prom_startcpu_cpuid(int cpuid, unsigned long pc, unsigned long arg)
  340. {
  341. unsigned long args[6];
  342. args[0] = (unsigned long) "SUNW,start-cpu-by-cpuid";
  343. args[1] = 3;
  344. args[2] = 0;
  345. args[3] = (unsigned int) cpuid;
  346. args[4] = pc;
  347. args[5] = arg;
  348. p1275_cmd_direct(args);
  349. }
  350. void prom_stopcpu_cpuid(int cpuid)
  351. {
  352. unsigned long args[4];
  353. args[0] = (unsigned long) "SUNW,stop-cpu-by-cpuid";
  354. args[1] = 1;
  355. args[2] = 0;
  356. args[3] = (unsigned int) cpuid;
  357. p1275_cmd_direct(args);
  358. }
  359. void prom_stopself(void)
  360. {
  361. unsigned long args[3];
  362. args[0] = (unsigned long) "SUNW,stop-self";
  363. args[1] = 0;
  364. args[2] = 0;
  365. p1275_cmd_direct(args);
  366. }
  367. void prom_idleself(void)
  368. {
  369. unsigned long args[3];
  370. args[0] = (unsigned long) "SUNW,idle-self";
  371. args[1] = 0;
  372. args[2] = 0;
  373. p1275_cmd_direct(args);
  374. }
  375. void prom_resumecpu(int cpunode)
  376. {
  377. unsigned long args[4];
  378. args[0] = (unsigned long) "SUNW,resume-cpu";
  379. args[1] = 1;
  380. args[2] = 0;
  381. args[3] = (unsigned int) cpunode;
  382. p1275_cmd_direct(args);
  383. }
  384. #endif