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
);
84 /* Drop into the prom, with the chance to continue with the 'go'
87 void prom_cmdline(void)
89 unsigned long args
[3];
92 local_irq_save(flags
);
98 args
[0] = (unsigned long) "enter";
102 p1275_cmd_direct(args
);
108 local_irq_restore(flags
);
111 /* Drop into the prom, but completely terminate the program.
112 * No chance of continuing.
114 void notrace
prom_halt(void)
116 unsigned long args
[3];
118 #ifdef CONFIG_SUN_LDOMS
119 if (ldom_domaining_enabled
)
123 args
[0] = (unsigned long) "exit";
126 p1275_cmd_direct(args
);
127 goto again
; /* PROM is out to get me -DaveM */
130 void prom_halt_power_off(void)
132 unsigned long args
[3];
134 #ifdef CONFIG_SUN_LDOMS
135 if (ldom_domaining_enabled
)
138 args
[0] = (unsigned long) "SUNW,power-off";
141 p1275_cmd_direct(args
);
143 /* if nothing else helps, we just halt */
147 /* Get the idprom and stuff it into buffer 'idbuf'. Returns the
148 * format type. 'num_bytes' is the number of bytes that your idbuf
149 * has space for. Returns 0xff on error.
151 unsigned char prom_get_idprom(char *idbuf
, int num_bytes
)
155 len
= prom_getproplen(prom_root_node
, "idprom");
156 if ((len
>num_bytes
) || (len
== -1))
158 if (!prom_getproperty(prom_root_node
, "idprom", idbuf
, num_bytes
))
164 int prom_get_mmu_ihandle(void)
169 if (prom_mmu_ihandle_cache
!= 0)
170 return prom_mmu_ihandle_cache
;
172 node
= prom_finddevice(prom_chosen_path
);
173 ret
= prom_getint(node
, prom_mmu_name
);
174 if (ret
== -1 || ret
== 0)
175 prom_mmu_ihandle_cache
= -1;
177 prom_mmu_ihandle_cache
= ret
;
182 static int prom_get_memory_ihandle(void)
184 static int memory_ihandle_cache
;
188 if (memory_ihandle_cache
!= 0)
189 return memory_ihandle_cache
;
191 node
= prom_finddevice("/chosen");
192 ret
= prom_getint(node
, "memory");
193 if (ret
== -1 || ret
== 0)
194 memory_ihandle_cache
= -1;
196 memory_ihandle_cache
= ret
;
201 /* Load explicit I/D TLB entries. */
202 static long tlb_load(const char *type
, unsigned long index
,
203 unsigned long tte_data
, unsigned long vaddr
)
205 unsigned long args
[9];
207 args
[0] = (unsigned long) prom_callmethod_name
;
210 args
[3] = (unsigned long) type
;
211 args
[4] = (unsigned int) prom_get_mmu_ihandle();
215 args
[8] = (unsigned long) -1;
217 p1275_cmd_direct(args
);
219 return (long) args
[8];
222 long prom_itlb_load(unsigned long index
,
223 unsigned long tte_data
,
226 return tlb_load("SUNW,itlb-load", index
, tte_data
, vaddr
);
229 long prom_dtlb_load(unsigned long index
,
230 unsigned long tte_data
,
233 return tlb_load("SUNW,dtlb-load", index
, tte_data
, vaddr
);
236 int prom_map(int mode
, unsigned long size
,
237 unsigned long vaddr
, unsigned long paddr
)
239 unsigned long args
[11];
242 args
[0] = (unsigned long) prom_callmethod_name
;
245 args
[3] = (unsigned long) prom_map_name
;
246 args
[4] = (unsigned int) prom_get_mmu_ihandle();
247 args
[5] = (unsigned int) mode
;
252 args
[10] = (unsigned long) -1;
254 p1275_cmd_direct(args
);
256 ret
= (int) args
[10];
262 void prom_unmap(unsigned long size
, unsigned long vaddr
)
264 unsigned long args
[7];
266 args
[0] = (unsigned long) prom_callmethod_name
;
269 args
[3] = (unsigned long) prom_unmap_name
;
270 args
[4] = (unsigned int) prom_get_mmu_ihandle();
274 p1275_cmd_direct(args
);
277 /* Set aside physical memory which is not touched or modified
278 * across soft resets.
280 int prom_retain(const char *name
, unsigned long size
,
281 unsigned long align
, unsigned long *paddr
)
283 unsigned long args
[11];
285 args
[0] = (unsigned long) prom_callmethod_name
;
288 args
[3] = (unsigned long) "SUNW,retain";
289 args
[4] = (unsigned int) prom_get_memory_ihandle();
292 args
[7] = (unsigned long) name
;
293 args
[8] = (unsigned long) -1;
294 args
[9] = (unsigned long) -1;
295 args
[10] = (unsigned long) -1;
297 p1275_cmd_direct(args
);
300 return (int) args
[8];
302 /* Next we get "phys_high" then "phys_low". On 64-bit
303 * the phys_high cell is don't care since the phys_low
304 * cell has the full value.
311 /* Get "Unumber" string for the SIMM at the given
312 * memory address. Usually this will be of the form
313 * "Uxxxx" where xxxx is a decimal number which is
314 * etched into the motherboard next to the SIMM slot
317 int prom_getunumber(int syndrome_code
,
318 unsigned long phys_addr
,
319 char *buf
, int buflen
)
321 unsigned long args
[12];
323 args
[0] = (unsigned long) prom_callmethod_name
;
326 args
[3] = (unsigned long) "SUNW,get-unumber";
327 args
[4] = (unsigned int) prom_get_memory_ihandle();
329 args
[6] = (unsigned long) buf
;
332 args
[9] = (unsigned int) syndrome_code
;
333 args
[10] = (unsigned long) -1;
334 args
[11] = (unsigned long) -1;
336 p1275_cmd_direct(args
);
338 return (int) args
[10];
341 /* Power management extensions. */
342 void prom_sleepself(void)
344 unsigned long args
[3];
346 args
[0] = (unsigned long) "SUNW,sleep-self";
349 p1275_cmd_direct(args
);
352 int prom_sleepsystem(void)
354 unsigned long args
[4];
356 args
[0] = (unsigned long) "SUNW,sleep-system";
359 args
[3] = (unsigned long) -1;
360 p1275_cmd_direct(args
);
362 return (int) args
[3];
365 int prom_wakeupsystem(void)
367 unsigned long args
[4];
369 args
[0] = (unsigned long) "SUNW,wakeup-system";
372 args
[3] = (unsigned long) -1;
373 p1275_cmd_direct(args
);
375 return (int) args
[3];
379 void prom_startcpu(int cpunode
, unsigned long pc
, unsigned long arg
)
381 unsigned long args
[6];
383 args
[0] = (unsigned long) "SUNW,start-cpu";
386 args
[3] = (unsigned int) cpunode
;
389 p1275_cmd_direct(args
);
392 void prom_startcpu_cpuid(int cpuid
, unsigned long pc
, unsigned long arg
)
394 unsigned long args
[6];
396 args
[0] = (unsigned long) "SUNW,start-cpu-by-cpuid";
399 args
[3] = (unsigned int) cpuid
;
402 p1275_cmd_direct(args
);
405 void prom_stopcpu_cpuid(int cpuid
)
407 unsigned long args
[4];
409 args
[0] = (unsigned long) "SUNW,stop-cpu-by-cpuid";
412 args
[3] = (unsigned int) cpuid
;
413 p1275_cmd_direct(args
);
416 void prom_stopself(void)
418 unsigned long args
[3];
420 args
[0] = (unsigned long) "SUNW,stop-self";
423 p1275_cmd_direct(args
);
426 void prom_idleself(void)
428 unsigned long args
[3];
430 args
[0] = (unsigned long) "SUNW,idle-self";
433 p1275_cmd_direct(args
);
436 void prom_resumecpu(int cpunode
)
438 unsigned long args
[4];
440 args
[0] = (unsigned long) "SUNW,resume-cpu";
443 args
[3] = (unsigned int) cpunode
;
444 p1275_cmd_direct(args
);