Pull acpi_os_free into release branch
[linux-2.6] / arch / sparc64 / prom / misc.c
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.
4  *
5  * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
6  * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
7  */
8
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
18 /* Reset and reboot the machine with the command 'bcommand'. */
19 void prom_reboot(const char *bcommand)
20 {
21         p1275_cmd("boot", P1275_ARG(0, P1275_ARG_IN_STRING) |
22                   P1275_INOUT(1, 0), bcommand);
23 }
24
25 /* Forth evaluate the expression contained in 'fstring'. */
26 void prom_feval(const char *fstring)
27 {
28         if (!fstring || fstring[0] == 0)
29                 return;
30         p1275_cmd("interpret", P1275_ARG(0, P1275_ARG_IN_STRING) |
31                   P1275_INOUT(1, 1), fstring);
32 }
33
34 /* We want to do this more nicely some day. */
35 extern void (*prom_palette)(int);
36
37 #ifdef CONFIG_SMP
38 extern void smp_capture(void);
39 extern void smp_release(void);
40 #endif
41
42 /* Drop into the prom, with the chance to continue with the 'go'
43  * prom command.
44  */
45 void prom_cmdline(void)
46 {
47         unsigned long flags;
48
49         local_irq_save(flags);
50
51         if (!serial_console && prom_palette)
52                 prom_palette(1);
53
54 #ifdef CONFIG_SMP
55         smp_capture();
56 #endif
57
58         p1275_cmd("enter", P1275_INOUT(0, 0));
59
60 #ifdef CONFIG_SMP
61         smp_release();
62 #endif
63
64         if (!serial_console && prom_palette)
65                 prom_palette(0);
66
67         local_irq_restore(flags);
68 }
69
70 /* Drop into the prom, but completely terminate the program.
71  * No chance of continuing.
72  */
73 void prom_halt(void)
74 {
75 again:
76         p1275_cmd("exit", P1275_INOUT(0, 0));
77         goto again; /* PROM is out to get me -DaveM */
78 }
79
80 void prom_halt_power_off(void)
81 {
82         p1275_cmd("SUNW,power-off", P1275_INOUT(0, 0));
83
84         /* if nothing else helps, we just halt */
85         prom_halt();
86 }
87
88 /* Set prom sync handler to call function 'funcp'. */
89 void prom_setcallback(callback_func_t funcp)
90 {
91         if (!funcp)
92                 return;
93         p1275_cmd("set-callback", P1275_ARG(0, P1275_ARG_IN_FUNCTION) |
94                   P1275_INOUT(1, 1), funcp);
95 }
96
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.
100  */
101 unsigned char prom_get_idprom(char *idbuf, int num_bytes)
102 {
103         int len;
104
105         len = prom_getproplen(prom_root_node, "idprom");
106         if ((len >num_bytes) || (len == -1))
107                 return 0xff;
108         if (!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes))
109                 return idbuf[0];
110
111         return 0xff;
112 }
113
114 /* Install Linux trap table so PROM uses that instead of its own. */
115 void prom_set_trap_table(unsigned long tba)
116 {
117         p1275_cmd("SUNW,set-trap-table",
118                   (P1275_ARG(0, P1275_ARG_IN_64B) |
119                    P1275_INOUT(1, 0)), tba);
120 }
121
122 void prom_set_trap_table_sun4v(unsigned long tba, unsigned long mmfsa)
123 {
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);
128 }
129
130 int prom_get_mmu_ihandle(void)
131 {
132         int node, ret;
133
134         if (prom_mmu_ihandle_cache != 0)
135                 return prom_mmu_ihandle_cache;
136
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;
141         else
142                 prom_mmu_ihandle_cache = ret;
143
144         return ret;
145 }
146
147 static int prom_get_memory_ihandle(void)
148 {
149         static int memory_ihandle_cache;
150         int node, ret;
151
152         if (memory_ihandle_cache != 0)
153                 return memory_ihandle_cache;
154
155         node = prom_finddevice("/chosen");
156         ret = prom_getint(node, "memory");
157         if (ret == -1 || ret == 0)
158                 memory_ihandle_cache = -1;
159         else
160                 memory_ihandle_cache = ret;
161
162         return ret;
163 }
164
165 /* Load explicit I/D TLB entries. */
166 long prom_itlb_load(unsigned long index,
167                     unsigned long tte_data,
168                     unsigned long vaddr)
169 {
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) |
174                           P1275_INOUT(5, 1)),
175                          "SUNW,itlb-load",
176                          prom_get_mmu_ihandle(),
177                          /* And then our actual args are pushed backwards. */
178                          vaddr,
179                          tte_data,
180                          index);
181 }
182
183 long prom_dtlb_load(unsigned long index,
184                     unsigned long tte_data,
185                     unsigned long vaddr)
186 {
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) |
191                           P1275_INOUT(5, 1)),
192                          "SUNW,dtlb-load",
193                          prom_get_mmu_ihandle(),
194                          /* And then our actual args are pushed backwards. */
195                          vaddr,
196                          tte_data,
197                          index);
198 }
199
200 int prom_map(int mode, unsigned long size,
201              unsigned long vaddr, unsigned long paddr)
202 {
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) |
208                              P1275_INOUT(7, 1)),
209                             prom_map_name,
210                             prom_get_mmu_ihandle(),
211                             mode,
212                             size,
213                             vaddr,
214                             0,
215                             paddr);
216
217         if (ret == 0)
218                 ret = -1;
219         return ret;
220 }
221
222 void prom_unmap(unsigned long size, unsigned long vaddr)
223 {
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) |
228                    P1275_INOUT(4, 0)),
229                   prom_unmap_name,
230                   prom_get_mmu_ihandle(),
231                   size,
232                   vaddr);
233 }
234
235 /* Set aside physical memory which is not touched or modified
236  * across soft resets.
237  */
238 unsigned long prom_retain(const char *name,
239                           unsigned long pa_low, unsigned long pa_high,
240                           long size, long align)
241 {
242         /* XXX I don't think we return multiple values correctly.
243          * XXX OBP supposedly returns pa_low/pa_high here, how does
244          * XXX it work?
245          */
246
247         /* If align is zero, the pa_low/pa_high args are passed,
248          * else they are not.
249          */
250         if (align == 0)
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);
254         else
255                 return p1275_cmd("SUNW,retain",
256                                  (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(3, 2)),
257                                  name, size, align);
258 }
259
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
264  * in question.
265  */
266 int prom_getunumber(int syndrome_code,
267                     unsigned long phys_addr,
268                     char *buf, int buflen)
269 {
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)        |
274                           P1275_INOUT(8, 2)),
275                          "SUNW,get-unumber", prom_get_memory_ihandle(),
276                          buflen, buf, P1275_SIZE(buflen),
277                          0, phys_addr, syndrome_code);
278 }
279
280 /* Power management extensions. */
281 void prom_sleepself(void)
282 {
283         p1275_cmd("SUNW,sleep-self", P1275_INOUT(0, 0));
284 }
285
286 int prom_sleepsystem(void)
287 {
288         return p1275_cmd("SUNW,sleep-system", P1275_INOUT(0, 1));
289 }
290
291 int prom_wakeupsystem(void)
292 {
293         return p1275_cmd("SUNW,wakeup-system", P1275_INOUT(0, 1));
294 }
295
296 #ifdef CONFIG_SMP
297 void prom_startcpu(int cpunode, unsigned long pc, unsigned long arg)
298 {
299         p1275_cmd("SUNW,start-cpu", P1275_INOUT(3, 0), cpunode, pc, arg);
300 }
301
302 void prom_startcpu_cpuid(int cpuid, unsigned long pc, unsigned long arg)
303 {
304         p1275_cmd("SUNW,start-cpu-by-cpuid", P1275_INOUT(3, 0),
305                   cpuid, pc, arg);
306 }
307
308 void prom_stopcpu_cpuid(int cpuid)
309 {
310         p1275_cmd("SUNW,stop-cpu-by-cpuid", P1275_INOUT(1, 0),
311                   cpuid);
312 }
313
314 void prom_stopself(void)
315 {
316         p1275_cmd("SUNW,stop-self", P1275_INOUT(0, 0));
317 }
318
319 void prom_idleself(void)
320 {
321         p1275_cmd("SUNW,idle-self", P1275_INOUT(0, 0));
322 }
323
324 void prom_resumecpu(int cpunode)
325 {
326         p1275_cmd("SUNW,resume-cpu", P1275_INOUT(1, 0), cpunode);
327 }
328 #endif