@@ -9,6 +9,8 @@
#ifndef __ASM_AARCH32_GICV3_H
#define __ASM_AARCH32_GICV3_H
+#define ICC_CTLR_RESET (0UL)
+
static inline uint32_t gic_read_icc_sre(void)
{
uint32_t val;
@@ -26,4 +28,9 @@ static inline void gic_write_icc_ctlr(uint32_t val)
asm volatile ("mcr p15, 6, %0, c12, c12, 4" : : "r" (val));
}
+static inline void gic_init_icc_ctlr()
+{
+ gic_write_icc_ctlr(ICC_CTLR_RESET);
+}
+
#endif
@@ -15,21 +15,53 @@
#define ICC_CTLR_EL3 "S3_6_C12_C12_4"
#define ICC_PMR_EL1 "S3_0_C4_C6_0"
+#define ICC_CTLR_EL3_RESET (0UL)
+#define ICC_CTLR_EL1_RESET (0UL)
+
+static inline uint32_t current_el(void)
+{
+ uint32_t val;
+
+ asm volatile ("mrs %0, CurrentEL" : "=r" (val));
+ return val;
+}
+
static inline uint32_t gic_read_icc_sre(void)
{
uint32_t val;
- asm volatile ("mrs %0, " ICC_SRE_EL3 : "=r" (val));
+
+ if(current_el() == CURRENTEL_EL3)
+ asm volatile ("mrs %0, " ICC_SRE_EL3 : "=r" (val));
+ else
+ asm volatile ("mrs %0, " ICC_SRE_EL2 : "=r" (val));
+
return val;
}
static inline void gic_write_icc_sre(uint32_t val)
{
- asm volatile ("msr " ICC_SRE_EL3 ", %0" : : "r" (val));
+ if(current_el() == CURRENTEL_EL3)
+ asm volatile ("msr " ICC_SRE_EL3 ", %0" : : "r" (val));
+ else
+ asm volatile ("msr " ICC_SRE_EL2 ", %0" : : "r" (val));
}
-static inline void gic_write_icc_ctlr(uint32_t val)
+static inline void gic_write_icc_ctlr_el3(uint32_t val)
{
asm volatile ("msr " ICC_CTLR_EL3 ", %0" : : "r" (val));
}
+static inline void gic_write_icc_ctlr_el1(uint32_t val)
+{
+ asm volatile ("msr " ICC_CTLR_EL1 ", %0" : : "r" (val));
+}
+
+static inline void gic_init_icc_ctlr()
+{
+ if(current_el() == CURRENTEL_EL3)
+ gic_write_icc_ctlr_el3(ICC_CTLR_EL3_RESET);
+ else
+ gic_write_icc_ctlr_el1(ICC_CTLR_EL1_RESET);
+}
+
#endif
@@ -121,6 +121,6 @@ void gic_secure_init(void)
gic_write_icc_sre(sre);
isb();
- gic_write_icc_ctlr(0);
+ gic_init_icc_ctlr();
isb();
}