blob: 72d272c9de6b5aec988b9f99b9990e027c02f6dc [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>
David S. Millerb3e13fb2007-07-12 15:55:55 -070017#include <asm/ldc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
David S. Miller22d6a1c2007-05-25 00:37:12 -070019int prom_service_exists(const char *service_name)
20{
21 int err = p1275_cmd("test", P1275_ARG(0, P1275_ARG_IN_STRING) |
22 P1275_INOUT(1, 1), service_name);
23
24 if (err)
25 return 0;
26 return 1;
27}
28
29void prom_sun4v_guest_soft_state(void)
30{
31 const char *svc = "SUNW,soft-state-supported";
32
33 if (!prom_service_exists(svc))
34 return;
35 p1275_cmd(svc, P1275_INOUT(0, 0));
36}
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038/* Reset and reboot the machine with the command 'bcommand'. */
David S. Millerbff06d52005-09-22 20:11:33 -070039void prom_reboot(const char *bcommand)
Linus Torvalds1da177e2005-04-16 15:20:36 -070040{
David S. Millerb3e13fb2007-07-12 15:55:55 -070041#ifdef CONFIG_SUN_LDOMS
42 if (ldom_domaining_enabled)
43 ldom_reboot(bcommand);
44#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 p1275_cmd("boot", P1275_ARG(0, P1275_ARG_IN_STRING) |
46 P1275_INOUT(1, 0), bcommand);
47}
48
49/* Forth evaluate the expression contained in 'fstring'. */
David S. Millerbff06d52005-09-22 20:11:33 -070050void prom_feval(const char *fstring)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
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);
56}
57
58/* We want to do this more nicely some day. */
59extern void (*prom_palette)(int);
60
61#ifdef CONFIG_SMP
62extern void smp_capture(void);
63extern void smp_release(void);
64#endif
65
66/* Drop into the prom, with the chance to continue with the 'go'
67 * prom command.
68 */
69void prom_cmdline(void)
70{
71 unsigned long flags;
72
73 local_irq_save(flags);
74
75 if (!serial_console && prom_palette)
76 prom_palette(1);
77
78#ifdef CONFIG_SMP
79 smp_capture();
80#endif
81
82 p1275_cmd("enter", P1275_INOUT(0, 0));
83
84#ifdef CONFIG_SMP
85 smp_release();
86#endif
87
88 if (!serial_console && prom_palette)
89 prom_palette(0);
90
91 local_irq_restore(flags);
92}
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094/* Drop into the prom, but completely terminate the program.
95 * No chance of continuing.
96 */
97void prom_halt(void)
98{
Linus Torvalds1da177e2005-04-16 15:20:36 -070099again:
100 p1275_cmd("exit", P1275_INOUT(0, 0));
101 goto again; /* PROM is out to get me -DaveM */
102}
103
104void prom_halt_power_off(void)
105{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 p1275_cmd("SUNW,power-off", P1275_INOUT(0, 0));
107
108 /* if nothing else helps, we just halt */
109 prom_halt();
110}
111
112/* Set prom sync handler to call function 'funcp'. */
113void prom_setcallback(callback_func_t funcp)
114{
115 if (!funcp)
116 return;
117 p1275_cmd("set-callback", P1275_ARG(0, P1275_ARG_IN_FUNCTION) |
118 P1275_INOUT(1, 1), funcp);
119}
120
121/* Get the idprom and stuff it into buffer 'idbuf'. Returns the
122 * format type. 'num_bytes' is the number of bytes that your idbuf
123 * has space for. Returns 0xff on error.
124 */
125unsigned char prom_get_idprom(char *idbuf, int num_bytes)
126{
127 int len;
128
129 len = prom_getproplen(prom_root_node, "idprom");
130 if ((len >num_bytes) || (len == -1))
131 return 0xff;
132 if (!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes))
133 return idbuf[0];
134
135 return 0xff;
136}
137
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138/* Install Linux trap table so PROM uses that instead of its own. */
139void prom_set_trap_table(unsigned long tba)
140{
David S. Millerc79f7672006-02-20 22:56:01 -0800141 p1275_cmd("SUNW,set-trap-table",
142 (P1275_ARG(0, P1275_ARG_IN_64B) |
143 P1275_INOUT(1, 0)), tba);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144}
145
David S. Miller12eaa322006-02-10 15:39:51 -0800146void prom_set_trap_table_sun4v(unsigned long tba, unsigned long mmfsa)
147{
David S. Millerc79f7672006-02-20 22:56:01 -0800148 p1275_cmd("SUNW,set-trap-table",
149 (P1275_ARG(0, P1275_ARG_IN_64B) |
150 P1275_ARG(1, P1275_ARG_IN_64B) |
151 P1275_INOUT(2, 0)), tba, mmfsa);
David S. Miller12eaa322006-02-10 15:39:51 -0800152}
153
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154int prom_get_mmu_ihandle(void)
155{
156 int node, ret;
157
David S. Millerbff06d52005-09-22 20:11:33 -0700158 if (prom_mmu_ihandle_cache != 0)
159 return prom_mmu_ihandle_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
David S. Millerbff06d52005-09-22 20:11:33 -0700161 node = prom_finddevice(prom_chosen_path);
162 ret = prom_getint(node, prom_mmu_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 if (ret == -1 || ret == 0)
David S. Millerbff06d52005-09-22 20:11:33 -0700164 prom_mmu_ihandle_cache = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 else
David S. Millerbff06d52005-09-22 20:11:33 -0700166 prom_mmu_ihandle_cache = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168 return ret;
169}
170
171static int prom_get_memory_ihandle(void)
172{
173 static int memory_ihandle_cache;
174 int node, ret;
175
176 if (memory_ihandle_cache != 0)
177 return memory_ihandle_cache;
178
179 node = prom_finddevice("/chosen");
180 ret = prom_getint(node, "memory");
181 if (ret == -1 || ret == 0)
182 memory_ihandle_cache = -1;
183 else
184 memory_ihandle_cache = ret;
185
186 return ret;
187}
188
189/* Load explicit I/D TLB entries. */
190long prom_itlb_load(unsigned long index,
191 unsigned long tte_data,
192 unsigned long vaddr)
193{
David S. Millerbff06d52005-09-22 20:11:33 -0700194 return p1275_cmd(prom_callmethod_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 (P1275_ARG(0, P1275_ARG_IN_STRING) |
196 P1275_ARG(2, P1275_ARG_IN_64B) |
197 P1275_ARG(3, P1275_ARG_IN_64B) |
198 P1275_INOUT(5, 1)),
199 "SUNW,itlb-load",
200 prom_get_mmu_ihandle(),
201 /* And then our actual args are pushed backwards. */
202 vaddr,
203 tte_data,
204 index);
205}
206
207long prom_dtlb_load(unsigned long index,
208 unsigned long tte_data,
209 unsigned long vaddr)
210{
David S. Millerbff06d52005-09-22 20:11:33 -0700211 return p1275_cmd(prom_callmethod_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 (P1275_ARG(0, P1275_ARG_IN_STRING) |
213 P1275_ARG(2, P1275_ARG_IN_64B) |
214 P1275_ARG(3, P1275_ARG_IN_64B) |
215 P1275_INOUT(5, 1)),
216 "SUNW,dtlb-load",
217 prom_get_mmu_ihandle(),
218 /* And then our actual args are pushed backwards. */
219 vaddr,
220 tte_data,
221 index);
222}
223
224int prom_map(int mode, unsigned long size,
225 unsigned long vaddr, unsigned long paddr)
226{
David S. Millerbff06d52005-09-22 20:11:33 -0700227 int ret = p1275_cmd(prom_callmethod_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 (P1275_ARG(0, P1275_ARG_IN_STRING) |
229 P1275_ARG(3, P1275_ARG_IN_64B) |
230 P1275_ARG(4, P1275_ARG_IN_64B) |
231 P1275_ARG(6, P1275_ARG_IN_64B) |
232 P1275_INOUT(7, 1)),
David S. Millerbff06d52005-09-22 20:11:33 -0700233 prom_map_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 prom_get_mmu_ihandle(),
235 mode,
236 size,
237 vaddr,
238 0,
239 paddr);
240
241 if (ret == 0)
242 ret = -1;
243 return ret;
244}
245
246void prom_unmap(unsigned long size, unsigned long vaddr)
247{
David S. Millerbff06d52005-09-22 20:11:33 -0700248 p1275_cmd(prom_callmethod_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 (P1275_ARG(0, P1275_ARG_IN_STRING) |
250 P1275_ARG(2, P1275_ARG_IN_64B) |
251 P1275_ARG(3, P1275_ARG_IN_64B) |
252 P1275_INOUT(4, 0)),
David S. Millerbff06d52005-09-22 20:11:33 -0700253 prom_unmap_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 prom_get_mmu_ihandle(),
255 size,
256 vaddr);
257}
258
259/* Set aside physical memory which is not touched or modified
260 * across soft resets.
261 */
David S. Millerbff06d52005-09-22 20:11:33 -0700262unsigned long prom_retain(const char *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 unsigned long pa_low, unsigned long pa_high,
264 long size, long align)
265{
266 /* XXX I don't think we return multiple values correctly.
267 * XXX OBP supposedly returns pa_low/pa_high here, how does
268 * XXX it work?
269 */
270
271 /* If align is zero, the pa_low/pa_high args are passed,
272 * else they are not.
273 */
274 if (align == 0)
275 return p1275_cmd("SUNW,retain",
276 (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(5, 2)),
277 name, pa_low, pa_high, size, align);
278 else
279 return p1275_cmd("SUNW,retain",
280 (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(3, 2)),
281 name, size, align);
282}
283
284/* Get "Unumber" string for the SIMM at the given
285 * memory address. Usually this will be of the form
286 * "Uxxxx" where xxxx is a decimal number which is
287 * etched into the motherboard next to the SIMM slot
288 * in question.
289 */
290int prom_getunumber(int syndrome_code,
291 unsigned long phys_addr,
292 char *buf, int buflen)
293{
David S. Millerbff06d52005-09-22 20:11:33 -0700294 return p1275_cmd(prom_callmethod_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 (P1275_ARG(0, P1275_ARG_IN_STRING) |
296 P1275_ARG(3, P1275_ARG_OUT_BUF) |
297 P1275_ARG(6, P1275_ARG_IN_64B) |
298 P1275_INOUT(8, 2)),
299 "SUNW,get-unumber", prom_get_memory_ihandle(),
300 buflen, buf, P1275_SIZE(buflen),
301 0, phys_addr, syndrome_code);
302}
303
304/* Power management extensions. */
305void prom_sleepself(void)
306{
307 p1275_cmd("SUNW,sleep-self", P1275_INOUT(0, 0));
308}
309
310int prom_sleepsystem(void)
311{
312 return p1275_cmd("SUNW,sleep-system", P1275_INOUT(0, 1));
313}
314
315int prom_wakeupsystem(void)
316{
317 return p1275_cmd("SUNW,wakeup-system", P1275_INOUT(0, 1));
318}
319
320#ifdef CONFIG_SMP
David S. Miller7890f792006-02-15 02:26:54 -0800321void prom_startcpu(int cpunode, unsigned long pc, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322{
David S. Miller7890f792006-02-15 02:26:54 -0800323 p1275_cmd("SUNW,start-cpu", P1275_INOUT(3, 0), cpunode, pc, arg);
324}
325
326void prom_startcpu_cpuid(int cpuid, unsigned long pc, unsigned long arg)
327{
328 p1275_cmd("SUNW,start-cpu-by-cpuid", P1275_INOUT(3, 0),
329 cpuid, pc, arg);
330}
331
332void prom_stopcpu_cpuid(int cpuid)
333{
334 p1275_cmd("SUNW,stop-cpu-by-cpuid", P1275_INOUT(1, 0),
335 cpuid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336}
337
338void prom_stopself(void)
339{
340 p1275_cmd("SUNW,stop-self", P1275_INOUT(0, 0));
341}
342
343void prom_idleself(void)
344{
345 p1275_cmd("SUNW,idle-self", P1275_INOUT(0, 0));
346}
347
348void prom_resumecpu(int cpunode)
349{
350 p1275_cmd("SUNW,resume-cpu", P1275_INOUT(1, 0), cpunode);
351}
352#endif