From 5fbbff263a800227f30e14f2178a0af4bcd65fc5 Mon Sep 17 00:00:00 2001 From: Sean Dolbec Date: Thu, 12 Nov 2026 13:51:52 -0500 Subject: [PATCH 1/7] drm/asahi: g16: Accept the J773g loaded 25G83 image J773g loads a distinct normalized 25G83 image after iBoot fills a header word at 0x224 and the eight-byte DILS payload at 0x5c917. Add those per-boot regions and the measured digest so firmware admission recognizes that image. The same identity was boot-tested on a J773g with 25G83: GPU firmware started and accelerated rendering worked. Cover the new table entry with the existing measured-image lookup tests. Signed-off-by: Sean Dolbec --- drivers/gpu/drm/asahi/fwid.rs | 15 +++++++++++++++ drivers/gpu/drm/asahi/g16/hw.rs | 17 ++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/asahi/fwid.rs b/drivers/gpu/drm/asahi/fwid.rs index c7d2e84797cfb..c7b362a4e016c 100644 --- a/drivers/gpu/drm/asahi/fwid.rs +++ b/drivers/gpu/drm/asahi/fwid.rs @@ -545,6 +545,21 @@ mod tests { assert!(measured(builds, 0x13c000, &[[0x5c8df, 0x5c9c2]], [0; 32]).is_none()); } + #[cfg(CONFIG_DRM_ASAHI_G16)] + #[test] + fn j773g_accepts_its_loaded_image() { + let builds = crate::g16::hw::t8132::CONFIG.firmware; + let digest = [ + 0x91, 0x54, 0xc7, 0xf8, 0x4b, 0xce, 0x32, 0x15, 0x1e, 0x8a, 0x97, 0x41, 0x7d, 0x6a, + 0x20, 0x7a, 0x9e, 0xaf, 0x03, 0x54, 0xb4, 0xb8, 0xd6, 0xf0, 0x2a, 0xf5, 0x29, 0x95, + 0x40, 0xd3, 0xe8, 0x5a, + ]; + let found = measured(builds, 0x13c000, &[[0x5c8df, 0x5c9c2]], digest).unwrap(); + assert_eq!(found.name, "Apple GFX 25G83 (normalized loaded image, J773g)"); + assert_eq!(found.boot_filled, &[(0x224, 4), (0x5c917, 8)]); + assert!(measured(builds, 0x138000, &[[0x5c8df, 0x5c9c2]], digest).is_none()); + } + #[test] fn t6050_admits_only_its_pinned_image() { for cfg in [ diff --git a/drivers/gpu/drm/asahi/g16/hw.rs b/drivers/gpu/drm/asahi/g16/hw.rs index 353199dea75a1..b66afcc3cdd83 100644 --- a/drivers/gpu/drm/asahi/g16/hw.rs +++ b/drivers/gpu/drm/asahi/g16/hw.rs @@ -20,7 +20,7 @@ pub(crate) struct HwId { pub(crate) use crate::fwid::FirmwareBuild; -/// The J713/T8132 configuration. Hardware admission also checks the exact TEXT image. +/// The J713/J773g T8132 configuration. Hardware admission also checks the exact TEXT image. pub(crate) mod t8132 { use super::super::Config; use super::{FirmwareBuild, HwId}; @@ -79,6 +79,21 @@ pub(crate) mod t8132 { 0xc8, 0x29, 0x86, 0x8b, 0xc9, 0xcf, ], }, + FirmwareBuild { + // The 25G83 image as loaded by iBoot on a J773g (Mac mini). iBoot rewrites + // the header word at 0x224 and the 8-byte DILS payload at 0x5c917 on every + // boot there; they are zeroed before hashing. + name: "Apple GFX 25G83 (normalized loaded image, J773g)", + text_size: 0x60000, + data_size: 0x13c000, + entropy: &[[0x5c8df, 0x5c9c2]], + boot_filled: &[(0x224, 4), (0x5c917, 8)], + text_sha256: [ + 0x91, 0x54, 0xc7, 0xf8, 0x4b, 0xce, 0x32, 0x15, 0x1e, 0x8a, 0x97, 0x41, 0x7d, + 0x6a, 0x20, 0x7a, 0x9e, 0xaf, 0x03, 0x54, 0xb4, 0xb8, 0xd6, 0xf0, 0x2a, 0xf5, + 0x29, 0x95, 0x40, 0xd3, 0xe8, 0x5a, + ], + }, ], }; } From 7edecc5ef1a22bbe08da8c251360a99aae30581d Mon Sep 17 00:00:00 2001 From: Sean Dolbec Date: Wed, 4 Nov 2026 14:50:53 -0500 Subject: [PATCH 2/7] soc: apple: pmp: Name the retained T8132 firmware predicate The existing telemetry predicate already selects firmware-qualified T8132, including J773g, for endpoint 7. Name that condition for reuse by the PMP and GPU paths; this is a refactoring, not a change in admission. The misleading J713-only comments are corrected. A prior J773g bring-up stack required endpoint 7 to complete PMP probe; the current base already enables it on qualified T8132 machines. Assisted-by: LLM checkpatch Signed-off-by: Sean Dolbec --- drivers/soc/apple/pmp-telemetry.c | 3 ++- drivers/soc/apple/pmp.rs | 4 ++-- include/linux/soc/apple/pmp-display.h | 7 +++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/drivers/soc/apple/pmp-telemetry.c b/drivers/soc/apple/pmp-telemetry.c index 788a5e3a4fac2..9e39f1e63b474 100644 --- a/drivers/soc/apple/pmp-telemetry.c +++ b/drivers/soc/apple/pmp-telemetry.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -19,7 +20,7 @@ bool apple_pmp_telemetry_retained_board(void) { - return apple_t8132_firmware_path() && of_machine_is_compatible("apple,t8132"); + return apple_pmp_t8132_retained_board(); } static LIST_HEAD(apple_pmp_telemetry_list); diff --git a/drivers/soc/apple/pmp.rs b/drivers/soc/apple/pmp.rs index 337be4192474e..ee263c92500ff 100644 --- a/drivers/soc/apple/pmp.rs +++ b/drivers/soc/apple/pmp.rs @@ -840,7 +840,7 @@ struct PmpHwConfig { enum Ep7 { /// Never started. No, - /// Only on the retained J713 board. + /// Only on T8132 boards with a retained, qualified PMP session. RetainedBoard, /// On every board with this SoC. Always, @@ -970,7 +970,7 @@ impl platform::Driver for PmpDriver { } data.patch_bootargs(&pmp_mmio, &patches, cfg.check_bootargs_uuid)?; // EP7 is a startup dependency on every T6041 PMP, and on the - // retained J713 PMP among the T8132 boards. + // retained, qualified PMP session among the T8132 boards. let needs_coreanalytics = match cfg.coreanalytics { Ep7::No => false, Ep7::Always => true, diff --git a/include/linux/soc/apple/pmp-display.h b/include/linux/soc/apple/pmp-display.h index e65effb337aa8..87bfbf6a89a99 100644 --- a/include/linux/soc/apple/pmp-display.h +++ b/include/linux/soc/apple/pmp-display.h @@ -12,6 +12,13 @@ static inline bool apple_pmp_j713_board(void) return apple_t8132_firmware_path() && of_machine_is_compatible("apple,t8132"); } +/* T8132 boards on which Linux retains the qualified PMP firmware session. */ +static inline bool apple_pmp_t8132_retained_board(void) +{ + return apple_t8132_firmware_path() && + of_machine_is_compatible("apple,t8132"); +} + struct device; struct apple_pmp_display; From e2f2e3a83352872bf884bbb4b1fa6fbe10f94f12 Mon Sep 17 00:00:00 2001 From: Sean Dolbec Date: Wed, 4 Nov 2026 14:51:24 -0500 Subject: [PATCH 3/7] pmdomain: apple: pmp-report: Use the retained T8132 predicate Use the shared retained T8132 predicate for the report readiness path. The prior test already selected the T8132 report for a compatible T8132 supplier on the qualified firmware path. The new predicate additionally requires the machine compatible apple,t8132; it does not newly enable J773g. Update the host fixtures to provide the same helper. A prior J773g bring-up stack sent and received an AGX request with its PMP report present. This refactoring has not been isolated on hardware. Assisted-by: LLM checkpatch Signed-off-by: Sean Dolbec --- drivers/pmdomain/apple/pmp-report.c | 3 ++- tools/asahi/t6030-pmp-graph-tests.c | 7 +++++++ tools/asahi/t6030-pmp-supplier-tests.c | 7 +++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/pmdomain/apple/pmp-report.c b/drivers/pmdomain/apple/pmp-report.c index 7ce01a88bb069..b40fb8bbcc8a1 100644 --- a/drivers/pmdomain/apple/pmp-report.c +++ b/drivers/pmdomain/apple/pmp-report.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -623,7 +624,7 @@ int apple_pmp_report_wait_supplier_ready(struct device *supplier, unsigned int t struct platform_device *pdev; struct apple_pmp_report *rep; u64 status; - bool t8132 = apple_t8132_firmware_path() && + bool t8132 = apple_pmp_t8132_retained_board() && of_device_is_compatible(supplier->of_node, "apple,t8132-pmp-v2"); int ret; diff --git a/tools/asahi/t6030-pmp-graph-tests.c b/tools/asahi/t6030-pmp-graph-tests.c index e89d982d2d0a6..1a18e241658ac 100644 --- a/tools/asahi/t6030-pmp-graph-tests.c +++ b/tools/asahi/t6030-pmp-graph-tests.c @@ -478,6 +478,13 @@ static inline bool apple_t8132_firmware_path(void) { return apple_t8132_air(); } + +/* Production: . */ +static inline bool apple_pmp_t8132_retained_board(void) +{ + return apple_t8132_firmware_path() && + of_machine_is_compatible("apple,t8132"); +} static bool of_property_read_bool(const struct device_node *n, const char *p) { if (!strcmp(p, "apple,always-on")) diff --git a/tools/asahi/t6030-pmp-supplier-tests.c b/tools/asahi/t6030-pmp-supplier-tests.c index 59c2c0d3cd430..4dbadfee51818 100644 --- a/tools/asahi/t6030-pmp-supplier-tests.c +++ b/tools/asahi/t6030-pmp-supplier-tests.c @@ -172,6 +172,13 @@ static inline bool apple_t8132_firmware_path(void) { return apple_t8132_air(); } + +/* Production: . */ +static inline bool apple_pmp_t8132_retained_board(void) +{ + return apple_t8132_firmware_path() && + of_machine_is_compatible("apple,t8132"); +} static struct device_node *of_find_compatible_node(struct device_node *from, const char *type, const char *compat) From b5de9ff45973f976000685cb1c16547b60b67e73 Mon Sep 17 00:00:00 2001 From: Sean Dolbec Date: Wed, 4 Nov 2026 14:51:56 -0500 Subject: [PATCH 4/7] soc: apple: pmp-display: Carry the AGX vote on J773g The existing bridge treats every firmware-qualified T8132 machine as J713 and requires a DISP record. Select J773g by its machine compatible and require its AGX record instead, so the GPU can use the retained PMP vote bridge without a DISP record. Reject display consumers on J773g; other T8132 boards retain their existing behavior. The fixed table shape and exact supplier checks remain in place, and an accepted AGX vote is retained until reboot. The exported functions keep their apple_pmp_j713_gpu_*() names to avoid Rust driver churn. A prior J773g bring-up stack logged bridge registration and acknowledged AGX requests on ten boots. That was a different implementation; this change has not been booted on hardware. Assisted-by: LLM checkpatch Signed-off-by: Sean Dolbec --- drivers/soc/apple/pmp-display.c | 44 ++++++++++++++++----------- drivers/soc/apple/pmp.rs | 4 +-- include/linux/soc/apple/pmp-display.h | 12 ++++---- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/drivers/soc/apple/pmp-display.c b/drivers/soc/apple/pmp-display.c index b32e155ec09f0..d723ba5e9aea7 100644 --- a/drivers/soc/apple/pmp-display.c +++ b/drivers/soc/apple/pmp-display.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only OR MIT -/* Retained J713 DISP/AGX votes through the existing Rust PMP owner. - * Exactly one untagged request is in flight; invalid replies fail the epoch. +/* Retained J713 DISP and J713/J773g AGX votes through the existing Rust PMP + * owner. Exactly one untagged request is in flight; invalid replies fail the + * epoch. */ #include #include @@ -222,7 +223,7 @@ static DEFINE_MUTEX(pmp_display_registration); bool apple_pmp_display_retained_board(void) { - return apple_pmp_j713_board(); + return apple_pmp_t8132_retained_board(); } /* The qualified loader publishes the existing PMP through its alias. */ @@ -238,24 +239,26 @@ struct apple_pmp_display *apple_pmp_display_register(struct device *dev, struct device_node *node, *qualified; const void *table; int size; - bool match, j713 = apple_pmp_j713_board(); + bool match, j773g = of_machine_is_compatible("apple,j773g"); - if (!j713 || !dev->of_node || + if (!apple_pmp_t8132_retained_board() || !dev->of_node || !of_device_is_compatible(dev->of_node, "apple,t8132-pmp-v2")) return NULL; node = pmp_bridge_node(); match = node == dev->of_node; of_node_put(node); - if (j713) { - qualified = of_find_node_by_path("/soc/pmp@380500000"); - match = match && qualified == dev->of_node; - of_node_put(qualified); - } - /* J713 has a qualified fixed table shape. */ + qualified = of_find_node_by_path("/soc/pmp@380500000"); + match = match && qualified == dev->of_node; + of_node_put(qualified); + /* + * The existing T8132 path requires the DISP record. J773g has no + * display consumer, so require its AGX record instead. + */ table = of_get_property(dev->of_node, "apple,tunable-soc-device", &size); if (!match || !of_property_present(dev->of_node, "apple,tunable-soc-device") || - !cookie || !send || (j713 && !j713_disp_table(table, size))) + !cookie || !send || + (j773g ? !j713_agx_table(table, size) : !j713_disp_table(table, size))) return NULL; mutex_lock(&pmp_display_registration); if (pmp_display) @@ -267,7 +270,7 @@ struct apple_pmp_display *apple_pmp_display_register(struct device *dev, p->driver = dev->driver; p->cookie = cookie; p->send = send; - p->agx_table_valid = !j713 || j713_agx_table(table, size); + p->agx_table_valid = j713_agx_table(table, size); mutex_init(&p->request); spin_lock_init(&p->lock); init_completion(&p->reply); @@ -276,7 +279,7 @@ struct apple_pmp_display *apple_pmp_display_register(struct device *dev, pm_runtime_get_noresume(dev); smp_store_release(&pmp_display, p); dev_info(dev, "%s PMP vote bridge ready; retained existing PMP owner\n", - j713 ? "J713" : "J514S"); + j773g ? "J773g" : "T8132"); out: mutex_unlock(&pmp_display_registration); return p; @@ -319,7 +322,9 @@ static struct apple_pmp_display *pmp_power_consumer(struct device *consumer, struct device_node *pmp, *supplier; bool match; - if (apple_pmp_j713_board()) { + /* J773g uses the AGX record and has no display consumer. */ + if (kind == PMP_POWER_AGX ? apple_pmp_t8132_retained_board() : + (apple_pmp_j713_board() && !of_machine_is_compatible("apple,j773g"))) { /* Both consumers must name the exact boot-profile node. */ if ((kind != PMP_POWER_AGX && kind != PMP_POWER_DISP) || !consumer->of_node || !of_device_is_compatible(consumer->of_node, @@ -520,7 +525,8 @@ EXPORT_SYMBOL_GPL(apple_pmp_j713_display_prepare); int apple_pmp_j713_gpu_prepare(struct device *consumer) { - return apple_pmp_j713_board() ? pmp_power_prepare(consumer, PMP_POWER_AGX) : -ENODEV; + return apple_pmp_t8132_retained_board() ? + pmp_power_prepare(consumer, PMP_POWER_AGX) : -ENODEV; } EXPORT_SYMBOL_GPL(apple_pmp_j713_gpu_prepare); @@ -538,7 +544,8 @@ EXPORT_SYMBOL_GPL(apple_pmp_j713_display_check_release); int apple_pmp_j713_gpu_check(struct device *consumer) { - return apple_pmp_j713_board() ? pmp_power_check(consumer, PMP_POWER_AGX, false) : -ENODEV; + return apple_pmp_t8132_retained_board() ? + pmp_power_check(consumer, PMP_POWER_AGX, false) : -ENODEV; } EXPORT_SYMBOL_GPL(apple_pmp_j713_gpu_check); @@ -556,6 +563,7 @@ EXPORT_SYMBOL_GPL(apple_pmp_j713_display_put); int apple_pmp_j713_gpu_get(struct device *consumer) { - return apple_pmp_j713_board() ? pmp_power_get(consumer, PMP_POWER_AGX) : -ENODEV; + return apple_pmp_t8132_retained_board() ? + pmp_power_get(consumer, PMP_POWER_AGX) : -ENODEV; } EXPORT_SYMBOL_GPL(apple_pmp_j713_gpu_get); diff --git a/drivers/soc/apple/pmp.rs b/drivers/soc/apple/pmp.rs index ee263c92500ff..12a6a396bfa8a 100644 --- a/drivers/soc/apple/pmp.rs +++ b/drivers/soc/apple/pmp.rs @@ -800,7 +800,7 @@ impl rtkit::Operations for PmpData { fn recv_message(data: ::Borrowed<'_>, _ep: u8, msg: u64) { let ret = data.recv_message(msg); if let Err(e) = ret { - // Only the retained J713 bridge latches a message it cannot + // Only the retained T8132 bridge latches a message it cannot // handle as fatal. Other boards log it and keep power commands. // SAFETY: read-only board identity check. if unsafe { bindings::apple_pmp_display_retained_board() } { @@ -924,7 +924,7 @@ impl platform::Driver for PmpDriver { type Data<'bound> = PmpDriver; fn suppress_bind_attrs() -> bool { - // Retained J713 power votes have no teardown path, and an unbound T8140 PMP still runs. + // Retained T8132 power votes have no teardown path, and an unbound T8140 PMP still runs. // SAFETY: read-only machine identity checks; other machines remain unchanged. unsafe { bindings::apple_pmp_keep_bound() } } diff --git a/include/linux/soc/apple/pmp-display.h b/include/linux/soc/apple/pmp-display.h index 87bfbf6a89a99..1662f79a30345 100644 --- a/include/linux/soc/apple/pmp-display.h +++ b/include/linux/soc/apple/pmp-display.h @@ -37,12 +37,12 @@ void apple_pmp_display_fail(struct apple_pmp_display *display, int error); /* Internal: caller holds the bound supplier device lock. */ struct apple_pmp_display *apple_pmp_display_bound_owner(struct device *dev); -/* J713 votes share the existing PMP owner's untagged request stream. - * Prepare is probe-only; supplier links persist until reboot, and so do - * accepted votes, except that the DCP releases its DISP vote while it has - * powered the display domains down (put) and takes it again (get). Before - * that it asks, changing nothing, whether the vote can be released now and - * taken again later (check_release). +/* DISP (J713) and AGX (J713, J773g) votes share the existing PMP owner's + * untagged request stream. Prepare is probe-only; supplier links persist + * until reboot, and so do accepted votes, except that the J713 DCP releases + * its DISP vote while it has powered the display domains down (put) and + * takes it again (get). Before that it asks, changing nothing, whether the + * vote can be released now and taken again later (check_release). */ int apple_pmp_j713_display_prepare(struct device *consumer); int apple_pmp_j713_display_get(struct device *consumer); From a04a35e51c5a44d6c260322fdc1e9b0db7a36a9e Mon Sep 17 00:00:00 2001 From: Sean Dolbec Date: Wed, 4 Nov 2026 14:52:32 -0500 Subject: [PATCH 5/7] drm/asahi: g16: Name the retained T8132 board check Use the shared retained T8132 predicate at the G16 board check. The old apple_pmp_j713_board() already selected firmware-qualified T8132 machines, including J773g, so this is a rename with no admission change. The later handoff, firmware identity, DMA and hardware identity checks remain. A prior J773g bring-up stack admitted the handoff and reached firmware READY with subsequent changes; this rename was not isolated on hardware. Assisted-by: LLM checkpatch Signed-off-by: Sean Dolbec --- drivers/gpu/drm/asahi/g16/boot.rs | 2 +- drivers/gpu/drm/asahi/g16/glue.c | 4 ++-- drivers/gpu/drm/asahi/g16/mod.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/asahi/g16/boot.rs b/drivers/gpu/drm/asahi/g16/boot.rs index 97e0f8156e285..0b5a2862d38ad 100644 --- a/drivers/gpu/drm/asahi/g16/boot.rs +++ b/drivers/gpu/drm/asahi/g16/boot.rs @@ -60,7 +60,7 @@ pub(crate) mod glue { ) -> core::ffi::c_int; } - /// A qualified J713/T8132 board. + /// A qualified T8132 board (J713, J773g). pub(crate) fn board() -> bool { // SAFETY: Reads the machine compatible strings only. unsafe { asahi_g16_board() } diff --git a/drivers/gpu/drm/asahi/g16/glue.c b/drivers/gpu/drm/asahi/g16/glue.c index 368b56149acc7..5adb19bb3d820 100644 --- a/drivers/gpu/drm/asahi/g16/glue.c +++ b/drivers/gpu/drm/asahi/g16/glue.c @@ -200,10 +200,10 @@ int asahi_g16_tvm_enable(struct device *dev) return ret; } -/* Whether this is a qualified J713/T8132 board. */ +/* Whether this T8132 board's retained PMP carries the GPU's AGX vote. */ bool asahi_g16_board(void) { - return apple_pmp_j713_board(); + return apple_pmp_t8132_retained_board(); } /* diff --git a/drivers/gpu/drm/asahi/g16/mod.rs b/drivers/gpu/drm/asahi/g16/mod.rs index f161b218a0d06..33c8323cad5c8 100644 --- a/drivers/gpu/drm/asahi/g16/mod.rs +++ b/drivers/gpu/drm/asahi/g16/mod.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only OR MIT -//! G16 GPU support (T8132, M4: J713; the qualified 25G83 firmware). +//! G16 GPU support (T8132, M4: J713 and J773g; the qualified 25G83 firmware). //! //! G16 firmware is *classic*: one ring per engine (TA, FS, compute) and ordering expressed by //! in-ring barrier records that wait on another queue's stamp, unlike the G17 kick-ring/QID From be82a6f7a38329700c8a6663945c8d3c8963740f Mon Sep 17 00:00:00 2001 From: Sean Dolbec Date: Wed, 4 Nov 2026 14:56:03 -0500 Subject: [PATCH 6/7] drm/asahi: g16: Select the J773g DVFS table from its ADT The G16 driver builds its firmware DVFS table from the sixteen performance states of the original ADT, using a list of qualified ten-row index layouts: J713's (four single states, then six equal-voltage pairs) and J604's. The M4 Mac mini (J773g) has the J604 shape: five single states, five equal-voltage pairs and a single top state at 1578 MHz. That is eleven distinct rows, and the J604 layout drops the fifth low state to fit in ten. Keep every state on J773g. Add an eleven-row J773g layout and give each layout its row count. The board pins the row count it is qualified for, ten on J713 and J604 and eleven on J773g, and only layouts with that count are tried, so the J604 and J773g layouts of the same shape cannot be confused. The table holds up to eleven rows with a count, Main 0xfc0 carries that count instead of a constant 10, and the encoder's ceiling is the last row. Nothing changes on J713 or J604: their layouts and order are kept, the host tests' measured J713 ADT gives the same ten rows, the J604-shaped case still selects the J604 layout on a ten-row board, and the qualified initdata goldens still match at ceilings 1, 4 and 9. The host tests use synthetic voltage bins rather than a measured chip's, and substitute them into those goldens before comparing; every other byte is compared unchanged. The runtime ceiling policy is unchanged: it publishes at most S9, and the hardware performance state is still refused above 9. On J773g the top row (S10, 1578 MHz) is in the tables but never requested; using it needs evidence of its own. The reported maximum frequency is the top row's. Tested on a J773g, on an earlier integration/aurora (19f71a142419), with a voltage-grouping selection that gives the same rows as the J773g layout: the live ADT gave eleven rows, main/auxiliary 0/0, 338/338, 618/618, 796/796, 928/928, 1056/952, 1170/1053, 1278/1152, 1338/1204, 1470/1326 and 1578/1578 MHz. Voltage bins differ per chip; the table is selected from its ADT. The firmware accepted these tables, reached READY and completed a compute job. This layout-based version has not been booted on hardware. Assisted-by: LLM checkpatch Signed-off-by: Sean Dolbec --- drivers/gpu/drm/asahi/g16/board.rs | 24 ++-- drivers/gpu/drm/asahi/g16/board/data.rs | 43 ++++--- drivers/gpu/drm/asahi/g16/boot.rs | 7 ++ drivers/gpu/drm/asahi/g16/fw/initdata.rs | 25 +++- drivers/gpu/drm/asahi/g16/glue.c | 10 ++ drivers/gpu/drm/asahi/g16/glue.h | 7 ++ drivers/gpu/drm/asahi/g16/initdata.rs | 14 ++- .../gpu/asahi-m4/check-initdata-bounds.rs | 11 +- .../drivers/gpu/asahi-m4/check-initdata.rs | 25 ++-- .../drivers/gpu/asahi-m4/test-perf.py | 107 +++++++++++++++--- 10 files changed, 215 insertions(+), 58 deletions(-) create mode 100644 drivers/gpu/drm/asahi/g16/glue.h diff --git a/drivers/gpu/drm/asahi/g16/board.rs b/drivers/gpu/drm/asahi/g16/board.rs index 9d005164e6de8..7b0726b586208 100644 --- a/drivers/gpu/drm/asahi/g16/board.rs +++ b/drivers/gpu/drm/asahi/g16/board.rs @@ -2,33 +2,39 @@ //! M4 board admission for the qualified firmware graph. //! -//! M4 uses ten firmware rows selected from sixteen source states, including off, and sixteen -//! voltage lanes. The source values belong to this machine's preserved original ADT. +//! M4 uses ten (J713, J604) or eleven (J773g) firmware rows selected from sixteen source +//! states, including off, and sixteen voltage lanes. The source values belong to this +//! machine's preserved original ADT. pub(crate) mod data; use super::adt::GpuAdt; -use super::fw::initdata::{Performance, PERF_STATES}; +use super::fw::initdata::Performance; use kernel::{device, prelude::*}; /// Admit the qualified table layout while preserving every machine-specific source value. -/// Differently shaped tables and inconsistent voltage pairs fail before publication. +/// Differently shaped tables, inconsistent voltage pairs and layouts with a row count other +/// than the one qualified for this board fail before publication. pub(crate) fn qualify(dev: &device::Device, adt: &GpuAdt) -> Result { - let (performance, layout) = data::select_named(&adt.performance).map_err(|error| { + let rows = super::boot::glue::perf_rows(); + let (performance, layout) = data::select_named(&adt.performance, Some(rows)).map_err(|error| { dev_err!( dev, - "M4 original ADT performance layout rejected: {:?}\n", + "M4 original ADT performance layout rejected for {} firmware rows: {:?}\n", + rows, error ); EINVAL })?; dev_info!( dev, - "M4 ADT DVFS: 16 source states -> 10 firmware rows ({} layout), top {} MHz\n", + "M4 ADT DVFS: {} source states -> {} firmware rows ({} layout), top {} MHz\n", + adt.performance.count, + performance.count, layout, - performance.frequency[PERF_STATES - 1] + performance.frequency[performance.count - 1] ); - for i in 0..PERF_STATES { + for i in 0..performance.count { dev_info!( dev, "M4 ADT DVFS S{}: main={} MHz auxiliary={} MHz core={} mV SRAM={} mV\n", diff --git a/drivers/gpu/drm/asahi/g16/board/data.rs b/drivers/gpu/drm/asahi/g16/board/data.rs index 6d18386727a7f..9e68f62748855 100644 --- a/drivers/gpu/drm/asahi/g16/board/data.rs +++ b/drivers/gpu/drm/asahi/g16/board/data.rs @@ -2,27 +2,30 @@ //! Qualified selections of the original ADT's sixteen performance states for 25G83. //! -//! The firmware takes ten rows, each a main and an auxiliary frequency at one voltage. Every -//! qualified layout maps the sixteen ADT states onto those rows by index; the values are always -//! this machine's own, never frequencies or voltages copied from a reference machine. +//! The firmware takes ten or eleven rows, each a main and an auxiliary frequency at one voltage. +//! Every qualified layout maps the sixteen ADT states onto those rows by index; the values are +//! always this machine's own, never frequencies or voltages copied from a reference machine. pub(crate) const SOURCE_STATES: usize = 16; -/// One qualified mapping of the ADT states onto the firmware rows. +/// One qualified mapping of the ADT states onto the first `rows` firmware rows. pub(crate) struct Layout { pub(crate) name: &'static str, + pub(crate) rows: usize, pub(crate) main: [usize; PERF_STATES], pub(crate) auxiliary: [usize; PERF_STATES], } /// Tried in order; a layout matches only when each row's two states share frequency, SRAM -/// frequency and both voltages, so the shapes below cannot be mistaken for each other. -pub(crate) const LAYOUTS: [Layout; 2] = [ +/// frequency and both voltages, so the J713 shape cannot be mistaken for the others. J604 and +/// J773g have the same shape and differ only in their row count, which the board selects. +pub(crate) const LAYOUTS: [Layout; 3] = [ // J713: four common low states followed by six equal-voltage pairs. Layout { name: "J713", - main: [0, 1, 2, 3, 5, 7, 9, 11, 13, 15], - auxiliary: [0, 1, 2, 3, 4, 6, 8, 10, 12, 14], + rows: 10, + main: [0, 1, 2, 3, 5, 7, 9, 11, 13, 15, 0], + auxiliary: [0, 1, 2, 3, 4, 6, 8, 10, 12, 14, 0], }, // J604 (MacBook Pro 14-inch, M4): five low states, five equal-voltage pairs (5/6 to // 13/14) and a single top state 15. Eleven distinct rows do not fit in ten, so the fifth @@ -30,8 +33,16 @@ pub(crate) const LAYOUTS: [Layout; 2] = [ // their own ADT values. Layout { name: "J604", - main: [0, 1, 2, 3, 6, 8, 10, 12, 14, 15], - auxiliary: [0, 1, 2, 3, 5, 7, 9, 11, 13, 15], + rows: 10, + main: [0, 1, 2, 3, 6, 8, 10, 12, 14, 15, 0], + auxiliary: [0, 1, 2, 3, 5, 7, 9, 11, 13, 15, 0], + }, + // J773g (Mac mini, M4): the J604 shape, with every state kept in eleven rows. + Layout { + name: "J773g", + rows: 11, + main: [0, 1, 2, 3, 4, 6, 8, 10, 12, 14, 15], + auxiliary: [0, 1, 2, 3, 4, 5, 7, 9, 11, 13, 15], }, ]; @@ -41,18 +52,23 @@ use super::super::fw::initdata::{Performance, PERF_STATES}; pub(crate) fn select( source: &super::super::adt::perf::Source, ) -> core::result::Result { - select_named(source).map(|(performance, _)| performance) + select_named(source, None).map(|(performance, _)| performance) } -/// As [`select`], with the name of the layout that matched. +/// As [`select`], with the name of the layout that matched. With `rows`, only the layouts with +/// that row count, the one qualified for the board, are tried. pub(crate) fn select_named( source: &super::super::adt::perf::Source, + rows: Option, ) -> core::result::Result<(Performance, &'static str), super::super::adt::perf::Error> { use super::super::adt::perf::Error; if source.count != SOURCE_STATES { return Err(Error::Shape); } for layout in LAYOUTS.iter() { + if rows.is_some_and(|rows| rows != layout.rows) { + continue; + } match select_layout(source, layout) { Err(Error::Shape) => continue, Err(error) => return Err(error), @@ -68,12 +84,13 @@ fn select_layout( ) -> core::result::Result { use super::super::adt::perf::Error; let mut performance = Performance { + count: layout.rows, frequency: [0; PERF_STATES], auxiliary: [0; PERF_STATES], voltage: [0; PERF_STATES], sram: [0; PERF_STATES], }; - for i in 0..PERF_STATES { + for i in 0..layout.rows { let (main, aux) = (layout.main[i], layout.auxiliary[i]); if source.frequency_mhz[main] != source.sram_frequency_mhz[main] || source.frequency_mhz[aux] != source.sram_frequency_mhz[aux] diff --git a/drivers/gpu/drm/asahi/g16/boot.rs b/drivers/gpu/drm/asahi/g16/boot.rs index 0b5a2862d38ad..2b54e99a8e730 100644 --- a/drivers/gpu/drm/asahi/g16/boot.rs +++ b/drivers/gpu/drm/asahi/g16/boot.rs @@ -43,6 +43,7 @@ pub(crate) mod glue { extern "C" { fn asahi_g16_board() -> bool; fn asahi_g16_display_prepare(dev: *mut core::ffi::c_void) -> core::ffi::c_int; + fn asahi_g16_perf_rows() -> core::ffi::c_uint; fn asahi_g16_hold_power(dev: *mut core::ffi::c_void) -> core::ffi::c_int; fn asahi_g16_ram_disjoint(start: u64, size: u64) -> bool; fn asahi_g16_ioremap_wc(start: u64, size: usize) -> *mut core::ffi::c_void; @@ -72,6 +73,12 @@ pub(crate) mod glue { kernel::error::to_result(unsafe { asahi_g16_display_prepare(dev.as_raw().cast()) }) } + /// The firmware DVFS row count qualified for this board, or zero. + pub(crate) fn perf_rows() -> usize { + // SAFETY: Reads the machine compatible strings only. + unsafe { asahi_g16_perf_rows() as usize } + } + /// Holds the GFX power domain for the retained session. pub(crate) fn hold_power(dev: &device::Device) -> Result { // SAFETY: `dev` is a valid device; runtime-PM accounting on it has no other requirement. diff --git a/drivers/gpu/drm/asahi/g16/fw/initdata.rs b/drivers/gpu/drm/asahi/g16/fw/initdata.rs index 9acbb4ac763a5..0083f5cad939e 100644 --- a/drivers/gpu/drm/asahi/g16/fw/initdata.rs +++ b/drivers/gpu/drm/asahi/g16/fw/initdata.rs @@ -324,12 +324,15 @@ pub(crate) fn loader_encode(slot: usize, va: u64, record: &mut [u8]) -> Result<( put64(out, 0x20, u64::from(e.mode)) } -pub(crate) const PERF_STATES: usize = 10; +/// Capacity for the largest qualified table: J713 has ten rows, J773g eleven. +pub(crate) const PERF_STATES: usize = 11; /// Machine-specific values selected from the original ADT before firmware publication. /// Frequencies are exact MHz, voltages are millivolts. No reference-bin defaults exist. +/// Only the first `count` rows are used; the rest are zero. #[derive(Clone, Debug, PartialEq, Eq)] pub(crate) struct Performance { + pub(crate) count: usize, pub(crate) frequency: [u32; PERF_STATES], pub(crate) auxiliary: [u32; PERF_STATES], pub(crate) voltage: [u32; PERF_STATES], @@ -338,7 +341,19 @@ pub(crate) struct Performance { impl Performance { pub(crate) fn valid(&self) -> bool { - for i in 0..PERF_STATES { + if !(2..=PERF_STATES).contains(&self.count) { + return false; + } + for i in self.count..PERF_STATES { + if self.frequency[i] != 0 + || self.auxiliary[i] != 0 + || self.voltage[i] != 0 + || self.sram[i] != 0 + { + return false; + } + } + for i in 0..self.count { if self.frequency[i] > 3000 || self.auxiliary[i] > self.frequency[i] || ((i == 0) != (self.frequency[i] == 0)) @@ -445,8 +460,8 @@ pub(crate) fn encode( input: &Input, ceiling: u32, ) -> Result<(), ()> { - if !(1..=9).contains(&ceiling) - || !input.performance.valid() + if !input.performance.valid() + || !(1..input.performance.count as u32).contains(&ceiling) || !object_va(input.scratch, 0x8000) || !bootstrap_alias(input.lower_uma) || !bootstrap_alias(input.lower_parameter) @@ -542,7 +557,7 @@ pub(crate) fn encode( (0xed0, 24000), (0xed4, 1), (0xed8, 8), - (0xfc0, 10), + (0xfc0, input.performance.count as u32), (0x259c, 1), (0x2544, 4), (0x2548, 6), diff --git a/drivers/gpu/drm/asahi/g16/glue.c b/drivers/gpu/drm/asahi/g16/glue.c index 5adb19bb3d820..ab68633f83bcb 100644 --- a/drivers/gpu/drm/asahi/g16/glue.c +++ b/drivers/gpu/drm/asahi/g16/glue.c @@ -25,6 +25,8 @@ #include #include +#include "glue.h" + bool asahi_g16_board(void); int asahi_g16_display_prepare(struct device *dev); int asahi_g16_hold_power(struct device *dev); @@ -206,6 +208,14 @@ bool asahi_g16_board(void) return apple_pmp_t8132_retained_board(); } +/* Preserve the existing ten-row table except for the qualified J773g layout. */ +unsigned int asahi_g16_perf_rows(void) +{ + if (!apple_pmp_t8132_retained_board()) + return 0; + return of_machine_is_compatible("apple,j773g") ? 11 : 10; +} + /* * The first firmware start follows the native display the boot loader handed * over, as on J713 bring-up: defer until drm/apple has published it. A boot diff --git a/drivers/gpu/drm/asahi/g16/glue.h b/drivers/gpu/drm/asahi/g16/glue.h new file mode 100644 index 0000000000000..c1c3adc3e2b39 --- /dev/null +++ b/drivers/gpu/drm/asahi/g16/glue.h @@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +#ifndef _ASAHI_G16_GLUE_H +#define _ASAHI_G16_GLUE_H + +unsigned int asahi_g16_perf_rows(void); + +#endif /* _ASAHI_G16_GLUE_H */ diff --git a/drivers/gpu/drm/asahi/g16/initdata.rs b/drivers/gpu/drm/asahi/g16/initdata.rs index ecdde0579133a..58a19546fdad2 100644 --- a/drivers/gpu/drm/asahi/g16/initdata.rs +++ b/drivers/gpu/drm/asahi/g16/initdata.rs @@ -83,7 +83,9 @@ pub(crate) fn build( objects: &mut Objects, ) -> Result<(InitData, Channels, u32)> { let performance = board::qualify(dev, adt)?; - let max_khz = performance.frequency[wire::PERF_STATES - 1] * 1000; + // The top row: S9 on J713, S10 on J773g. + let ceiling = performance.count as u32 - 1; + let max_khz = performance.frequency[ceiling as usize] * 1000; let mut graph = KVec::with_capacity(wire::OBJECT_COUNT, GFP_KERNEL)?; for (i, size) in wire::OBJECT_SIZE.iter().copied().enumerate() { let lower = match i { @@ -184,11 +186,11 @@ pub(crate) fn build( } let array: &mut [&mut [u8]; wire::OBJECT_COUNT] = (&mut slices[..]).try_into().map_err(|_| EINVAL)?; - wire::encode(array, &input, 9).map_err(|()| EINVAL)?; + wire::encode(array, &input, ceiling).map_err(|()| EINVAL)?; } let mut loader = [0u8; wire::LOADER_BYTES]; loader.copy_from_slice(&images[id::MAIN][0x640..0x640 + wire::LOADER_BYTES]); - // Host startup policy: Main and PowerPerformance contain S9, but the + // Host startup policy: Main and PowerPerformance contain the top row, but the // published selectors remain S1 until the thermal owner admits a raise. for at in globals::PSTATE_SELECTORS { images[id::GLOBALS][at..at + 4].copy_from_slice(&100u32.to_le_bytes()); @@ -197,7 +199,11 @@ pub(crate) fn build( graph[i].write(0, &images[i])?; } - dev_info!(dev, "M4 initdata: 31 objects, 12 submit channel pairs, 42 loader records, S1 startup (S9 tables)\n"); + dev_info!( + dev, + "M4 initdata: 31 objects, 12 submit channel pairs, 42 loader records, S1 startup (S{} tables)\n", + ceiling + ); Ok(( InitData { globals: Some(graph[id::GLOBALS].clone()), diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/check-initdata-bounds.rs b/tools/testing/selftests/drivers/gpu/asahi-m4/check-initdata-bounds.rs index 29b51ee5cefaf..72eae3a009585 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/check-initdata-bounds.rs +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/check-initdata-bounds.rs @@ -6,12 +6,13 @@ const HOST: u64 = wire::HOST_START; fn emit(out:&mut Vec, value:Result)->Option { out.push(u8::from(value.is_err()));value.ok() } fn input()->wire::Input { wire::Input { - // Independently pinned qualified C/J713 bin for this immutable byte fixture. + // J713 frequencies with synthetic voltage bins. performance: wire::Performance { - frequency: [0,338,618,796,928,1056,1170,1278,1338,1470], - auxiliary: [0,338,618,796,836,952,1053,1152,1204,1326], - voltage: [125,610,645,680,725,780,825,865,895,970], - sram: [780,780,780,780,780,780,825,865,895,970], + count: 10, + frequency: [0,338,618,796,928,1056,1170,1278,1338,1470,0], + auxiliary: [0,338,618,796,836,952,1053,1152,1204,1326,0], + voltage: [100,600,650,700,750,800,850,900,950,1000,0], + sram: [800,800,800,800,800,800,850,900,950,1000,0], }, va: core::array::from_fn(|i|HOST+0x100000+i as u64*0x100000), channel_state:core::array::from_fn(|i|HOST+0x4000000+i as u64*0x10000), diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/check-initdata.rs b/tools/testing/selftests/drivers/gpu/asahi-m4/check-initdata.rs index 97d526fbf504f..98419052d41ad 100644 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/check-initdata.rs +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/check-initdata.rs @@ -7,12 +7,13 @@ fn input(variant: u64) -> initdata::Input { let start = 0xfffffc2000000000u64; let shift = variant * 0x100000000; let mut input = initdata::Input { - // Independently pinned qualified C/J713 bin for this immutable byte fixture. + // J713 frequencies with synthetic voltage bins. performance: initdata::Performance { - frequency: [0,338,618,796,928,1056,1170,1278,1338,1470], - auxiliary: [0,338,618,796,836,952,1053,1152,1204,1326], - voltage: [125,610,645,680,725,780,825,865,895,970], - sram: [780,780,780,780,780,780,825,865,895,970], + count: 10, + frequency: [0,338,618,796,928,1056,1170,1278,1338,1470,0], + auxiliary: [0,338,618,796,836,952,1053,1152,1204,1326,0], + voltage: [100,600,650,700,750,800,850,900,950,1000,0], + sram: [800,800,800,800,800,800,850,900,950,1000,0], }, va: core::array::from_fn(|i| start + shift + 0x100000 + i as u64 * 0x100000), channel_state: core::array::from_fn(|i| start + shift + 0x4000000 + i as u64 * 0x10000), @@ -41,12 +42,22 @@ fn main() { let mut slices: [&mut [u8]; initdata::OBJECT_COUNT] = buffers.each_mut().map(|buffer| buffer.as_mut_slice()); initdata::encode(&mut slices, &input(variant as u64), ceiling).expect("valid C fixture rejected"); let got: Vec<_> = buffers.into_iter().flatten().collect(); - let expected = std::fs::read(directory.join(format!("initdata-{variant}.bin"))).unwrap(); + let mut expected = + std::fs::read(directory.join(format!("initdata-{variant}.bin"))).unwrap(); + // Substitute synthetic voltages in the immutable C golden before comparison. + let main: usize = initdata::OBJECT_SIZE[..initdata::id::MAIN].iter().sum(); + let perf = input(variant as u64).performance; + for i in 0..=ceiling as usize { for lane in 0..16 { + for (offset, value) in [(0x1008, perf.voltage[i]), (0x1408, perf.sram[i])] { + let at = main + offset + (i * 16 + lane) * 4; + expected[at..at+4].copy_from_slice(&value.to_le_bytes()); + } + }} if let Some(offset) = got.iter().zip(&expected).position(|(a, b)| a != b) { panic!("initdata variant {variant} differs at {offset:#x}: C={:#x}, Rust={:#x}", expected[offset], got[offset]); } assert_eq!(got.len(), expected.len()); bytes_checked += got.len(); } - println!("3 initdata fixtures / {bytes_checked} output bytes match qualified C exactly"); + println!("3 initdata fixtures / {bytes_checked} bytes match C with synthetic voltages"); } diff --git a/tools/testing/selftests/drivers/gpu/asahi-m4/test-perf.py b/tools/testing/selftests/drivers/gpu/asahi-m4/test-perf.py index 36574512d4298..0daa8ffdcd8d8 100755 --- a/tools/testing/selftests/drivers/gpu/asahi-m4/test-perf.py +++ b/tools/testing/selftests/drivers/gpu/asahi-m4/test-perf.py @@ -66,11 +66,74 @@ def node(props, children=()): fn get32(bytes: &[u8], at: usize) -> u32 { u32::from_le_bytes(bytes[at..at+4].try_into().unwrap()) } #[test] fn measured_original_adt_produces_qualified_tables() { let s=source(); assert_eq!(s.count,16); - let p=tables(); - assert_eq!(p.frequency,[0,338,618,796,928,1056,1170,1278,1338,1470]); - assert_eq!(p.auxiliary,[0,338,618,796,836,952,1053,1152,1204,1326]); - assert_eq!(p.voltage,[125,610,645,680,725,780,825,865,895,970]); - assert_eq!(p.sram,[780,780,780,780,780,780,825,865,895,970]); + // Keep the original frequency layout but use synthetic voltage bins. + let mut s=s; + s.core_mv[..16].copy_from_slice(&[100,600,650,700,750,750,800,800,850,850,900,900,950,950,1000,1000]); + s.sram_mv[..16].copy_from_slice(&[800,800,800,800,800,800,800,800,850,850,900,900,950,950,1000,1000]); + let p=data::select(&s).unwrap(); assert_eq!(p.count,10); + assert_eq!(p.frequency,[0,338,618,796,928,1056,1170,1278,1338,1470,0]); + assert_eq!(p.auxiliary,[0,338,618,796,836,952,1053,1152,1204,1326,0]); + assert_eq!(p.voltage,[100,600,650,700,750,800,850,900,950,1000,0]); + assert_eq!(p.sram,[800,800,800,800,800,800,850,900,950,1000,0]); + assert_eq!(get32(&encode(p).unwrap()[wire::id::MAIN],0xfc0),10); +} +// J773g frequency layout with synthetic voltage bins, both with eleven groups. +fn j773g(core: [u32; 16], sram: [u32; 16]) -> perf::Source { + let mhz=[0,338,618,796,928,952,1056,1053,1170,1152,1278,1204,1338,1326,1470,1578]; + let mut s=source(); s.count=16; + s.frequency_mhz=[0;perf::MAX_STATES]; s.sram_frequency_mhz=[0;perf::MAX_STATES]; + s.core_mv=[0;perf::MAX_STATES]; s.sram_mv=[0;perf::MAX_STATES]; + s.frequency_mhz[..16].copy_from_slice(&mhz); s.sram_frequency_mhz[..16].copy_from_slice(&mhz); + s.core_mv[..16].copy_from_slice(&core); s.sram_mv[..16].copy_from_slice(&sram); + s +} +#[test] fn j773g_synthetic_bins_produce_eleven_rows_and_encode_all_of_them() { + for (core,sram,voltage,row_sram) in [ + ([100,600,620,660,700,750,750,800,800,850,850,900,900,950,950,1000], + [740,740,740,740,740,750,750,800,800,850,850,900,900,950,950,1000], + [100,600,620,660,700,750,800,850,900,950,1000], + [740,740,740,740,740,750,800,850,900,950,1000]), + ([100,590,630,650,690,730,730,790,790,840,840,890,890,940,940,990], + [760,760,760,760,760,760,760,790,790,840,840,890,890,940,940,990], + [100,590,630,650,690,730,790,840,890,940,990], + [760,760,760,760,760,760,790,840,890,940,990]), + ] { + let (p,name)=data::select_named(&j773g(core,sram),Some(11)).unwrap(); + assert_eq!(name,"J773g"); assert_eq!(p.count,11); + assert_eq!(p.frequency,[0,338,618,796,928,1056,1170,1278,1338,1470,1578]); + assert_eq!(p.auxiliary,[0,338,618,796,928,952,1053,1152,1204,1326,1578]); + assert_eq!(p.voltage,voltage); assert_eq!(p.sram,row_sram); + let mut buffers=wire::OBJECT_SIZE.map(|size|vec![0xa5;size]); + wire::encode(&mut buffers.each_mut().map(|b|b.as_mut_slice()),&input(p.clone()),10).unwrap(); + let main=&buffers[wire::id::MAIN]; + assert_eq!(get32(main,0xfc0),11); assert_eq!(get32(main,0xfc4),10); + for i in 0..11 { + assert_eq!(get32(main,0xfc8+i*4),p.frequency[i]); + assert_eq!(get32(main,0x1808+i*4),p.auxiliary[i]); + assert_eq!(get32(main,0x1008+i*16*4),p.voltage[i]); + assert_eq!(get32(main,0x1408+(i*16+15)*4),p.sram[i]); + } + } +} +#[test] fn the_row_count_bounds_the_encoded_ceiling() { + let j713=tables(); let j773g=data::select_named(&j773g( + [100,600,620,660,700,750,750,800,800,850,850,900,900,950,950,1000], + [740,740,740,740,740,750,750,800,800,850,850,900,900,950,950,1000]),Some(11)).unwrap().0; + for (p,good,bad) in [(j713,[1,9],[0,10]),(j773g,[1,10],[0,11])] { + for ceiling in good { + let mut buffers=wire::OBJECT_SIZE.map(|size|vec![0xa5;size]); + assert!(wire::encode(&mut buffers.each_mut().map(|b|b.as_mut_slice()),&input(p.clone()),ceiling).is_ok()); + assert_eq!(get32(&buffers[wire::id::MAIN],0xfc0),p.count as u32); + } + for ceiling in bad { + let mut buffers=wire::OBJECT_SIZE.map(|size|vec![0xa5;size]); + assert!(wire::encode(&mut buffers.each_mut().map(|b|b.as_mut_slice()),&input(p.clone()),ceiling).is_err()); + assert!(buffers.iter().all(|buffer|buffer.iter().all(|&byte|byte==0xa5))); + } + } + // Rows past the count must stay zero, and the count must match the rows. + let mut p=tables(); p.frequency[10]=1500; assert!(!p.valid()); + let mut p=tables(); p.count=11; assert!(!p.valid()); } #[test] fn different_real_bin_values_reach_all_firmware_lanes() { let mut raw=MEASURED.to_vec(); @@ -134,9 +197,12 @@ def node(props, children=()): let mut s=source();s.frequency_mhz[4]=s.frequency_mhz[5]+1;s.sram_frequency_mhz[4]=s.frequency_mhz[4];assert!(data::select(&s).is_err()); let mut s=source();s.frequency_mhz[7]=s.frequency_mhz[5];s.sram_frequency_mhz[7]=s.frequency_mhz[7];assert!(data::select(&s).is_err()); let mut s=source();s.core_mv[14]=600;s.core_mv[15]=600;assert!(data::select(&s).is_err()); + // Three states at one voltage, and split pairs, match no layout. + let mut s=source();s.core_mv[6]=s.core_mv[5];s.sram_mv[6]=s.sram_mv[5];assert!(data::select(&s).is_err()); + let mut s=source();s.core_mv[4]-=1;s.core_mv[6]-=1;assert!(data::select(&s).is_err()); } #[test] fn j604_shape_selects_its_own_layout_and_the_j713_keeps_its_own() { - assert_eq!(data::select_named(&source()).unwrap().1,"J713"); + assert_eq!(data::select_named(&source(),None).unwrap().1,"J713"); // J604 shape: five low states, equal-voltage pairs 5/6 to 13/14, a single top state 15. // Rows 0-3 and 5-15 are the J604's selected values; state 4 (left out) is synthetic. let mhz=[0,338,618,796,928,952,1056,1053,1170,1152,1278,1204,1338,1326,1470,1578]; @@ -146,16 +212,27 @@ def node(props, children=()): s.frequency_mhz[i]=mhz[i];s.sram_frequency_mhz[i]=mhz[i]; s.core_mv[i]=mv[i];s.sram_mv[i]=mv[i].max(780); } - let (p,name)=data::select_named(&s).unwrap(); - assert_eq!(name,"J604"); - assert_eq!(p.frequency,[0,338,618,796,1056,1170,1278,1338,1470,1578]); - assert_eq!(p.auxiliary,[0,338,618,796,952,1053,1152,1204,1326,1578]); - assert_eq!(p.voltage,[125,625,640,680,780,825,865,895,970,1045]); - assert_eq!(p.sram,[780,780,780,780,780,825,865,895,970,1045]); - assert!(encode(p).is_ok()); - // A J604 shape with one unequal pair matches neither layout. + let (p,name)=data::select_named(&s,None).unwrap(); + assert_eq!(name,"J604"); assert_eq!(p.count,10); + assert_eq!(p.frequency,[0,338,618,796,1056,1170,1278,1338,1470,1578,0]); + assert_eq!(p.auxiliary,[0,338,618,796,952,1053,1152,1204,1326,1578,0]); + assert_eq!(p.voltage,[125,625,640,680,780,825,865,895,970,1045,0]); + assert_eq!(p.sram,[780,780,780,780,780,825,865,895,970,1045,0]); + assert!(encode(p.clone()).is_ok()); + // The board's row count picks between the two layouts of this shape. + assert_eq!(data::select_named(&s,Some(10)).unwrap(),(p,"J604")); + let (p,name)=data::select_named(&s,Some(11)).unwrap(); + assert_eq!(name,"J773g"); assert_eq!(p.count,11); + assert_eq!(p.frequency,[0,338,618,796,928,1056,1170,1278,1338,1470,1578]); + assert_eq!(p.auxiliary,[0,338,618,796,928,952,1053,1152,1204,1326,1578]); + // The J713 shape has no eleven-row layout, and no board has another row count. + assert_eq!(data::select_named(&source(),Some(10)).unwrap().1,"J713"); + assert_eq!(data::select_named(&source(),Some(11)),Err(perf::Error::Shape)); + for rows in [0,9,12] { assert_eq!(data::select_named(&s,Some(rows)),Err(perf::Error::Shape)); } + // A J604 shape with one unequal pair matches no layout. let mut bad=s;bad.core_mv[9]+=1;bad.sram_mv[9]+=1; assert_eq!(data::select(&bad),Err(perf::Error::Shape)); + assert_eq!(data::select_named(&bad,Some(11)),Err(perf::Error::Shape)); } #[test] fn invalid_encoder_input_is_refused_without_mutating_output() { for variant in 0..5 { @@ -177,7 +254,7 @@ def node(props, children=()): print(run.stdout, end='') print(run.stderr, end='') run.check_returncode() -report = {'passed': True, 'test_groups': 8, 'hardware_validated': False, +report = {'passed': True, 'test_groups': 10, 'hardware_validated': False, 'fixture_sha256': sha(fixture), 'original_adt_sha256': metadata['provenance']['source_sha256'], 'production_sha256': {str(p.relative_to(root)): sha(p) for p in [backend / 'adt.rs', backend / 'adt/perf.rs', backend / 'board.rs', backend / 'board/data.rs', backend / 'initdata.rs', backend / 'fw/initdata.rs']}} From 709a5689b6d3d68533cc2804a697cbb9e9f5df70 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Thu, 19 Nov 2026 03:06:04 -0500 Subject: [PATCH 7/7] drm/asahi: g16: Run up to the board's top performance state The utilization governor, the cooling ceiling and the check of the GPU's reported performance state all stopped at S9, the top row of the ten-row J713 and J604 tables. The J773g (Mac mini) table has eleven rows. Its top state S10 runs at 1578 MHz. Initdata already initializes that state and names it the ceiling, but the governor never asked for it, so a busy GPU ran at 1470 MHz. Take the top state from the board's firmware table and use it for the governor's load target, the configured ceiling and the bound on the pstate register. A reported state above the table's top is still a protocol error. Before this change, publishing S10 made the next register check fail-stop the GPU with EPROTO. Cooling keeps one state per level below the top, and S1 at full cooling on every table. The ten-row tables behave exactly as before. Signed-off-by: Diljit Singh --- drivers/gpu/drm/asahi/g16/boot.rs | 8 +- drivers/gpu/drm/asahi/g16/initdata.rs | 4 + drivers/gpu/drm/asahi/g16/mod.rs | 3 +- drivers/gpu/drm/asahi/g16/power.rs | 24 +++- drivers/gpu/drm/asahi/g16/power/policy.rs | 131 ++++++++++++++++------ drivers/gpu/drm/asahi/g16/regs.rs | 22 +++- 6 files changed, 147 insertions(+), 45 deletions(-) diff --git a/drivers/gpu/drm/asahi/g16/boot.rs b/drivers/gpu/drm/asahi/g16/boot.rs index 2b54e99a8e730..1c388062d5661 100644 --- a/drivers/gpu/drm/asahi/g16/boot.rs +++ b/drivers/gpu/drm/asahi/g16/boot.rs @@ -415,7 +415,7 @@ impl Session { self.shared.check()?; if !self.rtkit.running() || self.regs.asc_control()? & regs::ASC_RUN == 0 - || self.regs.pstate()? > 9 + || self.regs.pstate()? > self.regs.top() { return Err(EIO); } @@ -736,7 +736,7 @@ pub(crate) fn start( "M4 G16G: {} cores enabled\n", id.core_masks[0].count_ones() ); - if regs.pstate()? > 9 { + if regs.pstate()? > regs.top() { return Err(eproto()); } // Cold only: ASC RUN clear and an all-zero TTBAT before ownership. @@ -785,6 +785,10 @@ pub(crate) fn start( events.reserve()?; // Every host object and every context-0 alias is prepared before RUN is set. built = Some(initdata::build(&d, &session.adt, &mut objects)?); + if let Some((init, _, _)) = built.as_ref() { + // The running firmware may report any state of the board's table, up to S10 on J773g. + session.regs.set_table(init.rows); + } objects.window.lock().bootstrap(&d, &session.uat)?; uat::tlbi_all(); if session.regs.asc_control()? & regs::ASC_RUN != 0 { diff --git a/drivers/gpu/drm/asahi/g16/initdata.rs b/drivers/gpu/drm/asahi/g16/initdata.rs index 58a19546fdad2..f022689ad0878 100644 --- a/drivers/gpu/drm/asahi/g16/initdata.rs +++ b/drivers/gpu/drm/asahi/g16/initdata.rs @@ -38,6 +38,8 @@ pub(crate) struct InitData { #[allow(dead_code)] pub(crate) parameter: Arc, root: Arc, + /// Rows of the board's firmware performance table, including off. + pub(crate) rows: u32, loader: [u8; wire::LOADER_BYTES], /// The complete inventory, including firmware-only log and retention data. _graph: KVec>, @@ -85,6 +87,7 @@ pub(crate) fn build( let performance = board::qualify(dev, adt)?; // The top row: S9 on J713, S10 on J773g. let ceiling = performance.count as u32 - 1; + let rows = performance.count as u32; let max_khz = performance.frequency[ceiling as usize] * 1000; let mut graph = KVec::with_capacity(wire::OBJECT_COUNT, GFP_KERNEL)?; for (i, size) in wire::OBJECT_SIZE.iter().copied().enumerate() { @@ -219,6 +222,7 @@ pub(crate) fn build( uma: graph[id::UMA].clone(), parameter: graph[id::PARAMETER].clone(), root: graph[id::ROOT].clone(), + rows, loader, _graph: graph, }, diff --git a/drivers/gpu/drm/asahi/g16/mod.rs b/drivers/gpu/drm/asahi/g16/mod.rs index 33c8323cad5c8..8287d6fd140f1 100644 --- a/drivers/gpu/drm/asahi/g16/mod.rs +++ b/drivers/gpu/drm/asahi/g16/mod.rs @@ -456,7 +456,7 @@ impl Firmware { dev: &AsahiDrmDevice, booted: boot::Booted, shared: &Arc, - power: power::Power, + mut power: power::Power, ) -> Result> { let boot::Booted { session, @@ -470,6 +470,7 @@ impl Firmware { dev.as_ref(), "G16: firmware at READY, starting the backend\n" ); + power.set_table(init.rows); let orphan = |session: boot::Session, objects: object::Objects, channels: channel::Channels, diff --git a/drivers/gpu/drm/asahi/g16/power.rs b/drivers/gpu/drm/asahi/g16/power.rs index 5e3346e3cf1e2..ae07876b3b45b 100644 --- a/drivers/gpu/drm/asahi/g16/power.rs +++ b/drivers/gpu/drm/asahi/g16/power.rs @@ -24,7 +24,7 @@ use super::fw::initdata::globals; use super::recovery::now_ns; use super::regs::wmb; use super::Firmware; -use policy::{COOLING_MAX, PSTATE_MAX}; +use policy::{COOLING_MAX, TOP_DEFAULT}; static_assert!(globals::PSTATE_SELECTORS[0] == 0x88); static_assert!(globals::PSTATE_SELECTORS[1] == 0x8c); @@ -155,6 +155,8 @@ pub(crate) struct Power { cooling: Cooling, sample: Sample, last_sample_ns: Option, + /// The board's top state: S9 on the ten-row tables, S10 on the J773g table. + pub(crate) top: u32, pub(crate) configured: u32, pub(crate) user: u32, pub(crate) effective: u32, @@ -170,7 +172,7 @@ pub(crate) struct Power { } impl Power { - /// The Main image initializes all nine active states. Initdata publishes + /// The Main image initializes every active state of the board's table. Initdata publishes /// startup S1 before INIT; this object starts with that same effective state. pub(crate) fn new(dev: &device::Device) -> Result { Ok(Self { @@ -185,8 +187,9 @@ impl Power { backstop: COOLING_MAX, }, last_sample_ns: None, - configured: PSTATE_MAX, - user: PSTATE_MAX, + top: TOP_DEFAULT, + configured: TOP_DEFAULT, + user: TOP_DEFAULT, effective: 1, temperature_mc: 0, governor: COOLING_MAX, @@ -200,6 +203,17 @@ impl Power { }) } + /// Adopts the board's firmware table, `rows` rows including off, before the first + /// governed publication: its top row is the governor's top state and configured + /// ceiling. The J773g table has eleven rows, so its top state is S10. + pub(crate) fn set_table(&mut self, rows: u32) { + let top = policy::top_of(rows); + self.top = top; + self.configured = top; + self.user = top; + self.utilization.top = top; + } + /// Reports a change of work in flight to the CLPC: the memory and fabric /// floor follows it, not the GFX power state. pub(crate) fn report_work(&mut self, in_flight: bool) { @@ -221,7 +235,7 @@ impl Power { self.budget = self.sample.budget; } let level = self.governor.max(self.budget).max(self.sample.backstop); - let ceiling = PSTATE_MAX - level.min(COOLING_MAX); + let ceiling = policy::cooling_ceiling(self.top, level); let limit = policy::limit(self.configured, ceiling, self.user); let decision = ( limit, diff --git a/drivers/gpu/drm/asahi/g16/power/policy.rs b/drivers/gpu/drm/asahi/g16/power/policy.rs index 0d127b8a5f817..d1d34b6245f52 100644 --- a/drivers/gpu/drm/asahi/g16/power/policy.rs +++ b/drivers/gpu/drm/asahi/g16/power/policy.rs @@ -6,7 +6,11 @@ //! Temperature decoding and regulation belong to the PMP provider and the //! shared C cooling policy. This module defines no temperature thresholds. -pub(crate) const PSTATE_MAX: u32 = 9; +/// Highest selector any M4 table can have: S9 on the ten-row J713/J604 tables, S10 on the +/// eleven-row J773g table. The board's own top state (`top`) bounds every request. +pub(crate) const PSTATE_MAX: u32 = 10; +/// Top state of the ten-row tables, used until the board's table is known. +pub(crate) const TOP_DEFAULT: u32 = 9; pub(crate) const COOLING_MAX: u32 = 8; pub(crate) const SAMPLE_NS: u64 = 5_000_000; /// Utilization window of the governor. @@ -21,11 +25,26 @@ pub(crate) fn read_due(last: Option, now: u64) -> bool { } /// Zero is not an unlimited selector in the firmware. Every published state -/// is 1..=9, bounded by the initialized Main table and the user ceiling. +/// is 1..=top, bounded by the initialized Main table and the user ceiling. pub(crate) fn limit(configured: u32, ceiling: u32, user: u32) -> u32 { ceiling.min(PSTATE_MAX).min(configured).min(user).max(1) } +/// The board's top state, from its firmware table's row count (row 0 is off). +pub(crate) fn top_of(rows: u32) -> u32 { + rows.saturating_sub(1).clamp(FLOOR, PSTATE_MAX) +} + +/// The cooling ceiling for a cooling `level` (0..=COOLING_MAX) under the board's `top` +/// state: one state per level below the top, and S1 at full cooling on every table. +pub(crate) fn cooling_ceiling(top: u32, level: u32) -> u32 { + if level >= COOLING_MAX { + 1 + } else { + top.saturating_sub(level).max(1) + } +} + /// Percentage of `window` ns the GPU was busy for. pub(crate) fn utilization(busy: u64, window: u64) -> u32 { if window == 0 { @@ -53,9 +72,10 @@ pub(crate) fn smooth(average: u32, util: u32, window: u64) -> u32 { /// The state to request from the `current` published one: up on the last /// window's utilization `util`, to the top state under heavy load, and down /// on the smoothed `average`, to the floor when idle. -pub(crate) fn demand(current: u32, util: u32, average: u32) -> u32 { +pub(crate) fn demand(current: u32, util: u32, average: u32, top: u32) -> u32 { + let top = top.clamp(FLOOR, PSTATE_MAX); let next = if util >= 70 { - PSTATE_MAX + top } else if util >= 40 { current.saturating_add(1) } else if average < 10 { @@ -65,7 +85,7 @@ pub(crate) fn demand(current: u32, util: u32, average: u32) -> u32 { } else { current }; - next.clamp(FLOOR, PSTATE_MAX) + next.clamp(FLOOR, top) } /// Busy-time accounting over the governor's windows. The engine reports each @@ -74,6 +94,8 @@ pub(crate) struct Governor { /// The requested state and the smoothed utilization. pub(crate) demand: u32, pub(crate) average: u32, + /// The board's top state. + pub(crate) top: u32, window_ns: u64, busy_since: Option, busy_ns: u64, @@ -84,6 +106,7 @@ impl Governor { Self { demand: FLOOR, average: 0, + top: TOP_DEFAULT, window_ns: 0, busy_since: None, busy_ns: 0, @@ -123,7 +146,7 @@ impl Governor { } let util = utilization(self.busy_ns, window); self.average = smooth(self.average, util, window); - self.demand = demand(self.demand.min(limit), util, self.average); + self.demand = demand(self.demand.min(limit), util, self.average, self.top); self.window_ns = now; self.busy_ns = 0; } @@ -135,6 +158,9 @@ impl Governor { mod tests { use super::*; + /// The ten-row tables' top state; the J773g cases name theirs. + const TOP: u32 = TOP_DEFAULT; + #[test] fn provider_sampling_is_independent_of_completion_polling() { assert!(read_due(None, 0)); @@ -146,7 +172,7 @@ mod tests { #[test] fn initialized_selectors_and_user_caps_bound_every_request() { - assert_eq!(COOLING_MAX, PSTATE_MAX - 1); + assert_eq!(COOLING_MAX, TOP_DEFAULT - 1); for configured in [0, 1, 7, 9, 10, u32::MAX] { for ceiling in [0, 1, 5, 9, 10, u32::MAX] { for user in [0, 1, 3, 9, 10, u32::MAX] { @@ -180,7 +206,7 @@ mod tests { assert_eq!(smooth(u32::MAX, u32::MAX, w), 100); let mut average = 100; let mut windows = 0; - while demand(PSTATE_MAX, 0, average) != FLOOR { + while demand(TOP, 0, average, TOP) != FLOOR { average = smooth(average, 0, w); windows += 1; } @@ -189,23 +215,23 @@ mod tests { #[test] fn demand_rises_fast_and_falls_on_the_average() { - assert_eq!(demand(FLOOR, 100, 0), PSTATE_MAX); - assert_eq!(demand(FLOOR, 70, 0), PSTATE_MAX); - assert_eq!(demand(4, 50, 0), 5); - assert_eq!(demand(PSTATE_MAX, 50, 0), PSTATE_MAX); + assert_eq!(demand(FLOOR, 100, 0, TOP), TOP); + assert_eq!(demand(FLOOR, 70, 0, TOP), TOP); + assert_eq!(demand(4, 50, 0, TOP), 5); + assert_eq!(demand(TOP, 50, 0, TOP), TOP); // A short dip under a busy average holds the state. - assert_eq!(demand(PSTATE_MAX, 5, 80), PSTATE_MAX); - assert_eq!(demand(6, 30, 30), 6); - assert_eq!(demand(6, 20, 20), 5); - assert_eq!(demand(PSTATE_MAX, 0, 5), FLOOR); + assert_eq!(demand(TOP, 5, 80, TOP), TOP); + assert_eq!(demand(6, 30, 30, TOP), 6); + assert_eq!(demand(6, 20, 20, TOP), 5); + assert_eq!(demand(TOP, 0, 5, TOP), FLOOR); // A light 60 fps load near 25% busy settles on the floor. - assert_eq!(demand(FLOOR, 25, 24), FLOOR); - assert_eq!(demand(1, 30, 30), FLOOR); - for current in [0, 1, FLOOR, 7, PSTATE_MAX, u32::MAX] { + assert_eq!(demand(FLOOR, 25, 24, TOP), FLOOR); + assert_eq!(demand(1, 30, 30, TOP), FLOOR); + for current in [0, 1, FLOOR, 7, TOP, u32::MAX] { for util in [0, 20, 50, 70, 100, u32::MAX] { for average in [0, 9, 20, 30, 100, u32::MAX] { - let next = demand(current, util, average); - assert!((FLOOR..=PSTATE_MAX).contains(&next)); + let next = demand(current, util, average, TOP); + assert!((FLOOR..=TOP).contains(&next)); } } } @@ -216,7 +242,7 @@ mod tests { /// A governor whose first window closed idle at `T`. fn started() -> Governor { let mut governor = Governor::new(); - assert_eq!(governor.govern(T, PSTATE_MAX, false), FLOOR); + assert_eq!(governor.govern(T, TOP, false), FLOOR); assert_eq!(governor.average, 0); governor } @@ -232,10 +258,10 @@ mod tests { // A drain without a publication adds nothing. g.idle(T + 9_000_000); // A service before the window is due changes nothing. - assert_eq!(g.govern(T + w - 1, PSTATE_MAX, false), FLOOR); + assert_eq!(g.govern(T + w - 1, TOP, false), FLOOR); assert_eq!(g.average, 0); // 5 ms of 20 ms: 25%, a quarter of it in the average. - assert_eq!(g.govern(T + w, PSTATE_MAX, false), FLOOR); + assert_eq!(g.govern(T + w, TOP, false), FLOOR); assert_eq!(g.average, 6); } @@ -246,13 +272,13 @@ mod tests { g.busy(T); assert!(!g.decaying()); // Busy through the window: all of it counts, and the load gets the top state. - assert_eq!(g.govern(T + w, PSTATE_MAX, true), PSTATE_MAX); + assert_eq!(g.govern(T + w, TOP, true), TOP); assert_eq!(g.average, 25); // Busy above the floor: the engine's own polls govern it, not the idle re-arm. assert!(!g.decaying()); // The span carries on from the window's end, not from its publication. g.idle(T + w + w / 2); - assert_eq!(g.govern(T + 2 * w, PSTATE_MAX, false), PSTATE_MAX); + assert_eq!(g.govern(T + 2 * w, TOP, false), TOP); assert_eq!(g.average, (3 * 25 + 50) / 4); } @@ -263,15 +289,15 @@ mod tests { g.busy(T); // Recovery dropped the flights and reported no drain: the next service, // finding none outstanding, ends the span there. - assert_eq!(g.govern(T + w / 2, PSTATE_MAX, false), FLOOR); + assert_eq!(g.govern(T + w / 2, TOP, false), FLOOR); assert!(!g.decaying()); - assert_eq!(g.govern(T + w, PSTATE_MAX, false), FLOOR + 1); + assert_eq!(g.govern(T + w, TOP, false), FLOOR + 1); assert_eq!(g.average, 50 / 4); // Idle above the floor: the poll keeps coming back. assert!(g.decaying()); // A late drain report counts nothing more. g.idle(T + w + 1); - assert_eq!(g.govern(T + 2 * w, PSTATE_MAX, false), FLOOR); + assert_eq!(g.govern(T + 2 * w, TOP, false), FLOOR); assert!(!g.decaying()); } @@ -281,7 +307,7 @@ mod tests { let mut g = started(); g.busy(T); for n in 1..=8 { - assert_eq!(g.govern(T + n * w, PSTATE_MAX, true), PSTATE_MAX); + assert_eq!(g.govern(T + n * w, TOP, true), TOP); } let mut now = T + 8 * w; g.idle(now); @@ -289,21 +315,21 @@ mod tests { let mut passes = 0; while g.decaying() { now += w; - g.govern(now, PSTATE_MAX, false); + g.govern(now, TOP, false); passes += 1; assert!(passes <= 10); } assert_eq!(g.demand, FLOOR); assert!(passes > 1); // At the floor nothing re-arms, and a later service holds it there. - assert_eq!(g.govern(now + 10 * w, PSTATE_MAX, false), FLOOR); + assert_eq!(g.govern(now + 10 * w, TOP, false), FLOOR); assert!(!g.decaying()); // A long sleep between passes restarts the average and drops at once. let mut g = started(); g.busy(T); - assert_eq!(g.govern(T + w, PSTATE_MAX, true), PSTATE_MAX); + assert_eq!(g.govern(T + w, TOP, true), TOP); g.idle(T + w); - assert_eq!(g.govern(T + 6 * w, PSTATE_MAX, false), FLOOR); + assert_eq!(g.govern(T + 6 * w, TOP, false), FLOOR); assert!(!g.decaying()); } @@ -318,7 +344,7 @@ mod tests { assert_eq!(g.govern(T + 2 * w, 1, true), 1); assert_eq!(g.govern(T + 2 * w + 1, 2, true), 2); // Released, the load's request applies at once. - assert_eq!(g.govern(T + 2 * w + 2, PSTATE_MAX, true), PSTATE_MAX); + assert_eq!(g.govern(T + 2 * w + 2, TOP, true), TOP); // Idle under a ceiling below the floor: one window gives it all back. g.idle(T + 3 * w); assert!(g.decaying()); @@ -326,4 +352,39 @@ mod tests { assert_eq!(g.demand, FLOOR); assert!(!g.decaying()); } + + #[test] + fn the_board_table_sets_the_top_state() { + // J713/J604: ten rows, top S9. J773g: eleven rows, top S10 (1578 MHz on the Mac mini). + assert_eq!(top_of(10), 9); + assert_eq!(top_of(11), 10); + assert_eq!(top_of(12), PSTATE_MAX); + assert_eq!(top_of(0), FLOOR); + for top in [9, 10] { + assert_eq!(demand(FLOOR, 100, 0, top), top); + assert_eq!(demand(top, 50, 80, top), top); + assert_eq!(demand(top, 0, 5, top), FLOOR); + let mut g = Governor::new(); + g.top = top; + assert_eq!(g.govern(T, top, false), FLOOR); + g.busy(T); + assert_eq!(g.govern(T + WINDOW_NS, top, true), top); + // A ceiling still bounds the request. + assert_eq!(g.govern(T + 2 * WINDOW_NS, top - 1, true), top - 1); + } + } + + #[test] + fn cooling_keeps_one_state_per_level_and_s1_at_full_cooling() { + // Ten-row tables: unchanged, 9 - level, S1 at level 8. + for level in 0..=COOLING_MAX { + assert_eq!(cooling_ceiling(9, level), 9 - level); + } + // Eleven rows: S10..S3 for levels 0..7, S1 at full cooling. + assert_eq!(cooling_ceiling(10, 0), 10); + assert_eq!(cooling_ceiling(10, 7), 3); + assert_eq!(cooling_ceiling(10, COOLING_MAX), 1); + assert_eq!(cooling_ceiling(10, u32::MAX), 1); + assert_eq!(limit(10, cooling_ceiling(10, 0), 10), 10); + } } diff --git a/drivers/gpu/drm/asahi/g16/regs.rs b/drivers/gpu/drm/asahi/g16/regs.rs index e264e319c2a64..77478c9a42dab 100644 --- a/drivers/gpu/drm/asahi/g16/regs.rs +++ b/drivers/gpu/drm/asahi/g16/regs.rs @@ -21,6 +21,8 @@ use kernel::{ prelude::*, }; +use core::sync::atomic::{AtomicU32, Ordering}; + use crate::regs::G16Resources; /// Write memory barrier (`wmb()`): `dsb st`. @@ -179,6 +181,9 @@ pub(crate) struct Regs { status: Mapping, /// Host-owned generation register page (SGX +0xd60000). generation: Mapping, + /// Highest firmware performance state the board's table holds: S9 until the table is + /// known (the ten-row J713/J604 tables), S10 on the eleven-row J773g table. + top: AtomicU32, } impl Regs { @@ -198,6 +203,7 @@ impl Regs { asc: window(c_str!("asc"), 0)?, status: window(c_str!("sgx"), SGX_STATUS as u64)?, generation: window(c_str!("sgx"), 0xd60000)?, + top: AtomicU32::new(9), res, }) } @@ -216,10 +222,22 @@ impl Regs { }) } - /// Actual cold or running firmware pstate (zero is valid while stopped). + /// Adopts the board's firmware performance table, `rows` rows including off. + pub(crate) fn set_table(&self, rows: u32) { + let top = rows.saturating_sub(1).clamp(1, super::fw::initdata::PERF_STATES as u32 - 1); + self.top.store(top, Ordering::Relaxed); + } + + /// Highest performance state the firmware may run in. + pub(crate) fn top(&self) -> u32 { + self.top.load(Ordering::Relaxed) + } + + /// Actual cold or running firmware pstate (zero is valid while stopped). A state above the + /// board table's top row is a protocol error. pub(crate) fn pstate(&self) -> Result { let state = self.res.sgx_read32_at(SGX_CORE + 0x1000)? & 0xf; - if state > 9 { + if state > self.top() { Err(super::boot::eproto()) } else { Ok(state)