2 * misc.c: Miscellaneous prom functions that don't belong
5 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
6 * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
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 <linux/module.h>
16 #include <asm/openprom.h>
17 #include <asm/oplib.h>
20 static int prom_service_exists(const char *service_name
)
22 unsigned long args
[5];
24 args
[0] = (unsigned long) "test";
27 args
[3] = (unsigned long) service_name
;
28 args
[4] = (unsigned long) -1;
30 p1275_cmd_direct(args
);
37 void prom_sun4v_guest_soft_state(void)
39 const char *svc
= "SUNW,soft-state-supported";
40 unsigned long args
[3];
42 if (!prom_service_exists(svc
))
44 args
[0] = (unsigned long) svc
;
47 p1275_cmd_direct(args
);
50 /* Reset and reboot the machine with the command 'bcommand'. */
51 void prom_reboot(const char *bcommand
)
53 unsigned long args
[4];
55 #ifdef CONFIG_SUN_LDOMS
56 if (ldom_domaining_enabled
)
57 ldom_reboot(bcommand
);
59 args
[0] = (unsigned long) "boot";
62 args
[3] = (unsigned long) bcommand
;
64 p1275_cmd_direct(args
);
67 /* Forth evaluate the expression contained in 'fstring'. */
68 void prom_feval(const char *fstring
)
70 unsigned long args
[5];
72 if (!fstring
|| fstring
[0] == 0)
74 args
[0] = (unsigned long) "interpret";
77 args
[3] = (unsigned long) fstring
;
78 args
[4] = (unsigned long) -1;
80 p1275_cmd_direct(args
);
82 EXPORT_SYMBOL(prom_feval
);
85 extern void smp_capture(void);
86 extern void smp_release(void);
89 /* Drop into the prom, with the chance to continue with the 'go'
92 void prom_cmdline(void)
94 unsigned long args
[3];
97 local_irq_save(flags
);
103 args
[0] = (unsigned long) "enter";
107 p1275_cmd_direct(args
);
113 local_irq_restore(flags
);
116 /* Drop into the prom, but completely terminate the program.
117 * No chance of continuing.
119 void notrace
prom_halt(void)
121 unsigned long args
[3];
123 #ifdef CONFIG_SUN_LDOMS
124 if (ldom_domaining_enabled
)
128 args
[0] = (unsigned long) "exit";
131 p1275_cmd_direct(args
);
132 goto again
; /* PROM is out to get me -DaveM */
135 void prom_halt_power_off(void)
137 unsigned long args
[3];
139 #ifdef CONFIG_SUN_LDOMS
140 if (ldom_domaining_enabled
)
143 args
[0] = (unsigned long) "SUNW,power-off";
146 p1275_cmd_direct(args
);
148 /* if nothing else helps, we just halt */
152 /* Get the idprom and stuff it into buffer 'idbuf'. Returns the
153 * format type. 'num_bytes' is the number of bytes that your idbuf
154 * has space for. Returns 0xff on error.
156 unsigned char prom_get_idprom(char *idbuf
, int num_bytes
)
160 len
= prom_getproplen(prom_root_node
, "idprom");
161 if ((len
>num_bytes
) || (len
== -1))
163 if (!prom_getproperty(prom_root_node
, "idprom", idbuf
, num_bytes
))
169 int prom_get_mmu_ihandle(void)
174 if (prom_mmu_ihandle_cache
!= 0)
175 return prom_mmu_ihandle_cache
;
177 node
= prom_finddevice(prom_chosen_path
);
178 ret
= prom_getint(node
, prom_mmu_name
);
179 if (ret
== -1 || ret
== 0)
180 prom_mmu_ihandle_cache
= -1;
182 prom_mmu_ihandle_cache
= ret
;
187 static int prom_get_memory_ihandle(void)
189 static int memory_ihandle_cache
;
193 if (memory_ihandle_cache
!= 0)
194 return memory_ihandle_cache
;
196 node
= prom_finddevice("/chosen");
197 ret
= prom_getint(node
, "memory");
198 if (ret
== -1 || ret
== 0)
199 memory_ihandle_cache
= -1;
201 memory_ihandle_cache
= ret
;
206 /* Load explicit I/D TLB entries. */
207 static long tlb_load(const char *type
, unsigned long index
,
208 unsigned long tte_data
, unsigned long vaddr
)
210 unsigned long args
[9];
212 args
[0] = (unsigned long) prom_callmethod_name
;
215 args
[3] = (unsigned long) type
;
216 args
[4] = (unsigned int) prom_get_mmu_ihandle();
220 args
[8] = (unsigned long) -1;
222 p1275_cmd_direct(args
);
224 return (long) args
[8];
227 long prom_itlb_load(unsigned long index
,
228 unsigned long tte_data
,
231 return tlb_load("SUNW,itlb-load", index
, tte_data
, vaddr
);
234 long prom_dtlb_load(unsigned long index
,
235 unsigned long tte_data
,
238 return tlb_load("SUNW,dtlb-load", index
, tte_data
, vaddr
);
241 int prom_map(int mode
, unsigned long size
,
242 unsigned long vaddr
, unsigned long paddr
)
244 unsigned long args
[11];
247 args
[0] = (unsigned long) prom_callmethod_name
;
250 args
[3] = (unsigned long) prom_map_name
;
251 args
[4] = (unsigned int) prom_get_mmu_ihandle();
252 args
[5] = (unsigned int) mode
;
257 args
[10] = (unsigned long) -1;
259 p1275_cmd_direct(args
);
261 ret
= (int) args
[10];
267 void prom_unmap(unsigned long size
, unsigned long vaddr
)
269 unsigned long args
[7];
271 args
[0] = (unsigned long) prom_callmethod_name
;
274 args
[3] = (unsigned long) prom_unmap_name
;
275 args
[4] = (unsigned int) prom_get_mmu_ihandle();
279 p1275_cmd_direct(args
);
282 /* Set aside physical memory which is not touched or modified
283 * across soft resets.
285 int prom_retain(const char *name
, unsigned long size
,
286 unsigned long align
, unsigned long *paddr
)
288 unsigned long args
[11];
290 args
[0] = (unsigned long) prom_callmethod_name
;
293 args
[3] = (unsigned long) "SUNW,retain";
294 args
[4] = (unsigned int) prom_get_memory_ihandle();
297 args
[7] = (unsigned long) name
;
298 args
[8] = (unsigned long) -1;
299 args
[9] = (unsigned long) -1;
300 args
[10] = (unsigned long) -1;
302 p1275_cmd_direct(args
);
305 return (int) args
[8];
307 /* Next we get "phys_high" then "phys_low". On 64-bit
308 * the phys_high cell is don't care since the phys_low
309 * cell has the full value.
316 /* Get "Unumber" string for the SIMM at the given
317 * memory address. Usually this will be of the form
318 * "Uxxxx" where xxxx is a decimal number which is
319 * etched into the motherboard next to the SIMM slot
322 int prom_getunumber(int syndrome_code
,
323 unsigned long phys_addr
,
324 char *buf
, int buflen
)
326 unsigned long args
[12];
328 args
[0] = (unsigned long) prom_callmethod_name
;
331 args
[3] = (unsigned long) "SUNW,get-unumber";
332 args
[4] = (unsigned int) prom_get_memory_ihandle();
334 args
[6] = (unsigned long) buf
;
337 args
[9] = (unsigned int) syndrome_code
;
338 args
[10] = (unsigned long) -1;
339 args
[11] = (unsigned long) -1;
341 p1275_cmd_direct(args
);
343 return (int) args
[10];
346 /* Power management extensions. */
347 void prom_sleepself(void)
349 unsigned long args
[3];
351 args
[0] = (unsigned long) "SUNW,sleep-self";
354 p1275_cmd_direct(args
);
357 int prom_sleepsystem(void)
359 unsigned long args
[4];
361 args
[0] = (unsigned long) "SUNW,sleep-system";
364 args
[3] = (unsigned long) -1;
365 p1275_cmd_direct(args
);
367 return (int) args
[3];
370 int prom_wakeupsystem(void)
372 unsigned long args
[4];
374 args
[0] = (unsigned long) "SUNW,wakeup-system";
377 args
[3] = (unsigned long) -1;
378 p1275_cmd_direct(args
);
380 return (int) args
[3];
384 void prom_startcpu(int cpunode
, unsigned long pc
, unsigned long arg
)
386 unsigned long args
[6];
388 args
[0] = (unsigned long) "SUNW,start-cpu";
391 args
[3] = (unsigned int) cpunode
;
394 p1275_cmd_direct(args
);
397 void prom_startcpu_cpuid(int cpuid
, unsigned long pc
, unsigned long arg
)
399 unsigned long args
[6];
401 args
[0] = (unsigned long) "SUNW,start-cpu-by-cpuid";
404 args
[3] = (unsigned int) cpuid
;
407 p1275_cmd_direct(args
);
410 void prom_stopcpu_cpuid(int cpuid
)
412 unsigned long args
[4];
414 args
[0] = (unsigned long) "SUNW,stop-cpu-by-cpuid";
417 args
[3] = (unsigned int) cpuid
;
418 p1275_cmd_direct(args
);
421 void prom_stopself(void)
423 unsigned long args
[3];
425 args
[0] = (unsigned long) "SUNW,stop-self";
428 p1275_cmd_direct(args
);
431 void prom_idleself(void)
433 unsigned long args
[3];
435 args
[0] = (unsigned long) "SUNW,idle-self";
438 p1275_cmd_direct(args
);
441 void prom_resumecpu(int cpunode
)
443 unsigned long args
[4];
445 args
[0] = (unsigned long) "SUNW,resume-cpu";
448 args
[3] = (unsigned int) cpunode
;
449 p1275_cmd_direct(args
);