1 // SPDX-License-Identifier: GPL-2.0
3 * misc.c: Miscellaneous prom functions that don't belong
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 <linux/module.h>
17 #include <asm/openprom.h>
18 #include <asm/oplib.h>
21 static int prom_service_exists(const char *service_name)
23 unsigned long args[5];
25 args[0] = (unsigned long) "test";
28 args[3] = (unsigned long) service_name;
29 args[4] = (unsigned long) -1;
31 p1275_cmd_direct(args);
38 void prom_sun4v_guest_soft_state(void)
40 const char *svc = "SUNW,soft-state-supported";
41 unsigned long args[3];
43 if (!prom_service_exists(svc))
45 args[0] = (unsigned long) svc;
48 p1275_cmd_direct(args);
51 /* Reset and reboot the machine with the command 'bcommand'. */
52 void prom_reboot(const char *bcommand)
54 unsigned long args[4];
56 #ifdef CONFIG_SUN_LDOMS
57 if (ldom_domaining_enabled)
58 ldom_reboot(bcommand);
60 args[0] = (unsigned long) "boot";
63 args[3] = (unsigned long) bcommand;
65 p1275_cmd_direct(args);
68 /* Forth evaluate the expression contained in 'fstring'. */
69 void prom_feval(const char *fstring)
71 unsigned long args[5];
73 if (!fstring || fstring[0] == 0)
75 args[0] = (unsigned long) "interpret";
78 args[3] = (unsigned long) fstring;
79 args[4] = (unsigned long) -1;
81 p1275_cmd_direct(args);
83 EXPORT_SYMBOL(prom_feval);
85 /* Drop into the prom, with the chance to continue with the 'go'
88 void prom_cmdline(void)
90 unsigned long args[3];
93 local_irq_save(flags);
99 args[0] = (unsigned long) "enter";
103 p1275_cmd_direct(args);
109 local_irq_restore(flags);
112 /* Drop into the prom, but completely terminate the program.
113 * No chance of continuing.
115 void notrace prom_halt(void)
117 unsigned long args[3];
119 #ifdef CONFIG_SUN_LDOMS
120 if (ldom_domaining_enabled)
124 args[0] = (unsigned long) "exit";
127 p1275_cmd_direct(args);
128 goto again; /* PROM is out to get me -DaveM */
131 void prom_halt_power_off(void)
133 unsigned long args[3];
135 #ifdef CONFIG_SUN_LDOMS
136 if (ldom_domaining_enabled)
139 args[0] = (unsigned long) "SUNW,power-off";
142 p1275_cmd_direct(args);
144 /* if nothing else helps, we just halt */
148 /* Get the idprom and stuff it into buffer 'idbuf'. Returns the
149 * format type. 'num_bytes' is the number of bytes that your idbuf
150 * has space for. Returns 0xff on error.
152 unsigned char prom_get_idprom(char *idbuf, int num_bytes)
156 len = prom_getproplen(prom_root_node, "idprom");
157 if ((len >num_bytes) || (len == -1))
159 if (!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes))
165 int prom_get_mmu_ihandle(void)
170 if (prom_mmu_ihandle_cache != 0)
171 return prom_mmu_ihandle_cache;
173 node = prom_finddevice(prom_chosen_path);
174 ret = prom_getint(node, prom_mmu_name);
175 if (ret == -1 || ret == 0)
176 prom_mmu_ihandle_cache = -1;
178 prom_mmu_ihandle_cache = ret;
183 static int prom_get_memory_ihandle(void)
185 static int memory_ihandle_cache;
189 if (memory_ihandle_cache != 0)
190 return memory_ihandle_cache;
192 node = prom_finddevice("/chosen");
193 ret = prom_getint(node, "memory");
194 if (ret == -1 || ret == 0)
195 memory_ihandle_cache = -1;
197 memory_ihandle_cache = ret;
202 /* Load explicit I/D TLB entries. */
203 static long tlb_load(const char *type, unsigned long index,
204 unsigned long tte_data, unsigned long vaddr)
206 unsigned long args[9];
208 args[0] = (unsigned long) prom_callmethod_name;
211 args[3] = (unsigned long) type;
212 args[4] = (unsigned int) prom_get_mmu_ihandle();
216 args[8] = (unsigned long) -1;
218 p1275_cmd_direct(args);
220 return (long) args[8];
223 long prom_itlb_load(unsigned long index,
224 unsigned long tte_data,
227 return tlb_load("SUNW,itlb-load", index, tte_data, vaddr);
230 long prom_dtlb_load(unsigned long index,
231 unsigned long tte_data,
234 return tlb_load("SUNW,dtlb-load", index, tte_data, vaddr);
237 int prom_map(int mode, unsigned long size,
238 unsigned long vaddr, unsigned long paddr)
240 unsigned long args[11];
243 args[0] = (unsigned long) prom_callmethod_name;
246 args[3] = (unsigned long) prom_map_name;
247 args[4] = (unsigned int) prom_get_mmu_ihandle();
248 args[5] = (unsigned int) mode;
253 args[10] = (unsigned long) -1;
255 p1275_cmd_direct(args);
257 ret = (int) args[10];
263 void prom_unmap(unsigned long size, unsigned long vaddr)
265 unsigned long args[7];
267 args[0] = (unsigned long) prom_callmethod_name;
270 args[3] = (unsigned long) prom_unmap_name;
271 args[4] = (unsigned int) prom_get_mmu_ihandle();
275 p1275_cmd_direct(args);
278 /* Set aside physical memory which is not touched or modified
279 * across soft resets.
281 int prom_retain(const char *name, unsigned long size,
282 unsigned long align, unsigned long *paddr)
284 unsigned long args[11];
286 args[0] = (unsigned long) prom_callmethod_name;
289 args[3] = (unsigned long) "SUNW,retain";
290 args[4] = (unsigned int) prom_get_memory_ihandle();
293 args[7] = (unsigned long) name;
294 args[8] = (unsigned long) -1;
295 args[9] = (unsigned long) -1;
296 args[10] = (unsigned long) -1;
298 p1275_cmd_direct(args);
301 return (int) args[8];
303 /* Next we get "phys_high" then "phys_low". On 64-bit
304 * the phys_high cell is don't care since the phys_low
305 * cell has the full value.
312 /* Get "Unumber" string for the SIMM at the given
313 * memory address. Usually this will be of the form
314 * "Uxxxx" where xxxx is a decimal number which is
315 * etched into the motherboard next to the SIMM slot
318 int prom_getunumber(int syndrome_code,
319 unsigned long phys_addr,
320 char *buf, int buflen)
322 unsigned long args[12];
324 args[0] = (unsigned long) prom_callmethod_name;
327 args[3] = (unsigned long) "SUNW,get-unumber";
328 args[4] = (unsigned int) prom_get_memory_ihandle();
330 args[6] = (unsigned long) buf;
333 args[9] = (unsigned int) syndrome_code;
334 args[10] = (unsigned long) -1;
335 args[11] = (unsigned long) -1;
337 p1275_cmd_direct(args);
339 return (int) args[10];
342 /* Power management extensions. */
343 void prom_sleepself(void)
345 unsigned long args[3];
347 args[0] = (unsigned long) "SUNW,sleep-self";
350 p1275_cmd_direct(args);
353 int prom_sleepsystem(void)
355 unsigned long args[4];
357 args[0] = (unsigned long) "SUNW,sleep-system";
360 args[3] = (unsigned long) -1;
361 p1275_cmd_direct(args);
363 return (int) args[3];
366 int prom_wakeupsystem(void)
368 unsigned long args[4];
370 args[0] = (unsigned long) "SUNW,wakeup-system";
373 args[3] = (unsigned long) -1;
374 p1275_cmd_direct(args);
376 return (int) args[3];
380 void prom_startcpu(int cpunode, unsigned long pc, unsigned long arg)
382 unsigned long args[6];
384 args[0] = (unsigned long) "SUNW,start-cpu";
387 args[3] = (unsigned int) cpunode;
390 p1275_cmd_direct(args);
393 void prom_startcpu_cpuid(int cpuid, unsigned long pc, unsigned long arg)
395 unsigned long args[6];
397 args[0] = (unsigned long) "SUNW,start-cpu-by-cpuid";
400 args[3] = (unsigned int) cpuid;
403 p1275_cmd_direct(args);
406 void prom_stopcpu_cpuid(int cpuid)
408 unsigned long args[4];
410 args[0] = (unsigned long) "SUNW,stop-cpu-by-cpuid";
413 args[3] = (unsigned int) cpuid;
414 p1275_cmd_direct(args);
417 void prom_stopself(void)
419 unsigned long args[3];
421 args[0] = (unsigned long) "SUNW,stop-self";
424 p1275_cmd_direct(args);
427 void prom_idleself(void)
429 unsigned long args[3];
431 args[0] = (unsigned long) "SUNW,idle-self";
434 p1275_cmd_direct(args);
437 void prom_resumecpu(int cpunode)
439 unsigned long args[4];
441 args[0] = (unsigned long) "SUNW,resume-cpu";
444 args[3] = (unsigned int) cpunode;
445 p1275_cmd_direct(args);