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> 327a4571aeSMichael Ellerman #include <linux/debugfs.h> 330ebfff14SBenjamin Herrenschmidt #include <linux/irq.h> 3495f72d1eSYinghai Lu #include <linux/memblock.h> 351cf3d8b3SNathan Fontenot #include <linux/of.h> 369b6b563cSPaul Mackerras 379b6b563cSPaul Mackerras #include <asm/prom.h> 389b6b563cSPaul Mackerras #include <asm/rtas.h> 399b6b563cSPaul Mackerras #include <asm/page.h> 409b6b563cSPaul Mackerras #include <asm/processor.h> 419b6b563cSPaul Mackerras #include <asm/irq.h> 429b6b563cSPaul Mackerras #include <asm/io.h> 430cc4746cSMichael Ellerman #include <asm/kdump.h> 449b6b563cSPaul Mackerras #include <asm/smp.h> 459b6b563cSPaul Mackerras #include <asm/mmu.h> 461426d5a3SMichael Ellerman #include <asm/paca.h> 479b6b563cSPaul Mackerras #include <asm/pgtable.h> 489b6b563cSPaul Mackerras #include <asm/pci.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); 120087f79c4SJeremy Kerr size = be32_to_cpu(initial_boot_params->totalsize); 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); 1272babf5c2SMichael Ellerman initial_boot_params = (struct boot_param_header *)p; 1282babf5c2SMichael Ellerman DBG("Moved device tree to 0x%p\n", p); 1292babf5c2SMichael Ellerman } 1302babf5c2SMichael Ellerman 1312babf5c2SMichael Ellerman DBG("<- move_device_tree\n"); 1322babf5c2SMichael Ellerman } 1339b6b563cSPaul Mackerras 134d205819eSPaul Mackerras /* 135d205819eSPaul Mackerras * ibm,pa-features is a per-cpu property that contains a string of 136d205819eSPaul Mackerras * attribute descriptors, each of which has a 2 byte header plus up 137d205819eSPaul Mackerras * to 254 bytes worth of processor attribute bits. First header 138d205819eSPaul Mackerras * byte specifies the number of bytes following the header. 139d205819eSPaul Mackerras * Second header byte is an "attribute-specifier" type, of which 140d205819eSPaul Mackerras * zero is the only currently-defined value. 141d205819eSPaul Mackerras * Implementation: Pass in the byte and bit offset for the feature 142d205819eSPaul Mackerras * that we are interested in. The function will return -1 if the 143d205819eSPaul Mackerras * pa-features property is missing, or a 1/0 to indicate if the feature 144d205819eSPaul Mackerras * is supported/not supported. Note that the bit numbers are 145d205819eSPaul Mackerras * big-endian to match the definition in PAPR. 146d205819eSPaul Mackerras */ 147d205819eSPaul Mackerras static struct ibm_pa_feature { 148d205819eSPaul Mackerras unsigned long cpu_features; /* CPU_FTR_xxx bit */ 14944ae3ab3SMatt Evans unsigned long mmu_features; /* MMU_FTR_xxx bit */ 150d205819eSPaul Mackerras unsigned int cpu_user_ftrs; /* PPC_FEATURE_xxx bit */ 151d205819eSPaul Mackerras unsigned char pabyte; /* byte number in ibm,pa-features */ 152d205819eSPaul Mackerras unsigned char pabit; /* bit number (big-endian) */ 153d205819eSPaul Mackerras unsigned char invert; /* if 1, pa bit set => clear feature */ 154d205819eSPaul Mackerras } ibm_pa_features[] __initdata = { 15544ae3ab3SMatt Evans {0, 0, PPC_FEATURE_HAS_MMU, 0, 0, 0}, 15644ae3ab3SMatt Evans {0, 0, PPC_FEATURE_HAS_FPU, 0, 1, 0}, 15744ae3ab3SMatt Evans {0, MMU_FTR_SLB, 0, 0, 2, 0}, 15844ae3ab3SMatt Evans {CPU_FTR_CTRL, 0, 0, 0, 3, 0}, 15944ae3ab3SMatt Evans {CPU_FTR_NOEXECUTE, 0, 0, 0, 6, 0}, 16044ae3ab3SMatt Evans {CPU_FTR_NODSISRALIGN, 0, 0, 1, 1, 1}, 16144ae3ab3SMatt Evans {0, MMU_FTR_CI_LARGE_PAGE, 0, 1, 2, 0}, 162339d76c5SPaul Mackerras {CPU_FTR_REAL_LE, PPC_FEATURE_TRUE_LE, 5, 0, 0}, 163d205819eSPaul Mackerras }; 164d205819eSPaul Mackerras 165974a76f5SPaul Mackerras static void __init scan_features(unsigned long node, unsigned char *ftrs, 166974a76f5SPaul Mackerras unsigned long tablelen, 167974a76f5SPaul Mackerras struct ibm_pa_feature *fp, 168974a76f5SPaul Mackerras unsigned long ft_size) 169d205819eSPaul Mackerras { 170974a76f5SPaul Mackerras unsigned long i, len, bit; 171d205819eSPaul Mackerras 172d205819eSPaul Mackerras /* find descriptor with type == 0 */ 173d205819eSPaul Mackerras for (;;) { 174d205819eSPaul Mackerras if (tablelen < 3) 175d205819eSPaul Mackerras return; 176974a76f5SPaul Mackerras len = 2 + ftrs[0]; 177d205819eSPaul Mackerras if (tablelen < len) 178d205819eSPaul Mackerras return; /* descriptor 0 not found */ 179974a76f5SPaul Mackerras if (ftrs[1] == 0) 180d205819eSPaul Mackerras break; 181d205819eSPaul Mackerras tablelen -= len; 182974a76f5SPaul Mackerras ftrs += len; 183d205819eSPaul Mackerras } 184d205819eSPaul Mackerras 185d205819eSPaul Mackerras /* loop over bits we know about */ 186974a76f5SPaul Mackerras for (i = 0; i < ft_size; ++i, ++fp) { 187974a76f5SPaul Mackerras if (fp->pabyte >= ftrs[0]) 188d205819eSPaul Mackerras continue; 189974a76f5SPaul Mackerras bit = (ftrs[2 + fp->pabyte] >> (7 - fp->pabit)) & 1; 190d205819eSPaul Mackerras if (bit ^ fp->invert) { 191d205819eSPaul Mackerras cur_cpu_spec->cpu_features |= fp->cpu_features; 192d205819eSPaul Mackerras cur_cpu_spec->cpu_user_features |= fp->cpu_user_ftrs; 19344ae3ab3SMatt Evans cur_cpu_spec->mmu_features |= fp->mmu_features; 194d205819eSPaul Mackerras } else { 195d205819eSPaul Mackerras cur_cpu_spec->cpu_features &= ~fp->cpu_features; 196d205819eSPaul Mackerras cur_cpu_spec->cpu_user_features &= ~fp->cpu_user_ftrs; 19744ae3ab3SMatt Evans cur_cpu_spec->mmu_features &= ~fp->mmu_features; 198d205819eSPaul Mackerras } 199d205819eSPaul Mackerras } 200d205819eSPaul Mackerras } 201d205819eSPaul Mackerras 202974a76f5SPaul Mackerras static void __init check_cpu_pa_features(unsigned long node) 203974a76f5SPaul Mackerras { 204974a76f5SPaul Mackerras unsigned char *pa_ftrs; 205974a76f5SPaul Mackerras unsigned long tablelen; 206974a76f5SPaul Mackerras 207974a76f5SPaul Mackerras pa_ftrs = of_get_flat_dt_prop(node, "ibm,pa-features", &tablelen); 208974a76f5SPaul Mackerras if (pa_ftrs == NULL) 209974a76f5SPaul Mackerras return; 210974a76f5SPaul Mackerras 211974a76f5SPaul Mackerras scan_features(node, pa_ftrs, tablelen, 212974a76f5SPaul Mackerras ibm_pa_features, ARRAY_SIZE(ibm_pa_features)); 213974a76f5SPaul Mackerras } 214974a76f5SPaul Mackerras 21594491685SBenjamin Herrenschmidt #ifdef CONFIG_PPC_STD_MMU_64 216584f8b71SMichael Neuling static void __init check_cpu_slb_size(unsigned long node) 217584f8b71SMichael Neuling { 218584f8b71SMichael Neuling u32 *slb_size_ptr; 219584f8b71SMichael Neuling 220b60c31d8SMichael Neuling slb_size_ptr = of_get_flat_dt_prop(node, "slb-size", NULL); 221b60c31d8SMichael Neuling if (slb_size_ptr != NULL) { 222b60c31d8SMichael Neuling mmu_slb_size = *slb_size_ptr; 223b60c31d8SMichael Neuling return; 224b60c31d8SMichael Neuling } 225584f8b71SMichael Neuling slb_size_ptr = of_get_flat_dt_prop(node, "ibm,slb-size", NULL); 226584f8b71SMichael Neuling if (slb_size_ptr != NULL) { 227584f8b71SMichael Neuling mmu_slb_size = *slb_size_ptr; 228584f8b71SMichael Neuling } 229584f8b71SMichael Neuling } 230584f8b71SMichael Neuling #else 231584f8b71SMichael Neuling #define check_cpu_slb_size(node) do { } while(0) 232584f8b71SMichael Neuling #endif 233584f8b71SMichael Neuling 234974a76f5SPaul Mackerras static struct feature_property { 235974a76f5SPaul Mackerras const char *name; 236974a76f5SPaul Mackerras u32 min_value; 237974a76f5SPaul Mackerras unsigned long cpu_feature; 238974a76f5SPaul Mackerras unsigned long cpu_user_ftr; 239974a76f5SPaul Mackerras } feature_properties[] __initdata = { 240974a76f5SPaul Mackerras #ifdef CONFIG_ALTIVEC 241974a76f5SPaul Mackerras {"altivec", 0, CPU_FTR_ALTIVEC, PPC_FEATURE_HAS_ALTIVEC}, 242974a76f5SPaul Mackerras {"ibm,vmx", 1, CPU_FTR_ALTIVEC, PPC_FEATURE_HAS_ALTIVEC}, 243974a76f5SPaul Mackerras #endif /* CONFIG_ALTIVEC */ 244b962ce9dSMichael Neuling #ifdef CONFIG_VSX 245b962ce9dSMichael Neuling /* Yes, this _really_ is ibm,vmx == 2 to enable VSX */ 246b962ce9dSMichael Neuling {"ibm,vmx", 2, CPU_FTR_VSX, PPC_FEATURE_HAS_VSX}, 247b962ce9dSMichael Neuling #endif /* CONFIG_VSX */ 248974a76f5SPaul Mackerras #ifdef CONFIG_PPC64 249974a76f5SPaul Mackerras {"ibm,dfp", 1, 0, PPC_FEATURE_HAS_DFP}, 250974a76f5SPaul Mackerras {"ibm,purr", 1, CPU_FTR_PURR, 0}, 251974a76f5SPaul Mackerras {"ibm,spurr", 1, CPU_FTR_SPURR, 0}, 252974a76f5SPaul Mackerras #endif /* CONFIG_PPC64 */ 253974a76f5SPaul Mackerras }; 254974a76f5SPaul Mackerras 25514b3d926SValentine Barshak #if defined(CONFIG_44x) && defined(CONFIG_PPC_FPU) 25614b3d926SValentine Barshak static inline void identical_pvr_fixup(unsigned long node) 25714b3d926SValentine Barshak { 25814b3d926SValentine Barshak unsigned int pvr; 25914b3d926SValentine Barshak char *model = of_get_flat_dt_prop(node, "model", NULL); 26014b3d926SValentine Barshak 26114b3d926SValentine Barshak /* 26214b3d926SValentine Barshak * Since 440GR(x)/440EP(x) processors have the same pvr, 26314b3d926SValentine Barshak * we check the node path and set bit 28 in the cur_cpu_spec 26414b3d926SValentine Barshak * pvr for EP(x) processor version. This bit is always 0 in 26514b3d926SValentine Barshak * the "real" pvr. Then we call identify_cpu again with 26614b3d926SValentine Barshak * the new logical pvr to enable FPU support. 26714b3d926SValentine Barshak */ 26814b3d926SValentine Barshak if (model && strstr(model, "440EP")) { 26914b3d926SValentine Barshak pvr = cur_cpu_spec->pvr_value | 0x8; 27014b3d926SValentine Barshak identify_cpu(0, pvr); 27114b3d926SValentine Barshak DBG("Using logical pvr %x for %s\n", pvr, model); 27214b3d926SValentine Barshak } 27314b3d926SValentine Barshak } 27414b3d926SValentine Barshak #else 27514b3d926SValentine Barshak #define identical_pvr_fixup(node) do { } while(0) 27614b3d926SValentine Barshak #endif 27714b3d926SValentine Barshak 278974a76f5SPaul Mackerras static void __init check_cpu_feature_properties(unsigned long node) 279974a76f5SPaul Mackerras { 280974a76f5SPaul Mackerras unsigned long i; 281974a76f5SPaul Mackerras struct feature_property *fp = feature_properties; 282974a76f5SPaul Mackerras const u32 *prop; 283974a76f5SPaul Mackerras 284974a76f5SPaul Mackerras for (i = 0; i < ARRAY_SIZE(feature_properties); ++i, ++fp) { 285974a76f5SPaul Mackerras prop = of_get_flat_dt_prop(node, fp->name, NULL); 286974a76f5SPaul Mackerras if (prop && *prop >= fp->min_value) { 287974a76f5SPaul Mackerras cur_cpu_spec->cpu_features |= fp->cpu_feature; 288974a76f5SPaul Mackerras cur_cpu_spec->cpu_user_features |= fp->cpu_user_ftr; 289974a76f5SPaul Mackerras } 290974a76f5SPaul Mackerras } 291974a76f5SPaul Mackerras } 292974a76f5SPaul Mackerras 2939b6b563cSPaul Mackerras static int __init early_init_dt_scan_cpus(unsigned long node, 2944df20460SAnton Blanchard const char *uname, int depth, 2954df20460SAnton Blanchard void *data) 2969b6b563cSPaul Mackerras { 2974df20460SAnton Blanchard char *type = of_get_flat_dt_prop(node, "device_type", NULL); 298974a76f5SPaul Mackerras const u32 *prop; 299974a76f5SPaul Mackerras const u32 *intserv; 3004df20460SAnton Blanchard int i, nthreads; 3014df20460SAnton Blanchard unsigned long len; 3029d07bc84SBenjamin Herrenschmidt int found = -1; 303208b3a4cSBenjamin Herrenschmidt int found_thread = 0; 3049b6b563cSPaul Mackerras 3059b6b563cSPaul Mackerras /* We are scanning "cpu" nodes only */ 3069b6b563cSPaul Mackerras if (type == NULL || strcmp(type, "cpu") != 0) 3079b6b563cSPaul Mackerras return 0; 3089b6b563cSPaul Mackerras 3094df20460SAnton Blanchard /* Get physical cpuid */ 3104df20460SAnton Blanchard intserv = of_get_flat_dt_prop(node, "ibm,ppc-interrupt-server#s", &len); 3114df20460SAnton Blanchard if (intserv) { 3124df20460SAnton Blanchard nthreads = len / sizeof(int); 3139b6b563cSPaul Mackerras } else { 3144df20460SAnton Blanchard intserv = of_get_flat_dt_prop(node, "reg", NULL); 3154df20460SAnton Blanchard nthreads = 1; 3164df20460SAnton Blanchard } 3174df20460SAnton Blanchard 3184df20460SAnton Blanchard /* 3194df20460SAnton Blanchard * Now see if any of these threads match our boot cpu. 3204df20460SAnton Blanchard * NOTE: This must match the parsing done in smp_setup_cpu_maps. 3214df20460SAnton Blanchard */ 3224df20460SAnton Blanchard for (i = 0; i < nthreads; i++) { 3234df20460SAnton Blanchard /* 3244df20460SAnton Blanchard * version 2 of the kexec param format adds the phys cpuid of 3254df20460SAnton Blanchard * booted proc. 3264df20460SAnton Blanchard */ 327208b3a4cSBenjamin Herrenschmidt if (initial_boot_params->version >= 2) { 328208b3a4cSBenjamin Herrenschmidt if (intserv[i] == initial_boot_params->boot_cpuid_phys) { 3299d07bc84SBenjamin Herrenschmidt found = boot_cpu_count; 330208b3a4cSBenjamin Herrenschmidt found_thread = i; 331208b3a4cSBenjamin Herrenschmidt } 3324df20460SAnton Blanchard } else { 3334df20460SAnton Blanchard /* 3344df20460SAnton Blanchard * Check if it's the boot-cpu, set it's hw index now, 3354df20460SAnton Blanchard * unfortunately this format did not support booting 3364df20460SAnton Blanchard * off secondary threads. 3374df20460SAnton Blanchard */ 3383c726f8dSBenjamin Herrenschmidt if (of_get_flat_dt_prop(node, 3399d07bc84SBenjamin Herrenschmidt "linux,boot-cpu", NULL) != NULL) 3409d07bc84SBenjamin Herrenschmidt found = boot_cpu_count; 3419b6b563cSPaul Mackerras } 3424df20460SAnton Blanchard #ifdef CONFIG_SMP 3434df20460SAnton Blanchard /* logical cpu id is always 0 on UP kernels */ 3449d07bc84SBenjamin Herrenschmidt boot_cpu_count++; 3454df20460SAnton Blanchard #endif 3464df20460SAnton Blanchard } 3474df20460SAnton Blanchard 3489d07bc84SBenjamin Herrenschmidt if (found >= 0) { 3499d07bc84SBenjamin Herrenschmidt DBG("boot cpu: logical %d physical %d\n", found, 350208b3a4cSBenjamin Herrenschmidt intserv[found_thread]); 3519d07bc84SBenjamin Herrenschmidt boot_cpuid = found; 352208b3a4cSBenjamin Herrenschmidt set_hard_smp_processor_id(found, intserv[found_thread]); 353974a76f5SPaul Mackerras 354974a76f5SPaul Mackerras /* 355974a76f5SPaul Mackerras * PAPR defines "logical" PVR values for cpus that 356974a76f5SPaul Mackerras * meet various levels of the architecture: 357974a76f5SPaul Mackerras * 0x0f000001 Architecture version 2.04 358974a76f5SPaul Mackerras * 0x0f000002 Architecture version 2.05 359974a76f5SPaul Mackerras * If the cpu-version property in the cpu node contains 360974a76f5SPaul Mackerras * such a value, we call identify_cpu again with the 361974a76f5SPaul Mackerras * logical PVR value in order to use the cpu feature 362974a76f5SPaul Mackerras * bits appropriate for the architecture level. 363974a76f5SPaul Mackerras * 364974a76f5SPaul Mackerras * A POWER6 partition in "POWER6 architected" mode 365974a76f5SPaul Mackerras * uses the 0x0f000002 PVR value; in POWER5+ mode 366974a76f5SPaul Mackerras * it uses 0x0f000001. 367974a76f5SPaul Mackerras */ 368974a76f5SPaul Mackerras prop = of_get_flat_dt_prop(node, "cpu-version", NULL); 369974a76f5SPaul Mackerras if (prop && (*prop & 0xff000000) == 0x0f000000) 370974a76f5SPaul Mackerras identify_cpu(0, *prop); 37114b3d926SValentine Barshak 37214b3d926SValentine Barshak identical_pvr_fixup(node); 3734df20460SAnton Blanchard } 3749b6b563cSPaul Mackerras 375974a76f5SPaul Mackerras check_cpu_feature_properties(node); 376d205819eSPaul Mackerras check_cpu_pa_features(node); 377584f8b71SMichael Neuling check_cpu_slb_size(node); 378d205819eSPaul Mackerras 3799b6b563cSPaul Mackerras #ifdef CONFIG_PPC_PSERIES 3804df20460SAnton Blanchard if (nthreads > 1) 3819b6b563cSPaul Mackerras cur_cpu_spec->cpu_features |= CPU_FTR_SMT; 3824df20460SAnton Blanchard else 3834df20460SAnton Blanchard cur_cpu_spec->cpu_features &= ~CPU_FTR_SMT; 3849b6b563cSPaul Mackerras #endif 3859b6b563cSPaul Mackerras 3869b6b563cSPaul Mackerras return 0; 3879b6b563cSPaul Mackerras } 3889b6b563cSPaul Mackerras 38932c97689SGrant Likely int __init early_init_dt_scan_chosen_ppc(unsigned long node, const char *uname, 39032c97689SGrant Likely int depth, void *data) 3919b6b563cSPaul Mackerras { 3929b6b563cSPaul Mackerras unsigned long *lprop; 3939b6b563cSPaul Mackerras 39432c97689SGrant Likely /* Use common scan routine to determine if this is the chosen node */ 39532c97689SGrant Likely if (early_init_dt_scan_chosen(node, uname, depth, data) == 0) 39632c97689SGrant Likely return 0; 39732c97689SGrant Likely 3989b6b563cSPaul Mackerras #ifdef CONFIG_PPC64 3999b6b563cSPaul Mackerras /* check if iommu is forced on or off */ 4003c726f8dSBenjamin Herrenschmidt if (of_get_flat_dt_prop(node, "linux,iommu-off", NULL) != NULL) 4019b6b563cSPaul Mackerras iommu_is_off = 1; 4023c726f8dSBenjamin Herrenschmidt if (of_get_flat_dt_prop(node, "linux,iommu-force-on", NULL) != NULL) 4039b6b563cSPaul Mackerras iommu_force_on = 1; 4049b6b563cSPaul Mackerras #endif 4059b6b563cSPaul Mackerras 4062babf5c2SMichael Ellerman /* mem=x on the command line is the preferred mechanism */ 4073c726f8dSBenjamin Herrenschmidt lprop = of_get_flat_dt_prop(node, "linux,memory-limit", NULL); 4089b6b563cSPaul Mackerras if (lprop) 4099b6b563cSPaul Mackerras memory_limit = *lprop; 4109b6b563cSPaul Mackerras 4119b6b563cSPaul Mackerras #ifdef CONFIG_PPC64 4123c726f8dSBenjamin Herrenschmidt lprop = of_get_flat_dt_prop(node, "linux,tce-alloc-start", NULL); 4139b6b563cSPaul Mackerras if (lprop) 4149b6b563cSPaul Mackerras tce_alloc_start = *lprop; 4153c726f8dSBenjamin Herrenschmidt lprop = of_get_flat_dt_prop(node, "linux,tce-alloc-end", NULL); 4169b6b563cSPaul Mackerras if (lprop) 4179b6b563cSPaul Mackerras tce_alloc_end = *lprop; 4189b6b563cSPaul Mackerras #endif 4199b6b563cSPaul Mackerras 420dcee3036SMichael Ellerman #ifdef CONFIG_KEXEC 42163277161SStephen Rothwell lprop = of_get_flat_dt_prop(node, "linux,crashkernel-base", NULL); 422dcee3036SMichael Ellerman if (lprop) 423dcee3036SMichael Ellerman crashk_res.start = *lprop; 424dcee3036SMichael Ellerman 42563277161SStephen Rothwell lprop = of_get_flat_dt_prop(node, "linux,crashkernel-size", NULL); 426dcee3036SMichael Ellerman if (lprop) 427dcee3036SMichael Ellerman crashk_res.end = crashk_res.start + *lprop - 1; 428dcee3036SMichael Ellerman #endif 42932c97689SGrant Likely 43032c97689SGrant Likely /* break now */ 43132c97689SGrant Likely return 1; 4329b6b563cSPaul Mackerras } 4339b6b563cSPaul Mackerras 4340204568aSPaul Mackerras #ifdef CONFIG_PPC_PSERIES 4350204568aSPaul Mackerras /* 4360204568aSPaul Mackerras * Interpret the ibm,dynamic-memory property in the 4370204568aSPaul Mackerras * /ibm,dynamic-reconfiguration-memory node. 4380204568aSPaul Mackerras * This contains a list of memory blocks along with NUMA affinity 4390204568aSPaul Mackerras * information. 4400204568aSPaul Mackerras */ 4410204568aSPaul Mackerras static int __init early_init_dt_scan_drconf_memory(unsigned long node) 4420204568aSPaul Mackerras { 4430f0b56c3SGrant Likely __be32 *dm, *ls, *usm; 444abe76885SBecky Bruce unsigned long l, n, flags; 44595f72d1eSYinghai Lu u64 base, size, memblock_size; 446cf00085dSChandru unsigned int is_kexec_kdump = 0, rngs; 4470204568aSPaul Mackerras 4483fdfd990SBenjamin Herrenschmidt ls = of_get_flat_dt_prop(node, "ibm,lmb-size", &l); 4490f0b56c3SGrant Likely if (ls == NULL || l < dt_root_size_cells * sizeof(__be32)) 4500204568aSPaul Mackerras return 0; 45195f72d1eSYinghai Lu memblock_size = dt_mem_next_cell(dt_root_size_cells, &ls); 4520204568aSPaul Mackerras 45363277161SStephen Rothwell dm = of_get_flat_dt_prop(node, "ibm,dynamic-memory", &l); 4540f0b56c3SGrant Likely if (dm == NULL || l < sizeof(__be32)) 4550204568aSPaul Mackerras return 0; 4560204568aSPaul Mackerras 4570204568aSPaul Mackerras n = *dm++; /* number of entries */ 4580f0b56c3SGrant Likely if (l < (n * (dt_root_addr_cells + 4) + 1) * sizeof(__be32)) 4590204568aSPaul Mackerras return 0; 4600204568aSPaul Mackerras 461cf00085dSChandru /* check if this is a kexec/kdump kernel. */ 46263277161SStephen Rothwell usm = of_get_flat_dt_prop(node, "linux,drconf-usable-memory", 463cf00085dSChandru &l); 464cf00085dSChandru if (usm != NULL) 465cf00085dSChandru is_kexec_kdump = 1; 466cf00085dSChandru 4670204568aSPaul Mackerras for (; n != 0; --n) { 4680204568aSPaul Mackerras base = dt_mem_next_cell(dt_root_addr_cells, &dm); 4690204568aSPaul Mackerras flags = dm[3]; 4700204568aSPaul Mackerras /* skip DRC index, pad, assoc. list index, flags */ 4710204568aSPaul Mackerras dm += 4; 4720204568aSPaul Mackerras /* skip this block if the reserved bit is set in flags (0x80) 4730204568aSPaul Mackerras or if the block is not assigned to this partition (0x8) */ 4740204568aSPaul Mackerras if ((flags & 0x80) || !(flags & 0x8)) 4750204568aSPaul Mackerras continue; 47695f72d1eSYinghai Lu size = memblock_size; 477cf00085dSChandru rngs = 1; 478cf00085dSChandru if (is_kexec_kdump) { 479cf00085dSChandru /* 48095f72d1eSYinghai Lu * For each memblock in ibm,dynamic-memory, a corresponding 481cf00085dSChandru * entry in linux,drconf-usable-memory property contains 482cf00085dSChandru * a counter 'p' followed by 'p' (base, size) duple. 483cf00085dSChandru * Now read the counter from 484cf00085dSChandru * linux,drconf-usable-memory property 485cf00085dSChandru */ 486cf00085dSChandru rngs = dt_mem_next_cell(dt_root_size_cells, &usm); 487cf00085dSChandru if (!rngs) /* there are no (base, size) duple */ 488cf00085dSChandru continue; 489cf00085dSChandru } 490cf00085dSChandru do { 491cf00085dSChandru if (is_kexec_kdump) { 492cf00085dSChandru base = dt_mem_next_cell(dt_root_addr_cells, 493cf00085dSChandru &usm); 494cf00085dSChandru size = dt_mem_next_cell(dt_root_size_cells, 495cf00085dSChandru &usm); 496cf00085dSChandru } 4970204568aSPaul Mackerras if (iommu_is_off) { 4980204568aSPaul Mackerras if (base >= 0x80000000ul) 4990204568aSPaul Mackerras continue; 5000204568aSPaul Mackerras if ((base + size) > 0x80000000ul) 5010204568aSPaul Mackerras size = 0x80000000ul - base; 5020204568aSPaul Mackerras } 50395f72d1eSYinghai Lu memblock_add(base, size); 504cf00085dSChandru } while (--rngs); 5050204568aSPaul Mackerras } 50695f72d1eSYinghai Lu memblock_dump_all(); 5070204568aSPaul Mackerras return 0; 5080204568aSPaul Mackerras } 5090204568aSPaul Mackerras #else 5100204568aSPaul Mackerras #define early_init_dt_scan_drconf_memory(node) 0 5110204568aSPaul Mackerras #endif /* CONFIG_PPC_PSERIES */ 5129b6b563cSPaul Mackerras 51351975db0SGrant Likely static int __init early_init_dt_scan_memory_ppc(unsigned long node, 51451975db0SGrant Likely const char *uname, 51551975db0SGrant Likely int depth, void *data) 5169b6b563cSPaul Mackerras { 5170204568aSPaul Mackerras if (depth == 1 && 5180204568aSPaul Mackerras strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0) 5190204568aSPaul Mackerras return early_init_dt_scan_drconf_memory(node); 5200204568aSPaul Mackerras 52151975db0SGrant Likely return early_init_dt_scan_memory(node, uname, depth, data); 52251975db0SGrant Likely } 5239b6b563cSPaul Mackerras 52451975db0SGrant Likely void __init early_init_dt_add_memory_arch(u64 base, u64 size) 52551975db0SGrant Likely { 526cd3db0c4SBenjamin Herrenschmidt #ifdef CONFIG_PPC64 5279b6b563cSPaul Mackerras if (iommu_is_off) { 5289b6b563cSPaul Mackerras if (base >= 0x80000000ul) 52951975db0SGrant Likely return; 5309b6b563cSPaul Mackerras if ((base + size) > 0x80000000ul) 5319b6b563cSPaul Mackerras size = 0x80000000ul - base; 5329b6b563cSPaul Mackerras } 5339b6b563cSPaul Mackerras #endif 53403bf469aSBenjamin Herrenschmidt /* Keep track of the beginning of memory -and- the size of 53503bf469aSBenjamin Herrenschmidt * the very first block in the device-tree as it represents 53603bf469aSBenjamin Herrenschmidt * the RMA on ppc64 server 53703bf469aSBenjamin Herrenschmidt */ 53803bf469aSBenjamin Herrenschmidt if (base < memstart_addr) { 53903bf469aSBenjamin Herrenschmidt memstart_addr = base; 54003bf469aSBenjamin Herrenschmidt first_memblock_size = size; 54103bf469aSBenjamin Herrenschmidt } 542cd3db0c4SBenjamin Herrenschmidt 543cd3db0c4SBenjamin Herrenschmidt /* Add the chunk to the MEMBLOCK list */ 544cd3db0c4SBenjamin Herrenschmidt memblock_add(base, size); 5459b6b563cSPaul Mackerras } 54637dd2badSKumar Gala 547672c5446SGrant Likely void * __init early_init_dt_alloc_memory_arch(u64 size, u64 align) 5484ef7b373SJeremy Kerr { 549672c5446SGrant Likely return __va(memblock_alloc(size, align)); 5504ef7b373SJeremy Kerr } 5514ef7b373SJeremy Kerr 5521406bc2fSJeremy Kerr #ifdef CONFIG_BLK_DEV_INITRD 5531406bc2fSJeremy Kerr void __init early_init_dt_setup_initrd_arch(unsigned long start, 5541406bc2fSJeremy Kerr unsigned long end) 5551406bc2fSJeremy Kerr { 5561406bc2fSJeremy Kerr initrd_start = (unsigned long)__va(start); 5571406bc2fSJeremy Kerr initrd_end = (unsigned long)__va(end); 5581406bc2fSJeremy Kerr initrd_below_start_ok = 1; 5591406bc2fSJeremy Kerr } 5601406bc2fSJeremy Kerr #endif 5611406bc2fSJeremy Kerr 562*c039e3a8SBenjamin Herrenschmidt static void __init early_reserve_mem_dt(void) 5630962e800SJeremy Kerr { 5640962e800SJeremy Kerr unsigned long i, len, dt_root; 5650962e800SJeremy Kerr const __be32 *prop; 5660962e800SJeremy Kerr 5670962e800SJeremy Kerr dt_root = of_get_flat_dt_root(); 5680962e800SJeremy Kerr 5690962e800SJeremy Kerr prop = of_get_flat_dt_prop(dt_root, "reserved-ranges", &len); 5700962e800SJeremy Kerr 5710962e800SJeremy Kerr if (!prop) 572*c039e3a8SBenjamin Herrenschmidt return; 573*c039e3a8SBenjamin Herrenschmidt 574*c039e3a8SBenjamin Herrenschmidt DBG("Found new-style reserved-ranges\n"); 5750962e800SJeremy Kerr 5760962e800SJeremy Kerr /* Each reserved range is an (address,size) pair, 2 cells each, 5770962e800SJeremy Kerr * totalling 4 cells per range. */ 5780962e800SJeremy Kerr for (i = 0; i < len / (sizeof(*prop) * 4); i++) { 5790962e800SJeremy Kerr u64 base, size; 5800962e800SJeremy Kerr 5810962e800SJeremy Kerr base = of_read_number(prop + (i * 4) + 0, 2); 5820962e800SJeremy Kerr size = of_read_number(prop + (i * 4) + 2, 2); 5830962e800SJeremy Kerr 584*c039e3a8SBenjamin Herrenschmidt if (size) { 585*c039e3a8SBenjamin Herrenschmidt DBG("reserving: %llx -> %llx\n", base, size); 5860962e800SJeremy Kerr memblock_reserve(base, size); 5870962e800SJeremy Kerr } 588*c039e3a8SBenjamin Herrenschmidt } 5890962e800SJeremy Kerr } 5900962e800SJeremy Kerr 5919b6b563cSPaul Mackerras static void __init early_reserve_mem(void) 5929b6b563cSPaul Mackerras { 593cbbcf340SKumar Gala u64 base, size; 594cbbcf340SKumar Gala u64 *reserve_map; 5958a300887SJon Loeliger unsigned long self_base; 5968a300887SJon Loeliger unsigned long self_size; 5979b6b563cSPaul Mackerras 598cbbcf340SKumar Gala reserve_map = (u64 *)(((unsigned long)initial_boot_params) + 5999b6b563cSPaul Mackerras initial_boot_params->off_mem_rsvmap); 6004d1f3f25SJimi Xenidis 6014d1f3f25SJimi Xenidis /* before we do anything, lets reserve the dt blob */ 6028a300887SJon Loeliger self_base = __pa((unsigned long)initial_boot_params); 6038a300887SJon Loeliger self_size = initial_boot_params->totalsize; 60495f72d1eSYinghai Lu memblock_reserve(self_base, self_size); 6054d1f3f25SJimi Xenidis 606*c039e3a8SBenjamin Herrenschmidt /* Look for the new "reserved-regions" property in the DT */ 607*c039e3a8SBenjamin Herrenschmidt early_reserve_mem_dt(); 6080962e800SJeremy Kerr 60930437b3eSDavid Gibson #ifdef CONFIG_BLK_DEV_INITRD 610*c039e3a8SBenjamin Herrenschmidt /* Then reserve the initrd, if any */ 611*c039e3a8SBenjamin Herrenschmidt if (initrd_start && (initrd_end > initrd_start)) { 612307cfe71SBenjamin Herrenschmidt memblock_reserve(_ALIGN_DOWN(__pa(initrd_start), PAGE_SIZE), 613307cfe71SBenjamin Herrenschmidt _ALIGN_UP(initrd_end, PAGE_SIZE) - 614307cfe71SBenjamin Herrenschmidt _ALIGN_DOWN(initrd_start, PAGE_SIZE)); 615*c039e3a8SBenjamin Herrenschmidt } 61630437b3eSDavid Gibson #endif /* CONFIG_BLK_DEV_INITRD */ 61730437b3eSDavid Gibson 618cbbcf340SKumar Gala #ifdef CONFIG_PPC32 619cbbcf340SKumar Gala /* 620cbbcf340SKumar Gala * Handle the case where we might be booting from an old kexec 621cbbcf340SKumar Gala * image that setup the mem_rsvmap as pairs of 32-bit values 622cbbcf340SKumar Gala */ 623cbbcf340SKumar Gala if (*reserve_map > 0xffffffffull) { 624cbbcf340SKumar Gala u32 base_32, size_32; 625cbbcf340SKumar Gala u32 *reserve_map_32 = (u32 *)reserve_map; 626cbbcf340SKumar Gala 627*c039e3a8SBenjamin Herrenschmidt DBG("Found old 32-bit reserve map\n"); 628*c039e3a8SBenjamin Herrenschmidt 629cbbcf340SKumar Gala while (1) { 630cbbcf340SKumar Gala base_32 = *(reserve_map_32++); 631cbbcf340SKumar Gala size_32 = *(reserve_map_32++); 632cbbcf340SKumar Gala if (size_32 == 0) 633cbbcf340SKumar Gala break; 6348a300887SJon Loeliger /* skip if the reservation is for the blob */ 6358a300887SJon Loeliger if (base_32 == self_base && size_32 == self_size) 6368a300887SJon Loeliger continue; 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 643*c039e3a8SBenjamin Herrenschmidt DBG("Processing reserve map\n"); 644*c039e3a8SBenjamin Herrenschmidt 645*c039e3a8SBenjamin Herrenschmidt /* Handle the reserve map in the fdt blob if it exists */ 6469b6b563cSPaul Mackerras while (1) { 6479b6b563cSPaul Mackerras base = *(reserve_map++); 6489b6b563cSPaul Mackerras size = *(reserve_map++); 6499b6b563cSPaul Mackerras if (size == 0) 6509b6b563cSPaul Mackerras break; 651cbbcf340SKumar Gala DBG("reserving: %llx -> %llx\n", base, size); 65295f72d1eSYinghai Lu memblock_reserve(base, size); 6539b6b563cSPaul Mackerras } 6549b6b563cSPaul Mackerras } 6559b6b563cSPaul Mackerras 6569b6b563cSPaul Mackerras void __init early_init_devtree(void *params) 6579b6b563cSPaul Mackerras { 65849a84965SBecky Bruce phys_addr_t limit; 6596ca4f749SHollis Blanchard 66044348105SGeoff Levand DBG(" -> early_init_devtree(%p)\n", params); 6619b6b563cSPaul Mackerras 6629b6b563cSPaul Mackerras /* Setup flat device-tree pointer */ 6639b6b563cSPaul Mackerras initial_boot_params = params; 6649b6b563cSPaul Mackerras 665458148c0SMichael Ellerman #ifdef CONFIG_PPC_RTAS 666458148c0SMichael Ellerman /* Some machines might need RTAS info for debugging, grab it now. */ 667458148c0SMichael Ellerman of_scan_flat_dt(early_init_dt_scan_rtas, NULL); 668458148c0SMichael Ellerman #endif 669458148c0SMichael Ellerman 67014a43e69SBenjamin Herrenschmidt #ifdef CONFIG_PPC_POWERNV 67114a43e69SBenjamin Herrenschmidt /* Some machines might need OPAL info for debugging, grab it now. */ 67214a43e69SBenjamin Herrenschmidt of_scan_flat_dt(early_init_dt_scan_opal, NULL); 67314a43e69SBenjamin Herrenschmidt #endif 67414a43e69SBenjamin Herrenschmidt 675eb39c880SMahesh Salgaonkar #ifdef CONFIG_FA_DUMP 676eb39c880SMahesh Salgaonkar /* scan tree to see if dump is active during last boot */ 677eb39c880SMahesh Salgaonkar of_scan_flat_dt(early_init_dt_scan_fw_dump, NULL); 678eb39c880SMahesh Salgaonkar #endif 679eb39c880SMahesh Salgaonkar 680817c21adSBenjamin Herrenschmidt /* Pre-initialize the cmd_line with the content of boot_commmand_line, 681817c21adSBenjamin Herrenschmidt * which will be empty except when the content of the variable has 682817c21adSBenjamin Herrenschmidt * been overriden by a bootloading mechanism. This happens typically 683817c21adSBenjamin Herrenschmidt * with HAL takeover 684817c21adSBenjamin Herrenschmidt */ 685817c21adSBenjamin Herrenschmidt strlcpy(cmd_line, boot_command_line, COMMAND_LINE_SIZE); 686817c21adSBenjamin Herrenschmidt 6879b6b563cSPaul Mackerras /* Retrieve various informations from the /chosen node of the 6889b6b563cSPaul Mackerras * device-tree, including the platform type, initrd location and 6899b6b563cSPaul Mackerras * size, TCE reserve, and more ... 6909b6b563cSPaul Mackerras */ 69185f60ae4SGrant Likely of_scan_flat_dt(early_init_dt_scan_chosen_ppc, cmd_line); 6929b6b563cSPaul Mackerras 69395f72d1eSYinghai Lu /* Scan memory nodes and rebuild MEMBLOCKs */ 6943c726f8dSBenjamin Herrenschmidt of_scan_flat_dt(early_init_dt_scan_root, NULL); 69551975db0SGrant Likely of_scan_flat_dt(early_init_dt_scan_memory_ppc, NULL); 696846f77b0SMichael Ellerman 697846f77b0SMichael Ellerman /* Save command line for /proc/cmdline and then parse parameters */ 698b8757b21SAlon Bar-Lev strlcpy(boot_command_line, cmd_line, COMMAND_LINE_SIZE); 699846f77b0SMichael Ellerman parse_early_param(); 700846f77b0SMichael Ellerman 701ba14f649SKumar Gala /* make sure we've parsed cmdline for mem= before this */ 702ba14f649SKumar Gala if (memory_limit) 703a84fcd46SSuzuki Poulose first_memblock_size = min_t(u64, first_memblock_size, memory_limit); 704ba14f649SKumar Gala setup_initial_memory_limit(memstart_addr, first_memblock_size); 70595f72d1eSYinghai Lu /* Reserve MEMBLOCK regions used by kernel, initrd, dt, etc... */ 70695f72d1eSYinghai Lu memblock_reserve(PHYSICAL_START, __pa(klimit) - PHYSICAL_START); 707549e8152SPaul Mackerras /* If relocatable, reserve first 32k for interrupt vectors etc. */ 708549e8152SPaul Mackerras if (PHYSICAL_START > MEMORY_START) 70995f72d1eSYinghai Lu memblock_reserve(MEMORY_START, 0x8000); 71047310413SMichael Ellerman reserve_kdump_trampoline(); 711eb39c880SMahesh Salgaonkar #ifdef CONFIG_FA_DUMP 712eb39c880SMahesh Salgaonkar /* 713eb39c880SMahesh Salgaonkar * If we fail to reserve memory for firmware-assisted dump then 714eb39c880SMahesh Salgaonkar * fallback to kexec based kdump. 715eb39c880SMahesh Salgaonkar */ 716eb39c880SMahesh Salgaonkar if (fadump_reserve_mem() == 0) 717eb39c880SMahesh Salgaonkar #endif 71835dd5432SMichael Ellerman reserve_crashkernel(); 7199b6b563cSPaul Mackerras early_reserve_mem(); 7209b6b563cSPaul Mackerras 7216fbef13cSTejun Heo /* 7226fbef13cSTejun Heo * Ensure that total memory size is page-aligned, because otherwise 7236fbef13cSTejun Heo * mark_bootmem() gets upset. 7246fbef13cSTejun Heo */ 7256fbef13cSTejun Heo limit = ALIGN(memory_limit ?: memblock_phys_mem_size(), PAGE_SIZE); 72695f72d1eSYinghai Lu memblock_enforce_memory_limit(limit); 7276ca4f749SHollis Blanchard 7281aadc056STejun Heo memblock_allow_resize(); 72995f72d1eSYinghai Lu memblock_dump_all(); 7302babf5c2SMichael Ellerman 73195f72d1eSYinghai Lu DBG("Phys. mem: %llx\n", memblock_phys_mem_size()); 7322babf5c2SMichael Ellerman 7332babf5c2SMichael Ellerman /* We may need to relocate the flat tree, do it now. 7342babf5c2SMichael Ellerman * FIXME .. and the initrd too? */ 7352babf5c2SMichael Ellerman move_device_tree(); 7362babf5c2SMichael Ellerman 7371426d5a3SMichael Ellerman allocate_pacas(); 7381426d5a3SMichael Ellerman 7399b6b563cSPaul Mackerras DBG("Scanning CPUs ...\n"); 7409b6b563cSPaul Mackerras 74125985edcSLucas De Marchi /* Retrieve CPU related informations from the flat tree 7423c726f8dSBenjamin Herrenschmidt * (altivec support, boot CPU ID, ...) 7439b6b563cSPaul Mackerras */ 7443c726f8dSBenjamin Herrenschmidt of_scan_flat_dt(early_init_dt_scan_cpus, NULL); 7459b6b563cSPaul Mackerras 7467ac87abbSMatt Evans #if defined(CONFIG_SMP) && defined(CONFIG_PPC64) 7477ac87abbSMatt Evans /* We'll later wait for secondaries to check in; there are 7487ac87abbSMatt Evans * NCPUS-1 non-boot CPUs :-) 7497ac87abbSMatt Evans */ 7507ac87abbSMatt Evans spinning_secondaries = boot_cpu_count - 1; 7517ac87abbSMatt Evans #endif 7527ac87abbSMatt Evans 7539b6b563cSPaul Mackerras DBG(" <- early_init_devtree()\n"); 7549b6b563cSPaul Mackerras } 7559b6b563cSPaul Mackerras 7569b6b563cSPaul Mackerras /******* 7579b6b563cSPaul Mackerras * 7589b6b563cSPaul Mackerras * New implementation of the OF "find" APIs, return a refcounted 7599b6b563cSPaul Mackerras * object, call of_node_put() when done. The device tree and list 7609b6b563cSPaul Mackerras * are protected by a rw_lock. 7619b6b563cSPaul Mackerras * 7629b6b563cSPaul Mackerras * Note that property management will need some locking as well, 7639b6b563cSPaul Mackerras * this isn't dealt with yet. 7649b6b563cSPaul Mackerras * 7659b6b563cSPaul Mackerras *******/ 7669b6b563cSPaul Mackerras 7679b6b563cSPaul Mackerras /** 768e523f723SNathan Lynch * of_find_next_cache_node - Find a node's subsidiary cache 769e523f723SNathan Lynch * @np: node of type "cpu" or "cache" 770e523f723SNathan Lynch * 771e523f723SNathan Lynch * Returns a node pointer with refcount incremented, use 772e523f723SNathan Lynch * of_node_put() on it when done. Caller should hold a reference 773e523f723SNathan Lynch * to np. 774e523f723SNathan Lynch */ 775e523f723SNathan Lynch struct device_node *of_find_next_cache_node(struct device_node *np) 776e523f723SNathan Lynch { 777e523f723SNathan Lynch struct device_node *child; 778e523f723SNathan Lynch const phandle *handle; 779e523f723SNathan Lynch 780e523f723SNathan Lynch handle = of_get_property(np, "l2-cache", NULL); 781e523f723SNathan Lynch if (!handle) 782e523f723SNathan Lynch handle = of_get_property(np, "next-level-cache", NULL); 783e523f723SNathan Lynch 784e523f723SNathan Lynch if (handle) 785e523f723SNathan Lynch return of_find_node_by_phandle(*handle); 786e523f723SNathan Lynch 787e523f723SNathan Lynch /* OF on pmac has nodes instead of properties named "l2-cache" 788e523f723SNathan Lynch * beneath CPU nodes. 789e523f723SNathan Lynch */ 790e523f723SNathan Lynch if (!strcmp(np->type, "cpu")) 791e523f723SNathan Lynch for_each_child_of_node(np, child) 792e523f723SNathan Lynch if (!strcmp(child->type, "cache")) 793e523f723SNathan Lynch return child; 794e523f723SNathan Lynch 795e523f723SNathan Lynch return NULL; 796e523f723SNathan Lynch } 797e523f723SNathan Lynch 7989b6b563cSPaul Mackerras #ifdef CONFIG_PPC_PSERIES 7999b6b563cSPaul Mackerras /* 8009b6b563cSPaul Mackerras * Fix up the uninitialized fields in a new device node: 8010ebfff14SBenjamin Herrenschmidt * name, type and pci-specific fields 8029b6b563cSPaul Mackerras */ 8039b6b563cSPaul Mackerras 804cc5d0189SBenjamin Herrenschmidt static int of_finish_dynamic_node(struct device_node *node) 8059b6b563cSPaul Mackerras { 8069b6b563cSPaul Mackerras struct device_node *parent = of_get_parent(node); 8079b6b563cSPaul Mackerras int err = 0; 808a7f67bdfSJeremy Kerr const phandle *ibm_phandle; 8099b6b563cSPaul Mackerras 8100e56efc7SStephen Rothwell node->name = of_get_property(node, "name", NULL); 8110e56efc7SStephen Rothwell node->type = of_get_property(node, "device_type", NULL); 8129b6b563cSPaul Mackerras 813847f5976SBenjamin Herrenschmidt if (!node->name) 814847f5976SBenjamin Herrenschmidt node->name = "<NULL>"; 815847f5976SBenjamin Herrenschmidt if (!node->type) 816847f5976SBenjamin Herrenschmidt node->type = "<NULL>"; 817847f5976SBenjamin Herrenschmidt 8189b6b563cSPaul Mackerras if (!parent) { 8199b6b563cSPaul Mackerras err = -ENODEV; 8209b6b563cSPaul Mackerras goto out; 8219b6b563cSPaul Mackerras } 8229b6b563cSPaul Mackerras 8239b6b563cSPaul Mackerras /* We don't support that function on PowerMac, at least 8249b6b563cSPaul Mackerras * not yet 8259b6b563cSPaul Mackerras */ 826e8222502SBenjamin Herrenschmidt if (machine_is(powermac)) 8279b6b563cSPaul Mackerras return -ENODEV; 8289b6b563cSPaul Mackerras 8296016a363SGrant Likely /* fix up new node's phandle field */ 8300e56efc7SStephen Rothwell if ((ibm_phandle = of_get_property(node, "ibm,phandle", NULL))) 8316016a363SGrant Likely node->phandle = *ibm_phandle; 8329b6b563cSPaul Mackerras 8339b6b563cSPaul Mackerras out: 8349b6b563cSPaul Mackerras of_node_put(parent); 8359b6b563cSPaul Mackerras return err; 8369b6b563cSPaul Mackerras } 8379b6b563cSPaul Mackerras 8389b6b563cSPaul Mackerras static int prom_reconfig_notifier(struct notifier_block *nb, 8399b6b563cSPaul Mackerras unsigned long action, void *node) 8409b6b563cSPaul Mackerras { 8419b6b563cSPaul Mackerras int err; 8429b6b563cSPaul Mackerras 8439b6b563cSPaul Mackerras switch (action) { 8441cf3d8b3SNathan Fontenot case OF_RECONFIG_ATTACH_NODE: 845cc5d0189SBenjamin Herrenschmidt err = of_finish_dynamic_node(node); 846de2780a3SAkinobu Mita if (err < 0) 8479b6b563cSPaul Mackerras printk(KERN_ERR "finish_node returned %d\n", err); 8489b6b563cSPaul Mackerras break; 8499b6b563cSPaul Mackerras default: 850de2780a3SAkinobu Mita err = 0; 8519b6b563cSPaul Mackerras break; 8529b6b563cSPaul Mackerras } 853de2780a3SAkinobu Mita return notifier_from_errno(err); 8549b6b563cSPaul Mackerras } 8559b6b563cSPaul Mackerras 8569b6b563cSPaul Mackerras static struct notifier_block prom_reconfig_nb = { 8579b6b563cSPaul Mackerras .notifier_call = prom_reconfig_notifier, 8589b6b563cSPaul Mackerras .priority = 10, /* This one needs to run first */ 8599b6b563cSPaul Mackerras }; 8609b6b563cSPaul Mackerras 8619b6b563cSPaul Mackerras static int __init prom_reconfig_setup(void) 8629b6b563cSPaul Mackerras { 8631cf3d8b3SNathan Fontenot return of_reconfig_notifier_register(&prom_reconfig_nb); 8649b6b563cSPaul Mackerras } 8659b6b563cSPaul Mackerras __initcall(prom_reconfig_setup); 8669b6b563cSPaul Mackerras #endif 8679b6b563cSPaul Mackerras 868acf7d768SBenjamin Herrenschmidt /* Find the device node for a given logical cpu number, also returns the cpu 869acf7d768SBenjamin Herrenschmidt * local thread number (index in ibm,interrupt-server#s) if relevant and 870acf7d768SBenjamin Herrenschmidt * asked for (non NULL) 871acf7d768SBenjamin Herrenschmidt */ 872acf7d768SBenjamin Herrenschmidt struct device_node *of_get_cpu_node(int cpu, unsigned int *thread) 873acf7d768SBenjamin Herrenschmidt { 874acf7d768SBenjamin Herrenschmidt int hardid; 875acf7d768SBenjamin Herrenschmidt struct device_node *np; 876acf7d768SBenjamin Herrenschmidt 877acf7d768SBenjamin Herrenschmidt hardid = get_hard_smp_processor_id(cpu); 878acf7d768SBenjamin Herrenschmidt 879acf7d768SBenjamin Herrenschmidt for_each_node_by_type(np, "cpu") { 880a7f67bdfSJeremy Kerr const u32 *intserv; 881acf7d768SBenjamin Herrenschmidt unsigned int plen, t; 882acf7d768SBenjamin Herrenschmidt 883acf7d768SBenjamin Herrenschmidt /* Check for ibm,ppc-interrupt-server#s. If it doesn't exist 884acf7d768SBenjamin Herrenschmidt * fallback to "reg" property and assume no threads 885acf7d768SBenjamin Herrenschmidt */ 8860e56efc7SStephen Rothwell intserv = of_get_property(np, "ibm,ppc-interrupt-server#s", 887acf7d768SBenjamin Herrenschmidt &plen); 888acf7d768SBenjamin Herrenschmidt if (intserv == NULL) { 8890e56efc7SStephen Rothwell const u32 *reg = of_get_property(np, "reg", NULL); 890acf7d768SBenjamin Herrenschmidt if (reg == NULL) 891acf7d768SBenjamin Herrenschmidt continue; 892acf7d768SBenjamin Herrenschmidt if (*reg == hardid) { 893acf7d768SBenjamin Herrenschmidt if (thread) 894acf7d768SBenjamin Herrenschmidt *thread = 0; 895acf7d768SBenjamin Herrenschmidt return np; 896acf7d768SBenjamin Herrenschmidt } 897acf7d768SBenjamin Herrenschmidt } else { 898acf7d768SBenjamin Herrenschmidt plen /= sizeof(u32); 899acf7d768SBenjamin Herrenschmidt for (t = 0; t < plen; t++) { 900acf7d768SBenjamin Herrenschmidt if (hardid == intserv[t]) { 901acf7d768SBenjamin Herrenschmidt if (thread) 902acf7d768SBenjamin Herrenschmidt *thread = t; 903acf7d768SBenjamin Herrenschmidt return np; 904acf7d768SBenjamin Herrenschmidt } 905acf7d768SBenjamin Herrenschmidt } 906acf7d768SBenjamin Herrenschmidt } 907acf7d768SBenjamin Herrenschmidt } 908acf7d768SBenjamin Herrenschmidt return NULL; 909acf7d768SBenjamin Herrenschmidt } 91036ca4ba4SChristian Krafft EXPORT_SYMBOL(of_get_cpu_node); 9117a4571aeSMichael Ellerman 91294a3807cSMichael Ellerman #if defined(CONFIG_DEBUG_FS) && defined(DEBUG) 9137a4571aeSMichael Ellerman static struct debugfs_blob_wrapper flat_dt_blob; 9147a4571aeSMichael Ellerman 9157a4571aeSMichael Ellerman static int __init export_flat_device_tree(void) 9167a4571aeSMichael Ellerman { 9177a4571aeSMichael Ellerman struct dentry *d; 9187a4571aeSMichael Ellerman 9197a4571aeSMichael Ellerman flat_dt_blob.data = initial_boot_params; 9207a4571aeSMichael Ellerman flat_dt_blob.size = initial_boot_params->totalsize; 9217a4571aeSMichael Ellerman 9227a4571aeSMichael Ellerman d = debugfs_create_blob("flat-device-tree", S_IFREG | S_IRUSR, 92394a3807cSMichael Ellerman powerpc_debugfs_root, &flat_dt_blob); 9247a4571aeSMichael Ellerman if (!d) 9257a4571aeSMichael Ellerman return 1; 9267a4571aeSMichael Ellerman 9277a4571aeSMichael Ellerman return 0; 9287a4571aeSMichael Ellerman } 9297a4571aeSMichael Ellerman __initcall(export_flat_device_tree); 9307a4571aeSMichael Ellerman #endif 931