Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Procedures for creating, accessing and interpreting the device tree. |
| 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 |
| 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/stringify.h> |
| 27 | #include <linux/delay.h> |
| 28 | #include <linux/initrd.h> |
| 29 | #include <linux/bitops.h> |
| 30 | #include <linux/module.h> |
Michael Ellerman | dcee303 | 2005-12-04 18:39:48 +1100 | [diff] [blame] | 31 | #include <linux/kexec.h> |
Michael Ellerman | 7a4571a | 2006-06-23 18:16:03 +1000 | [diff] [blame] | 32 | #include <linux/debugfs.h> |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 33 | #include <linux/irq.h> |
David S. Miller | d9b2b2a | 2008-02-13 16:56:49 -0800 | [diff] [blame] | 34 | #include <linux/lmb.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 35 | |
| 36 | #include <asm/prom.h> |
| 37 | #include <asm/rtas.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 38 | #include <asm/page.h> |
| 39 | #include <asm/processor.h> |
| 40 | #include <asm/irq.h> |
| 41 | #include <asm/io.h> |
Michael Ellerman | 0cc4746 | 2005-12-04 18:39:37 +1100 | [diff] [blame] | 42 | #include <asm/kdump.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 43 | #include <asm/smp.h> |
| 44 | #include <asm/system.h> |
| 45 | #include <asm/mmu.h> |
| 46 | #include <asm/pgtable.h> |
| 47 | #include <asm/pci.h> |
| 48 | #include <asm/iommu.h> |
| 49 | #include <asm/btext.h> |
| 50 | #include <asm/sections.h> |
| 51 | #include <asm/machdep.h> |
| 52 | #include <asm/pSeries_reconfig.h> |
Paul Mackerras | 40ef8cb | 2005-10-10 22:50:37 +1000 | [diff] [blame] | 53 | #include <asm/pci-bridge.h> |
Manish Ahuja | 6ac26c8 | 2008-03-22 10:37:08 +1100 | [diff] [blame] | 54 | #include <asm/phyp_dump.h> |
Michael Ellerman | 2babf5c | 2006-05-17 18:00:46 +1000 | [diff] [blame] | 55 | #include <asm/kexec.h> |
Kumar Gala | 37dd2ba | 2008-04-22 04:22:34 +1000 | [diff] [blame] | 56 | #include <mm/mmu_decl.h> |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 57 | |
| 58 | #ifdef DEBUG |
| 59 | #define DBG(fmt...) printk(KERN_ERR fmt) |
| 60 | #else |
| 61 | #define DBG(fmt...) |
| 62 | #endif |
| 63 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 64 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 65 | static int __initdata dt_root_addr_cells; |
| 66 | static int __initdata dt_root_size_cells; |
| 67 | |
| 68 | #ifdef CONFIG_PPC64 |
Olof Johansson | 2889773 | 2006-04-12 21:52:33 -0500 | [diff] [blame] | 69 | int __initdata iommu_is_off; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 70 | int __initdata iommu_force_on; |
Paul Mackerras | cf00a8d | 2005-10-31 13:07:02 +1100 | [diff] [blame] | 71 | unsigned long tce_alloc_start, tce_alloc_end; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 72 | #endif |
| 73 | |
| 74 | typedef u32 cell_t; |
| 75 | |
Stephen Rothwell | 581b605 | 2007-04-24 16:46:53 +1000 | [diff] [blame] | 76 | extern rwlock_t devtree_lock; /* temporary while merging */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 77 | |
| 78 | /* export that to outside world */ |
| 79 | struct device_node *of_chosen; |
| 80 | |
Michael Ellerman | 2babf5c | 2006-05-17 18:00:46 +1000 | [diff] [blame] | 81 | static int __init early_parse_mem(char *p) |
| 82 | { |
| 83 | if (!p) |
| 84 | return 1; |
| 85 | |
| 86 | memory_limit = PAGE_ALIGN(memparse(p, &p)); |
Becky Bruce | 49a8496 | 2009-05-08 12:19:27 +0000 | [diff] [blame] | 87 | DBG("memory limit = 0x%llx\n", (unsigned long long)memory_limit); |
Michael Ellerman | 2babf5c | 2006-05-17 18:00:46 +1000 | [diff] [blame] | 88 | |
| 89 | return 0; |
| 90 | } |
| 91 | early_param("mem", early_parse_mem); |
| 92 | |
Linas Vepstas | 3c607ce | 2007-09-07 03:47:29 +1000 | [diff] [blame] | 93 | /** |
| 94 | * move_device_tree - move tree to an unused area, if needed. |
| 95 | * |
| 96 | * The device tree may be allocated beyond our memory limit, or inside the |
| 97 | * crash kernel region for kdump. If so, move it out of the way. |
Michael Ellerman | 2babf5c | 2006-05-17 18:00:46 +1000 | [diff] [blame] | 98 | */ |
Geert Uytterhoeven | 18f032c | 2008-03-29 03:07:45 +1100 | [diff] [blame] | 99 | static void __init move_device_tree(void) |
Michael Ellerman | 2babf5c | 2006-05-17 18:00:46 +1000 | [diff] [blame] | 100 | { |
| 101 | unsigned long start, size; |
| 102 | void *p; |
| 103 | |
| 104 | DBG("-> move_device_tree\n"); |
| 105 | |
| 106 | start = __pa(initial_boot_params); |
| 107 | size = initial_boot_params->totalsize; |
| 108 | |
| 109 | if ((memory_limit && (start + size) > memory_limit) || |
| 110 | overlaps_crashkernel(start, size)) { |
| 111 | p = __va(lmb_alloc_base(size, PAGE_SIZE, lmb.rmo_size)); |
| 112 | memcpy(p, initial_boot_params, size); |
| 113 | initial_boot_params = (struct boot_param_header *)p; |
| 114 | DBG("Moved device tree to 0x%p\n", p); |
| 115 | } |
| 116 | |
| 117 | DBG("<- move_device_tree\n"); |
| 118 | } |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 119 | |
Paul Mackerras | d205819 | 2006-05-03 23:04:37 +1000 | [diff] [blame] | 120 | /* |
| 121 | * ibm,pa-features is a per-cpu property that contains a string of |
| 122 | * attribute descriptors, each of which has a 2 byte header plus up |
| 123 | * to 254 bytes worth of processor attribute bits. First header |
| 124 | * byte specifies the number of bytes following the header. |
| 125 | * Second header byte is an "attribute-specifier" type, of which |
| 126 | * zero is the only currently-defined value. |
| 127 | * Implementation: Pass in the byte and bit offset for the feature |
| 128 | * that we are interested in. The function will return -1 if the |
| 129 | * pa-features property is missing, or a 1/0 to indicate if the feature |
| 130 | * is supported/not supported. Note that the bit numbers are |
| 131 | * big-endian to match the definition in PAPR. |
| 132 | */ |
| 133 | static struct ibm_pa_feature { |
| 134 | unsigned long cpu_features; /* CPU_FTR_xxx bit */ |
| 135 | unsigned int cpu_user_ftrs; /* PPC_FEATURE_xxx bit */ |
| 136 | unsigned char pabyte; /* byte number in ibm,pa-features */ |
| 137 | unsigned char pabit; /* bit number (big-endian) */ |
| 138 | unsigned char invert; /* if 1, pa bit set => clear feature */ |
| 139 | } ibm_pa_features[] __initdata = { |
| 140 | {0, PPC_FEATURE_HAS_MMU, 0, 0, 0}, |
| 141 | {0, PPC_FEATURE_HAS_FPU, 0, 1, 0}, |
| 142 | {CPU_FTR_SLB, 0, 0, 2, 0}, |
| 143 | {CPU_FTR_CTRL, 0, 0, 3, 0}, |
| 144 | {CPU_FTR_NOEXECUTE, 0, 0, 6, 0}, |
| 145 | {CPU_FTR_NODSISRALIGN, 0, 1, 1, 1}, |
| 146 | {CPU_FTR_CI_LARGE_PAGE, 0, 1, 2, 0}, |
Paul Mackerras | 339d76c | 2006-06-29 17:12:30 +1000 | [diff] [blame] | 147 | {CPU_FTR_REAL_LE, PPC_FEATURE_TRUE_LE, 5, 0, 0}, |
Paul Mackerras | d205819 | 2006-05-03 23:04:37 +1000 | [diff] [blame] | 148 | }; |
| 149 | |
Paul Mackerras | 974a76f | 2006-11-10 20:38:53 +1100 | [diff] [blame] | 150 | static void __init scan_features(unsigned long node, unsigned char *ftrs, |
| 151 | unsigned long tablelen, |
| 152 | struct ibm_pa_feature *fp, |
| 153 | unsigned long ft_size) |
Paul Mackerras | d205819 | 2006-05-03 23:04:37 +1000 | [diff] [blame] | 154 | { |
Paul Mackerras | 974a76f | 2006-11-10 20:38:53 +1100 | [diff] [blame] | 155 | unsigned long i, len, bit; |
Paul Mackerras | d205819 | 2006-05-03 23:04:37 +1000 | [diff] [blame] | 156 | |
| 157 | /* find descriptor with type == 0 */ |
| 158 | for (;;) { |
| 159 | if (tablelen < 3) |
| 160 | return; |
Paul Mackerras | 974a76f | 2006-11-10 20:38:53 +1100 | [diff] [blame] | 161 | len = 2 + ftrs[0]; |
Paul Mackerras | d205819 | 2006-05-03 23:04:37 +1000 | [diff] [blame] | 162 | if (tablelen < len) |
| 163 | return; /* descriptor 0 not found */ |
Paul Mackerras | 974a76f | 2006-11-10 20:38:53 +1100 | [diff] [blame] | 164 | if (ftrs[1] == 0) |
Paul Mackerras | d205819 | 2006-05-03 23:04:37 +1000 | [diff] [blame] | 165 | break; |
| 166 | tablelen -= len; |
Paul Mackerras | 974a76f | 2006-11-10 20:38:53 +1100 | [diff] [blame] | 167 | ftrs += len; |
Paul Mackerras | d205819 | 2006-05-03 23:04:37 +1000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /* loop over bits we know about */ |
Paul Mackerras | 974a76f | 2006-11-10 20:38:53 +1100 | [diff] [blame] | 171 | for (i = 0; i < ft_size; ++i, ++fp) { |
| 172 | if (fp->pabyte >= ftrs[0]) |
Paul Mackerras | d205819 | 2006-05-03 23:04:37 +1000 | [diff] [blame] | 173 | continue; |
Paul Mackerras | 974a76f | 2006-11-10 20:38:53 +1100 | [diff] [blame] | 174 | bit = (ftrs[2 + fp->pabyte] >> (7 - fp->pabit)) & 1; |
Paul Mackerras | d205819 | 2006-05-03 23:04:37 +1000 | [diff] [blame] | 175 | if (bit ^ fp->invert) { |
| 176 | cur_cpu_spec->cpu_features |= fp->cpu_features; |
| 177 | cur_cpu_spec->cpu_user_features |= fp->cpu_user_ftrs; |
| 178 | } else { |
| 179 | cur_cpu_spec->cpu_features &= ~fp->cpu_features; |
| 180 | cur_cpu_spec->cpu_user_features &= ~fp->cpu_user_ftrs; |
| 181 | } |
| 182 | } |
| 183 | } |
| 184 | |
Paul Mackerras | 974a76f | 2006-11-10 20:38:53 +1100 | [diff] [blame] | 185 | static void __init check_cpu_pa_features(unsigned long node) |
| 186 | { |
| 187 | unsigned char *pa_ftrs; |
| 188 | unsigned long tablelen; |
| 189 | |
| 190 | pa_ftrs = of_get_flat_dt_prop(node, "ibm,pa-features", &tablelen); |
| 191 | if (pa_ftrs == NULL) |
| 192 | return; |
| 193 | |
| 194 | scan_features(node, pa_ftrs, tablelen, |
| 195 | ibm_pa_features, ARRAY_SIZE(ibm_pa_features)); |
| 196 | } |
| 197 | |
Benjamin Herrenschmidt | 9449168 | 2009-06-02 21:17:45 +0000 | [diff] [blame] | 198 | #ifdef CONFIG_PPC_STD_MMU_64 |
Michael Neuling | 584f8b7 | 2007-12-06 17:24:48 +1100 | [diff] [blame] | 199 | static void __init check_cpu_slb_size(unsigned long node) |
| 200 | { |
| 201 | u32 *slb_size_ptr; |
| 202 | |
Michael Neuling | b60c31d | 2009-01-14 13:42:41 +0000 | [diff] [blame] | 203 | slb_size_ptr = of_get_flat_dt_prop(node, "slb-size", NULL); |
| 204 | if (slb_size_ptr != NULL) { |
| 205 | mmu_slb_size = *slb_size_ptr; |
| 206 | return; |
| 207 | } |
Michael Neuling | 584f8b7 | 2007-12-06 17:24:48 +1100 | [diff] [blame] | 208 | slb_size_ptr = of_get_flat_dt_prop(node, "ibm,slb-size", NULL); |
| 209 | if (slb_size_ptr != NULL) { |
| 210 | mmu_slb_size = *slb_size_ptr; |
| 211 | } |
| 212 | } |
| 213 | #else |
| 214 | #define check_cpu_slb_size(node) do { } while(0) |
| 215 | #endif |
| 216 | |
Paul Mackerras | 974a76f | 2006-11-10 20:38:53 +1100 | [diff] [blame] | 217 | static struct feature_property { |
| 218 | const char *name; |
| 219 | u32 min_value; |
| 220 | unsigned long cpu_feature; |
| 221 | unsigned long cpu_user_ftr; |
| 222 | } feature_properties[] __initdata = { |
| 223 | #ifdef CONFIG_ALTIVEC |
| 224 | {"altivec", 0, CPU_FTR_ALTIVEC, PPC_FEATURE_HAS_ALTIVEC}, |
| 225 | {"ibm,vmx", 1, CPU_FTR_ALTIVEC, PPC_FEATURE_HAS_ALTIVEC}, |
| 226 | #endif /* CONFIG_ALTIVEC */ |
Michael Neuling | b962ce9 | 2008-06-25 14:07:18 +1000 | [diff] [blame] | 227 | #ifdef CONFIG_VSX |
| 228 | /* Yes, this _really_ is ibm,vmx == 2 to enable VSX */ |
| 229 | {"ibm,vmx", 2, CPU_FTR_VSX, PPC_FEATURE_HAS_VSX}, |
| 230 | #endif /* CONFIG_VSX */ |
Paul Mackerras | 974a76f | 2006-11-10 20:38:53 +1100 | [diff] [blame] | 231 | #ifdef CONFIG_PPC64 |
| 232 | {"ibm,dfp", 1, 0, PPC_FEATURE_HAS_DFP}, |
| 233 | {"ibm,purr", 1, CPU_FTR_PURR, 0}, |
| 234 | {"ibm,spurr", 1, CPU_FTR_SPURR, 0}, |
| 235 | #endif /* CONFIG_PPC64 */ |
| 236 | }; |
| 237 | |
Valentine Barshak | 14b3d92 | 2007-12-22 03:24:02 +1100 | [diff] [blame] | 238 | #if defined(CONFIG_44x) && defined(CONFIG_PPC_FPU) |
| 239 | static inline void identical_pvr_fixup(unsigned long node) |
| 240 | { |
| 241 | unsigned int pvr; |
| 242 | char *model = of_get_flat_dt_prop(node, "model", NULL); |
| 243 | |
| 244 | /* |
| 245 | * Since 440GR(x)/440EP(x) processors have the same pvr, |
| 246 | * we check the node path and set bit 28 in the cur_cpu_spec |
| 247 | * pvr for EP(x) processor version. This bit is always 0 in |
| 248 | * the "real" pvr. Then we call identify_cpu again with |
| 249 | * the new logical pvr to enable FPU support. |
| 250 | */ |
| 251 | if (model && strstr(model, "440EP")) { |
| 252 | pvr = cur_cpu_spec->pvr_value | 0x8; |
| 253 | identify_cpu(0, pvr); |
| 254 | DBG("Using logical pvr %x for %s\n", pvr, model); |
| 255 | } |
| 256 | } |
| 257 | #else |
| 258 | #define identical_pvr_fixup(node) do { } while(0) |
| 259 | #endif |
| 260 | |
Paul Mackerras | 974a76f | 2006-11-10 20:38:53 +1100 | [diff] [blame] | 261 | static void __init check_cpu_feature_properties(unsigned long node) |
| 262 | { |
| 263 | unsigned long i; |
| 264 | struct feature_property *fp = feature_properties; |
| 265 | const u32 *prop; |
| 266 | |
| 267 | for (i = 0; i < ARRAY_SIZE(feature_properties); ++i, ++fp) { |
| 268 | prop = of_get_flat_dt_prop(node, fp->name, NULL); |
| 269 | if (prop && *prop >= fp->min_value) { |
| 270 | cur_cpu_spec->cpu_features |= fp->cpu_feature; |
| 271 | cur_cpu_spec->cpu_user_features |= fp->cpu_user_ftr; |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 276 | static int __init early_init_dt_scan_cpus(unsigned long node, |
Anton Blanchard | 4df2046 | 2006-03-25 17:25:17 +1100 | [diff] [blame] | 277 | const char *uname, int depth, |
| 278 | void *data) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 279 | { |
Anton Blanchard | 4df2046 | 2006-03-25 17:25:17 +1100 | [diff] [blame] | 280 | static int logical_cpuid = 0; |
| 281 | char *type = of_get_flat_dt_prop(node, "device_type", NULL); |
Paul Mackerras | 974a76f | 2006-11-10 20:38:53 +1100 | [diff] [blame] | 282 | const u32 *prop; |
| 283 | const u32 *intserv; |
Anton Blanchard | 4df2046 | 2006-03-25 17:25:17 +1100 | [diff] [blame] | 284 | int i, nthreads; |
| 285 | unsigned long len; |
| 286 | int found = 0; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 287 | |
| 288 | /* We are scanning "cpu" nodes only */ |
| 289 | if (type == NULL || strcmp(type, "cpu") != 0) |
| 290 | return 0; |
| 291 | |
Anton Blanchard | 4df2046 | 2006-03-25 17:25:17 +1100 | [diff] [blame] | 292 | /* Get physical cpuid */ |
| 293 | intserv = of_get_flat_dt_prop(node, "ibm,ppc-interrupt-server#s", &len); |
| 294 | if (intserv) { |
| 295 | nthreads = len / sizeof(int); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 296 | } else { |
Anton Blanchard | 4df2046 | 2006-03-25 17:25:17 +1100 | [diff] [blame] | 297 | intserv = of_get_flat_dt_prop(node, "reg", NULL); |
| 298 | nthreads = 1; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 299 | } |
Anton Blanchard | 4df2046 | 2006-03-25 17:25:17 +1100 | [diff] [blame] | 300 | |
| 301 | /* |
| 302 | * Now see if any of these threads match our boot cpu. |
| 303 | * NOTE: This must match the parsing done in smp_setup_cpu_maps. |
| 304 | */ |
| 305 | for (i = 0; i < nthreads; i++) { |
| 306 | /* |
| 307 | * version 2 of the kexec param format adds the phys cpuid of |
| 308 | * booted proc. |
| 309 | */ |
| 310 | if (initial_boot_params && initial_boot_params->version >= 2) { |
| 311 | if (intserv[i] == |
| 312 | initial_boot_params->boot_cpuid_phys) { |
| 313 | found = 1; |
| 314 | break; |
| 315 | } |
| 316 | } else { |
| 317 | /* |
| 318 | * Check if it's the boot-cpu, set it's hw index now, |
| 319 | * unfortunately this format did not support booting |
| 320 | * off secondary threads. |
| 321 | */ |
| 322 | if (of_get_flat_dt_prop(node, |
| 323 | "linux,boot-cpu", NULL) != NULL) { |
| 324 | found = 1; |
| 325 | break; |
| 326 | } |
| 327 | } |
| 328 | |
| 329 | #ifdef CONFIG_SMP |
| 330 | /* logical cpu id is always 0 on UP kernels */ |
| 331 | logical_cpuid++; |
| 332 | #endif |
| 333 | } |
| 334 | |
| 335 | if (found) { |
| 336 | DBG("boot cpu: logical %d physical %d\n", logical_cpuid, |
| 337 | intserv[i]); |
| 338 | boot_cpuid = logical_cpuid; |
| 339 | set_hard_smp_processor_id(boot_cpuid, intserv[i]); |
Paul Mackerras | 974a76f | 2006-11-10 20:38:53 +1100 | [diff] [blame] | 340 | |
| 341 | /* |
| 342 | * PAPR defines "logical" PVR values for cpus that |
| 343 | * meet various levels of the architecture: |
| 344 | * 0x0f000001 Architecture version 2.04 |
| 345 | * 0x0f000002 Architecture version 2.05 |
| 346 | * If the cpu-version property in the cpu node contains |
| 347 | * such a value, we call identify_cpu again with the |
| 348 | * logical PVR value in order to use the cpu feature |
| 349 | * bits appropriate for the architecture level. |
| 350 | * |
| 351 | * A POWER6 partition in "POWER6 architected" mode |
| 352 | * uses the 0x0f000002 PVR value; in POWER5+ mode |
| 353 | * it uses 0x0f000001. |
| 354 | */ |
| 355 | prop = of_get_flat_dt_prop(node, "cpu-version", NULL); |
| 356 | if (prop && (*prop & 0xff000000) == 0x0f000000) |
| 357 | identify_cpu(0, *prop); |
Valentine Barshak | 14b3d92 | 2007-12-22 03:24:02 +1100 | [diff] [blame] | 358 | |
| 359 | identical_pvr_fixup(node); |
Anton Blanchard | 4df2046 | 2006-03-25 17:25:17 +1100 | [diff] [blame] | 360 | } |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 361 | |
Paul Mackerras | 974a76f | 2006-11-10 20:38:53 +1100 | [diff] [blame] | 362 | check_cpu_feature_properties(node); |
Paul Mackerras | d205819 | 2006-05-03 23:04:37 +1000 | [diff] [blame] | 363 | check_cpu_pa_features(node); |
Michael Neuling | 584f8b7 | 2007-12-06 17:24:48 +1100 | [diff] [blame] | 364 | check_cpu_slb_size(node); |
Paul Mackerras | d205819 | 2006-05-03 23:04:37 +1000 | [diff] [blame] | 365 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 366 | #ifdef CONFIG_PPC_PSERIES |
Anton Blanchard | 4df2046 | 2006-03-25 17:25:17 +1100 | [diff] [blame] | 367 | if (nthreads > 1) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 368 | cur_cpu_spec->cpu_features |= CPU_FTR_SMT; |
Anton Blanchard | 4df2046 | 2006-03-25 17:25:17 +1100 | [diff] [blame] | 369 | else |
| 370 | cur_cpu_spec->cpu_features &= ~CPU_FTR_SMT; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 371 | #endif |
| 372 | |
| 373 | return 0; |
| 374 | } |
| 375 | |
Michael Ellerman | 40472a5 | 2007-05-10 17:06:30 +1000 | [diff] [blame] | 376 | #ifdef CONFIG_BLK_DEV_INITRD |
| 377 | static void __init early_init_dt_check_for_initrd(unsigned long node) |
| 378 | { |
| 379 | unsigned long l; |
| 380 | u32 *prop; |
| 381 | |
| 382 | DBG("Looking for initrd properties... "); |
| 383 | |
| 384 | prop = of_get_flat_dt_prop(node, "linux,initrd-start", &l); |
| 385 | if (prop) { |
| 386 | initrd_start = (unsigned long)__va(of_read_ulong(prop, l/4)); |
| 387 | |
| 388 | prop = of_get_flat_dt_prop(node, "linux,initrd-end", &l); |
| 389 | if (prop) { |
| 390 | initrd_end = (unsigned long) |
| 391 | __va(of_read_ulong(prop, l/4)); |
| 392 | initrd_below_start_ok = 1; |
| 393 | } else { |
| 394 | initrd_start = 0; |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | DBG("initrd_start=0x%lx initrd_end=0x%lx\n", initrd_start, initrd_end); |
| 399 | } |
| 400 | #else |
| 401 | static inline void early_init_dt_check_for_initrd(unsigned long node) |
| 402 | { |
| 403 | } |
| 404 | #endif /* CONFIG_BLK_DEV_INITRD */ |
| 405 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 406 | static int __init early_init_dt_scan_chosen(unsigned long node, |
| 407 | const char *uname, int depth, void *data) |
| 408 | { |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 409 | unsigned long *lprop; |
Kumar Gala | 329dda0 | 2006-02-24 10:54:52 -0600 | [diff] [blame] | 410 | unsigned long l; |
| 411 | char *p; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 412 | |
| 413 | DBG("search \"chosen\", depth: %d, uname: %s\n", depth, uname); |
| 414 | |
Paul Mackerras | a575b80 | 2005-10-23 17:23:21 +1000 | [diff] [blame] | 415 | if (depth != 1 || |
| 416 | (strcmp(uname, "chosen") != 0 && strcmp(uname, "chosen@0") != 0)) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 417 | return 0; |
| 418 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 419 | #ifdef CONFIG_PPC64 |
| 420 | /* check if iommu is forced on or off */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 421 | if (of_get_flat_dt_prop(node, "linux,iommu-off", NULL) != NULL) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 422 | iommu_is_off = 1; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 423 | if (of_get_flat_dt_prop(node, "linux,iommu-force-on", NULL) != NULL) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 424 | iommu_force_on = 1; |
| 425 | #endif |
| 426 | |
Michael Ellerman | 2babf5c | 2006-05-17 18:00:46 +1000 | [diff] [blame] | 427 | /* mem=x on the command line is the preferred mechanism */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 428 | lprop = of_get_flat_dt_prop(node, "linux,memory-limit", NULL); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 429 | if (lprop) |
| 430 | memory_limit = *lprop; |
| 431 | |
| 432 | #ifdef CONFIG_PPC64 |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 433 | lprop = of_get_flat_dt_prop(node, "linux,tce-alloc-start", NULL); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 434 | if (lprop) |
| 435 | tce_alloc_start = *lprop; |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 436 | lprop = of_get_flat_dt_prop(node, "linux,tce-alloc-end", NULL); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 437 | if (lprop) |
| 438 | tce_alloc_end = *lprop; |
| 439 | #endif |
| 440 | |
Michael Ellerman | dcee303 | 2005-12-04 18:39:48 +1100 | [diff] [blame] | 441 | #ifdef CONFIG_KEXEC |
Stephen Rothwell | 6327716 | 2009-01-06 13:54:25 +0000 | [diff] [blame] | 442 | lprop = of_get_flat_dt_prop(node, "linux,crashkernel-base", NULL); |
Linas Vepstas | 70c6cc3 | 2007-09-07 03:46:15 +1000 | [diff] [blame] | 443 | if (lprop) |
| 444 | crashk_res.start = *lprop; |
Michael Ellerman | dcee303 | 2005-12-04 18:39:48 +1100 | [diff] [blame] | 445 | |
Stephen Rothwell | 6327716 | 2009-01-06 13:54:25 +0000 | [diff] [blame] | 446 | lprop = of_get_flat_dt_prop(node, "linux,crashkernel-size", NULL); |
Linas Vepstas | 70c6cc3 | 2007-09-07 03:46:15 +1000 | [diff] [blame] | 447 | if (lprop) |
| 448 | crashk_res.end = crashk_res.start + *lprop - 1; |
Michael Ellerman | dcee303 | 2005-12-04 18:39:48 +1100 | [diff] [blame] | 449 | #endif |
| 450 | |
Michael Ellerman | 40472a5 | 2007-05-10 17:06:30 +1000 | [diff] [blame] | 451 | early_init_dt_check_for_initrd(node); |
David Gibson | 30437b3 | 2007-02-28 14:12:29 +1100 | [diff] [blame] | 452 | |
Kumar Gala | 329dda0 | 2006-02-24 10:54:52 -0600 | [diff] [blame] | 453 | /* Retreive command line */ |
| 454 | p = of_get_flat_dt_prop(node, "bootargs", &l); |
| 455 | if (p != NULL && l > 0) |
| 456 | strlcpy(cmd_line, p, min((int)l, COMMAND_LINE_SIZE)); |
| 457 | |
| 458 | #ifdef CONFIG_CMDLINE |
Geoff Levand | c1ce464 | 2006-10-05 11:35:16 -0700 | [diff] [blame] | 459 | if (p == NULL || l == 0 || (l == 1 && (*p) == 0)) |
Kumar Gala | 329dda0 | 2006-02-24 10:54:52 -0600 | [diff] [blame] | 460 | strlcpy(cmd_line, CONFIG_CMDLINE, COMMAND_LINE_SIZE); |
| 461 | #endif /* CONFIG_CMDLINE */ |
| 462 | |
| 463 | DBG("Command line is: %s\n", cmd_line); |
| 464 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 465 | /* break now */ |
| 466 | return 1; |
| 467 | } |
| 468 | |
| 469 | static int __init early_init_dt_scan_root(unsigned long node, |
| 470 | const char *uname, int depth, void *data) |
| 471 | { |
| 472 | u32 *prop; |
| 473 | |
| 474 | if (depth != 0) |
| 475 | return 0; |
| 476 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 477 | prop = of_get_flat_dt_prop(node, "#size-cells", NULL); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 478 | dt_root_size_cells = (prop == NULL) ? 1 : *prop; |
| 479 | DBG("dt_root_size_cells = %x\n", dt_root_size_cells); |
| 480 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 481 | prop = of_get_flat_dt_prop(node, "#address-cells", NULL); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 482 | dt_root_addr_cells = (prop == NULL) ? 2 : *prop; |
| 483 | DBG("dt_root_addr_cells = %x\n", dt_root_addr_cells); |
| 484 | |
| 485 | /* break now */ |
| 486 | return 1; |
| 487 | } |
| 488 | |
Becky Bruce | abe7688 | 2008-02-16 05:17:14 +1100 | [diff] [blame] | 489 | static u64 __init dt_mem_next_cell(int s, cell_t **cellp) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 490 | { |
| 491 | cell_t *p = *cellp; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 492 | |
Paul Mackerras | a4dc7ff | 2006-09-19 14:06:27 +1000 | [diff] [blame] | 493 | *cellp = p + s; |
Becky Bruce | abe7688 | 2008-02-16 05:17:14 +1100 | [diff] [blame] | 494 | return of_read_number(p, s); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 495 | } |
| 496 | |
Paul Mackerras | 0204568 | 2006-11-29 22:27:42 +1100 | [diff] [blame] | 497 | #ifdef CONFIG_PPC_PSERIES |
| 498 | /* |
| 499 | * Interpret the ibm,dynamic-memory property in the |
| 500 | * /ibm,dynamic-reconfiguration-memory node. |
| 501 | * This contains a list of memory blocks along with NUMA affinity |
| 502 | * information. |
| 503 | */ |
| 504 | static int __init early_init_dt_scan_drconf_memory(unsigned long node) |
| 505 | { |
Chandru | cf00085 | 2008-08-30 00:28:16 +1000 | [diff] [blame] | 506 | cell_t *dm, *ls, *usm; |
Becky Bruce | abe7688 | 2008-02-16 05:17:14 +1100 | [diff] [blame] | 507 | unsigned long l, n, flags; |
| 508 | u64 base, size, lmb_size; |
Chandru | cf00085 | 2008-08-30 00:28:16 +1000 | [diff] [blame] | 509 | unsigned int is_kexec_kdump = 0, rngs; |
Paul Mackerras | 0204568 | 2006-11-29 22:27:42 +1100 | [diff] [blame] | 510 | |
Stephen Rothwell | 6327716 | 2009-01-06 13:54:25 +0000 | [diff] [blame] | 511 | ls = of_get_flat_dt_prop(node, "ibm,lmb-size", &l); |
Paul Mackerras | 0204568 | 2006-11-29 22:27:42 +1100 | [diff] [blame] | 512 | if (ls == NULL || l < dt_root_size_cells * sizeof(cell_t)) |
| 513 | return 0; |
| 514 | lmb_size = dt_mem_next_cell(dt_root_size_cells, &ls); |
| 515 | |
Stephen Rothwell | 6327716 | 2009-01-06 13:54:25 +0000 | [diff] [blame] | 516 | dm = of_get_flat_dt_prop(node, "ibm,dynamic-memory", &l); |
Paul Mackerras | 0204568 | 2006-11-29 22:27:42 +1100 | [diff] [blame] | 517 | if (dm == NULL || l < sizeof(cell_t)) |
| 518 | return 0; |
| 519 | |
| 520 | n = *dm++; /* number of entries */ |
| 521 | if (l < (n * (dt_root_addr_cells + 4) + 1) * sizeof(cell_t)) |
| 522 | return 0; |
| 523 | |
Chandru | cf00085 | 2008-08-30 00:28:16 +1000 | [diff] [blame] | 524 | /* check if this is a kexec/kdump kernel. */ |
Stephen Rothwell | 6327716 | 2009-01-06 13:54:25 +0000 | [diff] [blame] | 525 | usm = of_get_flat_dt_prop(node, "linux,drconf-usable-memory", |
Chandru | cf00085 | 2008-08-30 00:28:16 +1000 | [diff] [blame] | 526 | &l); |
| 527 | if (usm != NULL) |
| 528 | is_kexec_kdump = 1; |
| 529 | |
Paul Mackerras | 0204568 | 2006-11-29 22:27:42 +1100 | [diff] [blame] | 530 | for (; n != 0; --n) { |
| 531 | base = dt_mem_next_cell(dt_root_addr_cells, &dm); |
| 532 | flags = dm[3]; |
| 533 | /* skip DRC index, pad, assoc. list index, flags */ |
| 534 | dm += 4; |
| 535 | /* skip this block if the reserved bit is set in flags (0x80) |
| 536 | or if the block is not assigned to this partition (0x8) */ |
| 537 | if ((flags & 0x80) || !(flags & 0x8)) |
| 538 | continue; |
| 539 | size = lmb_size; |
Chandru | cf00085 | 2008-08-30 00:28:16 +1000 | [diff] [blame] | 540 | rngs = 1; |
| 541 | if (is_kexec_kdump) { |
| 542 | /* |
| 543 | * For each lmb in ibm,dynamic-memory, a corresponding |
| 544 | * entry in linux,drconf-usable-memory property contains |
| 545 | * a counter 'p' followed by 'p' (base, size) duple. |
| 546 | * Now read the counter from |
| 547 | * linux,drconf-usable-memory property |
| 548 | */ |
| 549 | rngs = dt_mem_next_cell(dt_root_size_cells, &usm); |
| 550 | if (!rngs) /* there are no (base, size) duple */ |
Paul Mackerras | 0204568 | 2006-11-29 22:27:42 +1100 | [diff] [blame] | 551 | continue; |
Paul Mackerras | 0204568 | 2006-11-29 22:27:42 +1100 | [diff] [blame] | 552 | } |
Chandru | cf00085 | 2008-08-30 00:28:16 +1000 | [diff] [blame] | 553 | do { |
| 554 | if (is_kexec_kdump) { |
| 555 | base = dt_mem_next_cell(dt_root_addr_cells, |
| 556 | &usm); |
| 557 | size = dt_mem_next_cell(dt_root_size_cells, |
| 558 | &usm); |
| 559 | } |
| 560 | if (iommu_is_off) { |
| 561 | if (base >= 0x80000000ul) |
| 562 | continue; |
| 563 | if ((base + size) > 0x80000000ul) |
| 564 | size = 0x80000000ul - base; |
| 565 | } |
| 566 | lmb_add(base, size); |
| 567 | } while (--rngs); |
Paul Mackerras | 0204568 | 2006-11-29 22:27:42 +1100 | [diff] [blame] | 568 | } |
| 569 | lmb_dump_all(); |
| 570 | return 0; |
| 571 | } |
| 572 | #else |
| 573 | #define early_init_dt_scan_drconf_memory(node) 0 |
| 574 | #endif /* CONFIG_PPC_PSERIES */ |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 575 | |
| 576 | static int __init early_init_dt_scan_memory(unsigned long node, |
| 577 | const char *uname, int depth, void *data) |
| 578 | { |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 579 | char *type = of_get_flat_dt_prop(node, "device_type", NULL); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 580 | cell_t *reg, *endp; |
| 581 | unsigned long l; |
| 582 | |
Paul Mackerras | 0204568 | 2006-11-29 22:27:42 +1100 | [diff] [blame] | 583 | /* Look for the ibm,dynamic-reconfiguration-memory node */ |
| 584 | if (depth == 1 && |
| 585 | strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0) |
| 586 | return early_init_dt_scan_drconf_memory(node); |
| 587 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 588 | /* We are scanning "memory" nodes only */ |
Paul Mackerras | a23414b | 2005-11-10 12:00:55 +1100 | [diff] [blame] | 589 | if (type == NULL) { |
| 590 | /* |
| 591 | * The longtrail doesn't have a device_type on the |
| 592 | * /memory node, so look for the node called /memory@0. |
| 593 | */ |
| 594 | if (depth != 1 || strcmp(uname, "memory@0") != 0) |
| 595 | return 0; |
| 596 | } else if (strcmp(type, "memory") != 0) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 597 | return 0; |
| 598 | |
Stephen Rothwell | 6327716 | 2009-01-06 13:54:25 +0000 | [diff] [blame] | 599 | reg = of_get_flat_dt_prop(node, "linux,usable-memory", &l); |
Michael Ellerman | ba75948 | 2005-12-04 18:39:55 +1100 | [diff] [blame] | 600 | if (reg == NULL) |
Stephen Rothwell | 6327716 | 2009-01-06 13:54:25 +0000 | [diff] [blame] | 601 | reg = of_get_flat_dt_prop(node, "reg", &l); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 602 | if (reg == NULL) |
| 603 | return 0; |
| 604 | |
| 605 | endp = reg + (l / sizeof(cell_t)); |
| 606 | |
Michael Ellerman | 358c86f | 2005-11-03 15:39:09 +1100 | [diff] [blame] | 607 | DBG("memory scan node %s, reg size %ld, data: %x %x %x %x,\n", |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 608 | uname, l, reg[0], reg[1], reg[2], reg[3]); |
| 609 | |
| 610 | while ((endp - reg) >= (dt_root_addr_cells + dt_root_size_cells)) { |
Becky Bruce | abe7688 | 2008-02-16 05:17:14 +1100 | [diff] [blame] | 611 | u64 base, size; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 612 | |
| 613 | base = dt_mem_next_cell(dt_root_addr_cells, ®); |
| 614 | size = dt_mem_next_cell(dt_root_size_cells, ®); |
| 615 | |
| 616 | if (size == 0) |
| 617 | continue; |
Becky Bruce | abe7688 | 2008-02-16 05:17:14 +1100 | [diff] [blame] | 618 | DBG(" - %llx , %llx\n", (unsigned long long)base, |
| 619 | (unsigned long long)size); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 620 | #ifdef CONFIG_PPC64 |
| 621 | if (iommu_is_off) { |
| 622 | if (base >= 0x80000000ul) |
| 623 | continue; |
| 624 | if ((base + size) > 0x80000000ul) |
| 625 | size = 0x80000000ul - base; |
| 626 | } |
| 627 | #endif |
| 628 | lmb_add(base, size); |
Kumar Gala | 37dd2ba | 2008-04-22 04:22:34 +1000 | [diff] [blame] | 629 | |
| 630 | memstart_addr = min((u64)memstart_addr, base); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 631 | } |
Kumar Gala | 37dd2ba | 2008-04-22 04:22:34 +1000 | [diff] [blame] | 632 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 633 | return 0; |
| 634 | } |
| 635 | |
| 636 | static void __init early_reserve_mem(void) |
| 637 | { |
Kumar Gala | cbbcf34 | 2006-01-11 17:57:13 -0600 | [diff] [blame] | 638 | u64 base, size; |
| 639 | u64 *reserve_map; |
Jon Loeliger | 8a30088 | 2006-06-17 17:51:09 -0500 | [diff] [blame] | 640 | unsigned long self_base; |
| 641 | unsigned long self_size; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 642 | |
Kumar Gala | cbbcf34 | 2006-01-11 17:57:13 -0600 | [diff] [blame] | 643 | reserve_map = (u64 *)(((unsigned long)initial_boot_params) + |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 644 | initial_boot_params->off_mem_rsvmap); |
Jimi Xenidis | 4d1f3f2 | 2006-05-18 17:03:05 -0500 | [diff] [blame] | 645 | |
| 646 | /* before we do anything, lets reserve the dt blob */ |
Jon Loeliger | 8a30088 | 2006-06-17 17:51:09 -0500 | [diff] [blame] | 647 | self_base = __pa((unsigned long)initial_boot_params); |
| 648 | self_size = initial_boot_params->totalsize; |
| 649 | lmb_reserve(self_base, self_size); |
Jimi Xenidis | 4d1f3f2 | 2006-05-18 17:03:05 -0500 | [diff] [blame] | 650 | |
David Gibson | 30437b3 | 2007-02-28 14:12:29 +1100 | [diff] [blame] | 651 | #ifdef CONFIG_BLK_DEV_INITRD |
| 652 | /* then reserve the initrd, if any */ |
| 653 | if (initrd_start && (initrd_end > initrd_start)) |
| 654 | lmb_reserve(__pa(initrd_start), initrd_end - initrd_start); |
| 655 | #endif /* CONFIG_BLK_DEV_INITRD */ |
| 656 | |
Kumar Gala | cbbcf34 | 2006-01-11 17:57:13 -0600 | [diff] [blame] | 657 | #ifdef CONFIG_PPC32 |
| 658 | /* |
| 659 | * Handle the case where we might be booting from an old kexec |
| 660 | * image that setup the mem_rsvmap as pairs of 32-bit values |
| 661 | */ |
| 662 | if (*reserve_map > 0xffffffffull) { |
| 663 | u32 base_32, size_32; |
| 664 | u32 *reserve_map_32 = (u32 *)reserve_map; |
| 665 | |
| 666 | while (1) { |
| 667 | base_32 = *(reserve_map_32++); |
| 668 | size_32 = *(reserve_map_32++); |
| 669 | if (size_32 == 0) |
| 670 | break; |
Jon Loeliger | 8a30088 | 2006-06-17 17:51:09 -0500 | [diff] [blame] | 671 | /* skip if the reservation is for the blob */ |
| 672 | if (base_32 == self_base && size_32 == self_size) |
| 673 | continue; |
Kumar Gala | 329dda0 | 2006-02-24 10:54:52 -0600 | [diff] [blame] | 674 | DBG("reserving: %x -> %x\n", base_32, size_32); |
Kumar Gala | cbbcf34 | 2006-01-11 17:57:13 -0600 | [diff] [blame] | 675 | lmb_reserve(base_32, size_32); |
| 676 | } |
| 677 | return; |
| 678 | } |
| 679 | #endif |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 680 | while (1) { |
| 681 | base = *(reserve_map++); |
| 682 | size = *(reserve_map++); |
| 683 | if (size == 0) |
| 684 | break; |
Kumar Gala | cbbcf34 | 2006-01-11 17:57:13 -0600 | [diff] [blame] | 685 | DBG("reserving: %llx -> %llx\n", base, size); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 686 | lmb_reserve(base, size); |
| 687 | } |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 688 | } |
| 689 | |
Manish Ahuja | 6ac26c8 | 2008-03-22 10:37:08 +1100 | [diff] [blame] | 690 | #ifdef CONFIG_PHYP_DUMP |
| 691 | /** |
Manish Ahuja | 37ddd5d | 2008-04-12 09:31:52 +1000 | [diff] [blame] | 692 | * phyp_dump_calculate_reserve_size() - reserve variable boot area 5% or arg |
| 693 | * |
| 694 | * Function to find the largest size we need to reserve |
| 695 | * during early boot process. |
| 696 | * |
| 697 | * It either looks for boot param and returns that OR |
| 698 | * returns larger of 256 or 5% rounded down to multiples of 256MB. |
| 699 | * |
| 700 | */ |
| 701 | static inline unsigned long phyp_dump_calculate_reserve_size(void) |
| 702 | { |
| 703 | unsigned long tmp; |
| 704 | |
| 705 | if (phyp_dump_info->reserve_bootvar) |
| 706 | return phyp_dump_info->reserve_bootvar; |
| 707 | |
| 708 | /* divide by 20 to get 5% of value */ |
| 709 | tmp = lmb_end_of_DRAM(); |
| 710 | do_div(tmp, 20); |
| 711 | |
| 712 | /* round it down in multiples of 256 */ |
| 713 | tmp = tmp & ~0x0FFFFFFFUL; |
| 714 | |
| 715 | return (tmp > PHYP_DUMP_RMR_END ? tmp : PHYP_DUMP_RMR_END); |
| 716 | } |
| 717 | |
| 718 | /** |
Manish Ahuja | 6ac26c8 | 2008-03-22 10:37:08 +1100 | [diff] [blame] | 719 | * phyp_dump_reserve_mem() - reserve all not-yet-dumped mmemory |
| 720 | * |
| 721 | * This routine may reserve memory regions in the kernel only |
| 722 | * if the system is supported and a dump was taken in last |
| 723 | * boot instance or if the hardware is supported and the |
| 724 | * scratch area needs to be setup. In other instances it returns |
| 725 | * without reserving anything. The memory in case of dump being |
| 726 | * active is freed when the dump is collected (by userland tools). |
| 727 | */ |
| 728 | static void __init phyp_dump_reserve_mem(void) |
| 729 | { |
| 730 | unsigned long base, size; |
Manish Ahuja | 37ddd5d | 2008-04-12 09:31:52 +1000 | [diff] [blame] | 731 | unsigned long variable_reserve_size; |
| 732 | |
Manish Ahuja | 6ac26c8 | 2008-03-22 10:37:08 +1100 | [diff] [blame] | 733 | if (!phyp_dump_info->phyp_dump_configured) { |
| 734 | printk(KERN_ERR "Phyp-dump not supported on this hardware\n"); |
| 735 | return; |
| 736 | } |
| 737 | |
Manish Ahuja | 654f596 | 2008-03-22 11:38:59 +1100 | [diff] [blame] | 738 | if (!phyp_dump_info->phyp_dump_at_boot) { |
| 739 | printk(KERN_INFO "Phyp-dump disabled at boot time\n"); |
| 740 | return; |
| 741 | } |
| 742 | |
Manish Ahuja | 37ddd5d | 2008-04-12 09:31:52 +1000 | [diff] [blame] | 743 | variable_reserve_size = phyp_dump_calculate_reserve_size(); |
| 744 | |
Manish Ahuja | 6ac26c8 | 2008-03-22 10:37:08 +1100 | [diff] [blame] | 745 | if (phyp_dump_info->phyp_dump_is_active) { |
| 746 | /* Reserve *everything* above RMR.Area freed by userland tools*/ |
Manish Ahuja | 37ddd5d | 2008-04-12 09:31:52 +1000 | [diff] [blame] | 747 | base = variable_reserve_size; |
Manish Ahuja | 6ac26c8 | 2008-03-22 10:37:08 +1100 | [diff] [blame] | 748 | size = lmb_end_of_DRAM() - base; |
| 749 | |
| 750 | /* XXX crashed_ram_end is wrong, since it may be beyond |
| 751 | * the memory_limit, it will need to be adjusted. */ |
| 752 | lmb_reserve(base, size); |
| 753 | |
| 754 | phyp_dump_info->init_reserve_start = base; |
| 755 | phyp_dump_info->init_reserve_size = size; |
| 756 | } else { |
| 757 | size = phyp_dump_info->cpu_state_size + |
| 758 | phyp_dump_info->hpte_region_size + |
Manish Ahuja | 37ddd5d | 2008-04-12 09:31:52 +1000 | [diff] [blame] | 759 | variable_reserve_size; |
Manish Ahuja | 6ac26c8 | 2008-03-22 10:37:08 +1100 | [diff] [blame] | 760 | base = lmb_end_of_DRAM() - size; |
| 761 | lmb_reserve(base, size); |
| 762 | phyp_dump_info->init_reserve_start = base; |
| 763 | phyp_dump_info->init_reserve_size = size; |
| 764 | } |
| 765 | } |
| 766 | #else |
| 767 | static inline void __init phyp_dump_reserve_mem(void) {} |
| 768 | #endif /* CONFIG_PHYP_DUMP && CONFIG_PPC_RTAS */ |
| 769 | |
| 770 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 771 | void __init early_init_devtree(void *params) |
| 772 | { |
Becky Bruce | 49a8496 | 2009-05-08 12:19:27 +0000 | [diff] [blame] | 773 | phys_addr_t limit; |
Hollis Blanchard | 6ca4f74 | 2008-11-26 10:19:26 -0600 | [diff] [blame] | 774 | |
Geoff Levand | 4434810 | 2007-06-16 08:06:14 +1000 | [diff] [blame] | 775 | DBG(" -> early_init_devtree(%p)\n", params); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 776 | |
| 777 | /* Setup flat device-tree pointer */ |
| 778 | initial_boot_params = params; |
| 779 | |
Michael Ellerman | 458148c | 2006-06-23 18:20:13 +1000 | [diff] [blame] | 780 | #ifdef CONFIG_PPC_RTAS |
| 781 | /* Some machines might need RTAS info for debugging, grab it now. */ |
| 782 | of_scan_flat_dt(early_init_dt_scan_rtas, NULL); |
| 783 | #endif |
| 784 | |
Manish Ahuja | 6ac26c8 | 2008-03-22 10:37:08 +1100 | [diff] [blame] | 785 | #ifdef CONFIG_PHYP_DUMP |
| 786 | /* scan tree to see if dump occured during last boot */ |
| 787 | of_scan_flat_dt(early_init_dt_scan_phyp_dump, NULL); |
| 788 | #endif |
| 789 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 790 | /* Retrieve various informations from the /chosen node of the |
| 791 | * device-tree, including the platform type, initrd location and |
| 792 | * size, TCE reserve, and more ... |
| 793 | */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 794 | of_scan_flat_dt(early_init_dt_scan_chosen, NULL); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 795 | |
| 796 | /* Scan memory nodes and rebuild LMBs */ |
| 797 | lmb_init(); |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 798 | of_scan_flat_dt(early_init_dt_scan_root, NULL); |
| 799 | of_scan_flat_dt(early_init_dt_scan_memory, NULL); |
Michael Ellerman | 846f77b | 2006-05-17 18:00:45 +1000 | [diff] [blame] | 800 | |
| 801 | /* Save command line for /proc/cmdline and then parse parameters */ |
Alon Bar-Lev | b8757b2 | 2007-02-12 00:54:17 -0800 | [diff] [blame] | 802 | strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE); |
Michael Ellerman | 846f77b | 2006-05-17 18:00:45 +1000 | [diff] [blame] | 803 | parse_early_param(); |
| 804 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 805 | /* Reserve LMB regions used by kernel, initrd, dt, etc... */ |
Michael Ellerman | 0cc4746 | 2005-12-04 18:39:37 +1100 | [diff] [blame] | 806 | lmb_reserve(PHYSICAL_START, __pa(klimit) - PHYSICAL_START); |
Paul Mackerras | 549e815 | 2008-08-30 11:43:47 +1000 | [diff] [blame] | 807 | /* If relocatable, reserve first 32k for interrupt vectors etc. */ |
| 808 | if (PHYSICAL_START > MEMORY_START) |
| 809 | lmb_reserve(MEMORY_START, 0x8000); |
Michael Ellerman | 4731041 | 2006-05-17 18:00:49 +1000 | [diff] [blame] | 810 | reserve_kdump_trampoline(); |
Michael Ellerman | 35dd543 | 2006-05-18 11:16:11 +1000 | [diff] [blame] | 811 | reserve_crashkernel(); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 812 | early_reserve_mem(); |
Manish Ahuja | 6ac26c8 | 2008-03-22 10:37:08 +1100 | [diff] [blame] | 813 | phyp_dump_reserve_mem(); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 814 | |
Hollis Blanchard | 6ca4f74 | 2008-11-26 10:19:26 -0600 | [diff] [blame] | 815 | limit = memory_limit; |
| 816 | if (! limit) { |
Becky Bruce | 49a8496 | 2009-05-08 12:19:27 +0000 | [diff] [blame] | 817 | phys_addr_t memsize; |
Hollis Blanchard | 6ca4f74 | 2008-11-26 10:19:26 -0600 | [diff] [blame] | 818 | |
| 819 | /* Ensure that total memory size is page-aligned, because |
| 820 | * otherwise mark_bootmem() gets upset. */ |
| 821 | lmb_analyze(); |
| 822 | memsize = lmb_phys_mem_size(); |
| 823 | if ((memsize & PAGE_MASK) != memsize) |
| 824 | limit = memsize & PAGE_MASK; |
| 825 | } |
| 826 | lmb_enforce_memory_limit(limit); |
| 827 | |
Michael Ellerman | 2babf5c | 2006-05-17 18:00:46 +1000 | [diff] [blame] | 828 | lmb_analyze(); |
Michael Ellerman | 059f134 | 2009-01-14 20:46:01 +0000 | [diff] [blame] | 829 | lmb_dump_all(); |
Michael Ellerman | 2babf5c | 2006-05-17 18:00:46 +1000 | [diff] [blame] | 830 | |
Becky Bruce | 49a8496 | 2009-05-08 12:19:27 +0000 | [diff] [blame] | 831 | DBG("Phys. mem: %llx\n", lmb_phys_mem_size()); |
Michael Ellerman | 2babf5c | 2006-05-17 18:00:46 +1000 | [diff] [blame] | 832 | |
| 833 | /* We may need to relocate the flat tree, do it now. |
| 834 | * FIXME .. and the initrd too? */ |
| 835 | move_device_tree(); |
| 836 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 837 | DBG("Scanning CPUs ...\n"); |
| 838 | |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 839 | /* Retreive CPU related informations from the flat tree |
| 840 | * (altivec support, boot CPU ID, ...) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 841 | */ |
Benjamin Herrenschmidt | 3c726f8 | 2005-11-07 11:06:55 +1100 | [diff] [blame] | 842 | of_scan_flat_dt(early_init_dt_scan_cpus, NULL); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 843 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 844 | DBG(" <- early_init_devtree()\n"); |
| 845 | } |
| 846 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 847 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 848 | /** |
| 849 | * Indicates whether the root node has a given value in its |
| 850 | * compatible property. |
| 851 | */ |
| 852 | int machine_is_compatible(const char *compat) |
| 853 | { |
| 854 | struct device_node *root; |
| 855 | int rc = 0; |
| 856 | |
| 857 | root = of_find_node_by_path("/"); |
| 858 | if (root) { |
Stephen Rothwell | 7a92f74 | 2007-04-03 10:55:39 +1000 | [diff] [blame] | 859 | rc = of_device_is_compatible(root, compat); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 860 | of_node_put(root); |
| 861 | } |
| 862 | return rc; |
| 863 | } |
| 864 | EXPORT_SYMBOL(machine_is_compatible); |
| 865 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 866 | /******* |
| 867 | * |
| 868 | * New implementation of the OF "find" APIs, return a refcounted |
| 869 | * object, call of_node_put() when done. The device tree and list |
| 870 | * are protected by a rw_lock. |
| 871 | * |
| 872 | * Note that property management will need some locking as well, |
| 873 | * this isn't dealt with yet. |
| 874 | * |
| 875 | *******/ |
| 876 | |
| 877 | /** |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 878 | * of_find_node_by_phandle - Find a node given a phandle |
| 879 | * @handle: phandle of the node to find |
| 880 | * |
| 881 | * Returns a node pointer with refcount incremented, use |
| 882 | * of_node_put() on it when done. |
| 883 | */ |
| 884 | struct device_node *of_find_node_by_phandle(phandle handle) |
| 885 | { |
| 886 | struct device_node *np; |
| 887 | |
| 888 | read_lock(&devtree_lock); |
| 889 | for (np = allnodes; np != 0; np = np->allnext) |
| 890 | if (np->linux_phandle == handle) |
| 891 | break; |
Mariusz Kozlowski | b137405 | 2007-01-02 12:31:47 +0100 | [diff] [blame] | 892 | of_node_get(np); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 893 | read_unlock(&devtree_lock); |
| 894 | return np; |
| 895 | } |
| 896 | EXPORT_SYMBOL(of_find_node_by_phandle); |
| 897 | |
| 898 | /** |
Nathan Lynch | e523f72 | 2008-12-10 14:46:04 +0000 | [diff] [blame] | 899 | * of_find_next_cache_node - Find a node's subsidiary cache |
| 900 | * @np: node of type "cpu" or "cache" |
| 901 | * |
| 902 | * Returns a node pointer with refcount incremented, use |
| 903 | * of_node_put() on it when done. Caller should hold a reference |
| 904 | * to np. |
| 905 | */ |
| 906 | struct device_node *of_find_next_cache_node(struct device_node *np) |
| 907 | { |
| 908 | struct device_node *child; |
| 909 | const phandle *handle; |
| 910 | |
| 911 | handle = of_get_property(np, "l2-cache", NULL); |
| 912 | if (!handle) |
| 913 | handle = of_get_property(np, "next-level-cache", NULL); |
| 914 | |
| 915 | if (handle) |
| 916 | return of_find_node_by_phandle(*handle); |
| 917 | |
| 918 | /* OF on pmac has nodes instead of properties named "l2-cache" |
| 919 | * beneath CPU nodes. |
| 920 | */ |
| 921 | if (!strcmp(np->type, "cpu")) |
| 922 | for_each_child_of_node(np, child) |
| 923 | if (!strcmp(child->type, "cache")) |
| 924 | return child; |
| 925 | |
| 926 | return NULL; |
| 927 | } |
| 928 | |
| 929 | /** |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 930 | * of_node_get - Increment refcount of a node |
| 931 | * @node: Node to inc refcount, NULL is supported to |
| 932 | * simplify writing of callers |
| 933 | * |
| 934 | * Returns node. |
| 935 | */ |
| 936 | struct device_node *of_node_get(struct device_node *node) |
| 937 | { |
| 938 | if (node) |
| 939 | kref_get(&node->kref); |
| 940 | return node; |
| 941 | } |
| 942 | EXPORT_SYMBOL(of_node_get); |
| 943 | |
| 944 | static inline struct device_node * kref_to_device_node(struct kref *kref) |
| 945 | { |
| 946 | return container_of(kref, struct device_node, kref); |
| 947 | } |
| 948 | |
| 949 | /** |
| 950 | * of_node_release - release a dynamically allocated node |
| 951 | * @kref: kref element of the node to be released |
| 952 | * |
| 953 | * In of_node_put() this function is passed to kref_put() |
| 954 | * as the destructor. |
| 955 | */ |
| 956 | static void of_node_release(struct kref *kref) |
| 957 | { |
| 958 | struct device_node *node = kref_to_device_node(kref); |
| 959 | struct property *prop = node->properties; |
| 960 | |
Michael Ellerman | 6a281856 | 2007-06-19 16:08:00 +1000 | [diff] [blame] | 961 | /* We should never be releasing nodes that haven't been detached. */ |
| 962 | if (!of_node_check_flag(node, OF_DETACHED)) { |
| 963 | printk("WARNING: Bad of_node_put() on %s\n", node->full_name); |
| 964 | dump_stack(); |
| 965 | kref_init(&node->kref); |
| 966 | return; |
| 967 | } |
| 968 | |
Michael Ellerman | d3b814b | 2007-06-19 16:07:58 +1000 | [diff] [blame] | 969 | if (!of_node_check_flag(node, OF_DYNAMIC)) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 970 | return; |
Michael Ellerman | 6a281856 | 2007-06-19 16:08:00 +1000 | [diff] [blame] | 971 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 972 | while (prop) { |
| 973 | struct property *next = prop->next; |
| 974 | kfree(prop->name); |
| 975 | kfree(prop->value); |
| 976 | kfree(prop); |
| 977 | prop = next; |
Dave C Boutcher | 088186d | 2006-01-12 16:08:27 -0600 | [diff] [blame] | 978 | |
| 979 | if (!prop) { |
| 980 | prop = node->deadprops; |
| 981 | node->deadprops = NULL; |
| 982 | } |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 983 | } |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 984 | kfree(node->full_name); |
| 985 | kfree(node->data); |
| 986 | kfree(node); |
| 987 | } |
| 988 | |
| 989 | /** |
| 990 | * of_node_put - Decrement refcount of a node |
| 991 | * @node: Node to dec refcount, NULL is supported to |
| 992 | * simplify writing of callers |
| 993 | * |
| 994 | */ |
| 995 | void of_node_put(struct device_node *node) |
| 996 | { |
| 997 | if (node) |
| 998 | kref_put(&node->kref, of_node_release); |
| 999 | } |
| 1000 | EXPORT_SYMBOL(of_node_put); |
| 1001 | |
| 1002 | /* |
| 1003 | * Plug a device node into the tree and global list. |
| 1004 | */ |
| 1005 | void of_attach_node(struct device_node *np) |
| 1006 | { |
Benjamin Herrenschmidt | f4ac7b5 | 2008-04-09 17:21:36 +1000 | [diff] [blame] | 1007 | unsigned long flags; |
| 1008 | |
| 1009 | write_lock_irqsave(&devtree_lock, flags); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1010 | np->sibling = np->parent->child; |
| 1011 | np->allnext = allnodes; |
| 1012 | np->parent->child = np; |
| 1013 | allnodes = np; |
Benjamin Herrenschmidt | f4ac7b5 | 2008-04-09 17:21:36 +1000 | [diff] [blame] | 1014 | write_unlock_irqrestore(&devtree_lock, flags); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | /* |
| 1018 | * "Unplug" a node from the device tree. The caller must hold |
| 1019 | * a reference to the node. The memory associated with the node |
| 1020 | * is not freed until its refcount goes to zero. |
| 1021 | */ |
Segher Boessenkool | 34f329d | 2007-07-20 15:58:38 +1000 | [diff] [blame] | 1022 | void of_detach_node(struct device_node *np) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1023 | { |
| 1024 | struct device_node *parent; |
Benjamin Herrenschmidt | f4ac7b5 | 2008-04-09 17:21:36 +1000 | [diff] [blame] | 1025 | unsigned long flags; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1026 | |
Benjamin Herrenschmidt | f4ac7b5 | 2008-04-09 17:21:36 +1000 | [diff] [blame] | 1027 | write_lock_irqsave(&devtree_lock, flags); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1028 | |
| 1029 | parent = np->parent; |
Michael Ellerman | 972d17c | 2007-06-19 16:07:56 +1000 | [diff] [blame] | 1030 | if (!parent) |
| 1031 | goto out_unlock; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1032 | |
| 1033 | if (allnodes == np) |
| 1034 | allnodes = np->allnext; |
| 1035 | else { |
| 1036 | struct device_node *prev; |
| 1037 | for (prev = allnodes; |
| 1038 | prev->allnext != np; |
| 1039 | prev = prev->allnext) |
| 1040 | ; |
| 1041 | prev->allnext = np->allnext; |
| 1042 | } |
| 1043 | |
| 1044 | if (parent->child == np) |
| 1045 | parent->child = np->sibling; |
| 1046 | else { |
| 1047 | struct device_node *prevsib; |
| 1048 | for (prevsib = np->parent->child; |
| 1049 | prevsib->sibling != np; |
| 1050 | prevsib = prevsib->sibling) |
| 1051 | ; |
| 1052 | prevsib->sibling = np->sibling; |
| 1053 | } |
| 1054 | |
Michael Ellerman | 6a281856 | 2007-06-19 16:08:00 +1000 | [diff] [blame] | 1055 | of_node_set_flag(np, OF_DETACHED); |
| 1056 | |
Michael Ellerman | 972d17c | 2007-06-19 16:07:56 +1000 | [diff] [blame] | 1057 | out_unlock: |
Benjamin Herrenschmidt | f4ac7b5 | 2008-04-09 17:21:36 +1000 | [diff] [blame] | 1058 | write_unlock_irqrestore(&devtree_lock, flags); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1059 | } |
| 1060 | |
| 1061 | #ifdef CONFIG_PPC_PSERIES |
| 1062 | /* |
| 1063 | * Fix up the uninitialized fields in a new device node: |
Benjamin Herrenschmidt | 0ebfff1 | 2006-07-03 21:36:01 +1000 | [diff] [blame] | 1064 | * name, type and pci-specific fields |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1065 | */ |
| 1066 | |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 1067 | static int of_finish_dynamic_node(struct device_node *node) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1068 | { |
| 1069 | struct device_node *parent = of_get_parent(node); |
| 1070 | int err = 0; |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 1071 | const phandle *ibm_phandle; |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1072 | |
Stephen Rothwell | 0e56efc | 2007-04-03 10:54:01 +1000 | [diff] [blame] | 1073 | node->name = of_get_property(node, "name", NULL); |
| 1074 | node->type = of_get_property(node, "device_type", NULL); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1075 | |
Benjamin Herrenschmidt | 847f597 | 2007-05-16 16:57:24 +1000 | [diff] [blame] | 1076 | if (!node->name) |
| 1077 | node->name = "<NULL>"; |
| 1078 | if (!node->type) |
| 1079 | node->type = "<NULL>"; |
| 1080 | |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1081 | if (!parent) { |
| 1082 | err = -ENODEV; |
| 1083 | goto out; |
| 1084 | } |
| 1085 | |
| 1086 | /* We don't support that function on PowerMac, at least |
| 1087 | * not yet |
| 1088 | */ |
Benjamin Herrenschmidt | e822250 | 2006-03-28 23:15:54 +1100 | [diff] [blame] | 1089 | if (machine_is(powermac)) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1090 | return -ENODEV; |
| 1091 | |
| 1092 | /* fix up new node's linux_phandle field */ |
Stephen Rothwell | 0e56efc | 2007-04-03 10:54:01 +1000 | [diff] [blame] | 1093 | if ((ibm_phandle = of_get_property(node, "ibm,phandle", NULL))) |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1094 | node->linux_phandle = *ibm_phandle; |
| 1095 | |
| 1096 | out: |
| 1097 | of_node_put(parent); |
| 1098 | return err; |
| 1099 | } |
| 1100 | |
| 1101 | static int prom_reconfig_notifier(struct notifier_block *nb, |
| 1102 | unsigned long action, void *node) |
| 1103 | { |
| 1104 | int err; |
| 1105 | |
| 1106 | switch (action) { |
| 1107 | case PSERIES_RECONFIG_ADD: |
Benjamin Herrenschmidt | cc5d018 | 2005-12-13 18:01:21 +1100 | [diff] [blame] | 1108 | err = of_finish_dynamic_node(node); |
Paul Mackerras | 9b6b563 | 2005-10-06 12:06:20 +1000 | [diff] [blame] | 1109 | if (err < 0) { |
| 1110 | printk(KERN_ERR "finish_node returned %d\n", err); |
| 1111 | err = NOTIFY_BAD; |
| 1112 | } |
| 1113 | break; |
| 1114 | default: |
| 1115 | err = NOTIFY_DONE; |
| 1116 | break; |
| 1117 | } |
| 1118 | return err; |
| 1119 | } |
| 1120 | |
| 1121 | static struct notifier_block prom_reconfig_nb = { |
| 1122 | .notifier_call = prom_reconfig_notifier, |
| 1123 | .priority = 10, /* This one needs to run first */ |
| 1124 | }; |
| 1125 | |
| 1126 | static int __init prom_reconfig_setup(void) |
| 1127 | { |
| 1128 | return pSeries_reconfig_notifier_register(&prom_reconfig_nb); |
| 1129 | } |
| 1130 | __initcall(prom_reconfig_setup); |
| 1131 | #endif |
| 1132 | |
Benjamin Herrenschmidt | acf7d76 | 2006-06-19 20:33:16 +0200 | [diff] [blame] | 1133 | /* Find the device node for a given logical cpu number, also returns the cpu |
| 1134 | * local thread number (index in ibm,interrupt-server#s) if relevant and |
| 1135 | * asked for (non NULL) |
| 1136 | */ |
| 1137 | struct device_node *of_get_cpu_node(int cpu, unsigned int *thread) |
| 1138 | { |
| 1139 | int hardid; |
| 1140 | struct device_node *np; |
| 1141 | |
| 1142 | hardid = get_hard_smp_processor_id(cpu); |
| 1143 | |
| 1144 | for_each_node_by_type(np, "cpu") { |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 1145 | const u32 *intserv; |
Benjamin Herrenschmidt | acf7d76 | 2006-06-19 20:33:16 +0200 | [diff] [blame] | 1146 | unsigned int plen, t; |
| 1147 | |
| 1148 | /* Check for ibm,ppc-interrupt-server#s. If it doesn't exist |
| 1149 | * fallback to "reg" property and assume no threads |
| 1150 | */ |
Stephen Rothwell | 0e56efc | 2007-04-03 10:54:01 +1000 | [diff] [blame] | 1151 | intserv = of_get_property(np, "ibm,ppc-interrupt-server#s", |
Jeremy Kerr | a7f67bd | 2006-07-12 15:35:54 +1000 | [diff] [blame] | 1152 | &plen); |
Benjamin Herrenschmidt | acf7d76 | 2006-06-19 20:33:16 +0200 | [diff] [blame] | 1153 | if (intserv == NULL) { |
Stephen Rothwell | 0e56efc | 2007-04-03 10:54:01 +1000 | [diff] [blame] | 1154 | const u32 *reg = of_get_property(np, "reg", NULL); |
Benjamin Herrenschmidt | acf7d76 | 2006-06-19 20:33:16 +0200 | [diff] [blame] | 1155 | if (reg == NULL) |
| 1156 | continue; |
| 1157 | if (*reg == hardid) { |
| 1158 | if (thread) |
| 1159 | *thread = 0; |
| 1160 | return np; |
| 1161 | } |
| 1162 | } else { |
| 1163 | plen /= sizeof(u32); |
| 1164 | for (t = 0; t < plen; t++) { |
| 1165 | if (hardid == intserv[t]) { |
| 1166 | if (thread) |
| 1167 | *thread = t; |
| 1168 | return np; |
| 1169 | } |
| 1170 | } |
| 1171 | } |
| 1172 | } |
| 1173 | return NULL; |
| 1174 | } |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 1175 | EXPORT_SYMBOL(of_get_cpu_node); |
Michael Ellerman | 7a4571a | 2006-06-23 18:16:03 +1000 | [diff] [blame] | 1176 | |
Michael Ellerman | 94a3807 | 2007-06-20 10:54:19 +1000 | [diff] [blame] | 1177 | #if defined(CONFIG_DEBUG_FS) && defined(DEBUG) |
Michael Ellerman | 7a4571a | 2006-06-23 18:16:03 +1000 | [diff] [blame] | 1178 | static struct debugfs_blob_wrapper flat_dt_blob; |
| 1179 | |
| 1180 | static int __init export_flat_device_tree(void) |
| 1181 | { |
| 1182 | struct dentry *d; |
| 1183 | |
Michael Ellerman | 7a4571a | 2006-06-23 18:16:03 +1000 | [diff] [blame] | 1184 | flat_dt_blob.data = initial_boot_params; |
| 1185 | flat_dt_blob.size = initial_boot_params->totalsize; |
| 1186 | |
| 1187 | d = debugfs_create_blob("flat-device-tree", S_IFREG | S_IRUSR, |
Michael Ellerman | 94a3807 | 2007-06-20 10:54:19 +1000 | [diff] [blame] | 1188 | powerpc_debugfs_root, &flat_dt_blob); |
Michael Ellerman | 7a4571a | 2006-06-23 18:16:03 +1000 | [diff] [blame] | 1189 | if (!d) |
| 1190 | return 1; |
| 1191 | |
| 1192 | return 0; |
| 1193 | } |
| 1194 | __initcall(export_flat_device_tree); |
| 1195 | #endif |