Skip to content

Commit af040ff

Browse files
author
Russell King
committed
ARM: make it easier to check the CPU part number correctly
Ensure that platform maintainers check the CPU part number in the right manner: the CPU part number is meaningless without also checking the CPU implement(e|o)r (choose your preferred spelling!) Provide an interface which returns both the implementer and part number together, and update the definitions to include the implementer. Mark the old function as being deprecated... indeed, using the old function with the definitions will now always evaluate as false, so people must update their un-merged code to the new function. While this could be avoided by adding new definitions, we'd also have to create new names for them which would be awkward. Acked-by: Nicolas Pitre <nico@linaro.org> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent ee2593e commit af040ff

10 files changed

Lines changed: 66 additions & 63 deletions

File tree

‎arch/arm/include/asm/cputype.h‎

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,18 @@
6262
#define ARM_CPU_IMP_ARM 0x41
6363
#define ARM_CPU_IMP_INTEL 0x69
6464

65-
#define ARM_CPU_PART_ARM1136 0xB360
66-
#define ARM_CPU_PART_ARM1156 0xB560
67-
#define ARM_CPU_PART_ARM1176 0xB760
68-
#define ARM_CPU_PART_ARM11MPCORE 0xB020
69-
#define ARM_CPU_PART_CORTEX_A8 0xC080
70-
#define ARM_CPU_PART_CORTEX_A9 0xC090
71-
#define ARM_CPU_PART_CORTEX_A5 0xC050
72-
#define ARM_CPU_PART_CORTEX_A15 0xC0F0
73-
#define ARM_CPU_PART_CORTEX_A7 0xC070
74-
#define ARM_CPU_PART_CORTEX_A12 0xC0D0
75-
#define ARM_CPU_PART_CORTEX_A17 0xC0E0
65+
/* ARM implemented processors */
66+
#define ARM_CPU_PART_ARM1136 0x4100b360
67+
#define ARM_CPU_PART_ARM1156 0x4100b560
68+
#define ARM_CPU_PART_ARM1176 0x4100b760
69+
#define ARM_CPU_PART_ARM11MPCORE 0x4100b020
70+
#define ARM_CPU_PART_CORTEX_A8 0x4100c080
71+
#define ARM_CPU_PART_CORTEX_A9 0x4100c090
72+
#define ARM_CPU_PART_CORTEX_A5 0x4100c050
73+
#define ARM_CPU_PART_CORTEX_A7 0x4100c070
74+
#define ARM_CPU_PART_CORTEX_A12 0x4100c0d0
75+
#define ARM_CPU_PART_CORTEX_A17 0x4100c0e0
76+
#define ARM_CPU_PART_CORTEX_A15 0x4100c0f0
7677

7778
#define ARM_CPU_XSCALE_ARCH_MASK 0xe000
7879
#define ARM_CPU_XSCALE_ARCH_V1 0x2000
@@ -171,14 +172,24 @@ static inline unsigned int __attribute_const__ read_cpuid_implementor(void)
171172
return (read_cpuid_id() & 0xFF000000) >> 24;
172173
}
173174

174-
static inline unsigned int __attribute_const__ read_cpuid_part_number(void)
175+
/*
176+
* The CPU part number is meaningless without referring to the CPU
177+
* implementer: implementers are free to define their own part numbers
178+
* which are permitted to clash with other implementer part numbers.
179+
*/
180+
static inline unsigned int __attribute_const__ read_cpuid_part(void)
181+
{
182+
return read_cpuid_id() & 0xff00fff0;
183+
}
184+
185+
static inline unsigned int __attribute_const__ __deprecated read_cpuid_part_number(void)
175186
{
176187
return read_cpuid_id() & 0xFFF0;
177188
}
178189

179190
static inline unsigned int __attribute_const__ xscale_cpu_arch_version(void)
180191
{
181-
return read_cpuid_part_number() & ARM_CPU_XSCALE_ARCH_MASK;
192+
return read_cpuid_id() & ARM_CPU_XSCALE_ARCH_MASK;
182193
}
183194

184195
static inline unsigned int __attribute_const__ read_cpuid_cachetype(void)

‎arch/arm/include/asm/smp_scu.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
static inline bool scu_a9_has_base(void)
1313
{
14-
return read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9;
14+
return read_cpuid_part() == ARM_CPU_PART_CORTEX_A9;
1515
}
1616

1717
static inline unsigned long scu_a9_get_base(void)

‎arch/arm/kernel/perf_event_cpu.c‎

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -250,40 +250,39 @@ static struct platform_device_id cpu_pmu_plat_device_ids[] = {
250250
static int probe_current_pmu(struct arm_pmu *pmu)
251251
{
252252
int cpu = get_cpu();
253-
unsigned long implementor = read_cpuid_implementor();
254-
unsigned long part_number = read_cpuid_part_number();
255253
int ret = -ENODEV;
256254

257255
pr_info("probing PMU on CPU %d\n", cpu);
258256

257+
switch (read_cpuid_part()) {
259258
/* ARM Ltd CPUs. */
260-
if (implementor == ARM_CPU_IMP_ARM) {
261-
switch (part_number) {
262-
case ARM_CPU_PART_ARM1136:
263-
case ARM_CPU_PART_ARM1156:
264-
case ARM_CPU_PART_ARM1176:
265-
ret = armv6pmu_init(pmu);
266-
break;
267-
case ARM_CPU_PART_ARM11MPCORE:
268-
ret = armv6mpcore_pmu_init(pmu);
269-
break;
270-
case ARM_CPU_PART_CORTEX_A8:
271-
ret = armv7_a8_pmu_init(pmu);
272-
break;
273-
case ARM_CPU_PART_CORTEX_A9:
274-
ret = armv7_a9_pmu_init(pmu);
275-
break;
276-
}
277-
/* Intel CPUs [xscale]. */
278-
} else if (implementor == ARM_CPU_IMP_INTEL) {
279-
switch (xscale_cpu_arch_version()) {
280-
case ARM_CPU_XSCALE_ARCH_V1:
281-
ret = xscale1pmu_init(pmu);
282-
break;
283-
case ARM_CPU_XSCALE_ARCH_V2:
284-
ret = xscale2pmu_init(pmu);
285-
break;
259+
case ARM_CPU_PART_ARM1136:
260+
case ARM_CPU_PART_ARM1156:
261+
case ARM_CPU_PART_ARM1176:
262+
ret = armv6pmu_init(pmu);
263+
break;
264+
case ARM_CPU_PART_ARM11MPCORE:
265+
ret = armv6mpcore_pmu_init(pmu);
266+
break;
267+
case ARM_CPU_PART_CORTEX_A8:
268+
ret = armv7_a8_pmu_init(pmu);
269+
break;
270+
case ARM_CPU_PART_CORTEX_A9:
271+
ret = armv7_a9_pmu_init(pmu);
272+
break;
273+
274+
default:
275+
if (read_cpuid_implementor() == ARM_CPU_IMP_INTEL) {
276+
switch (xscale_cpu_arch_version()) {
277+
case ARM_CPU_XSCALE_ARCH_V1:
278+
ret = xscale1pmu_init(pmu);
279+
break;
280+
case ARM_CPU_XSCALE_ARCH_V2:
281+
ret = xscale2pmu_init(pmu);
282+
break;
283+
}
286284
}
285+
break;
287286
}
288287

289288
put_cpu();

‎arch/arm/kvm/guest.c‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,7 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
274274

275275
int __attribute_const__ kvm_target_cpu(void)
276276
{
277-
unsigned long implementor = read_cpuid_implementor();
278-
unsigned long part_number = read_cpuid_part_number();
279-
280-
if (implementor != ARM_CPU_IMP_ARM)
281-
return -EINVAL;
282-
283-
switch (part_number) {
277+
switch (read_cpuid_part()) {
284278
case ARM_CPU_PART_CORTEX_A7:
285279
return KVM_ARM_TARGET_CORTEX_A7;
286280
case ARM_CPU_PART_CORTEX_A15:

‎arch/arm/mach-exynos/mcpm-exynos.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ static void exynos_power_down(void)
196196
if (last_man && __mcpm_outbound_enter_critical(cpu, cluster)) {
197197
arch_spin_unlock(&exynos_mcpm_lock);
198198

199-
if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A15) {
199+
if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A15) {
200200
/*
201201
* On the Cortex-A15 we need to disable
202202
* L2 prefetching before flushing the cache.
@@ -291,7 +291,7 @@ static void __naked exynos_pm_power_up_setup(unsigned int affinity_level)
291291

292292
static void __init exynos_cache_off(void)
293293
{
294-
if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A15) {
294+
if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A15) {
295295
/* disable L2 prefetching on the Cortex-A15 */
296296
asm volatile(
297297
"mcr p15, 1, %0, c15, c0, 3\n\t"

‎arch/arm/mach-exynos/platsmp.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static void __init exynos_smp_init_cpus(void)
188188
void __iomem *scu_base = scu_base_addr();
189189
unsigned int i, ncores;
190190

191-
if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9)
191+
if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9)
192192
ncores = scu_base ? scu_get_core_count(scu_base) : 1;
193193
else
194194
/*
@@ -214,7 +214,7 @@ static void __init exynos_smp_prepare_cpus(unsigned int max_cpus)
214214

215215
exynos_sysram_init();
216216

217-
if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9)
217+
if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9)
218218
scu_enable(scu_base_addr());
219219

220220
/*

‎arch/arm/mach-exynos/pm.c‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ static int exynos_pm_suspend(void)
300300
tmp = (S5P_USE_STANDBY_WFI0 | S5P_USE_STANDBY_WFE0);
301301
__raw_writel(tmp, S5P_CENTRAL_SEQ_OPTION);
302302

303-
if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9)
303+
if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9)
304304
exynos_cpu_save_register();
305305

306306
return 0;
@@ -334,7 +334,7 @@ static void exynos_pm_resume(void)
334334
if (exynos_pm_central_resume())
335335
goto early_wakeup;
336336

337-
if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9)
337+
if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9)
338338
exynos_cpu_restore_register();
339339

340340
/* For release retention */
@@ -353,7 +353,7 @@ static void exynos_pm_resume(void)
353353

354354
s3c_pm_do_restore_core(exynos_core_save, ARRAY_SIZE(exynos_core_save));
355355

356-
if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9)
356+
if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9)
357357
scu_enable(S5P_VA_SCU);
358358

359359
early_wakeup:
@@ -440,15 +440,14 @@ static int exynos_cpu_pm_notifier(struct notifier_block *self,
440440
case CPU_PM_ENTER:
441441
if (cpu == 0) {
442442
exynos_pm_central_suspend();
443-
if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9)
443+
if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9)
444444
exynos_cpu_save_register();
445445
}
446446
break;
447447

448448
case CPU_PM_EXIT:
449449
if (cpu == 0) {
450-
if (read_cpuid_part_number() ==
451-
ARM_CPU_PART_CORTEX_A9) {
450+
if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9) {
452451
scu_enable(S5P_VA_SCU);
453452
exynos_cpu_restore_register();
454453
}

‎arch/arm/mach-vexpress/tc2_pm.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static void tc2_pm_down(u64 residency)
152152
if (last_man && __mcpm_outbound_enter_critical(cpu, cluster)) {
153153
arch_spin_unlock(&tc2_pm_lock);
154154

155-
if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A15) {
155+
if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A15) {
156156
/*
157157
* On the Cortex-A15 we need to disable
158158
* L2 prefetching before flushing the cache.
@@ -326,7 +326,7 @@ static void __naked tc2_pm_power_up_setup(unsigned int affinity_level)
326326
static void __init tc2_cache_off(void)
327327
{
328328
pr_info("TC2: disabling cache during MCPM loopback test\n");
329-
if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A15) {
329+
if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A15) {
330330
/* disable L2 prefetching on the Cortex-A15 */
331331
asm volatile(
332332
"mcr p15, 1, %0, c15, c0, 3 \n\t"

‎arch/arm/mm/cache-l2x0.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ static int l2c310_cpu_enable_flz(struct notifier_block *nb, unsigned long act, v
665665
static void __init l2c310_enable(void __iomem *base, u32 aux, unsigned num_lock)
666666
{
667667
unsigned rev = readl_relaxed(base + L2X0_CACHE_ID) & L2X0_CACHE_ID_PART_MASK;
668-
bool cortex_a9 = read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9;
668+
bool cortex_a9 = read_cpuid_part() == ARM_CPU_PART_CORTEX_A9;
669669

670670
if (rev >= L310_CACHE_ID_RTL_R2P0) {
671671
if (cortex_a9) {

‎drivers/clocksource/arm_global_timer.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ static void __init global_timer_of_register(struct device_node *np)
250250
* fire when the timer value is greater than or equal to. In previous
251251
* revisions the comparators fired when the timer value was equal to.
252252
*/
253-
if (read_cpuid_part_number() == ARM_CPU_PART_CORTEX_A9
253+
if (read_cpuid_part() == ARM_CPU_PART_CORTEX_A9
254254
&& (read_cpuid_id() & 0xf0000f) < 0x200000) {
255255
pr_warn("global-timer: non support for this cpu version.\n");
256256
return;

0 commit comments

Comments
 (0)