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
9 changes: 8 additions & 1 deletion drivers/media/platform/apple/ave/ave-abi-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1502,7 +1502,8 @@ static void ave_26b123_layout(struct kunit *test)
/*
* The M2 with the 27.2 stub: the reserved segment sizes select the 27.2
* build's own start (device 12, handshake type 12) and the 26B123 layout;
* the 13.5 build keeps the M2's 6070 start, and other sizes stay refused.
* the 13.5 build keeps the M2's 6070 start. Other sizes fall back to
* ave_t8112, whose size check in ave_fw_probe() then refuses them.
*/
static void ave_t8112_26b123_build(struct kunit *test)
{
Expand All @@ -1516,6 +1517,12 @@ static void ave_t8112_26b123_build(struct kunit *test)
&ave_t8112);
KUNIT_EXPECT_PTR_EQ(test, ave_fw_select_build(&ave_t8112, 0x134000, 0x128000),
&ave_t8112);
/* The near misses are refused: no variant of the chain pins them. */
KUNIT_EXPECT_FALSE(test, ave_fw_sizes_match(&ave_t8112, 0x11c000, 0x12c000));
KUNIT_EXPECT_FALSE(test, ave_fw_sizes_match(&ave_t8112, 0x134000, 0x128000));
KUNIT_EXPECT_FALSE(test, ave_fw_sizes_match(n, 0x11c000, 0x12c000));
KUNIT_EXPECT_TRUE(test, ave_fw_sizes_match(&ave_t8112, 0xd0000, 0x128000));
KUNIT_EXPECT_TRUE(test, ave_fw_sizes_match(n, 0x11c000, 0x128000));
KUNIT_EXPECT_NULL(test, n->next_build);
KUNIT_EXPECT_TRUE(test, n->boot_qualified);
KUNIT_EXPECT_PTR_EQ(test, n->regs, ave_t8112.regs);
Expand Down
17 changes: 9 additions & 8 deletions drivers/media/platform/apple/ave/ave-fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,11 @@ static const struct ave_fw_build *ave_fw_find_build(const struct ave_variant *v,
return NULL;
}

/* Whether these are the segment sizes of one of v's builds */
static bool ave_fw_sizes_match(const struct ave_variant *v, size_t text,
size_t data)
/*
* Whether TEXT/DATA segments of these sizes are a build the variant pins.
* ave_fw_probe() refuses the firmware when they are not.
*/
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);
Expand Down Expand Up @@ -297,12 +299,11 @@ int ave_fw_probe(struct ave_dev *ave)
want_crc = build->text_crc;
} else if (!ave->variant->boot_qualified && !ave->variant->fw_text_size) {
/* A probe-only variant that pins no build takes any segment sizes. */
} else if (ave->text.size != ave->variant->fw_text_size ||
(ave->data.size != ave->variant->fw_data_size &&
(!ave->variant->fw_data_size_alt ||
ave->data.size != ave->variant->fw_data_size_alt))) {
} else if (!ave_fw_sizes_match(ave->variant, ave->text.size,
ave->data.size)) {
return dev_err_probe(dev, -EINVAL,
"unexpected firmware segment sizes\n");
"unexpected firmware segment sizes (TEXT %#zx DATA %#zx)\n",
ave->text.size, ave->data.size);
}
if ((ave->text.phys < ave->data.phys + ave->data.size &&
ave->data.phys < ave->text.phys + ave->text.size) ||
Expand Down
6 changes: 5 additions & 1 deletion drivers/media/platform/apple/ave/ave.h
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,10 @@ struct ave_variant {
* The same encoder running another firmware build that a newer
* 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.
* 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.
*/
const struct ave_variant *next_build;

Expand Down Expand Up @@ -580,6 +583,7 @@ extern const struct ave_variant ave_t6000, ave_t6041, ave_t8112, ave_t8132,
/* ave-fw.c */
u64 ave_fw_vcbar(const struct ave_variant *variant, u64 text_iova);
int ave_fw_probe(struct ave_dev *ave);
bool ave_fw_sizes_match(const struct ave_variant *v, size_t text, size_t data);
const struct ave_variant *ave_fw_select_build(const struct ave_variant *v,
size_t text, size_t data);
int ave_fw_text_id_crc(const void *text, size_t size, u32 cell_off,
Expand Down
Loading