xref: /optee_os/core/arch/arm/include/arm.h (revision c6c416f1bf4617feef23d592155ba7de69bceea9)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright (c) 2015, Linaro Limited
4  * Copyright (c) 2019, Arm Limited. All rights reserved.
5  */
6 #ifndef ARM_H
7 #define ARM_H
8 
9 #include <stdbool.h>
10 #include <stdint.h>
11 #include <util.h>
12 
13 /* MIDR definitions */
14 #define MIDR_PRIMARY_PART_NUM_SHIFT	U(4)
15 #define MIDR_PRIMARY_PART_NUM_WIDTH	U(12)
16 #define MIDR_PRIMARY_PART_NUM_MASK	(BIT(MIDR_PRIMARY_PART_NUM_WIDTH) - 1)
17 
18 #define MIDR_IMPLEMENTER_SHIFT		U(24)
19 #define MIDR_IMPLEMENTER_WIDTH		U(8)
20 #define MIDR_IMPLEMENTER_MASK		(BIT(MIDR_IMPLEMENTER_WIDTH) - 1)
21 #define MIDR_IMPLEMENTER_ARM		U(0x41)
22 
23 #define CORTEX_A5_PART_NUM		U(0xC05)
24 #define CORTEX_A7_PART_NUM		U(0xC07)
25 #define CORTEX_A8_PART_NUM		U(0xC08)
26 #define CORTEX_A9_PART_NUM		U(0xC09)
27 #define CORTEX_A15_PART_NUM		U(0xC0F)
28 #define CORTEX_A17_PART_NUM		U(0xC0E)
29 #define CORTEX_A57_PART_NUM		U(0xD07)
30 #define CORTEX_A72_PART_NUM		U(0xD08)
31 #define CORTEX_A73_PART_NUM		U(0xD09)
32 #define CORTEX_A75_PART_NUM		U(0xD0A)
33 
34 /* MPIDR definitions */
35 #define MPIDR_AFFINITY_BITS	U(8)
36 #define MPIDR_AFFLVL_MASK	U(0xff)
37 #define MPIDR_AFF0_SHIFT	U(0)
38 #define MPIDR_AFF0_MASK		(MPIDR_AFFLVL_MASK << MPIDR_AFF0_SHIFT)
39 #define MPIDR_AFF1_SHIFT	U(8)
40 #define MPIDR_AFF1_MASK		(MPIDR_AFFLVL_MASK << MPIDR_AFF1_SHIFT)
41 #define MPIDR_AFF2_SHIFT	U(16)
42 #define MPIDR_AFF2_MASK		(MPIDR_AFFLVL_MASK << MPIDR_AFF2_SHIFT)
43 
44 #define MPIDR_MT_SHIFT		U(24)
45 #define MPIDR_MT_MASK		BIT(MPIDR_MT_SHIFT)
46 
47 #define MPIDR_CPU_MASK		MPIDR_AFF0_MASK
48 #define MPIDR_CLUSTER_SHIFT	MPIDR_AFF1_SHIFT
49 #define MPIDR_CLUSTER_MASK	MPIDR_AFF1_MASK
50 
51 #define MPIDR_AARCH32_AFF_MASK	(MPIDR_AFF0_MASK | MPIDR_AFF1_MASK | \
52 				 MPIDR_AFF2_MASK)
53 
54 /* CLIDR definitions */
55 #define CLIDR_LOUIS_SHIFT	U(21)
56 #define CLIDR_LOC_SHIFT		U(24)
57 #define CLIDR_FIELD_WIDTH	U(3)
58 
59 /* CSSELR definitions */
60 #define CSSELR_LEVEL_SHIFT	U(1)
61 
62 /* CTR definitions */
63 #define CTR_CWG_SHIFT		U(24)
64 #define CTR_CWG_MASK		U(0xf)
65 #define CTR_ERG_SHIFT		U(20)
66 #define CTR_ERG_MASK		U(0xf)
67 #define CTR_DMINLINE_SHIFT	U(16)
68 #define CTR_DMINLINE_WIDTH	U(4)
69 #define CTR_DMINLINE_MASK	(BIT(4) - 1)
70 #define CTR_L1IP_SHIFT		U(14)
71 #define CTR_L1IP_MASK		U(0x3)
72 #define CTR_IMINLINE_SHIFT	U(0)
73 #define CTR_IMINLINE_MASK	U(0xf)
74 #define CTR_WORD_SIZE		U(4)
75 
76 #define ARM32_CPSR_MODE_MASK	U(0x1f)
77 #define ARM32_CPSR_MODE_USR	U(0x10)
78 #define ARM32_CPSR_MODE_FIQ	U(0x11)
79 #define ARM32_CPSR_MODE_IRQ	U(0x12)
80 #define ARM32_CPSR_MODE_SVC	U(0x13)
81 #define ARM32_CPSR_MODE_MON	U(0x16)
82 #define ARM32_CPSR_MODE_ABT	U(0x17)
83 #define ARM32_CPSR_MODE_UND	U(0x1b)
84 #define ARM32_CPSR_MODE_SYS	U(0x1f)
85 
86 #define ARM32_CPSR_T		BIT(5)
87 #define ARM32_CPSR_F_SHIFT	U(6)
88 #define ARM32_CPSR_F		BIT(6)
89 #define ARM32_CPSR_I		BIT(7)
90 #define ARM32_CPSR_A		BIT(8)
91 #define ARM32_CPSR_E		BIT(9)
92 #define ARM32_CPSR_FIA		(ARM32_CPSR_F | ARM32_CPSR_I | ARM32_CPSR_A)
93 #define ARM32_CPSR_IT_MASK	(ARM32_CPSR_IT_MASK1 | ARM32_CPSR_IT_MASK2)
94 #define ARM32_CPSR_IT_MASK1	U(0x06000000)
95 #define ARM32_CPSR_IT_MASK2	U(0x0000fc00)
96 
97 /* ARM Generic timer definitions */
98 #define CNTKCTL_PL0PCTEN	BIT(0) /* physical counter el0 access enable */
99 #define CNTKCTL_PL0VCTEN	BIT(1) /* virtual counter el0 access enable */
100 
101 #ifdef ARM32
102 #include <arm32.h>
103 #endif
104 
105 #ifdef ARM64
106 #include <arm64.h>
107 #endif
108 
109 #ifndef __ASSEMBLER__
110 static inline __noprof uint64_t barrier_read_counter_timer(void)
111 {
112 	isb();
113 #ifdef CFG_CORE_SEL2_SPMC
114 	return read_cntvct();
115 #else
116 	return read_cntpct();
117 #endif
118 }
119 
120 static inline bool feat_bti_is_implemented(void)
121 {
122 #ifdef ARM32
123 	return false;
124 #else
125 	return ((read_id_aa64pfr1_el1() & ID_AA64PFR1_EL1_BT_MASK) ==
126 		FEAT_BTI_IMPLEMENTED);
127 #endif
128 }
129 #endif
130 
131 #endif /*ARM_H*/
132