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 */ 151*beff8237SAnton Blanchard unsigned int cpu_user_ftrs2; /* PPC_FEATURE2_xxx bit */ 152d205819eSPaul Mackerras unsigned char pabyte; /* byte number in ibm,pa-features */ 153d205819eSPaul Mackerras unsigned char pabit; /* bit number (big-endian) */ 154d205819eSPaul Mackerras unsigned char invert; /* if 1, pa bit set => clear feature */ 155d205819eSPaul Mackerras } ibm_pa_features[] __initdata = { 156*beff8237SAnton Blanchard {0, 0, PPC_FEATURE_HAS_MMU, 0, 0, 0, 0}, 157*beff8237SAnton Blanchard {0, 0, PPC_FEATURE_HAS_FPU, 0, 0, 1, 0}, 158*beff8237SAnton Blanchard {CPU_FTR_CTRL, 0, 0, 0, 0, 3, 0}, 159*beff8237SAnton Blanchard {CPU_FTR_NOEXECUTE, 0, 0, 0, 0, 6, 0}, 160*beff8237SAnton Blanchard {CPU_FTR_NODSISRALIGN, 0, 0, 0, 1, 1, 1}, 161*beff8237SAnton Blanchard {0, MMU_FTR_CI_LARGE_PAGE, 0, 0, 1, 2, 0}, 162*beff8237SAnton Blanchard {CPU_FTR_REAL_LE, 0, PPC_FEATURE_TRUE_LE, 0, 5, 0, 0}, 1639e819963SAneesh Kumar K.V /* 1649e819963SAneesh Kumar K.V * If the kernel doesn't support TM (ie. CONFIG_PPC_TRANSACTIONAL_MEM=n), 1659e819963SAneesh Kumar K.V * we don't want to turn on CPU_FTR_TM here, so we use CPU_FTR_TM_COMP 1669e819963SAneesh Kumar K.V * which is 0 if the kernel doesn't support TM. 1679e819963SAneesh Kumar K.V */ 168*beff8237SAnton Blanchard {CPU_FTR_TM_COMP, 0, 0, 0, 22, 0, 0}, 169d205819eSPaul Mackerras }; 170d205819eSPaul Mackerras 1719d0c4dfeSRob Herring static void __init scan_features(unsigned long node, const unsigned char *ftrs, 172974a76f5SPaul Mackerras unsigned long tablelen, 173974a76f5SPaul Mackerras struct ibm_pa_feature *fp, 174974a76f5SPaul Mackerras unsigned long ft_size) 175d205819eSPaul Mackerras { 176974a76f5SPaul Mackerras unsigned long i, len, bit; 177d205819eSPaul Mackerras 178d205819eSPaul Mackerras /* find descriptor with type == 0 */ 179d205819eSPaul Mackerras for (;;) { 180d205819eSPaul Mackerras if (tablelen < 3) 181d205819eSPaul Mackerras return; 182974a76f5SPaul Mackerras len = 2 + ftrs[0]; 183d205819eSPaul Mackerras if (tablelen < len) 184d205819eSPaul Mackerras return; /* descriptor 0 not found */ 185974a76f5SPaul Mackerras if (ftrs[1] == 0) 186d205819eSPaul Mackerras break; 187d205819eSPaul Mackerras tablelen -= len; 188974a76f5SPaul Mackerras ftrs += len; 189d205819eSPaul Mackerras } 190d205819eSPaul Mackerras 191d205819eSPaul Mackerras /* loop over bits we know about */ 192974a76f5SPaul Mackerras for (i = 0; i < ft_size; ++i, ++fp) { 193974a76f5SPaul Mackerras if (fp->pabyte >= ftrs[0]) 194d205819eSPaul Mackerras continue; 195974a76f5SPaul Mackerras bit = (ftrs[2 + fp->pabyte] >> (7 - fp->pabit)) & 1; 196d205819eSPaul Mackerras if (bit ^ fp->invert) { 197d205819eSPaul Mackerras cur_cpu_spec->cpu_features |= fp->cpu_features; 198d205819eSPaul Mackerras cur_cpu_spec->cpu_user_features |= fp->cpu_user_ftrs; 199*beff8237SAnton Blanchard cur_cpu_spec->cpu_user_features2 |= fp->cpu_user_ftrs2; 20044ae3ab3SMatt Evans cur_cpu_spec->mmu_features |= fp->mmu_features; 201d205819eSPaul Mackerras } else { 202d205819eSPaul Mackerras cur_cpu_spec->cpu_features &= ~fp->cpu_features; 203d205819eSPaul Mackerras cur_cpu_spec->cpu_user_features &= ~fp->cpu_user_ftrs; 204*beff8237SAnton Blanchard cur_cpu_spec->cpu_user_features2 &= ~fp->cpu_user_ftrs2; 20544ae3ab3SMatt Evans cur_cpu_spec->mmu_features &= ~fp->mmu_features; 206d205819eSPaul Mackerras } 207d205819eSPaul Mackerras } 208d205819eSPaul Mackerras } 209d205819eSPaul Mackerras 210974a76f5SPaul Mackerras static void __init check_cpu_pa_features(unsigned long node) 211974a76f5SPaul Mackerras { 2129d0c4dfeSRob Herring const unsigned char *pa_ftrs; 2139d0c4dfeSRob Herring int tablelen; 214974a76f5SPaul Mackerras 215974a76f5SPaul Mackerras pa_ftrs = of_get_flat_dt_prop(node, "ibm,pa-features", &tablelen); 216974a76f5SPaul Mackerras if (pa_ftrs == NULL) 217974a76f5SPaul Mackerras return; 218974a76f5SPaul Mackerras 219974a76f5SPaul Mackerras scan_features(node, pa_ftrs, tablelen, 220974a76f5SPaul Mackerras ibm_pa_features, ARRAY_SIZE(ibm_pa_features)); 221974a76f5SPaul Mackerras } 222974a76f5SPaul Mackerras 22394491685SBenjamin Herrenschmidt #ifdef CONFIG_PPC_STD_MMU_64 2249c61f7a0SAnshuman Khandual static void __init init_mmu_slb_size(unsigned long node) 225584f8b71SMichael Neuling { 2269d0c4dfeSRob Herring const __be32 *slb_size_ptr; 227584f8b71SMichael Neuling 2289c61f7a0SAnshuman Khandual slb_size_ptr = of_get_flat_dt_prop(node, "slb-size", NULL) ? : 2299c61f7a0SAnshuman Khandual of_get_flat_dt_prop(node, "ibm,slb-size", NULL); 2309c61f7a0SAnshuman Khandual 2319c61f7a0SAnshuman Khandual if (slb_size_ptr) 232dc0e643aSIan Munsie mmu_slb_size = be32_to_cpup(slb_size_ptr); 233584f8b71SMichael Neuling } 234584f8b71SMichael Neuling #else 2359c61f7a0SAnshuman Khandual #define init_mmu_slb_size(node) do { } while(0) 236584f8b71SMichael Neuling #endif 237584f8b71SMichael Neuling 238974a76f5SPaul Mackerras static struct feature_property { 239974a76f5SPaul Mackerras const char *name; 240974a76f5SPaul Mackerras u32 min_value; 241974a76f5SPaul Mackerras unsigned long cpu_feature; 242974a76f5SPaul Mackerras unsigned long cpu_user_ftr; 243974a76f5SPaul Mackerras } feature_properties[] __initdata = { 244974a76f5SPaul Mackerras #ifdef CONFIG_ALTIVEC 245974a76f5SPaul Mackerras {"altivec", 0, CPU_FTR_ALTIVEC, PPC_FEATURE_HAS_ALTIVEC}, 246974a76f5SPaul Mackerras {"ibm,vmx", 1, CPU_FTR_ALTIVEC, PPC_FEATURE_HAS_ALTIVEC}, 247974a76f5SPaul Mackerras #endif /* CONFIG_ALTIVEC */ 248b962ce9dSMichael Neuling #ifdef CONFIG_VSX 249b962ce9dSMichael Neuling /* Yes, this _really_ is ibm,vmx == 2 to enable VSX */ 250b962ce9dSMichael Neuling {"ibm,vmx", 2, CPU_FTR_VSX, PPC_FEATURE_HAS_VSX}, 251b962ce9dSMichael Neuling #endif /* CONFIG_VSX */ 252974a76f5SPaul Mackerras #ifdef CONFIG_PPC64 253974a76f5SPaul Mackerras {"ibm,dfp", 1, 0, PPC_FEATURE_HAS_DFP}, 254974a76f5SPaul Mackerras {"ibm,purr", 1, CPU_FTR_PURR, 0}, 255974a76f5SPaul Mackerras {"ibm,spurr", 1, CPU_FTR_SPURR, 0}, 256974a76f5SPaul Mackerras #endif /* CONFIG_PPC64 */ 257974a76f5SPaul Mackerras }; 258974a76f5SPaul Mackerras 25914b3d926SValentine Barshak #if defined(CONFIG_44x) && defined(CONFIG_PPC_FPU) 26014b3d926SValentine Barshak static inline void identical_pvr_fixup(unsigned long node) 26114b3d926SValentine Barshak { 26214b3d926SValentine Barshak unsigned int pvr; 2639d0c4dfeSRob Herring const char *model = of_get_flat_dt_prop(node, "model", NULL); 26414b3d926SValentine Barshak 26514b3d926SValentine Barshak /* 26614b3d926SValentine Barshak * Since 440GR(x)/440EP(x) processors have the same pvr, 26714b3d926SValentine Barshak * we check the node path and set bit 28 in the cur_cpu_spec 26814b3d926SValentine Barshak * pvr for EP(x) processor version. This bit is always 0 in 26914b3d926SValentine Barshak * the "real" pvr. Then we call identify_cpu again with 27014b3d926SValentine Barshak * the new logical pvr to enable FPU support. 27114b3d926SValentine Barshak */ 27214b3d926SValentine Barshak if (model && strstr(model, "440EP")) { 27314b3d926SValentine Barshak pvr = cur_cpu_spec->pvr_value | 0x8; 27414b3d926SValentine Barshak identify_cpu(0, pvr); 27514b3d926SValentine Barshak DBG("Using logical pvr %x for %s\n", pvr, model); 27614b3d926SValentine Barshak } 27714b3d926SValentine Barshak } 27814b3d926SValentine Barshak #else 27914b3d926SValentine Barshak #define identical_pvr_fixup(node) do { } while(0) 28014b3d926SValentine Barshak #endif 28114b3d926SValentine Barshak 282974a76f5SPaul Mackerras static void __init check_cpu_feature_properties(unsigned long node) 283974a76f5SPaul Mackerras { 284974a76f5SPaul Mackerras unsigned long i; 285974a76f5SPaul Mackerras struct feature_property *fp = feature_properties; 286dc0e643aSIan Munsie const __be32 *prop; 287974a76f5SPaul Mackerras 288974a76f5SPaul Mackerras for (i = 0; i < ARRAY_SIZE(feature_properties); ++i, ++fp) { 289974a76f5SPaul Mackerras prop = of_get_flat_dt_prop(node, fp->name, NULL); 290dc0e643aSIan Munsie if (prop && be32_to_cpup(prop) >= fp->min_value) { 291974a76f5SPaul Mackerras cur_cpu_spec->cpu_features |= fp->cpu_feature; 292974a76f5SPaul Mackerras cur_cpu_spec->cpu_user_features |= fp->cpu_user_ftr; 293974a76f5SPaul Mackerras } 294974a76f5SPaul Mackerras } 295974a76f5SPaul Mackerras } 296974a76f5SPaul Mackerras 2979b6b563cSPaul Mackerras static int __init early_init_dt_scan_cpus(unsigned long node, 2984df20460SAnton Blanchard const char *uname, int depth, 2994df20460SAnton Blanchard void *data) 3009b6b563cSPaul Mackerras { 3019d0c4dfeSRob Herring const char *type = of_get_flat_dt_prop(node, "device_type", NULL); 302dc0e643aSIan Munsie const __be32 *prop; 303dc0e643aSIan Munsie const __be32 *intserv; 3044df20460SAnton Blanchard int i, nthreads; 3059d0c4dfeSRob Herring int len; 3069d07bc84SBenjamin Herrenschmidt int found = -1; 307208b3a4cSBenjamin Herrenschmidt int found_thread = 0; 3089b6b563cSPaul Mackerras 3099b6b563cSPaul Mackerras /* We are scanning "cpu" nodes only */ 3109b6b563cSPaul Mackerras if (type == NULL || strcmp(type, "cpu") != 0) 3119b6b563cSPaul Mackerras return 0; 3129b6b563cSPaul Mackerras 3134df20460SAnton Blanchard /* Get physical cpuid */ 3144df20460SAnton Blanchard intserv = of_get_flat_dt_prop(node, "ibm,ppc-interrupt-server#s", &len); 315e16c8765SAndy Fleming if (!intserv) 316e16c8765SAndy Fleming intserv = of_get_flat_dt_prop(node, "reg", &len); 317e16c8765SAndy Fleming 3184df20460SAnton Blanchard nthreads = len / sizeof(int); 3194df20460SAnton Blanchard 3204df20460SAnton Blanchard /* 3214df20460SAnton Blanchard * Now see if any of these threads match our boot cpu. 3224df20460SAnton Blanchard * NOTE: This must match the parsing done in smp_setup_cpu_maps. 3234df20460SAnton Blanchard */ 3244df20460SAnton Blanchard for (i = 0; i < nthreads; i++) { 3254df20460SAnton Blanchard /* 3264df20460SAnton Blanchard * version 2 of the kexec param format adds the phys cpuid of 3274df20460SAnton Blanchard * booted proc. 3284df20460SAnton Blanchard */ 329060f78c2SRob Herring if (fdt_version(initial_boot_params) >= 2) { 330dc0e643aSIan Munsie if (be32_to_cpu(intserv[i]) == 331060f78c2SRob Herring fdt_boot_cpuid_phys(initial_boot_params)) { 3329d07bc84SBenjamin Herrenschmidt found = boot_cpu_count; 333208b3a4cSBenjamin Herrenschmidt found_thread = i; 334208b3a4cSBenjamin Herrenschmidt } 3354df20460SAnton Blanchard } else { 3364df20460SAnton Blanchard /* 3374df20460SAnton Blanchard * Check if it's the boot-cpu, set it's hw index now, 3384df20460SAnton Blanchard * unfortunately this format did not support booting 3394df20460SAnton Blanchard * off secondary threads. 3404df20460SAnton Blanchard */ 3413c726f8dSBenjamin Herrenschmidt if (of_get_flat_dt_prop(node, 3429d07bc84SBenjamin Herrenschmidt "linux,boot-cpu", NULL) != NULL) 3439d07bc84SBenjamin Herrenschmidt found = boot_cpu_count; 3449b6b563cSPaul Mackerras } 3454df20460SAnton Blanchard #ifdef CONFIG_SMP 3464df20460SAnton Blanchard /* logical cpu id is always 0 on UP kernels */ 3479d07bc84SBenjamin Herrenschmidt boot_cpu_count++; 3484df20460SAnton Blanchard #endif 3494df20460SAnton Blanchard } 3504df20460SAnton Blanchard 3517222f779SBenjamin Herrenschmidt /* Not the boot CPU */ 3527222f779SBenjamin Herrenschmidt if (found < 0) 3537222f779SBenjamin Herrenschmidt return 0; 3547222f779SBenjamin Herrenschmidt 3559d07bc84SBenjamin Herrenschmidt DBG("boot cpu: logical %d physical %d\n", found, 356dc0e643aSIan Munsie be32_to_cpu(intserv[found_thread])); 3579d07bc84SBenjamin Herrenschmidt boot_cpuid = found; 3587222f779SBenjamin Herrenschmidt set_hard_smp_processor_id(found, be32_to_cpu(intserv[found_thread])); 359974a76f5SPaul Mackerras 360974a76f5SPaul Mackerras /* 361974a76f5SPaul Mackerras * PAPR defines "logical" PVR values for cpus that 362974a76f5SPaul Mackerras * meet various levels of the architecture: 363974a76f5SPaul Mackerras * 0x0f000001 Architecture version 2.04 364974a76f5SPaul Mackerras * 0x0f000002 Architecture version 2.05 365974a76f5SPaul Mackerras * If the cpu-version property in the cpu node contains 366974a76f5SPaul Mackerras * such a value, we call identify_cpu again with the 367974a76f5SPaul Mackerras * logical PVR value in order to use the cpu feature 368974a76f5SPaul Mackerras * bits appropriate for the architecture level. 369974a76f5SPaul Mackerras * 370974a76f5SPaul Mackerras * A POWER6 partition in "POWER6 architected" mode 371974a76f5SPaul Mackerras * uses the 0x0f000002 PVR value; in POWER5+ mode 372974a76f5SPaul Mackerras * it uses 0x0f000001. 373974a76f5SPaul Mackerras */ 374974a76f5SPaul Mackerras prop = of_get_flat_dt_prop(node, "cpu-version", NULL); 375dc0e643aSIan Munsie if (prop && (be32_to_cpup(prop) & 0xff000000) == 0x0f000000) 376dc0e643aSIan Munsie identify_cpu(0, be32_to_cpup(prop)); 37714b3d926SValentine Barshak 37814b3d926SValentine Barshak identical_pvr_fixup(node); 3799b6b563cSPaul Mackerras 380974a76f5SPaul Mackerras check_cpu_feature_properties(node); 381d205819eSPaul Mackerras check_cpu_pa_features(node); 3829c61f7a0SAnshuman Khandual init_mmu_slb_size(node); 383d205819eSPaul Mackerras 3844a85b31dSBenjamin Herrenschmidt #ifdef CONFIG_PPC64 3854df20460SAnton Blanchard if (nthreads > 1) 3869b6b563cSPaul Mackerras cur_cpu_spec->cpu_features |= CPU_FTR_SMT; 3874df20460SAnton Blanchard else 3884df20460SAnton Blanchard cur_cpu_spec->cpu_features &= ~CPU_FTR_SMT; 3899b6b563cSPaul Mackerras #endif 3909b6b563cSPaul Mackerras return 0; 3919b6b563cSPaul Mackerras } 3929b6b563cSPaul Mackerras 393e51df2c1SAnton Blanchard static int __init early_init_dt_scan_chosen_ppc(unsigned long node, 394e51df2c1SAnton Blanchard const char *uname, 39532c97689SGrant Likely int depth, void *data) 3969b6b563cSPaul Mackerras { 3979d0c4dfeSRob Herring const unsigned long *lprop; /* All these set by kernel, so no need to convert endian */ 3989b6b563cSPaul Mackerras 39932c97689SGrant Likely /* Use common scan routine to determine if this is the chosen node */ 40032c97689SGrant Likely if (early_init_dt_scan_chosen(node, uname, depth, data) == 0) 40132c97689SGrant Likely return 0; 40232c97689SGrant Likely 4039b6b563cSPaul Mackerras #ifdef CONFIG_PPC64 4049b6b563cSPaul Mackerras /* check if iommu is forced on or off */ 4053c726f8dSBenjamin Herrenschmidt if (of_get_flat_dt_prop(node, "linux,iommu-off", NULL) != NULL) 4069b6b563cSPaul Mackerras iommu_is_off = 1; 4073c726f8dSBenjamin Herrenschmidt if (of_get_flat_dt_prop(node, "linux,iommu-force-on", NULL) != NULL) 4089b6b563cSPaul Mackerras iommu_force_on = 1; 4099b6b563cSPaul Mackerras #endif 4109b6b563cSPaul Mackerras 4112babf5c2SMichael Ellerman /* mem=x on the command line is the preferred mechanism */ 4123c726f8dSBenjamin Herrenschmidt lprop = of_get_flat_dt_prop(node, "linux,memory-limit", NULL); 4139b6b563cSPaul Mackerras if (lprop) 4149b6b563cSPaul Mackerras memory_limit = *lprop; 4159b6b563cSPaul Mackerras 4169b6b563cSPaul Mackerras #ifdef CONFIG_PPC64 4173c726f8dSBenjamin Herrenschmidt lprop = of_get_flat_dt_prop(node, "linux,tce-alloc-start", NULL); 4189b6b563cSPaul Mackerras if (lprop) 4199b6b563cSPaul Mackerras tce_alloc_start = *lprop; 4203c726f8dSBenjamin Herrenschmidt lprop = of_get_flat_dt_prop(node, "linux,tce-alloc-end", NULL); 4219b6b563cSPaul Mackerras if (lprop) 4229b6b563cSPaul Mackerras tce_alloc_end = *lprop; 4239b6b563cSPaul Mackerras #endif 4249b6b563cSPaul Mackerras 425dcee3036SMichael Ellerman #ifdef CONFIG_KEXEC 42663277161SStephen Rothwell lprop = of_get_flat_dt_prop(node, "linux,crashkernel-base", NULL); 427dcee3036SMichael Ellerman if (lprop) 428dcee3036SMichael Ellerman crashk_res.start = *lprop; 429dcee3036SMichael Ellerman 43063277161SStephen Rothwell lprop = of_get_flat_dt_prop(node, "linux,crashkernel-size", NULL); 431dcee3036SMichael Ellerman if (lprop) 432dcee3036SMichael Ellerman crashk_res.end = crashk_res.start + *lprop - 1; 433dcee3036SMichael Ellerman #endif 43432c97689SGrant Likely 43532c97689SGrant Likely /* break now */ 43632c97689SGrant Likely return 1; 4379b6b563cSPaul Mackerras } 4389b6b563cSPaul Mackerras 4390204568aSPaul Mackerras #ifdef CONFIG_PPC_PSERIES 4400204568aSPaul Mackerras /* 4410204568aSPaul Mackerras * Interpret the ibm,dynamic-memory property in the 4420204568aSPaul Mackerras * /ibm,dynamic-reconfiguration-memory node. 4430204568aSPaul Mackerras * This contains a list of memory blocks along with NUMA affinity 4440204568aSPaul Mackerras * information. 4450204568aSPaul Mackerras */ 4460204568aSPaul Mackerras static int __init early_init_dt_scan_drconf_memory(unsigned long node) 4470204568aSPaul Mackerras { 4489d0c4dfeSRob Herring const __be32 *dm, *ls, *usm; 4499d0c4dfeSRob Herring int l; 4509d0c4dfeSRob Herring unsigned long n, flags; 45195f72d1eSYinghai Lu u64 base, size, memblock_size; 452cf00085dSChandru unsigned int is_kexec_kdump = 0, rngs; 4530204568aSPaul Mackerras 4543fdfd990SBenjamin Herrenschmidt ls = of_get_flat_dt_prop(node, "ibm,lmb-size", &l); 4550f0b56c3SGrant Likely if (ls == NULL || l < dt_root_size_cells * sizeof(__be32)) 4560204568aSPaul Mackerras return 0; 45795f72d1eSYinghai Lu memblock_size = dt_mem_next_cell(dt_root_size_cells, &ls); 4580204568aSPaul Mackerras 45963277161SStephen Rothwell dm = of_get_flat_dt_prop(node, "ibm,dynamic-memory", &l); 4600f0b56c3SGrant Likely if (dm == NULL || l < sizeof(__be32)) 4610204568aSPaul Mackerras return 0; 4620204568aSPaul Mackerras 463e91ae5bdSAlistair Popple n = of_read_number(dm++, 1); /* number of entries */ 4640f0b56c3SGrant Likely if (l < (n * (dt_root_addr_cells + 4) + 1) * sizeof(__be32)) 4650204568aSPaul Mackerras return 0; 4660204568aSPaul Mackerras 467cf00085dSChandru /* check if this is a kexec/kdump kernel. */ 46863277161SStephen Rothwell usm = of_get_flat_dt_prop(node, "linux,drconf-usable-memory", 469cf00085dSChandru &l); 470cf00085dSChandru if (usm != NULL) 471cf00085dSChandru is_kexec_kdump = 1; 472cf00085dSChandru 4730204568aSPaul Mackerras for (; n != 0; --n) { 4740204568aSPaul Mackerras base = dt_mem_next_cell(dt_root_addr_cells, &dm); 475e91ae5bdSAlistair Popple flags = of_read_number(&dm[3], 1); 4760204568aSPaul Mackerras /* skip DRC index, pad, assoc. list index, flags */ 4770204568aSPaul Mackerras dm += 4; 4789afac933SAnshuman Khandual /* skip this block if the reserved bit is set in flags 4799afac933SAnshuman Khandual or if the block is not assigned to this partition */ 4809afac933SAnshuman Khandual if ((flags & DRCONF_MEM_RESERVED) || 4819afac933SAnshuman Khandual !(flags & DRCONF_MEM_ASSIGNED)) 4820204568aSPaul Mackerras continue; 48395f72d1eSYinghai Lu size = memblock_size; 484cf00085dSChandru rngs = 1; 485cf00085dSChandru if (is_kexec_kdump) { 486cf00085dSChandru /* 48795f72d1eSYinghai Lu * For each memblock in ibm,dynamic-memory, a corresponding 488cf00085dSChandru * entry in linux,drconf-usable-memory property contains 489cf00085dSChandru * a counter 'p' followed by 'p' (base, size) duple. 490cf00085dSChandru * Now read the counter from 491cf00085dSChandru * linux,drconf-usable-memory property 492cf00085dSChandru */ 493cf00085dSChandru rngs = dt_mem_next_cell(dt_root_size_cells, &usm); 494cf00085dSChandru if (!rngs) /* there are no (base, size) duple */ 495cf00085dSChandru continue; 496cf00085dSChandru } 497cf00085dSChandru do { 498cf00085dSChandru if (is_kexec_kdump) { 499cf00085dSChandru base = dt_mem_next_cell(dt_root_addr_cells, 500cf00085dSChandru &usm); 501cf00085dSChandru size = dt_mem_next_cell(dt_root_size_cells, 502cf00085dSChandru &usm); 503cf00085dSChandru } 5040204568aSPaul Mackerras if (iommu_is_off) { 5050204568aSPaul Mackerras if (base >= 0x80000000ul) 5060204568aSPaul Mackerras continue; 5070204568aSPaul Mackerras if ((base + size) > 0x80000000ul) 5080204568aSPaul Mackerras size = 0x80000000ul - base; 5090204568aSPaul Mackerras } 51095f72d1eSYinghai Lu memblock_add(base, size); 511cf00085dSChandru } while (--rngs); 5120204568aSPaul Mackerras } 51395f72d1eSYinghai Lu memblock_dump_all(); 5140204568aSPaul Mackerras return 0; 5150204568aSPaul Mackerras } 5160204568aSPaul Mackerras #else 5170204568aSPaul Mackerras #define early_init_dt_scan_drconf_memory(node) 0 5180204568aSPaul Mackerras #endif /* CONFIG_PPC_PSERIES */ 5199b6b563cSPaul Mackerras 52051975db0SGrant Likely static int __init early_init_dt_scan_memory_ppc(unsigned long node, 52151975db0SGrant Likely const char *uname, 52251975db0SGrant Likely int depth, void *data) 5239b6b563cSPaul Mackerras { 5240204568aSPaul Mackerras if (depth == 1 && 5250204568aSPaul Mackerras strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0) 5260204568aSPaul Mackerras return early_init_dt_scan_drconf_memory(node); 5270204568aSPaul Mackerras 52851975db0SGrant Likely return early_init_dt_scan_memory(node, uname, depth, data); 52951975db0SGrant Likely } 5309b6b563cSPaul Mackerras 531b27652ddSKevin Hao /* 532b27652ddSKevin Hao * For a relocatable kernel, we need to get the memstart_addr first, 533b27652ddSKevin Hao * then use it to calculate the virtual kernel start address. This has 534b27652ddSKevin Hao * to happen at a very early stage (before machine_init). In this case, 535b27652ddSKevin Hao * we just want to get the memstart_address and would not like to mess the 536b27652ddSKevin Hao * memblock at this stage. So introduce a variable to skip the memblock_add() 537b27652ddSKevin Hao * for this reason. 538b27652ddSKevin Hao */ 539b27652ddSKevin Hao #ifdef CONFIG_RELOCATABLE 540b27652ddSKevin Hao static int add_mem_to_memblock = 1; 541b27652ddSKevin Hao #else 542b27652ddSKevin Hao #define add_mem_to_memblock 1 543b27652ddSKevin Hao #endif 544b27652ddSKevin Hao 54551975db0SGrant Likely void __init early_init_dt_add_memory_arch(u64 base, u64 size) 54651975db0SGrant Likely { 547cd3db0c4SBenjamin Herrenschmidt #ifdef CONFIG_PPC64 5489b6b563cSPaul Mackerras if (iommu_is_off) { 5499b6b563cSPaul Mackerras if (base >= 0x80000000ul) 55051975db0SGrant Likely return; 5519b6b563cSPaul Mackerras if ((base + size) > 0x80000000ul) 5529b6b563cSPaul Mackerras size = 0x80000000ul - base; 5539b6b563cSPaul Mackerras } 5549b6b563cSPaul Mackerras #endif 55503bf469aSBenjamin Herrenschmidt /* Keep track of the beginning of memory -and- the size of 55603bf469aSBenjamin Herrenschmidt * the very first block in the device-tree as it represents 55703bf469aSBenjamin Herrenschmidt * the RMA on ppc64 server 55803bf469aSBenjamin Herrenschmidt */ 55903bf469aSBenjamin Herrenschmidt if (base < memstart_addr) { 56003bf469aSBenjamin Herrenschmidt memstart_addr = base; 56103bf469aSBenjamin Herrenschmidt first_memblock_size = size; 56203bf469aSBenjamin Herrenschmidt } 563cd3db0c4SBenjamin Herrenschmidt 564cd3db0c4SBenjamin Herrenschmidt /* Add the chunk to the MEMBLOCK list */ 565b27652ddSKevin Hao if (add_mem_to_memblock) 566cd3db0c4SBenjamin Herrenschmidt memblock_add(base, size); 5679b6b563cSPaul Mackerras } 56837dd2badSKumar Gala 569c039e3a8SBenjamin Herrenschmidt static void __init early_reserve_mem_dt(void) 5700962e800SJeremy Kerr { 5719d0c4dfeSRob Herring unsigned long i, dt_root; 5729d0c4dfeSRob Herring int len; 5730962e800SJeremy Kerr const __be32 *prop; 5740962e800SJeremy Kerr 57524bbd929SArd Biesheuvel early_init_fdt_reserve_self(); 576edba274cSRob Herring early_init_fdt_scan_reserved_mem(); 577edba274cSRob Herring 5780962e800SJeremy Kerr dt_root = of_get_flat_dt_root(); 5790962e800SJeremy Kerr 5800962e800SJeremy Kerr prop = of_get_flat_dt_prop(dt_root, "reserved-ranges", &len); 5810962e800SJeremy Kerr 5820962e800SJeremy Kerr if (!prop) 583c039e3a8SBenjamin Herrenschmidt return; 584c039e3a8SBenjamin Herrenschmidt 585c039e3a8SBenjamin Herrenschmidt DBG("Found new-style reserved-ranges\n"); 5860962e800SJeremy Kerr 5870962e800SJeremy Kerr /* Each reserved range is an (address,size) pair, 2 cells each, 5880962e800SJeremy Kerr * totalling 4 cells per range. */ 5890962e800SJeremy Kerr for (i = 0; i < len / (sizeof(*prop) * 4); i++) { 5900962e800SJeremy Kerr u64 base, size; 5910962e800SJeremy Kerr 5920962e800SJeremy Kerr base = of_read_number(prop + (i * 4) + 0, 2); 5930962e800SJeremy Kerr size = of_read_number(prop + (i * 4) + 2, 2); 5940962e800SJeremy Kerr 595c039e3a8SBenjamin Herrenschmidt if (size) { 596c039e3a8SBenjamin Herrenschmidt DBG("reserving: %llx -> %llx\n", base, size); 5970962e800SJeremy Kerr memblock_reserve(base, size); 5980962e800SJeremy Kerr } 599c039e3a8SBenjamin Herrenschmidt } 6000962e800SJeremy Kerr } 6010962e800SJeremy Kerr 6029b6b563cSPaul Mackerras static void __init early_reserve_mem(void) 6039b6b563cSPaul Mackerras { 604dc0e643aSIan Munsie __be64 *reserve_map; 6059b6b563cSPaul Mackerras 606dc0e643aSIan Munsie reserve_map = (__be64 *)(((unsigned long)initial_boot_params) + 607060f78c2SRob Herring fdt_off_mem_rsvmap(initial_boot_params)); 6084d1f3f25SJimi Xenidis 609c039e3a8SBenjamin Herrenschmidt /* Look for the new "reserved-regions" property in the DT */ 610c039e3a8SBenjamin Herrenschmidt early_reserve_mem_dt(); 6110962e800SJeremy Kerr 61230437b3eSDavid Gibson #ifdef CONFIG_BLK_DEV_INITRD 613c039e3a8SBenjamin Herrenschmidt /* Then reserve the initrd, if any */ 614c039e3a8SBenjamin Herrenschmidt if (initrd_start && (initrd_end > initrd_start)) { 615307cfe71SBenjamin Herrenschmidt memblock_reserve(_ALIGN_DOWN(__pa(initrd_start), PAGE_SIZE), 616307cfe71SBenjamin Herrenschmidt _ALIGN_UP(initrd_end, PAGE_SIZE) - 617307cfe71SBenjamin Herrenschmidt _ALIGN_DOWN(initrd_start, PAGE_SIZE)); 618c039e3a8SBenjamin Herrenschmidt } 61930437b3eSDavid Gibson #endif /* CONFIG_BLK_DEV_INITRD */ 62030437b3eSDavid Gibson 621cbbcf340SKumar Gala #ifdef CONFIG_PPC32 622cbbcf340SKumar Gala /* 623cbbcf340SKumar Gala * Handle the case where we might be booting from an old kexec 624cbbcf340SKumar Gala * image that setup the mem_rsvmap as pairs of 32-bit values 625cbbcf340SKumar Gala */ 626dc0e643aSIan Munsie if (be64_to_cpup(reserve_map) > 0xffffffffull) { 627cbbcf340SKumar Gala u32 base_32, size_32; 628dc0e643aSIan Munsie __be32 *reserve_map_32 = (__be32 *)reserve_map; 629cbbcf340SKumar Gala 630c039e3a8SBenjamin Herrenschmidt DBG("Found old 32-bit reserve map\n"); 631c039e3a8SBenjamin Herrenschmidt 632cbbcf340SKumar Gala while (1) { 633dc0e643aSIan Munsie base_32 = be32_to_cpup(reserve_map_32++); 634dc0e643aSIan Munsie size_32 = be32_to_cpup(reserve_map_32++); 635cbbcf340SKumar Gala if (size_32 == 0) 636cbbcf340SKumar Gala break; 637329dda08SKumar Gala DBG("reserving: %x -> %x\n", base_32, size_32); 63895f72d1eSYinghai Lu memblock_reserve(base_32, size_32); 639cbbcf340SKumar Gala } 640cbbcf340SKumar Gala return; 641cbbcf340SKumar Gala } 642cbbcf340SKumar Gala #endif 6439b6b563cSPaul Mackerras } 6449b6b563cSPaul Mackerras 6459b6b563cSPaul Mackerras void __init early_init_devtree(void *params) 6469b6b563cSPaul Mackerras { 64749a84965SBecky Bruce phys_addr_t limit; 6486ca4f749SHollis Blanchard 64944348105SGeoff Levand DBG(" -> early_init_devtree(%p)\n", params); 6509b6b563cSPaul Mackerras 651ad72a279SMichael Ellerman /* Too early to BUG_ON(), do it by hand */ 652ad72a279SMichael Ellerman if (!early_init_dt_verify(params)) 653ad72a279SMichael Ellerman panic("BUG: Failed verifying flat device tree, bad version?"); 654ad72a279SMichael Ellerman 655458148c0SMichael Ellerman #ifdef CONFIG_PPC_RTAS 656458148c0SMichael Ellerman /* Some machines might need RTAS info for debugging, grab it now. */ 657458148c0SMichael Ellerman of_scan_flat_dt(early_init_dt_scan_rtas, NULL); 658458148c0SMichael Ellerman #endif 659458148c0SMichael Ellerman 66014a43e69SBenjamin Herrenschmidt #ifdef CONFIG_PPC_POWERNV 66114a43e69SBenjamin Herrenschmidt /* Some machines might need OPAL info for debugging, grab it now. */ 66214a43e69SBenjamin Herrenschmidt of_scan_flat_dt(early_init_dt_scan_opal, NULL); 66314a43e69SBenjamin Herrenschmidt #endif 66414a43e69SBenjamin Herrenschmidt 665eb39c880SMahesh Salgaonkar #ifdef CONFIG_FA_DUMP 666eb39c880SMahesh Salgaonkar /* scan tree to see if dump is active during last boot */ 667eb39c880SMahesh Salgaonkar of_scan_flat_dt(early_init_dt_scan_fw_dump, NULL); 668eb39c880SMahesh Salgaonkar #endif 669eb39c880SMahesh Salgaonkar 6709b6b563cSPaul Mackerras /* Retrieve various informations from the /chosen node of the 6719b6b563cSPaul Mackerras * device-tree, including the platform type, initrd location and 6729b6b563cSPaul Mackerras * size, TCE reserve, and more ... 6739b6b563cSPaul Mackerras */ 6743e47d147SAnton Blanchard of_scan_flat_dt(early_init_dt_scan_chosen_ppc, boot_command_line); 6759b6b563cSPaul Mackerras 67695f72d1eSYinghai Lu /* Scan memory nodes and rebuild MEMBLOCKs */ 6773c726f8dSBenjamin Herrenschmidt of_scan_flat_dt(early_init_dt_scan_root, NULL); 67851975db0SGrant Likely of_scan_flat_dt(early_init_dt_scan_memory_ppc, NULL); 679846f77b0SMichael Ellerman 680846f77b0SMichael Ellerman parse_early_param(); 681846f77b0SMichael Ellerman 682ba14f649SKumar Gala /* make sure we've parsed cmdline for mem= before this */ 683ba14f649SKumar Gala if (memory_limit) 684a84fcd46SSuzuki Poulose first_memblock_size = min_t(u64, first_memblock_size, memory_limit); 685ba14f649SKumar Gala setup_initial_memory_limit(memstart_addr, first_memblock_size); 68695f72d1eSYinghai Lu /* Reserve MEMBLOCK regions used by kernel, initrd, dt, etc... */ 68795f72d1eSYinghai Lu memblock_reserve(PHYSICAL_START, __pa(klimit) - PHYSICAL_START); 688549e8152SPaul Mackerras /* If relocatable, reserve first 32k for interrupt vectors etc. */ 689549e8152SPaul Mackerras if (PHYSICAL_START > MEMORY_START) 69095f72d1eSYinghai Lu memblock_reserve(MEMORY_START, 0x8000); 69147310413SMichael Ellerman reserve_kdump_trampoline(); 692eb39c880SMahesh Salgaonkar #ifdef CONFIG_FA_DUMP 693eb39c880SMahesh Salgaonkar /* 694eb39c880SMahesh Salgaonkar * If we fail to reserve memory for firmware-assisted dump then 695eb39c880SMahesh Salgaonkar * fallback to kexec based kdump. 696eb39c880SMahesh Salgaonkar */ 697eb39c880SMahesh Salgaonkar if (fadump_reserve_mem() == 0) 698eb39c880SMahesh Salgaonkar #endif 69935dd5432SMichael Ellerman reserve_crashkernel(); 7009b6b563cSPaul Mackerras early_reserve_mem(); 7019b6b563cSPaul Mackerras 70214ed7409SAnton Blanchard /* Ensure that total memory size is page-aligned. */ 7036fbef13cSTejun Heo limit = ALIGN(memory_limit ?: memblock_phys_mem_size(), PAGE_SIZE); 70495f72d1eSYinghai Lu memblock_enforce_memory_limit(limit); 7056ca4f749SHollis Blanchard 7061aadc056STejun Heo memblock_allow_resize(); 70795f72d1eSYinghai Lu memblock_dump_all(); 7082babf5c2SMichael Ellerman 70995f72d1eSYinghai Lu DBG("Phys. mem: %llx\n", memblock_phys_mem_size()); 7102babf5c2SMichael Ellerman 7112babf5c2SMichael Ellerman /* We may need to relocate the flat tree, do it now. 7122babf5c2SMichael Ellerman * FIXME .. and the initrd too? */ 7132babf5c2SMichael Ellerman move_device_tree(); 7142babf5c2SMichael Ellerman 7151426d5a3SMichael Ellerman allocate_pacas(); 7161426d5a3SMichael Ellerman 7179b6b563cSPaul Mackerras DBG("Scanning CPUs ...\n"); 7189b6b563cSPaul Mackerras 71925985edcSLucas De Marchi /* Retrieve CPU related informations from the flat tree 7203c726f8dSBenjamin Herrenschmidt * (altivec support, boot CPU ID, ...) 7219b6b563cSPaul Mackerras */ 7223c726f8dSBenjamin Herrenschmidt of_scan_flat_dt(early_init_dt_scan_cpus, NULL); 72336ae37e3SBenjamin Herrenschmidt if (boot_cpuid < 0) { 724d939be3aSMasanari Iida printk("Failed to identify boot CPU !\n"); 72536ae37e3SBenjamin Herrenschmidt BUG(); 72636ae37e3SBenjamin Herrenschmidt } 7279b6b563cSPaul Mackerras 7287ac87abbSMatt Evans #if defined(CONFIG_SMP) && defined(CONFIG_PPC64) 7297ac87abbSMatt Evans /* We'll later wait for secondaries to check in; there are 7307ac87abbSMatt Evans * NCPUS-1 non-boot CPUs :-) 7317ac87abbSMatt Evans */ 7327ac87abbSMatt Evans spinning_secondaries = boot_cpu_count - 1; 7337ac87abbSMatt Evans #endif 7347ac87abbSMatt Evans 73555672ecfSMahesh Salgaonkar #ifdef CONFIG_PPC_POWERNV 73655672ecfSMahesh Salgaonkar /* Scan and build the list of machine check recoverable ranges */ 73755672ecfSMahesh Salgaonkar of_scan_flat_dt(early_init_dt_scan_recoverable_ranges, NULL); 73855672ecfSMahesh Salgaonkar #endif 73955672ecfSMahesh Salgaonkar 7409b6b563cSPaul Mackerras DBG(" <- early_init_devtree()\n"); 7419b6b563cSPaul Mackerras } 7429b6b563cSPaul Mackerras 743b27652ddSKevin Hao #ifdef CONFIG_RELOCATABLE 744b27652ddSKevin Hao /* 745b27652ddSKevin Hao * This function run before early_init_devtree, so we have to init 746b27652ddSKevin Hao * initial_boot_params. 747b27652ddSKevin Hao */ 748b27652ddSKevin Hao void __init early_get_first_memblock_info(void *params, phys_addr_t *size) 749b27652ddSKevin Hao { 750b27652ddSKevin Hao /* Setup flat device-tree pointer */ 751b27652ddSKevin Hao initial_boot_params = params; 752b27652ddSKevin Hao 753b27652ddSKevin Hao /* 754b27652ddSKevin Hao * Scan the memory nodes and set add_mem_to_memblock to 0 to avoid 755b27652ddSKevin Hao * mess the memblock. 756b27652ddSKevin Hao */ 757b27652ddSKevin Hao add_mem_to_memblock = 0; 758b27652ddSKevin Hao of_scan_flat_dt(early_init_dt_scan_root, NULL); 759b27652ddSKevin Hao of_scan_flat_dt(early_init_dt_scan_memory_ppc, NULL); 760b27652ddSKevin Hao add_mem_to_memblock = 1; 761b27652ddSKevin Hao 762b27652ddSKevin Hao if (size) 763b27652ddSKevin Hao *size = first_memblock_size; 764b27652ddSKevin Hao } 765b27652ddSKevin Hao #endif 766b27652ddSKevin Hao 7679b6b563cSPaul Mackerras /******* 7689b6b563cSPaul Mackerras * 7699b6b563cSPaul Mackerras * New implementation of the OF "find" APIs, return a refcounted 7709b6b563cSPaul Mackerras * object, call of_node_put() when done. The device tree and list 7719b6b563cSPaul Mackerras * are protected by a rw_lock. 7729b6b563cSPaul Mackerras * 7739b6b563cSPaul Mackerras * Note that property management will need some locking as well, 7749b6b563cSPaul Mackerras * this isn't dealt with yet. 7759b6b563cSPaul Mackerras * 7769b6b563cSPaul Mackerras *******/ 7779b6b563cSPaul Mackerras 7789b6b563cSPaul Mackerras /** 779b37193b7SBenjamin Herrenschmidt * of_get_ibm_chip_id - Returns the IBM "chip-id" of a device 780b37193b7SBenjamin Herrenschmidt * @np: device node of the device 781b37193b7SBenjamin Herrenschmidt * 782b37193b7SBenjamin Herrenschmidt * This looks for a property "ibm,chip-id" in the node or any 783b37193b7SBenjamin Herrenschmidt * of its parents and returns its content, or -1 if it cannot 784b37193b7SBenjamin Herrenschmidt * be found. 785b37193b7SBenjamin Herrenschmidt */ 786b37193b7SBenjamin Herrenschmidt int of_get_ibm_chip_id(struct device_node *np) 787b37193b7SBenjamin Herrenschmidt { 788b37193b7SBenjamin Herrenschmidt of_node_get(np); 789b37193b7SBenjamin Herrenschmidt while (np) { 7901856f50cSChristophe Jaillet u32 chip_id; 791b37193b7SBenjamin Herrenschmidt 7921856f50cSChristophe Jaillet /* 7931856f50cSChristophe Jaillet * Skiboot may produce memory nodes that contain more than one 7941856f50cSChristophe Jaillet * cell in chip-id, we only read the first one here. 7951856f50cSChristophe Jaillet */ 7961856f50cSChristophe Jaillet if (!of_property_read_u32(np, "ibm,chip-id", &chip_id)) { 797b37193b7SBenjamin Herrenschmidt of_node_put(np); 7981856f50cSChristophe Jaillet return chip_id; 799b37193b7SBenjamin Herrenschmidt } 80016c1d606SMichael Ellerman 80116c1d606SMichael Ellerman np = of_get_next_parent(np); 802b37193b7SBenjamin Herrenschmidt } 803b37193b7SBenjamin Herrenschmidt return -1; 804b37193b7SBenjamin Herrenschmidt } 805b130e7c0SDan Streetman EXPORT_SYMBOL(of_get_ibm_chip_id); 806b37193b7SBenjamin Herrenschmidt 8073eb906c6SMichael Ellerman /** 8083eb906c6SMichael Ellerman * cpu_to_chip_id - Return the cpus chip-id 8093eb906c6SMichael Ellerman * @cpu: The logical cpu number. 8103eb906c6SMichael Ellerman * 8113eb906c6SMichael Ellerman * Return the value of the ibm,chip-id property corresponding to the given 8123eb906c6SMichael Ellerman * logical cpu number. If the chip-id can not be found, returns -1. 8133eb906c6SMichael Ellerman */ 8143eb906c6SMichael Ellerman int cpu_to_chip_id(int cpu) 8153eb906c6SMichael Ellerman { 8163eb906c6SMichael Ellerman struct device_node *np; 8173eb906c6SMichael Ellerman 8183eb906c6SMichael Ellerman np = of_get_cpu_node(cpu, NULL); 8193eb906c6SMichael Ellerman if (!np) 8203eb906c6SMichael Ellerman return -1; 8213eb906c6SMichael Ellerman 8223eb906c6SMichael Ellerman of_node_put(np); 8233eb906c6SMichael Ellerman return of_get_ibm_chip_id(np); 8243eb906c6SMichael Ellerman } 8253eb906c6SMichael Ellerman EXPORT_SYMBOL(cpu_to_chip_id); 8263eb906c6SMichael Ellerman 827819d5965SSudeep KarkadaNagesha bool arch_match_cpu_phys_id(int cpu, u64 phys_id) 828819d5965SSudeep KarkadaNagesha { 829819d5965SSudeep KarkadaNagesha return (int)phys_id == get_hard_smp_processor_id(cpu); 830819d5965SSudeep KarkadaNagesha } 831