Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions drivers/media/platform/apple/ave/ave-abi-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down
43 changes: 25 additions & 18 deletions drivers/media/platform/apple/ave/ave-drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,21 @@ 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,
.vcbar_mask = GENMASK_ULL(41, 11),
.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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -174,19 +180,21 @@ 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,
.vcbar_mask = U64_MAX,
.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,
};

Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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,
};
Expand Down
20 changes: 9 additions & 11 deletions drivers/media/platform/apple/ave/ave-fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}

/*
Expand Down Expand Up @@ -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");
Expand Down
25 changes: 12 additions & 13 deletions drivers/media/platform/apple/ave/ave.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Loading