1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2001 Ben. Herrenschmidt (benh@kernel.crashing.org)
5 * Modifications for ppc64:
6 * Copyright (C) 2003 Dave Engebretsen <engebret@us.ibm.com>
9 #include <linux/string.h>
10 #include <linux/sched.h>
11 #include <linux/threads.h>
12 #include <linux/init.h>
13 #include <linux/export.h>
14 #include <linux/jump_label.h>
17 #include <asm/cputable.h>
20 #include <asm/setup.h>
21 #include <asm/cpu_setup.h>
23 static struct cpu_spec the_cpu_spec __read_mostly;
25 struct cpu_spec* cur_cpu_spec __read_mostly = NULL;
26 EXPORT_SYMBOL(cur_cpu_spec);
28 /* The platform string corresponding to the real PVR */
29 const char *powerpc_base_platform;
31 #include "cpu_specs.h"
33 void __init set_cur_cpu_spec(struct cpu_spec *s)
35 struct cpu_spec *t = &the_cpu_spec;
39 * use memcpy() instead of *t = *s so that GCC replaces it
40 * by __memcpy() when KASAN is active
42 memcpy(t, s, sizeof(*t));
44 *PTRRELOC(&cur_cpu_spec) = &the_cpu_spec;
47 static struct cpu_spec * __init setup_cpu_spec(unsigned long offset,
50 struct cpu_spec *t = &the_cpu_spec;
57 * Copy everything, then do fixups. Use memcpy() instead of *t = *s
58 * so that GCC replaces it by __memcpy() when KASAN is active
60 memcpy(t, s, sizeof(*t));
63 * If we are overriding a previous value derived from the real
64 * PVR with a new value obtained using a logical PVR value,
65 * don't modify the performance monitor fields.
67 if (old.num_pmcs && !s->num_pmcs) {
68 t->num_pmcs = old.num_pmcs;
69 t->pmc_type = old.pmc_type;
72 * Let's ensure that the
73 * fix for the PMAO bug is enabled on compatibility mode.
75 t->cpu_features |= old.cpu_features & CPU_FTR_PMAO_BUG;
78 *PTRRELOC(&cur_cpu_spec) = &the_cpu_spec;
81 * Set the base platform string once; assumes
82 * we're called with real pvr first.
84 if (*PTRRELOC(&powerpc_base_platform) == NULL)
85 *PTRRELOC(&powerpc_base_platform) = t->platform;
87 #if defined(CONFIG_PPC64) || defined(CONFIG_BOOKE)
88 /* ppc64 and booke expect identify_cpu to also call setup_cpu for
89 * that processor. I will consolidate that at a later time, for now,
90 * just use #ifdef. We also don't need to PTRRELOC the function
91 * pointer on ppc64 and booke as we are running at 0 in real mode
92 * on ppc64 and reloc_offset is always 0 on booke.
95 t->cpu_setup(offset, t);
97 #endif /* CONFIG_PPC64 || CONFIG_BOOKE */
102 struct cpu_spec * __init identify_cpu(unsigned long offset, unsigned int pvr)
104 struct cpu_spec *s = cpu_specs;
107 BUILD_BUG_ON(!ARRAY_SIZE(cpu_specs));
111 for (i = 0; i < ARRAY_SIZE(cpu_specs); i++,s++) {
112 if ((pvr & s->pvr_mask) == s->pvr_value)
113 return setup_cpu_spec(offset, s);
122 * Used by cpufeatures to get the name for CPUs with a PVR table.
123 * If they don't hae a PVR table, cpufeatures gets the name from
124 * cpu device-tree node.
126 void __init identify_cpu_name(unsigned int pvr)
128 struct cpu_spec *s = cpu_specs;
129 struct cpu_spec *t = &the_cpu_spec;
135 for (i = 0; i < ARRAY_SIZE(cpu_specs); i++,s++) {
136 if ((pvr & s->pvr_mask) == s->pvr_value) {
137 t->cpu_name = s->cpu_name;
144 #ifdef CONFIG_JUMP_LABEL_FEATURE_CHECKS
145 struct static_key_true cpu_feature_keys[NUM_CPU_FTR_KEYS] = {
146 [0 ... NUM_CPU_FTR_KEYS - 1] = STATIC_KEY_TRUE_INIT
148 EXPORT_SYMBOL_GPL(cpu_feature_keys);
150 void __init cpu_feature_keys_init(void)
154 for (i = 0; i < NUM_CPU_FTR_KEYS; i++) {
155 unsigned long f = 1ul << i;
157 if (!(cur_cpu_spec->cpu_features & f))
158 static_branch_disable(&cpu_feature_keys[i]);
162 struct static_key_true mmu_feature_keys[NUM_MMU_FTR_KEYS] = {
163 [0 ... NUM_MMU_FTR_KEYS - 1] = STATIC_KEY_TRUE_INIT
165 EXPORT_SYMBOL(mmu_feature_keys);
167 void __init mmu_feature_keys_init(void)
171 for (i = 0; i < NUM_MMU_FTR_KEYS; i++) {
172 unsigned long f = 1ul << i;
174 if (!(cur_cpu_spec->mmu_features & f))
175 static_branch_disable(&mmu_feature_keys[i]);