misc_64.c 8.8 KB

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