blob: ee6403df9fe4c1f32e9a7b30172a7a141056ec40 [file] [log] [blame]
Catalin Marinas9cce7a42012-03-05 11:49:28 +00001/*
2 * Copyright (C) 2012 ARM Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16#ifndef __ASM_CPUTYPE_H
17#define __ASM_CPUTYPE_H
18
Javi Merino3e98fda2013-01-31 20:09:04 +000019#define INVALID_HWID ULONG_MAX
20
Zi Shen Lim4e6f7082014-06-07 01:55:27 +010021#define MPIDR_UP_BITMASK (0x1 << 30)
22#define MPIDR_MT_BITMASK (0x1 << 24)
Javi Merino4c7aa002012-08-29 09:47:19 +010023#define MPIDR_HWID_BITMASK 0xff00ffffff
24
Lorenzo Pieralisib0584502013-08-05 15:24:27 +010025#define MPIDR_LEVEL_BITS_SHIFT 3
26#define MPIDR_LEVEL_BITS (1 << MPIDR_LEVEL_BITS_SHIFT)
27#define MPIDR_LEVEL_MASK ((1 << MPIDR_LEVEL_BITS) - 1)
28
29#define MPIDR_LEVEL_SHIFT(level) \
30 (((1 << level) >> 1) << MPIDR_LEVEL_BITS_SHIFT)
31
32#define MPIDR_AFFINITY_LEVEL(mpidr, level) \
33 ((mpidr >> MPIDR_LEVEL_SHIFT(level)) & MPIDR_LEVEL_MASK)
34
Catalin Marinas9cce7a42012-03-05 11:49:28 +000035#define read_cpuid(reg) ({ \
36 u64 __val; \
Ard Biesheuvel148eb0a2013-12-16 21:04:35 +000037 asm("mrs %0, " #reg : "=r" (__val)); \
Catalin Marinas9cce7a42012-03-05 11:49:28 +000038 __val; \
39})
40
Mark Rutland89c4a302014-07-16 16:32:43 +010041#define MIDR_REVISION_MASK 0xf
42#define MIDR_REVISION(midr) ((midr) & MIDR_REVISION_MASK)
43#define MIDR_PARTNUM_SHIFT 4
44#define MIDR_PARTNUM_MASK (0xfff << MIDR_PARTNUM_SHIFT)
45#define MIDR_PARTNUM(midr) \
46 (((midr) & MIDR_PARTNUM_MASK) >> MIDR_PARTNUM_SHIFT)
47#define MIDR_ARCHITECTURE_SHIFT 16
48#define MIDR_ARCHITECTURE_MASK (0xf << MIDR_ARCHITECTURE_SHIFT)
49#define MIDR_ARCHITECTURE(midr) \
50 (((midr) & MIDR_ARCHITECTURE_MASK) >> MIDR_ARCHITECTURE_SHIFT)
51#define MIDR_VARIANT_SHIFT 20
52#define MIDR_VARIANT_MASK (0xf << MIDR_VARIANT_SHIFT)
53#define MIDR_VARIANT(midr) \
54 (((midr) & MIDR_VARIANT_MASK) >> MIDR_VARIANT_SHIFT)
55#define MIDR_IMPLEMENTOR_SHIFT 24
56#define MIDR_IMPLEMENTOR_MASK (0xff << MIDR_IMPLEMENTOR_SHIFT)
57#define MIDR_IMPLEMENTOR(midr) \
58 (((midr) & MIDR_IMPLEMENTOR_MASK) >> MIDR_IMPLEMENTOR_SHIFT)
59
Andre Przywara301bcfa2014-11-14 15:54:10 +000060#define MIDR_CPU_PART(imp, partnum) \
61 (((imp) << MIDR_IMPLEMENTOR_SHIFT) | \
62 (0xf << MIDR_ARCHITECTURE_SHIFT) | \
63 ((partnum) << MIDR_PARTNUM_SHIFT))
64
Marc Zyngierd9c19512013-02-27 18:05:59 +000065#define ARM_CPU_IMP_ARM 0x41
Vinayak Kale4ad637a2013-04-24 10:06:59 +010066#define ARM_CPU_IMP_APM 0x50
Marc Zyngierd9c19512013-02-27 18:05:59 +000067
Mark Rutland89c4a302014-07-16 16:32:43 +010068#define ARM_CPU_PART_AEM_V8 0xD0F
69#define ARM_CPU_PART_FOUNDATION 0xD00
70#define ARM_CPU_PART_CORTEX_A57 0xD07
71#define ARM_CPU_PART_CORTEX_A53 0xD03
Marc Zyngierd9c19512013-02-27 18:05:59 +000072
Mark Rutland89c4a302014-07-16 16:32:43 +010073#define APM_CPU_PART_POTENZA 0x000
Vinayak Kale4ad637a2013-04-24 10:06:59 +010074
Suzuki K. Poulose04597a62015-01-21 12:43:09 +000075#define ID_AA64MMFR0_BIGENDEL0_SHIFT 16
76#define ID_AA64MMFR0_BIGENDEL0_MASK (0xf << ID_AA64MMFR0_BIGENDEL0_SHIFT)
77#define ID_AA64MMFR0_BIGENDEL0(mmfr0) \
78 (((mmfr0) & ID_AA64MMFR0_BIGENDEL0_MASK) >> ID_AA64MMFR0_BIGENDEL0_SHIFT)
79#define ID_AA64MMFR0_BIGEND_SHIFT 8
80#define ID_AA64MMFR0_BIGEND_MASK (0xf << ID_AA64MMFR0_BIGEND_SHIFT)
81#define ID_AA64MMFR0_BIGEND(mmfr0) \
82 (((mmfr0) & ID_AA64MMFR0_BIGEND_MASK) >> ID_AA64MMFR0_BIGEND_SHIFT)
83
Javi Merino0359b0e2012-08-29 18:32:18 +010084#ifndef __ASSEMBLY__
85
Catalin Marinas9cce7a42012-03-05 11:49:28 +000086/*
87 * The CPU ID never changes at run time, so we might as well tell the
88 * compiler that it's constant. Use this function to read the CPU ID
89 * rather than directly reading processor_id or read_cpuid() directly.
90 */
91static inline u32 __attribute_const__ read_cpuid_id(void)
92{
Ard Biesheuvel148eb0a2013-12-16 21:04:35 +000093 return read_cpuid(MIDR_EL1);
Catalin Marinas9cce7a42012-03-05 11:49:28 +000094}
95
Marc Zyngierd9c19512013-02-27 18:05:59 +000096static inline u64 __attribute_const__ read_cpuid_mpidr(void)
97{
Ard Biesheuvel148eb0a2013-12-16 21:04:35 +000098 return read_cpuid(MPIDR_EL1);
Marc Zyngierd9c19512013-02-27 18:05:59 +000099}
100
101static inline unsigned int __attribute_const__ read_cpuid_implementor(void)
102{
Mark Rutland89c4a302014-07-16 16:32:43 +0100103 return MIDR_IMPLEMENTOR(read_cpuid_id());
Marc Zyngierd9c19512013-02-27 18:05:59 +0000104}
105
106static inline unsigned int __attribute_const__ read_cpuid_part_number(void)
107{
Mark Rutland89c4a302014-07-16 16:32:43 +0100108 return MIDR_PARTNUM(read_cpuid_id());
Marc Zyngierd9c19512013-02-27 18:05:59 +0000109}
110
Catalin Marinas9cce7a42012-03-05 11:49:28 +0000111static inline u32 __attribute_const__ read_cpuid_cachetype(void)
112{
Ard Biesheuvel148eb0a2013-12-16 21:04:35 +0000113 return read_cpuid(CTR_EL0);
Catalin Marinas9cce7a42012-03-05 11:49:28 +0000114}
115
Suzuki K. Poulose04597a62015-01-21 12:43:09 +0000116static inline bool id_aa64mmfr0_mixed_endian_el0(u64 mmfr0)
117{
118 return (ID_AA64MMFR0_BIGEND(mmfr0) == 0x1) ||
119 (ID_AA64MMFR0_BIGENDEL0(mmfr0) == 0x1);
120}
Javi Merino0359b0e2012-08-29 18:32:18 +0100121#endif /* __ASSEMBLY__ */
122
Catalin Marinas9cce7a42012-03-05 11:49:28 +0000123#endif