From ea4d918f700a13bb0f49517618c246084e197937 Mon Sep 17 00:00:00 2001 From: Chris Lew Date: Fri, 24 Jun 2022 15:15:39 -0700 Subject: [PATCH 1/2] soc: qcom: smp2p: Introduce pending state for virtual irq If a smp2p change occurs while a virtual interrupt is disabled, smp2p should be able to resend that interrupt on enablement. This functionality requires the CONFIG_HARDIRQS_SW_RESEND to be enabled to reschedule the interrupts. To ensure the mask and unmask functions are called during enabled and disable, set the flag to disable lazy IRQ state handling (IRQ_DISABLE_UNLAZY). Change-Id: I75c662c61a9705c05278d238ca51f7a2e74806d8 Signed-off-by: Chris Lew --- drivers/soc/qcom/smp2p.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/soc/qcom/smp2p.c b/drivers/soc/qcom/smp2p.c index 4a157240f419..1e0b099a4c41 100644 --- a/drivers/soc/qcom/smp2p.c +++ b/drivers/soc/qcom/smp2p.c @@ -2,6 +2,7 @@ /* * Copyright (c) 2015, Sony Mobile Communications AB. * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. + * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. */ #include @@ -101,6 +102,7 @@ struct smp2p_entry { struct irq_domain *domain; DECLARE_BITMAP(irq_enabled, 32); + DECLARE_BITMAP(irq_pending, 32); DECLARE_BITMAP(irq_rising, 32); DECLARE_BITMAP(irq_falling, 32); @@ -146,6 +148,7 @@ struct qcom_smp2p { unsigned local_pid; unsigned remote_pid; + int irq; struct regmap *ipc_regmap; int ipc_offset; int ipc_bit; @@ -217,8 +220,8 @@ static void qcom_smp2p_notify_in(struct qcom_smp2p *smp2p) { struct smp2p_smem_item *in; struct smp2p_entry *entry; + unsigned long status; int irq_pin; - u32 status; char buf[SMP2P_MAX_ENTRY_NAME]; u32 val; int i; @@ -247,19 +250,22 @@ static void qcom_smp2p_notify_in(struct qcom_smp2p *smp2p) status = val ^ entry->last_value; entry->last_value = val; + status |= *entry->irq_pending; /* No changes of this entry? */ if (!status) continue; - for_each_set_bit(i, entry->irq_enabled, 32) { - if (!(status & BIT(i))) - continue; - + for_each_set_bit(i, &status, 32) { if ((val & BIT(i) && test_bit(i, entry->irq_rising)) || (!(val & BIT(i)) && test_bit(i, entry->irq_falling))) { irq_pin = irq_find_mapping(entry->domain, i); handle_nested_irq(irq_pin); + + if (test_bit(i, entry->irq_enabled)) + clear_bit(i, entry->irq_pending); + else + set_bit(i, entry->irq_pending); } } } @@ -365,6 +371,8 @@ static int smp2p_irq_map(struct irq_domain *d, irq_set_chip_data(irq, entry); irq_set_nested_thread(irq, 1); irq_set_noprobe(irq); + irq_set_parent(irq, entry->smp2p->irq); + irq_set_status_flags(irq, IRQ_DISABLE_UNLAZY); return 0; } @@ -608,6 +616,7 @@ static int qcom_smp2p_probe(struct platform_device *pdev) /* Kick the outgoing edge after allocating entries */ qcom_smp2p_kick(smp2p); + smp2p->irq = irq; ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, qcom_smp2p_intr, IRQF_ONESHOT, From 317e5785898a96dab283a655c31a65e973b4d8f9 Mon Sep 17 00:00:00 2001 From: Chris Lew Date: Fri, 24 Jun 2022 15:18:47 -0700 Subject: [PATCH 2/2] soc: qcom: smp2p: Add proper retrigger detection Currently, smp2p relies on the hwirq resend feature to retrigger irqs that were missed because the irq was disabled at the time of receiving it. The hwirq resend feature will retrigger the parent smp2p interrupt. In order to keep track of what children needed to be retriggered, the pending bitmap was added. After calling handle_nested_irq, smp2p checks if the interrupt is enabled and sets the pending bit if the interrupt is not enabled. There is a small window where a client can enable the interrupt between calling handle_nested_irq and checking if the interrupt is enabled. If this happens, the interrupt is never called when the parent smp2p interrupt is retriggered. Add the irq_retrigger callback so smp2p can know which child interrupts need to be retriggered. Set the pending bits accordingly. Change-Id: I774b6ef91e22edbd55ddfffbbb3ae6062d48a560 Signed-off-by: Chris Lew --- drivers/soc/qcom/smp2p.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/drivers/soc/qcom/smp2p.c b/drivers/soc/qcom/smp2p.c index 1e0b099a4c41..475edd587e16 100644 --- a/drivers/soc/qcom/smp2p.c +++ b/drivers/soc/qcom/smp2p.c @@ -261,11 +261,7 @@ static void qcom_smp2p_notify_in(struct qcom_smp2p *smp2p) (!(val & BIT(i)) && test_bit(i, entry->irq_falling))) { irq_pin = irq_find_mapping(entry->domain, i); handle_nested_irq(irq_pin); - - if (test_bit(i, entry->irq_enabled)) - clear_bit(i, entry->irq_pending); - else - set_bit(i, entry->irq_pending); + clear_bit(i, entry->irq_pending); } } } @@ -354,11 +350,22 @@ static int smp2p_set_irq_type(struct irq_data *irqd, unsigned int type) return 0; } +static int smp2p_retrigger_irq(struct irq_data *irqd) +{ + struct smp2p_entry *entry = irq_data_get_irq_chip_data(irqd); + irq_hw_number_t irq = irqd_to_hwirq(irqd); + + set_bit(irq, entry->irq_pending); + + return 0; +} + static struct irq_chip smp2p_irq_chip = { .name = "smp2p", .irq_mask = smp2p_mask_irq, .irq_unmask = smp2p_unmask_irq, .irq_set_type = smp2p_set_irq_type, + .irq_retrigger = smp2p_retrigger_irq, }; static int smp2p_irq_map(struct irq_domain *d,