Merge branch 'scsi-scan'
[powerpc.git] / 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/config.h>
10 #include <linux/types.h>
11 #include <linux/kernel.h>
12 #include <linux/sched.h>
13 #include <linux/interrupt.h>
14 #include <linux/delay.h>
15 #include <asm/openprom.h>
16 #include <asm/oplib.h>
17 #include <asm/system.h>
18
19 /* Reset and reboot the machine with the command 'bcommand'. */
20 void prom_reboot(const char *bcommand)
21 {
22         p1275_cmd("boot", P1275_ARG(0, P1275_ARG_IN_STRING) |
23                   P1275_INOUT(1, 0), bcommand);
24 }
25
26 /* Forth evaluate the expression contained in 'fstring'. */
27 void prom_feval(const char *fstring)
28 {
29         if (!fstring || fstring[0] == 0)
30                 return;
31         p1275_cmd("interpret", P1275_ARG(0, P1275_ARG_IN_STRING) |
32                   P1275_INOUT(1, 1), fstring);
33 }
34
35 /* We want to do this more nicely some day. */
36 extern void (*prom_palette)(int);
37
38 #ifdef CONFIG_SMP
39 extern void smp_capture(void);
40 extern void smp_release(void);
41 #endif
42
43 /* Drop into the prom, with the chance to continue with the 'go'
44  * prom command.
45  */
46 void prom_cmdline(void)
47 {
48         unsigned long flags;
49
50         local_irq_save(flags);
51
52         if (!serial_console && prom_palette)
53                 prom_palette(1);
54
55 #ifdef CONFIG_SMP
56         smp_capture();
57 #endif
58
59         p1275_cmd("enter", P1275_INOUT(0, 0));
60
61 #ifdef CONFIG_SMP
62         smp_release();
63 #endif
64
65         if (!serial_console && prom_palette)
66                 prom_palette(0);
67
68         local_irq_restore(flags);
69 }
70
71 #ifdef CONFIG_SMP
72 extern void smp_promstop_others(void);
73 #endif
74
75 /* Drop into the prom, but completely terminate the program.
76  * No chance of continuing.
77  */
78 void prom_halt(void)
79 {
80 #ifdef CONFIG_SMP
81         smp_promstop_others();
82         udelay(8000);
83 #endif
84 again:
85         p1275_cmd("exit", P1275_INOUT(0, 0));
86         goto again; /* PROM is out to get me -DaveM */
87 }
88
89 void prom_halt_power_off(void)
90 {
91 #ifdef CONFIG_SMP
92         smp_promstop_others();
93         udelay(8000);
94 #endif
95         p1275_cmd("SUNW,power-off", P1275_INOUT(0, 0));
96
97         /* if nothing else helps, we just halt */
98         prom_halt();
99 }
100
101 /* Set prom sync handler to call function 'funcp'. */
102 void prom_setcallback(callback_func_t funcp)
103 {
104         if (!funcp)
105                 return;
106         p1275_cmd("set-callback", P1275_ARG(0, P1275_ARG_IN_FUNCTION) |
107                   P1275_INOUT(1, 1), funcp);
108 }
109
110 /* Get the idprom and stuff it into buffer 'idbuf'.  Returns the
111  * format type.  'num_bytes' is the number of bytes that your idbuf
112  * has space for.  Returns 0xff on error.
113  */
114 unsigned char prom_get_idprom(char *idbuf, int num_bytes)
115 {
116         int len;
117
118         len = prom_getproplen(prom_root_node, "idprom");
119         if ((len >num_bytes) || (len == -1))
120                 return 0xff;
121         if (!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes))
122                 return idbuf[0];
123
124         return 0xff;
125 }
126
127 /* Get the major prom version number. */
128 int prom_version(void)
129 {
130         return PROM_P1275;
131 }
132
133 /* Get the prom plugin-revision. */
134 int prom_getrev(void)
135 {
136         return prom_rev;
137 }
138
139 /* Get the prom firmware print revision. */
140 int prom_getprev(void)
141 {
142         return prom_prev;
143 }
144
145 /* Install Linux trap table so PROM uses that instead of its own. */
146 void prom_set_trap_table(unsigned long tba)
147 {
148         p1275_cmd("SUNW,set-trap-table", P1275_INOUT(1, 0), tba);
149 }
150
151 int prom_get_mmu_ihandle(void)
152 {
153         int node, ret;
154
155         if (prom_mmu_ihandle_cache != 0)
156                 return prom_mmu_ihandle_cache;
157
158         node = prom_finddevice(prom_chosen_path);
159         ret = prom_getint(node, prom_mmu_name);
160         if (ret == -1 || ret == 0)
161                 prom_mmu_ihandle_cache = -1;
162         else
163                 prom_mmu_ihandle_cache = ret;
164
165         return ret;
166 }
167
168 static int prom_get_memory_ihandle(void)
169 {
170         static int memory_ihandle_cache;
171         int node, ret;
172
173         if (memory_ihandle_cache != 0)
174                 return memory_ihandle_cache;
175
176         node = prom_finddevice("/chosen");
177         ret = prom_getint(node, "memory");
178         if (ret == -1 || ret == 0)
179                 memory_ihandle_cache = -1;
180         else
181                 memory_ihandle_cache = ret;
182
183         return ret;
184 }
185
186 /* Load explicit I/D TLB entries. */
187 long prom_itlb_load(unsigned long index,
188                     unsigned long tte_data,
189                     unsigned long vaddr)
190 {
191         return p1275_cmd(prom_callmethod_name,
192                          (P1275_ARG(0, P1275_ARG_IN_STRING) |
193                           P1275_ARG(2, P1275_ARG_IN_64B) |
194                           P1275_ARG(3, P1275_ARG_IN_64B) |
195                           P1275_INOUT(5, 1)),
196                          "SUNW,itlb-load",
197                          prom_get_mmu_ihandle(),
198                          /* And then our actual args are pushed backwards. */
199                          vaddr,
200                          tte_data,
201                          index);
202 }
203
204 long prom_dtlb_load(unsigned long index,
205                     unsigned long tte_data,
206                     unsigned long vaddr)
207 {
208         return p1275_cmd(prom_callmethod_name,
209                          (P1275_ARG(0, P1275_ARG_IN_STRING) |
210                           P1275_ARG(2, P1275_ARG_IN_64B) |
211                           P1275_ARG(3, P1275_ARG_IN_64B) |
212                           P1275_INOUT(5, 1)),
213                          "SUNW,dtlb-load",
214                          prom_get_mmu_ihandle(),
215                          /* And then our actual args are pushed backwards. */
216                          vaddr,
217                          tte_data,
218                          index);
219 }
220
221 int prom_map(int mode, unsigned long size,
222              unsigned long vaddr, unsigned long paddr)
223 {
224         int ret = p1275_cmd(prom_callmethod_name,
225                             (P1275_ARG(0, P1275_ARG_IN_STRING) |
226                              P1275_ARG(3, P1275_ARG_IN_64B) |
227                              P1275_ARG(4, P1275_ARG_IN_64B) |
228                              P1275_ARG(6, P1275_ARG_IN_64B) |
229                              P1275_INOUT(7, 1)),
230                             prom_map_name,
231                             prom_get_mmu_ihandle(),
232                             mode,
233                             size,
234                             vaddr,
235                             0,
236                             paddr);
237
238         if (ret == 0)
239                 ret = -1;
240         return ret;
241 }
242
243 void prom_unmap(unsigned long size, unsigned long vaddr)
244 {
245         p1275_cmd(prom_callmethod_name,
246                   (P1275_ARG(0, P1275_ARG_IN_STRING) |
247                    P1275_ARG(2, P1275_ARG_IN_64B) |
248                    P1275_ARG(3, P1275_ARG_IN_64B) |
249                    P1275_INOUT(4, 0)),
250                   prom_unmap_name,
251                   prom_get_mmu_ihandle(),
252                   size,
253                   vaddr);
254 }
255
256 /* Set aside physical memory which is not touched or modified
257  * across soft resets.
258  */
259 unsigned long prom_retain(const char *name,
260                           unsigned long pa_low, unsigned long pa_high,
261                           long size, long align)
262 {
263         /* XXX I don't think we return multiple values correctly.
264          * XXX OBP supposedly returns pa_low/pa_high here, how does
265          * XXX it work?
266          */
267
268         /* If align is zero, the pa_low/pa_high args are passed,
269          * else they are not.
270          */
271         if (align == 0)
272                 return p1275_cmd("SUNW,retain",
273                                  (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(5, 2)),
274                                  name, pa_low, pa_high, size, align);
275         else
276                 return p1275_cmd("SUNW,retain",
277                                  (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(3, 2)),
278                                  name, size, align);
279 }
280
281 /* Get "Unumber" string for the SIMM at the given
282  * memory address.  Usually this will be of the form
283  * "Uxxxx" where xxxx is a decimal number which is
284  * etched into the motherboard next to the SIMM slot
285  * in question.
286  */
287 int prom_getunumber(int syndrome_code,
288                     unsigned long phys_addr,
289                     char *buf, int buflen)
290 {
291         return p1275_cmd(prom_callmethod_name,
292                          (P1275_ARG(0, P1275_ARG_IN_STRING)     |
293                           P1275_ARG(3, P1275_ARG_OUT_BUF)       |
294                           P1275_ARG(6, P1275_ARG_IN_64B)        |
295                           P1275_INOUT(8, 2)),
296                          "SUNW,get-unumber", prom_get_memory_ihandle(),
297                          buflen, buf, P1275_SIZE(buflen),
298                          0, phys_addr, syndrome_code);
299 }
300
301 /* Power management extensions. */
302 void prom_sleepself(void)
303 {
304         p1275_cmd("SUNW,sleep-self", P1275_INOUT(0, 0));
305 }
306
307 int prom_sleepsystem(void)
308 {
309         return p1275_cmd("SUNW,sleep-system", P1275_INOUT(0, 1));
310 }
311
312 int prom_wakeupsystem(void)
313 {
314         return p1275_cmd("SUNW,wakeup-system", P1275_INOUT(0, 1));
315 }
316
317 #ifdef CONFIG_SMP
318 void prom_startcpu(int cpunode, unsigned long pc, unsigned long o0)
319 {
320         p1275_cmd("SUNW,start-cpu", P1275_INOUT(3, 0), cpunode, pc, o0);
321 }
322
323 void prom_stopself(void)
324 {
325         p1275_cmd("SUNW,stop-self", P1275_INOUT(0, 0));
326 }
327
328 void prom_idleself(void)
329 {
330         p1275_cmd("SUNW,idle-self", P1275_INOUT(0, 0));
331 }
332
333 void prom_resumecpu(int cpunode)
334 {
335         p1275_cmd("SUNW,resume-cpu", P1275_INOUT(1, 0), cpunode);
336 }
337 #endif