misc.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:8k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* $Id: misc.c,v 1.20 2001/09/21 03:17:07 kanoj Exp $
  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/config.h>
  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 <asm/openprom.h>
  15. #include <asm/oplib.h>
  16. /* Reset and reboot the machine with the command 'bcommand'. */
  17. void
  18. prom_reboot(char *bcommand)
  19. {
  20. p1275_cmd ("boot", P1275_ARG(0,P1275_ARG_IN_STRING)|
  21.            P1275_INOUT(1,0), bcommand);
  22. }
  23. /* Forth evaluate the expression contained in 'fstring'. */
  24. void
  25. prom_feval(char *fstring)
  26. {
  27. if(!fstring || fstring[0] == 0)
  28. return;
  29. p1275_cmd ("interpret", P1275_ARG(0,P1275_ARG_IN_STRING)|
  30. P1275_INOUT(1,1), fstring);
  31. }
  32. /* We want to do this more nicely some day. */
  33. #ifdef CONFIG_SUN_CONSOLE
  34. extern void (*prom_palette)(int);
  35. extern int serial_console;
  36. #endif
  37. #ifdef CONFIG_SMP
  38. extern void smp_capture(void);
  39. extern void smp_release(void);
  40. #endif
  41. /* Drop into the prom, with the chance to continue with the 'go'
  42.  * prom command.
  43.  */
  44. void
  45. prom_cmdline(void)
  46. {
  47. unsigned long flags;
  48. __save_and_cli(flags);
  49. #ifdef CONFIG_SUN_CONSOLE
  50. if(!serial_console && prom_palette)
  51. prom_palette (1);
  52. #endif
  53. #ifdef CONFIG_SMP
  54. smp_capture();
  55. #endif
  56. p1275_cmd ("enter", P1275_INOUT(0,0));
  57. #ifdef CONFIG_SMP
  58. smp_release();
  59. spin_unlock_wait(&__br_write_locks[BR_GLOBALIRQ_LOCK].lock);
  60. #endif
  61. #ifdef CONFIG_SUN_CONSOLE
  62. if(!serial_console && prom_palette)
  63. prom_palette (0);
  64. #endif
  65. __restore_flags(flags);
  66. }
  67. #ifdef CONFIG_SMP
  68. extern void smp_promstop_others(void);
  69. #endif
  70. /* Drop into the prom, but completely terminate the program.
  71.  * No chance of continuing.
  72.  */
  73. void
  74. prom_halt(void)
  75. {
  76. #ifdef CONFIG_SMP
  77. smp_promstop_others();
  78. udelay(8000);
  79. #endif
  80. again:
  81. p1275_cmd ("exit", P1275_INOUT(0,0));
  82. goto again; /* PROM is out to get me -DaveM */
  83. }
  84. void
  85. prom_halt_power_off(void)
  86. {
  87. #ifdef CONFIG_SMP
  88. smp_promstop_others();
  89. udelay(8000);
  90. #endif
  91. p1275_cmd ("SUNW,power-off", P1275_INOUT(0,0));
  92. /* if nothing else helps, we just halt */
  93. prom_halt ();
  94. }
  95. /* Set prom sync handler to call function 'funcp'. */
  96. void
  97. prom_setcallback(callback_func_t funcp)
  98. {
  99. if(!funcp) return;
  100. p1275_cmd ("set-callback", P1275_ARG(0,P1275_ARG_IN_FUNCTION)|
  101.    P1275_INOUT(1,1), funcp);
  102. }
  103. /* Get the idprom and stuff it into buffer 'idbuf'.  Returns the
  104.  * format type.  'num_bytes' is the number of bytes that your idbuf
  105.  * has space for.  Returns 0xff on error.
  106.  */
  107. unsigned char
  108. prom_get_idprom(char *idbuf, int num_bytes)
  109. {
  110. int len;
  111. len = prom_getproplen(prom_root_node, "idprom");
  112. if((len>num_bytes) || (len==-1)) return 0xff;
  113. if(!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes))
  114. return idbuf[0];
  115. return 0xff;
  116. }
  117. /* Get the major prom version number. */
  118. int
  119. prom_version(void)
  120. {
  121. return PROM_P1275;
  122. }
  123. /* Get the prom plugin-revision. */
  124. int
  125. prom_getrev(void)
  126. {
  127. return prom_rev;
  128. }
  129. /* Get the prom firmware print revision. */
  130. int
  131. prom_getprev(void)
  132. {
  133. return prom_prev;
  134. }
  135. /* Install Linux trap table so PROM uses that instead of it's own. */
  136. void prom_set_trap_table(unsigned long tba)
  137. {
  138. p1275_cmd("SUNW,set-trap-table", P1275_INOUT(1, 0), tba);
  139. }
  140. int mmu_ihandle_cache = 0;
  141. int prom_get_mmu_ihandle(void)
  142. {
  143. int node, ret;
  144. if (mmu_ihandle_cache != 0)
  145. return mmu_ihandle_cache;
  146. node = prom_finddevice("/chosen");
  147. ret = prom_getint(node, "mmu");
  148. if(ret == -1 || ret == 0)
  149. mmu_ihandle_cache = -1;
  150. else
  151. mmu_ihandle_cache = ret;
  152. return ret;
  153. }
  154. static int prom_get_memory_ihandle(void)
  155. {
  156. static int memory_ihandle_cache;
  157. int node, 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. long prom_itlb_load(unsigned long index,
  170.     unsigned long tte_data,
  171.     unsigned long vaddr)
  172. {
  173. return p1275_cmd("call-method",
  174.  (P1275_ARG(0, P1275_ARG_IN_STRING) |
  175.   P1275_ARG(2, P1275_ARG_IN_64B) |
  176.   P1275_ARG(3, P1275_ARG_IN_64B) |
  177.   P1275_INOUT(5, 1)),
  178.  "SUNW,itlb-load",
  179.  prom_get_mmu_ihandle(),
  180.  /* And then our actual args are pushed backwards. */
  181.  vaddr,
  182.  tte_data,
  183.  index);
  184. }
  185. long prom_dtlb_load(unsigned long index,
  186.     unsigned long tte_data,
  187.     unsigned long vaddr)
  188. {
  189. return p1275_cmd("call-method",
  190.  (P1275_ARG(0, P1275_ARG_IN_STRING) |
  191.   P1275_ARG(2, P1275_ARG_IN_64B) |
  192.   P1275_ARG(3, P1275_ARG_IN_64B) |
  193.   P1275_INOUT(5, 1)),
  194.  "SUNW,dtlb-load",
  195.  prom_get_mmu_ihandle(),
  196.  /* And then our actual args are pushed backwards. */
  197.  vaddr,
  198.  tte_data,
  199.  index);
  200. }
  201. int prom_map(int mode, unsigned long size,
  202.      unsigned long vaddr, unsigned long paddr)
  203. {
  204. int ret = p1275_cmd("call-method",
  205.     (P1275_ARG(0, P1275_ARG_IN_STRING) |
  206.      P1275_ARG(3, P1275_ARG_IN_64B) |
  207.      P1275_ARG(4, P1275_ARG_IN_64B) |
  208.      P1275_ARG(6, P1275_ARG_IN_64B) |
  209.      P1275_INOUT(7, 1)),
  210.     "map",
  211.     prom_get_mmu_ihandle(),
  212.     mode,
  213.     size,
  214.     vaddr,
  215.     0,
  216.     paddr);
  217. if (ret == 0)
  218. ret = -1;
  219. return ret;
  220. }
  221. void prom_unmap(unsigned long size, unsigned long vaddr)
  222. {
  223. p1275_cmd("call-method",
  224.   (P1275_ARG(0, P1275_ARG_IN_STRING) |
  225.    P1275_ARG(2, P1275_ARG_IN_64B) |
  226.    P1275_ARG(3, P1275_ARG_IN_64B) |
  227.    P1275_INOUT(4, 0)),
  228.   "unmap",
  229.   prom_get_mmu_ihandle(),
  230.   size,
  231.   vaddr);
  232. }
  233. /* Set aside physical memory which is not touched or modified
  234.  * across soft resets.
  235.  */
  236. unsigned long prom_retain(char *name,
  237.   unsigned long pa_low, unsigned long pa_high,
  238.   long size, long align)
  239. {
  240. /* XXX I don't think we return multiple values correctly.
  241.  * XXX OBP supposedly returns pa_low/pa_high here, how does
  242.  * XXX it work?
  243.  */
  244. /* If align is zero, the pa_low/pa_high args are passed,
  245.  * else they are not.
  246.  */
  247. if(align == 0)
  248. return p1275_cmd("SUNW,retain",
  249.  (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(5, 2)),
  250.  name, pa_low, pa_high, size, align);
  251. else
  252. return p1275_cmd("SUNW,retain",
  253.  (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(3, 2)),
  254.  name, size, align);
  255. }
  256. /* Get "Unumber" string for the SIMM at the given
  257.  * memory address.  Usually this will be of the form
  258.  * "Uxxxx" where xxxx is a decimal number which is
  259.  * etched into the motherboard next to the SIMM slot
  260.  * in question.
  261.  */
  262. int prom_getunumber(int syndrome_code,
  263.     unsigned long phys_addr,
  264.     char *buf, int buflen)
  265. {
  266. return p1275_cmd("call-method",
  267.  (P1275_ARG(0, P1275_ARG_IN_STRING) |
  268.   P1275_ARG(3, P1275_ARG_OUT_BUF) |
  269.   P1275_ARG(6, P1275_ARG_IN_64B) |
  270.   P1275_INOUT(8, 2)),
  271.  "SUNW,get-unumber", prom_get_memory_ihandle(),
  272.  buflen, buf, P1275_SIZE(buflen),
  273.  0, phys_addr, syndrome_code);
  274. }
  275. /* Power management extensions. */
  276. void prom_sleepself(void)
  277. {
  278. p1275_cmd("SUNW,sleep-self", P1275_INOUT(0, 0));
  279. }
  280. int prom_sleepsystem(void)
  281. {
  282. return p1275_cmd("SUNW,sleep-system", P1275_INOUT(0, 1));
  283. }
  284. int prom_wakeupsystem(void)
  285. {
  286. return p1275_cmd("SUNW,wakeup-system", P1275_INOUT(0, 1));
  287. }
  288. #ifdef CONFIG_SMP
  289. void prom_startcpu(int cpunode, unsigned long pc, unsigned long o0)
  290. {
  291. p1275_cmd("SUNW,start-cpu", P1275_INOUT(3, 0), cpunode, pc, o0);
  292. }
  293. void prom_stopself(void)
  294. {
  295. p1275_cmd("SUNW,stop-self", P1275_INOUT(0, 0));
  296. }
  297. void prom_idleself(void)
  298. {
  299. p1275_cmd("SUNW,idle-self", P1275_INOUT(0, 0));
  300. }
  301. void prom_resumecpu(int cpunode)
  302. {
  303. p1275_cmd("SUNW,resume-cpu", P1275_INOUT(1, 0), cpunode);
  304. }
  305. #endif