misc_64.c 9.2 KB

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