blob: 577bde8b664766703bd7fab1ff7f93a4a645d169 [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
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'. */
David S. Millerbff06d52005-09-22 20:11:33 -070020void prom_reboot(const char *bcommand)
Linus Torvalds1da177e2005-04-16 15:20:36 -070021{
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'. */
David S. Millerbff06d52005-09-22 20:11:33 -070027void prom_feval(const char *fstring)
Linus Torvalds1da177e2005-04-16 15:20:36 -070028{
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. */
36extern void (*prom_palette)(int);
37
38#ifdef CONFIG_SMP
39extern void smp_capture(void);
40extern void smp_release(void);
41#endif
42
43/* Drop into the prom, with the chance to continue with the 'go'
44 * prom command.
45 */
46void 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070071/* Drop into the prom, but completely terminate the program.
72 * No chance of continuing.
73 */
74void prom_halt(void)
75{
Linus Torvalds1da177e2005-04-16 15:20:36 -070076again:
77 p1275_cmd("exit", P1275_INOUT(0, 0));
78 goto again; /* PROM is out to get me -DaveM */
79}
80
81void prom_halt_power_off(void)
82{
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 p1275_cmd("SUNW,power-off", P1275_INOUT(0, 0));
84
85 /* if nothing else helps, we just halt */
86 prom_halt();
87}
88
89/* Set prom sync handler to call function 'funcp'. */
90void prom_setcallback(callback_func_t funcp)
91{
92 if (!funcp)
93 return;
94 p1275_cmd("set-callback", P1275_ARG(0, P1275_ARG_IN_FUNCTION) |
95 P1275_INOUT(1, 1), funcp);
96}
97
98/* Get the idprom and stuff it into buffer 'idbuf'. Returns the
99 * format type. 'num_bytes' is the number of bytes that your idbuf
100 * has space for. Returns 0xff on error.
101 */
102unsigned char prom_get_idprom(char *idbuf, int num_bytes)
103{
104 int len;
105
106 len = prom_getproplen(prom_root_node, "idprom");
107 if ((len >num_bytes) || (len == -1))
108 return 0xff;
109 if (!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes))
110 return idbuf[0];
111
112 return 0xff;
113}
114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115/* Install Linux trap table so PROM uses that instead of its own. */
116void prom_set_trap_table(unsigned long tba)
117{
David S. Millerc79f7672006-02-20 22:56:01 -0800118 p1275_cmd("SUNW,set-trap-table",
119 (P1275_ARG(0, P1275_ARG_IN_64B) |
120 P1275_INOUT(1, 0)), tba);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121}
122
David S. Miller12eaa322006-02-10 15:39:51 -0800123void prom_set_trap_table_sun4v(unsigned long tba, unsigned long mmfsa)
124{
David S. Millerc79f7672006-02-20 22:56:01 -0800125 p1275_cmd("SUNW,set-trap-table",
126 (P1275_ARG(0, P1275_ARG_IN_64B) |
127 P1275_ARG(1, P1275_ARG_IN_64B) |
128 P1275_INOUT(2, 0)), tba, mmfsa);
David S. Miller12eaa322006-02-10 15:39:51 -0800129}
130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131int prom_get_mmu_ihandle(void)
132{
133 int node, ret;
134
David S. Millerbff06d52005-09-22 20:11:33 -0700135 if (prom_mmu_ihandle_cache != 0)
136 return prom_mmu_ihandle_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
David S. Millerbff06d52005-09-22 20:11:33 -0700138 node = prom_finddevice(prom_chosen_path);
139 ret = prom_getint(node, prom_mmu_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 if (ret == -1 || ret == 0)
David S. Millerbff06d52005-09-22 20:11:33 -0700141 prom_mmu_ihandle_cache = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 else
David S. Millerbff06d52005-09-22 20:11:33 -0700143 prom_mmu_ihandle_cache = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145 return ret;
146}
147
148static int prom_get_memory_ihandle(void)
149{
150 static int memory_ihandle_cache;
151 int node, ret;
152
153 if (memory_ihandle_cache != 0)
154 return memory_ihandle_cache;
155
156 node = prom_finddevice("/chosen");
157 ret = prom_getint(node, "memory");
158 if (ret == -1 || ret == 0)
159 memory_ihandle_cache = -1;
160 else
161 memory_ihandle_cache = ret;
162
163 return ret;
164}
165
166/* Load explicit I/D TLB entries. */
167long prom_itlb_load(unsigned long index,
168 unsigned long tte_data,
169 unsigned long vaddr)
170{
David S. Millerbff06d52005-09-22 20:11:33 -0700171 return p1275_cmd(prom_callmethod_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 (P1275_ARG(0, P1275_ARG_IN_STRING) |
173 P1275_ARG(2, P1275_ARG_IN_64B) |
174 P1275_ARG(3, P1275_ARG_IN_64B) |
175 P1275_INOUT(5, 1)),
176 "SUNW,itlb-load",
177 prom_get_mmu_ihandle(),
178 /* And then our actual args are pushed backwards. */
179 vaddr,
180 tte_data,
181 index);
182}
183
184long prom_dtlb_load(unsigned long index,
185 unsigned long tte_data,
186 unsigned long vaddr)
187{
David S. Millerbff06d52005-09-22 20:11:33 -0700188 return p1275_cmd(prom_callmethod_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 (P1275_ARG(0, P1275_ARG_IN_STRING) |
190 P1275_ARG(2, P1275_ARG_IN_64B) |
191 P1275_ARG(3, P1275_ARG_IN_64B) |
192 P1275_INOUT(5, 1)),
193 "SUNW,dtlb-load",
194 prom_get_mmu_ihandle(),
195 /* And then our actual args are pushed backwards. */
196 vaddr,
197 tte_data,
198 index);
199}
200
201int prom_map(int mode, unsigned long size,
202 unsigned long vaddr, unsigned long paddr)
203{
David S. Millerbff06d52005-09-22 20:11:33 -0700204 int ret = p1275_cmd(prom_callmethod_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 (P1275_ARG(0, P1275_ARG_IN_STRING) |
206 P1275_ARG(3, P1275_ARG_IN_64B) |
207 P1275_ARG(4, P1275_ARG_IN_64B) |
208 P1275_ARG(6, P1275_ARG_IN_64B) |
209 P1275_INOUT(7, 1)),
David S. Millerbff06d52005-09-22 20:11:33 -0700210 prom_map_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 prom_get_mmu_ihandle(),
212 mode,
213 size,
214 vaddr,
215 0,
216 paddr);
217
218 if (ret == 0)
219 ret = -1;
220 return ret;
221}
222
223void prom_unmap(unsigned long size, unsigned long vaddr)
224{
David S. Millerbff06d52005-09-22 20:11:33 -0700225 p1275_cmd(prom_callmethod_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 (P1275_ARG(0, P1275_ARG_IN_STRING) |
227 P1275_ARG(2, P1275_ARG_IN_64B) |
228 P1275_ARG(3, P1275_ARG_IN_64B) |
229 P1275_INOUT(4, 0)),
David S. Millerbff06d52005-09-22 20:11:33 -0700230 prom_unmap_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 prom_get_mmu_ihandle(),
232 size,
233 vaddr);
234}
235
236/* Set aside physical memory which is not touched or modified
237 * across soft resets.
238 */
David S. Millerbff06d52005-09-22 20:11:33 -0700239unsigned long prom_retain(const char *name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 unsigned long pa_low, unsigned long pa_high,
241 long size, long align)
242{
243 /* XXX I don't think we return multiple values correctly.
244 * XXX OBP supposedly returns pa_low/pa_high here, how does
245 * XXX it work?
246 */
247
248 /* If align is zero, the pa_low/pa_high args are passed,
249 * else they are not.
250 */
251 if (align == 0)
252 return p1275_cmd("SUNW,retain",
253 (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(5, 2)),
254 name, pa_low, pa_high, size, align);
255 else
256 return p1275_cmd("SUNW,retain",
257 (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(3, 2)),
258 name, size, align);
259}
260
261/* Get "Unumber" string for the SIMM at the given
262 * memory address. Usually this will be of the form
263 * "Uxxxx" where xxxx is a decimal number which is
264 * etched into the motherboard next to the SIMM slot
265 * in question.
266 */
267int prom_getunumber(int syndrome_code,
268 unsigned long phys_addr,
269 char *buf, int buflen)
270{
David S. Millerbff06d52005-09-22 20:11:33 -0700271 return p1275_cmd(prom_callmethod_name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 (P1275_ARG(0, P1275_ARG_IN_STRING) |
273 P1275_ARG(3, P1275_ARG_OUT_BUF) |
274 P1275_ARG(6, P1275_ARG_IN_64B) |
275 P1275_INOUT(8, 2)),
276 "SUNW,get-unumber", prom_get_memory_ihandle(),
277 buflen, buf, P1275_SIZE(buflen),
278 0, phys_addr, syndrome_code);
279}
280
281/* Power management extensions. */
282void prom_sleepself(void)
283{
284 p1275_cmd("SUNW,sleep-self", P1275_INOUT(0, 0));
285}
286
287int prom_sleepsystem(void)
288{
289 return p1275_cmd("SUNW,sleep-system", P1275_INOUT(0, 1));
290}
291
292int prom_wakeupsystem(void)
293{
294 return p1275_cmd("SUNW,wakeup-system", P1275_INOUT(0, 1));
295}
296
297#ifdef CONFIG_SMP
David S. Miller7890f792006-02-15 02:26:54 -0800298void prom_startcpu(int cpunode, unsigned long pc, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{
David S. Miller7890f792006-02-15 02:26:54 -0800300 p1275_cmd("SUNW,start-cpu", P1275_INOUT(3, 0), cpunode, pc, arg);
301}
302
303void prom_startcpu_cpuid(int cpuid, unsigned long pc, unsigned long arg)
304{
305 p1275_cmd("SUNW,start-cpu-by-cpuid", P1275_INOUT(3, 0),
306 cpuid, pc, arg);
307}
308
309void prom_stopcpu_cpuid(int cpuid)
310{
311 p1275_cmd("SUNW,stop-cpu-by-cpuid", P1275_INOUT(1, 0),
312 cpuid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313}
314
315void prom_stopself(void)
316{
317 p1275_cmd("SUNW,stop-self", P1275_INOUT(0, 0));
318}
319
320void prom_idleself(void)
321{
322 p1275_cmd("SUNW,idle-self", P1275_INOUT(0, 0));
323}
324
325void prom_resumecpu(int cpunode)
326{
327 p1275_cmd("SUNW,resume-cpu", P1275_INOUT(1, 0), cpunode);
328}
329#endif