Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Procedures for interfacing to Open Firmware. |
| 3 | * |
| 4 | * Paul Mackerras August 1996. |
| 5 | * Copyright (C) 1996-2005 Paul Mackerras. |
| 6 | * |
| 7 | * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner. |
| 8 | * {engebret|bergner}@us.ibm.com |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License |
| 12 | * as published by the Free Software Foundation; either version |
| 13 | * 2 of the License, or (at your option) any later version. |
| 14 | */ |
| 15 | |
| 16 | #undef DEBUG_PROM |
| 17 | |
| 18 | #include <stdarg.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 19 | #include <linux/kernel.h> |
| 20 | #include <linux/string.h> |
| 21 | #include <linux/init.h> |
| 22 | #include <linux/threads.h> |
| 23 | #include <linux/spinlock.h> |
| 24 | #include <linux/types.h> |
| 25 | #include <linux/pci.h> |
| 26 | #include <linux/proc_fs.h> |
| 27 | #include <linux/stringify.h> |
| 28 | #include <linux/delay.h> |
| 29 | #include <linux/initrd.h> |
| 30 | #include <linux/bitops.h> |
| 31 | #include <asm/prom.h> |
| 32 | #include <asm/rtas.h> |
| 33 | #include <asm/page.h> |
| 34 | #include <asm/processor.h> |
| 35 | #include <asm/irq.h> |
| 36 | #include <asm/io.h> |
| 37 | #include <asm/smp.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 38 | #include <asm/mmu.h> |
| 39 | #include <asm/pgtable.h> |
| 40 | #include <asm/pci.h> |
| 41 | #include <asm/iommu.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 42 | #include <asm/btext.h> |
| 43 | #include <asm/sections.h> |
| 44 | #include <asm/machdep.h> |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 45 | #include <asm/opal.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 46 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 47 | #include <linux/linux_logo.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 48 | |
| 49 | /* |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 50 | * Eventually bump that one up |
| 51 | */ |
| 52 | #define DEVTREE_CHUNK_SIZE 0x100000 |
| 53 | |
| 54 | /* |
| 55 | * This is the size of the local memory reserve map that gets copied |
| 56 | * into the boot params passed to the kernel. That size is totally |
| 57 | * flexible as the kernel just reads the list until it encounters an |
| 58 | * entry with size 0, so it can be changed without breaking binary |
| 59 | * compatibility |
| 60 | */ |
| 61 | #define MEM_RESERVE_MAP_SIZE 8 |
| 62 | |
| 63 | /* |
| 64 | * prom_init() is called very early on, before the kernel text |
| 65 | * and data have been mapped to KERNELBASE. At this point the code |
| 66 | * is running at whatever address it has been loaded at. |
| 67 | * On ppc32 we compile with -mrelocatable, which means that references |
| 68 | * to extern and static variables get relocated automatically. |
Anton Blanchard | 5ac47f7 | 2012-11-26 17:39:03 +0000 | [diff] [blame] | 69 | * ppc64 objects are always relocatable, we just need to relocate the |
| 70 | * TOC. |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 71 | * |
| 72 | * Because OF may have mapped I/O devices into the area starting at |
| 73 | * KERNELBASE, particularly on CHRP machines, we can't safely call |
| 74 | * OF once the kernel has been mapped to KERNELBASE. Therefore all |
| 75 | * OF calls must be done within prom_init(). |
| 76 | * |
| 77 | * ADDR is used in calls to call_prom. The 4th and following |
| 78 | * arguments to call_prom should be 32-bit values. |
| 79 | * On ppc64, 64 bit values are truncated to 32 bits (and |
| 80 | * fortunately don't get interpreted as two arguments). |
| 81 | */ |
Anton Blanchard | 5ac47f7 | 2012-11-26 17:39:03 +0000 | [diff] [blame] | 82 | #define ADDR(x) (u32)(unsigned long)(x) |
| 83 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 84 | #ifdef CONFIG_PPC64 |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 85 | #define OF_WORKAROUNDS 0 |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 86 | #else |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 87 | #define OF_WORKAROUNDS of_workarounds |
| 88 | int of_workarounds; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 89 | #endif |
| 90 | |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 91 | #define OF_WA_CLAIM 1 /* do phys/virt claim separately, then map */ |
| 92 | #define OF_WA_LONGTRAIL 2 /* work around longtrail bugs */ |
| 93 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 94 | #define PROM_BUG() do { \ |
| 95 | prom_printf("kernel BUG at %s line 0x%x!\n", \ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 96 | __FILE__, __LINE__); \ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 97 | __asm__ __volatile__(".long " BUG_ILLEGAL_INSTR); \ |
| 98 | } while (0) |
| 99 | |
| 100 | #ifdef DEBUG_PROM |
| 101 | #define prom_debug(x...) prom_printf(x) |
| 102 | #else |
| 103 | #define prom_debug(x...) |
| 104 | #endif |
| 105 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 106 | |
| 107 | typedef u32 prom_arg_t; |
| 108 | |
| 109 | struct prom_args { |
| 110 | u32 service; |
| 111 | u32 nargs; |
| 112 | u32 nret; |
| 113 | prom_arg_t args[10]; |
| 114 | }; |
| 115 | |
| 116 | struct prom_t { |
| 117 | ihandle root; |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 118 | phandle chosen; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 119 | int cpu; |
| 120 | ihandle stdout; |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 121 | ihandle mmumap; |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 122 | ihandle memory; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | struct mem_map_entry { |
Kumar Gala | cbbcf34 | 2006-01-11 17:57:13 -0600 | [diff] [blame] | 126 | u64 base; |
| 127 | u64 size; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | typedef u32 cell_t; |
| 131 | |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 132 | extern void __start(unsigned long r3, unsigned long r4, unsigned long r5, |
| 133 | unsigned long r6, unsigned long r7, unsigned long r8, |
| 134 | unsigned long r9); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 135 | |
| 136 | #ifdef CONFIG_PPC64 |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 137 | extern int enter_prom(struct prom_args *args, unsigned long entry); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 138 | #else |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 139 | static inline int enter_prom(struct prom_args *args, unsigned long entry) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 140 | { |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 141 | return ((int (*)(struct prom_args *))entry)(args); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 142 | } |
| 143 | #endif |
| 144 | |
| 145 | extern void copy_and_flush(unsigned long dest, unsigned long src, |
| 146 | unsigned long size, unsigned long offset); |
| 147 | |
| 148 | /* prom structure */ |
| 149 | static struct prom_t __initdata prom; |
| 150 | |
| 151 | static unsigned long prom_entry __initdata; |
| 152 | |
| 153 | #define PROM_SCRATCH_SIZE 256 |
| 154 | |
| 155 | static char __initdata of_stdout_device[256]; |
| 156 | static char __initdata prom_scratch[PROM_SCRATCH_SIZE]; |
| 157 | |
| 158 | static unsigned long __initdata dt_header_start; |
| 159 | static unsigned long __initdata dt_struct_start, dt_struct_end; |
| 160 | static unsigned long __initdata dt_string_start, dt_string_end; |
| 161 | |
| 162 | static unsigned long __initdata prom_initrd_start, prom_initrd_end; |
| 163 | |
| 164 | #ifdef CONFIG_PPC64 |
Jeremy Kerr | 165785e | 2006-11-11 17:25:18 +1100 | [diff] [blame] | 165 | static int __initdata prom_iommu_force_on; |
| 166 | static int __initdata prom_iommu_off; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 167 | static unsigned long __initdata prom_tce_alloc_start; |
| 168 | static unsigned long __initdata prom_tce_alloc_end; |
| 169 | #endif |
| 170 | |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 171 | /* Platforms codes are now obsolete in the kernel. Now only used within this |
| 172 | * file and ultimately gone too. Feel free to change them if you need, they |
| 173 | * are not shared with anything outside of this file anymore |
| 174 | */ |
| 175 | #define PLATFORM_PSERIES 0x0100 |
| 176 | #define PLATFORM_PSERIES_LPAR 0x0101 |
| 177 | #define PLATFORM_LPAR 0x0001 |
| 178 | #define PLATFORM_POWERMAC 0x0400 |
| 179 | #define PLATFORM_GENERIC 0x0500 |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 180 | #define PLATFORM_OPAL 0x0600 |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 181 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 182 | static int __initdata of_platform; |
| 183 | |
| 184 | static char __initdata prom_cmd_line[COMMAND_LINE_SIZE]; |
| 185 | |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 186 | static unsigned long __initdata prom_memory_limit; |
| 187 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 188 | static unsigned long __initdata alloc_top; |
| 189 | static unsigned long __initdata alloc_top_high; |
| 190 | static unsigned long __initdata alloc_bottom; |
| 191 | static unsigned long __initdata rmo_top; |
| 192 | static unsigned long __initdata ram_top; |
| 193 | |
| 194 | static struct mem_map_entry __initdata mem_reserve_map[MEM_RESERVE_MAP_SIZE]; |
| 195 | static int __initdata mem_reserve_cnt; |
| 196 | |
| 197 | static cell_t __initdata regbuf[1024]; |
| 198 | |
| 199 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 200 | /* |
| 201 | * Error results ... some OF calls will return "-1" on error, some |
| 202 | * will return 0, some will return either. To simplify, here are |
| 203 | * macros to use with any ihandle or phandle return value to check if |
| 204 | * it is valid |
| 205 | */ |
| 206 | |
| 207 | #define PROM_ERROR (-1u) |
| 208 | #define PHANDLE_VALID(p) ((p) != 0 && (p) != PROM_ERROR) |
| 209 | #define IHANDLE_VALID(i) ((i) != 0 && (i) != PROM_ERROR) |
| 210 | |
| 211 | |
| 212 | /* This is the one and *ONLY* place where we actually call open |
| 213 | * firmware. |
| 214 | */ |
| 215 | |
| 216 | static int __init call_prom(const char *service, int nargs, int nret, ...) |
| 217 | { |
| 218 | int i; |
| 219 | struct prom_args args; |
| 220 | va_list list; |
| 221 | |
| 222 | args.service = ADDR(service); |
| 223 | args.nargs = nargs; |
| 224 | args.nret = nret; |
| 225 | |
| 226 | va_start(list, nret); |
| 227 | for (i = 0; i < nargs; i++) |
| 228 | args.args[i] = va_arg(list, prom_arg_t); |
| 229 | va_end(list); |
| 230 | |
| 231 | for (i = 0; i < nret; i++) |
| 232 | args.args[nargs+i] = 0; |
| 233 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 234 | if (enter_prom(&args, prom_entry) < 0) |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 235 | return PROM_ERROR; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 236 | |
| 237 | return (nret > 0) ? args.args[nargs] : 0; |
| 238 | } |
| 239 | |
| 240 | static int __init call_prom_ret(const char *service, int nargs, int nret, |
| 241 | prom_arg_t *rets, ...) |
| 242 | { |
| 243 | int i; |
| 244 | struct prom_args args; |
| 245 | va_list list; |
| 246 | |
| 247 | args.service = ADDR(service); |
| 248 | args.nargs = nargs; |
| 249 | args.nret = nret; |
| 250 | |
| 251 | va_start(list, rets); |
| 252 | for (i = 0; i < nargs; i++) |
| 253 | args.args[i] = va_arg(list, prom_arg_t); |
| 254 | va_end(list); |
| 255 | |
| 256 | for (i = 0; i < nret; i++) |
Olaf Hering | ed1189b7 | 2005-11-29 14:04:05 +0100 | [diff] [blame] | 257 | args.args[nargs+i] = 0; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 258 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 259 | if (enter_prom(&args, prom_entry) < 0) |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 260 | return PROM_ERROR; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 261 | |
| 262 | if (rets != NULL) |
| 263 | for (i = 1; i < nret; ++i) |
Paul Mackerras | c5200c9 | 2005-10-10 22:57:03 +1000 | [diff] [blame] | 264 | rets[i-1] = args.args[nargs+i]; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 265 | |
| 266 | return (nret > 0) ? args.args[nargs] : 0; |
| 267 | } |
| 268 | |
| 269 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 270 | static void __init prom_print(const char *msg) |
| 271 | { |
| 272 | const char *p, *q; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 273 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 274 | if (prom.stdout == 0) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 275 | return; |
| 276 | |
| 277 | for (p = msg; *p != 0; p = q) { |
| 278 | for (q = p; *q != 0 && *q != '\n'; ++q) |
| 279 | ; |
| 280 | if (q > p) |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 281 | call_prom("write", 3, 1, prom.stdout, p, q - p); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 282 | if (*q == 0) |
| 283 | break; |
| 284 | ++q; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 285 | call_prom("write", 3, 1, prom.stdout, ADDR("\r\n"), 2); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 286 | } |
| 287 | } |
| 288 | |
| 289 | |
| 290 | static void __init prom_print_hex(unsigned long val) |
| 291 | { |
| 292 | int i, nibbles = sizeof(val)*2; |
| 293 | char buf[sizeof(val)*2+1]; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 294 | |
| 295 | for (i = nibbles-1; i >= 0; i--) { |
| 296 | buf[i] = (val & 0xf) + '0'; |
| 297 | if (buf[i] > '9') |
| 298 | buf[i] += ('a'-'0'-10); |
| 299 | val >>= 4; |
| 300 | } |
| 301 | buf[nibbles] = '\0'; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 302 | call_prom("write", 3, 1, prom.stdout, buf, nibbles); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 303 | } |
| 304 | |
Michael Neuling | 2c48a7d | 2010-07-27 18:26:21 +0000 | [diff] [blame] | 305 | /* max number of decimal digits in an unsigned long */ |
| 306 | #define UL_DIGITS 21 |
| 307 | static void __init prom_print_dec(unsigned long val) |
| 308 | { |
| 309 | int i, size; |
| 310 | char buf[UL_DIGITS+1]; |
Michael Neuling | 2c48a7d | 2010-07-27 18:26:21 +0000 | [diff] [blame] | 311 | |
| 312 | for (i = UL_DIGITS-1; i >= 0; i--) { |
| 313 | buf[i] = (val % 10) + '0'; |
| 314 | val = val/10; |
| 315 | if (val == 0) |
| 316 | break; |
| 317 | } |
| 318 | /* shift stuff down */ |
| 319 | size = UL_DIGITS - i; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 320 | call_prom("write", 3, 1, prom.stdout, buf+i, size); |
Michael Neuling | 2c48a7d | 2010-07-27 18:26:21 +0000 | [diff] [blame] | 321 | } |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 322 | |
| 323 | static void __init prom_printf(const char *format, ...) |
| 324 | { |
| 325 | const char *p, *q, *s; |
| 326 | va_list args; |
| 327 | unsigned long v; |
Benjamin Herrenschmidt | af27714 | 2011-04-06 10:51:17 +1000 | [diff] [blame] | 328 | long vs; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 329 | |
| 330 | va_start(args, format); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 331 | for (p = format; *p != 0; p = q) { |
| 332 | for (q = p; *q != 0 && *q != '\n' && *q != '%'; ++q) |
| 333 | ; |
| 334 | if (q > p) |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 335 | call_prom("write", 3, 1, prom.stdout, p, q - p); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 336 | if (*q == 0) |
| 337 | break; |
| 338 | if (*q == '\n') { |
| 339 | ++q; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 340 | call_prom("write", 3, 1, prom.stdout, |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 341 | ADDR("\r\n"), 2); |
| 342 | continue; |
| 343 | } |
| 344 | ++q; |
| 345 | if (*q == 0) |
| 346 | break; |
| 347 | switch (*q) { |
| 348 | case 's': |
| 349 | ++q; |
| 350 | s = va_arg(args, const char *); |
| 351 | prom_print(s); |
| 352 | break; |
| 353 | case 'x': |
| 354 | ++q; |
| 355 | v = va_arg(args, unsigned long); |
| 356 | prom_print_hex(v); |
| 357 | break; |
Benjamin Herrenschmidt | af27714 | 2011-04-06 10:51:17 +1000 | [diff] [blame] | 358 | case 'd': |
| 359 | ++q; |
| 360 | vs = va_arg(args, int); |
| 361 | if (vs < 0) { |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 362 | prom_print("-"); |
Benjamin Herrenschmidt | af27714 | 2011-04-06 10:51:17 +1000 | [diff] [blame] | 363 | vs = -vs; |
| 364 | } |
| 365 | prom_print_dec(vs); |
| 366 | break; |
Michael Neuling | 2c48a7d | 2010-07-27 18:26:21 +0000 | [diff] [blame] | 367 | case 'l': |
| 368 | ++q; |
Benjamin Herrenschmidt | af27714 | 2011-04-06 10:51:17 +1000 | [diff] [blame] | 369 | if (*q == 0) |
| 370 | break; |
| 371 | else if (*q == 'x') { |
| 372 | ++q; |
| 373 | v = va_arg(args, unsigned long); |
| 374 | prom_print_hex(v); |
| 375 | } else if (*q == 'u') { /* '%lu' */ |
Michael Neuling | 2c48a7d | 2010-07-27 18:26:21 +0000 | [diff] [blame] | 376 | ++q; |
| 377 | v = va_arg(args, unsigned long); |
| 378 | prom_print_dec(v); |
Benjamin Herrenschmidt | af27714 | 2011-04-06 10:51:17 +1000 | [diff] [blame] | 379 | } else if (*q == 'd') { /* %ld */ |
| 380 | ++q; |
| 381 | vs = va_arg(args, long); |
| 382 | if (vs < 0) { |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 383 | prom_print("-"); |
Benjamin Herrenschmidt | af27714 | 2011-04-06 10:51:17 +1000 | [diff] [blame] | 384 | vs = -vs; |
| 385 | } |
| 386 | prom_print_dec(vs); |
Michael Neuling | 2c48a7d | 2010-07-27 18:26:21 +0000 | [diff] [blame] | 387 | } |
| 388 | break; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 389 | } |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 394 | static unsigned int __init prom_claim(unsigned long virt, unsigned long size, |
| 395 | unsigned long align) |
| 396 | { |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 397 | |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 398 | if (align == 0 && (OF_WORKAROUNDS & OF_WA_CLAIM)) { |
| 399 | /* |
| 400 | * Old OF requires we claim physical and virtual separately |
| 401 | * and then map explicitly (assuming virtual mode) |
| 402 | */ |
| 403 | int ret; |
| 404 | prom_arg_t result; |
| 405 | |
| 406 | ret = call_prom_ret("call-method", 5, 2, &result, |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 407 | ADDR("claim"), prom.memory, |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 408 | align, size, virt); |
| 409 | if (ret != 0 || result == -1) |
| 410 | return -1; |
| 411 | ret = call_prom_ret("call-method", 5, 2, &result, |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 412 | ADDR("claim"), prom.mmumap, |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 413 | align, size, virt); |
| 414 | if (ret != 0) { |
| 415 | call_prom("call-method", 4, 1, ADDR("release"), |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 416 | prom.memory, size, virt); |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 417 | return -1; |
| 418 | } |
| 419 | /* the 0x12 is M (coherence) + PP == read/write */ |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 420 | call_prom("call-method", 6, 1, |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 421 | ADDR("map"), prom.mmumap, 0x12, size, virt, virt); |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 422 | return virt; |
| 423 | } |
| 424 | return call_prom("claim", 3, 1, (prom_arg_t)virt, (prom_arg_t)size, |
| 425 | (prom_arg_t)align); |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 426 | } |
| 427 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 428 | static void __init __attribute__((noreturn)) prom_panic(const char *reason) |
| 429 | { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 430 | prom_print(reason); |
Olaf Hering | add60ef | 2006-03-23 22:03:57 +0100 | [diff] [blame] | 431 | /* Do not call exit because it clears the screen on pmac |
| 432 | * it also causes some sort of double-fault on early pmacs */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 433 | if (of_platform == PLATFORM_POWERMAC) |
Olaf Hering | add60ef | 2006-03-23 22:03:57 +0100 | [diff] [blame] | 434 | asm("trap\n"); |
| 435 | |
Stephen Rothwell | 1d9a473 | 2012-03-21 18:23:27 +0000 | [diff] [blame] | 436 | /* ToDo: should put up an SRC here on pSeries */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 437 | call_prom("exit", 0, 0); |
| 438 | |
| 439 | for (;;) /* should never get here */ |
| 440 | ; |
| 441 | } |
| 442 | |
| 443 | |
| 444 | static int __init prom_next_node(phandle *nodep) |
| 445 | { |
| 446 | phandle node; |
| 447 | |
| 448 | if ((node = *nodep) != 0 |
| 449 | && (*nodep = call_prom("child", 1, 1, node)) != 0) |
| 450 | return 1; |
| 451 | if ((*nodep = call_prom("peer", 1, 1, node)) != 0) |
| 452 | return 1; |
| 453 | for (;;) { |
| 454 | if ((node = call_prom("parent", 1, 1, node)) == 0) |
| 455 | return 0; |
| 456 | if ((*nodep = call_prom("peer", 1, 1, node)) != 0) |
| 457 | return 1; |
| 458 | } |
| 459 | } |
| 460 | |
Benjamin Herrenschmidt | 21fe330 | 2005-11-07 16:41:59 +1100 | [diff] [blame] | 461 | static int inline prom_getprop(phandle node, const char *pname, |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 462 | void *value, size_t valuelen) |
| 463 | { |
| 464 | return call_prom("getprop", 4, 1, node, ADDR(pname), |
| 465 | (u32)(unsigned long) value, (u32) valuelen); |
| 466 | } |
| 467 | |
Benjamin Herrenschmidt | 21fe330 | 2005-11-07 16:41:59 +1100 | [diff] [blame] | 468 | static int inline prom_getproplen(phandle node, const char *pname) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 469 | { |
| 470 | return call_prom("getproplen", 2, 1, node, ADDR(pname)); |
| 471 | } |
| 472 | |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 473 | static void add_string(char **str, const char *q) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 474 | { |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 475 | char *p = *str; |
| 476 | |
| 477 | while (*q) |
| 478 | *p++ = *q++; |
| 479 | *p++ = ' '; |
| 480 | *str = p; |
| 481 | } |
| 482 | |
| 483 | static char *tohex(unsigned int x) |
| 484 | { |
| 485 | static char digits[] = "0123456789abcdef"; |
| 486 | static char result[9]; |
| 487 | int i; |
| 488 | |
| 489 | result[8] = 0; |
| 490 | i = 8; |
| 491 | do { |
| 492 | --i; |
| 493 | result[i] = digits[x & 0xf]; |
| 494 | x >>= 4; |
| 495 | } while (x != 0 && i > 0); |
| 496 | return &result[i]; |
| 497 | } |
| 498 | |
| 499 | static int __init prom_setprop(phandle node, const char *nodename, |
| 500 | const char *pname, void *value, size_t valuelen) |
| 501 | { |
| 502 | char cmd[256], *p; |
| 503 | |
| 504 | if (!(OF_WORKAROUNDS & OF_WA_LONGTRAIL)) |
| 505 | return call_prom("setprop", 4, 1, node, ADDR(pname), |
| 506 | (u32)(unsigned long) value, (u32) valuelen); |
| 507 | |
| 508 | /* gah... setprop doesn't work on longtrail, have to use interpret */ |
| 509 | p = cmd; |
| 510 | add_string(&p, "dev"); |
| 511 | add_string(&p, nodename); |
| 512 | add_string(&p, tohex((u32)(unsigned long) value)); |
| 513 | add_string(&p, tohex(valuelen)); |
| 514 | add_string(&p, tohex(ADDR(pname))); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 515 | add_string(&p, tohex(strlen(pname))); |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 516 | add_string(&p, "property"); |
| 517 | *p = 0; |
| 518 | return call_prom("interpret", 1, 1, (u32)(unsigned long) cmd); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 519 | } |
| 520 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 521 | /* We can't use the standard versions because of relocation headaches. */ |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 522 | #define isxdigit(c) (('0' <= (c) && (c) <= '9') \ |
| 523 | || ('a' <= (c) && (c) <= 'f') \ |
| 524 | || ('A' <= (c) && (c) <= 'F')) |
| 525 | |
| 526 | #define isdigit(c) ('0' <= (c) && (c) <= '9') |
| 527 | #define islower(c) ('a' <= (c) && (c) <= 'z') |
| 528 | #define toupper(c) (islower(c) ? ((c) - 'a' + 'A') : (c)) |
| 529 | |
| 530 | unsigned long prom_strtoul(const char *cp, const char **endp) |
| 531 | { |
| 532 | unsigned long result = 0, base = 10, value; |
| 533 | |
| 534 | if (*cp == '0') { |
| 535 | base = 8; |
| 536 | cp++; |
| 537 | if (toupper(*cp) == 'X') { |
| 538 | cp++; |
| 539 | base = 16; |
| 540 | } |
| 541 | } |
| 542 | |
| 543 | while (isxdigit(*cp) && |
| 544 | (value = isdigit(*cp) ? *cp - '0' : toupper(*cp) - 'A' + 10) < base) { |
| 545 | result = result * base + value; |
| 546 | cp++; |
| 547 | } |
| 548 | |
| 549 | if (endp) |
| 550 | *endp = cp; |
| 551 | |
| 552 | return result; |
| 553 | } |
| 554 | |
| 555 | unsigned long prom_memparse(const char *ptr, const char **retptr) |
| 556 | { |
| 557 | unsigned long ret = prom_strtoul(ptr, retptr); |
| 558 | int shift = 0; |
| 559 | |
| 560 | /* |
| 561 | * We can't use a switch here because GCC *may* generate a |
| 562 | * jump table which won't work, because we're not running at |
| 563 | * the address we're linked at. |
| 564 | */ |
| 565 | if ('G' == **retptr || 'g' == **retptr) |
| 566 | shift = 30; |
| 567 | |
| 568 | if ('M' == **retptr || 'm' == **retptr) |
| 569 | shift = 20; |
| 570 | |
| 571 | if ('K' == **retptr || 'k' == **retptr) |
| 572 | shift = 10; |
| 573 | |
| 574 | if (shift) { |
| 575 | ret <<= shift; |
| 576 | (*retptr)++; |
| 577 | } |
| 578 | |
| 579 | return ret; |
| 580 | } |
| 581 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 582 | /* |
| 583 | * Early parsing of the command line passed to the kernel, used for |
| 584 | * "mem=x" and the options that affect the iommu |
| 585 | */ |
| 586 | static void __init early_cmdline_parse(void) |
| 587 | { |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 588 | const char *opt; |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 589 | |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 590 | char *p; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 591 | int l = 0; |
| 592 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 593 | prom_cmd_line[0] = 0; |
| 594 | p = prom_cmd_line; |
| 595 | if ((long)prom.chosen > 0) |
| 596 | l = prom_getprop(prom.chosen, "bootargs", p, COMMAND_LINE_SIZE-1); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 597 | #ifdef CONFIG_CMDLINE |
Amos Waterland | 0e4aa9c | 2006-06-12 23:45:02 -0400 | [diff] [blame] | 598 | if (l <= 0 || p[0] == '\0') /* dbl check */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 599 | strlcpy(prom_cmd_line, |
| 600 | CONFIG_CMDLINE, sizeof(prom_cmd_line)); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 601 | #endif /* CONFIG_CMDLINE */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 602 | prom_printf("command line: %s\n", prom_cmd_line); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 603 | |
| 604 | #ifdef CONFIG_PPC64 |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 605 | opt = strstr(prom_cmd_line, "iommu="); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 606 | if (opt) { |
| 607 | prom_printf("iommu opt is: %s\n", opt); |
| 608 | opt += 6; |
| 609 | while (*opt && *opt == ' ') |
| 610 | opt++; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 611 | if (!strncmp(opt, "off", 3)) |
| 612 | prom_iommu_off = 1; |
| 613 | else if (!strncmp(opt, "force", 5)) |
| 614 | prom_iommu_force_on = 1; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 615 | } |
| 616 | #endif |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 617 | opt = strstr(prom_cmd_line, "mem="); |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 618 | if (opt) { |
| 619 | opt += 4; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 620 | prom_memory_limit = prom_memparse(opt, (const char **)&opt); |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 621 | #ifdef CONFIG_PPC64 |
| 622 | /* Align to 16 MB == size of ppc64 large page */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 623 | prom_memory_limit = ALIGN(prom_memory_limit, 0x1000000); |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 624 | #endif |
| 625 | } |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 626 | } |
| 627 | |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 628 | #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 629 | /* |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 630 | * There are two methods for telling firmware what our capabilities are. |
| 631 | * Newer machines have an "ibm,client-architecture-support" method on the |
| 632 | * root node. For older machines, we have to call the "process-elf-header" |
| 633 | * method in the /packages/elf-loader node, passing it a fake 32-bit |
| 634 | * ELF header containing a couple of PT_NOTE sections that contain |
| 635 | * structures that contain various information. |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 636 | */ |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 637 | |
| 638 | /* |
| 639 | * New method - extensible architecture description vector. |
| 640 | * |
| 641 | * Because the description vector contains a mix of byte and word |
| 642 | * values, we declare it as an unsigned char array, and use this |
| 643 | * macro to put word values in. |
| 644 | */ |
| 645 | #define W(x) ((x) >> 24) & 0xff, ((x) >> 16) & 0xff, \ |
| 646 | ((x) >> 8) & 0xff, (x) & 0xff |
| 647 | |
| 648 | /* Option vector bits - generic bits in byte 1 */ |
| 649 | #define OV_IGNORE 0x80 /* ignore this vector */ |
| 650 | #define OV_CESSATION_POLICY 0x40 /* halt if unsupported option present*/ |
| 651 | |
| 652 | /* Option vector 1: processor architectures supported */ |
| 653 | #define OV1_PPC_2_00 0x80 /* set if we support PowerPC 2.00 */ |
| 654 | #define OV1_PPC_2_01 0x40 /* set if we support PowerPC 2.01 */ |
| 655 | #define OV1_PPC_2_02 0x20 /* set if we support PowerPC 2.02 */ |
| 656 | #define OV1_PPC_2_03 0x10 /* set if we support PowerPC 2.03 */ |
| 657 | #define OV1_PPC_2_04 0x08 /* set if we support PowerPC 2.04 */ |
| 658 | #define OV1_PPC_2_05 0x04 /* set if we support PowerPC 2.05 */ |
Joel Schopp | 0cb9901 | 2008-06-19 06:23:23 +1000 | [diff] [blame] | 659 | #define OV1_PPC_2_06 0x02 /* set if we support PowerPC 2.06 */ |
Michael Neuling | df77c79 | 2012-11-08 20:23:11 +0000 | [diff] [blame] | 660 | #define OV1_PPC_2_07 0x01 /* set if we support PowerPC 2.07 */ |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 661 | |
| 662 | /* Option vector 2: Open Firmware options supported */ |
| 663 | #define OV2_REAL_MODE 0x20 /* set if we want OF in real mode */ |
| 664 | |
| 665 | /* Option vector 3: processor options supported */ |
| 666 | #define OV3_FP 0x80 /* floating point */ |
| 667 | #define OV3_VMX 0x40 /* VMX/Altivec */ |
Paul Mackerras | 974a76f | 2006-11-10 20:38:53 +1100 | [diff] [blame] | 668 | #define OV3_DFP 0x20 /* decimal FP */ |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 669 | |
Robert Jennings | 404e32e | 2012-05-10 08:55:49 +0000 | [diff] [blame] | 670 | /* Option vector 4: IBM PAPR implementation */ |
| 671 | #define OV4_MIN_ENT_CAP 0x01 /* minimum VP entitled capacity */ |
| 672 | |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 673 | /* Option vector 5: PAPR/OF options supported */ |
| 674 | #define OV5_LPAR 0x80 /* logical partitioning supported */ |
| 675 | #define OV5_SPLPAR 0x40 /* shared-processor LPAR supported */ |
| 676 | /* ibm,dynamic-reconfiguration-memory property supported */ |
| 677 | #define OV5_DRCONF_MEMORY 0x20 |
| 678 | #define OV5_LARGE_PAGES 0x10 /* large pages supported */ |
Jake Moilanen | d8c391a | 2007-06-08 07:27:11 +1000 | [diff] [blame] | 679 | #define OV5_DONATE_DEDICATE_CPU 0x02 /* donate dedicated CPU support */ |
Michael Ellerman | 014dad9 | 2007-05-08 12:58:35 +1000 | [diff] [blame] | 680 | /* PCIe/MSI support. Without MSI full PCIe is not supported */ |
| 681 | #ifdef CONFIG_PCI_MSI |
| 682 | #define OV5_MSI 0x01 /* PCIe/MSI support */ |
| 683 | #else |
| 684 | #define OV5_MSI 0x00 |
| 685 | #endif /* CONFIG_PCI_MSI */ |
Nathan Fontenot | 8391e42 | 2008-07-24 04:36:38 +1000 | [diff] [blame] | 686 | #ifdef CONFIG_PPC_SMLPAR |
| 687 | #define OV5_CMO 0x80 /* Cooperative Memory Overcommitment */ |
Brian King | 9ee820f | 2011-05-04 16:01:20 +1000 | [diff] [blame] | 688 | #define OV5_XCMO 0x40 /* Page Coalescing */ |
Nathan Fontenot | 8391e42 | 2008-07-24 04:36:38 +1000 | [diff] [blame] | 689 | #else |
| 690 | #define OV5_CMO 0x00 |
Brian King | 9ee820f | 2011-05-04 16:01:20 +1000 | [diff] [blame] | 691 | #define OV5_XCMO 0x00 |
Nathan Fontenot | 8391e42 | 2008-07-24 04:36:38 +1000 | [diff] [blame] | 692 | #endif |
Anton Blanchard | 4b83c33 | 2010-04-07 15:33:44 +0000 | [diff] [blame] | 693 | #define OV5_TYPE1_AFFINITY 0x80 /* Type 1 NUMA affinity */ |
Kent Yoder | 828d2b5 | 2012-04-12 05:17:51 +0000 | [diff] [blame] | 694 | #define OV5_PFO_HW_RNG 0x80 /* PFO Random Number Generator */ |
Seth Jennings | da29aa8 | 2012-07-19 09:42:39 -0500 | [diff] [blame] | 695 | #define OV5_PFO_HW_842 0x40 /* PFO Compression Accelerator */ |
Kent Yoder | 7e3a4fa | 2012-04-12 05:39:35 +0000 | [diff] [blame] | 696 | #define OV5_PFO_HW_ENCR 0x20 /* PFO Encryption Accelerator */ |
Michael Neuling | df77c79 | 2012-11-08 20:23:11 +0000 | [diff] [blame] | 697 | #define OV5_SUB_PROCESSORS 0x01 /* 1,2,or 4 Sub-Processors supported */ |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 698 | |
jschopp@austin.ibm.com | 28bb9ee | 2010-02-01 12:50:48 +0000 | [diff] [blame] | 699 | /* Option Vector 6: IBM PAPR hints */ |
| 700 | #define OV6_LINUX 0x02 /* Linux is our OS */ |
| 701 | |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 702 | /* |
| 703 | * The architecture vector has an array of PVR mask/value pairs, |
| 704 | * followed by # option vectors - 1, followed by the option vectors. |
| 705 | */ |
| 706 | static unsigned char ibm_architecture_vec[] = { |
| 707 | W(0xfffe0000), W(0x003a0000), /* POWER5/POWER5+ */ |
Anton Blanchard | 03054d5 | 2006-04-29 09:51:06 +1000 | [diff] [blame] | 708 | W(0xffff0000), W(0x003e0000), /* POWER6 */ |
Michael Neuling | e952e6c | 2008-06-18 10:47:26 +1000 | [diff] [blame] | 709 | W(0xffff0000), W(0x003f0000), /* POWER7 */ |
Michael Neuling | df77c79 | 2012-11-08 20:23:11 +0000 | [diff] [blame] | 710 | W(0xffff0000), W(0x004b0000), /* POWER8 */ |
| 711 | W(0xffffffff), W(0x0f000004), /* all 2.07-compliant */ |
Joel Schopp | 0cb9901 | 2008-06-19 06:23:23 +1000 | [diff] [blame] | 712 | W(0xffffffff), W(0x0f000003), /* all 2.06-compliant */ |
Paul Mackerras | 0efbc18 | 2006-11-29 22:31:47 +1100 | [diff] [blame] | 713 | W(0xffffffff), W(0x0f000002), /* all 2.05-compliant */ |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 714 | W(0xfffffffe), W(0x0f000001), /* all 2.04-compliant and earlier */ |
jschopp@austin.ibm.com | 28bb9ee | 2010-02-01 12:50:48 +0000 | [diff] [blame] | 715 | 6 - 1, /* 6 option vectors */ |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 716 | |
| 717 | /* option vector 1: processor architectures supported */ |
Will Schmidt | 11e9ed4 | 2006-08-25 15:46:59 -0500 | [diff] [blame] | 718 | 3 - 2, /* length */ |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 719 | 0, /* don't ignore, don't halt */ |
| 720 | OV1_PPC_2_00 | OV1_PPC_2_01 | OV1_PPC_2_02 | OV1_PPC_2_03 | |
Michael Neuling | df77c79 | 2012-11-08 20:23:11 +0000 | [diff] [blame] | 721 | OV1_PPC_2_04 | OV1_PPC_2_05 | OV1_PPC_2_06 | OV1_PPC_2_07, |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 722 | |
| 723 | /* option vector 2: Open Firmware options supported */ |
Will Schmidt | 11e9ed4 | 2006-08-25 15:46:59 -0500 | [diff] [blame] | 724 | 34 - 2, /* length */ |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 725 | OV2_REAL_MODE, |
| 726 | 0, 0, |
| 727 | W(0xffffffff), /* real_base */ |
| 728 | W(0xffffffff), /* real_size */ |
| 729 | W(0xffffffff), /* virt_base */ |
| 730 | W(0xffffffff), /* virt_size */ |
| 731 | W(0xffffffff), /* load_base */ |
Anton Blanchard | 3339264 | 2011-12-04 13:13:58 +0000 | [diff] [blame] | 732 | W(256), /* 256MB min RMA */ |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 733 | W(0xffffffff), /* full client load */ |
| 734 | 0, /* min RMA percentage of total RAM */ |
| 735 | 48, /* max log_2(hash table size) */ |
| 736 | |
| 737 | /* option vector 3: processor options supported */ |
Will Schmidt | 11e9ed4 | 2006-08-25 15:46:59 -0500 | [diff] [blame] | 738 | 3 - 2, /* length */ |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 739 | 0, /* don't ignore, don't halt */ |
Paul Mackerras | 974a76f | 2006-11-10 20:38:53 +1100 | [diff] [blame] | 740 | OV3_FP | OV3_VMX | OV3_DFP, |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 741 | |
| 742 | /* option vector 4: IBM PAPR implementation */ |
Robert Jennings | 404e32e | 2012-05-10 08:55:49 +0000 | [diff] [blame] | 743 | 3 - 2, /* length */ |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 744 | 0, /* don't halt */ |
Robert Jennings | 404e32e | 2012-05-10 08:55:49 +0000 | [diff] [blame] | 745 | OV4_MIN_ENT_CAP, /* minimum VP entitled capacity */ |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 746 | |
| 747 | /* option vector 5: PAPR/OF options */ |
Michael Neuling | df77c79 | 2012-11-08 20:23:11 +0000 | [diff] [blame] | 748 | 19 - 2, /* length */ |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 749 | 0, /* don't ignore, don't halt */ |
Jake Moilanen | d8c391a | 2007-06-08 07:27:11 +1000 | [diff] [blame] | 750 | OV5_LPAR | OV5_SPLPAR | OV5_LARGE_PAGES | OV5_DRCONF_MEMORY | |
| 751 | OV5_DONATE_DEDICATE_CPU | OV5_MSI, |
Nathan Fontenot | 8391e42 | 2008-07-24 04:36:38 +1000 | [diff] [blame] | 752 | 0, |
Brian King | 9ee820f | 2011-05-04 16:01:20 +1000 | [diff] [blame] | 753 | OV5_CMO | OV5_XCMO, |
Anton Blanchard | 4b83c33 | 2010-04-07 15:33:44 +0000 | [diff] [blame] | 754 | OV5_TYPE1_AFFINITY, |
jschopp@austin.ibm.com | 28bb9ee | 2010-02-01 12:50:48 +0000 | [diff] [blame] | 755 | 0, |
| 756 | 0, |
| 757 | 0, |
Benjamin Herrenschmidt | efec959 | 2010-02-04 14:33:54 +1100 | [diff] [blame] | 758 | /* WARNING: The offset of the "number of cores" field below |
| 759 | * must match by the macro below. Update the definition if |
| 760 | * the structure layout changes. |
| 761 | */ |
Michael Neuling | df77c79 | 2012-11-08 20:23:11 +0000 | [diff] [blame] | 762 | #define IBM_ARCH_VEC_NRCORES_OFFSET 117 |
Benjamin Herrenschmidt | efec959 | 2010-02-04 14:33:54 +1100 | [diff] [blame] | 763 | W(NR_CPUS), /* number of cores supported */ |
Kent Yoder | 828d2b5 | 2012-04-12 05:17:51 +0000 | [diff] [blame] | 764 | 0, |
| 765 | 0, |
| 766 | 0, |
| 767 | 0, |
Seth Jennings | da29aa8 | 2012-07-19 09:42:39 -0500 | [diff] [blame] | 768 | OV5_PFO_HW_RNG | OV5_PFO_HW_ENCR | OV5_PFO_HW_842, |
Michael Neuling | df77c79 | 2012-11-08 20:23:11 +0000 | [diff] [blame] | 769 | OV5_SUB_PROCESSORS, |
jschopp@austin.ibm.com | 28bb9ee | 2010-02-01 12:50:48 +0000 | [diff] [blame] | 770 | /* option vector 6: IBM PAPR hints */ |
| 771 | 4 - 2, /* length */ |
| 772 | 0, |
| 773 | 0, |
| 774 | OV6_LINUX, |
| 775 | |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 776 | }; |
| 777 | |
| 778 | /* Old method - ELF header with PT_NOTE sections */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 779 | static struct fake_elf { |
| 780 | Elf32_Ehdr elfhdr; |
| 781 | Elf32_Phdr phdr[2]; |
| 782 | struct chrpnote { |
| 783 | u32 namesz; |
| 784 | u32 descsz; |
| 785 | u32 type; |
| 786 | char name[8]; /* "PowerPC" */ |
| 787 | struct chrpdesc { |
| 788 | u32 real_mode; |
| 789 | u32 real_base; |
| 790 | u32 real_size; |
| 791 | u32 virt_base; |
| 792 | u32 virt_size; |
| 793 | u32 load_base; |
| 794 | } chrpdesc; |
| 795 | } chrpnote; |
| 796 | struct rpanote { |
| 797 | u32 namesz; |
| 798 | u32 descsz; |
| 799 | u32 type; |
| 800 | char name[24]; /* "IBM,RPA-Client-Config" */ |
| 801 | struct rpadesc { |
| 802 | u32 lpar_affinity; |
| 803 | u32 min_rmo_size; |
| 804 | u32 min_rmo_percent; |
| 805 | u32 max_pft_size; |
| 806 | u32 splpar; |
| 807 | u32 min_load; |
| 808 | u32 new_mem_def; |
| 809 | u32 ignore_me; |
| 810 | } rpadesc; |
| 811 | } rpanote; |
Paul Mackerras | 5663a12 | 2008-10-31 22:27:17 +1100 | [diff] [blame] | 812 | } fake_elf = { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 813 | .elfhdr = { |
| 814 | .e_ident = { 0x7f, 'E', 'L', 'F', |
| 815 | ELFCLASS32, ELFDATA2MSB, EV_CURRENT }, |
| 816 | .e_type = ET_EXEC, /* yeah right */ |
| 817 | .e_machine = EM_PPC, |
| 818 | .e_version = EV_CURRENT, |
| 819 | .e_phoff = offsetof(struct fake_elf, phdr), |
| 820 | .e_phentsize = sizeof(Elf32_Phdr), |
| 821 | .e_phnum = 2 |
| 822 | }, |
| 823 | .phdr = { |
| 824 | [0] = { |
| 825 | .p_type = PT_NOTE, |
| 826 | .p_offset = offsetof(struct fake_elf, chrpnote), |
| 827 | .p_filesz = sizeof(struct chrpnote) |
| 828 | }, [1] = { |
| 829 | .p_type = PT_NOTE, |
| 830 | .p_offset = offsetof(struct fake_elf, rpanote), |
| 831 | .p_filesz = sizeof(struct rpanote) |
| 832 | } |
| 833 | }, |
| 834 | .chrpnote = { |
| 835 | .namesz = sizeof("PowerPC"), |
| 836 | .descsz = sizeof(struct chrpdesc), |
| 837 | .type = 0x1275, |
| 838 | .name = "PowerPC", |
| 839 | .chrpdesc = { |
| 840 | .real_mode = ~0U, /* ~0 means "don't care" */ |
| 841 | .real_base = ~0U, |
| 842 | .real_size = ~0U, |
| 843 | .virt_base = ~0U, |
| 844 | .virt_size = ~0U, |
| 845 | .load_base = ~0U |
| 846 | }, |
| 847 | }, |
| 848 | .rpanote = { |
| 849 | .namesz = sizeof("IBM,RPA-Client-Config"), |
| 850 | .descsz = sizeof(struct rpadesc), |
| 851 | .type = 0x12759999, |
| 852 | .name = "IBM,RPA-Client-Config", |
| 853 | .rpadesc = { |
Paul Mackerras | 5663a12 | 2008-10-31 22:27:17 +1100 | [diff] [blame] | 854 | .lpar_affinity = 0, |
| 855 | .min_rmo_size = 64, /* in megabytes */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 856 | .min_rmo_percent = 0, |
Paul Mackerras | 5663a12 | 2008-10-31 22:27:17 +1100 | [diff] [blame] | 857 | .max_pft_size = 48, /* 2^48 bytes max PFT size */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 858 | .splpar = 1, |
| 859 | .min_load = ~0U, |
Paul Mackerras | 5663a12 | 2008-10-31 22:27:17 +1100 | [diff] [blame] | 860 | .new_mem_def = 0 |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 861 | } |
| 862 | } |
| 863 | }; |
| 864 | |
Benjamin Herrenschmidt | efec959 | 2010-02-04 14:33:54 +1100 | [diff] [blame] | 865 | static int __init prom_count_smt_threads(void) |
| 866 | { |
| 867 | phandle node; |
| 868 | char type[64]; |
| 869 | unsigned int plen; |
| 870 | |
| 871 | /* Pick up th first CPU node we can find */ |
| 872 | for (node = 0; prom_next_node(&node); ) { |
| 873 | type[0] = 0; |
| 874 | prom_getprop(node, "device_type", type, sizeof(type)); |
| 875 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 876 | if (strcmp(type, "cpu")) |
Benjamin Herrenschmidt | efec959 | 2010-02-04 14:33:54 +1100 | [diff] [blame] | 877 | continue; |
| 878 | /* |
| 879 | * There is an entry for each smt thread, each entry being |
| 880 | * 4 bytes long. All cpus should have the same number of |
| 881 | * smt threads, so return after finding the first. |
| 882 | */ |
| 883 | plen = prom_getproplen(node, "ibm,ppc-interrupt-server#s"); |
| 884 | if (plen == PROM_ERROR) |
| 885 | break; |
| 886 | plen >>= 2; |
Michael Neuling | 2c48a7d | 2010-07-27 18:26:21 +0000 | [diff] [blame] | 887 | prom_debug("Found %lu smt threads per core\n", (unsigned long)plen); |
Benjamin Herrenschmidt | efec959 | 2010-02-04 14:33:54 +1100 | [diff] [blame] | 888 | |
| 889 | /* Sanity check */ |
| 890 | if (plen < 1 || plen > 64) { |
Michael Neuling | 2c48a7d | 2010-07-27 18:26:21 +0000 | [diff] [blame] | 891 | prom_printf("Threads per core %lu out of bounds, assuming 1\n", |
Benjamin Herrenschmidt | efec959 | 2010-02-04 14:33:54 +1100 | [diff] [blame] | 892 | (unsigned long)plen); |
| 893 | return 1; |
| 894 | } |
| 895 | return plen; |
| 896 | } |
| 897 | prom_debug("No threads found, assuming 1 per core\n"); |
| 898 | |
| 899 | return 1; |
| 900 | |
| 901 | } |
| 902 | |
| 903 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 904 | static void __init prom_send_capabilities(void) |
| 905 | { |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 906 | ihandle elfloader, root; |
| 907 | prom_arg_t ret; |
Benjamin Herrenschmidt | efec959 | 2010-02-04 14:33:54 +1100 | [diff] [blame] | 908 | u32 *cores; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 909 | |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 910 | root = call_prom("open", 1, 1, ADDR("/")); |
| 911 | if (root != 0) { |
Benjamin Herrenschmidt | efec959 | 2010-02-04 14:33:54 +1100 | [diff] [blame] | 912 | /* We need to tell the FW about the number of cores we support. |
| 913 | * |
| 914 | * To do that, we count the number of threads on the first core |
| 915 | * (we assume this is the same for all cores) and use it to |
| 916 | * divide NR_CPUS. |
| 917 | */ |
Anton Blanchard | 5ac47f7 | 2012-11-26 17:39:03 +0000 | [diff] [blame] | 918 | cores = (u32 *)&ibm_architecture_vec[IBM_ARCH_VEC_NRCORES_OFFSET]; |
Benjamin Herrenschmidt | efec959 | 2010-02-04 14:33:54 +1100 | [diff] [blame] | 919 | if (*cores != NR_CPUS) { |
| 920 | prom_printf("WARNING ! " |
Michael Neuling | 2c48a7d | 2010-07-27 18:26:21 +0000 | [diff] [blame] | 921 | "ibm_architecture_vec structure inconsistent: %lu!\n", |
Benjamin Herrenschmidt | efec959 | 2010-02-04 14:33:54 +1100 | [diff] [blame] | 922 | *cores); |
| 923 | } else { |
Anton Blanchard | 33ad5e4 | 2010-06-17 14:33:06 +0000 | [diff] [blame] | 924 | *cores = DIV_ROUND_UP(NR_CPUS, prom_count_smt_threads()); |
Michael Neuling | 2c48a7d | 2010-07-27 18:26:21 +0000 | [diff] [blame] | 925 | prom_printf("Max number of cores passed to firmware: %lu (NR_CPUS = %lu)\n", |
| 926 | *cores, NR_CPUS); |
Benjamin Herrenschmidt | efec959 | 2010-02-04 14:33:54 +1100 | [diff] [blame] | 927 | } |
| 928 | |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 929 | /* try calling the ibm,client-architecture-support method */ |
Anton Blanchard | 049d049 | 2009-09-21 20:47:39 +0000 | [diff] [blame] | 930 | prom_printf("Calling ibm,client-architecture-support..."); |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 931 | if (call_prom_ret("call-method", 3, 2, &ret, |
| 932 | ADDR("ibm,client-architecture-support"), |
Benjamin Herrenschmidt | 33b7497 | 2006-06-07 12:01:32 +1000 | [diff] [blame] | 933 | root, |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 934 | ADDR(ibm_architecture_vec)) == 0) { |
| 935 | /* the call exists... */ |
| 936 | if (ret) |
Anton Blanchard | 4da727a | 2009-03-31 20:06:14 +0000 | [diff] [blame] | 937 | prom_printf("\nWARNING: ibm,client-architecture" |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 938 | "-support call FAILED!\n"); |
| 939 | call_prom("close", 1, 0, root); |
Anton Blanchard | 4da727a | 2009-03-31 20:06:14 +0000 | [diff] [blame] | 940 | prom_printf(" done\n"); |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 941 | return; |
| 942 | } |
| 943 | call_prom("close", 1, 0, root); |
Anton Blanchard | 049d049 | 2009-09-21 20:47:39 +0000 | [diff] [blame] | 944 | prom_printf(" not implemented\n"); |
Paul Mackerras | f709bfa | 2006-04-28 16:28:35 +1000 | [diff] [blame] | 945 | } |
| 946 | |
| 947 | /* no ibm,client-architecture-support call, try the old way */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 948 | elfloader = call_prom("open", 1, 1, ADDR("/packages/elf-loader")); |
| 949 | if (elfloader == 0) { |
| 950 | prom_printf("couldn't open /packages/elf-loader\n"); |
| 951 | return; |
| 952 | } |
| 953 | call_prom("call-method", 3, 1, ADDR("process-elf-header"), |
| 954 | elfloader, ADDR(&fake_elf)); |
| 955 | call_prom("close", 1, 0, elfloader); |
| 956 | } |
| 957 | #endif |
| 958 | |
| 959 | /* |
| 960 | * Memory allocation strategy... our layout is normally: |
| 961 | * |
| 962 | * at 14Mb or more we have vmlinux, then a gap and initrd. In some |
| 963 | * rare cases, initrd might end up being before the kernel though. |
| 964 | * We assume this won't override the final kernel at 0, we have no |
| 965 | * provision to handle that in this version, but it should hopefully |
| 966 | * never happen. |
| 967 | * |
| 968 | * alloc_top is set to the top of RMO, eventually shrink down if the |
| 969 | * TCEs overlap |
| 970 | * |
| 971 | * alloc_bottom is set to the top of kernel/initrd |
| 972 | * |
| 973 | * from there, allocations are done this way : rtas is allocated |
| 974 | * topmost, and the device-tree is allocated from the bottom. We try |
| 975 | * to grow the device-tree allocation as we progress. If we can't, |
| 976 | * then we fail, we don't currently have a facility to restart |
| 977 | * elsewhere, but that shouldn't be necessary. |
| 978 | * |
| 979 | * Note that calls to reserve_mem have to be done explicitly, memory |
| 980 | * allocated with either alloc_up or alloc_down isn't automatically |
| 981 | * reserved. |
| 982 | */ |
| 983 | |
| 984 | |
| 985 | /* |
| 986 | * Allocates memory in the RMO upward from the kernel/initrd |
| 987 | * |
| 988 | * When align is 0, this is a special case, it means to allocate in place |
| 989 | * at the current location of alloc_bottom or fail (that is basically |
| 990 | * extending the previous allocation). Used for the device-tree flattening |
| 991 | */ |
| 992 | static unsigned long __init alloc_up(unsigned long size, unsigned long align) |
| 993 | { |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 994 | unsigned long base = alloc_bottom; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 995 | unsigned long addr = 0; |
| 996 | |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 997 | if (align) |
| 998 | base = _ALIGN_UP(base, align); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 999 | prom_debug("alloc_up(%x, %x)\n", size, align); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1000 | if (ram_top == 0) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1001 | prom_panic("alloc_up() called with mem not initialized\n"); |
| 1002 | |
| 1003 | if (align) |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1004 | base = _ALIGN_UP(alloc_bottom, align); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1005 | else |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1006 | base = alloc_bottom; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1007 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1008 | for(; (base + size) <= alloc_top; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1009 | base = _ALIGN_UP(base + 0x100000, align)) { |
| 1010 | prom_debug(" trying: 0x%x\n\r", base); |
| 1011 | addr = (unsigned long)prom_claim(base, size, 0); |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 1012 | if (addr != PROM_ERROR && addr != 0) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1013 | break; |
| 1014 | addr = 0; |
| 1015 | if (align == 0) |
| 1016 | break; |
| 1017 | } |
| 1018 | if (addr == 0) |
| 1019 | return 0; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1020 | alloc_bottom = addr + size; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1021 | |
| 1022 | prom_debug(" -> %x\n", addr); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1023 | prom_debug(" alloc_bottom : %x\n", alloc_bottom); |
| 1024 | prom_debug(" alloc_top : %x\n", alloc_top); |
| 1025 | prom_debug(" alloc_top_hi : %x\n", alloc_top_high); |
| 1026 | prom_debug(" rmo_top : %x\n", rmo_top); |
| 1027 | prom_debug(" ram_top : %x\n", ram_top); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1028 | |
| 1029 | return addr; |
| 1030 | } |
| 1031 | |
| 1032 | /* |
| 1033 | * Allocates memory downward, either from top of RMO, or if highmem |
| 1034 | * is set, from the top of RAM. Note that this one doesn't handle |
| 1035 | * failures. It does claim memory if highmem is not set. |
| 1036 | */ |
| 1037 | static unsigned long __init alloc_down(unsigned long size, unsigned long align, |
| 1038 | int highmem) |
| 1039 | { |
| 1040 | unsigned long base, addr = 0; |
| 1041 | |
| 1042 | prom_debug("alloc_down(%x, %x, %s)\n", size, align, |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1043 | highmem ? "(high)" : "(low)"); |
| 1044 | if (ram_top == 0) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1045 | prom_panic("alloc_down() called with mem not initialized\n"); |
| 1046 | |
| 1047 | if (highmem) { |
| 1048 | /* Carve out storage for the TCE table. */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1049 | addr = _ALIGN_DOWN(alloc_top_high - size, align); |
| 1050 | if (addr <= alloc_bottom) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1051 | return 0; |
| 1052 | /* Will we bump into the RMO ? If yes, check out that we |
| 1053 | * didn't overlap existing allocations there, if we did, |
| 1054 | * we are dead, we must be the first in town ! |
| 1055 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1056 | if (addr < rmo_top) { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1057 | /* Good, we are first */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1058 | if (alloc_top == rmo_top) |
| 1059 | alloc_top = rmo_top = addr; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1060 | else |
| 1061 | return 0; |
| 1062 | } |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1063 | alloc_top_high = addr; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1064 | goto bail; |
| 1065 | } |
| 1066 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1067 | base = _ALIGN_DOWN(alloc_top - size, align); |
| 1068 | for (; base > alloc_bottom; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1069 | base = _ALIGN_DOWN(base - 0x100000, align)) { |
| 1070 | prom_debug(" trying: 0x%x\n\r", base); |
| 1071 | addr = (unsigned long)prom_claim(base, size, 0); |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 1072 | if (addr != PROM_ERROR && addr != 0) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1073 | break; |
| 1074 | addr = 0; |
| 1075 | } |
| 1076 | if (addr == 0) |
| 1077 | return 0; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1078 | alloc_top = addr; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1079 | |
| 1080 | bail: |
| 1081 | prom_debug(" -> %x\n", addr); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1082 | prom_debug(" alloc_bottom : %x\n", alloc_bottom); |
| 1083 | prom_debug(" alloc_top : %x\n", alloc_top); |
| 1084 | prom_debug(" alloc_top_hi : %x\n", alloc_top_high); |
| 1085 | prom_debug(" rmo_top : %x\n", rmo_top); |
| 1086 | prom_debug(" ram_top : %x\n", ram_top); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1087 | |
| 1088 | return addr; |
| 1089 | } |
| 1090 | |
| 1091 | /* |
| 1092 | * Parse a "reg" cell |
| 1093 | */ |
| 1094 | static unsigned long __init prom_next_cell(int s, cell_t **cellp) |
| 1095 | { |
| 1096 | cell_t *p = *cellp; |
| 1097 | unsigned long r = 0; |
| 1098 | |
| 1099 | /* Ignore more than 2 cells */ |
| 1100 | while (s > sizeof(unsigned long) / 4) { |
| 1101 | p++; |
| 1102 | s--; |
| 1103 | } |
| 1104 | r = *p++; |
| 1105 | #ifdef CONFIG_PPC64 |
Paul Mackerras | 35499c0 | 2005-10-22 16:02:39 +1000 | [diff] [blame] | 1106 | if (s > 1) { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1107 | r <<= 32; |
| 1108 | r |= *(p++); |
| 1109 | } |
| 1110 | #endif |
| 1111 | *cellp = p; |
| 1112 | return r; |
| 1113 | } |
| 1114 | |
| 1115 | /* |
| 1116 | * Very dumb function for adding to the memory reserve list, but |
| 1117 | * we don't need anything smarter at this point |
| 1118 | * |
| 1119 | * XXX Eventually check for collisions. They should NEVER happen. |
| 1120 | * If problems seem to show up, it would be a good start to track |
| 1121 | * them down. |
| 1122 | */ |
Michael Ellerman | 0108d3f | 2007-05-07 15:58:28 +1000 | [diff] [blame] | 1123 | static void __init reserve_mem(u64 base, u64 size) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1124 | { |
Kumar Gala | cbbcf34 | 2006-01-11 17:57:13 -0600 | [diff] [blame] | 1125 | u64 top = base + size; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1126 | unsigned long cnt = mem_reserve_cnt; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1127 | |
| 1128 | if (size == 0) |
| 1129 | return; |
| 1130 | |
| 1131 | /* We need to always keep one empty entry so that we |
| 1132 | * have our terminator with "size" set to 0 since we are |
| 1133 | * dumb and just copy this entire array to the boot params |
| 1134 | */ |
| 1135 | base = _ALIGN_DOWN(base, PAGE_SIZE); |
| 1136 | top = _ALIGN_UP(top, PAGE_SIZE); |
| 1137 | size = top - base; |
| 1138 | |
| 1139 | if (cnt >= (MEM_RESERVE_MAP_SIZE - 1)) |
| 1140 | prom_panic("Memory reserve map exhausted !\n"); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1141 | mem_reserve_map[cnt].base = base; |
| 1142 | mem_reserve_map[cnt].size = size; |
| 1143 | mem_reserve_cnt = cnt + 1; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | /* |
Adrian Bunk | b3c2ffd | 2006-06-30 18:20:44 +0200 | [diff] [blame] | 1147 | * Initialize memory allocation mechanism, parse "memory" nodes and |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1148 | * obtain that way the top of memory and RMO to setup out local allocator |
| 1149 | */ |
| 1150 | static void __init prom_init_mem(void) |
| 1151 | { |
| 1152 | phandle node; |
| 1153 | char *path, type[64]; |
| 1154 | unsigned int plen; |
| 1155 | cell_t *p, *endp; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1156 | u32 rac, rsc; |
| 1157 | |
| 1158 | /* |
| 1159 | * We iterate the memory nodes to find |
| 1160 | * 1) top of RMO (first node) |
| 1161 | * 2) top of memory |
| 1162 | */ |
| 1163 | rac = 2; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1164 | prom_getprop(prom.root, "#address-cells", &rac, sizeof(rac)); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1165 | rsc = 1; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1166 | prom_getprop(prom.root, "#size-cells", &rsc, sizeof(rsc)); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1167 | prom_debug("root_addr_cells: %x\n", (unsigned long) rac); |
| 1168 | prom_debug("root_size_cells: %x\n", (unsigned long) rsc); |
| 1169 | |
| 1170 | prom_debug("scanning memory:\n"); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1171 | path = prom_scratch; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1172 | |
| 1173 | for (node = 0; prom_next_node(&node); ) { |
| 1174 | type[0] = 0; |
| 1175 | prom_getprop(node, "device_type", type, sizeof(type)); |
| 1176 | |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 1177 | if (type[0] == 0) { |
| 1178 | /* |
| 1179 | * CHRP Longtrail machines have no device_type |
| 1180 | * on the memory node, so check the name instead... |
| 1181 | */ |
| 1182 | prom_getprop(node, "name", type, sizeof(type)); |
| 1183 | } |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1184 | if (strcmp(type, "memory")) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1185 | continue; |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 1186 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1187 | plen = prom_getprop(node, "reg", regbuf, sizeof(regbuf)); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1188 | if (plen > sizeof(regbuf)) { |
| 1189 | prom_printf("memory node too large for buffer !\n"); |
| 1190 | plen = sizeof(regbuf); |
| 1191 | } |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1192 | p = regbuf; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1193 | endp = p + (plen / sizeof(cell_t)); |
| 1194 | |
| 1195 | #ifdef DEBUG_PROM |
| 1196 | memset(path, 0, PROM_SCRATCH_SIZE); |
| 1197 | call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-1); |
| 1198 | prom_debug(" node %s :\n", path); |
| 1199 | #endif /* DEBUG_PROM */ |
| 1200 | |
| 1201 | while ((endp - p) >= (rac + rsc)) { |
| 1202 | unsigned long base, size; |
| 1203 | |
| 1204 | base = prom_next_cell(rac, &p); |
| 1205 | size = prom_next_cell(rsc, &p); |
| 1206 | |
| 1207 | if (size == 0) |
| 1208 | continue; |
| 1209 | prom_debug(" %x %x\n", base, size); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1210 | if (base == 0 && (of_platform & PLATFORM_LPAR)) |
| 1211 | rmo_top = size; |
| 1212 | if ((base + size) > ram_top) |
| 1213 | ram_top = base + size; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1214 | } |
| 1215 | } |
| 1216 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1217 | alloc_bottom = PAGE_ALIGN((unsigned long)&_end + 0x4000); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1218 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1219 | /* |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 1220 | * If prom_memory_limit is set we reduce the upper limits *except* for |
| 1221 | * alloc_top_high. This must be the real top of RAM so we can put |
| 1222 | * TCE's up there. |
| 1223 | */ |
| 1224 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1225 | alloc_top_high = ram_top; |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 1226 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1227 | if (prom_memory_limit) { |
| 1228 | if (prom_memory_limit <= alloc_bottom) { |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 1229 | prom_printf("Ignoring mem=%x <= alloc_bottom.\n", |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1230 | prom_memory_limit); |
| 1231 | prom_memory_limit = 0; |
| 1232 | } else if (prom_memory_limit >= ram_top) { |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 1233 | prom_printf("Ignoring mem=%x >= ram_top.\n", |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1234 | prom_memory_limit); |
| 1235 | prom_memory_limit = 0; |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 1236 | } else { |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1237 | ram_top = prom_memory_limit; |
| 1238 | rmo_top = min(rmo_top, prom_memory_limit); |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 1239 | } |
| 1240 | } |
| 1241 | |
| 1242 | /* |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1243 | * Setup our top alloc point, that is top of RMO or top of |
| 1244 | * segment 0 when running non-LPAR. |
| 1245 | * Some RS64 machines have buggy firmware where claims up at |
| 1246 | * 1GB fail. Cap at 768MB as a workaround. |
| 1247 | * Since 768MB is plenty of room, and we need to cap to something |
| 1248 | * reasonable on 32-bit, cap at 768MB on all machines. |
| 1249 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1250 | if (!rmo_top) |
| 1251 | rmo_top = ram_top; |
| 1252 | rmo_top = min(0x30000000ul, rmo_top); |
| 1253 | alloc_top = rmo_top; |
| 1254 | alloc_top_high = ram_top; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1255 | |
Paul Mackerras | 64968f6 | 2011-12-13 17:54:13 +0000 | [diff] [blame] | 1256 | /* |
| 1257 | * Check if we have an initrd after the kernel but still inside |
| 1258 | * the RMO. If we do move our bottom point to after it. |
| 1259 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1260 | if (prom_initrd_start && |
| 1261 | prom_initrd_start < rmo_top && |
| 1262 | prom_initrd_end > alloc_bottom) |
| 1263 | alloc_bottom = PAGE_ALIGN(prom_initrd_end); |
Paul Mackerras | 64968f6 | 2011-12-13 17:54:13 +0000 | [diff] [blame] | 1264 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1265 | prom_printf("memory layout at init:\n"); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1266 | prom_printf(" memory_limit : %x (16 MB aligned)\n", prom_memory_limit); |
| 1267 | prom_printf(" alloc_bottom : %x\n", alloc_bottom); |
| 1268 | prom_printf(" alloc_top : %x\n", alloc_top); |
| 1269 | prom_printf(" alloc_top_hi : %x\n", alloc_top_high); |
| 1270 | prom_printf(" rmo_top : %x\n", rmo_top); |
| 1271 | prom_printf(" ram_top : %x\n", ram_top); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1272 | } |
| 1273 | |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1274 | static void __init prom_close_stdin(void) |
| 1275 | { |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1276 | ihandle val; |
| 1277 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1278 | if (prom_getprop(prom.chosen, "stdin", &val, sizeof(val)) > 0) |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1279 | call_prom("close", 1, 0, val); |
| 1280 | } |
| 1281 | |
| 1282 | #ifdef CONFIG_PPC_POWERNV |
| 1283 | |
| 1284 | static u64 __initdata prom_opal_size; |
| 1285 | static u64 __initdata prom_opal_align; |
| 1286 | static int __initdata prom_rtas_start_cpu; |
| 1287 | static u64 __initdata prom_rtas_data; |
| 1288 | static u64 __initdata prom_rtas_entry; |
| 1289 | |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 1290 | #ifdef CONFIG_PPC_EARLY_DEBUG_OPAL |
| 1291 | static u64 __initdata prom_opal_base; |
| 1292 | static u64 __initdata prom_opal_entry; |
| 1293 | #endif |
| 1294 | |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1295 | /* XXX Don't change this structure without updating opal-takeover.S */ |
| 1296 | static struct opal_secondary_data { |
| 1297 | s64 ack; /* 0 */ |
| 1298 | u64 go; /* 8 */ |
| 1299 | struct opal_takeover_args args; /* 16 */ |
| 1300 | } opal_secondary_data; |
| 1301 | |
| 1302 | extern char opal_secondary_entry; |
| 1303 | |
Li Zhong | 2cb387a | 2012-06-07 17:44:23 +0000 | [diff] [blame] | 1304 | static void __init prom_query_opal(void) |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1305 | { |
| 1306 | long rc; |
| 1307 | |
Benjamin Herrenschmidt | 7680057 | 2011-09-28 20:51:46 +0000 | [diff] [blame] | 1308 | /* We must not query for OPAL presence on a machine that |
| 1309 | * supports TNK takeover (970 blades), as this uses the same |
| 1310 | * h-call with different arguments and will crash |
| 1311 | */ |
| 1312 | if (PHANDLE_VALID(call_prom("finddevice", 1, 1, |
| 1313 | ADDR("/tnk-memory-map")))) { |
| 1314 | prom_printf("TNK takeover detected, skipping OPAL check\n"); |
| 1315 | return; |
| 1316 | } |
| 1317 | |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1318 | prom_printf("Querying for OPAL presence... "); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1319 | rc = opal_query_takeover(&prom_opal_size, |
| 1320 | &prom_opal_align); |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1321 | prom_debug("(rc = %ld) ", rc); |
| 1322 | if (rc != 0) { |
| 1323 | prom_printf("not there.\n"); |
| 1324 | return; |
| 1325 | } |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1326 | of_platform = PLATFORM_OPAL; |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1327 | prom_printf(" there !\n"); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1328 | prom_debug(" opal_size = 0x%lx\n", prom_opal_size); |
| 1329 | prom_debug(" opal_align = 0x%lx\n", prom_opal_align); |
| 1330 | if (prom_opal_align < 0x10000) |
| 1331 | prom_opal_align = 0x10000; |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1332 | } |
| 1333 | |
| 1334 | static int prom_rtas_call(int token, int nargs, int nret, int *outputs, ...) |
| 1335 | { |
| 1336 | struct rtas_args rtas_args; |
| 1337 | va_list list; |
| 1338 | int i; |
| 1339 | |
| 1340 | rtas_args.token = token; |
| 1341 | rtas_args.nargs = nargs; |
| 1342 | rtas_args.nret = nret; |
| 1343 | rtas_args.rets = (rtas_arg_t *)&(rtas_args.args[nargs]); |
| 1344 | va_start(list, outputs); |
| 1345 | for (i = 0; i < nargs; ++i) |
| 1346 | rtas_args.args[i] = va_arg(list, rtas_arg_t); |
| 1347 | va_end(list); |
| 1348 | |
| 1349 | for (i = 0; i < nret; ++i) |
| 1350 | rtas_args.rets[i] = 0; |
| 1351 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1352 | opal_enter_rtas(&rtas_args, prom_rtas_data, |
| 1353 | prom_rtas_entry); |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1354 | |
| 1355 | if (nret > 1 && outputs != NULL) |
| 1356 | for (i = 0; i < nret-1; ++i) |
| 1357 | outputs[i] = rtas_args.rets[i+1]; |
| 1358 | return (nret > 0)? rtas_args.rets[0]: 0; |
| 1359 | } |
| 1360 | |
| 1361 | static void __init prom_opal_hold_cpus(void) |
| 1362 | { |
| 1363 | int i, cnt, cpu, rc; |
| 1364 | long j; |
| 1365 | phandle node; |
| 1366 | char type[64]; |
| 1367 | u32 servers[8]; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1368 | void *entry = (unsigned long *)&opal_secondary_entry; |
| 1369 | struct opal_secondary_data *data = &opal_secondary_data; |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1370 | |
| 1371 | prom_debug("prom_opal_hold_cpus: start...\n"); |
| 1372 | prom_debug(" - entry = 0x%x\n", entry); |
| 1373 | prom_debug(" - data = 0x%x\n", data); |
| 1374 | |
| 1375 | data->ack = -1; |
| 1376 | data->go = 0; |
| 1377 | |
| 1378 | /* look for cpus */ |
| 1379 | for (node = 0; prom_next_node(&node); ) { |
| 1380 | type[0] = 0; |
| 1381 | prom_getprop(node, "device_type", type, sizeof(type)); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1382 | if (strcmp(type, "cpu") != 0) |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1383 | continue; |
| 1384 | |
| 1385 | /* Skip non-configured cpus. */ |
| 1386 | if (prom_getprop(node, "status", type, sizeof(type)) > 0) |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1387 | if (strcmp(type, "okay") != 0) |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1388 | continue; |
| 1389 | |
| 1390 | cnt = prom_getprop(node, "ibm,ppc-interrupt-server#s", servers, |
| 1391 | sizeof(servers)); |
| 1392 | if (cnt == PROM_ERROR) |
| 1393 | break; |
| 1394 | cnt >>= 2; |
| 1395 | for (i = 0; i < cnt; i++) { |
| 1396 | cpu = servers[i]; |
| 1397 | prom_debug("CPU %d ... ", cpu); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1398 | if (cpu == prom.cpu) { |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1399 | prom_debug("booted !\n"); |
| 1400 | continue; |
| 1401 | } |
| 1402 | prom_debug("starting ... "); |
| 1403 | |
| 1404 | /* Init the acknowledge var which will be reset by |
| 1405 | * the secondary cpu when it awakens from its OF |
| 1406 | * spinloop. |
| 1407 | */ |
| 1408 | data->ack = -1; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1409 | rc = prom_rtas_call(prom_rtas_start_cpu, 3, 1, |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1410 | NULL, cpu, entry, data); |
| 1411 | prom_debug("rtas rc=%d ...", rc); |
| 1412 | |
| 1413 | for (j = 0; j < 100000000 && data->ack == -1; j++) { |
| 1414 | HMT_low(); |
| 1415 | mb(); |
| 1416 | } |
| 1417 | HMT_medium(); |
| 1418 | if (data->ack != -1) |
| 1419 | prom_debug("done, PIR=0x%x\n", data->ack); |
| 1420 | else |
| 1421 | prom_debug("timeout !\n"); |
| 1422 | } |
| 1423 | } |
| 1424 | prom_debug("prom_opal_hold_cpus: end...\n"); |
| 1425 | } |
| 1426 | |
Li Zhong | 2cb387a | 2012-06-07 17:44:23 +0000 | [diff] [blame] | 1427 | static void __init prom_opal_takeover(void) |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1428 | { |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1429 | struct opal_secondary_data *data = &opal_secondary_data; |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1430 | struct opal_takeover_args *args = &data->args; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1431 | u64 align = prom_opal_align; |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1432 | u64 top_addr, opal_addr; |
| 1433 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1434 | args->k_image = (u64)_stext; |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1435 | args->k_size = _end - _stext; |
| 1436 | args->k_entry = 0; |
| 1437 | args->k_entry2 = 0x60; |
| 1438 | |
| 1439 | top_addr = _ALIGN_UP(args->k_size, align); |
| 1440 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1441 | if (prom_initrd_start != 0) { |
| 1442 | args->rd_image = prom_initrd_start; |
| 1443 | args->rd_size = prom_initrd_end - args->rd_image; |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1444 | args->rd_loc = top_addr; |
| 1445 | top_addr = _ALIGN_UP(args->rd_loc + args->rd_size, align); |
| 1446 | } |
| 1447 | |
| 1448 | /* Pickup an address for the HAL. We want to go really high |
| 1449 | * up to avoid problem with future kexecs. On the other hand |
| 1450 | * we don't want to be all over the TCEs on P5IOC2 machines |
| 1451 | * which are going to be up there too. We assume the machine |
| 1452 | * has plenty of memory, and we ask for the HAL for now to |
| 1453 | * be just below the 1G point, or above the initrd |
| 1454 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1455 | opal_addr = _ALIGN_DOWN(0x40000000 - prom_opal_size, align); |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1456 | if (opal_addr < top_addr) |
| 1457 | opal_addr = top_addr; |
| 1458 | args->hal_addr = opal_addr; |
| 1459 | |
Benjamin Herrenschmidt | 817c21a | 2011-09-19 17:44:56 +0000 | [diff] [blame] | 1460 | /* Copy the command line to the kernel image */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1461 | strlcpy(boot_command_line, prom_cmd_line, |
Benjamin Herrenschmidt | 817c21a | 2011-09-19 17:44:56 +0000 | [diff] [blame] | 1462 | COMMAND_LINE_SIZE); |
| 1463 | |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1464 | prom_debug(" k_image = 0x%lx\n", args->k_image); |
| 1465 | prom_debug(" k_size = 0x%lx\n", args->k_size); |
| 1466 | prom_debug(" k_entry = 0x%lx\n", args->k_entry); |
| 1467 | prom_debug(" k_entry2 = 0x%lx\n", args->k_entry2); |
| 1468 | prom_debug(" hal_addr = 0x%lx\n", args->hal_addr); |
| 1469 | prom_debug(" rd_image = 0x%lx\n", args->rd_image); |
| 1470 | prom_debug(" rd_size = 0x%lx\n", args->rd_size); |
| 1471 | prom_debug(" rd_loc = 0x%lx\n", args->rd_loc); |
| 1472 | prom_printf("Performing OPAL takeover,this can take a few minutes..\n"); |
| 1473 | prom_close_stdin(); |
| 1474 | mb(); |
| 1475 | data->go = 1; |
| 1476 | for (;;) |
| 1477 | opal_do_takeover(args); |
| 1478 | } |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 1479 | |
| 1480 | /* |
| 1481 | * Allocate room for and instantiate OPAL |
| 1482 | */ |
| 1483 | static void __init prom_instantiate_opal(void) |
| 1484 | { |
| 1485 | phandle opal_node; |
| 1486 | ihandle opal_inst; |
| 1487 | u64 base, entry; |
| 1488 | u64 size = 0, align = 0x10000; |
| 1489 | u32 rets[2]; |
| 1490 | |
| 1491 | prom_debug("prom_instantiate_opal: start...\n"); |
| 1492 | |
| 1493 | opal_node = call_prom("finddevice", 1, 1, ADDR("/ibm,opal")); |
| 1494 | prom_debug("opal_node: %x\n", opal_node); |
| 1495 | if (!PHANDLE_VALID(opal_node)) |
| 1496 | return; |
| 1497 | |
| 1498 | prom_getprop(opal_node, "opal-runtime-size", &size, sizeof(size)); |
| 1499 | if (size == 0) |
| 1500 | return; |
| 1501 | prom_getprop(opal_node, "opal-runtime-alignment", &align, |
| 1502 | sizeof(align)); |
| 1503 | |
| 1504 | base = alloc_down(size, align, 0); |
| 1505 | if (base == 0) { |
| 1506 | prom_printf("OPAL allocation failed !\n"); |
| 1507 | return; |
| 1508 | } |
| 1509 | |
| 1510 | opal_inst = call_prom("open", 1, 1, ADDR("/ibm,opal")); |
| 1511 | if (!IHANDLE_VALID(opal_inst)) { |
| 1512 | prom_printf("opening opal package failed (%x)\n", opal_inst); |
| 1513 | return; |
| 1514 | } |
| 1515 | |
| 1516 | prom_printf("instantiating opal at 0x%x...", base); |
| 1517 | |
| 1518 | if (call_prom_ret("call-method", 4, 3, rets, |
| 1519 | ADDR("load-opal-runtime"), |
| 1520 | opal_inst, |
| 1521 | base >> 32, base & 0xffffffff) != 0 |
| 1522 | || (rets[0] == 0 && rets[1] == 0)) { |
| 1523 | prom_printf(" failed\n"); |
| 1524 | return; |
| 1525 | } |
| 1526 | entry = (((u64)rets[0]) << 32) | rets[1]; |
| 1527 | |
| 1528 | prom_printf(" done\n"); |
| 1529 | |
| 1530 | reserve_mem(base, size); |
| 1531 | |
| 1532 | prom_debug("opal base = 0x%x\n", base); |
| 1533 | prom_debug("opal align = 0x%x\n", align); |
| 1534 | prom_debug("opal entry = 0x%x\n", entry); |
| 1535 | prom_debug("opal size = 0x%x\n", (long)size); |
| 1536 | |
| 1537 | prom_setprop(opal_node, "/ibm,opal", "opal-base-address", |
| 1538 | &base, sizeof(base)); |
| 1539 | prom_setprop(opal_node, "/ibm,opal", "opal-entry-address", |
| 1540 | &entry, sizeof(entry)); |
| 1541 | |
| 1542 | #ifdef CONFIG_PPC_EARLY_DEBUG_OPAL |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1543 | prom_opal_base = base; |
| 1544 | prom_opal_entry = entry; |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 1545 | #endif |
| 1546 | prom_debug("prom_instantiate_opal: end...\n"); |
| 1547 | } |
| 1548 | |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1549 | #endif /* CONFIG_PPC_POWERNV */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1550 | |
| 1551 | /* |
| 1552 | * Allocate room for and instantiate RTAS |
| 1553 | */ |
| 1554 | static void __init prom_instantiate_rtas(void) |
| 1555 | { |
| 1556 | phandle rtas_node; |
| 1557 | ihandle rtas_inst; |
| 1558 | u32 base, entry = 0; |
| 1559 | u32 size = 0; |
| 1560 | |
| 1561 | prom_debug("prom_instantiate_rtas: start...\n"); |
| 1562 | |
| 1563 | rtas_node = call_prom("finddevice", 1, 1, ADDR("/rtas")); |
| 1564 | prom_debug("rtas_node: %x\n", rtas_node); |
| 1565 | if (!PHANDLE_VALID(rtas_node)) |
| 1566 | return; |
| 1567 | |
| 1568 | prom_getprop(rtas_node, "rtas-size", &size, sizeof(size)); |
| 1569 | if (size == 0) |
| 1570 | return; |
| 1571 | |
| 1572 | base = alloc_down(size, PAGE_SIZE, 0); |
Anton Blanchard | 6d1e2c6 | 2011-11-14 12:55:47 +0000 | [diff] [blame] | 1573 | if (base == 0) |
| 1574 | prom_panic("Could not allocate memory for RTAS\n"); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1575 | |
| 1576 | rtas_inst = call_prom("open", 1, 1, ADDR("/rtas")); |
| 1577 | if (!IHANDLE_VALID(rtas_inst)) { |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 1578 | prom_printf("opening rtas package failed (%x)\n", rtas_inst); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1579 | return; |
| 1580 | } |
| 1581 | |
Anton Blanchard | 1f8737a | 2009-03-31 20:06:15 +0000 | [diff] [blame] | 1582 | prom_printf("instantiating rtas at 0x%x...", base); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1583 | |
| 1584 | if (call_prom_ret("call-method", 3, 2, &entry, |
| 1585 | ADDR("instantiate-rtas"), |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 1586 | rtas_inst, base) != 0 |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1587 | || entry == 0) { |
| 1588 | prom_printf(" failed\n"); |
| 1589 | return; |
| 1590 | } |
| 1591 | prom_printf(" done\n"); |
| 1592 | |
| 1593 | reserve_mem(base, size); |
| 1594 | |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 1595 | prom_setprop(rtas_node, "/rtas", "linux,rtas-base", |
| 1596 | &base, sizeof(base)); |
| 1597 | prom_setprop(rtas_node, "/rtas", "linux,rtas-entry", |
| 1598 | &entry, sizeof(entry)); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1599 | |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1600 | #ifdef CONFIG_PPC_POWERNV |
| 1601 | /* PowerVN takeover hack */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1602 | prom_rtas_data = base; |
| 1603 | prom_rtas_entry = entry; |
| 1604 | prom_getprop(rtas_node, "start-cpu", &prom_rtas_start_cpu, 4); |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1605 | #endif |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1606 | prom_debug("rtas base = 0x%x\n", base); |
| 1607 | prom_debug("rtas entry = 0x%x\n", entry); |
| 1608 | prom_debug("rtas size = 0x%x\n", (long)size); |
| 1609 | |
| 1610 | prom_debug("prom_instantiate_rtas: end...\n"); |
| 1611 | } |
| 1612 | |
| 1613 | #ifdef CONFIG_PPC64 |
| 1614 | /* |
Ashley Lai | 4a72742 | 2012-08-14 18:34:57 -0500 | [diff] [blame] | 1615 | * Allocate room for and instantiate Stored Measurement Log (SML) |
| 1616 | */ |
| 1617 | static void __init prom_instantiate_sml(void) |
| 1618 | { |
| 1619 | phandle ibmvtpm_node; |
| 1620 | ihandle ibmvtpm_inst; |
| 1621 | u32 entry = 0, size = 0; |
| 1622 | u64 base; |
| 1623 | |
| 1624 | prom_debug("prom_instantiate_sml: start...\n"); |
| 1625 | |
| 1626 | ibmvtpm_node = call_prom("finddevice", 1, 1, ADDR("/ibm,vtpm")); |
| 1627 | prom_debug("ibmvtpm_node: %x\n", ibmvtpm_node); |
| 1628 | if (!PHANDLE_VALID(ibmvtpm_node)) |
| 1629 | return; |
| 1630 | |
| 1631 | ibmvtpm_inst = call_prom("open", 1, 1, ADDR("/ibm,vtpm")); |
| 1632 | if (!IHANDLE_VALID(ibmvtpm_inst)) { |
| 1633 | prom_printf("opening vtpm package failed (%x)\n", ibmvtpm_inst); |
| 1634 | return; |
| 1635 | } |
| 1636 | |
| 1637 | if (call_prom_ret("call-method", 2, 2, &size, |
| 1638 | ADDR("sml-get-handover-size"), |
| 1639 | ibmvtpm_inst) != 0 || size == 0) { |
| 1640 | prom_printf("SML get handover size failed\n"); |
| 1641 | return; |
| 1642 | } |
| 1643 | |
| 1644 | base = alloc_down(size, PAGE_SIZE, 0); |
| 1645 | if (base == 0) |
| 1646 | prom_panic("Could not allocate memory for sml\n"); |
| 1647 | |
| 1648 | prom_printf("instantiating sml at 0x%x...", base); |
| 1649 | |
| 1650 | if (call_prom_ret("call-method", 4, 2, &entry, |
| 1651 | ADDR("sml-handover"), |
| 1652 | ibmvtpm_inst, size, base) != 0 || entry == 0) { |
| 1653 | prom_printf("SML handover failed\n"); |
| 1654 | return; |
| 1655 | } |
| 1656 | prom_printf(" done\n"); |
| 1657 | |
| 1658 | reserve_mem(base, size); |
| 1659 | |
| 1660 | prom_setprop(ibmvtpm_node, "/ibm,vtpm", "linux,sml-base", |
| 1661 | &base, sizeof(base)); |
| 1662 | prom_setprop(ibmvtpm_node, "/ibm,vtpm", "linux,sml-size", |
| 1663 | &size, sizeof(size)); |
| 1664 | |
| 1665 | prom_debug("sml base = 0x%x\n", base); |
| 1666 | prom_debug("sml size = 0x%x\n", (long)size); |
| 1667 | |
| 1668 | prom_debug("prom_instantiate_sml: end...\n"); |
| 1669 | } |
| 1670 | |
| 1671 | /* |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1672 | * Allocate room for and initialize TCE tables |
| 1673 | */ |
| 1674 | static void __init prom_initialize_tce_table(void) |
| 1675 | { |
| 1676 | phandle node; |
| 1677 | ihandle phb_node; |
| 1678 | char compatible[64], type[64], model[64]; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1679 | char *path = prom_scratch; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1680 | u64 base, align; |
| 1681 | u32 minalign, minsize; |
| 1682 | u64 tce_entry, *tce_entryp; |
| 1683 | u64 local_alloc_top, local_alloc_bottom; |
| 1684 | u64 i; |
| 1685 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1686 | if (prom_iommu_off) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1687 | return; |
| 1688 | |
| 1689 | prom_debug("starting prom_initialize_tce_table\n"); |
| 1690 | |
| 1691 | /* Cache current top of allocs so we reserve a single block */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1692 | local_alloc_top = alloc_top_high; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1693 | local_alloc_bottom = local_alloc_top; |
| 1694 | |
| 1695 | /* Search all nodes looking for PHBs. */ |
| 1696 | for (node = 0; prom_next_node(&node); ) { |
| 1697 | compatible[0] = 0; |
| 1698 | type[0] = 0; |
| 1699 | model[0] = 0; |
| 1700 | prom_getprop(node, "compatible", |
| 1701 | compatible, sizeof(compatible)); |
| 1702 | prom_getprop(node, "device_type", type, sizeof(type)); |
| 1703 | prom_getprop(node, "model", model, sizeof(model)); |
| 1704 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1705 | if ((type[0] == 0) || (strstr(type, "pci") == NULL)) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1706 | continue; |
| 1707 | |
Linas Vepstas | e788ff1 | 2007-09-07 03:45:21 +1000 | [diff] [blame] | 1708 | /* Keep the old logic intact to avoid regression. */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1709 | if (compatible[0] != 0) { |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1710 | if ((strstr(compatible, "python") == NULL) && |
| 1711 | (strstr(compatible, "Speedwagon") == NULL) && |
| 1712 | (strstr(compatible, "Winnipeg") == NULL)) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1713 | continue; |
| 1714 | } else if (model[0] != 0) { |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1715 | if ((strstr(model, "ython") == NULL) && |
| 1716 | (strstr(model, "peedwagon") == NULL) && |
| 1717 | (strstr(model, "innipeg") == NULL)) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1718 | continue; |
| 1719 | } |
| 1720 | |
| 1721 | if (prom_getprop(node, "tce-table-minalign", &minalign, |
| 1722 | sizeof(minalign)) == PROM_ERROR) |
| 1723 | minalign = 0; |
| 1724 | if (prom_getprop(node, "tce-table-minsize", &minsize, |
| 1725 | sizeof(minsize)) == PROM_ERROR) |
| 1726 | minsize = 4UL << 20; |
| 1727 | |
| 1728 | /* |
| 1729 | * Even though we read what OF wants, we just set the table |
| 1730 | * size to 4 MB. This is enough to map 2GB of PCI DMA space. |
| 1731 | * By doing this, we avoid the pitfalls of trying to DMA to |
| 1732 | * MMIO space and the DMA alias hole. |
| 1733 | * |
| 1734 | * On POWER4, firmware sets the TCE region by assuming |
| 1735 | * each TCE table is 8MB. Using this memory for anything |
| 1736 | * else will impact performance, so we always allocate 8MB. |
| 1737 | * Anton |
| 1738 | */ |
Michael Ellerman | d3dbeef | 2012-08-19 21:44:01 +0000 | [diff] [blame] | 1739 | if (pvr_version_is(PVR_POWER4) || pvr_version_is(PVR_POWER4p)) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1740 | minsize = 8UL << 20; |
| 1741 | else |
| 1742 | minsize = 4UL << 20; |
| 1743 | |
| 1744 | /* Align to the greater of the align or size */ |
| 1745 | align = max(minalign, minsize); |
| 1746 | base = alloc_down(minsize, align, 1); |
| 1747 | if (base == 0) |
| 1748 | prom_panic("ERROR, cannot find space for TCE table.\n"); |
| 1749 | if (base < local_alloc_bottom) |
| 1750 | local_alloc_bottom = base; |
| 1751 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1752 | /* It seems OF doesn't null-terminate the path :-( */ |
Li Zefan | aca71ef | 2007-11-05 13:21:56 +1100 | [diff] [blame] | 1753 | memset(path, 0, PROM_SCRATCH_SIZE); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1754 | /* Call OF to setup the TCE hardware */ |
| 1755 | if (call_prom("package-to-path", 3, 1, node, |
| 1756 | path, PROM_SCRATCH_SIZE-1) == PROM_ERROR) { |
| 1757 | prom_printf("package-to-path failed\n"); |
| 1758 | } |
| 1759 | |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 1760 | /* Save away the TCE table attributes for later use. */ |
| 1761 | prom_setprop(node, path, "linux,tce-base", &base, sizeof(base)); |
| 1762 | prom_setprop(node, path, "linux,tce-size", &minsize, sizeof(minsize)); |
| 1763 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1764 | prom_debug("TCE table: %s\n", path); |
| 1765 | prom_debug("\tnode = 0x%x\n", node); |
| 1766 | prom_debug("\tbase = 0x%x\n", base); |
| 1767 | prom_debug("\tsize = 0x%x\n", minsize); |
| 1768 | |
| 1769 | /* Initialize the table to have a one-to-one mapping |
| 1770 | * over the allocated size. |
| 1771 | */ |
Ingo Molnar | 2b931fb | 2009-01-06 13:56:52 +0000 | [diff] [blame] | 1772 | tce_entryp = (u64 *)base; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1773 | for (i = 0; i < (minsize >> 3) ;tce_entryp++, i++) { |
| 1774 | tce_entry = (i << PAGE_SHIFT); |
| 1775 | tce_entry |= 0x3; |
| 1776 | *tce_entryp = tce_entry; |
| 1777 | } |
| 1778 | |
| 1779 | prom_printf("opening PHB %s", path); |
| 1780 | phb_node = call_prom("open", 1, 1, path); |
| 1781 | if (phb_node == 0) |
| 1782 | prom_printf("... failed\n"); |
| 1783 | else |
| 1784 | prom_printf("... done\n"); |
| 1785 | |
| 1786 | call_prom("call-method", 6, 0, ADDR("set-64-bit-addressing"), |
| 1787 | phb_node, -1, minsize, |
| 1788 | (u32) base, (u32) (base >> 32)); |
| 1789 | call_prom("close", 1, 0, phb_node); |
| 1790 | } |
| 1791 | |
| 1792 | reserve_mem(local_alloc_bottom, local_alloc_top - local_alloc_bottom); |
| 1793 | |
Michael Ellerman | 2babf5c | 2006-05-17 18:00:46 +1000 | [diff] [blame] | 1794 | /* These are only really needed if there is a memory limit in |
| 1795 | * effect, but we don't know so export them always. */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1796 | prom_tce_alloc_start = local_alloc_bottom; |
| 1797 | prom_tce_alloc_end = local_alloc_top; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1798 | |
| 1799 | /* Flag the first invalid entry */ |
| 1800 | prom_debug("ending prom_initialize_tce_table\n"); |
| 1801 | } |
| 1802 | #endif |
| 1803 | |
| 1804 | /* |
| 1805 | * With CHRP SMP we need to use the OF to start the other processors. |
| 1806 | * We can't wait until smp_boot_cpus (the OF is trashed by then) |
| 1807 | * so we have to put the processors into a holding pattern controlled |
| 1808 | * by the kernel (not OF) before we destroy the OF. |
| 1809 | * |
| 1810 | * This uses a chunk of low memory, puts some holding pattern |
| 1811 | * code there and sends the other processors off to there until |
| 1812 | * smp_boot_cpus tells them to do something. The holding pattern |
| 1813 | * checks that address until its cpu # is there, when it is that |
| 1814 | * cpu jumps to __secondary_start(). smp_boot_cpus() takes care |
| 1815 | * of setting those values. |
| 1816 | * |
| 1817 | * We also use physical address 0x4 here to tell when a cpu |
| 1818 | * is in its holding pattern code. |
| 1819 | * |
| 1820 | * -- Cort |
| 1821 | */ |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 1822 | /* |
| 1823 | * We want to reference the copy of __secondary_hold_* in the |
| 1824 | * 0 - 0x100 address range |
| 1825 | */ |
| 1826 | #define LOW_ADDR(x) (((unsigned long) &(x)) & 0xff) |
| 1827 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1828 | static void __init prom_hold_cpus(void) |
| 1829 | { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1830 | unsigned long i; |
| 1831 | unsigned int reg; |
| 1832 | phandle node; |
| 1833 | char type[64]; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1834 | unsigned long *spinloop |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 1835 | = (void *) LOW_ADDR(__secondary_hold_spinloop); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1836 | unsigned long *acknowledge |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 1837 | = (void *) LOW_ADDR(__secondary_hold_acknowledge); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 1838 | unsigned long secondary_hold = LOW_ADDR(__secondary_hold); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1839 | |
| 1840 | prom_debug("prom_hold_cpus: start...\n"); |
| 1841 | prom_debug(" 1) spinloop = 0x%x\n", (unsigned long)spinloop); |
| 1842 | prom_debug(" 1) *spinloop = 0x%x\n", *spinloop); |
| 1843 | prom_debug(" 1) acknowledge = 0x%x\n", |
| 1844 | (unsigned long)acknowledge); |
| 1845 | prom_debug(" 1) *acknowledge = 0x%x\n", *acknowledge); |
| 1846 | prom_debug(" 1) secondary_hold = 0x%x\n", secondary_hold); |
| 1847 | |
| 1848 | /* Set the common spinloop variable, so all of the secondary cpus |
| 1849 | * will block when they are awakened from their OF spinloop. |
| 1850 | * This must occur for both SMP and non SMP kernels, since OF will |
| 1851 | * be trashed when we move the kernel. |
| 1852 | */ |
| 1853 | *spinloop = 0; |
| 1854 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1855 | /* look for cpus */ |
| 1856 | for (node = 0; prom_next_node(&node); ) { |
| 1857 | type[0] = 0; |
| 1858 | prom_getprop(node, "device_type", type, sizeof(type)); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1859 | if (strcmp(type, "cpu") != 0) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1860 | continue; |
| 1861 | |
| 1862 | /* Skip non-configured cpus. */ |
| 1863 | if (prom_getprop(node, "status", type, sizeof(type)) > 0) |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1864 | if (strcmp(type, "okay") != 0) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1865 | continue; |
| 1866 | |
| 1867 | reg = -1; |
| 1868 | prom_getprop(node, "reg", ®, sizeof(reg)); |
| 1869 | |
Michael Neuling | 2c48a7d | 2010-07-27 18:26:21 +0000 | [diff] [blame] | 1870 | prom_debug("cpu hw idx = %lu\n", reg); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1871 | |
| 1872 | /* Init the acknowledge var which will be reset by |
| 1873 | * the secondary cpu when it awakens from its OF |
| 1874 | * spinloop. |
| 1875 | */ |
| 1876 | *acknowledge = (unsigned long)-1; |
| 1877 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1878 | if (reg != prom.cpu) { |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 1879 | /* Primary Thread of non-boot cpu or any thread */ |
Michael Neuling | 2c48a7d | 2010-07-27 18:26:21 +0000 | [diff] [blame] | 1880 | prom_printf("starting cpu hw idx %lu... ", reg); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1881 | call_prom("start-cpu", 3, 0, node, |
| 1882 | secondary_hold, reg); |
| 1883 | |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 1884 | for (i = 0; (i < 100000000) && |
| 1885 | (*acknowledge == ((unsigned long)-1)); i++ ) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1886 | mb(); |
| 1887 | |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 1888 | if (*acknowledge == reg) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1889 | prom_printf("done\n"); |
Paul Mackerras | bbd0abd | 2005-10-26 21:45:56 +1000 | [diff] [blame] | 1890 | else |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1891 | prom_printf("failed: %x\n", *acknowledge); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1892 | } |
| 1893 | #ifdef CONFIG_SMP |
| 1894 | else |
Michael Neuling | 2c48a7d | 2010-07-27 18:26:21 +0000 | [diff] [blame] | 1895 | prom_printf("boot cpu hw idx %lu\n", reg); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1896 | #endif /* CONFIG_SMP */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1897 | } |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1898 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1899 | prom_debug("prom_hold_cpus: end...\n"); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1900 | } |
| 1901 | |
| 1902 | |
| 1903 | static void __init prom_init_client_services(unsigned long pp) |
| 1904 | { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1905 | /* Get a handle to the prom entry point before anything else */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1906 | prom_entry = pp; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1907 | |
| 1908 | /* get a handle for the stdout device */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1909 | prom.chosen = call_prom("finddevice", 1, 1, ADDR("/chosen")); |
| 1910 | if (!PHANDLE_VALID(prom.chosen)) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1911 | prom_panic("cannot find chosen"); /* msg won't be printed :( */ |
| 1912 | |
| 1913 | /* get device tree root */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1914 | prom.root = call_prom("finddevice", 1, 1, ADDR("/")); |
| 1915 | if (!PHANDLE_VALID(prom.root)) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1916 | prom_panic("cannot find device tree root"); /* msg won't be printed :( */ |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 1917 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1918 | prom.mmumap = 0; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1919 | } |
| 1920 | |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 1921 | #ifdef CONFIG_PPC32 |
| 1922 | /* |
| 1923 | * For really old powermacs, we need to map things we claim. |
| 1924 | * For that, we need the ihandle of the mmu. |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 1925 | * Also, on the longtrail, we need to work around other bugs. |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 1926 | */ |
| 1927 | static void __init prom_find_mmu(void) |
| 1928 | { |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 1929 | phandle oprom; |
| 1930 | char version[64]; |
| 1931 | |
| 1932 | oprom = call_prom("finddevice", 1, 1, ADDR("/openprom")); |
| 1933 | if (!PHANDLE_VALID(oprom)) |
| 1934 | return; |
| 1935 | if (prom_getprop(oprom, "model", version, sizeof(version)) <= 0) |
| 1936 | return; |
| 1937 | version[sizeof(version) - 1] = 0; |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 1938 | /* XXX might need to add other versions here */ |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 1939 | if (strcmp(version, "Open Firmware, 1.0.5") == 0) |
| 1940 | of_workarounds = OF_WA_CLAIM; |
| 1941 | else if (strncmp(version, "FirmWorks,3.", 12) == 0) { |
| 1942 | of_workarounds = OF_WA_CLAIM | OF_WA_LONGTRAIL; |
| 1943 | call_prom("interpret", 1, 1, "dev /memory 0 to allow-reclaim"); |
| 1944 | } else |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 1945 | return; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1946 | prom.memory = call_prom("open", 1, 1, ADDR("/memory")); |
| 1947 | prom_getprop(prom.chosen, "mmu", &prom.mmumap, |
| 1948 | sizeof(prom.mmumap)); |
| 1949 | if (!IHANDLE_VALID(prom.memory) || !IHANDLE_VALID(prom.mmumap)) |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 1950 | of_workarounds &= ~OF_WA_CLAIM; /* hmmm */ |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 1951 | } |
| 1952 | #else |
| 1953 | #define prom_find_mmu() |
| 1954 | #endif |
| 1955 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1956 | static void __init prom_init_stdout(void) |
| 1957 | { |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1958 | char *path = of_stdout_device; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1959 | char type[16]; |
| 1960 | u32 val; |
| 1961 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1962 | if (prom_getprop(prom.chosen, "stdout", &val, sizeof(val)) <= 0) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1963 | prom_panic("cannot find stdout"); |
| 1964 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1965 | prom.stdout = val; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1966 | |
| 1967 | /* Get the full OF pathname of the stdout device */ |
| 1968 | memset(path, 0, 256); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1969 | call_prom("instance-to-path", 3, 1, prom.stdout, path, 255); |
| 1970 | val = call_prom("instance-to-package", 1, 1, prom.stdout); |
| 1971 | prom_setprop(prom.chosen, "/chosen", "linux,stdout-package", |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 1972 | &val, sizeof(val)); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1973 | prom_printf("OF stdout device is: %s\n", of_stdout_device); |
| 1974 | prom_setprop(prom.chosen, "/chosen", "linux,stdout-path", |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 1975 | path, strlen(path) + 1); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1976 | |
| 1977 | /* If it's a display, note it */ |
| 1978 | memset(type, 0, sizeof(type)); |
| 1979 | prom_getprop(val, "device_type", type, sizeof(type)); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1980 | if (strcmp(type, "display") == 0) |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 1981 | prom_setprop(val, path, "linux,boot-display", NULL, 0); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1982 | } |
| 1983 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1984 | static int __init prom_find_machine_type(void) |
| 1985 | { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1986 | char compat[256]; |
| 1987 | int len, i = 0; |
Benjamin Herrenschmidt | 21fe330 | 2005-11-07 16:41:59 +1100 | [diff] [blame] | 1988 | #ifdef CONFIG_PPC64 |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1989 | phandle rtas; |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 1990 | int x; |
Benjamin Herrenschmidt | 21fe330 | 2005-11-07 16:41:59 +1100 | [diff] [blame] | 1991 | #endif |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 1992 | |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 1993 | /* Look for a PowerMac or a Cell */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 1994 | len = prom_getprop(prom.root, "compatible", |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1995 | compat, sizeof(compat)-1); |
| 1996 | if (len > 0) { |
| 1997 | compat[len] = 0; |
| 1998 | while (i < len) { |
| 1999 | char *p = &compat[i]; |
| 2000 | int sl = strlen(p); |
| 2001 | if (sl == 0) |
| 2002 | break; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2003 | if (strstr(p, "Power Macintosh") || |
| 2004 | strstr(p, "MacRISC")) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2005 | return PLATFORM_POWERMAC; |
Arnd Bergmann | 133dda1 | 2006-06-07 12:04:18 +1000 | [diff] [blame] | 2006 | #ifdef CONFIG_PPC64 |
| 2007 | /* We must make sure we don't detect the IBM Cell |
| 2008 | * blades as pSeries due to some firmware issues, |
| 2009 | * so we do it here. |
| 2010 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2011 | if (strstr(p, "IBM,CBEA") || |
| 2012 | strstr(p, "IBM,CPBW-1.0")) |
Arnd Bergmann | 133dda1 | 2006-06-07 12:04:18 +1000 | [diff] [blame] | 2013 | return PLATFORM_GENERIC; |
| 2014 | #endif /* CONFIG_PPC64 */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2015 | i += sl + 1; |
| 2016 | } |
| 2017 | } |
| 2018 | #ifdef CONFIG_PPC64 |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 2019 | /* Try to detect OPAL */ |
| 2020 | if (PHANDLE_VALID(call_prom("finddevice", 1, 1, ADDR("/ibm,opal")))) |
| 2021 | return PLATFORM_OPAL; |
| 2022 | |
| 2023 | /* Try to figure out if it's an IBM pSeries or any other |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 2024 | * PAPR compliant platform. We assume it is if : |
| 2025 | * - /device_type is "chrp" (please, do NOT use that for future |
| 2026 | * non-IBM designs ! |
| 2027 | * - it has /rtas |
| 2028 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2029 | len = prom_getprop(prom.root, "device_type", |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 2030 | compat, sizeof(compat)-1); |
| 2031 | if (len <= 0) |
| 2032 | return PLATFORM_GENERIC; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2033 | if (strcmp(compat, "chrp")) |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 2034 | return PLATFORM_GENERIC; |
| 2035 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2036 | /* Default to pSeries. We need to know if we are running LPAR */ |
| 2037 | rtas = call_prom("finddevice", 1, 1, ADDR("/rtas")); |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 2038 | if (!PHANDLE_VALID(rtas)) |
| 2039 | return PLATFORM_GENERIC; |
| 2040 | x = prom_getproplen(rtas, "ibm,hypertas-functions"); |
| 2041 | if (x != PROM_ERROR) { |
Anton Blanchard | 4da727a | 2009-03-31 20:06:14 +0000 | [diff] [blame] | 2042 | prom_debug("Hypertas detected, assuming LPAR !\n"); |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 2043 | return PLATFORM_PSERIES_LPAR; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2044 | } |
| 2045 | return PLATFORM_PSERIES; |
| 2046 | #else |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 2047 | return PLATFORM_GENERIC; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2048 | #endif |
| 2049 | } |
| 2050 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2051 | static int __init prom_set_color(ihandle ih, int i, int r, int g, int b) |
| 2052 | { |
| 2053 | return call_prom("call-method", 6, 1, ADDR("color!"), ih, i, b, g, r); |
| 2054 | } |
| 2055 | |
| 2056 | /* |
| 2057 | * If we have a display that we don't know how to drive, |
| 2058 | * we will want to try to execute OF's open method for it |
| 2059 | * later. However, OF will probably fall over if we do that |
| 2060 | * we've taken over the MMU. |
| 2061 | * So we check whether we will need to open the display, |
| 2062 | * and if so, open it now. |
| 2063 | */ |
| 2064 | static void __init prom_check_displays(void) |
| 2065 | { |
| 2066 | char type[16], *path; |
| 2067 | phandle node; |
| 2068 | ihandle ih; |
| 2069 | int i; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2070 | |
| 2071 | static unsigned char default_colors[] = { |
| 2072 | 0x00, 0x00, 0x00, |
| 2073 | 0x00, 0x00, 0xaa, |
| 2074 | 0x00, 0xaa, 0x00, |
| 2075 | 0x00, 0xaa, 0xaa, |
| 2076 | 0xaa, 0x00, 0x00, |
| 2077 | 0xaa, 0x00, 0xaa, |
| 2078 | 0xaa, 0xaa, 0x00, |
| 2079 | 0xaa, 0xaa, 0xaa, |
| 2080 | 0x55, 0x55, 0x55, |
| 2081 | 0x55, 0x55, 0xff, |
| 2082 | 0x55, 0xff, 0x55, |
| 2083 | 0x55, 0xff, 0xff, |
| 2084 | 0xff, 0x55, 0x55, |
| 2085 | 0xff, 0x55, 0xff, |
| 2086 | 0xff, 0xff, 0x55, |
| 2087 | 0xff, 0xff, 0xff |
| 2088 | }; |
| 2089 | const unsigned char *clut; |
| 2090 | |
Anton Blanchard | 4da727a | 2009-03-31 20:06:14 +0000 | [diff] [blame] | 2091 | prom_debug("Looking for displays\n"); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2092 | for (node = 0; prom_next_node(&node); ) { |
| 2093 | memset(type, 0, sizeof(type)); |
| 2094 | prom_getprop(node, "device_type", type, sizeof(type)); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2095 | if (strcmp(type, "display") != 0) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2096 | continue; |
| 2097 | |
| 2098 | /* It seems OF doesn't null-terminate the path :-( */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2099 | path = prom_scratch; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2100 | memset(path, 0, PROM_SCRATCH_SIZE); |
| 2101 | |
| 2102 | /* |
| 2103 | * leave some room at the end of the path for appending extra |
| 2104 | * arguments |
| 2105 | */ |
| 2106 | if (call_prom("package-to-path", 3, 1, node, path, |
| 2107 | PROM_SCRATCH_SIZE-10) == PROM_ERROR) |
| 2108 | continue; |
Anton Blanchard | 1f8737a | 2009-03-31 20:06:15 +0000 | [diff] [blame] | 2109 | prom_printf("found display : %s, opening... ", path); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2110 | |
| 2111 | ih = call_prom("open", 1, 1, path); |
| 2112 | if (ih == 0) { |
| 2113 | prom_printf("failed\n"); |
| 2114 | continue; |
| 2115 | } |
| 2116 | |
| 2117 | /* Success */ |
| 2118 | prom_printf("done\n"); |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 2119 | prom_setprop(node, path, "linux,opened", NULL, 0); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2120 | |
| 2121 | /* Setup a usable color table when the appropriate |
| 2122 | * method is available. Should update this to set-colors */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2123 | clut = default_colors; |
Benjamin Herrenschmidt | 3f53638 | 2011-12-14 13:55:11 +0000 | [diff] [blame] | 2124 | for (i = 0; i < 16; i++, clut += 3) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2125 | if (prom_set_color(ih, i, clut[0], clut[1], |
| 2126 | clut[2]) != 0) |
| 2127 | break; |
| 2128 | |
| 2129 | #ifdef CONFIG_LOGO_LINUX_CLUT224 |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2130 | clut = PTRRELOC(logo_linux_clut224.clut); |
| 2131 | for (i = 0; i < logo_linux_clut224.clutsize; i++, clut += 3) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2132 | if (prom_set_color(ih, i + 32, clut[0], clut[1], |
| 2133 | clut[2]) != 0) |
| 2134 | break; |
| 2135 | #endif /* CONFIG_LOGO_LINUX_CLUT224 */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2136 | } |
| 2137 | } |
| 2138 | |
| 2139 | |
| 2140 | /* Return (relocated) pointer to this much memory: moves initrd if reqd. */ |
| 2141 | static void __init *make_room(unsigned long *mem_start, unsigned long *mem_end, |
| 2142 | unsigned long needed, unsigned long align) |
| 2143 | { |
| 2144 | void *ret; |
| 2145 | |
| 2146 | *mem_start = _ALIGN(*mem_start, align); |
| 2147 | while ((*mem_start + needed) > *mem_end) { |
| 2148 | unsigned long room, chunk; |
| 2149 | |
| 2150 | prom_debug("Chunk exhausted, claiming more at %x...\n", |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2151 | alloc_bottom); |
| 2152 | room = alloc_top - alloc_bottom; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2153 | if (room > DEVTREE_CHUNK_SIZE) |
| 2154 | room = DEVTREE_CHUNK_SIZE; |
| 2155 | if (room < PAGE_SIZE) |
Anton Blanchard | fbafd72 | 2011-07-25 20:47:51 +0000 | [diff] [blame] | 2156 | prom_panic("No memory for flatten_device_tree " |
| 2157 | "(no room)\n"); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2158 | chunk = alloc_up(room, 0); |
| 2159 | if (chunk == 0) |
Anton Blanchard | fbafd72 | 2011-07-25 20:47:51 +0000 | [diff] [blame] | 2160 | prom_panic("No memory for flatten_device_tree " |
| 2161 | "(claim failed)\n"); |
Anton Blanchard | 966728d | 2011-07-25 20:47:07 +0000 | [diff] [blame] | 2162 | *mem_end = chunk + room; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2163 | } |
| 2164 | |
| 2165 | ret = (void *)*mem_start; |
| 2166 | *mem_start += needed; |
| 2167 | |
| 2168 | return ret; |
| 2169 | } |
| 2170 | |
| 2171 | #define dt_push_token(token, mem_start, mem_end) \ |
| 2172 | do { *((u32 *)make_room(mem_start, mem_end, 4, 4)) = token; } while(0) |
| 2173 | |
| 2174 | static unsigned long __init dt_find_string(char *str) |
| 2175 | { |
| 2176 | char *s, *os; |
| 2177 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2178 | s = os = (char *)dt_string_start; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2179 | s += 4; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2180 | while (s < (char *)dt_string_end) { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2181 | if (strcmp(s, str) == 0) |
| 2182 | return s - os; |
| 2183 | s += strlen(s) + 1; |
| 2184 | } |
| 2185 | return 0; |
| 2186 | } |
| 2187 | |
| 2188 | /* |
| 2189 | * The Open Firmware 1275 specification states properties must be 31 bytes or |
| 2190 | * less, however not all firmwares obey this. Make it 64 bytes to be safe. |
| 2191 | */ |
| 2192 | #define MAX_PROPERTY_NAME 64 |
| 2193 | |
| 2194 | static void __init scan_dt_build_strings(phandle node, |
| 2195 | unsigned long *mem_start, |
| 2196 | unsigned long *mem_end) |
| 2197 | { |
| 2198 | char *prev_name, *namep, *sstart; |
| 2199 | unsigned long soff; |
| 2200 | phandle child; |
| 2201 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2202 | sstart = (char *)dt_string_start; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2203 | |
| 2204 | /* get and store all property names */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2205 | prev_name = ""; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2206 | for (;;) { |
| 2207 | /* 64 is max len of name including nul. */ |
| 2208 | namep = make_room(mem_start, mem_end, MAX_PROPERTY_NAME, 1); |
| 2209 | if (call_prom("nextprop", 3, 1, node, prev_name, namep) != 1) { |
| 2210 | /* No more nodes: unwind alloc */ |
| 2211 | *mem_start = (unsigned long)namep; |
| 2212 | break; |
| 2213 | } |
| 2214 | |
| 2215 | /* skip "name" */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2216 | if (strcmp(namep, "name") == 0) { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2217 | *mem_start = (unsigned long)namep; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2218 | prev_name = "name"; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2219 | continue; |
| 2220 | } |
| 2221 | /* get/create string entry */ |
| 2222 | soff = dt_find_string(namep); |
| 2223 | if (soff != 0) { |
| 2224 | *mem_start = (unsigned long)namep; |
| 2225 | namep = sstart + soff; |
| 2226 | } else { |
| 2227 | /* Trim off some if we can */ |
| 2228 | *mem_start = (unsigned long)namep + strlen(namep) + 1; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2229 | dt_string_end = *mem_start; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2230 | } |
| 2231 | prev_name = namep; |
| 2232 | } |
| 2233 | |
| 2234 | /* do all our children */ |
| 2235 | child = call_prom("child", 1, 1, node); |
| 2236 | while (child != 0) { |
| 2237 | scan_dt_build_strings(child, mem_start, mem_end); |
| 2238 | child = call_prom("peer", 1, 1, child); |
| 2239 | } |
| 2240 | } |
| 2241 | |
| 2242 | static void __init scan_dt_build_struct(phandle node, unsigned long *mem_start, |
| 2243 | unsigned long *mem_end) |
| 2244 | { |
| 2245 | phandle child; |
| 2246 | char *namep, *prev_name, *sstart, *p, *ep, *lp, *path; |
| 2247 | unsigned long soff; |
| 2248 | unsigned char *valp; |
| 2249 | static char pname[MAX_PROPERTY_NAME]; |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 2250 | int l, room, has_phandle = 0; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2251 | |
| 2252 | dt_push_token(OF_DT_BEGIN_NODE, mem_start, mem_end); |
| 2253 | |
| 2254 | /* get the node's full name */ |
| 2255 | namep = (char *)*mem_start; |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 2256 | room = *mem_end - *mem_start; |
| 2257 | if (room > 255) |
| 2258 | room = 255; |
| 2259 | l = call_prom("package-to-path", 3, 1, node, namep, room); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2260 | if (l >= 0) { |
| 2261 | /* Didn't fit? Get more room. */ |
Paul Mackerras | c4988820 | 2005-10-26 21:52:53 +1000 | [diff] [blame] | 2262 | if (l >= room) { |
| 2263 | if (l >= *mem_end - *mem_start) |
| 2264 | namep = make_room(mem_start, mem_end, l+1, 1); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2265 | call_prom("package-to-path", 3, 1, node, namep, l); |
| 2266 | } |
| 2267 | namep[l] = '\0'; |
| 2268 | |
| 2269 | /* Fixup an Apple bug where they have bogus \0 chars in the |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 2270 | * middle of the path in some properties, and extract |
| 2271 | * the unit name (everything after the last '/'). |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2272 | */ |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 2273 | for (lp = p = namep, ep = namep + l; p < ep; p++) { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2274 | if (*p == '/') |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 2275 | lp = namep; |
| 2276 | else if (*p != 0) |
| 2277 | *lp++ = *p; |
| 2278 | } |
| 2279 | *lp = 0; |
| 2280 | *mem_start = _ALIGN((unsigned long)lp + 1, 4); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2281 | } |
| 2282 | |
| 2283 | /* get it again for debugging */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2284 | path = prom_scratch; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2285 | memset(path, 0, PROM_SCRATCH_SIZE); |
| 2286 | call_prom("package-to-path", 3, 1, node, path, PROM_SCRATCH_SIZE-1); |
| 2287 | |
| 2288 | /* get and store all properties */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2289 | prev_name = ""; |
| 2290 | sstart = (char *)dt_string_start; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2291 | for (;;) { |
| 2292 | if (call_prom("nextprop", 3, 1, node, prev_name, |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2293 | pname) != 1) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2294 | break; |
| 2295 | |
| 2296 | /* skip "name" */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2297 | if (strcmp(pname, "name") == 0) { |
| 2298 | prev_name = "name"; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2299 | continue; |
| 2300 | } |
| 2301 | |
| 2302 | /* find string offset */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2303 | soff = dt_find_string(pname); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2304 | if (soff == 0) { |
| 2305 | prom_printf("WARNING: Can't find string index for" |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2306 | " <%s>, node %s\n", pname, path); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2307 | break; |
| 2308 | } |
| 2309 | prev_name = sstart + soff; |
| 2310 | |
| 2311 | /* get length */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2312 | l = call_prom("getproplen", 2, 1, node, pname); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2313 | |
| 2314 | /* sanity checks */ |
| 2315 | if (l == PROM_ERROR) |
| 2316 | continue; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2317 | |
| 2318 | /* push property head */ |
| 2319 | dt_push_token(OF_DT_PROP, mem_start, mem_end); |
| 2320 | dt_push_token(l, mem_start, mem_end); |
| 2321 | dt_push_token(soff, mem_start, mem_end); |
| 2322 | |
| 2323 | /* push property content */ |
| 2324 | valp = make_room(mem_start, mem_end, l, 4); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2325 | call_prom("getprop", 4, 1, node, pname, valp, l); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2326 | *mem_start = _ALIGN(*mem_start, 4); |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 2327 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2328 | if (!strcmp(pname, "phandle")) |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 2329 | has_phandle = 1; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2330 | } |
| 2331 | |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 2332 | /* Add a "linux,phandle" property if no "phandle" property already |
| 2333 | * existed (can happen with OPAL) |
| 2334 | */ |
| 2335 | if (!has_phandle) { |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2336 | soff = dt_find_string("linux,phandle"); |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 2337 | if (soff == 0) |
| 2338 | prom_printf("WARNING: Can't find string index for" |
| 2339 | " <linux-phandle> node %s\n", path); |
| 2340 | else { |
| 2341 | dt_push_token(OF_DT_PROP, mem_start, mem_end); |
| 2342 | dt_push_token(4, mem_start, mem_end); |
| 2343 | dt_push_token(soff, mem_start, mem_end); |
| 2344 | valp = make_room(mem_start, mem_end, 4, 4); |
| 2345 | *(u32 *)valp = node; |
| 2346 | } |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2347 | } |
| 2348 | |
| 2349 | /* do all our children */ |
| 2350 | child = call_prom("child", 1, 1, node); |
| 2351 | while (child != 0) { |
| 2352 | scan_dt_build_struct(child, mem_start, mem_end); |
| 2353 | child = call_prom("peer", 1, 1, child); |
| 2354 | } |
| 2355 | |
| 2356 | dt_push_token(OF_DT_END_NODE, mem_start, mem_end); |
| 2357 | } |
| 2358 | |
| 2359 | static void __init flatten_device_tree(void) |
| 2360 | { |
| 2361 | phandle root; |
| 2362 | unsigned long mem_start, mem_end, room; |
| 2363 | struct boot_param_header *hdr; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2364 | char *namep; |
| 2365 | u64 *rsvmap; |
| 2366 | |
| 2367 | /* |
| 2368 | * Check how much room we have between alloc top & bottom (+/- a |
Anton Blanchard | fbafd72 | 2011-07-25 20:47:51 +0000 | [diff] [blame] | 2369 | * few pages), crop to 1MB, as this is our "chunk" size |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2370 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2371 | room = alloc_top - alloc_bottom - 0x4000; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2372 | if (room > DEVTREE_CHUNK_SIZE) |
| 2373 | room = DEVTREE_CHUNK_SIZE; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2374 | prom_debug("starting device tree allocs at %x\n", alloc_bottom); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2375 | |
| 2376 | /* Now try to claim that */ |
| 2377 | mem_start = (unsigned long)alloc_up(room, PAGE_SIZE); |
| 2378 | if (mem_start == 0) |
| 2379 | prom_panic("Can't allocate initial device-tree chunk\n"); |
Anton Blanchard | 966728d | 2011-07-25 20:47:07 +0000 | [diff] [blame] | 2380 | mem_end = mem_start + room; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2381 | |
| 2382 | /* Get root of tree */ |
| 2383 | root = call_prom("peer", 1, 1, (phandle)0); |
| 2384 | if (root == (phandle)0) |
| 2385 | prom_panic ("couldn't get device tree root\n"); |
| 2386 | |
| 2387 | /* Build header and make room for mem rsv map */ |
| 2388 | mem_start = _ALIGN(mem_start, 4); |
| 2389 | hdr = make_room(&mem_start, &mem_end, |
| 2390 | sizeof(struct boot_param_header), 4); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2391 | dt_header_start = (unsigned long)hdr; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2392 | rsvmap = make_room(&mem_start, &mem_end, sizeof(mem_reserve_map), 8); |
| 2393 | |
| 2394 | /* Start of strings */ |
| 2395 | mem_start = PAGE_ALIGN(mem_start); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2396 | dt_string_start = mem_start; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2397 | mem_start += 4; /* hole */ |
| 2398 | |
| 2399 | /* Add "linux,phandle" in there, we'll need it */ |
| 2400 | namep = make_room(&mem_start, &mem_end, 16, 1); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2401 | strcpy(namep, "linux,phandle"); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2402 | mem_start = (unsigned long)namep + strlen(namep) + 1; |
| 2403 | |
| 2404 | /* Build string array */ |
| 2405 | prom_printf("Building dt strings...\n"); |
| 2406 | scan_dt_build_strings(root, &mem_start, &mem_end); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2407 | dt_string_end = mem_start; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2408 | |
| 2409 | /* Build structure */ |
| 2410 | mem_start = PAGE_ALIGN(mem_start); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2411 | dt_struct_start = mem_start; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2412 | prom_printf("Building dt structure...\n"); |
| 2413 | scan_dt_build_struct(root, &mem_start, &mem_end); |
| 2414 | dt_push_token(OF_DT_END, &mem_start, &mem_end); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2415 | dt_struct_end = PAGE_ALIGN(mem_start); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2416 | |
| 2417 | /* Finish header */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2418 | hdr->boot_cpuid_phys = prom.cpu; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2419 | hdr->magic = OF_DT_HEADER; |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2420 | hdr->totalsize = dt_struct_end - dt_header_start; |
| 2421 | hdr->off_dt_struct = dt_struct_start - dt_header_start; |
| 2422 | hdr->off_dt_strings = dt_string_start - dt_header_start; |
| 2423 | hdr->dt_strings_size = dt_string_end - dt_string_start; |
| 2424 | hdr->off_mem_rsvmap = ((unsigned long)rsvmap) - dt_header_start; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2425 | hdr->version = OF_DT_VERSION; |
| 2426 | /* Version 16 is not backward compatible */ |
| 2427 | hdr->last_comp_version = 0x10; |
| 2428 | |
Jimi Xenidis | 4d1f3f2 | 2006-05-18 17:03:05 -0500 | [diff] [blame] | 2429 | /* Copy the reserve map in */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2430 | memcpy(rsvmap, mem_reserve_map, sizeof(mem_reserve_map)); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2431 | |
| 2432 | #ifdef DEBUG_PROM |
| 2433 | { |
| 2434 | int i; |
| 2435 | prom_printf("reserved memory map:\n"); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2436 | for (i = 0; i < mem_reserve_cnt; i++) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2437 | prom_printf(" %x - %x\n", |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2438 | mem_reserve_map[i].base, |
| 2439 | mem_reserve_map[i].size); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2440 | } |
| 2441 | #endif |
Jimi Xenidis | 4d1f3f2 | 2006-05-18 17:03:05 -0500 | [diff] [blame] | 2442 | /* Bump mem_reserve_cnt to cause further reservations to fail |
| 2443 | * since it's too late. |
| 2444 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2445 | mem_reserve_cnt = MEM_RESERVE_MAP_SIZE; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2446 | |
| 2447 | prom_printf("Device tree strings 0x%x -> 0x%x\n", |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2448 | dt_string_start, dt_string_end); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2449 | prom_printf("Device tree struct 0x%x -> 0x%x\n", |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2450 | dt_struct_start, dt_struct_end); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2451 | |
| 2452 | } |
| 2453 | |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2454 | #ifdef CONFIG_PPC_MAPLE |
| 2455 | /* PIBS Version 1.05.0000 04/26/2005 has an incorrect /ht/isa/ranges property. |
| 2456 | * The values are bad, and it doesn't even have the right number of cells. */ |
| 2457 | static void __init fixup_device_tree_maple(void) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2458 | { |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2459 | phandle isa; |
Benjamin Herrenschmidt | 980a651 | 2006-07-03 17:22:05 +1000 | [diff] [blame] | 2460 | u32 rloc = 0x01002000; /* IO space; PCI device = 4 */ |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2461 | u32 isa_ranges[6]; |
Benjamin Herrenschmidt | 980a651 | 2006-07-03 17:22:05 +1000 | [diff] [blame] | 2462 | char *name; |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2463 | |
Benjamin Herrenschmidt | 980a651 | 2006-07-03 17:22:05 +1000 | [diff] [blame] | 2464 | name = "/ht@0/isa@4"; |
| 2465 | isa = call_prom("finddevice", 1, 1, ADDR(name)); |
| 2466 | if (!PHANDLE_VALID(isa)) { |
| 2467 | name = "/ht@0/isa@6"; |
| 2468 | isa = call_prom("finddevice", 1, 1, ADDR(name)); |
| 2469 | rloc = 0x01003000; /* IO space; PCI device = 6 */ |
| 2470 | } |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2471 | if (!PHANDLE_VALID(isa)) |
| 2472 | return; |
| 2473 | |
Benjamin Herrenschmidt | 980a651 | 2006-07-03 17:22:05 +1000 | [diff] [blame] | 2474 | if (prom_getproplen(isa, "ranges") != 12) |
| 2475 | return; |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2476 | if (prom_getprop(isa, "ranges", isa_ranges, sizeof(isa_ranges)) |
| 2477 | == PROM_ERROR) |
| 2478 | return; |
| 2479 | |
| 2480 | if (isa_ranges[0] != 0x1 || |
| 2481 | isa_ranges[1] != 0xf4000000 || |
| 2482 | isa_ranges[2] != 0x00010000) |
| 2483 | return; |
| 2484 | |
Benjamin Herrenschmidt | 980a651 | 2006-07-03 17:22:05 +1000 | [diff] [blame] | 2485 | prom_printf("Fixing up bogus ISA range on Maple/Apache...\n"); |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2486 | |
| 2487 | isa_ranges[0] = 0x1; |
| 2488 | isa_ranges[1] = 0x0; |
Benjamin Herrenschmidt | 980a651 | 2006-07-03 17:22:05 +1000 | [diff] [blame] | 2489 | isa_ranges[2] = rloc; |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2490 | isa_ranges[3] = 0x0; |
| 2491 | isa_ranges[4] = 0x0; |
| 2492 | isa_ranges[5] = 0x00010000; |
Benjamin Herrenschmidt | 980a651 | 2006-07-03 17:22:05 +1000 | [diff] [blame] | 2493 | prom_setprop(isa, name, "ranges", |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2494 | isa_ranges, sizeof(isa_ranges)); |
| 2495 | } |
Harry Ciao | 8f101a05 | 2009-06-17 16:28:00 -0700 | [diff] [blame] | 2496 | |
| 2497 | #define CPC925_MC_START 0xf8000000 |
| 2498 | #define CPC925_MC_LENGTH 0x1000000 |
| 2499 | /* The values for memory-controller don't have right number of cells */ |
| 2500 | static void __init fixup_device_tree_maple_memory_controller(void) |
| 2501 | { |
| 2502 | phandle mc; |
| 2503 | u32 mc_reg[4]; |
| 2504 | char *name = "/hostbridge@f8000000"; |
Harry Ciao | 8f101a05 | 2009-06-17 16:28:00 -0700 | [diff] [blame] | 2505 | u32 ac, sc; |
| 2506 | |
| 2507 | mc = call_prom("finddevice", 1, 1, ADDR(name)); |
| 2508 | if (!PHANDLE_VALID(mc)) |
| 2509 | return; |
| 2510 | |
| 2511 | if (prom_getproplen(mc, "reg") != 8) |
| 2512 | return; |
| 2513 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2514 | prom_getprop(prom.root, "#address-cells", &ac, sizeof(ac)); |
| 2515 | prom_getprop(prom.root, "#size-cells", &sc, sizeof(sc)); |
Harry Ciao | 8f101a05 | 2009-06-17 16:28:00 -0700 | [diff] [blame] | 2516 | if ((ac != 2) || (sc != 2)) |
| 2517 | return; |
| 2518 | |
| 2519 | if (prom_getprop(mc, "reg", mc_reg, sizeof(mc_reg)) == PROM_ERROR) |
| 2520 | return; |
| 2521 | |
| 2522 | if (mc_reg[0] != CPC925_MC_START || mc_reg[1] != CPC925_MC_LENGTH) |
| 2523 | return; |
| 2524 | |
| 2525 | prom_printf("Fixing up bogus hostbridge on Maple...\n"); |
| 2526 | |
| 2527 | mc_reg[0] = 0x0; |
| 2528 | mc_reg[1] = CPC925_MC_START; |
| 2529 | mc_reg[2] = 0x0; |
| 2530 | mc_reg[3] = CPC925_MC_LENGTH; |
| 2531 | prom_setprop(mc, name, "reg", mc_reg, sizeof(mc_reg)); |
| 2532 | } |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2533 | #else |
| 2534 | #define fixup_device_tree_maple() |
Harry Ciao | 8f101a05 | 2009-06-17 16:28:00 -0700 | [diff] [blame] | 2535 | #define fixup_device_tree_maple_memory_controller() |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2536 | #endif |
| 2537 | |
Benjamin Herrenschmidt | e8c0acf | 2006-07-04 14:06:29 +1000 | [diff] [blame] | 2538 | #ifdef CONFIG_PPC_CHRP |
Olaf Hering | e480592 | 2007-04-04 18:20:04 +0200 | [diff] [blame] | 2539 | /* |
| 2540 | * Pegasos and BriQ lacks the "ranges" property in the isa node |
| 2541 | * Pegasos needs decimal IRQ 14/15, not hexadecimal |
Olaf Hering | 556ecf9 | 2007-08-18 04:27:17 +1000 | [diff] [blame] | 2542 | * Pegasos has the IDE configured in legacy mode, but advertised as native |
Olaf Hering | e480592 | 2007-04-04 18:20:04 +0200 | [diff] [blame] | 2543 | */ |
Benjamin Herrenschmidt | e8c0acf | 2006-07-04 14:06:29 +1000 | [diff] [blame] | 2544 | static void __init fixup_device_tree_chrp(void) |
| 2545 | { |
Olaf Hering | e480592 | 2007-04-04 18:20:04 +0200 | [diff] [blame] | 2546 | phandle ph; |
| 2547 | u32 prop[6]; |
Benjamin Herrenschmidt | 26c5032 | 2006-07-04 14:16:28 +1000 | [diff] [blame] | 2548 | u32 rloc = 0x01006000; /* IO space; PCI device = 12 */ |
Benjamin Herrenschmidt | e8c0acf | 2006-07-04 14:06:29 +1000 | [diff] [blame] | 2549 | char *name; |
| 2550 | int rc; |
| 2551 | |
| 2552 | name = "/pci@80000000/isa@c"; |
Olaf Hering | e480592 | 2007-04-04 18:20:04 +0200 | [diff] [blame] | 2553 | ph = call_prom("finddevice", 1, 1, ADDR(name)); |
| 2554 | if (!PHANDLE_VALID(ph)) { |
Benjamin Herrenschmidt | 26c5032 | 2006-07-04 14:16:28 +1000 | [diff] [blame] | 2555 | name = "/pci@ff500000/isa@6"; |
Olaf Hering | e480592 | 2007-04-04 18:20:04 +0200 | [diff] [blame] | 2556 | ph = call_prom("finddevice", 1, 1, ADDR(name)); |
Benjamin Herrenschmidt | 26c5032 | 2006-07-04 14:16:28 +1000 | [diff] [blame] | 2557 | rloc = 0x01003000; /* IO space; PCI device = 6 */ |
| 2558 | } |
Olaf Hering | e480592 | 2007-04-04 18:20:04 +0200 | [diff] [blame] | 2559 | if (PHANDLE_VALID(ph)) { |
| 2560 | rc = prom_getproplen(ph, "ranges"); |
| 2561 | if (rc == 0 || rc == PROM_ERROR) { |
| 2562 | prom_printf("Fixing up missing ISA range on Pegasos...\n"); |
Benjamin Herrenschmidt | e8c0acf | 2006-07-04 14:06:29 +1000 | [diff] [blame] | 2563 | |
Olaf Hering | e480592 | 2007-04-04 18:20:04 +0200 | [diff] [blame] | 2564 | prop[0] = 0x1; |
| 2565 | prop[1] = 0x0; |
| 2566 | prop[2] = rloc; |
| 2567 | prop[3] = 0x0; |
| 2568 | prop[4] = 0x0; |
| 2569 | prop[5] = 0x00010000; |
| 2570 | prom_setprop(ph, name, "ranges", prop, sizeof(prop)); |
| 2571 | } |
| 2572 | } |
Benjamin Herrenschmidt | e8c0acf | 2006-07-04 14:06:29 +1000 | [diff] [blame] | 2573 | |
Olaf Hering | e480592 | 2007-04-04 18:20:04 +0200 | [diff] [blame] | 2574 | name = "/pci@80000000/ide@C,1"; |
| 2575 | ph = call_prom("finddevice", 1, 1, ADDR(name)); |
| 2576 | if (PHANDLE_VALID(ph)) { |
| 2577 | prom_printf("Fixing up IDE interrupt on Pegasos...\n"); |
| 2578 | prop[0] = 14; |
| 2579 | prop[1] = 0x0; |
Olaf Hering | 556ecf9 | 2007-08-18 04:27:17 +1000 | [diff] [blame] | 2580 | prom_setprop(ph, name, "interrupts", prop, 2*sizeof(u32)); |
| 2581 | prom_printf("Fixing up IDE class-code on Pegasos...\n"); |
| 2582 | rc = prom_getprop(ph, "class-code", prop, sizeof(u32)); |
| 2583 | if (rc == sizeof(u32)) { |
| 2584 | prop[0] &= ~0x5; |
| 2585 | prom_setprop(ph, name, "class-code", prop, sizeof(u32)); |
| 2586 | } |
Olaf Hering | e480592 | 2007-04-04 18:20:04 +0200 | [diff] [blame] | 2587 | } |
Benjamin Herrenschmidt | e8c0acf | 2006-07-04 14:06:29 +1000 | [diff] [blame] | 2588 | } |
| 2589 | #else |
| 2590 | #define fixup_device_tree_chrp() |
| 2591 | #endif |
| 2592 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2593 | #if defined(CONFIG_PPC64) && defined(CONFIG_PPC_PMAC) |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2594 | static void __init fixup_device_tree_pmac(void) |
| 2595 | { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2596 | phandle u3, i2c, mpic; |
| 2597 | u32 u3_rev; |
| 2598 | u32 interrupts[2]; |
| 2599 | u32 parent; |
| 2600 | |
| 2601 | /* Some G5s have a missing interrupt definition, fix it up here */ |
| 2602 | u3 = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000")); |
| 2603 | if (!PHANDLE_VALID(u3)) |
| 2604 | return; |
| 2605 | i2c = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000/i2c@f8001000")); |
| 2606 | if (!PHANDLE_VALID(i2c)) |
| 2607 | return; |
| 2608 | mpic = call_prom("finddevice", 1, 1, ADDR("/u3@0,f8000000/mpic@f8040000")); |
| 2609 | if (!PHANDLE_VALID(mpic)) |
| 2610 | return; |
| 2611 | |
| 2612 | /* check if proper rev of u3 */ |
| 2613 | if (prom_getprop(u3, "device-rev", &u3_rev, sizeof(u3_rev)) |
| 2614 | == PROM_ERROR) |
| 2615 | return; |
Benjamin Herrenschmidt | 7d49697 | 2005-11-07 14:36:21 +1100 | [diff] [blame] | 2616 | if (u3_rev < 0x35 || u3_rev > 0x39) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2617 | return; |
| 2618 | /* does it need fixup ? */ |
| 2619 | if (prom_getproplen(i2c, "interrupts") > 0) |
| 2620 | return; |
| 2621 | |
| 2622 | prom_printf("fixing up bogus interrupts for u3 i2c...\n"); |
| 2623 | |
| 2624 | /* interrupt on this revision of u3 is number 0 and level */ |
| 2625 | interrupts[0] = 0; |
| 2626 | interrupts[1] = 1; |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 2627 | prom_setprop(i2c, "/u3@0,f8000000/i2c@f8001000", "interrupts", |
| 2628 | &interrupts, sizeof(interrupts)); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2629 | parent = (u32)mpic; |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 2630 | prom_setprop(i2c, "/u3@0,f8000000/i2c@f8001000", "interrupt-parent", |
| 2631 | &parent, sizeof(parent)); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2632 | } |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2633 | #else |
| 2634 | #define fixup_device_tree_pmac() |
| 2635 | #endif |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2636 | |
Sylvain Munaut | 88fd2a9 | 2007-02-12 23:13:20 +0100 | [diff] [blame] | 2637 | #ifdef CONFIG_PPC_EFIKA |
Grant Likely | 94d2dde | 2008-01-24 22:25:32 -0700 | [diff] [blame] | 2638 | /* |
| 2639 | * The MPC5200 FEC driver requires an phy-handle property to tell it how |
| 2640 | * to talk to the phy. If the phy-handle property is missing, then this |
| 2641 | * function is called to add the appropriate nodes and link it to the |
| 2642 | * ethernet node. |
| 2643 | */ |
| 2644 | static void __init fixup_device_tree_efika_add_phy(void) |
Sylvain Munaut | 88fd2a9 | 2007-02-12 23:13:20 +0100 | [diff] [blame] | 2645 | { |
Sylvain Munaut | 88fd2a9 | 2007-02-12 23:13:20 +0100 | [diff] [blame] | 2646 | u32 node; |
| 2647 | char prop[64]; |
Grant Likely | 94d2dde | 2008-01-24 22:25:32 -0700 | [diff] [blame] | 2648 | int rv; |
Sylvain Munaut | 88fd2a9 | 2007-02-12 23:13:20 +0100 | [diff] [blame] | 2649 | |
Grant Likely | 94d2dde | 2008-01-24 22:25:32 -0700 | [diff] [blame] | 2650 | /* Check if /builtin/ethernet exists - bail if it doesn't */ |
| 2651 | node = call_prom("finddevice", 1, 1, ADDR("/builtin/ethernet")); |
Sylvain Munaut | 88fd2a9 | 2007-02-12 23:13:20 +0100 | [diff] [blame] | 2652 | if (!PHANDLE_VALID(node)) |
| 2653 | return; |
| 2654 | |
Grant Likely | 94d2dde | 2008-01-24 22:25:32 -0700 | [diff] [blame] | 2655 | /* Check if the phy-handle property exists - bail if it does */ |
| 2656 | rv = prom_getprop(node, "phy-handle", prop, sizeof(prop)); |
| 2657 | if (!rv) |
Sylvain Munaut | 88fd2a9 | 2007-02-12 23:13:20 +0100 | [diff] [blame] | 2658 | return; |
| 2659 | |
Grant Likely | 94d2dde | 2008-01-24 22:25:32 -0700 | [diff] [blame] | 2660 | /* |
| 2661 | * At this point the ethernet device doesn't have a phy described. |
| 2662 | * Now we need to add the missing phy node and linkage |
| 2663 | */ |
Sylvain Munaut | 88fd2a9 | 2007-02-12 23:13:20 +0100 | [diff] [blame] | 2664 | |
Grant Likely | 94d2dde | 2008-01-24 22:25:32 -0700 | [diff] [blame] | 2665 | /* Check for an MDIO bus node - if missing then create one */ |
Olaf Hering | 6f4347c | 2008-01-10 01:06:08 +1100 | [diff] [blame] | 2666 | node = call_prom("finddevice", 1, 1, ADDR("/builtin/mdio")); |
| 2667 | if (!PHANDLE_VALID(node)) { |
| 2668 | prom_printf("Adding Ethernet MDIO node\n"); |
| 2669 | call_prom("interpret", 1, 1, |
| 2670 | " s\" /builtin\" find-device" |
| 2671 | " new-device" |
| 2672 | " 1 encode-int s\" #address-cells\" property" |
| 2673 | " 0 encode-int s\" #size-cells\" property" |
Grant Likely | 94d2dde | 2008-01-24 22:25:32 -0700 | [diff] [blame] | 2674 | " s\" mdio\" device-name" |
| 2675 | " s\" fsl,mpc5200b-mdio\" encode-string" |
Olaf Hering | 6f4347c | 2008-01-10 01:06:08 +1100 | [diff] [blame] | 2676 | " s\" compatible\" property" |
| 2677 | " 0xf0003000 0x400 reg" |
| 2678 | " 0x2 encode-int" |
| 2679 | " 0x5 encode-int encode+" |
| 2680 | " 0x3 encode-int encode+" |
| 2681 | " s\" interrupts\" property" |
| 2682 | " finish-device"); |
| 2683 | }; |
| 2684 | |
Grant Likely | 94d2dde | 2008-01-24 22:25:32 -0700 | [diff] [blame] | 2685 | /* Check for a PHY device node - if missing then create one and |
| 2686 | * give it's phandle to the ethernet node */ |
| 2687 | node = call_prom("finddevice", 1, 1, |
| 2688 | ADDR("/builtin/mdio/ethernet-phy")); |
Olaf Hering | 6f4347c | 2008-01-10 01:06:08 +1100 | [diff] [blame] | 2689 | if (!PHANDLE_VALID(node)) { |
| 2690 | prom_printf("Adding Ethernet PHY node\n"); |
| 2691 | call_prom("interpret", 1, 1, |
| 2692 | " s\" /builtin/mdio\" find-device" |
| 2693 | " new-device" |
| 2694 | " s\" ethernet-phy\" device-name" |
| 2695 | " 0x10 encode-int s\" reg\" property" |
| 2696 | " my-self" |
| 2697 | " ihandle>phandle" |
| 2698 | " finish-device" |
| 2699 | " s\" /builtin/ethernet\" find-device" |
| 2700 | " encode-int" |
| 2701 | " s\" phy-handle\" property" |
| 2702 | " device-end"); |
| 2703 | } |
Grant Likely | 94d2dde | 2008-01-24 22:25:32 -0700 | [diff] [blame] | 2704 | } |
Olaf Hering | 6f4347c | 2008-01-10 01:06:08 +1100 | [diff] [blame] | 2705 | |
Grant Likely | 94d2dde | 2008-01-24 22:25:32 -0700 | [diff] [blame] | 2706 | static void __init fixup_device_tree_efika(void) |
| 2707 | { |
| 2708 | int sound_irq[3] = { 2, 2, 0 }; |
| 2709 | int bcomm_irq[3*16] = { 3,0,0, 3,1,0, 3,2,0, 3,3,0, |
| 2710 | 3,4,0, 3,5,0, 3,6,0, 3,7,0, |
| 2711 | 3,8,0, 3,9,0, 3,10,0, 3,11,0, |
| 2712 | 3,12,0, 3,13,0, 3,14,0, 3,15,0 }; |
| 2713 | u32 node; |
| 2714 | char prop[64]; |
| 2715 | int rv, len; |
| 2716 | |
| 2717 | /* Check if we're really running on a EFIKA */ |
| 2718 | node = call_prom("finddevice", 1, 1, ADDR("/")); |
| 2719 | if (!PHANDLE_VALID(node)) |
| 2720 | return; |
| 2721 | |
| 2722 | rv = prom_getprop(node, "model", prop, sizeof(prop)); |
| 2723 | if (rv == PROM_ERROR) |
| 2724 | return; |
| 2725 | if (strcmp(prop, "EFIKA5K2")) |
| 2726 | return; |
| 2727 | |
| 2728 | prom_printf("Applying EFIKA device tree fixups\n"); |
| 2729 | |
| 2730 | /* Claiming to be 'chrp' is death */ |
| 2731 | node = call_prom("finddevice", 1, 1, ADDR("/")); |
| 2732 | rv = prom_getprop(node, "device_type", prop, sizeof(prop)); |
| 2733 | if (rv != PROM_ERROR && (strcmp(prop, "chrp") == 0)) |
| 2734 | prom_setprop(node, "/", "device_type", "efika", sizeof("efika")); |
| 2735 | |
David Woodhouse | 7f4392c | 2008-04-14 02:52:38 +1000 | [diff] [blame] | 2736 | /* CODEGEN,description is exposed in /proc/cpuinfo so |
| 2737 | fix that too */ |
| 2738 | rv = prom_getprop(node, "CODEGEN,description", prop, sizeof(prop)); |
| 2739 | if (rv != PROM_ERROR && (strstr(prop, "CHRP"))) |
| 2740 | prom_setprop(node, "/", "CODEGEN,description", |
| 2741 | "Efika 5200B PowerPC System", |
| 2742 | sizeof("Efika 5200B PowerPC System")); |
| 2743 | |
Grant Likely | 94d2dde | 2008-01-24 22:25:32 -0700 | [diff] [blame] | 2744 | /* Fixup bestcomm interrupts property */ |
| 2745 | node = call_prom("finddevice", 1, 1, ADDR("/builtin/bestcomm")); |
| 2746 | if (PHANDLE_VALID(node)) { |
| 2747 | len = prom_getproplen(node, "interrupts"); |
| 2748 | if (len == 12) { |
| 2749 | prom_printf("Fixing bestcomm interrupts property\n"); |
| 2750 | prom_setprop(node, "/builtin/bestcom", "interrupts", |
| 2751 | bcomm_irq, sizeof(bcomm_irq)); |
| 2752 | } |
| 2753 | } |
| 2754 | |
| 2755 | /* Fixup sound interrupts property */ |
| 2756 | node = call_prom("finddevice", 1, 1, ADDR("/builtin/sound")); |
| 2757 | if (PHANDLE_VALID(node)) { |
| 2758 | rv = prom_getprop(node, "interrupts", prop, sizeof(prop)); |
| 2759 | if (rv == PROM_ERROR) { |
| 2760 | prom_printf("Adding sound interrupts property\n"); |
| 2761 | prom_setprop(node, "/builtin/sound", "interrupts", |
| 2762 | sound_irq, sizeof(sound_irq)); |
| 2763 | } |
| 2764 | } |
| 2765 | |
| 2766 | /* Make sure ethernet phy-handle property exists */ |
| 2767 | fixup_device_tree_efika_add_phy(); |
Sylvain Munaut | 88fd2a9 | 2007-02-12 23:13:20 +0100 | [diff] [blame] | 2768 | } |
| 2769 | #else |
| 2770 | #define fixup_device_tree_efika() |
| 2771 | #endif |
| 2772 | |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2773 | static void __init fixup_device_tree(void) |
| 2774 | { |
| 2775 | fixup_device_tree_maple(); |
Harry Ciao | 8f101a05 | 2009-06-17 16:28:00 -0700 | [diff] [blame] | 2776 | fixup_device_tree_maple_memory_controller(); |
Benjamin Herrenschmidt | e8c0acf | 2006-07-04 14:06:29 +1000 | [diff] [blame] | 2777 | fixup_device_tree_chrp(); |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2778 | fixup_device_tree_pmac(); |
Sylvain Munaut | 88fd2a9 | 2007-02-12 23:13:20 +0100 | [diff] [blame] | 2779 | fixup_device_tree_efika(); |
Hollis Blanchard | 54f4ee1 | 2006-05-25 16:36:53 -0500 | [diff] [blame] | 2780 | } |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2781 | |
| 2782 | static void __init prom_find_boot_cpu(void) |
| 2783 | { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2784 | u32 getprop_rval; |
| 2785 | ihandle prom_cpu; |
| 2786 | phandle cpu_pkg; |
| 2787 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2788 | prom.cpu = 0; |
| 2789 | if (prom_getprop(prom.chosen, "cpu", &prom_cpu, sizeof(prom_cpu)) <= 0) |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 2790 | return; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2791 | |
| 2792 | cpu_pkg = call_prom("instance-to-package", 1, 1, prom_cpu); |
| 2793 | |
| 2794 | prom_getprop(cpu_pkg, "reg", &getprop_rval, sizeof(getprop_rval)); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2795 | prom.cpu = getprop_rval; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2796 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2797 | prom_debug("Booting CPU hw index = %lu\n", prom.cpu); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2798 | } |
| 2799 | |
| 2800 | static void __init prom_check_initrd(unsigned long r3, unsigned long r4) |
| 2801 | { |
| 2802 | #ifdef CONFIG_BLK_DEV_INITRD |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2803 | if (r3 && r4 && r4 != 0xdeadbeef) { |
| 2804 | unsigned long val; |
| 2805 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2806 | prom_initrd_start = is_kernel_addr(r3) ? __pa(r3) : r3; |
| 2807 | prom_initrd_end = prom_initrd_start + r4; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2808 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2809 | val = prom_initrd_start; |
| 2810 | prom_setprop(prom.chosen, "/chosen", "linux,initrd-start", |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 2811 | &val, sizeof(val)); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2812 | val = prom_initrd_end; |
| 2813 | prom_setprop(prom.chosen, "/chosen", "linux,initrd-end", |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 2814 | &val, sizeof(val)); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2815 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2816 | reserve_mem(prom_initrd_start, |
| 2817 | prom_initrd_end - prom_initrd_start); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2818 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2819 | prom_debug("initrd_start=0x%x\n", prom_initrd_start); |
| 2820 | prom_debug("initrd_end=0x%x\n", prom_initrd_end); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2821 | } |
| 2822 | #endif /* CONFIG_BLK_DEV_INITRD */ |
| 2823 | } |
| 2824 | |
Anton Blanchard | 5ac47f7 | 2012-11-26 17:39:03 +0000 | [diff] [blame] | 2825 | #ifdef CONFIG_PPC64 |
| 2826 | #ifdef CONFIG_RELOCATABLE |
| 2827 | static void reloc_toc(void) |
| 2828 | { |
| 2829 | } |
| 2830 | |
| 2831 | static void unreloc_toc(void) |
| 2832 | { |
| 2833 | } |
| 2834 | #else |
Anton Blanchard | 1674400 | 2013-03-12 01:51:51 +0000 | [diff] [blame] | 2835 | static void __reloc_toc(unsigned long offset, unsigned long nr_entries) |
Anton Blanchard | 5ac47f7 | 2012-11-26 17:39:03 +0000 | [diff] [blame] | 2836 | { |
| 2837 | unsigned long i; |
Anton Blanchard | 1674400 | 2013-03-12 01:51:51 +0000 | [diff] [blame] | 2838 | unsigned long *toc_entry; |
| 2839 | |
| 2840 | /* Get the start of the TOC by using r2 directly. */ |
| 2841 | asm volatile("addi %0,2,-0x8000" : "=b" (toc_entry)); |
Anton Blanchard | 5ac47f7 | 2012-11-26 17:39:03 +0000 | [diff] [blame] | 2842 | |
| 2843 | for (i = 0; i < nr_entries; i++) { |
| 2844 | *toc_entry = *toc_entry + offset; |
| 2845 | toc_entry++; |
| 2846 | } |
| 2847 | } |
| 2848 | |
| 2849 | static void reloc_toc(void) |
| 2850 | { |
| 2851 | unsigned long offset = reloc_offset(); |
| 2852 | unsigned long nr_entries = |
| 2853 | (__prom_init_toc_end - __prom_init_toc_start) / sizeof(long); |
| 2854 | |
Anton Blanchard | 1674400 | 2013-03-12 01:51:51 +0000 | [diff] [blame] | 2855 | __reloc_toc(offset, nr_entries); |
Anton Blanchard | 5ac47f7 | 2012-11-26 17:39:03 +0000 | [diff] [blame] | 2856 | |
| 2857 | mb(); |
| 2858 | } |
| 2859 | |
| 2860 | static void unreloc_toc(void) |
| 2861 | { |
| 2862 | unsigned long offset = reloc_offset(); |
| 2863 | unsigned long nr_entries = |
| 2864 | (__prom_init_toc_end - __prom_init_toc_start) / sizeof(long); |
| 2865 | |
| 2866 | mb(); |
| 2867 | |
Anton Blanchard | 1674400 | 2013-03-12 01:51:51 +0000 | [diff] [blame] | 2868 | __reloc_toc(-offset, nr_entries); |
Anton Blanchard | 5ac47f7 | 2012-11-26 17:39:03 +0000 | [diff] [blame] | 2869 | } |
| 2870 | #endif |
| 2871 | #endif |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 2872 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2873 | /* |
| 2874 | * We enter here early on, when the Open Firmware prom is still |
| 2875 | * handling exceptions and the MMU hash table for us. |
| 2876 | */ |
| 2877 | |
| 2878 | unsigned long __init prom_init(unsigned long r3, unsigned long r4, |
| 2879 | unsigned long pp, |
Paul Mackerras | 549e815 | 2008-08-30 11:43:47 +1000 | [diff] [blame] | 2880 | unsigned long r6, unsigned long r7, |
| 2881 | unsigned long kbase) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2882 | { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2883 | unsigned long hdr; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2884 | |
| 2885 | #ifdef CONFIG_PPC32 |
Paul Mackerras | 549e815 | 2008-08-30 11:43:47 +1000 | [diff] [blame] | 2886 | unsigned long offset = reloc_offset(); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2887 | reloc_got2(offset); |
Anton Blanchard | 5ac47f7 | 2012-11-26 17:39:03 +0000 | [diff] [blame] | 2888 | #else |
| 2889 | reloc_toc(); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2890 | #endif |
| 2891 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2892 | /* |
| 2893 | * First zero the BSS |
| 2894 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2895 | memset(&__bss_start, 0, __bss_stop - __bss_start); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2896 | |
| 2897 | /* |
| 2898 | * Init interface to Open Firmware, get some node references, |
| 2899 | * like /chosen |
| 2900 | */ |
| 2901 | prom_init_client_services(pp); |
| 2902 | |
| 2903 | /* |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 2904 | * See if this OF is old enough that we need to do explicit maps |
| 2905 | * and other workarounds |
| 2906 | */ |
| 2907 | prom_find_mmu(); |
| 2908 | |
| 2909 | /* |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2910 | * Init prom stdout device |
| 2911 | */ |
| 2912 | prom_init_stdout(); |
| 2913 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2914 | prom_printf("Preparing to boot %s", linux_banner); |
Michael Ellerman | e7943fb | 2009-03-04 19:02:01 +0000 | [diff] [blame] | 2915 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2916 | /* |
| 2917 | * Get default machine type. At this point, we do not differentiate |
| 2918 | * between pSeries SMP and pSeries LPAR |
| 2919 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2920 | of_platform = prom_find_machine_type(); |
| 2921 | prom_printf("Detected machine type: %x\n", of_platform); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2922 | |
Suzuki Poulose | 0f890c8 | 2011-12-14 22:57:15 +0000 | [diff] [blame] | 2923 | #ifndef CONFIG_NONSTATIC_KERNEL |
Olaf Hering | add60ef | 2006-03-23 22:03:57 +0100 | [diff] [blame] | 2924 | /* Bail if this is a kdump kernel. */ |
| 2925 | if (PHYSICAL_START > 0) |
| 2926 | prom_panic("Error: You can't boot a kdump kernel from OF!\n"); |
Paul Mackerras | 549e815 | 2008-08-30 11:43:47 +1000 | [diff] [blame] | 2927 | #endif |
Olaf Hering | add60ef | 2006-03-23 22:03:57 +0100 | [diff] [blame] | 2928 | |
| 2929 | /* |
| 2930 | * Check for an initrd |
| 2931 | */ |
| 2932 | prom_check_initrd(r3, r4); |
| 2933 | |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 2934 | #if defined(CONFIG_PPC_PSERIES) || defined(CONFIG_PPC_POWERNV) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2935 | /* |
| 2936 | * On pSeries, inform the firmware about our capabilities |
| 2937 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2938 | if (of_platform == PLATFORM_PSERIES || |
| 2939 | of_platform == PLATFORM_PSERIES_LPAR) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2940 | prom_send_capabilities(); |
| 2941 | #endif |
| 2942 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2943 | /* |
Arnd Bergmann | f3f66f5 | 2005-10-31 20:08:37 -0500 | [diff] [blame] | 2944 | * Copy the CPU hold code |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2945 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2946 | if (of_platform != PLATFORM_POWERMAC) |
Paul Mackerras | 549e815 | 2008-08-30 11:43:47 +1000 | [diff] [blame] | 2947 | copy_and_flush(0, kbase, 0x100, 0); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2948 | |
| 2949 | /* |
| 2950 | * Do early parsing of command line |
| 2951 | */ |
| 2952 | early_cmdline_parse(); |
| 2953 | |
| 2954 | /* |
| 2955 | * Initialize memory management within prom_init |
| 2956 | */ |
| 2957 | prom_init_mem(); |
| 2958 | |
| 2959 | /* |
| 2960 | * Determine which cpu is actually running right _now_ |
| 2961 | */ |
| 2962 | prom_find_boot_cpu(); |
| 2963 | |
| 2964 | /* |
| 2965 | * Initialize display devices |
| 2966 | */ |
| 2967 | prom_check_displays(); |
| 2968 | |
| 2969 | #ifdef CONFIG_PPC64 |
| 2970 | /* |
| 2971 | * Initialize IOMMU (TCE tables) on pSeries. Do that before anything else |
| 2972 | * that uses the allocator, we need to make sure we get the top of memory |
| 2973 | * available for us here... |
| 2974 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2975 | if (of_platform == PLATFORM_PSERIES) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2976 | prom_initialize_tce_table(); |
| 2977 | #endif |
| 2978 | |
| 2979 | /* |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 2980 | * On non-powermacs, try to instantiate RTAS. PowerMacs don't |
| 2981 | * have a usable RTAS implementation. |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2982 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2983 | if (of_platform != PLATFORM_POWERMAC && |
| 2984 | of_platform != PLATFORM_OPAL) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 2985 | prom_instantiate_rtas(); |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 2986 | |
| 2987 | #ifdef CONFIG_PPC_POWERNV |
| 2988 | /* Detect HAL and try instanciating it & doing takeover */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2989 | if (of_platform == PLATFORM_PSERIES_LPAR) { |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 2990 | prom_query_opal(); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2991 | if (of_platform == PLATFORM_OPAL) { |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 2992 | prom_opal_hold_cpus(); |
| 2993 | prom_opal_takeover(); |
| 2994 | } |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 2995 | } else if (of_platform == PLATFORM_OPAL) |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 2996 | prom_instantiate_opal(); |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 2997 | #endif |
| 2998 | |
Ashley Lai | 4a72742 | 2012-08-14 18:34:57 -0500 | [diff] [blame] | 2999 | #ifdef CONFIG_PPC64 |
| 3000 | /* instantiate sml */ |
| 3001 | prom_instantiate_sml(); |
| 3002 | #endif |
| 3003 | |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 3004 | /* |
| 3005 | * On non-powermacs, put all CPUs in spin-loops. |
| 3006 | * |
| 3007 | * PowerMacs use a different mechanism to spin CPUs |
| 3008 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 3009 | if (of_platform != PLATFORM_POWERMAC && |
| 3010 | of_platform != PLATFORM_OPAL) |
Benjamin Herrenschmidt | 27f4488 | 2011-09-19 18:27:58 +0000 | [diff] [blame] | 3011 | prom_hold_cpus(); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3012 | |
| 3013 | /* |
| 3014 | * Fill in some infos for use by the kernel later on |
| 3015 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 3016 | if (prom_memory_limit) |
| 3017 | prom_setprop(prom.chosen, "/chosen", "linux,memory-limit", |
| 3018 | &prom_memory_limit, |
Benjamin Krill | cf68787 | 2009-07-27 22:02:39 +0000 | [diff] [blame] | 3019 | sizeof(prom_memory_limit)); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3020 | #ifdef CONFIG_PPC64 |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 3021 | if (prom_iommu_off) |
| 3022 | prom_setprop(prom.chosen, "/chosen", "linux,iommu-off", |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 3023 | NULL, 0); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3024 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 3025 | if (prom_iommu_force_on) |
| 3026 | prom_setprop(prom.chosen, "/chosen", "linux,iommu-force-on", |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 3027 | NULL, 0); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3028 | |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 3029 | if (prom_tce_alloc_start) { |
| 3030 | prom_setprop(prom.chosen, "/chosen", "linux,tce-alloc-start", |
| 3031 | &prom_tce_alloc_start, |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3032 | sizeof(prom_tce_alloc_start)); |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 3033 | prom_setprop(prom.chosen, "/chosen", "linux,tce-alloc-end", |
| 3034 | &prom_tce_alloc_end, |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3035 | sizeof(prom_tce_alloc_end)); |
| 3036 | } |
| 3037 | #endif |
| 3038 | |
| 3039 | /* |
| 3040 | * Fixup any known bugs in the device-tree |
| 3041 | */ |
| 3042 | fixup_device_tree(); |
| 3043 | |
| 3044 | /* |
| 3045 | * Now finally create the flattened device-tree |
| 3046 | */ |
Anton Blanchard | 1f8737a | 2009-03-31 20:06:15 +0000 | [diff] [blame] | 3047 | prom_printf("copying OF device tree...\n"); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3048 | flatten_device_tree(); |
| 3049 | |
Paul Mackerras | 3825ac0 | 2005-11-08 22:48:08 +1100 | [diff] [blame] | 3050 | /* |
| 3051 | * in case stdin is USB and still active on IBM machines... |
| 3052 | * Unfortunately quiesce crashes on some powermacs if we have |
Benjamin Herrenschmidt | 40dfef6 | 2011-11-29 18:22:56 +0000 | [diff] [blame] | 3053 | * closed stdin already (in particular the powerbook 101). It |
| 3054 | * appears that the OPAL version of OFW doesn't like it either. |
Paul Mackerras | 3825ac0 | 2005-11-08 22:48:08 +1100 | [diff] [blame] | 3055 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 3056 | if (of_platform != PLATFORM_POWERMAC && |
| 3057 | of_platform != PLATFORM_OPAL) |
Paul Mackerras | 3825ac0 | 2005-11-08 22:48:08 +1100 | [diff] [blame] | 3058 | prom_close_stdin(); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3059 | |
| 3060 | /* |
| 3061 | * Call OF "quiesce" method to shut down pending DMA's from |
| 3062 | * devices etc... |
| 3063 | */ |
Anton Blanchard | 1f8737a | 2009-03-31 20:06:15 +0000 | [diff] [blame] | 3064 | prom_printf("Calling quiesce...\n"); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3065 | call_prom("quiesce", 0, 0); |
| 3066 | |
| 3067 | /* |
| 3068 | * And finally, call the kernel passing it the flattened device |
| 3069 | * tree and NULL as r5, thus triggering the new entry point which |
| 3070 | * is common to us and kexec |
| 3071 | */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 3072 | hdr = dt_header_start; |
Benjamin Herrenschmidt | 40dfef6 | 2011-11-29 18:22:56 +0000 | [diff] [blame] | 3073 | |
| 3074 | /* Don't print anything after quiesce under OPAL, it crashes OFW */ |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 3075 | if (of_platform != PLATFORM_OPAL) { |
Benjamin Herrenschmidt | 40dfef6 | 2011-11-29 18:22:56 +0000 | [diff] [blame] | 3076 | prom_printf("returning from prom_init\n"); |
| 3077 | prom_debug("->dt_header_start=0x%x\n", hdr); |
| 3078 | } |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3079 | |
| 3080 | #ifdef CONFIG_PPC32 |
| 3081 | reloc_got2(-offset); |
Anton Blanchard | 5ac47f7 | 2012-11-26 17:39:03 +0000 | [diff] [blame] | 3082 | #else |
| 3083 | unreloc_toc(); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3084 | #endif |
| 3085 | |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 3086 | #ifdef CONFIG_PPC_EARLY_DEBUG_OPAL |
| 3087 | /* OPAL early debug gets the OPAL base & entry in r8 and r9 */ |
| 3088 | __start(hdr, kbase, 0, 0, 0, |
Anton Blanchard | 5827d41 | 2012-11-26 17:40:03 +0000 | [diff] [blame] | 3089 | prom_opal_base, prom_opal_entry); |
Benjamin Herrenschmidt | 6e35d5d | 2011-09-19 18:28:01 +0000 | [diff] [blame] | 3090 | #else |
| 3091 | __start(hdr, kbase, 0, 0, 0, 0, 0); |
| 3092 | #endif |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 3093 | |
| 3094 | return 0; |
| 3095 | } |