blob: aed94cd4a1e738c7020856a2a3b0f80c0fae8fb8 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Adrian Bunkb00dc832008-05-19 16:52:27 -07002/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * misc.c: Miscellaneous prom functions that don't belong
4 * anywhere else.
5 *
6 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
7 * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
8 */
9
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <linux/types.h>
11#include <linux/kernel.h>
12#include <linux/sched.h>
13#include <linux/interrupt.h>
14#include <linux/delay.h>
Sam Ravnborg917c3662009-01-08 16:58:20 -080015#include <linux/module.h>
16
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/openprom.h>
18#include <asm/oplib.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/* Drop into the prom, with the chance to continue with the 'go'
86 * prom command.
87 */
88void prom_cmdline(void)
89{
David S. Miller25edd692010-08-23 23:10:57 -070090 unsigned long args[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 unsigned long flags;
92
93 local_irq_save(flags);
94
Linus Torvalds1da177e2005-04-16 15:20:36 -070095#ifdef CONFIG_SMP
96 smp_capture();
97#endif
98
David S. Miller25edd692010-08-23 23:10:57 -070099 args[0] = (unsigned long) "enter";
100 args[1] = 0;
101 args[2] = 0;
102
103 p1275_cmd_direct(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105#ifdef CONFIG_SMP
106 smp_release();
107#endif
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 local_irq_restore(flags);
110}
111
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112/* Drop into the prom, but completely terminate the program.
113 * No chance of continuing.
114 */
David S. Millerbd4352c2009-09-04 03:38:54 -0700115void notrace prom_halt(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116{
David S. Miller25edd692010-08-23 23:10:57 -0700117 unsigned long args[3];
118
David S. Miller4f0234f2007-07-13 16:03:42 -0700119#ifdef CONFIG_SUN_LDOMS
120 if (ldom_domaining_enabled)
121 ldom_power_off();
122#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123again:
David S. Miller25edd692010-08-23 23:10:57 -0700124 args[0] = (unsigned long) "exit";
125 args[1] = 0;
126 args[2] = 0;
127 p1275_cmd_direct(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 goto again; /* PROM is out to get me -DaveM */
129}
130
131void prom_halt_power_off(void)
132{
David S. Miller25edd692010-08-23 23:10:57 -0700133 unsigned long args[3];
134
David S. Miller4f0234f2007-07-13 16:03:42 -0700135#ifdef CONFIG_SUN_LDOMS
136 if (ldom_domaining_enabled)
137 ldom_power_off();
138#endif
David S. Miller25edd692010-08-23 23:10:57 -0700139 args[0] = (unsigned long) "SUNW,power-off";
140 args[1] = 0;
141 args[2] = 0;
142 p1275_cmd_direct(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144 /* if nothing else helps, we just halt */
145 prom_halt();
146}
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148/* 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.
151 */
152unsigned char prom_get_idprom(char *idbuf, int num_bytes)
153{
154 int len;
155
156 len = prom_getproplen(prom_root_node, "idprom");
157 if ((len >num_bytes) || (len == -1))
158 return 0xff;
159 if (!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes))
160 return idbuf[0];
161
162 return 0xff;
163}
164
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165int prom_get_mmu_ihandle(void)
166{
Andres Salomon8d125562010-10-08 14:18:11 -0700167 phandle node;
168 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
David S. Millerbff06d52005-09-22 20:11:33 -0700170 if (prom_mmu_ihandle_cache != 0)
171 return prom_mmu_ihandle_cache;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
David S. Millerbff06d52005-09-22 20:11:33 -0700173 node = prom_finddevice(prom_chosen_path);
174 ret = prom_getint(node, prom_mmu_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 if (ret == -1 || ret == 0)
David S. Millerbff06d52005-09-22 20:11:33 -0700176 prom_mmu_ihandle_cache = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 else
David S. Millerbff06d52005-09-22 20:11:33 -0700178 prom_mmu_ihandle_cache = ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180 return ret;
181}
182
183static int prom_get_memory_ihandle(void)
184{
185 static int memory_ihandle_cache;
Andres Salomon8d125562010-10-08 14:18:11 -0700186 phandle node;
187 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189 if (memory_ihandle_cache != 0)
190 return memory_ihandle_cache;
191
192 node = prom_finddevice("/chosen");
193 ret = prom_getint(node, "memory");
194 if (ret == -1 || ret == 0)
195 memory_ihandle_cache = -1;
196 else
197 memory_ihandle_cache = ret;
198
199 return ret;
200}
201
202/* Load explicit I/D TLB entries. */
David S. Miller25edd692010-08-23 23:10:57 -0700203static long tlb_load(const char *type, unsigned long index,
204 unsigned long tte_data, unsigned long vaddr)
205{
206 unsigned long args[9];
207
208 args[0] = (unsigned long) prom_callmethod_name;
209 args[1] = 5;
210 args[2] = 1;
211 args[3] = (unsigned long) type;
212 args[4] = (unsigned int) prom_get_mmu_ihandle();
213 args[5] = vaddr;
214 args[6] = tte_data;
215 args[7] = index;
216 args[8] = (unsigned long) -1;
217
218 p1275_cmd_direct(args);
219
220 return (long) args[8];
221}
222
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223long prom_itlb_load(unsigned long index,
224 unsigned long tte_data,
225 unsigned long vaddr)
226{
David S. Miller25edd692010-08-23 23:10:57 -0700227 return tlb_load("SUNW,itlb-load", index, tte_data, vaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228}
229
230long prom_dtlb_load(unsigned long index,
231 unsigned long tte_data,
232 unsigned long vaddr)
233{
David S. Miller25edd692010-08-23 23:10:57 -0700234 return tlb_load("SUNW,dtlb-load", index, tte_data, vaddr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235}
236
237int prom_map(int mode, unsigned long size,
238 unsigned long vaddr, unsigned long paddr)
239{
David S. Miller25edd692010-08-23 23:10:57 -0700240 unsigned long args[11];
241 int ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
David S. Miller25edd692010-08-23 23:10:57 -0700243 args[0] = (unsigned long) prom_callmethod_name;
244 args[1] = 7;
245 args[2] = 1;
246 args[3] = (unsigned long) prom_map_name;
247 args[4] = (unsigned int) prom_get_mmu_ihandle();
248 args[5] = (unsigned int) mode;
249 args[6] = size;
250 args[7] = vaddr;
251 args[8] = 0;
252 args[9] = paddr;
253 args[10] = (unsigned long) -1;
254
255 p1275_cmd_direct(args);
256
257 ret = (int) args[10];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 if (ret == 0)
259 ret = -1;
260 return ret;
261}
262
263void prom_unmap(unsigned long size, unsigned long vaddr)
264{
David S. Miller25edd692010-08-23 23:10:57 -0700265 unsigned long args[7];
266
267 args[0] = (unsigned long) prom_callmethod_name;
268 args[1] = 4;
269 args[2] = 0;
270 args[3] = (unsigned long) prom_unmap_name;
271 args[4] = (unsigned int) prom_get_mmu_ihandle();
272 args[5] = size;
273 args[6] = vaddr;
274
275 p1275_cmd_direct(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276}
277
278/* Set aside physical memory which is not touched or modified
279 * across soft resets.
280 */
David S. Miller25edd692010-08-23 23:10:57 -0700281int prom_retain(const char *name, unsigned long size,
282 unsigned long align, unsigned long *paddr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
David S. Miller25edd692010-08-23 23:10:57 -0700284 unsigned long args[11];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
David S. Miller25edd692010-08-23 23:10:57 -0700286 args[0] = (unsigned long) prom_callmethod_name;
287 args[1] = 5;
288 args[2] = 3;
289 args[3] = (unsigned long) "SUNW,retain";
290 args[4] = (unsigned int) prom_get_memory_ihandle();
291 args[5] = align;
292 args[6] = size;
293 args[7] = (unsigned long) name;
294 args[8] = (unsigned long) -1;
295 args[9] = (unsigned long) -1;
296 args[10] = (unsigned long) -1;
297
298 p1275_cmd_direct(args);
299
300 if (args[8])
301 return (int) args[8];
302
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.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 */
David S. Miller25edd692010-08-23 23:10:57 -0700307 *paddr = args[10];
308
309 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310}
311
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
316 * in question.
317 */
318int prom_getunumber(int syndrome_code,
319 unsigned long phys_addr,
320 char *buf, int buflen)
321{
David S. Miller25edd692010-08-23 23:10:57 -0700322 unsigned long args[12];
323
324 args[0] = (unsigned long) prom_callmethod_name;
325 args[1] = 7;
326 args[2] = 2;
327 args[3] = (unsigned long) "SUNW,get-unumber";
328 args[4] = (unsigned int) prom_get_memory_ihandle();
329 args[5] = buflen;
330 args[6] = (unsigned long) buf;
331 args[7] = 0;
332 args[8] = phys_addr;
333 args[9] = (unsigned int) syndrome_code;
334 args[10] = (unsigned long) -1;
335 args[11] = (unsigned long) -1;
336
337 p1275_cmd_direct(args);
338
339 return (int) args[10];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340}
341
342/* Power management extensions. */
343void prom_sleepself(void)
344{
David S. Miller25edd692010-08-23 23:10:57 -0700345 unsigned long args[3];
346
347 args[0] = (unsigned long) "SUNW,sleep-self";
348 args[1] = 0;
349 args[2] = 0;
350 p1275_cmd_direct(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351}
352
353int prom_sleepsystem(void)
354{
David S. Miller25edd692010-08-23 23:10:57 -0700355 unsigned long args[4];
356
357 args[0] = (unsigned long) "SUNW,sleep-system";
358 args[1] = 0;
359 args[2] = 1;
360 args[3] = (unsigned long) -1;
361 p1275_cmd_direct(args);
362
363 return (int) args[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364}
365
366int prom_wakeupsystem(void)
367{
David S. Miller25edd692010-08-23 23:10:57 -0700368 unsigned long args[4];
369
370 args[0] = (unsigned long) "SUNW,wakeup-system";
371 args[1] = 0;
372 args[2] = 1;
373 args[3] = (unsigned long) -1;
374 p1275_cmd_direct(args);
375
376 return (int) args[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377}
378
379#ifdef CONFIG_SMP
David S. Miller7890f792006-02-15 02:26:54 -0800380void prom_startcpu(int cpunode, unsigned long pc, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381{
David S. Miller25edd692010-08-23 23:10:57 -0700382 unsigned long args[6];
383
384 args[0] = (unsigned long) "SUNW,start-cpu";
385 args[1] = 3;
386 args[2] = 0;
387 args[3] = (unsigned int) cpunode;
388 args[4] = pc;
389 args[5] = arg;
390 p1275_cmd_direct(args);
David S. Miller7890f792006-02-15 02:26:54 -0800391}
392
393void prom_startcpu_cpuid(int cpuid, unsigned long pc, unsigned long arg)
394{
David S. Miller25edd692010-08-23 23:10:57 -0700395 unsigned long args[6];
396
397 args[0] = (unsigned long) "SUNW,start-cpu-by-cpuid";
398 args[1] = 3;
399 args[2] = 0;
400 args[3] = (unsigned int) cpuid;
401 args[4] = pc;
402 args[5] = arg;
403 p1275_cmd_direct(args);
David S. Miller7890f792006-02-15 02:26:54 -0800404}
405
406void prom_stopcpu_cpuid(int cpuid)
407{
David S. Miller25edd692010-08-23 23:10:57 -0700408 unsigned long args[4];
409
410 args[0] = (unsigned long) "SUNW,stop-cpu-by-cpuid";
411 args[1] = 1;
412 args[2] = 0;
413 args[3] = (unsigned int) cpuid;
414 p1275_cmd_direct(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415}
416
417void prom_stopself(void)
418{
David S. Miller25edd692010-08-23 23:10:57 -0700419 unsigned long args[3];
420
421 args[0] = (unsigned long) "SUNW,stop-self";
422 args[1] = 0;
423 args[2] = 0;
424 p1275_cmd_direct(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425}
426
427void prom_idleself(void)
428{
David S. Miller25edd692010-08-23 23:10:57 -0700429 unsigned long args[3];
430
431 args[0] = (unsigned long) "SUNW,idle-self";
432 args[1] = 0;
433 args[2] = 0;
434 p1275_cmd_direct(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435}
436
437void prom_resumecpu(int cpunode)
438{
David S. Miller25edd692010-08-23 23:10:57 -0700439 unsigned long args[4];
440
441 args[0] = (unsigned long) "SUNW,resume-cpu";
442 args[1] = 1;
443 args[2] = 0;
444 args[3] = (unsigned int) cpunode;
445 p1275_cmd_direct(args);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446}
447#endif