ARM: Factor out cpuid implementor and part number
Subsystems (3)
PATCH v3 1/1 ARM: Factor out cpuid implementor and part number
Decoding the implementor and part number of the CPU id in the CPU ID register is needed by KVM, so we factor it out to share the code.
---
Changes since v2:
- Take implementor as argument to read_cpuid_part_number
Changes since v1:
- Accidentally pointed to an old file, this one has more consistent naming of the cpu implementor and part number defines.
arch/arm/include/asm/cputype.h | 34 ++++++++++++++++++++++++++++++++++ arch/arm/kernel/perf_event_cpu.c | 33 +++++++++++++++++---------------- 2 files changed, 51 insertions(+), 16 deletions(-)
arch/arm/include/asm/cputype.h +34 -0
@@ -51,6 +51,22 @@ extern unsigned int processor_id;#define read_cpuid_ext (reg) 0#endif +#define ARM_CPU_IMP_ARM 0x41 +#define ARM_CPU_IMP_INTEL 0x69 + +#define ARM_CPU_PART_ARM1136 0xB360 +#define ARM_CPU_PART_ARM1156 0xB560 +#define ARM_CPU_PART_ARM1176 0xB760 +#define ARM_CPU_PART_ARM11MPCORE 0xB020 +#define ARM_CPU_PART_CORTEX_A8 0xC080 +#define ARM_CPU_PART_CORTEX_A9 0xC090 +#define ARM_CPU_PART_CORTEX_A5 0xC050 +#define ARM_CPU_PART_CORTEX_A15 0xC0F0 +#define ARM_CPU_PART_CORTEX_A7 0xC070 + +#define ARM_CPU_PART_XSCALE1 0x1 +#define ARM_CPU_PART_XSCALE2 0x2 +/* * The CPU ID never changes at run time, so we might as well tell the * compiler that it's constant. Use this function to read the CPU ID
@@ -61,6 +77,24 @@ static inline unsigned int __attribute_const__ read_cpuid_id(void)return read_cpuid (CPUID_ID ); } +static inline unsigned int __attribute_const__ read_cpuid_implementor(void) +{ +return (read_cpuid_id () &0xFF000000 ) >>24 ; +} + +static inline unsigned int __attribute_const__ +read_cpuid_part_number (unsigned int implementor) +{ +switch (implementor) { +case ARM_CPU_IMP_ARM : +return (read_cpuid_id () &0xFFF0 ); +case ARM_CPU_IMP_INTEL : +return (read_cpuid_id () >>13 ) &0x7 ; +default : +return 0 ; + } +} + static inline unsigned int __attribute_const__ read_cpuid_cachetype(void) {return read_cpuid (CPUID_CACHETYPE );
arch/arm/kernel/perf_event_cpu.c +17 -16
@@ -202,47 +202,48 @@ static int __devinit probe_current_pmu(struct arm_pmu *pmu) {int cpu =get_cpu ();unsigned long cpuid =read_cpuid_id (); -unsigned long implementor = (cpuid &0xFF000000 ) >>24 ; -unsigned long part_number = (cpuid &0xFFF0 ); +unsigned long implementor =read_cpuid_implementor (); +unsigned long part_number;int ret = -ENODEV ;pr_info ("probing PMU on CPU %d\n" , cpu);/* ARM Ltd CPUs. */ -if (0x41 == implementor) { +if (implementor ==ARM_CPU_IMP_ARM ) { + part_number =read_cpuid_part_number (implementor);switch (part_number) { -case 0xB360 :/* ARM1136 */ -case 0xB560 :/* ARM1156 */ -case 0xB760 :/* ARM1176 */ +case ARM_CPU_PART_ARM1136 : +case ARM_CPU_PART_ARM1156 : +case ARM_CPU_PART_ARM1176 : ret =armv6pmu_init (pmu);break ; -case 0xB020 :/* ARM11mpcore */ +case ARM_CPU_PART_ARM11MPCORE : ret =armv6mpcore_pmu_init (pmu);break ; -case 0xC080 :/* Cortex-A8 */ +case ARM_CPU_PART_CORTEX_A8 : ret =armv7_a8_pmu_init (pmu);break ; -case 0xC090 :/* Cortex-A9 */ +case ARM_CPU_PART_CORTEX_A9 : ret =armv7_a9_pmu_init (pmu);break ; -case 0xC050 :/* Cortex-A5 */ +case ARM_CPU_PART_CORTEX_A5 : ret =armv7_a5_pmu_init (pmu);break ; -case 0xC0F0 :/* Cortex-A15 */ +case ARM_CPU_PART_CORTEX_A15 : ret =armv7_a15_pmu_init (pmu);break ; -case 0xC070 :/* Cortex-A7 */ +case ARM_CPU_PART_CORTEX_A7 : ret =armv7_a7_pmu_init (pmu);break ; }/* Intel CPUs [xscale]. */ - }else if (0x69 == implementor) { - part_number = (cpuid >>13 ) &0x7 ; + }else if (implementor ==ARM_CPU_IMP_INTEL ) { + part_number =read_cpuid_part_number (implementor);switch (part_number) { -case 1 : +case ARM_CPU_PART_XSCALE1 : ret =xscale1pmu_init (pmu);break ; -case 2 : +case ARM_CPU_PART_XSCALE2 : ret =xscale2pmu_init (pmu);break ; }
Signature · 1 line
1.7.9.5
PATCH v3 1/1 ARM: Factor out cpuid implementor and part number
Quoted 8 lines · Christoffer Dall
Decoding the implementor and part number of the CPU id in the CPU ID register is needed by KVM, so we factor it out to share the code.
Cc Will Deacon <[email protected]>Signed-off-by Christoffer Dall <[email protected]>---
Changes since v2:
- Take implementor as argument toread_cpuid_part_number
Actually, I don't think this is the correct way. There's noting inherently different about Xscale wrt part numbers, it's just that someone decided to do stuff "differently" and use the CPU part number to identify the SoC as a whole.
Here's the full list:
80200 69052000 fffffff0
PXA250 69052100 fffff7f0
PXA210 69052120 fffff3f0
8032x 69052420 fffff7e0
PXA255 69052d00 fffffff0
80219 69052e20 ffffffe0
8033x 69054010 fffffd30
IXP43x 69054040 fffffff0
PXA270 69054110 fffffff0
IXP2400 69054190 fffffff0
IXP2800 690541a0 fffffff0
IXP42x 690541c0 ffffffc0
IXP46x 69054200 ffffff00
Xscale3 69056000 ffffe000
PXA935 56056000 ffffe000
What we get from these is:
XScale1 can be identified by (id & 0xe000) == 0x2000 Xscale2 can be identified by (id & 0xe000) == 0x4000 Xscale3 can be identified by (id & 0xe000) == 0x6000
I don't think we should make a distinction in read_cpuid_part_number() between these; if manufacturers are silly enough to abuse these fields then its their problem. :)
What I suggest is that read_cpuid_part_number() returns the part number field as defined by ARM. We then also define XSCALE_ARCH_MASK to be 0xe000 and a bunch of XSCALE_ARCH_V1..V3 along those lines. Maybe even a xscale_cpu_version() macro which returns the XScale CPU version pre-masked.
That would mean this becomes:
arch/arm/kernel/perf_event_cpu.c static int __devinit probe_current_pmu(struct arm_pmu *pmu) · line 205
Quoted 7 lines
arch/arm/kernel/perf_event_cpu.c +1
-2@@ -202,47 +202,48 @@ static int __devinit probe_current_pmu(struct arm_pmu *pmu) {int cpu =get_cpu ();unsigned long cpuid =read_cpuid_id (); -unsigned long implementor = (cpuid &0xFF000000 ) >>24 ; -unsigned long part_number = (cpuid &0xFFF0 ); +unsigned long implementor =read_cpuid_implementor ();
Why not pass the cpuid that we read into these functions?
arch/arm/kernel/perf_event_cpu.c static int __devinit probe_current_pmu(struct arm_pmu *pmu) · line 206
Quoted 1 line
arch/arm/kernel/perf_event_cpu.c +1
-0+unsigned long part_number;
unsigned long part_number = read_cpuid_part_number(cpuid);
arch/arm/kernel/perf_event_cpu.c static int __devinit probe_current_pmu(struct arm_pmu *pmu) · line 213
Quoted 8 lines
arch/arm/kernel/perf_event_cpu.c +2
-1int ret = -ENODEV ;pr_info ("probing PMU on CPU %d\n" , cpu);/* ARM Ltd CPUs. */ -if (0x41 == implementor) { +if (implementor ==ARM_CPU_IMP_ARM ) { + part_number =read_cpuid_part_number (implementor);
This goes.
Quoted 30 lines
arch/arm/kernel/perf_event_cpu.c +8
-9switch (part_number) { -case 0xB360 :/* ARM1136 */ -case 0xB560 :/* ARM1156 */ -case 0xB760 :/* ARM1176 */ +case ARM_CPU_PART_ARM1136 : +case ARM_CPU_PART_ARM1156 : +case ARM_CPU_PART_ARM1176 : ret =armv6pmu_init (pmu);break ; -case 0xB020 :/* ARM11mpcore */ +case ARM_CPU_PART_ARM11MPCORE : ret =armv6mpcore_pmu_init (pmu);break ; -case 0xC080 :/* Cortex-A8 */ +case ARM_CPU_PART_CORTEX_A8 : ret =armv7_a8_pmu_init (pmu);break ; -case 0xC090 :/* Cortex-A9 */ +case ARM_CPU_PART_CORTEX_A9 : ret =armv7_a9_pmu_init (pmu);break ; -case 0xC050 :/* Cortex-A5 */ +case ARM_CPU_PART_CORTEX_A5 : ret =armv7_a5_pmu_init (pmu);break ; -case 0xC0F0 :/* Cortex-A15 */ +case ARM_CPU_PART_CORTEX_A15 : ret =armv7_a15_pmu_init (pmu);break ; -case 0xC070 :/* Cortex-A7 */
arch/arm/kernel/perf_event_cpu.c static int __devinit probe_current_pmu(struct arm_pmu *pmu) · line 242
Quoted 10 lines
arch/arm/kernel/perf_event_cpu.c +3
-2+case ARM_CPU_PART_CORTEX_A7 : ret =armv7_a7_pmu_init (pmu);break ; }/* Intel CPUs [xscale]. */ - }else if (0x69 == implementor) { - part_number = (cpuid >>13 ) &0x7 ; + }else if (implementor ==ARM_CPU_IMP_INTEL ) { + part_number =read_cpuid_part_number (implementor);switch (part_number) {
switch (xscale_cpu_version(part_number)) {arch/arm/kernel/perf_event_cpu.c static int __devinit probe_current_pmu(struct arm_pmu *pmu) · line 243
Quoted 2 lines
arch/arm/kernel/perf_event_cpu.c +1
-1-case 1 : +case ARM_CPU_PART_XSCALE1 :
case XSCALE_ARCH_V1:
arch/arm/kernel/perf_event_cpu.c static int __devinit probe_current_pmu(struct arm_pmu *pmu) · line 246
Quoted 4 lines
arch/arm/kernel/perf_event_cpu.c +1
-1ret =xscale1pmu_init (pmu);break ; -case 2 : +case ARM_CPU_PART_XSCALE2 :
case XSCALE_ARCH_V2:
and we can use read_cpuid_part_number() where getting at that field in the CPU ID information matters.
PATCH v3 1/1 ARM: Factor out cpuid implementor and part number
Quoted 42 lines · Russell King - ARM Linux
Quoted 8 lines · Christoffer Dall
Decoding the implementor and part number of the CPU id in the CPU ID register is needed by KVM, so we factor it out to share the code.
Cc Will Deacon <[email protected]>Signed-off-by Christoffer Dall <[email protected]>---
Changes since v2:
- Take implementor as argument toread_cpuid_part_numberActually, I don't think this is the correct way. There's noting inherently different about Xscale wrt part numbers, it's just that someone decided to do stuff "differently" and use the CPU part number to identify the SoC as a whole.
Here's the full list:
80200 69052000
fffffff0
PXA250 69052100fffff7f0
PXA210 69052120fffff3f0
8032x 69052420fffff7e0
PXA25569052d00fffffff0
8021969052e20ffffffe0
8033x 69054010fffffd30
IXP43x 69054040fffffff0
PXA270 69054110fffffff0
IXP2400 69054190fffffff0
IXP2800690541a0fffffff0
IXP42x690541c0ffffffc0
IXP46x 69054200ffffff00
Xscale3 69056000ffffe000
PXA935 56056000ffffe000What we get from these is:
XScale1 can be identified by (id &0xe000) ==0x2000Xscale2 can be identified by (id &0xe000) ==0x4000Xscale3 can be identified by (id &0xe000) ==0x6000I don't think we should make a distinction in
read_cpuid_part_number()between these; if manufacturers are silly enough to abuse these fields then its their problem. :)
Quoted 5 lines
What I suggest is that
read_cpuid_part_number()returns the part number field as defined by ARM. We then also defineXSCALE_ARCH_MASKto be0xe000and a bunch of XSCALE_ARCH_V1..V3 along those lines. Maybe even axscale_cpu_version()macro which returns the XScale CPU version pre-masked.
Here's the other place where the CPU ID is parsed on Xscale devices:
drivers/usb/gadget/pxa25x_udc.c-#define CP15R0_VENDOR_MASK 0xffffe000
drivers/usb/gadget/pxa25x_udc.c:#define CP15R0_XSCALE_VALUE 0x69052000 /* intel/arm/xscale */
drivers/usb/gadget/pxa25x_udc.c:#define CP15R0_XSCALE_VALUE 0x69054000 /* intel/arm/ixp4xx */drivers/usb/gadget/pxa25x_udc.c- asm("mrc%? p15, 0, %0, c0, c0" : "=r" (chiprev));drivers/usb/gadget/pxa25x_udc.c: if ((chiprev & CP15R0_VENDOR_MASK) != CP15R0_XSCALE_VALUE) {drivers/usb/gadget/pxa25x_udc.c- pr_err("%s: not XScale!\n", driver_name);drivers/usb/gadget/pxa25x_udc.c- return -ENODEV;drivers/usb/gadget/pxa25x_udc.c- }
PATCH v3 1/1 ARM: Factor out cpuid implementor and part number
In reply to Russell King - ARM LinuxQuoted 42 lines · Russell King - ARM Linux
Quoted 8 lines · Christoffer Dall
Decoding the implementor and part number of the CPU id in the CPU ID register is needed by KVM, so we factor it out to share the code.
Cc Will Deacon <[email protected]>Signed-off-by Christoffer Dall <[email protected]>---
Changes since v2:
- Take implementor as argument toread_cpuid_part_numberActually, I don't think this is the correct way. There's noting inherently different about Xscale wrt part numbers, it's just that someone decided to do stuff "differently" and use the CPU part number to identify the SoC as a whole.
Here's the full list:
80200 69052000 fffffff0 PXA250 69052100 fffff7f0 PXA210 69052120 fffff3f0 8032x 69052420 fffff7e0 PXA255 69052d00 fffffff0 80219 69052e20 ffffffe0 8033x 69054010 fffffd30 IXP43x 69054040 fffffff0 PXA270 69054110 fffffff0 IXP2400 69054190 fffffff0 IXP2800 690541a0 fffffff0 IXP42x 690541c0 ffffffc0 IXP46x 69054200 ffffff00 Xscale3 69056000 ffffe000 PXA935 56056000 ffffe000What we get from these is:
XScale1 can be identified by (id &0xe000) ==0x2000Xscale2 can be identified by (id &0xe000) ==0x4000Xscale3 can be identified by (id &0xe000) ==0x6000I don't think we should make a distinction in
read_cpuid_part_number()between these; if manufacturers are silly enough to abuse these fields then its their problem. :)
Quoted 8 lines
What I suggest is that
read_cpuid_part_number()returns the part number field as defined by ARM. We then also defineXSCALE_ARCH_MASKto be0xe000and a bunch of XSCALE_ARCH_V1..V3 along those lines. Maybe even axscale_cpu_version()macro which returns the XScale CPU version pre-masked.That would mean this becomes:
sounds great to me.
Quoted 10 lines
arch/arm/kernel/perf_event_cpu.c static int __devinit probe_current_pmu(struct arm_pmu *pmu) · line 205
Quoted 7 lines
arch/arm/kernel/perf_event_cpu.c +1
-2@@ -202,47 +202,48 @@ static int __devinit probe_current_pmu(struct arm_pmu *pmu) {int cpu =get_cpu ();unsigned long cpuid =read_cpuid_id (); -unsigned long implementor = (cpuid &0xFF000000 ) >>24 ; -unsigned long part_number = (cpuid &0xFFF0 ); +unsigned long implementor =read_cpuid_implementor ();Why not pass the cpuid that we read into these functions?
we actually don't need that one anymore, and it all has __attribute_const__ anyhow.
Quoted 67 lines
arch/arm/kernel/perf_event_cpu.c static int __devinit probe_current_pmu(struct arm_pmu *pmu) · line 206
Quoted 1 line
arch/arm/kernel/perf_event_cpu.c +1
-0+unsigned long part_number;unsigned long part_number = read_cpuid_part_number(cpuid);arch/arm/kernel/perf_event_cpu.c static int __devinit probe_current_pmu(struct arm_pmu *pmu) · line 213
Quoted 8 lines
arch/arm/kernel/perf_event_cpu.c +2
-1int ret = -ENODEV ;pr_info ("probing PMU on CPU %d\n" , cpu);/* ARM Ltd CPUs. */ -if (0x41 == implementor) { +if (implementor ==ARM_CPU_IMP_ARM ) { + part_number =read_cpuid_part_number (implementor);This goes.
Quoted 30 lines
arch/arm/kernel/perf_event_cpu.c +8
-9switch (part_number) { -case 0xB360 :/* ARM1136 */ -case 0xB560 :/* ARM1156 */ -case 0xB760 :/* ARM1176 */ +case ARM_CPU_PART_ARM1136 : +case ARM_CPU_PART_ARM1156 : +case ARM_CPU_PART_ARM1176 : ret =armv6pmu_init (pmu);break ; -case 0xB020 :/* ARM11mpcore */ +case ARM_CPU_PART_ARM11MPCORE : ret =armv6mpcore_pmu_init (pmu);break ; -case 0xC080 :/* Cortex-A8 */ +case ARM_CPU_PART_CORTEX_A8 : ret =armv7_a8_pmu_init (pmu);break ; -case 0xC090 :/* Cortex-A9 */ +case ARM_CPU_PART_CORTEX_A9 : ret =armv7_a9_pmu_init (pmu);break ; -case 0xC050 :/* Cortex-A5 */ +case ARM_CPU_PART_CORTEX_A5 : ret =armv7_a5_pmu_init (pmu);break ; -case 0xC0F0 :/* Cortex-A15 */ +case ARM_CPU_PART_CORTEX_A15 : ret =armv7_a15_pmu_init (pmu);break ; -case 0xC070 :/* Cortex-A7 */ arch/arm/kernel/perf_event_cpu.c static int __devinit probe_current_pmu(struct arm_pmu *pmu) · line 242
Quoted 10 lines
arch/arm/kernel/perf_event_cpu.c +3
-2+case ARM_CPU_PART_CORTEX_A7 : ret =armv7_a7_pmu_init (pmu);break ; }/* Intel CPUs [xscale]. */ - }else if (0x69 == implementor) { - part_number = (cpuid >>13 ) &0x7 ; + }else if (implementor ==ARM_CPU_IMP_INTEL ) { + part_number =read_cpuid_part_number (implementor);switch (part_number) {switch (xscale_cpu_version(part_number)) {arch/arm/kernel/perf_event_cpu.c static int __devinit probe_current_pmu(struct arm_pmu *pmu) · line 243
Quoted 2 lines
arch/arm/kernel/perf_event_cpu.c +1
-1-case 1 : +case ARM_CPU_PART_XSCALE1 :case
XSCALE_ARCH_V1:arch/arm/kernel/perf_event_cpu.c static int __devinit probe_current_pmu(struct arm_pmu *pmu) · line 246
Quoted 4 lines
arch/arm/kernel/perf_event_cpu.c +1
-1ret =xscale1pmu_init (pmu);break ; -case 2 : +case ARM_CPU_PART_XSCALE2 :
Quoted 4 lines
case
XSCALE_ARCH_V2:and we can use
read_cpuid_part_number()where getting at that field in the CPU ID information matters.
sending out a new patch.
Thanks!
-Christoffer