From 1ccee5b0b1574973eaad1161d7f48ada4507afbc Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Sat, 31 Oct 2026 10:27:58 -0400 Subject: [PATCH 01/47] dt-bindings: display: apple: describe a common scanout aperture Document the display consumer's optional DMA aperture, which can differ from the defaults of individual scanout DARTs. Include the T8122 display subsystem compatible so its shared aperture is checked by this binding. Assisted-by: OpenAI Codex (gpt-6.1-sol) Signed-off-by: DjDeveloperr Signed-off-by: Scott Jones --- .../bindings/display/apple,display-subsystem.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Documentation/devicetree/bindings/display/apple,display-subsystem.yaml b/Documentation/devicetree/bindings/display/apple,display-subsystem.yaml index ac106575a9672..d2f0438188560 100644 --- a/Documentation/devicetree/bindings/display/apple,display-subsystem.yaml +++ b/Documentation/devicetree/bindings/display/apple,display-subsystem.yaml @@ -19,6 +19,7 @@ properties: - enum: - apple,display-subsystem - apple,t6031-display-subsystem + - apple,t8122-display-subsystem - apple,t8132-display-subsystem - const: apple,t8132-display-diagnostics deprecated: true @@ -50,6 +51,15 @@ properties: type: boolean description: The loader validated the inherited J713 SID0 scanout mapping. + apple,dma-range: + $ref: /schemas/types.yaml#/definitions/uint64-array + minItems: 2 + maxItems: 2 + description: + Common scanout DMA aperture, encoded as a base and nonzero size. This + overrides the default aperture of each referenced DART stream. Other + consumers of the same DART retain their own apertures. + required: - compatible - iommus From 130cd47bac10f3b4e3ced98dcc9f1ed3660f03a1 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Sat, 31 Oct 2026 10:27:58 -0400 Subject: [PATCH 02/47] iommu/apple-dart: honor consumer apertures before intersecting streams Domain allocation already lets a consumer specify apple,dma-range, but of_xlate intersects the provider defaults before that override is read. A consumer with a common scanout alias and DARTs with disjoint defaults therefore fails configuration before its domain can be allocated. Apply the same consumer aperture while parsing each specifier, retaining validation of both explicit five-cell windows and the override. Share the alignment, overflow and alias-width checks. Consumers without an override keep their existing windows. Add KUnit cases for the J613 high scanout alias across internal/external DART defaults, independent low PIODMA, malformed overrides and invalid five-cell specifiers. An ASAN/UBSAN fixture executing the production parser and of_xlate reproduces the old rejection and accepts the common window. Assisted-by: OpenAI Codex (gpt-6.1-sol) Signed-off-by: DjDeveloperr Signed-off-by: Scott Jones --- drivers/iommu/apple-dart-test.c | 104 ++++++++++++++++++++++++++++++++ drivers/iommu/apple-dart.c | 81 +++++++++++++++---------- 2 files changed, 153 insertions(+), 32 deletions(-) diff --git a/drivers/iommu/apple-dart-test.c b/drivers/iommu/apple-dart-test.c index dcb65db633d80..f5c8efc52e7f9 100644 --- a/drivers/iommu/apple-dart-test.c +++ b/drivers/iommu/apple-dart-test.c @@ -90,6 +90,108 @@ static void apple_dart_test_iommu_specifiers(struct kunit *test) } } +static void apple_dart_test_consumer_window(struct kunit *test) +{ + __be32 value[] = { cpu_to_be32(0x100), 0, cpu_to_be32(0x10), 0 }; + struct property property = { + .name = "apple,dma-range", + .length = sizeof(value), + .value = value, + }; + struct device_node node = { .properties = &property }; + struct of_phandle_args args = { .args_count = 1 }; + struct apple_dart *dart; + struct device *dev; + dma_addr_t dma_min, dma_max; + int i, ret; + + dev = kunit_device_register(test, "apple-dart-consumer-window-test"); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev); + dart = kunit_kzalloc(test, sizeof(*dart), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, dart); + dart->ias = 36; + dart->pgsize = SZ_16K; + dev->of_node = &node; + + /* J613's common scanout aperture must survive both DART defaults. */ + for (i = 0; i < 2; i++) { + dart->dma_min = i ? 0 : 0x10000000000; + dart->dma_max = i ? 0xffffeffff : 0x10fffffffff; + ret = apple_dart_parse_dma_window(dev, dart, &args, + &dma_min, &dma_max); + KUNIT_EXPECT_EQ(test, ret, 0); + KUNIT_EXPECT_EQ(test, dma_min, (dma_addr_t)0x10000000000); + KUNIT_EXPECT_EQ(test, dma_max, (dma_addr_t)0x10fffffffff); + } + + /* Domain allocation gives the consumer priority over five-cell args too. */ + args.args_count = 5; + args.args[3] = 0xf; + args.args[4] = 0xffff0000; + ret = apple_dart_parse_dma_window(dev, dart, &args, &dma_min, &dma_max); + KUNIT_EXPECT_EQ(test, ret, 0); + KUNIT_EXPECT_EQ(test, dma_min, (dma_addr_t)0x10000000000); + KUNIT_EXPECT_EQ(test, dma_max, (dma_addr_t)0x10fffffffff); + + /* An override must not make a malformed stream specifier acceptable. */ + args.args[3] = 0; + args.args[4] = 0; + KUNIT_EXPECT_EQ(test, apple_dart_parse_dma_window(dev, dart, &args, + &dma_min, &dma_max), -EINVAL); + + /* PIODMA is a different consumer of the same external display DART. */ + dev->of_node = NULL; + args.args_count = 1; + args.args[0] = 4; + ret = apple_dart_parse_dma_window(dev, dart, &args, &dma_min, &dma_max); + KUNIT_EXPECT_EQ(test, ret, 0); + KUNIT_EXPECT_EQ(test, dma_min, (dma_addr_t)0); + KUNIT_EXPECT_EQ(test, dma_max, (dma_addr_t)0xffffeffff); +} + +static void apple_dart_test_invalid_consumer_window(struct kunit *test) +{ + static const struct { + u64 base, size; + } windows[] = { + { 0, 0 }, + { U64_MAX - SZ_16K + 1, 2 * SZ_16K }, + { 1, SZ_16K }, + { 0, SZ_16K + 1 }, + { 0, BIT_ULL(37) }, + }; + __be64 value[2]; + struct property property = { + .name = "apple,dma-range", + .length = sizeof(value), + .value = value, + }; + struct device_node node = { .properties = &property }; + struct of_phandle_args args = { .args_count = 1 }; + struct apple_dart *dart; + struct device *dev; + dma_addr_t dma_min, dma_max; + int i; + + dev = kunit_device_register(test, "apple-dart-invalid-window-test"); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev); + dart = kunit_kzalloc(test, sizeof(*dart), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, dart); + dart->ias = 36; + dart->pgsize = SZ_16K; + dev->of_node = &node; + for (i = 0; i < ARRAY_SIZE(windows); i++) { + value[0] = cpu_to_be64(windows[i].base); + value[1] = cpu_to_be64(windows[i].size); + KUNIT_EXPECT_EQ(test, apple_dart_parse_dma_window(dev, dart, &args, + &dma_min, &dma_max), -EINVAL); + } + property.length = sizeof(__be32); + KUNIT_EXPECT_LT(test, apple_dart_parse_dma_window(dev, dart, &args, + &dma_min, &dma_max), 0); + dev->of_node = NULL; +} + static void apple_dart_test_before_attach(struct kunit *test) { struct apple_dart_master_cfg master = {}; @@ -1174,6 +1276,8 @@ static struct kunit_case apple_dart_test_cases[] = { KUNIT_CASE(apple_dart_test_strict_engines), KUNIT_CASE(apple_dart_test_topology), KUNIT_CASE(apple_dart_test_iommu_specifiers), + KUNIT_CASE(apple_dart_test_consumer_window), + KUNIT_CASE(apple_dart_test_invalid_consumer_window), KUNIT_CASE(apple_dart_test_independent_remap_roots), KUNIT_CASE(apple_dart_test_before_attach), KUNIT_CASE(apple_dart_test_locked_handoff), diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index b97b0c3378e45..c7ebb762d515e 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -3849,10 +3849,37 @@ static void apple_dart_domain_free(struct iommu_domain *domain) kfree(dart_domain); } +static int apple_dart_validate_dma_window(struct device *dev, + const struct apple_dart *dart, + dma_addr_t dma_min, dma_addr_t length, + dma_addr_t *dma_max) +{ + if (!length) + return -EINVAL; + if (!IS_ALIGNED(dma_min, dart->pgsize) || !IS_ALIGNED(length, dart->pgsize)) { + dev_err(dev, "Unaligned DMA window %pad, %pad (0x%x)\n", + &dma_min, &length, dart->pgsize); + return -EINVAL; + } + if (check_add_overflow(dma_min, length - 1, dma_max)) { + dev_err(dev, "DMA window length (%pad) overflows range for start %pad\n", + &length, &dma_min); + return -EINVAL; + } + + /* High bits may select an alias, but the window must fit within it. */ + if ((dma_min ^ *dma_max) & ~DMA_BIT_MASK(dart->ias)) { + dev_err(dev, "Invalid DMA window for ias=%d\n", dart->ias); + return -EINVAL; + } + return 0; +} + /* * Work out the DMA window of one "iommus" specifier. One cell is the stream * ID alone and keeps the window of the DART node. Five cells add the 64-bit - * start and length of the window that the device uses. + * start and length of the window that the device uses. A consumer's + * apple,dma-range overrides either default, as it does at domain allocation. */ static int apple_dart_parse_dma_window(struct device *dev, const struct apple_dart *dart, @@ -3861,43 +3888,33 @@ static int apple_dart_parse_dma_window(struct device *dev, dma_addr_t *dma_max) { dma_addr_t length; + u64 window[2]; + int ret; + if (args->args_count != 1 && args->args_count != 5) + return -EINVAL; *dma_min = dart->dma_min; *dma_max = dart->dma_max; - if (args->args_count == 1) - return 0; - if (args->args_count != 5) - return -EINVAL; - - length = ((dma_addr_t)args->args[3] << 32) | args->args[4]; - if (!length) - return -EINVAL; - - if (*dma_min != 0 || *dma_max != DMA_BIT_MASK(dart->ias)) - dev_err(dev, "still using legacy \"apple,dma-range\" property\n"); - - *dma_min = ((dma_addr_t)args->args[1] << 32) | args->args[2]; - - if (!IS_ALIGNED(*dma_min, dart->pgsize) || - !IS_ALIGNED(length, dart->pgsize)) { - dev_err(dev, "Unaligned DMA window %pad, %pad (0x%x)\n", - dma_min, &length, dart->pgsize); - return -EINVAL; - } - if (check_add_overflow(*dma_min, length - 1, dma_max)) { - dev_err(dev, "DMA window length (%pad) overflows range for start %pad\n", - &length, dma_min); - return -EINVAL; - } - - /* Ensure that the DMA window does not exceed the DART's ias. */ - if ((*dma_min ^ *dma_max) & ~DMA_BIT_MASK(dart->ias)) { - dev_err(dev, "Invalid DMA window for ias=%d\n", dart->ias); - return -EINVAL; + if (args->args_count == 5) { + if (*dma_min != 0 || *dma_max != DMA_BIT_MASK(dart->ias)) + dev_err(dev, "still using legacy \"apple,dma-range\" property\n"); + *dma_min = ((dma_addr_t)args->args[1] << 32) | args->args[2]; + length = ((dma_addr_t)args->args[3] << 32) | args->args[4]; + ret = apple_dart_validate_dma_window(dev, dart, *dma_min, length, dma_max); + if (ret) + return ret; } - return 0; + /* Apply the consumer aperture before intersecting its DART windows. */ + if (!of_property_present(dev->of_node, "apple,dma-range")) + return 0; + ret = of_property_read_u64_array(dev->of_node, "apple,dma-range", + window, ARRAY_SIZE(window)); + if (ret) + return ret; + *dma_min = window[0]; + return apple_dart_validate_dma_window(dev, dart, *dma_min, window[1], dma_max); } static int apple_dart_of_xlate(struct device *dev, From 4e3334872df8d6e618c7089ab7e87a3c68760508 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Sat, 31 Oct 2026 10:27:59 -0400 Subject: [PATCH 03/47] arm64: dts: apple: t8122: retain the common scanout DMA alias The display gate adds the external display DART to the shared display subsystem. Its low PIODMA default does not overlap the internal display's inherited 1 TiB alias, so their defaults cannot be intersected for scanout. Describe the subsystem's common scanout aperture explicitly, matching the internal DART. The external PIODMA consumer retains its existing low aperture and the external processor still requires the firmware-ready gate. This is a software-validated candidate; hardware external-display qualification remains pending. Assisted-by: OpenAI Codex (gpt-6.1-sol) Signed-off-by: DjDeveloperr Signed-off-by: Scott Jones --- arch/arm64/boot/dts/apple/t8122-dcp.dtsi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8122-dcp.dtsi b/arch/arm64/boot/dts/apple/t8122-dcp.dtsi index 8d812eae377e8..59233e5138ed4 100644 --- a/arch/arm64/boot/dts/apple/t8122-dcp.dtsi +++ b/arch/arm64/boot/dts/apple/t8122-dcp.dtsi @@ -33,6 +33,8 @@ display: display-subsystem { compatible = "apple,t8122-display-subsystem"; iommus = <&disp0_dart 0>; + /* Keep the inherited scanout alias when adding external streams. */ + apple,dma-range = /bits/ 64 <0x10000000000 0x1000000000>; status = "disabled"; }; }; From e57886c269dfa1ef3d46038147e95c37c6c65be3 Mon Sep 17 00:00:00 2001 From: Nikita Konkov <95355711+javanoo6@users.noreply.github.com> Date: Thu, 5 Nov 2026 12:11:51 +0300 Subject: [PATCH 04/47] drm/asahi: g15: pin J514S cd05 firmware TEXT The J514S 14.7 boot chain can load a T6030 firmware build whose full TEXT digest is not in the admission table. Probe refuses it and no GPU render node is created. Desktop use with the explicit prefix override reaches firmware READY and reduces Hyprland CPU use from several cores to single-digit percentages. Pin the complete measured digest only for J514S, with its segment sizes and marker, rather than requiring a persistent bring-up override. Exercise the production firmware table and exact lookup with the override disabled. Reject other boards, altered digest suffixes, sizes and markers. Link: https://github.com/omacom/linux-aurora/issues/247 Signed-off-by: Nikita Konkov <95355711+javanoo6@users.noreply.github.com> Signed-off-by: Scott Jones --- drivers/gpu/drm/asahi/g15/hw.rs | 15 ++++++++++ tools/asahi/g15-maintained-handoff-tests.py | 31 +++++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/asahi/g15/hw.rs b/drivers/gpu/drm/asahi/g15/hw.rs index b211088310210..36310376e12b5 100644 --- a/drivers/gpu/drm/asahi/g15/hw.rs +++ b/drivers/gpu/drm/asahi/g15/hw.rs @@ -175,6 +175,21 @@ pub(crate) mod t6030 { 0xe7, 0x9b, 0xb9, 0xb0, 0x22, 0x09, 0xdb, 0x53, ], }, + // J514S firmware measured on the 14.7 boot chain; desktop rendering + // was verified with the bring-up prefix override (issue #247). + FirmwareBuild { + name: "J514S cd05 firmware (14.7 boot chain)", + machine: Some(kernel::c_str!("apple,j514s")), + text_size: 0x5c000, + data_size: 0x114000, + marker: 0x58e88, + text_sha256: [ + 0xcd, 0x05, 0xaf, 0x6a, 0x82, 0x8b, 0x52, 0xe4, + 0xc2, 0xfe, 0xd2, 0x00, 0x86, 0xd3, 0xd1, 0x8a, + 0x7d, 0xb4, 0x2e, 0x03, 0xa8, 0xfd, 0x6f, 0x83, + 0x54, 0xf9, 0xf0, 0x6e, 0x0a, 0x61, 0x36, 0x3e, + ], + }, ], machine: kernel::c_str!("apple,t6030"), platform: super::Platform::AdtWithPmp, diff --git a/tools/asahi/g15-maintained-handoff-tests.py b/tools/asahi/g15-maintained-handoff-tests.py index fdafd799645cb..e0fb4438de379 100644 --- a/tools/asahi/g15-maintained-handoff-tests.py +++ b/tools/asahi/g15-maintained-handoff-tests.py @@ -137,12 +137,38 @@ def item(s, marker): OWNER_CALLS.set(0); let bytes = fixture(kind); assert!(parse(&dev, &Adt { data: &bytes }).is_err()); assert_eq!(OWNER_CALLS.get(), 0); } - assert_eq!(BUILDS.len(), 3, "maintained B0 firmware row must not require an absent profile symbol"); + assert_eq!(BUILDS.len(), 4, "maintained B0 firmware row must not require an absent profile symbol"); for (row, machine) in [(1, &b"apple,j516s"[..]), (2, &b"apple,j514s"[..])] { assert_eq!(BUILDS[row].machine.unwrap().to_bytes(), machine); assert_eq!((BUILDS[row].text_size, BUILDS[row].data_size, BUILDS[row].marker), (0x5c000, 0x114000, 0x58e88)); assert_eq!(BUILDS[row].text_sha256, [0xda,0x26,0xec,0xca,0xb1,0xf8,0x59,0x8d,0xa8,0x0c,0x85,0x5e,0xca,0x91,0x65,0x20,0x40,0x6d,0x1d,0x06,0x70,0xf1,0xd4,0x70,0xe7,0x9b,0xb9,0xb0,0x22,0x09,0xdb,0x53]); } + // Issue #247: this J514S build must pin without the bring-up override. + use identity::lookup::{Measured, Verdict, verdict}; + let measured = Measured { + text_size: 0x5c000, data_size: 0x114000, marker: 0x58e88, + sha256: [0xcd,0x05,0xaf,0x6a,0x82,0x8b,0x52,0xe4, + 0xc2,0xfe,0xd2,0x00,0x86,0xd3,0xd1,0x8a, + 0x7d,0xb4,0x2e,0x03,0xa8,0xfd,0x6f,0x83, + 0x54,0xf9,0xf0,0x6e,0x0a,0x61,0x36,0x3e], + }; + let identify = |m: &Measured, machine: &[u8]| verdict(m, BUILDS.iter().map(|b| ( + Measured { text_size: b.text_size, data_size: b.data_size, + marker: b.marker, sha256: b.text_sha256 }, + b.machine.map_or(true, |board| board.to_bytes() == machine), + )), 0); + assert!(matches!(identify(&measured, b"apple,j514s"), Verdict::Pinned(_)), + "J514S cd05 firmware must pin without a prefix override"); + assert_eq!(identify(&measured, b"apple,j516s"), Verdict::Refused); + let mut changed = measured; + changed.sha256[31] ^= 1; + assert_eq!(identify(&changed, b"apple,j514s"), Verdict::Refused); + changed = measured; changed.text_size += 0x1000; + assert_eq!(identify(&changed, b"apple,j514s"), Verdict::Refused); + changed = measured; changed.data_size += 0x1000; + assert_eq!(identify(&changed, b"apple,j514s"), Verdict::Refused); + changed = measured; changed.marker += 8; + assert_eq!(identify(&changed, b"apple,j514s"), Verdict::Refused); for error in [0, -517, -12] { INIT_ERROR.set(error); let shared = Arc::new(Shared); let result = Rtkit::new(&dev, &shared); assert_eq!(result.is_ok(), error == 0); @@ -167,7 +193,8 @@ def main(): while depth: depth+=(hw[end]=='[')-(hw[end]==']'); end+=1 firmware='static BUILDS: &[FirmwareBuild] = &'+hw[start:end]+';\n'+item(hw,'pub(crate) struct FirmwareBuild') constructor=item(boot,' fn new(dev: &device::Device, shared: &Arc)') - source=PREFIX+'\nmod hw {\n'+constants+'\n}\nmod record {\n'+record_constants+'\n}\n'+helpers+'\n'+firmware+'\nimpl Rtkit {\n'+constructor+'\n}\n'+CASES + identity='mod identity {\n'+''.join(f'#[path = "{G15 / "identity" / (name + ".rs")}"] pub(crate) mod {name};\n' for name in ['matching', 'lookup'])+'}\n' + source=PREFIX+'\nmod hw {\n'+constants+'\n}\nmod record {\n'+record_constants+'\n}\n'+helpers+'\n'+firmware+'\nimpl Rtkit {\n'+constructor+'\n}\n'+identity+CASES variants={'actual':source} if a.mutations: variants['skip-owner-check']=source.replace('if !glue::reserved_uat(i as u32, r.start, r.end - r.start) {','if false {') From bcd44e5d6bc144ebc1e90cb96f66a1049d96413a Mon Sep 17 00:00:00 2001 From: Scott Jones Date: Sun, 8 Nov 2026 00:39:01 -0500 Subject: [PATCH 05/47] tools/asahi: refresh T6030 golden pins for the J514S cd05 row The J514S cd05 FirmwareBuild row adds 15 lines to the T6030 firmware table, which changes the pinned hw.rs file and t6030 module digests. With that row removed both digests are their previous values, so the T6030 profile itself is unchanged. Refresh the two pins and record why. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Scott Jones --- tools/asahi/g15-zero-words-tests.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tools/asahi/g15-zero-words-tests.py b/tools/asahi/g15-zero-words-tests.py index c6e32d76cb415..2a73390f55282 100644 --- a/tools/asahi/g15-zero-words-tests.py +++ b/tools/asahi/g15-zero-words-tests.py @@ -18,9 +18,11 @@ renumbering margins became tuning constants (the tables are unchanged). Its T6030 configuration module is independently pinned to the original bytes, -except for the J514S B0 FirmwareBuild row added to its firmware table: the -module is the original pinned bytes (0079ae08) plus that one 15-line row, and -the whole hw.rs pin was refreshed with it. prepare_board() is pinned too; +except for the J514S B0 FirmwareBuild row and the J514S cd05 FirmwareBuild row +added to its firmware table: the module is the original pinned bytes (0079ae08) +plus those two 15-line rows, and the whole hw.rs pin was refreshed with each +(with the cd05 row removed, both pins are their earlier values e9b80be9 and +cab592b5). prepare_board() is pinned too; it was refreshed for the same Board change (its T6030 arm is unchanged). """ @@ -37,11 +39,11 @@ GOLDEN_FILES = { "board/data.rs": "7c5ff1077ca3296cbfc9e7144294162b6dea78a3774c38eeed4b0f59a14d7a5c", "board/template.rs": "286872f5474a67534f214e83e659253299f85143f3dc59035fa80894022e2549", - "hw.rs": "c54a4f8342fb466f82f4b9cfed6a137ee1ca1f4d80ede4e1b7f397d39223558e", + "hw.rs": "82ee9d163da888e6dc506635e8e4a59cd3f4b4c34b3879e162702b8561093d9e", "power/idle.rs": "4928ecf7699b3ca85ff5143eb6e996efd40d47321e29a238a02c8873bc9f102c", } GOLDEN_FUNCTIONS = { - ("hw.rs", "pub(crate) mod t6030 {"): "cab592b5d776be9ede93b96b1b0526c1d838ef2948a5e4a86caa4ec71f71c2ca", + ("hw.rs", "pub(crate) mod t6030 {"): "d6c3020007646cba504db26bdfe5232e45185aba1d4603931da9a8d29bec40de", ("initdata.rs", "fn templates("): "c3115c9926d3d7d93317cb8510e93b04f30b0c256811d7137568e822dd93b8ee", ("initdata.rs", "pub(crate) fn prepare_board("): "ebef64ab87ef7b1f994eb7fa2a2424d05bc4fc9e88cbfbf18e51570bdfc4222d", ("board.rs", "pub(crate) fn from_adt("): "cecd0b28db5bd94d3b75c1bbb5f35204e8bf0699f74e5b3d08228c59025f6ac2", From cbfc6b031b11208b21f7d0968507c6cab64d60a6 Mon Sep 17 00:00:00 2001 From: joel cristobal Date: Fri, 6 Nov 2026 02:07:57 -0500 Subject: [PATCH 06/47] drm/asahi: g15: pin the cd05 firmware TEXT on the J516S Some 16-inch M3 Pro (J516S) units on the 14.7 boot chain load a B0 GPU firmware image whose TEXT digest differs from the pinned J516S row: TEXT 0x5c000, DATA 0x114000, GKTS marker 0x58e88 and TEXT sha256 cd05af6a828b52e4c2fed20086d3d18a7db42e03a8fd6f8354f9f06e0a61363e. The build is refused with "loaded GFX TEXT identity mismatch", so there is no render node and the compositor falls back to llvmpipe. The GPU only starts with the g15_accept_text_prefix bring-up override. Add this build as a J516S-only row. Rows still pin on the machine they name; nothing changes on the J514S or on other machines. Extend the maintained-handoff host test to check the new row and refresh the zero-words golden pins for hw.rs and the T6030 module, which change by exactly this one row. Measured on a J516S (apple,j516s apple,t6030; os-fw 14.7, system-fw 15.5, iBoot2 iBoot-10151.140.19.700.2) with linux-aurora 7.2.11.aurora14-1 and the override: the admission line reports the identical sizes, marker and digest, and the GPU reaches READY with renderD128 present. Link: https://github.com/omacom/linux-aurora/issues/247 Link: https://github.com/omacom/omarchy/issues/17739 Signed-off-by: joel cristobal Signed-off-by: Scott Jones --- drivers/gpu/drm/asahi/g15/hw.rs | 16 ++++++++++++++++ tools/asahi/g15-maintained-handoff-tests.py | 9 ++++++--- tools/asahi/g15-zero-words-tests.py | 14 +++++++------- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/asahi/g15/hw.rs b/drivers/gpu/drm/asahi/g15/hw.rs index 36310376e12b5..14e4c92a60888 100644 --- a/drivers/gpu/drm/asahi/g15/hw.rs +++ b/drivers/gpu/drm/asahi/g15/hw.rs @@ -190,6 +190,22 @@ pub(crate) mod t6030 { 0x54, 0xf9, 0xf0, 0x6e, 0x0a, 0x61, 0x36, 0x3e, ], }, + // Some J516S units on the same 14.7 boot chain load a different B0 + // TEXT image with identical sizes and marker. Pin its complete + // measured digest for the J516S only. + FirmwareBuild { + name: "J516S cd05 firmware (14.7 boot chain)", + machine: Some(kernel::c_str!("apple,j516s")), + text_size: 0x5c000, + data_size: 0x114000, + marker: 0x58e88, + text_sha256: [ + 0xcd, 0x05, 0xaf, 0x6a, 0x82, 0x8b, 0x52, 0xe4, + 0xc2, 0xfe, 0xd2, 0x00, 0x86, 0xd3, 0xd1, 0x8a, + 0x7d, 0xb4, 0x2e, 0x03, 0xa8, 0xfd, 0x6f, 0x83, + 0x54, 0xf9, 0xf0, 0x6e, 0x0a, 0x61, 0x36, 0x3e, + ], + }, ], machine: kernel::c_str!("apple,t6030"), platform: super::Platform::AdtWithPmp, diff --git a/tools/asahi/g15-maintained-handoff-tests.py b/tools/asahi/g15-maintained-handoff-tests.py index e0fb4438de379..f2e344697dc3d 100644 --- a/tools/asahi/g15-maintained-handoff-tests.py +++ b/tools/asahi/g15-maintained-handoff-tests.py @@ -137,12 +137,15 @@ def item(s, marker): OWNER_CALLS.set(0); let bytes = fixture(kind); assert!(parse(&dev, &Adt { data: &bytes }).is_err()); assert_eq!(OWNER_CALLS.get(), 0); } - assert_eq!(BUILDS.len(), 4, "maintained B0 firmware row must not require an absent profile symbol"); + assert_eq!(BUILDS.len(), 5, "maintained B0 firmware row must not require an absent profile symbol"); for (row, machine) in [(1, &b"apple,j516s"[..]), (2, &b"apple,j514s"[..])] { assert_eq!(BUILDS[row].machine.unwrap().to_bytes(), machine); assert_eq!((BUILDS[row].text_size, BUILDS[row].data_size, BUILDS[row].marker), (0x5c000, 0x114000, 0x58e88)); assert_eq!(BUILDS[row].text_sha256, [0xda,0x26,0xec,0xca,0xb1,0xf8,0x59,0x8d,0xa8,0x0c,0x85,0x5e,0xca,0x91,0x65,0x20,0x40,0x6d,0x1d,0x06,0x70,0xf1,0xd4,0x70,0xe7,0x9b,0xb9,0xb0,0x22,0x09,0xdb,0x53]); } + assert_eq!(BUILDS[4].machine.unwrap().to_bytes(), b"apple,j516s"); + assert_eq!((BUILDS[4].text_size, BUILDS[4].data_size, BUILDS[4].marker), (0x5c000, 0x114000, 0x58e88)); + assert_eq!(BUILDS[4].text_sha256, [0xcd,0x05,0xaf,0x6a,0x82,0x8b,0x52,0xe4,0xc2,0xfe,0xd2,0x00,0x86,0xd3,0xd1,0x8a,0x7d,0xb4,0x2e,0x03,0xa8,0xfd,0x6f,0x83,0x54,0xf9,0xf0,0x6e,0x0a,0x61,0x36,0x3e]); // Issue #247: this J514S build must pin without the bring-up override. use identity::lookup::{Measured, Verdict, verdict}; let measured = Measured { @@ -157,9 +160,9 @@ def item(s, marker): marker: b.marker, sha256: b.text_sha256 }, b.machine.map_or(true, |board| board.to_bytes() == machine), )), 0); - assert!(matches!(identify(&measured, b"apple,j514s"), Verdict::Pinned(_)), + assert!(matches!(identify(&measured, b"apple,j514s"), Verdict::Pinned(3)), "J514S cd05 firmware must pin without a prefix override"); - assert_eq!(identify(&measured, b"apple,j516s"), Verdict::Refused); + assert_eq!(identify(&measured, b"apple,j516s"), Verdict::Pinned(4)); let mut changed = measured; changed.sha256[31] ^= 1; assert_eq!(identify(&changed, b"apple,j514s"), Verdict::Refused); diff --git a/tools/asahi/g15-zero-words-tests.py b/tools/asahi/g15-zero-words-tests.py index 2a73390f55282..ae40a73974969 100644 --- a/tools/asahi/g15-zero-words-tests.py +++ b/tools/asahi/g15-zero-words-tests.py @@ -18,11 +18,11 @@ renumbering margins became tuning constants (the tables are unchanged). Its T6030 configuration module is independently pinned to the original bytes, -except for the J514S B0 FirmwareBuild row and the J514S cd05 FirmwareBuild row -added to its firmware table: the module is the original pinned bytes (0079ae08) -plus those two 15-line rows, and the whole hw.rs pin was refreshed with each -(with the cd05 row removed, both pins are their earlier values e9b80be9 and -cab592b5). prepare_board() is pinned too; +except for the J514S B0 FirmwareBuild row and the J514S cd05 and J516S cd05 +FirmwareBuild rows added to its firmware table: the module is the original +pinned bytes (0079ae08) plus those three rows, and the whole hw.rs pin was +refreshed with each (with the cd05 rows removed, both pins are their earlier +values e9b80be9 and cab592b5). prepare_board() is pinned too; it was refreshed for the same Board change (its T6030 arm is unchanged). """ @@ -39,11 +39,11 @@ GOLDEN_FILES = { "board/data.rs": "7c5ff1077ca3296cbfc9e7144294162b6dea78a3774c38eeed4b0f59a14d7a5c", "board/template.rs": "286872f5474a67534f214e83e659253299f85143f3dc59035fa80894022e2549", - "hw.rs": "82ee9d163da888e6dc506635e8e4a59cd3f4b4c34b3879e162702b8561093d9e", + "hw.rs": "95e745970891153307a8d6bbc04749d553de7fb490b9ef2ff0563cde7252d8bc", "power/idle.rs": "4928ecf7699b3ca85ff5143eb6e996efd40d47321e29a238a02c8873bc9f102c", } GOLDEN_FUNCTIONS = { - ("hw.rs", "pub(crate) mod t6030 {"): "d6c3020007646cba504db26bdfe5232e45185aba1d4603931da9a8d29bec40de", + ("hw.rs", "pub(crate) mod t6030 {"): "2667963ad7a0957bacf8118965a500586637b622a99e49916f111fcd02670fcd", ("initdata.rs", "fn templates("): "c3115c9926d3d7d93317cb8510e93b04f30b0c256811d7137568e822dd93b8ee", ("initdata.rs", "pub(crate) fn prepare_board("): "ebef64ab87ef7b1f994eb7fa2a2424d05bc4fc9e88cbfbf18e51570bdfc4222d", ("board.rs", "pub(crate) fn from_adt("): "cecd0b28db5bd94d3b75c1bbb5f35204e8bf0699f74e5b3d08228c59025f6ac2", From 03fce6f1ac8e40273ac79c1e4bf0817a33e11ea2 Mon Sep 17 00:00:00 2001 From: Scott Jones Date: Sun, 8 Nov 2026 15:32:06 -0500 Subject: [PATCH 07/47] drm/asahi: g15: pin the 4118 firmware TEXT on the J514S and J516S Some 14-inch (J514S) and 16-inch (J516S) M3 Pro units on the 14.7 boot chain load a third B0 GPU firmware image: TEXT 0x5c000, DATA 0x114000, GKTS marker 0x58e88 and TEXT sha256 411833a7ded773feeac4a181552e3ff5582eaf4435f2dd8f620c1ed0b31df1b0. No row pins it, so probe fails with "loaded GFX TEXT identity mismatch", there is no render node and the compositor falls back to llvmpipe. Three machines have reported it in issue omacom/linux-aurora#247, all on the 14.7 stub with system firmware 26.6.2: a J514S and a J516S (both iBoot-10151.140.19.700.2, mBoot-18000.161.10), which logged the identical sizes, marker and digest, and a second 14-inch M3 Pro. With g15_accept_text_prefix=0x411833a7ded773fe all three reached firmware READY with renderD128 present. The boot chain matches the J514S cd05 reports, so the chain alone does not select the image. Add one row per board, J514S then J516S, so each pin still names the machine it was measured on; nothing changes for other machines. Extend the maintained-handoff host test: both boards pin to their own row with the override disabled, other boards are refused, and an altered digest suffix, TEXT or DATA size or marker is refused. Refresh the zero-words golden pins for hw.rs and the T6030 module; with the two rows removed both are their previous values. Link: https://github.com/omacom/linux-aurora/issues/247 Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Scott Jones --- drivers/gpu/drm/asahi/g15/hw.rs | 32 +++++++++++++++++++++ tools/asahi/g15-maintained-handoff-tests.py | 32 ++++++++++++++++++++- tools/asahi/g15-zero-words-tests.py | 15 +++++----- 3 files changed, 71 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/asahi/g15/hw.rs b/drivers/gpu/drm/asahi/g15/hw.rs index 14e4c92a60888..be319b0cd2702 100644 --- a/drivers/gpu/drm/asahi/g15/hw.rs +++ b/drivers/gpu/drm/asahi/g15/hw.rs @@ -206,6 +206,38 @@ pub(crate) mod t6030 { 0x54, 0xf9, 0xf0, 0x6e, 0x0a, 0x61, 0x36, 0x3e, ], }, + // J514S (14-inch) firmware measured on the 14.7 boot chain with + // system firmware 26.6.2; the GPU reached READY with the bring-up + // prefix override (issue #247). + FirmwareBuild { + name: "J514S 4118 firmware (14.7 boot chain)", + machine: Some(kernel::c_str!("apple,j514s")), + text_size: 0x5c000, + data_size: 0x114000, + marker: 0x58e88, + text_sha256: [ + 0x41, 0x18, 0x33, 0xa7, 0xde, 0xd7, 0x73, 0xfe, + 0xea, 0xc4, 0xa1, 0x81, 0x55, 0x2e, 0x3f, 0xf5, + 0x58, 0x2e, 0xaf, 0x44, 0x35, 0xf2, 0xdd, 0x8f, + 0x62, 0x0c, 0x1e, 0xd0, 0xb3, 0x1d, 0xf1, 0xb0, + ], + }, + // J516S (16-inch) firmware measured on the 14.7 boot chain with + // system firmware 26.6.2; the GPU reached READY with the bring-up + // prefix override (issue #247). + FirmwareBuild { + name: "J516S 4118 firmware (14.7 boot chain)", + machine: Some(kernel::c_str!("apple,j516s")), + text_size: 0x5c000, + data_size: 0x114000, + marker: 0x58e88, + text_sha256: [ + 0x41, 0x18, 0x33, 0xa7, 0xde, 0xd7, 0x73, 0xfe, + 0xea, 0xc4, 0xa1, 0x81, 0x55, 0x2e, 0x3f, 0xf5, + 0x58, 0x2e, 0xaf, 0x44, 0x35, 0xf2, 0xdd, 0x8f, + 0x62, 0x0c, 0x1e, 0xd0, 0xb3, 0x1d, 0xf1, 0xb0, + ], + }, ], machine: kernel::c_str!("apple,t6030"), platform: super::Platform::AdtWithPmp, diff --git a/tools/asahi/g15-maintained-handoff-tests.py b/tools/asahi/g15-maintained-handoff-tests.py index f2e344697dc3d..738facb331e52 100644 --- a/tools/asahi/g15-maintained-handoff-tests.py +++ b/tools/asahi/g15-maintained-handoff-tests.py @@ -137,7 +137,7 @@ def item(s, marker): OWNER_CALLS.set(0); let bytes = fixture(kind); assert!(parse(&dev, &Adt { data: &bytes }).is_err()); assert_eq!(OWNER_CALLS.get(), 0); } - assert_eq!(BUILDS.len(), 5, "maintained B0 firmware row must not require an absent profile symbol"); + assert_eq!(BUILDS.len(), 7, "maintained B0 firmware row must not require an absent profile symbol"); for (row, machine) in [(1, &b"apple,j516s"[..]), (2, &b"apple,j514s"[..])] { assert_eq!(BUILDS[row].machine.unwrap().to_bytes(), machine); assert_eq!((BUILDS[row].text_size, BUILDS[row].data_size, BUILDS[row].marker), (0x5c000, 0x114000, 0x58e88)); @@ -172,6 +172,36 @@ def item(s, marker): assert_eq!(identify(&changed, b"apple,j514s"), Verdict::Refused); changed = measured; changed.marker += 8; assert_eq!(identify(&changed, b"apple,j514s"), Verdict::Refused); + // Issue #247: the 4118 build pins on the J514S and the J516S, each to + // its own row, without the bring-up override. + let digest = [0x41,0x18,0x33,0xa7,0xde,0xd7,0x73,0xfe, + 0xea,0xc4,0xa1,0x81,0x55,0x2e,0x3f,0xf5, + 0x58,0x2e,0xaf,0x44,0x35,0xf2,0xdd,0x8f, + 0x62,0x0c,0x1e,0xd0,0xb3,0x1d,0xf1,0xb0]; + for (row, machine) in [(5, &b"apple,j514s"[..]), (6, &b"apple,j516s"[..])] { + assert_eq!(BUILDS[row].machine.unwrap().to_bytes(), machine); + assert_eq!((BUILDS[row].text_size, BUILDS[row].data_size, BUILDS[row].marker), (0x5c000, 0x114000, 0x58e88)); + assert_eq!(BUILDS[row].text_sha256, digest); + } + let measured = Measured { text_size: 0x5c000, data_size: 0x114000, marker: 0x58e88, sha256: digest }; + assert_eq!(identify(&measured, b"apple,j514s"), Verdict::Pinned(5), + "J514S 4118 firmware must pin without a prefix override"); + assert_eq!(identify(&measured, b"apple,j516s"), Verdict::Pinned(6), + "J516S 4118 firmware must pin without a prefix override"); + for other in [&b"apple,j514c"[..], b"apple,j516c", b"apple,j514m", b"apple,j516m", b"apple,t6030"] { + assert_eq!(identify(&measured, other), Verdict::Refused); + } + for machine in [&b"apple,j514s"[..], b"apple,j516s"] { + let mut changed = measured; + changed.sha256[31] ^= 1; + assert_eq!(identify(&changed, machine), Verdict::Refused); + changed = measured; changed.text_size += 0x1000; + assert_eq!(identify(&changed, machine), Verdict::Refused); + changed = measured; changed.data_size += 0x1000; + assert_eq!(identify(&changed, machine), Verdict::Refused); + changed = measured; changed.marker += 8; + assert_eq!(identify(&changed, machine), Verdict::Refused); + } for error in [0, -517, -12] { INIT_ERROR.set(error); let shared = Arc::new(Shared); let result = Rtkit::new(&dev, &shared); assert_eq!(result.is_ok(), error == 0); diff --git a/tools/asahi/g15-zero-words-tests.py b/tools/asahi/g15-zero-words-tests.py index ae40a73974969..3a31cba6958bf 100644 --- a/tools/asahi/g15-zero-words-tests.py +++ b/tools/asahi/g15-zero-words-tests.py @@ -18,11 +18,12 @@ renumbering margins became tuning constants (the tables are unchanged). Its T6030 configuration module is independently pinned to the original bytes, -except for the J514S B0 FirmwareBuild row and the J514S cd05 and J516S cd05 -FirmwareBuild rows added to its firmware table: the module is the original -pinned bytes (0079ae08) plus those three rows, and the whole hw.rs pin was -refreshed with each (with the cd05 rows removed, both pins are their earlier -values e9b80be9 and cab592b5). prepare_board() is pinned too; +except for the J514S B0 FirmwareBuild row, the J514S cd05 and J516S cd05 +FirmwareBuild rows and the J514S 4118 and J516S 4118 FirmwareBuild rows added +to its firmware table: the module is the original pinned bytes (0079ae08) plus +those five rows, and the whole hw.rs pin was refreshed with each (with the 4118 +rows removed, both pins are their earlier values fb2118b6 and 2667963a; with +the cd05 rows also removed, e9b80be9 and cab592b5). prepare_board() is pinned too; it was refreshed for the same Board change (its T6030 arm is unchanged). """ @@ -39,11 +40,11 @@ GOLDEN_FILES = { "board/data.rs": "7c5ff1077ca3296cbfc9e7144294162b6dea78a3774c38eeed4b0f59a14d7a5c", "board/template.rs": "286872f5474a67534f214e83e659253299f85143f3dc59035fa80894022e2549", - "hw.rs": "95e745970891153307a8d6bbc04749d553de7fb490b9ef2ff0563cde7252d8bc", + "hw.rs": "f45a0f11f952fea4e36809267ffd240ee1e381e8f3400de5e8527cd316b9f225", "power/idle.rs": "4928ecf7699b3ca85ff5143eb6e996efd40d47321e29a238a02c8873bc9f102c", } GOLDEN_FUNCTIONS = { - ("hw.rs", "pub(crate) mod t6030 {"): "2667963ad7a0957bacf8118965a500586637b622a99e49916f111fcd02670fcd", + ("hw.rs", "pub(crate) mod t6030 {"): "4016ec0d46831482382a92791b625e10fb2f6e4e28115a9498fdde0776f82e52", ("initdata.rs", "fn templates("): "c3115c9926d3d7d93317cb8510e93b04f30b0c256811d7137568e822dd93b8ee", ("initdata.rs", "pub(crate) fn prepare_board("): "ebef64ab87ef7b1f994eb7fa2a2424d05bc4fc9e88cbfbf18e51570bdfc4222d", ("board.rs", "pub(crate) fn from_adt("): "cecd0b28db5bd94d3b75c1bbb5f35204e8bf0699f74e5b3d08228c59025f6ac2", From d46d1f15c9f7bd4f1869f75b4ddbe26552a34a79 Mon Sep 17 00:00:00 2001 From: Scott Jones Date: Fri, 13 Nov 2026 14:06:58 -0500 Subject: [PATCH 08/47] drm/asahi: g15: decline probes before activation with -ENODEV Before the module's final activate() step, the G15 probe returned -EPROBE_DEFER. That put the GPU on the driver core's deferred-probe list. activate() then runs the real probe through driver_attach(), but if that probe fails for good, for example because the firmware is rejected, the driver core does not take the device off the list. It stays in /sys/kernel/debug/devices_deferred until the deferred-probe work next runs, so anything that waits on that list keeps waiting. Return -ENODEV instead. activate() already reprobes every unbound device once MODULE_READY is set, and a device added later sees it set, so nothing needs the deferred list to retry. The display and PMP waits inside the real probe still return -EPROBE_DEFER. g15-probe-init-tests.py now checks that every probe before activation returns -ENODEV, and adds a mutant that defers again. Assisted-by: Claude:claude-opus-5-5 Co-Authored-By: Claude Opus 5.5 Signed-off-by: Scott Jones (cherry picked from commit 6447458068e3 on omacom/linux-aurora, omacom/linux-aurora#470) [7.3 base: the probe-init test also runs with the G16 registration here, so its pre-activation probe count follows the registration order; the new mutant is added to this base's expected-failure table.] --- drivers/gpu/drm/asahi/g15/mod.rs | 5 ++++- tools/asahi/g15-probe-init-tests.py | 25 +++++++++++++++++++++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/asahi/g15/mod.rs b/drivers/gpu/drm/asahi/g15/mod.rs index 4cb221fb0a5df..9553dc46f3c55 100644 --- a/drivers/gpu/drm/asahi/g15/mod.rs +++ b/drivers/gpu/drm/asahi/g15/mod.rs @@ -202,8 +202,11 @@ impl platform::Driver for Driver<'_> { // after probe_g15 started firmware would return an unbound device. try_pin_init!(Driver { _driver: { + // Not EPROBE_DEFER: a deferred device stays listed in devices_deferred until the + // deferred-probe work runs, even after activate()'s probe fails for good. Activation + // reprobes every unbound device; a device added later sees MODULE_READY set. if !MODULE_READY.load(Ordering::Acquire) { - return Err(EPROBE_DEFER); + return Err(ENODEV); } let cfg = *info.ok_or(ENODEV)?; dev_info!(pdev.as_ref(), "G15: probing ({})\n", cfg.name); diff --git a/tools/asahi/g15-probe-init-tests.py b/tools/asahi/g15-probe-init-tests.py index a7b9b900b7af5..133df94793352 100644 --- a/tools/asahi/g15-probe-init-tests.py +++ b/tools/asahi/g15-probe-init-tests.py @@ -82,6 +82,7 @@ def item(text, marker): static EXEC_SHARE_READY: Cell = const { Cell::new(false) }; static ATTACH_ERROR: Cell = const { Cell::new(false) }; static PROBE_ERROR: Cell = const { Cell::new(0) }; + static PRE_ACTIVATION: Cell = const { Cell::new(0) }; } struct Core<'a>(PhantomData<&'a ()>); struct Device { data: Cell<*mut core::ffi::c_void> } @@ -184,7 +185,16 @@ def item(text, marker): }; // Model driver_attach and a late driver_add_groups failure. A deferred // worker can also retry G15 while the other registration is in progress. - let _ = callback::>(&PDEV, Some(&&CFG)); + let ready = MODULE_READY.load(Ordering::Acquire); + let started = PROBES.get(); + let result = callback::>(&PDEV, Some(&&CFG)); + // A probe that started firmware here is the readiness-gate failure, checked below. + if !ready && PROBES.get() == started { + // A deferral would keep the GPU in devices_deferred after a later + // terminal failure; before activation the probe must decline outright. + assert_eq!(result, Err(ENODEV), "pre-activation probe deferred instead of ENODEV"); + PRE_ACTIVATION.set(PRE_ACTIVATION.get() + 1); + } if FAIL_REGISTRATION.get() == stage { return Err(-5); } COMPLETED_REGISTRATION.set(stage); stage @@ -252,7 +262,7 @@ def item(text, marker): PDEV.base.data.set(core::ptr::null_mut()); MODULE_READY.store(false, Ordering::Release); COMPLETED_REGISTRATION.set(0); FAIL_REGISTRATION.set(failure); - ACTIVATED.set(false); ATTACH_ERROR.set(failure == 0); + ACTIVATED.set(false); ATTACH_ERROR.set(failure == 0); PRE_ACTIVATION.set(0); let init = ::init(&MODULE); assert_eq!(PROBES.get(), 0, "module initializer eagerly started firmware"); let result = KBox::pin_init(init, GFP_KERNEL); @@ -269,6 +279,12 @@ def item(text, marker): assert!(!PDEV.base.data.get().is_null()); unsafe { drop(Box::from_raw(PDEV.base.data.get().cast::>())); } } + // Every probe before activation declined: one per completed or failing registration. + // The registrations run G15 (1), the generic driver (2), then G16 (3) where it is built. + let expected = if cfg!(CONFIG_DRM_ASAHI_G16) { + match failure { 1 => 1, 2 => 2, _ => 3 } + } else if failure == 1 { 1 } else { 2 }; + assert_eq!(PRE_ACTIVATION.get(), expected, "pre-activation probes"); println!("module-registration-{failure}: PASS"); } } @@ -415,9 +431,10 @@ def main(): needle = " None\n" assert probe.count(needle) == 1 variants["retained-error-unbinds"] = (probe.replace(needle, " return Err(error);\n"), module_code) - gate = " if !MODULE_READY.load(Ordering::Acquire) {\n return Err(EPROBE_DEFER);\n }\n" + gate = " if !MODULE_READY.load(Ordering::Acquire) {\n return Err(ENODEV);\n }\n" assert probe.count(gate) == 1 variants["no-registration-readiness-gate"] = (probe.replace(gate, ""), module_code) + variants["pre-activation-defers"] = (probe.replace(gate, gate.replace("ENODEV", "EPROBE_DEFER")), module_code) late = " #[cfg(CONFIG_DRM_ASAHI_G15)]\n _g15_ready: g15::activate(),\n" assert module_code.count(late) == 1 early = module_code.replace(late, "").replace(" _driver <-", late + " _driver <-", 1) @@ -446,7 +463,7 @@ def main(): else: receipt["mutants"][label] = result if r.returncode == 0: raise SystemExit("SURVIVED: " + name) - intended = {"eager-probe-before-allocation": "allocation-before-start: firmware probe before drvdata allocation", "retained-error-unbinds": "retained-start-failure-binds: callback result", "no-registration-readiness-gate": "late registration failure started firmware", "activation-before-last-registration": "activation before all registrations completed", "activation-before-g16-registration": "activation before all registrations completed"}[name] + intended = {"pre-activation-defers": "pre-activation probe deferred instead of ENODEV", "eager-probe-before-allocation": "allocation-before-start: firmware probe before drvdata allocation", "retained-error-unbinds": "retained-start-failure-binds: callback result", "no-registration-readiness-gate": "late registration failure started firmware", "activation-before-last-registration": "activation before all registrations completed", "activation-before-g16-registration": "activation before all registrations completed"}[name] result["intended_failure"] = intended in r.stderr if not result["intended_failure"]: raise SystemExit("INVALID unrelated failure: " + name + "\n" + r.stderr) (out / "result.json").write_text(json.dumps(receipt, indent=2) + "\n") From 580bd669d5f9270be480ef4e99471facda7eefd3 Mon Sep 17 00:00:00 2001 From: Scott Jones Date: Fri, 23 Oct 2026 00:24:18 -0400 Subject: [PATCH 09/47] pmdomain: apple: pmp-report: keep the T8122 14.x GPU readiness for the M3 runtime The 7.2 rebase replaced the T8122 14.x branch of apple_pmp_report_wait_supplier_ready() with a T6030-only one, so on an M3 MacBook Air every GPU power vote returns -ENODEV even with the PMP running. With the new hidden APPLE_T8122_GPU_PMP_LINK, which DRM_ASAHI_M3_T8122 selects (as DRM_ASAHI_G15 selects APPLE_T6030_GPU_PMP_LINK), wait for the unique T8122 report's display request (DISP, reg 7) to be ready and acknowledged before AGX, as on the 7.1.12 kernel the runtime was qualified with. The PMP graph and supplier host tests copy the dispatch, so they copy the T8122 wait too, built off there; their mutations still target the T6030 path. Generated-by: LLM Co-Authored-By: Claude Opus 5.5 Signed-off-by: Scott Jones --- drivers/gpu/drm/asahi/Kconfig | 1 + drivers/pmdomain/apple/pmp-report.c | 43 ++++++++++++++++++++++++- drivers/soc/apple/Kconfig | 9 ++++++ tools/asahi/t6030-pmp-graph-tests.c | 1 + tools/asahi/t6030-pmp-graph-tests.py | 12 +++++-- tools/asahi/t6030-pmp-supplier-tests.py | 12 +++++++ 6 files changed, 74 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/asahi/Kconfig b/drivers/gpu/drm/asahi/Kconfig index d383802ee8825..03939a732fc24 100644 --- a/drivers/gpu/drm/asahi/Kconfig +++ b/drivers/gpu/drm/asahi/Kconfig @@ -84,6 +84,7 @@ config DRM_ASAHI_M3_T8122 depends on DRM_ASAHI # The runtime adopts the firmware's UAT through the G15 backend's handoff helpers. depends on DRM_ASAHI_G15 + select APPLE_T8122_GPU_PMP_LINK select CRYPTO_LIB_SHA256 default n help diff --git a/drivers/pmdomain/apple/pmp-report.c b/drivers/pmdomain/apple/pmp-report.c index 42bff817bfa78..b375a83b9e0a2 100644 --- a/drivers/pmdomain/apple/pmp-report.c +++ b/drivers/pmdomain/apple/pmp-report.c @@ -687,6 +687,44 @@ static int apple_pmp_report_wait_t6030_14(struct device *supplier, unsigned int return ret; } +/* + * The T8122 (M3 MacBook Air) GPU on its 14.8.3 firmware, for the M3 runtime + * (APPLE_T8122_GPU_PMP_LINK): the unique T8122 report linked to this PMP, and + * its display request (DISP, reg 7) READY and acknowledged before AGX, as on + * the 7.1.12 kernel that runtime was qualified with. + */ +static int apple_pmp_report_wait_t8122_14(struct device *supplier, unsigned int timeout_ms) +{ + struct device_node *np, *report = NULL, *pmp, *entry; + int ret; + + if (!IS_ENABLED(CONFIG_APPLE_T8122_GPU_PMP_LINK) || + !of_machine_is_compatible("apple,t8122") || + !of_device_is_compatible(supplier->of_node, "apple,t8122-pmp-v2")) + return -ENODEV; + for_each_compatible_node(np, NULL, "apple,t8122-pmp-v2-report") { + if (report) { + of_node_put(np); + of_node_put(report); + return -ENODEV; + } + report = of_node_get(np); + } + if (!report || !of_device_is_available(report) || + of_property_count_u32_elems(report, "apple,pmp") != 1) { + of_node_put(report); + return -ENODEV; + } + pmp = of_parse_phandle(report, "apple,pmp", 0); + entry = apple_pmp_report_t6030_entry(report); + ret = pmp == supplier->of_node && entry ? + apple_pmp_report_wait_ready(entry, msecs_to_jiffies(timeout_ms)) : -ENODEV; + of_node_put(entry); + of_node_put(pmp); + of_node_put(report); + return ret; +} + /* The native 25G83 PMP starts through its supplier topology, after requests * are seeded. Its report is pinned against removal while readiness is read. */ @@ -701,8 +739,11 @@ int apple_pmp_report_wait_supplier_ready(struct device *supplier, unsigned int t int ret; /* A declared report always takes the existing native25 path below. */ - if (!np && !of_property_present(supplier->of_node, "apple,pmp-report")) + if (!np && !of_property_present(supplier->of_node, "apple,pmp-report")) { + if (of_machine_is_compatible("apple,t8122")) + return apple_pmp_report_wait_t8122_14(supplier, timeout_ms); return apple_pmp_report_wait_t6030_14(supplier, timeout_ms); + } if (!np || !of_device_is_compatible(np, t8132 ? "apple,t8132-pmp-v2-report" : "apple,j613-25g83-pmp-report")) { of_node_put(np); diff --git a/drivers/soc/apple/Kconfig b/drivers/soc/apple/Kconfig index c8b50840a7dda..3f6db5ef17ad8 100644 --- a/drivers/soc/apple/Kconfig +++ b/drivers/soc/apple/Kconfig @@ -368,6 +368,15 @@ config APPLE_DISPLAY_GATE Say 'y' if you want the native display on M3 Pro, M3 Max, M3 and M4 Pro Macs. +config APPLE_T8122_GPU_PMP_LINK + bool + depends on APPLE_PMP_REPORT + default n + help + Let T8122 (M3 MacBook Air) GPU power commands wait for the display + request the PMP report acknowledges on the 14.8.3 firmware, as the + M3 runtime of DRM_ASAHI_M3_T8122 requires. + config APPLE_T6030_GPU_PMP_LINK bool depends on APPLE_DISPLAY_GATE diff --git a/tools/asahi/t6030-pmp-graph-tests.c b/tools/asahi/t6030-pmp-graph-tests.c index e89d982d2d0a6..89a6ac0efc8e7 100644 --- a/tools/asahi/t6030-pmp-graph-tests.c +++ b/tools/asahi/t6030-pmp-graph-tests.c @@ -20,6 +20,7 @@ typedef uint8_t u8; #define BIT(n) (1U << (n)) #define IS_ENABLED(x) (x) #define CONFIG_APPLE_T6030_GPU_PMP_LINK 1 +#define CONFIG_APPLE_T8122_GPU_PMP_LINK 0 #define PMP_REPORT_READY 1 #define GFP_KERNEL 0 #define GENPD_FLAG_ACTIVE_WAKEUP 1 diff --git a/tools/asahi/t6030-pmp-graph-tests.py b/tools/asahi/t6030-pmp-graph-tests.py index 4c85001acf1a8..c8a58b302e727 100644 --- a/tools/asahi/t6030-pmp-graph-tests.py +++ b/tools/asahi/t6030-pmp-graph-tests.py @@ -60,6 +60,12 @@ def main(): 'static int apple_pmp_report_entry_resume_noirq('] offsets = re.search(r'static const struct apple_pmp_report_offsets apple_pmp_offsets_t6030 = \{.*?\n\};', source, re.S)[0] functions = '\n'.join(extract.function(source, n) for n in names) + # The T8122 14.x wait (CONFIG_APPLE_T8122_GPU_PMP_LINK=0 here) precedes the dispatch; it is + # added after the mutations are placed, so they target the T6030 path only. + t8122 = extract.function(source, 'static int apple_pmp_report_wait_t8122_14(') + '\n' + dispatch = 'int apple_pmp_report_wait_supplier_ready(' + def with_t8122(text): + return text.replace(dispatch, t8122 + dispatch, 1) validation = re.sub(r'^#include .*\n', '', (ROOT / 'drivers/pmdomain/apple/pmp-report-validation.h').read_text(), flags=re.M) dram_type = re.search(r'struct apple_pmp_dram \{.*?\n\};', (ROOT / 'drivers/pmdomain/apple/pmp-dram.h').read_text(), re.S)[0] @@ -78,7 +84,7 @@ def main(): '\n' + dram_attrs + '\n' + functions) # The actual overlay must still describe a halted supplier and disabled DMA/mailbox. assert overlay.count('status = \"disabled\";') >= 3 - (args.output / 'production.h').write_text(code) + (args.output / 'production.h').write_text(with_t8122(code)) (args.output / 'overlay.h').write_text('static const struct overlay_entry overlay_entries[] = {\n' + entry_data + '\n};\n') compiler = shlex.split(os.environ.get('CC', 'clang')) command = compiler + ['-std=gnu11', '-g', '-O1', '-Wall', '-Wextra', '-Werror', @@ -133,13 +139,13 @@ def main(): ] for name, old, new in controls: assert code.count(old) == 1, (name, code.count(old)) - (args.output / 'production.h').write_text(code.replace(old, new)) + (args.output / 'production.h').write_text(with_t8122(code.replace(old, new))) built = subprocess.run(command, capture_output=True, text=True) # A mutant must compile; compilation failure is not regression evidence. ran = subprocess.run([str(args.output / 'graph')], capture_output=True, text=True) if not built.returncode else None (args.output / (name + '.log')).write_text(built.stdout + built.stderr + (ran.stdout + ran.stderr if ran else '')) mutations.append({'name': name, 'build_rc': built.returncode, 'run_rc': ran.returncode if ran else None}) - (args.output / 'production.h').write_text(code) + (args.output / 'production.h').write_text(with_t8122(code)) assert all(m['build_rc'] == 0 and m['run_rc'] != 0 for m in mutations), mutations (args.output / 'receipt.json').write_text(json.dumps({'source_ref': args.ref, 'source_sha256': hashlib.sha256(code.encode()).hexdigest(), 'overlay_sha256': hashlib.sha256(overlay.encode()).hexdigest(), 'overlay_entries': entries, diff --git a/tools/asahi/t6030-pmp-supplier-tests.py b/tools/asahi/t6030-pmp-supplier-tests.py index 269006b36aa4f..725e37e24f6cf 100755 --- a/tools/asahi/t6030-pmp-supplier-tests.py +++ b/tools/asahi/t6030-pmp-supplier-tests.py @@ -56,6 +56,7 @@ def run(out, name, code, compiler, configs=(0, 1)): command = compiler + ["-std=gnu11", "-g", "-O1", "-Wall", "-Wextra", "-Werror", "-fsanitize=address,undefined", "-fno-omit-frame-pointer", f"-DCONFIG_APPLE_T6030_GPU_PMP_LINK={config}", + "-DCONFIG_APPLE_T8122_GPU_PMP_LINK=0", "-I", str(dest), str(ROOT / "tools/asahi/t6030-pmp-supplier-tests.c"), "-o", str(binary)] @@ -148,6 +149,17 @@ def main(): assert code.count(old) == 1, (name, code.count(old)) variants.append((name, code.replace(old, new))) variants.append(("control-after", code)) + # The T8122 14.x wait is built with CONFIG_APPLE_T8122_GPU_PMP_LINK=0 here; it is added to + # every variant after the T6030 mutations are placed, so they target the T6030 path only. + dispatch = "int apple_pmp_report_wait_supplier_ready(" + t8122 = function(report, "static int apple_pmp_report_wait_t8122_14(") + "\n" + def with_t8122(source): + if dispatch not in source: + return source + return source.replace(dispatch, t8122 + dispatch, 1) + variants = [(name, with_t8122(source)) for name, source in variants] + if baseline_code and "apple_pmp_report_wait_t8122_14(" in baseline_code: + baseline_code = with_t8122(baseline_code) results = [run(args.output, name, source, compiler) for name, source in variants] if baseline_code: results.append(run(args.output, "control-prior-config-off", baseline_code, compiler, (0,))) From 9a2a398556a65a618a10aa7a2517ef43af18ba34 Mon Sep 17 00:00:00 2001 From: Scott Jones Date: Fri, 23 Oct 2026 11:00:54 -0400 Subject: [PATCH 10/47] tools/asahi: test the T8122 14.x PMP wait in the supplier suite The supplier suite built apple_pmp_report_wait_t8122_14() only with APPLE_T8122_GPU_PMP_LINK off, so every case returned at its first check. Build it also as the M3 runtime does (T6030 and T8122 links on) and run the T8122 graph: the unique, available report linked to this PMP, with DISP (reg 7) acked, and its failures (machine, supplier and report compatibles, a duplicate or disabled report, the apple,pmp shape and identity, a missing, duplicate, disabled, incompatible or no-ack DISP entry, the managed start and its readiness). With the link off, a well-formed T8122 graph is refused. Mutants cover the wait's config scope, compatibles, report checks, readiness result and entry reference, and the dispatch's machine scope in both directions. Reported-by: Marcelo Alcantara Generated-by: LLM Co-Authored-By: Claude Opus 5.5 (1M context) Signed-off-by: Scott Jones --- tools/asahi/t6030-pmp-supplier-tests.c | 60 +++++++++++++++++++++++-- tools/asahi/t6030-pmp-supplier-tests.py | 47 +++++++++++++++---- 2 files changed, 95 insertions(+), 12 deletions(-) diff --git a/tools/asahi/t6030-pmp-supplier-tests.c b/tools/asahi/t6030-pmp-supplier-tests.c index 59c2c0d3cd430..f9ad353872de1 100644 --- a/tools/asahi/t6030-pmp-supplier-tests.c +++ b/tools/asahi/t6030-pmp-supplier-tests.c @@ -489,6 +489,17 @@ static void reset(void) lockable = present_device = link_ok = 1; status_word = PMP_REPORT_READY; } +/* The T8122 (M3 Air) 14.x graph: the same report shape, with T8122 compatibles. */ +static void t8122(void) +{ + machine = "apple,t8122"; + gate_soc = &gate_t8122; + supplier_node.compatible = "apple,t8122-pmp-v2"; + other_node.compatible = "apple,t8122-pmp-v2"; + gpu.compatible = "apple,agx-t8122"; + report14.compatible = "apple,t8122-pmp-v2-report"; + apple_pmp_starts.first = &managed_start; +} static int power(void) { return apple_pmp_set_device_power(0x0f, 5, 1); @@ -518,6 +529,7 @@ int main(void) (void)gate_find_one; (void)apple_pmp_report_t6030_entry; (void)apple_pmp_report_wait_t6030_14; + (void)apple_pmp_report_wait_t8122_14; reset(); assert(apple_pmp_offsets_t6030.starts_pmp == !!CONFIG_APPLE_T6030_GPU_PMP_LINK); @@ -574,9 +586,50 @@ int main(void) RUN((void)0, -ENODEV, 0, 0); assert(!find_calls); #endif - /* T8122 current14 remains unsupported by this supplier API. */ + /* A T8122 supplier never takes the T6030 report. */ RUN(machine = "apple,t8122"; supplier_node.compatible = "apple,t8122-pmp-v2", -ENODEV, 0, 0); +#if CONFIG_APPLE_T8122_GPU_PMP_LINK + /* The T8122 14.x wait: one available report linked to this PMP, DISP (reg 7) acked. */ + RUN(t8122(), 0, 0, 1); + RUN(t8122(); report14.child = &entry7; entry7.sibling = &entry17; + entry17.sibling = NULL, 0, 0, 1); + RUN(t8122(); apple_pmp_starts.first = NULL, -ENODEV, 0, 0); + RUN(t8122(); apple_pmp_starts.first = NULL; + apple_pmp_reports.first = NULL, -EPROBE_DEFER, 0, 0); + RUN(t8122(); managed_start.stopping = true, -ENODEV, 0, 0); + RUN(t8122(); ready_result = -ETIMEDOUT, -ETIMEDOUT, 0, 0); + RUN(t8122(); passive_words[apple_pmp_offsets_t6030.status / 8] = 0, -EIO, + 0, 0); + RUN(t8122(); passive_words[apple_pmp_offsets_t6030.actual / 8] = 0, -EIO, + 0, 0); + RUN(t8122(); power_result = -EIO, -EIO, 0, 1); + RUN(t8122(); machine = "apple,t6030", -ENODEV, 0, 0); + RUN(t8122(); machine = "apple,t8112", -ENODEV, 0, 0); + RUN(t8122(); supplier_node.compatible = "apple,t6030-pmp-v2", -ENODEV, 0, + 0); + RUN(t8122(); report14.compatible = NULL, -ENODEV, 0, 0); + RUN(t8122(); report14.compatible = "apple,t6030-pmp-v2-report", -ENODEV, + 0, 0); + RUN(t8122(); extra_report = report14, -ENODEV, 0, 0); + RUN(t8122(); extra_report = report14; extra_report.available = false, + -ENODEV, 0, 0); + RUN(t8122(); report14.available = false, -ENODEV, 0, 0); + RUN(t8122(); report14.has_pmp = false, -ENODEV, 0, 0); + RUN(t8122(); report14.pmp_cells = 0, -ENODEV, 0, 0); + RUN(t8122(); report14.pmp_cells = 2, -ENODEV, 0, 0); + RUN(t8122(); report14.pmp = NULL, -ENODEV, 0, 0); + RUN(t8122(); report14.pmp = &other_node, -ENODEV, 0, 0); + RUN(t8122(); entry17.sibling = NULL, -ENODEV, 0, 0); + RUN(t8122(); entry7.reg = 8, -ENODEV, 0, 0); + RUN(t8122(); entry7.available = false, -ENODEV, 0, 0); + RUN(t8122(); entry7.compatible = "apple,other", -ENODEV, 0, 0); + RUN(t8122(); entry7.no_ack = true, -ENODEV, 0, 0); + RUN(t8122(); entry17.reg = 7, -ENODEV, 0, 0); +#else + /* Without APPLE_T8122_GPU_PMP_LINK, even a well-formed T8122 graph is refused. */ + RUN(t8122(), -ENODEV, 0, 0); +#endif /* A declared report, including malformed/unresolved data, never falls back. */ RUN(supplier_node.has_report = true; supplier_node.report_cells = 0, -ENODEV, 0, 0); @@ -716,7 +769,8 @@ int main(void) assert(apple_pmp_link_device(&consumer) == -EINVAL); balanced(); case_count++; - printf("PASS: %d T6030 PMP cases, config=%d; reference, lock and command boundaries checked\n", - case_count, CONFIG_APPLE_T6030_GPU_PMP_LINK); + printf("PASS: %d T6030/T8122 PMP cases, config=%d/%d; reference, lock and command boundaries checked\n", + case_count, CONFIG_APPLE_T6030_GPU_PMP_LINK, + CONFIG_APPLE_T8122_GPU_PMP_LINK); return 0; } diff --git a/tools/asahi/t6030-pmp-supplier-tests.py b/tools/asahi/t6030-pmp-supplier-tests.py index 725e37e24f6cf..aee98f9c59953 100755 --- a/tools/asahi/t6030-pmp-supplier-tests.py +++ b/tools/asahi/t6030-pmp-supplier-tests.py @@ -46,17 +46,23 @@ def no_core(): resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) -def run(out, name, code, compiler, configs=(0, 1)): +# (CONFIG_APPLE_T6030_GPU_PMP_LINK, CONFIG_APPLE_T8122_GPU_PMP_LINK): off, G15 only, and G15 +# with the M3 runtime (DRM_ASAHI_M3_T8122 depends on DRM_ASAHI_G15). +CONFIGS = ((0, 0), (1, 0), (1, 1)) + + +def run(out, name, code, compiler, configs=CONFIGS): dest = out / name dest.mkdir() (dest / "t6030-pmp-production.h").write_text(code) results = [] - for config in configs: + for t6030, t8122 in configs: + config = f"{t6030}{t8122}" binary = dest / f"config-{config}" command = compiler + ["-std=gnu11", "-g", "-O1", "-Wall", "-Wextra", "-Werror", "-fsanitize=address,undefined", "-fno-omit-frame-pointer", - f"-DCONFIG_APPLE_T6030_GPU_PMP_LINK={config}", - "-DCONFIG_APPLE_T8122_GPU_PMP_LINK=0", + f"-DCONFIG_APPLE_T6030_GPU_PMP_LINK={t6030}", + f"-DCONFIG_APPLE_T8122_GPU_PMP_LINK={t8122}", "-I", str(dest), str(ROOT / "tools/asahi/t6030-pmp-supplier-tests.c"), "-o", str(binary)] @@ -149,20 +155,43 @@ def main(): assert code.count(old) == 1, (name, code.count(old)) variants.append((name, code.replace(old, new))) variants.append(("control-after", code)) - # The T8122 14.x wait is built with CONFIG_APPLE_T8122_GPU_PMP_LINK=0 here; it is added to - # every variant after the T6030 mutations are placed, so they target the T6030 path only. + # The T8122 14.x wait mirrors the T6030 one, so it is added to every variant after the + # T6030 mutations are placed; its own mutants change only its text. dispatch = "int apple_pmp_report_wait_supplier_ready(" t8122 = function(report, "static int apple_pmp_report_wait_t8122_14(") + "\n" - def with_t8122(source): + def with_t8122(source, text=t8122): if dispatch not in source: return source - return source.replace(dispatch, t8122 + dispatch, 1) + return source.replace(dispatch, text + dispatch, 1) variants = [(name, with_t8122(source)) for name, source in variants] + if args.mutations: + t8122_mutations = [ + ("t8122-config-scope", "if (!IS_ENABLED(CONFIG_APPLE_T8122_GPU_PMP_LINK) ||", "if (false ||"), + ("t8122-supplier-compat", '!of_device_is_compatible(supplier->of_node, "apple,t8122-pmp-v2"))', "false)"), + ("t8122-report-compat", 'for_each_compatible_node(np, NULL, "apple,t8122-pmp-v2-report")', + 'for_each_compatible_node(np, NULL, "apple,t6030-pmp-v2-report")'), + ("t8122-duplicate-report", "\t\tif (report) {", "\t\tif (false) {"), + ("t8122-disabled-report", "!of_device_is_available(report) ||", "false ||"), + ("t8122-report-phandle-shape", 'of_property_count_u32_elems(report, "apple,pmp") != 1', "false"), + ("t8122-supplier-identity", "pmp == supplier->of_node && entry ?", "entry ?"), + ("t8122-readiness-error", "apple_pmp_report_wait_ready(entry, msecs_to_jiffies(timeout_ms)) : -ENODEV;", + "(apple_pmp_report_wait_ready(entry, msecs_to_jiffies(timeout_ms)), 0) : -ENODEV;"), + ("t8122-entry-reference", "\tof_node_put(entry);\n\tof_node_put(pmp);", "\tof_node_put(pmp);"), + ] + for name, old, new in t8122_mutations: + assert t8122.count(old) == 1, (name, t8122.count(old)) + variants.insert(-1, (name, with_t8122(code, t8122.replace(old, new)))) + # The dispatch owns the machine scope: T8122 takes the T8122 wait, every other SoC the + # T6030 one. (The wait's own machine check repeats it and cannot be reached otherwise.) + machine = 'if (of_machine_is_compatible("apple,t8122"))' + assert code.count(machine) == 1 + for name, new in (("t8122-dispatch-never", "if (false)"), ("t8122-dispatch-always", "if (true)")): + variants.insert(-1, (name, with_t8122(code.replace(machine, new)))) if baseline_code and "apple_pmp_report_wait_t8122_14(" in baseline_code: baseline_code = with_t8122(baseline_code) results = [run(args.output, name, source, compiler) for name, source in variants] if baseline_code: - results.append(run(args.output, "control-prior-config-off", baseline_code, compiler, (0,))) + results.append(run(args.output, "control-prior-config-off", baseline_code, compiler, ((0, 0),))) valid = True for item in results: control = item["name"].startswith("control-") From 5c2bc76d16e60dc726bff223194a3079656d0eed Mon Sep 17 00:00:00 2001 From: Scott Jones Date: Thu, 5 Nov 2026 13:07:46 -0500 Subject: [PATCH 11/47] drm/apple: add the J504 internal panel record The 14" M3 MacBook Pro (J504) runs the same T8122 DCP image as the M3 MacBook Airs (90F849E1-..., named by the J504 ADT), so the 14.x IOMFB path can drive its panel once the boot loader hands the display over. Its panel is the J514S mini-LED panel: 3024x1964 with 74 notch rows, at 60 or 120 Hz. Add a J504 record with that geometry, ProMotion allowed, bring-up logging on, and this image's colour matrix methods. The panel level block is not qualified on this board, so brightness stays closed, and its swaps keep zero timestamps as on the Airs. Other T8122 Macs (the J433 and J434 iMacs) still have no record. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Scott Jones --- drivers/gpu/drm/apple/iomfb_v14_7.c | 25 ++++++++++++++++ drivers/gpu/drm/apple/v14-board-test.c | 41 ++++++++++++++++++++++++++ tools/asahi/dcp14-panel-tests.py | 22 ++++++++++++-- 3 files changed, 86 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/apple/iomfb_v14_7.c b/drivers/gpu/drm/apple/iomfb_v14_7.c index a99bfed67183f..b7de4b21e60a5 100644 --- a/drivers/gpu/drm/apple/iomfb_v14_7.c +++ b/drivers/gpu/drm/apple/iomfb_v14_7.c @@ -140,6 +140,30 @@ static const struct dcp_v14_board dcp_v14_board_j615 = { .ctm_get = A(420), }; +/* + * J504 (MacBook Pro 14", M3): the J613 DCP image on the same T8122 DCP (the + * J504 ADT names it), driving the 14" mini-LED panel of the J514S: 3024x1964 + * with 74 notch rows above the 3024x1890 boot framebuffer, at 60 or 120 Hz. + * The colour matrix methods are this image's. The panel level block is not + * qualified on this board, so brightness stays closed (no panel_nits), and + * its swaps keep zero timestamps as on the Airs. Every panel timing and the + * display clock are logged for the first boots. + */ +static const struct dcp_v14_board dcp_v14_board_j504 = { + .name = "J504", + .debugfs = "dcp-j504", + .dcp_compatible = "apple,t8122-dcp", + .machine = "apple,j504", + .firmware_uuid = DCP_V14_J613_FIRMWARE_UUID, + .handoff = "apple,t8122-handoff", + .panel_width = 3024, + .panel_height = 1964, + .promotion = true, + .log_bringup = true, + .ctm_set = A(421), + .ctm_get = A(420), +}; + /* * J516C (MacBook Pro 16", M3 Max): the J516S panel, 3456x2234 with 74 notch * rows above the 3456x2160 boot framebuffer, at 60 or 120 Hz, on the T6031 @@ -193,6 +217,7 @@ static const struct dcp_v14_board *const dcp_v14_boards[] = { &dcp_v14_board_t6030, &dcp_v14_board_j613, &dcp_v14_board_j615, + &dcp_v14_board_j504, &dcp_v14_board_j516c, &dcp_v14_board_j514c, }; diff --git a/drivers/gpu/drm/apple/v14-board-test.c b/drivers/gpu/drm/apple/v14-board-test.c index f9b84ab36a7cc..2a41853d76dd2 100644 --- a/drivers/gpu/drm/apple/v14-board-test.c +++ b/drivers/gpu/drm/apple/v14-board-test.c @@ -54,6 +54,8 @@ static const char *const j514c[] = { "apple,j514c", "apple,t6031", "apple,arm-pl static const char *const j516m[] = { "apple,j516m", "apple,t6034", "apple,arm-platform", NULL }; static const char *const j516s[] = { "apple,j516s", "apple,t6030", "apple,arm-platform", NULL }; static const char *const j613[] = { "apple,j613", "apple,t8122", "apple,arm-platform", NULL }; +static const char *const j504[] = { "apple,j504", "apple,t8122", "apple,arm-platform", NULL }; +static const char *const j433[] = { "apple,j433", "apple,t8122", "apple,arm-platform", NULL }; static void v14_board_j516c(struct kunit *test) { @@ -247,7 +249,46 @@ static void v14_swap_timestamps_encoding(struct kunit *test) } } +/* + * J504 (14" M3 MacBook Pro): the J613 image on the T8122 DCP, its own 3024x1964 + * ProMotion panel, brightness closed and unstamped swaps. The other T8122 + * Macs (J433, J434) have no record. + */ +static void v14_board_j504(struct kunit *test) +{ + const struct dcp_v14_board *b, *air; + bool known; + + b = board_for("apple,t8122-dcp", j504, &known); + KUNIT_ASSERT_NOT_NULL(test, b); + air = board_for("apple,t8122-dcp", j613, &known); + KUNIT_ASSERT_NOT_NULL(test, air); + KUNIT_EXPECT_PTR_NE(test, b, air); + KUNIT_EXPECT_STREQ(test, b->name, "J504"); + KUNIT_EXPECT_STREQ(test, b->machine, "apple,j504"); + KUNIT_EXPECT_STREQ(test, b->handoff, "apple,t8122-handoff"); + KUNIT_EXPECT_STREQ(test, b->firmware_uuid, J613_DCP_IMAGE); + KUNIT_EXPECT_EQ(test, b->panel_width, 3024); + KUNIT_EXPECT_EQ(test, b->panel_height, 1964); + KUNIT_EXPECT_TRUE(test, b->promotion); + KUNIT_EXPECT_TRUE(test, b->log_bringup); + KUNIT_EXPECT_FALSE(test, b->panel_nits); + KUNIT_EXPECT_FALSE(test, b->base_edid); + KUNIT_EXPECT_EQ(test, b->ctm_set, air->ctm_set); + KUNIT_EXPECT_EQ(test, b->ctm_get, air->ctm_get); + KUNIT_EXPECT_TRUE(test, dcp_v14_board_admits(b, J613_DCP_IMAGE)); + KUNIT_EXPECT_FALSE(test, dcp_v14_board_admits(b, T6030_DCP_IMAGE)); + KUNIT_EXPECT_FALSE(test, dcp_v14_board_admits(b, J516C_DCP_IMAGE)); + KUNIT_EXPECT_FALSE(test, dcp_v14_board_stamps_swaps(b, false)); + + KUNIT_EXPECT_NULL(test, board_for("apple,t8122-dcp", j433, &known)); + KUNIT_EXPECT_TRUE(test, known); + /* A J504 root with another SoC's DCP gets no J504 record. */ + KUNIT_EXPECT_NULL(test, board_for("apple,t6031-dcp", j504, &known)); +} + static struct kunit_case v14_board_cases[] = { + KUNIT_CASE(v14_board_j504), KUNIT_CASE(v14_board_j516c), KUNIT_CASE(v14_board_j514c), KUNIT_CASE(v14_board_t6031_other_boards), diff --git a/tools/asahi/dcp14-panel-tests.py b/tools/asahi/dcp14-panel-tests.py index 0abcd1e89d3f9..b6c5979b11714 100755 --- a/tools/asahi/dcp14-panel-tests.py +++ b/tools/asahi/dcp14-panel-tests.py @@ -87,7 +87,25 @@ machine="apple,j613";const struct dcp_v14_board*j=iomfb_v14_7_board(&dev); assert(!IS_ERR(j)&&j->panel_width==2560 && j->panel_height==1664); machine="apple,j700";assert(IS_ERR(iomfb_v14_7_board(&dev))); - machine="apple,j504";assert(IS_ERR(iomfb_v14_7_board(&dev))); + /* J504 (14" M3 MacBook Pro): the J613 image, the J514 panel, 60 or 120 Hz. */ + machine="apple,j504";const struct dcp_v14_board*p14=iomfb_v14_7_board(&dev); + assert(!IS_ERR(p14)&&p14&&!strcmp(p14->name,"J504")&&!strcmp(p14->debugfs,"dcp-j504")); + assert(p14->panel_width==3024&&p14->panel_height==1964&&p14->promotion&&p14->log_bringup); + assert(!strcmp(p14->firmware_uuid,"90F849E1-B422-367E-B389-50246F8DEC47")); + assert(!strcmp(p14->handoff,"apple,t8122-handoff")&&!p14->panel_nits&&!p14->swap_timestamps); + assert(p14->ctm_set==A(421)&&p14->ctm_get==A(420)); + image_uuid=p14->firmware_uuid;assert(probe_gate(&dev,p14)==0); + image_uuid="C042E95C-B9D8-3F0E-94B3-582A08AA6FDD";assert(probe_gate(&dev,p14)==-ENODEV); + image_uuid="F493F03E-CC40-3D89-9A08-5F259BA2B246";assert(probe_gate(&dev,p14)==-ENODEV); + image_uuid=NULL;assert(probe_gate(&dev,p14)==-ENODEV); + image_uuid=p14->firmware_uuid;marker_value=0;assert(probe_gate(&dev,p14)==-ENODEV);marker_value=1; + {struct apple_dcp_v14 q={.dev=&dev,.board=p14};width=3024;height=1890;stride=width*4;notch=74; + assert(dcp_v14_geometry(&q)==0&&q.panel_height==1964&&q.notch_rows==74); + height=1964;notch=0;assert(dcp_v14_geometry(&q)==0&&q.panel_height==1964); + width=2560;height=1600;stride=width*4;notch=64;assert(dcp_v14_geometry(&q)==-EINVAL);} + /* Other T8122 Macs (J433/J434 iMacs) have no record. */ + machine="apple,j433";assert(IS_ERR(iomfb_v14_7_board(&dev))); + machine="apple,j434";assert(IS_ERR(iomfb_v14_7_board(&dev))); dcp.compatible="apple,t6030-dcp";machine="apple,j516s";assert(iomfb_v14_7_board(&dev)==&dcp_v14_board_t6030); dcp.compatible="apple,t8122-dcp"; struct apple_dcp_v14 v={.dev=&dev,.board=b};width=2880;height=1800;stride=width*4;notch=64; @@ -139,7 +157,7 @@ machine="apple,j613";assert(IS_ERR(iomfb_v14_7_board(&dev))); machine="apple,j516m";assert(IS_ERR(iomfb_v14_7_board(&dev))); dcp.compatible="apple,t6030-dcp";machine="apple,j516s";assert(iomfb_v14_7_board(&dev)==&dcp_v14_board_t6030); - puts("current J615/J613/T6030/J516C/J514C admission + hidden/full notch, wrong geometry controls: PASS"); + puts("current J615/J613/J504/T6030/J516C/J514C admission + hidden/full notch, wrong geometry controls: PASS"); #endif } ''' From 96634b073fd8309a7b0d4a513e91efae86008465 Mon Sep 17 00:00:00 2001 From: Scott Jones Date: Thu, 5 Nov 2026 13:07:46 -0500 Subject: [PATCH 12/47] drm/asahi: start the T8122 GPU runtime on the J504 The J504 (14" M3 MacBook Pro) loads the same 14.8.3 G15G firmware image as the M3 MacBook Airs (UUID DF697F05-..., TEXT 0x64000, from its ADT). Move the T8122 board list into t8122_admission as T8122_BOARDS, add the J504, and test the exact list on the host. Firmware identity, resource admission, the performance-state cap and the thermal limit are unchanged; the J504 starts at the same conservative cap (state 2) as the Airs. The J433 and J434 iMacs stay unlisted. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Scott Jones --- drivers/gpu/drm/asahi/m3/m3_params.rs | 8 ++++---- drivers/gpu/drm/asahi/m3/m3_soc.rs | 7 ++++--- drivers/gpu/drm/asahi/m3/m3_thermal_policy.rs | 1 + drivers/gpu/drm/asahi/m3/t8122_admission.rs | 17 +++++++++++++++++ drivers/gpu/drm/asahi/m3/t8122_start.rs | 4 ++-- 5 files changed, 28 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/asahi/m3/m3_params.rs b/drivers/gpu/drm/asahi/m3/m3_params.rs index 85033c88e4192..be675d60a730c 100644 --- a/drivers/gpu/drm/asahi/m3/m3_params.rs +++ b/drivers/gpu/drm/asahi/m3/m3_params.rs @@ -589,9 +589,9 @@ pub(crate) fn thermal_hot_param() -> (u64, bool) { /// Whether to start the runtime backend on a T8122 (`asahi.m3_backend`), and say why not. /// -/// The runtime starts only on the boards the T8122 table allows (the M3 MacBook Airs), with -/// `auto` and `runtime` alike: it has not run on any T8122, so nothing forces it onto another -/// board. The G15 manager backend is T6030-only. +/// The runtime starts only on the boards the T8122 table allows (the M3 MacBook Airs and the +/// 14" M3 MacBook Pro, `t8122_admission::T8122_BOARDS`), with `auto` and `runtime` alike: +/// nothing forces it onto another board. The G15 manager backend is T6030-only. pub(crate) fn t8122_backend(pdev: &platform::Device>) -> bool { let dev = pdev.as_ref(); match M3_BACKEND.load(Ordering::Relaxed) { @@ -610,7 +610,7 @@ pub(crate) fn t8122_backend(pdev: &platform::Device>) -> bool { _ => { dev_info!( dev, - "M3: no GPU backend on this T8122 board: the runtime backend may start only on the M3 MacBook Airs (J613, J615)\n" + "M3: no GPU backend on this T8122 board: the runtime backend may start only on the M3 MacBook Airs (J613, J615) and the 14\" M3 MacBook Pro (J504)\n" ); false } diff --git a/drivers/gpu/drm/asahi/m3/m3_soc.rs b/drivers/gpu/drm/asahi/m3/m3_soc.rs index 7500822c4124c..3dcd15c896a48 100644 --- a/drivers/gpu/drm/asahi/m3/m3_soc.rs +++ b/drivers/gpu/drm/asahi/m3/m3_soc.rs @@ -284,9 +284,10 @@ pub(crate) static T8122: Soc = Soc { gpu_revision_id: hw::GpuRevisionID::C0, board: "apple,t8122", gpu: "apple,agx-t8122", - // The M3 MacBook Airs (13" J613, 15" J615). Allowed, not validated: the runtime has not run - // on either, and starts only behind a boot loader that hands the GPU over. - validated_boards: &[b"apple,j613", b"apple,j615"], + // The M3 MacBook Airs (13" J613, 15" J615) and the 14" M3 MacBook Pro (J504), which loads + // the same G15G image (`t8122_admission::T8122_BOARDS`). The runtime starts only behind a + // boot loader that hands the GPU over. + validated_boards: &crate::m3::t8122_admission::T8122_BOARDS, clusters: 1, cores_per_cluster: 10, mailbox_compatibles: &[ diff --git a/drivers/gpu/drm/asahi/m3/m3_thermal_policy.rs b/drivers/gpu/drm/asahi/m3/m3_thermal_policy.rs index 2ae70634ff556..1b2412b7f7809 100644 --- a/drivers/gpu/drm/asahi/m3/m3_thermal_policy.rs +++ b/drivers/gpu/drm/asahi/m3/m3_thermal_policy.rs @@ -271,6 +271,7 @@ mod zone_tests { } assert_eq!(required_zones(b"apple,j613\0"), 1); assert_eq!(required_zones(b"apple,j615\0"), 1); + assert_eq!(required_zones(b"apple,j504\0apple,t8122\0"), 1); } #[test] diff --git a/drivers/gpu/drm/asahi/m3/t8122_admission.rs b/drivers/gpu/drm/asahi/m3/t8122_admission.rs index fb280ebcde520..ff6d098f50a3c 100644 --- a/drivers/gpu/drm/asahi/m3/t8122_admission.rs +++ b/drivers/gpu/drm/asahi/m3/t8122_admission.rs @@ -4,6 +4,12 @@ use super::m3_profile::Profile; +/// The T8122 boards the M3 runtime starts on by default: the M3 MacBook Airs (13" J613, 15" J615) +/// and the 14" M3 MacBook Pro (J504). All three load the same 14.8.3 G15G image (UUID +/// `DF697F05-…`, checked separately by firmware admission). The other T8122 Macs (the J433 and +/// J434 iMacs) are not listed. +pub(crate) const T8122_BOARDS: [&[u8]; 3] = [b"apple,j613", b"apple,j615", b"apple,j504"]; + #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub(crate) struct Identity { pub(crate) active_cores: u32, @@ -195,6 +201,17 @@ pub(crate) fn read_identity_for( #[cfg(test)] mod tests { + use super::T8122_BOARDS; + + #[test] + fn the_t8122_runtime_boards_are_exactly_the_airs_and_the_14_inch_pro() { + // Exact: dropping the J504 or adding another T8122 Mac (J433, J434) must fail here. + assert_eq!(T8122_BOARDS, [&b"apple,j613"[..], b"apple,j615", b"apple,j504"]); + for other in [&b"apple,j433"[..], b"apple,j434", b"apple,t8122"] { + assert!(!T8122_BOARDS.contains(&other)); + } + } + use super::*; const G15G_C0: u32 = 0x0702_2000; diff --git a/drivers/gpu/drm/asahi/m3/t8122_start.rs b/drivers/gpu/drm/asahi/m3/t8122_start.rs index 737034dd6f8c1..f4fe2bae341aa 100644 --- a/drivers/gpu/drm/asahi/m3/t8122_start.rs +++ b/drivers/gpu/drm/asahi/m3/t8122_start.rs @@ -301,8 +301,8 @@ pub(crate) fn arm(dev: &device::Device, soc: &Soc) -> Result> e.mapping_count(), storage::IOMAP_BASE ); - // J613/J615 have no SoC die temperature zone yet, so a cap above the no-feedback limit runs - // the fanless GPU without any temperature feedback (`m3_thermal` holds the cap but gets no + // J615 and J504 have no SoC die temperature zone yet, so a cap above the no-feedback limit + // runs the GPU without any temperature feedback (`m3_thermal` holds the cap but gets no // reading). The runtime cap and the firmware ceiling stay equal, because the cap is at most // the no-feedback limit. if v.pstate_cap > knobs::PSTATE_CAP { From 36d06f668c0161bf33bb9ad64c79cfdddad29c9b Mon Sep 17 00:00:00 2001 From: Scott Jones Date: Thu, 5 Nov 2026 13:07:47 -0500 Subject: [PATCH 13/47] arm64: dts: apple: t8122-j504: describe the internal panel Give the J504 DCP its panel node (the J514S 14" mini-LED panel: 302 x 196 mm, 189 mm below the notch, 500 nits) and point the boot framebuffer at it, as on the J613, so simpledrm and the DCP driver use the same physical size. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Scott Jones --- arch/arm64/boot/dts/apple/t8122-j504.dts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/t8122-j504.dts b/arch/arm64/boot/dts/apple/t8122-j504.dts index f8258ba3a2f54..f290f01120677 100644 --- a/arch/arm64/boot/dts/apple/t8122-j504.dts +++ b/arch/arm64/boot/dts/apple/t8122-j504.dts @@ -39,13 +39,23 @@ &dcp { panel: panel { compatible = "apple,panel-j504", "apple,panel-mini-led", "apple,panel"; + /* + * The J514S panel: 3024x1964 at 254 ppi; 189 mm high without the + * 74 notch rows. The J504 boot framebuffer is 3024x1890 below them. + */ width-mm = <302>; height-mm = <196>; adj-height-mm = <189>; - apple,max-brightness = <600>; + apple,max-brightness = <500>; }; }; +/* The boot framebuffer is the same panel, as on the J613 (HiDPI scale for simpledrm). */ +&framebuffer0 { + panel = <&panel>; + post-init-providers = <&panel>; +}; + &wifi0 { brcm,board-type = "apple,tresco"; }; From 004f77c442d66691e6770a58635d48420e8bd09c Mon Sep 17 00:00:00 2001 From: Scott Jones Date: Thu, 5 Nov 2026 14:05:23 -0500 Subject: [PATCH 14/47] drm/apple: open the J504 panel brightness path The J504 runs the J613's DCP image, whose panel level block (brightness in nits) is qualified on the J613. Mark the J504 record panel_nits and admit the J504 machine for it, with the KUnit and host tests. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Scott Jones --- drivers/gpu/drm/apple/iomfb_v14_7.c | 10 ++++++---- drivers/gpu/drm/apple/iomfb_v14_7_backlight_test.c | 8 +++++++- drivers/gpu/drm/apple/v14-board-test.c | 4 ++-- tools/asahi/dcp14-panel-tests.py | 2 +- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/apple/iomfb_v14_7.c b/drivers/gpu/drm/apple/iomfb_v14_7.c index b7de4b21e60a5..b520b0a2c3afa 100644 --- a/drivers/gpu/drm/apple/iomfb_v14_7.c +++ b/drivers/gpu/drm/apple/iomfb_v14_7.c @@ -144,9 +144,9 @@ static const struct dcp_v14_board dcp_v14_board_j615 = { * J504 (MacBook Pro 14", M3): the J613 DCP image on the same T8122 DCP (the * J504 ADT names it), driving the 14" mini-LED panel of the J514S: 3024x1964 * with 74 notch rows above the 3024x1890 boot framebuffer, at 60 or 120 Hz. - * The colour matrix methods are this image's. The panel level block is not - * qualified on this board, so brightness stays closed (no panel_nits), and - * its swaps keep zero timestamps as on the Airs. Every panel timing and the + * The colour matrix methods are this image's, and so is the panel level + * block the J613 qualified (brightness in nits, 500 at most here). Its swaps + * keep zero timestamps as on the Airs. Every panel timing and the * display clock are logged for the first boots. */ static const struct dcp_v14_board dcp_v14_board_j504 = { @@ -160,6 +160,7 @@ static const struct dcp_v14_board dcp_v14_board_j504 = { .panel_height = 1964, .promotion = true, .log_bringup = true, + .panel_nits = true, .ctm_set = A(421), .ctm_get = A(420), }; @@ -1719,7 +1720,8 @@ static bool dcp_v14_panel_nits_admit(const struct dcp_v14_board *board, { return board && board->panel_nits && (machine_is(ctx, "apple,j514s") || machine_is(ctx, "apple,j516s") || - machine_is(ctx, "apple,j516c") || machine_is(ctx, "apple,j613")); + machine_is(ctx, "apple,j516c") || machine_is(ctx, "apple,j613") || + machine_is(ctx, "apple,j504")); } const char *iomfb_v14_7_board_name(const struct dcp_v14_board *board) diff --git a/drivers/gpu/drm/apple/iomfb_v14_7_backlight_test.c b/drivers/gpu/drm/apple/iomfb_v14_7_backlight_test.c index 3c1fc2f45d534..6f1b6ad2bfe96 100644 --- a/drivers/gpu/drm/apple/iomfb_v14_7_backlight_test.c +++ b/drivers/gpu/drm/apple/iomfb_v14_7_backlight_test.c @@ -122,13 +122,14 @@ static bool v14_bl_ctx_machine_is(const void *ctx, const char *compat) return !strcmp(((const char *const *)ctx)[1], compat); } -/* Only admitted T6030, J516C and J613 internal panels carry levels. */ +/* Only admitted T6030, J516C, J613 and J504 internal panels carry levels. */ static void v14_bl_boards(struct kunit *test) { static const char *const t6030_j516s[] = { "apple,t6030-dcp", "apple,j516s" }; static const char *const t6030_j514s[] = { "apple,t6030-dcp", "apple,j514s" }; static const char *const j613[] = { "apple,t8122-dcp", "apple,j613" }; static const char *const j615[] = { "apple,t8122-dcp", "apple,j615" }; + static const char *const j504[] = { "apple,t8122-dcp", "apple,j504" }; static const char *const j516c[] = { "apple,t6031-dcp", "apple,j516c" }; static const char *const other_t6030[] = { "apple,t6030-dcp", "apple,other" }; const struct dcp_v14_board *board; @@ -156,6 +157,11 @@ static void v14_bl_boards(struct kunit *test) board = dcp_v14_board_select(v14_bl_ctx_dcp_is, v14_bl_ctx_machine_is, j615, &known); KUNIT_ASSERT_NOT_NULL(test, board); KUNIT_EXPECT_FALSE(test, board->panel_nits); + board = dcp_v14_board_select(v14_bl_ctx_dcp_is, v14_bl_ctx_machine_is, j504, &known); + KUNIT_ASSERT_NOT_NULL(test, board); + KUNIT_EXPECT_TRUE(test, board->panel_nits); + KUNIT_EXPECT_TRUE(test, dcp_v14_panel_nits_admit(board, v14_bl_ctx_machine_is, j504)); + KUNIT_EXPECT_FALSE(test, dcp_v14_panel_nits_admit(board, v14_bl_ctx_machine_is, j615)); board = dcp_v14_board_select(v14_bl_ctx_dcp_is, v14_bl_ctx_machine_is, j516c, &known); KUNIT_ASSERT_NOT_NULL(test, board); KUNIT_EXPECT_TRUE(test, board->panel_nits); diff --git a/drivers/gpu/drm/apple/v14-board-test.c b/drivers/gpu/drm/apple/v14-board-test.c index 2a41853d76dd2..d79c2b79a9cbc 100644 --- a/drivers/gpu/drm/apple/v14-board-test.c +++ b/drivers/gpu/drm/apple/v14-board-test.c @@ -251,7 +251,7 @@ static void v14_swap_timestamps_encoding(struct kunit *test) /* * J504 (14" M3 MacBook Pro): the J613 image on the T8122 DCP, its own 3024x1964 - * ProMotion panel, brightness closed and unstamped swaps. The other T8122 + * ProMotion panel, the qualified level block (brightness) and unstamped swaps. The other T8122 * Macs (J433, J434) have no record. */ static void v14_board_j504(struct kunit *test) @@ -272,7 +272,7 @@ static void v14_board_j504(struct kunit *test) KUNIT_EXPECT_EQ(test, b->panel_height, 1964); KUNIT_EXPECT_TRUE(test, b->promotion); KUNIT_EXPECT_TRUE(test, b->log_bringup); - KUNIT_EXPECT_FALSE(test, b->panel_nits); + KUNIT_EXPECT_TRUE(test, b->panel_nits); KUNIT_EXPECT_FALSE(test, b->base_edid); KUNIT_EXPECT_EQ(test, b->ctm_set, air->ctm_set); KUNIT_EXPECT_EQ(test, b->ctm_get, air->ctm_get); diff --git a/tools/asahi/dcp14-panel-tests.py b/tools/asahi/dcp14-panel-tests.py index b6c5979b11714..19c02cafd8201 100755 --- a/tools/asahi/dcp14-panel-tests.py +++ b/tools/asahi/dcp14-panel-tests.py @@ -92,7 +92,7 @@ assert(!IS_ERR(p14)&&p14&&!strcmp(p14->name,"J504")&&!strcmp(p14->debugfs,"dcp-j504")); assert(p14->panel_width==3024&&p14->panel_height==1964&&p14->promotion&&p14->log_bringup); assert(!strcmp(p14->firmware_uuid,"90F849E1-B422-367E-B389-50246F8DEC47")); - assert(!strcmp(p14->handoff,"apple,t8122-handoff")&&!p14->panel_nits&&!p14->swap_timestamps); + assert(!strcmp(p14->handoff,"apple,t8122-handoff")&&p14->panel_nits&&!p14->swap_timestamps); assert(p14->ctm_set==A(421)&&p14->ctm_get==A(420)); image_uuid=p14->firmware_uuid;assert(probe_gate(&dev,p14)==0); image_uuid="C042E95C-B9D8-3F0E-94B3-582A08AA6FDD";assert(probe_gate(&dev,p14)==-ENODEV); From 5518d441ec1041529296de17c175f86065be2e62 Mon Sep 17 00:00:00 2001 From: Scott Jones Date: Tue, 10 Nov 2026 19:39:45 -0500 Subject: [PATCH 15/47] drm/asahi: m3: map the adopted handoff regions as the 7.2 runtime did On 7.3 the M3 MacBook Air runtime adopts the firmware's UAT through Uat::new_adopted_with_user_upper(), which always asks for a write-combined mapping of the handoff and TTBAT regions. On these Macs the boot loader leaves both regions in the kernel's memory map as reserved RAM, and memremap() refuses a write-combined mapping of RAM: memremap attempted on ram 0x00000103fff70000 size: 0x4000 aurora 292400000.gpu: probe with driver aurora failed with error -12 On 7.2 the same helper chose the mapping per region: write-back for reserved RAM, write-combined for a carveout. Uat::new_adopted() still does that on 7.3. Add Uat::new_adopted_ram_with_user_upper(), which makes the same per-region choice and keeps the caller's choice of user upper half, and use it for the M3 runtime. The M4 caller keeps the write-combined constructor; no other backend calls either. Seen on a J613 with a 7.3 kernel on the m1n1 1.6.1.aurora23 handoff. Co-Authored-By: Claude Fable 5.2 Signed-off-by: Scott Jones --- drivers/gpu/drm/asahi/m3/m3_runtime.rs | 2 +- drivers/gpu/drm/asahi/mmu.rs | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/asahi/m3/m3_runtime.rs b/drivers/gpu/drm/asahi/m3/m3_runtime.rs index 762c8bc26e75b..e521089c9ec46 100644 --- a/drivers/gpu/drm/asahi/m3/m3_runtime.rs +++ b/drivers/gpu/drm/asahi/m3/m3_runtime.rs @@ -1411,7 +1411,7 @@ fn adopt_uat(drm: &driver::AsahiDrmDevice, soc: &'static crate::m3::m3_soc::Soc, let range = |r: crate::m3::agx_resources::Region| r.base..r.base + r.size; let geometry = mmu::UatGeometry { ias: cfg.uat_ias.into(), oas: cfg.uat_oas }; let regions = mmu::AdoptedRegions { handoff: range(handoff), ttbs: range(ttbs), kernel_root: tables.base }; - let uat = mmu::Uat::new_adopted_with_user_upper(drm, geometry, ®ions, + let uat = mmu::Uat::new_adopted_ram_with_user_upper(drm, geometry, ®ions, profile == super::m3_profile::Profile::Legacy)?; let mut window = crate::g15::uat::Window::from_regions(handoff.base, ttbs.base, tables.base, shared_l2.base)?; window.bootstrap(drm.as_ref().as_ref(), &uat)?; diff --git a/drivers/gpu/drm/asahi/mmu.rs b/drivers/gpu/drm/asahi/mmu.rs index 4337024993025..dcb46d6080ad4 100644 --- a/drivers/gpu/drm/asahi/mmu.rs +++ b/drivers/gpu/drm/asahi/mmu.rs @@ -3571,7 +3571,7 @@ impl Uat { /// Creates the same owned-RAM adopted UAT, choosing whether application contexts also /// name the firmware upper root. M4 qualifies only context 0 for firmware-upper access; /// its application TTBAT upper words stay zero. G15 preserves its existing shared upper. - #[cfg(any(CONFIG_DRM_ASAHI_G16, CONFIG_DRM_ASAHI_M3_T8122))] + #[cfg(CONFIG_DRM_ASAHI_G16)] pub(crate) fn new_adopted_with_user_upper( dev: &driver::AsahiDrmDevice, geometry: UatGeometry, @@ -3581,6 +3581,20 @@ impl Uat { Self::new_adopted_inner(dev, geometry, regions, map_kernel_to_user, false) } + /// As [`Self::new_adopted_with_user_upper`], for regions that may be reserved System RAM: + /// each is mapped write-back when it is RAM and write-combined when it is a carveout, as + /// [`Self::new_adopted`] does. The M3 boot loaders leave the handoff and TTBAT regions in + /// the kernel's memory map as reserved RAM, which a write-combined mapping is refused for. + #[cfg(CONFIG_DRM_ASAHI_M3_T8122)] + pub(crate) fn new_adopted_ram_with_user_upper( + dev: &driver::AsahiDrmDevice, + geometry: UatGeometry, + regions: &AdoptedRegions, + map_kernel_to_user: bool, + ) -> Result { + Self::new_adopted_inner(dev, geometry, regions, map_kernel_to_user, true) + } + #[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] fn new_adopted_inner( dev: &driver::AsahiDrmDevice, From 48b5fd6db9877f1b5e44ccc3c16e80b76696e92e Mon Sep 17 00:00:00 2001 From: Scott Jones Date: Sat, 24 Oct 2026 02:23:50 -0400 Subject: [PATCH 16/47] drm/asahi: build the T8122 runtime without the G15 backend DRM_ASAHI_M3_T8122 depended on DRM_ASAHI_G15 only because the T8122 runtime adopts the firmware's UAT with the G15 backend's handoff helpers (g15::uat::Window and g15::memory_mode). Turning the M3 Air on therefore also turned the G15 backend on for M3 Pro/Max. Split the adoption out behind a hidden DRM_ASAHI_UAT_ADOPTION, selected by both options: - without G15, g15/adopt.rs builds only g15/{uat,regs,hw}.rs (no probe, no driver registration); what in them needs G15's Config or ADT (adopt(), Window::new, Regs::identity and the T6030/T6031 tables) stays under G15; - the RAM helpers memory_mode needs move from g15/glue.c to g15/uat_glue.c, so the runtime doesn't take glue.c's display helpers; - M3_T8122 now states its own dependency on APPLE_PMP, whose PMP votes the runtime calls directly (before, it was implied by nothing); - the mmu and pgtable items the runtime uses (the adopted Uat, with_tracked_status, read_user and point-of-coherency cleaning) are built with UAT_ADOPTION instead of G15. G15 selects UAT_ADOPTION, so every configuration that builds today is unchanged: off, G15 only and G15 with T8122 give the same warnings as before, and M3_T8122 alone now builds without warnings. The asahi-g15 selftest reads the helpers from their new file, and the g15-zero-words test pins the new hw.rs (its separate T6030 table pin is unchanged). Co-Authored-By: Claude Opus 5.5 (1M context) Signed-off-by: Scott Jones (ported from commit 9dff537d173 on omacom/linux-aurora) [7.3 base: G15 keeps this base's "default y" and selects the new option. The base builds what the runtime shares with G15 under "G15 or G16" and keeps the point-of-coherency cleaning unconditional, so the mmu and pgtable gates become "UAT_ADOPTION or G16" and gain no new #[cfg] on clean_poc. The module is aurora.ko here. g15-zero-words-tests pins hw.rs after the test's own normalisation. Built with G15 and T8122 (same warnings as before) and with T8122 alone: that builds, and none of its dead-code warnings is in g15/, m3/, mmu.rs or pgtable.rs. Not run on hardware.] Co-Authored-By: Claude Fable 5.2 --- drivers/gpu/drm/asahi/Kconfig | 14 ++++- drivers/gpu/drm/asahi/Makefile | 1 + drivers/gpu/drm/asahi/asahi_core.rs | 4 ++ drivers/gpu/drm/asahi/g15/adopt.rs | 32 ++++++++++ drivers/gpu/drm/asahi/g15/glue.c | 46 --------------- drivers/gpu/drm/asahi/g15/hw.rs | 2 + drivers/gpu/drm/asahi/g15/regs.rs | 3 +- drivers/gpu/drm/asahi/g15/uat.rs | 6 +- drivers/gpu/drm/asahi/g15/uat_glue.c | 59 +++++++++++++++++++ drivers/gpu/drm/asahi/mmu.rs | 28 ++++----- drivers/gpu/drm/asahi/pgtable.rs | 2 +- tools/asahi/g15-zero-words-tests.py | 6 +- .../selftests/drivers/gpu/asahi-g15/run.py | 8 ++- 13 files changed, 141 insertions(+), 70 deletions(-) create mode 100644 drivers/gpu/drm/asahi/g15/adopt.rs create mode 100644 drivers/gpu/drm/asahi/g15/uat_glue.c diff --git a/drivers/gpu/drm/asahi/Kconfig b/drivers/gpu/drm/asahi/Kconfig index 03939a732fc24..0df72bf32ae5b 100644 --- a/drivers/gpu/drm/asahi/Kconfig +++ b/drivers/gpu/drm/asahi/Kconfig @@ -79,11 +79,20 @@ config DRM_ASAHI_DEBUG_ALLOCATOR Say N unless you are debugging firmware structures or porting to a new firmware version. +config DRM_ASAHI_UAT_ADOPTION + bool + help + The firmware UAT handoff adoption shared by the G15 backend and the + T8122 runtime (g15/uat.rs, g15/regs.rs). + config DRM_ASAHI_M3_T8122 bool "M3 MacBook Air GPU runtime (T8122, 14.8.3 firmware)" depends on DRM_ASAHI - # The runtime adopts the firmware's UAT through the G15 backend's handoff helpers. - depends on DRM_ASAHI_G15 + # The runtime adopts the firmware's UAT as the G15 backend does, without + # needing that backend: M3 Pro/Max keep their own setting. + # Its PMP votes call apple-pmp directly (m3_device.rs). + depends on APPLE_PMP=y || (APPLE_PMP=m && DRM_ASAHI=m) + select DRM_ASAHI_UAT_ADOPTION select APPLE_T8122_GPU_PMP_LINK select CRYPTO_LIB_SHA256 default n @@ -102,6 +111,7 @@ config DRM_ASAHI_G15 depends on DRM_APPLE=y || (DRM_APPLE=m && DRM_ASAHI=m) select APPLE_T6030_GPU_PMP_LINK select CRYPTO_LIB_SHA256 + select DRM_ASAHI_UAT_ADOPTION default y help Backend for the M3 Pro (T6030) and M3 Max (T6031) GPUs on the diff --git a/drivers/gpu/drm/asahi/Makefile b/drivers/gpu/drm/asahi/Makefile index 890d47c40af6b..b39d2552dd900 100644 --- a/drivers/gpu/drm/asahi/Makefile +++ b/drivers/gpu/drm/asahi/Makefile @@ -5,6 +5,7 @@ aurora-y := asahi_core.o fwid.o legacy_sched.o sysfs.o g17/sync_input.o g17/sync CFLAGS_g17/trace.o := -I$(src)/g17 aurora-$(CONFIG_DRM_ASAHI_G15) += g15/glue.o +aurora-$(CONFIG_DRM_ASAHI_UAT_ADOPTION) += g15/uat_glue.o aurora-$(CONFIG_DRM_ASAHI_G16) += g16/glue.o diff --git a/drivers/gpu/drm/asahi/asahi_core.rs b/drivers/gpu/drm/asahi/asahi_core.rs index b970691651032..bd69152c3ce75 100644 --- a/drivers/gpu/drm/asahi/asahi_core.rs +++ b/drivers/gpu/drm/asahi/asahi_core.rs @@ -17,6 +17,10 @@ mod fw; mod fwid; #[cfg(CONFIG_DRM_ASAHI_G15)] mod g15; +// Without the G15 backend, only the UAT adoption the T8122 runtime shares with it. +#[cfg(all(CONFIG_DRM_ASAHI_UAT_ADOPTION, not(CONFIG_DRM_ASAHI_G15)))] +#[path = "g15/adopt.rs"] +mod g15; mod g17; mod gem; diff --git a/drivers/gpu/drm/asahi/g15/adopt.rs b/drivers/gpu/drm/asahi/g15/adopt.rs new file mode 100644 index 0000000000000..5dd54b04aaec6 --- /dev/null +++ b/drivers/gpu/drm/asahi/g15/adopt.rs @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT + +//! Without the G15 backend (`CONFIG_DRM_ASAHI_G15=n`), the parts of it the T8122 runtime uses to +//! adopt the firmware's UAT: the handoff window ([`uat`]), its mappings ([`regs`]) and the +//! hardware constants they name ([`hw`]). Nothing here probes a device. + +// Only the adoption is used; the rest of these files serves the G15 backend. +#![allow(dead_code)] + +// hw.rs's `t6031` submodule is cfg-gated on G15; were it built here, a #[path]-loaded file +// would look for it at g15/t6031.rs, not g15/hw/t6031.rs. +#[path = "hw.rs"] +pub(crate) mod hw; +#[path = "regs.rs"] +pub(crate) mod regs; +#[path = "uat.rs"] +pub(crate) mod uat; + +use kernel::prelude::*; + +extern "C" { + fn asahi_g15_memory_mode(start: u64, size: u64) -> u32; +} + +/// WB for complete reserved RAM, WC for aligned non-RAM carveouts; reject everything else. +pub(crate) fn memory_mode(start: u64, size: u64) -> Result { + // SAFETY: Only queries resources and page metadata; it does not create a mapping. + match unsafe { asahi_g15_memory_mode(start, size) } { + 0 => Err(EINVAL), + mode => Ok(mode), + } +} diff --git a/drivers/gpu/drm/asahi/g15/glue.c b/drivers/gpu/drm/asahi/g15/glue.c index 2a0346228c1e5..a12a5e6fa2fe7 100644 --- a/drivers/gpu/drm/asahi/g15/glue.c +++ b/drivers/gpu/drm/asahi/g15/glue.c @@ -29,9 +29,6 @@ void asahi_g15_release_power(struct device *dev); void asahi_g15_reprobe(void); void asahi_g15_report_loader_gpu(void); int asahi_g15_adt_phram(u64 *start, u64 *size); -bool asahi_g15_ram_disjoint(u64 start, u64 size); -bool asahi_g15_ram_within(u64 start, u64 size); -unsigned int asahi_g15_memory_mode(u64 start, u64 size); void __iomem *asahi_g15_ioremap_wc(u64 start, size_t size); bool asahi_g15_dma_coherent(struct device *dev); int asahi_g15_pmp_prepare(struct device *dev); @@ -275,13 +272,6 @@ int asahi_g15_adt_phram(u64 *start, u64 *size) return 0; } -/* The range is disjoint from System RAM (ADT region admission). */ -bool asahi_g15_ram_disjoint(u64 start, u64 size) -{ - return region_intersects(start, size, IORESOURCE_SYSTEM_RAM, IORES_DESC_NONE) == - REGION_DISJOINT; -} - /* * Whether DMA mappings of the device skip cache maintenance. The G15 firmware * objects rely on the DMA mapping cleaning their pages to the point of @@ -292,42 +282,6 @@ bool asahi_g15_dma_coherent(struct device *dev) return dev_is_dma_coherent(dev); } -/* - * Every page must be valid, System RAM and still reserved from the allocator. - * REGION_INTERSECTS alone also accepts RAM mixed with undefined memory holes. - */ -bool asahi_g15_ram_within(u64 start, u64 size) -{ - u64 end, pa; - - if (!size || !IS_ALIGNED(start, PAGE_SIZE) || - !IS_ALIGNED(size, PAGE_SIZE) || check_add_overflow(start, size, &end)) - return false; - for (pa = start; pa < end; pa += PAGE_SIZE) { - unsigned long pfn = PHYS_PFN(pa); - - if (!pfn_valid(pfn) || !page_is_ram(pfn) || - !PageReserved(pfn_to_page(pfn))) - return false; - } - return true; -} - -/* One classification for every adopted-UAT and firmware-region CPU mapping. */ -unsigned int asahi_g15_memory_mode(u64 start, u64 size) -{ - u64 end; - - if (!size || !IS_ALIGNED(start, PAGE_SIZE) || - !IS_ALIGNED(size, PAGE_SIZE) || check_add_overflow(start, size, &end)) - return 0; - if (asahi_g15_ram_within(start, size)) - return MEMREMAP_WB; - if (asahi_g15_ram_disjoint(start, size)) - return MEMREMAP_WC; - return 0; -} - /* The inherited RTKit buffer inside firmware DATA. */ void __iomem *asahi_g15_ioremap_wc(u64 start, size_t size) { diff --git a/drivers/gpu/drm/asahi/g15/hw.rs b/drivers/gpu/drm/asahi/g15/hw.rs index be319b0cd2702..cac11c55d3ca0 100644 --- a/drivers/gpu/drm/asahi/g15/hw.rs +++ b/drivers/gpu/drm/asahi/g15/hw.rs @@ -7,6 +7,7 @@ use core::ops::Range; +#[cfg(CONFIG_DRM_ASAHI_G15)] pub(crate) mod t6031; /// Identification register values of a qualified G15S. @@ -91,6 +92,7 @@ pub(crate) struct ComputeRegs { } /// The T6030 configuration. +#[cfg(CONFIG_DRM_ASAHI_G15)] pub(crate) mod t6030 { use super::super::Config; use super::{ComputeRegs, FirmwareBuild, HwId, Layout}; diff --git a/drivers/gpu/drm/asahi/g15/regs.rs b/drivers/gpu/drm/asahi/g15/regs.rs index 05a1b390b3dff..98e7d4c8cf78a 100644 --- a/drivers/gpu/drm/asahi/g15/regs.rs +++ b/drivers/gpu/drm/asahi/g15/regs.rs @@ -125,7 +125,7 @@ impl Mapping { if size == 0 { return Err(EINVAL); } - let mode = super::boot::glue::memory_mode(phys, size as u64)?; + let mode = super::memory_mode(phys, size as u64)?; if mode == bindings::MEMREMAP_WC as u32 { return Self::write_combined(phys, size); } @@ -252,6 +252,7 @@ impl Regs { /// Reads the identification words and the enabled-core mask (once the GPU is powered). A /// SoC with more than 32 core slots carries the mask in two words. + #[cfg(CONFIG_DRM_ASAHI_G15)] pub(crate) fn identity(&self, cfg: &super::Config) -> Result { let version = self.sgx.io().try_read32(SGX_ID)?; let counts = self.sgx.io().try_read32(SGX_ID + 0x10)?; diff --git a/drivers/gpu/drm/asahi/g15/uat.rs b/drivers/gpu/drm/asahi/g15/uat.rs index 0f91f7c9f0610..0f0aa01e23517 100644 --- a/drivers/gpu/drm/asahi/g15/uat.rs +++ b/drivers/gpu/drm/asahi/g15/uat.rs @@ -38,12 +38,14 @@ use kernel::{ bindings, device, io::Io, prelude::*, - sync::Arc, time::{delay::fsleep, Delta, Instant, Monotonic}, }; +#[cfg(CONFIG_DRM_ASAHI_G15)] +use kernel::sync::Arc; use super::hw; use super::regs::{mb, rmb, wmb, Mapping}; +#[cfg(CONFIG_DRM_ASAHI_G15)] use crate::driver::AsahiDrmDevice as AsahiDevice; use crate::{mmu, pgtable}; @@ -69,6 +71,7 @@ const fn indices(va: u64) -> [usize; 3] { } /// Creates the adopted UAT over the ADT regions (step 2 above). +#[cfg(CONFIG_DRM_ASAHI_G15)] pub(crate) fn adopt( dev: &AsahiDevice, cfg: &'static super::Config, @@ -201,6 +204,7 @@ pub(crate) struct Window { impl Window { /// Maps the UAT handoff regions ([`Mapping::region`]). + #[cfg(CONFIG_DRM_ASAHI_G15)] pub(crate) fn new(adt: &super::adt::GpuAdt) -> Result { Self::from_regions(adt.handoff.start, adt.ttbs.start, adt.tables.start, adt.shared_l2.start) } diff --git a/drivers/gpu/drm/asahi/g15/uat_glue.c b/drivers/gpu/drm/asahi/g15/uat_glue.c new file mode 100644 index 0000000000000..134ff4bb28ab6 --- /dev/null +++ b/drivers/gpu/drm/asahi/g15/uat_glue.c @@ -0,0 +1,59 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * C helpers of the UAT adoption (g15/uat.rs, g15/regs.rs), built for the G15 + * backend and for the T8122 runtime, which adopts the firmware's UAT the same + * way (CONFIG_DRM_ASAHI_UAT_ADOPTION). + */ +#include +#include +#include +#include +#include +#include + +bool asahi_g15_ram_disjoint(u64 start, u64 size); +bool asahi_g15_ram_within(u64 start, u64 size); +unsigned int asahi_g15_memory_mode(u64 start, u64 size); + +/* The range is disjoint from System RAM (ADT region admission). */ +bool asahi_g15_ram_disjoint(u64 start, u64 size) +{ + return region_intersects(start, size, IORESOURCE_SYSTEM_RAM, IORES_DESC_NONE) == + REGION_DISJOINT; +} + +/* + * Every page must be valid, System RAM and still reserved from the allocator. + * REGION_INTERSECTS alone also accepts RAM mixed with undefined memory holes. + */ +bool asahi_g15_ram_within(u64 start, u64 size) +{ + u64 end, pa; + + if (!size || !IS_ALIGNED(start, PAGE_SIZE) || + !IS_ALIGNED(size, PAGE_SIZE) || check_add_overflow(start, size, &end)) + return false; + for (pa = start; pa < end; pa += PAGE_SIZE) { + unsigned long pfn = PHYS_PFN(pa); + + if (!pfn_valid(pfn) || !page_is_ram(pfn) || + !PageReserved(pfn_to_page(pfn))) + return false; + } + return true; +} + +/* One classification for every adopted-UAT and firmware-region CPU mapping. */ +unsigned int asahi_g15_memory_mode(u64 start, u64 size) +{ + u64 end; + + if (!size || !IS_ALIGNED(start, PAGE_SIZE) || + !IS_ALIGNED(size, PAGE_SIZE) || check_add_overflow(start, size, &end)) + return 0; + if (asahi_g15_ram_within(start, size)) + return MEMREMAP_WB; + if (asahi_g15_ram_disjoint(start, size)) + return MEMREMAP_WC; + return 0; +} diff --git a/drivers/gpu/drm/asahi/mmu.rs b/drivers/gpu/drm/asahi/mmu.rs index dcb46d6080ad4..34c697be9bdb7 100644 --- a/drivers/gpu/drm/asahi/mmu.rs +++ b/drivers/gpu/drm/asahi/mmu.rs @@ -505,10 +505,10 @@ fn lock_vm( Ok(VmExecGuard(unsafe { gpuvm.exec_lock(obj, interruptible)? })) } -#[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] +#[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] pub(crate) struct VmReadGuard(VmExecGuard); -#[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] +#[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] impl VmReadGuard { #[cfg(CONFIG_DRM_ASAHI_G15)] pub(crate) fn covers_range(&mut self, address: u64, size: u64, read: bool, write: bool) -> bool { @@ -2596,7 +2596,7 @@ impl Vm { /// Attach a status and job lifetime tracking before sharing a newly created user VM with /// queues, without the G17 canonical context views, shared-object footprints and idle /// residency reclaim of [`Self::with_status`]. Used by G15, whose user objects stay pinned. - #[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] + #[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] pub(crate) fn with_tracked_status(mut self) -> Result { self.status = Some(Arc::pin_init( crate::g17::status::VmStatus::new(), @@ -2624,17 +2624,17 @@ impl Vm { /// and invalidated to the point of coherency first (never only invalidated: CPU-written lines /// may be dirty), so the copy sees what the GPU or a write-combined CPU view stored. The /// mappings cannot change during the copy (GPUVM exec lock). - #[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] + #[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] pub(crate) fn read_user(&self, va: u64, buf: &mut [u8]) -> Result { self.read_lock()?.read_user(va, buf) } - #[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] + #[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] pub(crate) fn read_lock(&self) -> Result { Ok(VmReadGuard(lock_vm(&self.gpuvm, None, false)?)) } - #[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] + #[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] fn read_user_locked(inner: &mut VmInner, va: u64, buf: &mut [u8]) -> Result { let mut done = 0usize; while done < buf.len() { @@ -3477,7 +3477,7 @@ impl Drop for VmInner { /// Physical regions of a UAT whose handoff the generation has already established itself /// ([`Uat::new_adopted`]). None of them needs to be in the kernel linear map. -#[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] +#[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] pub(crate) struct AdoptedRegions { /// The handoff region (PPL magic, lock and flush requests). pub(crate) handoff: Range, @@ -3500,7 +3500,7 @@ impl Uat { }) } - #[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] + #[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] /// Map a region given by its physical range, write-combined. fn map_physical( range: &Range, @@ -3521,7 +3521,7 @@ impl Uat { let res: io::resource::Resource = unsafe { core::mem::transmute(kernel::types::Opaque::new(raw)) }; let flags = io::mem::MemFlag::WC; - #[cfg(CONFIG_DRM_ASAHI_G15)] + #[cfg(CONFIG_DRM_ASAHI_UAT_ADOPTION)] let flags = if reserved_ram { // G15 admits only whole reserved RAM pages or wholly non-RAM carveouts. if crate::g15::memory_mode(range.start, size as u64)? @@ -3534,7 +3534,7 @@ impl Uat { } else { flags }; - #[cfg(not(CONFIG_DRM_ASAHI_G15))] + #[cfg(not(CONFIG_DRM_ASAHI_UAT_ADOPTION))] let _ = reserved_ram; // SAFETY: The UAT regions are only accessed through this mapping by the CPU; // the GPU reaches them through its own translation. @@ -3545,7 +3545,7 @@ impl Uat { }) } - #[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] + #[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] /// Creates a `Uat` for a handoff that the caller establishes itself (G15). /// /// This only maps the handoff and the TTBAT (write-combined); neither is written here. The @@ -3595,7 +3595,7 @@ impl Uat { Self::new_adopted_inner(dev, geometry, regions, map_kernel_to_user, true) } - #[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] + #[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] fn new_adopted_inner( dev: &driver::AsahiDrmDevice, geometry: UatGeometry, @@ -3686,13 +3686,13 @@ impl Uat { }) } - #[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] + #[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] /// Root of the kernel lower `Vm`, for TTBAT context 0 of an adopted handoff. pub(crate) fn kernel_lower_root(&self) -> PhysicalAddr { self.kernel_lower_vm.ttb() } - #[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] + #[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] /// Root whose driver-window entry names the second-level table of [`Self::kernel_vm`]'s /// driver window. With [`Self::new_adopted`] this is the shadow root that no context names. pub(crate) fn kernel_window_root(&self) -> PhysicalAddr { diff --git a/drivers/gpu/drm/asahi/pgtable.rs b/drivers/gpu/drm/asahi/pgtable.rs index 9fb2d0652e01e..0cc2fac3b340a 100644 --- a/drivers/gpu/drm/asahi/pgtable.rs +++ b/drivers/gpu/drm/asahi/pgtable.rs @@ -369,7 +369,7 @@ impl Prot { /// The protection bits of a leaf with this protection (no address, table type or non-global /// bits), for checking that a firmware leaf word round-trips through [`Self::from_pte`]. - #[cfg(any(CONFIG_DRM_ASAHI_G15, CONFIG_DRM_ASAHI_G16))] + #[cfg(any(CONFIG_DRM_ASAHI_UAT_ADOPTION, CONFIG_DRM_ASAHI_G16))] pub(crate) const fn leaf_bits(&self) -> u64 { self.as_pte() } diff --git a/tools/asahi/g15-zero-words-tests.py b/tools/asahi/g15-zero-words-tests.py index 3a31cba6958bf..f4d18bc9685ac 100644 --- a/tools/asahi/g15-zero-words-tests.py +++ b/tools/asahi/g15-zero-words-tests.py @@ -15,7 +15,9 @@ (one #[cfg] line; the tables are unchanged), and when the initial PB posting and the idle reclaim became fixed tuning constants instead of module parameters (four constants; the tables are unchanged), and when the two stamp -renumbering margins became tuning constants (the tables are unchanged). Its T6030 +renumbering margins became tuning constants (the tables are unchanged), and when +the T6030/T6031 tables were gated on CONFIG_DRM_ASAHI_G15 for the T8122 runtime's +UAT adoption (two #[cfg] lines; the tables are unchanged). Its T6030 configuration module is independently pinned to the original bytes, except for the J514S B0 FirmwareBuild row, the J514S cd05 and J516S cd05 @@ -40,7 +42,7 @@ GOLDEN_FILES = { "board/data.rs": "7c5ff1077ca3296cbfc9e7144294162b6dea78a3774c38eeed4b0f59a14d7a5c", "board/template.rs": "286872f5474a67534f214e83e659253299f85143f3dc59035fa80894022e2549", - "hw.rs": "f45a0f11f952fea4e36809267ffd240ee1e381e8f3400de5e8527cd316b9f225", + "hw.rs": "9fa2d6e5f5d14127574448cafd6523d2151dab77c66d16e74500fafde21e8d92", "power/idle.rs": "4928ecf7699b3ca85ff5143eb6e996efd40d47321e29a238a02c8873bc9f102c", } GOLDEN_FUNCTIONS = { diff --git a/tools/testing/selftests/drivers/gpu/asahi-g15/run.py b/tools/testing/selftests/drivers/gpu/asahi-g15/run.py index b0c3105235f7b..80b7174635b5d 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-g15/run.py +++ b/tools/testing/selftests/drivers/gpu/asahi-g15/run.py @@ -260,13 +260,15 @@ def main(): with tempfile.TemporaryDirectory(prefix="asahi-g15-host-") as temp: temp = Path(temp) glue = (G15 / "glue.c").read_text() + # The UAT adoption's helpers, shared with the T8122 runtime. + uat_glue = (G15 / "uat_glue.c").read_text() functions = [] for signature in ["bool asahi_g15_ram_disjoint", "bool asahi_g15_ram_within", "unsigned int asahi_g15_memory_mode"]: marker = signature + "(u64 start, u64 size)\n{" - start = glue.index(marker) - end = glue.index("\n}", start) + 2 - functions.append(glue[start:end]) + start = uat_glue.index(marker) + end = uat_glue.index("\n}", start) + 2 + functions.append(uat_glue[start:end]) c_source = temp / "memory.c" c_source.write_text(MEMORY_PREFIX + "\n".join(functions) + MEMORY_CASES) subprocess.run([os.environ.get("HOSTCC", "cc"), "-std=gnu11", "-Wall", "-Wextra", From 00b36b51d04cf29af0b53323f31a5c277934c7ae Mon Sep 17 00:00:00 2001 From: Naeem Malik Date: Thu, 22 Oct 2026 23:39:05 +0530 Subject: [PATCH 17/47] drm/apple: give the J516C panel an EDID The DCP gives no EDID for a built-in panel, so on the 14.7 panel role eDP-1 has an empty edid property and compositors see no make, model or physical size. Add a builder for a two-block EDID from the panel's device-tree node and a table of the known panel models: - the base block (EDID 1.4) names the panel by the PNP ID of the vendor prefix and the model of its most specific compatible ("apple,panel-j516" gives APP and the monitor name J516), gives its size, the model year (2023 for the J516), a nominal gamma of 2.2 and P3 primaries with a D65 white point (the panel is a P3 wide-colour panel, and the sRGB transfer function of Display P3 approximates a 2.2 gamma); - its first descriptor is a detailed timing, as EDID 1.4 requires, with the panel's geometry at 60 Hz: the same totals and horizontal porches as the panel's mode, the vertical front porch at 63 lines. The panel's own timing, 3456x2234 at 120 Hz, does not fit: the detailed timing's pixel clock field is 16 bits in 10 kHz units (at most 655.35 MHz) and the panel needs 3536 x 2456 x 120 = 1,042,129,920 Hz; its 6-bit vertical front porch cannot hold the panel's 118 lines either; - a DisplayID 2.0 extension carries the real 120 Hz timing as its preferred Type VII timing (1042130 kHz, the DCP mode line with the notch rows shown: 3456 3464 3496 3536 / 2234 2352 2360 2456), with the display parameters (size, native pixels, colour, gamma). Neither block is a mode source: DRM modes still come from the DCP firmware, and the update adds no mode. There is no product code, serial number, luminance or range descriptor. edid-decode and libdisplay-info both report the EDID conformant. dcp_panel_edid_update() publishes the EDID on a connector. Add a base_edid flag to the 14.x board records, set only in the J516C record. On that board, read the make and product from the panel node's first compatible at bind, and when a probe has modes and no other EDID, publish the panel's EDID sized as the connector is (dcp_update_connector_dimensions(): the firmware's size, else the node's), then give the connector back its size in millimetres, which the EDID update replaces with whole centimetres, and clear the firmware-derived EDID flag. Displays with a firmware EDID, the J514C (whose record carries J514S panel values) and the T6030 panels (J514S, J516S) leave the flag clear and are unchanged. On the J516C the connector keeps its one firmware mode, 3456x2160 at 120 Hz. KUnit (apple-dcp-panel-edid): the EDID is valid to drm_edid_valid(), drm_edid_get_product_id() and drm_edid_get_monitor_name() give APP, no product code or serial and J516; the base block holds 35x22 cm, gamma 2.2, model year 2023, the P3/D65 chromaticity, the 60 Hz detailed timing field by field and one extension; the DisplayID block holds its header, display parameters and every Type VII field of the 120 Hz timing, and both checksums; an update publishes 256 bytes and adds no mode. The fixture's connector uses the atomic state helpers. apple-dcp-v14-board checks that only the J516C record sets the flag (J514C, T6030 and J613 do not). Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Naeem Malik Signed-off-by: Scott Jones --- drivers/gpu/drm/apple/Makefile | 3 +- drivers/gpu/drm/apple/dcp-internal.h | 3 + drivers/gpu/drm/apple/dcp-panel-edid-test.c | 276 ++++++++++++++ drivers/gpu/drm/apple/dcp-panel-edid.c | 354 ++++++++++++++++++ drivers/gpu/drm/apple/dcp-panel-edid.h | 37 ++ drivers/gpu/drm/apple/dcp.c | 8 + drivers/gpu/drm/apple/iomfb.c | 16 + drivers/gpu/drm/apple/iomfb_v14_7.c | 6 + drivers/gpu/drm/apple/iomfb_v14_7.h | 2 + drivers/gpu/drm/apple/iomfb_v14_7_board.h | 5 + drivers/gpu/drm/apple/v14-board-test.c | 5 + .../selftests/drivers/gpu/apple-dcp/rate.py | 15 +- 12 files changed, 723 insertions(+), 7 deletions(-) create mode 100644 drivers/gpu/drm/apple/dcp-panel-edid-test.c create mode 100644 drivers/gpu/drm/apple/dcp-panel-edid.c create mode 100644 drivers/gpu/drm/apple/dcp-panel-edid.h diff --git a/drivers/gpu/drm/apple/Makefile b/drivers/gpu/drm/apple/Makefile index 8b2d7288b5639..d9300006b163d 100644 --- a/drivers/gpu/drm/apple/Makefile +++ b/drivers/gpu/drm/apple/Makefile @@ -7,7 +7,7 @@ appledrm-y += afk.o dcp.o dcp-fabric.o dcp_backlight.o dptxep.o iomfb.o parser.o appledrm-y += dcp-hdmi.o appledrm-$(CONFIG_DRM_APPLE_AUDIO) += audio.o appledrm-$(CONFIG_DRM_APPLE_AUDIO) += av.o -appledrm-y += connector.o dcp-panel-adt.o dcp-display-metadata.o dcp-180hz.o +appledrm-y += connector.o dcp-panel-adt.o dcp-display-metadata.o dcp-180hz.o dcp-panel-edid.o appledrm-y += ibootep.o appledrm-y += dcpext_scanout.o appledrm-y += dcpext_drm.o @@ -29,6 +29,7 @@ appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += dcp_external_ready_test.o appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += dcp_external_announce_test.o appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += dcp_external_relink_test.o appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += dcp_dropped_swap_test.o +appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += dcp-panel-edid-test.o appledrm-y += iomfb_v26_6.o iomfb_v26_6_link.o j613_dcp_activate.o appledrm-y += iomfb_v27.o appledrm-y += epic/dpavservep.o diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 97b0db066bb93..5b4838c1dca87 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -29,6 +29,7 @@ #include "dcp-announce.h" #include "dcp-display-metadata.h" #include "dcp-metadata-epoch.h" +#include "dcp-panel-edid.h" #include "dcp-180hz.h" #include "iomfb.h" #include "iomfb_h17p.h" @@ -224,6 +225,8 @@ struct dcp_panel { u32 edr_ceiling; /// calibrated colour target from the raw ADT; NULL if not given const struct dcp_color_space *color_target; + /// make and product for the base EDID, from the panel's compatible + struct dcp_panel_id id; }; /* diff --git a/drivers/gpu/drm/apple/dcp-panel-edid-test.c b/drivers/gpu/drm/apple/dcp-panel-edid-test.c new file mode 100644 index 0000000000000..399f6e5bfd647 --- /dev/null +++ b/drivers/gpu/drm/apple/dcp-panel-edid-test.c @@ -0,0 +1,276 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT + +/* + * The built-in panel's EDID, read back with the DRM EDID helpers: the make, + * product, model year and native timing come from the panel's compatible and + * the model table; the base block holds the panel's geometry at 60 Hz with P3 + * colour and gamma 2.2, the DisplayID extension the 120 Hz timing; an update + * publishes both blocks on the connector and adds no mode. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "dcp-panel-edid.h" + +#define J516_W_MM 346 +#define J516_H_MM 216 + +static void panel_id_j516(struct kunit *test, struct dcp_panel_id *id) +{ + KUNIT_ASSERT_EQ(test, dcp_panel_id_from_compatible(id, "apple,panel-j516"), 0); +} + +static void panel_id_from_compatible(struct kunit *test) +{ + struct dcp_panel_id id; + + panel_id_j516(test, &id); + KUNIT_EXPECT_STREQ(test, id.vendor, "APP"); + KUNIT_EXPECT_STREQ(test, id.name, "J516"); + KUNIT_EXPECT_EQ(test, id.model_year, 2023); + KUNIT_EXPECT_EQ(test, id.timing.clock_khz, 1042130); + KUNIT_EXPECT_EQ(test, id.timing.vtotal, 2456); + /* A model without a known year and timing gets none, and no EDID. */ + KUNIT_ASSERT_EQ(test, dcp_panel_id_from_compatible(&id, "apple,panel-j999"), 0); + KUNIT_EXPECT_EQ(test, id.model_year, 0); + KUNIT_EXPECT_EQ(test, id.timing.clock_khz, 0); +} + +static void panel_id_needs_a_model_and_a_known_vendor(struct kunit *test) +{ + struct dcp_panel_id id; + + KUNIT_EXPECT_EQ(test, dcp_panel_id_from_compatible(&id, "apple,panel"), -EINVAL); + KUNIT_EXPECT_EQ(test, dcp_panel_id_from_compatible(&id, "apple,panel-"), -EINVAL); + KUNIT_EXPECT_EQ(test, dcp_panel_id_from_compatible(&id, "panel-j516"), -EINVAL); + KUNIT_EXPECT_EQ(test, dcp_panel_id_from_compatible(&id, "acme,panel-j516"), -ENOENT); + KUNIT_EXPECT_EQ(test, dcp_panel_id_from_compatible(&id, "apple,panel-j516 x"), -EINVAL); + KUNIT_EXPECT_EQ(test, dcp_panel_id_from_compatible(&id, + "apple,panel-j5160000000000"), + -EINVAL); +} + +static const struct drm_edid *panel_edid_j516(struct kunit *test, + u8 e[DCP_PANEL_EDID_BLOCKS * EDID_LENGTH]) +{ + struct dcp_panel_id id; + const struct drm_edid *edid; + + panel_id_j516(test, &id); + KUNIT_ASSERT_EQ(test, dcp_panel_edid_build(&id, J516_W_MM, J516_H_MM, e), 0); + edid = drm_edid_alloc(e, DCP_PANEL_EDID_BLOCKS * EDID_LENGTH); + KUNIT_ASSERT_NOT_NULL(test, edid); + return edid; +} + +static u8 sum(const u8 *p, size_t len) +{ + u8 s = 0; + + while (len--) + s += *p++; + return s; +} + +static void panel_edid_parses_with_make_product_and_size(struct kunit *test) +{ + struct drm_edid_product_id product; + u8 e[DCP_PANEL_EDID_BLOCKS * EDID_LENGTH]; + const struct drm_edid *edid = panel_edid_j516(test, e); + const struct edid *raw; + char vendor[4], name[14]; + + KUNIT_EXPECT_TRUE(test, drm_edid_valid(edid)); + drm_edid_get_product_id(edid, &product); + drm_edid_decode_mfg_id(be16_to_cpu(product.manufacturer_name), vendor); + KUNIT_EXPECT_STREQ(test, vendor, "APP"); + KUNIT_EXPECT_EQ(test, le16_to_cpu(product.product_code), 0); + KUNIT_EXPECT_EQ(test, le32_to_cpu(product.serial_number), 0); + + raw = drm_edid_raw(edid); + KUNIT_ASSERT_NOT_NULL(test, raw); + drm_edid_get_monitor_name(raw, name, sizeof(name)); + KUNIT_EXPECT_STREQ(test, name, "J516"); + /* The connector's size (the firmware's), in whole centimetres. */ + KUNIT_EXPECT_EQ(test, raw->width_cm, 35); + KUNIT_EXPECT_EQ(test, raw->height_cm, 22); + /* Gamma 2.2, not 1.00 (0) and not "in an extension" (0xff). */ + KUNIT_EXPECT_EQ(test, raw->gamma, 0x78); + /* Model year 2023: week 0xff, year 2023 - 1990. */ + KUNIT_EXPECT_EQ(test, raw->mfg_week, 0xff); + KUNIT_EXPECT_EQ(test, raw->mfg_year, 33); + /* P3 red (0.680, 0.320) and the D65 white point (0.3127, 0.3290), 10-bit. */ + KUNIT_EXPECT_EQ(test, raw->red_x << 2 | raw->red_green_lo >> 6, 696); + KUNIT_EXPECT_EQ(test, raw->red_y << 2 | (raw->red_green_lo >> 4 & 3), 328); + KUNIT_EXPECT_EQ(test, raw->white_x << 2 | (raw->blue_white_lo >> 2 & 3), 320); + KUNIT_EXPECT_EQ(test, raw->white_y << 2 | (raw->blue_white_lo & 3), 337); + /* One extension; both blocks sum to 0. */ + KUNIT_EXPECT_EQ(test, raw->extensions, 1); + KUNIT_EXPECT_EQ(test, sum(e, EDID_LENGTH), 0); + KUNIT_EXPECT_EQ(test, sum(e + EDID_LENGTH, EDID_LENGTH), 0); + drm_edid_free(edid); +} + +/* + * The base block's first descriptor is the panel's geometry at 60 Hz (its 120 Hz + * clock does not fit the 16-bit field); the DisplayID extension holds the real + * 120 Hz timing as its preferred Type VII timing. + */ +static void panel_edid_timings_are_the_panels(struct kunit *test) +{ + u8 e[DCP_PANEL_EDID_BLOCKS * EDID_LENGTH]; + const struct drm_edid *edid = panel_edid_j516(test, e); + const struct edid *raw = drm_edid_raw(edid); + const struct detailed_timing *d = &raw->detailed_timings[0]; + const struct detailed_pixel_timing *pt = &d->data.pixel_data; + const u8 *ext = e + EDID_LENGTH, *section = ext + 1, *t; + unsigned int i, names = 0; + + /* 3536 x 2456 x 60 Hz = 521.06 MHz, in 10 kHz. */ + KUNIT_EXPECT_EQ(test, le16_to_cpu(d->pixel_clock), 52106); + KUNIT_EXPECT_EQ(test, pt->hactive_lo | (pt->hactive_hblank_hi >> 4) << 8, 3456); + KUNIT_EXPECT_EQ(test, pt->hblank_lo | (pt->hactive_hblank_hi & 0xf) << 8, 80); + KUNIT_EXPECT_EQ(test, pt->vactive_lo | (pt->vactive_vblank_hi >> 4) << 8, 2234); + KUNIT_EXPECT_EQ(test, pt->vblank_lo | (pt->vactive_vblank_hi & 0xf) << 8, 222); + KUNIT_EXPECT_EQ(test, pt->hsync_offset_lo, 8); + KUNIT_EXPECT_EQ(test, pt->hsync_pulse_width_lo, 32); + /* The front porch at the field's 63, the sync width the panel's 8. */ + KUNIT_EXPECT_EQ(test, (pt->vsync_offset_pulse_width_lo >> 4) | + (pt->hsync_vsync_offset_pulse_width_hi >> 2 & 3) << 4, 63); + KUNIT_EXPECT_EQ(test, pt->vsync_offset_pulse_width_lo & 0xf, 8); + KUNIT_EXPECT_EQ(test, pt->width_mm_lo | (pt->width_height_mm_hi >> 4) << 8, J516_W_MM); + KUNIT_EXPECT_EQ(test, pt->height_mm_lo | (pt->width_height_mm_hi & 0xf) << 8, J516_H_MM); + /* It is not the preferred mode with its refresh rate. */ + KUNIT_EXPECT_EQ(test, raw->features & DRM_EDID_FEATURE_PREFERRED_TIMING, 0); + for (i = 1; i < ARRAY_SIZE(raw->detailed_timings); i++) { + const struct detailed_timing *o = &raw->detailed_timings[i]; + + KUNIT_EXPECT_EQ(test, le16_to_cpu(o->pixel_clock), 0); + KUNIT_EXPECT_NE(test, o->data.other_data.type, EDID_DETAIL_MONITOR_SERIAL); + KUNIT_EXPECT_NE(test, o->data.other_data.type, EDID_DETAIL_MONITOR_RANGE); + names += o->data.other_data.type == EDID_DETAIL_MONITOR_NAME; + } + KUNIT_EXPECT_EQ(test, names, 1); + for (i = 0; i < sizeof(raw->established_timings); i++) + KUNIT_EXPECT_EQ(test, ((const u8 *)&raw->established_timings)[i], 0); + + /* DisplayID 2.0, generic display, Display Parameters then one Type VII timing. */ + KUNIT_EXPECT_EQ(test, ext[0], 0x70); + KUNIT_EXPECT_EQ(test, section[0], 0x20); + KUNIT_EXPECT_EQ(test, section[2], 0x02); + KUNIT_ASSERT_EQ(test, section[1], 3 + 29 + 3 + 20); + KUNIT_EXPECT_EQ(test, sum(section, 4 + section[1] + 1), 0); + KUNIT_EXPECT_EQ(test, section[4], 0x21); + KUNIT_EXPECT_EQ(test, section[6], 29); + /* Image size in 0.1 mm, the native pixels, gamma 2.2. */ + KUNIT_EXPECT_EQ(test, section[7] | section[8] << 8, J516_W_MM * 10); + KUNIT_EXPECT_EQ(test, section[9] | section[10] << 8, J516_H_MM * 10); + KUNIT_EXPECT_EQ(test, section[11] | section[12] << 8, 3456); + KUNIT_EXPECT_EQ(test, section[13] | section[14] << 8, 2234); + KUNIT_EXPECT_EQ(test, section[7 + 28], 0x78); + t = section + 4 + 3 + 29; + KUNIT_EXPECT_EQ(test, t[0], 0x22); + KUNIT_EXPECT_EQ(test, t[2], 20); + t += 3; + /* 1042130 kHz, preferred, and the DCP mode line's porches (each minus one). */ + KUNIT_EXPECT_EQ(test, t[0] | t[1] << 8 | t[2] << 16, 1042130 - 1); + KUNIT_EXPECT_EQ(test, t[3] & 0x80, 0x80); + KUNIT_EXPECT_EQ(test, t[4] | t[5] << 8, 3456 - 1); + KUNIT_EXPECT_EQ(test, t[6] | t[7] << 8, 3536 - 3456 - 1); + KUNIT_EXPECT_EQ(test, (t[8] | t[9] << 8) & 0x7fff, 3464 - 3456 - 1); + KUNIT_EXPECT_EQ(test, t[10] | t[11] << 8, 3496 - 3464 - 1); + KUNIT_EXPECT_EQ(test, t[12] | t[13] << 8, 2234 - 1); + KUNIT_EXPECT_EQ(test, t[14] | t[15] << 8, 2456 - 2234 - 1); + KUNIT_EXPECT_EQ(test, (t[16] | t[17] << 8) & 0x7fff, 2352 - 2234 - 1); + KUNIT_EXPECT_EQ(test, t[18] | t[19] << 8, 2360 - 2352 - 1); + drm_edid_free(edid); +} + +static void panel_edid_refuses_a_size_it_cannot_hold(struct kunit *test) +{ + u8 e[DCP_PANEL_EDID_BLOCKS * EDID_LENGTH]; + struct dcp_panel_id id; + + panel_id_j516(test, &id); + KUNIT_EXPECT_EQ(test, dcp_panel_edid_build(&id, 0, J516_H_MM, e), -EINVAL); + KUNIT_EXPECT_EQ(test, dcp_panel_edid_build(&id, J516_W_MM, 2560, e), -EINVAL); + id.model_year = 2005; + KUNIT_EXPECT_EQ(test, dcp_panel_edid_build(&id, J516_W_MM, J516_H_MM, e), -EINVAL); + id.model_year = 2023; + id.timing.clock_khz = 0; + KUNIT_EXPECT_EQ(test, dcp_panel_edid_build(&id, J516_W_MM, J516_H_MM, e), -EINVAL); + panel_id_j516(test, &id); + id.vendor[0] = '\0'; + KUNIT_EXPECT_EQ(test, dcp_panel_edid_build(&id, J516_W_MM, J516_H_MM, e), -EINVAL); +} + +struct panel_edid_test { + struct drm_device drm; + struct drm_connector connector; +}; + +/* The DRM KUnit device is atomic: a connector needs its state helpers. */ +static const struct drm_connector_funcs panel_edid_connector_funcs = { + .reset = drm_atomic_helper_connector_reset, + .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, +}; + +static void panel_edid_update_publishes_the_block(struct kunit *test) +{ + struct panel_edid_test *t; + struct drm_connector *connector; + struct dcp_panel_id id; + struct device *dev; + int ret; + + dev = drm_kunit_helper_alloc_device(test); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev); + t = drm_kunit_helper_alloc_drm_device(test, dev, struct panel_edid_test, drm, + DRIVER_MODESET); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, t); + connector = &t->connector; + ret = drmm_connector_init(&t->drm, connector, &panel_edid_connector_funcs, + DRM_MODE_CONNECTOR_eDP, NULL); + KUNIT_ASSERT_EQ(test, ret, 0); + + panel_id_j516(test, &id); + mutex_lock(&t->drm.mode_config.mutex); + ret = dcp_panel_edid_update(connector, &id, J516_W_MM, J516_H_MM); + mutex_unlock(&t->drm.mode_config.mutex); + KUNIT_ASSERT_EQ(test, ret, 0); + + /* The update sets 350x220 from the block; dcp_get_modes() restores the mm. */ + KUNIT_EXPECT_EQ(test, connector->display_info.width_mm, 350); + KUNIT_EXPECT_EQ(test, connector->display_info.height_mm, 220); + KUNIT_ASSERT_NOT_NULL(test, connector->edid_blob_ptr); + KUNIT_EXPECT_EQ(test, connector->edid_blob_ptr->length, 2 * EDID_LENGTH); + /* The update adds no mode: the modes stay the firmware's. */ + KUNIT_EXPECT_TRUE(test, list_empty(&connector->probed_modes)); +} + +static struct kunit_case panel_edid_cases[] = { + KUNIT_CASE(panel_id_from_compatible), + KUNIT_CASE(panel_id_needs_a_model_and_a_known_vendor), + KUNIT_CASE(panel_edid_parses_with_make_product_and_size), + KUNIT_CASE(panel_edid_timings_are_the_panels), + KUNIT_CASE(panel_edid_refuses_a_size_it_cannot_hold), + KUNIT_CASE(panel_edid_update_publishes_the_block), + {} +}; + +static struct kunit_suite panel_edid_suite = { + .name = "apple-dcp-panel-edid", + .test_cases = panel_edid_cases, +}; + +kunit_test_suite(panel_edid_suite); diff --git a/drivers/gpu/drm/apple/dcp-panel-edid.c b/drivers/gpu/drm/apple/dcp-panel-edid.c new file mode 100644 index 0000000000000..97eee16101697 --- /dev/null +++ b/drivers/gpu/drm/apple/dcp-panel-edid.c @@ -0,0 +1,354 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * An EDID for a built-in panel. + * + * The DCP gives no EDID for a built-in panel, so a compositor sees no make, + * model or physical size for it. This builds one from what the panel's + * device-tree node and a table of the known panel models say: the vendor and + * model of its most specific compatible ("apple,panel-j516": make APP, name + * J516), the size the connector has, the model year, the panel's native timing + * as the DCP's mode line gives it with all rows shown, and the colour of a P3 + * wide-colour panel (P3 primaries, D65 white point and a nominal gamma of + * 2.2, which the sRGB transfer function of Display P3 approximates). + * + * The native timing is 3456x2234 at 120 Hz with a pixel clock of 1042 MHz. + * The base block's detailed timing cannot hold it: its pixel clock field is + * 16 bits in 10 kHz units (at most 655.35 MHz) and its vertical front porch 6 + * bits. The base block therefore carries the panel's geometry at 60 Hz (the + * same totals and horizontal porches, the vertical front porch at most 63 + * lines), and a DisplayID 2.0 extension carries the real 120 Hz timing as its + * preferred timing, with the display parameters. Neither is a mode source: + * the driver publishes the firmware's modes and never adds modes from this + * EDID. It makes no other claim: no product code or serial number, no + * manufacture week, no luminance and no refresh range. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "dcp-panel-edid.h" + +/* Device-tree vendor prefixes and their PNP IDs. */ +static const struct { + const char *prefix; + const char *pnp; +} dcp_panel_vendors[] = { + { "apple", "APP" }, +}; + +/* + * Panel models: the year their machines came out (the EDID model year) and the + * native timing of the DCP's mode line, with the rows the notch hides shown. + */ +static const struct { + const char *name; + u16 year; + struct dcp_panel_timing timing; +} dcp_panel_models[] = { + /* MacBook Pro (16-inch, M3 Pro or M3 Max): 3456x2234 at 120 Hz */ + { "J516", 2023, { 1042130, 3456, 3464, 3496, 3536, 2234, 2352, 2360, 2456 } }, +}; + +/* EDID 1.4: a nominal gamma of 2.2 is (2.2 - 1) * 100 = 120. */ +#define DCP_PANEL_EDID_GAMMA 120 +/* EDID 1.4: week 0xff marks the year byte as the model year, from 1990. */ +#define DCP_PANEL_EDID_MODEL_YEAR 0xff +/* The base block's detailed timing: the panel's geometry at this rate. */ +#define DCP_PANEL_EDID_DTD_HZ 60 +/* EDID 1.4 detailed timing: the vertical front porch field is 6 bits. */ +#define DCP_PANEL_EDID_DTD_VFP_MAX 63 + +/* P3 primaries and the D65 white point, CIE 1931 x and y in 1/10000. */ +static const u16 dcp_panel_p3[8] = { 6800, 3200, 2650, 6900, 1500, 600, 3127, 3290 }; + +/* DisplayID 2.0 (VESA DisplayID Standard v2.0). */ +#define DISPLAYID_EXT 0x70 /* EDID extension tag */ +#define DISPLAYID_V20 0x20 /* structure version 2, revision 0 */ +#define DISPLAYID_GENERIC 0x02 /* primary use case: generic display */ +#define DISPLAYID_PARAMS 0x21 /* Display Parameters data block */ +#define DISPLAYID_PARAMS_LEN 29 +#define DISPLAYID_TYPE7 0x22 /* Type VII detailed timing data block */ +#define DISPLAYID_TYPE7_LEN 20 +#define DISPLAYID_PREFERRED 0x80 /* timing options: preferred */ +#define DISPLAYID_ASPECT_NONE 0x08 /* aspect ratio not given (from the pixels) */ +#define DISPLAYID_SYNC_POS 0x8000 /* front porch word: positive sync */ +#define DISPLAYID_NO_SPEAKERS 0x80 /* features: audio not integrated */ +#define DISPLAYID_TECH_LCD 0x10 /* device technology: active-matrix LCD */ + +int dcp_panel_id_from_compatible(struct dcp_panel_id *id, const char *compatible) +{ + const char *comma = strchr(compatible, ','), *model; + size_t vendor_len, len, i; + + memset(id, 0, sizeof(*id)); + if (!comma) + return -EINVAL; + vendor_len = comma - compatible; + model = comma + 1; + if (str_has_prefix(model, "panel-")) + model += strlen("panel-"); + else + return -EINVAL; + len = strlen(model); + if (!len || len > DCP_PANEL_NAME_LEN) + return -EINVAL; + for (i = 0; i < len; i++) { + if (!isalnum(model[i]) && model[i] != '-') + return -EINVAL; + id->name[i] = toupper(model[i]); + } + + for (i = 0; i < ARRAY_SIZE(dcp_panel_models); i++) { + if (!strcmp(id->name, dcp_panel_models[i].name)) { + id->model_year = dcp_panel_models[i].year; + id->timing = dcp_panel_models[i].timing; + } + } + for (i = 0; i < ARRAY_SIZE(dcp_panel_vendors); i++) { + if (strlen(dcp_panel_vendors[i].prefix) == vendor_len && + !strncmp(compatible, dcp_panel_vendors[i].prefix, vendor_len)) { + strscpy(id->vendor, dcp_panel_vendors[i].pnp); + return 0; + } + } + memset(id, 0, sizeof(*id)); + return -ENOENT; +} + +static void put_le16(u8 *p, u16 v) +{ + p[0] = v; + p[1] = v >> 8; +} + +static void checksum(u8 *start, size_t len) +{ + u8 sum = 0; + size_t i; + + for (i = 0; i < len - 1; i++) + sum += start[i]; + start[len - 1] = -sum; +} + +static bool timing_valid(const struct dcp_panel_timing *t) +{ + return t->clock_khz && t->hdisplay < t->hsync_start && t->hsync_start < t->hsync_end && + t->hsync_end < t->htotal && t->htotal - t->hdisplay < 4096 && + t->vdisplay < t->vsync_start && t->vsync_start < t->vsync_end && + t->vsync_end < t->vtotal && t->vtotal - t->vdisplay < 4096 && + t->hsync_start - t->hdisplay < 1024 && t->hsync_end - t->hsync_start < 1024 && + t->vsync_end - t->vsync_start < 64; +} + +/* The base block's detailed timing: the panel's geometry at DCP_PANEL_EDID_DTD_HZ. */ +static void base_dtd(u8 *d, const struct dcp_panel_timing *t, int width_mm, int height_mm) +{ + u32 clock = DIV_ROUND_CLOSEST((u32)t->htotal * t->vtotal * DCP_PANEL_EDID_DTD_HZ, 10000); + u16 hblank = t->htotal - t->hdisplay, vblank = t->vtotal - t->vdisplay; + u16 hfp = t->hsync_start - t->hdisplay, hsw = t->hsync_end - t->hsync_start; + u16 vfp = min_t(u16, t->vsync_start - t->vdisplay, DCP_PANEL_EDID_DTD_VFP_MAX); + u16 vsw = t->vsync_end - t->vsync_start; + + put_le16(d, clock); + d[2] = t->hdisplay; + d[3] = hblank; + d[4] = (t->hdisplay >> 8) << 4 | hblank >> 8; + d[5] = t->vdisplay; + d[6] = vblank; + d[7] = (t->vdisplay >> 8) << 4 | vblank >> 8; + d[8] = hfp; + d[9] = hsw; + d[10] = (vfp & 0xf) << 4 | (vsw & 0xf); + d[11] = (hfp >> 8) << 6 | (hsw >> 8) << 4 | (vfp >> 4) << 2 | (vsw >> 4); + d[12] = width_mm; + d[13] = height_mm; + d[14] = (width_mm >> 8) << 4 | height_mm >> 8; + /* Digital separate sync, positive vertical and horizontal sync. */ + d[17] = 0x1e; +} + +/* The P3/D65 chromaticity of the base block, in 10-bit fractions. */ +static void base_chromaticity(struct edid *block) +{ + u16 v[8]; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(v); i++) + v[i] = DIV_ROUND_CLOSEST(dcp_panel_p3[i] * 1024, 10000); + block->red_green_lo = (v[0] & 3) << 6 | (v[1] & 3) << 4 | (v[2] & 3) << 2 | (v[3] & 3); + block->blue_white_lo = (v[4] & 3) << 6 | (v[5] & 3) << 4 | (v[6] & 3) << 2 | (v[7] & 3); + block->red_x = v[0] >> 2; + block->red_y = v[1] >> 2; + block->green_x = v[2] >> 2; + block->green_y = v[3] >> 2; + block->blue_x = v[4] >> 2; + block->blue_y = v[5] >> 2; + block->white_x = v[6] >> 2; + block->white_y = v[7] >> 2; +} + +static int base_block(const struct dcp_panel_id *id, int width_mm, int height_mm, + struct edid *block) +{ + struct detailed_non_pixel *name; + u16 manufacturer = 0; + size_t len = strnlen(id->name, sizeof(id->name)); + unsigned int i; + + for (i = 0; i < 3; i++) { + if (id->vendor[i] < 'A' || id->vendor[i] > 'Z') + return -EINVAL; + manufacturer = manufacturer << 5 | (id->vendor[i] - '@'); + } + + memset(block, 0, sizeof(*block)); + memcpy(block->header, "\x00\xff\xff\xff\xff\xff\xff\x00", sizeof(block->header)); + block->product_id.manufacturer_name = cpu_to_be16(manufacturer); + block->mfg_week = DCP_PANEL_EDID_MODEL_YEAR; + block->mfg_year = id->model_year - 1990; + block->version = 1; + block->revision = 4; + block->input = DRM_EDID_INPUT_DIGITAL; + block->width_cm = DIV_ROUND_CLOSEST(width_mm, 10); + block->height_cm = DIV_ROUND_CLOSEST(height_mm, 10); + block->gamma = DCP_PANEL_EDID_GAMMA; + base_chromaticity(block); + /* Standard timings 0x0101 are unused slots. */ + memset(block->standard_timings, 0x01, sizeof(block->standard_timings)); + + /* EDID 1.4: the first descriptor is a detailed timing; the second names the panel. */ + base_dtd((u8 *)&block->detailed_timings[0], &id->timing, width_mm, height_mm); + name = &block->detailed_timings[1].data.other_data; + name->type = EDID_DETAIL_MONITOR_NAME; + memset(name->data.str.str, ' ', sizeof(name->data.str.str)); + memcpy(name->data.str.str, id->name, len); + if (len < sizeof(name->data.str.str)) + name->data.str.str[len] = '\n'; + for (i = 2; i < ARRAY_SIZE(block->detailed_timings); i++) + block->detailed_timings[i].data.other_data.type = 0x10; + block->extensions = DCP_PANEL_EDID_BLOCKS - 1; + checksum((u8 *)block, EDID_LENGTH); + return 0; +} + +/* DisplayID 2.0 CIE 1931 x/y pair in 12-bit fractions, packed in 3 bytes. */ +static void displayid_xy(u8 *p, u16 x, u16 y) +{ + u16 X = DIV_ROUND_CLOSEST(x * 4095, 10000), Y = DIV_ROUND_CLOSEST(y * 4095, 10000); + + p[0] = X; + p[1] = (X >> 8) | (Y & 0xf) << 4; + p[2] = Y >> 4; +} + +/* The DisplayID 2.0 extension: display parameters and the 120 Hz Type VII timing. */ +static void displayid_block(const struct dcp_panel_id *id, int width_mm, int height_mm, + u8 *ext) +{ + const struct dcp_panel_timing *t = &id->timing; + u8 *section = ext + 1, *p, *b; + unsigned int i; + + memset(ext, 0, EDID_LENGTH); + ext[0] = DISPLAYID_EXT; + section[0] = DISPLAYID_V20; + section[1] = 3 + DISPLAYID_PARAMS_LEN + 3 + DISPLAYID_TYPE7_LEN; + section[2] = DISPLAYID_GENERIC; + section[3] = 0; /* no further DisplayID extensions */ + + b = section + 4; + b[0] = DISPLAYID_PARAMS; + b[2] = DISPLAYID_PARAMS_LEN; + p = b + 3; + put_le16(p + 0, width_mm * 10); /* 0.1 mm */ + put_le16(p + 2, height_mm * 10); + put_le16(p + 4, t->hdisplay); + put_le16(p + 6, t->vdisplay); + /* Left to right, top to bottom; CIE 1931; the speakers are not the panel's. */ + p[8] = DISPLAYID_NO_SPEAKERS; + for (i = 0; i < 4; i++) + displayid_xy(p + 9 + 3 * i, dcp_panel_p3[2 * i], dcp_panel_p3[2 * i + 1]); + /* Bytes 21-26, the luminances, are not known: left 0. Colour depth not given. */ + p[27] = DISPLAYID_TECH_LCD; + p[28] = DCP_PANEL_EDID_GAMMA; + + b = p + DISPLAYID_PARAMS_LEN; + b[0] = DISPLAYID_TYPE7; + b[2] = DISPLAYID_TYPE7_LEN; + p = b + 3; + /* Pixel clock in kHz minus one, 24 bits. */ + p[0] = (t->clock_khz - 1); + p[1] = (t->clock_khz - 1) >> 8; + p[2] = (t->clock_khz - 1) >> 16; + p[3] = DISPLAYID_PREFERRED | DISPLAYID_ASPECT_NONE; + /* Each field minus one; the front porch words carry the sync polarity. */ + put_le16(p + 4, t->hdisplay - 1); + put_le16(p + 6, t->htotal - t->hdisplay - 1); + put_le16(p + 8, (t->hsync_start - t->hdisplay - 1) | DISPLAYID_SYNC_POS); + put_le16(p + 10, t->hsync_end - t->hsync_start - 1); + put_le16(p + 12, t->vdisplay - 1); + put_le16(p + 14, t->vtotal - t->vdisplay - 1); + put_le16(p + 16, (t->vsync_start - t->vdisplay - 1) | DISPLAYID_SYNC_POS); + put_le16(p + 18, t->vsync_end - t->vsync_start - 1); + + /* The section's checksum after its payload, then the block's. */ + checksum(section, 4 + section[1] + 1); + checksum(ext, EDID_LENGTH); +} + +int dcp_panel_edid_build(const struct dcp_panel_id *id, int width_mm, int height_mm, + u8 edid[DCP_PANEL_EDID_BLOCKS * EDID_LENGTH]) +{ + size_t len = strnlen(id->name, sizeof(id->name)); + int ret; + + if (width_mm <= 0 || height_mm <= 0 || width_mm > 4095 || height_mm > 4095 || + DIV_ROUND_CLOSEST(width_mm, 10) > 255 || DIV_ROUND_CLOSEST(height_mm, 10) > 255) + return -EINVAL; + if (strnlen(id->vendor, sizeof(id->vendor)) != 3 || !len || len > DCP_PANEL_NAME_LEN) + return -EINVAL; + /* EDID 1.4 reserves the years before 2006. */ + if (id->model_year < 2006 || id->model_year > 1990 + 255) + return -EINVAL; + if (!timing_valid(&id->timing)) + return -EINVAL; + ret = base_block(id, width_mm, height_mm, (struct edid *)edid); + if (ret) + return ret; + displayid_block(id, width_mm, height_mm, edid + EDID_LENGTH); + return 0; +} + +int dcp_panel_edid_update(struct drm_connector *connector, const struct dcp_panel_id *id, + int width_mm, int height_mm) +{ + const struct drm_edid *edid; + u8 *blocks; + int ret; + + blocks = kmalloc(DCP_PANEL_EDID_BLOCKS * EDID_LENGTH, GFP_KERNEL); + if (!blocks) + return -ENOMEM; + ret = dcp_panel_edid_build(id, width_mm, height_mm, blocks); + if (ret) + goto out; + edid = drm_edid_alloc(blocks, DCP_PANEL_EDID_BLOCKS * EDID_LENGTH); + if (!edid) { + ret = -ENOMEM; + goto out; + } + /* This sets the connector's size from the block, in whole centimetres. */ + ret = drm_edid_connector_update(connector, edid); + drm_edid_free(edid); +out: + kfree(blocks); + return ret; +} diff --git a/drivers/gpu/drm/apple/dcp-panel-edid.h b/drivers/gpu/drm/apple/dcp-panel-edid.h new file mode 100644 index 0000000000000..1e9a6242831b1 --- /dev/null +++ b/drivers/gpu/drm/apple/dcp-panel-edid.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* A base EDID for a built-in panel, from its device-tree node. */ +#ifndef __APPLE_DCP_PANEL_EDID_H__ +#define __APPLE_DCP_PANEL_EDID_H__ + +#include + +/* The monitor-name text of an EDID descriptor holds 13 characters. */ +#define DCP_PANEL_NAME_LEN 13 + +/* An EDID of a base block and one DisplayID extension. */ +#define DCP_PANEL_EDID_BLOCKS 2 + +/* A panel's native timing, as the DCP's mode line gives it (all rows shown). */ +struct dcp_panel_timing { + u32 clock_khz; + u16 hdisplay, hsync_start, hsync_end, htotal; + u16 vdisplay, vsync_start, vsync_end, vtotal; +}; + +/* The make, product, model year and native timing of a panel. */ +struct dcp_panel_id { + char vendor[4]; /* PNP ID, empty if unknown */ + char name[DCP_PANEL_NAME_LEN + 1]; /* monitor name */ + u16 model_year; /* the model's year, 0 if unknown */ + struct dcp_panel_timing timing; /* zero if unknown */ +}; + +struct drm_connector; + +int dcp_panel_id_from_compatible(struct dcp_panel_id *id, const char *compatible); +int dcp_panel_edid_build(const struct dcp_panel_id *id, int width_mm, int height_mm, + u8 edid[DCP_PANEL_EDID_BLOCKS * 128]); +int dcp_panel_edid_update(struct drm_connector *connector, const struct dcp_panel_id *id, + int width_mm, int height_mm); + +#endif diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index df6a8e976455e..5ccd0bbcd1d1d 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -6024,6 +6024,8 @@ static int dcp_comp_bind_pipe(struct device *dev, struct device *main, void *dat panel_np = of_get_compatible_child(dev->of_node, "apple,panel"); if (panel_np) { + const char *compatible; + if (dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP) { /* * Desktop 26.x swaps carry nits, and the panel node @@ -6042,6 +6044,12 @@ static int dcp_comp_bind_pipe(struct device *dev, struct device *main, void *dat } dcp_panel_read_dimensions(dcp, panel_np); + /* The most specific compatible names the panel for its EDID. */ + if (iomfb_v14_7_base_edid(dcp) && + !of_property_read_string_index(panel_np, "compatible", 0, &compatible) && + dcp_panel_id_from_compatible(&dcp->panel.id, compatible)) + dev_dbg(dev, "no EDID make and product in '%s'\n", compatible); + of_node_put(panel_np); /* Read target metadata for H17P and desktop firmware alike. */ dcp_panel_read_adt(dcp); diff --git a/drivers/gpu/drm/apple/iomfb.c b/drivers/gpu/drm/apple/iomfb.c index 3b41359bba82e..eabf90c1a140f 100644 --- a/drivers/gpu/drm/apple/iomfb.c +++ b/drivers/gpu/drm/apple/iomfb.c @@ -2785,6 +2785,22 @@ int dcp_get_modes(struct drm_connector *connector) if (dcp->hw.link_report) dcp_note_edid(apple_connector, apple_connector->drm_edid); } + } else if (nr_modes && dcp_is_v14_7_panel(dcp) && dcp->panel.id.vendor[0]) { + /* + * No EDID comes for this panel: publish the base block of its + * node, sized as the connector is (the firmware's size, else the + * node's), then give the connector back its size in millimetres. + */ + int update; + + dcp_update_connector_dimensions(dcp, connector); + update = dcp_panel_edid_update(connector, &dcp->panel.id, + connector->display_info.width_mm, + connector->display_info.height_mm); + dcp_update_connector_dimensions(dcp, connector); + apple_connector->drm_edid_firmware_derived = false; + if (update) + dev_warn_once(dcp->dev, "panel EDID publication failed: %d\n", update); } else { u64 generation = 0; u32 defaults = 0; diff --git a/drivers/gpu/drm/apple/iomfb_v14_7.c b/drivers/gpu/drm/apple/iomfb_v14_7.c index b520b0a2c3afa..2579842afb8cb 100644 --- a/drivers/gpu/drm/apple/iomfb_v14_7.c +++ b/drivers/gpu/drm/apple/iomfb_v14_7.c @@ -194,6 +194,7 @@ static const struct dcp_v14_board dcp_v14_board_j516c = { * at most), as the e272b67 path on this J516C presented it. */ .panel_nits = true, + .base_edid = true, }; /* @@ -1734,6 +1735,11 @@ bool dcp_v14_board_stamps_swaps(const struct dcp_v14_board *board, bool external return board && !external && board->swap_timestamps; } +bool iomfb_v14_7_base_edid(const struct apple_dcp *dcp) +{ + return dcp->v14 && dcp->v14->board && dcp->v14->board->base_edid; +} + int iomfb_v14_7_probe(struct apple_dcp *dcp) { struct device *dev = dcp->dev; diff --git a/drivers/gpu/drm/apple/iomfb_v14_7.h b/drivers/gpu/drm/apple/iomfb_v14_7.h index 8aa4eeda4be7a..7eb6ada2b1c26 100644 --- a/drivers/gpu/drm/apple/iomfb_v14_7.h +++ b/drivers/gpu/drm/apple/iomfb_v14_7.h @@ -28,6 +28,8 @@ const __be32 *of_translate_dma_region_checked(struct device_node *dev, */ const struct dcp_v14_board *iomfb_v14_7_board(struct device *dev); const char *iomfb_v14_7_board_name(const struct dcp_v14_board *board); +/* Whether the internal panel's board record gives it a base EDID. */ +bool iomfb_v14_7_base_edid(const struct apple_dcp *dcp); /* Platform probe: firmware identity, boot loader handoff, PMP acknowledgment. */ int iomfb_v14_7_probe(struct apple_dcp *dcp); diff --git a/drivers/gpu/drm/apple/iomfb_v14_7_board.h b/drivers/gpu/drm/apple/iomfb_v14_7_board.h index 6de1ae9004122..79eaac63a95b0 100644 --- a/drivers/gpu/drm/apple/iomfb_v14_7_board.h +++ b/drivers/gpu/drm/apple/iomfb_v14_7_board.h @@ -48,6 +48,11 @@ struct dcp_v14_board { bool swap_timestamps; /* This board has a qualified panel level block; machine admission is separate. */ bool panel_nits; + /* + * The panel gets a base EDID (make, model and size) built from its + * device-tree node, as the firmware gives none. + */ + bool base_edid; }; /* Whether the DCP node or the machine (as @ctx gives them) has @compat. */ diff --git a/drivers/gpu/drm/apple/v14-board-test.c b/drivers/gpu/drm/apple/v14-board-test.c index d79c2b79a9cbc..f6202c07e39b0 100644 --- a/drivers/gpu/drm/apple/v14-board-test.c +++ b/drivers/gpu/drm/apple/v14-board-test.c @@ -77,6 +77,7 @@ static void v14_board_j516c(struct kunit *test) /* No colour matrix method is known for this board. */ KUNIT_EXPECT_EQ(test, b->ctm_set, 0); KUNIT_EXPECT_EQ(test, b->ctm_get, 0); + KUNIT_EXPECT_TRUE(test, b->base_edid); } /* @@ -101,6 +102,8 @@ static void v14_board_j514c(struct kunit *test) KUNIT_EXPECT_TRUE(test, b->promotion); KUNIT_EXPECT_TRUE(test, b->log_bringup); KUNIT_EXPECT_EQ(test, b->ctm_set, 0); + /* Its panel is not the J516C's: no base EDID. */ + KUNIT_EXPECT_FALSE(test, b->base_edid); KUNIT_EXPECT_TRUE(test, dcp_v14_board_admits(b, J516C_DCP_IMAGE)); KUNIT_EXPECT_FALSE(test, dcp_v14_board_admits(b, T6030_DCP_IMAGE)); /* Not the J516C record. */ @@ -159,6 +162,7 @@ static void v14_board_unchanged(struct kunit *test) KUNIT_EXPECT_TRUE(test, b->promotion); KUNIT_EXPECT_FALSE(test, b->log_bringup); KUNIT_EXPECT_EQ(test, b->ctm_set, 0); + KUNIT_EXPECT_FALSE(test, b->base_edid); KUNIT_EXPECT_TRUE(test, dcp_v14_board_admits(b, T6030_DCP_IMAGE)); KUNIT_EXPECT_FALSE(test, dcp_v14_board_admits(b, J613_DCP_IMAGE)); /* The T6030 record serves a T6030 DCP on any machine, as before. */ @@ -173,6 +177,7 @@ static void v14_board_unchanged(struct kunit *test) KUNIT_EXPECT_EQ(test, b->panel_height, 1664); KUNIT_EXPECT_FALSE(test, b->promotion); KUNIT_EXPECT_FALSE(test, b->log_bringup); + KUNIT_EXPECT_FALSE(test, b->base_edid); KUNIT_EXPECT_FALSE(test, dcp_v14_board_admits(b, T6030_DCP_IMAGE)); /* A T8122 DCP on a T6031 machine has no record. */ diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py b/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py index 5d4f8c6abab76..dc04097d8eee0 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py @@ -757,7 +757,7 @@ def publication(root): state = n['state'] state = state.replace('struct apple_connector {', '''struct drm_device { void *dev; struct { bool mutex; } mode_config; }; struct drm_connector { struct drm_device *dev; int registration_state; void *state; - struct { struct { unsigned min_vfreq,max_vfreq; } monitor_range; } display_info; + struct { struct { unsigned min_vfreq,max_vfreq; } monitor_range; int width_mm,height_mm; } display_info; }; struct apple_connector {''') state = state.replace(' struct { int registration_state; } base;', ' struct drm_connector base;') @@ -772,7 +772,7 @@ def publication(root): int fw_compat,width_mm,height_mm,fixed_connector_type; unsigned notch_height; bool modes_lock,modes_admitted,modes_provisional,placeholder_retried,external_native; int external_held; u64 modes_generation,dimensions_generation; struct work_struct dimensions_wq; - struct { int width_mm,height_mm; } panel; + struct { int width_mm,height_mm; struct { char vendor[4]; } id; } panel; struct { size_t length,received; void *data; bool contiguous,payload_complete; u64 modes_generation; u64 av_service_epoch,automatic_connection_sequence; bool automatic_service_pending; struct dcp_metadata_ticket metadata_ticket,mode_ticket; @@ -834,6 +834,10 @@ def publication(root): /* The stubbed read always carries an EDID: nothing asks for a re-probe. */ static bool dcpavserv_edid_retry(struct apple_dcp *d,u64 e) { (void)d;(void)e;assert(0);return false; } static void dcpavserv_edid_retry_reset(struct apple_dcp *d) { assert(d->dcpavserv.lock); } +/* These H17P scenarios never reach the 14.7 panel's base EDID. */ +#define dev_warn_once(...) ((void)0) +static bool dcp_is_v14_7_panel(const struct apple_dcp *d) { (void)d; return false; } +static int dcp_panel_edid_update(struct drm_connector *c,const void *id,int w,int h) { (void)c;(void)id;(void)w;(void)h;assert(false);return 0; } static void dpavservep_detach(struct apple_dcp *d); static struct apple_dcp *probing; static struct drm_edid transport_edid; @@ -1188,10 +1192,9 @@ def panel_dimensions(root): unit = unit.replace('bool modes_lock,modes_admitted,', 'bool external_physically_absent,modes_lock,modes_admitted,', 1) # The connector's physical size, which DRM keeps in display_info. - old = 'struct { struct { unsigned min_vfreq,max_vfreq; } monitor_range; } display_info;' - assert unit.count(old) == 1 - unit = unit.replace(old, 'struct { struct { unsigned min_vfreq,max_vfreq; } monitor_range; ' - 'int width_mm,height_mm; } display_info;') + # publication() already gives display_info its size for the panel EDID path. + assert unit.count('struct { struct { unsigned min_vfreq,max_vfreq; } monitor_range; ' + 'int width_mm,height_mm; } display_info;') == 1 dcp = (root / 'drivers/gpu/drm/apple/dcp.c').read_text() unit = unit.replace(block(unit, 'static bool __attribute__((unused)) dcp_has_panel('), block(dcp, 'bool dcp_has_panel(')) From 7dc22ca97cd7bfbf7417cb1a72e6aa55c0290c5f Mon Sep 17 00:00:00 2001 From: Chris Kearney <303316+chriskearney@users.noreply.github.com> Date: Wed, 4 Nov 2026 21:08:10 -0800 Subject: [PATCH 18/47] drm/asahi: add explicit J514C bring-up admission J514C has the same four-cluster T6031 GPU as J516C, but the existing machine check refuses it before the shared display and firmware gates. Add a default-off parameter requiring exactly 1 and both J514C/T6031 compatibles on the DeviceTree platform. Preserve display publication, DT/ADT shape, hardware identity, core-mask and cold-start admission. This is an experimental same-die bring-up. The maximum-power, relative-power and two MTR mask groups remain J516C reference words; they have not been independently measured on J514C. The opt-in warning keeps this assumption visible. Do not claim thermal qualification. The production admission harness covers the exact board/SoC/parameter gates and native-display ordering, with compiled C and Rust mutants. Assisted-by: Codex:GPT-6 Signed-off-by: Scott Jones --- drivers/gpu/drm/asahi/asahi_core.rs | 4 ++ drivers/gpu/drm/asahi/g15/boot.rs | 20 +++++++- drivers/gpu/drm/asahi/g15/hw/t6031.rs | 5 +- drivers/gpu/drm/asahi/g15/params.rs | 6 +++ tools/asahi/g15-display-order-tests.py | 70 ++++++++++++++++++++++---- 5 files changed, 91 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/asahi/asahi_core.rs b/drivers/gpu/drm/asahi/asahi_core.rs index bd69152c3ce75..b5e42cf16aa9f 100644 --- a/drivers/gpu/drm/asahi/asahi_core.rs +++ b/drivers/gpu/drm/asahi/asahi_core.rs @@ -236,6 +236,10 @@ module! { default: 0, description: "G15: admit an unpinned GPU firmware build whose TEXT SHA-256 starts with these 8 bytes (bring-up only)", }, + g15_j514c_bringup: u32 { + default: 0, + description: "G15: opt into J514C/T6031 bring-up with the J516C reference power/thermal words (1 only; unqualified on J514C)", + }, stats_export: u8 { default: 1, // permissions: 0, diff --git a/drivers/gpu/drm/asahi/g15/boot.rs b/drivers/gpu/drm/asahi/g15/boot.rs index 95269e152177b..c790131a624b5 100644 --- a/drivers/gpu/drm/asahi/g15/boot.rs +++ b/drivers/gpu/drm/asahi/g15/boot.rs @@ -46,7 +46,7 @@ use super::fw::initdata::runtime; use super::hw; use super::initdata::{self, InitData}; use super::object::Objects; -use super::{identity, regs, uat, Config, Shared}; +use super::{identity, params, regs, uat, Config, Shared}; use crate::driver::AsahiDrmDevice as AsahiDevice; use crate::mmu; @@ -461,6 +461,16 @@ pub(crate) fn admit( ) -> Result { let dev = pdev.as_ref(); let pmp = cfg.platform == hw::Platform::AdtWithPmp; + // Experimental same-die candidate, not a qualification of the J516C + // reference words for the 14-inch chassis. Keep exact board AND SoC checks; + // T6034 boards must never inherit this four-cluster T6031 configuration. + // The remaining display, DT/ADT, full firmware identity, hardware identity + // and record-builder admission below is unchanged. + let j514c_candidate = cfg.chip_id == 0x6031 + && cfg.platform == hw::Platform::DeviceTree + && params::j514c_bringup() + && glue::machine(kernel::c_str!("apple,j514c")) + && glue::machine(kernel::c_str!("apple,t6031")); if pmp { if !glue::board() { return Err(ENODEV); @@ -475,7 +485,7 @@ pub(crate) fn admit( } return Err(err); } - } else if !glue::machine(cfg.machine) { + } else if !glue::machine(cfg.machine) && !j514c_candidate { dev_err!(dev, "G15: not a {} machine\n", cfg.name); return Err(ENODEV); } else { @@ -490,6 +500,12 @@ pub(crate) fn admit( return Err(err); } } + if j514c_candidate { + dev_warn!( + dev, + "J514C bring-up: using J516C reference power/thermal words; this board is not qualified\n" + ); + } let adt = adt::read(dev, cfg) .inspect_err(|e| dev_err!(dev, "GPU regions not admitted: {:?}\n", e))?; identity::firmware(dev, &adt, cfg.firmware) diff --git a/drivers/gpu/drm/asahi/g15/hw/t6031.rs b/drivers/gpu/drm/asahi/g15/hw/t6031.rs index 8bac33989db64..3f4f6d67f95d6 100644 --- a/drivers/gpu/drm/asahi/g15/hw/t6031.rs +++ b/drivers/gpu/drm/asahi/g15/hw/t6031.rs @@ -1,6 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-only OR MIT -//! T6031 (M3 Max, G15C) configuration, admitted on J516C only. +//! T6031 (M3 Max, G15C) configuration, qualified on J516C only. +//! +//! J514C may explicitly opt into a bring-up candidate using these reference +//! words with `g15_j514c_bringup=1`. This is not J514C power/thermal qualification. //! //! One die, four clusters of ten core slots. The firmware is the same RTKit 2419 generation as //! the T6030's and the initdata graph keeps the T6030 canonical VAs; what differs is the SoC diff --git a/drivers/gpu/drm/asahi/g15/params.rs b/drivers/gpu/drm/asahi/g15/params.rs index c2c3486475061..74d18cf4ed480 100644 --- a/drivers/gpu/drm/asahi/g15/params.rs +++ b/drivers/gpu/drm/asahi/g15/params.rs @@ -87,6 +87,12 @@ pub(crate) fn accept_text_prefix() -> u64 { module_parameters::g15_accept_text_prefix.value() } +/// Opt into the J514C candidate only at exactly 1. The default keeps the +/// qualified J516C-only board admission. This does not override firmware identity. +pub(crate) fn j514c_bringup() -> bool { + *module_parameters::g15_j514c_bringup.value() == 1 +} + /// The parameter for the PB growth maximum the firmware is given, in blocks, clamped to /// 64..=4095. [`super::pools::Pools::soft_max`] raises it to at least the initial posting; the /// blocks above it, up to the 4095 posted at most, answer the synchronous requests of partial diff --git a/tools/asahi/g15-display-order-tests.py b/tools/asahi/g15-display-order-tests.py index f07ca470c4c92..4e194ab920c76 100644 --- a/tools/asahi/g15-display-order-tests.py +++ b/tools/asahi/g15-display-order-tests.py @@ -267,6 +267,8 @@ def c_source(root): RS_PREFIX = r''' #![allow(dead_code, unused_variables, unused_imports, unused_macros, non_snake_case)] +extern crate self as kernel; +#[macro_export] macro_rules! c_str { ($s:literal) => { $s }; } use std::cell::RefCell; use std::marker::PhantomData; #[derive(Copy, Clone, PartialEq, Eq, Debug)] @@ -280,15 +282,22 @@ def c_source(root): macro_rules! dev_err { ($($args:tt)*) => {{}}; } macro_rules! dev_info { ($($args:tt)*) => {{}}; } macro_rules! dev_warn { ($($args:tt)*) => {{ warned(); }}; } -struct State { board: bool, machine: bool, pmp: i32, display: i32, sleep_hold: bool, asc_fail: bool } +struct State { board: bool, machine: bool, pmp: i32, display: i32, sleep_hold: bool, asc_fail: bool, j514c: bool, t6031: bool, bringup: u32 } thread_local! { static CALLS: RefCell> = const { RefCell::new(Vec::new()) }; - static STATE: RefCell = const { RefCell::new(State { board: true, machine: true, pmp: 0, display: 0, sleep_hold: true, asc_fail: false }) }; + static STATE: RefCell = const { RefCell::new(State { board: true, machine: true, pmp: 0, display: 0, sleep_hold: true, asc_fail: false, j514c: false, t6031: false, bringup: 0 }) }; static HOLD: RefCell> = const { RefCell::new(None) }; static WARNINGS: RefCell = const { RefCell::new(0) }; } fn warned() { WARNINGS.with(|w| *w.borrow_mut() += 1); } +mod module_parameters { + #[allow(non_upper_case_globals)] pub static g15_j514c_bringup: Parameter = Parameter; + pub struct Parameter; + impl Parameter { pub fn value(&self) -> Box { Box::new(super::STATE.with(|s| s.borrow().bringup)) } } +} mod params { + use super::module_parameters; + @J514C_GETTER@ pub fn sleep_hold() -> bool { super::STATE.with(|s| s.borrow().sleep_hold) } } fn call(name: &'static str) { CALLS.with(|c| c.borrow_mut().push(name)); } @@ -306,7 +315,7 @@ def c_source(root): #[derive(Copy, Clone, PartialEq, Eq)] pub enum Platform { AdtWithPmp, DeviceTree } #[derive(Copy, Clone, PartialEq, Eq)] pub enum Board { None, Templates, Blob } } -struct Config { platform: hw::Platform, machine: &'static str, name: &'static str, firmware: (), board: hw::Board } +struct Config { chip_id: u32, platform: hw::Platform, machine: &'static str, name: &'static str, firmware: (), board: hw::Board } mod adt { pub struct GpuAdt; pub fn read(_: &super::device::Device, _: &super::Config) -> super::Result { super::call("adt"); Ok(GpuAdt) } @@ -331,7 +340,7 @@ def c_source(root): mod glue { use super::{call, STATE}; pub fn board() -> bool { call("board"); STATE.with(|s| s.borrow().board) } - pub fn machine(_: &str) -> bool { call("machine"); STATE.with(|s| s.borrow().machine) } + pub fn machine(name: &str) -> bool { call("machine"); STATE.with(|s| { let s=s.borrow(); match name { "apple,j514c" => s.j514c, "apple,t6031" => s.t6031, _ => s.machine } }) } pub unsafe fn asahi_g15_pmp_prepare(_: *mut core::ffi::c_void) -> core::ffi::c_int { call("pmp"); STATE.with(|s| s.borrow().pmp) } pub unsafe fn asahi_g15_display_prepare(_: *mut core::ffi::c_void) -> core::ffi::c_int { call("display"); STATE.with(|s| s.borrow().display) } pub fn dma_coherent(_: &super::device::Device) -> bool { call("coherent"); false } @@ -341,12 +350,12 @@ def c_source(root): ''' RS_MAIN = r''' -static T6031: Config = Config { platform: hw::Platform::DeviceTree, machine: "apple,j516c", name: "T6031 G15C", firmware: (), board: hw::Board::Blob }; -static T6030: Config = Config { platform: hw::Platform::AdtWithPmp, machine: "apple,t6030", name: "T6030 G15S", firmware: (), board: hw::Board::Templates }; +static T6031: Config = Config { chip_id: 0x6031, platform: hw::Platform::DeviceTree, machine: "apple,j516c", name: "T6031 G15C", firmware: (), board: hw::Board::Blob }; +static T6030: Config = Config { chip_id: 0x6030, platform: hw::Platform::AdtWithPmp, machine: "apple,t6030", name: "T6030 G15S", firmware: (), board: hw::Board::Templates }; const TAIL: [&str; 6] = ["adt", "identity", "coherent", "board_images", "regs", "hold"]; fn run(cfg: &'static Config, machine: bool, pmp: i32, display: i32) -> (Result<()>, Vec<&'static str>) { CALLS.with(|c| c.borrow_mut().clear()); - STATE.with(|s| *s.borrow_mut() = State { board: true, machine, pmp, display, sleep_hold: true, asc_fail: false }); + STATE.with(|s| *s.borrow_mut() = State { board: true, machine, pmp, display, sleep_hold: true, asc_fail: false, j514c: false, t6031: false, bringup: 0 }); HOLD.with(|h| *h.borrow_mut() = None); WARNINGS.with(|w| *w.borrow_mut() = 0); let pdev = platform::Device(device::Device, Core(PhantomData)); @@ -355,7 +364,41 @@ def c_source(root): } fn with_tail(head: &[&'static str]) -> Vec<&'static str> { head.iter().chain(TAIL.iter()).copied().collect() } @SLEEP_HOLD_RUN@ +fn candidate_for(cfg: &'static Config, board: bool, soc: bool, value: u32, display: i32) -> (Result<()>, Vec<&'static str>, u32) { + CALLS.with(|c| c.borrow_mut().clear()); + STATE.with(|s| *s.borrow_mut() = State { board: true, machine: false, pmp: 0, display, sleep_hold: true, asc_fail: false, j514c: board, t6031: soc, bringup: value }); + WARNINGS.with(|w| *w.borrow_mut() = 0); + let pdev = platform::Device(device::Device, Core(PhantomData)); + let result = admit(&pdev, &AsahiDevice, cfg).map(|_| ()); + (result, CALLS.with(|c| c.borrow().clone()), WARNINGS.with(|w| *w.borrow())) +} +fn candidate(board: bool, soc: bool, value: u32, display: i32) -> (Result<()>, Vec<&'static str>, u32) { + candidate_for(&T6031, board, soc, value, display) +} +static T6034: Config = Config { chip_id: 0x6034, platform: hw::Platform::DeviceTree, machine: "apple,j514m", name: "T6034", firmware: (), board: hw::Board::Blob }; fn main() { + let (result, calls, _) = candidate_for(&T6034, true, true, 1, 0); + assert_eq!(result, Err(ENODEV), "wrong Config cannot inherit this candidate"); + assert!(!calls.contains(&"display") && !calls.contains(&"adt")); + for value in [0, 2, u32::MAX] { + let (result, calls, _) = candidate(true, true, value, 0); + assert_eq!(result, Err(ENODEV), "J514C requires exactly 1"); + assert!(!calls.contains(&"display") && !calls.contains(&"adt")); + } + for (board, soc) in [(false, true), (true, false), (false, false)] { + let (result, calls, _) = candidate(board, soc, 1, 0); + assert_eq!(result, Err(ENODEV), "wrong board or SoC must not inherit T6031"); + assert!(!calls.contains(&"display") && !calls.contains(&"adt")); + } + let (result, calls, warnings) = candidate(true, true, 1, 0); + assert_eq!(result, Ok(())); + assert!(calls.ends_with(&TAIL)); + assert_eq!(warnings, 1, "candidate must identify its unqualified reference assumptions"); + for code in [-517, -19] { + let (result, calls, _) = candidate(true, true, 1, code); + assert_eq!(result, Err(Error(code)), "candidate still requires its native display"); + assert!(!calls.contains(&"adt") && !calls.contains(&"hold")); + } assert_eq!(run(&T6031, true, 0, -517), (Err(EPROBE_DEFER), vec!["machine", "display"]), "T6031 defers before firmware"); assert_eq!(run(&T6031, true, 0, -19), (Err(ENODEV), vec!["machine", "display"]), "T6031 refusal stops admission"); assert_eq!(run(&T6031, true, 0, 0), (Ok(()), with_tail(&["machine", "display"])), "T6031 admitted after its display"); @@ -372,7 +415,7 @@ def c_source(root): SLEEP_HOLD_RUN = r''' fn run_hold(cfg: &'static Config, sleep_hold: bool, asc_fail: bool) -> (Result<()>, Vec<&'static str>, Option, u32) { CALLS.with(|c| c.borrow_mut().clear()); - STATE.with(|s| *s.borrow_mut() = State { board: true, machine: true, pmp: 0, display: 0, sleep_hold, asc_fail }); + STATE.with(|s| *s.borrow_mut() = State { board: true, machine: true, pmp: 0, display: 0, sleep_hold, asc_fail, j514c: false, t6031: false, bringup: 0 }); HOLD.with(|h| *h.borrow_mut() = None); WARNINGS.with(|w| *w.borrow_mut() = 0); let pdev = platform::Device(device::Device, Core(PhantomData)); @@ -399,6 +442,10 @@ def c_source(root): } RS_MUTANTS = { + "candidate-ignores-config-chip": ("cfg.chip_id == 0x6031", "true"), + "candidate-ignores-opt-in": ("&& params::j514c_bringup()", "&& true"), + "candidate-ignores-board": ('&& glue::machine(kernel::c_str!("apple,j514c"))', "&& true"), + "candidate-ignores-soc": ('&& glue::machine(kernel::c_str!("apple,t6031"))', "&& true"), "display-refusal-ignored": ("dev_err!(dev, \"native display not admitted: {:?}\\n\", err);\n }\n return Err(err);", "dev_err!(dev, \"native display not admitted: {:?}\\n\", err);\n }"), "display-order-skipped": ("let ret = unsafe { glue::asahi_g15_display_prepare(dev.as_raw().cast()) };", "let ret = 0;"), @@ -431,10 +478,10 @@ def c_failures(exe): return [s for s in C_SCENARIOS if subprocess.run([str(exe), s], capture_output=True).returncode] -def rs_model(admit): +def rs_model(admit, getter): """The prelude and main for this admit(): with the system-sleep hold argument (g15_sleep_hold) or without.""" sleep = "glue::hold_power(dev, sleep_hold);" in admit - prefix = RS_PREFIX.replace("@HOLD_POWER@", HOLD_SLEEP if sleep else HOLD_PLAIN) + prefix = RS_PREFIX.replace("@HOLD_POWER@", HOLD_SLEEP if sleep else HOLD_PLAIN).replace("@J514C_GETTER@", getter) main = RS_MAIN.replace("@SLEEP_HOLD_RUN@", SLEEP_HOLD_RUN if sleep else "").replace("@SLEEP_HOLD_CHECKS@", SLEEP_HOLD_CHECKS if sleep else "") return sleep, prefix, main @@ -480,7 +527,8 @@ def main(): checks = static_checks(args.root) source = c_source(args.root) admit = item((args.root / BOOT).read_text(), "pub(crate) fn admit(") - model = rs_model(admit) + getter = item((args.root / "drivers/gpu/drm/asahi/g15/params.rs").read_text(), "pub(crate) fn j514c_bringup(") + model = rs_model(admit, getter) rs_mutants = dict(RS_MUTANTS, **(SLEEP_HOLD_MUTANTS if model[0] else {})) with tempfile.TemporaryDirectory(prefix="g15-display-order-", dir=os.environ.get("TMPDIR")) as tmp: work = Path(tmp) From e6076b6149fe1991fbbc574d3032f5c5131eb704 Mon Sep 17 00:00:00 2001 From: Chris Kearney <303316+chriskearney@users.noreply.github.com> Date: Wed, 4 Nov 2026 22:16:22 -0800 Subject: [PATCH 19/47] drm/asahi: pin the J514C bring-up firmware candidate exactly The opted-in J514C rejects its loaded GFX TEXT because neither J516C pin matches. Record the canonical digest measured by the normal driver on the J514C/T6031 40-core target: OS boot-chain firmware 14.7, system firmware 26.5.2. No private firmware image was extracted or published. Pin the full canonical digest to J514C: 669913fba2736e4b8f8a0f81eadc5ac00c9dc51fdd4c9d3770c66d2b0a1e8786 Require TEXT 0x64000, DATA 0x140000 and GKTS marker 0x5cf28 as well. The eight entropy bytes after the single validated marker are zeroed by the existing canonical hash path. No digest-prefix override is needed. The original pre-review hardware cohort reached firmware READY on all 40 cores, displayed 3024x1964 at 120 Hz and passed short native GLES/Vulkan pixel checks with no wrong pixels. A later normal installed boot also passed automatic login with the separate local SDDM readiness fix. These runs do not establish CTS, sustained-load or thermal qualification. Link: https://github.com/omacom/linux-aurora/pull/363 Assisted-by: Codex:GPT-6 Signed-off-by: Scott Jones --- drivers/gpu/drm/asahi/g15/hw/t6031.rs | 15 ++++++++ tools/asahi/g15-j514c-firmware-tests.py | 50 +++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100755 tools/asahi/g15-j514c-firmware-tests.py diff --git a/drivers/gpu/drm/asahi/g15/hw/t6031.rs b/drivers/gpu/drm/asahi/g15/hw/t6031.rs index 3f4f6d67f95d6..8611844c98740 100644 --- a/drivers/gpu/drm/asahi/g15/hw/t6031.rs +++ b/drivers/gpu/drm/asahi/g15/hw/t6031.rs @@ -161,6 +161,21 @@ pub(crate) const CONFIG: Config = Config { 0x9d, 0x6b, 0xcd, 0xa0, 0x26, 0xcf, ], }, + // Measured by the normal driver on J514C's 14.7 boot chain. The + // board still needs explicit g15_j514c_bringup=1; runtime qualification + // is pending. Keep the full canonical digest and exact machine bound. + FirmwareBuild { + name: "J514C macOS 14.7 boot-chain candidate (runtime qualification pending)", + machine: Some(kernel::c_str!("apple,j514c")), + text_size: 0x64000, + data_size: 0x140000, + marker: 0x5cf28, + text_sha256: [ + 0x66, 0x99, 0x13, 0xfb, 0xa2, 0x73, 0x6e, 0x4b, 0x8f, 0x8a, 0x0f, 0x81, + 0xea, 0xdc, 0x5a, 0xc0, 0x0c, 0x9d, 0xc5, 0x1f, 0xdd, 0x4c, 0x9d, 0x37, + 0x70, 0xc6, 0x6d, 0x2b, 0x0a, 0x1e, 0x87, 0x86, + ], + }, ], // The reference words and measured layout belong to the J516C, not // every T6031 board (in particular, not the 14-inch J514C). diff --git a/tools/asahi/g15-j514c-firmware-tests.py b/tools/asahi/g15-j514c-firmware-tests.py new file mode 100755 index 0000000000000..4b28f58a6e82a --- /dev/null +++ b/tools/asahi/g15-j514c-firmware-tests.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python3 +"""Exercise production full firmware lookup against the actual T6031 rows. + +No firmware image is read. The J514C row is a bring-up candidate, not a hardware pass. +""" +from pathlib import Path +import re,subprocess,tempfile +root=Path(__file__).resolve().parents[2];hw=root/'drivers/gpu/drm/asahi/g15' +source=(hw/'hw/t6031.rs').read_text();rows=[] +for m in re.finditer(r'FirmwareBuild\s*\{(.*?)text_sha256:\s*\[(.*?)\],\s*\}',source,re.S): + body,raw=m.groups();digest=re.findall(r'0x[0-9a-f]+',raw);assert len(digest)==32 + fields={key:re.search(r'\b'+key+r':\s*(0x[0-9a-f]+)',body).group(1) for key in ('text_size','data_size','marker')} + machine=re.search(r'machine:\s*Some\(kernel::c_str!\("([^"]+)"\)\)',body) + rows.append((fields,digest,machine.group(1) if machine else None)) +assert len(rows)==3 and rows[2][2]=='apple,j514c' +measured=[];machines=[] +for f,d,machine in rows: + measured.append('Measured {text_size:'+f['text_size']+',data_size:'+f['data_size']+',marker:'+f['marker']+',sha256:['+','.join(d)+']}') + machines.append('None' if machine is None else 'Some("'+machine+'")') +code='''#[path="MATCHING"] mod matching; +#[path="LOOKUP"] mod lookup; +use lookup::{Measured,Verdict}; +fn rows(board:&str)->Vec<(Measured,bool)> { + let measurements=[MEASUREMENTS];let machines:[Option<&str>;3]=[MACHINES]; + measurements.into_iter().zip(machines).map(|(m,b)|(m,b.map_or(true,|b|b==board))).collect() +} +#[test] fn j514c_exact_candidate() { + let exact=rows("apple,j514c")[2].0; + assert_eq!(lookup::verdict(&exact,rows("apple,j514c"),0),Verdict::Pinned(2)); + for board in ["apple,j516c","apple,j514m","apple,j516m"] { + assert_eq!(lookup::verdict(&exact,rows(board),0),Verdict::Refused); + } + let mut bad=exact;bad.sha256[31]^=1; + assert_eq!(lookup::verdict(&bad,rows("apple,j514c"),0),Verdict::Refused); + let mut bad=exact;bad.text_size+=0x4000; + assert_eq!(lookup::verdict(&bad,rows("apple,j514c"),0),Verdict::Refused); + let mut bad=exact;bad.data_size+=0x4000; + assert_eq!(lookup::verdict(&bad,rows("apple,j514c"),0),Verdict::Refused); + let mut bad=exact;bad.marker+=8; + assert_eq!(lookup::verdict(&bad,rows("apple,j514c"),0),Verdict::Refused); +} +#[test] fn existing_rows_unchanged() { + for i in 0..2 {let m=rows("apple,j516c")[i].0; + assert_eq!(lookup::verdict(&m,rows("apple,j516c"),0),Verdict::Pinned(i));} +} +'''.replace('MATCHING',str(hw/'identity/matching.rs')).replace('LOOKUP',str(hw/'identity/lookup.rs')).replace('MEASUREMENTS',','.join(measured)).replace('MACHINES',','.join(machines)) +with tempfile.TemporaryDirectory(prefix='g15-fw-') as td: + p=Path(td);(p/'test.rs').write_text(code) + subprocess.run(['rustc','--edition=2021','--test',str(p/'test.rs'),'-o',str(p/'test')],check=True) + subprocess.run([str(p/'test')],check=True) From 11db9ef69934cc5cc67ddf457e368fe51b77833f Mon Sep 17 00:00:00 2001 From: Chris Kearney <303316+chriskearney@users.noreply.github.com> Date: Thu, 5 Nov 2026 06:36:09 -0800 Subject: [PATCH 20/47] drm/asahi: refine the J514C bring-up diagnostics and pin tests The J514C lookup test assumes exactly three table rows and a fixed J514C index. Another J516C firmware pin or table reordering breaks the harness without changing the lookup implementation. Find the J514C row by its board binding, derive the array size from the source and check all J516C or unscoped rows. Retain exact digest/size/marker refusal. Bind the current J516C rows explicitly so an opted-in J514C cannot use a pin belonging to that board. Log all four selected reference groups on the opted-in J514C path: maximum power, relative powers and both MTR masks. The warning reads the actual configured Reference. Do not derive a new cap from m1n1's OPP powers: they are stand-ins and not measured J514C chassis limits. The inherited values are still experimental and need native macOS measurement before any general qualification claim. Update the firmware label to reflect the earlier short native pixel and normal-login result. This revision has host checks only; the live target retains the previous hardware-tested package. Production admission tests type-check and assert the logged reference values. Exact lookup passes 14 tests both with reordered rows and with PR340's proposed additional row; removing the J514C binding is caught. The maintained handoff suite and 148 CI self-tests also pass. Link: https://github.com/omacom/linux-aurora/pull/363#issuecomment-6659196535 Assisted-by: Codex:GPT-6 Signed-off-by: Scott Jones --- drivers/gpu/drm/asahi/g15/boot.rs | 14 ++- drivers/gpu/drm/asahi/g15/hw/t6031.rs | 12 +-- tools/asahi/g15-display-order-tests.py | 32 ++++-- tools/asahi/g15-j514c-firmware-tests.py | 132 ++++++++++++++++-------- 4 files changed, 132 insertions(+), 58 deletions(-) diff --git a/drivers/gpu/drm/asahi/g15/boot.rs b/drivers/gpu/drm/asahi/g15/boot.rs index c790131a624b5..d43d1f5f36777 100644 --- a/drivers/gpu/drm/asahi/g15/boot.rs +++ b/drivers/gpu/drm/asahi/g15/boot.rs @@ -501,10 +501,16 @@ pub(crate) fn admit( } } if j514c_candidate { - dev_warn!( - dev, - "J514C bring-up: using J516C reference power/thermal words; this board is not qualified\n" - ); + if let hw::Board::DeviceTree(reference) = cfg.board { + dev_warn!( + dev, + "J514C bring-up: unqualified J516C reference: max_power_mw={} relative_power={:?} fast_die_mask={:#018x} alarm_mask={:#018x}; OPP powers are boot-loader stand-ins\n", + reference.max_power_mw, + reference.relative_power, + reference.fast_die_mask, + reference.alarm_mask + ); + } } let adt = adt::read(dev, cfg) .inspect_err(|e| dev_err!(dev, "GPU regions not admitted: {:?}\n", e))?; diff --git a/drivers/gpu/drm/asahi/g15/hw/t6031.rs b/drivers/gpu/drm/asahi/g15/hw/t6031.rs index 8611844c98740..479dc270b1e83 100644 --- a/drivers/gpu/drm/asahi/g15/hw/t6031.rs +++ b/drivers/gpu/drm/asahi/g15/hw/t6031.rs @@ -139,7 +139,7 @@ pub(crate) const CONFIG: Config = Config { firmware: &[ FirmwareBuild { name: "macOS 14.7 stub firmware (iBoot-10151.140.19.700.2), J516C", - machine: None, + machine: Some(kernel::c_str!("apple,j516c")), text_size: 0x64000, data_size: 0x140000, marker: 0x5cf28, @@ -151,7 +151,7 @@ pub(crate) const CONFIG: Config = Config { }, FirmwareBuild { name: "macOS 14.8 stub firmware, J516C", - machine: None, + machine: Some(kernel::c_str!("apple,j516c")), text_size: 0x64000, data_size: 0x140000, marker: 0x5cf28, @@ -161,11 +161,11 @@ pub(crate) const CONFIG: Config = Config { 0x9d, 0x6b, 0xcd, 0xa0, 0x26, 0xcf, ], }, - // Measured by the normal driver on J514C's 14.7 boot chain. The - // board still needs explicit g15_j514c_bringup=1; runtime qualification - // is pending. Keep the full canonical digest and exact machine bound. + // Measured by the normal driver on J514C's 14.7 boot chain (system + // firmware 26.5.2). Short native GL/Vulkan and normal-login checks passed; + // power/thermal qualification remains open. Explicit bring-up opt-in only. FirmwareBuild { - name: "J514C macOS 14.7 boot-chain candidate (runtime qualification pending)", + name: "J514C macOS 14.7 boot-chain firmware (experimental bring-up)", machine: Some(kernel::c_str!("apple,j514c")), text_size: 0x64000, data_size: 0x140000, diff --git a/tools/asahi/g15-display-order-tests.py b/tools/asahi/g15-display-order-tests.py index 4e194ab920c76..1c3658ffff753 100644 --- a/tools/asahi/g15-display-order-tests.py +++ b/tools/asahi/g15-display-order-tests.py @@ -281,15 +281,22 @@ def c_source(root): const EPROBE_DEFER: Error = Error(-517); macro_rules! dev_err { ($($args:tt)*) => {{}}; } macro_rules! dev_info { ($($args:tt)*) => {{}}; } -macro_rules! dev_warn { ($($args:tt)*) => {{ warned(); }}; } +macro_rules! dev_warn { ($dev:expr, $($args:tt)*) => {{ warned(format!($($args)*)); }}; } struct State { board: bool, machine: bool, pmp: i32, display: i32, sleep_hold: bool, asc_fail: bool, j514c: bool, t6031: bool, bringup: u32 } thread_local! { static CALLS: RefCell> = const { RefCell::new(Vec::new()) }; static STATE: RefCell = const { RefCell::new(State { board: true, machine: true, pmp: 0, display: 0, sleep_hold: true, asc_fail: false, j514c: false, t6031: false, bringup: 0 }) }; static HOLD: RefCell> = const { RefCell::new(None) }; static WARNINGS: RefCell = const { RefCell::new(0) }; + static WARNING_TEXT: RefCell = const { RefCell::new(String::new()) }; } -fn warned() { WARNINGS.with(|w| *w.borrow_mut() += 1); } +fn warned(text: String) { WARNINGS.with(|w| *w.borrow_mut() += 1); WARNING_TEXT.with(|w| *w.borrow_mut() = text); } +mod board { pub mod record { + const RELATIVE_STATES: usize = 7; + #[derive(Copy, Clone, Debug, PartialEq, Eq)] + @REFERENCE_TYPE@ + @REFERENCE_VALUE@; +} } mod module_parameters { #[allow(non_upper_case_globals)] pub static g15_j514c_bringup: Parameter = Parameter; pub struct Parameter; @@ -313,7 +320,7 @@ def c_source(root): struct AsahiDevice; mod hw { #[derive(Copy, Clone, PartialEq, Eq)] pub enum Platform { AdtWithPmp, DeviceTree } - #[derive(Copy, Clone, PartialEq, Eq)] pub enum Board { None, Templates, Blob } + #[derive(Copy, Clone, PartialEq, Eq)] pub enum Board { None, Templates, DeviceTree(&'static super::board::record::Reference) } } struct Config { chip_id: u32, platform: hw::Platform, machine: &'static str, name: &'static str, firmware: (), board: hw::Board } mod adt { @@ -350,7 +357,7 @@ def c_source(root): ''' RS_MAIN = r''' -static T6031: Config = Config { chip_id: 0x6031, platform: hw::Platform::DeviceTree, machine: "apple,j516c", name: "T6031 G15C", firmware: (), board: hw::Board::Blob }; +static T6031: Config = Config { chip_id: 0x6031, platform: hw::Platform::DeviceTree, machine: "apple,j516c", name: "T6031 G15C", firmware: (), board: hw::Board::DeviceTree(&board::record::J516C) }; static T6030: Config = Config { chip_id: 0x6030, platform: hw::Platform::AdtWithPmp, machine: "apple,t6030", name: "T6030 G15S", firmware: (), board: hw::Board::Templates }; const TAIL: [&str; 6] = ["adt", "identity", "coherent", "board_images", "regs", "hold"]; fn run(cfg: &'static Config, machine: bool, pmp: i32, display: i32) -> (Result<()>, Vec<&'static str>) { @@ -375,7 +382,7 @@ def c_source(root): fn candidate(board: bool, soc: bool, value: u32, display: i32) -> (Result<()>, Vec<&'static str>, u32) { candidate_for(&T6031, board, soc, value, display) } -static T6034: Config = Config { chip_id: 0x6034, platform: hw::Platform::DeviceTree, machine: "apple,j514m", name: "T6034", firmware: (), board: hw::Board::Blob }; +static T6034: Config = Config { chip_id: 0x6034, platform: hw::Platform::DeviceTree, machine: "apple,j514m", name: "T6034", firmware: (), board: hw::Board::DeviceTree(&board::record::J516C) }; fn main() { let (result, calls, _) = candidate_for(&T6034, true, true, 1, 0); assert_eq!(result, Err(ENODEV), "wrong Config cannot inherit this candidate"); @@ -394,6 +401,14 @@ def c_source(root): assert_eq!(result, Ok(())); assert!(calls.ends_with(&TAIL)); assert_eq!(warnings, 1, "candidate must identify its unqualified reference assumptions"); + WARNING_TEXT.with(|w| { + let text = w.borrow(); + for value in ["max_power_mw=116739", "relative_power=[11, 23, 33, 44, 55, 71, 90]", + "fast_die_mask=0x802a002b802a002b", "alarm_mask=0x902a102b802a002b", + "OPP powers are boot-loader stand-ins"] { + assert!(text.contains(value), "warning lacks {}: {}", value, text); + } + }); for code in [-517, -19] { let (result, calls, _) = candidate(true, true, 1, code); assert_eq!(result, Err(Error(code)), "candidate still requires its native display"); @@ -478,10 +493,13 @@ def c_failures(exe): return [s for s in C_SCENARIOS if subprocess.run([str(exe), s], capture_output=True).returncode] -def rs_model(admit, getter): +def rs_model(admit, getter, root): """The prelude and main for this admit(): with the system-sleep hold argument (g15_sleep_hold) or without.""" sleep = "glue::hold_power(dev, sleep_hold);" in admit prefix = RS_PREFIX.replace("@HOLD_POWER@", HOLD_SLEEP if sleep else HOLD_PLAIN).replace("@J514C_GETTER@", getter) + record = (root / "drivers/gpu/drm/asahi/g15/board/record.rs").read_text() + prefix = prefix.replace("@REFERENCE_TYPE@", item(record, "pub(crate) struct Reference {")) + prefix = prefix.replace("@REFERENCE_VALUE@", item(record, "pub(crate) const J516C: Reference = Reference {")) main = RS_MAIN.replace("@SLEEP_HOLD_RUN@", SLEEP_HOLD_RUN if sleep else "").replace("@SLEEP_HOLD_CHECKS@", SLEEP_HOLD_CHECKS if sleep else "") return sleep, prefix, main @@ -528,7 +546,7 @@ def main(): source = c_source(args.root) admit = item((args.root / BOOT).read_text(), "pub(crate) fn admit(") getter = item((args.root / "drivers/gpu/drm/asahi/g15/params.rs").read_text(), "pub(crate) fn j514c_bringup(") - model = rs_model(admit, getter) + model = rs_model(admit, getter, args.root) rs_mutants = dict(RS_MUTANTS, **(SLEEP_HOLD_MUTANTS if model[0] else {})) with tempfile.TemporaryDirectory(prefix="g15-display-order-", dir=os.environ.get("TMPDIR")) as tmp: work = Path(tmp) diff --git a/tools/asahi/g15-j514c-firmware-tests.py b/tools/asahi/g15-j514c-firmware-tests.py index 4b28f58a6e82a..9c3e94451805c 100755 --- a/tools/asahi/g15-j514c-firmware-tests.py +++ b/tools/asahi/g15-j514c-firmware-tests.py @@ -1,50 +1,100 @@ #!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only OR MIT """Exercise production full firmware lookup against the actual T6031 rows. -No firmware image is read. The J514C row is a bring-up candidate, not a hardware pass. +Only public table identities are read, never firmware images. --table allows +integration checks against a table containing another proposed firmware row. """ +import argparse from pathlib import Path -import re,subprocess,tempfile -root=Path(__file__).resolve().parents[2];hw=root/'drivers/gpu/drm/asahi/g15' -source=(hw/'hw/t6031.rs').read_text();rows=[] -for m in re.finditer(r'FirmwareBuild\s*\{(.*?)text_sha256:\s*\[(.*?)\],\s*\}',source,re.S): - body,raw=m.groups();digest=re.findall(r'0x[0-9a-f]+',raw);assert len(digest)==32 - fields={key:re.search(r'\b'+key+r':\s*(0x[0-9a-f]+)',body).group(1) for key in ('text_size','data_size','marker')} - machine=re.search(r'machine:\s*Some\(kernel::c_str!\("([^"]+)"\)\)',body) - rows.append((fields,digest,machine.group(1) if machine else None)) -assert len(rows)==3 and rows[2][2]=='apple,j514c' -measured=[];machines=[] -for f,d,machine in rows: - measured.append('Measured {text_size:'+f['text_size']+',data_size:'+f['data_size']+',marker:'+f['marker']+',sha256:['+','.join(d)+']}') - machines.append('None' if machine is None else 'Some("'+machine+'")') -code='''#[path="MATCHING"] mod matching; +import re +import subprocess +import tempfile + +root = Path(__file__).resolve().parents[2] +hw = root / "drivers/gpu/drm/asahi/g15" +parser = argparse.ArgumentParser(description=__doc__) +parser.add_argument("--table", type=Path, default=hw / "hw/t6031.rs") +args = parser.parse_args() +rows = [] +for match in re.finditer( + r"FirmwareBuild\s*\{(.*?)text_sha256:\s*\[(.*?)\],\s*\}", + args.table.read_text(), re.S): + body, raw = match.groups() + digest = re.findall(r"0x[0-9a-f]+", raw) + assert len(digest) == 32 + fields = { + key: re.search(r"\b" + key + r":\s*(0x[0-9a-f]+)", body).group(1) + for key in ("text_size", "data_size", "marker") + } + machine = re.search(r'machine:\s*Some\(kernel::c_str!\("([^"]+)"\)\)', body) + rows.append((fields, digest, machine.group(1) if machine else None)) +assert sum(machine == "apple,j514c" for _, _, machine in rows) == 1 +assert any(machine in (None, "apple,j516c") for _, _, machine in rows) +measurements = [] +machines = [] +for fields, digest, machine in rows: + measurements.append( + "Measured {text_size:" + fields["text_size"] + ",data_size:" + + fields["data_size"] + ",marker:" + fields["marker"] + + ",sha256:[" + ",".join(digest) + "]}" + ) + machines.append("None" if machine is None else 'Some("' + machine + '")') +code = r'''#[path="MATCHING"] mod matching; #[path="LOOKUP"] mod lookup; -use lookup::{Measured,Verdict}; -fn rows(board:&str)->Vec<(Measured,bool)> { - let measurements=[MEASUREMENTS];let machines:[Option<&str>;3]=[MACHINES]; - measurements.into_iter().zip(machines).map(|(m,b)|(m,b.map_or(true,|b|b==board))).collect() +use lookup::{Measured, Verdict}; +const MACHINES: [Option<&str>; ROW_COUNT] = [BOARD_BINDINGS]; +fn rows(board: &str) -> Vec<(Measured, bool)> { + let measurements = [MEASUREMENTS]; + measurements.into_iter().zip(MACHINES).map(|(m, b)| { + (m, b.map_or(true, |b| b == board)) + }).collect() } -#[test] fn j514c_exact_candidate() { - let exact=rows("apple,j514c")[2].0; - assert_eq!(lookup::verdict(&exact,rows("apple,j514c"),0),Verdict::Pinned(2)); - for board in ["apple,j516c","apple,j514m","apple,j516m"] { - assert_eq!(lookup::verdict(&exact,rows(board),0),Verdict::Refused); - } - let mut bad=exact;bad.sha256[31]^=1; - assert_eq!(lookup::verdict(&bad,rows("apple,j514c"),0),Verdict::Refused); - let mut bad=exact;bad.text_size+=0x4000; - assert_eq!(lookup::verdict(&bad,rows("apple,j514c"),0),Verdict::Refused); - let mut bad=exact;bad.data_size+=0x4000; - assert_eq!(lookup::verdict(&bad,rows("apple,j514c"),0),Verdict::Refused); - let mut bad=exact;bad.marker+=8; - assert_eq!(lookup::verdict(&bad,rows("apple,j514c"),0),Verdict::Refused); +#[test] +fn j514c_exact_candidate() { + let index = MACHINES.iter().position(|b| *b == Some("apple,j514c")).unwrap(); + let exact = rows("apple,j514c")[index].0; + assert_eq!(lookup::verdict(&exact, rows("apple,j514c"), 0), Verdict::Pinned(index)); + for board in ["apple,j516c", "apple,j514m", "apple,j516m"] { + assert_eq!(lookup::verdict(&exact, rows(board), 0), Verdict::Refused); + } + let mut bad = exact; bad.sha256[31] ^= 1; + assert_eq!(lookup::verdict(&bad, rows("apple,j514c"), 0), Verdict::Refused); + let mut bad = exact; bad.text_size += 0x4000; + assert_eq!(lookup::verdict(&bad, rows("apple,j514c"), 0), Verdict::Refused); + let mut bad = exact; bad.data_size += 0x4000; + assert_eq!(lookup::verdict(&bad, rows("apple,j514c"), 0), Verdict::Refused); + let mut bad = exact; bad.marker += 8; + assert_eq!(lookup::verdict(&bad, rows("apple,j514c"), 0), Verdict::Refused); } -#[test] fn existing_rows_unchanged() { - for i in 0..2 {let m=rows("apple,j516c")[i].0; - assert_eq!(lookup::verdict(&m,rows("apple,j516c"),0),Verdict::Pinned(i));} +#[test] +fn existing_rows_unchanged() { + for (index, board) in MACHINES.into_iter().enumerate() { + if board.is_none() || board == Some("apple,j516c") { + let measured = rows("apple,j516c")[index].0; + assert_eq!(lookup::verdict(&measured, rows("apple,j516c"), 0), Verdict::Pinned(index)); + if board.is_some() { + for other in ["apple,j514c", "apple,j514m", "apple,j516m"] { + assert_eq!(lookup::verdict(&measured, rows(other), 0), Verdict::Refused); + } + } + } + } } -'''.replace('MATCHING',str(hw/'identity/matching.rs')).replace('LOOKUP',str(hw/'identity/lookup.rs')).replace('MEASUREMENTS',','.join(measured)).replace('MACHINES',','.join(machines)) -with tempfile.TemporaryDirectory(prefix='g15-fw-') as td: - p=Path(td);(p/'test.rs').write_text(code) - subprocess.run(['rustc','--edition=2021','--test',str(p/'test.rs'),'-o',str(p/'test')],check=True) - subprocess.run([str(p/'test')],check=True) +''' +for token, replacement in { + "MATCHING": str(hw / "identity/matching.rs"), + "LOOKUP": str(hw / "identity/lookup.rs"), + "ROW_COUNT": str(len(rows)), + "MEASUREMENTS": ",".join(measurements), + "BOARD_BINDINGS": ",".join(machines), +}.items(): + code = code.replace(token, replacement) +with tempfile.TemporaryDirectory(prefix="g15-fw-") as directory: + path = Path(directory) + (path / "test.rs").write_text(code) + subprocess.run([ + "rustc", "--edition=2021", "--test", str(path / "test.rs"), + "-o", str(path / "test"), + ], check=True) + subprocess.run([str(path / "test")], check=True) From 9b81cd999040dedcc051bc3799918afe2187f029 Mon Sep 17 00:00:00 2001 From: Chris Kearney <303316+chriskearney@users.noreply.github.com> Date: Thu, 5 Nov 2026 06:57:06 -0800 Subject: [PATCH 21/47] drm/asahi: start J514C graphics on normal boots A supported J514C boot must reach native graphics without an extra kernel enable parameter. Admit its exact board and T6031 compatible on the existing DeviceTree path and remove g15_j514c_bringup entirely. Native display publication, the full board-scoped firmware digest, segment shape, hardware identity/core masks, cold-start and record checks still apply. T6034 and other boards do not inherit this path. Keep the explicit diagnostic of the inherited reference power words; automatic startup does not establish power/thermal qualification. Run the production admission harness with no parameter model. Its normal J514C path passes, wrong board/SoC/config and native display failure controls refuse, and compiled mutants catch gate bypasses. The exact firmware suite passes all 14 tests. Assisted-by: Codex:GPT-6 Signed-off-by: Scott Jones --- drivers/gpu/drm/asahi/asahi_core.rs | 4 --- drivers/gpu/drm/asahi/g15/boot.rs | 11 +++--- drivers/gpu/drm/asahi/g15/hw/t6031.rs | 2 +- drivers/gpu/drm/asahi/g15/params.rs | 6 ---- tools/asahi/g15-display-order-tests.py | 48 ++++++++++---------------- 5 files changed, 24 insertions(+), 47 deletions(-) diff --git a/drivers/gpu/drm/asahi/asahi_core.rs b/drivers/gpu/drm/asahi/asahi_core.rs index b5e42cf16aa9f..bd69152c3ce75 100644 --- a/drivers/gpu/drm/asahi/asahi_core.rs +++ b/drivers/gpu/drm/asahi/asahi_core.rs @@ -236,10 +236,6 @@ module! { default: 0, description: "G15: admit an unpinned GPU firmware build whose TEXT SHA-256 starts with these 8 bytes (bring-up only)", }, - g15_j514c_bringup: u32 { - default: 0, - description: "G15: opt into J514C/T6031 bring-up with the J516C reference power/thermal words (1 only; unqualified on J514C)", - }, stats_export: u8 { default: 1, // permissions: 0, diff --git a/drivers/gpu/drm/asahi/g15/boot.rs b/drivers/gpu/drm/asahi/g15/boot.rs index d43d1f5f36777..e0d6ef6b347e5 100644 --- a/drivers/gpu/drm/asahi/g15/boot.rs +++ b/drivers/gpu/drm/asahi/g15/boot.rs @@ -461,14 +461,13 @@ pub(crate) fn admit( ) -> Result { let dev = pdev.as_ref(); let pmp = cfg.platform == hw::Platform::AdtWithPmp; - // Experimental same-die candidate, not a qualification of the J516C - // reference words for the 14-inch chassis. Keep exact board AND SoC checks; + // J514C uses the same-die T6031 path on a normal boot. This does not qualify + // the inherited J516C reference words. Keep exact board AND SoC checks; // T6034 boards must never inherit this four-cluster T6031 configuration. // The remaining display, DT/ADT, full firmware identity, hardware identity // and record-builder admission below is unchanged. - let j514c_candidate = cfg.chip_id == 0x6031 + let j514c_board = cfg.chip_id == 0x6031 && cfg.platform == hw::Platform::DeviceTree - && params::j514c_bringup() && glue::machine(kernel::c_str!("apple,j514c")) && glue::machine(kernel::c_str!("apple,t6031")); if pmp { @@ -485,7 +484,7 @@ pub(crate) fn admit( } return Err(err); } - } else if !glue::machine(cfg.machine) && !j514c_candidate { + } else if !glue::machine(cfg.machine) && !j514c_board { dev_err!(dev, "G15: not a {} machine\n", cfg.name); return Err(ENODEV); } else { @@ -500,7 +499,7 @@ pub(crate) fn admit( return Err(err); } } - if j514c_candidate { + if j514c_board { if let hw::Board::DeviceTree(reference) = cfg.board { dev_warn!( dev, diff --git a/drivers/gpu/drm/asahi/g15/hw/t6031.rs b/drivers/gpu/drm/asahi/g15/hw/t6031.rs index 479dc270b1e83..db24b9bff56ce 100644 --- a/drivers/gpu/drm/asahi/g15/hw/t6031.rs +++ b/drivers/gpu/drm/asahi/g15/hw/t6031.rs @@ -163,7 +163,7 @@ pub(crate) const CONFIG: Config = Config { }, // Measured by the normal driver on J514C's 14.7 boot chain (system // firmware 26.5.2). Short native GL/Vulkan and normal-login checks passed; - // power/thermal qualification remains open. Explicit bring-up opt-in only. + // power/thermal qualification remains open. Exact board identity is required. FirmwareBuild { name: "J514C macOS 14.7 boot-chain firmware (experimental bring-up)", machine: Some(kernel::c_str!("apple,j514c")), diff --git a/drivers/gpu/drm/asahi/g15/params.rs b/drivers/gpu/drm/asahi/g15/params.rs index 74d18cf4ed480..c2c3486475061 100644 --- a/drivers/gpu/drm/asahi/g15/params.rs +++ b/drivers/gpu/drm/asahi/g15/params.rs @@ -87,12 +87,6 @@ pub(crate) fn accept_text_prefix() -> u64 { module_parameters::g15_accept_text_prefix.value() } -/// Opt into the J514C candidate only at exactly 1. The default keeps the -/// qualified J516C-only board admission. This does not override firmware identity. -pub(crate) fn j514c_bringup() -> bool { - *module_parameters::g15_j514c_bringup.value() == 1 -} - /// The parameter for the PB growth maximum the firmware is given, in blocks, clamped to /// 64..=4095. [`super::pools::Pools::soft_max`] raises it to at least the initial posting; the /// blocks above it, up to the 4095 posted at most, answer the synchronous requests of partial diff --git a/tools/asahi/g15-display-order-tests.py b/tools/asahi/g15-display-order-tests.py index 1c3658ffff753..7d874f1a6a766 100644 --- a/tools/asahi/g15-display-order-tests.py +++ b/tools/asahi/g15-display-order-tests.py @@ -282,10 +282,10 @@ def c_source(root): macro_rules! dev_err { ($($args:tt)*) => {{}}; } macro_rules! dev_info { ($($args:tt)*) => {{}}; } macro_rules! dev_warn { ($dev:expr, $($args:tt)*) => {{ warned(format!($($args)*)); }}; } -struct State { board: bool, machine: bool, pmp: i32, display: i32, sleep_hold: bool, asc_fail: bool, j514c: bool, t6031: bool, bringup: u32 } +struct State { board: bool, machine: bool, pmp: i32, display: i32, sleep_hold: bool, asc_fail: bool, j514c: bool, t6031: bool } thread_local! { static CALLS: RefCell> = const { RefCell::new(Vec::new()) }; - static STATE: RefCell = const { RefCell::new(State { board: true, machine: true, pmp: 0, display: 0, sleep_hold: true, asc_fail: false, j514c: false, t6031: false, bringup: 0 }) }; + static STATE: RefCell = const { RefCell::new(State { board: true, machine: true, pmp: 0, display: 0, sleep_hold: true, asc_fail: false, j514c: false, t6031: false }) }; static HOLD: RefCell> = const { RefCell::new(None) }; static WARNINGS: RefCell = const { RefCell::new(0) }; static WARNING_TEXT: RefCell = const { RefCell::new(String::new()) }; @@ -297,14 +297,7 @@ def c_source(root): @REFERENCE_TYPE@ @REFERENCE_VALUE@; } } -mod module_parameters { - #[allow(non_upper_case_globals)] pub static g15_j514c_bringup: Parameter = Parameter; - pub struct Parameter; - impl Parameter { pub fn value(&self) -> Box { Box::new(super::STATE.with(|s| s.borrow().bringup)) } } -} mod params { - use super::module_parameters; - @J514C_GETTER@ pub fn sleep_hold() -> bool { super::STATE.with(|s| s.borrow().sleep_hold) } } fn call(name: &'static str) { CALLS.with(|c| c.borrow_mut().push(name)); } @@ -347,7 +340,7 @@ def c_source(root): mod glue { use super::{call, STATE}; pub fn board() -> bool { call("board"); STATE.with(|s| s.borrow().board) } - pub fn machine(name: &str) -> bool { call("machine"); STATE.with(|s| { let s=s.borrow(); match name { "apple,j514c" => s.j514c, "apple,t6031" => s.t6031, _ => s.machine } }) } + pub fn machine(name: &str) -> bool { if name != "apple,j514c" && name != "apple,t6031" { call("machine"); } STATE.with(|s| { let s=s.borrow(); match name { "apple,j514c" => s.j514c, "apple,t6031" => s.t6031, _ => s.machine } }) } pub unsafe fn asahi_g15_pmp_prepare(_: *mut core::ffi::c_void) -> core::ffi::c_int { call("pmp"); STATE.with(|s| s.borrow().pmp) } pub unsafe fn asahi_g15_display_prepare(_: *mut core::ffi::c_void) -> core::ffi::c_int { call("display"); STATE.with(|s| s.borrow().display) } pub fn dma_coherent(_: &super::device::Device) -> bool { call("coherent"); false } @@ -362,7 +355,7 @@ def c_source(root): const TAIL: [&str; 6] = ["adt", "identity", "coherent", "board_images", "regs", "hold"]; fn run(cfg: &'static Config, machine: bool, pmp: i32, display: i32) -> (Result<()>, Vec<&'static str>) { CALLS.with(|c| c.borrow_mut().clear()); - STATE.with(|s| *s.borrow_mut() = State { board: true, machine, pmp, display, sleep_hold: true, asc_fail: false, j514c: false, t6031: false, bringup: 0 }); + STATE.with(|s| *s.borrow_mut() = State { board: true, machine, pmp, display, sleep_hold: true, asc_fail: false, j514c: false, t6031: false }); HOLD.with(|h| *h.borrow_mut() = None); WARNINGS.with(|w| *w.borrow_mut() = 0); let pdev = platform::Device(device::Device, Core(PhantomData)); @@ -371,33 +364,28 @@ def c_source(root): } fn with_tail(head: &[&'static str]) -> Vec<&'static str> { head.iter().chain(TAIL.iter()).copied().collect() } @SLEEP_HOLD_RUN@ -fn candidate_for(cfg: &'static Config, board: bool, soc: bool, value: u32, display: i32) -> (Result<()>, Vec<&'static str>, u32) { +fn candidate_for(cfg: &'static Config, board: bool, soc: bool, display: i32) -> (Result<()>, Vec<&'static str>, u32) { CALLS.with(|c| c.borrow_mut().clear()); - STATE.with(|s| *s.borrow_mut() = State { board: true, machine: false, pmp: 0, display, sleep_hold: true, asc_fail: false, j514c: board, t6031: soc, bringup: value }); + STATE.with(|s| *s.borrow_mut() = State { board: true, machine: false, pmp: 0, display, sleep_hold: true, asc_fail: false, j514c: board, t6031: soc }); WARNINGS.with(|w| *w.borrow_mut() = 0); let pdev = platform::Device(device::Device, Core(PhantomData)); let result = admit(&pdev, &AsahiDevice, cfg).map(|_| ()); (result, CALLS.with(|c| c.borrow().clone()), WARNINGS.with(|w| *w.borrow())) } -fn candidate(board: bool, soc: bool, value: u32, display: i32) -> (Result<()>, Vec<&'static str>, u32) { - candidate_for(&T6031, board, soc, value, display) +fn candidate(board: bool, soc: bool, display: i32) -> (Result<()>, Vec<&'static str>, u32) { + candidate_for(&T6031, board, soc, display) } static T6034: Config = Config { chip_id: 0x6034, platform: hw::Platform::DeviceTree, machine: "apple,j514m", name: "T6034", firmware: (), board: hw::Board::DeviceTree(&board::record::J516C) }; fn main() { - let (result, calls, _) = candidate_for(&T6034, true, true, 1, 0); + let (result, calls, _) = candidate_for(&T6034, true, true, 0); assert_eq!(result, Err(ENODEV), "wrong Config cannot inherit this candidate"); assert!(!calls.contains(&"display") && !calls.contains(&"adt")); - for value in [0, 2, u32::MAX] { - let (result, calls, _) = candidate(true, true, value, 0); - assert_eq!(result, Err(ENODEV), "J514C requires exactly 1"); - assert!(!calls.contains(&"display") && !calls.contains(&"adt")); - } for (board, soc) in [(false, true), (true, false), (false, false)] { - let (result, calls, _) = candidate(board, soc, 1, 0); + let (result, calls, _) = candidate(board, soc, 0); assert_eq!(result, Err(ENODEV), "wrong board or SoC must not inherit T6031"); assert!(!calls.contains(&"display") && !calls.contains(&"adt")); } - let (result, calls, warnings) = candidate(true, true, 1, 0); + let (result, calls, warnings) = candidate(true, true, 0); assert_eq!(result, Ok(())); assert!(calls.ends_with(&TAIL)); assert_eq!(warnings, 1, "candidate must identify its unqualified reference assumptions"); @@ -410,7 +398,7 @@ def c_source(root): } }); for code in [-517, -19] { - let (result, calls, _) = candidate(true, true, 1, code); + let (result, calls, _) = candidate(true, true, code); assert_eq!(result, Err(Error(code)), "candidate still requires its native display"); assert!(!calls.contains(&"adt") && !calls.contains(&"hold")); } @@ -430,7 +418,7 @@ def c_source(root): SLEEP_HOLD_RUN = r''' fn run_hold(cfg: &'static Config, sleep_hold: bool, asc_fail: bool) -> (Result<()>, Vec<&'static str>, Option, u32) { CALLS.with(|c| c.borrow_mut().clear()); - STATE.with(|s| *s.borrow_mut() = State { board: true, machine: true, pmp: 0, display: 0, sleep_hold, asc_fail, j514c: false, t6031: false, bringup: 0 }); + STATE.with(|s| *s.borrow_mut() = State { board: true, machine: true, pmp: 0, display: 0, sleep_hold, asc_fail, j514c: false, t6031: false }); HOLD.with(|h| *h.borrow_mut() = None); WARNINGS.with(|w| *w.borrow_mut() = 0); let pdev = platform::Device(device::Device, Core(PhantomData)); @@ -458,7 +446,6 @@ def c_source(root): RS_MUTANTS = { "candidate-ignores-config-chip": ("cfg.chip_id == 0x6031", "true"), - "candidate-ignores-opt-in": ("&& params::j514c_bringup()", "&& true"), "candidate-ignores-board": ('&& glue::machine(kernel::c_str!("apple,j514c"))', "&& true"), "candidate-ignores-soc": ('&& glue::machine(kernel::c_str!("apple,t6031"))', "&& true"), "display-refusal-ignored": ("dev_err!(dev, \"native display not admitted: {:?}\\n\", err);\n }\n return Err(err);", @@ -493,10 +480,10 @@ def c_failures(exe): return [s for s in C_SCENARIOS if subprocess.run([str(exe), s], capture_output=True).returncode] -def rs_model(admit, getter, root): +def rs_model(admit, root): """The prelude and main for this admit(): with the system-sleep hold argument (g15_sleep_hold) or without.""" sleep = "glue::hold_power(dev, sleep_hold);" in admit - prefix = RS_PREFIX.replace("@HOLD_POWER@", HOLD_SLEEP if sleep else HOLD_PLAIN).replace("@J514C_GETTER@", getter) + prefix = RS_PREFIX.replace("@HOLD_POWER@", HOLD_SLEEP if sleep else HOLD_PLAIN) record = (root / "drivers/gpu/drm/asahi/g15/board/record.rs").read_text() prefix = prefix.replace("@REFERENCE_TYPE@", item(record, "pub(crate) struct Reference {")) prefix = prefix.replace("@REFERENCE_VALUE@", item(record, "pub(crate) const J516C: Reference = Reference {")) @@ -543,10 +530,11 @@ def main(): args = parser.parse_args() rustcs = args.rustc or ["rustc"] checks = static_checks(args.root) + for path in ("drivers/gpu/drm/asahi/asahi_core.rs", "drivers/gpu/drm/asahi/g15/params.rs"): + assert "g15_j514c_bringup" not in (args.root / path).read_text(), "normal boot must not require an enable flag" source = c_source(args.root) admit = item((args.root / BOOT).read_text(), "pub(crate) fn admit(") - getter = item((args.root / "drivers/gpu/drm/asahi/g15/params.rs").read_text(), "pub(crate) fn j514c_bringup(") - model = rs_model(admit, getter, args.root) + model = rs_model(admit, args.root) rs_mutants = dict(RS_MUTANTS, **(SLEEP_HOLD_MUTANTS if model[0] else {})) with tempfile.TemporaryDirectory(prefix="g15-display-order-", dir=os.environ.get("TMPDIR")) as tmp: work = Path(tmp) From 08a72f3d92cbe67c022cab1f5a184b841ede63cc Mon Sep 17 00:00:00 2001 From: Chris Kearney <303316+chriskearney@users.noreply.github.com> Date: Thu, 5 Nov 2026 07:13:33 -0800 Subject: [PATCH 22/47] drm/asahi: describe normal J514C profile admission Remove the obsolete enable-parameter description from the T6031 hardware profile. J514C now follows normal board, firmware and hardware admission on boot; the inherited power and thermal qualification limits remain explicit. Assisted-by: Codex:GPT-6 Signed-off-by: Scott Jones --- drivers/gpu/drm/asahi/g15/hw/t6031.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/asahi/g15/hw/t6031.rs b/drivers/gpu/drm/asahi/g15/hw/t6031.rs index db24b9bff56ce..46b31ab36890e 100644 --- a/drivers/gpu/drm/asahi/g15/hw/t6031.rs +++ b/drivers/gpu/drm/asahi/g15/hw/t6031.rs @@ -2,8 +2,8 @@ //! T6031 (M3 Max, G15C) configuration, qualified on J516C only. //! -//! J514C may explicitly opt into a bring-up candidate using these reference -//! words with `g15_j514c_bringup=1`. This is not J514C power/thermal qualification. +//! J514C uses these reference words on normal boots after its board, firmware, +//! and hardware checks pass. This is not J514C power/thermal qualification. //! //! One die, four clusters of ten core slots. The firmware is the same RTKit 2419 generation as //! the T6030's and the initdata graph keeps the T6030 canonical VAs; what differs is the SoC From 2a0e626fee5b896971d416aae0c2bf6b1d7b8f57 Mon Sep 17 00:00:00 2001 From: Chris Kearney <303316+chriskearney@users.noreply.github.com> Date: Thu, 5 Nov 2026 07:26:19 -0800 Subject: [PATCH 23/47] soc: apple: default J514C native display on normal boots Admit the exact J514C and T6031 pair in the native-display default selector, alongside J516C. An explicit display disable still wins. Keep all loader handoff, PMP and display publication checks before G15 firmware startup. Update the device-tree and wait diagnostics so they no longer describe an enable flag as required on J514C. The production selector and request helper pass host tests for both supported boards, wrong SoCs and boards, and explicit owner choices. Mutants that remove J514C, drop the SoC check or lose the disable choice are rejected. Assisted-by: Codex:GPT-6 Signed-off-by: Scott Jones --- drivers/gpu/drm/asahi/g15/glue.c | 2 +- drivers/pmdomain/apple/pmp-report.c | 2 +- drivers/soc/apple/Kconfig | 2 +- drivers/soc/apple/display-gate-test.c | 45 +++++++++++----- drivers/soc/apple/display-gate.c | 39 +++++++++++--- .../asahi/g15-j514c-display-default-tests.py | 52 +++++++++++++++++++ 6 files changed, 117 insertions(+), 25 deletions(-) create mode 100644 tools/asahi/g15-j514c-display-default-tests.py diff --git a/drivers/gpu/drm/asahi/g15/glue.c b/drivers/gpu/drm/asahi/g15/glue.c index a12a5e6fa2fe7..d224385d49b73 100644 --- a/drivers/gpu/drm/asahi/g15/glue.c +++ b/drivers/gpu/drm/asahi/g15/glue.c @@ -161,7 +161,7 @@ int asahi_g15_display_prepare(struct device *dev) return ret; np = of_find_compatible_node(NULL, NULL, "apple,t6031-display-subsystem"); if (!np || !of_device_is_available(np)) - dev_info_once(dev, "G15: waiting for the T6031 native display, which this boot did not enable (it needs the boot loader's display handoff, and apple_t6031_display.enable=1 except on the J516C)\n"); + dev_info_once(dev, "G15: waiting for the T6031 native display, which this boot did not enable (it needs the boot loader's display handoff, and an admitted native-display board)\n"); else dev_info_once(dev, "G15: waiting for the T6031 native display to come up: the GPU firmware starts only after the display is published\n"); of_node_put(np); diff --git a/drivers/pmdomain/apple/pmp-report.c b/drivers/pmdomain/apple/pmp-report.c index b375a83b9e0a2..979b2161abf85 100644 --- a/drivers/pmdomain/apple/pmp-report.c +++ b/drivers/pmdomain/apple/pmp-report.c @@ -2555,7 +2555,7 @@ static const struct apple_pmp_report_offsets apple_pmp_offsets_t6031 = { .status = 0x10, .starts_pmp = true, .name = "T6031", - .fallback = "leave out apple_t6031_display.enable=1", + .fallback = "apple_t6031_display.enable=0", .pwrstate = "apple,t6031-pmgr-pwrstate", .devices_ordered = true, }; diff --git a/drivers/soc/apple/Kconfig b/drivers/soc/apple/Kconfig index 3f6db5ef17ad8..50fb493139312 100644 --- a/drivers/soc/apple/Kconfig +++ b/drivers/soc/apple/Kconfig @@ -393,7 +393,7 @@ config APPLE_DISPLAY_GATE_KUNIT_TEST help Runs the display gate on test device trees with the T6030, T6031 and T8122 display nodes, without Apple hardware. On T6031: on by - default only on the default board (the J516C), otherwise only with + default only on J514C and J516C, otherwise only with apple_t6031_display.enable=1, off with apple_t6031_display.enable=0, only with the boot loader's handoff marker and this Mac's PMP values, and with nothing changed when a check fails. On T6030: on by default, as diff --git a/drivers/soc/apple/display-gate-test.c b/drivers/soc/apple/display-gate-test.c index 3b0b162ed6799..75fc70ffb3111 100644 --- a/drivers/soc/apple/display-gate-test.c +++ b/drivers/soc/apple/display-gate-test.c @@ -8,8 +8,8 @@ * the T6031 switch does not change it. Run first: the T6031 and T8122 * trees describe a PMP, and the T6030 gate refuses to add a second one. * - T6031 (t6031-gate-test.dtso): on by default only on the default board - * (the J516C; the cases point it at the test tree's own root to run that - * path), otherwise only with apple_t6031_display.enable=1, never with + * (J514C or J516C; the cases supply a synthetic root identity), + * otherwise only with apple_t6031_display.enable=1, never with * apple_t6031_display.enable=0; always with the full handoff, and nothing * changed when a check fails. * - T8122 (t8122-gate-test.dtso): on by default, with the full handoff, @@ -157,7 +157,7 @@ struct gate_test { struct of_changeset cs; /* this case's own edits to the test tree */ bool requested, t6031_requested; int t6031_switch; - const char *t6031_board; + const char *default_board; }; static struct device_node *__init gt_node(struct kunit *test, const char *path) @@ -396,6 +396,16 @@ static int __init gt_suite_init_t8122(struct kunit_suite *suite) return gt_apply_fixture(>_t8122, >_fixture_t8122); } +/* Static-stub resources are task-scoped and removed by KUnit case cleanup. */ +static bool __init gt_root_is_compatible(const char *compat) +{ + struct kunit *test = kunit_get_current_test(); + struct gate_test *t = test->priv; + + return t->default_board && + (!strcmp(compat, "apple,t6031") || !strcmp(compat, t->default_board)); +} + static int __init gt_init(struct kunit *test, const struct gt_soc *s) { struct gate_test *t = kunit_kzalloc(test, sizeof(*t), GFP_KERNEL); @@ -408,7 +418,6 @@ static int __init gt_init(struct kunit *test, const struct gt_soc *s) t->requested = gate_requested; t->t6031_requested = gate_t6031_requested; t->t6031_switch = gate_t6031_switch; - t->t6031_board = gate_t6031_board; of_changeset_init(&t->cs); gate_soc = s->soc; gate_pmp_values = NULL; @@ -419,6 +428,7 @@ static int __init gt_init(struct kunit *test, const struct gt_soc *s) gate_t6031_switch = -1; if (gt_live_soc) kunit_skip(test, "the booted device tree has its own /soc"); + kunit_activate_static_stub(test, gate_t6031_is_compatible, gt_root_is_compatible); return 0; } @@ -463,7 +473,6 @@ static void __init gt_exit(struct kunit *test) gate_requested = t->requested; gate_t6031_requested = t->t6031_requested; gate_t6031_switch = t->t6031_switch; - gate_t6031_board = t->t6031_board; gate_soc = NULL; } @@ -476,7 +485,7 @@ static void __init gate_t6031_param(struct kunit *test) KUNIT_EXPECT_FALSE(test, t->t6031_requested); KUNIT_EXPECT_EQ(test, t->t6031_switch, -1); - KUNIT_EXPECT_STREQ(test, t->t6031_board, "apple,j516c"); + KUNIT_EXPECT_NULL(test, gate_t6031_default_board()); KUNIT_EXPECT_TRUE(test, t->requested); KUNIT_EXPECT_EQ(test, gate_setup_t6031("1"), 0); @@ -514,14 +523,19 @@ static void __init gate_t6031_resolution(struct kunit *test) KUNIT_EXPECT_TRUE(test, gate_t6031_wanted(1, false)); } -/* Points the default board at the test tree's root, so gate_run() takes that path. */ +static const char * const gt_default_boards[] = { + "apple,j514c", + "apple,j516c", +}; +KUNIT_ARRAY_PARAM(gt_default_board, gt_default_boards, NULL); + +/* Exercise the real selector and gate_run(), with a test-scoped identity. */ static void __init gt_default_board(struct kunit *test) { - const char *root = NULL; + struct gate_test *t = test->priv; - if (of_property_read_string(of_root, "compatible", &root) || !root) - kunit_skip(test, "the test tree's root has no compatible"); - gate_t6031_board = root; + t->default_board = *(const char * const *)test->param_value; + KUNIT_ASSERT_STREQ(test, gate_t6031_default_board(), t->default_board); } /* On the default board, the full handoff and no switch: enabled. */ @@ -529,6 +543,7 @@ static void __init gate_t6031_default_board_on(struct kunit *test) { gt_default_board(test); gt_run(test); + KUNIT_EXPECT_TRUE(test, gate_t6031_requested); gt_expect_enabled(test); } @@ -538,6 +553,7 @@ static void __init gate_t6031_default_board_switched_off(struct kunit *test) gt_default_board(test); KUNIT_ASSERT_EQ(test, gate_setup_t6031("0"), 0); gt_run(test); + KUNIT_EXPECT_FALSE(test, gate_t6031_requested); gt_expect_untouched(test); } @@ -547,6 +563,7 @@ static void __init gate_t6031_default_board_no_marker(struct kunit *test) gt_default_board(test); gt_remove(test, gt_t6031.dcp, "apple,t6031-handoff"); gt_run(test); + KUNIT_EXPECT_TRUE(test, gate_t6031_requested); gt_expect_untouched(test); } @@ -901,9 +918,9 @@ static struct kunit_case gate_t6031_cases[] __refdata = { KUNIT_CASE(gate_t6031_param), KUNIT_CASE(gate_t6031_resolution), KUNIT_CASE(gate_t6031_off_by_default), - KUNIT_CASE(gate_t6031_default_board_on), - KUNIT_CASE(gate_t6031_default_board_switched_off), - KUNIT_CASE(gate_t6031_default_board_no_marker), + KUNIT_CASE_PARAM(gate_t6031_default_board_on, gt_default_board_gen_params), + KUNIT_CASE_PARAM(gate_t6031_default_board_switched_off, gt_default_board_gen_params), + KUNIT_CASE_PARAM(gate_t6031_default_board_no_marker, gt_default_board_gen_params), KUNIT_CASE(gate_t6031_switched_off), KUNIT_CASE(gate_t6031_enabled), KUNIT_CASE(gate_t6031_no_dcp_marker), diff --git a/drivers/soc/apple/display-gate.c b/drivers/soc/apple/display-gate.c index 03db5ed73e343..87790b4e204ef 100644 --- a/drivers/soc/apple/display-gate.c +++ b/drivers/soc/apple/display-gate.c @@ -53,8 +53,8 @@ * option. * * On T6031 (M3 Max) the gate serves the same handoff, marked - * apple,t6031-handoff. Its default is scoped to the J516C: there the native - * display is on unless apple_t6031_display.enable=0; the other T6031 boards + * apple,t6031-handoff. Its default is scoped to J514C and J516C: there the native + * display is on unless apple_t6031_display.enable=0; other T6031 boards * need apple_t6031_display.enable=1. The T6031 GPU starts its firmware only * after this native display is up, so enable=0 (or a display that never * comes up) keeps the GPU off for that boot too: it is not a display-only @@ -115,6 +115,10 @@ #include #include