Skip to content

Commit 4fc1c22

Browse files
author
Gilbert
committed
[arch][arm] Enable distributor with ARE, group 1
1 parent b11ead5 commit 4fc1c22

File tree

5 files changed

+52
-5
lines changed

5 files changed

+52
-5
lines changed

arch/arm64/arch.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ static spin_lock_t arm_boot_cpu_lock = 1;
2727
static volatile int secondaries_to_init = 0;
2828
#endif
2929

30+
/* Defined in start.S. */
31+
extern uint64_t arm64_boot_el;
32+
33+
uint64_t arm64_get_boot_el(void) {
34+
return arm64_boot_el >> 2;
35+
}
36+
3037
static void arm64_cpu_early_init(void) {
3138
/* set the vector base */
3239
ARM64_WRITE_SYSREG(VBAR_EL1, (uint64_t)&arm64_exception_base);
@@ -88,6 +95,8 @@ void arch_init(void) {
8895
/* flush the release of the lock, since the secondary cpus are running without cache on */
8996
arch_clean_cache_range((addr_t)&arm_boot_cpu_lock, sizeof(arm_boot_cpu_lock));
9097
#endif
98+
99+
LTRACEF("ARM boot EL%llu\n", arm64_get_boot_el());
91100
}
92101

93102
void arch_quiesce(void) {

arch/arm64/asm.S

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ FUNCTION(arm64_elX_to_el1)
8484
cmp x4, #(0b01 << 2)
8585
bne .notEL1
8686
/* Already in EL1 */
87-
ret
87+
ret
8888

8989
.notEL1:
9090
cmp x4, #(0b10 << 2)

arch/arm64/include/arch/arm64.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ __BEGIN_CDECLS
3434

3535
void arm64_context_switch(vaddr_t *old_sp, vaddr_t new_sp);
3636

37+
uint64_t arm64_get_boot_el(void);
38+
3739
/* exception handling */
3840
struct arm64_iframe_long {
3941
uint64_t r[30];
@@ -82,5 +84,14 @@ void arm64_local_invalidate_cache_all(void);
8284
void arm64_local_clean_invalidate_cache_all(void);
8385
void arm64_local_clean_cache_all(void);
8486

87+
/* Current Exception Level values, as contained in CurrentEL */
88+
#define CurrentEL_EL1 (1 << 2)
89+
#define CurrentEL_EL2 (2 << 2)
90+
91+
static inline bool arm64_is_kernel_in_hyp_mode(void) {
92+
return ARM64_READ_SYSREG(CURRENTEL) == CurrentEL_EL2;
93+
}
94+
95+
8596
__END_CDECLS
8697

dev/interrupt/arm_gic/arm_gic_common.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,26 @@ GEN_CP15_REG64_FUNCS(icc_sgi0r_el1, 2, c12);
230230
#define GICD_MIN_SIZE (GICD_LIMIT - GICD_OFFSET)
231231
#endif /* GIC_VERSION <= 2 */
232232

233+
/* GICD_CTRL Register
234+
* Non-Secure Only_a_Single two_Security
235+
* (1U << 8) RES0 nASSGIreq RES0
236+
* (1U << 7) RES0 E1NWF E1NWF
237+
* (1U << 5) RES0 RES0 ARE_NS
238+
* (1U << 4) ARE_NS ARE ARE_S
239+
* (1U << 2) RES0 RES0 ENABLE_G1S
240+
* (1U << 1) ENABLE_G1A ENABLE_G1 ENABLE_G1NS
241+
* (1U << 0) ENABLE_G1 ENABLE_G0 ENABLE_G0
242+
*/
243+
#define GICD_CTLR_RWP (1U << 31)
244+
#define GICD_CTLR_nASSGIreq (1U << 8)
245+
#define GICD_CTRL_E1NWF (1U << 7)
246+
#define GICD_CTLR_DS (1U << 6)
247+
#define GICD_CTLR_ARE_NS (1U << 5)
248+
#define GICD_CTLR_ARE_S (1U << 4)
249+
#define GICD_CTLR_ENABLE_G1S (1U << 2)
250+
#define GICD_CTLR_ENABLE_G1NS (1U << 1)
251+
#define GICD_CTLR_ENABLE_G0 (1U << 0)
252+
233253
#if GIC_VERSION > 2
234254
/* some registers of GICD are 64 bit */
235255
#define GICDREG_READ64(gic, reg) ({ \

dev/interrupt/arm_gic/gic_v3.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@ static void gicv3_gicr_init(void) {
105105
gicv3_gicr_mark_awake(cpu);
106106
}
107107

108-
109-
/* GICD_CTRL Register write pending bit */
110-
#define GICD_CTLR_RWP (0x1U << 31)
111-
112108
void arm_gicv3_wait_for_write_complete(void) {
113109
/* wait until write complete */
114110
while (GICDREG_READ(0, GICD_CTLR) & GICD_CTLR_RWP) {
@@ -158,6 +154,10 @@ static void gicv3_gicd_setup_default_group(uint32_t grp) {
158154
}
159155
}
160156

157+
static bool gicv3_gicd_security_disabled(void) {
158+
return GICDREG_READ(0, GICD_CTLR) & GICD_CTLR_DS;
159+
}
160+
161161
static void gicv3_gicr_setup_irq_group(uint32_t vector, uint32_t grp) {
162162
uint32_t val;
163163
uint32_t mask;
@@ -193,6 +193,7 @@ static void gicv3_gicr_setup_default_group(uint32_t grp) {
193193

194194
void arm_gicv3_init(void) {
195195
uint32_t grp_mask = (0x1u << GICV3_IRQ_GROUP);
196+
bool disabled_security = gicv3_gicd_security_disabled();
196197

197198
#if !WITH_LIB_SM
198199
/* non-TZ */
@@ -212,6 +213,12 @@ void arm_gicv3_init(void) {
212213
}
213214
#endif
214215

216+
/* Enable distributor with ARE, group 1 enable */
217+
if (disabled_security == false) {
218+
gicv3_gicd_ctrl_write(GICDREG_READ(0, GICD_CTLR) |
219+
(GICD_CTLR_ENABLE_G0 | GICD_CTLR_ENABLE_G1NS | GICD_CTLR_ARE_S));
220+
}
221+
215222
/* Enable selected group */
216223
gicv3_gicd_ctrl_write(GICDREG_READ(0, GICD_CTLR) | grp_mask);
217224
}

0 commit comments

Comments
 (0)