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>
19 int prom_service_exists(const char *service_name
)
21 int err
= p1275_cmd("test", P1275_ARG(0, P1275_ARG_IN_STRING
) |
22 P1275_INOUT(1, 1), service_name
);
29 void prom_sun4v_guest_soft_state(void)
31 const char *svc
= "SUNW,soft-state-supported";
33 if (!prom_service_exists(svc
))
35 p1275_cmd(svc
, P1275_INOUT(0, 0));
38 /* Reset and reboot the machine with the command 'bcommand'. */
39 void prom_reboot(const char *bcommand
)
41 #ifdef CONFIG_SUN_LDOMS
42 if (ldom_domaining_enabled
)
43 ldom_reboot(bcommand
);
45 p1275_cmd("boot", P1275_ARG(0, P1275_ARG_IN_STRING
) |
46 P1275_INOUT(1, 0), bcommand
);
49 /* Forth evaluate the expression contained in 'fstring'. */
50 void prom_feval(const char *fstring
)
52 if (!fstring
|| fstring
[0] == 0)
54 p1275_cmd("interpret", P1275_ARG(0, P1275_ARG_IN_STRING
) |
55 P1275_INOUT(1, 1), fstring
);
58 /* We want to do this more nicely some day. */
59 extern void (*prom_palette
)(int);
62 extern void smp_capture(void);
63 extern void smp_release(void);
66 /* Drop into the prom, with the chance to continue with the 'go'
69 void prom_cmdline(void)
73 local_irq_save(flags
);
75 if (!serial_console
&& prom_palette
)
82 p1275_cmd("enter", P1275_INOUT(0, 0));
88 if (!serial_console
&& prom_palette
)
91 local_irq_restore(flags
);
94 /* Drop into the prom, but completely terminate the program.
95 * No chance of continuing.
100 p1275_cmd("exit", P1275_INOUT(0, 0));
101 goto again
; /* PROM is out to get me -DaveM */
104 void prom_halt_power_off(void)
106 p1275_cmd("SUNW,power-off", P1275_INOUT(0, 0));
108 /* if nothing else helps, we just halt */
112 /* Set prom sync handler to call function 'funcp'. */
113 void prom_setcallback(callback_func_t funcp
)
117 p1275_cmd("set-callback", P1275_ARG(0, P1275_ARG_IN_FUNCTION
) |
118 P1275_INOUT(1, 1), funcp
);
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.
125 unsigned char prom_get_idprom(char *idbuf
, int num_bytes
)
129 len
= prom_getproplen(prom_root_node
, "idprom");
130 if ((len
>num_bytes
) || (len
== -1))
132 if (!prom_getproperty(prom_root_node
, "idprom", idbuf
, num_bytes
))
138 /* Install Linux trap table so PROM uses that instead of its own. */
139 void prom_set_trap_table(unsigned long tba
)
141 p1275_cmd("SUNW,set-trap-table",
142 (P1275_ARG(0, P1275_ARG_IN_64B
) |
143 P1275_INOUT(1, 0)), tba
);
146 void prom_set_trap_table_sun4v(unsigned long tba
, unsigned long mmfsa
)
148 p1275_cmd("SUNW,set-trap-table",
149 (P1275_ARG(0, P1275_ARG_IN_64B
) |
150 P1275_ARG(1, P1275_ARG_IN_64B
) |
151 P1275_INOUT(2, 0)), tba
, mmfsa
);
154 int prom_get_mmu_ihandle(void)
158 if (prom_mmu_ihandle_cache
!= 0)
159 return prom_mmu_ihandle_cache
;
161 node
= prom_finddevice(prom_chosen_path
);
162 ret
= prom_getint(node
, prom_mmu_name
);
163 if (ret
== -1 || ret
== 0)
164 prom_mmu_ihandle_cache
= -1;
166 prom_mmu_ihandle_cache
= ret
;
171 static int prom_get_memory_ihandle(void)
173 static int memory_ihandle_cache
;
176 if (memory_ihandle_cache
!= 0)
177 return memory_ihandle_cache
;
179 node
= prom_finddevice("/chosen");
180 ret
= prom_getint(node
, "memory");
181 if (ret
== -1 || ret
== 0)
182 memory_ihandle_cache
= -1;
184 memory_ihandle_cache
= ret
;
189 /* Load explicit I/D TLB entries. */
190 long prom_itlb_load(unsigned long index
,
191 unsigned long tte_data
,
194 return p1275_cmd(prom_callmethod_name
,
195 (P1275_ARG(0, P1275_ARG_IN_STRING
) |
196 P1275_ARG(2, P1275_ARG_IN_64B
) |
197 P1275_ARG(3, P1275_ARG_IN_64B
) |
200 prom_get_mmu_ihandle(),
201 /* And then our actual args are pushed backwards. */
207 long prom_dtlb_load(unsigned long index
,
208 unsigned long tte_data
,
211 return p1275_cmd(prom_callmethod_name
,
212 (P1275_ARG(0, P1275_ARG_IN_STRING
) |
213 P1275_ARG(2, P1275_ARG_IN_64B
) |
214 P1275_ARG(3, P1275_ARG_IN_64B
) |
217 prom_get_mmu_ihandle(),
218 /* And then our actual args are pushed backwards. */
224 int prom_map(int mode
, unsigned long size
,
225 unsigned long vaddr
, unsigned long paddr
)
227 int ret
= p1275_cmd(prom_callmethod_name
,
228 (P1275_ARG(0, P1275_ARG_IN_STRING
) |
229 P1275_ARG(3, P1275_ARG_IN_64B
) |
230 P1275_ARG(4, P1275_ARG_IN_64B
) |
231 P1275_ARG(6, P1275_ARG_IN_64B
) |
234 prom_get_mmu_ihandle(),
246 void prom_unmap(unsigned long size
, unsigned long vaddr
)
248 p1275_cmd(prom_callmethod_name
,
249 (P1275_ARG(0, P1275_ARG_IN_STRING
) |
250 P1275_ARG(2, P1275_ARG_IN_64B
) |
251 P1275_ARG(3, P1275_ARG_IN_64B
) |
254 prom_get_mmu_ihandle(),
259 /* Set aside physical memory which is not touched or modified
260 * across soft resets.
262 unsigned long prom_retain(const char *name
,
263 unsigned long pa_low
, unsigned long pa_high
,
264 long size
, long align
)
266 /* XXX I don't think we return multiple values correctly.
267 * XXX OBP supposedly returns pa_low/pa_high here, how does
271 /* If align is zero, the pa_low/pa_high args are passed,
275 return p1275_cmd("SUNW,retain",
276 (P1275_ARG(0, P1275_ARG_IN_BUF
) | P1275_INOUT(5, 2)),
277 name
, pa_low
, pa_high
, size
, align
);
279 return p1275_cmd("SUNW,retain",
280 (P1275_ARG(0, P1275_ARG_IN_BUF
) | P1275_INOUT(3, 2)),
284 /* Get "Unumber" string for the SIMM at the given
285 * memory address. Usually this will be of the form
286 * "Uxxxx" where xxxx is a decimal number which is
287 * etched into the motherboard next to the SIMM slot
290 int prom_getunumber(int syndrome_code
,
291 unsigned long phys_addr
,
292 char *buf
, int buflen
)
294 return p1275_cmd(prom_callmethod_name
,
295 (P1275_ARG(0, P1275_ARG_IN_STRING
) |
296 P1275_ARG(3, P1275_ARG_OUT_BUF
) |
297 P1275_ARG(6, P1275_ARG_IN_64B
) |
299 "SUNW,get-unumber", prom_get_memory_ihandle(),
300 buflen
, buf
, P1275_SIZE(buflen
),
301 0, phys_addr
, syndrome_code
);
304 /* Power management extensions. */
305 void prom_sleepself(void)
307 p1275_cmd("SUNW,sleep-self", P1275_INOUT(0, 0));
310 int prom_sleepsystem(void)
312 return p1275_cmd("SUNW,sleep-system", P1275_INOUT(0, 1));
315 int prom_wakeupsystem(void)
317 return p1275_cmd("SUNW,wakeup-system", P1275_INOUT(0, 1));
321 void prom_startcpu(int cpunode
, unsigned long pc
, unsigned long arg
)
323 p1275_cmd("SUNW,start-cpu", P1275_INOUT(3, 0), cpunode
, pc
, arg
);
326 void prom_startcpu_cpuid(int cpuid
, unsigned long pc
, unsigned long arg
)
328 p1275_cmd("SUNW,start-cpu-by-cpuid", P1275_INOUT(3, 0),
332 void prom_stopcpu_cpuid(int cpuid
)
334 p1275_cmd("SUNW,stop-cpu-by-cpuid", P1275_INOUT(1, 0),
338 void prom_stopself(void)
340 p1275_cmd("SUNW,stop-self", P1275_INOUT(0, 0));
343 void prom_idleself(void)
345 p1275_cmd("SUNW,idle-self", P1275_INOUT(0, 0));
348 void prom_resumecpu(int cpunode
)
350 p1275_cmd("SUNW,resume-cpu", P1275_INOUT(1, 0), cpunode
);