From 404788a51301370721bcd8e4dd62d10d39377b4c Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Fri, 20 Nov 2026 00:24:05 -0500 Subject: [PATCH 01/11] soc: apple: display: recognise the T8132 macOS 27.2 DCP image The Mac mini (J773g) on macOS 27.2 (26B123) runs one DCP image, UUID B3BA603C-3CA7-3E21-B393-44EB20BD2AEF, on dcp, dcpext0 and dcpext1 (its 27.2 ADT; the three share __TEXT). Its external processors are to be driven through the firmware-27 backend as the T6041's 27.2 ones are, so the display gate and the DCP driver need the same pinned admission the T6041 helpers give: the image UUID, firmware version and compatibility 27.2.0. Split the T6041 check into apple_dcp_image_v27_2(), which takes the image UUID, and add apple_t8132_dcpext_v27_2() for a J773g dcpext. It is limited to the J773g until another T8132 board's 27.2 trace shows the same interface. apple_t8132_dcpext_v27_2() is in linux/soc/apple/t8132.h, with the other T8132 board helpers: its machine check stays out of display.h, whose T6041 helpers key on the processor and its image alone (the apple-dcp boot selftest builds them with no of_machine_is_compatible()). Signed-off-by: Diljit Singh --- include/linux/soc/apple/display.h | 6 ++++++ include/linux/soc/apple/t8132.h | 15 +++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/soc/apple/display.h b/include/linux/soc/apple/display.h index aa7266693ace..f6264be746ca 100644 --- a/include/linux/soc/apple/display.h +++ b/include/linux/soc/apple/display.h @@ -18,6 +18,12 @@ int apple_drm_t8132_link_device(struct device *consumer); /* T6041 DCP image shipped with macOS 27.2 (26B123). */ #define APPLE_T6041_DCP_26B123_UUID "964EDE5B-8F78-38C2-A727-519CC9F0AF27" +/* + * T8132 DCP image shipped with macOS 27.2 (26B123), as the J773g's 27.2 ADT + * names it for dcp, dcpext0 and dcpext1 alike (they share its __TEXT). + */ +#define APPLE_T8132_DCP_26B123_UUID "B3BA603C-3CA7-3E21-B393-44EB20BD2AEF" + /* * @np is a @compat_name display processor that the boot loader handed over * with the 27.2 (26B123) image @image_uuid: firmware version and diff --git a/include/linux/soc/apple/t8132.h b/include/linux/soc/apple/t8132.h index ec91e8faaa9b..9a0607a7eb96 100644 --- a/include/linux/soc/apple/t8132.h +++ b/include/linux/soc/apple/t8132.h @@ -3,6 +3,7 @@ #define _LINUX_SOC_APPLE_T8132_H #include +#include #include #include @@ -54,6 +55,20 @@ static inline bool apple_t8132_firmware_path(void) return apple_t8132_air() || apple_t8132_qualified_firmware(); } +/* + * A T8132 external display processor on the Mac mini (J773g) handed over + * with the 27.2 image: it runs the firmware-27 backend (iomfb_v27.c), not + * the M4 26.6.2 one (iomfb_m4.c). Other T8132 boards and images are not + * admitted until a trace of theirs says the same interface applies. Kept + * here, not in display.h, whose T6041 helpers key on the processor alone. + */ +static inline bool apple_t8132_dcpext_v27_2(const struct device_node *np) +{ + return of_machine_is_compatible("apple,j773g") && + apple_dcp_image_v27_2(np, "apple,t8132-dcpext", + APPLE_T8132_DCP_26B123_UUID); +} + /* * The radio port the Airs have: reg-on on the SMC's gP13 with the same * template, and the radio's two ordinary streams managed on port 0 of the From cb9fdb871c77d691a3331f228ea584eaea45cd25 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Fri, 20 Nov 2026 00:25:04 -0500 Subject: [PATCH 02/11] drm/apple: keep the M4 backend off firmware-27 T8132 display processors The M4 backend (iomfb_m4.c, t8132_ext_drm.c) adopts T8132 display processors on the 26.6.2 firmware path. The Mac mini's device tree is also booted on macOS 27.2 firmware, where the boot loader leaves the main DCP running idle and hands it to nobody, and where dcpext0 is to run the firmware-27 backend instead. Make the M4 paths say so: - dcp_check_firmware_version() refuses an M4 hw-data DCP off apple_t8132_firmware_path(), before the probe claims its IOMMU domain. iomfb_m4_init() refused such firmware already, but only later. - apple_dcp_usable() leaves the main T8132 DCP out of the DRM device's components off that path, so a device tree that enables it (as the 26.6.2 HDMI work does) does not hold the DRM device up waiting for it. - dcp_is_t8132_ext() and the probe, remove and shutdown dispatch match only an M4-adopted dcpext (dcp_t8132_ext_m4_node()): a J773g dcpext with the 27.2 image (apple_t8132_dcpext_v27_2()) is neither routed through dcp_platform_probe_t8132_ext() nor caught by the T8132 Type-C, crossbar and tunnel special cases of the fabric and the DPTX service. Nothing changes on the Airs (any firmware) or on any T8132 Mac on 26.6.2. The host replays that extract dcp_is_t8132_ext() (tiled-split, dcpext26-crossbar-union) take the new helper with it; the crossbar one also checks that a J773g 27.2 dcpext takes the T6041 firmware-27 link. The apple-dcp boot selftest checks the gate both ways: a T8132 processor of the M4 backend is the M4 backend's on its firmware path, and nobody's off it. Signed-off-by: Diljit Singh --- drivers/gpu/drm/apple/apple_drv.c | 9 ++++++- drivers/gpu/drm/apple/dcp-fabric.c | 20 ++++++++++----- drivers/gpu/drm/apple/dcp-fabric.h | 7 +++++- drivers/gpu/drm/apple/dcp.c | 20 ++++++++++++--- tools/asahi/dcpext26-crossbar-union-tests.py | 19 +++++++++++--- tools/asahi/t6030-clock/fixture.c | 4 +-- tools/asahi/tiled-split-tests.py | 3 ++- tools/asahi/tiled-split/fixture.c | 7 ++++++ tools/asahi/tunnel-route/fixture.c | 2 +- .../selftests/drivers/gpu/apple-dcp/boot.py | 25 +++++++++++++++++++ 10 files changed, 98 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/drm/apple/apple_drv.c b/drivers/gpu/drm/apple/apple_drv.c index b6ec46a79025..0a19d5ae26e1 100644 --- a/drivers/gpu/drm/apple/apple_drv.c +++ b/drivers/gpu/drm/apple/apple_drv.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -1497,7 +1498,13 @@ static bool apple_dcp_usable(struct device_node *np) dcp_h17p_external_supported(np)) && /* t6041_dcpext=0 keeps the T6041 external processors out. */ (!of_device_is_compatible(np, "apple,t6041-dcpext") || - dcp_t6041_ext_enabled()); + dcp_t6041_ext_enabled()) && + /* + * The T8132 main DCP is the M4 backend's, on its 26.6.2 + * firmware path only (see dcp_check_firmware_version()). + */ + (!of_device_is_compatible(np, "apple,t8132-dcp") || + apple_t8132_firmware_path()); } static void apple_drm_quiesce_connectors(struct drm_device *drm) diff --git a/drivers/gpu/drm/apple/dcp-fabric.c b/drivers/gpu/drm/apple/dcp-fabric.c index 08f5057cf1a9..7ff72bfe6ddd 100644 --- a/drivers/gpu/drm/apple/dcp-fabric.c +++ b/drivers/gpu/drm/apple/dcp-fabric.c @@ -12,7 +12,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -226,6 +228,17 @@ bool dcp_hdmi_port_attached(struct apple_dcp *dcp) gpiod_get_value_cansleep(dcp->hdmi_hpd) > 0; } +bool dcp_t8132_ext_m4_node(const struct device_node *np) +{ + return of_device_is_compatible(np, "apple,t8132-dcpext") && + !apple_t8132_dcpext_v27_2(np); +} + +bool dcp_is_t8132_ext(const struct apple_dcp *dcp) +{ + return dcp_t8132_ext_m4_node(dcp->dev->of_node); +} + /* * A route of an adopted T8132 dcpext whose PHY has no DP alt mode: the * crossbar's DP PHY output has nothing behind it. The board marks the PHYs @@ -234,17 +247,12 @@ bool dcp_hdmi_port_attached(struct apple_dcp *dcp) */ static bool dcp_typec_route_no_dp_alt(const struct apple_dcp_typec_route *route) { - if (!of_device_is_compatible(route->dcp->dev->of_node, "apple,t8132-dcpext")) + if (!dcp_is_t8132_ext(route->dcp)) return false; return IS_ERR_OR_NULL(route->phy) || !of_property_read_bool(route->phy->dev.of_node, "apple,dp-alt-mode"); } -bool dcp_is_t8132_ext(const struct apple_dcp *dcp) -{ - return of_device_is_compatible(dcp->dev->of_node, "apple,t8132-dcpext"); -} - /* * DP IN outputs (bits 0/1) whose tunnel pixel clock source @route cannot be: * T6030 even sources only, T8132 its dcpexts (2 and 4), others any. diff --git a/drivers/gpu/drm/apple/dcp-fabric.h b/drivers/gpu/drm/apple/dcp-fabric.h index 7876718cbfdf..9457e0016c1f 100644 --- a/drivers/gpu/drm/apple/dcp-fabric.h +++ b/drivers/gpu/drm/apple/dcp-fabric.h @@ -120,7 +120,12 @@ int dcp_tunnel_set_rate(struct apple_dcp *dcp, struct phy *phy, u32 unit, u32 link_rate); int dcp_tunnel_dpin_activate(struct apple_dcp *dcp, u32 unit, bool active); -/* An adopted T8132 dcpext. */ +/* + * A T8132 dcpext adopted through the M4 26.6.2 backend (iomfb_m4.c, + * t8132_ext_drm.c). A J773g dcpext on firmware 27.2 is an ordinary + * firmware-27 pipe instead and is neither of these. + */ +bool dcp_t8132_ext_m4_node(const struct device_node *np); bool dcp_is_t8132_ext(const struct apple_dcp *dcp); /* DCP probe, resume and endpoint teardown hooks. */ diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index b16995083020..2f120135cc42 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include @@ -6008,6 +6009,19 @@ static enum dcp_firmware_version dcp_check_firmware_version(struct device *dev) return dcp_v27_method_table(dev, compat_str); } + /* + * The M4 backend (iomfb_m4.c) is written for the 26.6.2 firmware path + * only (apple_t8132_firmware_path()). Off it, as on a Mac mini booted + * from macOS 27.2, the boot loader leaves the main DCP running idle and + * hands it to nobody: never adopt or touch it. iomfb_m4_init() would + * refuse such firmware too, but only after the probe has claimed the + * DCP's IOMMU domain. + */ + if (hw->firmware_compat == DCP_FIRMWARE_M4 && !apple_t8132_firmware_path()) { + dev_info(dev, "T8132 display processor left alone off the M4 26.6.2 firmware path\n"); + return DCP_FIRMWARE_UNKNOWN; + } + /* * SoCs introduced with H17-generation firmware pin its interface; the * loader may not recognise their boot firmware version. @@ -7898,7 +7912,7 @@ static int dcp_platform_probe(struct platform_device *pdev) return -ENODEV; } - if (of_device_is_compatible(dev->of_node, "apple,t8132-dcpext")) + if (dcp_t8132_ext_m4_node(dev->of_node)) return dcp_platform_probe_t8132_ext(pdev); if (!dcp_ext_is_failsafe(dev->of_node)) return dcp_platform_probe_pipe(pdev); @@ -7974,7 +7988,7 @@ static void dcp_platform_remove(struct platform_device *pdev) if (dcp) av_audiosrv_quiesce(dcp); /* An adopted external DCP never joined the DRM device. */ - if (of_device_is_compatible(pdev->dev.of_node, "apple,t8132-dcpext")) { + if (dcp_t8132_ext_m4_node(pdev->dev.of_node)) { /* Enabled with its Type-C routes, see dcp_t8132_ext_routes(). */ if (dcp) disable_delayed_work_sync(&dcp->typec_reconnect_wq); @@ -8040,7 +8054,7 @@ VISIBLE_IF_KUNIT void dcp_platform_shutdown(struct platform_device *pdev) } /* An adopted external DCP never joined the DRM device. */ - if (of_device_is_compatible(pdev->dev.of_node, "apple,t8132-dcpext")) + if (dcp_t8132_ext_m4_node(pdev->dev.of_node)) return; component_del(&pdev->dev, &dcp_comp_ops); } diff --git a/tools/asahi/dcpext26-crossbar-union-tests.py b/tools/asahi/dcpext26-crossbar-union-tests.py index 9607ad8ee202..b6291bcf9155 100644 --- a/tools/asahi/dcpext26-crossbar-union-tests.py +++ b/tools/asahi/dcpext26-crossbar-union-tests.py @@ -44,7 +44,7 @@ def function(text, name): #include #include enum { DCP_FIRMWARE_V_27_0 = 27, DCP_IOMFB_METHODS_J613_EXT26 = 26 }; -struct device_node { const char *compatible; }; +struct device_node { const char *compatible; bool v27_2; }; struct device { struct device_node *of_node; }; struct mux_control { int id; }; struct apple_dcp_typec_route { @@ -68,6 +68,10 @@ def function(text, name): static bool of_device_is_compatible(const struct device_node *n, const char *name) { return !strcmp(n->compatible, name); } +/* The J773g's 27.2 (26B123) dcpext admission, include/linux/soc/apple/display.h. */ +static bool apple_t8132_dcpext_v27_2(const struct device_node *n) { + return of_device_is_compatible(n, "apple,t8132-dcpext") && n->v27_2; +} static void mock_guard(int *lock) { (void)lock; locks++; } #define guard(kind) mock_guard #define dev_warn(...) ((void)0) @@ -81,7 +85,7 @@ def function(text, name): cases = r''' static void reset(void) { links = v27 = locks = 0; last = NULL; last_up = false; fault = 0; } int main(void) { - struct device_node node = { "apple,other-dcp" }; + struct device_node node = { .compatible = "apple,other-dcp" }; struct device dev = { &node }; struct mux_control a = {1}, b = {2}; struct apple_dcp_typec_route route = { .xbar = &a, .selected = true }; @@ -128,16 +132,25 @@ def function(text, name): reset(); assert(dcp_direct_crossbar_link(&d, true) == 0); assert(v27 == 0 && links == 1 && locks == 1); } + /* A J773g dcpext on firmware 27.2 is no M4 dcpext: it links as a T6041 firmware-27 one. */ + machine = "apple,other"; node.compatible = "apple,t8132-dcpext"; node.v27_2 = true; + struct apple_dcp j773g = { .dev = &dev, .active_typec_route = &route, + .fw_compat = DCP_FIRMWARE_V_27_0, .desktop_external = true }; + assert(!dcp_is_t8132_ext(&j773g)); + reset(); assert(dcp_direct_crossbar_link(&j773g, true) == 0); + assert(v27 == 0 && links == 1 && locks == 1 && j773g.direct_xbar_up == &a); + node.v27_2 = false; machine = "apple,other"; node.compatible = "apple,other-dcp"; struct apple_dcp unrelated = { .dev = &dev, .active_typec_route = &route }; reset(); assert(dcp_direct_crossbar_link(&unrelated, true) == 0); assert(links == 0 && locks == 0); - puts("PASS production crossbar union, route/cache/error behavior, V27 precedence and unrelated exclusion"); + puts("PASS production crossbar union, route/cache/error behavior, V27 precedence, J773g 27.2 and unrelated exclusion"); return 0; } ''' unit = pre + function(header, 'dcp_is_ext26') + '\n' unit += function(source, 'dcp_t6041_ext_v27') + '\n' +unit += function(source, 'dcp_t8132_ext_m4_node') + '\n' unit += function(source, 'dcp_is_t8132_ext') + '\n' + link + '\n' + cases with tempfile.TemporaryDirectory() as tmp: c = Path(tmp) / 'crossbar.c' diff --git a/tools/asahi/t6030-clock/fixture.c b/tools/asahi/t6030-clock/fixture.c index 3efdc838fe8d..580fc335c2f6 100644 --- a/tools/asahi/t6030-clock/fixture.c +++ b/tools/asahi/t6030-clock/fixture.c @@ -139,8 +139,8 @@ static int apple_t6050_dp_tunnel_clock(struct phy *p, unsigned clock, u8 rate) return t6050_error; } /* - * Production: of_device_is_compatible(dcp->dev->of_node, "apple,t8132-dcpext"). - * These are T6030 DCPs: the T8132 dcpext paths must never be taken. + * Production: an apple,t8132-dcpext the M4 backend adopts (dcp_t8132_ext_m4_node(): + * not a J773g one on firmware 27.2). These are T6030 DCPs: the T8132 dcpext paths must never be taken. */ static bool dcp_is_t8132_ext(const struct apple_dcp *dcp) { diff --git a/tools/asahi/tiled-split-tests.py b/tools/asahi/tiled-split-tests.py index 7ee72aa18bf5..8ee3749aa80b 100644 --- a/tools/asahi/tiled-split-tests.py +++ b/tools/asahi/tiled-split-tests.py @@ -21,7 +21,8 @@ 'drivers/gpu/drm/apple/dcp-fabric-session.h': ['dcp_fabric_binding_request'], 'drivers/gpu/drm/apple/dcp-fabric-core.c': ['dcp_fabric_tunnel_slot'], 'drivers/gpu/drm/apple/dcp-fabric.c': [ - 'dcp_typec_route_no_dp_alt', 'dcp_is_t8132_ext', 'dcp_typec_port_untileable', + 'dcp_t8132_ext_m4_node', 'dcp_is_t8132_ext', 'dcp_typec_route_no_dp_alt', + 'dcp_typec_port_untileable', 'dcp_tb_slot', 'dcp_tb_split_locked', 'dcp_tb_dispatch_request'], } CASES = ['t6030-dpin1-alone', 't6030-dpin1-alone-before-services', diff --git a/tools/asahi/tiled-split/fixture.c b/tools/asahi/tiled-split/fixture.c index 30f4ca0a7972..a0a697440807 100644 --- a/tools/asahi/tiled-split/fixture.c +++ b/tools/asahi/tiled-split/fixture.c @@ -61,6 +61,13 @@ static bool of_property_read_bool(const struct device_node *np, const char *name return np && !strcmp(name, "apple,dp-alt-mode") && np->dp_alt_mode; } +/* No J773g firmware-27.2 dcpext here: every T8132 dcpext is the M4 backend's. */ +static bool apple_t8132_dcpext_v27_2(const struct device_node *np) +{ + (void)np; + return false; +} + #define IS_ERR_OR_NULL(ptr) (!(ptr)) struct phy { struct device dev; }; struct mux_chip; diff --git a/tools/asahi/tunnel-route/fixture.c b/tools/asahi/tunnel-route/fixture.c index 2bcb8e713e5b..e95d06be8446 100644 --- a/tools/asahi/tunnel-route/fixture.c +++ b/tools/asahi/tunnel-route/fixture.c @@ -67,7 +67,7 @@ static bool of_machine_is_compatible(const char *compatible) assert(!strcmp(compatible, "apple,t6030")); return t6030; } -/* Production: of_device_is_compatible(dcp->dev->of_node, "apple,t8132-dcpext"). */ +/* Production: an M4-adopted apple,t8132-dcpext (dcp_t8132_ext_m4_node()). */ static bool dcp_is_t8132_ext(const struct apple_dcp *dcp) { return t8132_ext; diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py index b7ebb2fc9fc5..ad07edf47e59 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py @@ -228,6 +228,7 @@ def t6041_v27_admission(root): DCP_FIRMWARE_UNKNOWN, DCP_FIRMWARE_V_26_6_DESKTOP, DCP_FIRMWARE_V_27_0, + DCP_FIRMWARE_M4, }; struct dcp_v14_board; struct apple_dcp_hw_data { enum dcp_firmware_version firmware_compat; }; @@ -294,6 +295,13 @@ def t6041_v27_admission(root): #define DCP_FW_VERSION_STR_LEN 32 #define GFP_KERNEL 0 #define dev_err(...) ((void)0) +#define dev_info(...) ((void)0) +/* linux/soc/apple/t8132.h: the M4 backend's 26.6.2 firmware path (or an Air) */ +static bool t8132_firmware_path; +static bool apple_t8132_firmware_path(void) +{ + return t8132_firmware_path; +} static void *devm_kmemdup(struct device *dev, const void *src, size_t len, unsigned int gfp) { (void)dev; (void)src; (void)len; (void)gfp; @@ -422,9 +430,26 @@ def t6041_v27_admission(root): node.fw[2] = 0; node.compat[2] = 0; assert(apple_t8122_dcp_v27_2(&node)); + /* + * A T8132 processor of the M4 backend keeps it on the M4 firmware path + * only; off it (a Mac mini booted from 27.2) nobody adopts or touches it. + */ + static struct apple_dcp_hw_data hw_m4 = { .firmware_compat = DCP_FIRMWARE_M4 }; + dev.hw = &hw_m4; + for (unsigned ext = 0; ext < 2; ext++) { + reset_t6041_26b123(ext); + node.compatible = ext ? "apple,t8132-dcpext" : "apple,t8132-dcp"; + node.uuid = "other"; + t8132_firmware_path = true; + assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_M4); + t8132_firmware_path = false; + assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_UNKNOWN); + } + dev.hw = &hw_t6041; puts("PASS T6041 26B123 v27.2 internal/external admission, refusal controls, and desktop 26.x preservation"); puts("PASS T8122 internal DCP on its 27.2 image alone runs the 27.2 table"); + puts("PASS T8132 M4 backend only on its firmware path"); return 0; } ''' From 3f777b58516e510f506a6b41957840eb49d51c34 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Fri, 20 Nov 2026 00:27:15 -0500 Subject: [PATCH 03/11] drm/apple: dcp: run the J773g dcpext on firmware 27.2 with the 27.2 table On macOS 27.2 (26B123) the Mac mini's (J773g) external display processors run the same image as its main DCP (UUID B3BA603C), and aura hands them over the way it hands over the M4 Max Mac Studio's (J575c): firmware memory in text/data/heap regions, apple,firmware-version and -compat 27.2.0, the image UUID, and the dispextN provider clocks. Admit such a dcpext the way the T6041 27.2 dcpext is admitted: - dcp_check_firmware_version() returns firmware 27 for it, with the 27.2 method table, before the M4 hw data is looked at. That the T8132 26B123 image numbers its IOMFB methods as the T6041 and T8142 26B123 images do is assumed, not traced; the comment says so. The method table check is now one helper, dcp_v27_method_table(), shared with the existing firmware-27 and T6041 cases. - It gets apple_dcp_hw_t8132_dcpext_v27, whichever hw data its compatible matched: firmware_dma_bits 41 (the firmware DART window, 1 TiB + 64 GiB, ADT dart-dcpext0 vm-base and vm-size-23), num_dptx_ports 2, adopt_live_session (iBoot leaves it running, pre-loaded = running = 1) and sink_metadata_edid, as T6041's dcpext gets on 27.2. No sleep support. - It is a failsafe external processor and a component of the DRM device (apple_dcp_id_tbl, apple_dcp_usable()), unlike an M4-adopted dcpext. The apple-dcp boot selftest (t6041-v27-admission) now also builds dcp_v27_method_table() and the real apple_t8132_dcpext_v27_2(), with its machine check as a flag. It checks: - the J773g dcpext with the T8132 27.2 image runs the 27.2 table, on and off the M4 path; - another M4 Mac's dcpext does not; - the main DCP, the T6041 image, a missing or second UUID, and other releases are refused. Signed-off-by: Diljit Singh --- drivers/gpu/drm/apple/apple_drv.c | 10 ++- drivers/gpu/drm/apple/dcp.c | 61 +++++++++++++++++-- .../selftests/drivers/gpu/apple-dcp/boot.py | 55 +++++++++++++++-- 3 files changed, 117 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/apple/apple_drv.c b/drivers/gpu/drm/apple/apple_drv.c index 0a19d5ae26e1..d791d22ec6d1 100644 --- a/drivers/gpu/drm/apple/apple_drv.c +++ b/drivers/gpu/drm/apple/apple_drv.c @@ -1480,6 +1480,8 @@ static const struct of_device_id apple_dcp_id_tbl[] = { #if IS_ENABLED(CONFIG_DRM_APPLE_DCP_T8132) { .compatible = "apple,t8132-dcp" }, #endif + /* apple_dcp_usable(): only a J773g one on firmware 27.2. */ + { .compatible = "apple,t8132-dcpext" }, {}, }; @@ -1504,7 +1506,13 @@ static bool apple_dcp_usable(struct device_node *np) * firmware path only (see dcp_check_firmware_version()). */ (!of_device_is_compatible(np, "apple,t8132-dcp") || - apple_t8132_firmware_path()); + apple_t8132_firmware_path()) && + /* + * A T8132 dcpext the M4 backend adopts is no component: its + * outputs are t8132_ext_drm.c's. The J773g's on 27.2 is a pipe. + */ + (!of_device_is_compatible(np, "apple,t8132-dcpext") || + apple_t8132_dcpext_v27_2(np)); } static void apple_drm_quiesce_connectors(struct drm_device *drm) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 2f120135cc42..4378f6ad93ca 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -6000,6 +6000,25 @@ static enum dcp_firmware_version dcp_check_firmware_version(struct device *dev) return dcp_v27_method_table(dev, compat_str); } + /* + * T8132 external processors: the Mac mini's (J773g) on macOS 27.2 + * (26B123), handed over as the T6041's 27.2 ones are, run the + * firmware-27 backend with the 27.2 method table, as on T6041; any + * other is the M4 backend's (below). Both need + * CONFIG_DRM_APPLE_DCP_T8132, which matches the T8132 nodes. + * + * ASSUMED, NOT TRACED: the T8132 26B123 image (B3BA603C) numbers its + * IOMFB methods as the T6041 (964EDE5B) and T8142 26B123 images do + * (dcp_methods_27_2), and calls the same D-callbacks. A trace of macOS + * 27.2 driving the mini's dcpext0 has to confirm the A4xx/A5xx IDs + * before this is relied on. + */ + if (apple_t8132_dcpext_v27_2(dev->of_node)) { + /* Checked by apple_t8132_dcpext_v27_2(). */ + dcp_read_fw_version(dev, "apple,firmware-compat", compat_str); + return dcp_v27_method_table(dev, compat_str); + } + if (hw->firmware_compat == DCP_FIRMWARE_V_27_0) { ret = dcp_read_fw_version(dev, "apple,firmware-compat", compat_str); if (ret < 0) { @@ -6782,8 +6801,9 @@ static void dcp_ext_give_up(struct apple_dcp *dcp, int err, const char *when); /* * The external processors whose failure must not take the DRM device down: - * T8122's, T6041's, T6050's and T8142's dcpext. One that fails to probe or bind joins - * as an unusable pipe (ext_dead), and the other displays go on without it. + * T8122's, T6041's, T6050's and T8142's dcpext, and the J773g's on 27.2. One + * that fails to probe or bind joins as an unusable pipe (ext_dead), and the + * other displays go on without it. * With every processor failed the DRM device has no pipe and does not bind. */ static bool dcp_ext_is_failsafe(struct device_node *np) @@ -6791,7 +6811,8 @@ static bool dcp_ext_is_failsafe(struct device_node *np) return of_device_is_compatible(np, "apple,t8122-dcpext") || of_device_is_compatible(np, "apple,t6041-dcpext") || of_device_is_compatible(np, "apple,t6050-dcpext") || - of_device_is_compatible(np, "apple,t8142-dcpext"); + of_device_is_compatible(np, "apple,t8142-dcpext") || + apple_t8132_dcpext_v27_2(np); } /* @@ -7164,6 +7185,32 @@ static void dcp_t8132_ext_routes(struct apple_dcp *dcp) static int dcp_s2r_pm_register(struct apple_dcp *dcp); +/* + * T8132 (Mac mini, J773g) external processor on firmware 27.2, admitted by + * dcp_check_firmware_version(): what the T6041 dcpext gets on that firmware + * (see dcp_platform_probe_pipe()), whatever hw data the compatible matched. + * - firmware_dma_bits 41: its firmware DART's window (ADT dart-dcpext0 + * vm-base 1 TiB, vm-size-23 64 GiB; apple,dma-range <0x100 0 0x10 0>) + * ends at 1 TiB + 64 GiB, which takes 41 bits, as on T6041. + * - num_dptx_ports 2: the dcpdptx-port-epic units 0 and 1 every external + * processor of this generation has (T6041's, and T8132's own on the M4 + * path); the fixed HDMI port is unit 0. + * - adopt_live_session: iBoot leaves it running with the 27.2 image + * loaded (ADT pre-loaded = running = 1), as the boot loader hands it + * over; Linux never starts its CPU. + * - sink_metadata_edid: the display it finds at boot is its first sink, + * as on the T6041 dcpext. + * No sleep support: neither a firmware-27 sleep nor a link release has run + * on this processor. + */ +static const struct apple_dcp_hw_data apple_dcp_hw_t8132_dcpext_v27 = { + .firmware_dma_bits = 41, + .num_dptx_ports = 2, + .adopt_live_session = true, + .firmware_compat = DCP_FIRMWARE_V_27_0, + .sink_metadata_edid = true, +}; + static int dcp_platform_probe_pipe(struct platform_device *pdev) { const struct apple_dcp_hw_data *hw = of_device_get_match_data(&pdev->dev); @@ -7364,6 +7411,9 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) /* Its ports where they have been opened so far, see dcp_v27_dptx_layout(). */ dcp->hw.dptx_endpoint = DPTX_ENDPOINT_V2; } + if (fw_compat == DCP_FIRMWARE_V_27_0 && + of_device_is_compatible(dev->of_node, "apple,t8132-dcpext")) + dcp->hw = apple_dcp_hw_t8132_dcpext_v27; /* * A SoC with derived power words is offered the stop only when asked for, and only on * firmware 27.0, whose calls are the ones that ran with them. @@ -10141,7 +10191,10 @@ static const struct of_device_id of_match[] = { { .compatible = "apple,t8142-dcp", .data = &apple_dcp_hw_t8142, }, #if IS_ENABLED(CONFIG_DRM_APPLE_DCP_T8132) { .compatible = "apple,t8132-dcp", .data = &apple_dcp_hw_t8132, }, - /* Same firmware as the internal DCP; adopted from the boot loader. */ + /* + * Same firmware as the internal DCP; adopted from the boot loader. The + * J773g's on 27.2 is a firmware-27 pipe (apple_dcp_hw_t8132_dcpext_v27). + */ { .compatible = "apple,t8132-dcpext", .data = &apple_dcp_hw_t8132_dcpext, }, #endif { .compatible = "apple,t6030-dcp", .data = &apple_dcp_hw_t6030, }, diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py index ad07edf47e59..f4ff686713ef 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py @@ -199,8 +199,9 @@ def t6041_v27_admission(root): display_h = (root / 'include/linux/soc/apple/display.h').read_text() uuid_defines = [line for line in display_h.splitlines() if line.startswith(('#define APPLE_T6041_DCP_26B123_UUID ', - '#define APPLE_T8122_DCP_26B123_UUID '))] - assert len(uuid_defines) == 2 + '#define APPLE_T8122_DCP_26B123_UUID ', + '#define APPLE_T8132_DCP_26B123_UUID '))] + assert len(uuid_defines) == 3 helper = '\n'.join((*uuid_defines, *( block(display_h, 'static inline bool ' + name + '(') for name in ( 'apple_dcp_image_v27_2', @@ -217,6 +218,13 @@ def t6041_v27_admission(root): selector_full = block(dcp_c, 'static enum dcp_firmware_version dcp_check_firmware_version(') cutoff = '\n\tret = dcp_read_fw_version(dev, "apple,firmware-compat", compat_str);\n\tif (ret < 0)' selector = selector_full[:selector_full.index(cutoff)] + '\n\t(void)v14_board;\n\treturn DCP_FIRMWARE_UNKNOWN;\n}\n' + # The J773g's admission, with its machine check as a flag: no of_machine_is_compatible() + # exists in this translation unit, so the T6041 helpers cannot depend on the machine. + t8132_h = (root / 'include/linux/soc/apple/t8132.h').read_text() + t8132_admission = block(t8132_h, 'static inline bool apple_t8132_dcpext_v27_2(') + assert t8132_admission.count('of_machine_is_compatible("apple,j773g")') == 1 + t8132_admission = ('static bool machine_j773g;\n' + + t8132_admission.replace('of_machine_is_compatible("apple,j773g")', 'machine_j773g')) return r''' #include #include @@ -320,7 +328,7 @@ def t6041_v27_admission(root): snprintf(out, DCP_FW_VERSION_STR_LEN, "%u.%u.%u", v[0], v[1], v[2]); return 3; } -''' + helper + '\n' + methods_decl + '\n' + v27_tables + '\n' + method_table + '\n' + selector + r''' +''' + helper + '\n' + methods_decl + '\n' + v27_tables + '\n' + t8132_admission + '\n' + method_table + '\n' + selector + r''' static struct device_node node; static struct apple_dcp_hw_data hw_t6041; static struct device dev = { .of_node = &node, .hw = &hw_t6041 }; @@ -446,10 +454,49 @@ def t6041_v27_admission(root): assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_UNKNOWN); } + /* + * The Mac mini's (J773g) dcpext handed over with the T8132 27.2 image runs + * the 27.2 table; nothing else of T8132 does, whatever the firmware path. + */ + reset_t6041_26b123(true); + node.compatible = "apple,t8132-dcpext"; + node.uuid = APPLE_T8132_DCP_26B123_UUID; + assert(!apple_t6041_dcpext_v27_2(&node)); + for (unsigned path = 0; path < 2; path++) { + t8132_firmware_path = path; + machine_j773g = true; + assert(apple_t8132_dcpext_v27_2(&node)); + assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_V_27_0); + /* Another M4 Mac (J713, J604): the M4 backend's, as before. */ + machine_j773g = false; + assert(!apple_t8132_dcpext_v27_2(&node)); + assert(dcp_check_firmware_version(&dev) == (path ? DCP_FIRMWARE_M4 : DCP_FIRMWARE_UNKNOWN)); + } + t8132_firmware_path = false; + machine_j773g = true; + /* The internal DCP is never admitted: macOS parks it; aura hands it to nobody. */ + node.compatible = "apple,t8132-dcp"; + assert(!apple_t8132_dcpext_v27_2(&node)); + assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_UNKNOWN); + /* The T6041 image, a missing or second UUID, and other releases are refused. */ + node.compatible = "apple,t8132-dcpext"; + node.uuid = APPLE_T6041_DCP_26B123_UUID; + assert(!apple_t8132_dcpext_v27_2(&node)); + assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_UNKNOWN); + node.uuid = APPLE_T8132_DCP_26B123_UUID; + node.uuid_count = 0; assert(!apple_t8132_dcpext_v27_2(&node)); + node.uuid_count = 2; assert(!apple_t8132_dcpext_v27_2(&node)); + node.uuid_count = 1; + node.compat[1] = 0; assert(!apple_t8132_dcpext_v27_2(&node)); + assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_UNKNOWN); + node.compat[1] = 2; node.fw[2] = 1; assert(!apple_t8132_dcpext_v27_2(&node)); + node.fw[2] = 0; assert(apple_t8132_dcpext_v27_2(&node)); + machine_j773g = false; + dev.hw = &hw_t6041; puts("PASS T6041 26B123 v27.2 internal/external admission, refusal controls, and desktop 26.x preservation"); puts("PASS T8122 internal DCP on its 27.2 image alone runs the 27.2 table"); - puts("PASS T8132 M4 backend only on its firmware path"); + puts("PASS T8132 M4 backend only on its firmware path; the J773g dcpext on 27.2 alone runs the 27.2 table"); return 0; } ''' From 135817ee37e118151d10b4a16114c0edef2a8e4d Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Fri, 20 Nov 2026 00:28:37 -0500 Subject: [PATCH 04/11] drm/apple: dcp: drive the J773g HDMI port from dcpext0 as the J575c does macOS 27.2 drives the Mac mini's HDMI port from DCPEXT0 alone (4K60 without DSC, 4K120 with DSC, FRL on the PS190 converter): the LPDPTX PHY with source select = dcpext0's dcp-index 1, the converter's rails on SMC GPIOs 15 (hdmi_pwr_en) and 26 (dp2hdmi_pwr_en), and no Type-C crossbar route. That is the M4 Max Mac Studio's (J575c) HDMI port: the same converter, rails and LPDPTX PHY ("dptx-phy,t8132" in both ADTs), which its T6041 dcpext0 drives on 27.2 as a desktop external processor. Make the J773g's firmware-27 dcpext a desktop external processor too (dcp->desktop_external, now the one test dcp_desktop_external() reads), so it takes the J575c's fixed-port path rather than porting the M4 backend's (dcp_t8132_fixed_hdmi on 26.6.2): - its fixed dp-phy is initialised and powered at probe (dcp_desktop_probe_routes()), and the converter rails get their 100 ms before the DCP asks for the link; - a direct crossbar link request takes the T6041 path, not the T6050 crossbar one (dcp_direct_crossbar_link()); with no crossbar or route described it has nothing to do. The HPD line, the rails, the PHY and the connector type come from the device tree, as on J575c. Signed-off-by: Diljit Singh --- drivers/gpu/drm/apple/dcp-fabric.c | 1 + drivers/gpu/drm/apple/dcp-internal.h | 6 +++++- drivers/gpu/drm/apple/dcp.c | 23 +++++++++++++++++++---- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-fabric.c b/drivers/gpu/drm/apple/dcp-fabric.c index 7ff72bfe6ddd..791c24262f10 100644 --- a/drivers/gpu/drm/apple/dcp-fabric.c +++ b/drivers/gpu/drm/apple/dcp-fabric.c @@ -553,6 +553,7 @@ static int dcp_dpxbar_tunnel_select_source(struct mux_control *mux, int state) return ret; } +/* A desktop external processor on firmware 27: T6041's, or the J773g's T8132 one. */ static bool dcp_t6041_ext_v27(const struct apple_dcp *dcp) { return dcp->fw_compat == DCP_FIRMWARE_V_27_0 && dcp->desktop_external; diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 515e6bf065f0..2042e257f552 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -568,7 +568,11 @@ struct apple_dcp { bool external; /* Any external processor (apple,dcpext), whatever its SoC; set at probe. */ bool dcpext; - /* A desktop 26.x external processor (apple,t6041-dcpext) */ + /* + * A desktop external processor: apple,t6041-dcpext (26.x or 27.2), or + * the J773g's apple,t8132-dcpext on 27.2 (apple_t8132_dcpext_v27_2()), + * which drives the HDMI port the same way. + */ bool desktop_external; /* * A failsafe dcpext (dcp_ext_is_failsafe(): T8122's, T6041's, T6050's): diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 4378f6ad93ca..f44e79ad3266 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -507,7 +507,21 @@ bool dcp_t6041_ext_enabled(void) static bool dcp_desktop_external(struct apple_dcp *dcp) { - return of_device_is_compatible(dcp->dev->of_node, "apple,t6041-dcpext"); + return dcp->desktop_external; +} + +/* + * The T6041 external processors, and the Mac mini's (J773g) T8132 ones on + * macOS 27.2: macOS drives the mini's HDMI port from dcpext0 alone, through + * the LPDPTX PHY (source select = dcp-index 1) and a PS190 DP-to-HDMI + * converter on the same SMC rails (gP0f, gP1a) as the M4 Max Mac Studio's + * (J575c), whose dcpext0 drives its HDMI port the same way. Its fixed PHY is + * powered at probe and its converter rails settle before the link, as there. + */ +static bool dcp_desktop_external_node(const struct device_node *np) +{ + return of_device_is_compatible(np, "apple,t6041-dcpext") || + apple_t8132_dcpext_v27_2(np); } /* @@ -7117,8 +7131,9 @@ static void dcp_desktop_phy_off(void *data) } /* - * The fixed HDMI output of a desktop 26.x external processor (T6041 dcpext0): - * its DP PHY is powered here, as the boot loader's working sequence does. A + * The fixed HDMI output of a desktop external processor (T6041 dcpext0, and + * the J773g's T8132 dcpext0 on 27.2): its DP PHY is powered here, as the + * boot loader's working sequence does. A * Type-C output (dcpext1) has no fixed PHY; the display fabric powers the * PHY of the route a port claims (see dcp_typec_phy_on()). */ @@ -7332,7 +7347,7 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) dcp->ext_failsafe = dcp_ext_is_failsafe(dev->of_node); dcp->dcpext = of_device_is_compatible(dev->of_node, "apple,dcpext"); dcp->external = of_device_is_compatible(dev->of_node, "apple,t6030-dcpext"); - dcp->desktop_external = of_device_is_compatible(dev->of_node, "apple,t6041-dcpext"); + dcp->desktop_external = dcp_desktop_external_node(dev->of_node); dcp->external_native = dcp->external && dcp_t6030_ext_native(dev->of_node); /* * J714s: the internal panel's processor suspends and resumes asynchronously, not in From 79c27af9800edbb757c208e4244c870dd6a9d2c4 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Fri, 20 Nov 2026 00:28:53 -0500 Subject: [PATCH 05/11] dt-bindings: phy: apple,dptx-phy: add the T8132 LPDPTX PHY The Mac mini (J773g) drives its HDMI port through the T8132's own LPDPTX PHY (ADT /arm-io/dptx-phy, "dptx-phy,t8132", crossbar dfp-endpoint 4). The M4 Max Mac Studio's HDMI PHY is the same block ("dptx-phy,t8132" in its ADT too) and is described as the T6050 layout with the ADT's PLL calibration. Allow apple,t8132-dptx-phy with the same fallback, and the calibration's sixth value, RODCOROLEAKCOMP, which the driver reads (apple,pll-rodcoroleakcomp) and the mini's ADT sets (0), where the Studio's leaves it unset. Signed-off-by: Diljit Singh --- Documentation/devicetree/bindings/phy/apple,dptx-phy.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/phy/apple,dptx-phy.yaml b/Documentation/devicetree/bindings/phy/apple,dptx-phy.yaml index 5e48405d80a1..01dc9abadc88 100644 --- a/Documentation/devicetree/bindings/phy/apple,dptx-phy.yaml +++ b/Documentation/devicetree/bindings/phy/apple,dptx-phy.yaml @@ -24,6 +24,7 @@ select: - apple,t6041-dptx-phy - apple,t6050-dptx-phy - apple,t8122-dptx-phy + - apple,t8132-dptx-phy required: - compatible @@ -36,7 +37,9 @@ properties: - const: apple,dptx-phy - const: apple,t6050-dptx-phy - items: - - const: apple,t6041-dptx-phy + - enum: + - apple,t6041-dptx-phy + - apple,t8132-dptx-phy - const: apple,t6050-dptx-phy reg: @@ -63,7 +66,7 @@ properties: The display crossbar's upstream-facing endpoint that feeds this PHY. patternProperties: - '^apple,(pll-(dcocfg|dtcvreg|dtccal|dcdadj|dlfcfg)|pclkdrv-select)$': + '^apple,(pll-(dcocfg|dtcvreg|dtccal|dcdadj|dlfcfg|rodcoroleakcomp)|pclkdrv-select)$': $ref: /schemas/types.yaml#/definitions/uint32 description: PLL and pixel clock driver settings the PHY is programmed with, as the From e4d7957f27b485b2c216f2c94b8d6f95284a25fa Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Fri, 20 Nov 2026 00:30:04 -0500 Subject: [PATCH 06/11] soc: apple: display-gate: enable the J773g HDMI chain on macOS 27.2 On macOS 27.2 the Mac mini (J773g) is off the M4 26.6.2 firmware path, so the display gate did nothing for it. aura hands it over as it hands over the M4 Max Mac Studio (J575c): dcpext0's (and dcpext1's) firmware memory and firmware clocks, the main DCP left running idle, and the display subsystem and its DART enabled on iBoot's boot framebuffer, with every dcpext node left disabled for this gate. Add a J773g gate that does what gate_t6041_max_run() does for the J575c's HDMI chain: once dcpext0 has its firmware memory, the display subsystem is enabled and the image is the pinned 27.2 one (apple_t8132_dcpext_v27_2()), enable the LPDPTX PHY, dcpext0's firmware and display DARTs, its mailbox, its PIODMA child and dcpext0 in one changeset. A chain that is not all there and disabled is left alone, as there. It runs only off the M4 firmware path; on 26.6.2 the J713 dcpext route handling runs instead, unchanged. One difference from the J575c: the display subsystem's iommus become dispext0's DART rather than having it appended. The main pipe's display DART (disp0) belongs to the running main DCP, which nothing hands over on this firmware and which apple-dart never probes there; left in the iommus it would hold the display subsystem's probe forever. The main DCP's own nodes are left as the device tree has them. Signed-off-by: Diljit Singh --- drivers/soc/apple/display-gate.c | 145 +++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) diff --git a/drivers/soc/apple/display-gate.c b/drivers/soc/apple/display-gate.c index 2830a17ae6ca..e2dce8a89f54 100644 --- a/drivers/soc/apple/display-gate.c +++ b/drivers/soc/apple/display-gate.c @@ -84,6 +84,13 @@ * display processor's firmware memory. The gate enables a chain once its * processor has that memory and the display subsystem is enabled, before any * device exists (see gate_t6041_max_run()). + * + * The M4 Mac mini (J773g, apple,t8132) on macOS 27.2 is handed over as the + * J575c is: aura fills dcpext0's and dcpext1's firmware memory, adds their + * firmware clocks, leaves the main DCP running idle and enables the display + * subsystem on iBoot's boot framebuffer. The gate enables the HDMI chain + * behind dcpext0 the same way (see gate_t8132_j773g_run()). On the M4 26.6.2 + * firmware path the J713 dcpext routes below apply instead. */ #define pr_fmt(fmt) fmt @@ -362,12 +369,28 @@ static const struct gate_soc gate_t6041_max __initconst = { .run = gate_t6041_max_run, }; +static void __init gate_t8132_j773g_run(void); + +/* + * T8132 Mac mini (J773g) off the M4 26.6.2 firmware path: no internal display + * handoff, only its HDMI chain, as on the J575c. + */ +static const struct gate_soc gate_t8132_j773g __initconst = { + .machine = "apple,j773g", + .prefix = "apple-t8132-display: ", + .name = "T8132", + .dcp_compat = "apple,t8132-dcp", + .display_compat = "apple,t8132-display-subsystem", + .run = gate_t8132_j773g_run, +}; + static const struct gate_soc *const gate_socs[] __initconst = { &gate_t6030, &gate_t8122, &gate_t6031, &gate_t6041, &gate_t6041_max, + &gate_t8132_j773g, }; /* The SoC this boot runs on, if the gate serves it. */ @@ -3398,6 +3421,128 @@ static void __init gate_j713_dcpext_routes(void) gate_cs_free(cs); } +/* + * The J773g's HDMI chain on macOS 27.2 (t8132-j773g.dts): the LPDPTX PHY, + * dcpext0's firmware and display DARTs, its mailbox, its PIODMA child, then + * dcpext0. As on the J575c no PMP runs and no DISPEXT0 power domain is + * described for them: iBoot leaves the pipe powered. No Type-C route: dcpext0 + * drives only the HDMI port here. + */ +static const char *const t8132_j773g_hdmi_nodes[] = { + "/soc/phy@39a700000", + "/soc/iommu@286340000", + "/soc/iommu@286300000", + "/soc/mailbox@286e08000", + "/soc/dcp@286e00000/piodma", + "/soc/dcp@286e00000", +}; + +static const struct gate_staged t8132_j773g_hdmi = { + "/soc/iommu@286300000", t8132_j773g_hdmi_nodes, ARRAY_SIZE(t8132_j773g_hdmi_nodes), +}; + +/* Applied, it stays: the live tree refers to it. */ +static struct of_changeset t8132_j773g_cs; + +/* The display subsystem's iommus become <@dart 0>, whatever they were. */ +static int __init gate_iommus_set(struct of_changeset *cs, struct device_node *display, + struct device_node *dart) +{ + struct property *prop; + __be32 *value; + + if (!dart->phandle) + return -EINVAL; + prop = kzalloc_obj(*prop); + value = kmalloc(2 * sizeof(*value), GFP_KERNEL); + if (!prop || !value) { + kfree(prop); + kfree(value); + return -ENOMEM; + } + value[0] = cpu_to_be32(dart->phandle); + value[1] = cpu_to_be32(0); + prop->name = "iommus"; + prop->length = 2 * sizeof(*value); + prop->value = value; + return of_changeset_update_property(cs, display, prop); +} + +/* + * The J773g on macOS 27.2: dcpext0 drives the HDMI port, as macOS does there, + * through the firmware-27 backend (apple_t8132_dcpext_v27_2()). Its chain is + * enabled in one changeset once aura has given dcpext0 its firmware memory and + * enabled the display subsystem, and only for the pinned 27.2 image. + * + * The display subsystem's iommus are set to dispext0's DART instead of having + * it appended, as on the J575c: the main pipe's display DART (disp0) belongs + * to the main DCP, which iBoot leaves running and nothing hands over on this + * firmware, and the DART driver never probes it there (apple-dart.c). Left in + * the iommus, it would hold the display subsystem's probe forever. The main + * DCP's own nodes are left as the device tree has them: its driver refuses it + * off the M4 firmware path (dcp_check_firmware_version()). + */ +static void __init gate_t8132_j773g_run(void) +{ + const struct gate_staged *st = &t8132_j773g_hdmi; + const char *dcp_path = st->nodes[st->nr - 1]; + struct device_node *display, *np; + bool approved; + unsigned int i; + int ret; + + if (IS_ENABLED(CONFIG_VIDEO) && video_firmware_drivers_only()) + return; + staged_prefix = gate_soc->prefix; + + np = of_find_node_by_path(dcp_path); + if (!np) + return; /* a tree without the external pipes */ + approved = apple_t8132_dcpext_v27_2(np); + if (!approved && of_property_present(np, "apple,firmware-compat")) + staged_info("%s: not the 27.2 (26B123) image, HDMI left off\n", dcp_path); + of_node_put(np); + if (!approved) + return; + + display = of_find_node_by_path("disp0"); + if (!display || !of_device_is_compatible(display, gate_soc->display_compat)) { + staged_err("no display subsystem, HDMI left off\n"); + of_node_put(display); + return; + } + if (!of_device_is_available(display)) { + staged_info("display subsystem not enabled, HDMI left off\n"); + of_node_put(display); + return; + } + if (!staged_ready(st)) { + of_node_put(display); + return; + } + + of_changeset_init(&t8132_j773g_cs); + np = of_find_node_by_path(st->dart); + ret = np ? gate_iommus_set(&t8132_j773g_cs, display, np) : -ENODEV; + of_node_put(np); + for (i = 0; !ret && i < st->nr; i++) { + np = of_find_node_by_path(st->nodes[i]); + ret = np ? of_changeset_update_prop_string(&t8132_j773g_cs, np, "status", "okay") : + -ENODEV; + of_node_put(np); + } + if (!ret) + ret = of_changeset_apply(&t8132_j773g_cs); + if (ret) { + of_changeset_destroy(&t8132_j773g_cs); + staged_err("%s: could not enable the HDMI chain: %d\n", dcp_path, ret); + } else { + staged_info("%s enabled for HDMI; display subsystem on %s only\n", dcp_path, + st->dart); + } + of_node_put(display); +} + /* Runs before of_platform_default_populate_init() at arch_initcall_sync. */ static int __init apple_display_gate(void) { From 9dd242c0e804ea743b4a2bf41df22fc39e6d33f4 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Fri, 20 Nov 2026 00:32:17 -0500 Subject: [PATCH 07/11] arm64: dts: apple: t8132-j773g: describe the HDMI port on dcpext0 for 27.2 On macOS 27.2 the Mac mini drives its HDMI port from DCPEXT0 alone, through the LPDPTX PHY (source select = dcpext0's dcp-index 1) and the PS190 DP-to-HDMI converter, whose rails are SMC GPIOs 15 and 26. It is the M4 Max Mac Studio's HDMI port, so describe it in the J575c's style (t6041-j575c-hdmi.dtsi), from the mini's 27.2 ADT: - dcpext0's firmware memory as three disabled apple,asc-mem placeholders named text, data and heap, for aura to fill; - the PHY (ADT /arm-io/dptx-phy, "dptx-phy,t8132", core and dptx banks at 0x39a700000/0x39a740000) in the T6050 layout with the ADT's PLL calibration, crossbar ufp-endpoint 0 (dispext0), disabled; - dcpext0 as an HDMI-A port: that PHY at crossbar output 4, hdmi_hpd on AOP GPIO 41, hdmi_pwr_en and dp2hdmi_pwr_en on SMC gP0f and gP1a; - no power domain on dcpext0, its mailbox and DARTs: no PMP runs off the M4 firmware path and iBoot leaves DISPEXT0 powered, as on the J575c (and as the 26.6.2 HDMI work found for this pipe). - DISPEXT0_FE always on: only the boot framebuffer holds it (and DISPEXT0_SYS through it), so once the display driver removes that, genpd would power the front end off under the running dcpext0. The T8132 PMGR driver leaves its auto-enable bits alone either way. Everything stays disabled: the display gate enables the chain on 27.2. The main DCP, its DARTs and the display subsystem are left as they were, so a 26.6.2 boot, whose main-DCP HDMI path enables them from the board tree, keeps them. On 26.6.2 the M4 PMGR policy still decides whether DISPEXT0_FE is Linux's at all; always-on only applies where it is and the policy does not give it to the firmware. Signed-off-by: Diljit Singh --- arch/arm64/boot/dts/apple/t8132-j773g.dts | 114 +++++++++++++++++++++- 1 file changed, 113 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/t8132-j773g.dts b/arch/arm64/boot/dts/apple/t8132-j773g.dts index baf3e3ffcfec..3d0ffe608fb8 100644 --- a/arch/arm64/boot/dts/apple/t8132-j773g.dts +++ b/arch/arm64/boot/dts/apple/t8132-j773g.dts @@ -4,7 +4,8 @@ * * target-type: J773g * - * Wired from the J773g ADT (macOS 26.6.2). + * Wired from the J773g ADT (macOS 26.6.2; the HDMI port on dcpext0 from the + * macOS 27.2 one). * * Copyright The Asahi Linux Contributors */ @@ -43,6 +44,117 @@ power-domains = <&ps_dispext0_fe>, <&ps_dptx_phy>; }; +/* + * The HDMI port as macOS 27.2 drives it: from dispext0 alone (4K60, and + * 4K120 with DSC; the main DCP started and then parked), through the LPDPTX + * PHY and the PS190 DP-to-HDMI converter. It is the M4 Max Mac Studio's HDMI + * port (t6041-j575c-hdmi.dtsi): the same PHY block, converter and rails, and + * it is handed over the same way, on the firmware-27 backend. + * + * Every node is disabled. On macOS 27.2 the boot loader (aura) fills + * dcpext0's firmware memory and firmware clocks, leaves the main DCP running + * idle, and enables the display subsystem on iBoot's framebuffer; the display + * gate (drivers/soc/apple/display-gate.c) then enables this chain and points + * the display subsystem at dispext0's DART. On the M4 26.6.2 firmware path + * none of it is enabled from here. + */ +/ { + reserved-memory { + /* Filled by the boot loader on macOS 27.2, as the J575c's. */ + dcpext0_text: dcpext0-text { + compatible = "apple,asc-mem"; + reg = <0x0 0x0 0x0 0x4000>; + no-map; + status = "disabled"; + }; + + dcpext0_data: dcpext0-data { + compatible = "apple,asc-mem"; + reg = <0x0 0x0 0x0 0x4000>; + no-map; + status = "disabled"; + }; + + dcpext0_heap: dcpext0-heap { + compatible = "apple,asc-mem"; + reg = <0x0 0x0 0x0 0x4000>; + no-map; + status = "disabled"; + }; + }; +}; + +&soc { + /* + * ADT /arm-io/dptx-phy (dptx-phy,t8132, as the J575c's lpdptx-phy0): + * the T6050 layout, a core bank and a dptx bank, and the ADT's PLL + * calibration (FD0FD1SWAP unset). The display crossbar's dfp-endpoint 4 + * (lpdptx); dispext0 is its ufp-endpoint 0, which the PHY's source + * select takes as 1, dcpext0's apple,dcp-index. + */ + lpdptx_phy: phy@39a700000 { + compatible = "apple,t8132-dptx-phy", "apple,t6050-dptx-phy"; + reg = <0x3 0x9a700000 0x0 0x4000>, + <0x3 0x9a740000 0x0 0x10000>; + reg-names = "core", "dptx"; + power-domains = <&ps_dptx_phy>; + #phy-cells = <0>; + #reset-cells = <0>; + apple,ufp-endpoint = <0>; + apple,pll-dcocfg = <0x4>; + apple,pll-dtcvreg = <0xf>; + apple,pll-dtccal = <0x2>; + apple,pll-dcdadj = <0x10>; + apple,pll-dlfcfg = <0x3>; + apple,pll-rodcoroleakcomp = <0x0>; + status = "disabled"; + }; +}; + +/* + * No PMP runs off the M4 firmware path, and iBoot leaves DISPEXT0 powered + * with its CPU domain under hardware control: as on the J575c, the pipe has + * no power domain here, and Linux never switches it. Its front end (and + * through it DISPEXT0_SYS) is held by the boot framebuffer only: keep it on + * once the display driver has taken over, or the domain would be powered off + * under the running processor. + */ +&ps_dispext0_fe { + apple,always-on; +}; + +&dcpext0_mbox { + /delete-property/ power-domains; +}; + +&dcpext0_dart { + /delete-property/ power-domains; +}; + +&dispext0_dart { + /delete-property/ power-domains; +}; + +/* + * ADT /arm-io/dp2hdmi-gpio0: hdmi_hpd on AOP GPIO 41, hdmi_pwr_en on SMC + * gP0f and dp2hdmi_pwr_en on SMC gP1a (the J575c's rails). No Type-C route: + * dcpext0 drives only this port. + */ +&dcpext0 { + /delete-property/ power-domains; + apple,iomfb-surfaces = <1 1 0 0>; + apple,connector-type = "HDMI-A"; + hdmi-hpd-gpios = <&pinctrl_aop 41 GPIO_ACTIVE_HIGH>; + hdmi-pwren-gpios = <&smc_gpio 15 GPIO_ACTIVE_HIGH>; + dp2hdmi-pwren-gpios = <&smc_gpio 26 GPIO_ACTIVE_HIGH>; + phys = <&lpdptx_phy>; + phy-names = "dp-phy"; + /* the crossbar's output 4 (ADT dptx-phy dp-switch-dfp-endpoint) */ + apple,dptx-phy = <4>; + memory-region = <&dcpext0_text>, <&dcpext0_data>, <&dcpext0_heap>; + memory-region-names = "text", "data", "heap"; +}; + /* * Without this, the PMP firmware faults in the PMC block (0x382800000) * shortly after it starts on this board. J713 keeps ps_pmc out of Linux From 0b2f60befbfab87990e8fbaf48ce4b842eb0e122 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Fri, 20 Nov 2026 19:28:26 -0500 Subject: [PATCH 08/11] soc: apple: t8132: admit a 27.2 dcpext by its processor and image, not its board apple_t8132_dcpext_v27_2() also required of_machine_is_compatible( "apple,j773g"). The firmware interface belongs to the coprocessor and the image it runs, and both are already checked: an apple,t8132-dcpext node with the T8132 27.2 (26B123) image UUID and firmware version and compatibility 27.2.0. What differs between T8132 boards (the J773g's fixed HDMI port, its LPDPTX PHY, converter rails and hot-plug line) is described in each board's device tree, and the driver takes it from there. RyanTheTide asked for this in the review of aurora-silicon/linux#2541. Drop the board check. The apple-dcp boot unit now asserts that the admission has no machine check and that a T8132 dcpext on the 27.2 image is admitted on either firmware path. Signed-off-by: Diljit Singh --- drivers/gpu/drm/apple/apple_drv.c | 4 ++-- include/linux/soc/apple/t8132.h | 14 +++++------ .../selftests/drivers/gpu/apple-dcp/boot.py | 23 +++++++------------ 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/apple/apple_drv.c b/drivers/gpu/drm/apple/apple_drv.c index d791d22ec6d1..de0dbb7a5976 100644 --- a/drivers/gpu/drm/apple/apple_drv.c +++ b/drivers/gpu/drm/apple/apple_drv.c @@ -1480,7 +1480,7 @@ static const struct of_device_id apple_dcp_id_tbl[] = { #if IS_ENABLED(CONFIG_DRM_APPLE_DCP_T8132) { .compatible = "apple,t8132-dcp" }, #endif - /* apple_dcp_usable(): only a J773g one on firmware 27.2. */ + /* apple_dcp_usable(): only one on firmware 27.2 (apple_t8132_dcpext_v27_2()). */ { .compatible = "apple,t8132-dcpext" }, {}, }; @@ -1509,7 +1509,7 @@ static bool apple_dcp_usable(struct device_node *np) apple_t8132_firmware_path()) && /* * A T8132 dcpext the M4 backend adopts is no component: its - * outputs are t8132_ext_drm.c's. The J773g's on 27.2 is a pipe. + * outputs are t8132_ext_drm.c's. One on the 27.2 image is a pipe. */ (!of_device_is_compatible(np, "apple,t8132-dcpext") || apple_t8132_dcpext_v27_2(np)); diff --git a/include/linux/soc/apple/t8132.h b/include/linux/soc/apple/t8132.h index 9a0607a7eb96..72ece899b148 100644 --- a/include/linux/soc/apple/t8132.h +++ b/include/linux/soc/apple/t8132.h @@ -56,16 +56,16 @@ static inline bool apple_t8132_firmware_path(void) } /* - * A T8132 external display processor on the Mac mini (J773g) handed over - * with the 27.2 image: it runs the firmware-27 backend (iomfb_v27.c), not - * the M4 26.6.2 one (iomfb_m4.c). Other T8132 boards and images are not - * admitted until a trace of theirs says the same interface applies. Kept - * here, not in display.h, whose T6041 helpers key on the processor alone. + * A T8132 external display processor handed over with the 27.2 image + * (first on the Mac mini, J773g): it runs the firmware-27 backend + * (iomfb_v27.c), not the M4 26.6.2 one (iomfb_m4.c). The firmware + * interface belongs to the processor and the image it runs, so both are + * checked and the board is not; what differs between boards (the HDMI + * port, its PHY, rails and hot-plug line) comes from the device tree. */ static inline bool apple_t8132_dcpext_v27_2(const struct device_node *np) { - return of_machine_is_compatible("apple,j773g") && - apple_dcp_image_v27_2(np, "apple,t8132-dcpext", + return apple_dcp_image_v27_2(np, "apple,t8132-dcpext", APPLE_T8132_DCP_26B123_UUID); } diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py index f4ff686713ef..543e5be16969 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py @@ -218,13 +218,12 @@ def t6041_v27_admission(root): selector_full = block(dcp_c, 'static enum dcp_firmware_version dcp_check_firmware_version(') cutoff = '\n\tret = dcp_read_fw_version(dev, "apple,firmware-compat", compat_str);\n\tif (ret < 0)' selector = selector_full[:selector_full.index(cutoff)] + '\n\t(void)v14_board;\n\treturn DCP_FIRMWARE_UNKNOWN;\n}\n' - # The J773g's admission, with its machine check as a flag: no of_machine_is_compatible() - # exists in this translation unit, so the T6041 helpers cannot depend on the machine. + # The T8132 27.2 dcpext admission: by processor and image, never by board. No + # of_machine_is_compatible() exists in this translation unit, so neither it nor the T6041 + # helpers can depend on the machine. t8132_h = (root / 'include/linux/soc/apple/t8132.h').read_text() t8132_admission = block(t8132_h, 'static inline bool apple_t8132_dcpext_v27_2(') - assert t8132_admission.count('of_machine_is_compatible("apple,j773g")') == 1 - t8132_admission = ('static bool machine_j773g;\n' + - t8132_admission.replace('of_machine_is_compatible("apple,j773g")', 'machine_j773g')) + assert 'of_machine_is_compatible' not in t8132_admission return r''' #include #include @@ -455,8 +454,9 @@ def t6041_v27_admission(root): } /* - * The Mac mini's (J773g) dcpext handed over with the T8132 27.2 image runs - * the 27.2 table; nothing else of T8132 does, whatever the firmware path. + * A T8132 dcpext handed over with the T8132 27.2 image (first the Mac + * mini's, J773g) runs the 27.2 table, whatever the firmware path and on + * any board: the selection is by processor and image. */ reset_t6041_26b123(true); node.compatible = "apple,t8132-dcpext"; @@ -464,16 +464,10 @@ def t6041_v27_admission(root): assert(!apple_t6041_dcpext_v27_2(&node)); for (unsigned path = 0; path < 2; path++) { t8132_firmware_path = path; - machine_j773g = true; assert(apple_t8132_dcpext_v27_2(&node)); assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_V_27_0); - /* Another M4 Mac (J713, J604): the M4 backend's, as before. */ - machine_j773g = false; - assert(!apple_t8132_dcpext_v27_2(&node)); - assert(dcp_check_firmware_version(&dev) == (path ? DCP_FIRMWARE_M4 : DCP_FIRMWARE_UNKNOWN)); } t8132_firmware_path = false; - machine_j773g = true; /* The internal DCP is never admitted: macOS parks it; aura hands it to nobody. */ node.compatible = "apple,t8132-dcp"; assert(!apple_t8132_dcpext_v27_2(&node)); @@ -491,12 +485,11 @@ def t6041_v27_admission(root): assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_UNKNOWN); node.compat[1] = 2; node.fw[2] = 1; assert(!apple_t8132_dcpext_v27_2(&node)); node.fw[2] = 0; assert(apple_t8132_dcpext_v27_2(&node)); - machine_j773g = false; dev.hw = &hw_t6041; puts("PASS T6041 26B123 v27.2 internal/external admission, refusal controls, and desktop 26.x preservation"); puts("PASS T8122 internal DCP on its 27.2 image alone runs the 27.2 table"); - puts("PASS T8132 M4 backend only on its firmware path; the J773g dcpext on 27.2 alone runs the 27.2 table"); + puts("PASS T8132 M4 backend only on its firmware path; a T8132 dcpext on the 27.2 image runs the 27.2 table on any board"); return 0; } ''' From 7317d4c70cd1407721ca3fc8ece8cbd862e71666 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Fri, 20 Nov 2026 19:28:27 -0500 Subject: [PATCH 09/11] selftests: apple-dcp: readiness: stub the T8132 admission helpers apple_dcp_usable() calls apple_t8132_firmware_path() and apple_t8132_dcpext_v27_2() since this series, and the readiness unit extracts it without linux/soc/apple/t8132.h, so it no longer compiled. No scenario there has a T8132 node: stub both as unreachable, like the T6030 and T6041 helpers next to them. The patch is RyanTheTide's, from the review of aurora-silicon/linux#2541. Signed-off-by: Diljit Singh --- tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py index e41e10447eb2..02fdb3eff477 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py @@ -1579,6 +1579,11 @@ def function(source, marker): /* Nor a T6041 dcpext. */ static bool __attribute__((unused)) dcp_t6041_ext_enabled(void) { assert(!"T6041 dcpext in a J700 scenario"); return false; } +/* Nor a T8132 processor of either backend. */ +static bool __attribute__((unused)) apple_t8132_firmware_path(void) +{ assert(!"T8132 DCP in a J700 scenario"); return false; } +static bool __attribute__((unused)) apple_t8132_dcpext_v27_2(const struct device_node *n) +{ (void)n; assert(!"T8132 dcpext in a J700 scenario"); return false; } static void __attribute__((unused)) iomfb_v14_7_external_refuse(struct apple_dcp *d, const char *why) { (void)d; (void)why; assert(!"T6030 external processor in a J700 scenario"); } struct drm_device { int unused; }; From bc0067c7a0a10a4603e0e72266686a6bf1df1527 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Sat, 21 Nov 2026 16:40:40 -0500 Subject: [PATCH 10/11] soc: apple: display-gate: key T8132 fixed-DP chain on DT phandles Match gate_t8132 on the SoC ("apple,t8132") instead of "apple,j773g" and drop the hard-coded J773g node path table. The M4 Airs still route to gate_j713_dcpext_routes() before gate_socs[] is walked. In gate_t8132_run(), walk apple,t8132-dcpext nodes, select any that names a fixed "dp-phy" and passes apple_t8132_dcpext_v27_2(), and derive its chain from its DT phandles (phys, iommus, mboxes, piodma and piodma's iommus). When the main apple,t8132-dcp is handed over on 27.2 (26B123 image plus apple,clock-ids, e.g. a T8132 laptop with an internal panel), append the external display DART to disp0's iommus instead of replacing it; on a headless Mac mini where the main DCP is not handed over, replace iommus as before. Add tools/asahi/t8132-display-gate-tests.py (registered in tools/asahi/run-host-tests.py) covering phandle-derived chain resolution, replace-vs-append disp0 iommus behavior, and fail-closed controls. Signed-off-by: Diljit Singh --- drivers/soc/apple/display-gate.c | 335 ++++++++--- tools/asahi/run-host-tests.py | 1 + tools/asahi/t8132-display-gate-tests.py | 732 ++++++++++++++++++++++++ 3 files changed, 973 insertions(+), 95 deletions(-) create mode 100755 tools/asahi/t8132-display-gate-tests.py diff --git a/drivers/soc/apple/display-gate.c b/drivers/soc/apple/display-gate.c index e2dce8a89f54..d6580c1c4b0e 100644 --- a/drivers/soc/apple/display-gate.c +++ b/drivers/soc/apple/display-gate.c @@ -85,12 +85,14 @@ * processor has that memory and the display subsystem is enabled, before any * device exists (see gate_t6041_max_run()). * - * The M4 Mac mini (J773g, apple,t8132) on macOS 27.2 is handed over as the - * J575c is: aura fills dcpext0's and dcpext1's firmware memory, adds their - * firmware clocks, leaves the main DCP running idle and enables the display - * subsystem on iBoot's boot framebuffer. The gate enables the HDMI chain - * behind dcpext0 the same way (see gate_t8132_j773g_run()). On the M4 26.6.2 - * firmware path the J713 dcpext routes below apply instead. + * On T8132 (apple,t8132) off the M4 26.6.2 firmware path (first the Mac mini, + * J773g, on macOS 27.2), aura hands over external display processors as on the + * J575c: it fills their firmware memory, adds their firmware clocks, and + * enables the display subsystem on iBoot's boot framebuffer. For any + * apple,t8132-dcpext with a fixed dp-phy running the pinned 27.2 image, the + * gate derives the chain from its phandles and enables it in one changeset + * (see gate_t8132_run()). On the M4 26.6.2 firmware path (and on M4 Airs) the + * J713 dcpext routes below apply instead. */ #define pr_fmt(fmt) fmt @@ -369,19 +371,21 @@ static const struct gate_soc gate_t6041_max __initconst = { .run = gate_t6041_max_run, }; -static void __init gate_t8132_j773g_run(void); +static void __init gate_t8132_run(void); /* - * T8132 Mac mini (J773g) off the M4 26.6.2 firmware path: no internal display - * handoff, only its HDMI chain, as on the J575c. + * T8132 off the M4 26.6.2 firmware path (the Airs take + * gate_j713_dcpext_routes() before gate_socs[] is walked): enable any + * fixed-DP external display chain (phy-names = "dp-phy") running the pinned + * 27.2 image, as on the J575c. */ -static const struct gate_soc gate_t8132_j773g __initconst = { - .machine = "apple,j773g", +static const struct gate_soc gate_t8132 __initconst = { + .machine = "apple,t8132", .prefix = "apple-t8132-display: ", .name = "T8132", .dcp_compat = "apple,t8132-dcp", .display_compat = "apple,t8132-display-subsystem", - .run = gate_t8132_j773g_run, + .run = gate_t8132_run, }; static const struct gate_soc *const gate_socs[] __initconst = { @@ -390,7 +394,7 @@ static const struct gate_soc *const gate_socs[] __initconst = { &gate_t6031, &gate_t6041, &gate_t6041_max, - &gate_t8132_j773g, + &gate_t8132, }; /* The SoC this boot runs on, if the gate serves it. */ @@ -3421,29 +3425,6 @@ static void __init gate_j713_dcpext_routes(void) gate_cs_free(cs); } -/* - * The J773g's HDMI chain on macOS 27.2 (t8132-j773g.dts): the LPDPTX PHY, - * dcpext0's firmware and display DARTs, its mailbox, its PIODMA child, then - * dcpext0. As on the J575c no PMP runs and no DISPEXT0 power domain is - * described for them: iBoot leaves the pipe powered. No Type-C route: dcpext0 - * drives only the HDMI port here. - */ -static const char *const t8132_j773g_hdmi_nodes[] = { - "/soc/phy@39a700000", - "/soc/iommu@286340000", - "/soc/iommu@286300000", - "/soc/mailbox@286e08000", - "/soc/dcp@286e00000/piodma", - "/soc/dcp@286e00000", -}; - -static const struct gate_staged t8132_j773g_hdmi = { - "/soc/iommu@286300000", t8132_j773g_hdmi_nodes, ARRAY_SIZE(t8132_j773g_hdmi_nodes), -}; - -/* Applied, it stays: the live tree refers to it. */ -static struct of_changeset t8132_j773g_cs; - /* The display subsystem's iommus become <@dart 0>, whatever they were. */ static int __init gate_iommus_set(struct of_changeset *cs, struct device_node *display, struct device_node *dart) @@ -3468,77 +3449,241 @@ static int __init gate_iommus_set(struct of_changeset *cs, struct device_node *d return of_changeset_update_property(cs, display, prop); } +enum { + T8132_HDMI_PHY, + T8132_HDMI_FW_DART, + T8132_HDMI_DISP_DART, + T8132_HDMI_MBOX, + T8132_HDMI_PIODMA, + T8132_HDMI_DCP, + T8132_HDMI_NR, +}; + +/* + * Check that every memory-region of @np is an available apple,asc-mem node, + * as staged_firmware_memory() does for path-addressed stages. + */ +static bool __init staged_node_firmware_memory(struct device_node *np) +{ + struct device_node *chosen, *region; + int i, n; + u32 record[2]; + + n = of_count_phandle_with_args(np, "memory-region", NULL); + for (i = 0; i < n; i++) { + region = of_parse_phandle(np, "memory-region", i); + if (region && of_device_is_available(region) && + of_device_is_compatible(region, "apple,asc-mem")) { + of_node_put(region); + continue; + } + of_node_put(region); + n = -ENODEV; + break; + } + if (n > 0) + return true; + chosen = of_find_node_by_path("/chosen"); + if (chosen && !of_property_read_u32_array(chosen, "m4,dcpext", record, 2)) + staged_err("%pOF: no firmware memory (loader record <%u %u>), nothing enabled\n", + np, record[0], record[1]); + else + staged_err("%pOF: no firmware memory, nothing enabled\n", np); + of_node_put(chosen); + return false; +} + +/* + * A T8132 internal display processor handed over with the 27.2 (26B123) image + * and firmware-27 clock metadata (apple,clock-ids): present on a laptop with + * an internal panel (e.g. a 14-inch MacBook Pro), absent on a headless Mac + * mini whose main DCP is left running idle. + */ +static bool __init gate_t8132_dcp_v27_2(const struct device_node *np) +{ + return apple_dcp_image_v27_2(np, "apple,t8132-dcp", + APPLE_T8132_DCP_26B123_UUID) && + of_property_present(np, "apple,clock-ids"); +} + +static void __init gate_t8132_put_nodes(struct device_node *nodes[T8132_HDMI_NR]) +{ + unsigned int i; + + for (i = 0; i < T8132_HDMI_NR; i++) { + of_node_put(nodes[i]); + nodes[i] = NULL; + } +} + +/* + * Derive a fixed-DP T8132 dcpext's chain from its own DT phandles: the dp-phy + * PHY, firmware DART (iommus), display DART (piodma's iommus), mailbox + * (mboxes), piodma child, then the dcpext node itself. + */ +static int __init gate_t8132_resolve_fixed_dp(struct device_node *dcp, + int phy_idx, + struct device_node *nodes[T8132_HDMI_NR]) +{ + struct of_phandle_args args; + + memset(nodes, 0, T8132_HDMI_NR * sizeof(*nodes)); + + if (of_parse_phandle_with_args(dcp, "phys", "#phy-cells", phy_idx, &args)) + goto fail; + nodes[T8132_HDMI_PHY] = args.np; + + if (of_parse_phandle_with_args(dcp, "iommus", "#iommu-cells", 0, &args)) + goto fail; + nodes[T8132_HDMI_FW_DART] = args.np; + + if (of_parse_phandle_with_args(dcp, "mboxes", "#mbox-cells", 0, &args)) + goto fail; + nodes[T8132_HDMI_MBOX] = args.np; + + nodes[T8132_HDMI_PIODMA] = of_get_child_by_name(dcp, "piodma"); + if (!nodes[T8132_HDMI_PIODMA]) + goto fail; + + if (of_parse_phandle_with_args(nodes[T8132_HDMI_PIODMA], "iommus", + "#iommu-cells", 0, &args)) + goto fail; + nodes[T8132_HDMI_DISP_DART] = args.np; + + nodes[T8132_HDMI_DCP] = of_node_get(dcp); + return 0; + +fail: + gate_t8132_put_nodes(nodes); + return -EINVAL; +} + +/* Every node of @nodes is distinct and still disabled, and its processor has firmware memory. */ +static bool __init gate_t8132_fixed_dp_ready(struct device_node *nodes[T8132_HDMI_NR]) +{ + unsigned int i, j; + + if (!staged_node_firmware_memory(nodes[T8132_HDMI_DCP])) + return false; + for (i = 0; i < T8132_HDMI_NR; i++) { + if (!nodes[i]) + return false; + for (j = 0; j < i; j++) { + if (nodes[j] == nodes[i]) { + staged_err("%pOF: duplicate node in chain, nothing enabled\n", + nodes[i]); + return false; + } + } + if (of_device_is_available(nodes[i])) { + staged_err("%pOF: already enabled, nothing changed\n", nodes[i]); + return false; + } + } + return true; +} + /* - * The J773g on macOS 27.2: dcpext0 drives the HDMI port, as macOS does there, - * through the firmware-27 backend (apple_t8132_dcpext_v27_2()). Its chain is - * enabled in one changeset once aura has given dcpext0 its firmware memory and - * enabled the display subsystem, and only for the pinned 27.2 image. + * T8132 on macOS 27.2 (off the M4 26.6.2 firmware path): any apple,t8132-dcpext + * wired to a fixed DP PHY (phy-names = "dp-phy", e.g. the J773g HDMI port) + * runs through the firmware-27 backend (apple_t8132_dcpext_v27_2()). Its chain + * is derived from its DT phandles and enabled in one changeset once aura has + * given it firmware memory and enabled the display subsystem, and only for the + * pinned 27.2 image. * - * The display subsystem's iommus are set to dispext0's DART instead of having - * it appended, as on the J575c: the main pipe's display DART (disp0) belongs - * to the main DCP, which iBoot leaves running and nothing hands over on this - * firmware, and the DART driver never probes it there (apple-dart.c). Left in - * the iommus, it would hold the display subsystem's probe forever. The main - * DCP's own nodes are left as the device tree has them: its driver refuses it - * off the M4 firmware path (dcp_check_firmware_version()). + * When the main DCP is also handed over on 27.2 (a T8132 laptop with an + * internal panel), dispext's display DART is appended to the display + * subsystem's iommus so the internal panel keeps its DART. When the main DCP + * is not handed over (a headless Mac mini), disp0's DART is left unprobed by + * apple-dart and would hold the display subsystem's probe forever, so iommus + * is replaced with dispext's DART instead. */ -static void __init gate_t8132_j773g_run(void) +static void __init gate_t8132_run(void) { - const struct gate_staged *st = &t8132_j773g_hdmi; - const char *dcp_path = st->nodes[st->nr - 1]; - struct device_node *display, *np; - bool approved; + struct device_node *display = NULL, *internal, *dcp; + struct device_node *nodes[T8132_HDMI_NR]; + bool append_dart = false; + bool display_checked = false; unsigned int i; - int ret; + int phy_idx, ret; if (IS_ENABLED(CONFIG_VIDEO) && video_firmware_drivers_only()) return; staged_prefix = gate_soc->prefix; - np = of_find_node_by_path(dcp_path); - if (!np) - return; /* a tree without the external pipes */ - approved = apple_t8132_dcpext_v27_2(np); - if (!approved && of_property_present(np, "apple,firmware-compat")) - staged_info("%s: not the 27.2 (26B123) image, HDMI left off\n", dcp_path); - of_node_put(np); - if (!approved) - return; + for_each_compatible_node(dcp, NULL, "apple,t8132-dcpext") { + struct of_changeset *cs; - display = of_find_node_by_path("disp0"); - if (!display || !of_device_is_compatible(display, gate_soc->display_compat)) { - staged_err("no display subsystem, HDMI left off\n"); - of_node_put(display); - return; - } - if (!of_device_is_available(display)) { - staged_info("display subsystem not enabled, HDMI left off\n"); - of_node_put(display); - return; - } - if (!staged_ready(st)) { - of_node_put(display); - return; - } + phy_idx = of_property_match_string(dcp, "phy-names", "dp-phy"); + if (phy_idx < 0) + continue; - of_changeset_init(&t8132_j773g_cs); - np = of_find_node_by_path(st->dart); - ret = np ? gate_iommus_set(&t8132_j773g_cs, display, np) : -ENODEV; - of_node_put(np); - for (i = 0; !ret && i < st->nr; i++) { - np = of_find_node_by_path(st->nodes[i]); - ret = np ? of_changeset_update_prop_string(&t8132_j773g_cs, np, "status", "okay") : - -ENODEV; - of_node_put(np); - } - if (!ret) - ret = of_changeset_apply(&t8132_j773g_cs); - if (ret) { - of_changeset_destroy(&t8132_j773g_cs); - staged_err("%s: could not enable the HDMI chain: %d\n", dcp_path, ret); - } else { - staged_info("%s enabled for HDMI; display subsystem on %s only\n", dcp_path, - st->dart); + if (!apple_t8132_dcpext_v27_2(dcp)) { + if (of_property_present(dcp, "apple,firmware-compat")) + staged_info("%pOF: not the 27.2 (26B123) image, HDMI left off\n", + dcp); + continue; + } + + if (!display_checked) { + display_checked = true; + display = of_find_node_by_path("disp0"); + if (!display) + display = of_find_compatible_node(NULL, NULL, + gate_soc->display_compat); + if (!display || !of_device_is_compatible(display, + gate_soc->display_compat)) { + staged_err("no display subsystem, HDMI left off\n"); + of_node_put(display); + of_node_put(dcp); + return; + } + if (!of_device_is_available(display)) { + staged_info("display subsystem not enabled, HDMI left off\n"); + of_node_put(display); + of_node_put(dcp); + return; + } + internal = of_find_node_by_path("dcp"); + if (!internal) + internal = of_find_compatible_node(NULL, NULL, + gate_soc->dcp_compat); + append_dart = gate_t8132_dcp_v27_2(internal); + of_node_put(internal); + } + + if (gate_t8132_resolve_fixed_dp(dcp, phy_idx, nodes)) { + staged_err("%pOF: incomplete fixed-DP chain, HDMI left off\n", dcp); + continue; + } + if (!gate_t8132_fixed_dp_ready(nodes)) { + gate_t8132_put_nodes(nodes); + continue; + } + + cs = gate_cs_alloc(); + if (!cs) { + staged_err("%pOF: could not allocate changeset\n", dcp); + gate_t8132_put_nodes(nodes); + continue; + } + ret = append_dart ? + gate_iommus_append(cs, display, nodes[T8132_HDMI_DISP_DART]) : + gate_iommus_set(cs, display, nodes[T8132_HDMI_DISP_DART]); + for (i = 0; !ret && i < T8132_HDMI_NR; i++) + ret = of_changeset_update_prop_string(cs, nodes[i], "status", "okay"); + if (!ret) + ret = of_changeset_apply(cs); + if (ret) { + gate_cs_free(cs); + staged_err("%pOF: could not enable the HDMI chain: %d\n", dcp, ret); + } else { + staged_info("%pOF enabled for HDMI; display subsystem %s %pOF\n", dcp, + append_dart ? "appended" : "on", + nodes[T8132_HDMI_DISP_DART]); + append_dart = true; + } + gate_t8132_put_nodes(nodes); } of_node_put(display); } diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index 8ad9b94ac5b3..e07441a3af90 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -303,6 +303,7 @@ def mutations(flag, names, base, expect=KILL): 't6040-calibration-tests.py': [([], PASS)], 't604x-cpu-order-tests.py': [(out('--output') + ['--dtc', '{dtc}'], PASS)], 't6050-combo-join-tests.py': [([], PASS)], + 't8132-display-gate-tests.py': [([], PASS)], 't8132-usb4-policy-tests.py': [(out('--output') + ['--dtc', '{dtc}'], PASS)], 'tb-cio-sleep-tests.py': [(out('--output'), PASS)], 'tb-dock-pm-tests.py': [(out('--output'), PASS)], diff --git a/tools/asahi/t8132-display-gate-tests.py b/tools/asahi/t8132-display-gate-tests.py new file mode 100755 index 000000000000..9361b8a6008f --- /dev/null +++ b/tools/asahi/t8132-display-gate-tests.py @@ -0,0 +1,732 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only OR MIT +"""Host tests for the T8132 fixed-DP display gate (drivers/soc/apple/display-gate.c).""" +import os +from pathlib import Path +import re +import subprocess +import tempfile + +ROOT = Path(__file__).resolve().parents[2] + + +def extract_block(source, marker): + match = None + for cand in re.finditer(marker, source, re.M): + semi = source.find(';', cand.start()) + brace = source.find('{', cand.start()) + if brace >= 0 and (semi < 0 or brace < semi): + match = cand + break + assert match, f'missing marker: {marker}' + start = match.start() + brace = source.index('{', start) + depth = 1 + pos = brace + 1 + while depth: + depth += (source[pos] == '{') - (source[pos] == '}') + pos += 1 + if pos < len(source) and source[pos] == ';': + pos += 1 + return source[start:pos] + '\n' + + +def main(): + gate_src = (ROOT / 'drivers/soc/apple/display-gate.c').read_text() + disp_hdr = (ROOT / 'include/linux/soc/apple/display.h').read_text() + t8132_hdr = (ROOT / 'include/linux/soc/apple/t8132.h').read_text() + + # Enforce at source level that T8132 fixed-DP gate matches the SoC, not a board name, + # and carries no hard-coded board node paths. + soc_block = extract_block(gate_src, r'^static const struct gate_soc gate_t8132\b') + assert '.machine = "apple,t8132"' in soc_block, soc_block + assert 'j773g' not in soc_block, soc_block + assert 't8132_j773g_hdmi_nodes' not in gate_src + + uuid_lines = '\n'.join( + line for line in disp_hdr.splitlines() + if line.startswith('#define APPLE_T8132_DCP_26B123_UUID') + ) + helpers = '\n'.join([ + uuid_lines, + extract_block(disp_hdr, r'^static inline bool apple_dcp_image_v27_2\('), + extract_block(t8132_hdr, r'^static inline bool apple_t8132_dcpext_v27_2\('), + extract_block(gate_src, r'^static int gate_iommus_append\('), + extract_block(gate_src, r'^static struct of_changeset \*__init gate_cs_alloc\('), + extract_block(gate_src, r'^static void __init gate_cs_free\('), + extract_block(gate_src, r'^static int __init gate_iommus_set\('), + extract_block(gate_src, r'^enum \{\n\tT8132_HDMI_PHY,'), + extract_block(gate_src, r'^static bool __init staged_node_firmware_memory\('), + extract_block(gate_src, r'^static bool __init gate_t8132_dcp_v27_2\('), + extract_block(gate_src, r'^static void __init gate_t8132_put_nodes\('), + extract_block(gate_src, r'^static int __init gate_t8132_resolve_fixed_dp\('), + extract_block(gate_src, r'^static bool __init gate_t8132_fixed_dp_ready\('), + extract_block(gate_src, r'^static void __init gate_t8132_run\('), + ]) + + program = r''' +#include +#include +#include +#include +#include +#include +#include + +typedef uint32_t u32; +typedef uint32_t __be32; +#define __init +#define __initconst +#define GFP_KERNEL 0 +#define CONFIG_VIDEO 1 +#define IS_ENABLED(x) (x) +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) +#define kzalloc_obj(x) calloc(1, sizeof(x)) +#define kmalloc(n, g) malloc(n) +#define kfree(p) free(p) + +static __be32 cpu_to_be32(u32 v) { return __builtin_bswap32(v); } +static u32 be32_to_cpu(__be32 v) { return __builtin_bswap32(v); } + +struct gate_soc { + const char *machine; + const char *prefix; + const char *name; + const char *dcp_compat; + const char *display_compat; +}; + +static const struct gate_soc test_soc = { + .machine = "apple,t8132", + .prefix = "apple-t8132-display: ", + .name = "T8132", + .dcp_compat = "apple,t8132-dcp", + .display_compat = "apple,t8132-display-subsystem", +}; +static const struct gate_soc *gate_soc = &test_soc; +static const char *staged_prefix; +static bool nomodeset; +static unsigned int err_count, info_count; + +#define staged_info(...) do { (void)staged_prefix; info_count++; } while (0) +#define staged_err(...) do { (void)staged_prefix; err_count++; } while (0) + +static bool video_firmware_drivers_only(void) { return nomodeset; } + +struct property { + const char *name; + void *value; + size_t length; +}; + +struct device_node { + const char *path; + const char *alias; + const char *name; + const char *compatible; + u32 phandle; + bool available; + int refcount; + + /* Firmware identity */ + const char *fw_uuid; + int fw_uuid_count; + u32 fw_ver[3]; + int fw_ver_cells; + u32 fw_compat[3]; + int fw_compat_cells; + bool has_clock_ids; + + /* Phandle references */ + const char *phy_names[4]; + int phy_name_count; + struct device_node *phys[4]; + + struct device_node *iommus[4]; + u32 iommu_args[4]; + int iommu_count; + struct property iommus_prop; + __be32 iommus_buf[8]; + + struct device_node *mboxes[2]; + int mbox_count; + + struct device_node *mem_regions[4]; + int mem_region_count; + + struct device_node *piodma_child; +}; + +struct of_phandle_args { + struct device_node *np; + int args_count; + u32 args[4]; +}; + +struct cs_op { + struct device_node *np; + bool is_status; + const char *status; + struct property *prop; +}; + +struct of_changeset { + struct cs_op ops[16]; + unsigned int nops; + bool applied; +}; + +#define MAX_NODES 32 +static struct device_node *all_nodes[MAX_NODES]; +static unsigned int nr_nodes; +static struct of_changeset *applied_cs[8]; +static unsigned int nr_applied_cs; + +static void sync_iommus_prop(struct device_node *np) +{ + int i; + + if (np->iommu_count <= 0) { + np->iommus_prop.name = NULL; + np->iommus_prop.value = NULL; + np->iommus_prop.length = 0; + return; + } + for (i = 0; i < np->iommu_count; i++) { + np->iommus_buf[2 * i] = cpu_to_be32(np->iommus[i]->phandle); + np->iommus_buf[2 * i + 1] = cpu_to_be32(np->iommu_args[i]); + } + np->iommus_prop.name = "iommus"; + np->iommus_prop.value = np->iommus_buf; + np->iommus_prop.length = (size_t)np->iommu_count * 2 * sizeof(__be32); +} + +static struct device_node *of_node_get(struct device_node *np) +{ + if (np) + np->refcount++; + return np; +} + +static void of_node_put(struct device_node *np) +{ + if (np) { + assert(np->refcount > 0); + np->refcount--; + } +} + +static bool of_device_is_compatible(const struct device_node *np, const char *compat) +{ + return np && np->compatible && !strcmp(np->compatible, compat); +} + +static bool of_device_is_available(const struct device_node *np) +{ + return np && np->available; +} + +static bool of_property_present(const struct device_node *np, const char *name) +{ + if (!np) + return false; + if (!strcmp(name, "apple,firmware-compat")) + return np->fw_compat_cells > 0; + if (!strcmp(name, "apple,clock-ids")) + return np->has_clock_ids; + return false; +} + +static int of_property_count_strings(const struct device_node *np, const char *name) +{ + assert(!strcmp(name, "apple,firmware-uuid")); + return np ? np->fw_uuid_count : -EINVAL; +} + +static int of_property_read_string(const struct device_node *np, const char *name, const char **out) +{ + assert(!strcmp(name, "apple,firmware-uuid")); + if (!np || np->fw_uuid_count < 1 || !np->fw_uuid) + return -EINVAL; + *out = np->fw_uuid; + return 0; +} + +static int of_property_count_u32_elems(const struct device_node *np, const char *name) +{ + if (!np) + return -EINVAL; + if (!strcmp(name, "apple,firmware-version")) + return np->fw_ver_cells; + if (!strcmp(name, "apple,firmware-compat")) + return np->fw_compat_cells; + return -EINVAL; +} + +static int of_property_read_u32_array(const struct device_node *np, const char *name, + u32 *out, size_t n) +{ + if (!np) + return -EINVAL; + if (!strcmp(name, "apple,firmware-version") && n == 3 && np->fw_ver_cells == 3) { + memcpy(out, np->fw_ver, 3 * sizeof(u32)); + return 0; + } + if (!strcmp(name, "apple,firmware-compat") && n == 3 && np->fw_compat_cells == 3) { + memcpy(out, np->fw_compat, 3 * sizeof(u32)); + return 0; + } + return -ENOENT; +} + +static int of_property_match_string(const struct device_node *np, const char *prop, const char *val) +{ + int i; + + assert(!strcmp(prop, "phy-names")); + if (!np) + return -EINVAL; + for (i = 0; i < np->phy_name_count; i++) { + if (np->phy_names[i] && !strcmp(np->phy_names[i], val)) + return i; + } + return -ENODATA; +} + +static struct property *of_find_property(struct device_node *np, const char *name, int *lenp) +{ + assert(!strcmp(name, "iommus")); + if (!np || !np->iommus_prop.name) + return NULL; + if (lenp) + *lenp = (int)np->iommus_prop.length; + return &np->iommus_prop; +} + +static int of_count_phandle_with_args(const struct device_node *np, const char *list, + const char *cells) +{ + (void)cells; + if (!np) + return -EINVAL; + if (!strcmp(list, "memory-region")) + return np->mem_region_count; + if (!strcmp(list, "iommus")) + return np->iommu_count; + return -EINVAL; +} + +static struct device_node *of_parse_phandle(const struct device_node *np, const char *name, int idx) +{ + assert(!strcmp(name, "memory-region")); + if (!np || idx < 0 || idx >= np->mem_region_count || !np->mem_regions[idx]) + return NULL; + return of_node_get(np->mem_regions[idx]); +} + +static int of_parse_phandle_with_args(const struct device_node *np, const char *list, + const char *cells, int idx, struct of_phandle_args *out) +{ + (void)cells; + if (!np || idx < 0) + return -EINVAL; + if (!strcmp(list, "phys")) { + if (idx >= np->phy_name_count || !np->phys[idx]) + return -ENOENT; + out->np = of_node_get(np->phys[idx]); + out->args_count = 0; + return 0; + } + if (!strcmp(list, "iommus")) { + if (idx >= np->iommu_count || !np->iommus[idx]) + return -ENOENT; + out->np = of_node_get(np->iommus[idx]); + out->args_count = 1; + out->args[0] = np->iommu_args[idx]; + return 0; + } + if (!strcmp(list, "mboxes")) { + if (idx >= np->mbox_count || !np->mboxes[idx]) + return -ENOENT; + out->np = of_node_get(np->mboxes[idx]); + out->args_count = 0; + return 0; + } + return -EINVAL; +} + +static struct device_node *of_get_child_by_name(const struct device_node *np, const char *name) +{ + assert(!strcmp(name, "piodma")); + return (np && np->piodma_child) ? of_node_get(np->piodma_child) : NULL; +} + +static struct device_node *of_find_node_by_path(const char *path) +{ + unsigned int i; + + for (i = 0; i < nr_nodes; i++) { + if ((all_nodes[i]->path && !strcmp(all_nodes[i]->path, path)) || + (all_nodes[i]->alias && !strcmp(all_nodes[i]->alias, path))) + return of_node_get(all_nodes[i]); + } + return NULL; +} + +static struct device_node *of_find_compatible_node(struct device_node *from, + const char *type, const char *compat) +{ + unsigned int i = 0; + + (void)type; + if (from) { + while (i < nr_nodes && all_nodes[i] != from) + i++; + if (i < nr_nodes) + i++; + of_node_put(from); + } + for (; i < nr_nodes; i++) { + if (of_device_is_compatible(all_nodes[i], compat)) + return of_node_get(all_nodes[i]); + } + return NULL; +} + +#define for_each_compatible_node(dn, type, compatible) \ + for (dn = of_find_compatible_node(NULL, type, compatible); dn; \ + dn = of_find_compatible_node(dn, type, compatible)) + +static struct device_node *find_by_phandle(u32 phandle) +{ + unsigned int i; + + for (i = 0; i < nr_nodes; i++) { + if (all_nodes[i]->phandle == phandle) + return all_nodes[i]; + } + return NULL; +} + +static void of_changeset_init(struct of_changeset *cs) +{ + memset(cs, 0, sizeof(*cs)); +} + +static void of_changeset_destroy(struct of_changeset *cs) +{ + unsigned int i; + + for (i = 0; i < cs->nops; i++) { + if (!cs->ops[i].is_status && cs->ops[i].prop) { + free(cs->ops[i].prop->value); + free(cs->ops[i].prop); + } + } + cs->nops = 0; +} + +static int of_changeset_update_property(struct of_changeset *cs, struct device_node *np, + struct property *prop) +{ + assert(cs->nops < ARRAY_SIZE(cs->ops)); + cs->ops[cs->nops++] = (struct cs_op){ .np = np, .is_status = false, .prop = prop }; + return 0; +} + +static int of_changeset_update_prop_string(struct of_changeset *cs, struct device_node *np, + const char *name, const char *val) +{ + assert(!strcmp(name, "status")); + assert(cs->nops < ARRAY_SIZE(cs->ops)); + cs->ops[cs->nops++] = (struct cs_op){ .np = np, .is_status = true, .status = val }; + return 0; +} + +static int of_changeset_apply(struct of_changeset *cs) +{ + unsigned int i; + + for (i = 0; i < cs->nops; i++) { + struct cs_op *op = &cs->ops[i]; + + if (op->is_status) { + op->np->available = !strcmp(op->status, "okay"); + } else { + const __be32 *vals = op->prop->value; + int n = (int)(op->prop->length / (2 * sizeof(__be32))); + int j; + + assert(!strcmp(op->prop->name, "iommus")); + assert(n >= 1 && n <= 4); + op->np->iommu_count = n; + for (j = 0; j < n; j++) { + op->np->iommus[j] = find_by_phandle(be32_to_cpu(vals[2 * j])); + assert(op->np->iommus[j]); + op->np->iommu_args[j] = be32_to_cpu(vals[2 * j + 1]); + } + sync_iommus_prop(op->np); + } + } + cs->applied = true; + assert(nr_applied_cs < ARRAY_SIZE(applied_cs)); + applied_cs[nr_applied_cs++] = cs; + return 0; +} +''' + helpers + r''' +struct fixture { + struct device_node display, disp0_dart, main_dcp; + struct device_node phy, fw_dart, disp_dart, mbox, piodma, dcpext0; + struct device_node mem_text, mem_data, mem_heap; + struct device_node dcpext1; +}; + +static void register_node(struct device_node *np) +{ + assert(nr_nodes < MAX_NODES); + all_nodes[nr_nodes++] = np; +} + +static void cleanup_applied(void) +{ + unsigned int i; + + for (i = 0; i < nr_applied_cs; i++) { + of_changeset_destroy(applied_cs[i]); + free(applied_cs[i]); + } + nr_applied_cs = 0; +} + +static void check_refs_zero(void) +{ + unsigned int i; + + for (i = 0; i < nr_nodes; i++) + assert(all_nodes[i]->refcount == 0); +} + +static void set_v27_2(struct device_node *np) +{ + np->fw_uuid = APPLE_T8132_DCP_26B123_UUID; + np->fw_uuid_count = 1; + np->fw_ver[0] = 27; np->fw_ver[1] = 2; np->fw_ver[2] = 0; + np->fw_ver_cells = 3; + np->fw_compat[0] = 27; np->fw_compat[1] = 2; np->fw_compat[2] = 0; + np->fw_compat_cells = 3; +} + +static void init_fixture(struct fixture *f) +{ + cleanup_applied(); + memset(f, 0, sizeof(*f)); + nr_nodes = 0; + nomodeset = false; + err_count = info_count = 0; + + /* Deliberately use non-J773g paths to prove resolution is phandle-driven. */ + f->disp0_dart = (struct device_node){ + .path = "/soc/iommu@111100000", .phandle = 10, .available = false, + }; + f->display = (struct device_node){ + .path = "/soc/display-subsystem", .alias = "disp0", + .compatible = "apple,t8132-display-subsystem", + .phandle = 11, .available = true, + .iommus = { &f->disp0_dart }, .iommu_args = { 0 }, .iommu_count = 1, + }; + sync_iommus_prop(&f->display); + + f->main_dcp = (struct device_node){ + .path = "/soc/dcp@111e00000", .alias = "dcp", + .compatible = "apple,t8132-dcp", .phandle = 12, .available = false, + }; + + f->phy = (struct device_node){ + .path = "/soc/phy@999700000", .phandle = 20, .available = false, + }; + f->fw_dart = (struct device_node){ + .path = "/soc/iommu@999340000", .phandle = 21, .available = false, + }; + f->disp_dart = (struct device_node){ + .path = "/soc/iommu@999300000", .phandle = 22, .available = false, + }; + f->mbox = (struct device_node){ + .path = "/soc/mailbox@999e08000", .phandle = 23, .available = false, + }; + f->piodma = (struct device_node){ + .path = "/soc/dcp@999e00000/piodma", .name = "piodma", + .phandle = 24, .available = false, + .iommus = { &f->disp_dart }, .iommu_args = { 16 }, .iommu_count = 1, + }; + sync_iommus_prop(&f->piodma); + + f->mem_text = (struct device_node){ + .path = "/reserved-memory/text", .compatible = "apple,asc-mem", .available = true, + }; + f->mem_data = (struct device_node){ + .path = "/reserved-memory/data", .compatible = "apple,asc-mem", .available = true, + }; + f->mem_heap = (struct device_node){ + .path = "/reserved-memory/heap", .compatible = "apple,asc-mem", .available = true, + }; + + f->dcpext0 = (struct device_node){ + .path = "/soc/dcp@999e00000", .compatible = "apple,t8132-dcpext", + .phandle = 25, .available = false, + .phy_names = { "dp-phy" }, .phy_name_count = 1, .phys = { &f->phy }, + .iommus = { &f->fw_dart }, .iommu_args = { 23 }, .iommu_count = 1, + .mboxes = { &f->mbox }, .mbox_count = 1, + .mem_regions = { &f->mem_text, &f->mem_data, &f->mem_heap }, + .mem_region_count = 3, + .piodma_child = &f->piodma, + }; + sync_iommus_prop(&f->dcpext0); + set_v27_2(&f->dcpext0); + + /* Second dcpext without dp-phy (Type-C only): must stay untouched. */ + f->dcpext1 = (struct device_node){ + .path = "/soc/dcp@888e00000", .compatible = "apple,t8132-dcpext", + .phandle = 30, .available = false, + .phy_names = { "typec0" }, .phy_name_count = 1, .phys = { &f->phy }, + }; + set_v27_2(&f->dcpext1); + + register_node(&f->disp0_dart); + register_node(&f->display); + register_node(&f->main_dcp); + register_node(&f->phy); + register_node(&f->fw_dart); + register_node(&f->disp_dart); + register_node(&f->mbox); + register_node(&f->piodma); + register_node(&f->mem_text); + register_node(&f->mem_data); + register_node(&f->mem_heap); + register_node(&f->dcpext0); + register_node(&f->dcpext1); +} + +static void expect_chain(struct fixture *f, bool enabled) +{ + assert(f->phy.available == enabled); + assert(f->fw_dart.available == enabled); + assert(f->disp_dart.available == enabled); + assert(f->mbox.available == enabled); + assert(f->piodma.available == enabled); + assert(f->dcpext0.available == enabled); + assert(!f->dcpext1.available); +} + +int main(void) +{ + struct fixture f; + + /* 1. Headless T8132 (J773g-like): phandle-derived chain enabled; disp0 iommus replaced. */ + init_fixture(&f); + gate_t8132_run(); + expect_chain(&f, true); + assert(f.display.iommu_count == 1); + assert(f.display.iommus[0] == &f.disp_dart && f.display.iommu_args[0] == 0); + check_refs_zero(); + + /* 2. Laptop T8132 (14" MBP-like): main DCP handed over on 27.2 -> disp0 iommus appended. */ + init_fixture(&f); + set_v27_2(&f.main_dcp); + f.main_dcp.has_clock_ids = true; + gate_t8132_run(); + expect_chain(&f, true); + assert(f.display.iommu_count == 2); + assert(f.display.iommus[0] == &f.disp0_dart && f.display.iommu_args[0] == 0); + assert(f.display.iommus[1] == &f.disp_dart && f.display.iommu_args[1] == 0); + check_refs_zero(); + + /* 3. Main DCP with 27.2 image but no apple,clock-ids (idle) -> replaced, not appended. */ + init_fixture(&f); + set_v27_2(&f.main_dcp); + f.main_dcp.has_clock_ids = false; + gate_t8132_run(); + expect_chain(&f, true); + assert(f.display.iommu_count == 1 && f.display.iommus[0] == &f.disp_dart); + check_refs_zero(); + + /* 4. Unapproved firmware UUID on dcpext0 -> chain stays disabled, disp0 unchanged. */ + init_fixture(&f); + f.dcpext0.fw_uuid = "00000000-0000-0000-0000-000000000000"; + gate_t8132_run(); + expect_chain(&f, false); + assert(f.display.iommu_count == 1 && f.display.iommus[0] == &f.disp0_dart); + check_refs_zero(); + + /* 5. Placeholder (disabled) memory-region -> refused whole. */ + init_fixture(&f); + f.mem_heap.available = false; + gate_t8132_run(); + expect_chain(&f, false); + assert(f.display.iommu_count == 1 && f.display.iommus[0] == &f.disp0_dart); + check_refs_zero(); + + /* 6. Missing phandle (e.g. no piodma child) -> refused whole. */ + init_fixture(&f); + f.dcpext0.piodma_child = NULL; + gate_t8132_run(); + expect_chain(&f, false); + assert(f.display.iommu_count == 1 && f.display.iommus[0] == &f.disp0_dart); + check_refs_zero(); + + /* 7. Any chain node already enabled -> refused whole, DART not modified. */ + init_fixture(&f); + f.phy.available = true; + gate_t8132_run(); + assert(f.phy.available); + assert(!f.fw_dart.available && !f.disp_dart.available && !f.mbox.available && + !f.piodma.available && !f.dcpext0.available); + assert(f.display.iommu_count == 1 && f.display.iommus[0] == &f.disp0_dart); + check_refs_zero(); + + /* 8. Disabled display subsystem -> chain stays disabled. */ + init_fixture(&f); + f.display.available = false; + gate_t8132_run(); + expect_chain(&f, false); + assert(f.display.iommu_count == 1 && f.display.iommus[0] == &f.disp0_dart); + check_refs_zero(); + + /* 9. Tree with no fixed dp-phy on any dcpext -> quiet no-op. */ + init_fixture(&f); + f.dcpext0.phy_names[0] = "typec1"; + gate_t8132_run(); + expect_chain(&f, false); + assert(err_count == 0 && info_count == 0); + check_refs_zero(); + + /* 10. nomodeset -> no-op. */ + init_fixture(&f); + nomodeset = true; + gate_t8132_run(); + expect_chain(&f, false); + check_refs_zero(); + + cleanup_applied(); + puts("PASS T8132 fixed-DP display gate: phandle chain, replace vs append disp0 iommus, fail-closed controls"); + return 0; +} +''' + + with tempfile.TemporaryDirectory(prefix='t8132-display-gate-') as tmp: + src = Path(tmp) / 'test.c' + exe = Path(tmp) / 'test' + src.write_text(program) + subprocess.run( + [os.environ.get('CC', 'clang'), '-std=gnu11', '-Wall', '-Wextra', '-Werror', + '-fsanitize=address,undefined', str(src), '-o', str(exe)], + check=True, + ) + subprocess.run( + [str(exe)], + check=True, + env={**os.environ, 'ASAN_OPTIONS': 'detect_leaks=0'}, + ) + + +if __name__ == '__main__': + main() From 5f66e6979d88059eee062f8dba841cc1126a8aca Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Thu, 26 Nov 2026 07:14:31 -0500 Subject: [PATCH 11/11] soc: apple: display-gate: boot the J773g as main does when dcpext0 cannot be adopted On the J773g on macOS 27.2, the boot loader hands dcpext0 over running and enables the display subsystem and disp0's DART for it. The gate then enabled dcpext0's chain. But apple-dart keeps a locked DART's firmware roots only for T6041, T6050, T8140 and T8142 DARTs, not for a T8132 one. So dcpext0's firmware DART failed its probe (-EBUSY, with a WARNING in iommu_setup_default_domain()), and the DCP and its PHY never probed. The display subsystem never registered, and G16, which waits for a handed-over display before its first start, never probed either. The same Mac boots main with the GPU up on the boot framebuffer. - include/linux/soc/apple/dart.h: apple_dart_keeps_locked_roots() names the DART kinds whose locked firmware roots apple-dart keeps (fw_mirror). apple-dart.c takes its fw_mirror list from it, with no functional change. - The gate enables a T8132 fixed-DP chain only when both of its DARTs are of such a kind. On this tree no T8132 DART is, so the J773g HDMI chain stays off until apple-dart keeps a locked T8132 DART's roots. - When no chain is enabled on a headless T8132 (no internal DCP handed over on 27.2), nomodeset included, the gate disables what the boot loader enabled for the external processors: the display subsystem, and its DART unless the main DCP is enabled. With no display handed over, G16 starts on the boot framebuffer, as on main. - A boot where the loader published nothing for the dcpexts changes nothing. tools/asahi/t8132-display-gate-tests.py now also covers: - no handover: no change to any node, to disp0's iommus or to the log, with and without nomodeset; - the J773g's T8132 DARTs: the chain stays off, and the display and its DART go; - either DART of the chain alone not kept; - a laptop whose main DCP is handed over: its display is kept; - a headless tree with the main DCP enabled: the display goes, its DART stays. The existing refusal cases also check that the display goes. Signed-off-by: DjDeveloperr --- drivers/iommu/apple-dart.c | 5 +- drivers/soc/apple/display-gate.c | 91 +++++++++++- include/linux/soc/apple/dart.h | 15 ++ tools/asahi/t8132-display-gate-tests.py | 184 ++++++++++++++++++++++-- 4 files changed, 281 insertions(+), 14 deletions(-) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index dc0b0a15d163..c630e5a248b1 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -6377,10 +6377,7 @@ static int apple_dart_probe(struct platform_device *pdev) * roots of its own (dart-dcpextN SID 23, dart-dispextN SIDs 0 and 16). */ dart->fw_mirror = dart->locked && !dart->fw_handoff && - (of_device_is_compatible(dev->of_node, "apple,t6041-dart") || - of_device_is_compatible(dev->of_node, "apple,t6050-dart") || - of_device_is_compatible(dev->of_node, "apple,t8140-dart") || - of_device_is_compatible(dev->of_node, "apple,t8142-dart")); + apple_dart_keeps_locked_roots(dev->of_node); /* * A T6040/T6041 MTP (apple,t6041-mtp on both) may arrive live after the * boot keyboard used it; its firmware cannot be restarted. Do not reset diff --git a/drivers/soc/apple/display-gate.c b/drivers/soc/apple/display-gate.c index dc63ff1734d3..4aac37b50f97 100644 --- a/drivers/soc/apple/display-gate.c +++ b/drivers/soc/apple/display-gate.c @@ -117,6 +117,7 @@ #include #include #include +#include #include #include #include @@ -3691,9 +3692,86 @@ static bool __init gate_t8132_fixed_dp_ready(struct device_node *nodes[T8132_HDM return false; } } + /* + * The processor runs on through the handover, behind DARTs the boot + * loader leaves locked: adopting it needs apple-dart to keep their + * firmware roots. Off that, the firmware DART's probe fails (-EBUSY on + * the J773g), the processor and its PHY never probe, and the display + * subsystem never binds. + */ + if (!apple_dart_keeps_locked_roots(nodes[T8132_HDMI_FW_DART]) || + !apple_dart_keeps_locked_roots(nodes[T8132_HDMI_DISP_DART])) { + staged_info("%pOF: the firmware roots of %pOF and %pOF are not kept, HDMI left off\n", + nodes[T8132_HDMI_DCP], nodes[T8132_HDMI_FW_DART], + nodes[T8132_HDMI_DISP_DART]); + return false; + } return true; } +/* + * A headless T8132 (no internal display processor handed over on 27.2) whose + * HDMI chain stays off: the display subsystem the boot loader enabled for it + * has no processor left to bind, since the main DCP is the M4 backend's on its + * firmware path only (apple_dcp_usable()). Left enabled it never registers, + * and the GPU, whose first start follows a handed-over display, waits for it + * for good. Disable it, as when the boot loader hands over no display: the + * boot framebuffer stays, and the GPU starts on it. Its DART (disp0's), which + * the boot loader enabled with it, goes too unless the main DCP, whose piodma + * also maps through it, is enabled. + */ +static void __init gate_t8132_display_off(void) +{ + struct device_node *display, *internal; + struct of_phandle_args args; + struct of_changeset *cs; + bool panel, internal_on; + int i, ret; + + display = of_find_node_by_path("disp0"); + if (!display) + display = of_find_compatible_node(NULL, NULL, gate_soc->display_compat); + if (!display || !of_device_is_compatible(display, gate_soc->display_compat) || + !of_device_is_available(display)) { + of_node_put(display); + return; + } + internal = of_find_node_by_path("dcp"); + if (!internal) + internal = of_find_compatible_node(NULL, NULL, gate_soc->dcp_compat); + panel = gate_t8132_dcp_v27_2(internal); + internal_on = of_device_is_available(internal); + of_node_put(internal); + if (panel) { + of_node_put(display); + return; + } + + cs = gate_cs_alloc(); + if (!cs) { + staged_err("%pOF: could not allocate changeset\n", display); + of_node_put(display); + return; + } + ret = of_changeset_update_prop_string(cs, display, "status", "disabled"); + for (i = 0; !ret && !internal_on && + !of_parse_phandle_with_args(display, "iommus", "#iommu-cells", i, &args); i++) { + if (of_device_is_available(args.np)) + ret = of_changeset_update_prop_string(cs, args.np, "status", "disabled"); + of_node_put(args.np); + } + if (!ret) + ret = of_changeset_apply(cs); + if (ret) { + gate_cs_free(cs); + staged_err("%pOF: could not disable it without HDMI: %d\n", display, ret); + } else { + staged_info("no HDMI chain and no internal display: %pOF disabled, boot framebuffer kept\n", + display); + } + of_node_put(display); +} + /* * T8132 on macOS 27.2 (off the M4 26.6.2 firmware path): any apple,t8132-dcpext * wired to a fixed DP PHY (phy-names = "dp-phy", e.g. the J773g HDMI port) @@ -3708,6 +3786,9 @@ static bool __init gate_t8132_fixed_dp_ready(struct device_node *nodes[T8132_HDM * is not handed over (a headless Mac mini), disp0's DART is left unprobed by * apple-dart and would hold the display subsystem's probe forever, so iommus * is replaced with dispext's DART instead. + * + * With no chain enabled (no handover, a refused one, or nomodeset), a headless + * T8132 boots as without this gate: see gate_t8132_display_off(). */ static void __init gate_t8132_run(void) { @@ -3715,12 +3796,15 @@ static void __init gate_t8132_run(void) struct device_node *nodes[T8132_HDMI_NR]; bool append_dart = false; bool display_checked = false; + bool enabled = false; unsigned int i; int phy_idx, ret; - if (IS_ENABLED(CONFIG_VIDEO) && video_firmware_drivers_only()) - return; staged_prefix = gate_soc->prefix; + if (IS_ENABLED(CONFIG_VIDEO) && video_firmware_drivers_only()) { + gate_t8132_display_off(); + return; + } for_each_compatible_node(dcp, NULL, "apple,t8132-dcpext") { struct of_changeset *cs; @@ -3793,10 +3877,13 @@ static void __init gate_t8132_run(void) append_dart ? "appended" : "on", nodes[T8132_HDMI_DISP_DART]); append_dart = true; + enabled = true; } gate_t8132_put_nodes(nodes); } of_node_put(display); + if (!enabled) + gate_t8132_display_off(); } /* Runs before of_platform_default_populate_init() at arch_initcall_sync. */ diff --git a/include/linux/soc/apple/dart.h b/include/linux/soc/apple/dart.h index 3c46255efd6e..15e7c256999e 100644 --- a/include/linux/soc/apple/dart.h +++ b/include/linux/soc/apple/dart.h @@ -6,11 +6,26 @@ #include #include #include +#include #include struct device; struct device_node; +/* + * Whether apple-dart keeps the firmware's root slots of a DART of @np's kind + * that the boot loader leaves locked (fw_mirror). Only then can a coprocessor + * the boot loader leaves running behind such a DART be adopted: on the plain + * locked path its firmware loses the mappings it runs on. + */ +static inline bool apple_dart_keeps_locked_roots(const struct device_node *np) +{ + return of_device_is_compatible(np, "apple,t6041-dart") || + of_device_is_compatible(np, "apple,t6050-dart") || + of_device_is_compatible(np, "apple,t8140-dart") || + of_device_is_compatible(np, "apple,t8142-dart"); +} + /* Retained internal-display ownership is qualified only with a built-in * DART provider. Other consumers, including modular DART, keep the APIs below. */ diff --git a/tools/asahi/t8132-display-gate-tests.py b/tools/asahi/t8132-display-gate-tests.py index 9361b8a6008f..01fb832783e5 100755 --- a/tools/asahi/t8132-display-gate-tests.py +++ b/tools/asahi/t8132-display-gate-tests.py @@ -35,6 +35,7 @@ def main(): gate_src = (ROOT / 'drivers/soc/apple/display-gate.c').read_text() disp_hdr = (ROOT / 'include/linux/soc/apple/display.h').read_text() t8132_hdr = (ROOT / 'include/linux/soc/apple/t8132.h').read_text() + dart_hdr = (ROOT / 'include/linux/soc/apple/dart.h').read_text() # Enforce at source level that T8132 fixed-DP gate matches the SoC, not a board name, # and carries no hard-coded board node paths. @@ -51,6 +52,7 @@ def main(): uuid_lines, extract_block(disp_hdr, r'^static inline bool apple_dcp_image_v27_2\('), extract_block(t8132_hdr, r'^static inline bool apple_t8132_dcpext_v27_2\('), + extract_block(dart_hdr, r'^static inline bool apple_dart_keeps_locked_roots\('), extract_block(gate_src, r'^static int gate_iommus_append\('), extract_block(gate_src, r'^static struct of_changeset \*__init gate_cs_alloc\('), extract_block(gate_src, r'^static void __init gate_cs_free\('), @@ -61,6 +63,7 @@ def main(): extract_block(gate_src, r'^static void __init gate_t8132_put_nodes\('), extract_block(gate_src, r'^static int __init gate_t8132_resolve_fixed_dp\('), extract_block(gate_src, r'^static bool __init gate_t8132_fixed_dp_ready\('), + extract_block(gate_src, r'^static void __init gate_t8132_display_off\('), extract_block(gate_src, r'^static void __init gate_t8132_run\('), ]) @@ -474,6 +477,13 @@ def main(): return 0; } ''' + helpers + r''' +/* + * A DART kind whose locked firmware roots apple-dart keeps + * (apple_dart_keeps_locked_roots()). The J773g's own, apple,t8132-dart, is not + * one in this tree: see j773g_darts(). + */ +#define KEPT_DART "apple,t6041-dart" + struct fixture { struct device_node display, disp0_dart, main_dcp; struct device_node phy, fw_dart, disp_dart, mbox, piodma, dcpext0; @@ -545,10 +555,12 @@ def main(): .path = "/soc/phy@999700000", .phandle = 20, .available = false, }; f->fw_dart = (struct device_node){ - .path = "/soc/iommu@999340000", .phandle = 21, .available = false, + .path = "/soc/iommu@999340000", .compatible = KEPT_DART, + .phandle = 21, .available = false, }; f->disp_dart = (struct device_node){ - .path = "/soc/iommu@999300000", .phandle = 22, .available = false, + .path = "/soc/iommu@999300000", .compatible = KEPT_DART, + .phandle = 22, .available = false, }; f->mbox = (struct device_node){ .path = "/soc/mailbox@999e08000", .phandle = 23, .available = false, @@ -606,6 +618,67 @@ def main(): register_node(&f->dcpext1); } +/* The J773g's dcpext0 DARTs, which this tree's apple-dart does not keep the locked roots of. */ +static void j773g_darts(struct fixture *f) +{ + f->fw_dart.compatible = "apple,t8132-dart"; + f->disp_dart.compatible = "apple,t8132-dart"; +} + +/* Stage 2 published nothing for the dcpexts: no image, placeholders, no display. */ +static void no_handover(struct fixture *f) +{ + struct device_node *dcps[] = { &f->dcpext0, &f->dcpext1 }; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(dcps); i++) { + dcps[i]->fw_uuid = NULL; + dcps[i]->fw_uuid_count = 0; + dcps[i]->fw_ver_cells = 0; + dcps[i]->fw_compat_cells = 0; + } + f->mem_text.available = f->mem_data.available = f->mem_heap.available = false; + f->display.available = false; +} + +struct snapshot { + bool available[MAX_NODES]; + int display_iommus; + struct device_node *display_iommu[4]; +}; + +static void take_snapshot(struct fixture *f, struct snapshot *snap) +{ + unsigned int i; + + for (i = 0; i < nr_nodes; i++) + snap->available[i] = all_nodes[i]->available; + snap->display_iommus = f->display.iommu_count; + memcpy(snap->display_iommu, f->display.iommus, sizeof(snap->display_iommu)); +} + +static void expect_unchanged(struct fixture *f, const struct snapshot *snap) +{ + unsigned int i; + + for (i = 0; i < nr_nodes; i++) + assert(all_nodes[i]->available == snap->available[i]); + assert(f->display.iommu_count == snap->display_iommus); + assert(!memcmp(f->display.iommus, snap->display_iommu, sizeof(snap->display_iommu))); + assert(nr_applied_cs == 0); +} + +/* + * What the GPU sees (asahi_g16_display_prepare()): with the display subsystem + * disabled it starts on the boot framebuffer instead of waiting for it. + */ +static void expect_gpu_on_boot_framebuffer(struct fixture *f) +{ + assert(!of_device_is_available(&f->display)); + assert(!f->disp0_dart.available); + assert(f->display.iommu_count == 1 && f->display.iommus[0] == &f->disp0_dart); +} + static void expect_chain(struct fixture *f, bool enabled) { assert(f->phy.available == enabled); @@ -619,6 +692,7 @@ def main(): int main(void) { + struct snapshot snap; struct fixture f; /* 1. Headless T8132 (J773g-like): phandle-derived chain enabled; disp0 iommus replaced. */ @@ -649,38 +723,47 @@ def main(): assert(f.display.iommu_count == 1 && f.display.iommus[0] == &f.disp_dart); check_refs_zero(); + /* + * 4-7: a refused chain on a headless T8132 leaves the display subsystem the + * boot loader enabled, and its DART, disabled: the GPU starts on the boot + * framebuffer. + */ /* 4. Unapproved firmware UUID on dcpext0 -> chain stays disabled, disp0 unchanged. */ init_fixture(&f); + f.disp0_dart.available = true; f.dcpext0.fw_uuid = "00000000-0000-0000-0000-000000000000"; gate_t8132_run(); expect_chain(&f, false); - assert(f.display.iommu_count == 1 && f.display.iommus[0] == &f.disp0_dart); + expect_gpu_on_boot_framebuffer(&f); check_refs_zero(); /* 5. Placeholder (disabled) memory-region -> refused whole. */ init_fixture(&f); + f.disp0_dart.available = true; f.mem_heap.available = false; gate_t8132_run(); expect_chain(&f, false); - assert(f.display.iommu_count == 1 && f.display.iommus[0] == &f.disp0_dart); + expect_gpu_on_boot_framebuffer(&f); check_refs_zero(); /* 6. Missing phandle (e.g. no piodma child) -> refused whole. */ init_fixture(&f); + f.disp0_dart.available = true; f.dcpext0.piodma_child = NULL; gate_t8132_run(); expect_chain(&f, false); - assert(f.display.iommu_count == 1 && f.display.iommus[0] == &f.disp0_dart); + expect_gpu_on_boot_framebuffer(&f); check_refs_zero(); /* 7. Any chain node already enabled -> refused whole, DART not modified. */ init_fixture(&f); + f.disp0_dart.available = true; f.phy.available = true; gate_t8132_run(); assert(f.phy.available); assert(!f.fw_dart.available && !f.disp_dart.available && !f.mbox.available && !f.piodma.available && !f.dcpext0.available); - assert(f.display.iommu_count == 1 && f.display.iommus[0] == &f.disp0_dart); + expect_gpu_on_boot_framebuffer(&f); check_refs_zero(); /* 8. Disabled display subsystem -> chain stays disabled. */ @@ -691,23 +774,108 @@ def main(): assert(f.display.iommu_count == 1 && f.display.iommus[0] == &f.disp0_dart); check_refs_zero(); - /* 9. Tree with no fixed dp-phy on any dcpext -> quiet no-op. */ + /* + * 9. No fixed dp-phy on any dcpext -> no chain, no error; the display + * subsystem has nothing to bind and goes. + */ init_fixture(&f); + f.disp0_dart.available = true; f.dcpext0.phy_names[0] = "typec1"; gate_t8132_run(); expect_chain(&f, false); + expect_gpu_on_boot_framebuffer(&f); + assert(err_count == 0 && info_count == 1); + check_refs_zero(); + + /* 10. nomodeset -> no chain; drm/apple does not register, so neither does the display. */ + init_fixture(&f); + f.disp0_dart.available = true; + nomodeset = true; + gate_t8132_run(); + expect_chain(&f, false); + expect_gpu_on_boot_framebuffer(&f); + check_refs_zero(); + + /* + * 11. No handover (Stage 2 published nothing for the dcpexts): no change + * from a tree without this gate. Nothing is enabled or disabled, disp0's + * iommus stay, and nothing is logged. + */ + init_fixture(&f); + no_handover(&f); + take_snapshot(&f, &snap); + gate_t8132_run(); + expect_unchanged(&f, &snap); assert(err_count == 0 && info_count == 0); check_refs_zero(); - /* 10. nomodeset -> no-op. */ + /* 11b. The same with the J773g's DARTs, and under nomodeset. */ init_fixture(&f); + no_handover(&f); + j773g_darts(&f); + take_snapshot(&f, &snap); + gate_t8132_run(); + expect_unchanged(&f, &snap); nomodeset = true; gate_t8132_run(); + expect_unchanged(&f, &snap); + check_refs_zero(); + + /* + * 12. The J773g on 27.2 with this tree: Stage 2 handed dcpext0 over and + * enabled the display subsystem and disp0's DART, but apple-dart keeps no + * locked roots of a T8132 DART. The chain stays off and the display goes, + * so the GPU starts on the boot framebuffer as without the handover. + */ + init_fixture(&f); + j773g_darts(&f); + f.disp0_dart.available = true; + gate_t8132_run(); + expect_chain(&f, false); + expect_gpu_on_boot_framebuffer(&f); + assert(err_count == 0); + check_refs_zero(); + + /* 13. Either DART of the chain alone not kept -> the same. */ + init_fixture(&f); + f.disp0_dart.available = true; + f.fw_dart.compatible = "apple,t8132-dart"; + gate_t8132_run(); + expect_chain(&f, false); + expect_gpu_on_boot_framebuffer(&f); + init_fixture(&f); + f.disp0_dart.available = true; + f.disp_dart.compatible = "apple,t8132-dart"; + gate_t8132_run(); + expect_chain(&f, false); + expect_gpu_on_boot_framebuffer(&f); + check_refs_zero(); + + /* 14. Laptop: main DCP handed over on 27.2 -> its display subsystem and DART stay. */ + init_fixture(&f); + j773g_darts(&f); + set_v27_2(&f.main_dcp); + f.main_dcp.has_clock_ids = true; + f.main_dcp.available = true; + f.disp0_dart.available = true; + take_snapshot(&f, &snap); + gate_t8132_run(); + expect_unchanged(&f, &snap); + check_refs_zero(); + + /* 15. Headless, but the main DCP enabled: the display goes, disp0's DART (its piodma's) stays. */ + init_fixture(&f); + j773g_darts(&f); + f.main_dcp.available = true; + f.disp0_dart.available = true; + gate_t8132_run(); expect_chain(&f, false); + assert(!f.display.available && f.disp0_dart.available); check_refs_zero(); cleanup_applied(); puts("PASS T8132 fixed-DP display gate: phandle chain, replace vs append disp0 iommus, fail-closed controls"); + puts("PASS T8132 display gate: no handover or no kept DART roots boots as without the gate, GPU on the boot framebuffer"); return 0; } '''