From 628c256988eb8f82ef4e33ca28e6990aa23cf6ba Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 31 Oct 2026 04:16:53 +1100 Subject: [PATCH 1/3] dt-bindings: media: apple,ave: describe T6000 and T8112 Add the M1 Pro and M2 AVE compatibles to the shared encoder binding. Both use the same three register windows, five power domains and paired DART topology. Assisted-by: LLM Signed-off-by: Ryan Murray --- .../devicetree/bindings/media/apple,t8140-ave.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/media/apple,t8140-ave.yaml b/Documentation/devicetree/bindings/media/apple,t8140-ave.yaml index 61e10feb5df71..cfc518d4a0237 100644 --- a/Documentation/devicetree/bindings/media/apple,t8140-ave.yaml +++ b/Documentation/devicetree/bindings/media/apple,t8140-ave.yaml @@ -10,14 +10,16 @@ maintainers: - Miguel Cruz <7362641+Acelogic@users.noreply.github.com> description: | - The T6041 and T8140 AVE coprocessors encode video using firmware preloaded by the - bootloader. Its two DART instances translate the same stream. The + The T6000, T6041, T8112 and T8140 AVE coprocessors encode video using firmware + preloaded by the bootloader. Its two DART instances translate the same stream. The bootloader supplies two reserved firmware regions and their IOVA mappings. properties: compatible: enum: + - apple,t6000-ave - apple,t6041-ave + - apple,t8112-ave - apple,t8140-ave reg: From 244eddc0a09840a53fd67028297f76de11f8b179 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 31 Oct 2026 04:16:53 +1100 Subject: [PATCH 2/3] media: apple: ave: add probe-only T6000 and T8112 match data Select firmware segment sizes, boot identity, device type, explicit coprocessor offsets and LFS reference sizing from SoC match data. Validate both reserved segments and their loader checksums before binding. The pre-M4 command constants, MCC DSID and firmware builds still need qualification. Refuse encoding and firmware startup with an informational message on these SoCs, even if their TEXT checksum happens to match T8140. Keep the shared wire layouts and the qualified T8140 command path. Exercise exact descriptor sizes and alignment boundaries with an independent KUnit sizing suite. Assisted-by: LLM Signed-off-by: Ryan Murray --- Documentation/admin-guide/media/apple-ave.rst | 14 +++ MAINTAINERS | 1 + drivers/media/platform/apple/ave/.kunitconfig | 7 ++ drivers/media/platform/apple/ave/Kconfig | 12 +++ drivers/media/platform/apple/ave/Makefile | 1 + drivers/media/platform/apple/ave/ave-drv.c | 48 ++++++++- drivers/media/platform/apple/ave/ave-fw.c | 100 ++++++++++++------ drivers/media/platform/apple/ave/ave-ipc.c | 6 +- drivers/media/platform/apple/ave/ave-regs.h | 4 +- drivers/media/platform/apple/ave/ave-sess.c | 4 +- .../media/platform/apple/ave/ave-sizes-test.c | 59 +++++++++++ drivers/media/platform/apple/ave/ave-sizes.h | 21 ++++ drivers/media/platform/apple/ave/ave.h | 26 +++++ 13 files changed, 263 insertions(+), 40 deletions(-) create mode 100644 drivers/media/platform/apple/ave/.kunitconfig create mode 100644 drivers/media/platform/apple/ave/ave-sizes-test.c create mode 100644 drivers/media/platform/apple/ave/ave-sizes.h diff --git a/Documentation/admin-guide/media/apple-ave.rst b/Documentation/admin-guide/media/apple-ave.rst index 2a76d4eac23d1..fbac9d743da9b 100644 --- a/Documentation/admin-guide/media/apple-ave.rst +++ b/Documentation/admin-guide/media/apple-ave.rst @@ -45,6 +45,20 @@ build the device binds, but starting a stream fails with ``ENOTSUPP`` and a message naming the checksum, until that build's command layout has been checked. +T6000 (M1 Pro) and T8112 (M2) have probe-only support in this driver. Their +device tree nodes and both encoder DARTs remain disabled. The firmware +handoff must reserve their preloaded TEXT (0xd0000 bytes) and DATA +(0x128000 bytes), preserve the ADT remap addresses and export both CRCs. +An enabled node with a valid handoff may bind, but encoding is refused with +an informational message until per-SoC command constants, MCC DSID and the +firmware CRCs have been qualified. The T8140 command constants are never a +fallback for these devices. Enabling a node alone does not enable encoding. + +The shared Start layout uses a smaller LFS reference surface on both +pre-M4 devices: at 1920x1080 its exact descriptor size is 0x85200 for AVC +and 0x1fe00 for HEVC, before the DMA allocation is page rounded. The +``apple-ave-sizes`` KUnit suite checks these sizes and alignment boundaries. + With debugfs mounted, ``apple-ave/last_start_h264``, ``last_start_hevc``, ``last_process0_h264`` and ``last_process0_hevc`` hold the last Start command built and the first Process command of the last session, diff --git a/MAINTAINERS b/MAINTAINERS index 93fa816104d7f..859f70c1d19bb 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2808,6 +2808,7 @@ L: linux-media@vger.kernel.org S: Maintained W: https://aurora-silicon.github.io F: Documentation/admin-guide/media/apple-ave.rst +F: Documentation/devicetree/bindings/media/apple,t8140-ave.yaml F: drivers/media/platform/apple/ave/ ARM/APPLE QSPIMC DRIVER diff --git a/drivers/media/platform/apple/ave/.kunitconfig b/drivers/media/platform/apple/ave/.kunitconfig new file mode 100644 index 0000000000000..891a4969c8986 --- /dev/null +++ b/drivers/media/platform/apple/ave/.kunitconfig @@ -0,0 +1,7 @@ +CONFIG_KUNIT=y +CONFIG_EXPERT=y +CONFIG_NO_IOMEM=n +CONFIG_MEDIA_SUPPORT=y +CONFIG_MEDIA_SUPPORT_FILTER=n +CONFIG_MEDIA_PLATFORM_DRIVERS=y +CONFIG_VIDEO_APPLE_AVE_KUNIT_TEST=y diff --git a/drivers/media/platform/apple/ave/Kconfig b/drivers/media/platform/apple/ave/Kconfig index baf6218ecdd5b..20eb7cc404192 100644 --- a/drivers/media/platform/apple/ave/Kconfig +++ b/drivers/media/platform/apple/ave/Kconfig @@ -10,9 +10,21 @@ config VIDEO_APPLE_AVE help V4L2 memory-to-memory driver for the AVE H.264/HEVC encoder in Apple T8140 (A18 Pro) SoCs, as in the MacBook Neo. + T6000 (M1 Pro) and T8112 (M2) have probe-only support; encoding + requires qualified firmware command constants. The encoder firmware is loaded by the bootloader; the driver builds every command itself. See Documentation/admin-guide/media/apple-ave.rst. To compile this driver as a module, choose M here: the module will be called apple-ave. + +config VIDEO_APPLE_AVE_KUNIT_TEST + tristate "KUnit tests for Apple AVE buffer sizing" if !KUNIT_ALL_TESTS + depends on KUNIT + default KUNIT_ALL_TESTS + help + Test the exact LFS reference descriptor sizes for pre-M4 and T8140 + encoders, including picture alignment boundaries and the reference + 1920x1080 AVC and HEVC sizes. The tests do not need an encoder or + any firmware and can run independently of the AVE driver. diff --git a/drivers/media/platform/apple/ave/Makefile b/drivers/media/platform/apple/ave/Makefile index 53bb6b554f770..899d8990555ea 100644 --- a/drivers/media/platform/apple/ave/Makefile +++ b/drivers/media/platform/apple/ave/Makefile @@ -2,3 +2,4 @@ obj-$(CONFIG_VIDEO_APPLE_AVE) += apple-ave.o apple-ave-y := ave-drv.o ave-fw.o ave-ipc.o ave-cmd.o ave-image.o ave-sess.o ave-v4l2.o +obj-$(CONFIG_VIDEO_APPLE_AVE_KUNIT_TEST) += ave-sizes-test.o diff --git a/drivers/media/platform/apple/ave/ave-drv.c b/drivers/media/platform/apple/ave/ave-drv.c index b25ac9df48a67..09eb356332abc 100644 --- a/drivers/media/platform/apple/ave/ave-drv.c +++ b/drivers/media/platform/apple/ave/ave-drv.c @@ -14,14 +14,55 @@ #include #include #include +#include #include #include #include #include "ave.h" +#include "ave-regs.h" #define AVE_AUTOSUSPEND_MS 2000 +static const struct ave_coproc_regs ave_coproc_v40 = { + .vcbar = AVE_COPROC_VCBAR, + .timebase_freq = AVE_COPROC_TIMEBASE_FREQ, + .timebase = AVE_COPROC_TIMEBASE, + .ctrl = AVE_COPROC_CTRL, + .status = AVE_COPROC_STATUS, + .boot_arg = AVE_COPROC_BOOT_ARG, + .keep_mappings = AVE_COPROC_KEEP_MAPPINGS, +}; + +/* Pre-M4 wire layouts are shared; their command constants still need traces. */ +static const struct ave_variant ave_t6000 = { + .regs = &ave_coproc_v40, + .fw_text_size = 0xd0000, + .fw_data_size = 0x128000, + .boot_device_id = 11, + .device_type = 9, + .lfs_ref_scale = 1, +}; + +static const struct ave_variant ave_t8112 = { + .regs = &ave_coproc_v40, + .fw_text_size = 0xd0000, + .fw_data_size = 0x128000, + .boot_device_id = 15, + .device_type = 13, + .lfs_ref_scale = 1, +}; + +static const struct ave_variant ave_t8140 = { + .regs = &ave_coproc_v40, + .fw_text_size = 0x14c000, + .fw_data_size = 0x130000, + .boot_device_id = 29, + .device_type = 27, + .lfs_ref_scale = 2, + .encoding_text_crc = AVE_FW_TEXT_CRC_9003_78_0, +}; + /* * debugfs: apple-ave/last_start_{h264,hevc} hold the last Start built and * last_process0_{h264,hevc} the first Process of the last session, so the @@ -84,6 +125,9 @@ static int ave_probe(struct platform_device *pdev) if (!ave) return -ENOMEM; ave->dev = dev; + ave->variant = of_device_get_match_data(dev); + if (!ave->variant) + return -ENODEV; mutex_init(&ave->hw_lock); platform_set_drvdata(pdev, ave); @@ -202,7 +246,9 @@ static const struct dev_pm_ops ave_pm_ops = { }; static const struct of_device_id ave_of_match[] = { - { .compatible = "apple,t8140-ave" }, + { .compatible = "apple,t6000-ave", .data = &ave_t6000 }, + { .compatible = "apple,t8112-ave", .data = &ave_t8112 }, + { .compatible = "apple,t8140-ave", .data = &ave_t8140 }, { } }; MODULE_DEVICE_TABLE(of, ave_of_match); diff --git a/drivers/media/platform/apple/ave/ave-fw.c b/drivers/media/platform/apple/ave/ave-fw.c index 9b4d3c3f67662..fb7563252ab8c 100644 --- a/drivers/media/platform/apple/ave/ave-fw.c +++ b/drivers/media/platform/apple/ave/ave-fw.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -60,6 +61,12 @@ static int ave_fw_segment(struct ave_dev *ave, unsigned int index, np = of_parse_phandle(ave->dev->of_node, "memory-region", index); if (!np) return -ENOENT; + if (!of_node_name_eq(np->parent, "reserved-memory") || + !of_device_is_compatible(np, "apple,asc-mem") || + !of_property_read_bool(np, "no-map")) { + ret = -EINVAL; + goto out; + } ret = of_address_to_resource(np, 0, &res); if (ret) goto out; @@ -74,7 +81,9 @@ static int ave_fw_segment(struct ave_dev *ave, unsigned int index, seg->phys = res.start; seg->size = resource_size(&res); seg->iova = of_read_number(prop + 1, 2); - if (of_read_number(prop + 3, 2) != seg->size || + if (!seg->size || seg->phys > PHYS_ADDR_MAX - seg->size || + seg->iova > U64_MAX - seg->size || + of_read_number(prop + 3, 2) != seg->size || !IS_ALIGNED(seg->phys, SZ_16K) || !IS_ALIGNED(seg->iova, SZ_16K)) ret = -EINVAL; out: @@ -90,18 +99,17 @@ static int ave_fw_check_mapping(struct ave_dev *ave, const struct ave_fw_segment return 0; } -static u32 ave_fw_crc(const struct ave_fw_segment *seg, void **copy) +static int ave_fw_crc(const struct ave_fw_segment *seg, u32 *crc, void *copy) { void *va = memremap(seg->phys, seg->size, MEMREMAP_WB); - u32 crc; if (!va) - return 0; - crc = crc32_le(~0U, va, seg->size) ^ ~0U; + return -ENOMEM; + *crc = crc32_le(~0U, va, seg->size) ^ ~0U; if (copy) - memcpy(*copy, va, seg->size); + memcpy(copy, va, seg->size); memunmap(va); - return crc; + return 0; } /* @@ -112,7 +120,7 @@ int ave_fw_probe(struct ave_dev *ave) { struct device *dev = ave->dev; u32 text_crc, data_crc, want; - bool known = false; + bool known = !ave->variant->encoding_text_crc; int ret; if (of_count_phandle_with_args(dev->of_node, "memory-region", NULL) != 2) @@ -124,10 +132,24 @@ int ave_fw_probe(struct ave_dev *ave) if (ret) return dev_err_probe(dev, ret, "bad firmware reservation\n"); + if (ave->text.size != ave->variant->fw_text_size || + ave->data.size != ave->variant->fw_data_size) + return dev_err_probe(dev, -EINVAL, "unexpected firmware segment sizes\n"); + if ((ave->text.phys < ave->data.phys + ave->data.size && + ave->data.phys < ave->text.phys + ave->text.size) || + (ave->text.iova < ave->data.iova + ave->data.size && + ave->data.iova < ave->text.iova + ave->text.size)) + return dev_err_probe(dev, -EINVAL, "overlapping firmware segments\n"); + if (ave_fw_check_mapping(ave, &ave->text) || ave_fw_check_mapping(ave, &ave->data)) return dev_err_probe(dev, -EIO, "firmware is not mapped where it was loaded\n"); - text_crc = ave_fw_crc(&ave->text, NULL); + ret = ave_fw_crc(&ave->text, &text_crc, NULL); + if (ret) + return ret; + ret = ave_fw_chosen_crc(ave, "aurora,ave-text-crc32", &want); + if (ret || text_crc != want) + return dev_err_probe(dev, -ENODEV, "firmware text differs from loader CRC\n"); for (unsigned int i = 0; i < ARRAY_SIZE(ave_known_text_crc); i++) known |= text_crc == ave_known_text_crc[i]; if (!known) @@ -138,7 +160,9 @@ int ave_fw_probe(struct ave_dev *ave) ave->data_pristine = vmalloc(ave->data.size); if (!ave->data_pristine) return -ENOMEM; - data_crc = ave_fw_crc(&ave->data, &ave->data_pristine); + ret = ave_fw_crc(&ave->data, &data_crc, ave->data_pristine); + if (ret) + goto free_data; /* * The loader records the DATA checksum before anything runs. If it @@ -146,14 +170,21 @@ int ave_fw_probe(struct ave_dev *ave) */ ret = ave_fw_chosen_crc(ave, "aurora,ave-data-crc32", &want); if (ret || data_crc != want) { - vfree(ave->data_pristine); - ave->data_pristine = NULL; - return dev_err_probe(dev, -ENODEV, - "firmware data is not in its boot state\n"); + ret = dev_err_probe(dev, -ENODEV, "firmware data is not in its boot state\n"); + goto free_data; } + ave->data_crc = data_crc; ave->fw_state = AVE_FW_OFF; + if (!ave->variant->encoding_text_crc) + dev_info(dev, "probe only: device type %u firmware TEXT %08x DATA %08x needs qualification\n", + ave->variant->device_type, text_crc, data_crc); return 0; + +free_data: + vfree(ave->data_pristine); + ave->data_pristine = NULL; + return ret; } static void ave_fw_restore_data(struct ave_dev *ave) @@ -212,10 +243,11 @@ int ave_alloc(struct ave_dev *ave, struct ave_buf *b, size_t size, unsigned long */ int ave_fw_check_build(struct ave_dev *ave) { - if (ave->text_crc == AVE_FW_TEXT_CRC_9003_78_0) + if (ave->variant->encoding_text_crc && + ave->text_crc == ave->variant->encoding_text_crc) return 0; - dev_err(ave->dev, "encoder firmware %08x is not validated for encoding (only %08x is)\n", - ave->text_crc, AVE_FW_TEXT_CRC_9003_78_0); + dev_info(ave->dev, "encoding refused: device type %u firmware TEXT %08x DATA %08x has no qualified command constants/MCC DSID\n", + ave->variant->device_type, ave->text_crc, ave->data_crc); return -ENOTSUPP; } @@ -231,9 +263,10 @@ void ave_fw_remove(struct ave_dev *ave) static bool ave_fw_idle(struct ave_dev *ave) { - if (readq(ave->coproc + AVE_COPROC_VCBAR) != (ave->text.iova | AVE_COPROC_VCBAR_VALID)) + if (readq(ave->coproc + ave->variant->regs->vcbar) != + (ave->text.iova | AVE_COPROC_VCBAR_VALID)) return false; - if (readl(ave->coproc + AVE_COPROC_CTRL) || readl(ave->mbox + AVE_MBOX_STATUS)) + if (readl(ave->coproc + ave->variant->regs->ctrl) || readl(ave->mbox + AVE_MBOX_STATUS)) return false; for (unsigned int i = 0; i < AVE_MBOX_SCRATCH_COUNT; i++) if (readl(ave->mbox + AVE_MBOX_SCRATCH(i))) @@ -253,15 +286,16 @@ static int ave_fw_prepare_restart(struct ave_dev *ave) { u32 status; - if (readq(ave->coproc + AVE_COPROC_VCBAR) != (ave->text.iova | AVE_COPROC_VCBAR_VALID)) { + if (readq(ave->coproc + ave->variant->regs->vcbar) != + (ave->text.iova | AVE_COPROC_VCBAR_VALID)) { dev_err(ave->dev, "coprocessor lost its code base (vcbar %#llx)\n", - readq(ave->coproc + AVE_COPROC_VCBAR)); + readq(ave->coproc + ave->variant->regs->vcbar)); return -EIO; } if (ave->fw_state != AVE_FW_HALTED) return 0; - if (readl(ave->coproc + AVE_COPROC_CTRL)) { + if (readl(ave->coproc + ave->variant->regs->ctrl)) { dev_dbg(ave->dev, "coprocessor kept power after its halt; retry once it suspends\n"); return -EAGAIN; } @@ -303,8 +337,8 @@ static int ave_fw_boot(struct ave_dev *ave) */ if (!ave_fw_idle(ave)) { dev_err(ave->dev, "coprocessor is not in its reset state (vcbar %#llx ctrl %#x)\n", - readq(ave->coproc + AVE_COPROC_VCBAR), - readl(ave->coproc + AVE_COPROC_CTRL)); + readq(ave->coproc + ave->variant->regs->vcbar), + readl(ave->coproc + ave->variant->regs->ctrl)); return -EIO; } @@ -320,7 +354,7 @@ static int ave_fw_boot(struct ave_dev *ave) log = ave->log.cpu; memset(cfg, 0, AVE_BOOT_CFG_BYTES); memset(log, 0, ave->log.size); - cfg[AVE_BOOT_CFG_DEVICE] = cpu_to_le32(AVE_BOOT_CFG_DEVICE_T8140); + cfg[AVE_BOOT_CFG_DEVICE] = cpu_to_le32(ave->variant->boot_device_id); cfg[AVE_BOOT_CFG_UNITS] = cpu_to_le32(1); cfg[AVE_BOOT_CFG_GROUPS] = cpu_to_le32(1); cfg[AVE_BOOT_CFG_SUBID_MASK] = cpu_to_le32(1); @@ -338,16 +372,16 @@ static int ave_fw_boot(struct ave_dev *ave) writel(upper_32_bits(ave->boot_cfg.dma), ave->mbox + AVE_MBOX_SCRATCH(2)); ave->data_dirty = true; - writel(1, ave->coproc + AVE_COPROC_KEEP_MAPPINGS); - writel(0, ave->coproc + AVE_COPROC_CTRL); - writel(AVE_COPROC_BOOT_ARG_VALUE, ave->coproc + AVE_COPROC_BOOT_ARG); - writel(AVE_COPROC_CTRL_RUN, ave->coproc + AVE_COPROC_CTRL); + writel(1, ave->coproc + ave->variant->regs->keep_mappings); + writel(0, ave->coproc + ave->variant->regs->ctrl); + writel(AVE_COPROC_BOOT_ARG_VALUE, ave->coproc + ave->variant->regs->boot_arg); + writel(AVE_COPROC_CTRL_RUN, ave->coproc + ave->variant->regs->ctrl); ret = readl_poll_timeout(ave->mbox + AVE_MBOX_STATUS, status, status & AVE_MBOX_STATUS_PENDING, 50, AVE_MBOX_TIMEOUT_US); if (ret) { dev_err(ave->dev, "firmware did not answer (status %#x)\n", - readl(ave->coproc + AVE_COPROC_STATUS)); + readl(ave->coproc + ave->variant->regs->status)); return ret; } for (unsigned int i = 0; i < 4; i++) @@ -377,6 +411,9 @@ int ave_fw_ensure_running(struct ave_dev *ave) int ret; lockdep_assert_held(&ave->hw_lock); + ret = ave_fw_check_build(ave); + if (ret) + return ret; switch (ave->fw_state) { case AVE_FW_RUNNING: return 0; @@ -396,7 +433,8 @@ int ave_fw_ensure_running(struct ave_dev *ave) prev = ave->fw_state; ret = ave_fw_boot(ave); if (ret) { - ave->fw_state = readl(ave->coproc + AVE_COPROC_CTRL) ? AVE_FW_HALTED : prev; + ave->fw_state = readl(ave->coproc + ave->variant->regs->ctrl) ? + AVE_FW_HALTED : prev; memset(ave->ring, 0, sizeof(ave->ring)); ave->ipc_fw_base = 0; } diff --git a/drivers/media/platform/apple/ave/ave-ipc.c b/drivers/media/platform/apple/ave/ave-ipc.c index 974f3b2e8cc90..c197671debbbe 100644 --- a/drivers/media/platform/apple/ave/ave-ipc.c +++ b/drivers/media/platform/apple/ave/ave-ipc.c @@ -157,8 +157,8 @@ int ave_ipc_negotiate(struct ave_dev *ave, const u32 hello[4]) writel(AVE_MBOX_STATUS_PENDING, ave->mbox + AVE_MBOX_STATUS); /* Tell the firmware how far its timebase is from the host's. */ - ticks = readq(ave->coproc + AVE_COPROC_TIMEBASE); - freq = readl(ave->coproc + AVE_COPROC_TIMEBASE_FREQ); + ticks = readq(ave->coproc + ave->variant->regs->timebase); + freq = readl(ave->coproc + ave->variant->regs->timebase_freq); if (freq && freq < 1000000) return -EPROTO; ticks = div64_u64(ticks, freq ? freq / 1000000 : 24); @@ -184,7 +184,7 @@ int ave_ipc_negotiate(struct ave_dev *ave, const u32 hello[4]) put_unaligned_le32(AVE_IPC_SHARED_BYTES, hs + AVE_HS_SHARED_BYTES); put_unaligned_le64(ave->heap.dma, hs + AVE_HS_HEAP); put_unaligned_le32(hello[3], hs + AVE_HS_HEAP_BYTES); - put_unaligned_le32(AVE_HS_MAGIC_VALUE, hs + AVE_HS_MAGIC); + put_unaligned_le32(ave->variant->device_type, hs + AVE_HS_DEVICE_TYPE); dma_wmb(); ave_mbox_send(ave, lower_32_bits(ave->ipc_fw_base + AVE_IPC_HANDSHAKE_OFF), diff --git a/drivers/media/platform/apple/ave/ave-regs.h b/drivers/media/platform/apple/ave/ave-regs.h index a85fde26278a6..4b625ad3b70d9 100644 --- a/drivers/media/platform/apple/ave/ave-regs.h +++ b/drivers/media/platform/apple/ave/ave-regs.h @@ -36,7 +36,6 @@ #define AVE_BOOT_MAGIC 0x08042006 #define AVE_BOOT_CFG_BYTES 0x40 #define AVE_BOOT_CFG_DEVICE 1 /* word index */ -#define AVE_BOOT_CFG_DEVICE_T8140 29 #define AVE_BOOT_CFG_UNITS 2 #define AVE_BOOT_CFG_GROUPS 3 #define AVE_BOOT_CFG_SUBID_MASK 4 @@ -64,8 +63,7 @@ #define AVE_HS_SHARED_BYTES 0x18 #define AVE_HS_HEAP 0x1c #define AVE_HS_HEAP_BYTES 0x24 -#define AVE_HS_MAGIC 0x28 -#define AVE_HS_MAGIC_VALUE 27 +#define AVE_HS_DEVICE_TYPE 0x28 /* Channel descriptors the firmware writes into the channel area */ #define AVE_CHAN_DESC_STRIDE 0x100 diff --git a/drivers/media/platform/apple/ave/ave-sess.c b/drivers/media/platform/apple/ave/ave-sess.c index e58d485eb61c1..c97681d7fb840 100644 --- a/drivers/media/platform/apple/ave/ave-sess.c +++ b/drivers/media/platform/apple/ave/ave-sess.c @@ -232,7 +232,7 @@ static int ave_sess_alloc(struct ave_dev *ave, struct ave_session *sess) bool hevc = p->codec == AVE_CODEC_HEVC; u32 w = p->width, h = p->height; u32 w16 = DIV_ROUND_UP(w, 16), w32 = DIV_ROUND_UP(w, 32); - u32 h32 = DIV_ROUND_UP(h, 32), w64 = DIV_ROUND_UP(w, 64), h64 = DIV_ROUND_UP(h, 64); + u32 h32 = DIV_ROUND_UP(h, 32), h64 = DIV_ROUND_UP(h, 64); const unsigned long nomap = DMA_ATTR_NO_KERNEL_MAPPING; size_t ref_a, ref_b, ref_c, ref_d, tile, mapped = 0; struct ave_buf_req *r; @@ -245,7 +245,7 @@ static int ave_sess_alloc(struct ave_dev *ave, struct ave_session *sess) ref_a = ALIGN(w, 32) * ALIGN(h + 16, 32); ref_b = roundup_pow_of_two(w) * roundup_pow_of_two(h) / 32; - ref_c = hevc ? 512 * w64 * h64 : ALIGN(w, 64) * (ALIGN(h, 16) / 2 + 24); + ref_c = ave_lfs_ref_size(w, h, hevc, ave->variant->lfs_ref_scale); ref_d = ALIGN(hevc ? 64 * w32 * h32 : 128 * p->mbs, SZ_16K); tile = hevc ? 2304 * w32 * h64 : ALIGN(w, 16) * ALIGN(h, 64); diff --git a/drivers/media/platform/apple/ave/ave-sizes-test.c b/drivers/media/platform/apple/ave/ave-sizes-test.c new file mode 100644 index 0000000000000..72e92f67b2d5e --- /dev/null +++ b/drivers/media/platform/apple/ave/ave-sizes-test.c @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Apple AVE LFS reference descriptor sizes, not DMA allocation sizes. */ +#include +#include + +#include "ave-sizes.h" + +struct ave_size_case { + u32 width; + u32 height; + u32 avc; + u32 hevc; + u32 avc_t8140; + u32 hevc_t8140; +}; + +static const struct ave_size_case ave_size_cases[] = { + { 320, 240, 0x5a00, 0x1400, 0xb400, 0x2800 }, + { 640, 480, 0x14a00, 0x5000, 0x29400, 0xa000 }, + { 642, 482, 0x17600, 0x5800, 0x2ec00, 0xb000 }, + { 1280, 720, 0x3c000, 0xf000, 0x78000, 0x1e000 }, + { 1920, 1080, 0x85200, 0x1fe00, 0x10a400, 0x3fc00 }, + { 1920, 1088, 0x85200, 0x1fe00, 0x10a400, 0x3fc00 }, + { 1922, 1090, 0x8b800, 0x22e00, 0x117000, 0x45c00 }, + { 2560, 1600, 0x101800, 0x3e800, 0x203000, 0x7d000 }, +}; + +static void ave_size_desc(const struct ave_size_case *c, char *desc) +{ + snprintf(desc, KUNIT_PARAM_DESC_SIZE, "%ux%u", c->width, c->height); +} + +KUNIT_ARRAY_PARAM(ave_size, ave_size_cases, ave_size_desc); + +static void ave_lfs_ref_test(struct kunit *test) +{ + const struct ave_size_case *c = test->param_value; + + /* T6000 and T8112 both select scale 1; T8140 selects scale 2. */ + KUNIT_EXPECT_EQ(test, ave_lfs_ref_size(c->width, c->height, false, 1), c->avc); + KUNIT_EXPECT_EQ(test, ave_lfs_ref_size(c->width, c->height, true, 1), c->hevc); + KUNIT_EXPECT_EQ(test, ave_lfs_ref_size(c->width, c->height, false, 2), c->avc_t8140); + KUNIT_EXPECT_EQ(test, ave_lfs_ref_size(c->width, c->height, true, 2), c->hevc_t8140); +} + +static struct kunit_case ave_sizes_tests[] = { + KUNIT_CASE_PARAM(ave_lfs_ref_test, ave_size_gen_params), + { } +}; + +static struct kunit_suite ave_sizes_suite = { + .name = "apple-ave-sizes", + .test_cases = ave_sizes_tests, +}; + +kunit_test_suite(ave_sizes_suite); + +MODULE_DESCRIPTION("Apple AVE buffer sizing tests"); +MODULE_LICENSE("GPL"); diff --git a/drivers/media/platform/apple/ave/ave-sizes.h b/drivers/media/platform/apple/ave/ave-sizes.h new file mode 100644 index 0000000000000..01e29678035b5 --- /dev/null +++ b/drivers/media/platform/apple/ave/ave-sizes.h @@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _APPLE_AVE_SIZES_H_ +#define _APPLE_AVE_SIZES_H_ + +#include +#include +#include + +/* Start +0x7d0 LFSRef: exact descriptor bytes, before DMA page rounding. */ +static inline u32 ave_lfs_ref_size(u32 width, u32 height, bool hevc, u32 scale) +{ + u32 size; + + if (hevc) + size = 256 * DIV_ROUND_UP(width, 64) * DIV_ROUND_UP(height, 64); + else + size = ALIGN(width, 64) * (ALIGN(height, 16) / 4 + 12); + return size * scale; +} + +#endif diff --git a/drivers/media/platform/apple/ave/ave.h b/drivers/media/platform/apple/ave/ave.h index 0f6e2b38d86ca..c0c150f7fab42 100644 --- a/drivers/media/platform/apple/ave/ave.h +++ b/drivers/media/platform/apple/ave/ave.h @@ -19,6 +19,8 @@ #include #include +#include "ave-sizes.h" + struct debugfs_blob_wrapper; struct dentry; struct dev_pm_domain_list; @@ -111,8 +113,31 @@ enum ave_image { struct ave_ctx; +/* Register offsets for the shared 0x40 coprocessor architecture. */ +struct ave_coproc_regs { + u32 vcbar; + u32 timebase_freq; + u32 timebase; + u32 ctrl; + u32 status; + u32 boot_arg; + u32 keep_mappings; +}; + +struct ave_variant { + const struct ave_coproc_regs *regs; + u32 fw_text_size; + u32 fw_data_size; + u32 boot_device_id; + u32 device_type; + u32 lfs_ref_scale; + /* Zero means no command constants or MCC DSID have been qualified. */ + u32 encoding_text_crc; +}; + struct ave_dev { struct device *dev; + const struct ave_variant *variant; void __iomem *codec; void __iomem *mbox; void __iomem *coproc; @@ -122,6 +147,7 @@ struct ave_dev { struct ave_fw_segment text; struct ave_fw_segment data; u32 text_crc; + u32 data_crc; void *data_pristine; bool data_dirty; From 38fc158c628c60ac4400f7dc543287c9ad50529f Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 31 Oct 2026 04:16:54 +1100 Subject: [PATCH 3/3] arm64: dts: apple: describe disabled T6000 and T8112 AVE blocks Describe the codec, mailbox and coprocessor windows, all five AVE IRQs and both SID 0 DARTs from the ADT facts. Use the existing VENC power domains and preserve the 0x8000 pre-M4 mailbox windows. Leave the encoder and both DARTs disabled pending loader handoff and owner qualification. Do not guess the DMA aperture or add an RTKit endpoint. Assisted-by: LLM Signed-off-by: Ryan Murray --- arch/arm64/boot/dts/apple/t600x-die0.dtsi | 39 +++++++++++++++++++++++ arch/arm64/boot/dts/apple/t8112.dtsi | 39 +++++++++++++++++++++++ 2 files changed, 78 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t600x-die0.dtsi b/arch/arm64/boot/dts/apple/t600x-die0.dtsi index 2cbe84a3d5625..8357258058339 100644 --- a/arch/arm64/boot/dts/apple/t600x-die0.dtsi +++ b/arch/arm64/boot/dts/apple/t600x-die0.dtsi @@ -8,6 +8,45 @@ &SOC_NODE { + ave_dart1: iommu@20d030000 { + compatible = "apple,t6000-dart"; + reg = <0x2 0x0d030000 0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&ps_venc_sys>; + #iommu-cells = <1>; + status = "disabled"; + }; + + ave_dart0: iommu@20d040000 { + compatible = "apple,t6000-dart"; + reg = <0x2 0x0d040000 0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&ps_venc_sys>; + #iommu-cells = <1>; + status = "disabled"; + }; + + ave: video-codec@20d100000 { + compatible = "apple,t6000-ave"; + reg = <0x2 0x0d100000 0 0x45c000>, + <0x2 0x0d050000 0 0x8000>, + <0x2 0x0d800000 0 0x800000>; + reg-names = "codec", "mailbox", "coproc"; + interrupt-parent = <&aic>; + interrupts = , + , + , + , + ; + power-domains = <&ps_venc_dma>, <&ps_venc_pipe4>, + <&ps_venc_pipe5>, <&ps_venc_me0>, <&ps_venc_me1>; + power-domain-names = "dma", "pipe4", "pipe5", "me0", "me1"; + iommus = <&ave_dart0 0>, <&ave_dart1 0>; + status = "disabled"; + }; + ane_dart0: iommu@285800000 { compatible = "apple,t6000-dart"; reg = <0x2 0x85800000 0x0 0x4000>; diff --git a/arch/arm64/boot/dts/apple/t8112.dtsi b/arch/arm64/boot/dts/apple/t8112.dtsi index 90f9311d4aede..d7a4246482355 100644 --- a/arch/arm64/boot/dts/apple/t8112.dtsi +++ b/arch/arm64/boot/dts/apple/t8112.dtsi @@ -505,6 +505,45 @@ /* Required to get >32-bit DMA via DARTs */ dma-ranges = <0 0 0 0 0xffffffff 0xffffc000>; + ave_dart0: iommu@67030000 { + compatible = "apple,t8112-dart", "apple,t8110-dart"; + reg = <0 0x67030000 0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&ps_venc_sys>; + #iommu-cells = <1>; + status = "disabled"; + }; + + ave_dart1: iommu@67040000 { + compatible = "apple,t8112-dart", "apple,t8110-dart"; + reg = <0 0x67040000 0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&ps_venc_sys>; + #iommu-cells = <1>; + status = "disabled"; + }; + + ave: video-codec@67100000 { + compatible = "apple,t8112-ave"; + reg = <0 0x67100000 0 0x45c000>, + <0 0x67050000 0 0x8000>, + <0 0x67800000 0 0x800000>; + reg-names = "codec", "mailbox", "coproc"; + interrupt-parent = <&aic>; + interrupts = , + , + , + , + ; + power-domains = <&ps_venc_dma>, <&ps_venc_pipe4>, + <&ps_venc_pipe5>, <&ps_venc_me0>, <&ps_venc_me1>; + power-domain-names = "dma", "pipe4", "pipe5", "me0", "me1"; + iommus = <&ave_dart0 0>, <&ave_dart1 0>; + status = "disabled"; + }; + gpu: gpu@206400000 { compatible = "apple,agx-t8112", "apple,agx-g14g"; reg = <0x2 0x6400000 0 0x40000>,