• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2012 ARM Ltd.
4  */
5 #ifndef __ASM_CPUTYPE_H
6 #define __ASM_CPUTYPE_H
7 
8 #define INVALID_HWID		ULONG_MAX
9 
10 #define MPIDR_UP_BITMASK	(0x1 << 30)
11 #define MPIDR_MT_BITMASK	(0x1 << 24)
12 #define MPIDR_HWID_BITMASK	UL(0xff00ffffff)
13 
14 #define MPIDR_LEVEL_BITS_SHIFT	3
15 #define MPIDR_LEVEL_BITS	(1 << MPIDR_LEVEL_BITS_SHIFT)
16 #define MPIDR_LEVEL_MASK	((1 << MPIDR_LEVEL_BITS) - 1)
17 
18 #define MPIDR_LEVEL_SHIFT(level) \
19 	(((1 << level) >> 1) << MPIDR_LEVEL_BITS_SHIFT)
20 
21 #define MPIDR_AFFINITY_LEVEL(mpidr, level) \
22 	((mpidr >> MPIDR_LEVEL_SHIFT(level)) & MPIDR_LEVEL_MASK)
23 
24 #define MIDR_REVISION_MASK	0xf
25 #define MIDR_REVISION(midr)	((midr) & MIDR_REVISION_MASK)
26 #define MIDR_PARTNUM_SHIFT	4
27 #define MIDR_PARTNUM_MASK	(0xfff << MIDR_PARTNUM_SHIFT)
28 #define MIDR_PARTNUM(midr)	\
29 	(((midr) & MIDR_PARTNUM_MASK) >> MIDR_PARTNUM_SHIFT)
30 #define MIDR_ARCHITECTURE_SHIFT	16
31 #define MIDR_ARCHITECTURE_MASK	(0xf << MIDR_ARCHITECTURE_SHIFT)
32 #define MIDR_ARCHITECTURE(midr)	\
33 	(((midr) & MIDR_ARCHITECTURE_MASK) >> MIDR_ARCHITECTURE_SHIFT)
34 #define MIDR_VARIANT_SHIFT	20
35 #define MIDR_VARIANT_MASK	(0xf << MIDR_VARIANT_SHIFT)
36 #define MIDR_VARIANT(midr)	\
37 	(((midr) & MIDR_VARIANT_MASK) >> MIDR_VARIANT_SHIFT)
38 #define MIDR_IMPLEMENTOR_SHIFT	24
39 #define MIDR_IMPLEMENTOR_MASK	(0xff << MIDR_IMPLEMENTOR_SHIFT)
40 #define MIDR_IMPLEMENTOR(midr)	\
41 	(((midr) & MIDR_IMPLEMENTOR_MASK) >> MIDR_IMPLEMENTOR_SHIFT)
42 
43 #define MIDR_CPU_MODEL(imp, partnum) \
44 	(((imp)			<< MIDR_IMPLEMENTOR_SHIFT) | \
45 	(0xf			<< MIDR_ARCHITECTURE_SHIFT) | \
46 	((partnum)		<< MIDR_PARTNUM_SHIFT))
47 
48 #define MIDR_CPU_VAR_REV(var, rev) \
49 	(((var)	<< MIDR_VARIANT_SHIFT) | (rev))
50 
51 #define MIDR_CPU_MODEL_MASK (MIDR_IMPLEMENTOR_MASK | MIDR_PARTNUM_MASK | \
52 			     MIDR_ARCHITECTURE_MASK)
53 
54 #define ARM_CPU_IMP_ARM			0x41
55 #define ARM_CPU_IMP_APM			0x50
56 #define ARM_CPU_IMP_CAVIUM		0x43
57 #define ARM_CPU_IMP_BRCM		0x42
58 #define ARM_CPU_IMP_QCOM		0x51
59 #define ARM_CPU_IMP_NVIDIA		0x4E
60 #define ARM_CPU_IMP_FUJITSU		0x46
61 #define ARM_CPU_IMP_HISI		0x48
62 
63 #define ARM_CPU_PART_AEM_V8		0xD0F
64 #define ARM_CPU_PART_FOUNDATION		0xD00
65 #define ARM_CPU_PART_CORTEX_A57		0xD07
66 #define ARM_CPU_PART_CORTEX_A72		0xD08
67 #define ARM_CPU_PART_CORTEX_A53		0xD03
68 #define ARM_CPU_PART_CORTEX_A73		0xD09
69 #define ARM_CPU_PART_CORTEX_A75		0xD0A
70 #define ARM_CPU_PART_CORTEX_A35		0xD04
71 #define ARM_CPU_PART_CORTEX_A55		0xD05
72 #define ARM_CPU_PART_CORTEX_A76		0xD0B
73 #define ARM_CPU_PART_NEOVERSE_N1	0xD0C
74 
75 #define APM_CPU_PART_POTENZA		0x000
76 
77 #define CAVIUM_CPU_PART_THUNDERX	0x0A1
78 #define CAVIUM_CPU_PART_THUNDERX_81XX	0x0A2
79 #define CAVIUM_CPU_PART_THUNDERX_83XX	0x0A3
80 #define CAVIUM_CPU_PART_THUNDERX2	0x0AF
81 
82 #define BRCM_CPU_PART_BRAHMA_B53	0x100
83 #define BRCM_CPU_PART_VULCAN		0x516
84 
85 #define QCOM_CPU_PART_FALKOR_V1		0x800
86 #define QCOM_CPU_PART_FALKOR		0xC00
87 #define QCOM_CPU_PART_KRYO		0x200
88 
89 #define NVIDIA_CPU_PART_DENVER		0x003
90 #define NVIDIA_CPU_PART_CARMEL		0x004
91 
92 #define FUJITSU_CPU_PART_A64FX		0x001
93 
94 #define HISI_CPU_PART_TSV110		0xD01
95 
96 #define MIDR_CORTEX_A53 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A53)
97 #define MIDR_CORTEX_A57 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A57)
98 #define MIDR_CORTEX_A72 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A72)
99 #define MIDR_CORTEX_A73 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A73)
100 #define MIDR_CORTEX_A75 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A75)
101 #define MIDR_CORTEX_A35 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A35)
102 #define MIDR_CORTEX_A55 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A55)
103 #define MIDR_CORTEX_A76	MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_CORTEX_A76)
104 #define MIDR_NEOVERSE_N1 MIDR_CPU_MODEL(ARM_CPU_IMP_ARM, ARM_CPU_PART_NEOVERSE_N1)
105 #define MIDR_THUNDERX	MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX)
106 #define MIDR_THUNDERX_81XX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX_81XX)
107 #define MIDR_THUNDERX_83XX MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX_83XX)
108 #define MIDR_CAVIUM_THUNDERX2 MIDR_CPU_MODEL(ARM_CPU_IMP_CAVIUM, CAVIUM_CPU_PART_THUNDERX2)
109 #define MIDR_BRAHMA_B53 MIDR_CPU_MODEL(ARM_CPU_IMP_BRCM, BRCM_CPU_PART_BRAHMA_B53)
110 #define MIDR_BRCM_VULCAN MIDR_CPU_MODEL(ARM_CPU_IMP_BRCM, BRCM_CPU_PART_VULCAN)
111 #define MIDR_QCOM_FALKOR_V1 MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_FALKOR_V1)
112 #define MIDR_QCOM_FALKOR MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_FALKOR)
113 #define MIDR_QCOM_KRYO MIDR_CPU_MODEL(ARM_CPU_IMP_QCOM, QCOM_CPU_PART_KRYO)
114 #define MIDR_NVIDIA_DENVER MIDR_CPU_MODEL(ARM_CPU_IMP_NVIDIA, NVIDIA_CPU_PART_DENVER)
115 #define MIDR_NVIDIA_CARMEL MIDR_CPU_MODEL(ARM_CPU_IMP_NVIDIA, NVIDIA_CPU_PART_CARMEL)
116 #define MIDR_FUJITSU_A64FX MIDR_CPU_MODEL(ARM_CPU_IMP_FUJITSU, FUJITSU_CPU_PART_A64FX)
117 #define MIDR_HISI_TSV110 MIDR_CPU_MODEL(ARM_CPU_IMP_HISI, HISI_CPU_PART_TSV110)
118 
119 /* Fujitsu Erratum 010001 affects A64FX 1.0 and 1.1, (v0r0 and v1r0) */
120 #define MIDR_FUJITSU_ERRATUM_010001		MIDR_FUJITSU_A64FX
121 #define MIDR_FUJITSU_ERRATUM_010001_MASK	(~MIDR_CPU_VAR_REV(1, 0))
122 #define TCR_CLEAR_FUJITSU_ERRATUM_010001	(TCR_NFD1 | TCR_NFD0)
123 
124 #ifndef __ASSEMBLY__
125 
126 #include <asm/sysreg.h>
127 
128 #define read_cpuid(reg)			read_sysreg_s(SYS_ ## reg)
129 
130 /*
131  * Represent a range of MIDR values for a given CPU model and a
132  * range of variant/revision values.
133  *
134  * @model	- CPU model as defined by MIDR_CPU_MODEL
135  * @rv_min	- Minimum value for the revision/variant as defined by
136  *		  MIDR_CPU_VAR_REV
137  * @rv_max	- Maximum value for the variant/revision for the range.
138  */
139 struct midr_range {
140 	u32 model;
141 	u32 rv_min;
142 	u32 rv_max;
143 };
144 
145 #define MIDR_RANGE(m, v_min, r_min, v_max, r_max)		\
146 	{							\
147 		.model = m,					\
148 		.rv_min = MIDR_CPU_VAR_REV(v_min, r_min),	\
149 		.rv_max = MIDR_CPU_VAR_REV(v_max, r_max),	\
150 	}
151 
152 #define MIDR_REV_RANGE(m, v, r_min, r_max) MIDR_RANGE(m, v, r_min, v, r_max)
153 #define MIDR_REV(m, v, r) MIDR_RANGE(m, v, r, v, r)
154 #define MIDR_ALL_VERSIONS(m) MIDR_RANGE(m, 0, 0, 0xf, 0xf)
155 
midr_is_cpu_model_range(u32 midr,u32 model,u32 rv_min,u32 rv_max)156 static inline bool midr_is_cpu_model_range(u32 midr, u32 model, u32 rv_min,
157 					   u32 rv_max)
158 {
159 	u32 _model = midr & MIDR_CPU_MODEL_MASK;
160 	u32 rv = midr & (MIDR_REVISION_MASK | MIDR_VARIANT_MASK);
161 
162 	return _model == model && rv >= rv_min && rv <= rv_max;
163 }
164 
is_midr_in_range(u32 midr,struct midr_range const * range)165 static inline bool is_midr_in_range(u32 midr, struct midr_range const *range)
166 {
167 	return midr_is_cpu_model_range(midr, range->model,
168 				       range->rv_min, range->rv_max);
169 }
170 
171 static inline bool
is_midr_in_range_list(u32 midr,struct midr_range const * ranges)172 is_midr_in_range_list(u32 midr, struct midr_range const *ranges)
173 {
174 	while (ranges->model)
175 		if (is_midr_in_range(midr, ranges++))
176 			return true;
177 	return false;
178 }
179 
180 /*
181  * The CPU ID never changes at run time, so we might as well tell the
182  * compiler that it's constant.  Use this function to read the CPU ID
183  * rather than directly reading processor_id or read_cpuid() directly.
184  */
read_cpuid_id(void)185 static inline u32 __attribute_const__ read_cpuid_id(void)
186 {
187 	return read_cpuid(MIDR_EL1);
188 }
189 
read_cpuid_mpidr(void)190 static inline u64 __attribute_const__ read_cpuid_mpidr(void)
191 {
192 	return read_cpuid(MPIDR_EL1);
193 }
194 
read_cpuid_implementor(void)195 static inline unsigned int __attribute_const__ read_cpuid_implementor(void)
196 {
197 	return MIDR_IMPLEMENTOR(read_cpuid_id());
198 }
199 
read_cpuid_part_number(void)200 static inline unsigned int __attribute_const__ read_cpuid_part_number(void)
201 {
202 	return MIDR_PARTNUM(read_cpuid_id());
203 }
204 
read_cpuid_cachetype(void)205 static inline u32 __attribute_const__ read_cpuid_cachetype(void)
206 {
207 	return read_cpuid(CTR_EL0);
208 }
209 #endif /* __ASSEMBLY__ */
210 
211 #endif
212