From 44a2b85696c5d13bdc271f18de955c313475d0c8 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 13 Nov 2026 09:55:49 +0100 Subject: [PATCH 01/12] dt-bindings: iommu: apple,dart: add the T8152 Gen3 display DARTs The DARTs in front of the T8152 display coprocessors (DCP, DCPEXT) and their display pipes (ADT "dart,gen3", version 0x300) use the T8110 register layout, but they belong to the SPTM, and the bootloader hands them over locked. Their TLB command register at 0x80 answers translation queries instead of flushing. A stream is invalidated the way iBoot does it: a payload naming the DART and the stream is written to the SoC's TLB invalidation aperture, which these DARTs share, and a broadcast TLBI follows. Add apple,t8152-dart-gen3 for them, without the apple,t8110-dart fallback, since a T8110 driver would flush through the wrong register, and a "tlbi" register entry for the DART's window in the aperture. Signed-off-by: Thomas Glanzmann (cherry picked from commit 36cd29376a8391909546af1a4b8bbc89c47e9407) --- .../devicetree/bindings/iommu/apple,dart.yaml | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/iommu/apple,dart.yaml b/Documentation/devicetree/bindings/iommu/apple,dart.yaml index 6e7fdf9af5fdd..ceaccfabb54cc 100644 --- a/Documentation/devicetree/bindings/iommu/apple,dart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,dart.yaml @@ -32,6 +32,7 @@ properties: - apple,t8103-usb4-dart - apple,t8110-dart - apple,t6000-dart + - apple,t8152-dart-gen3 - items: - const: apple,t8140-ane-dart - const: apple,t8140-dart @@ -87,13 +88,16 @@ properties: fabric filter (GAPF) that protects the power state of the coprocessor CPU behind this DART, cleared to power that CPU down, or the shared PS write-disable register that holds this DART's - bit for the same purpose (T8142) + bit for the same purpose (T8142), or on a T8152 Gen3 DART its + window in the SoC's TLB invalidation aperture (ADT + dart-tlbi-aperture plus tlbi-aperture-offset), which the Gen3 + DARTs share reg-names: minItems: 1 items: - const: dart - - enum: [dapf, gapf, ps-wr-dis, auxiliary] + - enum: [dapf, gapf, ps-wr-dis, auxiliary, tlbi] interrupts: maxItems: 1 @@ -350,6 +354,35 @@ allOf: then: required: - reg-names + - if: + properties: + compatible: + contains: + const: apple,t8152-dart-gen3 + then: + description: + The T8152 Gen3 DARTs in front of the display coprocessors and their + display pipes belong to the SPTM. The bootloader hands them over + locked, and the operating system only adds page table entries in + root slots that are empty at handoff. Their TLB command register + answers translation queries; a stream is invalidated through the + TLB invalidation aperture instead. + properties: + reg: + minItems: 2 + reg-names: + items: + - const: dart + - const: tlbi + required: + - reg-names + else: + properties: + reg-names: + minItems: 1 + items: + - const: dart + - enum: [dapf, gapf, ps-wr-dis, auxiliary] additionalProperties: false From 1d2eb4a2d905893412750a30cb90dac828a2f2d3 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 13 Nov 2026 09:57:36 +0100 Subject: [PATCH 02/12] iommu: apple-dart: support the locked Gen3 DARTs of T8152 The T8152 display DARTs (ADT "dart,gen3", version 0x300) use the T8110 register layout but belong to the SPTM: their TLB command register at 0x80 answers translation queries instead of flushing. A stream is invalidated the way iBoot does it, by writing a 128-bit payload (valid, route, SID) to the SoC's shared TLBI aperture and broadcasting a TLBI, which the DART snoops. The route is the DART's 0x4604 register. Admit a Gen3 DART only when the bootloader hands it over locked (its streams cannot be set up cold yet), map the aperture from a second "tlbi" reg entry without claiming it, since every Gen3 DART shares it, flush the whole stream where a range flush would go through 0x80, and do not claim the fault interrupt or drain stale exceptions, whose handling acknowledges through that register as well. The range flush test fixture gains the new hw flag. Signed-off-by: Thomas Glanzmann (cherry picked from commit 1ce2050b715beb668cbe652ec02df329b968ce35) --- drivers/iommu/apple-dart.c | 113 +++++++++++++++++++++++++- tools/asahi/apple-dart-range-tests.py | 2 +- 2 files changed, 111 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 4bb6491eedb8c..ba30e51a0ecfa 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -277,6 +277,8 @@ struct apple_dart; struct apple_dart_hw { enum dart_type type; + /* T8110 register layout, SPTM-owned TLB invalidation (T8152) */ + bool gen3; irqreturn_t (*irq_handler)(int irq, void *dev); int (*invalidate_tlb)(struct apple_dart_stream_map *stream_map); void (*enable_remap)(struct apple_dart *dart, int sid, int remap_to); @@ -540,6 +542,10 @@ struct apple_dart { unsigned int sleep_writers; bool sleep_closed; + /* Gen3: shared TLBI aperture and this DART's route in it */ + void __iomem *tlbi; + u8 tlbi_route; + DECLARE_BITMAP(remapped, DART_MAX_STREAMS); u8 remap_target[DART_MAX_STREAMS]; @@ -1985,6 +1991,43 @@ static int apple_dart_fw_invalidate(struct apple_dart_stream_map *stream_map, return 0; } +#define DART_GEN3_TLBI_ROUTE 0x4604 +#define DART_GEN3_TLBI_VALID BIT_ULL(60) +#define DART_GEN3_TLBI_ROUTE_FIELD GENMASK_ULL(59, 56) +#define DART_GEN3_TLBI_SID GENMASK_ULL(55, 48) + +/* + * Gen3 DARTs (T8152) are owned by the SPTM, and their TLB command register at + * 0x80 answers translation queries instead of flushing. A stream is + * invalidated the way iBoot does it: write a 128-bit payload (valid, route, + * SID) to the shared TLBI aperture, then broadcast a TLBI, which the DART + * snoops and applies to that stream. + */ +static int +apple_dart_gen3_hw_invalidate_tlb(struct apple_dart_stream_map *stream_map) +{ + struct apple_dart *dart = stream_map->dart; + unsigned long flags; + int sid; + + spin_lock_irqsave(&dart->lock, flags); + for_each_set_bit(sid, stream_map->sidmap, dart->num_streams) { + u64 lo = DART_GEN3_TLBI_VALID | + FIELD_PREP(DART_GEN3_TLBI_ROUTE_FIELD, dart->tlbi_route) | + FIELD_PREP(DART_GEN3_TLBI_SID, sid); + + dma_wmb(); + asm volatile("stp %0, xzr, [%1]\n" + "dsb ish\n" + ".inst 0xd50881bf\n" /* tlbi vale1os, xzr */ + "dsb osh\n" + : : "r"(lo), "r"(dart->tlbi) : "memory"); + } + spin_unlock_irqrestore(&dart->lock, flags); + + return 0; +} + static int apple_dart_t8020_hw_invalidate_tlb(struct apple_dart_stream_map *stream_map) { @@ -2723,8 +2766,11 @@ static int apple_dart_domain_flush_tlb_range(struct apple_dart_domain *domain, /* The range registers take the DVA the device issues. */ start = first + domain->dma_offset; end = last + domain->dma_offset; - if (range && (stream.dart->fw_mirror || stream.dart->fw_handoff) && - stream.dart->version >= 0x0202) + /* Gen3 has no range command; invalidate the complete stream. */ + if (stream.dart->hw->gen3) + ret = stream.dart->hw->invalidate_tlb(&stream); + else if (range && (stream.dart->fw_mirror || stream.dart->fw_handoff) && + stream.dart->version >= 0x0202) ret = apple_dart_fw_invalidate(&stream, start, end); else if (range && stream.dart->locked && stream.dart->version >= 0x0202) ret = apple_dart_t8110_hw_tlb_command_range(&stream, op, true, @@ -5611,6 +5657,13 @@ static int apple_dart_probe(struct platform_device *pdev) * not admitted: never enable that level IRQ for one block alone. */ dart->irq = -1; + } else if (dart->hw->gen3) { + /* + * The T8110 fault handler acknowledges through the TLB command + * register, which a Gen3 DART uses for translation queries. + * Leave its faults to the firmware for now. + */ + dart->irq = -1; } else if (dart->preserve_display || j713_radio) { dart->irq = platform_get_irq_optional(pdev, 0); if (dart->irq == -ENXIO) @@ -5997,8 +6050,34 @@ static int apple_dart_probe(struct platform_device *pdev) goto err_clk_disable; } + if (dart->hw->gen3) { + struct resource *tlbi; + + /* Only an iBoot-provisioned (locked) Gen3 stream is supported. */ + if (!dart->locked) { + dev_err(dev, "Gen3 DART is not locked; cold setup is not supported\n"); + ret = -ENODEV; + goto err_clk_disable; + } + /* The aperture is shared by every Gen3 DART: map, do not claim. */ + tlbi = platform_get_resource_byname(pdev, IORESOURCE_MEM, "tlbi"); + if (!tlbi || resource_size(tlbi) < 16) { + dev_err(dev, "Gen3 DART needs its TLBI aperture\n"); + ret = -EINVAL; + goto err_clk_disable; + } + dart->tlbi = devm_ioremap(dev, tlbi->start, resource_size(tlbi)); + if (!dart->tlbi) { + ret = -ENOMEM; + goto err_clk_disable; + } + dart->tlbi_route = apple_dart_readl(dart, DART_GEN3_TLBI_ROUTE) & 0xf; + dev_info(dev, "Gen3 DART, version %#x, TLBI route %u\n", + dart->version, dart->tlbi_route); + } + /* Borrowed display state: never acknowledge someone else's fault. */ - if (dart->locked && !dart->preserve_display) + if (dart->locked && !dart->preserve_display && !dart->hw->gen3) apple_dart_drain_stale_exceptions(dart); /* Refuse an already pending inherited fault before joining the shared IRQ. */ @@ -6353,6 +6432,33 @@ static const struct apple_dart_hw apple_dart_hw_t6000 = { .ttbr_count = 4, }; +static const struct apple_dart_hw apple_dart_hw_gen3 = { + .type = DART_T8110, + .gen3 = true, + .irq_handler = apple_dart_t8110_irq, + .invalidate_tlb = apple_dart_gen3_hw_invalidate_tlb, + .fmt = APPLE_DART2, + .max_sid_count = 256, + + .enable_streams = DART_T8110_ENABLE_STREAMS, + .lock = DART_T8110_PROTECT, + .lock_bit = DART_T8110_PROTECT_TTBR_TCR, + + .error = DART_T8110_ERROR, + + .tcr = DART_T8110_TCR, + .tcr_enabled = DART_T8110_TCR_TRANSLATE_ENABLE, + .tcr_disabled = 0, + .tcr_bypass = DART_T8110_TCR_BYPASS_DAPF | DART_T8110_TCR_BYPASS_DART, + .tcr_4level = DART_T8110_TCR_FOUR_LEVEL, + + .ttbr = DART_T8110_TTBR, + .ttbr_valid = DART_T8110_TTBR_VALID, + .ttbr_addr_field_shift = DART_T8110_TTBR_ADDR_FIELD_SHIFT, + .ttbr_shift = DART_T8110_TTBR_SHIFT, + .ttbr_count = 1, +}; + static const struct apple_dart_hw apple_dart_hw_t8110 = { .type = DART_T8110, .irq_handler = apple_dart_t8110_irq, @@ -7131,6 +7237,7 @@ static const struct dev_pm_ops apple_dart_pm_ops = { }; static const struct of_device_id apple_dart_of_match[] = { + { .compatible = "apple,t8152-dart-gen3", .data = &apple_dart_hw_gen3 }, { .compatible = "apple,t8103-dart", .data = &apple_dart_hw_t8103 }, { .compatible = "apple,t8103-usb4-dart", .data = &apple_dart_hw_t8103_usb4 }, { .compatible = "apple,t8110-dart", .data = &apple_dart_hw_t8110 }, diff --git a/tools/asahi/apple-dart-range-tests.py b/tools/asahi/apple-dart-range-tests.py index edebda6eb6a9d..8939de0a74e85 100644 --- a/tools/asahi/apple-dart-range-tests.py +++ b/tools/asahi/apple-dart-range-tests.py @@ -44,7 +44,7 @@ def main(): #define io_pgtable_ops_to_pgtable(x) ((struct io_pgtable *)(x)) struct apple_dart; struct apple_dart_stream_map { struct apple_dart *dart; unsigned long sidmap[1]; }; -struct apple_dart_hw { int (*invalidate_tlb)(struct apple_dart_stream_map *); }; +struct apple_dart_hw { int (*invalidate_tlb)(struct apple_dart_stream_map *); bool gen3; }; struct apple_dart { int num_streams, locked, version; bool fw_mirror, fw_handoff, managed_sids, display_dark, display_tlb_stale; void *dev; struct apple_dart_hw *hw; }; struct apple_dart_atomic_stream_map { struct apple_dart *dart; unsigned long sidmap[1]; }; struct apple_dart_domain { From c668e94095229cd6fc729d927d697c4564e38de1 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 13 Nov 2026 09:58:00 +0100 Subject: [PATCH 03/12] iommu: apple-dart: issue the Gen3 TLBI in the EL1&0 regime on VHE The Gen3 DART snoops the broadcast TLBI that follows the aperture write. iBoot and the aura bootloader issue TLBI VALE1OS at EL2 without VHE, which targets the EL1&0 regime. On a VHE kernel the same instruction targets EL2&0 while HCR_EL2.TGE is set, so clear TGE around it, as KVM does to reach the EL1&0 regime. The J873g display works with this in place; the effect of the change on its own has not been isolated on hardware. Signed-off-by: Thomas Glanzmann (cherry picked from commit d57b118b74e56baf0d8028c94a8435f9e8bb795b) --- drivers/iommu/apple-dart.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index ba30e51a0ecfa..74acfa05044dd 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -57,6 +57,9 @@ #include #include +#include +#include + #include "dma-iommu.h" #if IS_ENABLED(CONFIG_APPLE_DART_KUNIT_TEST) @@ -2008,9 +2011,21 @@ apple_dart_gen3_hw_invalidate_tlb(struct apple_dart_stream_map *stream_map) { struct apple_dart *dart = stream_map->dart; unsigned long flags; + u64 hcr = 0; int sid; spin_lock_irqsave(&dart->lock, flags); + /* + * The DART snoops an EL1&0 TLBI, as iBoot and aura (EL2 without VHE) + * issue it. A VHE kernel's TLBI VALE1OS targets EL2&0 while + * HCR_EL2.TGE is set, so clear TGE around it, as KVM does to reach + * the EL1&0 regime. + */ + if (is_kernel_in_hyp_mode()) { + hcr = read_sysreg(hcr_el2); + write_sysreg(hcr & ~HCR_TGE, hcr_el2); + isb(); + } for_each_set_bit(sid, stream_map->sidmap, dart->num_streams) { u64 lo = DART_GEN3_TLBI_VALID | FIELD_PREP(DART_GEN3_TLBI_ROUTE_FIELD, dart->tlbi_route) | @@ -2023,6 +2038,10 @@ apple_dart_gen3_hw_invalidate_tlb(struct apple_dart_stream_map *stream_map) "dsb osh\n" : : "r"(lo), "r"(dart->tlbi) : "memory"); } + if (is_kernel_in_hyp_mode()) { + write_sysreg(hcr, hcr_el2); + isb(); + } spin_unlock_irqrestore(&dart->lock, flags); return 0; From bc17bdbd04385411e833c14df15977ccebdcfab5 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 21:32:39 +0100 Subject: [PATCH 04/12] iommu: apple-dart: report T8152 Gen3 DART faults A T8152 Gen3 DART reports a fault as a v2 DART does: a bitmap of the streams with a pending exception at 0x4000, a record per stream at 0x8000 (status, address), acknowledged by writing the bitmap back. Request its interrupt and let apple_dart_t8110_v2_irq() report and acknowledge its faults instead of leaving them to the firmware. Only the unlock after a lock-on-error exception differs: a Gen3 DART's TLB command register serves translation queries, so it is not used to unlock. A Gen3 DART with lock-on-error set says that its stream stays stopped. The J873g's Gen3 DARTs have it clear. Tested on the J873g by clearing the AVD DART's SID 0 TTBR during an H.264 decode: one interrupt, "translation fault: SID:0 write TTBR invalid at 0x10fff000000 (status 0x00000100)", the bitmap acknowledged with no repeat, and the decoder retired by its recovery path. After the TTBR was restored and the decoder reloaded, the same file decoded bit-exact again. None of the other eight Gen3 DART fault lines fired, including those of the locked display DARTs with three displays running. Signed-off-by: Thomas Glanzmann --- drivers/iommu/apple-dart.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 74acfa05044dd..d749eae6a41dd 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -2217,6 +2217,15 @@ static int apple_dart_t8110_v2_unlock(struct apple_dart *dart) return -EPERM; if (!(readl(dart->regs + DART_T8110_DIAG_LOCK) & DART_T8110_DIAG_LOCK_ON_ERR)) return 0; + /* + * A Gen3 DART's TLB command register serves translation queries and + * cannot unlock it. Its streams stay stopped until the DART is reset. + */ + if (dart->hw->gen3) { + dev_err_ratelimited(dart->dev, + "locked on error; a Gen3 DART is not unlocked\n"); + return -EOPNOTSUPP; + } /* Unlock after acknowledging a lock-on-error exception. */ __set_bit(0, stream_map.sidmap); @@ -5678,11 +5687,16 @@ static int apple_dart_probe(struct platform_device *pdev) dart->irq = -1; } else if (dart->hw->gen3) { /* - * The T8110 fault handler acknowledges through the TLB command - * register, which a Gen3 DART uses for translation queries. - * Leave its faults to the firmware for now. + * Gen3 reports a fault like a v2 DART: the per-SID exception + * bitmap and records, acknowledged by writing the bitmap back + * (apple_dart_t8110_v2_irq()). Only the unlock after a + * lock-on-error exception differs: see apple_dart_t8110_v2_unlock(). */ - dart->irq = -1; + dart->irq = platform_get_irq_optional(pdev, 0); + if (dart->irq == -ENXIO) + dart->irq = -1; + else if (dart->irq < 0) + return dart->irq; } else if (dart->preserve_display || j713_radio) { dart->irq = platform_get_irq_optional(pdev, 0); if (dart->irq == -ENXIO) From dcce1871cbdb02c95e3c0242da284c795430bc93 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 20:54:59 +0100 Subject: [PATCH 05/12] dt-bindings: power: add the Apple T8152 PSD service On T8152 the video decoder, the USB4 routers and their PHYs and the USB controllers are powered through PMGR2 PSD services instead of PMGR power-state registers. Each service has a 0x100-byte block with a target state, an acknowledge bit and the current state. Describe one service per node as a power domain, with an optional apple,always-on for a service whose consumers cannot restore what another agent set up in its blocks yet. Signed-off-by: Thomas Glanzmann --- .../bindings/power/apple,t8152-psd.yaml | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/apple,t8152-psd.yaml diff --git a/Documentation/devicetree/bindings/power/apple,t8152-psd.yaml b/Documentation/devicetree/bindings/power/apple,t8152-psd.yaml new file mode 100644 index 0000000000000..fa61de7d3d7e7 --- /dev/null +++ b/Documentation/devicetree/bindings/power/apple,t8152-psd.yaml @@ -0,0 +1,63 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/power/apple,t8152-psd.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple T8152 PMGR2 PSD service + +maintainers: + - Thomas Glanzmann + +description: + On T8152 several blocks (the video decoder, the USB4 routers and their + PHYs, the USB controllers) are powered through PMGR2 PSD services rather + than through PMGR power-state registers. Each service has its own 0x100 + byte register block at the PSD base plus 0x100 times the service number, + with a target-state request, an acknowledge bit and the current state + (0 powered, 6 cold). Reading the state consumes the acknowledge. One node + describes one service as a power domain. + +allOf: + - $ref: power-domain.yaml# + +properties: + compatible: + const: apple,t8152-psd + + reg: + maxItems: 1 + + '#power-domain-cells': + const: 0 + + label: + description: The service's name, for the power domain. + + apple,always-on: + type: boolean + description: + Keep the service powered. For a service whose consumers cannot yet + restore the state another agent set up in its blocks, such as a PHY + configured by the bootloader. + +required: + - compatible + - reg + - '#power-domain-cells' + +unevaluatedProperties: false + +examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + power-controller@303a13200 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a13200 0x0 0x100>; + #power-domain-cells = <0>; + label = "avd"; + }; + }; From 85d94ffc4da940181db97ef151c01d8e57f63ee6 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 20:54:59 +0100 Subject: [PATCH 06/12] pmdomain: apple: add the T8152 PSD power domains Provide each T8152 PMGR2 PSD service as a power domain. Power-on requests state 0 and power-off the cold state 6. The driver waits for the acknowledge before it reads the state, because reading the state consumes the acknowledge. A service marked apple,always-on is powered at probe and kept on. Otherwise the domain starts in the state the hardware reports, so genpd powers off a service that nothing uses. The consumers include IRQ-safe devices, the DARTs, so the domains are IRQ-safe and a transition is polled atomically, as the PMGR power states are. On the J873g the AVD service (50) reaches state 0 in 390-500 us and the cold state in about 240 us; the timeout is 10 ms. The AVD and the USB4 routers' CIO services, which so far each had their own variant of this, and the USB controllers (services 175 and 176) use it. Signed-off-by: Thomas Glanzmann --- drivers/pmdomain/apple/Makefile | 1 + drivers/pmdomain/apple/pmgr-psd.c | 151 ++++++++++++++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 drivers/pmdomain/apple/pmgr-psd.c diff --git a/drivers/pmdomain/apple/Makefile b/drivers/pmdomain/apple/Makefile index ef35dddc526f1..c7ac608079081 100644 --- a/drivers/pmdomain/apple/Makefile +++ b/drivers/pmdomain/apple/Makefile @@ -8,3 +8,4 @@ obj-$(CONFIG_APPLE_PMP_DRAM_KUNIT_TEST) += pmp-dram-test.o obj-$(CONFIG_APPLE_PMC) += pmc.o obj-$(CONFIG_APPLE_PMP_ANE_KUNIT_TEST) += pmp-ane-test.o obj-$(CONFIG_APPLE_PMP_J613_FLOOR_KUNIT_TEST) += pmp-j613-floor-gov-test.o +obj-$(CONFIG_APPLE_PMGR_PWRSTATE) += pmgr-psd.o diff --git a/drivers/pmdomain/apple/pmgr-psd.c b/drivers/pmdomain/apple/pmgr-psd.c new file mode 100644 index 0000000000000..04bbf0d35e948 --- /dev/null +++ b/drivers/pmdomain/apple/pmgr-psd.c @@ -0,0 +1,151 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * Apple T8152 PMGR2 PSD services as power domains. + * + * Each service has a 0x100 byte register block: the target state at +0x90, + * the acknowledge in bit 0 of +0xbc, and the current state in bits 2:0 of + * +0x80 (0 powered, 6 cold). Reading the state consumes the acknowledge, so + * the state is read only once the acknowledge is set. + * + * The consumers include IRQ-safe devices (DARTs), so the domains are IRQ-safe + * and a transition is polled atomically, as for the PMGR power states. + */ +#include +#include +#include +#include +#include +#include +#include + +#define APPLE_PSD_STATE 0x80 +#define APPLE_PSD_STATE_CUR GENMASK(2, 0) +#define APPLE_PSD_TARGET 0x90 +#define APPLE_PSD_ACK 0xbc +#define APPLE_PSD_ACK_DONE BIT(0) + +#define APPLE_PSD_ON 0 +#define APPLE_PSD_COLD 6 + +#define APPLE_PSD_TIMEOUT_US 10000 + +struct apple_psd { + struct generic_pm_domain genpd; + struct device *dev; + void __iomem *regs; +}; + +static u32 apple_psd_state(struct apple_psd *psd) +{ + return readl(psd->regs + APPLE_PSD_STATE) & APPLE_PSD_STATE_CUR; +} + +static bool apple_psd_reached(struct apple_psd *psd, u32 target, u32 *ack, + u32 *state) +{ + *ack = readl(psd->regs + APPLE_PSD_ACK); + if (!(*ack & APPLE_PSD_ACK_DONE)) + return false; + *state = apple_psd_state(psd); + return *state == target; +} + +static int apple_psd_set_state(struct generic_pm_domain *genpd, u32 target) +{ + struct apple_psd *psd = container_of(genpd, struct apple_psd, genpd); + u32 ack = 0, state; + bool done; + int ret; + + state = apple_psd_state(psd); + if (state == target) + return 0; + writel(target, psd->regs + APPLE_PSD_TARGET); + ret = read_poll_timeout_atomic(apple_psd_reached, done, done, 1, + APPLE_PSD_TIMEOUT_US, false, psd, target, + &ack, &state); + if (ret) { + dev_err(psd->dev, "%s: state %u not reached: ack %#x, state %u\n", + genpd->name, target, ack, state); + return ret; + } + return 0; +} + +static int apple_psd_power_on(struct generic_pm_domain *genpd) +{ + return apple_psd_set_state(genpd, APPLE_PSD_ON); +} + +static int apple_psd_power_off(struct generic_pm_domain *genpd) +{ + return apple_psd_set_state(genpd, APPLE_PSD_COLD); +} + +static void apple_psd_remove_provider(void *data) +{ + struct apple_psd *psd = data; + + of_genpd_del_provider(psd->dev->of_node); + pm_genpd_remove(&psd->genpd); +} + +static int apple_psd_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + struct apple_psd *psd; + bool is_off; + int ret; + + psd = devm_kzalloc(dev, sizeof(*psd), GFP_KERNEL); + if (!psd) + return -ENOMEM; + psd->dev = dev; + psd->regs = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(psd->regs)) + return PTR_ERR(psd->regs); + + if (of_property_read_string(np, "label", &psd->genpd.name)) + psd->genpd.name = dev_name(dev); + psd->genpd.power_on = apple_psd_power_on; + psd->genpd.power_off = apple_psd_power_off; + psd->genpd.flags = GENPD_FLAG_IRQ_SAFE; + + if (of_property_read_bool(np, "apple,always-on")) { + psd->genpd.flags |= GENPD_FLAG_ALWAYS_ON; + ret = apple_psd_power_on(&psd->genpd); + if (ret) + return ret; + } + is_off = apple_psd_state(psd) != APPLE_PSD_ON; + + ret = pm_genpd_init(&psd->genpd, NULL, is_off); + if (ret) + return ret; + ret = of_genpd_add_provider_simple(np, &psd->genpd); + if (ret) { + pm_genpd_remove(&psd->genpd); + return ret; + } + return devm_add_action_or_reset(dev, apple_psd_remove_provider, psd); +} + +static const struct of_device_id apple_psd_match[] = { + { .compatible = "apple,t8152-psd" }, + {} +}; +MODULE_DEVICE_TABLE(of, apple_psd_match); + +static struct platform_driver apple_psd_driver = { + .probe = apple_psd_probe, + .driver = { + .name = "apple-pmgr-psd", + .of_match_table = apple_psd_match, + .suppress_bind_attrs = true, + }, +}; +module_platform_driver(apple_psd_driver); + +MODULE_LICENSE("Dual MIT/GPL"); +MODULE_DESCRIPTION("Apple T8152 PMGR2 PSD power domains"); From ba2ef79b215d74be99df01cdb24f7c07ad39b7f0 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 12:16:30 +0100 Subject: [PATCH 07/12] dt-bindings: iommu: apple,dart: describe the T8152 AVD instance The AVD Gen3 DART uses the shared TLBI aperture like the display DARTs, but Linux initializes it from an unlocked state with inactive streams. Require its PSD power domain, DMA aperture and initialization tunables. Signed-off-by: Thomas Glanzmann --- .../devicetree/bindings/iommu/apple,dart.yaml | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/iommu/apple,dart.yaml b/Documentation/devicetree/bindings/iommu/apple,dart.yaml index ceaccfabb54cc..b7aca038c24a1 100644 --- a/Documentation/devicetree/bindings/iommu/apple,dart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,dart.yaml @@ -33,6 +33,7 @@ properties: - apple,t8110-dart - apple,t6000-dart - apple,t8152-dart-gen3 + - apple,t8152-avd-dart - items: - const: apple,t8140-ane-dart - const: apple,t8140-dart @@ -358,7 +359,9 @@ allOf: properties: compatible: contains: - const: apple,t8152-dart-gen3 + enum: + - apple,t8152-dart-gen3 + - apple,t8152-avd-dart then: description: The T8152 Gen3 DARTs in front of the display coprocessors and their @@ -366,7 +369,9 @@ allOf: locked, and the operating system only adds page table entries in root slots that are empty at handoff. Their TLB command register answers translation queries; a stream is invalidated through the - TLB invalidation aperture instead. + TLB invalidation aperture instead. The T8152 AVD instance uses the + same invalidation aperture, but starts unlocked with inactive streams + and is initialized by the operating system after its PSD domain is on. properties: reg: minItems: 2 @@ -384,6 +389,17 @@ allOf: - const: dart - enum: [dapf, gapf, ps-wr-dis, auxiliary] + - if: + properties: + compatible: + contains: + const: apple,t8152-avd-dart + then: + required: + - power-domains + - apple,dma-range + - apple,tunable + additionalProperties: false examples: From 7364ab9bca1b37c0428de3d3aaa32590235905b3 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 12:16:30 +0100 Subject: [PATCH 08/12] iommu: apple-dart: initialize the inactive T8152 AVD Gen3 DART Admit cold Gen3 setup only for the instance its apple,t8152-avd-dart compatible selects, with version 0x300, 16 streams, its PSD domain, ADT tunables and inactive streams 0..2. Clear those streams, apply their tunables and use the Gen3 TLBI aperture before enabling translation. Map the TLBI aperture before reset and select a two-level 16K page table inside a single 64 GiB high DMA window. Keep the existing locked display DART admission and all other unlocked Gen3 instances unchanged. On J873g this maps all three decoder streams for bit-exact H.264, HEVC, HEVC Main10, VP9 and AV1 decoding. Gen3 fault IRQ handling and suspend recovery remain outside this initial bring-up. Signed-off-by: Thomas Glanzmann --- drivers/iommu/apple-dart.c | 83 ++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 26 deletions(-) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index d749eae6a41dd..aef3c4e96e082 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -361,6 +361,7 @@ struct apple_dart_fw_tree { #define APPLE_DART_GAPF_PROTECT BIT(4) struct apple_dart { + bool cold_gen3; struct device *dev; const struct apple_dart_hw *hw; @@ -2648,6 +2649,17 @@ static int apple_dart_hw_reset(struct apple_dart *dart) struct apple_dart_stream_map stream_map; int i; + if (dart->cold_gen3) { + stream_map.dart = dart; + bitmap_zero(stream_map.sidmap, DART_MAX_STREAMS); + bitmap_set(stream_map.sidmap, 0, 3); + apple_dart_hw_disable_dma(&stream_map); + apple_dart_hw_clear_all_ttbrs(&stream_map); + apple_dart_apply_own_tunables(dart); + apple_dart_writel(dart, 7, dart->hw->enable_streams); + return dart->hw->invalidate_tlb(&stream_map); + } + if (dart->isp_host) return apple_dart_isp_host_reset(dart); if (dart->managed_sids || dart->cold_ane) @@ -3380,6 +3392,17 @@ static int __apple_dart_finalize_domain(struct apple_dart_domain *dart_domain, .iommu_dev = dart->dev, }; + if (dart->cold_gen3) { + if ((dma_min ^ dma_max) & ~DMA_BIT_MASK(36)) { + ret = -ERANGE; + goto done; + } + /* Gen3 selects the high DMA window separately from its two-level + * 16K page-table indices, as with iBoot's display streams. + */ + pgtbl_cfg.ias = 36; + } + if (dart->locked) { unsigned long *sidmap; int sid; @@ -5527,6 +5550,7 @@ static int apple_dart_probe(struct platform_device *pdev) dart->dev = dev; dart->hw = of_device_get_match_data(dev); dart->tunneled = tunneled; + dart->cold_gen3 = of_device_is_compatible(dev->of_node, "apple,t8152-avd-dart"); dart->cold_ane = of_device_is_compatible(dev->of_node, "apple,t8140-ane-dart") || of_device_is_compatible(dev->of_node, "apple,t8142-ane-dart"); if (dart->cold_ane && !IS_BUILTIN(CONFIG_APPLE_DART)) @@ -5943,6 +5967,38 @@ static int apple_dart_probe(struct platform_device *pdev) ret = -EBUSY; goto err_clk_disable; } + if (dart->hw->gen3) { + struct resource *tlbi; + + /* Cold initialization is qualified only for the AVD instance. */ + if (!dart->locked && !dart->cold_gen3) { + dev_err(dev, "Gen3 DART is not locked; cold setup is not supported\n"); + ret = -ENODEV; + goto err_clk_disable; + } + if (dart->cold_gen3 && (dart->locked || dart->version != 0x300 || + dart->num_streams != 16 || !dev->pm_domain || !dart->tunables || + (apple_dart_readl(dart, dart->hw->enable_streams) & 7))) { + ret = -EINVAL; + goto err_clk_disable; + } + /* The aperture is shared by every Gen3 DART: map, do not claim. */ + tlbi = platform_get_resource_byname(pdev, IORESOURCE_MEM, "tlbi"); + if (!tlbi || resource_size(tlbi) < 16) { + dev_err(dev, "Gen3 DART needs its TLBI aperture\n"); + ret = -EINVAL; + goto err_clk_disable; + } + dart->tlbi = devm_ioremap(dev, tlbi->start, resource_size(tlbi)); + if (!dart->tlbi) { + ret = -ENOMEM; + goto err_clk_disable; + } + dart->tlbi_route = apple_dart_readl(dart, DART_GEN3_TLBI_ROUTE) & 0xf; + dev_info(dev, "Gen3 DART, version %#x, TLBI route %u\n", + dart->version, dart->tlbi_route); + } + apple_dart_parse_sleep_list(dart, res, "apple,sleep-prepare", &dart->sleep_prepare); apple_dart_parse_sleep_list(dart, res, "apple,sleep-restore", &dart->sleep_restore); apple_dart_parse_sleep_list(dart, res, "apple,sleep-restore-late", @@ -6083,32 +6139,6 @@ static int apple_dart_probe(struct platform_device *pdev) goto err_clk_disable; } - if (dart->hw->gen3) { - struct resource *tlbi; - - /* Only an iBoot-provisioned (locked) Gen3 stream is supported. */ - if (!dart->locked) { - dev_err(dev, "Gen3 DART is not locked; cold setup is not supported\n"); - ret = -ENODEV; - goto err_clk_disable; - } - /* The aperture is shared by every Gen3 DART: map, do not claim. */ - tlbi = platform_get_resource_byname(pdev, IORESOURCE_MEM, "tlbi"); - if (!tlbi || resource_size(tlbi) < 16) { - dev_err(dev, "Gen3 DART needs its TLBI aperture\n"); - ret = -EINVAL; - goto err_clk_disable; - } - dart->tlbi = devm_ioremap(dev, tlbi->start, resource_size(tlbi)); - if (!dart->tlbi) { - ret = -ENOMEM; - goto err_clk_disable; - } - dart->tlbi_route = apple_dart_readl(dart, DART_GEN3_TLBI_ROUTE) & 0xf; - dev_info(dev, "Gen3 DART, version %#x, TLBI route %u\n", - dart->version, dart->tlbi_route); - } - /* Borrowed display state: never acknowledge someone else's fault. */ if (dart->locked && !dart->preserve_display && !dart->hw->gen3) apple_dart_drain_stale_exceptions(dart); @@ -7271,6 +7301,7 @@ static const struct dev_pm_ops apple_dart_pm_ops = { static const struct of_device_id apple_dart_of_match[] = { { .compatible = "apple,t8152-dart-gen3", .data = &apple_dart_hw_gen3 }, + { .compatible = "apple,t8152-avd-dart", .data = &apple_dart_hw_gen3 }, { .compatible = "apple,t8103-dart", .data = &apple_dart_hw_t8103 }, { .compatible = "apple,t8103-usb4-dart", .data = &apple_dart_hw_t8103_usb4 }, { .compatible = "apple,t8110-dart", .data = &apple_dart_hw_t8110 }, From b0af8c32bd20ba6197388189f26c50dd43ed8c14 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 12:16:30 +0100 Subject: [PATCH 09/12] media: dt-bindings: describe the T8152 Kopsia decoder Describe the Kopsia MCU, decoder, wrapper and PIODMA register apertures, its three DART streams and its shared PSD power domain. The initial transport submits from the host with the MCU halted and polls completion; it does not use the PostOffice mailbox or the legacy decoder reset line. Signed-off-by: Thomas Glanzmann --- .../bindings/media/apple,t8152-avd.yaml | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/apple,t8152-avd.yaml diff --git a/Documentation/devicetree/bindings/media/apple,t8152-avd.yaml b/Documentation/devicetree/bindings/media/apple,t8152-avd.yaml new file mode 100644 index 0000000000000..585a0a897fed7 --- /dev/null +++ b/Documentation/devicetree/bindings/media/apple,t8152-avd.yaml @@ -0,0 +1,73 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/apple,t8152-avd.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple T8152 Kopsia video decoder + +maintainers: + - Thomas Glanzmann + +description: + Kopsia is the T8152 stateless video decoder. Its decoder, PIODMA and + auxiliary data streams share a Gen3 DART and a PSD power domain. The host + submits codec programs with the MCU halted and polls decoder status; + the PostOffice mailbox transport is not used by this implementation. + +properties: + compatible: + const: apple,t8152-avd + + reg: + items: + - description: MCU code memory + - description: MCU control registers + - description: Decoder control registers + - description: Decoder wrapper registers + - description: PIODMA registers + + reg-names: + items: + - const: code + - const: mbox + - const: ctrl + - const: wrap + - const: dma + + iommus: + items: + - description: Decoder stream + - description: PIODMA stream + - description: Auxiliary data stream + + power-domains: + maxItems: 1 + +required: + - compatible + - reg + - reg-names + - iommus + - power-domains + +additionalProperties: false + +examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + video-codec@485400000 { + compatible = "apple,t8152-avd"; + reg = <0x4 0x85400000 0x0 0x12000>, + <0x4 0x85500000 0x0 0x4000>, + <0x4 0x85100000 0x0 0x10000>, + <0x4 0x850c0000 0x0 0x4000>, + <0x4 0x85070000 0x0 0x4000>; + reg-names = "code", "mbox", "ctrl", "wrap", "dma"; + iommus = <&avd_dart 0>, <&avd_dart 1>, <&avd_dart 2>; + power-domains = <&ps_avd>; + }; + }; From e27c046fa9311811d400c6c7b15c34295b8b57e2 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 12:16:30 +0100 Subject: [PATCH 10/12] media: apple: avd: add a polled host backend for T8152 Kopsia T8152 Kopsia retains the T8142 codec program format but uses different initialization and completion registers. Add a host backend that halts the MCU, initializes the wrapper and PIODMA, and reuses the existing codec submission and completion logic with one frame in flight. Poll VP/PP status only while a frame is active. Enable H.264, HEVC, VP9 and AV1 on this variant without an external firmware image. Retain the 128-byte H.264 MV and HEVC v5 header quirks. Disable recovery reset: the existing watchdog parks DMA and retires the decoder instead of issuing an unqualified reset. The 346 register tunables are unchanged from the MIT-licensed avd-fw v5/tier2 table. The J873g ADT's avd node carries no tunables of its own (unlike its DART's), so there is nothing T8152-specific to describe in the device tree. The table was checked on the J873g by its output: with it, H.264, HEVC, HEVC Main10, VP9 and AV1 decode bit-exact against software (60 frames each), 4K60 H.264 runs at about 150 fps, and the results stay exact across hundreds of power-domain cycles, each of which applies the table again. On J873g, forced DRM PRIME decode and download compares exactly with software for 60 frames of each codec, including HEVC Main10; mpv also renders through DRM PRIME and seeks in both directions. The decoder is runtime power-gated through its PSD domain: the backend is set up again on every resume. A DART fault (injected on the J873g) retires the decoder through the existing recovery path until the module is reloaded. PostOffice completion and suspend/resume remain outstanding. Link: https://github.com/aurora-silicon/avd-fw/blob/ea3a65cc9c0c41907e6ad2714b813e4be6858485/src/hw/tunables/tunables_v5t2.h Signed-off-by: Thomas Glanzmann --- drivers/media/platform/apple/avd/Kconfig | 4 +- drivers/media/platform/apple/avd/Makefile | 2 +- .../platform/apple/avd/avd-backend-kopsia.c | 176 +++++++++ .../platform/apple/avd/avd-backend-open.c | 24 +- drivers/media/platform/apple/avd/avd-drv.c | 53 ++- .../platform/apple/avd/avd-kopsia-tunables.h | 350 ++++++++++++++++++ drivers/media/platform/apple/avd/avd.h | 5 + 7 files changed, 595 insertions(+), 19 deletions(-) create mode 100644 drivers/media/platform/apple/avd/avd-backend-kopsia.c create mode 100644 drivers/media/platform/apple/avd/avd-kopsia-tunables.h diff --git a/drivers/media/platform/apple/avd/Kconfig b/drivers/media/platform/apple/avd/Kconfig index d3bb9763b6230..4aa061da424e6 100644 --- a/drivers/media/platform/apple/avd/Kconfig +++ b/drivers/media/platform/apple/avd/Kconfig @@ -14,7 +14,9 @@ config VIDEO_APPLE_AVD help Support the Apple Silicon stateless video decoder. - Build the decoder firmware from https://github.com/aurora-silicon/avd-fw + T8152 uses host submission and does not need a firmware image. + + For earlier SoCs, build the decoder firmware from https://github.com/aurora-silicon/avd-fw and install it under /lib/firmware/apple/. J700/T8140 uses the avd-fw-v5-t0.bin image. Firmware is supplied separately from this driver. diff --git a/drivers/media/platform/apple/avd/Makefile b/drivers/media/platform/apple/avd/Makefile index 60560dbab592a..66b8e3c61356a 100644 --- a/drivers/media/platform/apple/avd/Makefile +++ b/drivers/media/platform/apple/avd/Makefile @@ -2,7 +2,7 @@ apple-avd-y := avd-drv.o avd-v4l2.o avd-hw.o avd-pm.o avd-h264.o avd-vp9.o \ avd-hevc.o avd-av1.o avd-av1-entropymode.o avd-queue.o avd-backend-open.o \ - avd-backend-apple.o avd-backend-queue.o + avd-backend-apple.o avd-backend-queue.o avd-backend-kopsia.o apple-avd-$(CONFIG_VIDEO_APPLE_AVD_KUNIT_TEST) += avd-h264-test.o avd-queue-test.o \ avd-pm-test.o obj-$(CONFIG_VIDEO_APPLE_AVD) += apple-avd.o diff --git a/drivers/media/platform/apple/avd/avd-backend-kopsia.c b/drivers/media/platform/apple/avd/avd-backend-kopsia.c new file mode 100644 index 0000000000000..f242e90d4be8a --- /dev/null +++ b/drivers/media/platform/apple/avd/avd-backend-kopsia.c @@ -0,0 +1,176 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * T8152 Kopsia bring-up: host submission and polled VP/PP completion. + * + * Completion is polled because no decoder interrupt is described: the ADT's + * avd node lists only its PostOffice mailbox pair (AIC 308 and 268, mailbox + * 9's send-empty and recv-not-empty), and with the MCU halted nothing is known + * to raise them. The poll runs only while a frame is active. + */ +#include +#include +#include "avd.h" + +#define KOPSIA_STATUS(n) (0x194 + 4 * (n)) +#define KOPSIA_ERROR BIT(1) +#define KOPSIA_DONE BIT(2) +#define KOPSIA_PP 13 + +struct avd_kopsia_tunable { u32 off, mask, val; }; +#include "avd-kopsia-tunables.h" + +struct avd_kopsia { + struct avd_dev *avd; + void __iomem *wrap; + void __iomem *dma; + struct work_struct poll_work; + bool running; +}; + +static void kopsia_update(void __iomem *reg, u32 mask, u32 value) +{ + writel((readl(reg) & ~mask) | value, reg); +} + +static int avd_kopsia_boot(struct avd_dev *avd) +{ + struct avd_kopsia *k = avd->backend_priv; + unsigned int i; + + if (readl(avd->ctrl) != 0x40030) + return -ENODEV; + + /* Keep the MCU halted: this transport owns the hardware status bits. */ + writel(0xe, avd->mbox + 0x28); + kopsia_update(avd->mbox + 0x40, BIT(24), BIT(24)); + writel(0, avd->mbox + 0x104); + writel(1, k->wrap + 0x18); + writel(0, k->dma); + writel(0x20, avd->ctrl + 0x1cc); + writel(U32_MAX, avd->ctrl + 0xe6d0); + writel(U32_MAX, avd->ctrl + 0xe6d4); + writel(U32_MAX, avd->ctrl + 0xe710); + writel(U32_MAX, avd->ctrl + 0xe714); + for (i = 0; i < ARRAY_SIZE(kopsia_tunables); i++) { + const struct avd_kopsia_tunable *t = &kopsia_tunables[i]; + + kopsia_update(avd->ctrl + t->off, t->mask, t->val); + } + kopsia_update(k->wrap + 0x14, 1, 1); + kopsia_update(k->wrap + 0x18, 1, 1); + kopsia_update(k->wrap + 0x4c, 1, 1); + kopsia_update(k->dma, 2, 0); + kopsia_update(k->dma + 0x10, 0x1ff8000f, 2); + kopsia_update(k->dma + 0x14, 0x1ff8000f, 2); + kopsia_update(k->dma + 0x18, 0x1ff8000f, 3); + kopsia_update(k->dma + 0x1c, 0xf, 0); + kopsia_update(k->dma + 0x20, 0xf, 0); + for (i = 0; i <= KOPSIA_PP; i++) + writel(KOPSIA_DONE | KOPSIA_ERROR, avd->ctrl + KOPSIA_STATUS(i)); + k->running = true; + dev_info_once(avd->dev, "Kopsia host backend, decoder %#x (polled completion)\n", + readl(avd->ctrl)); + return 0; +} + +static void avd_kopsia_shutdown(struct avd_dev *avd) +{ + struct avd_kopsia *k = avd->backend_priv; + + /* Serialized against polling by queue_mutex or the idle PM reference. */ + WRITE_ONCE(k->running, false); +} + +static void avd_kopsia_poll(struct work_struct *work) +{ + struct avd_kopsia *k = container_of(work, struct avd_kopsia, poll_work); + struct avd_dev *avd = k->avd; + + for (;;) { + struct avd_frame *f; + u32 vp, status; + bool active; + + mutex_lock(&avd->queue_mutex); + f = avd->compat_active; + if (!READ_ONCE(k->running) || !f || avd->stopping || avd->faulted) { + mutex_unlock(&avd->queue_mutex); + break; + } + vp = avd->variant->vp_slot_base[f->cmd[0]]; + status = readl(avd->ctrl + KOPSIA_STATUS(vp)); + if (status & KOPSIA_ERROR) { + writel(KOPSIA_ERROR, avd->ctrl + KOPSIA_STATUS(vp)); + avd_status(avd, vp); + avd_open_complete(avd, vp); + mutex_unlock(&avd->queue_mutex); + break; + } + if (status & KOPSIA_DONE) { + writel(KOPSIA_DONE, avd->ctrl + KOPSIA_STATUS(vp)); + avd_open_complete(avd, 0x100 | vp); + } + status = readl(avd->ctrl + KOPSIA_STATUS(KOPSIA_PP)); + if (status & KOPSIA_DONE) { + writel(KOPSIA_DONE, avd->ctrl + KOPSIA_STATUS(KOPSIA_PP)); + avd_open_complete(avd, 0x1000); + } + active = avd->compat_active != NULL; + mutex_unlock(&avd->queue_mutex); + if (!active) + break; + usleep_range(100, 200); + } +} + +static int avd_kopsia_submit(struct avd_dev *avd, struct avd_frame *f) +{ + struct avd_kopsia *k = avd->backend_priv; + int ret = avd_open_submit(avd, f); + + if (!ret) + queue_work(system_dfl_wq, &k->poll_work); + return ret; +} + +static unsigned int avd_kopsia_max_inflight(struct avd_dev *avd) +{ + return 1; +} + +static void avd_kopsia_cleanup(void *data) +{ + struct avd_kopsia *k = data; + + WRITE_ONCE(k->running, false); + cancel_work_sync(&k->poll_work); +} + +static int avd_kopsia_probe(struct avd_dev *avd) +{ + struct avd_kopsia *k = devm_kzalloc(avd->dev, sizeof(*k), GFP_KERNEL); + + if (!k) + return -ENOMEM; + k->avd = avd; + k->wrap = devm_platform_ioremap_resource_byname(avd->pdev, "wrap"); + if (IS_ERR(k->wrap)) + return PTR_ERR(k->wrap); + k->dma = devm_platform_ioremap_resource_byname(avd->pdev, "dma"); + if (IS_ERR(k->dma)) + return PTR_ERR(k->dma); + INIT_WORK(&k->poll_work, avd_kopsia_poll); + avd->backend_priv = k; + return devm_add_action_or_reset(avd->dev, avd_kopsia_cleanup, k); +} + +const struct avd_backend_ops avd_kopsia_backend = { + .name = "kopsia-host", + .probe = avd_kopsia_probe, + .boot = avd_kopsia_boot, + .shutdown = avd_kopsia_shutdown, + .max_inflight = avd_kopsia_max_inflight, + .submit = avd_kopsia_submit, + .suspend = avd_pm_backend_suspend, + .resume = avd_pm_backend_resume, +}; diff --git a/drivers/media/platform/apple/avd/avd-backend-open.c b/drivers/media/platform/apple/avd/avd-backend-open.c index d2054d06f948b..527b7fadd5543 100644 --- a/drivers/media/platform/apple/avd/avd-backend-open.c +++ b/drivers/media/platform/apple/avd/avd-backend-open.c @@ -74,7 +74,7 @@ static unsigned int avd_open_max_inflight(struct avd_dev *avd) return 1; } -static int avd_open_submit(struct avd_dev *avd, struct avd_frame *f) +int avd_open_submit(struct avd_dev *avd, struct avd_frame *f) { struct avd_ctx *ctx = f->ctx; u32 codec = f->cmd[0], vp = 0; @@ -131,13 +131,9 @@ static int avd_open_submit(struct avd_dev *avd, struct avd_frame *f) return 0; } -static irqreturn_t avd_open_irq(struct avd_dev *avd) +irqreturn_t avd_open_complete(struct avd_dev *avd, u32 status) { struct avd_frame *f = avd->compat_active; - u32 status; - - if (!avd_mbox_pop(avd, &status)) - return IRQ_HANDLED; if (!f) { /* * The old driver kicked PP for every VP DONE. A VP DONE with no @@ -177,6 +173,15 @@ static irqreturn_t avd_open_irq(struct avd_dev *avd) return IRQ_HANDLED; } +static irqreturn_t avd_open_irq(struct avd_dev *avd) +{ + u32 status; + + if (!avd_mbox_pop(avd, &status)) + return IRQ_HANDLED; + return avd_open_complete(avd, status); +} + const struct avd_backend_ops avd_open_backend = { .name = "open-compat", .boot = avd_boot, @@ -236,6 +241,13 @@ int avd_backend_select(struct avd_dev *avd) { int ret; + if (avd->variant->quirks & AVD_QUIRK_KOPSIA) { + avd->backend = &avd_kopsia_backend; + avd->capabilities = avd->variant->capabilities; + avd->fw_capabilities = avd->capabilities; + return avd->backend->probe(avd); + } + /* Apple probe returns -ENOENT only when no usable image is present. */ if (avd->variant->apple) { ret = avd_apple_backend.probe(avd); diff --git a/drivers/media/platform/apple/avd/avd-drv.c b/drivers/media/platform/apple/avd/avd-drv.c index b0ad4b2e261b2..8b96dd1eddb40 100644 --- a/drivers/media/platform/apple/avd/avd-drv.c +++ b/drivers/media/platform/apple/avd/avd-drv.c @@ -585,8 +585,35 @@ static const struct avd_variant avd_t8142_variant = { .quirks = AVD_QUIRK_HEVC_V5_HEADER | AVD_QUIRK_H264_MV_128, }; +static const struct avd_variant avd_t8152_variant = { + .vp_slots = { + [AVD_CODEC_HEVC] = 2, + [AVD_CODEC_H264] = 1, + [AVD_CODEC_VP9] = 1, + [AVD_CODEC_AV1] = 1, + }, + .vp_slot_base = { + [AVD_CODEC_HEVC] = 0, + [AVD_CODEC_H264] = 4, + [AVD_CODEC_VP9] = 8, + [AVD_CODEC_AV1] = 9, + }, + .fifo_slots = 7, + .configure_stream = t8122_configure_stream, + .capabilities = AVD_CAPABILITY_H264 | AVD_CAPABILITY_HEVC | + AVD_CAPABILITY_VP9 | AVD_CAPABILITY_AV1, + .revision = 4, + .vp_slot_offset = 0xc, + .submit_offset = 0x40, + .submit_queue_max_offset = 0x44, + .submit_queue_status_offset = 0x7c, + .quirks = AVD_QUIRK_HEVC_V5_HEADER | AVD_QUIRK_H264_MV_128 | + AVD_QUIRK_NO_RECOVERY_RESET | AVD_QUIRK_KOPSIA, +}; + /* can also be derived from a version register */ static const struct of_device_id avd_of_match[] = { + { .compatible = "apple,t8152-avd", .data = &avd_t8152_variant }, { .compatible = "apple,t8103-avd", .data = &avd_t8103_variant @@ -662,7 +689,8 @@ static int avd_probe(struct platform_device *pdev) match = of_match_node(avd_of_match, pdev->dev.of_node); avd->variant = match->data; - avd->rstc = devm_reset_control_get_exclusive(avd->dev, NULL); + avd->rstc = avd->variant->quirks & AVD_QUIRK_KOPSIA ? NULL : + devm_reset_control_get_exclusive(avd->dev, NULL); if (IS_ERR(avd->rstc)) return PTR_ERR(avd->rstc); @@ -724,16 +752,19 @@ static int avd_probe(struct platform_device *pdev) return ret; } - irq = platform_get_irq(pdev, 1); - if (irq < 0) - return irq; - avd->pm.irq = irq; - ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, - avd_irq_handler, IRQF_ONESHOT | IRQF_NO_AUTOEN, - dev_name(&pdev->dev), avd); - if (ret) { - dev_err(avd->dev, "Could not request IRQ 1"); - return ret; + /* Kopsia has no described completion interrupt; its backend polls. */ + if (!(avd->variant->quirks & AVD_QUIRK_KOPSIA)) { + irq = platform_get_irq(pdev, 1); + if (irq < 0) + return irq; + avd->pm.irq = irq; + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, + avd_irq_handler, IRQF_ONESHOT | IRQF_NO_AUTOEN, + dev_name(&pdev->dev), avd); + if (ret) { + dev_err(avd->dev, "Could not request IRQ 1"); + return ret; + } } /* diff --git a/drivers/media/platform/apple/avd/avd-kopsia-tunables.h b/drivers/media/platform/apple/avd/avd-kopsia-tunables.h new file mode 100644 index 0000000000000..95fb2d6d4792a --- /dev/null +++ b/drivers/media/platform/apple/avd/avd-kopsia-tunables.h @@ -0,0 +1,350 @@ +/* SPDX-License-Identifier: MIT */ +/* avd-fw v5/tier2 table, Copyright The Asahi Linux Contributors. */ +static const struct avd_kopsia_tunable kopsia_tunables[] = { + {0x0008, 0x80000000, 0x80000000}, /* MCTL_MODE */ + {0x1000, 0x80000000, 0x80000000}, /* HEVC_MODE */ + {0x1100, 0x80000000, 0x80000000}, /* HEVC_MODE */ + {0x1200, 0x80000000, 0x80000000}, /* HEVC_MODE */ + {0x1300, 0x80000000, 0x80000000}, /* HEVC_MODE */ + {0x1400, 0x80000000, 0x80000000}, /* H264_MODE */ + {0x1500, 0x80000000, 0x80000000}, /* H264_MODE */ + {0x1600, 0x80000000, 0x80000000}, /* H264_MODE */ + {0x1700, 0x80000000, 0x80000000}, /* H264_MODE */ + {0x1800, 0x80000000, 0x80000000}, /* VP9_MODE */ + {0x1900, 0x80000000, 0x80000000}, /* AV1_MODE */ + {0x1a00, 0x80000000, 0x80000000}, /* AV1_MODE */ + {0x1b00, 0x80000000, 0x80000000}, /* AV1_MODE */ + {0x4000, 0x80000000, 0x80000000}, /* QT_MODE */ + {0x4100, 0x80000000, 0x80000000}, /* IPMC_MODE */ + {0x4200, 0x80000000, 0x80000000}, /* LF_MODE */ + {0x4300, 0x80000000, 0x80000000}, /* MV_MODE */ + {0x4400, 0x80000000, 0x80000000}, /* TP_MODE */ + {0x4500, 0x80000000, 0x80000000}, /* PC_MODE */ + {0x4600, 0x80000000, 0x80000000}, /* SW_MODE */ + {0x4700, 0x80000000, 0x80000000}, /* LR_MODE */ + {0xc000, 0x00000001, 0x00000001}, /* VP_TOP_CLOCK_GATING */ + {0xc080, 0x800f0000, 0x80020000}, /* R_HEVC_BITS */ + {0xc084, 0x1fff1fff, 0x00000028}, /* BUF */ + {0xc090, 0x000000ff, 0x00000001}, /* EXT */ + {0xc0c0, 0x800f0000, 0x80020000}, /* R_HEVC_BITS */ + {0xc0c4, 0x1fff1fff, 0x00280028}, /* BUF */ + {0xc0d0, 0x000000ff, 0x00000002}, /* EXT */ + {0xc100, 0x800f0000, 0x80020000}, /* R_HEVC_BITS */ + {0xc104, 0x1fff1fff, 0x00500028}, /* BUF */ + {0xc110, 0x000000ff, 0x00000003}, /* EXT */ + {0xc140, 0x800f0000, 0x80020000}, /* R_HEVC_BITS */ + {0xc144, 0x1fff1fff, 0x00780028}, /* BUF */ + {0xc150, 0x000000ff, 0x00000004}, /* EXT */ + {0xc180, 0x800f0000, 0x80010000}, /* W_HEVC_INSN */ + {0xc184, 0x0fff0fff, 0x00be0028}, /* BUF */ + {0xc190, 0x000000ff, 0x00000056}, /* EXT */ + {0xc1c0, 0x800f0000, 0x80010000}, /* W_HEVC_INSN */ + {0xc1c4, 0x0fff0fff, 0x00e60028}, /* BUF */ + {0xc1d0, 0x000000ff, 0x00000057}, /* EXT */ + {0xc200, 0x800f0000, 0x80010000}, /* W_HEVC_INSN */ + {0xc204, 0x0fff0fff, 0x010e0028}, /* BUF */ + {0xc210, 0x000000ff, 0x00000058}, /* EXT */ + {0xc240, 0x800f0000, 0x80010000}, /* W_HEVC_INSN */ + {0xc244, 0x0fff0fff, 0x01360028}, /* BUF */ + {0xc250, 0x000000ff, 0x00000059}, /* EXT */ + {0xc280, 0x800f0000, 0x80020000}, /* R_H264_BITS */ + {0xc284, 0x1fff1fff, 0x00a00020}, /* BUF */ + {0xc290, 0x000000ff, 0x0000000d}, /* EXT */ + {0xc2c0, 0x800f0000, 0x80020000}, /* R_H264_BITS */ + {0xc2c4, 0x1fff1fff, 0x00c00020}, /* BUF */ + {0xc2d0, 0x000000ff, 0x0000000e}, /* EXT */ + {0xc300, 0x800f0000, 0x80020000}, /* R_H264_BITS */ + {0xc304, 0x1fff1fff, 0x00e00020}, /* BUF */ + {0xc310, 0x000000ff, 0x0000000f}, /* EXT */ + {0xc340, 0x800f0000, 0x80020000}, /* R_H264_BITS */ + {0xc344, 0x1fff1fff, 0x01000020}, /* BUF */ + {0xc350, 0x000000ff, 0x00000010}, /* EXT */ + {0xc380, 0x800f0000, 0x80020000}, /* W_H264_ABOVE_INFO */ + {0xc384, 0x0fff0fff, 0x00000004}, /* BUF */ + {0xc390, 0x000000ff, 0x00000011}, /* EXT */ + {0xc3c0, 0x800f0000, 0x80020000}, /* W_H264_ABOVE_INFO */ + {0xc3c4, 0x0fff0fff, 0x00040004}, /* BUF */ + {0xc3d0, 0x000000ff, 0x00000012}, /* EXT */ + {0xc400, 0x800f0000, 0x80020000}, /* W_H264_ABOVE_INFO */ + {0xc404, 0x0fff0fff, 0x00080004}, /* BUF */ + {0xc410, 0x000000ff, 0x00000013}, /* EXT */ + {0xc440, 0x800f0000, 0x80020000}, /* W_H264_ABOVE_INFO */ + {0xc444, 0x0fff0fff, 0x000c0004}, /* BUF */ + {0xc450, 0x000000ff, 0x00000014}, /* EXT */ + {0xc480, 0x800f0000, 0x80020000}, /* R_H264_ABOVE_INFO */ + {0xc484, 0x1fff1fff, 0x01200006}, /* BUF */ + {0xc490, 0x000000ff, 0x00000015}, /* EXT */ + {0xc4c0, 0x800f0000, 0x80020000}, /* R_H264_ABOVE_INFO */ + {0xc4c4, 0x1fff1fff, 0x01260006}, /* BUF */ + {0xc4d0, 0x000000ff, 0x00000016}, /* EXT */ + {0xc500, 0x800f0000, 0x80020000}, /* R_H264_ABOVE_INFO */ + {0xc504, 0x1fff1fff, 0x012c0006}, /* BUF */ + {0xc510, 0x000000ff, 0x00000017}, /* EXT */ + {0xc540, 0x800f0000, 0x80020000}, /* R_H264_ABOVE_INFO */ + {0xc544, 0x1fff1fff, 0x01320006}, /* BUF */ + {0xc550, 0x000000ff, 0x00000018}, /* EXT */ + {0xc580, 0x800f0000, 0x80010000}, /* W_H264_INSN */ + {0xc584, 0x0fff0fff, 0x015e0020}, /* BUF */ + {0xc590, 0x000000ff, 0x0000005a}, /* EXT */ + {0xc5c0, 0x800f0000, 0x80010000}, /* W_H264_INSN */ + {0xc5c4, 0x0fff0fff, 0x017e0020}, /* BUF */ + {0xc5d0, 0x000000ff, 0x0000005b}, /* EXT */ + {0xc600, 0x800f0000, 0x80010000}, /* W_H264_INSN */ + {0xc604, 0x0fff0fff, 0x019e0020}, /* BUF */ + {0xc610, 0x000000ff, 0x0000005c}, /* EXT */ + {0xc640, 0x800f0000, 0x80010000}, /* W_H264_INSN */ + {0xc644, 0x0fff0fff, 0x01be0020}, /* BUF */ + {0xc650, 0x000000ff, 0x0000005d}, /* EXT */ + {0xc680, 0x800f0000, 0x80020000}, /* R_VP9_BITS */ + {0xc684, 0x1fff1fff, 0x01380018}, /* BUF */ + {0xc690, 0x000000ff, 0x00000021}, /* EXT */ + {0xc6c0, 0x800f0000, 0x80020000}, /* W_VP9_ABOVE_INFO */ + {0xc6c4, 0x0fff0fff, 0x0010000a}, /* BUF */ + {0xc6d0, 0x000000ff, 0x00000022}, /* EXT */ + {0xc700, 0x800f0000, 0x80020000}, /* R_VP9_ABOVE_INFO */ + {0xc704, 0x1fff1fff, 0x0150000e}, /* BUF */ + {0xc710, 0x000000ff, 0x00000023}, /* EXT */ + {0xc740, 0x800f0000, 0x80020000}, /* W_VP9_SEG */ + {0xc744, 0x0fff0fff, 0x001a000a}, /* BUF */ + {0xc750, 0x000000ff, 0x00000024}, /* EXT */ + {0xc780, 0x800f0000, 0x80020000}, /* R_VP9_SEG */ + {0xc784, 0x1fff1fff, 0x015e000a}, /* BUF */ + {0xc790, 0x000000ff, 0x00000025}, /* EXT */ + {0xc7c0, 0x800f0000, 0x80020000}, /* W_VP9_COLOR */ + {0xc7c4, 0x0fff0fff, 0x0024000c}, /* BUF */ + {0xc7d0, 0x000000ff, 0x00000026}, /* EXT */ + {0xc800, 0x800f0000, 0x80020000}, /* R_VP9_COLOR */ + {0xc804, 0x1fff1fff, 0x01680012}, /* BUF */ + {0xc810, 0x000000ff, 0x00000027}, /* EXT */ + {0xc840, 0x800f0000, 0x80020000}, /* W_VP9_STATE */ + {0xc844, 0x0fff0fff, 0x0030000a}, /* BUF */ + {0xc850, 0x000000ff, 0x00000028}, /* EXT */ + {0xc880, 0x800f0000, 0x80020000}, /* R_VP9_STATE */ + {0xc884, 0x1fff1fff, 0x017a000a}, /* BUF */ + {0xc890, 0x000000ff, 0x00000029}, /* EXT */ + {0xc8c0, 0x800f0000, 0x80010000}, /* W_VP9_INSN */ + {0xc8c4, 0x0fff0fff, 0x01de0018}, /* BUF */ + {0xc8d0, 0x000000ff, 0x0000005e}, /* EXT */ + {0xc900, 0x800f0000, 0x80020000}, /* R_AV1_BITS */ + {0xc904, 0x1fff1fff, 0x01840016}, /* BUF */ + {0xc910, 0x000000ff, 0x0000002a}, /* EXT */ + {0xc940, 0x800f0000, 0x80020000}, /* R_AV1_BITS */ + {0xc944, 0x1fff1fff, 0x019a0016}, /* BUF */ + {0xc950, 0x000000ff, 0x0000002b}, /* EXT */ + {0xc980, 0x800f0000, 0x80020000}, /* R_AV1_BITS */ + {0xc984, 0x1fff1fff, 0x01b00016}, /* BUF */ + {0xc990, 0x000000ff, 0x0000002c}, /* EXT */ + {0xca00, 0x800f0000, 0x80020000}, /* W_AV1_ABOVE_INFO */ + {0xca04, 0x0fff0fff, 0x003a000a}, /* BUF */ + {0xca10, 0x000000ff, 0x0000002e}, /* EXT */ + {0xca40, 0x800f0000, 0x80020000}, /* W_AV1_ABOVE_INFO */ + {0xca44, 0x0fff0fff, 0x0044000a}, /* BUF */ + {0xca50, 0x000000ff, 0x0000002f}, /* EXT */ + {0xca80, 0x800f0000, 0x80020000}, /* W_AV1_ABOVE_INFO */ + {0xca84, 0x0fff0fff, 0x004e000a}, /* BUF */ + {0xca90, 0x000000ff, 0x00000030}, /* EXT */ + {0xcb00, 0x800f0000, 0x80020000}, /* R_AV1_ABOVE_INFO */ + {0xcb04, 0x1fff1fff, 0x01c60014}, /* BUF */ + {0xcb10, 0x000000ff, 0x00000032}, /* EXT */ + {0xcb40, 0x800f0000, 0x80020000}, /* R_AV1_ABOVE_INFO */ + {0xcb44, 0x1fff1fff, 0x01da0014}, /* BUF */ + {0xcb50, 0x000000ff, 0x00000033}, /* EXT */ + {0xcb80, 0x800f0000, 0x80020000}, /* R_AV1_ABOVE_INFO */ + {0xcb84, 0x1fff1fff, 0x01ee0014}, /* BUF */ + {0xcb90, 0x000000ff, 0x00000034}, /* EXT */ + {0xcc00, 0x800f0000, 0x80020000}, /* W_AV1_SEG */ + {0xcc04, 0x0fff0fff, 0x00580004}, /* BUF */ + {0xcc10, 0x000000ff, 0x00000036}, /* EXT */ + {0xcc40, 0x800f0000, 0x80020000}, /* W_AV1_SEG */ + {0xcc44, 0x0fff0fff, 0x005c0004}, /* BUF */ + {0xcc50, 0x000000ff, 0x00000037}, /* EXT */ + {0xcc80, 0x800f0000, 0x80020000}, /* W_AV1_SEG */ + {0xcc84, 0x0fff0fff, 0x00600004}, /* BUF */ + {0xcc90, 0x000000ff, 0x00000038}, /* EXT */ + {0xcd00, 0x800f0000, 0x80020000}, /* R_AV1_SEG */ + {0xcd04, 0x1fff1fff, 0x02020008}, /* BUF */ + {0xcd10, 0x000000ff, 0x0000003a}, /* EXT */ + {0xcd40, 0x800f0000, 0x80020000}, /* R_AV1_SEG */ + {0xcd44, 0x1fff1fff, 0x020a0008}, /* BUF */ + {0xcd50, 0x000000ff, 0x0000003b}, /* EXT */ + {0xcd80, 0x800f0000, 0x80020000}, /* R_AV1_SEG */ + {0xcd84, 0x1fff1fff, 0x02120008}, /* BUF */ + {0xcd90, 0x000000ff, 0x0000003c}, /* EXT */ + {0xce00, 0x800f0000, 0x80020000}, /* W_AV1_COLOR */ + {0xce04, 0x0fff0fff, 0x00640008}, /* BUF */ + {0xce10, 0x000000ff, 0x0000003e}, /* EXT */ + {0xce40, 0x800f0000, 0x80020000}, /* W_AV1_COLOR */ + {0xce44, 0x0fff0fff, 0x006c0008}, /* BUF */ + {0xce50, 0x000000ff, 0x0000003f}, /* EXT */ + {0xce80, 0x800f0000, 0x80020000}, /* W_AV1_COLOR */ + {0xce84, 0x0fff0fff, 0x00740008}, /* BUF */ + {0xce90, 0x000000ff, 0x00000040}, /* EXT */ + {0xcf00, 0x800f0000, 0x80020000}, /* R_AV1_COLOR0 */ + {0xcf04, 0x1fff1fff, 0x021a0010}, /* BUF */ + {0xcf10, 0x000000ff, 0x00000042}, /* EXT */ + {0xcf40, 0x800f0000, 0x80020000}, /* R_AV1_COLOR0 */ + {0xcf44, 0x1fff1fff, 0x022a0010}, /* BUF */ + {0xcf50, 0x000000ff, 0x00000043}, /* EXT */ + {0xcf80, 0x800f0000, 0x80020000}, /* R_AV1_COLOR0 */ + {0xcf84, 0x1fff1fff, 0x023a0010}, /* BUF */ + {0xcf90, 0x000000ff, 0x00000044}, /* EXT */ + {0xd000, 0x800f0000, 0x80020000}, /* R_AV1_COLOR1 */ + {0xd004, 0x1fff1fff, 0x024a0010}, /* BUF */ + {0xd010, 0x000000ff, 0x00000046}, /* EXT */ + {0xd040, 0x800f0000, 0x80020000}, /* R_AV1_COLOR1 */ + {0xd044, 0x1fff1fff, 0x025a0010}, /* BUF */ + {0xd050, 0x000000ff, 0x00000047}, /* EXT */ + {0xd080, 0x800f0000, 0x80020000}, /* R_AV1_COLOR1 */ + {0xd084, 0x1fff1fff, 0x026a0010}, /* BUF */ + {0xd090, 0x000000ff, 0x00000048}, /* EXT */ + {0xd100, 0x800f0000, 0x80020000}, /* R_AV1_COLOR2 */ + {0xd104, 0x1fff1fff, 0x027a0010}, /* BUF */ + {0xd110, 0x000000ff, 0x0000004a}, /* EXT */ + {0xd140, 0x800f0000, 0x80020000}, /* R_AV1_COLOR2 */ + {0xd144, 0x1fff1fff, 0x028a0010}, /* BUF */ + {0xd150, 0x000000ff, 0x0000004b}, /* EXT */ + {0xd180, 0x800f0000, 0x80020000}, /* R_AV1_COLOR2 */ + {0xd184, 0x1fff1fff, 0x029a0010}, /* BUF */ + {0xd190, 0x000000ff, 0x0000004c}, /* EXT */ + {0xd200, 0x800f0000, 0x80020000}, /* W_AV1_PROBS */ + {0xd204, 0x0fff0fff, 0x007c0016}, /* BUF */ + {0xd210, 0x000000ff, 0x0000004e}, /* EXT */ + {0xd240, 0x800f0000, 0x80020000}, /* W_AV1_PROBS */ + {0xd244, 0x0fff0fff, 0x00920016}, /* BUF */ + {0xd250, 0x000000ff, 0x0000004f}, /* EXT */ + {0xd280, 0x800f0000, 0x80020000}, /* W_AV1_PROBS */ + {0xd284, 0x0fff0fff, 0x00a80016}, /* BUF */ + {0xd290, 0x000000ff, 0x00000050}, /* EXT */ + {0xd300, 0x800f0000, 0x80020000}, /* R_AV1_PROBS */ + {0xd304, 0x1fff1fff, 0x02aa0074}, /* BUF */ + {0xd310, 0x000000ff, 0x00000052}, /* EXT */ + {0xd340, 0x800f0000, 0x80020000}, /* R_AV1_PROBS */ + {0xd344, 0x1fff1fff, 0x031e0074}, /* BUF */ + {0xd350, 0x000000ff, 0x00000053}, /* EXT */ + {0xd380, 0x800f0000, 0x80020000}, /* R_AV1_PROBS */ + {0xd384, 0x1fff1fff, 0x03920074}, /* BUF */ + {0xd390, 0x000000ff, 0x00000054}, /* EXT */ + {0xd400, 0x800f0000, 0x80010000}, /* W_AV1_INSN */ + {0xd404, 0x0fff0fff, 0x01f60016}, /* BUF */ + {0xd410, 0x000000ff, 0x0000005f}, /* EXT */ + {0xd440, 0x800f0000, 0x80010000}, /* W_AV1_INSN */ + {0xd444, 0x0fff0fff, 0x020c0016}, /* BUF */ + {0xd450, 0x000000ff, 0x00000060}, /* EXT */ + {0xd480, 0x800f0000, 0x80010000}, /* W_AV1_INSN */ + {0xd484, 0x0fff0fff, 0x02220016}, /* BUF */ + {0xd490, 0x000000ff, 0x00000061}, /* EXT */ + {0xd500, 0x800f3c00, 0x80011000}, /* R_PIPE_INSN */ + {0xd504, 0x1fff1fff, 0x040600f2}, /* BUF */ + {0xd510, 0x000000ff, 0x00000063}, /* EXT */ + {0xd540, 0x800f3c00, 0x80011000}, /* R_PIPE_INSN */ + {0xd544, 0x1fff1fff, 0x04f800f2}, /* BUF */ + {0xd550, 0x000000ff, 0x00000064}, /* EXT */ + {0xd580, 0x800f3c00, 0x80011000}, /* R_PIPE_INSN */ + {0xd584, 0x1fff1fff, 0x05ea00f2}, /* BUF */ + {0xd590, 0x000000ff, 0x00000065}, /* EXT */ + {0xd5c0, 0x800f3c00, 0x80011000}, /* R_PIPE_INSN */ + {0xd5c4, 0x1fff1fff, 0x06dc00f2}, /* BUF */ + {0xd5d0, 0x000000ff, 0x00000066}, /* EXT */ + {0xe000, 0x00000001, 0x00000001}, /* INTRA_TOP_CLOCK_GATING */ + {0xe080, 0x800f0000, 0x80020000}, /* W_IP_ABOVE_PIX */ + {0xe084, 0x0fff0fff, 0x0000001c}, /* BUF */ + {0xe090, 0x000000ff, 0x00000069}, /* EXT */ + {0xe0c0, 0x800f0000, 0x80020000}, /* R_IP_ABOVE_PIX */ + {0xe0c4, 0x1fff1fff, 0x0000002e}, /* BUF */ + {0xe0d0, 0x000000ff, 0x0000006a}, /* EXT */ + {0xe100, 0x800f0000, 0x80020000}, /* W_LF_ABOVE_PIX */ + {0xe104, 0x0fff0fff, 0x001c0054}, /* BUF */ + {0xe110, 0x000000ff, 0x00000071}, /* EXT */ + {0xe140, 0x800f0000, 0x80020000}, /* R_LF_ABOVE_PIX */ + {0xe144, 0x1fff1fff, 0x002e009e}, /* BUF */ + {0xe150, 0x000000ff, 0x00000072}, /* EXT */ + {0xe180, 0x800f0000, 0x80020000}, /* W_LF_ABOVE_INFO */ + {0xe184, 0x0fff0fff, 0x00700016}, /* BUF */ + {0xe190, 0x000000ff, 0x0000006f}, /* EXT */ + {0xe1c0, 0x800f0000, 0x80020000}, /* R_LF_ABOVE_INFO */ + {0xe1c4, 0x1fff1fff, 0x00cc0022}, /* BUF */ + {0xe1d0, 0x000000ff, 0x00000070}, /* EXT */ + {0xe200, 0x800f0000, 0x80020000}, /* W_LF_LEFT_PIX */ + {0xe204, 0x0fff0fff, 0x00860032}, /* BUF */ + {0xe210, 0x000000ff, 0x00000075}, /* EXT */ + {0xe240, 0x800f0000, 0x80020000}, /* R_LF_LEFT_PIX */ + {0xe244, 0x1fff1fff, 0x00ee0032}, /* BUF */ + {0xe250, 0x000000ff, 0x00000076}, /* EXT */ + {0xe280, 0x800f0000, 0x80020000}, /* W_LF_LEFT_INFO */ + {0xe284, 0x0fff0fff, 0x00b8000c}, /* BUF */ + {0xe290, 0x000000ff, 0x00000073}, /* EXT */ + {0xe2c0, 0x800f0000, 0x80020000}, /* R_LF_LEFT_INFO */ + {0xe2c4, 0x1fff1fff, 0x0120000c}, /* BUF */ + {0xe2d0, 0x000000ff, 0x00000074}, /* EXT */ + {0xe300, 0x800f0000, 0x80020000}, /* W_SR_LEFT_PIX */ + {0xe304, 0x0fff0fff, 0x00c40046}, /* BUF */ + {0xe310, 0x000000ff, 0x00000077}, /* EXT */ + {0xe340, 0x800f0000, 0x80020000}, /* R_SR_LEFT_PIX */ + {0xe344, 0x1fff1fff, 0x012c0046}, /* BUF */ + {0xe350, 0x000000ff, 0x00000078}, /* EXT */ + {0xe380, 0x800f0000, 0x80020000}, /* W_RF_ABOVE_INFO */ + {0xe384, 0x0fff0fff, 0x010a001a}, /* BUF */ + {0xe390, 0x000000ff, 0x00000079}, /* EXT */ + {0xe3c0, 0x800f0000, 0x80020000}, /* R_RF_ABOVE_INFO */ + {0xe3c4, 0x1fff1fff, 0x01720032}, /* BUF */ + {0xe3d0, 0x000000ff, 0x0000007a}, /* EXT */ + {0xe400, 0x800f0000, 0x80020000}, /* W_RF_LEFT_PIX */ + {0xe404, 0x0fff0fff, 0x0124002a}, /* BUF */ + {0xe410, 0x000000ff, 0x0000007d}, /* EXT */ + {0xe440, 0x800f0000, 0x80020000}, /* R_RF_LEFT_PIX */ + {0xe444, 0x1fff1fff, 0x01a4002a}, /* BUF */ + {0xe450, 0x000000ff, 0x0000007e}, /* EXT */ + {0xe480, 0x800f0000, 0x80020000}, /* W_RF_LEFT_INFO */ + {0xe484, 0x0fff0fff, 0x014e000a}, /* BUF */ + {0xe490, 0x000000ff, 0x0000007b}, /* EXT */ + {0xe4c0, 0x800f0000, 0x80020000}, /* R_RF_LEFT_INFO */ + {0xe4c4, 0x1fff1fff, 0x01ce000a}, /* BUF */ + {0xe4d0, 0x000000ff, 0x0000007c}, /* EXT */ + {0xe500, 0x800f7c00, 0x80027c00}, /* W_SW_PIX */ + {0xe504, 0x0fff0fff, 0x016800d0}, /* BUF */ + {0xe510, 0x000000ff, 0x00000085}, /* EXT */ + {0xe540, 0x800f0000, 0x80020000}, /* W_SW_LEFT */ + {0xe544, 0x0fff0fff, 0x015c000c}, /* BUF */ + {0xe550, 0x000000ff, 0x00000083}, /* EXT */ + {0xe580, 0x800f0000, 0x80020000}, /* R_SW_LEFT */ + {0xe584, 0x1fff1fff, 0x01d8000c}, /* BUF */ + {0xe590, 0x000000ff, 0x00000084}, /* EXT */ + {0xe5c0, 0x800f0000, 0x80020000}, /* W_AZ_ABOVE_PIX */ + {0xe5c4, 0x0fff0fff, 0x02380012}, /* BUF */ + {0xe5d0, 0x000000ff, 0x0000007f}, /* EXT */ + {0xe600, 0x800f0000, 0x80020000}, /* R_AZ_ABOVE_PIX */ + {0xe604, 0x1fff1fff, 0x01e40020}, /* BUF */ + {0xe610, 0x000000ff, 0x00000080}, /* EXT */ + {0xe640, 0x800f0000, 0x80020000}, /* W_AZ_LEFT_PIX */ + {0xe644, 0x0fff0fff, 0x024a006c}, /* BUF */ + {0xe650, 0x000000ff, 0x00000081}, /* EXT */ + {0xe680, 0x800f0000, 0x80020000}, /* R_AZ_LEFT_PIX */ + {0xe684, 0x1fff1fff, 0x02040060}, /* BUF */ + {0xe690, 0x000000ff, 0x00000082}, /* EXT */ + {0xe6c0, 0x800ff000, 0x80034000}, /* W_ZIP */ + {0xe6c8, 0x0fff0fff, 0x02ce009e}, /* BUF (CMP) */ + {0xe6cc, 0x0fff0fff, 0x02b6000c}, /* BUF (HDR) */ + {0xe6ec, 0x0000ffff, 0x00008789}, /* EXT */ + {0xe700, 0x800ff000, 0x80034000}, /* W_ZIP */ + {0xe708, 0x0fff0fff, 0x036c009e}, /* BUF (CMP) */ + {0xe70c, 0x0fff0fff, 0x02c2000c}, /* BUF (HDR) */ + {0xe72c, 0x0000ffff, 0x0000888a}, /* EXT */ + {0xe740, 0x800f0000, 0x80020000}, /* W_PIPE_STATS */ + {0xe744, 0x0fff0fff, 0x01580004}, /* BUF */ + {0xe750, 0x000000ff, 0x00000067}, /* EXT */ + {0xe800, 0x00000001, 0x00000001}, /* INTER_TOP_CLOCK_GATING */ + {0xe880, 0x800f0000, 0x80020000}, /* W_MV_ABOVE_INFO */ + {0xe884, 0x0fff0fff, 0x00000016}, /* BUF */ + {0xe890, 0x000000ff, 0x0000006b}, /* EXT */ + {0xe8c0, 0x800f0000, 0x80020000}, /* R_MV_ABOVE_INFO */ + {0xe8c4, 0x1fff1fff, 0x00000022}, /* BUF */ + {0xe8d0, 0x000000ff, 0x0000006c}, /* EXT */ + {0xe900, 0x800f0000, 0x80020000}, /* W_MV_COLOR */ + {0xe904, 0x0fff0fff, 0x00160022}, /* BUF */ + {0xe910, 0x000000ff, 0x0000006d}, /* EXT */ + {0xe940, 0x800f0000, 0x80020000}, /* R_MV_COLOR */ + {0xe944, 0x1fff1fff, 0x0022003e}, /* BUF */ + {0xe950, 0x000000ff, 0x0000006e}, /* EXT */ + {0xe980, 0x80ff0004, 0x80550004}, /* R_ZIP */ + {0xe9a8, 0xffffffff, 0x8d8f8c8e}, /* EXT */ +}; diff --git a/drivers/media/platform/apple/avd/avd.h b/drivers/media/platform/apple/avd/avd.h index 568cbfc6d06f8..7437b54be580d 100644 --- a/drivers/media/platform/apple/avd/avd.h +++ b/drivers/media/platform/apple/avd/avd.h @@ -46,6 +46,8 @@ /* A reset after a timeout hangs the machine: stay parked and retire the decoder */ #define AVD_QUIRK_NO_RECOVERY_RESET BIT(5) +#define AVD_QUIRK_KOPSIA BIT(6) + #define VP_SLOT_NONE 255 #define INST_FIFO_SLOT_NONE 255 @@ -410,6 +412,9 @@ void avd_queue_add_ctx(struct avd_ctx *ctx); void avd_queue_del_ctx(struct avd_ctx *ctx); int avd_open_build_program(struct avd_ctx *ctx); extern const struct avd_backend_ops avd_open_backend; +extern const struct avd_backend_ops avd_kopsia_backend; +int avd_open_submit(struct avd_dev *avd, struct avd_frame *f); +irqreturn_t avd_open_complete(struct avd_dev *avd, u32 status); extern const struct avd_backend_ops avd_apple_backend; extern const struct avd_backend_ops avd_qfw_backend; struct avd_qfw; From 74fb6b5acc43b2c666155a53a5e82964b234c680 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 19:29:22 +0100 Subject: [PATCH 11/12] arm64: dts: apple: t8152: describe the Kopsia video decoder Describe the T8152 Kopsia decoder in the SoC peripherals, disabled, so every T8152 board can enable it: its five register banks, PSD service 50 (apple,t8152-psd) as the power domain shared by the decoder and its DART, powered off by genpd while both are idle, and the DART as the apple,t8152-avd-dart instance with its Gen3 TLBI aperture, its initialization tunables and a 64 GiB window at 1 TiB inside the native 1..4 TiB DMA aperture. The tunables are those of the J873g's ADT. Signed-off-by: Thomas Glanzmann --- .../boot/dts/apple/t8152-peripherals.dtsi | 55 ++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8152-peripherals.dtsi b/arch/arm64/boot/dts/apple/t8152-peripherals.dtsi index 1cbd604c41a47..b48005ad892c9 100644 --- a/arch/arm64/boot/dts/apple/t8152-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-peripherals.dtsi @@ -210,11 +210,62 @@ status = "disabled"; }; + /* Kopsia decoder: PSD service 50, Gen3 DART streams 0..2. */ + ps_avd: power-controller@303a13200 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a13200 0x0 0x100>; + #power-domain-cells = <0>; + label = "avd"; + status = "disabled"; + }; + avd_dart: iommu@485020000 { - compatible = "apple,t8152-dart", "apple,t8110-dart"; - reg = <0x4 0x85020000 0x0 0x20000>; + compatible = "apple,t8152-avd-dart"; + reg = <0x4 0x85020000 0x0 0x20000>, <0x2 0x300 0x0 0x10>; + reg-names = "dart", "tlbi"; interrupts = ; #iommu-cells = <1>; + power-domains = <&ps_avd>; + /* A 64-GiB window within the ADT's 1..4-TiB DMA aperture. */ + apple,dma-range = <0x100 0x0 0x10 0x0>; + apple,tunable = < + 0x20c 0x80000121 0x80000121 + 0x220 0xf0f 0xf0f + 0x224 0xffff 0x909 + 0x300 0x1f31 0x1 + 0x308 0x3ffffffc 0x10000000 + 0x310 0x3ffffffc 0x3ffffffc + 0x800 0xf007f 0x10000 + 0x804 0xf007f 0x20002 + 0x808 0xf007f 0x50006 + 0x80c 0xf007f 0x20026 + 0x810 0xf007f 0x3002a + 0x814 0xf007f 0x40032 + 0x818 0xf007f 0x0 + 0x81c 0xf007f 0x0 + 0x820 0xf007f 0x0 + 0x824 0xf007f 0x0 + 0x828 0xf007f 0x0 + 0x82c 0xf007f 0x0 + 0x830 0xf007f 0x0 + 0x834 0xf007f 0x0 + 0x838 0xf007f 0x0 + 0x83c 0xf007f 0x0 + 0x4600 0x2 0x2 + >; + status = "disabled"; + }; + + avd: video-codec@485400000 { + compatible = "apple,t8152-avd"; + reg = <0x4 0x85400000 0x0 0x12000>, + <0x4 0x85500000 0x0 0x4000>, + <0x4 0x85100000 0x0 0x10000>, + <0x4 0x850c0000 0x0 0x4000>, + <0x4 0x85070000 0x0 0x4000>; + reg-names = "code", "mbox", "ctrl", "wrap", "dma"; + power-domains = <&ps_avd>; + iommus = <&avd_dart 0>, <&avd_dart 1>, <&avd_dart 2>; status = "disabled"; }; From e9da8548f33fcaa4b2c786a658374594bd52a76c Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 19:29:27 +0100 Subject: [PATCH 12/12] arm64: dts: apple: j873: enable the Kopsia video decoder Enable the T8152 decoder, its PSD domain and its DART on the J873g. This enables the request decoder node used by FFmpeg and mpv on the M6 Mac mini. The PSD provider supplies both AVD and DART so translation is initialized only after their shared domain is powered. Signed-off-by: Thomas Glanzmann --- arch/arm64/boot/dts/apple/t8152-j873-avd.dtsi | 14 ++++++++++++++ arch/arm64/boot/dts/apple/t8152-j873g.dts | 2 ++ 2 files changed, 16 insertions(+) create mode 100644 arch/arm64/boot/dts/apple/t8152-j873-avd.dtsi diff --git a/arch/arm64/boot/dts/apple/t8152-j873-avd.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-avd.dtsi new file mode 100644 index 0000000000000..d36cd5ef242b2 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-avd.dtsi @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* J873g: the Kopsia video decoder (described in t8152-peripherals.dtsi). */ + +&ps_avd { + status = "okay"; +}; + +&avd_dart { + status = "okay"; +}; + +&avd { + status = "okay"; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873g.dts b/arch/arm64/boot/dts/apple/t8152-j873g.dts index 00fe5207a1956..fba4f0bfa2f66 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873g.dts +++ b/arch/arm64/boot/dts/apple/t8152-j873g.dts @@ -430,3 +430,5 @@ reg = <0x3 0x83020000 0x0 0xc000>, <0x3 0x83040000 0x0 0xc000>; }; + +#include "t8152-j873-avd.dtsi"