Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
| 4 | * |
| 5 | * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) |
| 6 | * Copyright (C) 1996,1997 Jakub Jelinek (jj@sunsite.mff.cuni.cz) |
| 7 | */ |
| 8 | |
| 9 | #include <linux/config.h> |
| 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 <asm/openprom.h> |
| 16 | #include <asm/oplib.h> |
| 17 | #include <asm/system.h> |
| 18 | |
| 19 | /* Reset and reboot the machine with the command 'bcommand'. */ |
David S. Miller | bff06d5 | 2005-09-22 20:11:33 -0700 | [diff] [blame] | 20 | void prom_reboot(const char *bcommand) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | { |
| 22 | p1275_cmd("boot", P1275_ARG(0, P1275_ARG_IN_STRING) | |
| 23 | P1275_INOUT(1, 0), bcommand); |
| 24 | } |
| 25 | |
| 26 | /* Forth evaluate the expression contained in 'fstring'. */ |
David S. Miller | bff06d5 | 2005-09-22 20:11:33 -0700 | [diff] [blame] | 27 | void prom_feval(const char *fstring) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | { |
| 29 | if (!fstring || fstring[0] == 0) |
| 30 | return; |
| 31 | p1275_cmd("interpret", P1275_ARG(0, P1275_ARG_IN_STRING) | |
| 32 | P1275_INOUT(1, 1), fstring); |
| 33 | } |
| 34 | |
| 35 | /* We want to do this more nicely some day. */ |
| 36 | extern void (*prom_palette)(int); |
| 37 | |
| 38 | #ifdef CONFIG_SMP |
| 39 | extern void smp_capture(void); |
| 40 | extern void smp_release(void); |
| 41 | #endif |
| 42 | |
| 43 | /* Drop into the prom, with the chance to continue with the 'go' |
| 44 | * prom command. |
| 45 | */ |
| 46 | void prom_cmdline(void) |
| 47 | { |
| 48 | unsigned long flags; |
| 49 | |
| 50 | local_irq_save(flags); |
| 51 | |
| 52 | if (!serial_console && prom_palette) |
| 53 | prom_palette(1); |
| 54 | |
| 55 | #ifdef CONFIG_SMP |
| 56 | smp_capture(); |
| 57 | #endif |
| 58 | |
| 59 | p1275_cmd("enter", P1275_INOUT(0, 0)); |
| 60 | |
| 61 | #ifdef CONFIG_SMP |
| 62 | smp_release(); |
| 63 | #endif |
| 64 | |
| 65 | if (!serial_console && prom_palette) |
| 66 | prom_palette(0); |
| 67 | |
| 68 | local_irq_restore(flags); |
| 69 | } |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | /* Drop into the prom, but completely terminate the program. |
| 72 | * No chance of continuing. |
| 73 | */ |
| 74 | void prom_halt(void) |
| 75 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | again: |
| 77 | p1275_cmd("exit", P1275_INOUT(0, 0)); |
| 78 | goto again; /* PROM is out to get me -DaveM */ |
| 79 | } |
| 80 | |
| 81 | void prom_halt_power_off(void) |
| 82 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | p1275_cmd("SUNW,power-off", P1275_INOUT(0, 0)); |
| 84 | |
| 85 | /* if nothing else helps, we just halt */ |
| 86 | prom_halt(); |
| 87 | } |
| 88 | |
| 89 | /* Set prom sync handler to call function 'funcp'. */ |
| 90 | void prom_setcallback(callback_func_t funcp) |
| 91 | { |
| 92 | if (!funcp) |
| 93 | return; |
| 94 | p1275_cmd("set-callback", P1275_ARG(0, P1275_ARG_IN_FUNCTION) | |
| 95 | P1275_INOUT(1, 1), funcp); |
| 96 | } |
| 97 | |
| 98 | /* Get the idprom and stuff it into buffer 'idbuf'. Returns the |
| 99 | * format type. 'num_bytes' is the number of bytes that your idbuf |
| 100 | * has space for. Returns 0xff on error. |
| 101 | */ |
| 102 | unsigned char prom_get_idprom(char *idbuf, int num_bytes) |
| 103 | { |
| 104 | int len; |
| 105 | |
| 106 | len = prom_getproplen(prom_root_node, "idprom"); |
| 107 | if ((len >num_bytes) || (len == -1)) |
| 108 | return 0xff; |
| 109 | if (!prom_getproperty(prom_root_node, "idprom", idbuf, num_bytes)) |
| 110 | return idbuf[0]; |
| 111 | |
| 112 | return 0xff; |
| 113 | } |
| 114 | |
| 115 | /* Get the major prom version number. */ |
| 116 | int prom_version(void) |
| 117 | { |
| 118 | return PROM_P1275; |
| 119 | } |
| 120 | |
| 121 | /* Get the prom plugin-revision. */ |
| 122 | int prom_getrev(void) |
| 123 | { |
| 124 | return prom_rev; |
| 125 | } |
| 126 | |
| 127 | /* Get the prom firmware print revision. */ |
| 128 | int prom_getprev(void) |
| 129 | { |
| 130 | return prom_prev; |
| 131 | } |
| 132 | |
| 133 | /* Install Linux trap table so PROM uses that instead of its own. */ |
| 134 | void prom_set_trap_table(unsigned long tba) |
| 135 | { |
| 136 | p1275_cmd("SUNW,set-trap-table", P1275_INOUT(1, 0), tba); |
| 137 | } |
| 138 | |
David S. Miller | 12eaa32 | 2006-02-10 15:39:51 -0800 | [diff] [blame] | 139 | void prom_set_trap_table_sun4v(unsigned long tba, unsigned long mmfsa) |
| 140 | { |
| 141 | p1275_cmd("SUNW,set-trap-table", P1275_INOUT(2, 0), tba, mmfsa); |
| 142 | } |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | int prom_get_mmu_ihandle(void) |
| 145 | { |
| 146 | int node, ret; |
| 147 | |
David S. Miller | bff06d5 | 2005-09-22 20:11:33 -0700 | [diff] [blame] | 148 | if (prom_mmu_ihandle_cache != 0) |
| 149 | return prom_mmu_ihandle_cache; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
David S. Miller | bff06d5 | 2005-09-22 20:11:33 -0700 | [diff] [blame] | 151 | node = prom_finddevice(prom_chosen_path); |
| 152 | ret = prom_getint(node, prom_mmu_name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | if (ret == -1 || ret == 0) |
David S. Miller | bff06d5 | 2005-09-22 20:11:33 -0700 | [diff] [blame] | 154 | prom_mmu_ihandle_cache = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | else |
David S. Miller | bff06d5 | 2005-09-22 20:11:33 -0700 | [diff] [blame] | 156 | prom_mmu_ihandle_cache = ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
| 158 | return ret; |
| 159 | } |
| 160 | |
| 161 | static int prom_get_memory_ihandle(void) |
| 162 | { |
| 163 | static int memory_ihandle_cache; |
| 164 | int node, ret; |
| 165 | |
| 166 | if (memory_ihandle_cache != 0) |
| 167 | return memory_ihandle_cache; |
| 168 | |
| 169 | node = prom_finddevice("/chosen"); |
| 170 | ret = prom_getint(node, "memory"); |
| 171 | if (ret == -1 || ret == 0) |
| 172 | memory_ihandle_cache = -1; |
| 173 | else |
| 174 | memory_ihandle_cache = ret; |
| 175 | |
| 176 | return ret; |
| 177 | } |
| 178 | |
| 179 | /* Load explicit I/D TLB entries. */ |
| 180 | long prom_itlb_load(unsigned long index, |
| 181 | unsigned long tte_data, |
| 182 | unsigned long vaddr) |
| 183 | { |
David S. Miller | bff06d5 | 2005-09-22 20:11:33 -0700 | [diff] [blame] | 184 | return p1275_cmd(prom_callmethod_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | (P1275_ARG(0, P1275_ARG_IN_STRING) | |
| 186 | P1275_ARG(2, P1275_ARG_IN_64B) | |
| 187 | P1275_ARG(3, P1275_ARG_IN_64B) | |
| 188 | P1275_INOUT(5, 1)), |
| 189 | "SUNW,itlb-load", |
| 190 | prom_get_mmu_ihandle(), |
| 191 | /* And then our actual args are pushed backwards. */ |
| 192 | vaddr, |
| 193 | tte_data, |
| 194 | index); |
| 195 | } |
| 196 | |
| 197 | long prom_dtlb_load(unsigned long index, |
| 198 | unsigned long tte_data, |
| 199 | unsigned long vaddr) |
| 200 | { |
David S. Miller | bff06d5 | 2005-09-22 20:11:33 -0700 | [diff] [blame] | 201 | return p1275_cmd(prom_callmethod_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | (P1275_ARG(0, P1275_ARG_IN_STRING) | |
| 203 | P1275_ARG(2, P1275_ARG_IN_64B) | |
| 204 | P1275_ARG(3, P1275_ARG_IN_64B) | |
| 205 | P1275_INOUT(5, 1)), |
| 206 | "SUNW,dtlb-load", |
| 207 | prom_get_mmu_ihandle(), |
| 208 | /* And then our actual args are pushed backwards. */ |
| 209 | vaddr, |
| 210 | tte_data, |
| 211 | index); |
| 212 | } |
| 213 | |
| 214 | int prom_map(int mode, unsigned long size, |
| 215 | unsigned long vaddr, unsigned long paddr) |
| 216 | { |
David S. Miller | bff06d5 | 2005-09-22 20:11:33 -0700 | [diff] [blame] | 217 | int ret = p1275_cmd(prom_callmethod_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | (P1275_ARG(0, P1275_ARG_IN_STRING) | |
| 219 | P1275_ARG(3, P1275_ARG_IN_64B) | |
| 220 | P1275_ARG(4, P1275_ARG_IN_64B) | |
| 221 | P1275_ARG(6, P1275_ARG_IN_64B) | |
| 222 | P1275_INOUT(7, 1)), |
David S. Miller | bff06d5 | 2005-09-22 20:11:33 -0700 | [diff] [blame] | 223 | prom_map_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | prom_get_mmu_ihandle(), |
| 225 | mode, |
| 226 | size, |
| 227 | vaddr, |
| 228 | 0, |
| 229 | paddr); |
| 230 | |
| 231 | if (ret == 0) |
| 232 | ret = -1; |
| 233 | return ret; |
| 234 | } |
| 235 | |
| 236 | void prom_unmap(unsigned long size, unsigned long vaddr) |
| 237 | { |
David S. Miller | bff06d5 | 2005-09-22 20:11:33 -0700 | [diff] [blame] | 238 | p1275_cmd(prom_callmethod_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | (P1275_ARG(0, P1275_ARG_IN_STRING) | |
| 240 | P1275_ARG(2, P1275_ARG_IN_64B) | |
| 241 | P1275_ARG(3, P1275_ARG_IN_64B) | |
| 242 | P1275_INOUT(4, 0)), |
David S. Miller | bff06d5 | 2005-09-22 20:11:33 -0700 | [diff] [blame] | 243 | prom_unmap_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | prom_get_mmu_ihandle(), |
| 245 | size, |
| 246 | vaddr); |
| 247 | } |
| 248 | |
| 249 | /* Set aside physical memory which is not touched or modified |
| 250 | * across soft resets. |
| 251 | */ |
David S. Miller | bff06d5 | 2005-09-22 20:11:33 -0700 | [diff] [blame] | 252 | unsigned long prom_retain(const char *name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | unsigned long pa_low, unsigned long pa_high, |
| 254 | long size, long align) |
| 255 | { |
| 256 | /* XXX I don't think we return multiple values correctly. |
| 257 | * XXX OBP supposedly returns pa_low/pa_high here, how does |
| 258 | * XXX it work? |
| 259 | */ |
| 260 | |
| 261 | /* If align is zero, the pa_low/pa_high args are passed, |
| 262 | * else they are not. |
| 263 | */ |
| 264 | if (align == 0) |
| 265 | return p1275_cmd("SUNW,retain", |
| 266 | (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(5, 2)), |
| 267 | name, pa_low, pa_high, size, align); |
| 268 | else |
| 269 | return p1275_cmd("SUNW,retain", |
| 270 | (P1275_ARG(0, P1275_ARG_IN_BUF) | P1275_INOUT(3, 2)), |
| 271 | name, size, align); |
| 272 | } |
| 273 | |
| 274 | /* Get "Unumber" string for the SIMM at the given |
| 275 | * memory address. Usually this will be of the form |
| 276 | * "Uxxxx" where xxxx is a decimal number which is |
| 277 | * etched into the motherboard next to the SIMM slot |
| 278 | * in question. |
| 279 | */ |
| 280 | int prom_getunumber(int syndrome_code, |
| 281 | unsigned long phys_addr, |
| 282 | char *buf, int buflen) |
| 283 | { |
David S. Miller | bff06d5 | 2005-09-22 20:11:33 -0700 | [diff] [blame] | 284 | return p1275_cmd(prom_callmethod_name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | (P1275_ARG(0, P1275_ARG_IN_STRING) | |
| 286 | P1275_ARG(3, P1275_ARG_OUT_BUF) | |
| 287 | P1275_ARG(6, P1275_ARG_IN_64B) | |
| 288 | P1275_INOUT(8, 2)), |
| 289 | "SUNW,get-unumber", prom_get_memory_ihandle(), |
| 290 | buflen, buf, P1275_SIZE(buflen), |
| 291 | 0, phys_addr, syndrome_code); |
| 292 | } |
| 293 | |
| 294 | /* Power management extensions. */ |
| 295 | void prom_sleepself(void) |
| 296 | { |
| 297 | p1275_cmd("SUNW,sleep-self", P1275_INOUT(0, 0)); |
| 298 | } |
| 299 | |
| 300 | int prom_sleepsystem(void) |
| 301 | { |
| 302 | return p1275_cmd("SUNW,sleep-system", P1275_INOUT(0, 1)); |
| 303 | } |
| 304 | |
| 305 | int prom_wakeupsystem(void) |
| 306 | { |
| 307 | return p1275_cmd("SUNW,wakeup-system", P1275_INOUT(0, 1)); |
| 308 | } |
| 309 | |
| 310 | #ifdef CONFIG_SMP |
David S. Miller | 7890f79 | 2006-02-15 02:26:54 -0800 | [diff] [blame^] | 311 | void prom_startcpu(int cpunode, unsigned long pc, unsigned long arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | { |
David S. Miller | 7890f79 | 2006-02-15 02:26:54 -0800 | [diff] [blame^] | 313 | p1275_cmd("SUNW,start-cpu", P1275_INOUT(3, 0), cpunode, pc, arg); |
| 314 | } |
| 315 | |
| 316 | void prom_startcpu_cpuid(int cpuid, unsigned long pc, unsigned long arg) |
| 317 | { |
| 318 | p1275_cmd("SUNW,start-cpu-by-cpuid", P1275_INOUT(3, 0), |
| 319 | cpuid, pc, arg); |
| 320 | } |
| 321 | |
| 322 | void prom_stopcpu_cpuid(int cpuid) |
| 323 | { |
| 324 | p1275_cmd("SUNW,stop-cpu-by-cpuid", P1275_INOUT(1, 0), |
| 325 | cpuid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | void prom_stopself(void) |
| 329 | { |
| 330 | p1275_cmd("SUNW,stop-self", P1275_INOUT(0, 0)); |
| 331 | } |
| 332 | |
| 333 | void prom_idleself(void) |
| 334 | { |
| 335 | p1275_cmd("SUNW,idle-self", P1275_INOUT(0, 0)); |
| 336 | } |
| 337 | |
| 338 | void prom_resumecpu(int cpunode) |
| 339 | { |
| 340 | p1275_cmd("SUNW,resume-cpu", P1275_INOUT(1, 0), cpunode); |
| 341 | } |
| 342 | #endif |