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
5 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
6 * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
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>
18 /* Reset and reboot the machine with the command 'bcommand'. */
20 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'. */
28 prom_feval(char *fstring)
30 if(!fstring || fstring[0] == 0)
32 p1275_cmd ("interpret", P1275_ARG(0,P1275_ARG_IN_STRING)|
33 P1275_INOUT(1,1), fstring);
36 /* We want to do this more nicely some day. */
37 #ifdef CONFIG_SUN_CONSOLE
38 extern void (*prom_palette)(int);
39 extern int serial_console;
43 extern void smp_capture(void);
44 extern void smp_release(void);
47 /* Drop into the prom, with the chance to continue with the 'go'
55 __save_and_cli(flags);
57 #ifdef CONFIG_SUN_CONSOLE
58 if(!serial_console && prom_palette)
66 p1275_cmd ("enter", P1275_INOUT(0,0));
70 spin_unlock_wait(&__br_write_locks[BR_GLOBALIRQ_LOCK].lock);
73 #ifdef CONFIG_SUN_CONSOLE
74 if(!serial_console && prom_palette)
78 __restore_flags(flags);
82 extern void smp_promstop_others(void);
85 /* Drop into the prom, but completely terminate the program.
86 * No chance of continuing.
92 smp_promstop_others();
96 p1275_cmd ("exit", P1275_INOUT(0,0));
97 goto again; /* PROM is out to get me -DaveM */
101 prom_halt_power_off(void)
104 smp_promstop_others();
107 p1275_cmd ("SUNW,power-off", P1275_INOUT(0,0));
109 /* if nothing else helps, we just halt */
113 /* Set prom sync handler to call function 'funcp'. */
115 prom_setcallback(callback_func_t funcp)
118 p1275_cmd ("set-callback", P1275_ARG(0,P1275_ARG_IN_FUNCTION)|
119 P1275_INOUT(1,1), funcp);
122 /* Get the idprom and stuff it into buffer 'idbuf'. Returns the
123 * format type. 'num_bytes' is the number of bytes that your idbuf
124 * has space for. Returns 0xff on error.
127 prom_get_idprom(char *idbuf, int num_bytes)
131 len = prom_getproplen(prom_root_node, "idprom");
132 if((len>num_bytes) || (len==-1)) return 0xff;
133 if(!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes))
139 /* Get the major prom version number. */
146 /* Get the prom plugin-revision. */
153 /* Get the prom firmware print revision. */
160 /* Install Linux trap table so PROM uses that instead of it's own. */
161 void prom_set_trap_table(unsigned long tba)
163 p1275_cmd("SUNW,set-trap-table", P1275_INOUT(1, 0), tba);
166 int mmu_ihandle_cache = 0;
168 int prom_get_mmu_ihandle(void)
172 if (mmu_ihandle_cache != 0)
173 return mmu_ihandle_cache;
175 node = prom_finddevice("/chosen");
176 ret = prom_getint(node, "mmu");
177 if(ret == -1 || ret == 0)
178 mmu_ihandle_cache = -1;
180 mmu_ihandle_cache = ret;
185 static int prom_get_memory_ihandle(void)
187 static int memory_ihandle_cache;
190 if (memory_ihandle_cache != 0)
191 return memory_ihandle_cache;
193 node = prom_finddevice("/chosen");
194 ret = prom_getint(node, "memory");
195 if (ret == -1 || ret == 0)
196 memory_ihandle_cache = -1;
198 memory_ihandle_cache = ret;
203 /* Load explicit I/D TLB entries. */
204 long prom_itlb_load(unsigned long index,
205 unsigned long tte_data,
208 return p1275_cmd("call-method",
209 (P1275_ARG(0, P1275_ARG_IN_STRING) |
210 P1275_ARG(2, P1275_ARG_IN_64B) |
211 P1275_ARG(3, P1275_ARG_IN_64B) |
214 prom_get_mmu_ihandle(),
215 /* And then our actual args are pushed backwards. */
221 long prom_dtlb_load(unsigned long index,
222 unsigned long tte_data,
225 return p1275_cmd("call-method",
226 (P1275_ARG(0, P1275_ARG_IN_STRING) |
227 P1275_ARG(2, P1275_ARG_IN_64B) |
228 P1275_ARG(3, P1275_ARG_IN_64B) |
231 prom_get_mmu_ihandle(),
232 /* And then our actual args are pushed backwards. */
238 int prom_map(int mode, unsigned long size,
239 unsigned long vaddr, unsigned long paddr)
241 int ret = p1275_cmd("call-method",
242 (P1275_ARG(0, P1275_ARG_IN_STRING) |
243 P1275_ARG(3, P1275_ARG_IN_64B) |
244 P1275_ARG(4, P1275_ARG_IN_64B) |
245 P1275_ARG(6, P1275_ARG_IN_64B) |
248 prom_get_mmu_ihandle(),
260 void prom_unmap(unsigned long size, unsigned long vaddr)
262 p1275_cmd("call-method",
263 (P1275_ARG(0, P1275_ARG_IN_STRING) |
264 P1275_ARG(2, P1275_ARG_IN_64B) |
265 P1275_ARG(3, P1275_ARG_IN_64B) |
268 prom_get_mmu_ihandle(),
273 /* Set aside physical memory which is not touched or modified
274 * across soft resets.
276 unsigned long prom_retain(char *name,
277 unsigned long pa_low, unsigned long pa_high,
278 long size, long align)
280 /* XXX I don't think we return multiple values correctly.
281 * XXX OBP supposedly returns pa_low/pa_high here, how does
285 /* If align is zero, the pa_low/pa_high args are passed,
289 return p1275_cmd("SUNW,retain",
290 (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(5, 2)),
291 name, pa_low, pa_high, size, align);
293 return p1275_cmd("SUNW,retain",
294 (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(3, 2)),
298 /* Get "Unumber" string for the SIMM at the given
299 * memory address. Usually this will be of the form
300 * "Uxxxx" where xxxx is a decimal number which is
301 * etched into the motherboard next to the SIMM slot
304 int prom_getunumber(int syndrome_code,
305 unsigned long phys_addr,
306 char *buf, int buflen)
308 return p1275_cmd("call-method",
309 (P1275_ARG(0, P1275_ARG_IN_STRING) |
310 P1275_ARG(3, P1275_ARG_OUT_BUF) |
311 P1275_ARG(6, P1275_ARG_IN_64B) |
313 "SUNW,get-unumber", prom_get_memory_ihandle(),
314 buflen, buf, P1275_SIZE(buflen),
315 0, phys_addr, syndrome_code);
318 /* Power management extensions. */
319 void prom_sleepself(void)
321 p1275_cmd("SUNW,sleep-self", P1275_INOUT(0, 0));
324 int prom_sleepsystem(void)
326 return p1275_cmd("SUNW,sleep-system", P1275_INOUT(0, 1));
329 int prom_wakeupsystem(void)
331 return p1275_cmd("SUNW,wakeup-system", P1275_INOUT(0, 1));
335 void prom_startcpu(int cpunode, unsigned long pc, unsigned long o0)
337 p1275_cmd("SUNW,start-cpu", P1275_INOUT(3, 0), cpunode, pc, o0);
340 void prom_stopself(void)
342 p1275_cmd("SUNW,stop-self", P1275_INOUT(0, 0));
345 void prom_idleself(void)
347 p1275_cmd("SUNW,idle-self", P1275_INOUT(0, 0));
350 void prom_resumecpu(int cpunode)
352 p1275_cmd("SUNW,resume-cpu", P1275_INOUT(1, 0), cpunode);