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
);
82 p1275_cmd("enter", P1275_INOUT(0, 0));
91 local_irq_restore(flags
);
94 /* Drop into the prom, but completely terminate the program.
95 * No chance of continuing.
99 #ifdef CONFIG_SUN_LDOMS
100 if (ldom_domaining_enabled
)
104 p1275_cmd("exit", P1275_INOUT(0, 0));
105 goto again
; /* PROM is out to get me -DaveM */
108 void prom_halt_power_off(void)
110 #ifdef CONFIG_SUN_LDOMS
111 if (ldom_domaining_enabled
)
114 p1275_cmd("SUNW,power-off", P1275_INOUT(0, 0));
116 /* if nothing else helps, we just halt */
120 /* Set prom sync handler to call function 'funcp'. */
121 void prom_setcallback(callback_func_t funcp
)
125 p1275_cmd("set-callback", P1275_ARG(0, P1275_ARG_IN_FUNCTION
) |
126 P1275_INOUT(1, 1), funcp
);
129 /* Get the idprom and stuff it into buffer 'idbuf'. Returns the
130 * format type. 'num_bytes' is the number of bytes that your idbuf
131 * has space for. Returns 0xff on error.
133 unsigned char prom_get_idprom(char *idbuf
, int num_bytes
)
137 len
= prom_getproplen(prom_root_node
, "idprom");
138 if ((len
>num_bytes
) || (len
== -1))
140 if (!prom_getproperty(prom_root_node
, "idprom", idbuf
, num_bytes
))
146 int prom_get_mmu_ihandle(void)
150 if (prom_mmu_ihandle_cache
!= 0)
151 return prom_mmu_ihandle_cache
;
153 node
= prom_finddevice(prom_chosen_path
);
154 ret
= prom_getint(node
, prom_mmu_name
);
155 if (ret
== -1 || ret
== 0)
156 prom_mmu_ihandle_cache
= -1;
158 prom_mmu_ihandle_cache
= ret
;
163 static int prom_get_memory_ihandle(void)
165 static int memory_ihandle_cache
;
168 if (memory_ihandle_cache
!= 0)
169 return memory_ihandle_cache
;
171 node
= prom_finddevice("/chosen");
172 ret
= prom_getint(node
, "memory");
173 if (ret
== -1 || ret
== 0)
174 memory_ihandle_cache
= -1;
176 memory_ihandle_cache
= ret
;
181 /* Load explicit I/D TLB entries. */
182 long prom_itlb_load(unsigned long index
,
183 unsigned long tte_data
,
186 return p1275_cmd(prom_callmethod_name
,
187 (P1275_ARG(0, P1275_ARG_IN_STRING
) |
188 P1275_ARG(2, P1275_ARG_IN_64B
) |
189 P1275_ARG(3, P1275_ARG_IN_64B
) |
192 prom_get_mmu_ihandle(),
193 /* And then our actual args are pushed backwards. */
199 long prom_dtlb_load(unsigned long index
,
200 unsigned long tte_data
,
203 return p1275_cmd(prom_callmethod_name
,
204 (P1275_ARG(0, P1275_ARG_IN_STRING
) |
205 P1275_ARG(2, P1275_ARG_IN_64B
) |
206 P1275_ARG(3, P1275_ARG_IN_64B
) |
209 prom_get_mmu_ihandle(),
210 /* And then our actual args are pushed backwards. */
216 int prom_map(int mode
, unsigned long size
,
217 unsigned long vaddr
, unsigned long paddr
)
219 int ret
= p1275_cmd(prom_callmethod_name
,
220 (P1275_ARG(0, P1275_ARG_IN_STRING
) |
221 P1275_ARG(3, P1275_ARG_IN_64B
) |
222 P1275_ARG(4, P1275_ARG_IN_64B
) |
223 P1275_ARG(6, P1275_ARG_IN_64B
) |
226 prom_get_mmu_ihandle(),
238 void prom_unmap(unsigned long size
, unsigned long vaddr
)
240 p1275_cmd(prom_callmethod_name
,
241 (P1275_ARG(0, P1275_ARG_IN_STRING
) |
242 P1275_ARG(2, P1275_ARG_IN_64B
) |
243 P1275_ARG(3, P1275_ARG_IN_64B
) |
246 prom_get_mmu_ihandle(),
251 /* Set aside physical memory which is not touched or modified
252 * across soft resets.
254 unsigned long prom_retain(const char *name
,
255 unsigned long pa_low
, unsigned long pa_high
,
256 long size
, long align
)
258 /* XXX I don't think we return multiple values correctly.
259 * XXX OBP supposedly returns pa_low/pa_high here, how does
263 /* If align is zero, the pa_low/pa_high args are passed,
267 return p1275_cmd("SUNW,retain",
268 (P1275_ARG(0, P1275_ARG_IN_BUF
) | P1275_INOUT(5, 2)),
269 name
, pa_low
, pa_high
, size
, align
);
271 return p1275_cmd("SUNW,retain",
272 (P1275_ARG(0, P1275_ARG_IN_BUF
) | P1275_INOUT(3, 2)),
276 /* Get "Unumber" string for the SIMM at the given
277 * memory address. Usually this will be of the form
278 * "Uxxxx" where xxxx is a decimal number which is
279 * etched into the motherboard next to the SIMM slot
282 int prom_getunumber(int syndrome_code
,
283 unsigned long phys_addr
,
284 char *buf
, int buflen
)
286 return p1275_cmd(prom_callmethod_name
,
287 (P1275_ARG(0, P1275_ARG_IN_STRING
) |
288 P1275_ARG(3, P1275_ARG_OUT_BUF
) |
289 P1275_ARG(6, P1275_ARG_IN_64B
) |
291 "SUNW,get-unumber", prom_get_memory_ihandle(),
292 buflen
, buf
, P1275_SIZE(buflen
),
293 0, phys_addr
, syndrome_code
);
296 /* Power management extensions. */
297 void prom_sleepself(void)
299 p1275_cmd("SUNW,sleep-self", P1275_INOUT(0, 0));
302 int prom_sleepsystem(void)
304 return p1275_cmd("SUNW,sleep-system", P1275_INOUT(0, 1));
307 int prom_wakeupsystem(void)
309 return p1275_cmd("SUNW,wakeup-system", P1275_INOUT(0, 1));
313 void prom_startcpu(int cpunode
, unsigned long pc
, unsigned long arg
)
315 p1275_cmd("SUNW,start-cpu", P1275_INOUT(3, 0), cpunode
, pc
, arg
);
318 void prom_startcpu_cpuid(int cpuid
, unsigned long pc
, unsigned long arg
)
320 p1275_cmd("SUNW,start-cpu-by-cpuid", P1275_INOUT(3, 0),
324 void prom_stopcpu_cpuid(int cpuid
)
326 p1275_cmd("SUNW,stop-cpu-by-cpuid", P1275_INOUT(1, 0),
330 void prom_stopself(void)
332 p1275_cmd("SUNW,stop-self", P1275_INOUT(0, 0));
335 void prom_idleself(void)
337 p1275_cmd("SUNW,idle-self", P1275_INOUT(0, 0));
340 void prom_resumecpu(int cpunode
)
342 p1275_cmd("SUNW,resume-cpu", P1275_INOUT(1, 0), cpunode
);