From 7a5780cb10314532df190fb1a8f86b9817a594cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pu=C5=A1k=C3=A1=C4=8D?= Date: Wed, 2 Dec 2026 15:58:49 +0100 Subject: [PATCH 01/14] drm/imagination: apple: t7000: move the firmware layout into a table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The A8 path writes the firmware's boot objects (INIT, PLATFORM, CONTROL) at offsets that were literals in t7000_init_build(). They belong to one firmware build (AGXG4P 133.6 from iOS 12.4); the A8X's AGXG4G from iPadOS 15.8 has the same rings, events, slots and MMU but its INIT, PLATFORM and CONTROL objects are laid out differently. Collect the offsets t7000_init_build() uses into struct t7000_fw_layout, add the one entry the driver has (t7000_fw_g4p_b0, every value the old literal) and point both A8-path variants (A8 and A7) at it. No functional change: every offset written is the value that was there before. Later patches add the A8X's firmware as a second entry. Assisted-by: LLM Signed-off-by: Martin Puškáč --- drivers/gpu/drm/imagination/pvr_apple_s8003.c | 114 ++++++++++++++---- 1 file changed, 89 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/imagination/pvr_apple_s8003.c b/drivers/gpu/drm/imagination/pvr_apple_s8003.c index e70cfd9b653916..b003b655b8ffd6 100644 --- a/drivers/gpu/drm/imagination/pvr_apple_s8003.c +++ b/drivers/gpu/drm/imagination/pvr_apple_s8003.c @@ -288,6 +288,40 @@ struct t7000_soc { u32 word_3d4; /* the 3D record's +0x3d4; AGXG3 writes none */ }; +/* + * Where the A8-path firmware finds its boot objects. The offsets of the INIT, + * PLATFORM and CONTROL objects change between firmware builds (the A8's AGXG4P + * 133.6 from iOS 12.4 and the A8X's AGXG4G from iPadOS 15.8 differ), while + * the ring layout, the events, the slots and the MMU do not. One entry per + * known build: t7000_fw_g4p_b0 is the A8's, the only one the driver had + * before this table. + */ +struct t7000_fw_layout { + const char *build; /* a short build label, for messages only */ + /* INIT */ + u32 init_objects; /* the object list: CHANNEL x3, POLICY, 0x4b */ + u32 init_tail; /* the tail: 0x4e, 0x4c, PLATFORM, TAG_SEEN, 0x4f */ + u32 init_coremem; /* the core memory: a u32 META address, then a u64 VA */ + /* PLATFORM */ + u32 plat_border; /* the BorderColorTable pointer */ + u32 plat_pio; /* the PIO window table, 4 x {phys, META address, size} */ + u32 plat_chip_info; /* three words: major class, minor class, cores */ + u32 plat_perf_hi; /* the highest performance state */ + u32 plat_perf_count; /* the number of performance states */ + u32 plat_mhz; /* the MHz table */ + u32 plat_mv; /* the mV table */ + u32 plat_irq; /* the host interrupt: AIC word, bit, time offset */ + u32 plat_thread; /* the second thread's entry: pc, then sp */ + u32 plat_fence; /* the FenceBuffer pointer */ + u32 plat_image_va; /* the image's VA */ + u32 plat_vm_ptr; /* a heap VA word (DAT 0x712fab8 on the A8) */ + /* CONTROL */ + u32 ctl_temp; /* gpu_temperature_limit */ + u32 ctl_power; /* the power target */ + u32 ctl_floor, ctl_ceiling; /* the floor and ceiling performance states */ + u32 ctl_tag_host, ctl_mmu_root; /* the TAG_HOST and MMU_ROOT pointers */ +}; + /* * The A7's firmware writes at GPU VA 0xff_ffff_fff0 at boot, as context 0 * (an MMU fault on the J71 without a page there: bank 1, tag 3); a scratch @@ -305,6 +339,7 @@ struct t7000_soc { struct s8003_variant { const char *name; const struct t7000_soc *soc; /* the A8 path's SoC: A8 or A7 */ + const struct t7000_fw_layout *fw; /* the A8 path's firmware layout */ u32 page_size; /* the GPU page size the firmware's tables have */ u32 image_size; /* the unpacked firmware image */ u32 root_size, shared_size; /* the root and shared memory as mapped */ @@ -3978,6 +4013,32 @@ static const u32 s5l8960x_platform_38[] = { static const u32 s5l8960x_mhz[7] = { 0, 330, 390, 450, 165, 195, 225 }; static const u32 s5l8960x_mv[7] = { 600, 871, 937, 1000, 871, 937, 1000 }; +/* The A8's firmware: AGXG4P 133.6 from iOS 12.4 (g4p_b0), the layout the driver always had */ +static const struct t7000_fw_layout t7000_fw_g4p_b0 = { + .build = "g4p_b0", + .init_objects = 0x88, + .init_tail = 0x470, + .init_coremem = 0x4a4, + .plat_border = 0x188, + .plat_pio = 0x190, + .plat_chip_info = 0x300, + .plat_perf_hi = 0x30c, + .plat_perf_count = 0x310, + .plat_mhz = 0x314, + .plat_mv = 0x354, + .plat_irq = 0x494, + .plat_thread = 0x4a0, + .plat_fence = 0x4a8, + .plat_image_va = 0x4b0, + .plat_vm_ptr = 0x4b8, + .ctl_temp = 0x34, + .ctl_power = 0xc66, + .ctl_floor = 0xc6a, + .ctl_ceiling = 0xc6e, + .ctl_tag_host = 0xd0e, + .ctl_mmu_root = 0xd12, +}; + static const struct t7000_soc t7000_soc_a8 = { .border_fw = T7000_BORDER_FW, .ps_gfx = T7000_PMGR_PS_GFX, @@ -4103,6 +4164,7 @@ static void t7000_init_build(struct pvr_apple *apple, u32 q) { s->rgx_phys, 0, 0x20000 }, }; const struct t7000_soc *soc = s->v->soc; + const struct t7000_fw_layout *fw = s->v->fw; u8 *init, *platform, *policy, *control, *o4c; u32 pmin, pmax; unsigned int i; @@ -4118,13 +4180,13 @@ static void t7000_init_build(struct pvr_apple *apple, u32 q) for (i = 0; i < ARRAY_SIZE(rings); i++) put32(init + 4 * i, s8003_object_addr(layout, rings[i])); for (i = 0; i < ARRAY_SIZE(objects); i++) - put32(init + 0x88 + 4 * i, s8003_object_addr(layout, objects[i])); + put32(init + fw->init_objects + 4 * i, s8003_object_addr(layout, objects[i])); for (i = 0; i < ARRAY_SIZE(tail); i++) - put32(init + 0x470 + 4 * i, s8003_object_addr(layout, tail[i])); + put32(init + fw->init_tail + 4 * i, s8003_object_addr(layout, tail[i])); /* No core memory: the image's end, size 0 (0x84724c4; P4 0x40024000, 0xe1c0024000, 0) */ - put32(init + 0x4a4, (lower_32_bits(S8003_IMAGE_VA + T7000_IMAGE_SIZE) + 0x40000000) | + put32(init + fw->init_coremem, (lower_32_bits(S8003_IMAGE_VA + T7000_IMAGE_SIZE) + 0x40000000) | 0x40000000); - put64(init + 0x4a8, S8003_IMAGE_VA + T7000_IMAGE_SIZE); + put64(init + fw->init_coremem + 4, S8003_IMAGE_VA + T7000_IMAGE_SIZE); /* Channel headers {0, self, 0, self + 8}; no channel 1 +0x778 on the A8 */ for (i = 0; i < 3; i++) { u8 *channel = s8003_object(s, S8003_CHANNEL + i); @@ -4144,7 +4206,7 @@ static void t7000_init_build(struct pvr_apple *apple, u32 q) for (i = 0; i < ARRAY_SIZE(t7000_platform_38); i++) put32(platform + 0x38 + 4 * i, soc->platform_38[i]); for (i = 0; i < ARRAY_SIZE(pio); i++) { - u8 *entry = platform + 0x190 + 16 * i; + u8 *entry = platform + fw->plat_pio + 16 * i; put64(entry, pio[i].phys); put32(entry + 8, pio[i].addr); @@ -4165,22 +4227,22 @@ static void t7000_init_build(struct pvr_apple *apple, u32 q) put32(platform + 0x2dc, 1); /* agf_frg_vce_inval */ /* chip info {major class, minor class, cores}: the A8's {2, 4, 4} */ for (i = 0; i < 3; i++) - put32(platform + 0x300 + 4 * i, + put32(platform + fw->plat_chip_info + 4 * i, s->chip_info[0] ? s->chip_info[i] : soc->chip_info[i]); - put32(platform + 0x30c, 3); /* the highest performance state */ - put32(platform + 0x310, soc->perf_count); + put32(platform + fw->plat_perf_hi, 3); /* the highest performance state */ + put32(platform + fw->plat_perf_count, soc->perf_count); for (i = 0; i < ARRAY_SIZE(s->mhz); i++) { - put32(platform + 0x314 + 4 * i, s->mhz[i]); - put32(platform + 0x354 + 4 * i, s->mv[i]); + put32(platform + fw->plat_mhz + 4 * i, s->mhz[i]); + put32(platform + fw->plat_mv + 4 * i, s->mv[i]); } /* The interrupt to the host: its word and bit among the AIC's software sets (P4 0x10, 0x400) */ - put32(platform + 0x494, 4 * (s->irq / 32)); - put32(platform + 0x498, BIT(s->irq % 32)); - put32(platform + 0x49c, AIC_TIME & 0xfff); /* in the time window */ - put32(platform + 0x4a0, s->thread_pc); - put32(platform + 0x4a4, s->thread_sp); - put64(platform + 0x4b0, S8003_IMAGE_VA); - put64(platform + 0x4b8, 0x700000000ull); /* DAT 0x712fab8 */ + put32(platform + fw->plat_irq, 4 * (s->irq / 32)); + put32(platform + fw->plat_irq + 4, BIT(s->irq % 32)); + put32(platform + fw->plat_irq + 8, AIC_TIME & 0xfff); /* in the time window */ + put32(platform + fw->plat_thread, s->thread_pc); + put32(platform + fw->plat_thread + 4, s->thread_sp); + put64(platform + fw->plat_image_va, S8003_IMAGE_VA); + put64(platform + fw->plat_vm_ptr, 0x700000000ull); /* DAT 0x712fab8 */ put32(platform + 0x4c8, 0xffff); /* agf_gtp_ks */ put32(platform + 0x4cc, 7); /* agf_frg_ks */ put32(platform + 0x4d0, 7); /* agf_compute_ks */ @@ -4196,14 +4258,14 @@ static void t7000_init_build(struct pvr_apple *apple, u32 q) put64(policy + 0x1008, arch_timer_read_counter()); /* the governor's last sample */ put32(control + 0x28, 1); - put32(control + 0x34, 0x78); /* gpu_temperature_limit */ + put32(control + fw->ctl_temp, 0x78); /* gpu_temperature_limit */ put32(control + 0x4a, 1); - put32(control + 0xc66, 1867); /* power target */ + put32(control + fw->ctl_power, 1867); /* power target */ t7000_perf_range(soc, q, &pmin, &pmax); - put32(control + 0xc6a, 100 * pmin); /* floor performance state */ - put32(control + 0xc6e, 100 * pmax); /* ceiling performance state */ - put32(control + 0xd0e, s8003_object_addr(layout, S8003_TAG_HOST)); - put32(control + 0xd12, s8003_object_addr(layout, S8003_MMU_ROOT)); + put32(control + fw->ctl_floor, 100 * pmin); /* floor performance state */ + put32(control + fw->ctl_ceiling, 100 * pmax); /* ceiling performance state */ + put32(control + fw->ctl_tag_host, s8003_object_addr(layout, S8003_TAG_HOST)); + put32(control + fw->ctl_mmu_root, s8003_object_addr(layout, S8003_MMU_ROOT)); put32(control + 0xd16, 1); /* GPU context 0 runs on the kernel VM, whose catalogue the boot stream gives the BIF */ put64(s8003_object(s, S8003_MMU_ROOT), @@ -4216,10 +4278,10 @@ static void t7000_init_build(struct pvr_apple *apple, u32 q) if (s->a7_scratch.map) memset(s->a7_scratch.map, 0, PVR_DEVICE_PAGE_SIZE); put64(platform + 0x30, T7000_HWOBJ_VA + t7000_hwobj_offset[T7000_HW_YUV]); - put64(platform + 0x188, T7000_HWOBJ_VA + t7000_hwobj_offset[T7000_HW_BORDER]); + put64(platform + fw->plat_border, T7000_HWOBJ_VA + t7000_hwobj_offset[T7000_HW_BORDER]); put64(o4c, T7000_HWOBJ_VA + t7000_hwobj_offset[T7000_HW_BRN44455]); if (soc->fence) { - put64(platform + 0x4a8, T7000_HWOBJ_VA + t7000_hwobj_offset[T7000_HW_FENCE]); + put64(platform + fw->plat_fence, T7000_HWOBJ_VA + t7000_hwobj_offset[T7000_HW_FENCE]); put64(o4c + 8, T7000_HWOBJ_VA + t7000_hwobj_offset[T7000_HW_FENCE]); } } @@ -6779,6 +6841,7 @@ static const struct s8003_variant s8003_variant_a9 = { static const struct s8003_variant s8003_variant_a8 = { .name = "A8", .soc = &t7000_soc_a8, + .fw = &t7000_fw_g4p_b0, .page_size = SZ_4K, .image_size = T7000_IMAGE_SIZE, .root_size = T7000_ROOT_SIZE, @@ -6823,6 +6886,7 @@ static const struct s8003_variant s8003_variant_a8 = { static const struct s8003_variant s8003_variant_a7 = { .name = "A7", .soc = &t7000_soc_a7, + .fw = &t7000_fw_g4p_b0, .page_size = SZ_4K, .image_size = T7000_IMAGE_SIZE, .root_size = T7000_ROOT_SIZE, From e967de1907e74ddad1a20367e77fdb15008eaeeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pu=C5=A1k=C3=A1=C4=8D?= Date: Wed, 2 Dec 2026 17:47:07 +0100 Subject: [PATCH 02/14] drm/imagination: apple: t7000: select the layout by the firmware's hash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hash the LDR file the user supplied and take the firmware layout of the entry that lists that SHA-256. Orchard's recipes produce four different files for the A8 and the A7 (per device and restore image), all of which run the A8's layout, so the A8 entry lists their hashes. A file nobody listed still gets the A8's layout, with a warning, as every file did before the table; an entry without that default (later entries) refuses the probe with -ENODEV when its file is not the one supplied. DRM_POWERVR_APPLE selects CRYPTO_LIB_SHA256 for sha256(). Assisted-by: LLM Signed-off-by: Martin Puškáč --- drivers/gpu/drm/imagination/Kconfig | 1 + drivers/gpu/drm/imagination/pvr_apple_s8003.c | 75 ++++++++++++++++++- 2 files changed, 72 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/imagination/Kconfig b/drivers/gpu/drm/imagination/Kconfig index 1ef4b723d07afe..edbe1ec049335a 100644 --- a/drivers/gpu/drm/imagination/Kconfig +++ b/drivers/gpu/drm/imagination/Kconfig @@ -24,6 +24,7 @@ config DRM_POWERVR_APPLE depends on DRM_POWERVR depends on APPLE_RTKIT && (ARCH_APPLE || COMPILE_TEST) depends on DRM_POWERVR=m || APPLE_RTKIT=y + select CRYPTO_LIB_SHA256 help Support the Rogue-based GPU of the Apple A10 (T8010), which runs Apple's GFX firmware on an RTKit coprocessor instead of diff --git a/drivers/gpu/drm/imagination/pvr_apple_s8003.c b/drivers/gpu/drm/imagination/pvr_apple_s8003.c index b003b655b8ffd6..278b0e4aece406 100644 --- a/drivers/gpu/drm/imagination/pvr_apple_s8003.c +++ b/drivers/gpu/drm/imagination/pvr_apple_s8003.c @@ -56,6 +56,7 @@ #include #include #include +#include #include #include #include @@ -298,6 +299,9 @@ struct t7000_soc { */ struct t7000_fw_layout { const char *build; /* a short build label, for messages only */ + const u8 (*sha256)[SHA256_DIGEST_SIZE]; /* the LDR files known to have this layout */ + unsigned int nr_sha256; + bool fallback; /* an LDR file nobody listed gets this layout */ /* INIT */ u32 init_objects; /* the object list: CHANNEL x3, POLICY, 0x4b */ u32 init_tail; /* the tail: 0x4e, 0x4c, PLATFORM, TAG_SEEN, 0x4f */ @@ -339,7 +343,8 @@ struct t7000_fw_layout { struct s8003_variant { const char *name; const struct t7000_soc *soc; /* the A8 path's SoC: A8 or A7 */ - const struct t7000_fw_layout *fw; /* the A8 path's firmware layout */ + const struct t7000_fw_layout *const *fws; /* the A8 path's firmware layouts, one per known LDR file */ + unsigned int nr_fws; u32 page_size; /* the GPU page size the firmware's tables have */ u32 image_size; /* the unpacked firmware image */ u32 root_size, shared_size; /* the root and shared memory as mapped */ @@ -384,6 +389,10 @@ struct s8003_variant { void (*event_fault)(struct pvr_apple *apple, const u8 *e); }; +static const struct t7000_fw_layout *t7000_fw_select(const struct s8003_variant *v, + const void *image, size_t size, + struct device *dev); + struct s8003_mem { struct pvr_gem_object *obj; u8 *map; @@ -518,6 +527,7 @@ struct pvr_apple_s8003 { const struct s8003_variant *v; bool ch_root; /* the channels are in the root memory: META's uncached window */ u64 pm_sets_va; /* where the PM sets are mapped, in every VM */ + const struct t7000_fw_layout *fwlay; /* the A8 path's layout for the LDR file loaded (t7000_fw_select()) */ struct delayed_work drain_work; /* reads the rings while the firmware runs */ struct mutex event_lock; /* the rings the firmware posts to */ ktime_t touched; /* s8003_touch() */ @@ -3481,6 +3491,11 @@ static int pvr_apple_s8003_init(struct pvr_apple *apple) err = pvr_apple_fw_load(apple, SZ_1M); if (err) return err; + if (v->nr_fws) { + s->fwlay = t7000_fw_select(v, apple->fw_image, apple->fw_size, dev); + if (!s->fwlay) + return -ENODEV; + } err = pvr_meta_ldr_process(from_pvr_device(apple->pvr_dev), apple->fw_image, apple->fw_size, v->ldr, s, NULL); if (!err && (!s->thread_pc || (v->ldr_conf_count && s->conf_count != v->ldr_conf_count))) @@ -4013,9 +4028,27 @@ static const u32 s5l8960x_platform_38[] = { static const u32 s5l8960x_mhz[7] = { 0, 330, 390, 450, 165, 195, 225 }; static const u32 s5l8960x_mv[7] = { 600, 871, 937, 1000, 871, 937, 1000 }; +/* + * The LDR files Orchard's firmware recipes produce for the A8 and the A7: they + * differ per device and restore image, and run with the one layout below. + */ +static const u8 t7000_fw_g4p_b0_sha256[][SHA256_DIGEST_SIZE] = { + /* A8: n102 and n56 (Orchard recipes) */ + { 0x5f, 0x99, 0xa8, 0xab, 0x88, 0xdd, 0xd3, 0x4f, 0x8f, 0x32, 0xc1, 0x1a, 0xdb, 0x21, 0xf6, 0xb2, 0x41, 0x0b, 0xec, 0xe3, 0xd2, 0x3a, 0x9a, 0xee, 0x56, 0x0c, 0xa8, 0x0f, 0xe8, 0xe4, 0x5f, 0x55 }, + /* A8: n61 */ + { 0x36, 0xbf, 0xc9, 0x05, 0xaa, 0xf4, 0x1b, 0xaa, 0xc1, 0x74, 0x88, 0x49, 0x94, 0x2c, 0x4b, 0x5f, 0x79, 0x6b, 0x1d, 0x29, 0x3e, 0x81, 0x71, 0x04, 0x5e, 0xe4, 0x5c, 0xf2, 0x53, 0x15, 0x0c, 0x68 }, + /* A8: j96 and j97 */ + { 0x0b, 0x60, 0xde, 0xf6, 0x72, 0x90, 0x39, 0x1b, 0x4c, 0x6a, 0xa9, 0x13, 0xd9, 0xa7, 0x8a, 0x81, 0x05, 0xd6, 0xd9, 0xb0, 0x37, 0x38, 0x17, 0x5b, 0x8e, 0x57, 0x32, 0x68, 0x9d, 0xb1, 0xe5, 0xba }, + /* A7: j71 (the 16H88 kernelcache) */ + { 0x44, 0x81, 0x67, 0x30, 0x09, 0x8c, 0x99, 0x12, 0x41, 0x90, 0xc8, 0xe4, 0x93, 0x3d, 0xdb, 0xac, 0x6b, 0x1b, 0x50, 0xeb, 0x86, 0x55, 0x5e, 0x88, 0x6d, 0xa5, 0x67, 0xa2, 0x4d, 0xc0, 0xeb, 0x88 }, +}; + /* The A8's firmware: AGXG4P 133.6 from iOS 12.4 (g4p_b0), the layout the driver always had */ static const struct t7000_fw_layout t7000_fw_g4p_b0 = { .build = "g4p_b0", + .sha256 = t7000_fw_g4p_b0_sha256, + .nr_sha256 = ARRAY_SIZE(t7000_fw_g4p_b0_sha256), + .fallback = true, .init_objects = 0x88, .init_tail = 0x470, .init_coremem = 0x4a4, @@ -4039,6 +4072,38 @@ static const struct t7000_fw_layout t7000_fw_g4p_b0 = { .ctl_mmu_root = 0xd12, }; +static const struct t7000_fw_layout *const t7000_fw_layouts[] = { + &t7000_fw_g4p_b0, +}; + +/* + * The layout of the LDR file the user supplied, by its SHA-256. A file nobody + * listed gets the A8's layout, as every file did before the table, unless the + * variant has no such default. + */ +static const struct t7000_fw_layout *t7000_fw_select(const struct s8003_variant *v, + const void *image, size_t size, + struct device *dev) +{ + u8 digest[SHA256_DIGEST_SIZE]; + unsigned int i, j; + + sha256(image, size, digest); + for (i = 0; i < v->nr_fws; i++) + for (j = 0; j < v->fws[i]->nr_sha256; j++) + if (!memcmp(v->fws[i]->sha256[j], digest, sizeof(digest))) + return v->fws[i]; + for (i = 0; i < v->nr_fws; i++) { + if (!v->fws[i]->fallback) + continue; + dev_warn(dev, "unknown GFX firmware sha256 %*phN: assuming the %s layout\n", + (int)sizeof(digest), digest, v->fws[i]->build); + return v->fws[i]; + } + dev_err(dev, "unknown GFX firmware sha256 %*phN\n", (int)sizeof(digest), digest); + return NULL; +} + static const struct t7000_soc t7000_soc_a8 = { .border_fw = T7000_BORDER_FW, .ps_gfx = T7000_PMGR_PS_GFX, @@ -4164,7 +4229,7 @@ static void t7000_init_build(struct pvr_apple *apple, u32 q) { s->rgx_phys, 0, 0x20000 }, }; const struct t7000_soc *soc = s->v->soc; - const struct t7000_fw_layout *fw = s->v->fw; + const struct t7000_fw_layout *fw = s->fwlay; u8 *init, *platform, *policy, *control, *o4c; u32 pmin, pmax; unsigned int i; @@ -6841,7 +6906,8 @@ static const struct s8003_variant s8003_variant_a9 = { static const struct s8003_variant s8003_variant_a8 = { .name = "A8", .soc = &t7000_soc_a8, - .fw = &t7000_fw_g4p_b0, + .fws = t7000_fw_layouts, + .nr_fws = ARRAY_SIZE(t7000_fw_layouts), .page_size = SZ_4K, .image_size = T7000_IMAGE_SIZE, .root_size = T7000_ROOT_SIZE, @@ -6886,7 +6952,8 @@ static const struct s8003_variant s8003_variant_a8 = { static const struct s8003_variant s8003_variant_a7 = { .name = "A7", .soc = &t7000_soc_a7, - .fw = &t7000_fw_g4p_b0, + .fws = t7000_fw_layouts, + .nr_fws = ARRAY_SIZE(t7000_fw_layouts), .page_size = SZ_4K, .image_size = T7000_IMAGE_SIZE, .root_size = T7000_ROOT_SIZE, From a172b6cdbce5d6c1867e997f75ea46b4bdcdc91c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pu=C5=A1k=C3=A1=C4=8D?= Date: Thu, 3 Dec 2026 14:18:38 +0100 Subject: [PATCH 03/14] drm/imagination: apple: t7000: run the A8X's INIT, CONTROL and POLICY on the A9 writers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The A8X firmware (AGXG4G, iPadOS 15.8.5 19H394) has the A9 builder's INIT, CONTROL and POLICY offsets; only PLATFORM differs and is shorter (0x318 bytes, no mV table or chip info). Add the 19H394 layout entry (selected by the LDR's SHA-256, no fallback), an A8-shaped PLATFORM hook (t7001_init_chip()), the PLATFORM flag words as a per-layout table, and a provisional A8X variant and SoC entry. Image size, core memory and the ring-lane size are placeholders until the next patch. Compile-checked only; not run on hardware. Assisted-by: LLM Signed-off-by: Martin Puškáč --- drivers/gpu/drm/imagination/pvr_apple_s8003.c | 526 +++++++++++++----- 1 file changed, 384 insertions(+), 142 deletions(-) diff --git a/drivers/gpu/drm/imagination/pvr_apple_s8003.c b/drivers/gpu/drm/imagination/pvr_apple_s8003.c index 278b0e4aece406..1746478665816b 100644 --- a/drivers/gpu/drm/imagination/pvr_apple_s8003.c +++ b/drivers/gpu/drm/imagination/pvr_apple_s8003.c @@ -265,8 +265,10 @@ struct t7000_soc { bool a8_globals; /* perf records, voltage manager, SOC_TVM (A8) */ u32 bridge_reg, bridge_val; /* the first bridge's one store */ const u32 *platform_38; /* PLATFORM +0x38: the CSC block, 30 words */ - const u32 *mhz, *mv; /* the ADT's perf-states, 7 rows, without an OPP table */ - u32 perf_count; /* PLATFORM +0x310 */ + const u32 *mhz, *mv; /* the ADT's perf-states, @nr_mhz rows; @mv may be NULL */ + unsigned int nr_mhz; + u32 perf_states; /* the full-clock states: PLATFORM perf_hi */ + u32 perf_count; /* PLATFORM perf_count */ bool fence; /* a FenceBuffer named to the firmware */ bool slc; /* SLC_CTRL_MISC and 0x3808 in the boot stream */ u32 rev_major; /* CORE_REVISION[23:16] */ @@ -302,6 +304,12 @@ struct t7000_fw_layout { const u8 (*sha256)[SHA256_DIGEST_SIZE]; /* the LDR files known to have this layout */ unsigned int nr_sha256; bool fallback; /* an LDR file nobody listed gets this layout */ + /* + * PLATFORM's single words (flags, small constants), {offset, value}; + * names per offset in the entry. + */ + const u32 (*plat_flags)[2]; + unsigned int nr_plat_flags; /* INIT */ u32 init_objects; /* the object list: CHANNEL x3, POLICY, 0x4b */ u32 init_tail; /* the tail: 0x4e, 0x4c, PLATFORM, TAG_SEEN, 0x4f */ @@ -309,11 +317,11 @@ struct t7000_fw_layout { /* PLATFORM */ u32 plat_border; /* the BorderColorTable pointer */ u32 plat_pio; /* the PIO window table, 4 x {phys, META address, size} */ - u32 plat_chip_info; /* three words: major class, minor class, cores */ + u32 plat_chip_info; /* three words: major class, minor class, cores; 0: none */ u32 plat_perf_hi; /* the highest performance state */ u32 plat_perf_count; /* the number of performance states */ u32 plat_mhz; /* the MHz table */ - u32 plat_mv; /* the mV table */ + u32 plat_mv; /* the mV table; 0: none */ u32 plat_irq; /* the host interrupt: AIC word, bit, time offset */ u32 plat_thread; /* the second thread's entry: pc, then sp */ u32 plat_fence; /* the FenceBuffer pointer */ @@ -368,6 +376,10 @@ struct s8003_variant { int (*map)(struct pvr_apple *apple); void (*unmap)(struct pvr_apple *apple); void (*init_build)(struct pvr_apple *apple, u32 q); + /* s8003_init_build(): the words the chip's firmware has its own layout for (PLATFORM) */ + void (*init_chip)(struct pvr_apple *apple); + u32 coremem, coremem_size; /* core memory's contents in the image (s8003_init_build()) */ + u32 perf_states; /* the governor's states above 0 (s8003_init_pins()) */ void (*channels_init)(struct pvr_apple_s8003 *s); int (*boot)(struct pvr_apple *apple); int (*release)(struct pvr_apple *apple, u32 q); @@ -870,19 +882,14 @@ static void s8003_image_configure(struct pvr_apple_s8003 *s) * changes the state and never powers the core off while idle: the host does * that (runtime PM). */ -static void s8003_init_perf(struct pvr_apple_s8003 *s, u32 q) +static const u32 s8003_mhz[] = { 0, 340, 474, 550, 723 }; + +static void s8003_init_pins(struct pvr_apple_s8003 *s, u32 q) { - static const u32 mhz[] = { 0, 340, 474, 550, 723 }; - u8 *platform = s8003_object(s, S8003_PLATFORM); u8 *control = s8003_object(s, S8003_CONTROL); u8 *policy = s8003_object(s, S8003_POLICY); - u32 top = 100 * (ARRAY_SIZE(mhz) - 1), pin = 100 * q; - unsigned int i; + u32 top = 100 * s->v->perf_states, pin = 100 * q; - put32(platform + 0x710, ARRAY_SIZE(mhz) - 1); - put32(platform + 0x714, ARRAY_SIZE(mhz)); - for (i = 0; i < ARRAY_SIZE(mhz); i++) - put32(platform + 0x718 + 4 * i, mhz[i]); put32(control + 0x1028, 3348); /* power envelope, mW */ put32(control + 0x102c, pin); /* floor */ put32(control + 0x1030, top); @@ -904,26 +911,10 @@ static void s8003_init_perf(struct pvr_apple_s8003 *s, u32 q) } } -/* - * The root and shared memory as the firmware finds it when it starts: where - * its objects are, the registers it may use, the interrupt it raises, its - * thread, and empty rings. What Apple's kext fills from the platform's power - * policy beyond s8003_init_perf() stays zero. - */ -static void s8003_init_build(struct pvr_apple *apple, u32 q) +/* The A9's PLATFORM, its clock table and CONTROL +0x104c */ +static void s8003_init_chip(struct pvr_apple *apple) { - static const u8 rings[] = { - S8003_WORK_CTL, S8003_WORK_RING, S8003_WORK_CTL + 4, S8003_WORK_RING + 4, - S8003_WORK_CTL + 8, S8003_WORK_RING + 8, S8003_DC_CTL, S8003_DC_RING, - S8003_EVENT_CTL, S8003_EVENTS, S8003_LOG_CTL, S8003_LOGS, - S8003_STATS_CTL, S8003_STATS, S8003_TRACE_CTL, S8003_TRACE, - }; - static const u8 objects[] = { - S8003_CHANNEL, S8003_CHANNEL + 1, S8003_CHANNEL + 2, S8003_POLICY, 0x4b, - }; - static const u8 tail[] = { 0x4e, 0x4c, S8003_PLATFORM, 0x85, 0x4f }; struct pvr_apple_s8003 *s = apple->chip_data; - const struct s8003_layout *layout = &s->layout; const struct { u64 phys; u32 addr; @@ -935,37 +926,9 @@ static void s8003_init_build(struct pvr_apple *apple, u32 q) s8003_meta_addr(S8003_PIO_VA + S8003_PIO_AIC + AIC_SW_SET), 0x4000 }, { s->rgx_phys, 0, 0x20000 }, }; - u8 *init, *platform, *policy, *control; - u64 now = arch_timer_read_counter(); + u8 *platform = s8003_object(s, S8003_PLATFORM); unsigned int i; - memset(s->root.map, 0, S8003_ROOT_SIZE); - memset(s->shared.map, 0, S8003_SHARED_SIZE); - init = s8003_object(s, S8003_INIT); - platform = s8003_object(s, S8003_PLATFORM); - policy = s8003_object(s, S8003_POLICY); - control = s8003_object(s, S8003_CONTROL); - - for (i = 0; i < ARRAY_SIZE(rings); i++) - put32(init + 4 * i, s8003_object_addr(layout, rings[i])); - for (i = 0; i < ARRAY_SIZE(objects); i++) - put32(init + 0x64 + 4 * i, s8003_object_addr(layout, objects[i])); - for (i = 0; i < ARRAY_SIZE(tail); i++) - put32(init + 0x44c + 4 * i, s8003_object_addr(layout, tail[i])); - for (i = 0; i < 3; i++) { - u8 *channel = s8003_object(s, S8003_CHANNEL + i); - u32 addr = s8003_object_addr(layout, S8003_CHANNEL + i); - - put32(channel + 4, addr); - put32(channel + 12, addr + 8); - } - put32(s8003_object(s, S8003_CHANNEL + 1) + 0x778, 0xffffffff); - /* Core memory's contents: uncached address, GPU address, size */ - put32(init + 0x480, - (lower_32_bits(S8003_IMAGE_VA + S8003_IMAGE_COREMEM) + 0x40000000) | 0x40000000); - put64(init + 0x484, S8003_IMAGE_VA + S8003_IMAGE_COREMEM); - put32(init + 0x48c, S8003_IMAGE_COREMEM_SIZE); - put64(platform, 0x600000000ull); put64(platform + 8, 0xffc00000); /* What PDS and USC code addresses are relative to: powervr's code heaps */ @@ -996,6 +959,64 @@ static void s8003_init_build(struct pvr_apple *apple, u32 q) put64(platform + 0x774, S8003_IMAGE_VA); put64(platform + 0x77c, 0x300000); /* +0x784: what the firmware adds to the AIC's time; Linux counts from it */ + put32(platform + 0x710, ARRAY_SIZE(s8003_mhz) - 1); + put32(platform + 0x714, ARRAY_SIZE(s8003_mhz)); + for (i = 0; i < ARRAY_SIZE(s8003_mhz); i++) + put32(platform + 0x718 + 4 * i, s8003_mhz[i]); + + put32(s8003_object(s, S8003_CONTROL) + 0x104c, 1); +} + +/* + * The root and shared memory as the firmware finds it when it starts: where + * its objects are, the registers it may use, the interrupt it raises, its + * thread, and empty rings. What Apple's kext fills from the platform's power + * policy beyond s8003_init_pins() stays zero. + */ +static void s8003_init_build(struct pvr_apple *apple, u32 q) +{ + static const u8 rings[] = { + S8003_WORK_CTL, S8003_WORK_RING, S8003_WORK_CTL + 4, S8003_WORK_RING + 4, + S8003_WORK_CTL + 8, S8003_WORK_RING + 8, S8003_DC_CTL, S8003_DC_RING, + S8003_EVENT_CTL, S8003_EVENTS, S8003_LOG_CTL, S8003_LOGS, + S8003_STATS_CTL, S8003_STATS, S8003_TRACE_CTL, S8003_TRACE, + }; + static const u8 objects[] = { + S8003_CHANNEL, S8003_CHANNEL + 1, S8003_CHANNEL + 2, S8003_POLICY, 0x4b, + }; + static const u8 tail[] = { 0x4e, 0x4c, S8003_PLATFORM, 0x85, 0x4f }; + struct pvr_apple_s8003 *s = apple->chip_data; + const struct s8003_variant *v = s->v; + const struct s8003_layout *layout = &s->layout; + u8 *init, *policy, *control; + u64 now = arch_timer_read_counter(); + unsigned int i; + + memset(s->root.map, 0, v->root_size); + memset(s->shared.map, 0, v->shared_size); + init = s8003_object(s, S8003_INIT); + policy = s8003_object(s, S8003_POLICY); + control = s8003_object(s, S8003_CONTROL); + + for (i = 0; i < ARRAY_SIZE(rings); i++) + put32(init + 4 * i, s8003_object_addr(layout, rings[i])); + for (i = 0; i < ARRAY_SIZE(objects); i++) + put32(init + 0x64 + 4 * i, s8003_object_addr(layout, objects[i])); + for (i = 0; i < ARRAY_SIZE(tail); i++) + put32(init + 0x44c + 4 * i, s8003_object_addr(layout, tail[i])); + for (i = 0; i < 3; i++) { + u8 *channel = s8003_object(s, S8003_CHANNEL + i); + u32 addr = s8003_object_addr(layout, S8003_CHANNEL + i); + + put32(channel + 4, addr); + put32(channel + 12, addr + 8); + } + put32(s8003_object(s, S8003_CHANNEL + 1) + 0x778, 0xffffffff); + /* Core memory's contents: uncached address, GPU address, size */ + put32(init + 0x480, + (lower_32_bits(S8003_IMAGE_VA + v->coremem) + 0x40000000) | 0x40000000); + put64(init + 0x484, S8003_IMAGE_VA + v->coremem); + put32(init + 0x48c, v->coremem_size); put64(policy + 8, 0x400000000ull); put64(policy + 0x10, 0x3f800000); @@ -1007,11 +1028,11 @@ static void s8003_init_build(struct pvr_apple *apple, u32 q) put32(control + 0x30, 1); put32(control + 0x1044, s8003_object_addr(layout, 0x84)); put32(control + 0x1048, s8003_object_addr(layout, S8003_MMU_ROOT)); - put32(control + 0x104c, 1); put64(s8003_object(s, S8003_MMU_ROOT), pvr_vm_get_page_table_root_addr(apple->pvr_dev->kernel_vm_ctx)); - s8003_init_perf(s, q); + s8003_init_pins(s, q); + v->init_chip(apple); } static void s8003_mem_fini(struct pvr_apple *apple, struct s8003_mem *mem) @@ -3811,6 +3832,49 @@ static const struct s8003_object_size s8003_objects_a8[] = { { S8003_MMU_ROOT, true, 0x40 }, }; +/* + * The A8X's (19H394) objects: INIT, POLICY and CONTROL have the A9's sizes, + * 0x4c and the 8-slot tables the A8's, PLATFORM its own. Its image and ring + * lanes: see T7001_*. + */ +#define T7001_IMAGE_SIZE 0 /* TBD: the private layout table (patches 3-4) */ +#define T7001_IMAGE_COREMEM 0 /* TBD: where patch 4 places core memory */ +#define T7001_IMAGE_COREMEM_SIZE 0 /* TBD: the LDR's core-memory section */ +#define T7001_RING_CTL_SIZE T7000_RING_CTL_SIZE /* unknown: 0x20 or 0x30, lanes 1-3 unmeasured */ + +static const struct s8003_object_size s8003_objects_a8x[] = { + { S8003_INIT, false, 0x1490 }, + { S8003_CHANNEL, false, 0x990 }, + { S8003_CHANNEL + 1, false, 0x8e0 }, + { S8003_CHANNEL + 2, false, 0x8c0 }, + { S8003_POLICY, false, 0x938 }, + { 0x4b, false, 0x28 }, + { 0x4c, false, 0x10 }, + { S8003_PLATFORM, false, 0x318 }, + { 0x4e, false, 0x84 }, + { S8003_TAG_SEEN, false, 0x20 }, + { S8003_CONTROL, true, 0x2058 }, + { S8003_EVENT_CTL, true, T7001_RING_CTL_SIZE }, + { S8003_LOG_CTL, true, 4 * T7001_RING_CTL_SIZE }, + { S8003_STATS_CTL, true, T7001_RING_CTL_SIZE }, + { S8003_TRACE_CTL, true, T7001_RING_CTL_SIZE }, + { S8003_EVENTS, true, 0x2c00 }, + { S8003_LOGS, true, 0xb000 }, + { 0x4f, true, 0x36000 }, + { S8003_STATS, true, 0x2c00 }, + { S8003_TRACE, true, 0x2400 }, + { S8003_WORK_CTL, true, T7001_RING_CTL_SIZE }, + { S8003_WORK_CTL + 4, true, T7001_RING_CTL_SIZE }, + { S8003_WORK_CTL + 8, true, T7001_RING_CTL_SIZE }, + { S8003_DC_CTL, true, T7001_RING_CTL_SIZE }, + { S8003_WORK_RING, true, 0x1400 }, + { S8003_WORK_RING + 4, true, 0x1400 }, + { S8003_WORK_RING + 8, true, 0x1400 }, + { S8003_DC_RING, true, 0x1400 }, + { S8003_TAG_HOST, true, 0x20 }, + { S8003_MMU_ROOT, true, 0x40 }, +}; + /* The image's segments: META address (bit 31 clear), size, offset in the image */ static const struct { u32 base, size, offset; @@ -4043,12 +4107,34 @@ static const u8 t7000_fw_g4p_b0_sha256[][SHA256_DIGEST_SIZE] = { { 0x44, 0x81, 0x67, 0x30, 0x09, 0x8c, 0x99, 0x12, 0x41, 0x90, 0xc8, 0xe4, 0x93, 0x3d, 0xdb, 0xac, 0x6b, 0x1b, 0x50, 0xeb, 0x86, 0x55, 0x5e, 0x88, 0x6d, 0xa5, 0x67, 0xa2, 0x4d, 0xc0, 0xeb, 0x88 }, }; +/* g4p_b0's PLATFORM words, names from the A8's kext (P4) */ +static const u32 t7000_plat_flags_g4p_b0[][2] = { + { 0x250, 1 }, /* Fender boot */ + { 0x254, 1 }, /* gpu_lockup_detection */ + { 0x258, 1 }, /* PIO supported */ + { 0x274, 1 }, /* agf_timeslice */ + { 0x278, 1 }, + { 0x27c, 1 }, /* agf_timer */ + { 0x280, 1000 * 0x18 }, /* agf_timer_period, 24 MHz ticks */ + { 0x284, 0x10 }, + { 0x290, 1 }, /* agf_dwb */ + { 0x294, 1 }, /* agf_itr_cache */ + { 0x29c, 1 }, /* agf_deferred_opaque */ + { 0x2b4, 0x1f }, /* agf_max_tiles_per_pipe */ + { 0x2dc, 1 }, /* agf_frg_vce_inval */ + { 0x4c8, 0xffff }, /* agf_gtp_ks */ + { 0x4cc, 7 }, /* agf_frg_ks */ + { 0x4d0, 7 }, /* agf_compute_ks */ +}; + /* The A8's firmware: AGXG4P 133.6 from iOS 12.4 (g4p_b0), the layout the driver always had */ static const struct t7000_fw_layout t7000_fw_g4p_b0 = { .build = "g4p_b0", .sha256 = t7000_fw_g4p_b0_sha256, .nr_sha256 = ARRAY_SIZE(t7000_fw_g4p_b0_sha256), .fallback = true, + .plat_flags = t7000_plat_flags_g4p_b0, + .nr_plat_flags = ARRAY_SIZE(t7000_plat_flags_g4p_b0), .init_objects = 0x88, .init_tail = 0x470, .init_coremem = 0x4a4, @@ -4072,10 +4158,56 @@ static const struct t7000_fw_layout t7000_fw_g4p_b0 = { .ctl_mmu_root = 0xd12, }; +/* + * The A8X's firmware: AGXG4G from iPadOS 15.8.5 (19H394). Its INIT, CONTROL + * and POLICY are the A9's (s8003_init_build()); PLATFORM keeps the A8's + * fields in a shorter object (0x318 bytes): no mV table and no chip info + * (+0x300 is the image's VA). The words without a name have none yet for + * this build: the values are the ones the A8X's firmware ran with. + */ +static const u32 t7000_plat_flags_g4g_19h394[][2] = { + { 0x250, 1 }, /* Fender boot (the A8's +0x250) */ + { 0x258, 1 }, /* PIO supported (the A8's +0x258) */ + { 0x26c, 1 }, /* agf_timeslice? (the A8's +0x274 - 8; inferred) */ + { 0x270, 1 }, + { 0x274, 1 }, /* agf_timer? (the A8's +0x27c - 8; inferred) */ + { 0x288, 1 }, +}; + +/* The A8X's LDR: AGXG4G of iPadOS 15.8.5 (19H394). No fallback: any other file is refused. */ +static const u8 t7000_fw_g4g_19h394_sha256[][SHA256_DIGEST_SIZE] = { + { 0x55, 0x01, 0x8c, 0x7e, 0xac, 0xef, 0x95, 0x0f, 0xf4, 0x38, 0x46, 0x1f, 0x79, 0xac, 0x65, 0x13, 0xe5, 0x0b, 0x0c, 0x85, 0x28, 0xb1, 0x91, 0xe8, 0xe0, 0x64, 0xdf, 0xae, 0x40, 0x09, 0x2c, 0x2f }, +}; + +static const struct t7000_fw_layout t7000_fw_g4g_19h394 = { + .build = "g4g 19H394", + .sha256 = t7000_fw_g4g_19h394_sha256, + .nr_sha256 = ARRAY_SIZE(t7000_fw_g4g_19h394_sha256), + .plat_flags = t7000_plat_flags_g4g_19h394, + .nr_plat_flags = ARRAY_SIZE(t7000_plat_flags_g4g_19h394), + /* INIT and CONTROL: written by s8003_init_build(), at the A9's offsets */ + .plat_border = 0x1b8, + .plat_pio = 0x1c0, + .plat_chip_info = 0, /* unknown in this build */ + .plat_perf_hi = 0x29c, + .plat_perf_count = 0x2a0, + .plat_mhz = 0x2a4, + .plat_mv = 0, /* none */ + .plat_irq = 0x2e4, + .plat_thread = 0x2f0, + .plat_fence = 0x2f8, + .plat_image_va = 0x300, + .plat_vm_ptr = 0x308, +}; + static const struct t7000_fw_layout *const t7000_fw_layouts[] = { &t7000_fw_g4p_b0, }; +static const struct t7000_fw_layout *const t7001_fw_layouts[] = { + &t7000_fw_g4g_19h394, +}; + /* * The layout of the LDR file the user supplied, by its SHA-256. A file nobody * listed gets the A8's layout, as every file did before the table, unless the @@ -4115,6 +4247,8 @@ static const struct t7000_soc t7000_soc_a8 = { .platform_38 = t7000_platform_38, .mhz = t7000_mhz, .mv = t7000_mv, + .nr_mhz = ARRAY_SIZE(t7000_mhz), + .perf_states = 3, .perf_count = 16, .fence = true, .slc = true, @@ -4150,6 +4284,8 @@ static const struct t7000_soc t7000_soc_a7 = { .platform_38 = s5l8960x_platform_38, .mhz = s5l8960x_mhz, .mv = s5l8960x_mv, + .nr_mhz = ARRAY_SIZE(s5l8960x_mhz), + .perf_states = 3, .perf_count = 7, .rev_major = 1, .chip_info = { 1, 4, 4 }, @@ -4160,6 +4296,38 @@ static const struct t7000_soc t7000_soc_a7 = { .pbe_3d = 0xd8, }; +/* + * The A8X (T7001, iPad Air 2): the A8's power state, PLL and boot steps; its + * core is revision 7.5 (CORE_REVISION 0x00070500) and its firmware (AGXG4G) + * has four full-clock performance states (365, 450, 500 and 550 MHz) and the + * same four at half clock. The mV are fused per device and left to the DT + * (@mv NULL); the CSC block is not written (nothing uses the YUV path yet). + * Provisional: the bridge store, the chip info (Orchard's kernelcache values, + * unproven) and the 3D record words are completed with the SoC's own patches. + */ +static const u32 t7001_mhz[9] = { 0, 365, 450, 500, 550, 182, 225, 250, 275 }; + +static const struct t7000_soc t7000_soc_a8x = { + .border_fw = T7000_BORDER_FW, + .ps_gfx = T7000_PMGR_PS_GFX, + .pll = T7000_PMGR_PLL5, + .pll_lock = T7000_PLL_LOCKED, + .a8_globals = true, + .bridge_reg = 0x18, + .bridge_val = 0x80010004, + .mhz = t7001_mhz, + .nr_mhz = ARRAY_SIZE(t7001_mhz), + .perf_states = 4, + .perf_count = 16, + .fence = true, + .slc = true, + .rev_major = 7, + .chip_info = { 3, 2, 8 }, + .settle_ms = 100, + .te_psg = 0x00020000, + .pbe_3d = 0x158, +}; + /* * Performance state floor/ceiling for the A8 firmware governor * (1 = 365 MHz, 2 = 450 MHz, 3 = 500 MHz). Both default to 1 (Apple's @@ -4201,20 +4369,9 @@ static void t7000_perf_range(const struct t7000_soc *soc, u32 q, u32 *pmin, u32 * pinned (Apple: state 1, 0x846eb10). CONTROL +0xcd0..+0xcd8, the * performance controller's inputs, stay zero as in Apple's live CONTROL. */ -static void t7000_init_build(struct pvr_apple *apple, u32 q) +static void t7000_platform_build(struct pvr_apple *apple) { - static const u8 rings[] = { - S8003_WORK_CTL, S8003_WORK_RING, S8003_WORK_CTL + 4, S8003_WORK_RING + 4, - S8003_WORK_CTL + 8, S8003_WORK_RING + 8, S8003_DC_CTL, S8003_DC_RING, - S8003_EVENT_CTL, S8003_EVENTS, S8003_LOG_CTL, S8003_LOGS, - S8003_STATS_CTL, S8003_STATS, S8003_TRACE_CTL, S8003_TRACE, - }; - static const u8 objects[] = { - S8003_CHANNEL, S8003_CHANNEL + 1, S8003_CHANNEL + 2, S8003_POLICY, 0x4b, - }; - static const u8 tail[] = { 0x4e, 0x4c, S8003_PLATFORM, S8003_TAG_SEEN, 0x4f }; struct pvr_apple_s8003 *s = apple->chip_data; - const struct s8003_layout *layout = &s->layout; const struct { u64 phys; u32 addr; @@ -4230,37 +4387,10 @@ static void t7000_init_build(struct pvr_apple *apple, u32 q) }; const struct t7000_soc *soc = s->v->soc; const struct t7000_fw_layout *fw = s->fwlay; - u8 *init, *platform, *policy, *control, *o4c; - u32 pmin, pmax; + u8 *platform = s8003_object(s, S8003_PLATFORM); + u8 *o4c = s8003_object(s, 0x4c); unsigned int i; - memset(s->root.map, 0, T7000_ROOT_SIZE); - memset(s->shared.map, 0, T7000_SHARED_SIZE); - init = s8003_object(s, S8003_INIT); - platform = s8003_object(s, S8003_PLATFORM); - policy = s8003_object(s, S8003_POLICY); - control = s8003_object(s, S8003_CONTROL); - o4c = s8003_object(s, 0x4c); - - for (i = 0; i < ARRAY_SIZE(rings); i++) - put32(init + 4 * i, s8003_object_addr(layout, rings[i])); - for (i = 0; i < ARRAY_SIZE(objects); i++) - put32(init + fw->init_objects + 4 * i, s8003_object_addr(layout, objects[i])); - for (i = 0; i < ARRAY_SIZE(tail); i++) - put32(init + fw->init_tail + 4 * i, s8003_object_addr(layout, tail[i])); - /* No core memory: the image's end, size 0 (0x84724c4; P4 0x40024000, 0xe1c0024000, 0) */ - put32(init + fw->init_coremem, (lower_32_bits(S8003_IMAGE_VA + T7000_IMAGE_SIZE) + 0x40000000) | - 0x40000000); - put64(init + fw->init_coremem + 4, S8003_IMAGE_VA + T7000_IMAGE_SIZE); - /* Channel headers {0, self, 0, self + 8}; no channel 1 +0x778 on the A8 */ - for (i = 0; i < 3; i++) { - u8 *channel = s8003_object(s, S8003_CHANNEL + i); - u32 addr = s8003_object_addr(layout, S8003_CHANNEL + i); - - put32(channel + 4, addr); - put32(channel + 12, addr + 8); - } - /* The heaps' bases (DAT 0x712f910): +0x20/+0x28 is the PDS and USC execution base */ put64(platform + 0x00, 0x500000000ull); put64(platform + 0x08, 0x600000000ull); @@ -4268,8 +4398,9 @@ static void t7000_init_build(struct pvr_apple *apple, u32 q) put64(platform + 0x18, 0x100000000ull); put64(platform + 0x20, 0x300000000ull); put64(platform + 0x28, 0x300000000ull); - for (i = 0; i < ARRAY_SIZE(t7000_platform_38); i++) - put32(platform + 0x38 + 4 * i, soc->platform_38[i]); + if (soc->platform_38) + for (i = 0; i < ARRAY_SIZE(t7000_platform_38); i++) + put32(platform + 0x38 + 4 * i, soc->platform_38[i]); for (i = 0; i < ARRAY_SIZE(pio); i++) { u8 *entry = platform + fw->plat_pio + 16 * i; @@ -4277,28 +4408,19 @@ static void t7000_init_build(struct pvr_apple *apple, u32 q) put32(entry + 8, pio[i].addr); put32(entry + 12, pio[i].size); } - put32(platform + 0x250, 1); /* Fender boot */ - put32(platform + 0x254, 1); /* gpu_lockup_detection */ - put32(platform + 0x258, 1); /* PIO supported */ - put32(platform + 0x274, 1); /* agf_timeslice */ - put32(platform + 0x278, 1); - put32(platform + 0x27c, 1); /* agf_timer */ - put32(platform + 0x280, 1000 * 0x18); /* agf_timer_period, 24 MHz ticks */ - put32(platform + 0x284, 0x10); - put32(platform + 0x290, 1); /* agf_dwb */ - put32(platform + 0x294, 1); /* agf_itr_cache */ - put32(platform + 0x29c, 1); /* agf_deferred_opaque */ - put32(platform + 0x2b4, 0x1f); /* agf_max_tiles_per_pipe */ - put32(platform + 0x2dc, 1); /* agf_frg_vce_inval */ + for (i = 0; i < fw->nr_plat_flags; i++) + put32(platform + fw->plat_flags[i][0], fw->plat_flags[i][1]); /* chip info {major class, minor class, cores}: the A8's {2, 4, 4} */ - for (i = 0; i < 3; i++) - put32(platform + fw->plat_chip_info + 4 * i, - s->chip_info[0] ? s->chip_info[i] : soc->chip_info[i]); - put32(platform + fw->plat_perf_hi, 3); /* the highest performance state */ + if (fw->plat_chip_info) + for (i = 0; i < 3; i++) + put32(platform + fw->plat_chip_info + 4 * i, + s->chip_info[0] ? s->chip_info[i] : soc->chip_info[i]); + put32(platform + fw->plat_perf_hi, soc->perf_states); /* the highest performance state */ put32(platform + fw->plat_perf_count, soc->perf_count); - for (i = 0; i < ARRAY_SIZE(s->mhz); i++) { + for (i = 0; i < soc->nr_mhz; i++) { put32(platform + fw->plat_mhz + 4 * i, s->mhz[i]); - put32(platform + fw->plat_mv + 4 * i, s->mv[i]); + if (fw->plat_mv) + put32(platform + fw->plat_mv + 4 * i, s->mv[i]); } /* The interrupt to the host: its word and bit among the AIC's software sets (P4 0x10, 0x400) */ put32(platform + fw->plat_irq, 4 * (s->irq / 32)); @@ -4308,9 +4430,81 @@ static void t7000_init_build(struct pvr_apple *apple, u32 q) put32(platform + fw->plat_thread + 4, s->thread_sp); put64(platform + fw->plat_image_va, S8003_IMAGE_VA); put64(platform + fw->plat_vm_ptr, 0x700000000ull); /* DAT 0x712fab8 */ - put32(platform + 0x4c8, 0xffff); /* agf_gtp_ks */ - put32(platform + 0x4cc, 7); /* agf_frg_ks */ - put32(platform + 0x4d0, 7); /* agf_compute_ks */ + + /* The hardware objects, fresh, and their names */ + for (i = 0; i < T7000_HW_OBJS; i++) + memset(s->hwobj[i].map, 0, T7000_HWOBJ_SIZE); + memcpy(s->hwobj[T7000_HW_BORDER].map, s->border, T7000_BORDER_SIZE); + if (s->a7_scratch.map) + memset(s->a7_scratch.map, 0, PVR_DEVICE_PAGE_SIZE); + put64(platform + 0x30, T7000_HWOBJ_VA + t7000_hwobj_offset[T7000_HW_YUV]); + put64(platform + fw->plat_border, T7000_HWOBJ_VA + t7000_hwobj_offset[T7000_HW_BORDER]); + put64(o4c, T7000_HWOBJ_VA + t7000_hwobj_offset[T7000_HW_BRN44455]); + if (soc->fence) { + put64(platform + fw->plat_fence, T7000_HWOBJ_VA + t7000_hwobj_offset[T7000_HW_FENCE]); + put64(o4c + 8, T7000_HWOBJ_VA + t7000_hwobj_offset[T7000_HW_FENCE]); + } +} + +/* + * The A8X: s8003_init_build() writes INIT, CONTROL and POLICY at the A9's + * offsets, then this the A8-shaped PLATFORM and POLICY's two words the A9 + * has none of (19H394's boot path: the state count x 100). + */ +static void t7001_init_chip(struct pvr_apple *apple) +{ + struct pvr_apple_s8003 *s = apple->chip_data; + u8 *policy = s8003_object(s, S8003_POLICY); + + t7000_platform_build(apple); + put32(policy + 0x6fc, 100 * s->v->perf_states); + put32(policy + 0x7cc, 100 * s->v->perf_states); +} + +static void t7000_init_build(struct pvr_apple *apple, u32 q) +{ + static const u8 rings[] = { + S8003_WORK_CTL, S8003_WORK_RING, S8003_WORK_CTL + 4, S8003_WORK_RING + 4, + S8003_WORK_CTL + 8, S8003_WORK_RING + 8, S8003_DC_CTL, S8003_DC_RING, + S8003_EVENT_CTL, S8003_EVENTS, S8003_LOG_CTL, S8003_LOGS, + S8003_STATS_CTL, S8003_STATS, S8003_TRACE_CTL, S8003_TRACE, + }; + static const u8 objects[] = { + S8003_CHANNEL, S8003_CHANNEL + 1, S8003_CHANNEL + 2, S8003_POLICY, 0x4b, + }; + static const u8 tail[] = { 0x4e, 0x4c, S8003_PLATFORM, S8003_TAG_SEEN, 0x4f }; + struct pvr_apple_s8003 *s = apple->chip_data; + const struct s8003_layout *layout = &s->layout; + const struct t7000_soc *soc = s->v->soc; + const struct t7000_fw_layout *fw = s->fwlay; + u8 *init, *policy, *control; + u32 pmin, pmax; + unsigned int i; + + memset(s->root.map, 0, T7000_ROOT_SIZE); + memset(s->shared.map, 0, T7000_SHARED_SIZE); + init = s8003_object(s, S8003_INIT); + policy = s8003_object(s, S8003_POLICY); + control = s8003_object(s, S8003_CONTROL); + + for (i = 0; i < ARRAY_SIZE(rings); i++) + put32(init + 4 * i, s8003_object_addr(layout, rings[i])); + for (i = 0; i < ARRAY_SIZE(objects); i++) + put32(init + fw->init_objects + 4 * i, s8003_object_addr(layout, objects[i])); + for (i = 0; i < ARRAY_SIZE(tail); i++) + put32(init + fw->init_tail + 4 * i, s8003_object_addr(layout, tail[i])); + /* No core memory: the image's end, size 0 (0x84724c4; P4 0x40024000, 0xe1c0024000, 0) */ + put32(init + fw->init_coremem, (lower_32_bits(S8003_IMAGE_VA + T7000_IMAGE_SIZE) + 0x40000000) | + 0x40000000); + put64(init + fw->init_coremem + 4, S8003_IMAGE_VA + T7000_IMAGE_SIZE); + /* Channel headers {0, self, 0, self + 8}; no channel 1 +0x778 on the A8 */ + for (i = 0; i < 3; i++) { + u8 *channel = s8003_object(s, S8003_CHANNEL + i); + u32 addr = s8003_object_addr(layout, S8003_CHANNEL + i); + + put32(channel + 4, addr); + put32(channel + 12, addr + 8); + } put32(policy + 0x04, 0x10); put64(policy + 0x10, 0x3f800000); @@ -4336,19 +4530,7 @@ static void t7000_init_build(struct pvr_apple *apple, u32 q) put64(s8003_object(s, S8003_MMU_ROOT), pvr_vm_get_page_table_root_addr(apple->pvr_dev->kernel_vm_ctx)); - /* The hardware objects, fresh, and their names */ - for (i = 0; i < T7000_HW_OBJS; i++) - memset(s->hwobj[i].map, 0, T7000_HWOBJ_SIZE); - memcpy(s->hwobj[T7000_HW_BORDER].map, s->border, T7000_BORDER_SIZE); - if (s->a7_scratch.map) - memset(s->a7_scratch.map, 0, PVR_DEVICE_PAGE_SIZE); - put64(platform + 0x30, T7000_HWOBJ_VA + t7000_hwobj_offset[T7000_HW_YUV]); - put64(platform + fw->plat_border, T7000_HWOBJ_VA + t7000_hwobj_offset[T7000_HW_BORDER]); - put64(o4c, T7000_HWOBJ_VA + t7000_hwobj_offset[T7000_HW_BRN44455]); - if (soc->fence) { - put64(platform + fw->plat_fence, T7000_HWOBJ_VA + t7000_hwobj_offset[T7000_HW_FENCE]); - put64(o4c + 8, T7000_HWOBJ_VA + t7000_hwobj_offset[T7000_HW_FENCE]); - } + t7000_platform_build(apple); } /* @@ -6780,8 +6962,10 @@ static int t7000_perf_rows(struct pvr_apple_s8003 *s) const struct t7000_soc *soc = s->v->soc; unsigned int level; - memcpy(s->mhz, soc->mhz, sizeof(s->mhz)); - memcpy(s->mv, soc->mv, sizeof(s->mv)); + /* the SoC's rows (A8: 7, A8X: fewer, and no mV table); the A7's come from the OPP table below */ + memcpy(s->mhz, soc->mhz, min_t(size_t, soc->nr_mhz, ARRAY_SIZE(s->mhz)) * sizeof(*s->mhz)); + if (soc->mv) + memcpy(s->mv, soc->mv, min_t(size_t, soc->nr_mhz, ARRAY_SIZE(s->mv)) * sizeof(*s->mv)); if (!of_property_present(dev->of_node, "operating-points-v2")) return 0; @@ -6885,6 +7069,10 @@ static const struct s8003_variant s8003_variant_a9 = { .map = s8003_map, .unmap = s8003_unmap, .init_build = s8003_init_build, + .init_chip = s8003_init_chip, + .coremem = S8003_IMAGE_COREMEM, + .coremem_size = S8003_IMAGE_COREMEM_SIZE, + .perf_states = ARRAY_SIZE(s8003_mhz) - 1, .channels_init = s8003_channels_init, .boot = s8003_boot, .release = s8003_release, @@ -6995,6 +7183,60 @@ static const struct s8003_variant s8003_variant_a7 = { .event_fault = t7000_event_fault, }; +/* + * The A8X: the A8's SoC steps, boot and objects in the kernel VM, the A9's + * INIT, CONTROL, POLICY and channels, its own PLATFORM (t7001_init_chip()). + * Its jobs take the A9's record and PM control forms. + */ +static const struct s8003_variant s8003_variant_a8x = { + .name = "A8X", + .soc = &t7000_soc_a8x, /* patch 7 */ + .fws = t7001_fw_layouts, + .nr_fws = ARRAY_SIZE(t7001_fw_layouts), + .page_size = SZ_4K, + .image_size = T7001_IMAGE_SIZE, + .root_size = T7000_ROOT_SIZE, + .shared_size = T7000_SHARED_SIZE, + .root_objects_end = T7000_ROOT_OBJECTS_END, + .shared_objects_end = T7000_SHARED_OBJECTS_END, + .objects = s8003_objects_a8x, + .nr_objects = ARRAY_SIZE(s8003_objects_a8x), + .ring_ctl_size = T7001_RING_CTL_SIZE, + .slots = T7000_SLOTS, + .slot_first = T7000_SLOT_FIRST, + .vm_slots = 1, + .channel = { T7000_TA_CHANNEL, T7000_3D_CHANNEL, T7000_CU_CHANNEL }, + .channels_root = true, + .ldr_conf_count = S8003_LDR_CONF_MAX, + .ldr = &t7000_ldr_target, + .init = t7000_init, + .image_configure = t7000_image_configure, + .map = t7000_map, + .unmap = t7000_unmap, + .init_build = s8003_init_build, + .init_chip = t7001_init_chip, + .coremem = T7001_IMAGE_COREMEM, + .coremem_size = T7001_IMAGE_COREMEM_SIZE, + .perf_states = 4, + .channels_init = s8003_channels_init, + .boot = t7000_boot, + .release = t7000_release, + .core_off = t7000_core_off, + .idle = t7000_idle, + .doorbell = t7000_doorbell, + .no_alive = t7000_no_alive, + .vm_map = t7000_vm_map, + .vm_put = t7000_vm_put, + .vm_unmap = t7000_vm_unmap, + .engine_done = t7000_engine_done, + .prepare_job = t7000_prepare_job, + .submit_geom = t7000_submit_geom, + .submit_frag = t7000_submit_frag, + .submit_compute = t7000_submit_compute, + .report_hang = t7000_report_hang, + .event_fault = t7000_event_fault, +}; + static const struct s8003_variant *s8003_variant_of(const struct pvr_apple_chip *chip) { if (chip == &pvr_apple_chip_t7000) From aef39a134a9b4f060459afd10b9862cad21ab744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pu=C5=A1k=C3=A1=C4=8D?= Date: Thu, 3 Dec 2026 14:41:17 +0100 Subject: [PATCH 04/14] drm/imagination: apple: t7000: derive the A8X image layout from the LDR records MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The load records of the A8X LDR give the four segments, the core memory, the image size and the handover offset (segment = address bits 29-30, laid out in the order 2, 0, 1, 3, then core memory; core-memory ZEROMEMs skipped), as the firmware's own loader computes them. Do it at probe for variants with ldr_layout set instead of keeping a table of numbers. The ring-lane size cannot be derived and stays open. Compile-checked only. Assisted-by: LLM Signed-off-by: Martin Puškáč --- drivers/gpu/drm/imagination/pvr_apple_s8003.c | 179 +++++++++++++++--- 1 file changed, 149 insertions(+), 30 deletions(-) diff --git a/drivers/gpu/drm/imagination/pvr_apple_s8003.c b/drivers/gpu/drm/imagination/pvr_apple_s8003.c index 1746478665816b..7abe68b2085cf8 100644 --- a/drivers/gpu/drm/imagination/pvr_apple_s8003.c +++ b/drivers/gpu/drm/imagination/pvr_apple_s8003.c @@ -230,6 +230,11 @@ enum { */ #define S8003_DRAIN_MS 100 +/* An image segment: META address (bit 31 clear), size, offset in the image */ +struct t7000_seg { + u32 base, size, offset; +}; + struct s8003_layout { u32 offset[S8003_OBJECTS]; u8 shared[S8003_OBJECTS]; /* in the shared memory, not the root */ @@ -379,6 +384,8 @@ struct s8003_variant { /* s8003_init_build(): the words the chip's firmware has its own layout for (PLATFORM) */ void (*init_chip)(struct pvr_apple *apple); u32 coremem, coremem_size; /* core memory's contents in the image (s8003_init_build()) */ + /* optional: the image layout from the LDR's records instead of the A8 table (t7000_ldr_layout()) */ + int (*image_layout)(struct pvr_apple_s8003 *s, const u8 *fw, size_t fw_size); u32 perf_states; /* the governor's states above 0 (s8003_init_pins()) */ void (*channels_init)(struct pvr_apple_s8003 *s); int (*boot)(struct pvr_apple *apple); @@ -596,6 +603,10 @@ struct pvr_apple_s8003 { struct s8003_layout layout; u8 *image; /* the unpacked image, as the bootloader finds it */ + u32 image_size; /* v->image_size, or the LDR's (t7000_ldr_layout()) */ + u32 coremem, coremem_size; /* v->coremem/_size, or the LDR's */ + const struct t7000_seg *segs; /* the A8 path's segments: t7000_segments[] or @ldr_segs */ + struct t7000_seg ldr_segs[4]; u32 conf[S8003_LDR_CONF_MAX][2]; u32 conf_count; u32 thread_sp; @@ -1014,9 +1025,9 @@ static void s8003_init_build(struct pvr_apple *apple, u32 q) put32(s8003_object(s, S8003_CHANNEL + 1) + 0x778, 0xffffffff); /* Core memory's contents: uncached address, GPU address, size */ put32(init + 0x480, - (lower_32_bits(S8003_IMAGE_VA + v->coremem) + 0x40000000) | 0x40000000); - put64(init + 0x484, S8003_IMAGE_VA + v->coremem); - put32(init + 0x48c, v->coremem_size); + (lower_32_bits(S8003_IMAGE_VA + s->coremem) + 0x40000000) | 0x40000000); + put64(init + 0x484, S8003_IMAGE_VA + s->coremem); + put32(init + 0x48c, s->coremem_size); put64(policy + 8, 0x400000000ull); put64(policy + 0x10, 0x3f800000); @@ -3503,12 +3514,6 @@ static int pvr_apple_s8003_init(struct pvr_apple *apple) if (err) return err; - s->image = kvzalloc(v->image_size, GFP_KERNEL); - if (!s->image) - return -ENOMEM; - err = devm_add_action_or_reset(dev, s8003_free_image, s->image); - if (err) - return err; err = pvr_apple_fw_load(apple, SZ_1M); if (err) return err; @@ -3517,6 +3522,21 @@ static int pvr_apple_s8003_init(struct pvr_apple *apple) if (!s->fwlay) return -ENODEV; } + s->image_size = v->image_size; + s->coremem = v->coremem; + s->coremem_size = v->coremem_size; + if (v->image_layout) { + err = v->image_layout(s, apple->fw_image, apple->fw_size); + if (err) + return dev_err_probe(dev, err, "no %s image layout in the GFX firmware\n", + v->name); + } + s->image = kvzalloc(s->image_size, GFP_KERNEL); + if (!s->image) + return -ENOMEM; + err = devm_add_action_or_reset(dev, s8003_free_image, s->image); + if (err) + return err; err = pvr_meta_ldr_process(from_pvr_device(apple->pvr_dev), apple->fw_image, apple->fw_size, v->ldr, s, NULL); if (!err && (!s->thread_pc || (v->ldr_conf_count && s->conf_count != v->ldr_conf_count))) @@ -3576,7 +3596,7 @@ static int pvr_apple_s8003_start(struct pvr_apple *apple) return err; } /* The firmware writes into its image while it runs: start from the copy */ - memcpy(s->fw.map, s->image, v->image_size); + memcpy(s->fw.map, s->image, s->image_size); v->init_build(apple, q); s8003_jobs_reset(s); @@ -3837,9 +3857,6 @@ static const struct s8003_object_size s8003_objects_a8[] = { * 0x4c and the 8-slot tables the A8's, PLATFORM its own. Its image and ring * lanes: see T7001_*. */ -#define T7001_IMAGE_SIZE 0 /* TBD: the private layout table (patches 3-4) */ -#define T7001_IMAGE_COREMEM 0 /* TBD: where patch 4 places core memory */ -#define T7001_IMAGE_COREMEM_SIZE 0 /* TBD: the LDR's core-memory section */ #define T7001_RING_CTL_SIZE T7000_RING_CTL_SIZE /* unknown: 0x20 or 0x30, lanes 1-3 unmeasured */ static const struct s8003_object_size s8003_objects_a8x[] = { @@ -3875,29 +3892,132 @@ static const struct s8003_object_size s8003_objects_a8x[] = { { S8003_MMU_ROOT, true, 0x40 }, }; -/* The image's segments: META address (bit 31 clear), size, offset in the image */ -static const struct { - u32 base, size, offset; -} t7000_segments[4] = { +/* The A8's image segments (iOS 12.4 g4p_b0, 0x84727c8) */ +static const struct t7000_seg t7000_segments[4] = { { 0x10000000, 0x1e000, 0x01000 }, { 0x20000000, 0x03000, 0x1f000 }, { 0x40000000, 0x01000, 0x00000 }, /* the bootloader's: not configured (0x8471b0c) */ { 0x60000000, 0x02000, 0x22000 }, }; +#define T7000_COREMEM_BASE 0x80000080 /* the 19H394 loader's constant */ + +/* + * The image layout as the A8X's kext derives it from the LDR (19H394 + * 0x668fc0c..0x668fe24): per segment (address bits 29-30) the extent of the + * LOADMEM and ZEROMEM records, each rounded up to a GPU page; segments 2, 0, + * 1, 3 in that order; then core memory's LOADMEM extent from + * T7000_COREMEM_BASE. Core memory's ZEROMEM records (the stacks) are skipped. + */ +static int t7000_ldr_layout(struct pvr_apple_s8003 *s, const u8 *fw, size_t fw_size) +{ + static const u8 order[] = { 2, 0, 1, 3 }; + u32 lo[4] = { U32_MAX, U32_MAX, U32_MAX, U32_MAX }, hi[4] = {}, core_end = 0; + u32 off, pos = 0, n = 0; + unsigned int i; + + if (fw_size < sizeof(struct rogue_meta_ldr_l1_data_blk)) + return -EINVAL; + off = get_unaligned_le32(fw + offsetof(struct rogue_meta_ldr_block_hdr, sl_data)); + while (off != U32_MAX) { + u16 cmd; + u32 addr, size; + + if (off > fw_size - sizeof(struct rogue_meta_ldr_l1_data_blk) || + ++n > fw_size / sizeof(struct rogue_meta_ldr_l1_data_blk)) + return -EINVAL; + cmd = get_unaligned_le16(fw + off); + addr = get_unaligned_le32(fw + off + 8); /* cmd_data[0] */ + size = get_unaligned_le32(fw + off + 12); /* cmd_data[1] */ + off = get_unaligned_le32(fw + off + 4); /* next */ + if (ROGUE_META_LDR_BLK_IS_COMMENT(cmd)) + continue; + cmd &= ROGUE_META_LDR_CMD_MASK; + if (cmd == ROGUE_META_LDR_CMD_LOADMEM) { + /* cmd_data[1] is the L2 block: tag, length (data + 6), data */ + u32 l2 = size, len; + + if (l2 > fw_size - sizeof(struct rogue_meta_ldr_l2_data_blk)) + return -EINVAL; + len = get_unaligned_le16(fw + l2 + 2); + if (len < 6 || len - 6 > fw_size - l2 - 4) + return -EINVAL; + size = len - 6; + } else if (cmd != ROGUE_META_LDR_CMD_ZEROMEM) { + continue; + } + if (!size || !(addr >> 27)) + continue; + if ((addr & BIT(31)) && addr < 0x87ffffff) { + u32 c = addr - T7000_COREMEM_BASE; + + if (cmd != ROGUE_META_LDR_CMD_LOADMEM || c >> 7 >= 0x17f) + continue; + if (size > (0x17f << 7) - c) /* past the core-memory window */ + return -EINVAL; + core_end = max(core_end, c + size); + continue; + } + i = (addr >> 29) & 3; + addr &= 0x7fffffff; + if (size > U32_MAX - addr) + return -EINVAL; + lo[i] = min(lo[i], addr); + hi[i] = max(hi[i], addr + size); + } + for (i = 0; i < ARRAY_SIZE(order); i++) { + struct t7000_seg *sg = &s->ldr_segs[order[i]]; + + sg->base = hi[order[i]] ? lo[order[i]] : 0; + sg->size = hi[order[i]] ? ALIGN(hi[order[i]] - lo[order[i]], PVR_DEVICE_PAGE_SIZE) : 0; + sg->offset = pos; + pos += sg->size; + } + /* + * The bootloader's configuration (+0x200) and the handover (+0xff8) must + * be where t7000_image_configure() puts them, behind seg2's own bytes, and + * segments 0, 1 and 3 must exist: their MMU words are always written. + */ + if (s->ldr_segs[2].size != PVR_DEVICE_PAGE_SIZE || s->ldr_segs[2].base != 0x40000000 || + hi[2] - lo[2] > S8003_IMAGE_CONF || !hi[0] || !hi[1] || !hi[3]) + return -EINVAL; + /* The image ends below the shared memory's VA */ + if (ALIGN(pos + core_end, PVR_DEVICE_PAGE_SIZE) > S8003_SHARED_VA - S8003_IMAGE_VA) + return -EINVAL; + s->segs = s->ldr_segs; + s->coremem = pos; + s->coremem_size = core_end; + s->image_size = ALIGN(pos + core_end, PVR_DEVICE_PAGE_SIZE); + return 0; +} + /* Where a section of the LDR image goes, as 0x8472a00 reads it */ static int t7000_ldr_mem(void *data, u32 addr, u32 size, bool zero, void **write_addr) { struct pvr_apple_s8003 *s = data; - u32 seg = (addr >> 29) & 3, a = addr & 0x7fffffff; + const struct t7000_seg *sg = &s->segs[(addr >> 29) & 3]; + u32 a = addr & 0x7fffffff; + + /* core memory (0x80000080..): the A8's image has none; the A8X's copy is in the image */ + if ((u32)(addr + 0x7fffff80) >> 7 < 0x17f) { + u32 c = addr - T7000_COREMEM_BASE; - /* core memory (0x80000080..): the A8's image has none */ - if ((u32)(addr + 0x7fffff80) >> 7 < 0x17f || !((addr >> 27) & 0xf)) + if (!s->coremem_size) + return -EINVAL; + if (zero) { /* stacks: not part of the copy (the kext skips them) */ + *write_addr = NULL; + return 0; + } + if (size > s->coremem_size || c > s->coremem_size - size) + return -EINVAL; + *write_addr = s->image + s->coremem + c; + return 0; + } + if (!((addr >> 27) & 0xf)) return -EINVAL; - if (a < t7000_segments[seg].base || size > t7000_segments[seg].size || - a - t7000_segments[seg].base > t7000_segments[seg].size - size) + if (a < sg->base || size > sg->size || a - sg->base > sg->size - size) return -EINVAL; - *write_addr = s->image + t7000_segments[seg].offset + a - t7000_segments[seg].base; + *write_addr = s->image + sg->offset + a - sg->base; return 0; } @@ -3935,13 +4055,13 @@ static void t7000_image_configure(struct pvr_apple_s8003 *s) unsigned int i; for (i = 0; i < ARRAY_SIZE(t7000_segments); i++) { - u64 out = S8003_IMAGE_VA + t7000_segments[i].offset; - u32 limit = max(t7000_segments[i].size - 1, 0xfffu); + u64 out = S8003_IMAGE_VA + s->segs[i].offset; + u32 limit = max(s->segs[i].size - 1, 0xfffu); if (i == 2) continue; put32(conf, META_CR_MMCU_SEGMENT_N_BASE(i)); - put32(conf + 4, t7000_segments[i].base | T7000_SEGMMU_ALLTHRS_WRITEABLE); + put32(conf + 4, s->segs[i].base | T7000_SEGMMU_ALLTHRS_WRITEABLE); put32(conf + 8, META_CR_MMCU_SEGMENT_N_LIMIT(i)); put32(conf + 12, limit); put32(conf + 16, META_CR_MMCU_SEGMENT_N_OUTA0(i)); @@ -3993,7 +4113,7 @@ static int t7000_map(struct pvr_apple *apple) unsigned int i; int err; - err = s8003_mem_init(apple, &s->fw, S8003_IMAGE_VA, T7000_IMAGE_SIZE, T7000_FW_FLAGS); + err = s8003_mem_init(apple, &s->fw, S8003_IMAGE_VA, s->image_size, T7000_FW_FLAGS); if (!err) err = s8003_mem_init(apple, &s->root, S8003_ROOT_VA, T7000_ROOT_SIZE, T7000_FW_FLAGS); if (!err) @@ -7017,6 +7137,7 @@ static int t7000_init(struct pvr_apple *apple) if (err) return err; + s->segs = t7000_segments; /* until a variant's image_layout replaces them */ s->pmgr = t7000_ioremap(dev, "pmgr"); s->bridges = t7000_ioremap(dev, "bridges"); if (!s->pmgr || !s->bridges) @@ -7194,7 +7315,7 @@ static const struct s8003_variant s8003_variant_a8x = { .fws = t7001_fw_layouts, .nr_fws = ARRAY_SIZE(t7001_fw_layouts), .page_size = SZ_4K, - .image_size = T7001_IMAGE_SIZE, + .image_layout = t7000_ldr_layout, /* image size, segments, core memory */ .root_size = T7000_ROOT_SIZE, .shared_size = T7000_SHARED_SIZE, .root_objects_end = T7000_ROOT_OBJECTS_END, @@ -7215,8 +7336,6 @@ static const struct s8003_variant s8003_variant_a8x = { .unmap = t7000_unmap, .init_build = s8003_init_build, .init_chip = t7001_init_chip, - .coremem = T7001_IMAGE_COREMEM, - .coremem_size = T7001_IMAGE_COREMEM_SIZE, .perf_states = 4, .channels_init = s8003_channels_init, .boot = t7000_boot, From 33e4eb5455480653f3ab0841a7862f57b9232c2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pu=C5=A1k=C3=A1=C4=8D?= Date: Thu, 3 Dec 2026 14:41:48 +0100 Subject: [PATCH 05/14] dt-bindings: gpu: apple,s8003-gpu: add the A8X (apple,t7001-gpu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The A8X's GPU (GXA6850, Apple's G4G) is the A8's family with eight clusters and a newer firmware. Its node has the A8's four register regions, no power domain (the driver switches ps_gfx itself after its PMGR stores, as on the A8), five interrupts (AIC 134-138, the last the firmware's interrupt to the host) and the settings of its two bus bridges as {offset, value} rows (apple,bridge-settings), so that the driver writes the values of the device's own firmware and never the A8's. The boot loader adds the rows from Apple's device tree, so a device tree source does not carry them and the schema does not require them; the driver refuses to probe without them. dt_binding_check was not run. Assisted-by: LLM Signed-off-by: Martin Puškáč --- .../bindings/gpu/apple,s8003-gpu.yaml | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/gpu/apple,s8003-gpu.yaml b/Documentation/devicetree/bindings/gpu/apple,s8003-gpu.yaml index 906e65d8d6f1ee..05753875ca5b8e 100644 --- a/Documentation/devicetree/bindings/gpu/apple,s8003-gpu.yaml +++ b/Documentation/devicetree/bindings/gpu/apple,s8003-gpu.yaml @@ -4,7 +4,7 @@ $id: http://devicetree.org/schemas/gpu/apple,s8003-gpu.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Apple S8000/S8003 (A9), T7000 (A8) and S5L8960X (A7) GPU +title: Apple S8000/S8003 (A9), T7000/T7001 (A8/A8X) and S5L8960X (A7) GPU maintainers: - Berkay Kösebay @@ -31,6 +31,13 @@ description: | power manager does. The S5L8965X, the iPad Air's variant of the A7, has the same GPU and takes its own compatible before the A7's. + The A8X's GPU (GXA6850, Apple's G4G) is the A8's family with eight clusters + and a newer firmware (AGXFirmwareKextG4G). Its node has the A8's registers + and, as the A8's, no power domain: the driver switches the GPU's power state + itself, after the power manager stores it must make first. The settings of + its two bus bridges come from the node, so that the driver writes the values + of the device's own firmware. + properties: compatible: oneOf: @@ -38,6 +45,7 @@ properties: - apple,s5l8960x-gpu - apple,s8003-gpu - apple,t7000-gpu + - apple,t7001-gpu - items: - const: apple,s8000-gpu - const: apple,s8003-gpu @@ -83,6 +91,20 @@ properties: Apple's bootloader sets them per chip; the bootloader that starts Linux (m1n1) fills an empty table from them. + apple,bridge-settings: + $ref: /schemas/types.yaml#/definitions/uint32-matrix + items: + items: + - description: Register offset, from the start of the bridges' region + - description: Value the driver writes there after every power-on + description: + The register stores of the GPU's two bus bridges (A8X), one row per + store, in the order the driver writes them. + The bootloader that starts Linux (m1n1) adds this property from + Apple's device tree: a device tree source does not carry it, so it is + not a required property of the schema, and the driver refuses to probe + without it. + firmware-name: maxItems: 1 description: @@ -107,6 +129,17 @@ allOf: reg-names: minItems: 4 power-domains: false + - if: + properties: + compatible: + const: apple,t7001-gpu + then: + properties: + reg: + minItems: 4 + reg-names: + minItems: 4 + power-domains: false - if: properties: compatible: @@ -211,3 +244,29 @@ examples: firmware-name = "apple/gfx-s5l8960x.bin"; }; }; + + - | + #include + #include + + soc { + #address-cells = <2>; + #size-cells = <2>; + + gpu@201000000 { + compatible = "apple,t7001-gpu"; + reg = <0x2 0x01000000 0x0 0x100000>, + <0x2 0x01e00000 0x0 0x100000>, + <0x2 0x0e000000 0x0 0x40000>, + <0x2 0x01f00000 0x0 0xc1000>; + reg-names = "rgx", "fender", "pmgr", "bridges"; + interrupt-parent = <&aic>; + interrupts = , + , + , + , + ; + apple,bridge-settings = <0x0 0x0>; + firmware-name = "apple/gfx-t7001.bin"; + }; + }; From 4392bfd69199d84f5e30c9a28ac6a0eaba186246 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pu=C5=A1k=C3=A1=C4=8D?= Date: Thu, 3 Dec 2026 14:52:51 +0100 Subject: [PATCH 06/14] drm/imagination: apple: t7000: bridge settings from the device tree for the A8X MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The A8 path writes one store and a table of 32 words (Apple's values for the A8's bridges) after every GPU power-on. The A8X's firmware has its own settings, so for variants with bridges_from_dt the driver writes the node's apple,bridge-settings {offset, value} rows instead, and refuses a missing, odd-sized or out-of-region list at probe. The A8's bridge_reg/bridge_val are no longer set for the A8X. Compile-checked only; not run on hardware. Assisted-by: LLM Signed-off-by: Martin Puškáč --- drivers/gpu/drm/imagination/pvr_apple_s8003.c | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/imagination/pvr_apple_s8003.c b/drivers/gpu/drm/imagination/pvr_apple_s8003.c index 7abe68b2085cf8..aad9b932d6c831 100644 --- a/drivers/gpu/drm/imagination/pvr_apple_s8003.c +++ b/drivers/gpu/drm/imagination/pvr_apple_s8003.c @@ -269,6 +269,7 @@ struct t7000_soc { u32 pll, pll_lock; /* the GPU PLL's lock bit in the PMGR */ bool a8_globals; /* perf records, voltage manager, SOC_TVM (A8) */ u32 bridge_reg, bridge_val; /* the first bridge's one store */ + bool bridges_from_dt; /* the bridge stores are the node's apple,bridge-settings rows (A8X) */ const u32 *platform_38; /* PLATFORM +0x38: the CSC block, 30 words */ const u32 *mhz, *mv; /* the ADT's perf-states, @nr_mhz rows; @mv may be NULL */ unsigned int nr_mhz; @@ -623,6 +624,8 @@ struct pvr_apple_s8003 { /* The A8's (T7000_*) */ void __iomem *pmgr; /* the power manager: GPU power state, PLL5 */ void __iomem *bridges; /* the GPU's two bus bridges */ + u32 (*bridge_set)[2]; /* A8X: the node's {offset, value} bridge stores */ + unsigned int nr_bridge_set; u8 *border; /* BorderColorTable's contents (firmware file) */ u32 chip_info[3]; /* PLATFORM +0x300..+0x308, from the core's ID */ u32 mhz[7], mv[7]; /* PLATFORM +0x314, +0x354: the performance rows */ @@ -4433,8 +4436,7 @@ static const struct t7000_soc t7000_soc_a8x = { .pll = T7000_PMGR_PLL5, .pll_lock = T7000_PLL_LOCKED, .a8_globals = true, - .bridge_reg = 0x18, - .bridge_val = 0x80010004, + .bridges_from_dt = true, .mhz = t7001_mhz, .nr_mhz = ARRAY_SIZE(t7001_mhz), .perf_states = 4, @@ -4839,6 +4841,9 @@ static bool t7000_ps_on(struct pvr_apple_s8003 *s) * Apple's bridge settings for the GPU (0x84a0098, from the ADT): one store to * bridge 10, 32 to bridge 11, after the GPU powers on. */ +#define T7001_BRIDGES_SIZE 0xc1000 /* the "bridges" region the node maps: the second bridge's table is at +0xc0000 */ +#define T7001_BRIDGE_ROWS_MAX 128u + static const u32 t7000_bridge11[32] = { 0x007c7c01, 0x007c7c01, 0x007c7c01, 0x007c7901, 0x007c7901, 0x007c7c01, 0x007c7c01, 0x007c7c01, 0x007c7c01, 0x007c7c01, 0x007c7c01, 0x007c7c01, 0x006c6901, 0x007c7901, @@ -4851,6 +4856,11 @@ static void t7000_bridges(struct pvr_apple_s8003 *s) { unsigned int i; + if (s->v->soc->bridges_from_dt) { + for (i = 0; i < s->nr_bridge_set; i++) + writel(s->bridge_set[i][1], s->bridges + s->bridge_set[i][0]); + return; + } writel(s->v->soc->bridge_val, s->bridges + s->v->soc->bridge_reg); for (i = 0; i < ARRAY_SIZE(t7000_bridge11); i++) writel(t7000_bridge11[i], s->bridges + 0x80000 + 4 * i); @@ -7143,6 +7153,29 @@ static int t7000_init(struct pvr_apple *apple) if (!s->pmgr || !s->bridges) return dev_err_probe(dev, -EINVAL, "no power manager or bridge registers\n"); + if (s->v->soc->bridges_from_dt) { + struct resource *res = platform_get_resource_byname(to_platform_device(dev), + IORESOURCE_MEM, "bridges"); + struct device_node *np = dev->of_node; + int n = of_property_count_u32_elems(np, "apple,bridge-settings"); + u32 bsize = res ? min_t(resource_size_t, resource_size(res), T7001_BRIDGES_SIZE) : 0; + unsigned int i; + + if (n <= 0 || n % 2 || n / 2 > T7001_BRIDGE_ROWS_MAX) + return dev_err_probe(dev, -EINVAL, "bad or missing apple,bridge-settings\n"); + s->nr_bridge_set = n / 2; + s->bridge_set = devm_kcalloc(dev, s->nr_bridge_set, sizeof(*s->bridge_set), GFP_KERNEL); + if (!s->bridge_set) + return -ENOMEM; + err = of_property_read_u32_array(np, "apple,bridge-settings", &s->bridge_set[0][0], n); + if (err) + return dev_err_probe(dev, err, "apple,bridge-settings\n"); + for (i = 0; i < s->nr_bridge_set; i++) + if (s->bridge_set[i][0] % 4 || bsize < 4 || s->bridge_set[i][0] > bsize - 4) + return dev_err_probe(dev, -EINVAL, "apple,bridge-settings row %u: offset %#x\n", + i, s->bridge_set[i][0]); + } + err = request_firmware(&border, s->v->soc->border_fw, dev); if (err) return dev_err_probe(dev, err, "no %s\n", s->v->soc->border_fw); From 31a223050bae31c48dc32d329399f5d1b519ba51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pu=C5=A1k=C3=A1=C4=8D?= Date: Thu, 3 Dec 2026 15:03:32 +0100 Subject: [PATCH 07/14] drm/imagination: apple: t7000: add the A8X chip (apple,t7001-gpu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pvr_apple_chip_t7001 is the A8's chip (the fields are shared through T7000_CHIP_COMMON) with its own firmware file, apple/gfx-t7001.bin, and the A8X variant. The core revision check accepts the A8X's 0x00070500, the chip info comes from the SoC data, the compatible is registered, and BVNC 7.5.8.3 (the J81's GXA6850) is listed as experimental, so the probe needs powervr.exp_hw_support=1 until a hardware run supports promoting it. Compile-checked only; not run on hardware. Assisted-by: LLM Signed-off-by: Martin Puškáč --- drivers/gpu/drm/imagination/pvr_apple.h | 1 + drivers/gpu/drm/imagination/pvr_apple_s8003.c | 122 ++++++++++-------- drivers/gpu/drm/imagination/pvr_device.c | 1 + drivers/gpu/drm/imagination/pvr_drv.c | 10 ++ 4 files changed, 80 insertions(+), 54 deletions(-) diff --git a/drivers/gpu/drm/imagination/pvr_apple.h b/drivers/gpu/drm/imagination/pvr_apple.h index 38ab492dd8389f..4e8b596a4549e3 100644 --- a/drivers/gpu/drm/imagination/pvr_apple.h +++ b/drivers/gpu/drm/imagination/pvr_apple.h @@ -29,6 +29,7 @@ extern const struct pvr_power_sequence_ops pvr_power_sequence_ops_apple; extern const struct pvr_apple_chip pvr_apple_chip_s5l8960x; extern const struct pvr_apple_chip pvr_apple_chip_s8003; extern const struct pvr_apple_chip pvr_apple_chip_t7000; +extern const struct pvr_apple_chip pvr_apple_chip_t7001; extern const struct pvr_apple_chip pvr_apple_chip_t8010; extern const struct pvr_apple_chip pvr_apple_chip_t8015; diff --git a/drivers/gpu/drm/imagination/pvr_apple_s8003.c b/drivers/gpu/drm/imagination/pvr_apple_s8003.c index aad9b932d6c831..69a746db517c5f 100644 --- a/drivers/gpu/drm/imagination/pvr_apple_s8003.c +++ b/drivers/gpu/drm/imagination/pvr_apple_s8003.c @@ -3705,6 +3705,7 @@ static int pvr_apple_s8003_prepare_job(struct pvr_apple *apple, struct pvr_job * /* The core this driver boots: CORE_REVISION major 3, minor 10 (readChipInfo 0x8479d14) */ #define T7000_CORE_REVISION 0x00030a00 +#define T7001_CORE_REVISION 0x00070500 /* the A8X's (19H394), as the module reads it */ /* The power manager's registers, from its base (ApplePMGR) */ #define T7000_PMGR_PLL5 0x5004 /* the GPU's PLL: bit 30 locked */ @@ -5000,6 +5001,8 @@ static bool t7000_rev_ok(struct pvr_apple_s8003 *s, u32 rev) if (s->v->soc->rev_major == 3) return rev == T7000_CORE_REVISION; + if (s->v->soc->rev_major == 7) + return rev == T7001_CORE_REVISION; return FIELD_GET(GENMASK(23, 16), rev) == 1 && !(rev & 0xff0000ff) && (minor == 0x32 || minor == 0x41 || minor == 0x46); } @@ -5040,8 +5043,8 @@ static int pvr_apple_t7000_read_gpu_id(struct pvr_apple *apple, struct pvr_gpu_i return -ENODEV; } /* readChipInfo: {2, 4} on the A8; {1, 3} or {1, 4} (minor 0x46) on the A7; the cores */ - s->chip_info[0] = s->v->soc->rev_major == 3 ? 2 : 1; - s->chip_info[1] = s->v->soc->rev_major == 3 ? 4 : + s->chip_info[0] = s->v->soc->rev_major == 3 ? 2 : s->v->soc->rev_major == 7 ? s->v->soc->chip_info[0] : 1; + s->chip_info[1] = s->v->soc->rev_major == 3 ? 4 : s->v->soc->rev_major == 7 ? s->v->soc->chip_info[1] : FIELD_GET(GENMASK(15, 8), rev) == 0x46 ? 4 : 3; s->chip_info[2] = FIELD_GET(GENMASK(15, 8), id); dev_info(apple_dev(apple), "%s GPU: CORE_REVISION %#010x CORE_ID %#010x\n", s->v->name, @@ -7344,7 +7347,7 @@ static const struct s8003_variant s8003_variant_a7 = { */ static const struct s8003_variant s8003_variant_a8x = { .name = "A8X", - .soc = &t7000_soc_a8x, /* patch 7 */ + .soc = &t7000_soc_a8x, .fws = t7001_fw_layouts, .nr_fws = ARRAY_SIZE(t7001_fw_layouts), .page_size = SZ_4K, @@ -7393,6 +7396,8 @@ static const struct s8003_variant *s8003_variant_of(const struct pvr_apple_chip { if (chip == &pvr_apple_chip_t7000) return &s8003_variant_a8; + if (chip == &pvr_apple_chip_t7001) + return &s8003_variant_a8x; if (chip == &pvr_apple_chip_s5l8960x) return &s8003_variant_a7; return &s8003_variant_a9; @@ -7485,59 +7490,68 @@ static const struct drm_pvr_heap t7000_heaps[] = { * of its states, and the host pins it there (PLATFORM, CONTROL). Jobs take * the A9's command streams: the A8's records hold the same registers. */ +#define T7000_CHIP_COMMON \ + .perf_state_max = 1, \ + .geom_stream = &pvr_apple_g5p_cmd_geom_stream, \ + .frag_stream = &pvr_apple_g5p_cmd_frag_stream, \ + .geom_ext_type = PVR_STREAM_EXTHDR_TYPE_GEOM_G5P, \ + .geom_ext_mask = PVR_STREAM_EXTHDR_GEOM_G5P_REGS, \ + .frag_ext_type = PVR_STREAM_EXTHDR_TYPE_FRAG_G5P, \ + .frag_ext_mask = PVR_STREAM_EXTHDR_FRAG_G5P_REGS, \ + .compute_stream = &pvr_apple_g5p_cmd_compute_stream, \ + .own_pm_pages = true, \ + /* Keep the core awake across consecutive 60 Hz (16.7 ms) frames. */ \ + .gate_off_ms = 40, \ + /* \ + * A firmware boot takes ~500 ms on the A8: stay on across reading \ + * pauses rather than stall the next touch. \ + */ \ + .autosuspend_ms = 10000, \ + .wait_deadline = true, \ + .fault_skips_done = true, \ + .irq_thread = true, \ + /* \ + * Between the firmware's interrupts the completion check runs every \ + * 250 us while jobs are pending: the A9's 1 ms was a sixth of an A8 \ + * compute job's wall clock. Memory only: the stamps and the rings. \ + */ \ + .irq_poll_us = 250, \ + .heaps = t7000_heaps, \ + .read_gpu_id = pvr_apple_t7000_read_gpu_id, \ + .report_fault = t7000_report_fault, \ + .debugfs_show = t7000_debugfs_show, \ + .debugfs_reset = t7000_debugfs_reset, \ + .job_retired = t7000_job_retired, \ + .poll_us = t7000_poll_us, \ + .recheck_us = t7000_recheck_us, \ + .irq_checked = t7000_irq_checked, \ + .joint = t7000_joint, \ + .init = pvr_apple_s8003_init, \ + .boot = pvr_apple_s8003_boot, \ + .start = pvr_apple_s8003_start, \ + .stop = pvr_apple_s8003_stop, \ + .idle = pvr_apple_s8003_idle, \ + .fini = pvr_apple_s8003_fini, \ + .restore_image = pvr_apple_s8003_restore_image, \ + .report_hang = pvr_apple_s8003_report_hang, \ + .prepare_job = pvr_apple_s8003_prepare_job, \ + .submit = pvr_apple_s8003_submit, \ + .engine_done = pvr_apple_s8003_engine_done, \ + .events = pvr_apple_s8003_events, \ + .vm_init = pvr_apple_s8003_vm_init, \ + .vm_fini = pvr_apple_s8003_vm_fini, \ + .mmu_flush = pvr_apple_s8003_mmu_flush, \ + .irq_ack = pvr_apple_s8003_irq_ack, + const struct pvr_apple_chip pvr_apple_chip_t7000 = { .fw_name = "apple/gfx-t7000.bin", - .perf_state_max = 1, - .geom_stream = &pvr_apple_g5p_cmd_geom_stream, - .frag_stream = &pvr_apple_g5p_cmd_frag_stream, - .geom_ext_type = PVR_STREAM_EXTHDR_TYPE_GEOM_G5P, - .geom_ext_mask = PVR_STREAM_EXTHDR_GEOM_G5P_REGS, - .frag_ext_type = PVR_STREAM_EXTHDR_TYPE_FRAG_G5P, - .frag_ext_mask = PVR_STREAM_EXTHDR_FRAG_G5P_REGS, - .compute_stream = &pvr_apple_g5p_cmd_compute_stream, - .own_pm_pages = true, - /* Keep the core awake across consecutive 60 Hz (16.7 ms) frames. */ - .gate_off_ms = 40, - /* - * A firmware boot takes ~500 ms on the A8: stay on across reading - * pauses rather than stall the next touch. - */ - .autosuspend_ms = 10000, - .wait_deadline = true, - .fault_skips_done = true, - .irq_thread = true, - /* - * Between the firmware's interrupts the completion check runs every - * 250 us while jobs are pending: the A9's 1 ms was a sixth of an A8 - * compute job's wall clock. Memory only: the stamps and the rings. - */ - .irq_poll_us = 250, - .heaps = t7000_heaps, - .read_gpu_id = pvr_apple_t7000_read_gpu_id, - .report_fault = t7000_report_fault, - .debugfs_show = t7000_debugfs_show, - .debugfs_reset = t7000_debugfs_reset, - .job_retired = t7000_job_retired, - .poll_us = t7000_poll_us, - .recheck_us = t7000_recheck_us, - .irq_checked = t7000_irq_checked, - .joint = t7000_joint, - .init = pvr_apple_s8003_init, - .boot = pvr_apple_s8003_boot, - .start = pvr_apple_s8003_start, - .stop = pvr_apple_s8003_stop, - .idle = pvr_apple_s8003_idle, - .fini = pvr_apple_s8003_fini, - .restore_image = pvr_apple_s8003_restore_image, - .report_hang = pvr_apple_s8003_report_hang, - .prepare_job = pvr_apple_s8003_prepare_job, - .submit = pvr_apple_s8003_submit, - .engine_done = pvr_apple_s8003_engine_done, - .events = pvr_apple_s8003_events, - .vm_init = pvr_apple_s8003_vm_init, - .vm_fini = pvr_apple_s8003_vm_fini, - .mmu_flush = pvr_apple_s8003_mmu_flush, - .irq_ack = pvr_apple_s8003_irq_ack, + T7000_CHIP_COMMON +}; + +/* The A8X: the A8's chip with its own firmware file (variant: s8003_variant_a8x) */ +const struct pvr_apple_chip pvr_apple_chip_t7001 = { + .fw_name = "apple/gfx-t7001.bin", + T7000_CHIP_COMMON }; /* diff --git a/drivers/gpu/drm/imagination/pvr_device.c b/drivers/gpu/drm/imagination/pvr_device.c index 580e76e7d91e3e..a6b569ecbd1f43 100644 --- a/drivers/gpu/drm/imagination/pvr_device.c +++ b/drivers/gpu/drm/imagination/pvr_device.c @@ -547,6 +547,7 @@ pvr_gpu_support_level(const struct pvr_gpu_id *gpu_id) return PVR_GPU_SUPPORTED; case PVR_PACKED_BVNC(1, 70, 4, 3): /* Apple A7 (S5L8960X), the J71's */ + case PVR_PACKED_BVNC(7, 5, 8, 3): /* Apple A8X (T7001), the J81's: GXA6850, 8 clusters */ return PVR_GPU_EXPERIMENTAL; default: diff --git a/drivers/gpu/drm/imagination/pvr_drv.c b/drivers/gpu/drm/imagination/pvr_drv.c index f84b607c829966..cb985237d2cabb 100644 --- a/drivers/gpu/drm/imagination/pvr_drv.c +++ b/drivers/gpu/drm/imagination/pvr_drv.c @@ -1572,6 +1572,12 @@ static const struct pvr_device_data pvr_device_data_apple_t7000 = { .apple_chip = &pvr_apple_chip_t7000, }; +static const struct pvr_device_data pvr_device_data_apple_t7001 = { + .pwr_ops = &pvr_power_sequence_ops_apple, + .apple_fw = true, + .apple_chip = &pvr_apple_chip_t7001, +}; + static const struct pvr_device_data pvr_device_data_apple_s5l8960x = { .pwr_ops = &pvr_power_sequence_ops_apple, .apple_fw = true, @@ -1597,6 +1603,10 @@ static const struct of_device_id dt_match[] = { .compatible = "apple,t7000-gpu", .data = &pvr_device_data_apple_t7000, }, + { + .compatible = "apple,t7001-gpu", + .data = &pvr_device_data_apple_t7001, + }, { .compatible = "apple,s5l8960x-gpu", .data = &pvr_device_data_apple_s5l8960x, From 6127e3965c37d1a4639225a93fa886379631e525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pu=C5=A1k=C3=A1=C4=8D?= Date: Thu, 3 Dec 2026 15:08:14 +0100 Subject: [PATCH 08/14] drm/imagination: apple: t7000: the A8X's power-up, in the order the J81 bring-up proved MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The A8X needs PMGR stores before its GPU power state is switched on: two PLL words, five memory-controller bank enables, the clock gating enable and the SoC voltage manager enable (with its status poll). They run as the last step of the probe (variant hook prepare), after the firmware's hash and layout are accepted and while the GPU is off; a word that is neither the expected old value nor the new one refuses the probe before anything is written. The node has no power-domains (genpd would power the domain on at attach, before the probe), so the driver owns the power state as on the A8: t7000_boot switches it on and t7000_ps_set sets AUTO_PM_EN (bit 28). The A8's performance-record check is gated on a8_globals, which the A8X does not set; the A8X's border file is its own; jobs are refused until the A9-form records exist. Whether each PMGR store is needed was never ablated. Compile-checked only; not run on hardware. Assisted-by: LLM Signed-off-by: Martin Puškáč --- drivers/gpu/drm/imagination/pvr_apple_s8003.c | 119 +++++++++++++++++- 1 file changed, 115 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/imagination/pvr_apple_s8003.c b/drivers/gpu/drm/imagination/pvr_apple_s8003.c index 69a746db517c5f..f6aee508b2e6d4 100644 --- a/drivers/gpu/drm/imagination/pvr_apple_s8003.c +++ b/drivers/gpu/drm/imagination/pvr_apple_s8003.c @@ -262,12 +262,28 @@ struct s8003_vm; * image layout, init builders, boot stream, start, stop and kicks); these * are the differences, and the A7's power manager's. */ +/* One PMGR store of the A8X's pre-power sequence: the word must read @old, then @val (under @mask) */ +struct t7001_pmgr_store { + u32 off, old, val, mask; +}; + struct t7000_soc { const char *border_fw; /* BorderColorTable: Apple's 0x800 bytes */ u32 ps_gfx; /* the GPU's power-state word in the PMGR */ bool ps_domain; /* that word is a Linux power domain's (A7) */ u32 pll, pll_lock; /* the GPU PLL's lock bit in the PMGR */ bool a8_globals; /* perf records, voltage manager, SOC_TVM (A8) */ + /* + * A8X: the PMGR stores that come before the GPU's power domain is + * switched on (in the order the bring-up module proved on the J81) and + * the checks around them. The driver then owns the power state (no + * power-domains in the node): t7000_ps_set() sets AUTO_PM_EN, bit 28. + */ + const struct t7001_pmgr_store *pmgr_prep; + unsigned int nr_pmgr_prep; + u32 pmgr_dwi; /* the DWI domain's power state word: 0xff before the stores */ + u32 tvm_status; /* SOC_TVM's status word: 1 once the enable took */ + u32 bridge_reg, bridge_val; /* the first bridge's one store */ bool bridges_from_dt; /* the bridge stores are the node's apple,bridge-settings rows (A8X) */ const u32 *platform_38; /* PLATFORM +0x38: the CSC block, 30 words */ @@ -379,6 +395,8 @@ struct s8003_variant { int (*init)(struct pvr_apple *apple); void (*image_configure)(struct pvr_apple_s8003 *s); + int (*prepare)(struct pvr_apple *apple); /* last step of the probe, after every refusal: the GPU is still off */ + bool no_jobs; /* the firmware boots, but the job records are not this firmware's yet */ int (*map)(struct pvr_apple *apple); void (*unmap)(struct pvr_apple *apple); void (*init_build)(struct pvr_apple *apple, u32 q); @@ -3559,7 +3577,7 @@ static int pvr_apple_s8003_init(struct pvr_apple *apple) layout->mmu_gen = offsetof(struct s8003_idle, mmu_gen); layout->event_consumer = offsetof(struct s8003_idle, event_consumer); layout->event_producer = offsetof(struct s8003_idle, event_producer); - return 0; + return v->prepare ? v->prepare(apple) : 0; } /* @@ -3689,6 +3707,11 @@ static int pvr_apple_s8003_prepare_job(struct pvr_apple *apple, struct pvr_job * { struct pvr_apple_s8003 *s = apple->chip_data; + if (s->v->no_jobs) { + dev_warn_once(apple_dev(apple), "%s: no jobs until the firmware's own records\n", + s->v->name); + return -EOPNOTSUPP; + } return s->v->prepare_job(apple, job); } @@ -4429,15 +4452,46 @@ static const struct t7000_soc t7000_soc_a7 = { * Provisional: the bridge store, the chip info (Orchard's kernelcache values, * unproven) and the 3D record words are completed with the SoC's own patches. */ +/* + * The A8X's PMGR stores before its power domain goes on, in the order the + * bring-up module ran them on the J81 (the old values are what iBoot leaves): + * the two PLL words, the five memory-controller bank enables, the clock + * gating enable and the SoC voltage manager enable. Whether each is needed + * was never ablated. + */ +#define T7001_MCC_BANK BIT(31) +#define T7001_MCC_CMP 0xbfffffffu /* bit 30 may change by itself */ +static const struct t7001_pmgr_store t7001_pmgr_prep[] = { + { 0x1008, 0x80480348, 0x40480348, ~0u }, + { 0x4008, 0x88480348, 0x48480348, ~0u }, + { 0x22000, 0x00000000, 0x00000000 | T7001_MCC_BANK, T7001_MCC_CMP }, + { 0x22090, 0x09070300, 0x09070300 | T7001_MCC_BANK, T7001_MCC_CMP }, + { 0x220a0, 0x09040300, 0x09040300 | T7001_MCC_BANK, T7001_MCC_CMP }, + { 0x220b0, 0x09060300, 0x09060300 | T7001_MCC_BANK, T7001_MCC_CMP }, + { 0x22130, 0x09040300, 0x09040300 | T7001_MCC_BANK, T7001_MCC_CMP }, + { 0x32000, 0, 1, ~0u }, /* T7000_PMGR_MISC_ACG */ + { 0x2d000, 0, 1, ~0u }, /* T7000_PMGR_SOC_TVM */ +}; + static const u32 t7001_mhz[9] = { 0, 365, 450, 500, 550, 182, 225, 250, 275 }; static const struct t7000_soc t7000_soc_a8x = { - .border_fw = T7000_BORDER_FW, + .border_fw = "apple/gfx-t7001-border.bin", /* AGXG4G's own 0x800-byte table */ .ps_gfx = T7000_PMGR_PS_GFX, + /* + * The driver owns the power state, as on the A8 (no power-domains in the + * node): genpd would switch the domain on when the device attaches, before + * the probe and before t7001_pmgr_prepare(), which the J81 never ran. + */ + .ps_domain = false, .pll = T7000_PMGR_PLL5, .pll_lock = T7000_PLL_LOCKED, - .a8_globals = true, + .a8_globals = false, /* no A8 perf records at 0x1c000 known on the A8X */ .bridges_from_dt = true, + .pmgr_prep = t7001_pmgr_prep, + .nr_pmgr_prep = ARRAY_SIZE(t7001_pmgr_prep), + .pmgr_dwi = 0x20120, + .tvm_status = 0x2d100, .mhz = t7001_mhz, .nr_mhz = ARRAY_SIZE(t7001_mhz), .perf_states = 4, @@ -4867,6 +4921,61 @@ static void t7000_bridges(struct pvr_apple_s8003 *s) writel(t7000_bridge11[i], s->bridges + 0x80000 + 4 * i); } +/* + * The A8X's pre-power sequence (see t7001_pmgr_prep): run at the end of the + * probe, once the firmware's hash and layout are accepted, while the GPU's + * power domain is still off. A word that is neither the expected old value + * nor the new one refuses the probe before anything is written. A second run + * (probe deferred and repeated) finds the new values and writes nothing. + */ +static int t7001_pmgr_prepare(struct pvr_apple *apple) +{ + struct device *dev = apple_dev(apple); + struct pvr_apple_s8003 *s = apple->chip_data; + const struct t7000_soc *soc = s->v->soc; + unsigned int i, t; + u32 cur; + + if (pmgr_read(s, soc->pmgr_dwi) != 0xff) + return dev_err_probe(dev, -ENODEV, "the DWI power domain is not on: %#x\n", + pmgr_read(s, soc->pmgr_dwi)); + if (FIELD_GET(T7000_PS_ACTUAL, pmgr_read(s, soc->ps_gfx))) + return dev_err_probe(dev, -EBUSY, "the GPU is powered already: %#x\n", + pmgr_read(s, soc->ps_gfx)); + for (i = 0; i < soc->nr_pmgr_prep; i++) { + const struct t7001_pmgr_store *st = &soc->pmgr_prep[i]; + + cur = pmgr_read(s, st->off); + if ((cur & st->mask) == (st->val & st->mask)) + continue; + if (cur != st->old) + return dev_err_probe(dev, -EBUSY, "PMGR %#x reads %#x, expected %#x\n", + st->off, cur, st->old); + } + for (i = 0; i < soc->nr_pmgr_prep; i++) { + const struct t7001_pmgr_store *st = &soc->pmgr_prep[i]; + + if ((pmgr_read(s, st->off) & st->mask) == (st->val & st->mask)) + continue; + writel(st->val, s->pmgr + st->off); + mb(); + usleep_range(500, 1500); + cur = pmgr_read(s, st->off); + if ((cur & st->mask) != (st->val & st->mask)) + return dev_err_probe(dev, -EIO, "PMGR %#x: wrote %#x, reads %#x\n", st->off, + st->val, cur); + } + for (t = 0; t < 100 && pmgr_read(s, soc->tvm_status) != 1; t++) + udelay(10); + if (pmgr_read(s, soc->tvm_status) != 1) + return dev_err_probe(dev, -EIO, "SoC voltage manager status %#x\n", + pmgr_read(s, soc->tvm_status)); + if (pmgr_read(s, soc->pmgr_dwi) != 0xff) + return dev_err_probe(dev, -ENODEV, "the DWI power domain was lost\n"); + dev_dbg(dev, "%s: PMGR prepared for the power domain\n", s->v->name); + return 0; +} + static int t7000_wake_fender(struct pvr_apple *apple); /* @@ -4932,7 +5041,7 @@ static int t7000_boot(struct pvr_apple *apple) dev_err(apple_dev(apple), "the GPU is powered already: not touched\n"); return -EBUSY; } - for (n = 1; n <= 3; n++) { + for (n = 1; s->v->soc->a8_globals && n <= 3; n++) { if (!(pmgr_read(s, T7000_PMGR_GPU_TABLE + 0x10 * n) & T7000_GPU_TABLE_VALID)) { dev_err(apple_dev(apple), "GPU performance record %u not valid\n", n); return -EIO; @@ -7350,6 +7459,8 @@ static const struct s8003_variant s8003_variant_a8x = { .soc = &t7000_soc_a8x, .fws = t7001_fw_layouts, .nr_fws = ARRAY_SIZE(t7001_fw_layouts), + .prepare = t7001_pmgr_prepare, + .no_jobs = true, /* until the A9-form TA/3D/compute records (the A8's would reach a 19H394 firmware) */ .page_size = SZ_4K, .image_layout = t7000_ldr_layout, /* image size, segments, core memory */ .root_size = T7000_ROOT_SIZE, From e670c6ab12bd879e74bc8dab0204fff6512df31f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pu=C5=A1k=C3=A1=C4=8D?= Date: Thu, 3 Dec 2026 15:22:35 +0100 Subject: [PATCH 09/14] drm/imagination: apple: t7000: the A8X's SLC_CTRL_MISC boot word MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The A8's boot stream stores 0x200001 in SLC_CTRL_MISC; the A8X's firmware boots only with its own 64-bit word (0x0003550000300001, from the J81's firmware list). Make the word a per-SoC value (slc_misc) instead of a constant. The A8 keeps its value. Compile-checked only; not run on hardware. Assisted-by: LLM Signed-off-by: Martin Puškáč --- drivers/gpu/drm/imagination/pvr_apple_s8003.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/imagination/pvr_apple_s8003.c b/drivers/gpu/drm/imagination/pvr_apple_s8003.c index f6aee508b2e6d4..e1b58dad2c01f7 100644 --- a/drivers/gpu/drm/imagination/pvr_apple_s8003.c +++ b/drivers/gpu/drm/imagination/pvr_apple_s8003.c @@ -293,6 +293,7 @@ struct t7000_soc { u32 perf_count; /* PLATFORM perf_count */ bool fence; /* a FenceBuffer named to the firmware */ bool slc; /* SLC_CTRL_MISC and 0x3808 in the boot stream */ + u64 slc_misc; /* SLC_CTRL_MISC's boot stream value: the A8's 0x200001, the A8X's 64-bit word */ u32 rev_major; /* CORE_REVISION[23:16] */ u32 chip_info[3]; /* without an ID read */ /* @@ -4399,6 +4400,7 @@ static const struct t7000_soc t7000_soc_a8 = { .perf_count = 16, .fence = true, .slc = true, + .slc_misc = 0x200001, .rev_major = 3, .chip_info = { 2, 4, 4 }, .settle_ms = 100, @@ -4498,6 +4500,7 @@ static const struct t7000_soc t7000_soc_a8x = { .perf_count = 16, .fence = true, .slc = true, + .slc_misc = 0x0003550000300001ull, /* the J81's firmware list (19H394); the A8's value is not accepted by its firmware */ .rev_major = 7, .chip_info = { 3, 2, 8 }, .settle_ms = 100, @@ -5276,7 +5279,7 @@ static int t7000_release(struct pvr_apple *apple, u32 q) t7000_stream_write64(&stream, ROGUE_CR_BIF_CAT_BASE0, pvr_vm_get_page_table_root_addr(apple->pvr_dev->kernel_vm_ctx)); if (s->v->soc->slc) { - t7000_stream_write64(&stream, ROGUE_CR_SLC_CTRL_MISC, 0x200001); + t7000_stream_write64(&stream, ROGUE_CR_SLC_CTRL_MISC, s->v->soc->slc_misc); t7000_stream_write64(&stream, T7000_CR_SLC_3808, 1); } t7000_stream_write64(&stream, ROGUE_CR_SOFT_RESET, 0); From 7e3d42beb9e883d6cd0a4d78ad864c150912a465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pu=C5=A1k=C3=A1=C4=8D?= Date: Thu, 3 Dec 2026 15:22:36 +0100 Subject: [PATCH 10/14] arm64: dts: apple: t7001: add the GPU node MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The A8X's GPU (apple,t7001-gpu): the Rogue core, Fender, the power manager and the bridges' register regions (the bridges region is 0xc1000 bytes: the second bridge's table is at +0xc0000), AIC 134-138 and the firmware name. No power-domains, as the A8's GPU: the driver switches ps_gfx itself after its PMGR stores. Disabled in the SoC file and enabled for the iPad Air 2 boards in t7001-air2.dtsi. The bridge settings are the device's: the loader adds apple,bridge-settings from the ADT, and the driver refuses to probe without them. Built with the kernel's dtc. Assisted-by: LLM Signed-off-by: Martin Puškáč --- arch/arm64/boot/dts/apple/t7001-air2.dtsi | 4 ++++ arch/arm64/boot/dts/apple/t7001.dtsi | 24 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t7001-air2.dtsi b/arch/arm64/boot/dts/apple/t7001-air2.dtsi index c3aa0770c6ae54..383415de8abd60 100644 --- a/arch/arm64/boot/dts/apple/t7001-air2.dtsi +++ b/arch/arm64/boot/dts/apple/t7001-air2.dtsi @@ -570,3 +570,7 @@ apple,always-on; apple,manual-pm; }; + +&gpu { + status = "okay"; +}; diff --git a/arch/arm64/boot/dts/apple/t7001.dtsi b/arch/arm64/boot/dts/apple/t7001.dtsi index a3ac9f31fefdd0..2a43769309d5fd 100644 --- a/arch/arm64/boot/dts/apple/t7001.dtsi +++ b/arch/arm64/boot/dts/apple/t7001.dtsi @@ -147,6 +147,30 @@ nonposted-mmio; ranges; + /* + * No power-domains, as the A8's GPU: the driver switches ps_gfx + * itself after its PMGR stores (genpd would power it on at attach, + * before the probe). The firmware's own bus-bridge settings (apple,bridge-settings, + * {offset, value} rows) are the device's: the loader fills them + * from the ADT, and the driver refuses to probe without them. + */ + gpu: gpu@201000000 { + compatible = "apple,t7001-gpu"; + reg = <0x2 0x01000000 0x0 0x100000>, + <0x2 0x01e00000 0x0 0x100000>, + <0x2 0x0e000000 0x0 0x40000>, + <0x2 0x01f00000 0x0 0xc1000>; + reg-names = "rgx", "fender", "pmgr", "bridges"; + interrupt-parent = <&aic>; + interrupts = , + , + , + , + ; + firmware-name = "apple/gfx-t7001.bin"; + status = "disabled"; + }; + cpufreq: performance-controller@202220000 { compatible = "apple,t7000-cluster-cpufreq", "apple,s5l8960x-cluster-cpufreq"; reg = <0x2 0x02220000 0 0x1000>; From cf3b9a814ca7438fd625b0a2920b61bb0a391424 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pu=C5=A1k=C3=A1=C4=8D?= Date: Thu, 3 Dec 2026 17:08:24 +0100 Subject: [PATCH 11/14] drm/imagination: apple: t7000: the A8X's ring-control lane size, LOG lane 0 only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ring-control lane stride of the A8X firmware (19H394) is unknown: the A9's 0x20 or the A8's 0x30, the stride at which the firmware reads LOG lanes 1-3. Size the control objects with the larger value, so that either fits, and add a per-variant log_lanes count: the A9, A8 and A7 keep 4, the A8X reads and discards lane 0 only, whose indices are at the same place in both layouts (a read of the J81's LOG control after rendering showed lane 0 at +0x00 and +0x10 and nothing in lanes 1-3). Set log_lanes to 4 once the stride is measured. Compile-checked only; not run on hardware. Assisted-by: LLM Signed-off-by: Martin Puškáč --- drivers/gpu/drm/imagination/pvr_apple_s8003.c | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/imagination/pvr_apple_s8003.c b/drivers/gpu/drm/imagination/pvr_apple_s8003.c index e1b58dad2c01f7..b59bfee164483d 100644 --- a/drivers/gpu/drm/imagination/pvr_apple_s8003.c +++ b/drivers/gpu/drm/imagination/pvr_apple_s8003.c @@ -384,6 +384,7 @@ struct s8003_variant { const struct s8003_object_size *objects; unsigned int nr_objects; u32 ring_ctl_size; /* one lane's ring indices */ + u32 log_lanes; /* LOG lanes the host reads and discards (lane n at n * ring_ctl_size) */ u32 slots; /* the firmware's slots for VMs */ u32 slot_first; /* the first slot the host may use */ unsigned int vm_slots; /* a VM's slots: 2 (geometry and compute, fragment) or 1 */ @@ -1389,11 +1390,23 @@ static int s8003_drain(struct pvr_apple *apple, bool *alive) int err = 0; guard(mutex)(&s->event_lock); - for (lane = 0; lane < 4 && !err; lane++) + for (lane = 0; lane < s->v->log_lanes && !err; lane++) err = s8003_ring_discard(s8003_object(s, S8003_LOG_CTL) + lane * s->v->ring_ctl_size); if (err) return err; + if (s->v->log_lanes < 4) { /* the stride is unknown: the first post beyond lane 0 reveals it */ + const u8 *log = s8003_object(s, S8003_LOG_CTL); + unsigned int off; + + for (off = 0x20; off < 4 * s->v->ring_ctl_size; off += 4) + if (get_unaligned_le32(log + off)) { + dev_warn_once(apple_dev(apple), + "LOG control word %#x is %#x: lanes 1-3 are in use, set the ring-control lane stride (T7001_RING_CTL_SIZE: +0x30 would be 0x20, +0x40 would be 0x30)\n", + off, get_unaligned_le32(log + off)); + break; + } + } consumer = ring_read(ctl, S8003_RING_CONSUMER); producer = ring_read(ctl, S8003_RING_PRODUCER); @@ -3885,7 +3898,17 @@ static const struct s8003_object_size s8003_objects_a8[] = { * 0x4c and the 8-slot tables the A8's, PLATFORM its own. Its image and ring * lanes: see T7001_*. */ -#define T7001_RING_CTL_SIZE T7000_RING_CTL_SIZE /* unknown: 0x20 or 0x30, lanes 1-3 unmeasured */ +/* + * The A8X's ring-control lane stride is unknown: 0x20 (the A9's) or 0x30 (the + * A8's), the stride at which the firmware reads LOG lanes 1-3 (firmware code, + * not in the LDR). The objects are sized with the larger value, so either + * stride fits (LOG_CTL is 4 x 0x30 = 0xc0 bytes), and the host reads and + * discards LOG lane 0 only (log_lanes = 1), which sits at the same place in + * both: a read of the J81's LOG control after rendering showed lane 0's + * indices at +0x00 and +0x10 and nothing at +0x30 or +0x40, i.e. lanes 1-3 + * never posted. Set log_lanes = 4 once the stride is measured. + */ +#define T7001_RING_CTL_SIZE 0x30 static const struct s8003_object_size s8003_objects_a8x[] = { { S8003_INIT, false, 0x1490 }, @@ -7013,7 +7036,7 @@ static void t7000_irq_checked(struct pvr_apple *apple, unsigned int retired, boo } } s->t7000_ev_cursor = cursor; - for (lane = 0; lane < 4 && !rings; lane++) { + for (lane = 0; lane < s->v->log_lanes && !rings; lane++) { u8 *log = s8003_object(s, S8003_LOG_CTL) + lane * s->v->ring_ctl_size; rings = ring_read(log, S8003_RING_CONSUMER) != ring_read(log, S8003_RING_PRODUCER); @@ -7325,6 +7348,7 @@ static const struct s8003_variant s8003_variant_a9 = { .objects = s8003_objects_a9, .nr_objects = ARRAY_SIZE(s8003_objects_a9), .ring_ctl_size = S8003_RING_CTL_SIZE, + .log_lanes = 4, .slots = S8003_SLOTS, .slot_first = S8003_SLOT_FIRST, .vm_slots = 2, @@ -7374,6 +7398,7 @@ static const struct s8003_variant s8003_variant_a8 = { .objects = s8003_objects_a8, .nr_objects = ARRAY_SIZE(s8003_objects_a8), .ring_ctl_size = T7000_RING_CTL_SIZE, + .log_lanes = 4, .slots = T7000_SLOTS, .slot_first = T7000_SLOT_FIRST, .vm_slots = 1, @@ -7420,6 +7445,7 @@ static const struct s8003_variant s8003_variant_a7 = { .objects = s8003_objects_a8, .nr_objects = ARRAY_SIZE(s8003_objects_a8), .ring_ctl_size = T7000_RING_CTL_SIZE, + .log_lanes = 4, .slots = T7000_SLOTS, .slot_first = T7000_SLOT_FIRST, .vm_slots = 1, @@ -7473,6 +7499,7 @@ static const struct s8003_variant s8003_variant_a8x = { .objects = s8003_objects_a8x, .nr_objects = ARRAY_SIZE(s8003_objects_a8x), .ring_ctl_size = T7001_RING_CTL_SIZE, + .log_lanes = 1, .slots = T7000_SLOTS, .slot_first = T7000_SLOT_FIRST, .vm_slots = 1, From f8b6d10ee844878c162caf89fed4e3feba32fe79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pu=C5=A1k=C3=A1=C4=8D?= Date: Thu, 3 Dec 2026 18:06:48 +0100 Subject: [PATCH 12/14] drm/imagination: apple: t7000: the A8X's compute job (A9 record, A8X words) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The A8X's compute job is the A9's record and microsequence (s8003_submit_compute) with the words the 19H394 firmware ran with on the J81 (cluster mask 0xff at +0x18, terminate descriptor 0x00900004 at +0x244), one record, and the A8's doorbell. The module's microsequence quirk is kept as SoC data: 50 copies of the start timestamp op and a poll of CLK_STATUS before the finish op, because the unpadded sequence cut long kernels off; the longer sequence lives in the page behind the channel's. Jobs are now a per-variant type mask: the A8X takes compute only, geometry and fragment follow with the A9-form TA and 3D records. Compile-checked only; not run on hardware. Assisted-by: LLM Signed-off-by: Martin Puškáč --- drivers/gpu/drm/imagination/pvr_apple_s8003.c | 125 +++++++++++++++++- 1 file changed, 119 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/imagination/pvr_apple_s8003.c b/drivers/gpu/drm/imagination/pvr_apple_s8003.c index b59bfee164483d..0b350a96bdf36b 100644 --- a/drivers/gpu/drm/imagination/pvr_apple_s8003.c +++ b/drivers/gpu/drm/imagination/pvr_apple_s8003.c @@ -293,6 +293,16 @@ struct t7000_soc { u32 perf_count; /* PLATFORM perf_count */ bool fence; /* a FenceBuffer named to the firmware */ bool slc; /* SLC_CTRL_MISC and 0x3808 in the boot stream */ + /* + * The A8X's compute record (t7001_submit_compute): the A9's with the + * cluster mask (+0x18) and the terminate descriptor (+0x244) the 19H394 + * firmware ran with, and the module's microsequence quirk: @cu_pad + * copies of the start timestamp op (more firmware path time between the + * CDM kick and the finish op: the unpadded sequence cut long kernels + * off) and a poll of RGX CLK_STATUS under @cu_wait before the finish. + */ + u32 cu_desc, cu_cmask, cu_wait; + u16 cu_pad; u64 slc_misc; /* SLC_CTRL_MISC's boot stream value: the A8's 0x200001, the A8X's 64-bit word */ u32 rev_major; /* CORE_REVISION[23:16] */ u32 chip_info[3]; /* without an ID read */ @@ -398,7 +408,7 @@ struct s8003_variant { int (*init)(struct pvr_apple *apple); void (*image_configure)(struct pvr_apple_s8003 *s); int (*prepare)(struct pvr_apple *apple); /* last step of the probe, after every refusal: the GPU is still off */ - bool no_jobs; /* the firmware boots, but the job records are not this firmware's yet */ + u32 jobs; /* BIT(DRM_PVR_JOB_TYPE_*) the variant takes: 0 = every type */ int (*map)(struct pvr_apple *apple); void (*unmap)(struct pvr_apple *apple); void (*init_build)(struct pvr_apple *apple, u32 q); @@ -3721,9 +3731,9 @@ static int pvr_apple_s8003_prepare_job(struct pvr_apple *apple, struct pvr_job * { struct pvr_apple_s8003 *s = apple->chip_data; - if (s->v->no_jobs) { - dev_warn_once(apple_dev(apple), "%s: no jobs until the firmware's own records\n", - s->v->name); + if (s->v->jobs && !(s->v->jobs & BIT(job->type))) { + dev_warn_once(apple_dev(apple), "%s: no jobs of type %u until the firmware's own records\n", + s->v->name, job->type); return -EOPNOTSUPP; } return s->v->prepare_job(apple, job); @@ -4524,6 +4534,10 @@ static const struct t7000_soc t7000_soc_a8x = { .fence = true, .slc = true, .slc_misc = 0x0003550000300001ull, /* the J81's firmware list (19H394); the A8's value is not accepted by its firmware */ + .cu_desc = 0x00900004, + .cu_cmask = 0xff, /* 8 clusters */ + .cu_pad = 50, + .cu_wait = 0x400, /* USC_RUNNING (CLK_STATUS bit 10) must be 0 */ .rev_major = 7, .chip_info = { 3, 2, 8 }, .settle_ms = 100, @@ -5696,6 +5710,105 @@ static int t7000_submit_compute(struct pvr_apple *apple, struct s8003_vm *vm, st return seq; } +/* + * The A8X's compute job: the A9's record and microsequence (s8003_submit_compute) + * with the A8X's words (t7000_soc::cu_*), one record, and the A8's doorbell + * (t7000_publish). The padded sequence does not fit the A9's 0xc0 bytes: it + * lives in the page behind the channel's, where the A8's second record is. The + * finish op's last operand is a byte offset back to the start op, which + * grows with every inserted word. + */ +#define T7001_CU_PAD_MAX 64 +#define T7001_CU_USEQ_WORDS_MAX (39 + 5 * T7001_CU_PAD_MAX + 3) + +static int t7001_submit_compute(struct pvr_apple *apple, struct s8003_vm *vm, struct pvr_job *job) +{ + const struct pvr_apple_g5p_cmd_compute *cmd = job->cmd; + const struct pvr_apple_g5p_compute_regs *g = &cmd->g5p; + struct pvr_apple_s8003 *s = apple->chip_data; + const struct t7000_soc *soc = s->v->soc; + u32 addr = s8003_channel_addr(s, APPLE_ENGINE_COMPUTE); + u32 global = s8003_object_addr(&s->layout, S8003_CHANNEL + 2); + u32 w = addr + S8003_CH_W, slot = vm->slot[0], seq; + u32 pad = soc->cu_pad, useq_off = pad ? T7000_CU_SLOT1 : S8003_CU_USEQ; + u8 *p = s8003_channel(s, APPLE_ENGINE_COMPUTE); + u8 *work = p + S8003_CH_W; + u8 *useq = p + useq_off, *out = useq; /* written straight into the channel's second page */ + unsigned int i, nw; + int err; + + BUILD_BUG_ON(T7000_CU_CHANNEL + T7000_CU_SLOT1 + 4 * T7001_CU_USEQ_WORDS_MAX > T7000_TA_CHANNEL); + if (pad > T7001_CU_PAD_MAX) + return -EINVAL; + err = s8003_wait_done(apple, APPLE_ENGINE_COMPUTE, apple->last_seq); + if (err) + return s8003_submit_error(apple, vm, "compute", err, S8003_REFUSED_SLOT_WAIT, + "record slot wait"); + err = t7000_publish_check(apple, APPLE_ENGINE_COMPUTE); + if (err) + return s8003_submit_error(apple, vm, "compute", err, S8003_REFUSED_PUBLISH, + "publish"); + seq = apple->last_seq + 1; + { + const u32 head[] = { + 0x32, w + 0x10, w + 0x60, global + 0x720, addr, slot, 0, 0, 0, w + 0x1e8, + 0, 0, seq, + }; + const u32 start[] = { 0x80000018, w + 0x278, w + 0x280, w + 0x280, seq }; + const u32 mid[] = { 0x101, 0x004a000a, 1, 1 }; + const u32 tail[] = { + 0x18, w + 0x278, w + 0x280, w + 0x284, seq, + 0x33, global + 0x720, addr, slot, w + 0x1e8, 0, 0, seq, + addr + S8003_CU_STAMP + 4, seq, 0 /* back to the start op: set below */, + 0x40000017, + }; + + const u32 wait[] = { 0x0008u << 12 | 0xa, soc->cu_wait, 0 }; /* op 0xa: (RGX[0x0008] & mask) == 0 */ + + memset(useq, 0, 4 * T7001_CU_USEQ_WORDS_MAX); + out = useq_put(out, head, ARRAY_SIZE(head)); + for (i = 0; i <= pad; i++) /* the start op, and @pad more copies of it */ + out = useq_put(out, start, ARRAY_SIZE(start)); + out = useq_put(out, mid, ARRAY_SIZE(mid)); + if (soc->cu_wait) + out = useq_put(out, wait, ARRAY_SIZE(wait)); + out = useq_put(out, tail, ARRAY_SIZE(tail)); + nw = (out - useq) / 4; + /* the finish op's operand, 3 words before the end op: back to the start op's first copy */ + put32(useq + 4 * (nw - 2), -(4 * (27 + 5 * pad + (soc->cu_wait ? 3 : 0)))); + } + memset(work, 0, S8003_CU_W_SIZE); + put32(work, 3); + put32(work + 8, slot); + put32(work + 0xc, addr + S8003_CU_DEP); + put32(work + 0x10, g->config[0]); + put32(work + 0x14, g->config[1]); + put32(work + 0x18, soc->cu_cmask); + put64(work + 0x60, g->tail); + put64(work + 0x68, g->pds_terminate); + put64(work + 0x70, cmd->cmd.regs.cdm_ctrl_stream_base); + put32(work + 0x1e0, addr + useq_off); + put32(work + 0x1e4, 4 * nw); + for (i = 0; i < 4; i++) + put64(work + 0x1ec + i * 8, g->state[i]); + put64(work + 0x20c, g->tail); + put64(work + 0x214, g->terminate); + put64(work + 0x21c, g->pds_store); + put32(work + 0x224, g->pds_store1); + put64(work + 0x22c, g->pds_resume); + put32(work + 0x234, g->pds_resume1); + put64(work + 0x23c, g->terminate); + put32(work + 0x244, soc->cu_desc); + put32(work + 0x258, addr + S8003_CU_STAMP); + put32(work + 0x25c, addr + S8003_CU_STAMP + 4); + put32(work + 0x260, seq); + put32(work + 0x270, seq); + put32(p + S8003_CH_RING + ((seq - 1) % S8003_CH_ENTRIES) * 4, w); + apple->last_seq = seq; + t7000_publish(apple, APPLE_ENGINE_COMPUTE, seq % S8003_CH_ENTRIES); + return seq; +} + /* * Render jobs. The A8's parameter manager keeps one set per VM: a control * block with 36 state records "S" of 0xc0 bytes behind its first 0x80 (root @@ -7489,7 +7602,7 @@ static const struct s8003_variant s8003_variant_a8x = { .fws = t7001_fw_layouts, .nr_fws = ARRAY_SIZE(t7001_fw_layouts), .prepare = t7001_pmgr_prepare, - .no_jobs = true, /* until the A9-form TA/3D/compute records (the A8's would reach a 19H394 firmware) */ + .jobs = BIT(DRM_PVR_JOB_TYPE_COMPUTE), /* the A9-form compute record first; geometry and fragment follow (the A8's forms would reach a 19H394 firmware) */ .page_size = SZ_4K, .image_layout = t7000_ldr_layout, /* image size, segments, core memory */ .root_size = T7000_ROOT_SIZE, @@ -7528,7 +7641,7 @@ static const struct s8003_variant s8003_variant_a8x = { .prepare_job = t7000_prepare_job, .submit_geom = t7000_submit_geom, .submit_frag = t7000_submit_frag, - .submit_compute = t7000_submit_compute, + .submit_compute = t7001_submit_compute, .report_hang = t7000_report_hang, .event_fault = t7000_event_fault, }; From 8a4fe835dfa430f90322ee4267ed98c6c05b9f58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pu=C5=A1k=C3=A1=C4=8D?= Date: Thu, 3 Dec 2026 18:51:27 +0100 Subject: [PATCH 13/14] drm/imagination: apple: t7000: the A8X's PM set and geometry job (A9-form TA) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The A8X's geometry job is the A9's TA record and microsequence (s8003_fill_ta, s8003_job_write) on the A8's job bookkeeping. The PM set takes the A9's control words and scene record at the A8's per-VM place; its pool is blocks x 8 chunks of 16 KiB, each physically contiguous (alloc_pages, dma_map_page; the kernel's pages may be 4 KiB and a GEM object's pages need not be adjacent), never mapped in a GPU VA, and the free list holds the four 4 KiB frame numbers of each chunk. The region headers are used at rgn_header_dev_addr (no mirrored ring), the pool does not grow, and the render channels publish in the A9's form (host watermark at S8003_CH_CTL, no +12 word). The A8X now takes compute and geometry jobs. Compile-checked only; not run on hardware. Assisted-by: LLM Signed-off-by: Martin Puškáč --- drivers/gpu/drm/imagination/pvr_apple_s8003.c | 251 ++++++++++++++++-- 1 file changed, 233 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/drm/imagination/pvr_apple_s8003.c b/drivers/gpu/drm/imagination/pvr_apple_s8003.c index 0b350a96bdf36b..b29468a1a241d7 100644 --- a/drivers/gpu/drm/imagination/pvr_apple_s8003.c +++ b/drivers/gpu/drm/imagination/pvr_apple_s8003.c @@ -303,6 +303,13 @@ struct t7000_soc { */ u32 cu_desc, cu_cmask, cu_wait; u16 cu_pad; + /* + * The render channels and records in the A9's form (the A8X's firmware + * runs the A9's TA and 3D records and PM control words): the host + * watermark at S8003_CH_CTL, no +12 word in the work-ring entry, the + * PM pool in physically contiguous 16 KiB chunks (t7001_pool_alloc()). + */ + bool a9_channels; u64 slc_misc; /* SLC_CTRL_MISC's boot stream value: the A8's 0x200001, the A8X's 64-bit word */ u32 rev_major; /* CORE_REVISION[23:16] */ u32 chip_info[3]; /* without an ID read */ @@ -540,6 +547,9 @@ struct s8003_vm { struct pvr_gem_object *next_pool; /* @want blocks, taken at a geometry job */ u8 *next_pool_map; u32 next_blocks; + struct page **chunk; /* A8X: the pool's 16 KiB chunks (blocks x 8), physically contiguous */ + dma_addr_t *chunk_dma; + u32 nchunks; u32 built; /* the firmware start the set was built for */ bool open; /* a geometry job waits for its fragment job */ const struct pvr_hwrt_data *hwrt; @@ -4538,6 +4548,7 @@ static const struct t7000_soc t7000_soc_a8x = { .cu_cmask = 0xff, /* 8 clusters */ .cu_pad = 50, .cu_wait = 0x400, /* USC_RUNNING (CLK_STATUS bit 10) must be 0 */ + .a9_channels = true, .rev_major = 7, .chip_info = { 3, 2, 8 }, .settle_ms = 100, @@ -5538,7 +5549,8 @@ static void t7000_publish(struct pvr_apple *apple, enum pvr_apple_engine engine, u32 fw_engine = s8003_engine(engine); u8 *ctl = s8003_object(s, S8003_WORK_CTL + 4 * fw_engine); u8 *ring = s8003_object(s, S8003_WORK_RING + 4 * fw_engine); - u32 host = engine == APPLE_ENGINE_COMPUTE ? S8003_CH_CTL : T7000_RCH_CTL; + bool a9 = engine == APPLE_ENGINE_COMPUTE || s->v->soc->a9_channels; + u32 host = a9 ? S8003_CH_CTL : T7000_RCH_CTL; u32 start = ring_read(ctl, S8003_RING_PRODUCER); u8 *p = s8003_channel(s, engine), *entry; @@ -5547,7 +5559,7 @@ static void t7000_publish(struct pvr_apple *apple, enum pvr_apple_engine engine, put32(entry, fw_engine); put32(entry + 4, s8003_channel_addr(s, engine)); put32(entry + 8, end); - if (engine != APPLE_ENGINE_COMPUTE) + if (!a9) put32(entry + 12, 1); wmb(); put32(p + host + S8003_CH_CTL_HOST, end); @@ -5982,8 +5994,12 @@ static void t7000_pm_obj_put(struct pvr_apple *apple, struct pvr_gem_object **ob } /* A VM's PM objects go with it; their VM mappings with the VM */ +static void t7001_pool_free(struct pvr_apple *apple, struct s8003_vm *vm); +static int t7001_pool_alloc(struct pvr_apple *apple, struct s8003_vm *vm, u32 blocks); + static void t7000_vm_put(struct pvr_apple *apple, struct s8003_vm *vm) { + t7001_pool_free(apple, vm); t7000_pm_obj_put(apple, &vm->t7000.aux, &vm->t7000.aux_map); t7000_pm_obj_put(apple, &vm->t7000.stack, &vm->t7000.stack_map); t7000_pm_obj_put(apple, &vm->t7000.pool, &vm->t7000.pool_map); @@ -6056,8 +6072,9 @@ static int t7000_prepare_job(struct pvr_apple *apple, struct pvr_job *job) struct s8003_vm *vm; struct pvr_hwrt_dataset *dataset; struct s8003_rt rt; - u64 ring; + u64 ring = 0; u32 slice, blocks; + bool a9 = s->v->soc->a9_channels; int err; if (job->type != DRM_PVR_JOB_TYPE_GEOMETRY) @@ -6076,13 +6093,15 @@ static int t7000_prepare_job(struct pvr_apple *apple, struct pvr_job *job) return -EOPNOTSUPP; } slice = ALIGN(rt.header, SZ_4K); - err = t7000_rgn_ring(vm->vm_ctx, job->hwrt->data.rgn_header_dev_addr, slice, &ring); - if (err) { - atomic64_inc(&s->refused[S8003_REFUSED_PREPARE_RING]); - dev_warn_ratelimited(apple_dev(apple), - "geometry job refused: region headers at %#llx are not a mirrored ring of 16 slices of %#x\n", - job->hwrt->data.rgn_header_dev_addr, slice); - return err; + if (!a9) { /* the A8X takes the region headers at rgn_header_dev_addr, as the A9 */ + err = t7000_rgn_ring(vm->vm_ctx, job->hwrt->data.rgn_header_dev_addr, slice, &ring); + if (err) { + atomic64_inc(&s->refused[S8003_REFUSED_PREPARE_RING]); + dev_warn_ratelimited(apple_dev(apple), + "geometry job refused: region headers at %#llx are not a mirrored ring of 16 slices of %#x\n", + job->hwrt->data.rgn_header_dev_addr, slice); + return err; + } } /* @@ -6102,7 +6121,7 @@ static int t7000_prepare_job(struct pvr_apple *apple, struct pvr_job *job) err = t7000_pm_obj(apple, T7000_PM_STACK_SIZE, &stack, &stack_map); blocks = clamp(max(READ_ONCE(a8_pm_blocks), READ_ONCE(s->t7000_pm_floor)), 2u, (u32)T7000_PM_BLOCKS_MAX); - if (!err) + if (!err && !a9) err = t7000_pm_obj(apple, (size_t)blocks * T7000_PM_SLICE_PAGES * SZ_4K, &pool, &pool_map); if (!err) @@ -6119,6 +6138,16 @@ static int t7000_prepare_job(struct pvr_apple *apple, struct pvr_job *job) t7000_pm_obj_put(apple, &pool, &pool_map); goto out; } + if (a9) { /* the pool: 16 KiB chunks outside the GEM objects (the VM keeps them until it goes) */ + err = t7001_pool_alloc(apple, vm, blocks); + if (err) { + pvr_vm_unmap_obj(vm->vm_ctx, stack, T7000_PM_STACK_VA, T7000_PM_STACK_SIZE); + pvr_vm_unmap_obj(vm->vm_ctx, aux, T7000_PM_AUX_VA, T7000_PM_AUX_SIZE); + t7000_pm_obj_put(apple, &aux, &aux_map); + t7000_pm_obj_put(apple, &stack, &stack_map); + goto out; + } + } mutex_lock(&apple->submit_lock); vm->t7000.aux = aux; vm->t7000.aux_map = aux_map; @@ -6137,7 +6166,7 @@ static int t7000_prepare_job(struct pvr_apple *apple, struct pvr_job *job) */ mutex_lock(&apple->submit_lock); blocks = max(vm->t7000.want, READ_ONCE(s->t7000_pm_floor)); - blocks = !READ_ONCE(a8_pm_grow) || vm->t7000.next_pool || blocks <= vm->t7000.blocks ? 0 : + blocks = a9 || !READ_ONCE(a8_pm_grow) || vm->t7000.next_pool || blocks <= vm->t7000.blocks ? 0 : min_t(u32, blocks, T7000_PM_BLOCKS_MAX); mutex_unlock(&apple->submit_lock); if (blocks) { @@ -6162,15 +6191,201 @@ static int t7000_prepare_job(struct pvr_apple *apple, struct pvr_job *job) * freed: no other target's job can take it before this one is * submitted. Its cursor starts at 0 with the data set. */ - mutex_lock(&apple->submit_lock); - dataset->apple_rgn.ring = ring; - dataset->apple_rgn.slice = slice; - mutex_unlock(&apple->submit_lock); + if (!a9) { + mutex_lock(&apple->submit_lock); + dataset->apple_rgn.ring = ring; + dataset->apple_rgn.slice = slice; + mutex_unlock(&apple->submit_lock); + } out: mutex_unlock(&vm->prepare_lock); return err; } +/* + * The A8X's PM: the A9's control words and scene record at the A8's per-VM + * place (t7000_pm_control_va(), t7000_pm_list_va()), a list of slices {link to + * the previous slice, 8 page numbers} (0x24 bytes) and the free list in the + * VM's stack object: for each 16 KiB PM page its four 4 KiB frame numbers. + * The pool is blocks x 8 chunks of 16 KiB, each physically contiguous (the + * kernel's pages may be 4 KiB, a GEM object's pages need not be adjacent), + * never mapped in a GPU VA: the PM writes their numbers to the hardware. + */ +#define T7001_PM_PAGE SZ_16K +#define T7001_PM_BLOCK_CHUNKS 8 +#define T7001_PM_SLICE 0x24 + +static void t7001_pool_free(struct pvr_apple *apple, struct s8003_vm *vm) +{ + u32 i; + + for (i = 0; i < vm->t7000.nchunks; i++) { + if (!vm->t7000.chunk || !vm->t7000.chunk[i]) + continue; + dma_unmap_page(apple_dev(apple), vm->t7000.chunk_dma[i], T7001_PM_PAGE, + DMA_BIDIRECTIONAL); + __free_pages(vm->t7000.chunk[i], get_order(T7001_PM_PAGE)); + } + kvfree(vm->t7000.chunk); + kvfree(vm->t7000.chunk_dma); + vm->t7000.chunk = NULL; + vm->t7000.chunk_dma = NULL; + vm->t7000.nchunks = 0; +} + +static int t7001_pool_alloc(struct pvr_apple *apple, struct s8003_vm *vm, u32 blocks) +{ + u32 i, n = blocks * T7001_PM_BLOCK_CHUNKS; + + vm->t7000.chunk = kvcalloc(n, sizeof(*vm->t7000.chunk), GFP_KERNEL); + vm->t7000.chunk_dma = kvcalloc(n, sizeof(*vm->t7000.chunk_dma), GFP_KERNEL); + if (!vm->t7000.chunk || !vm->t7000.chunk_dma) { + kvfree(vm->t7000.chunk); + kvfree(vm->t7000.chunk_dma); + vm->t7000.chunk = NULL; + vm->t7000.chunk_dma = NULL; + return -ENOMEM; + } + vm->t7000.nchunks = n; + for (i = 0; i < n; i++) { + vm->t7000.chunk[i] = alloc_pages(GFP_KERNEL | __GFP_ZERO | __GFP_NOWARN, + get_order(T7001_PM_PAGE)); + if (!vm->t7000.chunk[i]) + goto err; + vm->t7000.chunk_dma[i] = dma_map_page(apple_dev(apple), vm->t7000.chunk[i], 0, + T7001_PM_PAGE, DMA_BIDIRECTIONAL); + if (dma_mapping_error(apple_dev(apple), vm->t7000.chunk_dma[i])) { + __free_pages(vm->t7000.chunk[i], get_order(T7001_PM_PAGE)); + vm->t7000.chunk[i] = NULL; + goto err; + } + } + return 0; +err: + t7001_pool_free(apple, vm); + return -ENOMEM; +} + +static int t7001_pm_build(struct pvr_apple *apple, struct s8003_vm *vm) +{ + struct pvr_apple_s8003 *s = apple->chip_data; + u8 *control = s->root.map + t7000_pm_control_va(vm); + u8 *list = s->shared.map + t7000_pm_list_va(vm); + u32 list_meta = s8003_meta_addr(S8003_SHARED_VA + t7000_pm_list_va(vm)), previous = 0; + u32 blocks = vm->t7000.blocks, pages = blocks * T7000_PM_SLICE_PAGES; + u8 *record = control + S8003_PM_RECORD; + u8 *free = vm->t7000.stack_map; + unsigned int i, j, k; + + BUILD_BUG_ON(0x80 + T7000_PM_BLOCKS_MAX * T7001_PM_SLICE > T7000_PM_SET_SIZE); + BUILD_BUG_ON(4 * T7000_PM_BLOCKS_MAX * T7000_PM_SLICE_PAGES > T7000_PM_STACK_SIZE); + if (!blocks || blocks > T7000_PM_BLOCKS_MAX || vm->t7000.nchunks != blocks * T7001_PM_BLOCK_CHUNKS) + return -EINVAL; + vm->t7000.built = 0; + s->t7000_pm_builds++; + memset(free, 0, T7000_PM_STACK_SIZE); + memset(vm->t7000.aux_map, 0, T7000_PM_AUX_SIZE); + memset(control, 0, T7000_PM_SET_SIZE); + memset(list, 0, T7000_PM_SET_SIZE); + for (j = 0; j < blocks; j++) { + u32 at = 0x80 + j * T7001_PM_SLICE; + + put32(list + at, previous); + for (k = 0; k < T7001_PM_BLOCK_CHUNKS; k++) { + u32 ppn = (u32)(vm->t7000.chunk_dma[j * T7001_PM_BLOCK_CHUNKS + k] >> 12); + + put32(list + at + 4 + 4 * k, ppn); + for (i = 0; i < T7001_PM_PAGE / SZ_4K; i++) + put32(free + 4 * ((j * T7001_PM_BLOCK_CHUNKS + k) * 4 + i), ppn + i); + } + previous = list_meta + at; + } + put32(list + T7000_PM_FEEDBACK_TAKEN, 1); + put32(control + 0x10, previous); + put64(control + 0x14, T7000_PM_STACK_VA); + put32(control + 0x1c, pages * 4); + put32(control + 0x20, pages); + put32(control + 0x24, pages - 1); + put32(control + 0x34, T7001_PM_PAGE); + put32(control + 0x40, list_meta); + put32(control + 0x54, pages); + put32(control + 0x58, pages); + put64(record + 0xa8, T7000_PM_AUX_VA); + put64(record + 0xa0, T7000_PM_AUX_VA + 0x80); + put64(record + 0xb0, T7000_PM_AUX_VA + 0x80 + 0x10000); + put32(record + 0xb8, list_meta + 0x40); + wmb(); + vm->t7000.built = s->gen; + return 0; +} + +static void t7000_pm_feedback(struct pvr_apple *apple, struct s8003_vm *vm); +static void t7000_submit_times(struct pvr_apple_s8003 *s, enum pvr_apple_engine engine, + u64 t0, u64 t1, u64 t2); + +/* + * The A8X's geometry job: the A9's TA record and microsequence (s8003_fill_ta, + * s8003_job_write) on the A8's job bookkeeping (the feedback, the PM set per + * VM built anew for each start of the firmware, the record slot wait). The + * region headers are at rgn_header_dev_addr, as on the A9. The PM control is + * named by every TA (CMD_PM), the PM id is the VM's slot. + */ +static int t7001_submit_geom(struct pvr_apple *apple, struct s8003_vm *vm, struct pvr_job *job) +{ + struct pvr_hwrt_dataset *dataset = job->hwrt->hwrt_dataset; + struct pvr_apple_s8003 *s = apple->chip_data; + u32 addr = s8003_channel_addr(s, APPLE_ENGINE_GEOM); + u8 *p = s8003_channel(s, APPLE_ENGINE_GEOM); + u64 t0 = arch_timer_read_counter(), t1, t2; + struct s8003_rt rt; + u32 seq; + int err; + + if (!vm->t7000.stack || !vm->t7000.nchunks) + return s8003_submit_error(apple, vm, "geometry", -EINVAL, S8003_REFUSED_NOT_PREPARED, + "not prepared"); + err = s8003_rt_derive(dataset, &rt); + if (err) + return s8003_submit_error(apple, vm, "geometry", err, S8003_REFUSED_RT, + "rt derive"); + /* Every earlier scene is done here (a geometry job waits for the last fragment job): take the last scene's feedback */ + if (vm->t7000.built == s->gen && !vm->t7000.open) + t7000_pm_feedback(apple, vm); + s->t7000_geom_vm = vm; + if (vm->t7000.built != s->gen || vm->t7000.open) { + err = t7001_pm_build(apple, vm); + if (err) + return s8003_submit_error(apple, vm, "geometry", err, S8003_REFUSED_PM, + "PM set build"); + } + t1 = arch_timer_read_counter(); + /* The record slot of the job before the last one is free again (two alternating records) */ + if (apple->ta_seq) + err = s8003_wait_done(apple, APPLE_ENGINE_GEOM, apple->ta_seq - 1); + if (err) + return s8003_submit_error(apple, vm, "geometry", err, S8003_REFUSED_SLOT_WAIT, + "record slot wait"); + t2 = arch_timer_read_counter(); + err = t7000_publish_check(apple, APPLE_ENGINE_GEOM); + if (err) + return s8003_submit_error(apple, vm, "geometry", err, S8003_REFUSED_PUBLISH, + "publish"); + t7000_submit_times(s, APPLE_ENGINE_GEOM, t0, t1, t2); + + seq = apple->ta_seq + 1; + s8003_fill_ta(p + s8003_slot_of(seq, false).w, job->cmd, job->hwrt, &rt); + s8003_job_write(p, addr, s8003_object_addr(&s->layout, S8003_CHANNEL), + s8003_meta_addr(S8003_ROOT_VA + t7000_pm_control_va(vm)), vm->slot[0], + vm->slot[0], false, seq, addr + S8003_CH_STAMP + 4, 0, true); + vm->t7000.open = true; + vm->t7000.hwrt = job->hwrt; + vm->t7000.ta_seq = seq; + vm->t7000.rgn_addr = job->hwrt->data.rgn_header_dev_addr; + apple->ta_seq = seq; + t7000_publish(apple, APPLE_ENGINE_GEOM, (2 * seq) % S8003_CH_ENTRIES); + return seq; +} + /* The A8's records */ #define T7000_TA_W_SIZE 0x568 #define T7000_3D_W_SIZE 0x8b0 @@ -7602,7 +7817,7 @@ static const struct s8003_variant s8003_variant_a8x = { .fws = t7001_fw_layouts, .nr_fws = ARRAY_SIZE(t7001_fw_layouts), .prepare = t7001_pmgr_prepare, - .jobs = BIT(DRM_PVR_JOB_TYPE_COMPUTE), /* the A9-form compute record first; geometry and fragment follow (the A8's forms would reach a 19H394 firmware) */ + .jobs = BIT(DRM_PVR_JOB_TYPE_COMPUTE) | BIT(DRM_PVR_JOB_TYPE_GEOMETRY), /* the A9-form compute and TA records; fragment follows (the A8's forms would reach a 19H394 firmware) */ .page_size = SZ_4K, .image_layout = t7000_ldr_layout, /* image size, segments, core memory */ .root_size = T7000_ROOT_SIZE, @@ -7639,7 +7854,7 @@ static const struct s8003_variant s8003_variant_a8x = { .vm_unmap = t7000_vm_unmap, .engine_done = t7000_engine_done, .prepare_job = t7000_prepare_job, - .submit_geom = t7000_submit_geom, + .submit_geom = t7001_submit_geom, .submit_frag = t7000_submit_frag, .submit_compute = t7001_submit_compute, .report_hang = t7000_report_hang, From 364894d9a38de5c947716aecac4bf2aff5e782e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Pu=C5=A1k=C3=A1=C4=8D?= Date: Thu, 3 Dec 2026 19:23:28 +0100 Subject: [PATCH 14/14] drm/imagination: apple: t7000: the A8X's fragment job (A9 3D record, A8X words) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The A8X's fragment job is the A9's 3D record, barrier and microsequence (s8003_fill_3d, s8003_job_write with the CMD_WAIT on the TA's finish stamp) on the A8's bookkeeping: it follows its scene's geometry job (the data set and vm->t7000.open), one record per job with two alternating slots. What the 19H394 firmware's 3D needs on the J81: - the render targets' PBE words from the Rogue command at +0x158 (soc->pbe_3d; the A9 record has none); - EVENT_PIXEL_PDS_INFO (+0x3bc) with usc_sr_size (bits 9-14) doubled: the core counts it at twice the unit of Mesa's A8 word (0x202 stalls, 0x402 renders), as Apple's A9 family does; - RGX 0xfd8 (+0x3c8) at half the A9's count (4 at width 2); - the A9's partition words (+0x108..+0x150) zero: they land in other registers of the A8X's loader; - Apple's op 0xf (the 3D engine object + 0x724) and 0x14 in the 3D wait list, right after {0x201, 0x138204, 0x10} (the A9's list lacks them); the finish op's back offset grows by their 12 bytes. A device-control command that the firmware does not take (a wedged firmware) now logs the DC ring, the slot's tags, the engines' objects and the hang report (t7001_dc_report). The A8X takes compute, geometry and fragment jobs. Compile-checked only; the first render passed on the iPad without the last two items; not run with them. Assisted-by: LLM Signed-off-by: Martin Puškáč --- drivers/gpu/drm/imagination/pvr_apple_s8003.c | 180 ++++++++++++++++-- 1 file changed, 167 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/imagination/pvr_apple_s8003.c b/drivers/gpu/drm/imagination/pvr_apple_s8003.c index b29468a1a241d7..545db39398ff5f 100644 --- a/drivers/gpu/drm/imagination/pvr_apple_s8003.c +++ b/drivers/gpu/drm/imagination/pvr_apple_s8003.c @@ -415,6 +415,7 @@ struct s8003_variant { int (*init)(struct pvr_apple *apple); void (*image_configure)(struct pvr_apple_s8003 *s); int (*prepare)(struct pvr_apple *apple); /* last step of the probe, after every refusal: the GPU is still off */ + void (*dc_report)(struct pvr_apple *apple, u32 slot); /* a device-control command was not taken: log the state */ u32 jobs; /* BIT(DRM_PVR_JOB_TYPE_*) the variant takes: 0 = every type */ int (*map)(struct pvr_apple *apple); void (*unmap)(struct pvr_apple *apple); @@ -1897,6 +1898,8 @@ static int s8003_slots_load(struct pvr_apple *apple, const u32 *slot, u64 root, err = s8003_device_control(apple, cmd, n); if (err) dev_err(apple_dev(apple), "GFX firmware slot load failed: %d\n", err); + if (err && s->v->dc_report) + s->v->dc_report(apple, slot[0]); /* The firmware must copy the tag we held stable while loading the root. */ for (e = 0; e < n && !err; e++) { u32 seen = get32(s8003_object(s, S8003_TAG_SEEN) + 4 * slot[e]); @@ -2611,7 +2614,7 @@ static u8 *useq_put(u8 *out, const u32 *words, unsigned int n) */ static void s8003_job_write(struct pvr_apple_s8003 *s, u8 *p, u32 addr, u32 global, u32 pm, u32 pm_id, u32 slot, bool frag, u32 seq, u32 wait_stamp, u32 wait_seq, - bool pm_record, u64 gpu_ticks) + bool pm_record, u64 gpu_ticks, bool op_f) { struct s8003_job_slot at = s8003_slot_of(seq, frag); u32 w = addr + at.w, record = pm + S8003_PM_RECORD; @@ -2654,20 +2657,41 @@ static void s8003_job_write(struct pvr_apple_s8003 *s, u8 *p, u32 addr, u32 glob put32(work + (frag ? 0x8a0 : 0x544), seq); if (frag) { + /* + * The A8X's 19H394 firmware retires the 3D through the stamp block at + * record +0x878: the A9 form's block sits at +0x888, so its + * store went to a zero address. Apple's start/finish words point 0x10 + * lower too (W+0x868), at a word that must stay 0 (op 0x26 branches on it). + */ + const u32 w87c = get32(work + 0x87c), w884 = get32(work + 0x884); + const u32 stamp_at = op_f ? w + 0x868 : w + 0x878; const u32 start[] = { 0x25, w + 0x3a0, w + 0x58, record, global + 0x724, w + 0x7f0, w + 0x7f4, - w + 0x878, addr, w, slot, 0, pm_id, get32(work + 0x800), 0, 1, w + 0x6d8, - get32(work + 0x87c), get32(work + 0x884), 0, seq, + stamp_at, addr, w, slot, 0, pm_id, get32(work + 0x800), 0, 1, w + 0x6d8, + w87c, w884, 0, seq, }; + const u32 op_f_words[] = { 0xf, global + 0x724, 0x14 }; const u32 finish[] = { - 0x26, seq, stamp + 4, seq, record, pm, 1, global + 0x724, w + 0x878, - w + 0x7f0, addr, w, slot, w + 0x6d8, 0, get32(work + 0x87c), - get32(work + 0x884), (u32)-0x104, + 0x26, seq, stamp + 4, seq, record, pm, 1, global + 0x724, stamp_at, + w + 0x7f0, addr, w, slot, w + 0x6d8, 0, w87c, + w884, (u32)-(0x104 + (op_f ? 4 * ARRAY_SIZE(op_f_words) : 0)), }; + if (op_f) { + put32(work + 0x868, 0); + put32(work + 0x878, stamp); + put32(work + 0x87c, stamp + 4); + put32(work + 0x880, seq); + } useq = useq_put(useq, start, ARRAY_SIZE(start)); useq = useq_put(useq, time_start, ARRAY_SIZE(time_start)); - useq = useq_put(useq, s8003_3d_wait, ARRAY_SIZE(s8003_3d_wait)); + if (op_f) { /* the A8X: Apple's 19H394 list has {0xf, the 3D object + 0x724, 0x14} right after {0x201, 0x138204, 0x10} (the A9's list lacks them) */ + useq = useq_put(useq, s8003_3d_wait, 3); + useq = useq_put(useq, op_f_words, ARRAY_SIZE(op_f_words)); + useq = useq_put(useq, s8003_3d_wait + 3, ARRAY_SIZE(s8003_3d_wait) - 3); + } else { + useq = useq_put(useq, s8003_3d_wait, ARRAY_SIZE(s8003_3d_wait)); + } useq = useq_put(useq, time_end, ARRAY_SIZE(time_end)); useq = useq_put(useq, finish, ARRAY_SIZE(finish)); } else { @@ -3188,7 +3212,7 @@ static int s8003_submit_geom(struct pvr_apple *apple, struct s8003_vm *vm, struc s8003_object_addr(&s->layout, S8003_CHANNEL), s8003_meta_addr(s8003_pm_set_va(s, pm, 0)), pm->set + 1, vm->slot[0], false, seq, s8003_channel_addr(s, APPLE_ENGINE_GEOM) + S8003_CH_STAMP + 4, - pm_record ? 0 : pm->rec_seq, pm_record, gpu_ticks); + pm_record ? 0 : pm->rec_seq, pm_record, gpu_ticks, false); if (pm_record) pm->rec_seq = seq; pm->hwrt = job->hwrt; @@ -3248,7 +3272,7 @@ static int s8003_submit_frag(struct pvr_apple *apple, struct s8003_vm *vm, struc s8003_object_addr(&s->layout, S8003_CHANNEL + 1), s8003_meta_addr(s8003_pm_set_va(s, pm, 0)), pm->set + 1, vm->slot[1], true, seq, s8003_channel_addr(s, APPLE_ENGINE_GEOM) + S8003_CH_STAMP + 4, pm->ta_seq, true, - gpu_ticks); + gpu_ticks, false); pm->td_seq = seq; WRITE_ONCE(s->set_frag[pm->set], seq); apple->frag_seq = seq; @@ -6374,9 +6398,9 @@ static int t7001_submit_geom(struct pvr_apple *apple, struct s8003_vm *vm, struc seq = apple->ta_seq + 1; s8003_fill_ta(p + s8003_slot_of(seq, false).w, job->cmd, job->hwrt, &rt); - s8003_job_write(p, addr, s8003_object_addr(&s->layout, S8003_CHANNEL), + s8003_job_write(s, p, addr, s8003_object_addr(&s->layout, S8003_CHANNEL), s8003_meta_addr(S8003_ROOT_VA + t7000_pm_control_va(vm)), vm->slot[0], - vm->slot[0], false, seq, addr + S8003_CH_STAMP + 4, 0, true); + vm->slot[0], false, seq, addr + S8003_CH_STAMP + 4, 0, true, 0, false); vm->t7000.open = true; vm->t7000.hwrt = job->hwrt; vm->t7000.ta_seq = seq; @@ -6386,6 +6410,92 @@ static int t7001_submit_geom(struct pvr_apple *apple, struct s8003_vm *vm, struc return seq; } +/* + * The A8X's 3D record: the A9's fill (s8003_fill_3d) with what the 19H394 + * firmware's 3D needs on the J81: + * - the render targets' PBE register words from the Rogue command, two + * qwords per target at +0x158 (soc->pbe_3d; the A9's record has none: the + * A8's copies at +0x4c0 and +0x540 are not in this form); + * - EVENT_PIXEL_PDS_INFO (+0x3bc, RGX 0x628) with usc_sr_size (bits 9-14) + * doubled: the core counts it at twice the unit Mesa's A8 word has (0x202 + * stalls even a clear, 0x402 renders; it is Apple's A9-family rule); + * - RGX 0xfd8 (+0x3c8) is half the A9's count: 4 at width 2 (1-5 render, + * 0 and 8 stall; the widths 4 and 8 are inferred); + * - the output partition words (+0x108..+0x150) are zero: the A9's six + * partition slots land in other registers of the A8X's loader. + */ +static int t7001_fill_3d(u8 *w, const struct t7000_soc *soc, const struct pvr_apple_g5p_cmd_frag *cmd, + const struct pvr_hwrt_data *hwrt, const struct s8003_rt *rt) +{ + const struct pvr_apple_g5p_frag_regs *g = &cmd->g5p; + unsigned int i; + int err; + + err = s8003_fill_3d(w, cmd, hwrt, rt); + if (err) + return err; + for (i = 0; i < 8; i++) { + put64(w + soc->pbe_3d + i * 16, cmd->cmd.regs.pbe_word[i][0]); + put64(w + soc->pbe_3d + 8 + i * 16, cmd->cmd.regs.pbe_word[i][1]); + } + /* the A9's partition words (+0x108..+0x130) and zls[5] (+0x138) land in the A8X loader's 0xe020[6..7] / 0xe080[0..4]: Apple's kext form is 0 outside partition mode */ + memset(w + 0x108, 0, 0x50); + /* usc_sr_size (bits 9-14) counted at twice the unit: 0x202 -> 0x402; the other fields, as the undocumented bits 15 and up, stay */ + put32(w + 0x3bc, (g->eot[2] & ~(0x3fu << 9)) | (((((g->eot[2] >> 9) & 0x3f) * 2) & 0x3f) << 9)); + put32(w + 0x3c8, max(1u, 0x2000u / ((g->pixel_output_width ?: 2) << 10))); /* half the A9's count: 4 at width 2 */ + return 0; +} + +/* + * The A8X's fragment job: its scene's geometry job was submitted before it + * (the A8's pairing: vm->t7000.open and the data set). The A9's 3D record, + * microsequence and barrier (s8003_job_write, frag = true: CMD_WAIT on the + * TA's finish stamp) on the A8's bookkeeping. + */ +static int t7001_submit_frag(struct pvr_apple *apple, struct s8003_vm *vm, struct pvr_job *job) +{ + struct pvr_apple_s8003 *s = apple->chip_data; + u32 addr = s8003_channel_addr(s, APPLE_ENGINE_FRAG); + u32 ta_addr = s8003_channel_addr(s, APPLE_ENGINE_GEOM); + u8 *p = s8003_channel(s, APPLE_ENGINE_FRAG); + u64 t0 = arch_timer_read_counter(), t2; + struct s8003_rt rt; + u32 seq; + int err; + + if (!vm->t7000.open || vm->t7000.hwrt != job->hwrt || vm->t7000.built != s->gen) + return s8003_submit_error(apple, vm, "fragment", -ECANCELED, S8003_REFUSED_NO_GEOM, + "its geometry job failed or was not submitted"); + err = s8003_rt_derive(job->hwrt->hwrt_dataset, &rt); + if (err) + return s8003_submit_error(apple, vm, "fragment", err, S8003_REFUSED_RT, + "rt derive"); + if (apple->frag_seq) + err = s8003_wait_done(apple, APPLE_ENGINE_FRAG, apple->frag_seq - 1); + if (err) + return s8003_submit_error(apple, vm, "fragment", err, S8003_REFUSED_SLOT_WAIT, + "record slot wait"); + t2 = arch_timer_read_counter(); + err = t7000_publish_check(apple, APPLE_ENGINE_FRAG); + if (err) + return s8003_submit_error(apple, vm, "fragment", err, S8003_REFUSED_PUBLISH, + "publish"); + t7000_submit_times(s, APPLE_ENGINE_FRAG, t0, t0, t2); + + seq = apple->frag_seq + 1; + err = t7001_fill_3d(p + s8003_slot_of(seq, true).w, s->v->soc, job->cmd, job->hwrt, &rt); + if (err) + return s8003_submit_error(apple, vm, "fragment", err, S8003_REFUSED_FILL, + "3D record fill"); + s8003_job_write(s, p, addr, s8003_object_addr(&s->layout, S8003_CHANNEL + 1), + s8003_meta_addr(S8003_ROOT_VA + t7000_pm_control_va(vm)), vm->slot[0], + vm->slot[0], true, seq, ta_addr + S8003_CH_STAMP + 4, vm->t7000.ta_seq, true, 0, true); + vm->t7000.open = false; + apple->frag_seq = seq; + t7000_publish(apple, APPLE_ENGINE_FRAG, (2 * seq) % S8003_CH_ENTRIES); + return seq; +} + /* The A8's records */ #define T7000_TA_W_SIZE 0x568 #define T7000_3D_W_SIZE 0x8b0 @@ -7806,6 +7916,49 @@ static const struct s8003_variant s8003_variant_a7 = { .event_fault = t7000_event_fault, }; +/* + * A device-control command was not taken (the firmware stopped serving its + * rings): the DC ring and the slot's tags, the engines' + * objects (+0x724 the 3D engine busy/idle words, +0x734 busy, +0x77c flag, + * +0x830 the TA's), CONTROL's counters, then the hang report. Read-only. + */ +static void t7001_dc_report(struct pvr_apple *apple, u32 slot) +{ + struct pvr_apple_s8003 *s = apple->chip_data; + u8 *dc = s8003_object(s, S8003_DC_CTL), *ring = s8003_object(s, S8003_DC_RING); + u8 *control = s8003_object(s, S8003_CONTROL); + u32 producer = ring_read(dc, S8003_RING_PRODUCER); + u32 prev = (producer + APPLE_RING_ENTRIES - 1) % APPLE_RING_ENTRIES; + unsigned int e; + + dev_err(apple_dev(apple), "DC: consumer %u producer %u, entry %u %*ph, entry %u %*ph\n", + ring_read(dc, S8003_RING_CONSUMER), producer, prev, 16, ring + prev * S8003_DC_SIZE, + (prev + APPLE_RING_ENTRIES - 1) % APPLE_RING_ENTRIES, 16, + ring + ((prev + APPLE_RING_ENTRIES - 1) % APPLE_RING_ENTRIES) * S8003_DC_SIZE); + dev_err(apple_dev(apple), "DC: slot %u tag host %#x seen %#x, root %#llx; CONTROL +0x20 %#x +0x1020 %#x +0x1024 %#x\n", + slot, get32(s8003_object(s, S8003_TAG_HOST) + 4 * slot), + get32(s8003_object(s, S8003_TAG_SEEN) + 4 * slot), + le64_to_cpu(*(__le64 *)(s8003_object(s, S8003_MMU_ROOT) + 8 * slot)), + get32(control + 0x20), get32(control + 0x1020), get32(control + 0x1024)); + for (e = 0; e < 3; e++) { + u8 *obj = s8003_object(s, S8003_CHANNEL + e); + + dev_err(apple_dev(apple), "DC: object %#x +0x724 %#x +0x728 %#x +0x72c %#x +0x734 %#x +0x75c %#x +0x77c %#x +0x830 %#x\n", + S8003_CHANNEL + e, get32(obj + 0x724), get32(obj + 0x728), get32(obj + 0x72c), + get32(obj + 0x734), get32(obj + 0x75c), get32(obj + 0x77c), get32(obj + 0x830)); + } + { /* the DM0 gate inputs and the last 3D record's tail */ + u8 *pol = s8003_object(s, S8003_POLICY), *o4b = s8003_object(s, 0x4b); + u8 *w = s8003_channel(s, APPLE_ENGINE_FRAG) + T7000_RCH_W; + + dev_err(apple_dev(apple), "DC: POLICY +8 %#x +0xc %#x +0x34 %#x; CONTROL +0x1c %#x; obj4b %*ph\n", + get32(pol + 8), get32(pol + 0xc), get32(pol + 0x34), get32(control + 0x1c), + 40, o4b); + dev_err(apple_dev(apple), "DC: 3D tail +0x868 %*ph\n", 0x58, w + 0x868); + } + t7000_report_hang(apple); +} + /* * The A8X: the A8's SoC steps, boot and objects in the kernel VM, the A9's * INIT, CONTROL, POLICY and channels, its own PLATFORM (t7001_init_chip()). @@ -7817,7 +7970,8 @@ static const struct s8003_variant s8003_variant_a8x = { .fws = t7001_fw_layouts, .nr_fws = ARRAY_SIZE(t7001_fw_layouts), .prepare = t7001_pmgr_prepare, - .jobs = BIT(DRM_PVR_JOB_TYPE_COMPUTE) | BIT(DRM_PVR_JOB_TYPE_GEOMETRY), /* the A9-form compute and TA records; fragment follows (the A8's forms would reach a 19H394 firmware) */ + .dc_report = t7001_dc_report, + .jobs = BIT(DRM_PVR_JOB_TYPE_COMPUTE) | BIT(DRM_PVR_JOB_TYPE_GEOMETRY) | BIT(DRM_PVR_JOB_TYPE_FRAGMENT), /* the A9-form compute, TA and 3D records (the A8's forms would reach a 19H394 firmware) */ .page_size = SZ_4K, .image_layout = t7000_ldr_layout, /* image size, segments, core memory */ .root_size = T7000_ROOT_SIZE, @@ -7855,7 +8009,7 @@ static const struct s8003_variant s8003_variant_a8x = { .engine_done = t7000_engine_done, .prepare_job = t7000_prepare_job, .submit_geom = t7001_submit_geom, - .submit_frag = t7000_submit_frag, + .submit_frag = t7001_submit_frag, .submit_compute = t7001_submit_compute, .report_hang = t7000_report_hang, .event_fault = t7000_event_fault,