19b6b563cSPaul Mackerras /* 29b6b563cSPaul Mackerras * Procedures for creating, accessing and interpreting the device tree. 39b6b563cSPaul Mackerras * 49b6b563cSPaul Mackerras * Paul Mackerras August 1996. 59b6b563cSPaul Mackerras * Copyright (C) 1996-2005 Paul Mackerras. 69b6b563cSPaul Mackerras * 79b6b563cSPaul Mackerras * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner. 89b6b563cSPaul Mackerras * {engebret|bergner}@us.ibm.com 99b6b563cSPaul Mackerras * 109b6b563cSPaul Mackerras * This program is free software; you can redistribute it and/or 119b6b563cSPaul Mackerras * modify it under the terms of the GNU General Public License 129b6b563cSPaul Mackerras * as published by the Free Software Foundation; either version 139b6b563cSPaul Mackerras * 2 of the License, or (at your option) any later version. 149b6b563cSPaul Mackerras */ 159b6b563cSPaul Mackerras 169b6b563cSPaul Mackerras #undef DEBUG 179b6b563cSPaul Mackerras 189b6b563cSPaul Mackerras #include <stdarg.h> 199b6b563cSPaul Mackerras #include <linux/kernel.h> 209b6b563cSPaul Mackerras #include <linux/string.h> 219b6b563cSPaul Mackerras #include <linux/init.h> 229b6b563cSPaul Mackerras #include <linux/threads.h> 239b6b563cSPaul Mackerras #include <linux/spinlock.h> 249b6b563cSPaul Mackerras #include <linux/types.h> 259b6b563cSPaul Mackerras #include <linux/pci.h> 269b6b563cSPaul Mackerras #include <linux/stringify.h> 279b6b563cSPaul Mackerras #include <linux/delay.h> 289b6b563cSPaul Mackerras #include <linux/initrd.h> 299b6b563cSPaul Mackerras #include <linux/bitops.h> 304b16f8e2SPaul Gortmaker #include <linux/export.h> 31dcee3036SMichael Ellerman #include <linux/kexec.h> 320ebfff14SBenjamin Herrenschmidt #include <linux/irq.h> 3395f72d1eSYinghai Lu #include <linux/memblock.h> 341cf3d8b3SNathan Fontenot #include <linux/of.h> 35708b7eefSMarek Szyprowski #include <linux/of_fdt.h> 36060f78c2SRob Herring #include <linux/libfdt.h> 379b6b563cSPaul Mackerras 389b6b563cSPaul Mackerras #include <asm/prom.h> 399b6b563cSPaul Mackerras #include <asm/rtas.h> 409b6b563cSPaul Mackerras #include <asm/page.h> 419b6b563cSPaul Mackerras #include <asm/processor.h> 429b6b563cSPaul Mackerras #include <asm/irq.h> 439b6b563cSPaul Mackerras #include <asm/io.h> 440cc4746cSMichael Ellerman #include <asm/kdump.h> 459b6b563cSPaul Mackerras #include <asm/smp.h> 469b6b563cSPaul Mackerras #include <asm/mmu.h> 471426d5a3SMichael Ellerman #include <asm/paca.h> 489b6b563cSPaul Mackerras #include <asm/pgtable.h> 499b6b563cSPaul Mackerras #include <asm/iommu.h> 509b6b563cSPaul Mackerras #include <asm/btext.h> 519b6b563cSPaul Mackerras #include <asm/sections.h> 529b6b563cSPaul Mackerras #include <asm/machdep.h> 5340ef8cbcSPaul Mackerras #include <asm/pci-bridge.h> 542babf5c2SMichael Ellerman #include <asm/kexec.h> 5514a43e69SBenjamin Herrenschmidt #include <asm/opal.h> 56eb39c880SMahesh Salgaonkar #include <asm/fadump.h> 570dc3289cSTony Breeds #include <asm/debug.h> 5814a43e69SBenjamin Herrenschmidt 5937dd2badSKumar Gala #include <mm/mmu_decl.h> 609b6b563cSPaul Mackerras 619b6b563cSPaul Mackerras #ifdef DEBUG 629b6b563cSPaul Mackerras #define DBG(fmt...) printk(KERN_ERR fmt) 639b6b563cSPaul Mackerras #else 649b6b563cSPaul Mackerras #define DBG(fmt...) 659b6b563cSPaul Mackerras #endif 669b6b563cSPaul Mackerras 679b6b563cSPaul Mackerras #ifdef CONFIG_PPC64 6828897731SOlof Johansson int __initdata iommu_is_off; 699b6b563cSPaul Mackerras int __initdata iommu_force_on; 70cf00a8d1SPaul Mackerras unsigned long tce_alloc_start, tce_alloc_end; 71cd3db0c4SBenjamin Herrenschmidt u64 ppc64_rma_size; 729b6b563cSPaul Mackerras #endif 7303bf469aSBenjamin Herrenschmidt static phys_addr_t first_memblock_size; 747ac87abbSMatt Evans static int __initdata boot_cpu_count; 759b6b563cSPaul Mackerras 762babf5c2SMichael Ellerman static int __init early_parse_mem(char *p) 772babf5c2SMichael Ellerman { 782babf5c2SMichael Ellerman if (!p) 792babf5c2SMichael Ellerman return 1; 802babf5c2SMichael Ellerman 812babf5c2SMichael Ellerman memory_limit = PAGE_ALIGN(memparse(p, &p)); 82a84fcd46SSuzuki Poulose DBG("memory limit = 0x%llx\n", memory_limit); 832babf5c2SMichael Ellerman 842babf5c2SMichael Ellerman return 0; 852babf5c2SMichael Ellerman } 862babf5c2SMichael Ellerman early_param("mem", early_parse_mem); 872babf5c2SMichael Ellerman 88307cfe71SBenjamin Herrenschmidt /* 89307cfe71SBenjamin Herrenschmidt * overlaps_initrd - check for overlap with page aligned extension of 90307cfe71SBenjamin Herrenschmidt * initrd. 91307cfe71SBenjamin Herrenschmidt */ 92307cfe71SBenjamin Herrenschmidt static inline int overlaps_initrd(unsigned long start, unsigned long size) 93307cfe71SBenjamin Herrenschmidt { 94307cfe71SBenjamin Herrenschmidt #ifdef CONFIG_BLK_DEV_INITRD 95307cfe71SBenjamin Herrenschmidt if (!initrd_start) 96307cfe71SBenjamin Herrenschmidt return 0; 97307cfe71SBenjamin Herrenschmidt 98307cfe71SBenjamin Herrenschmidt return (start + size) > _ALIGN_DOWN(initrd_start, PAGE_SIZE) && 99307cfe71SBenjamin Herrenschmidt start <= _ALIGN_UP(initrd_end, PAGE_SIZE); 100307cfe71SBenjamin Herrenschmidt #else 101307cfe71SBenjamin Herrenschmidt return 0; 102307cfe71SBenjamin Herrenschmidt #endif 103307cfe71SBenjamin Herrenschmidt } 104307cfe71SBenjamin Herrenschmidt 1053c607ce2SLinas Vepstas /** 1063c607ce2SLinas Vepstas * move_device_tree - move tree to an unused area, if needed. 1073c607ce2SLinas Vepstas * 1083c607ce2SLinas Vepstas * The device tree may be allocated beyond our memory limit, or inside the 109307cfe71SBenjamin Herrenschmidt * crash kernel region for kdump, or within the page aligned range of initrd. 110307cfe71SBenjamin Herrenschmidt * If so, move it out of the way. 1112babf5c2SMichael Ellerman */ 11218f032cbSGeert Uytterhoeven static void __init move_device_tree(void) 1132babf5c2SMichael Ellerman { 1142babf5c2SMichael Ellerman unsigned long start, size; 1152babf5c2SMichael Ellerman void *p; 1162babf5c2SMichael Ellerman 1172babf5c2SMichael Ellerman DBG("-> move_device_tree\n"); 1182babf5c2SMichael Ellerman 1192babf5c2SMichael Ellerman start = __pa(initial_boot_params); 120060f78c2SRob Herring size = fdt_totalsize(initial_boot_params); 1212babf5c2SMichael Ellerman 1226dd22700SScott Wood if ((memory_limit && (start + size) > PHYSICAL_START + memory_limit) || 123307cfe71SBenjamin Herrenschmidt overlaps_crashkernel(start, size) || 124307cfe71SBenjamin Herrenschmidt overlaps_initrd(start, size)) { 125e63075a3SBenjamin Herrenschmidt p = __va(memblock_alloc(size, PAGE_SIZE)); 1262babf5c2SMichael Ellerman memcpy(p, initial_boot_params, size); 127060f78c2SRob Herring initial_boot_params = p; 1282babf5c2SMichael Ellerman DBG("Moved device tree to 0x%p\n", p); 1292babf5c2SMichael Ellerman } 1302babf5c2SMichael Ellerman 1312babf5c2SMichael Ellerman DBG("<- move_device_tree\n"); 1322babf5c2SMichael Ellerman } 1339b6b563cSPaul Mackerras 134d205819eSPaul Mackerras /* 135d205819eSPaul Mackerras * ibm,pa-features is a per-cpu property that contains a string of 136d205819eSPaul Mackerras * attribute descriptors, each of which has a 2 byte header plus up 137d205819eSPaul Mackerras * to 254 bytes worth of processor attribute bits. First header 138d205819eSPaul Mackerras * byte specifies the number of bytes following the header. 139d205819eSPaul Mackerras * Second header byte is an "attribute-specifier" type, of which 140d205819eSPaul Mackerras * zero is the only currently-defined value. 141d205819eSPaul Mackerras * Implementation: Pass in the byte and bit offset for the feature 142d205819eSPaul Mackerras * that we are interested in. The function will return -1 if the 143d205819eSPaul Mackerras * pa-features property is missing, or a 1/0 to indicate if the feature 144d205819eSPaul Mackerras * is supported/not supported. Note that the bit numbers are 145d205819eSPaul Mackerras * big-endian to match the definition in PAPR. 146d205819eSPaul Mackerras */ 147d205819eSPaul Mackerras static struct ibm_pa_feature { 148d205819eSPaul Mackerras unsigned long cpu_features; /* CPU_FTR_xxx bit */ 14944ae3ab3SMatt Evans unsigned long mmu_features; /* MMU_FTR_xxx bit */ 150d205819eSPaul Mackerras unsigned int cpu_user_ftrs; /* PPC_FEATURE_xxx bit */ 151d205819eSPaul Mackerras unsigned char pabyte; /* byte number in ibm,pa-features */ 152d205819eSPaul Mackerras unsigned char pabit; /* bit number (big-endian) */ 153d205819eSPaul Mackerras unsigned char invert; /* if 1, pa bit set => clear feature */ 154d205819eSPaul Mackerras } ibm_pa_features[] __initdata = { 15544ae3ab3SMatt Evans {0, 0, PPC_FEATURE_HAS_MMU, 0, 0, 0}, 15644ae3ab3SMatt Evans {0, 0, PPC_FEATURE_HAS_FPU, 0, 1, 0}, 15744ae3ab3SMatt Evans {CPU_FTR_CTRL, 0, 0, 0, 3, 0}, 15844ae3ab3SMatt Evans {CPU_FTR_NOEXECUTE, 0, 0, 0, 6, 0}, 15944ae3ab3SMatt Evans {CPU_FTR_NODSISRALIGN, 0, 0, 1, 1, 1}, 16044ae3ab3SMatt Evans {0, MMU_FTR_CI_LARGE_PAGE, 0, 1, 2, 0}, 161339d76c5SPaul Mackerras {CPU_FTR_REAL_LE, PPC_FEATURE_TRUE_LE, 5, 0, 0}, 1629e819963SAneesh Kumar K.V /* 1639e819963SAneesh Kumar K.V * If the kernel doesn't support TM (ie. CONFIG_PPC_TRANSACTIONAL_MEM=n), 1649e819963SAneesh Kumar K.V * we don't want to turn on CPU_FTR_TM here, so we use CPU_FTR_TM_COMP 1659e819963SAneesh Kumar K.V * which is 0 if the kernel doesn't support TM. 1669e819963SAneesh Kumar K.V */ 1679e819963SAneesh Kumar K.V {CPU_FTR_TM_COMP, 0, 0, 22, 0, 0}, 168d205819eSPaul Mackerras }; 169d205819eSPaul Mackerras 1709d0c4dfeSRob Herring static void __init scan_features(unsigned long node, const unsigned char *ftrs, 171974a76f5SPaul Mackerras unsigned long tablelen, 172974a76f5SPaul Mackerras struct ibm_pa_feature *fp, 173974a76f5SPaul Mackerras unsigned long ft_size) 174d205819eSPaul Mackerras { 175974a76f5SPaul Mackerras unsigned long i, len, bit; 176d205819eSPaul Mackerras 177d205819eSPaul Mackerras /* find descriptor with type == 0 */ 178d205819eSPaul Mackerras for (;;) { 179d205819eSPaul Mackerras if (tablelen < 3) 180d205819eSPaul Mackerras return; 181974a76f5SPaul Mackerras len = 2 + ftrs[0]; 182d205819eSPaul Mackerras if (tablelen < len) 183d205819eSPaul Mackerras return; /* descriptor 0 not found */ 184974a76f5SPaul Mackerras if (ftrs[1] == 0) 185d205819eSPaul Mackerras break; 186d205819eSPaul Mackerras tablelen -= len; 187974a76f5SPaul Mackerras ftrs += len; 188d205819eSPaul Mackerras } 189d205819eSPaul Mackerras 190d205819eSPaul Mackerras /* loop over bits we know about */ 191974a76f5SPaul Mackerras for (i = 0; i < ft_size; ++i, ++fp) { 192974a76f5SPaul Mackerras if (fp->pabyte >= ftrs[0]) 193d205819eSPaul Mackerras continue; 194974a76f5SPaul Mackerras bit = (ftrs[2 + fp->pabyte] >> (7 - fp->pabit)) & 1; 195d205819eSPaul Mackerras if (bit ^ fp->invert) { 196d205819eSPaul Mackerras cur_cpu_spec->cpu_features |= fp->cpu_features; 197d205819eSPaul Mackerras cur_cpu_spec->cpu_user_features |= fp->cpu_user_ftrs; 19844ae3ab3SMatt Evans cur_cpu_spec->mmu_features |= fp->mmu_features; 199d205819eSPaul Mackerras } else { 200d205819eSPaul Mackerras cur_cpu_spec->cpu_features &= ~fp->cpu_features; 201d205819eSPaul Mackerras cur_cpu_spec->cpu_user_features &= ~fp->cpu_user_ftrs; 20244ae3ab3SMatt Evans cur_cpu_spec->mmu_features &= ~fp->mmu_features; 203d205819eSPaul Mackerras } 204d205819eSPaul Mackerras } 205d205819eSPaul Mackerras } 206d205819eSPaul Mackerras 207974a76f5SPaul Mackerras static void __init check_cpu_pa_features(unsigned long node) 208974a76f5SPaul Mackerras { 2099d0c4dfeSRob Herring const unsigned char *pa_ftrs; 2109d0c4dfeSRob Herring int tablelen; 211974a76f5SPaul Mackerras 212974a76f5SPaul Mackerras pa_ftrs = of_get_flat_dt_prop(node, "ibm,pa-features", &tablelen); 213974a76f5SPaul Mackerras if (pa_ftrs == NULL) 214974a76f5SPaul Mackerras return; 215974a76f5SPaul Mackerras 216974a76f5SPaul Mackerras scan_features(node, pa_ftrs, tablelen, 217974a76f5SPaul Mackerras ibm_pa_features, ARRAY_SIZE(ibm_pa_features)); 218974a76f5SPaul Mackerras } 219974a76f5SPaul Mackerras 22094491685SBenjamin Herrenschmidt #ifdef CONFIG_PPC_STD_MMU_64 221*9c61f7a0SAnshuman Khandual static void __init init_mmu_slb_size(unsigned long node) 222584f8b71SMichael Neuling { 2239d0c4dfeSRob Herring const __be32 *slb_size_ptr; 224584f8b71SMichael Neuling 225*9c61f7a0SAnshuman Khandual slb_size_ptr = of_get_flat_dt_prop(node, "slb-size", NULL) ? : 226*9c61f7a0SAnshuman Khandual of_get_flat_dt_prop(node, "ibm,slb-size", NULL); 227*9c61f7a0SAnshuman Khandual 228*9c61f7a0SAnshuman Khandual if (slb_size_ptr) 229dc0e643aSIan Munsie mmu_slb_size = be32_to_cpup(slb_size_ptr); 230584f8b71SMichael Neuling } 231584f8b71SMichael Neuling #else 232*9c61f7a0SAnshuman Khandual #define init_mmu_slb_size(node) do { } while(0) 233584f8b71SMichael Neuling #endif 234584f8b71SMichael Neuling 235974a76f5SPaul Mackerras static struct feature_property { 236974a76f5SPaul Mackerras const char *name; 237974a76f5SPaul Mackerras u32 min_value; 238974a76f5SPaul Mackerras unsigned long cpu_feature; 239974a76f5SPaul Mackerras unsigned long cpu_user_ftr; 240974a76f5SPaul Mackerras } feature_properties[] __initdata = { 241974a76f5SPaul Mackerras #ifdef CONFIG_ALTIVEC 242974a76f5SPaul Mackerras {"altivec", 0, CPU_FTR_ALTIVEC, PPC_FEATURE_HAS_ALTIVEC}, 243974a76f5SPaul Mackerras {"ibm,vmx", 1, CPU_FTR_ALTIVEC, PPC_FEATURE_HAS_ALTIVEC}, 244974a76f5SPaul Mackerras #endif /* CONFIG_ALTIVEC */ 245b962ce9dSMichael Neuling #ifdef CONFIG_VSX 246b962ce9dSMichael Neuling /* Yes, this _really_ is ibm,vmx == 2 to enable VSX */ 247b962ce9dSMichael Neuling {"ibm,vmx", 2, CPU_FTR_VSX, PPC_FEATURE_HAS_VSX}, 248b962ce9dSMichael Neuling #endif /* CONFIG_VSX */ 249974a76f5SPaul Mackerras #ifdef CONFIG_PPC64 250974a76f5SPaul Mackerras {"ibm,dfp", 1, 0, PPC_FEATURE_HAS_DFP}, 251974a76f5SPaul Mackerras {"ibm,purr", 1, CPU_FTR_PURR, 0}, 252974a76f5SPaul Mackerras {"ibm,spurr", 1, CPU_FTR_SPURR, 0}, 253974a76f5SPaul Mackerras #endif /* CONFIG_PPC64 */ 254974a76f5SPaul Mackerras }; 255974a76f5SPaul Mackerras 25614b3d926SValentine Barshak #if defined(CONFIG_44x) && defined(CONFIG_PPC_FPU) 25714b3d926SValentine Barshak static inline void identical_pvr_fixup(unsigned long node) 25814b3d926SValentine Barshak { 25914b3d926SValentine Barshak unsigned int pvr; 2609d0c4dfeSRob Herring const char *model = of_get_flat_dt_prop(node, "model", NULL); 26114b3d926SValentine Barshak 26214b3d926SValentine Barshak /* 26314b3d926SValentine Barshak * Since 440GR(x)/440EP(x) processors have the same pvr, 26414b3d926SValentine Barshak * we check the node path and set bit 28 in the cur_cpu_spec 26514b3d926SValentine Barshak * pvr for EP(x) processor version. This bit is always 0 in 26614b3d926SValentine Barshak * the "real" pvr. Then we call identify_cpu again with 26714b3d926SValentine Barshak * the new logical pvr to enable FPU support. 26814b3d926SValentine Barshak */ 26914b3d926SValentine Barshak if (model && strstr(model, "440EP")) { 27014b3d926SValentine Barshak pvr = cur_cpu_spec->pvr_value | 0x8; 27114b3d926SValentine Barshak identify_cpu(0, pvr); 27214b3d926SValentine Barshak DBG("Using logical pvr %x for %s\n", pvr, model); 27314b3d926SValentine Barshak } 27414b3d926SValentine Barshak } 27514b3d926SValentine Barshak #else 27614b3d926SValentine Barshak #define identical_pvr_fixup(node) do { } while(0) 27714b3d926SValentine Barshak #endif 27814b3d926SValentine Barshak 279974a76f5SPaul Mackerras static void __init check_cpu_feature_properties(unsigned long node) 280974a76f5SPaul Mackerras { 281974a76f5SPaul Mackerras unsigned long i; 282974a76f5SPaul Mackerras struct feature_property *fp = feature_properties; 283dc0e643aSIan Munsie const __be32 *prop; 284974a76f5SPaul Mackerras 285974a76f5SPaul Mackerras for (i = 0; i < ARRAY_SIZE(feature_properties); ++i, ++fp) { 286974a76f5SPaul Mackerras prop = of_get_flat_dt_prop(node, fp->name, NULL); 287dc0e643aSIan Munsie if (prop && be32_to_cpup(prop) >= fp->min_value) { 288974a76f5SPaul Mackerras cur_cpu_spec->cpu_features |= fp->cpu_feature; 289974a76f5SPaul Mackerras cur_cpu_spec->cpu_user_features |= fp->cpu_user_ftr; 290974a76f5SPaul Mackerras } 291974a76f5SPaul Mackerras } 292974a76f5SPaul Mackerras } 293974a76f5SPaul Mackerras 2949b6b563cSPaul Mackerras static int __init early_init_dt_scan_cpus(unsigned long node, 2954df20460SAnton Blanchard const char *uname, int depth, 2964df20460SAnton Blanchard void *data) 2979b6b563cSPaul Mackerras { 2989d0c4dfeSRob Herring const char *type = of_get_flat_dt_prop(node, "device_type", NULL); 299dc0e643aSIan Munsie const __be32 *prop; 300dc0e643aSIan Munsie const __be32 *intserv; 3014df20460SAnton Blanchard int i, nthreads; 3029d0c4dfeSRob Herring int len; 3039d07bc84SBenjamin Herrenschmidt int found = -1; 304208b3a4cSBenjamin Herrenschmidt int found_thread = 0; 3059b6b563cSPaul Mackerras 3069b6b563cSPaul Mackerras /* We are scanning "cpu" nodes only */ 3079b6b563cSPaul Mackerras if (type == NULL || strcmp(type, "cpu") != 0) 3089b6b563cSPaul Mackerras return 0; 3099b6b563cSPaul Mackerras 3104df20460SAnton Blanchard /* Get physical cpuid */ 3114df20460SAnton Blanchard intserv = of_get_flat_dt_prop(node, "ibm,ppc-interrupt-server#s", &len); 312e16c8765SAndy Fleming if (!intserv) 313e16c8765SAndy Fleming intserv = of_get_flat_dt_prop(node, "reg", &len); 314e16c8765SAndy Fleming 3154df20460SAnton Blanchard nthreads = len / sizeof(int); 3164df20460SAnton Blanchard 3174df20460SAnton Blanchard /* 3184df20460SAnton Blanchard * Now see if any of these threads match our boot cpu. 3194df20460SAnton Blanchard * NOTE: This must match the parsing done in smp_setup_cpu_maps. 3204df20460SAnton Blanchard */ 3214df20460SAnton Blanchard for (i = 0; i < nthreads; i++) { 3224df20460SAnton Blanchard /* 3234df20460SAnton Blanchard * version 2 of the kexec param format adds the phys cpuid of 3244df20460SAnton Blanchard * booted proc. 3254df20460SAnton Blanchard */ 326060f78c2SRob Herring if (fdt_version(initial_boot_params) >= 2) { 327dc0e643aSIan Munsie if (be32_to_cpu(intserv[i]) == 328060f78c2SRob Herring fdt_boot_cpuid_phys(initial_boot_params)) { 3299d07bc84SBenjamin Herrenschmidt found = boot_cpu_count; 330208b3a4cSBenjamin Herrenschmidt found_thread = i; 331208b3a4cSBenjamin Herrenschmidt } 3324df20460SAnton Blanchard } else { 3334df20460SAnton Blanchard /* 3344df20460SAnton Blanchard * Check if it's the boot-cpu, set it's hw index now, 3354df20460SAnton Blanchard * unfortunately this format did not support booting 3364df20460SAnton Blanchard * off secondary threads. 3374df20460SAnton Blanchard */ 3383c726f8dSBenjamin Herrenschmidt if (of_get_flat_dt_prop(node, 3399d07bc84SBenjamin Herrenschmidt "linux,boot-cpu", NULL) != NULL) 3409d07bc84SBenjamin Herrenschmidt found = boot_cpu_count; 3419b6b563cSPaul Mackerras } 3424df20460SAnton Blanchard #ifdef CONFIG_SMP 3434df20460SAnton Blanchard /* logical cpu id is always 0 on UP kernels */ 3449d07bc84SBenjamin Herrenschmidt boot_cpu_count++; 3454df20460SAnton Blanchard #endif 3464df20460SAnton Blanchard } 3474df20460SAnton Blanchard 3487222f779SBenjamin Herrenschmidt /* Not the boot CPU */ 3497222f779SBenjamin Herrenschmidt if (found < 0) 3507222f779SBenjamin Herrenschmidt return 0; 3517222f779SBenjamin Herrenschmidt 3529d07bc84SBenjamin Herrenschmidt DBG("boot cpu: logical %d physical %d\n", found, 353dc0e643aSIan Munsie be32_to_cpu(intserv[found_thread])); 3549d07bc84SBenjamin Herrenschmidt boot_cpuid = found; 3557222f779SBenjamin Herrenschmidt set_hard_smp_processor_id(found, be32_to_cpu(intserv[found_thread])); 356974a76f5SPaul Mackerras 357974a76f5SPaul Mackerras /* 358974a76f5SPaul Mackerras * PAPR defines "logical" PVR values for cpus that 359974a76f5SPaul Mackerras * meet various levels of the architecture: 360974a76f5SPaul Mackerras * 0x0f000001 Architecture version 2.04 361974a76f5SPaul Mackerras * 0x0f000002 Architecture version 2.05 362974a76f5SPaul Mackerras * If the cpu-version property in the cpu node contains 363974a76f5SPaul Mackerras * such a value, we call identify_cpu again with the 364974a76f5SPaul Mackerras * logical PVR value in order to use the cpu feature 365974a76f5SPaul Mackerras * bits appropriate for the architecture level. 366974a76f5SPaul Mackerras * 367974a76f5SPaul Mackerras * A POWER6 partition in "POWER6 architected" mode 368974a76f5SPaul Mackerras * uses the 0x0f000002 PVR value; in POWER5+ mode 369974a76f5SPaul Mackerras * it uses 0x0f000001. 370974a76f5SPaul Mackerras */ 371974a76f5SPaul Mackerras prop = of_get_flat_dt_prop(node, "cpu-version", NULL); 372dc0e643aSIan Munsie if (prop && (be32_to_cpup(prop) & 0xff000000) == 0x0f000000) 373dc0e643aSIan Munsie identify_cpu(0, be32_to_cpup(prop)); 37414b3d926SValentine Barshak 37514b3d926SValentine Barshak identical_pvr_fixup(node); 3769b6b563cSPaul Mackerras 377974a76f5SPaul Mackerras check_cpu_feature_properties(node); 378d205819eSPaul Mackerras check_cpu_pa_features(node); 379*9c61f7a0SAnshuman Khandual init_mmu_slb_size(node); 380d205819eSPaul Mackerras 3814a85b31dSBenjamin Herrenschmidt #ifdef CONFIG_PPC64 3824df20460SAnton Blanchard if (nthreads > 1) 3839b6b563cSPaul Mackerras cur_cpu_spec->cpu_features |= CPU_FTR_SMT; 3844df20460SAnton Blanchard else 3854df20460SAnton Blanchard cur_cpu_spec->cpu_features &= ~CPU_FTR_SMT; 3869b6b563cSPaul Mackerras #endif 3879b6b563cSPaul Mackerras return 0; 3889b6b563cSPaul Mackerras } 3899b6b563cSPaul Mackerras 390e51df2c1SAnton Blanchard static int __init early_init_dt_scan_chosen_ppc(unsigned long node, 391e51df2c1SAnton Blanchard const char *uname, 39232c97689SGrant Likely int depth, void *data) 3939b6b563cSPaul Mackerras { 3949d0c4dfeSRob Herring const unsigned long *lprop; /* All these set by kernel, so no need to convert endian */ 3959b6b563cSPaul Mackerras 39632c97689SGrant Likely /* Use common scan routine to determine if this is the chosen node */ 39732c97689SGrant Likely if (early_init_dt_scan_chosen(node, uname, depth, data) == 0) 39832c97689SGrant Likely return 0; 39932c97689SGrant Likely 4009b6b563cSPaul Mackerras #ifdef CONFIG_PPC64 4019b6b563cSPaul Mackerras /* check if iommu is forced on or off */ 4023c726f8dSBenjamin Herrenschmidt if (of_get_flat_dt_prop(node, "linux,iommu-off", NULL) != NULL) 4039b6b563cSPaul Mackerras iommu_is_off = 1; 4043c726f8dSBenjamin Herrenschmidt if (of_get_flat_dt_prop(node, "linux,iommu-force-on", NULL) != NULL) 4059b6b563cSPaul Mackerras iommu_force_on = 1; 4069b6b563cSPaul Mackerras #endif 4079b6b563cSPaul Mackerras 4082babf5c2SMichael Ellerman /* mem=x on the command line is the preferred mechanism */ 4093c726f8dSBenjamin Herrenschmidt lprop = of_get_flat_dt_prop(node, "linux,memory-limit", NULL); 4109b6b563cSPaul Mackerras if (lprop) 4119b6b563cSPaul Mackerras memory_limit = *lprop; 4129b6b563cSPaul Mackerras 4139b6b563cSPaul Mackerras #ifdef CONFIG_PPC64 4143c726f8dSBenjamin Herrenschmidt lprop = of_get_flat_dt_prop(node, "linux,tce-alloc-start", NULL); 4159b6b563cSPaul Mackerras if (lprop) 4169b6b563cSPaul Mackerras tce_alloc_start = *lprop; 4173c726f8dSBenjamin Herrenschmidt lprop = of_get_flat_dt_prop(node, "linux,tce-alloc-end", NULL); 4189b6b563cSPaul Mackerras if (lprop) 4199b6b563cSPaul Mackerras tce_alloc_end = *lprop; 4209b6b563cSPaul Mackerras #endif 4219b6b563cSPaul Mackerras 422dcee3036SMichael Ellerman #ifdef CONFIG_KEXEC 42363277161SStephen Rothwell lprop = of_get_flat_dt_prop(node, "linux,crashkernel-base", NULL); 424dcee3036SMichael Ellerman if (lprop) 425dcee3036SMichael Ellerman crashk_res.start = *lprop; 426dcee3036SMichael Ellerman 42763277161SStephen Rothwell lprop = of_get_flat_dt_prop(node, "linux,crashkernel-size", NULL); 428dcee3036SMichael Ellerman if (lprop) 429dcee3036SMichael Ellerman crashk_res.end = crashk_res.start + *lprop - 1; 430dcee3036SMichael Ellerman #endif 43132c97689SGrant Likely 43232c97689SGrant Likely /* break now */ 43332c97689SGrant Likely return 1; 4349b6b563cSPaul Mackerras } 4359b6b563cSPaul Mackerras 4360204568aSPaul Mackerras #ifdef CONFIG_PPC_PSERIES 4370204568aSPaul Mackerras /* 4380204568aSPaul Mackerras * Interpret the ibm,dynamic-memory property in the 4390204568aSPaul Mackerras * /ibm,dynamic-reconfiguration-memory node. 4400204568aSPaul Mackerras * This contains a list of memory blocks along with NUMA affinity 4410204568aSPaul Mackerras * information. 4420204568aSPaul Mackerras */ 4430204568aSPaul Mackerras static int __init early_init_dt_scan_drconf_memory(unsigned long node) 4440204568aSPaul Mackerras { 4459d0c4dfeSRob Herring const __be32 *dm, *ls, *usm; 4469d0c4dfeSRob Herring int l; 4479d0c4dfeSRob Herring unsigned long n, flags; 44895f72d1eSYinghai Lu u64 base, size, memblock_size; 449cf00085dSChandru unsigned int is_kexec_kdump = 0, rngs; 4500204568aSPaul Mackerras 4513fdfd990SBenjamin Herrenschmidt ls = of_get_flat_dt_prop(node, "ibm,lmb-size", &l); 4520f0b56c3SGrant Likely if (ls == NULL || l < dt_root_size_cells * sizeof(__be32)) 4530204568aSPaul Mackerras return 0; 45495f72d1eSYinghai Lu memblock_size = dt_mem_next_cell(dt_root_size_cells, &ls); 4550204568aSPaul Mackerras 45663277161SStephen Rothwell dm = of_get_flat_dt_prop(node, "ibm,dynamic-memory", &l); 4570f0b56c3SGrant Likely if (dm == NULL || l < sizeof(__be32)) 4580204568aSPaul Mackerras return 0; 4590204568aSPaul Mackerras 460e91ae5bdSAlistair Popple n = of_read_number(dm++, 1); /* number of entries */ 4610f0b56c3SGrant Likely if (l < (n * (dt_root_addr_cells + 4) + 1) * sizeof(__be32)) 4620204568aSPaul Mackerras return 0; 4630204568aSPaul Mackerras 464cf00085dSChandru /* check if this is a kexec/kdump kernel. */ 46563277161SStephen Rothwell usm = of_get_flat_dt_prop(node, "linux,drconf-usable-memory", 466cf00085dSChandru &l); 467cf00085dSChandru if (usm != NULL) 468cf00085dSChandru is_kexec_kdump = 1; 469cf00085dSChandru 4700204568aSPaul Mackerras for (; n != 0; --n) { 4710204568aSPaul Mackerras base = dt_mem_next_cell(dt_root_addr_cells, &dm); 472e91ae5bdSAlistair Popple flags = of_read_number(&dm[3], 1); 4730204568aSPaul Mackerras /* skip DRC index, pad, assoc. list index, flags */ 4740204568aSPaul Mackerras dm += 4; 4750204568aSPaul Mackerras /* skip this block if the reserved bit is set in flags (0x80) 4760204568aSPaul Mackerras or if the block is not assigned to this partition (0x8) */ 4770204568aSPaul Mackerras if ((flags & 0x80) || !(flags & 0x8)) 4780204568aSPaul Mackerras continue; 47995f72d1eSYinghai Lu size = memblock_size; 480cf00085dSChandru rngs = 1; 481cf00085dSChandru if (is_kexec_kdump) { 482cf00085dSChandru /* 48395f72d1eSYinghai Lu * For each memblock in ibm,dynamic-memory, a corresponding 484cf00085dSChandru * entry in linux,drconf-usable-memory property contains 485cf00085dSChandru * a counter 'p' followed by 'p' (base, size) duple. 486cf00085dSChandru * Now read the counter from 487cf00085dSChandru * linux,drconf-usable-memory property 488cf00085dSChandru */ 489cf00085dSChandru rngs = dt_mem_next_cell(dt_root_size_cells, &usm); 490cf00085dSChandru if (!rngs) /* there are no (base, size) duple */ 491cf00085dSChandru continue; 492cf00085dSChandru } 493cf00085dSChandru do { 494cf00085dSChandru if (is_kexec_kdump) { 495cf00085dSChandru base = dt_mem_next_cell(dt_root_addr_cells, 496cf00085dSChandru &usm); 497cf00085dSChandru size = dt_mem_next_cell(dt_root_size_cells, 498cf00085dSChandru &usm); 499cf00085dSChandru } 5000204568aSPaul Mackerras if (iommu_is_off) { 5010204568aSPaul Mackerras if (base >= 0x80000000ul) 5020204568aSPaul Mackerras continue; 5030204568aSPaul Mackerras if ((base + size) > 0x80000000ul) 5040204568aSPaul Mackerras size = 0x80000000ul - base; 5050204568aSPaul Mackerras } 50695f72d1eSYinghai Lu memblock_add(base, size); 507cf00085dSChandru } while (--rngs); 5080204568aSPaul Mackerras } 50995f72d1eSYinghai Lu memblock_dump_all(); 5100204568aSPaul Mackerras return 0; 5110204568aSPaul Mackerras } 5120204568aSPaul Mackerras #else 5130204568aSPaul Mackerras #define early_init_dt_scan_drconf_memory(node) 0 5140204568aSPaul Mackerras #endif /* CONFIG_PPC_PSERIES */ 5159b6b563cSPaul Mackerras 51651975db0SGrant Likely static int __init early_init_dt_scan_memory_ppc(unsigned long node, 51751975db0SGrant Likely const char *uname, 51851975db0SGrant Likely int depth, void *data) 5199b6b563cSPaul Mackerras { 5200204568aSPaul Mackerras if (depth == 1 && 5210204568aSPaul Mackerras strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0) 5220204568aSPaul Mackerras return early_init_dt_scan_drconf_memory(node); 5230204568aSPaul Mackerras 52451975db0SGrant Likely return early_init_dt_scan_memory(node, uname, depth, data); 52551975db0SGrant Likely } 5269b6b563cSPaul Mackerras 527b27652ddSKevin Hao /* 528b27652ddSKevin Hao * For a relocatable kernel, we need to get the memstart_addr first, 529b27652ddSKevin Hao * then use it to calculate the virtual kernel start address. This has 530b27652ddSKevin Hao * to happen at a very early stage (before machine_init). In this case, 531b27652ddSKevin Hao * we just want to get the memstart_address and would not like to mess the 532b27652ddSKevin Hao * memblock at this stage. So introduce a variable to skip the memblock_add() 533b27652ddSKevin Hao * for this reason. 534b27652ddSKevin Hao */ 535b27652ddSKevin Hao #ifdef CONFIG_RELOCATABLE 536b27652ddSKevin Hao static int add_mem_to_memblock = 1; 537b27652ddSKevin Hao #else 538b27652ddSKevin Hao #define add_mem_to_memblock 1 539b27652ddSKevin Hao #endif 540b27652ddSKevin Hao 54151975db0SGrant Likely void __init early_init_dt_add_memory_arch(u64 base, u64 size) 54251975db0SGrant Likely { 543cd3db0c4SBenjamin Herrenschmidt #ifdef CONFIG_PPC64 5449b6b563cSPaul Mackerras if (iommu_is_off) { 5459b6b563cSPaul Mackerras if (base >= 0x80000000ul) 54651975db0SGrant Likely return; 5479b6b563cSPaul Mackerras if ((base + size) > 0x80000000ul) 5489b6b563cSPaul Mackerras size = 0x80000000ul - base; 5499b6b563cSPaul Mackerras } 5509b6b563cSPaul Mackerras #endif 55103bf469aSBenjamin Herrenschmidt /* Keep track of the beginning of memory -and- the size of 55203bf469aSBenjamin Herrenschmidt * the very first block in the device-tree as it represents 55303bf469aSBenjamin Herrenschmidt * the RMA on ppc64 server 55403bf469aSBenjamin Herrenschmidt */ 55503bf469aSBenjamin Herrenschmidt if (base < memstart_addr) { 55603bf469aSBenjamin Herrenschmidt memstart_addr = base; 55703bf469aSBenjamin Herrenschmidt first_memblock_size = size; 55803bf469aSBenjamin Herrenschmidt } 559cd3db0c4SBenjamin Herrenschmidt 560cd3db0c4SBenjamin Herrenschmidt /* Add the chunk to the MEMBLOCK list */ 561b27652ddSKevin Hao if (add_mem_to_memblock) 562cd3db0c4SBenjamin Herrenschmidt memblock_add(base, size); 5639b6b563cSPaul Mackerras } 56437dd2badSKumar Gala 565c039e3a8SBenjamin Herrenschmidt static void __init early_reserve_mem_dt(void) 5660962e800SJeremy Kerr { 5679d0c4dfeSRob Herring unsigned long i, dt_root; 5689d0c4dfeSRob Herring int len; 5690962e800SJeremy Kerr const __be32 *prop; 5700962e800SJeremy Kerr 57124bbd929SArd Biesheuvel early_init_fdt_reserve_self(); 572edba274cSRob Herring early_init_fdt_scan_reserved_mem(); 573edba274cSRob Herring 5740962e800SJeremy Kerr dt_root = of_get_flat_dt_root(); 5750962e800SJeremy Kerr 5760962e800SJeremy Kerr prop = of_get_flat_dt_prop(dt_root, "reserved-ranges", &len); 5770962e800SJeremy Kerr 5780962e800SJeremy Kerr if (!prop) 579c039e3a8SBenjamin Herrenschmidt return; 580c039e3a8SBenjamin Herrenschmidt 581c039e3a8SBenjamin Herrenschmidt DBG("Found new-style reserved-ranges\n"); 5820962e800SJeremy Kerr 5830962e800SJeremy Kerr /* Each reserved range is an (address,size) pair, 2 cells each, 5840962e800SJeremy Kerr * totalling 4 cells per range. */ 5850962e800SJeremy Kerr for (i = 0; i < len / (sizeof(*prop) * 4); i++) { 5860962e800SJeremy Kerr u64 base, size; 5870962e800SJeremy Kerr 5880962e800SJeremy Kerr base = of_read_number(prop + (i * 4) + 0, 2); 5890962e800SJeremy Kerr size = of_read_number(prop + (i * 4) + 2, 2); 5900962e800SJeremy Kerr 591c039e3a8SBenjamin Herrenschmidt if (size) { 592c039e3a8SBenjamin Herrenschmidt DBG("reserving: %llx -> %llx\n", base, size); 5930962e800SJeremy Kerr memblock_reserve(base, size); 5940962e800SJeremy Kerr } 595c039e3a8SBenjamin Herrenschmidt } 5960962e800SJeremy Kerr } 5970962e800SJeremy Kerr 5989b6b563cSPaul Mackerras static void __init early_reserve_mem(void) 5999b6b563cSPaul Mackerras { 600dc0e643aSIan Munsie __be64 *reserve_map; 6019b6b563cSPaul Mackerras 602dc0e643aSIan Munsie reserve_map = (__be64 *)(((unsigned long)initial_boot_params) + 603060f78c2SRob Herring fdt_off_mem_rsvmap(initial_boot_params)); 6044d1f3f25SJimi Xenidis 605c039e3a8SBenjamin Herrenschmidt /* Look for the new "reserved-regions" property in the DT */ 606c039e3a8SBenjamin Herrenschmidt early_reserve_mem_dt(); 6070962e800SJeremy Kerr 60830437b3eSDavid Gibson #ifdef CONFIG_BLK_DEV_INITRD 609c039e3a8SBenjamin Herrenschmidt /* Then reserve the initrd, if any */ 610c039e3a8SBenjamin Herrenschmidt if (initrd_start && (initrd_end > initrd_start)) { 611307cfe71SBenjamin Herrenschmidt memblock_reserve(_ALIGN_DOWN(__pa(initrd_start), PAGE_SIZE), 612307cfe71SBenjamin Herrenschmidt _ALIGN_UP(initrd_end, PAGE_SIZE) - 613307cfe71SBenjamin Herrenschmidt _ALIGN_DOWN(initrd_start, PAGE_SIZE)); 614c039e3a8SBenjamin Herrenschmidt } 61530437b3eSDavid Gibson #endif /* CONFIG_BLK_DEV_INITRD */ 61630437b3eSDavid Gibson 617cbbcf340SKumar Gala #ifdef CONFIG_PPC32 618cbbcf340SKumar Gala /* 619cbbcf340SKumar Gala * Handle the case where we might be booting from an old kexec 620cbbcf340SKumar Gala * image that setup the mem_rsvmap as pairs of 32-bit values 621cbbcf340SKumar Gala */ 622dc0e643aSIan Munsie if (be64_to_cpup(reserve_map) > 0xffffffffull) { 623cbbcf340SKumar Gala u32 base_32, size_32; 624dc0e643aSIan Munsie __be32 *reserve_map_32 = (__be32 *)reserve_map; 625cbbcf340SKumar Gala 626c039e3a8SBenjamin Herrenschmidt DBG("Found old 32-bit reserve map\n"); 627c039e3a8SBenjamin Herrenschmidt 628cbbcf340SKumar Gala while (1) { 629dc0e643aSIan Munsie base_32 = be32_to_cpup(reserve_map_32++); 630dc0e643aSIan Munsie size_32 = be32_to_cpup(reserve_map_32++); 631cbbcf340SKumar Gala if (size_32 == 0) 632cbbcf340SKumar Gala break; 633329dda08SKumar Gala DBG("reserving: %x -> %x\n", base_32, size_32); 63495f72d1eSYinghai Lu memblock_reserve(base_32, size_32); 635cbbcf340SKumar Gala } 636cbbcf340SKumar Gala return; 637cbbcf340SKumar Gala } 638cbbcf340SKumar Gala #endif 6399b6b563cSPaul Mackerras } 6409b6b563cSPaul Mackerras 6419b6b563cSPaul Mackerras void __init early_init_devtree(void *params) 6429b6b563cSPaul Mackerras { 64349a84965SBecky Bruce phys_addr_t limit; 6446ca4f749SHollis Blanchard 64544348105SGeoff Levand DBG(" -> early_init_devtree(%p)\n", params); 6469b6b563cSPaul Mackerras 647ad72a279SMichael Ellerman /* Too early to BUG_ON(), do it by hand */ 648ad72a279SMichael Ellerman if (!early_init_dt_verify(params)) 649ad72a279SMichael Ellerman panic("BUG: Failed verifying flat device tree, bad version?"); 650ad72a279SMichael Ellerman 651458148c0SMichael Ellerman #ifdef CONFIG_PPC_RTAS 652458148c0SMichael Ellerman /* Some machines might need RTAS info for debugging, grab it now. */ 653458148c0SMichael Ellerman of_scan_flat_dt(early_init_dt_scan_rtas, NULL); 654458148c0SMichael Ellerman #endif 655458148c0SMichael Ellerman 65614a43e69SBenjamin Herrenschmidt #ifdef CONFIG_PPC_POWERNV 65714a43e69SBenjamin Herrenschmidt /* Some machines might need OPAL info for debugging, grab it now. */ 65814a43e69SBenjamin Herrenschmidt of_scan_flat_dt(early_init_dt_scan_opal, NULL); 65914a43e69SBenjamin Herrenschmidt #endif 66014a43e69SBenjamin Herrenschmidt 661eb39c880SMahesh Salgaonkar #ifdef CONFIG_FA_DUMP 662eb39c880SMahesh Salgaonkar /* scan tree to see if dump is active during last boot */ 663eb39c880SMahesh Salgaonkar of_scan_flat_dt(early_init_dt_scan_fw_dump, NULL); 664eb39c880SMahesh Salgaonkar #endif 665eb39c880SMahesh Salgaonkar 6669b6b563cSPaul Mackerras /* Retrieve various informations from the /chosen node of the 6679b6b563cSPaul Mackerras * device-tree, including the platform type, initrd location and 6689b6b563cSPaul Mackerras * size, TCE reserve, and more ... 6699b6b563cSPaul Mackerras */ 6703e47d147SAnton Blanchard of_scan_flat_dt(early_init_dt_scan_chosen_ppc, boot_command_line); 6719b6b563cSPaul Mackerras 67295f72d1eSYinghai Lu /* Scan memory nodes and rebuild MEMBLOCKs */ 6733c726f8dSBenjamin Herrenschmidt of_scan_flat_dt(early_init_dt_scan_root, NULL); 67451975db0SGrant Likely of_scan_flat_dt(early_init_dt_scan_memory_ppc, NULL); 675846f77b0SMichael Ellerman 676846f77b0SMichael Ellerman parse_early_param(); 677846f77b0SMichael Ellerman 678ba14f649SKumar Gala /* make sure we've parsed cmdline for mem= before this */ 679ba14f649SKumar Gala if (memory_limit) 680a84fcd46SSuzuki Poulose first_memblock_size = min_t(u64, first_memblock_size, memory_limit); 681ba14f649SKumar Gala setup_initial_memory_limit(memstart_addr, first_memblock_size); 68295f72d1eSYinghai Lu /* Reserve MEMBLOCK regions used by kernel, initrd, dt, etc... */ 68395f72d1eSYinghai Lu memblock_reserve(PHYSICAL_START, __pa(klimit) - PHYSICAL_START); 684549e8152SPaul Mackerras /* If relocatable, reserve first 32k for interrupt vectors etc. */ 685549e8152SPaul Mackerras if (PHYSICAL_START > MEMORY_START) 68695f72d1eSYinghai Lu memblock_reserve(MEMORY_START, 0x8000); 68747310413SMichael Ellerman reserve_kdump_trampoline(); 688eb39c880SMahesh Salgaonkar #ifdef CONFIG_FA_DUMP 689eb39c880SMahesh Salgaonkar /* 690eb39c880SMahesh Salgaonkar * If we fail to reserve memory for firmware-assisted dump then 691eb39c880SMahesh Salgaonkar * fallback to kexec based kdump. 692eb39c880SMahesh Salgaonkar */ 693eb39c880SMahesh Salgaonkar if (fadump_reserve_mem() == 0) 694eb39c880SMahesh Salgaonkar #endif 69535dd5432SMichael Ellerman reserve_crashkernel(); 6969b6b563cSPaul Mackerras early_reserve_mem(); 6979b6b563cSPaul Mackerras 69814ed7409SAnton Blanchard /* Ensure that total memory size is page-aligned. */ 6996fbef13cSTejun Heo limit = ALIGN(memory_limit ?: memblock_phys_mem_size(), PAGE_SIZE); 70095f72d1eSYinghai Lu memblock_enforce_memory_limit(limit); 7016ca4f749SHollis Blanchard 7021aadc056STejun Heo memblock_allow_resize(); 70395f72d1eSYinghai Lu memblock_dump_all(); 7042babf5c2SMichael Ellerman 70595f72d1eSYinghai Lu DBG("Phys. mem: %llx\n", memblock_phys_mem_size()); 7062babf5c2SMichael Ellerman 7072babf5c2SMichael Ellerman /* We may need to relocate the flat tree, do it now. 7082babf5c2SMichael Ellerman * FIXME .. and the initrd too? */ 7092babf5c2SMichael Ellerman move_device_tree(); 7102babf5c2SMichael Ellerman 7111426d5a3SMichael Ellerman allocate_pacas(); 7121426d5a3SMichael Ellerman 7139b6b563cSPaul Mackerras DBG("Scanning CPUs ...\n"); 7149b6b563cSPaul Mackerras 71525985edcSLucas De Marchi /* Retrieve CPU related informations from the flat tree 7163c726f8dSBenjamin Herrenschmidt * (altivec support, boot CPU ID, ...) 7179b6b563cSPaul Mackerras */ 7183c726f8dSBenjamin Herrenschmidt of_scan_flat_dt(early_init_dt_scan_cpus, NULL); 71936ae37e3SBenjamin Herrenschmidt if (boot_cpuid < 0) { 720d939be3aSMasanari Iida printk("Failed to identify boot CPU !\n"); 72136ae37e3SBenjamin Herrenschmidt BUG(); 72236ae37e3SBenjamin Herrenschmidt } 7239b6b563cSPaul Mackerras 7247ac87abbSMatt Evans #if defined(CONFIG_SMP) && defined(CONFIG_PPC64) 7257ac87abbSMatt Evans /* We'll later wait for secondaries to check in; there are 7267ac87abbSMatt Evans * NCPUS-1 non-boot CPUs :-) 7277ac87abbSMatt Evans */ 7287ac87abbSMatt Evans spinning_secondaries = boot_cpu_count - 1; 7297ac87abbSMatt Evans #endif 7307ac87abbSMatt Evans 73155672ecfSMahesh Salgaonkar #ifdef CONFIG_PPC_POWERNV 73255672ecfSMahesh Salgaonkar /* Scan and build the list of machine check recoverable ranges */ 73355672ecfSMahesh Salgaonkar of_scan_flat_dt(early_init_dt_scan_recoverable_ranges, NULL); 73455672ecfSMahesh Salgaonkar #endif 73555672ecfSMahesh Salgaonkar 7369b6b563cSPaul Mackerras DBG(" <- early_init_devtree()\n"); 7379b6b563cSPaul Mackerras } 7389b6b563cSPaul Mackerras 739b27652ddSKevin Hao #ifdef CONFIG_RELOCATABLE 740b27652ddSKevin Hao /* 741b27652ddSKevin Hao * This function run before early_init_devtree, so we have to init 742b27652ddSKevin Hao * initial_boot_params. 743b27652ddSKevin Hao */ 744b27652ddSKevin Hao void __init early_get_first_memblock_info(void *params, phys_addr_t *size) 745b27652ddSKevin Hao { 746b27652ddSKevin Hao /* Setup flat device-tree pointer */ 747b27652ddSKevin Hao initial_boot_params = params; 748b27652ddSKevin Hao 749b27652ddSKevin Hao /* 750b27652ddSKevin Hao * Scan the memory nodes and set add_mem_to_memblock to 0 to avoid 751b27652ddSKevin Hao * mess the memblock. 752b27652ddSKevin Hao */ 753b27652ddSKevin Hao add_mem_to_memblock = 0; 754b27652ddSKevin Hao of_scan_flat_dt(early_init_dt_scan_root, NULL); 755b27652ddSKevin Hao of_scan_flat_dt(early_init_dt_scan_memory_ppc, NULL); 756b27652ddSKevin Hao add_mem_to_memblock = 1; 757b27652ddSKevin Hao 758b27652ddSKevin Hao if (size) 759b27652ddSKevin Hao *size = first_memblock_size; 760b27652ddSKevin Hao } 761b27652ddSKevin Hao #endif 762b27652ddSKevin Hao 7639b6b563cSPaul Mackerras /******* 7649b6b563cSPaul Mackerras * 7659b6b563cSPaul Mackerras * New implementation of the OF "find" APIs, return a refcounted 7669b6b563cSPaul Mackerras * object, call of_node_put() when done. The device tree and list 7679b6b563cSPaul Mackerras * are protected by a rw_lock. 7689b6b563cSPaul Mackerras * 7699b6b563cSPaul Mackerras * Note that property management will need some locking as well, 7709b6b563cSPaul Mackerras * this isn't dealt with yet. 7719b6b563cSPaul Mackerras * 7729b6b563cSPaul Mackerras *******/ 7739b6b563cSPaul Mackerras 7749b6b563cSPaul Mackerras /** 775b37193b7SBenjamin Herrenschmidt * of_get_ibm_chip_id - Returns the IBM "chip-id" of a device 776b37193b7SBenjamin Herrenschmidt * @np: device node of the device 777b37193b7SBenjamin Herrenschmidt * 778b37193b7SBenjamin Herrenschmidt * This looks for a property "ibm,chip-id" in the node or any 779b37193b7SBenjamin Herrenschmidt * of its parents and returns its content, or -1 if it cannot 780b37193b7SBenjamin Herrenschmidt * be found. 781b37193b7SBenjamin Herrenschmidt */ 782b37193b7SBenjamin Herrenschmidt int of_get_ibm_chip_id(struct device_node *np) 783b37193b7SBenjamin Herrenschmidt { 784b37193b7SBenjamin Herrenschmidt of_node_get(np); 785b37193b7SBenjamin Herrenschmidt while(np) { 786b37193b7SBenjamin Herrenschmidt struct device_node *old = np; 787b37193b7SBenjamin Herrenschmidt const __be32 *prop; 788b37193b7SBenjamin Herrenschmidt 789b37193b7SBenjamin Herrenschmidt prop = of_get_property(np, "ibm,chip-id", NULL); 790b37193b7SBenjamin Herrenschmidt if (prop) { 791b37193b7SBenjamin Herrenschmidt of_node_put(np); 792b37193b7SBenjamin Herrenschmidt return be32_to_cpup(prop); 793b37193b7SBenjamin Herrenschmidt } 794b37193b7SBenjamin Herrenschmidt np = of_get_parent(np); 795b37193b7SBenjamin Herrenschmidt of_node_put(old); 796b37193b7SBenjamin Herrenschmidt } 797b37193b7SBenjamin Herrenschmidt return -1; 798b37193b7SBenjamin Herrenschmidt } 799b130e7c0SDan Streetman EXPORT_SYMBOL(of_get_ibm_chip_id); 800b37193b7SBenjamin Herrenschmidt 8013eb906c6SMichael Ellerman /** 8023eb906c6SMichael Ellerman * cpu_to_chip_id - Return the cpus chip-id 8033eb906c6SMichael Ellerman * @cpu: The logical cpu number. 8043eb906c6SMichael Ellerman * 8053eb906c6SMichael Ellerman * Return the value of the ibm,chip-id property corresponding to the given 8063eb906c6SMichael Ellerman * logical cpu number. If the chip-id can not be found, returns -1. 8073eb906c6SMichael Ellerman */ 8083eb906c6SMichael Ellerman int cpu_to_chip_id(int cpu) 8093eb906c6SMichael Ellerman { 8103eb906c6SMichael Ellerman struct device_node *np; 8113eb906c6SMichael Ellerman 8123eb906c6SMichael Ellerman np = of_get_cpu_node(cpu, NULL); 8133eb906c6SMichael Ellerman if (!np) 8143eb906c6SMichael Ellerman return -1; 8153eb906c6SMichael Ellerman 8163eb906c6SMichael Ellerman of_node_put(np); 8173eb906c6SMichael Ellerman return of_get_ibm_chip_id(np); 8183eb906c6SMichael Ellerman } 8193eb906c6SMichael Ellerman EXPORT_SYMBOL(cpu_to_chip_id); 8203eb906c6SMichael Ellerman 821819d5965SSudeep KarkadaNagesha bool arch_match_cpu_phys_id(int cpu, u64 phys_id) 822819d5965SSudeep KarkadaNagesha { 823819d5965SSudeep KarkadaNagesha return (int)phys_id == get_hard_smp_processor_id(cpu); 824819d5965SSudeep KarkadaNagesha } 825