From e5dd49e7ab073720416dcdfcb3291ee16e149bb5 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 2 Dec 2026 15:38:08 +1100 Subject: [PATCH 1/3] media: apple: ave-dma: bind every SoC's apertures and let the domain idle The auxiliary DMA aperture driver matched only apple,t6000-ave-dma, so the T8103 node that linux #3551 enabled stayed unbound. Its PMGR sync_state() then stayed pending and held ps_venc_sys on for good, and J313 deep sleep stopped waking. On T6000 the driver binds but has no runtime PM, so genpd counts the device as active and ps_venc_sys never goes off there either. The encoder firmware needs that domain power-cycled between sessions. Match the generic apple,ave-dma compatible that every node carries, and enable runtime PM without ever resuming the device. The apertures only report faults through the interrupt they share with the encoder DARTs, which can only fire while the domain is on, so the encoder and its DARTs alone decide when ps_venc_sys is powered. The DT nodes stay enabled. Signed-off-by: Ryan Murray --- drivers/media/platform/apple/ave/apple-ave-dma.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/apple/ave/apple-ave-dma.c b/drivers/media/platform/apple/ave/apple-ave-dma.c index 8483045031c39..c152ebe5aac3a 100644 --- a/drivers/media/platform/apple/ave/apple-ave-dma.c +++ b/drivers/media/platform/apple/ave/apple-ave-dma.c @@ -6,6 +6,7 @@ #include #include #include +#include #define AVE_DMA_ERROR_STATUS 0x40 #define AVE_DMA_ERROR_PENDING BIT(31) @@ -51,7 +52,7 @@ static irqreturn_t apple_ave_dma_irq(int irq, void *data) static int apple_ave_dma_probe(struct platform_device *pdev) { struct apple_ave_dma *dma; - int irq; + int irq, ret; dma = devm_kzalloc(&pdev->dev, sizeof(*dma), GFP_KERNEL); if (!dma) @@ -66,12 +67,23 @@ static int apple_ave_dma_probe(struct platform_device *pdev) if (irq < 0) return irq; + /* + * The apertures only report faults; nothing here needs the block + * powered. Stay runtime-suspended so the encoder and its DARTs alone + * decide when ps_venc_sys is on: the firmware needs the domain + * power-cycled between sessions, and deep sleep needs it off. The + * shared interrupt can only fire while one of those powers it. + */ + ret = devm_pm_runtime_enable(&pdev->dev); + if (ret) + return ret; + return devm_request_irq(&pdev->dev, irq, apple_ave_dma_irq, IRQF_SHARED, dev_name(&pdev->dev), dma); } static const struct of_device_id apple_ave_dma_of_match[] = { - { .compatible = "apple,t6000-ave-dma" }, + { .compatible = "apple,ave-dma" }, {} }; MODULE_DEVICE_TABLE(of, apple_ave_dma_of_match); From f1d42e29c1d1825ef59760bc84a71910807d332b Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 2 Dec 2026 16:11:15 +1100 Subject: [PATCH 2/3] media: apple: ave-dma: read the apertures only while their domain is on With the device kept runtime-suspended, ps_venc_sys can be off while the shared interrupt handler is installed. A sharer's or a spurious interrupt, or the extra call CONFIG_DEBUG_SHIRQ makes in free_irq(), would then read a powered-off block. The device's own runtime-PM status cannot tell an idle encoder from a running one, since it stays suspended either way. Track the domain through its genpd on/off notifications instead, registered while runtime PM is still disabled and the domain is known to be on, and wait out a handler already past the check before the domain goes off. Stop reading before free_irq() too. Fault reports still come through while the encoder powers the domain. Signed-off-by: Ryan Murray --- .../media/platform/apple/ave/apple-ave-dma.c | 75 +++++++++++++++++-- 1 file changed, 70 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/apple/ave/apple-ave-dma.c b/drivers/media/platform/apple/ave/apple-ave-dma.c index c152ebe5aac3a..b69cbaba50be6 100644 --- a/drivers/media/platform/apple/ave/apple-ave-dma.c +++ b/drivers/media/platform/apple/ave/apple-ave-dma.c @@ -5,7 +5,9 @@ #include #include #include +#include #include +#include #include #define AVE_DMA_ERROR_STATUS 0x40 @@ -22,13 +24,55 @@ struct apple_ave_dma { struct device *dev; void __iomem *base; + struct notifier_block pd_nb; + int irq; + /* ps_venc_sys is on: the apertures answer */ + bool powered; + /* free_irq() has started; CONFIG_DEBUG_SHIRQ calls the handler there */ + bool stopping; }; +/* + * The device itself stays runtime-suspended even while the encoder runs, so + * the domain's own on/off notifications tell the handler when it may read. + */ +static int apple_ave_dma_pd_notify(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct apple_ave_dma *dma = container_of(nb, struct apple_ave_dma, pd_nb); + + if (action == GENPD_NOTIFY_ON) { + WRITE_ONCE(dma->powered, true); + } else if (action == GENPD_NOTIFY_PRE_OFF) { + WRITE_ONCE(dma->powered, false); + /* A handler past the check on another CPU finishes first */ + synchronize_hardirq(dma->irq); + } + return NOTIFY_OK; +} + +static void apple_ave_dma_remove_notifier(void *data) +{ + dev_pm_genpd_remove_notifier(data); +} + +static void apple_ave_dma_stop(void *data) +{ + struct apple_ave_dma *dma = data; + + WRITE_ONCE(dma->stopping, true); +} + static irqreturn_t apple_ave_dma_irq(int irq, void *data) { struct apple_ave_dma *dma = data; - u32 status = readl(dma->base + AVE_DMA_ERROR_STATUS); + u32 status; + /* A sharer's interrupt, a spurious one or teardown: no MMIO while off */ + if (READ_ONCE(dma->stopping) || !READ_ONCE(dma->powered)) + return IRQ_NONE; + + status = readl(dma->base + AVE_DMA_ERROR_STATUS); if (!(status & AVE_DMA_ERROR_PENDING)) return IRQ_NONE; @@ -66,20 +110,41 @@ static int apple_ave_dma_probe(struct platform_device *pdev) irq = platform_get_irq(pdev, 0); if (irq < 0) return irq; + dma->irq = irq; + + /* + * The domain is on here: genpd powered it for the probe, and with + * runtime PM still disabled it counts this device as active. Watch + * it from now on, before runtime PM can let it go. + */ + dma->powered = true; + dma->pd_nb.notifier_call = apple_ave_dma_pd_notify; + ret = dev_pm_genpd_add_notifier(&pdev->dev, &dma->pd_nb); + if (ret) + return dev_err_probe(&pdev->dev, ret, + "can't watch the power domain\n"); + ret = devm_add_action_or_reset(&pdev->dev, + apple_ave_dma_remove_notifier, &pdev->dev); + if (ret) + return ret; /* * The apertures only report faults; nothing here needs the block * powered. Stay runtime-suspended so the encoder and its DARTs alone * decide when ps_venc_sys is on: the firmware needs the domain - * power-cycled between sessions, and deep sleep needs it off. The - * shared interrupt can only fire while one of those powers it. + * power-cycled between sessions, and deep sleep needs it off. */ ret = devm_pm_runtime_enable(&pdev->dev); if (ret) return ret; - return devm_request_irq(&pdev->dev, irq, apple_ave_dma_irq, - IRQF_SHARED, dev_name(&pdev->dev), dma); + ret = devm_request_irq(&pdev->dev, irq, apple_ave_dma_irq, + IRQF_SHARED, dev_name(&pdev->dev), dma); + if (ret) + return ret; + + /* Released first, so the handler stops reading before free_irq() */ + return devm_add_action_or_reset(&pdev->dev, apple_ave_dma_stop, dma); } static const struct of_device_id apple_ave_dma_of_match[] = { From 6e5f92248d5ae2743d26cb516767c34ed389c2a1 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Wed, 2 Dec 2026 16:19:14 +1100 Subject: [PATCH 3/3] media: apple: ave-dma: lock the register reads against power-off synchronize_hardirq() only waits for hard interrupt handlers. Under threadirqs the shared handler runs in a thread, which can be preempted after its powered check and resume into a read once ps_venc_sys is off. Hold a raw spinlock in the handler from the check through its last register access, and take it in the PRE_OFF/ON notification and the teardown action, so neither can pass a reader in either case. The registers are copied under the lock and the fault is printed after. Signed-off-by: Ryan Murray --- .../media/platform/apple/ave/apple-ave-dma.c | 65 ++++++++++++------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/drivers/media/platform/apple/ave/apple-ave-dma.c b/drivers/media/platform/apple/ave/apple-ave-dma.c index b69cbaba50be6..ac5e67762edc2 100644 --- a/drivers/media/platform/apple/ave/apple-ave-dma.c +++ b/drivers/media/platform/apple/ave/apple-ave-dma.c @@ -9,6 +9,7 @@ #include #include #include +#include #define AVE_DMA_ERROR_STATUS 0x40 #define AVE_DMA_ERROR_PENDING BIT(31) @@ -25,7 +26,13 @@ struct apple_ave_dma { struct device *dev; void __iomem *base; struct notifier_block pd_nb; - int irq; + /* + * Held by the handler from its check through its last register access + * and by the domain's PRE_OFF notification, so no read can outlive the + * domain, threaded handlers (threadirqs) included. Raw: the notification + * comes under the irq-safe PMGR domain's lock. + */ + raw_spinlock_t lock; /* ps_venc_sys is on: the apertures answer */ bool powered; /* free_irq() has started; CONFIG_DEBUG_SHIRQ calls the handler there */ @@ -40,14 +47,15 @@ static int apple_ave_dma_pd_notify(struct notifier_block *nb, unsigned long action, void *data) { struct apple_ave_dma *dma = container_of(nb, struct apple_ave_dma, pd_nb); + unsigned long flags; - if (action == GENPD_NOTIFY_ON) { - WRITE_ONCE(dma->powered, true); - } else if (action == GENPD_NOTIFY_PRE_OFF) { - WRITE_ONCE(dma->powered, false); - /* A handler past the check on another CPU finishes first */ - synchronize_hardirq(dma->irq); - } + if (action != GENPD_NOTIFY_ON && action != GENPD_NOTIFY_PRE_OFF) + return NOTIFY_OK; + + /* A handler already reading finishes before the domain goes off */ + raw_spin_lock_irqsave(&dma->lock, flags); + dma->powered = action == GENPD_NOTIFY_ON; + raw_spin_unlock_irqrestore(&dma->lock, flags); return NOTIFY_OK; } @@ -59,37 +67,50 @@ static void apple_ave_dma_remove_notifier(void *data) static void apple_ave_dma_stop(void *data) { struct apple_ave_dma *dma = data; + unsigned long flags; - WRITE_ONCE(dma->stopping, true); + raw_spin_lock_irqsave(&dma->lock, flags); + dma->stopping = true; + raw_spin_unlock_irqrestore(&dma->lock, flags); } static irqreturn_t apple_ave_dma_irq(int irq, void *data) { struct apple_ave_dma *dma = data; - u32 status; + unsigned long flags; + u32 status, info[7]; + raw_spin_lock_irqsave(&dma->lock, flags); /* A sharer's interrupt, a spurious one or teardown: no MMIO while off */ - if (READ_ONCE(dma->stopping) || !READ_ONCE(dma->powered)) + if (dma->stopping || !dma->powered) { + raw_spin_unlock_irqrestore(&dma->lock, flags); return IRQ_NONE; + } status = readl(dma->base + AVE_DMA_ERROR_STATUS); - if (!(status & AVE_DMA_ERROR_PENDING)) + if (!(status & AVE_DMA_ERROR_PENDING)) { + raw_spin_unlock_irqrestore(&dma->lock, flags); return IRQ_NONE; + } - dev_err_ratelimited(dma->dev, - "DMA fault: status %08x info %08x %08x %08x address %08x info %08x %08x %08x\n", - status, readl(dma->base + AVE_DMA_ERROR_INFO0), - readl(dma->base + AVE_DMA_ERROR_INFO1), - readl(dma->base + AVE_DMA_ERROR_INFO2), - readl(dma->base + AVE_DMA_ERROR_ADDRESS), - readl(dma->base + AVE_DMA_ERROR_INFO3), - readl(dma->base + AVE_DMA_ERROR_INFO4), - readl(dma->base + AVE_DMA_ERROR_INFO5)); + info[0] = readl(dma->base + AVE_DMA_ERROR_INFO0); + info[1] = readl(dma->base + AVE_DMA_ERROR_INFO1); + info[2] = readl(dma->base + AVE_DMA_ERROR_INFO2); + info[3] = readl(dma->base + AVE_DMA_ERROR_ADDRESS); + info[4] = readl(dma->base + AVE_DMA_ERROR_INFO3); + info[5] = readl(dma->base + AVE_DMA_ERROR_INFO4); + info[6] = readl(dma->base + AVE_DMA_ERROR_INFO5); /* The implemented error bits are write-one-to-clear. */ writel(status & AVE_DMA_ERROR_ACK_MASK, dma->base + AVE_DMA_ERROR_STATUS); readl(dma->base + AVE_DMA_ERROR_STATUS); + raw_spin_unlock_irqrestore(&dma->lock, flags); + + dev_err_ratelimited(dma->dev, + "DMA fault: status %08x info %08x %08x %08x address %08x info %08x %08x %08x\n", + status, info[0], info[1], info[2], info[3], info[4], + info[5], info[6]); return IRQ_HANDLED; } @@ -110,13 +131,13 @@ static int apple_ave_dma_probe(struct platform_device *pdev) irq = platform_get_irq(pdev, 0); if (irq < 0) return irq; - dma->irq = irq; /* * The domain is on here: genpd powered it for the probe, and with * runtime PM still disabled it counts this device as active. Watch * it from now on, before runtime PM can let it go. */ + raw_spin_lock_init(&dma->lock); dma->powered = true; dma->pd_nb.notifier_call = apple_ave_dma_pd_notify; ret = dev_pm_genpd_add_notifier(&pdev->dev, &dma->pd_nb);