Skip to content

Commit 3362528

Browse files
author
Marc Zyngier
committed
irqchip/gic-v3: Probe for SCR_EL3 being clear before resetting AP0Rn
We would like to reset the Group-0 Active Priority Registers at boot time if they are available to us. They would be available if SCR_EL3.FIQ was not set, but we cannot directly probe this bit, and short of checking, we may end-up trapping to EL3, and the firmware may not be please to get such an exception. Yes, this is dumb. Instead, let's use PMR to find out if its value gets affected by SCR_EL3.FIQ being set. We use the fact that when SCR_EL3.FIQ is set, the LSB of the priority is lost due to the shifting back and forth of the actual priority. If we read back a 0, we know that Group0 is unavailable. In case we read a non-zero value, we can safely reset the AP0Rn register. Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
1 parent 6656905 commit 3362528

3 files changed

Lines changed: 41 additions & 16 deletions

File tree

‎arch/arm/include/asm/arch_gicv3.h‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ static inline u64 read_ ## a64(void) \
137137
return val; \
138138
}
139139

140+
CPUIF_MAP(ICC_PMR, ICC_PMR_EL1)
140141
CPUIF_MAP(ICC_AP0R0, ICC_AP0R0_EL1)
141142
CPUIF_MAP(ICC_AP0R1, ICC_AP0R1_EL1)
142143
CPUIF_MAP(ICC_AP0R2, ICC_AP0R2_EL1)
@@ -206,11 +207,6 @@ static inline u32 gic_read_iar(void)
206207
return irqstat;
207208
}
208209

209-
static inline void gic_write_pmr(u32 val)
210-
{
211-
write_sysreg(val, ICC_PMR);
212-
}
213-
214210
static inline void gic_write_ctlr(u32 val)
215211
{
216212
write_sysreg(val, ICC_CTLR);

‎arch/arm64/include/asm/arch_gicv3.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,6 @@ static inline u64 gic_read_iar_cavium_thunderx(void)
7676
return irqstat;
7777
}
7878

79-
static inline void gic_write_pmr(u32 val)
80-
{
81-
write_sysreg_s(val, SYS_ICC_PMR_EL1);
82-
}
83-
8479
static inline void gic_write_ctlr(u32 val)
8580
{
8681
write_sysreg_s(val, SYS_ICC_CTLR_EL1);

‎drivers/irqchip/irq-gic-v3.c‎

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,8 @@ static void gic_cpu_sys_reg_init(void)
532532
int i, cpu = smp_processor_id();
533533
u64 mpidr = cpu_logical_map(cpu);
534534
u64 need_rss = MPIDR_RS(mpidr);
535-
u32 val;
535+
bool group0;
536+
u32 val, pribits;
536537

537538
/*
538539
* Need to check that the SRE bit has actually been set. If
@@ -544,8 +545,28 @@ static void gic_cpu_sys_reg_init(void)
544545
if (!gic_enable_sre())
545546
pr_err("GIC: unable to set SRE (disabled at EL2), panic ahead\n");
546547

548+
pribits = gic_read_ctlr();
549+
pribits &= ICC_CTLR_EL1_PRI_BITS_MASK;
550+
pribits >>= ICC_CTLR_EL1_PRI_BITS_SHIFT;
551+
pribits++;
552+
553+
/*
554+
* Let's find out if Group0 is under control of EL3 or not by
555+
* setting the highest possible, non-zero priority in PMR.
556+
*
557+
* If SCR_EL3.FIQ is set, the priority gets shifted down in
558+
* order for the CPU interface to set bit 7, and keep the
559+
* actual priority in the non-secure range. In the process, it
560+
* looses the least significant bit and the actual priority
561+
* becomes 0x80. Reading it back returns 0, indicating that
562+
* we're don't have access to Group0.
563+
*/
564+
write_gicreg(BIT(8 - pribits), ICC_PMR_EL1);
565+
val = read_gicreg(ICC_PMR_EL1);
566+
group0 = val != 0;
567+
547568
/* Set priority mask register */
548-
gic_write_pmr(DEFAULT_PMR_VALUE);
569+
write_gicreg(DEFAULT_PMR_VALUE, ICC_PMR_EL1);
549570

550571
/*
551572
* Some firmwares hand over to the kernel with the BPR changed from
@@ -563,11 +584,24 @@ static void gic_cpu_sys_reg_init(void)
563584
gic_write_ctlr(ICC_CTLR_EL1_EOImode_drop_dir);
564585
}
565586

566-
val = gic_read_ctlr();
567-
val &= ICC_CTLR_EL1_PRI_BITS_MASK;
568-
val >>= ICC_CTLR_EL1_PRI_BITS_SHIFT;
587+
/* Always whack Group0 before Group1 */
588+
if (group0) {
589+
switch(pribits) {
590+
case 8:
591+
case 7:
592+
write_gicreg(0, ICC_AP0R3_EL1);
593+
write_gicreg(0, ICC_AP0R2_EL1);
594+
case 6:
595+
write_gicreg(0, ICC_AP0R1_EL1);
596+
case 5:
597+
case 4:
598+
write_gicreg(0, ICC_AP0R0_EL1);
599+
}
600+
601+
isb();
602+
}
569603

570-
switch(val + 1) {
604+
switch(pribits) {
571605
case 8:
572606
case 7:
573607
write_gicreg(0, ICC_AP1R3_EL1);

0 commit comments

Comments
 (0)