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