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/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 #include <asm/system.h>
18 /* Reset and reboot the machine with the command 'bcommand'. */
19 void prom_reboot(const char *bcommand
)
21 p1275_cmd("boot", P1275_ARG(0, P1275_ARG_IN_STRING
) |
22 P1275_INOUT(1, 0), bcommand
);
25 /* Forth evaluate the expression contained in 'fstring'. */
26 void prom_feval(const char *fstring
)
28 if (!fstring
|| fstring
[0] == 0)
30 p1275_cmd("interpret", P1275_ARG(0, P1275_ARG_IN_STRING
) |
31 P1275_INOUT(1, 1), fstring
);
34 /* We want to do this more nicely some day. */
35 extern void (*prom_palette
)(int);
38 extern void smp_capture(void);
39 extern void smp_release(void);
42 /* Drop into the prom, with the chance to continue with the 'go'
45 void prom_cmdline(void)
49 local_irq_save(flags
);
51 if (!serial_console
&& prom_palette
)
58 p1275_cmd("enter", P1275_INOUT(0, 0));
64 if (!serial_console
&& prom_palette
)
67 local_irq_restore(flags
);
70 /* Drop into the prom, but completely terminate the program.
71 * No chance of continuing.
76 p1275_cmd("exit", P1275_INOUT(0, 0));
77 goto again
; /* PROM is out to get me -DaveM */
80 void prom_halt_power_off(void)
82 p1275_cmd("SUNW,power-off", P1275_INOUT(0, 0));
84 /* if nothing else helps, we just halt */
88 /* Set prom sync handler to call function 'funcp'. */
89 void prom_setcallback(callback_func_t funcp
)
93 p1275_cmd("set-callback", P1275_ARG(0, P1275_ARG_IN_FUNCTION
) |
94 P1275_INOUT(1, 1), funcp
);
97 /* Get the idprom and stuff it into buffer 'idbuf'. Returns the
98 * format type. 'num_bytes' is the number of bytes that your idbuf
99 * has space for. Returns 0xff on error.
101 unsigned char prom_get_idprom(char *idbuf
, int num_bytes
)
105 len
= prom_getproplen(prom_root_node
, "idprom");
106 if ((len
>num_bytes
) || (len
== -1))
108 if (!prom_getproperty(prom_root_node
, "idprom", idbuf
, num_bytes
))
114 /* Install Linux trap table so PROM uses that instead of its own. */
115 void prom_set_trap_table(unsigned long tba
)
117 p1275_cmd("SUNW,set-trap-table",
118 (P1275_ARG(0, P1275_ARG_IN_64B
) |
119 P1275_INOUT(1, 0)), tba
);
122 void prom_set_trap_table_sun4v(unsigned long tba
, unsigned long mmfsa
)
124 p1275_cmd("SUNW,set-trap-table",
125 (P1275_ARG(0, P1275_ARG_IN_64B
) |
126 P1275_ARG(1, P1275_ARG_IN_64B
) |
127 P1275_INOUT(2, 0)), tba
, mmfsa
);
130 int prom_get_mmu_ihandle(void)
134 if (prom_mmu_ihandle_cache
!= 0)
135 return prom_mmu_ihandle_cache
;
137 node
= prom_finddevice(prom_chosen_path
);
138 ret
= prom_getint(node
, prom_mmu_name
);
139 if (ret
== -1 || ret
== 0)
140 prom_mmu_ihandle_cache
= -1;
142 prom_mmu_ihandle_cache
= ret
;
147 static int prom_get_memory_ihandle(void)
149 static int memory_ihandle_cache
;
152 if (memory_ihandle_cache
!= 0)
153 return memory_ihandle_cache
;
155 node
= prom_finddevice("/chosen");
156 ret
= prom_getint(node
, "memory");
157 if (ret
== -1 || ret
== 0)
158 memory_ihandle_cache
= -1;
160 memory_ihandle_cache
= ret
;
165 /* Load explicit I/D TLB entries. */
166 long prom_itlb_load(unsigned long index
,
167 unsigned long tte_data
,
170 return p1275_cmd(prom_callmethod_name
,
171 (P1275_ARG(0, P1275_ARG_IN_STRING
) |
172 P1275_ARG(2, P1275_ARG_IN_64B
) |
173 P1275_ARG(3, P1275_ARG_IN_64B
) |
176 prom_get_mmu_ihandle(),
177 /* And then our actual args are pushed backwards. */
183 long prom_dtlb_load(unsigned long index
,
184 unsigned long tte_data
,
187 return p1275_cmd(prom_callmethod_name
,
188 (P1275_ARG(0, P1275_ARG_IN_STRING
) |
189 P1275_ARG(2, P1275_ARG_IN_64B
) |
190 P1275_ARG(3, P1275_ARG_IN_64B
) |
193 prom_get_mmu_ihandle(),
194 /* And then our actual args are pushed backwards. */
200 int prom_map(int mode
, unsigned long size
,
201 unsigned long vaddr
, unsigned long paddr
)
203 int ret
= p1275_cmd(prom_callmethod_name
,
204 (P1275_ARG(0, P1275_ARG_IN_STRING
) |
205 P1275_ARG(3, P1275_ARG_IN_64B
) |
206 P1275_ARG(4, P1275_ARG_IN_64B
) |
207 P1275_ARG(6, P1275_ARG_IN_64B
) |
210 prom_get_mmu_ihandle(),
222 void prom_unmap(unsigned long size
, unsigned long vaddr
)
224 p1275_cmd(prom_callmethod_name
,
225 (P1275_ARG(0, P1275_ARG_IN_STRING
) |
226 P1275_ARG(2, P1275_ARG_IN_64B
) |
227 P1275_ARG(3, P1275_ARG_IN_64B
) |
230 prom_get_mmu_ihandle(),
235 /* Set aside physical memory which is not touched or modified
236 * across soft resets.
238 unsigned long prom_retain(const char *name
,
239 unsigned long pa_low
, unsigned long pa_high
,
240 long size
, long align
)
242 /* XXX I don't think we return multiple values correctly.
243 * XXX OBP supposedly returns pa_low/pa_high here, how does
247 /* If align is zero, the pa_low/pa_high args are passed,
251 return p1275_cmd("SUNW,retain",
252 (P1275_ARG(0, P1275_ARG_IN_BUF
) | P1275_INOUT(5, 2)),
253 name
, pa_low
, pa_high
, size
, align
);
255 return p1275_cmd("SUNW,retain",
256 (P1275_ARG(0, P1275_ARG_IN_BUF
) | P1275_INOUT(3, 2)),
260 /* Get "Unumber" string for the SIMM at the given
261 * memory address. Usually this will be of the form
262 * "Uxxxx" where xxxx is a decimal number which is
263 * etched into the motherboard next to the SIMM slot
266 int prom_getunumber(int syndrome_code
,
267 unsigned long phys_addr
,
268 char *buf
, int buflen
)
270 return p1275_cmd(prom_callmethod_name
,
271 (P1275_ARG(0, P1275_ARG_IN_STRING
) |
272 P1275_ARG(3, P1275_ARG_OUT_BUF
) |
273 P1275_ARG(6, P1275_ARG_IN_64B
) |
275 "SUNW,get-unumber", prom_get_memory_ihandle(),
276 buflen
, buf
, P1275_SIZE(buflen
),
277 0, phys_addr
, syndrome_code
);
280 /* Power management extensions. */
281 void prom_sleepself(void)
283 p1275_cmd("SUNW,sleep-self", P1275_INOUT(0, 0));
286 int prom_sleepsystem(void)
288 return p1275_cmd("SUNW,sleep-system", P1275_INOUT(0, 1));
291 int prom_wakeupsystem(void)
293 return p1275_cmd("SUNW,wakeup-system", P1275_INOUT(0, 1));
297 void prom_startcpu(int cpunode
, unsigned long pc
, unsigned long arg
)
299 p1275_cmd("SUNW,start-cpu", P1275_INOUT(3, 0), cpunode
, pc
, arg
);
302 void prom_startcpu_cpuid(int cpuid
, unsigned long pc
, unsigned long arg
)
304 p1275_cmd("SUNW,start-cpu-by-cpuid", P1275_INOUT(3, 0),
308 void prom_stopcpu_cpuid(int cpuid
)
310 p1275_cmd("SUNW,stop-cpu-by-cpuid", P1275_INOUT(1, 0),
314 void prom_stopself(void)
316 p1275_cmd("SUNW,stop-self", P1275_INOUT(0, 0));
319 void prom_idleself(void)
321 p1275_cmd("SUNW,idle-self", P1275_INOUT(0, 0));
324 void prom_resumecpu(int cpunode
)
326 p1275_cmd("SUNW,resume-cpu", P1275_INOUT(1, 0), cpunode
);