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 <linux/module.h>
16 #include <asm/openprom.h>
17 #include <asm/oplib.h>
18 #include <asm/system.h>
21 int prom_service_exists(const char *service_name)
23 int err = p1275_cmd("test", P1275_ARG(0, P1275_ARG_IN_STRING) |
24 P1275_INOUT(1, 1), service_name);
31 void prom_sun4v_guest_soft_state(void)
33 const char *svc = "SUNW,soft-state-supported";
35 if (!prom_service_exists(svc))
37 p1275_cmd(svc, P1275_INOUT(0, 0));
40 /* Reset and reboot the machine with the command 'bcommand'. */
41 void prom_reboot(const char *bcommand)
43 #ifdef CONFIG_SUN_LDOMS
44 if (ldom_domaining_enabled)
45 ldom_reboot(bcommand);
47 p1275_cmd("boot", P1275_ARG(0, P1275_ARG_IN_STRING) |
48 P1275_INOUT(1, 0), bcommand);
51 /* Forth evaluate the expression contained in 'fstring'. */
52 void prom_feval(const char *fstring)
54 if (!fstring || fstring[0] == 0)
56 p1275_cmd("interpret", P1275_ARG(0, P1275_ARG_IN_STRING) |
57 P1275_INOUT(1, 1), fstring);
59 EXPORT_SYMBOL(prom_feval);
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);
79 p1275_cmd("enter", P1275_INOUT(0, 0));
85 local_irq_restore(flags);
88 /* Drop into the prom, but completely terminate the program.
89 * No chance of continuing.
93 #ifdef CONFIG_SUN_LDOMS
94 if (ldom_domaining_enabled)
98 p1275_cmd("exit", P1275_INOUT(0, 0));
99 goto again; /* PROM is out to get me -DaveM */
102 void prom_halt_power_off(void)
104 #ifdef CONFIG_SUN_LDOMS
105 if (ldom_domaining_enabled)
108 p1275_cmd("SUNW,power-off", P1275_INOUT(0, 0));
110 /* if nothing else helps, we just halt */
114 /* Set prom sync handler to call function 'funcp'. */
115 void prom_setcallback(callback_func_t funcp)
119 p1275_cmd("set-callback", P1275_ARG(0, P1275_ARG_IN_FUNCTION) |
120 P1275_INOUT(1, 1), funcp);
123 /* Get the idprom and stuff it into buffer 'idbuf'. Returns the
124 * format type. 'num_bytes' is the number of bytes that your idbuf
125 * has space for. Returns 0xff on error.
127 unsigned char prom_get_idprom(char *idbuf, int num_bytes)
131 len = prom_getproplen(prom_root_node, "idprom");
132 if ((len >num_bytes) || (len == -1))
134 if (!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes))
140 int prom_get_mmu_ihandle(void)
144 if (prom_mmu_ihandle_cache != 0)
145 return prom_mmu_ihandle_cache;
147 node = prom_finddevice(prom_chosen_path);
148 ret = prom_getint(node, prom_mmu_name);
149 if (ret == -1 || ret == 0)
150 prom_mmu_ihandle_cache = -1;
152 prom_mmu_ihandle_cache = ret;
157 static int prom_get_memory_ihandle(void)
159 static int memory_ihandle_cache;
162 if (memory_ihandle_cache != 0)
163 return memory_ihandle_cache;
165 node = prom_finddevice("/chosen");
166 ret = prom_getint(node, "memory");
167 if (ret == -1 || ret == 0)
168 memory_ihandle_cache = -1;
170 memory_ihandle_cache = ret;
175 /* Load explicit I/D TLB entries. */
176 long prom_itlb_load(unsigned long index,
177 unsigned long tte_data,
180 return p1275_cmd(prom_callmethod_name,
181 (P1275_ARG(0, P1275_ARG_IN_STRING) |
182 P1275_ARG(2, P1275_ARG_IN_64B) |
183 P1275_ARG(3, P1275_ARG_IN_64B) |
186 prom_get_mmu_ihandle(),
187 /* And then our actual args are pushed backwards. */
193 long prom_dtlb_load(unsigned long index,
194 unsigned long tte_data,
197 return p1275_cmd(prom_callmethod_name,
198 (P1275_ARG(0, P1275_ARG_IN_STRING) |
199 P1275_ARG(2, P1275_ARG_IN_64B) |
200 P1275_ARG(3, P1275_ARG_IN_64B) |
203 prom_get_mmu_ihandle(),
204 /* And then our actual args are pushed backwards. */
210 int prom_map(int mode, unsigned long size,
211 unsigned long vaddr, unsigned long paddr)
213 int ret = p1275_cmd(prom_callmethod_name,
214 (P1275_ARG(0, P1275_ARG_IN_STRING) |
215 P1275_ARG(3, P1275_ARG_IN_64B) |
216 P1275_ARG(4, P1275_ARG_IN_64B) |
217 P1275_ARG(6, P1275_ARG_IN_64B) |
220 prom_get_mmu_ihandle(),
232 void prom_unmap(unsigned long size, unsigned long vaddr)
234 p1275_cmd(prom_callmethod_name,
235 (P1275_ARG(0, P1275_ARG_IN_STRING) |
236 P1275_ARG(2, P1275_ARG_IN_64B) |
237 P1275_ARG(3, P1275_ARG_IN_64B) |
240 prom_get_mmu_ihandle(),
245 /* Set aside physical memory which is not touched or modified
246 * across soft resets.
248 unsigned long prom_retain(const char *name,
249 unsigned long pa_low, unsigned long pa_high,
250 long size, long align)
252 /* XXX I don't think we return multiple values correctly.
253 * XXX OBP supposedly returns pa_low/pa_high here, how does
257 /* If align is zero, the pa_low/pa_high args are passed,
261 return p1275_cmd("SUNW,retain",
262 (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(5, 2)),
263 name, pa_low, pa_high, size, align);
265 return p1275_cmd("SUNW,retain",
266 (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(3, 2)),
270 /* Get "Unumber" string for the SIMM at the given
271 * memory address. Usually this will be of the form
272 * "Uxxxx" where xxxx is a decimal number which is
273 * etched into the motherboard next to the SIMM slot
276 int prom_getunumber(int syndrome_code,
277 unsigned long phys_addr,
278 char *buf, int buflen)
280 return p1275_cmd(prom_callmethod_name,
281 (P1275_ARG(0, P1275_ARG_IN_STRING) |
282 P1275_ARG(3, P1275_ARG_OUT_BUF) |
283 P1275_ARG(6, P1275_ARG_IN_64B) |
285 "SUNW,get-unumber", prom_get_memory_ihandle(),
286 buflen, buf, P1275_SIZE(buflen),
287 0, phys_addr, syndrome_code);
290 /* Power management extensions. */
291 void prom_sleepself(void)
293 p1275_cmd("SUNW,sleep-self", P1275_INOUT(0, 0));
296 int prom_sleepsystem(void)
298 return p1275_cmd("SUNW,sleep-system", P1275_INOUT(0, 1));
301 int prom_wakeupsystem(void)
303 return p1275_cmd("SUNW,wakeup-system", P1275_INOUT(0, 1));
307 void prom_startcpu(int cpunode, unsigned long pc, unsigned long arg)
309 p1275_cmd("SUNW,start-cpu", P1275_INOUT(3, 0), cpunode, pc, arg);
312 void prom_startcpu_cpuid(int cpuid, unsigned long pc, unsigned long arg)
314 p1275_cmd("SUNW,start-cpu-by-cpuid", P1275_INOUT(3, 0),
318 void prom_stopcpu_cpuid(int cpuid)
320 p1275_cmd("SUNW,stop-cpu-by-cpuid", P1275_INOUT(1, 0),
324 void prom_stopself(void)
326 p1275_cmd("SUNW,stop-self", P1275_INOUT(0, 0));
329 void prom_idleself(void)
331 p1275_cmd("SUNW,idle-self", P1275_INOUT(0, 0));
334 void prom_resumecpu(int cpunode)
336 p1275_cmd("SUNW,resume-cpu", P1275_INOUT(1, 0), cpunode);