[SERIAL] Make uart_line_info() correctly tell MMIO from I/O port
[linux-2.6/openmoko-kernel/knife-kernel.git] / arch / sparc64 / prom / misc.c
blob0b4213720d439167e3ba7f59ab5b78849df072d3
1 /* $Id: misc.c,v 1.20 2001/09/21 03:17:07 kanoj Exp $
2 * misc.c: Miscellaneous prom functions that don't belong
3 * anywhere else.
5 * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
6 * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
7 */
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 <asm/openprom.h>
15 #include <asm/oplib.h>
16 #include <asm/system.h>
18 /* Reset and reboot the machine with the command 'bcommand'. */
19 void prom_reboot(const char *bcommand)
21 p1275_cmd("boot", P1275_ARG(0, P1275_ARG_IN_STRING) |
22 P1275_INOUT(1, 0), bcommand);
25 /* Forth evaluate the expression contained in 'fstring'. */
26 void prom_feval(const char *fstring)
28 if (!fstring || fstring[0] == 0)
29 return;
30 p1275_cmd("interpret", P1275_ARG(0, P1275_ARG_IN_STRING) |
31 P1275_INOUT(1, 1), fstring);
34 /* We want to do this more nicely some day. */
35 extern void (*prom_palette)(int);
37 #ifdef CONFIG_SMP
38 extern void smp_capture(void);
39 extern void smp_release(void);
40 #endif
42 /* Drop into the prom, with the chance to continue with the 'go'
43 * prom command.
45 void prom_cmdline(void)
47 unsigned long flags;
49 local_irq_save(flags);
51 if (!serial_console && prom_palette)
52 prom_palette(1);
54 #ifdef CONFIG_SMP
55 smp_capture();
56 #endif
58 p1275_cmd("enter", P1275_INOUT(0, 0));
60 #ifdef CONFIG_SMP
61 smp_release();
62 #endif
64 if (!serial_console && prom_palette)
65 prom_palette(0);
67 local_irq_restore(flags);
70 /* Drop into the prom, but completely terminate the program.
71 * No chance of continuing.
73 void prom_halt(void)
75 again:
76 p1275_cmd("exit", P1275_INOUT(0, 0));
77 goto again; /* PROM is out to get me -DaveM */
80 void prom_halt_power_off(void)
82 p1275_cmd("SUNW,power-off", P1275_INOUT(0, 0));
84 /* if nothing else helps, we just halt */
85 prom_halt();
88 /* Set prom sync handler to call function 'funcp'. */
89 void prom_setcallback(callback_func_t funcp)
91 if (!funcp)
92 return;
93 p1275_cmd("set-callback", P1275_ARG(0, P1275_ARG_IN_FUNCTION) |
94 P1275_INOUT(1, 1), funcp);
97 /* Get the idprom and stuff it into buffer 'idbuf'. Returns the
98 * format type. 'num_bytes' is the number of bytes that your idbuf
99 * has space for. Returns 0xff on error.
101 unsigned char prom_get_idprom(char *idbuf, int num_bytes)
103 int len;
105 len = prom_getproplen(prom_root_node, "idprom");
106 if ((len >num_bytes) || (len == -1))
107 return 0xff;
108 if (!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes))
109 return idbuf[0];
111 return 0xff;
114 /* Install Linux trap table so PROM uses that instead of its own. */
115 void prom_set_trap_table(unsigned long tba)
117 p1275_cmd("SUNW,set-trap-table",
118 (P1275_ARG(0, P1275_ARG_IN_64B) |
119 P1275_INOUT(1, 0)), tba);
122 void prom_set_trap_table_sun4v(unsigned long tba, unsigned long mmfsa)
124 p1275_cmd("SUNW,set-trap-table",
125 (P1275_ARG(0, P1275_ARG_IN_64B) |
126 P1275_ARG(1, P1275_ARG_IN_64B) |
127 P1275_INOUT(2, 0)), tba, mmfsa);
130 int prom_get_mmu_ihandle(void)
132 int node, ret;
134 if (prom_mmu_ihandle_cache != 0)
135 return prom_mmu_ihandle_cache;
137 node = prom_finddevice(prom_chosen_path);
138 ret = prom_getint(node, prom_mmu_name);
139 if (ret == -1 || ret == 0)
140 prom_mmu_ihandle_cache = -1;
141 else
142 prom_mmu_ihandle_cache = ret;
144 return ret;
147 static int prom_get_memory_ihandle(void)
149 static int memory_ihandle_cache;
150 int node, ret;
152 if (memory_ihandle_cache != 0)
153 return memory_ihandle_cache;
155 node = prom_finddevice("/chosen");
156 ret = prom_getint(node, "memory");
157 if (ret == -1 || ret == 0)
158 memory_ihandle_cache = -1;
159 else
160 memory_ihandle_cache = ret;
162 return ret;
165 /* Load explicit I/D TLB entries. */
166 long prom_itlb_load(unsigned long index,
167 unsigned long tte_data,
168 unsigned long vaddr)
170 return p1275_cmd(prom_callmethod_name,
171 (P1275_ARG(0, P1275_ARG_IN_STRING) |
172 P1275_ARG(2, P1275_ARG_IN_64B) |
173 P1275_ARG(3, P1275_ARG_IN_64B) |
174 P1275_INOUT(5, 1)),
175 "SUNW,itlb-load",
176 prom_get_mmu_ihandle(),
177 /* And then our actual args are pushed backwards. */
178 vaddr,
179 tte_data,
180 index);
183 long prom_dtlb_load(unsigned long index,
184 unsigned long tte_data,
185 unsigned long vaddr)
187 return p1275_cmd(prom_callmethod_name,
188 (P1275_ARG(0, P1275_ARG_IN_STRING) |
189 P1275_ARG(2, P1275_ARG_IN_64B) |
190 P1275_ARG(3, P1275_ARG_IN_64B) |
191 P1275_INOUT(5, 1)),
192 "SUNW,dtlb-load",
193 prom_get_mmu_ihandle(),
194 /* And then our actual args are pushed backwards. */
195 vaddr,
196 tte_data,
197 index);
200 int prom_map(int mode, unsigned long size,
201 unsigned long vaddr, unsigned long paddr)
203 int ret = p1275_cmd(prom_callmethod_name,
204 (P1275_ARG(0, P1275_ARG_IN_STRING) |
205 P1275_ARG(3, P1275_ARG_IN_64B) |
206 P1275_ARG(4, P1275_ARG_IN_64B) |
207 P1275_ARG(6, P1275_ARG_IN_64B) |
208 P1275_INOUT(7, 1)),
209 prom_map_name,
210 prom_get_mmu_ihandle(),
211 mode,
212 size,
213 vaddr,
215 paddr);
217 if (ret == 0)
218 ret = -1;
219 return ret;
222 void prom_unmap(unsigned long size, unsigned long vaddr)
224 p1275_cmd(prom_callmethod_name,
225 (P1275_ARG(0, P1275_ARG_IN_STRING) |
226 P1275_ARG(2, P1275_ARG_IN_64B) |
227 P1275_ARG(3, P1275_ARG_IN_64B) |
228 P1275_INOUT(4, 0)),
229 prom_unmap_name,
230 prom_get_mmu_ihandle(),
231 size,
232 vaddr);
235 /* Set aside physical memory which is not touched or modified
236 * across soft resets.
238 unsigned long prom_retain(const char *name,
239 unsigned long pa_low, unsigned long pa_high,
240 long size, long align)
242 /* XXX I don't think we return multiple values correctly.
243 * XXX OBP supposedly returns pa_low/pa_high here, how does
244 * XXX it work?
247 /* If align is zero, the pa_low/pa_high args are passed,
248 * else they are not.
250 if (align == 0)
251 return p1275_cmd("SUNW,retain",
252 (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(5, 2)),
253 name, pa_low, pa_high, size, align);
254 else
255 return p1275_cmd("SUNW,retain",
256 (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(3, 2)),
257 name, size, align);
260 /* Get "Unumber" string for the SIMM at the given
261 * memory address. Usually this will be of the form
262 * "Uxxxx" where xxxx is a decimal number which is
263 * etched into the motherboard next to the SIMM slot
264 * in question.
266 int prom_getunumber(int syndrome_code,
267 unsigned long phys_addr,
268 char *buf, int buflen)
270 return p1275_cmd(prom_callmethod_name,
271 (P1275_ARG(0, P1275_ARG_IN_STRING) |
272 P1275_ARG(3, P1275_ARG_OUT_BUF) |
273 P1275_ARG(6, P1275_ARG_IN_64B) |
274 P1275_INOUT(8, 2)),
275 "SUNW,get-unumber", prom_get_memory_ihandle(),
276 buflen, buf, P1275_SIZE(buflen),
277 0, phys_addr, syndrome_code);
280 /* Power management extensions. */
281 void prom_sleepself(void)
283 p1275_cmd("SUNW,sleep-self", P1275_INOUT(0, 0));
286 int prom_sleepsystem(void)
288 return p1275_cmd("SUNW,sleep-system", P1275_INOUT(0, 1));
291 int prom_wakeupsystem(void)
293 return p1275_cmd("SUNW,wakeup-system", P1275_INOUT(0, 1));
296 #ifdef CONFIG_SMP
297 void prom_startcpu(int cpunode, unsigned long pc, unsigned long arg)
299 p1275_cmd("SUNW,start-cpu", P1275_INOUT(3, 0), cpunode, pc, arg);
302 void prom_startcpu_cpuid(int cpuid, unsigned long pc, unsigned long arg)
304 p1275_cmd("SUNW,start-cpu-by-cpuid", P1275_INOUT(3, 0),
305 cpuid, pc, arg);
308 void prom_stopcpu_cpuid(int cpuid)
310 p1275_cmd("SUNW,stop-cpu-by-cpuid", P1275_INOUT(1, 0),
311 cpuid);
314 void prom_stopself(void)
316 p1275_cmd("SUNW,stop-self", P1275_INOUT(0, 0));
319 void prom_idleself(void)
321 p1275_cmd("SUNW,idle-self", P1275_INOUT(0, 0));
324 void prom_resumecpu(int cpunode)
326 p1275_cmd("SUNW,resume-cpu", P1275_INOUT(1, 0), cpunode);
328 #endif