Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / arch / sparc64 / prom / misc.c
blob97aefd931834bd4b134545d976ba4396dc07c2a9
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
3 * anywhere else.
5 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
6 * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
7 */
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>
17 #include <asm/ldc.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);
24 if (err)
25 return 0;
26 return 1;
29 void prom_sun4v_guest_soft_state(void)
31 const char *svc = "SUNW,soft-state-supported";
33 if (!prom_service_exists(svc))
34 return;
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);
44 #endif
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)
53 return;
54 p1275_cmd("interpret", P1275_ARG(0, P1275_ARG_IN_STRING) |
55 P1275_INOUT(1, 1), fstring);
58 <<<<<<< HEAD:arch/sparc64/prom/misc.c
59 /* We want to do this more nicely some day. */
60 extern void (*prom_palette)(int);
62 =======
63 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/sparc64/prom/misc.c
64 #ifdef CONFIG_SMP
65 extern void smp_capture(void);
66 extern void smp_release(void);
67 #endif
69 /* Drop into the prom, with the chance to continue with the 'go'
70 * prom command.
72 void prom_cmdline(void)
74 unsigned long flags;
76 local_irq_save(flags);
78 <<<<<<< HEAD:arch/sparc64/prom/misc.c
79 if (prom_palette)
80 prom_palette(1);
82 =======
83 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/sparc64/prom/misc.c
84 #ifdef CONFIG_SMP
85 smp_capture();
86 #endif
88 p1275_cmd("enter", P1275_INOUT(0, 0));
90 #ifdef CONFIG_SMP
91 smp_release();
92 #endif
94 <<<<<<< HEAD:arch/sparc64/prom/misc.c
95 if (prom_palette)
96 prom_palette(0);
98 =======
99 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/sparc64/prom/misc.c
100 local_irq_restore(flags);
103 /* Drop into the prom, but completely terminate the program.
104 * No chance of continuing.
106 void prom_halt(void)
108 #ifdef CONFIG_SUN_LDOMS
109 if (ldom_domaining_enabled)
110 ldom_power_off();
111 #endif
112 again:
113 p1275_cmd("exit", P1275_INOUT(0, 0));
114 goto again; /* PROM is out to get me -DaveM */
117 void prom_halt_power_off(void)
119 #ifdef CONFIG_SUN_LDOMS
120 if (ldom_domaining_enabled)
121 ldom_power_off();
122 #endif
123 p1275_cmd("SUNW,power-off", P1275_INOUT(0, 0));
125 /* if nothing else helps, we just halt */
126 prom_halt();
129 /* Set prom sync handler to call function 'funcp'. */
130 void prom_setcallback(callback_func_t funcp)
132 if (!funcp)
133 return;
134 p1275_cmd("set-callback", P1275_ARG(0, P1275_ARG_IN_FUNCTION) |
135 P1275_INOUT(1, 1), funcp);
138 /* Get the idprom and stuff it into buffer 'idbuf'. Returns the
139 * format type. 'num_bytes' is the number of bytes that your idbuf
140 * has space for. Returns 0xff on error.
142 unsigned char prom_get_idprom(char *idbuf, int num_bytes)
144 int len;
146 len = prom_getproplen(prom_root_node, "idprom");
147 if ((len >num_bytes) || (len == -1))
148 return 0xff;
149 if (!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes))
150 return idbuf[0];
152 return 0xff;
155 int prom_get_mmu_ihandle(void)
157 int node, ret;
159 if (prom_mmu_ihandle_cache != 0)
160 return prom_mmu_ihandle_cache;
162 node = prom_finddevice(prom_chosen_path);
163 ret = prom_getint(node, prom_mmu_name);
164 if (ret == -1 || ret == 0)
165 prom_mmu_ihandle_cache = -1;
166 else
167 prom_mmu_ihandle_cache = ret;
169 return ret;
172 static int prom_get_memory_ihandle(void)
174 static int memory_ihandle_cache;
175 int node, ret;
177 if (memory_ihandle_cache != 0)
178 return memory_ihandle_cache;
180 node = prom_finddevice("/chosen");
181 ret = prom_getint(node, "memory");
182 if (ret == -1 || ret == 0)
183 memory_ihandle_cache = -1;
184 else
185 memory_ihandle_cache = ret;
187 return ret;
190 /* Load explicit I/D TLB entries. */
191 long prom_itlb_load(unsigned long index,
192 unsigned long tte_data,
193 unsigned long vaddr)
195 return p1275_cmd(prom_callmethod_name,
196 (P1275_ARG(0, P1275_ARG_IN_STRING) |
197 P1275_ARG(2, P1275_ARG_IN_64B) |
198 P1275_ARG(3, P1275_ARG_IN_64B) |
199 P1275_INOUT(5, 1)),
200 "SUNW,itlb-load",
201 prom_get_mmu_ihandle(),
202 /* And then our actual args are pushed backwards. */
203 vaddr,
204 tte_data,
205 index);
208 long prom_dtlb_load(unsigned long index,
209 unsigned long tte_data,
210 unsigned long vaddr)
212 return p1275_cmd(prom_callmethod_name,
213 (P1275_ARG(0, P1275_ARG_IN_STRING) |
214 P1275_ARG(2, P1275_ARG_IN_64B) |
215 P1275_ARG(3, P1275_ARG_IN_64B) |
216 P1275_INOUT(5, 1)),
217 "SUNW,dtlb-load",
218 prom_get_mmu_ihandle(),
219 /* And then our actual args are pushed backwards. */
220 vaddr,
221 tte_data,
222 index);
225 int prom_map(int mode, unsigned long size,
226 unsigned long vaddr, unsigned long paddr)
228 int ret = p1275_cmd(prom_callmethod_name,
229 (P1275_ARG(0, P1275_ARG_IN_STRING) |
230 P1275_ARG(3, P1275_ARG_IN_64B) |
231 P1275_ARG(4, P1275_ARG_IN_64B) |
232 P1275_ARG(6, P1275_ARG_IN_64B) |
233 P1275_INOUT(7, 1)),
234 prom_map_name,
235 prom_get_mmu_ihandle(),
236 mode,
237 size,
238 vaddr,
240 paddr);
242 if (ret == 0)
243 ret = -1;
244 return ret;
247 void prom_unmap(unsigned long size, unsigned long vaddr)
249 p1275_cmd(prom_callmethod_name,
250 (P1275_ARG(0, P1275_ARG_IN_STRING) |
251 P1275_ARG(2, P1275_ARG_IN_64B) |
252 P1275_ARG(3, P1275_ARG_IN_64B) |
253 P1275_INOUT(4, 0)),
254 prom_unmap_name,
255 prom_get_mmu_ihandle(),
256 size,
257 vaddr);
260 /* Set aside physical memory which is not touched or modified
261 * across soft resets.
263 unsigned long prom_retain(const char *name,
264 unsigned long pa_low, unsigned long pa_high,
265 long size, long align)
267 /* XXX I don't think we return multiple values correctly.
268 * XXX OBP supposedly returns pa_low/pa_high here, how does
269 * XXX it work?
272 /* If align is zero, the pa_low/pa_high args are passed,
273 * else they are not.
275 if (align == 0)
276 return p1275_cmd("SUNW,retain",
277 (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(5, 2)),
278 name, pa_low, pa_high, size, align);
279 else
280 return p1275_cmd("SUNW,retain",
281 (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(3, 2)),
282 name, size, align);
285 /* Get "Unumber" string for the SIMM at the given
286 * memory address. Usually this will be of the form
287 * "Uxxxx" where xxxx is a decimal number which is
288 * etched into the motherboard next to the SIMM slot
289 * in question.
291 int prom_getunumber(int syndrome_code,
292 unsigned long phys_addr,
293 char *buf, int buflen)
295 return p1275_cmd(prom_callmethod_name,
296 (P1275_ARG(0, P1275_ARG_IN_STRING) |
297 P1275_ARG(3, P1275_ARG_OUT_BUF) |
298 P1275_ARG(6, P1275_ARG_IN_64B) |
299 P1275_INOUT(8, 2)),
300 "SUNW,get-unumber", prom_get_memory_ihandle(),
301 buflen, buf, P1275_SIZE(buflen),
302 0, phys_addr, syndrome_code);
305 /* Power management extensions. */
306 void prom_sleepself(void)
308 p1275_cmd("SUNW,sleep-self", P1275_INOUT(0, 0));
311 int prom_sleepsystem(void)
313 return p1275_cmd("SUNW,sleep-system", P1275_INOUT(0, 1));
316 int prom_wakeupsystem(void)
318 return p1275_cmd("SUNW,wakeup-system", P1275_INOUT(0, 1));
321 #ifdef CONFIG_SMP
322 void prom_startcpu(int cpunode, unsigned long pc, unsigned long arg)
324 p1275_cmd("SUNW,start-cpu", P1275_INOUT(3, 0), cpunode, pc, arg);
327 void prom_startcpu_cpuid(int cpuid, unsigned long pc, unsigned long arg)
329 p1275_cmd("SUNW,start-cpu-by-cpuid", P1275_INOUT(3, 0),
330 cpuid, pc, arg);
333 void prom_stopcpu_cpuid(int cpuid)
335 p1275_cmd("SUNW,stop-cpu-by-cpuid", P1275_INOUT(1, 0),
336 cpuid);
339 void prom_stopself(void)
341 p1275_cmd("SUNW,stop-self", P1275_INOUT(0, 0));
344 void prom_idleself(void)
346 p1275_cmd("SUNW,idle-self", P1275_INOUT(0, 0));
349 void prom_resumecpu(int cpunode)
351 p1275_cmd("SUNW,resume-cpu", P1275_INOUT(1, 0), cpunode);
353 #endif