Commit | Line | Data |
---|---|---|
1da177e4 LT |
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 | ||
1da177e4 LT |
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> | |
b3e13fbe | 17 | #include <asm/ldc.h> |
1da177e4 | 18 | |
22d6a1cb DM |
19 | int 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 | ||
29 | void 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 | ||
1da177e4 | 38 | /* Reset and reboot the machine with the command 'bcommand'. */ |
bff06d55 | 39 | void prom_reboot(const char *bcommand) |
1da177e4 | 40 | { |
b3e13fbe DM |
41 | #ifdef CONFIG_SUN_LDOMS |
42 | if (ldom_domaining_enabled) | |
43 | ldom_reboot(bcommand); | |
44 | #endif | |
1da177e4 LT |
45 | 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'. */ | |
bff06d55 | 50 | void prom_feval(const char *fstring) |
1da177e4 LT |
51 | { |
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. */ | |
59 | extern void (*prom_palette)(int); | |
60 | ||
61 | #ifdef CONFIG_SMP | |
62 | extern void smp_capture(void); | |
63 | extern void smp_release(void); | |
64 | #endif | |
65 | ||
66 | /* Drop into the prom, with the chance to continue with the 'go' | |
67 | * prom command. | |
68 | */ | |
69 | void prom_cmdline(void) | |
70 | { | |
71 | unsigned long flags; | |
72 | ||
73 | local_irq_save(flags); | |
74 | ||
c73fcc84 | 75 | if (prom_palette) |
1da177e4 LT |
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 | ||
c73fcc84 | 88 | if (prom_palette) |
1da177e4 LT |
89 | prom_palette(0); |
90 | ||
91 | local_irq_restore(flags); | |
92 | } | |
93 | ||
1da177e4 LT |
94 | /* Drop into the prom, but completely terminate the program. |
95 | * No chance of continuing. | |
96 | */ | |
97 | void prom_halt(void) | |
98 | { | |
4f0234f4 DM |
99 | #ifdef CONFIG_SUN_LDOMS |
100 | if (ldom_domaining_enabled) | |
101 | ldom_power_off(); | |
102 | #endif | |
1da177e4 LT |
103 | again: |
104 | p1275_cmd("exit", P1275_INOUT(0, 0)); | |
105 | goto again; /* PROM is out to get me -DaveM */ | |
106 | } | |
107 | ||
108 | void prom_halt_power_off(void) | |
109 | { | |
4f0234f4 DM |
110 | #ifdef CONFIG_SUN_LDOMS |
111 | if (ldom_domaining_enabled) | |
112 | ldom_power_off(); | |
113 | #endif | |
1da177e4 LT |
114 | p1275_cmd("SUNW,power-off", P1275_INOUT(0, 0)); |
115 | ||
116 | /* if nothing else helps, we just halt */ | |
117 | prom_halt(); | |
118 | } | |
119 | ||
120 | /* Set prom sync handler to call function 'funcp'. */ | |
121 | void prom_setcallback(callback_func_t funcp) | |
122 | { | |
123 | if (!funcp) | |
124 | return; | |
125 | p1275_cmd("set-callback", P1275_ARG(0, P1275_ARG_IN_FUNCTION) | | |
126 | P1275_INOUT(1, 1), funcp); | |
127 | } | |
128 | ||
129 | /* Get the idprom and stuff it into buffer 'idbuf'. Returns the | |
130 | * format type. 'num_bytes' is the number of bytes that your idbuf | |
131 | * has space for. Returns 0xff on error. | |
132 | */ | |
133 | unsigned char prom_get_idprom(char *idbuf, int num_bytes) | |
134 | { | |
135 | int len; | |
136 | ||
137 | len = prom_getproplen(prom_root_node, "idprom"); | |
138 | if ((len >num_bytes) || (len == -1)) | |
139 | return 0xff; | |
140 | if (!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes)) | |
141 | return idbuf[0]; | |
142 | ||
143 | return 0xff; | |
144 | } | |
145 | ||
1da177e4 LT |
146 | /* Install Linux trap table so PROM uses that instead of its own. */ |
147 | void prom_set_trap_table(unsigned long tba) | |
148 | { | |
c79f7677 DM |
149 | p1275_cmd("SUNW,set-trap-table", |
150 | (P1275_ARG(0, P1275_ARG_IN_64B) | | |
151 | P1275_INOUT(1, 0)), tba); | |
1da177e4 LT |
152 | } |
153 | ||
12eaa328 DM |
154 | void prom_set_trap_table_sun4v(unsigned long tba, unsigned long mmfsa) |
155 | { | |
c79f7677 DM |
156 | p1275_cmd("SUNW,set-trap-table", |
157 | (P1275_ARG(0, P1275_ARG_IN_64B) | | |
158 | P1275_ARG(1, P1275_ARG_IN_64B) | | |
159 | P1275_INOUT(2, 0)), tba, mmfsa); | |
12eaa328 DM |
160 | } |
161 | ||
1da177e4 LT |
162 | int prom_get_mmu_ihandle(void) |
163 | { | |
164 | int node, ret; | |
165 | ||
bff06d55 DM |
166 | if (prom_mmu_ihandle_cache != 0) |
167 | return prom_mmu_ihandle_cache; | |
1da177e4 | 168 | |
bff06d55 DM |
169 | node = prom_finddevice(prom_chosen_path); |
170 | ret = prom_getint(node, prom_mmu_name); | |
1da177e4 | 171 | if (ret == -1 || ret == 0) |
bff06d55 | 172 | prom_mmu_ihandle_cache = -1; |
1da177e4 | 173 | else |
bff06d55 | 174 | prom_mmu_ihandle_cache = ret; |
1da177e4 LT |
175 | |
176 | return ret; | |
177 | } | |
178 | ||
179 | static int prom_get_memory_ihandle(void) | |
180 | { | |
181 | static int memory_ihandle_cache; | |
182 | int node, ret; | |
183 | ||
184 | if (memory_ihandle_cache != 0) | |
185 | return memory_ihandle_cache; | |
186 | ||
187 | node = prom_finddevice("/chosen"); | |
188 | ret = prom_getint(node, "memory"); | |
189 | if (ret == -1 || ret == 0) | |
190 | memory_ihandle_cache = -1; | |
191 | else | |
192 | memory_ihandle_cache = ret; | |
193 | ||
194 | return ret; | |
195 | } | |
196 | ||
197 | /* Load explicit I/D TLB entries. */ | |
198 | long prom_itlb_load(unsigned long index, | |
199 | unsigned long tte_data, | |
200 | unsigned long vaddr) | |
201 | { | |
bff06d55 | 202 | return p1275_cmd(prom_callmethod_name, |
1da177e4 LT |
203 | (P1275_ARG(0, P1275_ARG_IN_STRING) | |
204 | P1275_ARG(2, P1275_ARG_IN_64B) | | |
205 | P1275_ARG(3, P1275_ARG_IN_64B) | | |
206 | P1275_INOUT(5, 1)), | |
207 | "SUNW,itlb-load", | |
208 | prom_get_mmu_ihandle(), | |
209 | /* And then our actual args are pushed backwards. */ | |
210 | vaddr, | |
211 | tte_data, | |
212 | index); | |
213 | } | |
214 | ||
215 | long prom_dtlb_load(unsigned long index, | |
216 | unsigned long tte_data, | |
217 | unsigned long vaddr) | |
218 | { | |
bff06d55 | 219 | return p1275_cmd(prom_callmethod_name, |
1da177e4 LT |
220 | (P1275_ARG(0, P1275_ARG_IN_STRING) | |
221 | P1275_ARG(2, P1275_ARG_IN_64B) | | |
222 | P1275_ARG(3, P1275_ARG_IN_64B) | | |
223 | P1275_INOUT(5, 1)), | |
224 | "SUNW,dtlb-load", | |
225 | prom_get_mmu_ihandle(), | |
226 | /* And then our actual args are pushed backwards. */ | |
227 | vaddr, | |
228 | tte_data, | |
229 | index); | |
230 | } | |
231 | ||
232 | int prom_map(int mode, unsigned long size, | |
233 | unsigned long vaddr, unsigned long paddr) | |
234 | { | |
bff06d55 | 235 | int ret = p1275_cmd(prom_callmethod_name, |
1da177e4 LT |
236 | (P1275_ARG(0, P1275_ARG_IN_STRING) | |
237 | P1275_ARG(3, P1275_ARG_IN_64B) | | |
238 | P1275_ARG(4, P1275_ARG_IN_64B) | | |
239 | P1275_ARG(6, P1275_ARG_IN_64B) | | |
240 | P1275_INOUT(7, 1)), | |
bff06d55 | 241 | prom_map_name, |
1da177e4 LT |
242 | prom_get_mmu_ihandle(), |
243 | mode, | |
244 | size, | |
245 | vaddr, | |
246 | 0, | |
247 | paddr); | |
248 | ||
249 | if (ret == 0) | |
250 | ret = -1; | |
251 | return ret; | |
252 | } | |
253 | ||
254 | void prom_unmap(unsigned long size, unsigned long vaddr) | |
255 | { | |
bff06d55 | 256 | p1275_cmd(prom_callmethod_name, |
1da177e4 LT |
257 | (P1275_ARG(0, P1275_ARG_IN_STRING) | |
258 | P1275_ARG(2, P1275_ARG_IN_64B) | | |
259 | P1275_ARG(3, P1275_ARG_IN_64B) | | |
260 | P1275_INOUT(4, 0)), | |
bff06d55 | 261 | prom_unmap_name, |
1da177e4 LT |
262 | prom_get_mmu_ihandle(), |
263 | size, | |
264 | vaddr); | |
265 | } | |
266 | ||
267 | /* Set aside physical memory which is not touched or modified | |
268 | * across soft resets. | |
269 | */ | |
bff06d55 | 270 | unsigned long prom_retain(const char *name, |
1da177e4 LT |
271 | unsigned long pa_low, unsigned long pa_high, |
272 | long size, long align) | |
273 | { | |
274 | /* XXX I don't think we return multiple values correctly. | |
275 | * XXX OBP supposedly returns pa_low/pa_high here, how does | |
276 | * XXX it work? | |
277 | */ | |
278 | ||
279 | /* If align is zero, the pa_low/pa_high args are passed, | |
280 | * else they are not. | |
281 | */ | |
282 | if (align == 0) | |
283 | return p1275_cmd("SUNW,retain", | |
284 | (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(5, 2)), | |
285 | name, pa_low, pa_high, size, align); | |
286 | else | |
287 | return p1275_cmd("SUNW,retain", | |
288 | (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(3, 2)), | |
289 | name, size, align); | |
290 | } | |
291 | ||
292 | /* Get "Unumber" string for the SIMM at the given | |
293 | * memory address. Usually this will be of the form | |
294 | * "Uxxxx" where xxxx is a decimal number which is | |
295 | * etched into the motherboard next to the SIMM slot | |
296 | * in question. | |
297 | */ | |
298 | int prom_getunumber(int syndrome_code, | |
299 | unsigned long phys_addr, | |
300 | char *buf, int buflen) | |
301 | { | |
bff06d55 | 302 | return p1275_cmd(prom_callmethod_name, |
1da177e4 LT |
303 | (P1275_ARG(0, P1275_ARG_IN_STRING) | |
304 | P1275_ARG(3, P1275_ARG_OUT_BUF) | | |
305 | P1275_ARG(6, P1275_ARG_IN_64B) | | |
306 | P1275_INOUT(8, 2)), | |
307 | "SUNW,get-unumber", prom_get_memory_ihandle(), | |
308 | buflen, buf, P1275_SIZE(buflen), | |
309 | 0, phys_addr, syndrome_code); | |
310 | } | |
311 | ||
312 | /* Power management extensions. */ | |
313 | void prom_sleepself(void) | |
314 | { | |
315 | p1275_cmd("SUNW,sleep-self", P1275_INOUT(0, 0)); | |
316 | } | |
317 | ||
318 | int prom_sleepsystem(void) | |
319 | { | |
320 | return p1275_cmd("SUNW,sleep-system", P1275_INOUT(0, 1)); | |
321 | } | |
322 | ||
323 | int prom_wakeupsystem(void) | |
324 | { | |
325 | return p1275_cmd("SUNW,wakeup-system", P1275_INOUT(0, 1)); | |
326 | } | |
327 | ||
328 | #ifdef CONFIG_SMP | |
7890f794 | 329 | void prom_startcpu(int cpunode, unsigned long pc, unsigned long arg) |
1da177e4 | 330 | { |
7890f794 DM |
331 | p1275_cmd("SUNW,start-cpu", P1275_INOUT(3, 0), cpunode, pc, arg); |
332 | } | |
333 | ||
334 | void prom_startcpu_cpuid(int cpuid, unsigned long pc, unsigned long arg) | |
335 | { | |
336 | p1275_cmd("SUNW,start-cpu-by-cpuid", P1275_INOUT(3, 0), | |
337 | cpuid, pc, arg); | |
338 | } | |
339 | ||
340 | void prom_stopcpu_cpuid(int cpuid) | |
341 | { | |
342 | p1275_cmd("SUNW,stop-cpu-by-cpuid", P1275_INOUT(1, 0), | |
343 | cpuid); | |
1da177e4 LT |
344 | } |
345 | ||
346 | void prom_stopself(void) | |
347 | { | |
348 | p1275_cmd("SUNW,stop-self", P1275_INOUT(0, 0)); | |
349 | } | |
350 | ||
351 | void prom_idleself(void) | |
352 | { | |
353 | p1275_cmd("SUNW,idle-self", P1275_INOUT(0, 0)); | |
354 | } | |
355 | ||
356 | void prom_resumecpu(int cpunode) | |
357 | { | |
358 | p1275_cmd("SUNW,resume-cpu", P1275_INOUT(1, 0), cpunode); | |
359 | } | |
360 | #endif |