From b8b4948c6035a3b75cc59fcbf6a77ecf27f5aba3 Mon Sep 17 00:00:00 2001 From: Jeff Queisser Date: Sun, 22 Nov 2026 15:00:11 -0800 Subject: [PATCH] media: apple: ave: admit the J775D's encoder by its build's per-boot word On the Mac Studio (J775D) the encoder's TEXT CRC differs on every boot, so probe refuses it as "unsupported firmware". The firmware is the 26A428 build the T6050 variant already admits: with the build's per-boot word zeroed, the probe's TEXT CRC matches the admitted 26A428 CRC on every J775D boot tested. The T6041, T8132 and T8112 26B123 variants already handle the same word, with a text_boot_word on the variant: a TEXT CRC that is not a known build is retried with that word zeroed. The word belongs to a firmware build, though, not to a chip. On T6050 a variant-wide offset would also apply to the 26C5035 build, whose TEXT is 0x4000 larger and which has not been checked for such a word. So move text_boot_word into struct ave_fw_build and set it on the builds that have it: 26A428 on T6050, and the builds T6041, T8132 and T8112 26B123 already retried. 26C5035 keeps exact matching. Those variants now list their builds (sizes, CRC and word) instead of variant-wide sizes, which also replaces T6041's second DATA size, fw_data_size_alt, with its second build. A known CRC is still taken as it is. The KUnit cases that pin the offsets check them per build, including that 26C5035 has none. On the J775D this takes effect together with aurora-silicon/linux#2278, which enables that board's encoder node; without it the encoder is not probed there. Tested on a J775D (Mac Studio, M5 Ultra). Signed-off-by: Jeff Queisser --- .../media/platform/apple/ave/ave-abi-test.c | 32 ++++++++++---- drivers/media/platform/apple/ave/ave-drv.c | 43 +++++++++++-------- drivers/media/platform/apple/ave/ave-fw.c | 20 ++++----- drivers/media/platform/apple/ave/ave.h | 25 ++++++----- 4 files changed, 70 insertions(+), 50 deletions(-) diff --git a/drivers/media/platform/apple/ave/ave-abi-test.c b/drivers/media/platform/apple/ave/ave-abi-test.c index 72b7d969169c3..87859a739a8cf 100644 --- a/drivers/media/platform/apple/ave/ave-abi-test.c +++ b/drivers/media/platform/apple/ave/ave-abi-test.c @@ -1533,16 +1533,17 @@ static void ave_t8112_26b123_build(struct kunit *test) KUNIT_EXPECT_TRUE(test, n->restore_data_first); KUNIT_EXPECT_EQ(test, n->text_link_cell, 0U); /* The Mac mini's loader sets the word at TEXT 0x4224 on every boot. */ - KUNIT_EXPECT_EQ(test, n->text_boot_word, 0x4224U); + KUNIT_ASSERT_EQ(test, n->build_count, 1U); + KUNIT_EXPECT_EQ(test, n->builds[0].text_boot_word, 0x4224U); /* The 27.2 builds' reference buffer sizing, as on the M3 and M4. */ KUNIT_EXPECT_EQ(test, n->lfs_ref_scale, 2U); KUNIT_EXPECT_EQ(test, ave_t8112.lfs_ref_scale, 1U); KUNIT_EXPECT_EQ(test, n->extra0_size, 0U); KUNIT_EXPECT_EQ(test, n->vcbar_flags, (u64)AVE_COPROC_VCBAR_VALID); KUNIT_EXPECT_EQ(test, ave_fw_vcbar(n, 0x800000000ULL), 0x800000001ULL); - KUNIT_EXPECT_EQ(test, n->text_crc, AVE_FW_TEXT_CRC_T8112_26B123); + KUNIT_EXPECT_EQ(test, n->builds[0].text_crc, AVE_FW_TEXT_CRC_T8112_26B123); { - const u32 off = n->text_boot_word, size = off + 0x40; + const u32 off = n->builds[0].text_boot_word, size = off + 0x40; u8 *text = kunit_kzalloc(test, size, GFP_KERNEL); u32 zeroed, a, b; @@ -1556,25 +1557,40 @@ static void ave_t8112_26b123_build(struct kunit *test) KUNIT_EXPECT_EQ(test, a, zeroed); KUNIT_EXPECT_EQ(test, b, zeroed); } - KUNIT_EXPECT_PTR_EQ(test, ave_layout_for_crc(n->text_crc), &ave_layout_26b123); + KUNIT_EXPECT_PTR_EQ(test, ave_layout_for_crc(n->builds[0].text_crc), &ave_layout_26b123); KUNIT_EXPECT_PTR_EQ(test, ave_layout_for_crc(ave_t8112.text_crc), &ave_layout_6070_11_1); } static void ave_t6041_text_boot_word(struct kunit *test) { - const u32 off = ave_t6041.text_boot_word, size = off + 0x100; + const struct ave_fw_build *m4 = ave_t6041.builds; + const u32 off = m4[0].text_boot_word, size = off + 0x100; u8 *text = kunit_kzalloc(test, size, GFP_KERNEL); u32 image, a, b; KUNIT_ASSERT_NOT_NULL(test, text); KUNIT_EXPECT_EQ(test, off, 0x4224U); - KUNIT_EXPECT_EQ(test, ave_t6041.fw_data_size_alt, 0x130000U); + /* The M4 Pro and M4 Max builds: the same word, the Max with a larger DATA. */ + KUNIT_ASSERT_EQ(test, ave_t6041.build_count, 2U); + KUNIT_EXPECT_EQ(test, m4[1].data_size, 0x130000U); + KUNIT_EXPECT_EQ(test, m4[1].text_boot_word, off); KUNIT_EXPECT_EQ(test, ave_t6041.text_link_cell, 0U); /* The M4 27.2 build: the same word, set per boot by some loaders. */ - KUNIT_EXPECT_EQ(test, ave_t8132.text_boot_word, off); - KUNIT_EXPECT_EQ(test, ave_t8132.text_crc, AVE_FW_TEXT_CRC_T8132_26B123); + KUNIT_ASSERT_EQ(test, ave_t8132.build_count, 1U); + KUNIT_EXPECT_EQ(test, ave_t8132.builds[0].text_boot_word, off); + KUNIT_EXPECT_EQ(test, ave_t8132.builds[0].text_crc, AVE_FW_TEXT_CRC_T8132_26B123); KUNIT_EXPECT_EQ(test, ave_t8132.text_link_cell, 0U); + /* + * The M5 Pro/Max 26A428 build: the same word, which differs per boot on + * the J775D. The 26C5035 build has none set: its CRC matches as it is. + */ + KUNIT_ASSERT_EQ(test, ave_t6050.build_count, 2U); + KUNIT_EXPECT_EQ(test, ave_t6050.builds[0].text_boot_word, off); + KUNIT_EXPECT_EQ(test, ave_t6050.builds[0].text_crc, AVE_FW_TEXT_CRC_T6050_26A428); + KUNIT_EXPECT_EQ(test, ave_t6050.builds[1].text_boot_word, 0U); + KUNIT_EXPECT_EQ(test, ave_t6050.builds[1].text_crc, AVE_FW_TEXT_CRC_T6050_26C5035); + KUNIT_EXPECT_EQ(test, ave_t6050.text_link_cell, 0U); for (u32 i = 0; i < size; i++) text[i] = i * 7 + 3; memset(text + off, 0, 4); diff --git a/drivers/media/platform/apple/ave/ave-drv.c b/drivers/media/platform/apple/ave/ave-drv.c index a5897fe998f6c..bd3568d34deae 100644 --- a/drivers/media/platform/apple/ave/ave-drv.c +++ b/drivers/media/platform/apple/ave/ave-drv.c @@ -79,10 +79,14 @@ const struct ave_variant ave_t6000 = { * the bootloader's code base (marked valid) left as it is, and DATA restored * from the boot snapshot before every start. */ +static const struct ave_fw_build ave_t8112_26b123_builds[] = { + { "26B123", 0x11c000, 0x128000, AVE_FW_TEXT_CRC_T8112_26B123, 0x4224 }, +}; + static const struct ave_variant ave_t8112_26b123 = { .regs = &ave_coproc_6070, - .fw_text_size = 0x11c000, - .fw_data_size = 0x128000, + .builds = ave_t8112_26b123_builds, + .build_count = ARRAY_SIZE(ave_t8112_26b123_builds), .boot_device_id = 12, .boot_arg_value = AVE_COPROC_BOOT_ARG_VALUE, .timebase_multiplier = 1, @@ -90,8 +94,6 @@ static const struct ave_variant ave_t8112_26b123 = { .vcbar_flags = AVE_COPROC_VCBAR_VALID, .device_type = 12, .lfs_ref_scale = 2, - .text_crc = AVE_FW_TEXT_CRC_T8112_26B123, - .text_boot_word = 0x4224, .mbox_idle = 0x38, .restore_data_first = true, .boot_qualified = true, @@ -123,12 +125,16 @@ const struct ave_variant ave_t8112 = { * with soc-id t6040, the same way; iBoot 25G83 preloads it with a 0x130000 * DATA and sets a word at TEXT 0x4224 differently on every boot. */ +static const struct ave_fw_build ave_t6041_builds[] = { + { "25G83", 0x14c000, 0x12c000, 0, 0x4224 }, + /* The M4 Max's first encoder */ + { "25G83", 0x14c000, 0x130000, 0, 0x4224 }, +}; + const struct ave_variant ave_t6041 = { .regs = &ave_coproc_v40, - .fw_text_size = 0x14c000, - .fw_data_size = 0x12c000, - .fw_data_size_alt = 0x130000, - .text_boot_word = 0x4224, + .builds = ave_t6041_builds, + .build_count = ARRAY_SIZE(ave_t6041_builds), .boot_device_id = 27, .boot_arg_value = AVE_COPROC_BOOT_ARG_VALUE, .timebase_multiplier = 1, @@ -174,10 +180,14 @@ static const struct ave_variant ave_t8122 = { * unknown CRC is retried with it zeroed. The coprocessor and its start are * the M4 Pro's; this build boots as device 23 and takes handshake type 23. */ +static const struct ave_fw_build ave_t8132_builds[] = { + { "26B123", 0x154000, 0x12c000, AVE_FW_TEXT_CRC_T8132_26B123, 0x4224 }, +}; + const struct ave_variant ave_t8132 = { .regs = &ave_coproc_v40, - .fw_text_size = 0x154000, - .fw_data_size = 0x12c000, + .builds = ave_t8132_builds, + .build_count = ARRAY_SIZE(ave_t8132_builds), .boot_device_id = 23, .boot_arg_value = AVE_COPROC_BOOT_ARG_VALUE, .timebase_multiplier = 1, @@ -185,8 +195,6 @@ const struct ave_variant ave_t8132 = { .vcbar_flags = AVE_COPROC_VCBAR_VALID, .device_type = 23, .lfs_ref_scale = 2, - .text_crc = AVE_FW_TEXT_CRC_T8132_26B123, - .text_boot_word = 0x4224, .boot_qualified = true, }; @@ -209,10 +217,12 @@ static const struct ave_variant ave_t8140 = { * 0x154000 and DATA 0x134000 (ADT ave0 segment-ranges). macOS starts the coprocessor as on the * A18 Pro, after clearing the SVE idle word at mailbox +0x118. Its boot configuration names * device 28, and so does its handshake's device type. The macOS 27.3 beta 1 build is admitted - * beside it. + * beside it. As on the M4 Max, the 26A428 build's TEXT word at 0x4224 differs on every boot + * (the Mac Studio, J775D), so an unknown TEXT CRC of that build is retried with the word zeroed. + * The 26C5035 build has not been checked for such a word, so its CRC must match as it is. */ static const struct ave_fw_build ave_t6050_builds[] = { - { "26A428", 0x154000, 0x134000, AVE_FW_TEXT_CRC_T6050_26A428 }, + { "26A428", 0x154000, 0x134000, AVE_FW_TEXT_CRC_T6050_26A428, 0x4224 }, /* * macOS 27.3 beta 1 (iBoot 20457.60.65): TEXT is 0x4000 larger, DATA * keeps its size. It starts as 26A428 does and takes 26A428's command @@ -221,10 +231,8 @@ static const struct ave_fw_build ave_t6050_builds[] = { { "26C5035", 0x158000, 0x134000, AVE_FW_TEXT_CRC_T6050_26C5035 }, }; -static const struct ave_variant ave_t6050 = { +const struct ave_variant ave_t6050 = { .regs = &ave_coproc_v40, - .fw_text_size = 0x154000, - .fw_data_size = 0x134000, .builds = ave_t6050_builds, .build_count = ARRAY_SIZE(ave_t6050_builds), .boot_device_id = 28, @@ -234,7 +242,6 @@ static const struct ave_variant ave_t6050 = { .vcbar_flags = AVE_COPROC_VCBAR_VALID, .device_type = 28, .lfs_ref_scale = 2, - .text_crc = AVE_FW_TEXT_CRC_T6050_26A428, .mbox_idle = 0x118, .boot_qualified = true, }; diff --git a/drivers/media/platform/apple/ave/ave-fw.c b/drivers/media/platform/apple/ave/ave-fw.c index 49f1da033411f..9522672040711 100644 --- a/drivers/media/platform/apple/ave/ave-fw.c +++ b/drivers/media/platform/apple/ave/ave-fw.c @@ -185,9 +185,9 @@ int ave_fw_text_boot_crc(const void *text, size_t size, u32 word_off, /* * A known TEXT CRC (the M4 Pro build) stays as it is; any other is retried - * with the per-boot word zeroed (the M4 Max and M4 27.2 builds). + * with the build's per-boot word at @word_off zeroed. */ -static int ave_fw_text_boot_id(struct ave_dev *ave, u32 *crc) +static int ave_fw_text_boot_id(struct ave_dev *ave, u32 word_off, u32 *crc) { void *va; int ret; @@ -197,20 +197,20 @@ static int ave_fw_text_boot_id(struct ave_dev *ave, u32 *crc) va = memremap(ave->text.phys, ave->text.size, MEMREMAP_WB); if (!va) return -ENOMEM; - ret = ave_fw_text_boot_crc(va, ave->text.size, - ave->variant->text_boot_word, crc); + ret = ave_fw_text_boot_crc(va, ave->text.size, word_off, crc); memunmap(va); return ret; } -static int ave_fw_text_id(struct ave_dev *ave, u32 *crc) +static int ave_fw_text_id(struct ave_dev *ave, const struct ave_fw_build *build, + u32 *crc) { void *va; int ret; if (!ave->variant->text_link_cell) - return ave->variant->text_boot_word ? - ave_fw_text_boot_id(ave, crc) : 0; + return build && build->text_boot_word ? + ave_fw_text_boot_id(ave, build->text_boot_word, crc) : 0; va = memremap(ave->text.phys, ave->text.size, MEMREMAP_WB); if (!va) return -ENOMEM; @@ -243,9 +243,7 @@ bool ave_fw_sizes_match(const struct ave_variant *v, size_t text, size_t data) { if (v->build_count) return ave_fw_find_build(v, text, data, 0); - return text == v->fw_text_size && - (data == v->fw_data_size || - (v->fw_data_size_alt && data == v->fw_data_size_alt)); + return text == v->fw_text_size && data == v->fw_data_size; } /* @@ -337,7 +335,7 @@ int ave_fw_probe(struct ave_dev *ave) if (ret || text_crc != want) return dev_err_probe(dev, -ENODEV, "firmware text differs from loader CRC\n"); - ret = ave_fw_text_id(ave, &text_crc); + ret = ave_fw_text_id(ave, build, &text_crc); if (ret) return dev_err_probe(dev, ret, "firmware text link cell is not the DATA address\n"); diff --git a/drivers/media/platform/apple/ave/ave.h b/drivers/media/platform/apple/ave/ave.h index a0bda7749166a..11504b4ba5f0c 100644 --- a/drivers/media/platform/apple/ave/ave.h +++ b/drivers/media/platform/apple/ave/ave.h @@ -213,15 +213,20 @@ struct ave_fw_build { const char *name; u32 text_size; u32 data_size; + /* 0: any build in the known list */ u32 text_crc; + /* + * TEXT offset of a 32-bit word this build's loader sets differently on + * every boot; a TEXT CRC that is not a known build is retried with it + * zeroed. 0 when there is none, and the CRC must match as it is. + */ + u32 text_boot_word; }; struct ave_variant { const struct ave_coproc_regs *regs; u32 fw_text_size; u32 fw_data_size; - /* A second DATA size the variant accepts (the M4 Max build), or 0 */ - u32 fw_data_size_alt; /* * When set, the builds the variant admits. They replace fw_text_size, * fw_data_size and text_crc: the segment sizes select the build, and @@ -242,12 +247,6 @@ struct ave_variant { * address; it is zero in the firmware image. 0 when there is none. */ u32 text_link_cell; - /* - * TEXT offset of a 32-bit word the loader sets differently on every - * boot; a TEXT CRC that is not a known build is retried with it zeroed. - * 0 when there is none. - */ - u32 text_boot_word; /* * Mailbox offset of the SVE idle (clock gating) word that must read 0 * before the firmware starts, or 0 when the variant has none. @@ -260,9 +259,9 @@ struct ave_variant { * bootloader preloads, with a start and command protocol of its own. * The firmware segment sizes the bootloader reserved select it. * NULL when there is none. Use builds[] when the builds differ only - * in TEXT CRC (and command layout) but start the same way; use - * next_build when a build needs other start fields (boot device, - * handshake type, boot word, DATA handling) and has sizes of its own. + * in TEXT CRC, boot word (and command layout) but start the same way; + * use next_build when a build needs other start fields (boot device, + * handshake type, DATA handling) and has sizes of its own. */ const struct ave_variant *next_build; @@ -577,8 +576,8 @@ static inline struct ave_ctx *ave_file_to_ctx(struct file *file) return container_of(file_to_v4l2_fh(file), struct ave_ctx, fh); } -extern const struct ave_variant ave_t6000, ave_t6041, ave_t8112, ave_t8132, - ave_m3; +extern const struct ave_variant ave_t6000, ave_t6041, ave_t6050, ave_t8112, + ave_t8132, ave_m3; /* ave-fw.c */ u64 ave_fw_vcbar(const struct ave_variant *variant, u64 text_iova);