blob: f3e0c14e9eef001ba157307375555e2adf5efc57 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* $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
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#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
David S. Miller22d6a1c2007-05-25 00:37:12 -070018int prom_service_exists(const char *service_name)
19{
20 int err = p1275_cmd("test", P1275_ARG(0, P1275_ARG_IN_STRING) |
21 P1275_INOUT(1, 1), service_name);
22
23 if (err)
24 return 0;
25 return 1;
26}
27
28void prom_sun4v_guest_soft_state(void)
29{
30 const char *svc = "SUNW,soft-state-supported";
31
32 if (!prom_service_exists(svc))
33 return;
34 p1275_cmd(svc, P1275_INOUT(0, 0));
35}
36
Linus Torvalds1da177e2005-04-16 15:20:36 -070037/* Reset and reboot the machine with the command 'bcommand'. */
David S. Millerbff06d52005-09-22 20:11:33 -070038void prom_reboot(const char *bcommand)
Linus Torvalds1da177e2005-04-16 15:20:36 -070039{
40 p1275_cmd("boot", P1275_ARG(0, P1275_ARG_IN_STRING) |
41 P1275_INOUT(1, 0), bcommand);
42}
43
44/* Forth evaluate the expression contained in 'fstring'. */
David S. Millerbff06d52005-09-22 20:11:33 -070045void prom_feval(const char *fstring)
Linus Torvalds1da177e2005-04-16 15:20:36 -070046{
47 if (!fstring || fstring[0] == 0)
48 return;
49 p1275_cmd("interpret", P1275_ARG(0, P1275_ARG_IN_STRING) |
50 P1275_INOUT(1, 1), fstring);
51}
52
53/* We want to do this more nicely some day. */
54extern void (*prom_palette)(int);
55
56#ifdef CONFIG_SMP
57extern void smp_capture(void);
58extern void smp_release(void);
59#endif
60
61/* Drop into the prom, with the chance to continue with the 'go'
62 * prom command.
63 */
64void prom_cmdline(void)
65{
66 unsigned long flags;
67
68 local_irq_save(flags);
69
70 if (!serial_console && prom_palette)
71 prom_palette(1);
72
73#ifdef CONFIG_SMP
74 smp_capture();
75#endif
76
77 p1275_cmd("enter", P1275_INOUT(0, 0));
78
79#ifdef CONFIG_SMP
80 smp_release();
81#endif
82
83 if (!serial_console && prom_palette)
84 prom_palette(0);
85
86 local_irq_restore(flags);
87}
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089/* Drop into the prom, but completely terminate the program.
90 * No chance of continuing.
91 */
92void prom_halt(void)
93{
Linus Torvalds1da177e2005-04-16 15:20:36 -070094again:
95 p1275_cmd("exit", P1275_INOUT(0, 0));
96 goto again; /* PROM is out to get me -DaveM */
97}
98
99void prom_halt_power_off(void)
100{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 p1275_cmd("SUNW,power-off", P1275_INOUT(0, 0));
102
103 /* if nothing else helps, we just halt */
104 prom_halt();
105}
106
107/* Set prom sync handler to call function 'funcp'. */
108void prom_setcallback(callback_func_t funcp)
109{
110 if (!funcp)
111 return;
112 p1275_cmd("set-callback", P1275_ARG(0, P1275_ARG_IN_FUNCTION) |
113 P1275_INOUT(1, 1), funcp);
114}
115
116/* Get the idprom and stuff it into buffer 'idbuf'. Returns the
117 * format type. 'num_bytes' is the number of bytes that your idbuf
118 * has space for. Returns 0xff on error.
119 */
120unsigned char prom_get_idprom(char *idbuf, int num_bytes)
121{
122 int len;
123
124 len = prom_getproplen(prom_root_node, "idprom");
125 if ((len >num_bytes) || (len == -1))
126 return 0xff;
127 if (!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes))
128 return idbuf[0];
129
130 return 0xff;
131}
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133/* Install Linux trap table so PROM uses that instead of its own. */
134void prom_set_trap_table(unsigned long tba)
135{
David S. Millerc79f7672006-02-20 22:56:01 -0800136 p1275_cmd("SUNW,set-trap-table",
137 (P1275_ARG(0, P1275_ARG_IN_64B) |
138 P1275_INOUT(1, 0)), tba);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139}
140
David S. Miller12eaa322006-02-10 15:39:51 -0800141void prom_set_trap_table_sun4v(unsigned long tba, unsigned long mmfsa)
142{
David S. Millerc79f7672006-02-20 22:56:01 -0800143 p1275_cmd("SUNW,set-trap-table",
144 (P1275_ARG(0, P1275_ARG_IN_64B) |
145 P1275_ARG(1, P1275_ARG_IN_64B) |
146 P1275_INOUT(2, 0)), tba, mmfsa);
David S. Miller12eaa322006-02-10 15:39:51 -0800147}
148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149int prom_get_mmu_ihandle(void)
150{
151 int node, ret;
152
David S. Millerbff06d52005-09-22 20:11:33 -0700153 if (prom_mmu_ihandle_cache != 0)
154 return prom_mmu_ihandle_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
David S. Millerbff06d52005-09-22 20:11:33 -0700156 node = prom_finddevice(prom_chosen_path);
157 ret = prom_getint(node, prom_mmu_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 if (ret == -1 || ret == 0)
David S. Millerbff06d52005-09-22 20:11:33 -0700159 prom_mmu_ihandle_cache = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160 else
David S. Millerbff06d52005-09-22 20:11:33 -0700161 prom_mmu_ihandle_cache = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163 return ret;
164}
165
166static int prom_get_memory_ihandle(void)
167{
168 static int memory_ihandle_cache;
169 int node, ret;
170
171 if (memory_ihandle_cache != 0)
172 return memory_ihandle_cache;
173
174 node = prom_finddevice("/chosen");
175 ret = prom_getint(node, "memory");
176 if (ret == -1 || ret == 0)
177 memory_ihandle_cache = -1;
178 else
179 memory_ihandle_cache = ret;
180
181 return ret;
182}
183
184/* Load explicit I/D TLB entries. */
185long prom_itlb_load(unsigned long index,
186 unsigned long tte_data,
187 unsigned long vaddr)
188{
David S. Millerbff06d52005-09-22 20:11:33 -0700189 return p1275_cmd(prom_callmethod_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 (P1275_ARG(0, P1275_ARG_IN_STRING) |
191 P1275_ARG(2, P1275_ARG_IN_64B) |
192 P1275_ARG(3, P1275_ARG_IN_64B) |
193 P1275_INOUT(5, 1)),
194 "SUNW,itlb-load",
195 prom_get_mmu_ihandle(),
196 /* And then our actual args are pushed backwards. */
197 vaddr,
198 tte_data,
199 index);
200}
201
202long prom_dtlb_load(unsigned long index,
203 unsigned long tte_data,
204 unsigned long vaddr)
205{
David S. Millerbff06d52005-09-22 20:11:33 -0700206 return p1275_cmd(prom_callmethod_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 (P1275_ARG(0, P1275_ARG_IN_STRING) |
208 P1275_ARG(2, P1275_ARG_IN_64B) |
209 P1275_ARG(3, P1275_ARG_IN_64B) |
210 P1275_INOUT(5, 1)),
211 "SUNW,dtlb-load",
212 prom_get_mmu_ihandle(),
213 /* And then our actual args are pushed backwards. */
214 vaddr,
215 tte_data,
216 index);
217}
218
219int prom_map(int mode, unsigned long size,
220 unsigned long vaddr, unsigned long paddr)
221{
David S. Millerbff06d52005-09-22 20:11:33 -0700222 int ret = p1275_cmd(prom_callmethod_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 (P1275_ARG(0, P1275_ARG_IN_STRING) |
224 P1275_ARG(3, P1275_ARG_IN_64B) |
225 P1275_ARG(4, P1275_ARG_IN_64B) |
226 P1275_ARG(6, P1275_ARG_IN_64B) |
227 P1275_INOUT(7, 1)),
David S. Millerbff06d52005-09-22 20:11:33 -0700228 prom_map_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 prom_get_mmu_ihandle(),
230 mode,
231 size,
232 vaddr,
233 0,
234 paddr);
235
236 if (ret == 0)
237 ret = -1;
238 return ret;
239}
240
241void prom_unmap(unsigned long size, unsigned long vaddr)
242{
David S. Millerbff06d52005-09-22 20:11:33 -0700243 p1275_cmd(prom_callmethod_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 (P1275_ARG(0, P1275_ARG_IN_STRING) |
245 P1275_ARG(2, P1275_ARG_IN_64B) |
246 P1275_ARG(3, P1275_ARG_IN_64B) |
247 P1275_INOUT(4, 0)),
David S. Millerbff06d52005-09-22 20:11:33 -0700248 prom_unmap_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 prom_get_mmu_ihandle(),
250 size,
251 vaddr);
252}
253
254/* Set aside physical memory which is not touched or modified
255 * across soft resets.
256 */
David S. Millerbff06d52005-09-22 20:11:33 -0700257unsigned long prom_retain(const char *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 unsigned long pa_low, unsigned long pa_high,
259 long size, long align)
260{
261 /* XXX I don't think we return multiple values correctly.
262 * XXX OBP supposedly returns pa_low/pa_high here, how does
263 * XXX it work?
264 */
265
266 /* If align is zero, the pa_low/pa_high args are passed,
267 * else they are not.
268 */
269 if (align == 0)
270 return p1275_cmd("SUNW,retain",
271 (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(5, 2)),
272 name, pa_low, pa_high, size, align);
273 else
274 return p1275_cmd("SUNW,retain",
275 (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(3, 2)),
276 name, size, align);
277}
278
279/* Get "Unumber" string for the SIMM at the given
280 * memory address. Usually this will be of the form
281 * "Uxxxx" where xxxx is a decimal number which is
282 * etched into the motherboard next to the SIMM slot
283 * in question.
284 */
285int prom_getunumber(int syndrome_code,
286 unsigned long phys_addr,
287 char *buf, int buflen)
288{
David S. Millerbff06d52005-09-22 20:11:33 -0700289 return p1275_cmd(prom_callmethod_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 (P1275_ARG(0, P1275_ARG_IN_STRING) |
291 P1275_ARG(3, P1275_ARG_OUT_BUF) |
292 P1275_ARG(6, P1275_ARG_IN_64B) |
293 P1275_INOUT(8, 2)),
294 "SUNW,get-unumber", prom_get_memory_ihandle(),
295 buflen, buf, P1275_SIZE(buflen),
296 0, phys_addr, syndrome_code);
297}
298
299/* Power management extensions. */
300void prom_sleepself(void)
301{
302 p1275_cmd("SUNW,sleep-self", P1275_INOUT(0, 0));
303}
304
305int prom_sleepsystem(void)
306{
307 return p1275_cmd("SUNW,sleep-system", P1275_INOUT(0, 1));
308}
309
310int prom_wakeupsystem(void)
311{
312 return p1275_cmd("SUNW,wakeup-system", P1275_INOUT(0, 1));
313}
314
315#ifdef CONFIG_SMP
David S. Miller7890f792006-02-15 02:26:54 -0800316void prom_startcpu(int cpunode, unsigned long pc, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
David S. Miller7890f792006-02-15 02:26:54 -0800318 p1275_cmd("SUNW,start-cpu", P1275_INOUT(3, 0), cpunode, pc, arg);
319}
320
321void prom_startcpu_cpuid(int cpuid, unsigned long pc, unsigned long arg)
322{
323 p1275_cmd("SUNW,start-cpu-by-cpuid", P1275_INOUT(3, 0),
324 cpuid, pc, arg);
325}
326
327void prom_stopcpu_cpuid(int cpuid)
328{
329 p1275_cmd("SUNW,stop-cpu-by-cpuid", P1275_INOUT(1, 0),
330 cpuid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331}
332
333void prom_stopself(void)
334{
335 p1275_cmd("SUNW,stop-self", P1275_INOUT(0, 0));
336}
337
338void prom_idleself(void)
339{
340 p1275_cmd("SUNW,idle-self", P1275_INOUT(0, 0));
341}
342
343void prom_resumecpu(int cpunode)
344{
345 p1275_cmd("SUNW,resume-cpu", P1275_INOUT(1, 0), cpunode);
346}
347#endif