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
62 changes: 62 additions & 0 deletions arch/arm64/boot/dts/apple/t6041-j575c.dts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,68 @@
status = "okay";
};

/*
* The first video encoder (ADT ave0, soc-id t6040), its DARTs and its power
* domains, as on the J614c/J616c. iBoot preloads its firmware. The second
* encoder (ave1, soc-id t6041) is not described.
*/
&ps_venc0_sys {
status = "okay";
};

&ps_venc0_dma {
status = "okay";
};

&ps_venc0_pipe4 {
status = "okay";
};

&ps_venc0_pipe5 {
status = "okay";
};

&ps_venc0_me0 {
status = "okay";
};

&ps_venc0_me1 {
status = "okay";
};

&ave0_dart0 {
status = "okay";
};

&ave0_dart1 {
status = "okay";
};

&ave {
status = "okay";
};

/* Both JPEG engines; they have no board wiring. */
&ps_jpg {
status = "okay";
};

&jpeg0_dart {
status = "okay";
};

&jpeg0 {
status = "okay";
};

&jpeg1_dart {
status = "okay";
};

&jpeg1 {
status = "okay";
};

/*
* Three of the four back Thunderbolt ports, with the J773s's PD controllers
* (nub-spmi-a0 0xc, 0xa and 0x8 for ATC0-2), as on the J616c.
Expand Down
33 changes: 33 additions & 0 deletions drivers/media/platform/apple/ave/ave-abi-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1375,7 +1375,40 @@ static void ave_6070_text_id(struct kunit *test)
KUNIT_EXPECT_EQ(test, ave_fw_text_id_crc(text, size, size - 4, 0, &crc), -EINVAL);
}

/*
* The M4 Max loader sets one TEXT word every boot: the identity hashes it as
* zero, so two boots give one CRC, and it leaves the rest of TEXT counted.
*/
static void ave_t6041_text_boot_word(struct kunit *test)
{
const u32 off = ave_t6041.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);
KUNIT_EXPECT_EQ(test, ave_t6041.text_link_cell, 0U);
for (u32 i = 0; i < size; i++)
text[i] = i * 7 + 3;
memset(text + off, 0, 4);
image = crc32_le(~0U, text, size) ^ ~0U;

put_unaligned_le32(0x00dd0000, text + off);
KUNIT_EXPECT_EQ(test, ave_fw_text_boot_crc(text, size, off, &a), 0);
put_unaligned_le32(0x007d0000, text + off);
KUNIT_EXPECT_EQ(test, ave_fw_text_boot_crc(text, size, off, &b), 0);
KUNIT_EXPECT_EQ(test, a, image);
KUNIT_EXPECT_EQ(test, b, image);
/* A change anywhere else is a different TEXT. */
text[off + 4] ^= 1;
KUNIT_EXPECT_EQ(test, ave_fw_text_boot_crc(text, size, off, &a), 0);
KUNIT_EXPECT_NE(test, a, image);
KUNIT_EXPECT_EQ(test, ave_fw_text_boot_crc(text, size, size - 2, &a), -EINVAL);
}

static struct kunit_case ave_abi_cases[] = {
KUNIT_CASE(ave_t6041_text_boot_word),
KUNIT_CASE(ave_9003_byte_equality), KUNIT_CASE(ave_9003_hevc_main10),
KUNIT_CASE(ave_9003_speed), KUNIT_CASE(ave_cq_table),
KUNIT_CASE(ave_6070_images),
Expand Down
8 changes: 6 additions & 2 deletions drivers/media/platform/apple/ave/ave-drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,16 @@ const struct ave_variant ave_t8112 = {
/*
* The M4 Pro (T6040 in the ADT, apple,t6041 in the DT) starts its encoder
* like the A18 Pro: same coprocessor registers and boot sequence, its own
* device ID and type.
* device ID and type. The M4 Max (J575c) runs its first encoder, ADT ave0
* 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_variant ave_t6041 = {
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,
.boot_device_id = 27,
.boot_arg_value = AVE_COPROC_BOOT_ARG_VALUE,
.timebase_multiplier = 1,
Expand Down
55 changes: 51 additions & 4 deletions drivers/media/platform/apple/ave/ave-fw.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ static const u32 ave_known_text_crc[] = {
0x2ce7359e, /* AppleAVE2FW 9003.78.0 */
0x69c54454, /* AppleAVE2FW 9003.78.0 (macOS 26.0.x) */
AVE_FW_TEXT_CRC_T6040_25G83, /* AppleAVE2FW 9003.78.0 / T6040 */
AVE_FW_TEXT_CRC_T6041_25G83, /* AppleAVE2FW 9003.78.0 / M4 Max */
AVE_FW_TEXT_CRC_T6050_26A428, /* AppleAVE2FW, macOS 27.0 26A428 / T6050 */
0x460c7a7c, /* AppleAVE2FW 6070.11.1 / T6000 */
0x25bfd039, /* AppleAVE2FW 6070.11.1 / T8112 */
Expand Down Expand Up @@ -152,13 +153,58 @@ int ave_fw_text_id_crc(const void *text, size_t size, u32 cell_off,
return 0;
}

static bool ave_fw_known_crc(u32 crc)
{
for (unsigned int i = 0; i < ARRAY_SIZE(ave_known_text_crc); i++)
if (crc == ave_known_text_crc[i])
return true;
return false;
}

/* The TEXT CRC with the loader's per-boot word at @word_off zeroed. */
int ave_fw_text_boot_crc(const void *text, size_t size, u32 word_off,
u32 *crc)
{
static const u8 zero[sizeof(u32)];

if (word_off > size || size - word_off < sizeof(zero))
return -EINVAL;
*crc = crc32_le(~0U, text, word_off);
*crc = crc32_le(*crc, zero, sizeof(zero));
*crc = crc32_le(*crc, text + word_off + sizeof(zero),
size - word_off - sizeof(zero));
*crc ^= ~0U;
return 0;
}

/*
* 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 build).
*/
static int ave_fw_text_boot_id(struct ave_dev *ave, u32 *crc)
{
void *va;
int ret;

if (ave_fw_known_crc(*crc))
return 0;
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);
memunmap(va);
return ret;
}

static int ave_fw_text_id(struct ave_dev *ave, u32 *crc)
{
void *va;
int ret;

if (!ave->variant->text_link_cell)
return 0;
return ave->variant->text_boot_word ?
ave_fw_text_boot_id(ave, crc) : 0;
va = memremap(ave->text.phys, ave->text.size, MEMREMAP_WB);
if (!va)
return -ENOMEM;
Expand Down Expand Up @@ -191,7 +237,9 @@ int ave_fw_probe(struct ave_dev *ave)
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)
(ave->data.size != ave->variant->fw_data_size &&
(!ave->variant->fw_data_size_alt ||
ave->data.size != ave->variant->fw_data_size_alt)))
return dev_err_probe(dev, -EINVAL,
"unexpected firmware segment sizes\n");
if ((ave->text.phys < ave->data.phys + ave->data.size &&
Expand Down Expand Up @@ -230,8 +278,7 @@ int ave_fw_probe(struct ave_dev *ave)
if (ret)
return dev_err_probe(dev, ret,
"firmware text link cell is not the DATA address\n");
for (unsigned int i = 0; i < ARRAY_SIZE(ave_known_text_crc); i++)
known |= text_crc == ave_known_text_crc[i];
known |= ave_fw_known_crc(text_crc);
if (!known ||
(ave->variant->text_crc && text_crc != ave->variant->text_crc))
return dev_err_probe(dev, -ENODEV,
Expand Down
7 changes: 4 additions & 3 deletions drivers/media/platform/apple/ave/ave-layout.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,10 +946,11 @@ const struct ave_fw_layout ave_layout_6070_11_1 = {
const struct ave_fw_layout *ave_layout_for_crc(u32 crc)
{
/*
* The M4 Pro gets the same 25G83 firmware build as the A18 Pro, built
* for its own chip, and speaks the same command layout.
* The M4 Pro and M4 Max get the same 25G83 firmware build as the
* A18 Pro, built for their own chips, and speak the same command layout.
*/
if (crc == AVE_FW_TEXT_CRC_9003_78_0 || crc == AVE_FW_TEXT_CRC_T6040_25G83)
if (crc == AVE_FW_TEXT_CRC_9003_78_0 || crc == AVE_FW_TEXT_CRC_T6040_25G83 ||
crc == AVE_FW_TEXT_CRC_T6041_25G83)
return &ave_layout_9003_78_0;
if (crc == 0x460c7a7c || crc == 0x25bfd039)
return &ave_layout_6070_11_1;
Expand Down
2 changes: 2 additions & 0 deletions drivers/media/platform/apple/ave/ave-mctf.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,8 @@ static const struct ave_mctf_layout ave_mctf_layouts[] = {
AVE_MCTF_25G83(AVE_FW_TEXT_CRC_9003_78_0, true),
/* M4 Pro (T6040): same carrier sizes, no capture yet */
AVE_MCTF_25G83(AVE_FW_TEXT_CRC_T6040_25G83, false),
/* M4 Max (J575c): same build, no capture yet */
AVE_MCTF_25G83(AVE_FW_TEXT_CRC_T6041_25G83, false),
};

const struct ave_mctf_layout *ave_mctf_layout_for_crc(u32 text_crc)
Expand Down
18 changes: 17 additions & 1 deletion drivers/media/platform/apple/ave/ave.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,12 @@ enum ave_opcode {
#define AVE_FW_TEXT_CRC_9003_78_0 0x69c54454
/* The M4 Pro (T6040) build of the same 25G83 firmware. */
#define AVE_FW_TEXT_CRC_T6040_25G83 0x68d5f9f6
/*
* The M4 Max (J575c) build of AppleAVE2FW 9003.78.0, as iBoot 25G83 loads it:
* DATA is 0x130000, and the loader writes a per-boot word at TEXT 0x4224, so
* this is the TEXT CRC with that word zeroed.
*/
#define AVE_FW_TEXT_CRC_T6041_25G83 0x9a080cad
#define AVE_FW_TEXT_CRC_T6050_26A428 0x87279429

struct ave_ctx;
Expand All @@ -186,6 +192,8 @@ 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;
u32 boot_device_id;
u32 device_type;
u32 lfs_ref_scale;
Expand All @@ -199,6 +207,12 @@ 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 Down Expand Up @@ -516,13 +530,15 @@ 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_t8112;
extern const struct ave_variant ave_t6000, ave_t6041, ave_t8112;

/* ave-fw.c */
u64 ave_fw_vcbar(const struct ave_variant *variant, u64 text_iova);
int ave_fw_probe(struct ave_dev *ave);
int ave_fw_text_id_crc(const void *text, size_t size, u32 cell_off,
u64 data_iova, u32 *crc);
int ave_fw_text_boot_crc(const void *text, size_t size, u32 word_off,
u32 *crc);
void ave_fw_remove(struct ave_dev *ave);
int ave_fw_ensure_running(struct ave_dev *ave);
int ave_dart_audit(struct ave_dev *ave, const char *when);
Expand Down
Loading