^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Procedures for creating, accessing and interpreting the device tree.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Paul Mackerras August 1996.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 1996-2005 Paul Mackerras.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * {engebret|bergner}@us.ibm.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #undef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <stdarg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/threads.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/initrd.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/kexec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/memblock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/of_fdt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/libfdt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/pgtable.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <asm/prom.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <asm/rtas.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <asm/processor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <asm/irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #include <asm/kdump.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include <asm/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include <asm/mmu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #include <asm/paca.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #include <asm/powernv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #include <asm/iommu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #include <asm/btext.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #include <asm/sections.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #include <asm/machdep.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #include <asm/pci-bridge.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #include <asm/kexec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #include <asm/opal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #include <asm/fadump.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #include <asm/epapr_hcalls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #include <asm/firmware.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #include <asm/dt_cpu_ftrs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #include <asm/drmem.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) #include <asm/ultravisor.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #include <mm/mmu_decl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define DBG(fmt...) printk(KERN_ERR fmt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define DBG(fmt...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #ifdef CONFIG_PPC64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) int __initdata iommu_is_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) int __initdata iommu_force_on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) unsigned long tce_alloc_start, tce_alloc_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) u64 ppc64_rma_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static phys_addr_t first_memblock_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static int __initdata boot_cpu_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) static int __init early_parse_mem(char *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) memory_limit = PAGE_ALIGN(memparse(p, &p));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) DBG("memory limit = 0x%llx\n", memory_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) early_param("mem", early_parse_mem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * overlaps_initrd - check for overlap with page aligned extension of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * initrd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) static inline int overlaps_initrd(unsigned long start, unsigned long size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) #ifdef CONFIG_BLK_DEV_INITRD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) if (!initrd_start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) return (start + size) > ALIGN_DOWN(initrd_start, PAGE_SIZE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) start <= ALIGN(initrd_end, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) * move_device_tree - move tree to an unused area, if needed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) * The device tree may be allocated beyond our memory limit, or inside the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) * crash kernel region for kdump, or within the page aligned range of initrd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) * If so, move it out of the way.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static void __init move_device_tree(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) unsigned long start, size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) void *p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) DBG("-> move_device_tree\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) start = __pa(initial_boot_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) size = fdt_totalsize(initial_boot_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) if ((memory_limit && (start + size) > PHYSICAL_START + memory_limit) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) !memblock_is_memory(start + size - 1) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) overlaps_crashkernel(start, size) || overlaps_initrd(start, size)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) p = memblock_alloc_raw(size, PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) if (!p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) panic("Failed to allocate %lu bytes to move device tree\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) memcpy(p, initial_boot_params, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) initial_boot_params = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) DBG("Moved device tree to 0x%px\n", p);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) DBG("<- move_device_tree\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * ibm,pa-features is a per-cpu property that contains a string of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * attribute descriptors, each of which has a 2 byte header plus up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * to 254 bytes worth of processor attribute bits. First header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * byte specifies the number of bytes following the header.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) * Second header byte is an "attribute-specifier" type, of which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * zero is the only currently-defined value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * Implementation: Pass in the byte and bit offset for the feature
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * that we are interested in. The function will return -1 if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * pa-features property is missing, or a 1/0 to indicate if the feature
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * is supported/not supported. Note that the bit numbers are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * big-endian to match the definition in PAPR.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static struct ibm_pa_feature {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) unsigned long cpu_features; /* CPU_FTR_xxx bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) unsigned long mmu_features; /* MMU_FTR_xxx bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) unsigned int cpu_user_ftrs; /* PPC_FEATURE_xxx bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) unsigned int cpu_user_ftrs2; /* PPC_FEATURE2_xxx bit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) unsigned char pabyte; /* byte number in ibm,pa-features */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) unsigned char pabit; /* bit number (big-endian) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) unsigned char invert; /* if 1, pa bit set => clear feature */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) } ibm_pa_features[] __initdata = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) { .pabyte = 0, .pabit = 0, .cpu_user_ftrs = PPC_FEATURE_HAS_MMU },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) { .pabyte = 0, .pabit = 1, .cpu_user_ftrs = PPC_FEATURE_HAS_FPU },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) { .pabyte = 0, .pabit = 3, .cpu_features = CPU_FTR_CTRL },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) { .pabyte = 0, .pabit = 6, .cpu_features = CPU_FTR_NOEXECUTE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) { .pabyte = 1, .pabit = 2, .mmu_features = MMU_FTR_CI_LARGE_PAGE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) #ifdef CONFIG_PPC_RADIX_MMU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) { .pabyte = 40, .pabit = 0, .mmu_features = MMU_FTR_TYPE_RADIX | MMU_FTR_GTSE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) { .pabyte = 1, .pabit = 1, .invert = 1, .cpu_features = CPU_FTR_NODSISRALIGN },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) { .pabyte = 5, .pabit = 0, .cpu_features = CPU_FTR_REAL_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) .cpu_user_ftrs = PPC_FEATURE_TRUE_LE },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) * If the kernel doesn't support TM (ie CONFIG_PPC_TRANSACTIONAL_MEM=n),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * we don't want to turn on TM here, so we use the *_COMP versions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * which are 0 if the kernel doesn't support TM.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) { .pabyte = 22, .pabit = 0, .cpu_features = CPU_FTR_TM_COMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) .cpu_user_ftrs2 = PPC_FEATURE2_HTM_COMP | PPC_FEATURE2_HTM_NOSC_COMP },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) { .pabyte = 64, .pabit = 0, .cpu_features = CPU_FTR_DAWR1 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static void __init scan_features(unsigned long node, const unsigned char *ftrs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) unsigned long tablelen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct ibm_pa_feature *fp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) unsigned long ft_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) unsigned long i, len, bit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /* find descriptor with type == 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) for (;;) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (tablelen < 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) len = 2 + ftrs[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if (tablelen < len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) return; /* descriptor 0 not found */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (ftrs[1] == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) tablelen -= len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) ftrs += len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* loop over bits we know about */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) for (i = 0; i < ft_size; ++i, ++fp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) if (fp->pabyte >= ftrs[0])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) bit = (ftrs[2 + fp->pabyte] >> (7 - fp->pabit)) & 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if (bit ^ fp->invert) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) cur_cpu_spec->cpu_features |= fp->cpu_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) cur_cpu_spec->cpu_user_features |= fp->cpu_user_ftrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) cur_cpu_spec->cpu_user_features2 |= fp->cpu_user_ftrs2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) cur_cpu_spec->mmu_features |= fp->mmu_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) cur_cpu_spec->cpu_features &= ~fp->cpu_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) cur_cpu_spec->cpu_user_features &= ~fp->cpu_user_ftrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) cur_cpu_spec->cpu_user_features2 &= ~fp->cpu_user_ftrs2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) cur_cpu_spec->mmu_features &= ~fp->mmu_features;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static void __init check_cpu_pa_features(unsigned long node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) const unsigned char *pa_ftrs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) int tablelen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) pa_ftrs = of_get_flat_dt_prop(node, "ibm,pa-features", &tablelen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (pa_ftrs == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) scan_features(node, pa_ftrs, tablelen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) ibm_pa_features, ARRAY_SIZE(ibm_pa_features));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) #ifdef CONFIG_PPC_BOOK3S_64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static void __init init_mmu_slb_size(unsigned long node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) const __be32 *slb_size_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) slb_size_ptr = of_get_flat_dt_prop(node, "slb-size", NULL) ? :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) of_get_flat_dt_prop(node, "ibm,slb-size", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (slb_size_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) mmu_slb_size = be32_to_cpup(slb_size_ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) #define init_mmu_slb_size(node) do { } while(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) static struct feature_property {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) u32 min_value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) unsigned long cpu_feature;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) unsigned long cpu_user_ftr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) } feature_properties[] __initdata = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) #ifdef CONFIG_ALTIVEC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {"altivec", 0, CPU_FTR_ALTIVEC, PPC_FEATURE_HAS_ALTIVEC},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {"ibm,vmx", 1, CPU_FTR_ALTIVEC, PPC_FEATURE_HAS_ALTIVEC},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) #endif /* CONFIG_ALTIVEC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) #ifdef CONFIG_VSX
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) /* Yes, this _really_ is ibm,vmx == 2 to enable VSX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) {"ibm,vmx", 2, CPU_FTR_VSX, PPC_FEATURE_HAS_VSX},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) #endif /* CONFIG_VSX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) #ifdef CONFIG_PPC64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {"ibm,dfp", 1, 0, PPC_FEATURE_HAS_DFP},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {"ibm,purr", 1, CPU_FTR_PURR, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) {"ibm,spurr", 1, CPU_FTR_SPURR, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) #endif /* CONFIG_PPC64 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) #if defined(CONFIG_44x) && defined(CONFIG_PPC_FPU)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) static __init void identical_pvr_fixup(unsigned long node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) unsigned int pvr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) const char *model = of_get_flat_dt_prop(node, "model", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * Since 440GR(x)/440EP(x) processors have the same pvr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) * we check the node path and set bit 28 in the cur_cpu_spec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) * pvr for EP(x) processor version. This bit is always 0 in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) * the "real" pvr. Then we call identify_cpu again with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) * the new logical pvr to enable FPU support.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) if (model && strstr(model, "440EP")) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) pvr = cur_cpu_spec->pvr_value | 0x8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) identify_cpu(0, pvr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) DBG("Using logical pvr %x for %s\n", pvr, model);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) #define identical_pvr_fixup(node) do { } while(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) static void __init check_cpu_feature_properties(unsigned long node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) struct feature_property *fp = feature_properties;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) const __be32 *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) for (i = 0; i < (int)ARRAY_SIZE(feature_properties); ++i, ++fp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) prop = of_get_flat_dt_prop(node, fp->name, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (prop && be32_to_cpup(prop) >= fp->min_value) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) cur_cpu_spec->cpu_features |= fp->cpu_feature;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) cur_cpu_spec->cpu_user_features |= fp->cpu_user_ftr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) static int __init early_init_dt_scan_cpus(unsigned long node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) const char *uname, int depth,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) const char *type = of_get_flat_dt_prop(node, "device_type", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) const __be32 *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) const __be32 *intserv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) int i, nthreads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) int found = -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) int found_thread = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) /* We are scanning "cpu" nodes only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) if (type == NULL || strcmp(type, "cpu") != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) /* Get physical cpuid */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) intserv = of_get_flat_dt_prop(node, "ibm,ppc-interrupt-server#s", &len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) if (!intserv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) intserv = of_get_flat_dt_prop(node, "reg", &len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) nthreads = len / sizeof(int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) * Now see if any of these threads match our boot cpu.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) * NOTE: This must match the parsing done in smp_setup_cpu_maps.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) for (i = 0; i < nthreads; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (be32_to_cpu(intserv[i]) ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) fdt_boot_cpuid_phys(initial_boot_params)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) found = boot_cpu_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) found_thread = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) /* logical cpu id is always 0 on UP kernels */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) boot_cpu_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) /* Not the boot CPU */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) if (found < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) DBG("boot cpu: logical %d physical %d\n", found,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) be32_to_cpu(intserv[found_thread]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) boot_cpuid = found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) * PAPR defines "logical" PVR values for cpus that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) * meet various levels of the architecture:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) * 0x0f000001 Architecture version 2.04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) * 0x0f000002 Architecture version 2.05
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) * If the cpu-version property in the cpu node contains
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) * such a value, we call identify_cpu again with the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) * logical PVR value in order to use the cpu feature
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) * bits appropriate for the architecture level.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) * A POWER6 partition in "POWER6 architected" mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) * uses the 0x0f000002 PVR value; in POWER5+ mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) * it uses 0x0f000001.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) * If we're using device tree CPU feature discovery then we don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) * support the cpu-version property, and it's the responsibility of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) * firmware/hypervisor to provide the correct feature set for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) * architecture level via the ibm,powerpc-cpu-features binding.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (!dt_cpu_ftrs_in_use()) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) prop = of_get_flat_dt_prop(node, "cpu-version", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) if (prop && (be32_to_cpup(prop) & 0xff000000) == 0x0f000000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) identify_cpu(0, be32_to_cpup(prop));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) check_cpu_feature_properties(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) check_cpu_pa_features(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) identical_pvr_fixup(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) init_mmu_slb_size(node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) #ifdef CONFIG_PPC64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) if (nthreads == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) cur_cpu_spec->cpu_features &= ~CPU_FTR_SMT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) else if (!dt_cpu_ftrs_in_use())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) cur_cpu_spec->cpu_features |= CPU_FTR_SMT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) allocate_paca(boot_cpuid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) set_hard_smp_processor_id(found, be32_to_cpu(intserv[found_thread]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) static int __init early_init_dt_scan_chosen_ppc(unsigned long node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) const char *uname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) int depth, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) const unsigned long *lprop; /* All these set by kernel, so no need to convert endian */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) /* Use common scan routine to determine if this is the chosen node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) if (early_init_dt_scan_chosen(node, uname, depth, data) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) #ifdef CONFIG_PPC64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) /* check if iommu is forced on or off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) if (of_get_flat_dt_prop(node, "linux,iommu-off", NULL) != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) iommu_is_off = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) if (of_get_flat_dt_prop(node, "linux,iommu-force-on", NULL) != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) iommu_force_on = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) /* mem=x on the command line is the preferred mechanism */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) lprop = of_get_flat_dt_prop(node, "linux,memory-limit", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) if (lprop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) memory_limit = *lprop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) #ifdef CONFIG_PPC64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) lprop = of_get_flat_dt_prop(node, "linux,tce-alloc-start", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) if (lprop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) tce_alloc_start = *lprop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) lprop = of_get_flat_dt_prop(node, "linux,tce-alloc-end", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) if (lprop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) tce_alloc_end = *lprop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) #ifdef CONFIG_KEXEC_CORE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) lprop = of_get_flat_dt_prop(node, "linux,crashkernel-base", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) if (lprop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) crashk_res.start = *lprop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) lprop = of_get_flat_dt_prop(node, "linux,crashkernel-size", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) if (lprop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) crashk_res.end = crashk_res.start + *lprop - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) /* break now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) * Compare the range against max mem limit and update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) * size if it cross the limit.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) #ifdef CONFIG_SPARSEMEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) static bool validate_mem_limit(u64 base, u64 *size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) u64 max_mem = 1UL << (MAX_PHYSMEM_BITS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if (base >= max_mem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) if ((base + *size) > max_mem)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) *size = max_mem - base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) static bool validate_mem_limit(u64 base, u64 *size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) #ifdef CONFIG_PPC_PSERIES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) * Interpret the ibm dynamic reconfiguration memory LMBs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) * This contains a list of memory blocks along with NUMA affinity
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) * information.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) static int __init early_init_drmem_lmb(struct drmem_lmb *lmb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) const __be32 **usm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) u64 base, size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) int is_kexec_kdump = 0, rngs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) base = lmb->base_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) size = drmem_lmb_size();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) rngs = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) * Skip this block if the reserved bit is set in flags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) * or if the block is not assigned to this partition.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) if ((lmb->flags & DRCONF_MEM_RESERVED) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) !(lmb->flags & DRCONF_MEM_ASSIGNED))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) if (*usm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) is_kexec_kdump = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) if (is_kexec_kdump) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) * For each memblock in ibm,dynamic-memory, a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) * corresponding entry in linux,drconf-usable-memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) * property contains a counter 'p' followed by 'p'
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) * (base, size) duple. Now read the counter from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) * linux,drconf-usable-memory property
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) rngs = dt_mem_next_cell(dt_root_size_cells, usm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) if (!rngs) /* there are no (base, size) duple */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) if (is_kexec_kdump) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) base = dt_mem_next_cell(dt_root_addr_cells, usm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) size = dt_mem_next_cell(dt_root_size_cells, usm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) if (iommu_is_off) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) if (base >= 0x80000000ul)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) if ((base + size) > 0x80000000ul)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) size = 0x80000000ul - base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) if (!validate_mem_limit(base, &size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) DBG("Adding: %llx -> %llx\n", base, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) memblock_add(base, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) if (lmb->flags & DRCONF_MEM_HOTREMOVABLE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) memblock_mark_hotplug(base, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) } while (--rngs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) #endif /* CONFIG_PPC_PSERIES */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) static int __init early_init_dt_scan_memory_ppc(unsigned long node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) const char *uname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) int depth, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) #ifdef CONFIG_PPC_PSERIES
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) if (depth == 1 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) strcmp(uname, "ibm,dynamic-reconfiguration-memory") == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) walk_drmem_lmbs_early(node, NULL, early_init_drmem_lmb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) return early_init_dt_scan_memory(node, uname, depth, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) * For a relocatable kernel, we need to get the memstart_addr first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) * then use it to calculate the virtual kernel start address. This has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) * to happen at a very early stage (before machine_init). In this case,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) * we just want to get the memstart_address and would not like to mess the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) * memblock at this stage. So introduce a variable to skip the memblock_add()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) * for this reason.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) #ifdef CONFIG_RELOCATABLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) static int add_mem_to_memblock = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) #define add_mem_to_memblock 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) void __init early_init_dt_add_memory_arch(u64 base, u64 size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) #ifdef CONFIG_PPC64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) if (iommu_is_off) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) if (base >= 0x80000000ul)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) if ((base + size) > 0x80000000ul)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) size = 0x80000000ul - base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) /* Keep track of the beginning of memory -and- the size of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) * the very first block in the device-tree as it represents
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) * the RMA on ppc64 server
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) if (base < memstart_addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) memstart_addr = base;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) first_memblock_size = size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) /* Add the chunk to the MEMBLOCK list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) if (add_mem_to_memblock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) if (validate_mem_limit(base, &size))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) memblock_add(base, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) static void __init early_reserve_mem_dt(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) unsigned long i, dt_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) int len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) const __be32 *prop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) early_init_fdt_reserve_self();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) early_init_fdt_scan_reserved_mem();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) dt_root = of_get_flat_dt_root();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) prop = of_get_flat_dt_prop(dt_root, "reserved-ranges", &len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) if (!prop)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) DBG("Found new-style reserved-ranges\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) /* Each reserved range is an (address,size) pair, 2 cells each,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) * totalling 4 cells per range. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) for (i = 0; i < len / (sizeof(*prop) * 4); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) u64 base, size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) base = of_read_number(prop + (i * 4) + 0, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) size = of_read_number(prop + (i * 4) + 2, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) if (size) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) DBG("reserving: %llx -> %llx\n", base, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) memblock_reserve(base, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) static void __init early_reserve_mem(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) __be64 *reserve_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) reserve_map = (__be64 *)(((unsigned long)initial_boot_params) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) fdt_off_mem_rsvmap(initial_boot_params));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) /* Look for the new "reserved-regions" property in the DT */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) early_reserve_mem_dt();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) #ifdef CONFIG_BLK_DEV_INITRD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) /* Then reserve the initrd, if any */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) if (initrd_start && (initrd_end > initrd_start)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) memblock_reserve(ALIGN_DOWN(__pa(initrd_start), PAGE_SIZE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) ALIGN(initrd_end, PAGE_SIZE) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) ALIGN_DOWN(initrd_start, PAGE_SIZE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) #endif /* CONFIG_BLK_DEV_INITRD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) #ifdef CONFIG_PPC32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) * Handle the case where we might be booting from an old kexec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) * image that setup the mem_rsvmap as pairs of 32-bit values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) if (be64_to_cpup(reserve_map) > 0xffffffffull) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) u32 base_32, size_32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) __be32 *reserve_map_32 = (__be32 *)reserve_map;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) DBG("Found old 32-bit reserve map\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) while (1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) base_32 = be32_to_cpup(reserve_map_32++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) size_32 = be32_to_cpup(reserve_map_32++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) if (size_32 == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) DBG("reserving: %x -> %x\n", base_32, size_32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) memblock_reserve(base_32, size_32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) static bool tm_disabled __initdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) static int __init parse_ppc_tm(char *str)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) bool res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) if (kstrtobool(str, &res))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) tm_disabled = !res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) early_param("ppc_tm", parse_ppc_tm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) static void __init tm_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) if (tm_disabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) pr_info("Disabling hardware transactional memory (HTM)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) cur_cpu_spec->cpu_user_features2 &=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) ~(PPC_FEATURE2_HTM_NOSC | PPC_FEATURE2_HTM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) cur_cpu_spec->cpu_features &= ~CPU_FTR_TM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) pnv_tm_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) static void tm_init(void) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) #endif /* CONFIG_PPC_TRANSACTIONAL_MEM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) #ifdef CONFIG_PPC64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) static void __init save_fscr_to_task(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) * Ensure the init_task (pid 0, aka swapper) uses the value of FSCR we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) * have configured via the device tree features or via __init_FSCR().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) * That value will then be propagated to pid 1 (init) and all future
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) * processes.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) if (early_cpu_has_feature(CPU_FTR_ARCH_207S))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) init_task.thread.fscr = mfspr(SPRN_FSCR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) static inline void save_fscr_to_task(void) {};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) void __init early_init_devtree(void *params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) phys_addr_t limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) DBG(" -> early_init_devtree(%px)\n", params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) /* Too early to BUG_ON(), do it by hand */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) if (!early_init_dt_verify(params))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) panic("BUG: Failed verifying flat device tree, bad version?");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) #ifdef CONFIG_PPC_RTAS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) /* Some machines might need RTAS info for debugging, grab it now. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) of_scan_flat_dt(early_init_dt_scan_rtas, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) #ifdef CONFIG_PPC_POWERNV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) /* Some machines might need OPAL info for debugging, grab it now. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) of_scan_flat_dt(early_init_dt_scan_opal, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) /* Scan tree for ultravisor feature */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) of_scan_flat_dt(early_init_dt_scan_ultravisor, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) #if defined(CONFIG_FA_DUMP) || defined(CONFIG_PRESERVE_FA_DUMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) /* scan tree to see if dump is active during last boot */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) of_scan_flat_dt(early_init_dt_scan_fw_dump, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) /* Retrieve various informations from the /chosen node of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) * device-tree, including the platform type, initrd location and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) * size, TCE reserve, and more ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) of_scan_flat_dt(early_init_dt_scan_chosen_ppc, boot_command_line);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) /* Scan memory nodes and rebuild MEMBLOCKs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) of_scan_flat_dt(early_init_dt_scan_root, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) of_scan_flat_dt(early_init_dt_scan_memory_ppc, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) parse_early_param();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) /* make sure we've parsed cmdline for mem= before this */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) if (memory_limit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) first_memblock_size = min_t(u64, first_memblock_size, memory_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) setup_initial_memory_limit(memstart_addr, first_memblock_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) /* Reserve MEMBLOCK regions used by kernel, initrd, dt, etc... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) memblock_reserve(PHYSICAL_START, __pa(klimit) - PHYSICAL_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) /* If relocatable, reserve first 32k for interrupt vectors etc. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) if (PHYSICAL_START > MEMORY_START)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) memblock_reserve(MEMORY_START, 0x8000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) reserve_kdump_trampoline();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) #if defined(CONFIG_FA_DUMP) || defined(CONFIG_PRESERVE_FA_DUMP)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) * If we fail to reserve memory for firmware-assisted dump then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768) * fallback to kexec based kdump.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) if (fadump_reserve_mem() == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772) reserve_crashkernel();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) early_reserve_mem();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) /* Ensure that total memory size is page-aligned. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) limit = ALIGN(memory_limit ?: memblock_phys_mem_size(), PAGE_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) memblock_enforce_memory_limit(limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) #if defined(CONFIG_PPC_BOOK3S_64) && defined(CONFIG_PPC_4K_PAGES)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780) if (!early_radix_enabled())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) memblock_cap_memory_range(0, 1UL << (H_MAX_PHYSMEM_BITS));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) memblock_allow_resize();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) memblock_dump_all();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) DBG("Phys. mem: %llx\n", (unsigned long long)memblock_phys_mem_size());
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) /* We may need to relocate the flat tree, do it now.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790) * FIXME .. and the initrd too? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) move_device_tree();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) allocate_paca_ptrs();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) DBG("Scanning CPUs ...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797) dt_cpu_ftrs_scan();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) /* Retrieve CPU related informations from the flat tree
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) * (altivec support, boot CPU ID, ...)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) of_scan_flat_dt(early_init_dt_scan_cpus, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) if (boot_cpuid < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) printk("Failed to identify boot CPU !\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) save_fscr_to_task();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) #if defined(CONFIG_SMP) && defined(CONFIG_PPC64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) /* We'll later wait for secondaries to check in; there are
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) * NCPUS-1 non-boot CPUs :-)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) spinning_secondaries = boot_cpu_count - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) mmu_early_init_devtree();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) #ifdef CONFIG_PPC_POWERNV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) /* Scan and build the list of machine check recoverable ranges */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) of_scan_flat_dt(early_init_dt_scan_recoverable_ranges, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) epapr_paravirt_early_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) /* Now try to figure out if we are running on LPAR and so on */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) pseries_probe_fw_features();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 827)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 828) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 829) * Initialize pkey features and default AMR/IAMR values
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 830) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 831) pkey_early_init_devtree();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 832)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 833) #ifdef CONFIG_PPC_PS3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 834) /* Identify PS3 firmware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 835) if (of_flat_dt_is_compatible(of_get_flat_dt_root(), "sony,ps3"))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 836) powerpc_firmware_features |= FW_FEATURE_PS3_POSSIBLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 837) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 838)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 839) tm_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 840)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 841) DBG(" <- early_init_devtree()\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 842) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 843)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 844) #ifdef CONFIG_RELOCATABLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 845) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 846) * This function run before early_init_devtree, so we have to init
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 847) * initial_boot_params.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 848) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 849) void __init early_get_first_memblock_info(void *params, phys_addr_t *size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 850) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 851) /* Setup flat device-tree pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 852) initial_boot_params = params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 853)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 854) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 855) * Scan the memory nodes and set add_mem_to_memblock to 0 to avoid
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 856) * mess the memblock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 857) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 858) add_mem_to_memblock = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 859) of_scan_flat_dt(early_init_dt_scan_root, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 860) of_scan_flat_dt(early_init_dt_scan_memory_ppc, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 861) add_mem_to_memblock = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 862)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 863) if (size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 864) *size = first_memblock_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 866) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 867)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 868) /*******
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 869) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 870) * New implementation of the OF "find" APIs, return a refcounted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 871) * object, call of_node_put() when done. The device tree and list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 872) * are protected by a rw_lock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 873) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 874) * Note that property management will need some locking as well,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 875) * this isn't dealt with yet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 876) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 877) *******/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 878)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 879) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 880) * of_get_ibm_chip_id - Returns the IBM "chip-id" of a device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 881) * @np: device node of the device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 882) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 883) * This looks for a property "ibm,chip-id" in the node or any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 884) * of its parents and returns its content, or -1 if it cannot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 885) * be found.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 886) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 887) int of_get_ibm_chip_id(struct device_node *np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 888) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 889) of_node_get(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 890) while (np) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 891) u32 chip_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 892)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 893) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 894) * Skiboot may produce memory nodes that contain more than one
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 895) * cell in chip-id, we only read the first one here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 896) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 897) if (!of_property_read_u32(np, "ibm,chip-id", &chip_id)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 898) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 899) return chip_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 900) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 901)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 902) np = of_get_next_parent(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 903) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 904) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 905) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 906) EXPORT_SYMBOL(of_get_ibm_chip_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 907)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 908) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 909) * cpu_to_chip_id - Return the cpus chip-id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 910) * @cpu: The logical cpu number.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 911) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 912) * Return the value of the ibm,chip-id property corresponding to the given
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 913) * logical cpu number. If the chip-id can not be found, returns -1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 914) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 915) int cpu_to_chip_id(int cpu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 916) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 917) struct device_node *np;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 918)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 919) np = of_get_cpu_node(cpu, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 920) if (!np)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 921) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 922)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 923) of_node_put(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 924) return of_get_ibm_chip_id(np);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 925) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 926) EXPORT_SYMBOL(cpu_to_chip_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 927)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 928) bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 929) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 930) #ifdef CONFIG_SMP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 931) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 932) * Early firmware scanning must use this rather than
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 933) * get_hard_smp_processor_id because we don't have pacas allocated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 934) * until memory topology is discovered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 935) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 936) if (cpu_to_phys_id != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 937) return (int)phys_id == cpu_to_phys_id[cpu];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 938) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 939)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 940) return (int)phys_id == get_hard_smp_processor_id(cpu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 941) }