12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 29b6b563cSPaul Mackerras /* 39b6b563cSPaul Mackerras * Procedures for creating, accessing and interpreting the device tree. 49b6b563cSPaul Mackerras * 59b6b563cSPaul Mackerras * Paul Mackerras August 1996. 69b6b563cSPaul Mackerras * Copyright (C) 1996-2005 Paul Mackerras. 79b6b563cSPaul Mackerras * 89b6b563cSPaul Mackerras * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner. 99b6b563cSPaul Mackerras * {engebret|bergner}@us.ibm.com 109b6b563cSPaul Mackerras */ 119b6b563cSPaul Mackerras 129b6b563cSPaul Mackerras #undef DEBUG 139b6b563cSPaul Mackerras 149b6b563cSPaul Mackerras #include <stdarg.h> 159b6b563cSPaul Mackerras #include <linux/kernel.h> 169b6b563cSPaul Mackerras #include <linux/string.h> 179b6b563cSPaul Mackerras #include <linux/init.h> 189b6b563cSPaul Mackerras #include <linux/threads.h> 199b6b563cSPaul Mackerras #include <linux/spinlock.h> 209b6b563cSPaul Mackerras #include <linux/types.h> 219b6b563cSPaul Mackerras #include <linux/pci.h> 229b6b563cSPaul Mackerras #include <linux/delay.h> 239b6b563cSPaul Mackerras #include <linux/initrd.h> 249b6b563cSPaul Mackerras #include <linux/bitops.h> 254b16f8e2SPaul Gortmaker #include <linux/export.h> 26dcee3036SMichael Ellerman #include <linux/kexec.h> 270ebfff14SBenjamin Herrenschmidt #include <linux/irq.h> 2895f72d1eSYinghai Lu #include <linux/memblock.h> 291cf3d8b3SNathan Fontenot #include <linux/of.h> 30708b7eefSMarek Szyprowski #include <linux/of_fdt.h> 31060f78c2SRob Herring #include <linux/libfdt.h> 327f92bc56SDaniel Axtens #include <linux/cpu.h> 339b6b563cSPaul Mackerras 349b6b563cSPaul Mackerras #include <asm/prom.h> 359b6b563cSPaul Mackerras #include <asm/rtas.h> 369b6b563cSPaul Mackerras #include <asm/page.h> 379b6b563cSPaul Mackerras #include <asm/processor.h> 389b6b563cSPaul Mackerras #include <asm/irq.h> 399b6b563cSPaul Mackerras #include <asm/io.h> 400cc4746cSMichael Ellerman #include <asm/kdump.h> 419b6b563cSPaul Mackerras #include <asm/smp.h> 429b6b563cSPaul Mackerras #include <asm/mmu.h> 431426d5a3SMichael Ellerman #include <asm/paca.h> 449b6b563cSPaul Mackerras #include <asm/pgtable.h> 4554820530SMichael Ellerman #include <asm/powernv.h> 469b6b563cSPaul Mackerras #include <asm/iommu.h> 479b6b563cSPaul Mackerras #include <asm/btext.h> 489b6b563cSPaul Mackerras #include <asm/sections.h> 499b6b563cSPaul Mackerras #include <asm/machdep.h> 5040ef8cbcSPaul Mackerras #include <asm/pci-bridge.h> 512babf5c2SMichael Ellerman #include <asm/kexec.h> 5214a43e69SBenjamin Herrenschmidt #include <asm/opal.h> 53eb39c880SMahesh Salgaonkar #include <asm/fadump.h> 54da6a97bfSBenjamin Herrenschmidt #include <asm/epapr_hcalls.h> 553808a889SBenjamin Herrenschmidt #include <asm/firmware.h> 565a61ef74SNicholas Piggin #include <asm/dt_cpu_ftrs.h> 576c6ea537SNathan Fontenot #include <asm/drmem.h> 58*bb04ffe8SClaudio Carvalho #include <asm/ultravisor.h> 5914a43e69SBenjamin Herrenschmidt 6037dd2badSKumar Gala #include <mm/mmu_decl.h> 619b6b563cSPaul Mackerras 629b6b563cSPaul Mackerras #ifdef DEBUG 639b6b563cSPaul Mackerras #define DBG(fmt...) printk(KERN_ERR fmt) 649b6b563cSPaul Mackerras #else 659b6b563cSPaul Mackerras #define DBG(fmt...) 669b6b563cSPaul Mackerras #endif 679b6b563cSPaul Mackerras 689b6b563cSPaul Mackerras #ifdef CONFIG_PPC64 6928897731SOlof Johansson int __initdata iommu_is_off; 709b6b563cSPaul Mackerras int __initdata iommu_force_on; 71cf00a8d1SPaul Mackerras unsigned long tce_alloc_start, tce_alloc_end; 72cd3db0c4SBenjamin Herrenschmidt u64 ppc64_rma_size; 739b6b563cSPaul Mackerras #endif 7403bf469aSBenjamin Herrenschmidt static phys_addr_t first_memblock_size; 757ac87abbSMatt Evans static int __initdata boot_cpu_count; 769b6b563cSPaul Mackerras 772babf5c2SMichael Ellerman static int __init early_parse_mem(char *p) 782babf5c2SMichael Ellerman { 792babf5c2SMichael Ellerman if (!p) 802babf5c2SMichael Ellerman return 1; 812babf5c2SMichael Ellerman 822babf5c2SMichael Ellerman memory_limit = PAGE_ALIGN(memparse(p, &p)); 83a84fcd46SSuzuki Poulose DBG("memory limit = 0x%llx\n", memory_limit); 842babf5c2SMichael Ellerman 852babf5c2SMichael Ellerman return 0; 862babf5c2SMichael Ellerman } 872babf5c2SMichael Ellerman early_param("mem", early_parse_mem); 882babf5c2SMichael Ellerman 89307cfe71SBenjamin Herrenschmidt /* 90307cfe71SBenjamin Herrenschmidt * overlaps_initrd - check for overlap with page aligned extension of 91307cfe71SBenjamin Herrenschmidt * initrd. 92307cfe71SBenjamin Herrenschmidt */ 93307cfe71SBenjamin Herrenschmidt static inline int overlaps_initrd(unsigned long start, unsigned long size) 94307cfe71SBenjamin Herrenschmidt { 95307cfe71SBenjamin Herrenschmidt #ifdef CONFIG_BLK_DEV_INITRD 96307cfe71SBenjamin Herrenschmidt if (!initrd_start) 97307cfe71SBenjamin Herrenschmidt return 0; 98307cfe71SBenjamin Herrenschmidt 99307cfe71SBenjamin Herrenschmidt return (start + size) > _ALIGN_DOWN(initrd_start, PAGE_SIZE) && 100307cfe71SBenjamin Herrenschmidt start <= _ALIGN_UP(initrd_end, PAGE_SIZE); 101307cfe71SBenjamin Herrenschmidt #else 102307cfe71SBenjamin Herrenschmidt return 0; 103307cfe71SBenjamin Herrenschmidt #endif 104307cfe71SBenjamin Herrenschmidt } 105307cfe71SBenjamin Herrenschmidt 1063c607ce2SLinas Vepstas /** 1073c607ce2SLinas Vepstas * move_device_tree - move tree to an unused area, if needed. 1083c607ce2SLinas Vepstas * 1093c607ce2SLinas Vepstas * The device tree may be allocated beyond our memory limit, or inside the 110307cfe71SBenjamin Herrenschmidt * crash kernel region for kdump, or within the page aligned range of initrd. 111307cfe71SBenjamin Herrenschmidt * If so, move it out of the way. 1122babf5c2SMichael Ellerman */ 11318f032cbSGeert Uytterhoeven static void __init move_device_tree(void) 1142babf5c2SMichael Ellerman { 1152babf5c2SMichael Ellerman unsigned long start, size; 1162babf5c2SMichael Ellerman void *p; 1172babf5c2SMichael Ellerman 1182babf5c2SMichael Ellerman DBG("-> move_device_tree\n"); 1192babf5c2SMichael Ellerman 1202babf5c2SMichael Ellerman start = __pa(initial_boot_params); 121060f78c2SRob Herring size = fdt_totalsize(initial_boot_params); 1222babf5c2SMichael Ellerman 1236dd22700SScott Wood if ((memory_limit && (start + size) > PHYSICAL_START + memory_limit) || 124f242e0acSChristophe Leroy !memblock_is_memory(start + size - 1) || 125f242e0acSChristophe Leroy overlaps_crashkernel(start, size) || overlaps_initrd(start, size)) { 1261269f7b8SChristophe Leroy p = memblock_alloc_raw(size, PAGE_SIZE); 1271269f7b8SChristophe Leroy if (!p) 1281269f7b8SChristophe Leroy panic("Failed to allocate %lu bytes to move device tree\n", 1291269f7b8SChristophe Leroy size); 1302babf5c2SMichael Ellerman memcpy(p, initial_boot_params, size); 131060f78c2SRob Herring initial_boot_params = p; 132b18f0ae9SChristophe Leroy DBG("Moved device tree to 0x%px\n", p); 1332babf5c2SMichael Ellerman } 1342babf5c2SMichael Ellerman 1352babf5c2SMichael Ellerman DBG("<- move_device_tree\n"); 1362babf5c2SMichael Ellerman } 1379b6b563cSPaul Mackerras 138d205819eSPaul Mackerras /* 139d205819eSPaul Mackerras * ibm,pa-features is a per-cpu property that contains a string of 140d205819eSPaul Mackerras * attribute descriptors, each of which has a 2 byte header plus up 141d205819eSPaul Mackerras * to 254 bytes worth of processor attribute bits. First header 142d205819eSPaul Mackerras * byte specifies the number of bytes following the header. 143d205819eSPaul Mackerras * Second header byte is an "attribute-specifier" type, of which 144d205819eSPaul Mackerras * zero is the only currently-defined value. 145d205819eSPaul Mackerras * Implementation: Pass in the byte and bit offset for the feature 146d205819eSPaul Mackerras * that we are interested in. The function will return -1 if the 147d205819eSPaul Mackerras * pa-features property is missing, or a 1/0 to indicate if the feature 148d205819eSPaul Mackerras * is supported/not supported. Note that the bit numbers are 149d205819eSPaul Mackerras * big-endian to match the definition in PAPR. 150d205819eSPaul Mackerras */ 151d205819eSPaul Mackerras static struct ibm_pa_feature { 152d205819eSPaul Mackerras unsigned long cpu_features; /* CPU_FTR_xxx bit */ 15344ae3ab3SMatt Evans unsigned long mmu_features; /* MMU_FTR_xxx bit */ 154d205819eSPaul Mackerras unsigned int cpu_user_ftrs; /* PPC_FEATURE_xxx bit */ 155beff8237SAnton Blanchard unsigned int cpu_user_ftrs2; /* PPC_FEATURE2_xxx bit */ 156d205819eSPaul Mackerras unsigned char pabyte; /* byte number in ibm,pa-features */ 157d205819eSPaul Mackerras unsigned char pabit; /* bit number (big-endian) */ 158d205819eSPaul Mackerras unsigned char invert; /* if 1, pa bit set => clear feature */ 159d205819eSPaul Mackerras } ibm_pa_features[] __initdata = { 160e9eb0278SMichael Ellerman { .pabyte = 0, .pabit = 0, .cpu_user_ftrs = PPC_FEATURE_HAS_MMU }, 161e9eb0278SMichael Ellerman { .pabyte = 0, .pabit = 1, .cpu_user_ftrs = PPC_FEATURE_HAS_FPU }, 162e9eb0278SMichael Ellerman { .pabyte = 0, .pabit = 3, .cpu_features = CPU_FTR_CTRL }, 163e9eb0278SMichael Ellerman { .pabyte = 0, .pabit = 6, .cpu_features = CPU_FTR_NOEXECUTE }, 164e9eb0278SMichael Ellerman { .pabyte = 1, .pabit = 2, .mmu_features = MMU_FTR_CI_LARGE_PAGE }, 165d957fb4dSMichael Neuling #ifdef CONFIG_PPC_RADIX_MMU 166e9eb0278SMichael Ellerman { .pabyte = 40, .pabit = 0, .mmu_features = MMU_FTR_TYPE_RADIX }, 167d957fb4dSMichael Neuling #endif 168e9eb0278SMichael Ellerman { .pabyte = 1, .pabit = 1, .invert = 1, .cpu_features = CPU_FTR_NODSISRALIGN }, 169e9eb0278SMichael Ellerman { .pabyte = 5, .pabit = 0, .cpu_features = CPU_FTR_REAL_LE, 170e9eb0278SMichael Ellerman .cpu_user_ftrs = PPC_FEATURE_TRUE_LE }, 1719e819963SAneesh Kumar K.V /* 1724705e024SAnton Blanchard * If the kernel doesn't support TM (ie CONFIG_PPC_TRANSACTIONAL_MEM=n), 1734705e024SAnton Blanchard * we don't want to turn on TM here, so we use the *_COMP versions 1744705e024SAnton Blanchard * which are 0 if the kernel doesn't support TM. 1759e819963SAneesh Kumar K.V */ 176e9eb0278SMichael Ellerman { .pabyte = 22, .pabit = 0, .cpu_features = CPU_FTR_TM_COMP, 177e9eb0278SMichael Ellerman .cpu_user_ftrs2 = PPC_FEATURE2_HTM_COMP | PPC_FEATURE2_HTM_NOSC_COMP }, 178d205819eSPaul Mackerras }; 179d205819eSPaul Mackerras 1809d0c4dfeSRob Herring static void __init scan_features(unsigned long node, const unsigned char *ftrs, 181974a76f5SPaul Mackerras unsigned long tablelen, 182974a76f5SPaul Mackerras struct ibm_pa_feature *fp, 183974a76f5SPaul Mackerras unsigned long ft_size) 184d205819eSPaul Mackerras { 185974a76f5SPaul Mackerras unsigned long i, len, bit; 186d205819eSPaul Mackerras 187d205819eSPaul Mackerras /* find descriptor with type == 0 */ 188d205819eSPaul Mackerras for (;;) { 189d205819eSPaul Mackerras if (tablelen < 3) 190d205819eSPaul Mackerras return; 191974a76f5SPaul Mackerras len = 2 + ftrs[0]; 192d205819eSPaul Mackerras if (tablelen < len) 193d205819eSPaul Mackerras return; /* descriptor 0 not found */ 194974a76f5SPaul Mackerras if (ftrs[1] == 0) 195d205819eSPaul Mackerras break; 196d205819eSPaul Mackerras tablelen -= len; 197974a76f5SPaul Mackerras ftrs += len; 198d205819eSPaul Mackerras } 199d205819eSPaul Mackerras 200d205819eSPaul Mackerras /* loop over bits we know about */ 201974a76f5SPaul Mackerras for (i = 0; i < ft_size; ++i, ++fp) { 202974a76f5SPaul Mackerras if (fp->pabyte >= ftrs[0]) 203d205819eSPaul Mackerras continue; 204974a76f5SPaul Mackerras bit = (ftrs[2 + fp->pabyte] >> (7 - fp->pabit)) & 1; 205d205819eSPaul Mackerras if (bit ^ fp->invert) { 206d205819eSPaul Mackerras cur_cpu_spec->cpu_features |= fp->cpu_features; 207d205819eSPaul Mackerras cur_cpu_spec->cpu_user_features |= fp->cpu_user_ftrs; 208beff8237SAnton Blanchard cur_cpu_spec->cpu_user_features2 |= fp->cpu_user_ftrs2; 20944ae3ab3SMatt Evans cur_cpu_spec->mmu_features |= fp->mmu_features; 210d205819eSPaul Mackerras } else { 211d205819eSPaul Mackerras cur_cpu_spec->cpu_features &= ~fp->cpu_features; 212d205819eSPaul Mackerras cur_cpu_spec->cpu_user_features &= ~fp->cpu_user_ftrs; 213beff8237SAnton Blanchard cur_cpu_spec->cpu_user_features2 &= ~fp->cpu_user_ftrs2; 21444ae3ab3SMatt Evans cur_cpu_spec->mmu_features &= ~fp->mmu_features; 215d205819eSPaul Mackerras } 216d205819eSPaul Mackerras } 217d205819eSPaul Mackerras } 218d205819eSPaul Mackerras 219974a76f5SPaul Mackerras static void __init check_cpu_pa_features(unsigned long node) 220974a76f5SPaul Mackerras { 2219d0c4dfeSRob Herring const unsigned char *pa_ftrs; 2229d0c4dfeSRob Herring int tablelen; 223974a76f5SPaul Mackerras 224974a76f5SPaul Mackerras pa_ftrs = of_get_flat_dt_prop(node, "ibm,pa-features", &tablelen); 225974a76f5SPaul Mackerras if (pa_ftrs == NULL) 226974a76f5SPaul Mackerras return; 227974a76f5SPaul Mackerras 228974a76f5SPaul Mackerras scan_features(node, pa_ftrs, tablelen, 229974a76f5SPaul Mackerras ibm_pa_features, ARRAY_SIZE(ibm_pa_features)); 230974a76f5SPaul Mackerras } 231974a76f5SPaul Mackerras 2324e003747SMichael Ellerman #ifdef CONFIG_PPC_BOOK3S_64 2339c61f7a0SAnshuman Khandual static void __init init_mmu_slb_size(unsigned long node) 234584f8b71SMichael Neuling { 2359d0c4dfeSRob Herring const __be32 *slb_size_ptr; 236584f8b71SMichael Neuling 2379c61f7a0SAnshuman Khandual slb_size_ptr = of_get_flat_dt_prop(node, "slb-size", NULL) ? : 2389c61f7a0SAnshuman Khandual of_get_flat_dt_prop(node, "ibm,slb-size", NULL); 2399c61f7a0SAnshuman Khandual 2409c61f7a0SAnshuman Khandual if (slb_size_ptr) 241dc0e643aSIan Munsie mmu_slb_size = be32_to_cpup(slb_size_ptr); 242584f8b71SMichael Neuling } 243584f8b71SMichael Neuling #else 2449c61f7a0SAnshuman Khandual #define init_mmu_slb_size(node) do { } while(0) 245584f8b71SMichael Neuling #endif 246584f8b71SMichael Neuling 247974a76f5SPaul Mackerras static struct feature_property { 248974a76f5SPaul Mackerras const char *name; 249974a76f5SPaul Mackerras u32 min_value; 250974a76f5SPaul Mackerras unsigned long cpu_feature; 251974a76f5SPaul Mackerras unsigned long cpu_user_ftr; 252974a76f5SPaul Mackerras } feature_properties[] __initdata = { 253974a76f5SPaul Mackerras #ifdef CONFIG_ALTIVEC 254974a76f5SPaul Mackerras {"altivec", 0, CPU_FTR_ALTIVEC, PPC_FEATURE_HAS_ALTIVEC}, 255974a76f5SPaul Mackerras {"ibm,vmx", 1, CPU_FTR_ALTIVEC, PPC_FEATURE_HAS_ALTIVEC}, 256974a76f5SPaul Mackerras #endif /* CONFIG_ALTIVEC */ 257b962ce9dSMichael Neuling #ifdef CONFIG_VSX 258b962ce9dSMichael Neuling /* Yes, this _really_ is ibm,vmx == 2 to enable VSX */ 259b962ce9dSMichael Neuling {"ibm,vmx", 2, CPU_FTR_VSX, PPC_FEATURE_HAS_VSX}, 260b962ce9dSMichael Neuling #endif /* CONFIG_VSX */ 261974a76f5SPaul Mackerras #ifdef CONFIG_PPC64 262974a76f5SPaul Mackerras {"ibm,dfp", 1, 0, PPC_FEATURE_HAS_DFP}, 263974a76f5SPaul Mackerras {"ibm,purr", 1, CPU_FTR_PURR, 0}, 264974a76f5SPaul Mackerras {"ibm,spurr", 1, CPU_FTR_SPURR, 0}, 265974a76f5SPaul Mackerras #endif /* CONFIG_PPC64 */ 266974a76f5SPaul Mackerras }; 267974a76f5SPaul Mackerras 26814b3d926SValentine Barshak #if defined(CONFIG_44x) && defined(CONFIG_PPC_FPU) 26914b3d926SValentine Barshak static inline void identical_pvr_fixup(unsigned long node) 27014b3d926SValentine Barshak { 27114b3d926SValentine Barshak unsigned int pvr; 2729d0c4dfeSRob Herring const char *model = of_get_flat_dt_prop(node, "model", NULL); 27314b3d926SValentine Barshak 27414b3d926SValentine Barshak /* 27514b3d926SValentine Barshak * Since 440GR(x)/440EP(x) processors have the same pvr, 27614b3d926SValentine Barshak * we check the node path and set bit 28 in the cur_cpu_spec 27714b3d926SValentine Barshak * pvr for EP(x) processor version. This bit is always 0 in 27814b3d926SValentine Barshak * the "real" pvr. Then we call identify_cpu again with 27914b3d926SValentine Barshak * the new logical pvr to enable FPU support. 28014b3d926SValentine Barshak */ 28114b3d926SValentine Barshak if (model && strstr(model, "440EP")) { 28214b3d926SValentine Barshak pvr = cur_cpu_spec->pvr_value | 0x8; 28314b3d926SValentine Barshak identify_cpu(0, pvr); 28414b3d926SValentine Barshak DBG("Using logical pvr %x for %s\n", pvr, model); 28514b3d926SValentine Barshak } 28614b3d926SValentine Barshak } 28714b3d926SValentine Barshak #else 28814b3d926SValentine Barshak #define identical_pvr_fixup(node) do { } while(0) 28914b3d926SValentine Barshak #endif 29014b3d926SValentine Barshak 291974a76f5SPaul Mackerras static void __init check_cpu_feature_properties(unsigned long node) 292974a76f5SPaul Mackerras { 2934f1f40f7SMathieu Malaterre int i; 294974a76f5SPaul Mackerras struct feature_property *fp = feature_properties; 295dc0e643aSIan Munsie const __be32 *prop; 296974a76f5SPaul Mackerras 2974f1f40f7SMathieu Malaterre for (i = 0; i < (int)ARRAY_SIZE(feature_properties); ++i, ++fp) { 298974a76f5SPaul Mackerras prop = of_get_flat_dt_prop(node, fp->name, NULL); 299dc0e643aSIan Munsie if (prop && be32_to_cpup(prop) >= fp->min_value) { 300974a76f5SPaul Mackerras cur_cpu_spec->cpu_features |= fp->cpu_feature; 301974a76f5SPaul Mackerras cur_cpu_spec->cpu_user_features |= fp->cpu_user_ftr; 302974a76f5SPaul Mackerras } 303974a76f5SPaul Mackerras } 304974a76f5SPaul Mackerras } 305974a76f5SPaul Mackerras 3069b6b563cSPaul Mackerras static int __init early_init_dt_scan_cpus(unsigned long node, 3074df20460SAnton Blanchard const char *uname, int depth, 3084df20460SAnton Blanchard void *data) 3099b6b563cSPaul Mackerras { 3109d0c4dfeSRob Herring const char *type = of_get_flat_dt_prop(node, "device_type", NULL); 311dc0e643aSIan Munsie const __be32 *prop; 312dc0e643aSIan Munsie const __be32 *intserv; 3134df20460SAnton Blanchard int i, nthreads; 3149d0c4dfeSRob Herring int len; 3159d07bc84SBenjamin Herrenschmidt int found = -1; 316208b3a4cSBenjamin Herrenschmidt int found_thread = 0; 3179b6b563cSPaul Mackerras 3189b6b563cSPaul Mackerras /* We are scanning "cpu" nodes only */ 3199b6b563cSPaul Mackerras if (type == NULL || strcmp(type, "cpu") != 0) 3209b6b563cSPaul Mackerras return 0; 3219b6b563cSPaul Mackerras 3224df20460SAnton Blanchard /* Get physical cpuid */ 3234df20460SAnton Blanchard intserv = of_get_flat_dt_prop(node, "ibm,ppc-interrupt-server#s", &len); 324e16c8765SAndy Fleming if (!intserv) 325e16c8765SAndy Fleming intserv = of_get_flat_dt_prop(node, "reg", &len); 326e16c8765SAndy Fleming 3274df20460SAnton Blanchard nthreads = len / sizeof(int); 3284df20460SAnton Blanchard 3294df20460SAnton Blanchard /* 3304df20460SAnton Blanchard * Now see if any of these threads match our boot cpu. 3314df20460SAnton Blanchard * NOTE: This must match the parsing done in smp_setup_cpu_maps. 3324df20460SAnton Blanchard */ 3334df20460SAnton Blanchard for (i = 0; i < nthreads; i++) { 334dc0e643aSIan Munsie if (be32_to_cpu(intserv[i]) == 335060f78c2SRob Herring fdt_boot_cpuid_phys(initial_boot_params)) { 3369d07bc84SBenjamin Herrenschmidt found = boot_cpu_count; 337208b3a4cSBenjamin Herrenschmidt found_thread = i; 338208b3a4cSBenjamin Herrenschmidt } 3394df20460SAnton Blanchard #ifdef CONFIG_SMP 3404df20460SAnton Blanchard /* logical cpu id is always 0 on UP kernels */ 3419d07bc84SBenjamin Herrenschmidt boot_cpu_count++; 3424df20460SAnton Blanchard #endif 3434df20460SAnton Blanchard } 3444df20460SAnton Blanchard 3457222f779SBenjamin Herrenschmidt /* Not the boot CPU */ 3467222f779SBenjamin Herrenschmidt if (found < 0) 3477222f779SBenjamin Herrenschmidt return 0; 3487222f779SBenjamin Herrenschmidt 3499d07bc84SBenjamin Herrenschmidt DBG("boot cpu: logical %d physical %d\n", found, 350dc0e643aSIan Munsie be32_to_cpu(intserv[found_thread])); 3519d07bc84SBenjamin Herrenschmidt boot_cpuid = found; 352974a76f5SPaul Mackerras 353974a76f5SPaul Mackerras /* 354974a76f5SPaul Mackerras * PAPR defines "logical" PVR values for cpus that 355974a76f5SPaul Mackerras * meet various levels of the architecture: 356974a76f5SPaul Mackerras * 0x0f000001 Architecture version 2.04 357974a76f5SPaul Mackerras * 0x0f000002 Architecture version 2.05 358974a76f5SPaul Mackerras * If the cpu-version property in the cpu node contains 359974a76f5SPaul Mackerras * such a value, we call identify_cpu again with the 360974a76f5SPaul Mackerras * logical PVR value in order to use the cpu feature 361974a76f5SPaul Mackerras * bits appropriate for the architecture level. 362974a76f5SPaul Mackerras * 363974a76f5SPaul Mackerras * A POWER6 partition in "POWER6 architected" mode 364974a76f5SPaul Mackerras * uses the 0x0f000002 PVR value; in POWER5+ mode 365974a76f5SPaul Mackerras * it uses 0x0f000001. 3665a61ef74SNicholas Piggin * 3675a61ef74SNicholas Piggin * If we're using device tree CPU feature discovery then we don't 3685a61ef74SNicholas Piggin * support the cpu-version property, and it's the responsibility of the 3695a61ef74SNicholas Piggin * firmware/hypervisor to provide the correct feature set for the 3705a61ef74SNicholas Piggin * architecture level via the ibm,powerpc-cpu-features binding. 371974a76f5SPaul Mackerras */ 3725a61ef74SNicholas Piggin if (!dt_cpu_ftrs_in_use()) { 373974a76f5SPaul Mackerras prop = of_get_flat_dt_prop(node, "cpu-version", NULL); 374dc0e643aSIan Munsie if (prop && (be32_to_cpup(prop) & 0xff000000) == 0x0f000000) 375dc0e643aSIan Munsie identify_cpu(0, be32_to_cpup(prop)); 37614b3d926SValentine Barshak 377974a76f5SPaul Mackerras check_cpu_feature_properties(node); 378d205819eSPaul Mackerras check_cpu_pa_features(node); 3795a61ef74SNicholas Piggin } 3805a61ef74SNicholas Piggin 3815a61ef74SNicholas Piggin identical_pvr_fixup(node); 3829c61f7a0SAnshuman Khandual init_mmu_slb_size(node); 383d205819eSPaul Mackerras 3844a85b31dSBenjamin Herrenschmidt #ifdef CONFIG_PPC64 3855a61ef74SNicholas Piggin if (nthreads == 1) 3864df20460SAnton Blanchard cur_cpu_spec->cpu_features &= ~CPU_FTR_SMT; 3875a61ef74SNicholas Piggin else if (!dt_cpu_ftrs_in_use()) 3885a61ef74SNicholas Piggin cur_cpu_spec->cpu_features |= CPU_FTR_SMT; 38959f57774SNicholas Piggin allocate_paca(boot_cpuid); 3909b6b563cSPaul Mackerras #endif 39159f57774SNicholas Piggin set_hard_smp_processor_id(found, be32_to_cpu(intserv[found_thread])); 3925a61ef74SNicholas Piggin 3939b6b563cSPaul Mackerras return 0; 3949b6b563cSPaul Mackerras } 3959b6b563cSPaul Mackerras 396e51df2c1SAnton Blanchard static int __init early_init_dt_scan_chosen_ppc(unsigned long node, 397e51df2c1SAnton Blanchard const char *uname, 39832c97689SGrant Likely int depth, void *data) 3999b6b563cSPaul Mackerras { 4009d0c4dfeSRob Herring const unsigned long *lprop; /* All these set by kernel, so no need to convert endian */ 4019b6b563cSPaul Mackerras 40232c97689SGrant Likely /* Use common scan routine to determine if this is the chosen node */ 40332c97689SGrant Likely if (early_init_dt_scan_chosen(node, uname, depth, data) == 0) 40432c97689SGrant Likely return 0; 40532c97689SGrant Likely 4069b6b563cSPaul Mackerras #ifdef CONFIG_PPC64 4079b6b563cSPaul Mackerras /* check if iommu is forced on or off */ 4083c726f8dSBenjamin Herrenschmidt if (of_get_flat_dt_prop(node, "linux,iommu-off", NULL) != NULL) 4099b6b563cSPaul Mackerras iommu_is_off = 1; 4103c726f8dSBenjamin Herrenschmidt if (of_get_flat_dt_prop(node, "linux,iommu-force-on", NULL) != NULL) 4119b6b563cSPaul Mackerras iommu_force_on = 1; 4129b6b563cSPaul Mackerras #endif 4139b6b563cSPaul Mackerras 4142babf5c2SMichael Ellerman /* mem=x on the command line is the preferred mechanism */ 4153c726f8dSBenjamin Herrenschmidt lprop = of_get_flat_dt_prop(node, "linux,memory-limit", NULL); 4169b6b563cSPaul Mackerras if (lprop) 4179b6b563cSPaul Mackerras memory_limit = *lprop; 4189b6b563cSPaul Mackerras 4199b6b563cSPaul Mackerras #ifdef CONFIG_PPC64 4203c726f8dSBenjamin Herrenschmidt lprop = of_get_flat_dt_prop(node, "linux,tce-alloc-start", NULL); 4219b6b563cSPaul Mackerras if (lprop) 4229b6b563cSPaul Mackerras tce_alloc_start = *lprop; 4233c726f8dSBenjamin Herrenschmidt lprop = of_get_flat_dt_prop(node, "linux,tce-alloc-end", NULL); 4249b6b563cSPaul Mackerras if (lprop) 4259b6b563cSPaul Mackerras tce_alloc_end = *lprop; 4269b6b563cSPaul Mackerras #endif 4279b6b563cSPaul Mackerras 428da665885SThiago Jung Bauermann #ifdef CONFIG_KEXEC_CORE 42963277161SStephen Rothwell lprop = of_get_flat_dt_prop(node, "linux,crashkernel-base", NULL); 430dcee3036SMichael Ellerman if (lprop) 431dcee3036SMichael Ellerman crashk_res.start = *lprop; 432dcee3036SMichael Ellerman 43363277161SStephen Rothwell lprop = of_get_flat_dt_prop(node, "linux,crashkernel-size", NULL); 434dcee3036SMichael Ellerman if (lprop) 435dcee3036SMichael Ellerman crashk_res.end = crashk_res.start + *lprop - 1; 436dcee3036SMichael Ellerman #endif 43732c97689SGrant Likely 43832c97689SGrant Likely /* break now */ 43932c97689SGrant Likely return 1; 4409b6b563cSPaul Mackerras } 4419b6b563cSPaul Mackerras 4426aba0c84SAneesh Kumar K.V /* 4436aba0c84SAneesh Kumar K.V * Compare the range against max mem limit and update 4446aba0c84SAneesh Kumar K.V * size if it cross the limit. 4456aba0c84SAneesh Kumar K.V */ 4466aba0c84SAneesh Kumar K.V 4476aba0c84SAneesh Kumar K.V #ifdef CONFIG_SPARSEMEM 4486aba0c84SAneesh Kumar K.V static bool validate_mem_limit(u64 base, u64 *size) 4496aba0c84SAneesh Kumar K.V { 4506aba0c84SAneesh Kumar K.V u64 max_mem = 1UL << (MAX_PHYSMEM_BITS); 4516aba0c84SAneesh Kumar K.V 4526aba0c84SAneesh Kumar K.V if (base >= max_mem) 4536aba0c84SAneesh Kumar K.V return false; 4546aba0c84SAneesh Kumar K.V if ((base + *size) > max_mem) 4556aba0c84SAneesh Kumar K.V *size = max_mem - base; 4566aba0c84SAneesh Kumar K.V return true; 4576aba0c84SAneesh Kumar K.V } 4586aba0c84SAneesh Kumar K.V #else 4596aba0c84SAneesh Kumar K.V static bool validate_mem_limit(u64 base, u64 *size) 4606aba0c84SAneesh Kumar K.V { 4616aba0c84SAneesh Kumar K.V return true; 4626aba0c84SAneesh Kumar K.V } 4636aba0c84SAneesh Kumar K.V #endif 4646aba0c84SAneesh Kumar K.V 4650204568aSPaul Mackerras #ifdef CONFIG_PPC_PSERIES 4660204568aSPaul Mackerras /* 4676c6ea537SNathan Fontenot * Interpret the ibm dynamic reconfiguration memory LMBs. 4680204568aSPaul Mackerras * This contains a list of memory blocks along with NUMA affinity 4690204568aSPaul Mackerras * information. 4700204568aSPaul Mackerras */ 4716c6ea537SNathan Fontenot static void __init early_init_drmem_lmb(struct drmem_lmb *lmb, 4726c6ea537SNathan Fontenot const __be32 **usm) 4730204568aSPaul Mackerras { 4746c6ea537SNathan Fontenot u64 base, size; 4756c6ea537SNathan Fontenot int is_kexec_kdump = 0, rngs; 4760204568aSPaul Mackerras 4776c6ea537SNathan Fontenot base = lmb->base_addr; 4786c6ea537SNathan Fontenot size = drmem_lmb_size(); 4796c6ea537SNathan Fontenot rngs = 1; 4800204568aSPaul Mackerras 4816c6ea537SNathan Fontenot /* 4826c6ea537SNathan Fontenot * Skip this block if the reserved bit is set in flags 4836c6ea537SNathan Fontenot * or if the block is not assigned to this partition. 4846c6ea537SNathan Fontenot */ 4856c6ea537SNathan Fontenot if ((lmb->flags & DRCONF_MEM_RESERVED) || 4866c6ea537SNathan Fontenot !(lmb->flags & DRCONF_MEM_ASSIGNED)) 4876c6ea537SNathan Fontenot return; 4880204568aSPaul Mackerras 4896c6ea537SNathan Fontenot if (*usm) 490cf00085dSChandru is_kexec_kdump = 1; 491cf00085dSChandru 492cf00085dSChandru if (is_kexec_kdump) { 493cf00085dSChandru /* 4946c6ea537SNathan Fontenot * For each memblock in ibm,dynamic-memory, a 4956c6ea537SNathan Fontenot * corresponding entry in linux,drconf-usable-memory 4966c6ea537SNathan Fontenot * property contains a counter 'p' followed by 'p' 4976c6ea537SNathan Fontenot * (base, size) duple. Now read the counter from 498cf00085dSChandru * linux,drconf-usable-memory property 499cf00085dSChandru */ 5006c6ea537SNathan Fontenot rngs = dt_mem_next_cell(dt_root_size_cells, usm); 501cf00085dSChandru if (!rngs) /* there are no (base, size) duple */ 5026c6ea537SNathan Fontenot return; 503cf00085dSChandru } 5046c6ea537SNathan Fontenot 505cf00085dSChandru do { 506cf00085dSChandru if (is_kexec_kdump) { 5076c6ea537SNathan Fontenot base = dt_mem_next_cell(dt_root_addr_cells, usm); 5086c6ea537SNathan Fontenot size = dt_mem_next_cell(dt_root_size_cells, usm); 509cf00085dSChandru } 5106c6ea537SNathan Fontenot 5110204568aSPaul Mackerras if (iommu_is_off) { 5120204568aSPaul Mackerras if (base >= 0x80000000ul) 5130204568aSPaul Mackerras continue; 5140204568aSPaul Mackerras if ((base + size) > 0x80000000ul) 5150204568aSPaul Mackerras size = 0x80000000ul - base; 5160204568aSPaul Mackerras } 5176c6ea537SNathan Fontenot 5186c6ea537SNathan Fontenot DBG("Adding: %llx -> %llx\n", base, size); 5196aba0c84SAneesh Kumar K.V if (validate_mem_limit(base, &size)) 52095f72d1eSYinghai Lu memblock_add(base, size); 521cf00085dSChandru } while (--rngs); 5220204568aSPaul Mackerras } 5230204568aSPaul Mackerras #endif /* CONFIG_PPC_PSERIES */ 5249b6b563cSPaul Mackerras 52551975db0SGrant Likely static int __init early_init_dt_scan_memory_ppc(unsigned long node, 52651975db0SGrant Likely const char *uname, 52751975db0SGrant Likely int depth, void *data) 5289b6b563cSPaul Mackerras { 5296c6ea537SNathan Fontenot #ifdef CONFIG_PPC_PSERIES 5300204568aSPaul Mackerras if (depth == 1 && 5316c6ea537SNathan Fontenot strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0) { 5326c6ea537SNathan Fontenot walk_drmem_lmbs_early(node, early_init_drmem_lmb); 5336c6ea537SNathan Fontenot return 0; 5346c6ea537SNathan Fontenot } 5356c6ea537SNathan Fontenot #endif 5360204568aSPaul Mackerras 53751975db0SGrant Likely return early_init_dt_scan_memory(node, uname, depth, data); 53851975db0SGrant Likely } 5399b6b563cSPaul Mackerras 540b27652ddSKevin Hao /* 541b27652ddSKevin Hao * For a relocatable kernel, we need to get the memstart_addr first, 542b27652ddSKevin Hao * then use it to calculate the virtual kernel start address. This has 543b27652ddSKevin Hao * to happen at a very early stage (before machine_init). In this case, 544b27652ddSKevin Hao * we just want to get the memstart_address and would not like to mess the 545b27652ddSKevin Hao * memblock at this stage. So introduce a variable to skip the memblock_add() 546b27652ddSKevin Hao * for this reason. 547b27652ddSKevin Hao */ 548b27652ddSKevin Hao #ifdef CONFIG_RELOCATABLE 549b27652ddSKevin Hao static int add_mem_to_memblock = 1; 550b27652ddSKevin Hao #else 551b27652ddSKevin Hao #define add_mem_to_memblock 1 552b27652ddSKevin Hao #endif 553b27652ddSKevin Hao 55451975db0SGrant Likely void __init early_init_dt_add_memory_arch(u64 base, u64 size) 55551975db0SGrant Likely { 556cd3db0c4SBenjamin Herrenschmidt #ifdef CONFIG_PPC64 5579b6b563cSPaul Mackerras if (iommu_is_off) { 5589b6b563cSPaul Mackerras if (base >= 0x80000000ul) 55951975db0SGrant Likely return; 5609b6b563cSPaul Mackerras if ((base + size) > 0x80000000ul) 5619b6b563cSPaul Mackerras size = 0x80000000ul - base; 5629b6b563cSPaul Mackerras } 5639b6b563cSPaul Mackerras #endif 56403bf469aSBenjamin Herrenschmidt /* Keep track of the beginning of memory -and- the size of 56503bf469aSBenjamin Herrenschmidt * the very first block in the device-tree as it represents 56603bf469aSBenjamin Herrenschmidt * the RMA on ppc64 server 56703bf469aSBenjamin Herrenschmidt */ 56803bf469aSBenjamin Herrenschmidt if (base < memstart_addr) { 56903bf469aSBenjamin Herrenschmidt memstart_addr = base; 57003bf469aSBenjamin Herrenschmidt first_memblock_size = size; 57103bf469aSBenjamin Herrenschmidt } 572cd3db0c4SBenjamin Herrenschmidt 573cd3db0c4SBenjamin Herrenschmidt /* Add the chunk to the MEMBLOCK list */ 5746aba0c84SAneesh Kumar K.V if (add_mem_to_memblock) { 5756aba0c84SAneesh Kumar K.V if (validate_mem_limit(base, &size)) 576cd3db0c4SBenjamin Herrenschmidt memblock_add(base, size); 5779b6b563cSPaul Mackerras } 5786aba0c84SAneesh Kumar K.V } 57937dd2badSKumar Gala 580c039e3a8SBenjamin Herrenschmidt static void __init early_reserve_mem_dt(void) 5810962e800SJeremy Kerr { 5829d0c4dfeSRob Herring unsigned long i, dt_root; 5839d0c4dfeSRob Herring int len; 5840962e800SJeremy Kerr const __be32 *prop; 5850962e800SJeremy Kerr 58624bbd929SArd Biesheuvel early_init_fdt_reserve_self(); 587edba274cSRob Herring early_init_fdt_scan_reserved_mem(); 588edba274cSRob Herring 5890962e800SJeremy Kerr dt_root = of_get_flat_dt_root(); 5900962e800SJeremy Kerr 5910962e800SJeremy Kerr prop = of_get_flat_dt_prop(dt_root, "reserved-ranges", &len); 5920962e800SJeremy Kerr 5930962e800SJeremy Kerr if (!prop) 594c039e3a8SBenjamin Herrenschmidt return; 595c039e3a8SBenjamin Herrenschmidt 596c039e3a8SBenjamin Herrenschmidt DBG("Found new-style reserved-ranges\n"); 5970962e800SJeremy Kerr 5980962e800SJeremy Kerr /* Each reserved range is an (address,size) pair, 2 cells each, 5990962e800SJeremy Kerr * totalling 4 cells per range. */ 6000962e800SJeremy Kerr for (i = 0; i < len / (sizeof(*prop) * 4); i++) { 6010962e800SJeremy Kerr u64 base, size; 6020962e800SJeremy Kerr 6030962e800SJeremy Kerr base = of_read_number(prop + (i * 4) + 0, 2); 6040962e800SJeremy Kerr size = of_read_number(prop + (i * 4) + 2, 2); 6050962e800SJeremy Kerr 606c039e3a8SBenjamin Herrenschmidt if (size) { 607c039e3a8SBenjamin Herrenschmidt DBG("reserving: %llx -> %llx\n", base, size); 6080962e800SJeremy Kerr memblock_reserve(base, size); 6090962e800SJeremy Kerr } 610c039e3a8SBenjamin Herrenschmidt } 6110962e800SJeremy Kerr } 6120962e800SJeremy Kerr 6139b6b563cSPaul Mackerras static void __init early_reserve_mem(void) 6149b6b563cSPaul Mackerras { 615dc0e643aSIan Munsie __be64 *reserve_map; 6169b6b563cSPaul Mackerras 617dc0e643aSIan Munsie reserve_map = (__be64 *)(((unsigned long)initial_boot_params) + 618060f78c2SRob Herring fdt_off_mem_rsvmap(initial_boot_params)); 6194d1f3f25SJimi Xenidis 620c039e3a8SBenjamin Herrenschmidt /* Look for the new "reserved-regions" property in the DT */ 621c039e3a8SBenjamin Herrenschmidt early_reserve_mem_dt(); 6220962e800SJeremy Kerr 62330437b3eSDavid Gibson #ifdef CONFIG_BLK_DEV_INITRD 624c039e3a8SBenjamin Herrenschmidt /* Then reserve the initrd, if any */ 625c039e3a8SBenjamin Herrenschmidt if (initrd_start && (initrd_end > initrd_start)) { 626307cfe71SBenjamin Herrenschmidt memblock_reserve(_ALIGN_DOWN(__pa(initrd_start), PAGE_SIZE), 627307cfe71SBenjamin Herrenschmidt _ALIGN_UP(initrd_end, PAGE_SIZE) - 628307cfe71SBenjamin Herrenschmidt _ALIGN_DOWN(initrd_start, PAGE_SIZE)); 629c039e3a8SBenjamin Herrenschmidt } 63030437b3eSDavid Gibson #endif /* CONFIG_BLK_DEV_INITRD */ 63130437b3eSDavid Gibson 632cbbcf340SKumar Gala #ifdef CONFIG_PPC32 633cbbcf340SKumar Gala /* 634cbbcf340SKumar Gala * Handle the case where we might be booting from an old kexec 635cbbcf340SKumar Gala * image that setup the mem_rsvmap as pairs of 32-bit values 636cbbcf340SKumar Gala */ 637dc0e643aSIan Munsie if (be64_to_cpup(reserve_map) > 0xffffffffull) { 638cbbcf340SKumar Gala u32 base_32, size_32; 639dc0e643aSIan Munsie __be32 *reserve_map_32 = (__be32 *)reserve_map; 640cbbcf340SKumar Gala 641c039e3a8SBenjamin Herrenschmidt DBG("Found old 32-bit reserve map\n"); 642c039e3a8SBenjamin Herrenschmidt 643cbbcf340SKumar Gala while (1) { 644dc0e643aSIan Munsie base_32 = be32_to_cpup(reserve_map_32++); 645dc0e643aSIan Munsie size_32 = be32_to_cpup(reserve_map_32++); 646cbbcf340SKumar Gala if (size_32 == 0) 647cbbcf340SKumar Gala break; 648329dda08SKumar Gala DBG("reserving: %x -> %x\n", base_32, size_32); 64995f72d1eSYinghai Lu memblock_reserve(base_32, size_32); 650cbbcf340SKumar Gala } 651cbbcf340SKumar Gala return; 652cbbcf340SKumar Gala } 653cbbcf340SKumar Gala #endif 6549b6b563cSPaul Mackerras } 6559b6b563cSPaul Mackerras 65607fd1761SCyril Bur #ifdef CONFIG_PPC_TRANSACTIONAL_MEM 65707fd1761SCyril Bur static bool tm_disabled __initdata; 65807fd1761SCyril Bur 65907fd1761SCyril Bur static int __init parse_ppc_tm(char *str) 66007fd1761SCyril Bur { 66107fd1761SCyril Bur bool res; 66207fd1761SCyril Bur 66307fd1761SCyril Bur if (kstrtobool(str, &res)) 66407fd1761SCyril Bur return -EINVAL; 66507fd1761SCyril Bur 66607fd1761SCyril Bur tm_disabled = !res; 66707fd1761SCyril Bur 66807fd1761SCyril Bur return 0; 66907fd1761SCyril Bur } 67007fd1761SCyril Bur early_param("ppc_tm", parse_ppc_tm); 67107fd1761SCyril Bur 67207fd1761SCyril Bur static void __init tm_init(void) 67307fd1761SCyril Bur { 67407fd1761SCyril Bur if (tm_disabled) { 67507fd1761SCyril Bur pr_info("Disabling hardware transactional memory (HTM)\n"); 67607fd1761SCyril Bur cur_cpu_spec->cpu_user_features2 &= 67707fd1761SCyril Bur ~(PPC_FEATURE2_HTM_NOSC | PPC_FEATURE2_HTM); 67807fd1761SCyril Bur cur_cpu_spec->cpu_features &= ~CPU_FTR_TM; 67954820530SMichael Ellerman return; 68007fd1761SCyril Bur } 68154820530SMichael Ellerman 68254820530SMichael Ellerman pnv_tm_init(); 68307fd1761SCyril Bur } 68407fd1761SCyril Bur #else 68507fd1761SCyril Bur static void tm_init(void) { } 68607fd1761SCyril Bur #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */ 68707fd1761SCyril Bur 6889b6b563cSPaul Mackerras void __init early_init_devtree(void *params) 6899b6b563cSPaul Mackerras { 69049a84965SBecky Bruce phys_addr_t limit; 6916ca4f749SHollis Blanchard 692b18f0ae9SChristophe Leroy DBG(" -> early_init_devtree(%px)\n", params); 6939b6b563cSPaul Mackerras 694ad72a279SMichael Ellerman /* Too early to BUG_ON(), do it by hand */ 695ad72a279SMichael Ellerman if (!early_init_dt_verify(params)) 696ad72a279SMichael Ellerman panic("BUG: Failed verifying flat device tree, bad version?"); 697ad72a279SMichael Ellerman 698458148c0SMichael Ellerman #ifdef CONFIG_PPC_RTAS 699458148c0SMichael Ellerman /* Some machines might need RTAS info for debugging, grab it now. */ 700458148c0SMichael Ellerman of_scan_flat_dt(early_init_dt_scan_rtas, NULL); 701458148c0SMichael Ellerman #endif 702458148c0SMichael Ellerman 70314a43e69SBenjamin Herrenschmidt #ifdef CONFIG_PPC_POWERNV 70414a43e69SBenjamin Herrenschmidt /* Some machines might need OPAL info for debugging, grab it now. */ 70514a43e69SBenjamin Herrenschmidt of_scan_flat_dt(early_init_dt_scan_opal, NULL); 706*bb04ffe8SClaudio Carvalho 707*bb04ffe8SClaudio Carvalho /* Scan tree for ultravisor feature */ 708*bb04ffe8SClaudio Carvalho of_scan_flat_dt(early_init_dt_scan_ultravisor, NULL); 70914a43e69SBenjamin Herrenschmidt #endif 71014a43e69SBenjamin Herrenschmidt 711eb39c880SMahesh Salgaonkar #ifdef CONFIG_FA_DUMP 712eb39c880SMahesh Salgaonkar /* scan tree to see if dump is active during last boot */ 713eb39c880SMahesh Salgaonkar of_scan_flat_dt(early_init_dt_scan_fw_dump, NULL); 714eb39c880SMahesh Salgaonkar #endif 715eb39c880SMahesh Salgaonkar 7169b6b563cSPaul Mackerras /* Retrieve various informations from the /chosen node of the 7179b6b563cSPaul Mackerras * device-tree, including the platform type, initrd location and 7189b6b563cSPaul Mackerras * size, TCE reserve, and more ... 7199b6b563cSPaul Mackerras */ 7203e47d147SAnton Blanchard of_scan_flat_dt(early_init_dt_scan_chosen_ppc, boot_command_line); 7219b6b563cSPaul Mackerras 72295f72d1eSYinghai Lu /* Scan memory nodes and rebuild MEMBLOCKs */ 7233c726f8dSBenjamin Herrenschmidt of_scan_flat_dt(early_init_dt_scan_root, NULL); 72451975db0SGrant Likely of_scan_flat_dt(early_init_dt_scan_memory_ppc, NULL); 725846f77b0SMichael Ellerman 726846f77b0SMichael Ellerman parse_early_param(); 727846f77b0SMichael Ellerman 728ba14f649SKumar Gala /* make sure we've parsed cmdline for mem= before this */ 729ba14f649SKumar Gala if (memory_limit) 730a84fcd46SSuzuki Poulose first_memblock_size = min_t(u64, first_memblock_size, memory_limit); 731ba14f649SKumar Gala setup_initial_memory_limit(memstart_addr, first_memblock_size); 73295f72d1eSYinghai Lu /* Reserve MEMBLOCK regions used by kernel, initrd, dt, etc... */ 73395f72d1eSYinghai Lu memblock_reserve(PHYSICAL_START, __pa(klimit) - PHYSICAL_START); 734549e8152SPaul Mackerras /* If relocatable, reserve first 32k for interrupt vectors etc. */ 735549e8152SPaul Mackerras if (PHYSICAL_START > MEMORY_START) 73695f72d1eSYinghai Lu memblock_reserve(MEMORY_START, 0x8000); 73747310413SMichael Ellerman reserve_kdump_trampoline(); 738eb39c880SMahesh Salgaonkar #ifdef CONFIG_FA_DUMP 739eb39c880SMahesh Salgaonkar /* 740eb39c880SMahesh Salgaonkar * If we fail to reserve memory for firmware-assisted dump then 741eb39c880SMahesh Salgaonkar * fallback to kexec based kdump. 742eb39c880SMahesh Salgaonkar */ 743eb39c880SMahesh Salgaonkar if (fadump_reserve_mem() == 0) 744eb39c880SMahesh Salgaonkar #endif 74535dd5432SMichael Ellerman reserve_crashkernel(); 7469b6b563cSPaul Mackerras early_reserve_mem(); 7479b6b563cSPaul Mackerras 74814ed7409SAnton Blanchard /* Ensure that total memory size is page-aligned. */ 7496fbef13cSTejun Heo limit = ALIGN(memory_limit ?: memblock_phys_mem_size(), PAGE_SIZE); 75095f72d1eSYinghai Lu memblock_enforce_memory_limit(limit); 7516ca4f749SHollis Blanchard 7521aadc056STejun Heo memblock_allow_resize(); 75395f72d1eSYinghai Lu memblock_dump_all(); 7542babf5c2SMichael Ellerman 755b18f0ae9SChristophe Leroy DBG("Phys. mem: %llx\n", (unsigned long long)memblock_phys_mem_size()); 7562babf5c2SMichael Ellerman 7572babf5c2SMichael Ellerman /* We may need to relocate the flat tree, do it now. 7582babf5c2SMichael Ellerman * FIXME .. and the initrd too? */ 7592babf5c2SMichael Ellerman move_device_tree(); 7602babf5c2SMichael Ellerman 76159f57774SNicholas Piggin allocate_paca_ptrs(); 7621426d5a3SMichael Ellerman 7639b6b563cSPaul Mackerras DBG("Scanning CPUs ...\n"); 7649b6b563cSPaul Mackerras 7655a61ef74SNicholas Piggin dt_cpu_ftrs_scan(); 7665a61ef74SNicholas Piggin 76725985edcSLucas De Marchi /* Retrieve CPU related informations from the flat tree 7683c726f8dSBenjamin Herrenschmidt * (altivec support, boot CPU ID, ...) 7699b6b563cSPaul Mackerras */ 7703c726f8dSBenjamin Herrenschmidt of_scan_flat_dt(early_init_dt_scan_cpus, NULL); 77136ae37e3SBenjamin Herrenschmidt if (boot_cpuid < 0) { 772d939be3aSMasanari Iida printk("Failed to identify boot CPU !\n"); 77336ae37e3SBenjamin Herrenschmidt BUG(); 77436ae37e3SBenjamin Herrenschmidt } 7759b6b563cSPaul Mackerras 7767ac87abbSMatt Evans #if defined(CONFIG_SMP) && defined(CONFIG_PPC64) 7777ac87abbSMatt Evans /* We'll later wait for secondaries to check in; there are 7787ac87abbSMatt Evans * NCPUS-1 non-boot CPUs :-) 7797ac87abbSMatt Evans */ 7807ac87abbSMatt Evans spinning_secondaries = boot_cpu_count - 1; 7817ac87abbSMatt Evans #endif 7827ac87abbSMatt Evans 7831a01dc87SMichael Ellerman mmu_early_init_devtree(); 7841a01dc87SMichael Ellerman 78555672ecfSMahesh Salgaonkar #ifdef CONFIG_PPC_POWERNV 78655672ecfSMahesh Salgaonkar /* Scan and build the list of machine check recoverable ranges */ 78755672ecfSMahesh Salgaonkar of_scan_flat_dt(early_init_dt_scan_recoverable_ranges, NULL); 78855672ecfSMahesh Salgaonkar #endif 789da6a97bfSBenjamin Herrenschmidt epapr_paravirt_early_init(); 79055672ecfSMahesh Salgaonkar 7913808a889SBenjamin Herrenschmidt /* Now try to figure out if we are running on LPAR and so on */ 7923808a889SBenjamin Herrenschmidt pseries_probe_fw_features(); 7933808a889SBenjamin Herrenschmidt 794166dd7d3SBenjamin Herrenschmidt #ifdef CONFIG_PPC_PS3 795166dd7d3SBenjamin Herrenschmidt /* Identify PS3 firmware */ 796166dd7d3SBenjamin Herrenschmidt if (of_flat_dt_is_compatible(of_get_flat_dt_root(), "sony,ps3")) 797166dd7d3SBenjamin Herrenschmidt powerpc_firmware_features |= FW_FEATURE_PS3_POSSIBLE; 798166dd7d3SBenjamin Herrenschmidt #endif 799166dd7d3SBenjamin Herrenschmidt 80007fd1761SCyril Bur tm_init(); 80107fd1761SCyril Bur 8029b6b563cSPaul Mackerras DBG(" <- early_init_devtree()\n"); 8039b6b563cSPaul Mackerras } 8049b6b563cSPaul Mackerras 805b27652ddSKevin Hao #ifdef CONFIG_RELOCATABLE 806b27652ddSKevin Hao /* 807b27652ddSKevin Hao * This function run before early_init_devtree, so we have to init 808b27652ddSKevin Hao * initial_boot_params. 809b27652ddSKevin Hao */ 810b27652ddSKevin Hao void __init early_get_first_memblock_info(void *params, phys_addr_t *size) 811b27652ddSKevin Hao { 812b27652ddSKevin Hao /* Setup flat device-tree pointer */ 813b27652ddSKevin Hao initial_boot_params = params; 814b27652ddSKevin Hao 815b27652ddSKevin Hao /* 816b27652ddSKevin Hao * Scan the memory nodes and set add_mem_to_memblock to 0 to avoid 817b27652ddSKevin Hao * mess the memblock. 818b27652ddSKevin Hao */ 819b27652ddSKevin Hao add_mem_to_memblock = 0; 820b27652ddSKevin Hao of_scan_flat_dt(early_init_dt_scan_root, NULL); 821b27652ddSKevin Hao of_scan_flat_dt(early_init_dt_scan_memory_ppc, NULL); 822b27652ddSKevin Hao add_mem_to_memblock = 1; 823b27652ddSKevin Hao 824b27652ddSKevin Hao if (size) 825b27652ddSKevin Hao *size = first_memblock_size; 826b27652ddSKevin Hao } 827b27652ddSKevin Hao #endif 828b27652ddSKevin Hao 8299b6b563cSPaul Mackerras /******* 8309b6b563cSPaul Mackerras * 8319b6b563cSPaul Mackerras * New implementation of the OF "find" APIs, return a refcounted 8329b6b563cSPaul Mackerras * object, call of_node_put() when done. The device tree and list 8339b6b563cSPaul Mackerras * are protected by a rw_lock. 8349b6b563cSPaul Mackerras * 8359b6b563cSPaul Mackerras * Note that property management will need some locking as well, 8369b6b563cSPaul Mackerras * this isn't dealt with yet. 8379b6b563cSPaul Mackerras * 8389b6b563cSPaul Mackerras *******/ 8399b6b563cSPaul Mackerras 8409b6b563cSPaul Mackerras /** 841b37193b7SBenjamin Herrenschmidt * of_get_ibm_chip_id - Returns the IBM "chip-id" of a device 842b37193b7SBenjamin Herrenschmidt * @np: device node of the device 843b37193b7SBenjamin Herrenschmidt * 844b37193b7SBenjamin Herrenschmidt * This looks for a property "ibm,chip-id" in the node or any 845b37193b7SBenjamin Herrenschmidt * of its parents and returns its content, or -1 if it cannot 846b37193b7SBenjamin Herrenschmidt * be found. 847b37193b7SBenjamin Herrenschmidt */ 848b37193b7SBenjamin Herrenschmidt int of_get_ibm_chip_id(struct device_node *np) 849b37193b7SBenjamin Herrenschmidt { 850b37193b7SBenjamin Herrenschmidt of_node_get(np); 851b37193b7SBenjamin Herrenschmidt while (np) { 8521856f50cSChristophe Jaillet u32 chip_id; 853b37193b7SBenjamin Herrenschmidt 8541856f50cSChristophe Jaillet /* 8551856f50cSChristophe Jaillet * Skiboot may produce memory nodes that contain more than one 8561856f50cSChristophe Jaillet * cell in chip-id, we only read the first one here. 8571856f50cSChristophe Jaillet */ 8581856f50cSChristophe Jaillet if (!of_property_read_u32(np, "ibm,chip-id", &chip_id)) { 859b37193b7SBenjamin Herrenschmidt of_node_put(np); 8601856f50cSChristophe Jaillet return chip_id; 861b37193b7SBenjamin Herrenschmidt } 86216c1d606SMichael Ellerman 86316c1d606SMichael Ellerman np = of_get_next_parent(np); 864b37193b7SBenjamin Herrenschmidt } 865b37193b7SBenjamin Herrenschmidt return -1; 866b37193b7SBenjamin Herrenschmidt } 867b130e7c0SDan Streetman EXPORT_SYMBOL(of_get_ibm_chip_id); 868b37193b7SBenjamin Herrenschmidt 8693eb906c6SMichael Ellerman /** 8703eb906c6SMichael Ellerman * cpu_to_chip_id - Return the cpus chip-id 8713eb906c6SMichael Ellerman * @cpu: The logical cpu number. 8723eb906c6SMichael Ellerman * 8733eb906c6SMichael Ellerman * Return the value of the ibm,chip-id property corresponding to the given 8743eb906c6SMichael Ellerman * logical cpu number. If the chip-id can not be found, returns -1. 8753eb906c6SMichael Ellerman */ 8763eb906c6SMichael Ellerman int cpu_to_chip_id(int cpu) 8773eb906c6SMichael Ellerman { 8783eb906c6SMichael Ellerman struct device_node *np; 8793eb906c6SMichael Ellerman 8803eb906c6SMichael Ellerman np = of_get_cpu_node(cpu, NULL); 8813eb906c6SMichael Ellerman if (!np) 8823eb906c6SMichael Ellerman return -1; 8833eb906c6SMichael Ellerman 8843eb906c6SMichael Ellerman of_node_put(np); 8853eb906c6SMichael Ellerman return of_get_ibm_chip_id(np); 8863eb906c6SMichael Ellerman } 8873eb906c6SMichael Ellerman EXPORT_SYMBOL(cpu_to_chip_id); 8883eb906c6SMichael Ellerman 889819d5965SSudeep KarkadaNagesha bool arch_match_cpu_phys_id(int cpu, u64 phys_id) 890819d5965SSudeep KarkadaNagesha { 8919f593f13SNicholas Piggin #ifdef CONFIG_SMP 8929f593f13SNicholas Piggin /* 8939f593f13SNicholas Piggin * Early firmware scanning must use this rather than 8949f593f13SNicholas Piggin * get_hard_smp_processor_id because we don't have pacas allocated 8959f593f13SNicholas Piggin * until memory topology is discovered. 8969f593f13SNicholas Piggin */ 8979f593f13SNicholas Piggin if (cpu_to_phys_id != NULL) 8989f593f13SNicholas Piggin return (int)phys_id == cpu_to_phys_id[cpu]; 8999f593f13SNicholas Piggin #endif 9009f593f13SNicholas Piggin 901819d5965SSudeep KarkadaNagesha return (int)phys_id == get_hard_smp_processor_id(cpu); 902819d5965SSudeep KarkadaNagesha } 903