Linux-2.6.12-rc2
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / sparc64 / prom / misc.c
blob19c44e97e9eef88def0a838c4c1fd3f2991dda9b
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.
5 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
6 * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
7 */
9 #include <linux/config.h>
10 #include <linux/types.h>
11 #include <linux/kernel.h>
12 #include <linux/sched.h>
13 #include <linux/interrupt.h>
14 #include <linux/delay.h>
15 #include <asm/openprom.h>
16 #include <asm/oplib.h>
17 #include <asm/system.h>
19 /* Reset and reboot the machine with the command 'bcommand'. */
20 void prom_reboot(char *bcommand)
22 p1275_cmd("boot", P1275_ARG(0, P1275_ARG_IN_STRING) |
23 P1275_INOUT(1, 0), bcommand);
26 /* Forth evaluate the expression contained in 'fstring'. */
27 void prom_feval(char *fstring)
29 if (!fstring || fstring[0] == 0)
30 return;
31 p1275_cmd("interpret", P1275_ARG(0, P1275_ARG_IN_STRING) |
32 P1275_INOUT(1, 1), fstring);
35 /* We want to do this more nicely some day. */
36 extern void (*prom_palette)(int);
38 #ifdef CONFIG_SMP
39 extern void smp_capture(void);
40 extern void smp_release(void);
41 #endif
43 /* Drop into the prom, with the chance to continue with the 'go'
44 * prom command.
46 void prom_cmdline(void)
48 unsigned long flags;
50 local_irq_save(flags);
52 if (!serial_console && prom_palette)
53 prom_palette(1);
55 #ifdef CONFIG_SMP
56 smp_capture();
57 #endif
59 p1275_cmd("enter", P1275_INOUT(0, 0));
61 #ifdef CONFIG_SMP
62 smp_release();
63 #endif
65 if (!serial_console && prom_palette)
66 prom_palette(0);
68 local_irq_restore(flags);
71 #ifdef CONFIG_SMP
72 extern void smp_promstop_others(void);
73 #endif
75 /* Drop into the prom, but completely terminate the program.
76 * No chance of continuing.
78 void prom_halt(void)
80 #ifdef CONFIG_SMP
81 smp_promstop_others();
82 udelay(8000);
83 #endif
84 again:
85 p1275_cmd("exit", P1275_INOUT(0, 0));
86 goto again; /* PROM is out to get me -DaveM */
89 void prom_halt_power_off(void)
91 #ifdef CONFIG_SMP
92 smp_promstop_others();
93 udelay(8000);
94 #endif
95 p1275_cmd("SUNW,power-off", P1275_INOUT(0, 0));
97 /* if nothing else helps, we just halt */
98 prom_halt();
101 /* Set prom sync handler to call function 'funcp'. */
102 void prom_setcallback(callback_func_t funcp)
104 if (!funcp)
105 return;
106 p1275_cmd("set-callback", P1275_ARG(0, P1275_ARG_IN_FUNCTION) |
107 P1275_INOUT(1, 1), funcp);
110 /* Get the idprom and stuff it into buffer 'idbuf'. Returns the
111 * format type. 'num_bytes' is the number of bytes that your idbuf
112 * has space for. Returns 0xff on error.
114 unsigned char prom_get_idprom(char *idbuf, int num_bytes)
116 int len;
118 len = prom_getproplen(prom_root_node, "idprom");
119 if ((len >num_bytes) || (len == -1))
120 return 0xff;
121 if (!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes))
122 return idbuf[0];
124 return 0xff;
127 /* Get the major prom version number. */
128 int prom_version(void)
130 return PROM_P1275;
133 /* Get the prom plugin-revision. */
134 int prom_getrev(void)
136 return prom_rev;
139 /* Get the prom firmware print revision. */
140 int prom_getprev(void)
142 return prom_prev;
145 /* Install Linux trap table so PROM uses that instead of its own. */
146 void prom_set_trap_table(unsigned long tba)
148 p1275_cmd("SUNW,set-trap-table", P1275_INOUT(1, 0), tba);
151 int mmu_ihandle_cache = 0;
153 int prom_get_mmu_ihandle(void)
155 int node, ret;
157 if (mmu_ihandle_cache != 0)
158 return mmu_ihandle_cache;
160 node = prom_finddevice("/chosen");
161 ret = prom_getint(node, "mmu");
162 if (ret == -1 || ret == 0)
163 mmu_ihandle_cache = -1;
164 else
165 mmu_ihandle_cache = ret;
167 return ret;
170 static int prom_get_memory_ihandle(void)
172 static int memory_ihandle_cache;
173 int node, ret;
175 if (memory_ihandle_cache != 0)
176 return memory_ihandle_cache;
178 node = prom_finddevice("/chosen");
179 ret = prom_getint(node, "memory");
180 if (ret == -1 || ret == 0)
181 memory_ihandle_cache = -1;
182 else
183 memory_ihandle_cache = ret;
185 return ret;
188 /* Load explicit I/D TLB entries. */
189 long prom_itlb_load(unsigned long index,
190 unsigned long tte_data,
191 unsigned long vaddr)
193 return p1275_cmd("call-method",
194 (P1275_ARG(0, P1275_ARG_IN_STRING) |
195 P1275_ARG(2, P1275_ARG_IN_64B) |
196 P1275_ARG(3, P1275_ARG_IN_64B) |
197 P1275_INOUT(5, 1)),
198 "SUNW,itlb-load",
199 prom_get_mmu_ihandle(),
200 /* And then our actual args are pushed backwards. */
201 vaddr,
202 tte_data,
203 index);
206 long prom_dtlb_load(unsigned long index,
207 unsigned long tte_data,
208 unsigned long vaddr)
210 return p1275_cmd("call-method",
211 (P1275_ARG(0, P1275_ARG_IN_STRING) |
212 P1275_ARG(2, P1275_ARG_IN_64B) |
213 P1275_ARG(3, P1275_ARG_IN_64B) |
214 P1275_INOUT(5, 1)),
215 "SUNW,dtlb-load",
216 prom_get_mmu_ihandle(),
217 /* And then our actual args are pushed backwards. */
218 vaddr,
219 tte_data,
220 index);
223 int prom_map(int mode, unsigned long size,
224 unsigned long vaddr, unsigned long paddr)
226 int ret = p1275_cmd("call-method",
227 (P1275_ARG(0, P1275_ARG_IN_STRING) |
228 P1275_ARG(3, P1275_ARG_IN_64B) |
229 P1275_ARG(4, P1275_ARG_IN_64B) |
230 P1275_ARG(6, P1275_ARG_IN_64B) |
231 P1275_INOUT(7, 1)),
232 "map",
233 prom_get_mmu_ihandle(),
234 mode,
235 size,
236 vaddr,
238 paddr);
240 if (ret == 0)
241 ret = -1;
242 return ret;
245 void prom_unmap(unsigned long size, unsigned long vaddr)
247 p1275_cmd("call-method",
248 (P1275_ARG(0, P1275_ARG_IN_STRING) |
249 P1275_ARG(2, P1275_ARG_IN_64B) |
250 P1275_ARG(3, P1275_ARG_IN_64B) |
251 P1275_INOUT(4, 0)),
252 "unmap",
253 prom_get_mmu_ihandle(),
254 size,
255 vaddr);
258 /* Set aside physical memory which is not touched or modified
259 * across soft resets.
261 unsigned long prom_retain(char *name,
262 unsigned long pa_low, unsigned long pa_high,
263 long size, long align)
265 /* XXX I don't think we return multiple values correctly.
266 * XXX OBP supposedly returns pa_low/pa_high here, how does
267 * XXX it work?
270 /* If align is zero, the pa_low/pa_high args are passed,
271 * else they are not.
273 if (align == 0)
274 return p1275_cmd("SUNW,retain",
275 (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(5, 2)),
276 name, pa_low, pa_high, size, align);
277 else
278 return p1275_cmd("SUNW,retain",
279 (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(3, 2)),
280 name, size, align);
283 /* Get "Unumber" string for the SIMM at the given
284 * memory address. Usually this will be of the form
285 * "Uxxxx" where xxxx is a decimal number which is
286 * etched into the motherboard next to the SIMM slot
287 * in question.
289 int prom_getunumber(int syndrome_code,
290 unsigned long phys_addr,
291 char *buf, int buflen)
293 return p1275_cmd("call-method",
294 (P1275_ARG(0, P1275_ARG_IN_STRING) |
295 P1275_ARG(3, P1275_ARG_OUT_BUF) |
296 P1275_ARG(6, P1275_ARG_IN_64B) |
297 P1275_INOUT(8, 2)),
298 "SUNW,get-unumber", prom_get_memory_ihandle(),
299 buflen, buf, P1275_SIZE(buflen),
300 0, phys_addr, syndrome_code);
303 /* Power management extensions. */
304 void prom_sleepself(void)
306 p1275_cmd("SUNW,sleep-self", P1275_INOUT(0, 0));
309 int prom_sleepsystem(void)
311 return p1275_cmd("SUNW,sleep-system", P1275_INOUT(0, 1));
314 int prom_wakeupsystem(void)
316 return p1275_cmd("SUNW,wakeup-system", P1275_INOUT(0, 1));
319 #ifdef CONFIG_SMP
320 void prom_startcpu(int cpunode, unsigned long pc, unsigned long o0)
322 p1275_cmd("SUNW,start-cpu", P1275_INOUT(3, 0), cpunode, pc, o0);
325 void prom_stopself(void)
327 p1275_cmd("SUNW,stop-self", P1275_INOUT(0, 0));
330 void prom_idleself(void)
332 p1275_cmd("SUNW,idle-self", P1275_INOUT(0, 0));
335 void prom_resumecpu(int cpunode)
337 p1275_cmd("SUNW,resume-cpu", P1275_INOUT(1, 0), cpunode);
339 #endif