diff --git a/drivers/irqchip/irq-apple-aic.c b/drivers/irqchip/irq-apple-aic.c index 0a9aeced27721..52a892164c3a4 100644 --- a/drivers/irqchip/irq-apple-aic.c +++ b/drivers/irqchip/irq-apple-aic.c @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -210,8 +211,8 @@ * System interrupt configuration. AICv2 and later have no per-IRQ CPU target: * the controller delivers each IRQ to one of the CPUs that accept IRQs, and * this per-CPU field says whether a CPU does. A CPU whose field reads - * SIQ_CFG_ROUTE_NONE never receives an AIC IRQ. Only used on SoCs where this - * has been verified on hardware (aic_info.siq_cfg_routing). + * SIQ_CFG_ROUTE_NONE never receives an AIC IRQ. Read only at EL2, since a + * hypervisor or secure monitor may trap it. */ #define SYS_IMP_APL_SIQ_CFG_EL1 sys_reg(3, 4, 15, 10, 4) #define SIQ_CFG_ROUTE GENMASK(1, 0) @@ -275,15 +276,6 @@ struct aic_info { bool fast_ipi; bool local_fast_ipi; bool vm_timer_fiq_readonly; - /* - * SIQ_CFG routing verified on hardware: at EL2, AICv2+ IRQs report the - * CPUs that accept them as their effective affinity. The set grows as - * CPUs start and IRQs keep the set they were given, which is enough - * while only one CPU accepts IRQs. A SoC listed here with more than one - * accepting CPU would also need those masks refreshed when such a CPU - * comes online. - */ - bool siq_cfg_routing; /* A firmware-driven suspend powers the controller down: aic_syscore_ops keep it. */ bool fw_suspend; /* If set, fw_suspend holds on these boards only */ @@ -357,7 +349,6 @@ static const struct aic_info aic3_t8140_info __initconst = { .irq_cfg = AIC3_IRQ_CFG, .fast_ipi = true, .local_fast_ipi = true, - .siq_cfg_routing = true, .fw_suspend = true, }; @@ -438,7 +429,7 @@ static DEFINE_PER_CPU(uint32_t, aic_fiq_unmasked); static struct aic_irq_chip *aic_irqc; -/* CPUs that accept hardware IRQs, read from SIQ_CFG where siq_cfg_routing is set */ +/* CPUs that accept hardware IRQs, read from SIQ_CFG on AICv2+ at EL2 */ static struct cpumask aic_irq_cpus; static void aic_handle_ipi(struct pt_regs *regs); @@ -644,7 +635,7 @@ static int aic2_routed_irq_set_affinity(struct irq_data *d, return IRQ_SET_MASK_OK; } -/* AIC2 on SoCs whose SIQ_CFG routing is read (aic_info.siq_cfg_routing, at EL2) */ +/* AICv2+ at EL2, where SIQ_CFG is read */ static struct irq_chip aic2_routed_chip = { .name = "AIC2", .irq_mask = aic_irq_mask, @@ -829,8 +820,7 @@ static int aic_irq_domain_map(struct irq_domain *id, unsigned int irq, struct irq_chip *chip = &aic_chip; if (ic->info.version == 2 || ic->info.version == 3) - chip = ic->info.siq_cfg_routing && is_kernel_in_hyp_mode() ? - &aic2_routed_chip : &aic2_chip; + chip = is_kernel_in_hyp_mode() ? &aic2_routed_chip : &aic2_chip; if (type == AIC_EVENT_TYPE_IRQ) { irq_domain_set_info(id, irq, hw, chip, id->host_data, @@ -1104,25 +1094,53 @@ static int aic_init_cpu(unsigned int cpu) } } - /* - * Record whether the controller delivers IRQs to this CPU. SIQ_CFG is - * read only on SoCs where its routing has been verified on hardware, - * and only at EL2, since a hypervisor or secure monitor may trap it. - */ - if (aic_irqc->info.siq_cfg_routing && is_kernel_in_hyp_mode()) { - if (FIELD_GET(SIQ_CFG_ROUTE, read_sysreg_s(SYS_IMP_APL_SIQ_CFG_EL1)) == - SIQ_CFG_ROUTE_NONE) - cpumask_clear_cpu(cpu, &aic_irq_cpus); - else - cpumask_set_cpu(cpu, &aic_irq_cpus); - } - /* Initialize the local mask state */ __this_cpu_write(aic_fiq_unmasked, 0); return 0; } +/* + * Keep aic_irq_cpus to the online CPUs that accept IRQs. genirq takes an IRQ's + * effective affinity only when its affinity is set, so set it again on every + * requested IRQ when the set changes. + */ +static void aic_irq_cpus_update(unsigned int cpu, bool accepts) +{ + static struct cpumask aff; /* CPU hotplug is serialized */ + struct aic_irq_chip *ic = aic_irqc; + unsigned int die, i, virq; + + if (accepts == cpumask_test_cpu(cpu, &aic_irq_cpus)) + return; + assign_cpu(cpu, &aic_irq_cpus, accepts); + + for (die = 0; die < ic->nr_die; die++) { + for (i = 0; i < ic->nr_irq; i++) { + virq = irq_find_mapping(ic->hw_domain, AIC_IRQ_HWIRQ(die, i)); + if (!virq || !irq_has_action(virq)) + continue; + cpumask_copy(&aff, irq_get_affinity_mask(virq)); + irq_set_affinity(virq, &aff); + } + } +} + +/* Runs on @cpu, which reads its own SIQ_CFG */ +static int aic_irq_cpu_online(unsigned int cpu) +{ + aic_irq_cpus_update(cpu, FIELD_GET(SIQ_CFG_ROUTE, + read_sysreg_s(SYS_IMP_APL_SIQ_CFG_EL1)) != + SIQ_CFG_ROUTE_NONE); + return 0; +} + +static int aic_irq_cpu_offline(unsigned int cpu) +{ + aic_irq_cpus_update(cpu, false); + return 0; +} + static struct gic_kvm_info vgic_info __initdata = { .type = GIC_V3, .no_maint_irq_mask = true, @@ -1449,6 +1467,12 @@ static int __init aic_of_ic_init(struct device_node *node, struct device_node *p "irqchip/apple-aic/ipi:starting", aic_init_cpu, NULL); + if ((irqc->info.version == 2 || irqc->info.version == 3) && + is_kernel_in_hyp_mode() && + cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "irqchip/apple-aic:siq-cfg", + aic_irq_cpu_online, aic_irq_cpu_offline) < 0) + pr_warn("Cannot track the CPUs that accept IRQs\n"); + aic_sleep_init(irqc); if (is_kernel_in_hyp_mode()) {