diff --git a/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml b/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml index 7b060fd33b594..8c484ae685e2d 100644 --- a/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml +++ b/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml @@ -4,7 +4,7 @@ $id: http://devicetree.org/schemas/display/apple,t8140-display-power.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Apple T8103, T6041, T8140 and T8142 display power words +title: Apple T8103, T6041, T8132, T8140 and T8142 display power words maintainers: - Diljit Singh @@ -21,6 +21,7 @@ properties: enum: - apple,t8103-display-power - apple,t6041-display-power + - apple,t8132-display-power - apple,t8140-display-power - apple,t8142-display-power @@ -151,7 +152,9 @@ allOf: - if: properties: compatible: - const: apple,t8140-display-power + enum: + - apple,t8132-display-power + - apple,t8140-display-power then: properties: reg: diff --git a/arch/arm64/boot/dts/apple/t8132-dcp.dtsi b/arch/arm64/boot/dts/apple/t8132-dcp.dtsi index b4383741a15fb..b50f371e31fb9 100644 --- a/arch/arm64/boot/dts/apple/t8132-dcp.dtsi +++ b/arch/arm64/boot/dts/apple/t8132-dcp.dtsi @@ -70,6 +70,7 @@ iommus = <&dcp_dart 23>; power-domains = <&ps_disp_cpu>; dma-noncoherent; + apple,bw-scratch = <&pmgr_dcp 0 4 0>; status = "disabled"; disp0_piodma: piodma { @@ -79,6 +80,18 @@ }; }; + /* + * The internal pipe's realtime bandwidth request slot in the PMC, 0x20000 + * into the window the DCP has as disp-4: bandwidth agent 0, the one the + * ADT's disp0 bw_req interrupt names (agents are 0x4000 apart from + * 0x20000; the dcpexts' agents 3 and 4 are pmgr_dcpext's slots). + */ + pmgr_dcp: power-management@382820000 { + reg = <0x3 0x82820000 0x0 0x8>; + reg-names = "dcp-bw-scratch"; + #apple,bw-scratch-cells = <3>; + }; + /* The scanout frontend; it has no registers of its own. */ display: display-subsystem { compatible = "apple,t8132-display-subsystem", "apple,t8132-display-diagnostics"; diff --git a/arch/arm64/boot/dts/apple/t8132-j713.dts b/arch/arm64/boot/dts/apple/t8132-j713.dts index 440ecff14d4a1..57c761674b0b4 100644 --- a/arch/arm64/boot/dts/apple/t8132-j713.dts +++ b/arch/arm64/boot/dts/apple/t8132-j713.dts @@ -193,8 +193,40 @@ apple,clock-protection = <&ps_prot 8>; }; +/* + * The words the firmware-27 stop of the internal DCP writes (by default, see + * dcp_s2r_layout_from_dt()), the same ones the deep sleep lowers: pmc-dcp, the PMGR + * power states and its power gate block. + */ +&soc { + dcp_power: display-power@3828a9c14 { + compatible = "apple,t8132-display-power"; + reg = <0x3 0x828a9c14 0x0 0x4>, + <0x3 0x80700000 0x0 0x14000>, + <0x3 0x80724000 0x0 0x2000>; + reg-names = "pmc-dcp", "ps", "pwrgate"; + }; +}; + +/* Clock-protection slice 42 (ADT dart-dcp): it guards DISP_CPU's power state. */ +&dcp_dart { + reg = <0x3 0x0a340000 0x0 0x20000>, + <0x3 0x8079cb80 0x0 0x4>; + reg-names = "dart", "gapf"; +}; + &dcp { apple,pmc-interface = <&pmc_disp0>; + apple,display-power = <&dcp_power>; + + panel: panel { + compatible = "apple,panel-j713", "apple,panel"; + /* 2560x1664 at 224 ppi; 64 notch rows above the desktop. */ + width-mm = <290>; + height-mm = <189>; + adj-height-mm = <181>; + apple,max-brightness = <500>; + }; }; /* diff --git a/drivers/gpu/drm/apple/apple_drv.c b/drivers/gpu/drm/apple/apple_drv.c index b9790ecee9ec5..06e36e3a4a00d 100644 --- a/drivers/gpu/drm/apple/apple_drv.c +++ b/drivers/gpu/drm/apple/apple_drv.c @@ -1845,11 +1845,13 @@ static bool apple_dcp_usable(struct device_node *np) (!of_device_is_compatible(np, "apple,t6041-dcpext") || 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()). + * The T8132 main DCP is the M4 backend's on its 26.6.2 + * firmware path, and the firmware-27 backend's wherever the + * boot loader handed it over with the 27.2 image and its + * clocks, on any board (see dcp_check_firmware_version()). */ (!of_device_is_compatible(np, "apple,t8132-dcp") || - apple_t8132_firmware_path()) && + apple_t8132_firmware_path() || apple_t8132_dcp_v27_2(np)) && /* * 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. diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 9ec6b6ba41a27..f768e7b7ec8fe 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -252,6 +252,13 @@ struct dcp_s2r_layout { u32 disp_streams; /* "pmc-dcp" counts the powered DCPs: T8132 and T8140 only */ bool pmc_dcp; + /* + * From the device tree (dcp_s2r_layout_from_dt()): only the @*_mask bits of a + * retention word are written, @*_off while off and the value read at probe back on. + * Zero masks: the whole words, as above. + */ + u32 ret_ff_mask, ret_ff_off, ret_ff_on; + u32 ret_mem_mask, ret_mem_off, ret_mem_on; }; /* @@ -1016,6 +1023,9 @@ struct apple_dcp { struct dcp_t6041_power t6041_power; struct device *s2r_disp_dart; struct device *s2r_dcp_dart; + /* hw.s2r without a layout in its hw data: the device tree's, see dcp_s2r_layout_from_dt() */ + struct dcp_s2r_layout s2r_dt_layout; + bool s2r_dt_layout_ok; /* eDP display without DP-HDMI conversion */ bool main_display; diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 59a2b3d198c6c..30dbb2e7ebc31 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -324,9 +324,132 @@ static int dcp_secure_port_init(struct apple_dcp *dcp) * display domains through apple,display-power, and the internal DCP only takes IOP idle * once its secure port has gone idle. A device tree without those keeps the firmware * running: DPMS is the backlight alone and the display stays up across a sleep. A SoC - * without a secure mailbox says so (hw.s2r_no_secure_port), and one behind - * appledrm.s2r_untested stops its firmware for DPMS off and J813 system sleep. + * without a secure mailbox says so (hw.s2r_no_secure_port). Power words from the device + * tree stop the firmware by default; a SoC whose static words are only derived (T8142) does + * so only with appledrm.s2r_untested. + */ +/* + * hw.s2r without a layout in its hw data takes its words from the device tree, the ones its + * deep sleep lowers: DISP_CPU is the first state of the DCP's power-domains, DISP_FE that + * state's parent and DISP_SYS theirs, each at its reg in the power manager whose block the + * display-power node's "ps" starts. The retention words are DISP_CPU's two + * apple,retention-workaround entries (power manager offset, mask, value while off), in the + * node's "pwrgate" block, and the value each reads now, with the DCP running, is the one it + * gets back at power-on. It counts in pmc-dcp where the node has that word. The DART streams + * are the ones its DARTs have enabled at probe, see dcp_s2r_layout_streams(). + */ +static int dcp_s2r_layout_from_dt(struct apple_dcp *dcp) +{ + struct dcp_s2r_layout *l = &dcp->s2r_dt_layout; + struct device_node *power, *pmgr = NULL, *ps[3] = {}; + struct resource ps_res, gate_res, pmgr_res; + u32 off[3], ret[6]; + void __iomem *gate; + int i, err = -EINVAL; + + power = of_parse_phandle(dcp->dev->of_node, "apple,display-power", 0); + if (!power) + return -ENODEV; + if (of_address_to_resource(power, of_property_match_string(power, "reg-names", "ps"), + &ps_res) || + of_address_to_resource(power, of_property_match_string(power, "reg-names", "pwrgate"), + &gate_res)) + goto out; + ps[0] = of_parse_phandle(dcp->dev->of_node, "power-domains", 0); + for (i = 1; i < 3 && ps[i - 1]; i++) + ps[i] = of_parse_phandle(ps[i - 1], "power-domains", 0); + if (!ps[2]) + goto out; + pmgr = of_get_parent(ps[0]); + if (!pmgr || of_address_to_resource(pmgr, 0, &pmgr_res) || pmgr_res.start != ps_res.start) + goto out; + for (i = 0; i < 3; i++) { + struct device_node *parent = of_get_parent(ps[i]); + + of_node_put(parent); + if (parent != pmgr || of_property_read_u32(ps[i], "reg", &off[i]) || + resource_size(&ps_res) < 4 || off[i] > resource_size(&ps_res) - 4 || + off[i] % 4) + goto out; + } + if (of_property_read_u32_array(ps[0], "apple,retention-workaround", ret, 6) || + of_property_count_u32_elems(ps[0], "apple,retention-workaround") != 6) + goto out; + for (i = 0; i < 6; i += 3) { + u64 at = pmgr_res.start + ret[i]; + + if (at <= gate_res.start || at + 4 > gate_res.end + 1 || at % 4 || !ret[i + 1] || + ret[i + 2] & ~ret[i + 1]) + goto out; + } + gate = ioremap(gate_res.start, resource_size(&gate_res)); + if (!gate) { + err = -ENOMEM; + goto out; + } + *l = (struct dcp_s2r_layout){ + .disp_cpu = off[0], + .disp_fe = off[1], + .disp_sys = off[2], + .ret_ff = pmgr_res.start + ret[0] - gate_res.start, + .ret_ff_mask = ret[1], + .ret_ff_off = ret[2], + .ret_mem = pmgr_res.start + ret[3] - gate_res.start, + .ret_mem_mask = ret[4], + .ret_mem_off = ret[5], + .pmc_dcp = of_property_match_string(power, "reg-names", "pmc-dcp") >= 0, + }; + l->ret_ff_on = readl(gate + l->ret_ff); + l->ret_mem_on = readl(gate + l->ret_mem); + iounmap(gate); + dcp->s2r_dt_layout_ok = true; + dev_dbg(dcp->dev, "display power from the device tree: CPU %#x FE %#x SYS %#x, retention %#x/%#x on %#x/%#x\n", + l->disp_cpu, l->disp_fe, l->disp_sys, l->ret_ff, l->ret_mem, l->ret_ff_on, + l->ret_mem_on); + err = 0; +out: + for (i = 0; i < 3; i++) + of_node_put(ps[i]); + of_node_put(pmgr); + of_node_put(power); + return err; +} + +static struct device *dcp_s2r_find_dart(struct device_node *np); + +/* + * A device-tree layout's DART streams: the ones its DARTs have enabled at probe, with the + * firmware running. A DCP DART, or a piodma DART where the DCP has a piodma node, that is + * missing or reads none leaves nothing for the stop to restore, so the layout is refused. */ +static int dcp_s2r_layout_streams(struct apple_dcp *dcp) +{ + struct device_node *piodma; + struct device *dart; + + dart = dcp_s2r_find_dart(dcp->dev->of_node); + if (!dart) + return -ENODEV; + dcp->s2r_dt_layout.dcp_streams = apple_dart_enabled_streams(dart); + put_device(dart); + if (!dcp->s2r_dt_layout.dcp_streams) + return -ENODATA; + piodma = of_get_child_by_name(dcp->dev->of_node, "piodma"); + if (piodma) { + dart = dcp_s2r_find_dart(piodma); + of_node_put(piodma); + if (!dart) + return -ENODEV; + dcp->s2r_dt_layout.disp_streams = apple_dart_enabled_streams(dart); + put_device(dart); + if (!dcp->s2r_dt_layout.disp_streams) + return -ENODATA; + } + dev_dbg(dcp->dev, "DART streams for the stop: DCP %#x, display %#x\n", + dcp->s2r_dt_layout.dcp_streams, dcp->s2r_dt_layout.disp_streams); + return 0; +} + static void dcp_s2r_check_dt(struct apple_dcp *dcp) { struct device_node *np = dcp->dev->of_node; @@ -340,6 +463,16 @@ static void dcp_s2r_check_dt(struct apple_dcp *dcp) !power ? "apple,display-power" : "secure mailbox"); dcp->hw.s2r = false; } + if (dcp->hw.s2r && !dcp->hw.s2r_layout) { + int ret = dcp_s2r_layout_from_dt(dcp) ?: dcp_s2r_layout_streams(dcp); + + if (ret) { + dev_info(dcp->dev, "no display power layout (%d), the firmware keeps running\n", + ret); + dcp->s2r_dt_layout_ok = false; + dcp->hw.s2r = false; + } + } if (dcp->hw.s2r_ext && !power) { dev_info(dcp->dev, "no apple,display-power in the device tree, the firmware keeps running\n"); dcp->hw.s2r_ext = false; @@ -522,7 +655,7 @@ static bool dcp_j714s_ext(struct device *dev) static bool s2r_untested; module_param(s2r_untested, bool, 0444); MODULE_PARM_DESC(s2r_untested, - "Stop the DCP firmware on DPMS off and J813 system sleep using derived T8142 power words (default 0)"); + "Stop the DCP firmware on DPMS off and system sleep using derived T8142 power words (default 0)"); bool dcp_t6041_ext_enabled(void) { @@ -6527,6 +6660,20 @@ static enum dcp_firmware_version dcp_check_firmware_version(struct device *dev) return dcp_v27_method_table(dev, compat_str); } + /* + * The T8132 internal panel's processor on the macOS 27.2 stub, handed + * over by the boot loader with the 26B123 image (see + * apple_t8132_dcp_v27_2()): the firmware-27 backend with the 27.2 + * method table. That this image numbers its IOMFB methods as the + * T6041 and T8142 26B123 images do is the same assumption the J773g + * dcpext case above makes. + */ + if (apple_t8132_dcp_v27_2(dev->of_node)) { + /* Checked by apple_t8132_dcp_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 @@ -8230,6 +8377,27 @@ static const struct apple_dcp_hw_data apple_dcp_hw_t8132_dcpext_v27 = { .sink_metadata_edid = true, }; +/* + * T8132 internal display processor on firmware 27.2, admitted by + * dcp_check_firmware_version(), whatever hw data its compatible matched: + * - firmware_dma_bits 41: its firmware DART's window (apple,dma-range + * <0x100 0 0x10 0>, 1 TiB + 64 GiB) takes 41 bits, as the dcpext's does. + * - num_dptx_ports 0: it drives the panel only. + * - adopt_live_session: iBoot leaves it running with the 27.2 image and the + * panel lit; Linux never starts its CPU. + * - s2r: the firmware-27 stop (iomfb_v27.c) for DPMS off and deep sleep, + * with the 27.2 table's calls and the power words its device tree names + * (dcp_s2r_layout_from_dt()). It has no secure mailbox. + */ +static const struct apple_dcp_hw_data apple_dcp_hw_t8132_v27 = { + .firmware_dma_bits = 41, + .num_dptx_ports = 0, + .adopt_live_session = true, + .firmware_compat = DCP_FIRMWARE_V_27_0, + .s2r = true, + .s2r_no_secure_port = 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); @@ -8443,11 +8611,17 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) 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; + if (fw_compat == DCP_FIRMWARE_V_27_0 && + of_device_is_compatible(dev->of_node, "apple,t8132-dcp")) + dcp->hw = apple_dcp_hw_t8132_v27; /* - * A SoC with derived power words is offered the stop only when asked for, and only on + * A stop needs power words: a static layout, or the device tree's (see + * dcp_s2r_layout_from_dt(), offered by default). A SoC whose static words are only + * derived (hw.s2r_untested, T8142) is offered it only when asked for, and only on * firmware 27.0, whose calls are the ones that ran with them. */ - if (dcp->hw.s2r && (!dcp->hw.s2r_layout || + if (dcp->hw.s2r && ((!dcp->hw.s2r_layout && + !of_property_present(dev->of_node, "apple,display-power")) || (dcp->hw.s2r_untested && (!s2r_untested || fw_compat != DCP_FIRMWARE_V_27_0)))) dcp->hw.s2r = false; @@ -9506,7 +9680,9 @@ static const struct dcp_s2r_layout *dcp_s2r_layout(struct apple_dcp *dcp) { if (dcp_s2r_is_t8142_ext(dcp)) return &dcp_s2r_t8142_ext[dcp->index - 1]; - return dcp->hw.s2r_layout ?: &dcp_s2r_t8140; + if (dcp->hw.s2r_layout) + return dcp->hw.s2r_layout; + return dcp->s2r_dt_layout_ok ? &dcp->s2r_dt_layout : &dcp_s2r_t8140; } /* T6041's display stop and restart for its own sleep driver, below: T8140's DART streams. */ @@ -10068,6 +10244,12 @@ static void dcp_s2r_ps_lower(void __iomem *reg) writel((val & ~GENMASK(3, 0)) | GENMASK(9, 8), reg); } +/* A retention word: the whole of it from a hw-data layout, only its masked bits from the DT's. */ +static void dcp_s2r_ret_write(void __iomem *reg, u32 mask, u32 val, u32 word) +{ + writel(mask ? (readl(reg) & ~mask) | (val & mask) : word, reg); +} + /* Its display-power words, pwrgate and pmc-dcp only where the layout has them. */ static int dcp_s2r_map_power(struct apple_dcp *dcp, void __iomem **ps, void __iomem **pwrgate, void __iomem **pmc) @@ -10117,8 +10299,8 @@ static int dcp_s2r_domains_off(struct apple_dcp *dcp) if (val & BIT(28)) writel(val & ~(BIT(28) | GENMASK(9, 8)), ps + l->disp_cpu); if (l->ret_ff) { - writel(3, pwrgate + l->ret_ff); - writel(0, pwrgate + l->ret_mem); + dcp_s2r_ret_write(pwrgate + l->ret_ff, l->ret_ff_mask, l->ret_ff_off, 3); + dcp_s2r_ret_write(pwrgate + l->ret_mem, l->ret_mem_mask, l->ret_mem_off, 0); } dcp_s2r_ps_lower(ps + l->disp_cpu); dcp_s2r_ps_lower(ps + l->disp_fe); @@ -10174,8 +10356,8 @@ static int dcp_s2r_domains_on(struct apple_dcp *dcp) } writel(val | 0xf, ps + l->disp_cpu); if (l->ret_ff) { - writel(0, pwrgate + l->ret_ff); - writel(1, pwrgate + l->ret_mem); + dcp_s2r_ret_write(pwrgate + l->ret_ff, l->ret_ff_mask, l->ret_ff_on, 0); + dcp_s2r_ret_write(pwrgate + l->ret_mem, l->ret_mem_mask, l->ret_mem_on, 1); } writel(val | 0xf | BIT(28), ps + l->disp_cpu); if (pmc) @@ -11085,12 +11267,11 @@ static int dcp_platform_suspend(struct device *dev) } /* - * J813 uses the same qualified stop as DPMS off. Probe already gates - * its derived power layout on appledrm.s2r_untested; without this - * system-suspend path an active panel leaves the DCP running. + * The same stop as DPMS off; without this system-suspend path an active + * panel leaves the DCP running. Probe already gates a derived power + * layout (T8142) on appledrm.s2r_untested. */ - if (pm_suspend_via_firmware() && dcp_s2r_capable(dcp) && - (!dcp->hw.s2r_untested || of_machine_is_compatible("apple,j813"))) { + if (pm_suspend_via_firmware() && dcp_s2r_capable(dcp)) { int ret = dcp_s2r_suspend(dcp); /* Lit by the last resume with its CRTC off: the next resume finds it off by DPMS. */ diff --git a/drivers/gpu/drm/apple/iomfb_m4.c b/drivers/gpu/drm/apple/iomfb_m4.c index a85010b15c719..da94f912821e4 100644 --- a/drivers/gpu/drm/apple/iomfb_m4.c +++ b/drivers/gpu/drm/apple/iomfb_m4.c @@ -2725,7 +2725,12 @@ int iomfb_m4_init(struct apple_dcp *owner) return -ENOMEM; dcp->owner = owner; dcp->dev = dev; - dcp->bw_mailbox = dcp_m4_bw_mailbox(dev); + /* + * The 26.6.2 panel path runs without the realtime bandwidth mailbox; + * the slot the DT gives the internal DCP is the firmware-27 backend's. + */ + if (external) + dcp->bw_mailbox = dcp_m4_bw_mailbox(dev); mutex_init(&dcp->lock); mutex_init(&dcp->ext_modes_lock); spin_lock_init(&dcp->state_lock); diff --git a/drivers/iommu/apple-dart-test.c b/drivers/iommu/apple-dart-test.c index b6b0d1690bd95..a7ae726f341a6 100644 --- a/drivers/iommu/apple-dart-test.c +++ b/drivers/iommu/apple-dart-test.c @@ -1481,6 +1481,164 @@ static void apple_dart_test_host_power_tables(struct kunit *test) } #endif +/* A zeroed 16 KiB page marked reserved, as the firmware's tables are. */ +static void apple_dart_test_free_reserved(void *data) +{ + struct page *page = data; + + ClearPageReserved(page); + __free_pages(page, get_order(SZ_16K)); +} + +static u64 *apple_dart_test_reserved_table(struct kunit *test) +{ + struct page *page = alloc_pages(GFP_KERNEL | __GFP_ZERO, get_order(SZ_16K)); + + KUNIT_ASSERT_NOT_NULL(test, page); + SetPageReserved(page); + KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, apple_dart_test_free_reserved, page), + 0); + return page_address(page); +} + +/* + * fw_mirror from the DART's own state: a T8132 DART its handed-over internal + * DCP names mirrors when locked without reserved tables and not borrowed; any + * other locked T8132 DART (the PMP's) keeps the retained-root path. + */ +static void apple_dart_test_t8132_fw_mirror_selection(struct kunit *test) +{ + struct apple_dart dart = { .locked = true }; + + KUNIT_EXPECT_TRUE(test, apple_dart_selects_fw_mirror(&dart, NULL, true)); + /* A locked T8132 DART no display processor names: the PMP's. */ + KUNIT_EXPECT_FALSE(test, apple_dart_selects_fw_mirror(&dart, NULL, false)); + + dart.locked = false; + KUNIT_EXPECT_FALSE(test, apple_dart_selects_fw_mirror(&dart, NULL, true)); + dart.locked = true; + dart.fw_handoff = true; + KUNIT_EXPECT_FALSE(test, apple_dart_selects_fw_mirror(&dart, NULL, true)); + dart.fw_handoff = false; + dart.preserve_display = true; + KUNIT_EXPECT_FALSE(test, apple_dart_selects_fw_mirror(&dart, NULL, true)); +} + +/* + * A fw_mirror DART (here a T8132 internal display DART's layout): re-exported + * firmware segments take the protection of the live leaves that map them + * (read-only text, cacheable data); a region whose leaf maps another page + * keeps what it asked for. Any DART that is not fw_mirror is left alone. + */ +static void apple_dart_test_fw_mirror_prot(struct kunit *test) +{ + const u64 fields = GENMASK_ULL(51, 40) | BIT_ULL(0); + const phys_addr_t text_pa = 0x80000000ULL, data_pa = 0x80100000ULL; + const u64 dva = 0x10000000000ULL + (3ULL << 25); + struct iommu_resv_region text = {}, data = {}, moved = {}, mixed = {}, outside = {}; + struct apple_dart_master_cfg master = {}; + struct apple_dart *dart; + LIST_HEAD(head); + u64 *root, *leaf; + void *regs; + + if (PAGE_SIZE < SZ_16K) + kunit_skip(test, "needs kernel pages of at least 16 KiB"); + dart = kunit_kzalloc(test, sizeof(*dart), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, dart); + dart->dev = kunit_device_register(test, "apple-dart-fw-mirror-prot-test"); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dart->dev); + regs = vzalloc(APPLE_DART_TEST_REGS_SIZE); + KUNIT_ASSERT_NOT_NULL(test, regs); + KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, apple_dart_test_vfree, regs), 0); + dart->regs = (__force void __iomem *)regs; + dart->hw = &apple_dart_hw_t8110; + dart->pgsize = SZ_16K; + dart->num_streams = 32; + dart->oas = 42; + dart->locked = true; + dart->fw_mirror = true; + /* The display DARTs' window: 64 GiB at 1 TiB. */ + dart->locked_window[23] = 0x10000000000ULL; + root = apple_dart_test_reserved_table(test); + leaf = apple_dart_test_reserved_table(test); + KUNIT_ASSERT_TRUE(test, IS_ALIGNED(virt_to_phys(root) | virt_to_phys(leaf), SZ_16K)); + writel(((virt_to_phys(root) >> dart->hw->ttbr_shift) << dart->hw->ttbr_addr_field_shift) | + dart->hw->ttbr_valid, dart->regs + DART_TTBR(dart, 23, 0)); + root[3] = (virt_to_phys(leaf) >> 4) | BIT_ULL(0); + /* Text: two read-only pages; data: one read-write page; all cacheable. */ + leaf[0] = fields | (text_pa >> 4) | BIT_ULL(2); + leaf[1] = fields | ((text_pa + SZ_16K) >> 4) | BIT_ULL(2); + leaf[2] = fields | (data_pa >> 4); + /* Two pages that disagree: one read-only, one read-write. */ + leaf[4] = fields | ((data_pa + SZ_32K) >> 4) | BIT_ULL(2); + leaf[5] = fields | ((data_pa + SZ_32K + SZ_16K) >> 4); + text = (struct iommu_resv_region){ .start = text_pa, .dva = dva, .length = SZ_32K, + .prot = IOMMU_READ | IOMMU_WRITE, .type = IOMMU_RESV_TRANSLATED }; + data = (struct iommu_resv_region){ .start = data_pa, .dva = dva + SZ_32K, .length = SZ_16K, + .prot = IOMMU_READ | IOMMU_WRITE, .type = IOMMU_RESV_TRANSLATED }; + moved = (struct iommu_resv_region){ .start = data_pa + SZ_16K, .dva = dva + SZ_32K, + .length = SZ_16K, .prot = IOMMU_READ | IOMMU_WRITE, .type = IOMMU_RESV_TRANSLATED }; + mixed = (struct iommu_resv_region){ .start = data_pa + SZ_32K, .dva = dva + SZ_64K, + .length = SZ_32K, .prot = IOMMU_READ | IOMMU_WRITE, .type = IOMMU_RESV_TRANSLATED }; + /* 64 GiB higher: the same slot bits, outside the window. */ + outside = (struct iommu_resv_region){ .start = text_pa, .dva = dva + SZ_64G, + .length = SZ_32K, .prot = IOMMU_READ | IOMMU_WRITE, .type = IOMMU_RESV_TRANSLATED }; + list_add_tail(&text.list, &head); + list_add_tail(&data.list, &head); + list_add_tail(&moved.list, &head); + list_add_tail(&mixed.list, &head); + list_add_tail(&outside.list, &head); + master.stream_maps[0].dart = dart; + __set_bit(23, master.stream_maps[0].sidmap); + pm_runtime_set_active(dart->dev); + pm_runtime_enable(dart->dev); + + __apple_dart_fw_mirror_prot(&master, dart->dev, &head); + KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_CACHE); + KUNIT_EXPECT_EQ(test, data.prot, IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE); + KUNIT_EXPECT_EQ(test, moved.prot, IOMMU_READ | IOMMU_WRITE); + KUNIT_EXPECT_EQ(test, mixed.prot, IOMMU_READ | IOMMU_WRITE); + KUNIT_EXPECT_EQ(test, outside.prot, IOMMU_READ | IOMMU_WRITE); + + /* A leaf table outside reserved RAM is never mapped: nothing changes. */ + text.prot = IOMMU_READ | IOMMU_WRITE; + ClearPageReserved(virt_to_page(leaf)); + __apple_dart_fw_mirror_prot(&master, dart->dev, &head); + SetPageReserved(virt_to_page(leaf)); + KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_WRITE); + + /* A four-level root is not walked: nothing changes. */ + text.prot = IOMMU_READ | IOMMU_WRITE; + writel(dart->hw->tcr_4level, dart->regs + DART_TCR(dart, 23)); + __apple_dart_fw_mirror_prot(&master, dart->dev, &head); + writel(0, dart->regs + DART_TCR(dart, 23)); + KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_WRITE); + + /* + * Not fw_mirror (a locked DART on the retained-root path, such as the + * T8132 PMP's), with reserved tables, or unlocked: nothing changes. + */ + text.prot = IOMMU_READ | IOMMU_WRITE; + dart->fw_mirror = false; + __apple_dart_fw_mirror_prot(&master, dart->dev, &head); + KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_WRITE); + dart->fw_mirror = true; + dart->fw_handoff = true; + __apple_dart_fw_mirror_prot(&master, dart->dev, &head); + KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_WRITE); + dart->fw_handoff = false; + dart->locked = false; + __apple_dart_fw_mirror_prot(&master, dart->dev, &head); + KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_WRITE); + dart->locked = true; + + /* The same DART back on fw_mirror takes the leaves' protection again. */ + __apple_dart_fw_mirror_prot(&master, dart->dev, &head); + KUNIT_EXPECT_EQ(test, text.prot, IOMMU_READ | IOMMU_CACHE); + pm_runtime_disable(dart->dev); +} + static struct kunit_case apple_dart_test_cases[] = { KUNIT_CASE(apple_dart_test_strict_engines), KUNIT_CASE(apple_dart_test_topology), @@ -1493,6 +1651,8 @@ static struct kunit_case apple_dart_test_cases[] = { KUNIT_CASE(apple_dart_test_locked_handoff), KUNIT_CASE(apple_dart_test_sync_unknown_roots), KUNIT_CASE(apple_dart_test_firmware_roots), + KUNIT_CASE(apple_dart_test_t8132_fw_mirror_selection), + KUNIT_CASE(apple_dart_test_fw_mirror_prot), KUNIT_CASE(apple_dart_test_unmap_flush_after_publish_failure), KUNIT_CASE(apple_dart_test_gated_commands), KUNIT_CASE(apple_dart_test_resume_commands_failure), diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index c630e5a248b15..4153f86611f2e 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -4960,6 +4960,116 @@ static void apple_dart_get_fw_resv_regions(struct device *dev, } } +/* + * A fw_mirror DART (locked, no reserved-table handoff, not borrowed) on a + * three-level root: a boot loader may re-export the firmware's own segments + * as iommu-addresses, which the core maps read-write, and uncached for a + * non-coherent client such as a DCP. The firmware's leaves say what those + * pages are: its text read-only, all of it cacheable. A Linux table in a slot + * the firmware holds must mirror its leaves exactly (apple_dart_fw_slot_mirrors(), + * apple_dart_check_fw_map()), so give each such region the protection the + * live leaves give every one of its pages. A region whose pages are not mapped + * there, map elsewhere or disagree keeps its protection, and the attach then + * refuses it as before. A region whose protection already matches is left + * alone, so this changes only a mapping the attach would otherwise refuse. + */ +static void __apple_dart_fw_mirror_prot(struct apple_dart_master_cfg *cfg, + struct device *dev, struct list_head *head) +{ + const int mask = IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE; + struct iommu_resv_region *region; + struct apple_dart *dart; + phys_addr_t table; + u64 *root, span, base; + size_t entries; + u32 ttbr, tcr = 0; + int sid; + + if (!cfg || !cfg->stream_maps[0].dart || cfg->stream_maps[1].dart) + return; + dart = cfg->stream_maps[0].dart; + if (!dart->fw_mirror || dart->fw_handoff || !dart->locked || + dart->hw->fmt != APPLE_DART2) + return; + entries = dart->pgsize / sizeof(u64); + sid = find_first_bit(cfg->stream_maps[0].sidmap, dart->num_streams); + if (sid >= dart->num_streams || + bitmap_weight(cfg->stream_maps[0].sidmap, dart->num_streams) != 1) + return; + if (pm_runtime_resume_and_get(dart->dev) < 0) + return; + /* Read both registers while the DART is held powered. */ + ttbr = apple_dart_readl(dart, DART_TTBR(dart, sid, 0)); + if (dart->hw->tcr_4level) + tcr = apple_dart_readl(dart, DART_TCR(dart, sid)); + pm_runtime_put(dart->dev); + if (!(ttbr & dart->hw->ttbr_valid) || (tcr & dart->hw->tcr_4level)) + return; + ttbr &= ~dart->hw->ttbr_valid; + if (dart->hw->ttbr_addr_field_shift) + ttbr >>= dart->hw->ttbr_addr_field_shift; + table = ((phys_addr_t)ttbr) << dart->hw->ttbr_shift; + /* Only a firmware table in reserved RAM is mapped write-back, as elsewhere. */ + if (!apple_dart_fw_table_ram(dart, table)) + return; + root = memremap(table, dart->pgsize, MEMREMAP_WB); + if (!root) + return; + /* A three-level root walks one span of the stream's window (DVA bits 14..35). */ + span = BIT_ULL(ilog2(dart->pgsize) + 2 * ilog2(entries)); + base = READ_ONCE(dart->locked_window[sid]) & ~(span - 1); + + list_for_each_entry(region, head, list) { + u64 *leaf = NULL; + size_t mapped_slot = entries; + int prot = -1; + + if (region->type != IOMMU_RESV_TRANSLATED || !region->length || + !IS_ALIGNED(region->dva | region->start | region->length, dart->pgsize)) + continue; + /* Outside the window the slot bits would alias another region's leaves. */ + if (region->dva < base || region->length > span || + region->dva - base > span - region->length) + continue; + for (u64 off = 0; off < region->length; off += dart->pgsize) { + u64 dva = region->dva + off; /* bits 14..35: the 1 TiB base drops out */ + size_t slot = (dva >> (ilog2(dart->pgsize) + ilog2(entries))) & (entries - 1); + size_t idx = (dva >> ilog2(dart->pgsize)) & (entries - 1); + u64 entry = READ_ONCE(root[slot]); + phys_addr_t phys; + int page_prot; + + if (slot != mapped_slot) { + if (leaf) + memunmap(leaf); + leaf = apple_dart_fw_table_decode(dart, entry, &table) ? + memremap(table, dart->pgsize, MEMREMAP_WB) : NULL; + mapped_slot = slot; + } + if (!leaf || + !apple_dart_fw_leaf_decode(READ_ONCE(leaf[idx]), 0, &phys, &page_prot) || + phys != region->start + off || (prot >= 0 && page_prot != prot)) { + prot = -1; + break; + } + prot = page_prot; + } + if (leaf) + memunmap(leaf); + if (prot >= 0 && (region->prot & mask) != (prot & mask)) { + dev_info(dev, "firmware segment %pad+%#zx: protection %#x as its live leaves (asked %#x)\n", + ®ion->dva, region->length, prot & mask, region->prot & mask); + region->prot = (region->prot & ~mask) | (prot & mask); + } + } + memunmap(root); +} + +static void apple_dart_fw_mirror_prot(struct device *dev, struct list_head *head) +{ + __apple_dart_fw_mirror_prot(dev_iommu_priv_get(dev), dev, head); +} + static void apple_dart_get_resv_regions(struct device *dev, struct list_head *head) { @@ -4989,6 +5099,7 @@ static void apple_dart_get_resv_regions(struct device *dev, /* Keep the translated-domain requirement and inherited translations. */ iommu_dma_get_resv_regions(dev, head); + apple_dart_fw_mirror_prot(dev, head); apple_dart_get_fw_resv_regions(dev, head); } @@ -5755,6 +5866,67 @@ static bool apple_dart_is_available(struct device_node *np) return false; } +/* Whether @consumer names @dart_np in its iommus. */ +static bool apple_dart_np_is_iommu_of(const struct device_node *consumer, + const struct device_node *dart_np) +{ + struct of_phandle_args args; + + for (int i = 0; !of_parse_phandle_with_args(consumer, "iommus", "#iommu-cells", i, &args); + i++) { + bool match = args.np == dart_np; + + of_node_put(args.np); + if (match) + return true; + } + return false; +} + +/* + * Whether @dart_np serves an available T8132 internal display processor that + * the boot loader handed over with its firmware clocks (apple,clock-ids, from + * the ADT's /arm-io/disp0): its firmware DART (the processor's iommus) or its + * display DART (its PIODMA's). Those clocks are what the firmware-27 backend + * needs and what tells its handoff from the M4 26.6.2 one, whose DARTs are + * borrowed. The DART is keyed on what uses it, not on its address, the board + * or the firmware build: a PMP or external display DART is never named here, + * and an idle main DCP (a Mac mini's) is not handed over. + */ +static bool apple_dart_serves_t8132_dcp(const struct device_node *dart_np) +{ + struct device_node *np, *child; + bool serves = false; + + for_each_compatible_node(np, NULL, "apple,t8132-dcp") { + if (serves || !of_device_is_available(np) || + !of_property_present(np, "apple,clock-ids")) + continue; + serves = apple_dart_np_is_iommu_of(np, dart_np); + for_each_child_of_node(np, child) + if (!serves && apple_dart_np_is_iommu_of(child, dart_np)) + serves = true; + } + return serves; +} + +/* + * Whether a locked DART keeps its firmware's roots and mirrors Linux mappings + * into them (fw_mirror): it is locked, its boot loader handed over no reserved + * tables (fw_handoff), and no display driver borrows its live roots + * (preserve_display). That is the DART's own state; which DARTs take it is the + * SoC's (T6041, T6050, T8140, T8142: every one) or, on T8132, the DARTs of its + * handed-over internal display processor (@t8132_dcp). Other locked T8132 + * DARTs, the PMP's among them, keep the retained-root path they always had. + */ +static bool apple_dart_selects_fw_mirror(const struct apple_dart *dart, + const struct device_node *np, bool t8132_dcp) +{ + if (!dart->locked || dart->fw_handoff || dart->preserve_display) + return false; + return apple_dart_keeps_locked_roots(np) || t8132_dcp; +} + static int apple_dart_probe(struct platform_device *pdev) { int ret, sid; @@ -5767,7 +5939,7 @@ static int apple_dart_probe(struct platform_device *pdev) bool tunneled = dev->of_node->parent && of_node_name_prefix(dev->of_node->parent, "usb4-pcie-tunnel-"); - bool j713_display, j713_dcpext, j713_dispext, j713_radio; + bool j713_display, j713_dcpext, j713_dispext, j713_radio, t8132_dcp = false; bool cold_avd = of_device_is_compatible(dev->of_node, "apple,t8152-avd-dart"); /* @@ -5780,6 +5952,19 @@ static int apple_dart_probe(struct platform_device *pdev) j713_display = res && !tunneled && of_device_is_compatible(dev->of_node, "apple,t8132-dart") && (res->start == 0x30a300000ULL || res->start == 0x30a340000ULL); + /* + * An internal DCP handed over with its firmware clocks runs the + * firmware-27 backend, which DMAs through ordinary domains (RTKit and + * IOMFB shared memory, PIODMA maps) as on T6041. Its two display DARTs + * are then not borrowed: they keep their firmware's locked roots the way + * T6041's do (fw_mirror below). The borrowed path admits only the 26.6.2 + * layout and reserves its whole SID23 window from generic DMA. + */ + t8132_dcp = res && !tunneled && + of_device_is_compatible(dev->of_node, "apple,t8132-dart") && + apple_dart_serves_t8132_dcp(dev->of_node); + if (t8132_dcp) + j713_display = false; /* The external DCP firmware DARTs (SID23) of dcpext0 and dcpext1. */ j713_dcpext = res && !tunneled && apple_t8132_firmware_path() && of_device_is_compatible(dev->of_node, "apple,t8132-dart") && @@ -6376,8 +6561,22 @@ static int apple_dart_probe(struct platform_device *pdev) * T6050's boot loader leaves every display DART locked on four-level * roots of its own (dart-dcpextN SID 23, dart-dispextN SIDs 0 and 16). */ - dart->fw_mirror = dart->locked && !dart->fw_handoff && - apple_dart_keeps_locked_roots(dev->of_node); + dart->fw_mirror = apple_dart_selects_fw_mirror(dart, dev->of_node, t8132_dcp); + /* + * The firmware-27 backend runs on the locked roots alone: a DART that + * is not locked, or whose boot loader also handed over reserved tables, + * is not the handoff it was written for. Refuse either, saying which. + */ + if (t8132_dcp && dart->fw_mirror) + dev_info(dev, "T8132 internal display DART: locked roots kept (mirror)\n"); + else if (t8132_dcp && !dart->locked) + dev_err(dev, "T8132 internal display DART: NOT locked: refusing\n"); + else if (t8132_dcp) + dev_err(dev, "T8132 internal display DART: locked with a reserved-table handoff: refusing\n"); + if (t8132_dcp && !dart->fw_mirror) { + ret = -EINVAL; + goto err_clk_disable; + } /* * 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 @@ -8439,6 +8638,29 @@ int apple_dart_display_streams(struct device *dev, u32 streams, bool on, bool fl } EXPORT_SYMBOL_GPL(apple_dart_display_streams); +/* + * The streams a T8110 display DART has enabled, read while its domain is up: what a DCP + * whose device tree names no streams stops and enables again around its power cycle. The + * mask holds streams 0 to 31; a DART with any stream above them enabled can't be described + * by it and reads 0, which its caller takes as no streams to stop. + */ +u32 apple_dart_enabled_streams(struct device *dev) +{ + struct apple_dart *dart = dev_get_drvdata(dev); + unsigned int i; + + if (!dart || dart->hw->type != DART_T8110) + return 0; + for (i = 1; i < DIV_ROUND_UP(dart->num_streams, 32); i++) { + if (readl(dart->regs + DART_T8110_ENABLE_STREAMS + 4 * i)) { + dev_warn_once(dart->dev, "streams above 31 enabled: not reported\n"); + return 0; + } + } + return readl(dart->regs + DART_T8110_ENABLE_STREAMS); +} +EXPORT_SYMBOL_GPL(apple_dart_enabled_streams); + /* * A DART whose domain goes off with its consumer's, at runtime, while other users still map * into it: dark, maps reach memory only and their invalidations wait; lit, those run. Its diff --git a/include/linux/soc/apple/dart.h b/include/linux/soc/apple/dart.h index 15e7c256999e8..a25ab9ec840a7 100644 --- a/include/linux/soc/apple/dart.h +++ b/include/linux/soc/apple/dart.h @@ -221,6 +221,8 @@ int apple_dart_sleep_prepare(struct device *dev); void apple_dart_sleep_restore(struct device *dev); /* A display DART's streams around a display power cycle, see the DART driver. */ int apple_dart_display_streams(struct device *dev, u32 streams, bool on, bool flush); +/* The streams 0 to 31 a display DART has enabled; 0 if any stream above 31 is on. */ +u32 apple_dart_enabled_streams(struct device *dev); /* A locked display DART's TCR and TTBR words kept across a real sleep (T6041). */ int apple_dart_display_keep(struct device *dev, u32 streams, bool save); /* A GAPF slice released before its coprocessor's CPU domain comes up after a wake. */ @@ -257,6 +259,11 @@ static inline int apple_dart_display_streams(struct device *dev, u32 streams, bo return -ENODEV; } +static inline u32 apple_dart_enabled_streams(struct device *dev) +{ + return 0; +} + static inline int apple_dart_display_keep(struct device *dev, u32 streams, bool save) { return -ENODEV; diff --git a/include/linux/soc/apple/display.h b/include/linux/soc/apple/display.h index 7d35049b18669..9f252caabea75 100644 --- a/include/linux/soc/apple/display.h +++ b/include/linux/soc/apple/display.h @@ -52,6 +52,20 @@ static inline bool apple_dcp_image_v27_2(const struct device_node *np, compat[0] == 27 && compat[1] == 2 && compat[2] == 0; } +/* + * A T8132 internal display processor that the boot loader handed over with + * the 27.2 (26B123) image and the firmware-27 clock metadata (apple,clock-ids + * from the ADT's /arm-io/disp0): the firmware-27 backend's, not the M4 + * 26.6.2 one's. Keyed on the processor, the image and the handoff, so a main + * DCP a boot loader leaves running idle (a Mac mini's) is never adopted. + */ +static inline bool apple_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 inline bool apple_t6041_dcp_any_v27_2(const struct device_node *np, const char *compat_name) { diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py index b16366a175efa..14f46e0279025 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/boot.py @@ -205,6 +205,7 @@ def _v27_prelude(root): '#define APPLE_T8132_DCP_26B123_UUID '))] assert len(uuid_defines) == 3 helpers = ('static inline bool apple_dcp_image_v27_2(', + 'static inline bool apple_t8132_dcp_v27_2(', 'static inline bool apple_t6041_dcp_any_v27_2(', 'static inline bool apple_t6041_dcp_v27_2(', 'static inline bool apple_t6041_dcpext_v27_2(', @@ -259,6 +260,7 @@ def _v27_prelude(root): int fw_cells; u32 compat[DCP_FW_VERSION_MAX_LEN]; int compat_cells; + bool clock_ids; }; struct device { struct device_node *of_node; @@ -350,9 +352,11 @@ def _v27_prelude(root): { return dev->hw; } -/* No internal board profile is present in these fixtures. */ -static bool of_property_present(struct device_node *np, const char *name) +/* No internal board profile is present in these fixtures; apple,clock-ids is the handoff flag. */ +static bool of_property_present(const struct device_node *np, const char *name) { + if (!strcmp(name, "apple,clock-ids")) + return np && np->clock_ids; assert(!strcmp(name, "apple,j613-25g83-profile")); return false; } @@ -625,10 +629,47 @@ def t6041_v27_admission(root): 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)); + /* + * The internal DCP handed over with the T8132 27.2 image and its + * firmware-27 clocks (the M4 Air's on the 27.2 stub) runs the 27.2 + * table on any board and either firmware path; without the clocks it is + * the M4 backend's on its path and nobody's off it, as above. + */ + reset_t6041_26b123(false); + node.compatible = "apple,t8132-dcp"; + node.uuid = APPLE_T8132_DCP_26B123_UUID; + node.clock_ids = true; + for (unsigned path = 0; path < 2; path++) { + t8132_firmware_path = path; + assert(apple_t8132_dcp_v27_2(&node)); + assert(!apple_t8132_dcpext_v27_2(&node)); + assert(!apple_t6041_dcp_v27_2(&node)); + assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_V_27_0); + node.clock_ids = false; + assert(!apple_t8132_dcp_v27_2(&node)); + assert(dcp_check_firmware_version(&dev) == (path ? DCP_FIRMWARE_M4 : DCP_FIRMWARE_UNKNOWN)); + node.clock_ids = true; + } + t8132_firmware_path = true; + /* Not on a dcpext, nor with the T6041 image, a missing UUID or another release. */ + node.compatible = "apple,t8132-dcpext"; assert(!apple_t8132_dcp_v27_2(&node)); + node.compatible = "apple,t8132-dcp"; + node.uuid = APPLE_T6041_DCP_26B123_UUID; assert(!apple_t8132_dcp_v27_2(&node)); + assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_M4); + node.uuid = APPLE_T8132_DCP_26B123_UUID; + node.uuid_count = 0; assert(!apple_t8132_dcp_v27_2(&node)); + node.uuid_count = 1; + node.compat[1] = 0; assert(!apple_t8132_dcp_v27_2(&node)); + assert(dcp_check_firmware_version(&dev) == DCP_FIRMWARE_M4); + node.compat[1] = 2; assert(apple_t8132_dcp_v27_2(&node)); + node.clock_ids = false; + 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"); + puts("PASS T8132 internal DCP with the 27.2 image and its firmware-27 clocks runs the 27.2 table; without them nothing changes"); + puts("PASS T8132 internal DCP on the 27.2 image joins the DRM device on any board; off the M4 path nothing else does"); 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 b41b73ad7478f..3941f8bd0aebb 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py @@ -1597,6 +1597,8 @@ def function(source, marker): { 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 bool __attribute__((unused)) apple_t8132_dcp_v27_2(const struct device_node *n) +{ (void)n; assert(!"T8132 DCP 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; };