blob: e4f31d4d3715cc5c27752633ba58e052e853a956 [file] [log] [blame]
Adrian Bunkb00dc832008-05-19 16:52:27 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * 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>
Sam Ravnborg917c3662009-01-08 16:58:20 -080014#include <linux/module.h>
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <asm/openprom.h>
17#include <asm/oplib.h>
18#include <asm/system.h>
David S. Millerb3e13fb2007-07-12 15:55:55 -070019#include <asm/ldc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
David S. Millerf7b5f552010-11-16 12:24:16 -080021static int prom_service_exists(const char *service_name)
David S. Miller22d6a1c2007-05-25 00:37:12 -070022{
David S. Miller25edd692010-08-23 23:10:57 -070023 unsigned long args[5];
David S. Miller22d6a1c2007-05-25 00:37:12 -070024
David S. Miller25edd692010-08-23 23:10:57 -070025 args[0] = (unsigned long) "test";
26 args[1] = 1;
27 args[2] = 1;
28 args[3] = (unsigned long) service_name;
29 args[4] = (unsigned long) -1;
30
31 p1275_cmd_direct(args);
32
33 if (args[4])
David S. Miller22d6a1c2007-05-25 00:37:12 -070034 return 0;
35 return 1;
36}
37
38void prom_sun4v_guest_soft_state(void)
39{
40 const char *svc = "SUNW,soft-state-supported";
David S. Miller25edd692010-08-23 23:10:57 -070041 unsigned long args[3];
David S. Miller22d6a1c2007-05-25 00:37:12 -070042
43 if (!prom_service_exists(svc))
44 return;
David S. Miller25edd692010-08-23 23:10:57 -070045 args[0] = (unsigned long) svc;
46 args[1] = 0;
47 args[2] = 0;
48 p1275_cmd_direct(args);
David S. Miller22d6a1c2007-05-25 00:37:12 -070049}
50
Linus Torvalds1da177e2005-04-16 15:20:36 -070051/* Reset and reboot the machine with the command 'bcommand'. */
David S. Millerbff06d52005-09-22 20:11:33 -070052void prom_reboot(const char *bcommand)
Linus Torvalds1da177e2005-04-16 15:20:36 -070053{
David S. Miller25edd692010-08-23 23:10:57 -070054 unsigned long args[4];
55
David S. Millerb3e13fb2007-07-12 15:55:55 -070056#ifdef CONFIG_SUN_LDOMS
57 if (ldom_domaining_enabled)
58 ldom_reboot(bcommand);
59#endif
David S. Miller25edd692010-08-23 23:10:57 -070060 args[0] = (unsigned long) "boot";
61 args[1] = 1;
62 args[2] = 0;
63 args[3] = (unsigned long) bcommand;
64
65 p1275_cmd_direct(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066}
67
68/* Forth evaluate the expression contained in 'fstring'. */
David S. Millerbff06d52005-09-22 20:11:33 -070069void prom_feval(const char *fstring)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070{
David S. Miller25edd692010-08-23 23:10:57 -070071 unsigned long args[5];
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 if (!fstring || fstring[0] == 0)
74 return;
David S. Miller25edd692010-08-23 23:10:57 -070075 args[0] = (unsigned long) "interpret";
76 args[1] = 1;
77 args[2] = 1;
78 args[3] = (unsigned long) fstring;
79 args[4] = (unsigned long) -1;
80
81 p1275_cmd_direct(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -070082}
Sam Ravnborg917c3662009-01-08 16:58:20 -080083EXPORT_SYMBOL(prom_feval);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
Linus Torvalds1da177e2005-04-16 15:20:36 -070085#ifdef CONFIG_SMP
86extern void smp_capture(void);
87extern void smp_release(void);
88#endif
89
90/* Drop into the prom, with the chance to continue with the 'go'
91 * prom command.
92 */
93void prom_cmdline(void)
94{
David S. Miller25edd692010-08-23 23:10:57 -070095 unsigned long args[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 unsigned long flags;
97
98 local_irq_save(flags);
99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100#ifdef CONFIG_SMP
101 smp_capture();
102#endif
103
David S. Miller25edd692010-08-23 23:10:57 -0700104 args[0] = (unsigned long) "enter";
105 args[1] = 0;
106 args[2] = 0;
107
108 p1275_cmd_direct(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110#ifdef CONFIG_SMP
111 smp_release();
112#endif
113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 local_irq_restore(flags);
115}
116
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117/* Drop into the prom, but completely terminate the program.
118 * No chance of continuing.
119 */
David S. Millerbd4352c2009-09-04 03:38:54 -0700120void notrace prom_halt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
David S. Miller25edd692010-08-23 23:10:57 -0700122 unsigned long args[3];
123
David S. Miller4f0234f2007-07-13 16:03:42 -0700124#ifdef CONFIG_SUN_LDOMS
125 if (ldom_domaining_enabled)
126 ldom_power_off();
127#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128again:
David S. Miller25edd692010-08-23 23:10:57 -0700129 args[0] = (unsigned long) "exit";
130 args[1] = 0;
131 args[2] = 0;
132 p1275_cmd_direct(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 goto again; /* PROM is out to get me -DaveM */
134}
135
136void prom_halt_power_off(void)
137{
David S. Miller25edd692010-08-23 23:10:57 -0700138 unsigned long args[3];
139
David S. Miller4f0234f2007-07-13 16:03:42 -0700140#ifdef CONFIG_SUN_LDOMS
141 if (ldom_domaining_enabled)
142 ldom_power_off();
143#endif
David S. Miller25edd692010-08-23 23:10:57 -0700144 args[0] = (unsigned long) "SUNW,power-off";
145 args[1] = 0;
146 args[2] = 0;
147 p1275_cmd_direct(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149 /* if nothing else helps, we just halt */
150 prom_halt();
151}
152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153/* Get the idprom and stuff it into buffer 'idbuf'. Returns the
154 * format type. 'num_bytes' is the number of bytes that your idbuf
155 * has space for. Returns 0xff on error.
156 */
157unsigned char prom_get_idprom(char *idbuf, int num_bytes)
158{
159 int len;
160
161 len = prom_getproplen(prom_root_node, "idprom");
162 if ((len >num_bytes) || (len == -1))
163 return 0xff;
164 if (!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes))
165 return idbuf[0];
166
167 return 0xff;
168}
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170int prom_get_mmu_ihandle(void)
171{
Andres Salomon8d125562010-10-08 14:18:11 -0700172 phandle node;
173 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
David S. Millerbff06d52005-09-22 20:11:33 -0700175 if (prom_mmu_ihandle_cache != 0)
176 return prom_mmu_ihandle_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
David S. Millerbff06d52005-09-22 20:11:33 -0700178 node = prom_finddevice(prom_chosen_path);
179 ret = prom_getint(node, prom_mmu_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 if (ret == -1 || ret == 0)
David S. Millerbff06d52005-09-22 20:11:33 -0700181 prom_mmu_ihandle_cache = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 else
David S. Millerbff06d52005-09-22 20:11:33 -0700183 prom_mmu_ihandle_cache = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185 return ret;
186}
187
188static int prom_get_memory_ihandle(void)
189{
190 static int memory_ihandle_cache;
Andres Salomon8d125562010-10-08 14:18:11 -0700191 phandle node;
192 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
194 if (memory_ihandle_cache != 0)
195 return memory_ihandle_cache;
196
197 node = prom_finddevice("/chosen");
198 ret = prom_getint(node, "memory");
199 if (ret == -1 || ret == 0)
200 memory_ihandle_cache = -1;
201 else
202 memory_ihandle_cache = ret;
203
204 return ret;
205}
206
207/* Load explicit I/D TLB entries. */
David S. Miller25edd692010-08-23 23:10:57 -0700208static long tlb_load(const char *type, unsigned long index,
209 unsigned long tte_data, unsigned long vaddr)
210{
211 unsigned long args[9];
212
213 args[0] = (unsigned long) prom_callmethod_name;
214 args[1] = 5;
215 args[2] = 1;
216 args[3] = (unsigned long) type;
217 args[4] = (unsigned int) prom_get_mmu_ihandle();
218 args[5] = vaddr;
219 args[6] = tte_data;
220 args[7] = index;
221 args[8] = (unsigned long) -1;
222
223 p1275_cmd_direct(args);
224
225 return (long) args[8];
226}
227
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228long prom_itlb_load(unsigned long index,
229 unsigned long tte_data,
230 unsigned long vaddr)
231{
David S. Miller25edd692010-08-23 23:10:57 -0700232 return tlb_load("SUNW,itlb-load", index, tte_data, vaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233}
234
235long prom_dtlb_load(unsigned long index,
236 unsigned long tte_data,
237 unsigned long vaddr)
238{
David S. Miller25edd692010-08-23 23:10:57 -0700239 return tlb_load("SUNW,dtlb-load", index, tte_data, vaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240}
241
242int prom_map(int mode, unsigned long size,
243 unsigned long vaddr, unsigned long paddr)
244{
David S. Miller25edd692010-08-23 23:10:57 -0700245 unsigned long args[11];
246 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
David S. Miller25edd692010-08-23 23:10:57 -0700248 args[0] = (unsigned long) prom_callmethod_name;
249 args[1] = 7;
250 args[2] = 1;
251 args[3] = (unsigned long) prom_map_name;
252 args[4] = (unsigned int) prom_get_mmu_ihandle();
253 args[5] = (unsigned int) mode;
254 args[6] = size;
255 args[7] = vaddr;
256 args[8] = 0;
257 args[9] = paddr;
258 args[10] = (unsigned long) -1;
259
260 p1275_cmd_direct(args);
261
262 ret = (int) args[10];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 if (ret == 0)
264 ret = -1;
265 return ret;
266}
267
268void prom_unmap(unsigned long size, unsigned long vaddr)
269{
David S. Miller25edd692010-08-23 23:10:57 -0700270 unsigned long args[7];
271
272 args[0] = (unsigned long) prom_callmethod_name;
273 args[1] = 4;
274 args[2] = 0;
275 args[3] = (unsigned long) prom_unmap_name;
276 args[4] = (unsigned int) prom_get_mmu_ihandle();
277 args[5] = size;
278 args[6] = vaddr;
279
280 p1275_cmd_direct(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281}
282
283/* Set aside physical memory which is not touched or modified
284 * across soft resets.
285 */
David S. Miller25edd692010-08-23 23:10:57 -0700286int prom_retain(const char *name, unsigned long size,
287 unsigned long align, unsigned long *paddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
David S. Miller25edd692010-08-23 23:10:57 -0700289 unsigned long args[11];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290
David S. Miller25edd692010-08-23 23:10:57 -0700291 args[0] = (unsigned long) prom_callmethod_name;
292 args[1] = 5;
293 args[2] = 3;
294 args[3] = (unsigned long) "SUNW,retain";
295 args[4] = (unsigned int) prom_get_memory_ihandle();
296 args[5] = align;
297 args[6] = size;
298 args[7] = (unsigned long) name;
299 args[8] = (unsigned long) -1;
300 args[9] = (unsigned long) -1;
301 args[10] = (unsigned long) -1;
302
303 p1275_cmd_direct(args);
304
305 if (args[8])
306 return (int) args[8];
307
308 /* Next we get "phys_high" then "phys_low". On 64-bit
309 * the phys_high cell is don't care since the phys_low
310 * cell has the full value.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 */
David S. Miller25edd692010-08-23 23:10:57 -0700312 *paddr = args[10];
313
314 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315}
316
317/* Get "Unumber" string for the SIMM at the given
318 * memory address. Usually this will be of the form
319 * "Uxxxx" where xxxx is a decimal number which is
320 * etched into the motherboard next to the SIMM slot
321 * in question.
322 */
323int prom_getunumber(int syndrome_code,
324 unsigned long phys_addr,
325 char *buf, int buflen)
326{
David S. Miller25edd692010-08-23 23:10:57 -0700327 unsigned long args[12];
328
329 args[0] = (unsigned long) prom_callmethod_name;
330 args[1] = 7;
331 args[2] = 2;
332 args[3] = (unsigned long) "SUNW,get-unumber";
333 args[4] = (unsigned int) prom_get_memory_ihandle();
334 args[5] = buflen;
335 args[6] = (unsigned long) buf;
336 args[7] = 0;
337 args[8] = phys_addr;
338 args[9] = (unsigned int) syndrome_code;
339 args[10] = (unsigned long) -1;
340 args[11] = (unsigned long) -1;
341
342 p1275_cmd_direct(args);
343
344 return (int) args[10];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345}
346
347/* Power management extensions. */
348void prom_sleepself(void)
349{
David S. Miller25edd692010-08-23 23:10:57 -0700350 unsigned long args[3];
351
352 args[0] = (unsigned long) "SUNW,sleep-self";
353 args[1] = 0;
354 args[2] = 0;
355 p1275_cmd_direct(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356}
357
358int prom_sleepsystem(void)
359{
David S. Miller25edd692010-08-23 23:10:57 -0700360 unsigned long args[4];
361
362 args[0] = (unsigned long) "SUNW,sleep-system";
363 args[1] = 0;
364 args[2] = 1;
365 args[3] = (unsigned long) -1;
366 p1275_cmd_direct(args);
367
368 return (int) args[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369}
370
371int prom_wakeupsystem(void)
372{
David S. Miller25edd692010-08-23 23:10:57 -0700373 unsigned long args[4];
374
375 args[0] = (unsigned long) "SUNW,wakeup-system";
376 args[1] = 0;
377 args[2] = 1;
378 args[3] = (unsigned long) -1;
379 p1275_cmd_direct(args);
380
381 return (int) args[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382}
383
384#ifdef CONFIG_SMP
David S. Miller7890f792006-02-15 02:26:54 -0800385void prom_startcpu(int cpunode, unsigned long pc, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386{
David S. Miller25edd692010-08-23 23:10:57 -0700387 unsigned long args[6];
388
389 args[0] = (unsigned long) "SUNW,start-cpu";
390 args[1] = 3;
391 args[2] = 0;
392 args[3] = (unsigned int) cpunode;
393 args[4] = pc;
394 args[5] = arg;
395 p1275_cmd_direct(args);
David S. Miller7890f792006-02-15 02:26:54 -0800396}
397
398void prom_startcpu_cpuid(int cpuid, unsigned long pc, unsigned long arg)
399{
David S. Miller25edd692010-08-23 23:10:57 -0700400 unsigned long args[6];
401
402 args[0] = (unsigned long) "SUNW,start-cpu-by-cpuid";
403 args[1] = 3;
404 args[2] = 0;
405 args[3] = (unsigned int) cpuid;
406 args[4] = pc;
407 args[5] = arg;
408 p1275_cmd_direct(args);
David S. Miller7890f792006-02-15 02:26:54 -0800409}
410
411void prom_stopcpu_cpuid(int cpuid)
412{
David S. Miller25edd692010-08-23 23:10:57 -0700413 unsigned long args[4];
414
415 args[0] = (unsigned long) "SUNW,stop-cpu-by-cpuid";
416 args[1] = 1;
417 args[2] = 0;
418 args[3] = (unsigned int) cpuid;
419 p1275_cmd_direct(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420}
421
422void prom_stopself(void)
423{
David S. Miller25edd692010-08-23 23:10:57 -0700424 unsigned long args[3];
425
426 args[0] = (unsigned long) "SUNW,stop-self";
427 args[1] = 0;
428 args[2] = 0;
429 p1275_cmd_direct(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430}
431
432void prom_idleself(void)
433{
David S. Miller25edd692010-08-23 23:10:57 -0700434 unsigned long args[3];
435
436 args[0] = (unsigned long) "SUNW,idle-self";
437 args[1] = 0;
438 args[2] = 0;
439 p1275_cmd_direct(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440}
441
442void prom_resumecpu(int cpunode)
443{
David S. Miller25edd692010-08-23 23:10:57 -0700444 unsigned long args[4];
445
446 args[0] = (unsigned long) "SUNW,resume-cpu";
447 args[1] = 1;
448 args[2] = 0;
449 args[3] = (unsigned int) cpunode;
450 p1275_cmd_direct(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451}
452#endif