diff --git a/Documentation/devicetree/bindings/phy/apple,dptx-phy.yaml b/Documentation/devicetree/bindings/phy/apple,dptx-phy.yaml index 5e48405d80a12..01dc9abadc887 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 diff --git a/arch/arm64/boot/dts/apple/t8132-j773g.dts b/arch/arm64/boot/dts/apple/t8132-j773g.dts index 9e92081da8b59..fc0aec6118e65 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 diff --git a/drivers/gpu/drm/apple/apple_drv.c b/drivers/gpu/drm/apple/apple_drv.c index 5b621af9e8a2f..8af750efc7d2a 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 @@ -1785,6 +1786,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 one on firmware 27.2 (apple_t8132_dcpext_v27_2()). */ + { .compatible = "apple,t8132-dcpext" }, {}, }; @@ -1803,7 +1806,19 @@ 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()) && + /* + * A T8132 dcpext the M4 backend adopts is no component: its + * 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)); } 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 b07f3d0043ad9..22148f031868f 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. @@ -579,6 +587,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-fabric.h b/drivers/gpu/drm/apple/dcp-fabric.h index 78c7065a0baac..139c75f27f674 100644 --- a/drivers/gpu/drm/apple/dcp-fabric.h +++ b/drivers/gpu/drm/apple/dcp-fabric.h @@ -128,7 +128,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-firmware-test.c b/drivers/gpu/drm/apple/dcp-firmware-test.c index 1b411f88c84f7..86291297a660b 100644 --- a/drivers/gpu/drm/apple/dcp-firmware-test.c +++ b/drivers/gpu/drm/apple/dcp-firmware-test.c @@ -276,11 +276,15 @@ static void dcp_firmware_27_pin_precedence(struct kunit *test) fx->props[0].value = compat_27_2; #if IS_ENABLED(CONFIG_DRM_APPLE_DCP_T8132) - /* T8132 keeps its M4 match-data pin on 27.2. */ + /* + * T8132 keeps its M4 match-data pin on 27.2, never generic firmware + * 27: the M4 backend's on its 26.6.2 firmware path, nobody's off it. + */ fx->props[3].length = sizeof(t8132); fx->props[3].value = (void *)t8132; KUNIT_EXPECT_EQ(test, dcp_check_firmware_version(&fx->dev), - DCP_FIRMWARE_M4); + apple_t8132_firmware_path() ? DCP_FIRMWARE_M4 : + DCP_FIRMWARE_UNKNOWN); #endif } diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index d75849d99f2ec..f89e0635780a5 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -644,7 +644,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 4a696e8dc1b7a..1e911e8431eaf 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -542,7 +543,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); } /* @@ -6292,10 +6307,43 @@ static enum dcp_firmware_version dcp_check_firmware_version(struct device *dev) dcp_firmware_27(dev, &version)) return version; + /* + * 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); + } + + /* + * 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 M4 or H17-generation firmware pin their * interface; keep explicit match-data pins ahead of the generic - * firmware-27 rule below so T8132/T8140 stay on their pinned backend. + * firmware-27 rule below so T8132 (but for the 27.2 dcpext above) and + * T8140 stay on their pinned backend. */ if (hw->firmware_compat != DCP_FIRMWARE_UNKNOWN) return hw->firmware_compat; @@ -7220,8 +7268,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) @@ -7229,7 +7278,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); } /* @@ -7540,8 +7590,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()). */ @@ -7949,6 +8000,32 @@ static int dcp_t6041_map_power(struct apple_dcp *dcp) return ret; } +/* + * 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); @@ -8080,7 +8157,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 @@ -8157,6 +8234,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. @@ -8764,7 +8844,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); @@ -8845,7 +8925,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); @@ -8914,7 +8994,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); } @@ -11215,7 +11295,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/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index dc0b0a15d163c..c630e5a248b15 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 931fe3ef1adf8..4aac37b50f977 100644 --- a/drivers/soc/apple/display-gate.c +++ b/drivers/soc/apple/display-gate.c @@ -84,6 +84,15 @@ * 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()). + * + * 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 @@ -108,6 +117,7 @@ #include #include #include +#include #include #include #include @@ -371,12 +381,30 @@ static const struct gate_soc gate_t6041_max __initconst = { .run = gate_t6041_max_run, }; +static void __init gate_t8132_run(void); + +/* + * 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 __initconst = { + .machine = "apple,t8132", + .prefix = "apple-t8132-display: ", + .name = "T8132", + .dcp_compat = "apple,t8132-dcp", + .display_compat = "apple,t8132-display-subsystem", + .run = gate_t8132_run, +}; + static const struct gate_soc *const gate_socs[] __initconst = { &gate_t6030, &gate_t8122, &gate_t6031, &gate_t6041, &gate_t6041_max, + &gate_t8132, }; /* The SoC this boot runs on, if the gate serves it. */ @@ -3509,6 +3537,355 @@ static void __init gate_j713_dcpext_routes(void) gate_cs_free(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); +} + +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; + } + } + /* + * 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) + * 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. + * + * 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. + * + * 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) +{ + struct device_node *display = NULL, *internal, *dcp; + 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; + + 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; + + phy_idx = of_property_match_string(dcp, "phy-names", "dp-phy"); + if (phy_idx < 0) + continue; + + 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; + 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. */ static int __init apple_display_gate(void) { diff --git a/include/linux/soc/apple/dart.h b/include/linux/soc/apple/dart.h index 3c46255efd6e5..15e7c256999e8 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/include/linux/soc/apple/display.h b/include/linux/soc/apple/display.h index 5d25ec833f7ab..7d35049b18669 100644 --- a/include/linux/soc/apple/display.h +++ b/include/linux/soc/apple/display.h @@ -20,6 +20,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 ec91e8faaa9b5..72ece899b148a 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 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 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 diff --git a/tools/asahi/dcpext26-crossbar-union-tests.py b/tools/asahi/dcpext26-crossbar-union-tests.py index 9607ad8ee202e..b6291bcf91553 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/run-host-tests.py b/tools/asahi/run-host-tests.py index a3c33382e0fb1..e9738ef771492 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -446,6 +446,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/t6030-clock/fixture.c b/tools/asahi/t6030-clock/fixture.c index 832c412187e79..638785049ddca 100644 --- a/tools/asahi/t6030-clock/fixture.c +++ b/tools/asahi/t6030-clock/fixture.c @@ -175,8 +175,9 @@ static int phy_configure(struct phy *p, union phy_configure_opts *opts) return t6040_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/t8132-display-gate-tests.py b/tools/asahi/t8132-display-gate-tests.py new file mode 100755 index 0000000000000..01fb832783e50 --- /dev/null +++ b/tools/asahi/t8132-display-gate-tests.py @@ -0,0 +1,900 @@ +#!/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() + 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. + 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(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\('), + 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_display_off\('), + 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''' +/* + * 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; + 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", .compatible = KEPT_DART, + .phandle = 21, .available = false, + }; + f->disp_dart = (struct device_node){ + .path = "/soc/iommu@999300000", .compatible = KEPT_DART, + .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); +} + +/* 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); + 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 snapshot snap; + 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-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); + 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); + 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); + 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); + expect_gpu_on_boot_framebuffer(&f); + 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. 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(); + + /* 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; +} +''' + + 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() diff --git a/tools/asahi/tiled-split-tests.py b/tools/asahi/tiled-split-tests.py index 7ee72aa18bf5c..8ee3749aa80ba 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 30f4ca0a79726..a0a6974408071 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 2bcb8e713e5be..e95d06be8446c 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 74a7a11da1940..b16366a175efa 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py @@ -201,8 +201,9 @@ def _v27_prelude(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 helpers = ('static inline bool apple_dcp_image_v27_2(', 'static inline bool apple_t6041_dcp_any_v27_2(', 'static inline bool apple_t6041_dcp_v27_2(', @@ -210,7 +211,14 @@ def _v27_prelude(root): 'static inline bool apple_t8122_dcp_v27_2(', 'static inline bool\napple_t8122_dcpext_v27_2_for_internal(', 'static inline bool apple_t8122_dcpext_v27_2(') - helper = '\n'.join((*uuid_defines, *(block(display_h, marker) for marker in helpers))) + # The T8132 27.2 dcpext admission: by processor and image, never by board. No + # of_machine_is_compatible() exists in these units, so neither it nor the display.h + # 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 'of_machine_is_compatible' not in t8132_admission + helper = '\n'.join((*uuid_defines, *(block(display_h, marker) for marker in helpers), + t8132_admission)) iomfb_h = (root / 'drivers/gpu/drm/apple/iomfb.h').read_text() methods_decl = iomfb_h[iomfb_h.index('enum dcpep_method {'): iomfb_h.index('#define IOMFB_MAX_CB')] @@ -326,6 +334,13 @@ def _v27_prelude(root): #define dev_warn(...) ((void)0) #define IS_ERR(ptr) false static void dev_err(struct device *dev, const char *format, ...) {} +#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; @@ -561,8 +576,59 @@ 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); + } + + /* + * 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"; + 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; + assert(apple_t8132_dcpext_v27_2(&node)); + assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_V_27_0); + } + t8132_firmware_path = false; + /* 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)); + + dev.hw = &hw; puts("PASS T6041 26B123 v27.2 internal/external admission, refusal controls, and desktop 26.x preservation"); puts("PASS T8122 internal DCP needs its 27.2 image for 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; } ''' diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py index 1ac054a6ee361..b41b73ad7478f 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py @@ -1592,6 +1592,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; };