From e871c03cec199dd4ed93f5d8d649b1c735020c5f Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 05:57:14 +1100 Subject: [PATCH 01/16] soc: apple: rtkit: adopt a running session with its endpoint map A co-processor that a boot stage handed over running does not repeat HELLO or EPMAP, so its new owner cannot learn the endpoints from the firmware. apple_rtkit_init_adopted() and _with_buffers() assume every system endpoint and know no application endpoint, so apple_rtkit_start_ep() refuses all of the firmware's own services. Add apple_rtkit_init_adopted_with_session(). It takes what the previous owner negotiated: the protocol version, the endpoint map the firmware advertised and the retained system buffers. The map is copied before mailbox RX starts. Management must be in it, and a system endpoint this driver does not implement makes the session invalid instead of being ignored. Application endpoints are only advertised: the new owner starts each one as usual. The existing initialisers keep their behaviour. Signed-off-by: Ryan Murray --- drivers/soc/apple/rtkit.c | 72 ++++++++++++++++++++++++++++++--- include/linux/soc/apple/rtkit.h | 22 ++++++++++ 2 files changed, 89 insertions(+), 5 deletions(-) diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c index e529b4d4dd4c6..541f842840264 100644 --- a/drivers/soc/apple/rtkit.c +++ b/drivers/soc/apple/rtkit.c @@ -2289,12 +2289,54 @@ static int apple_rtkit_inherit_buffers( return 0; } +/* + * The endpoint map the previous owner received for this session. Management + * is always present; system endpoints are limited to those RTKit implements + * here, so that an unknown one is not silently ignored. + */ +static int apple_rtkit_inherit_endpoints( + struct apple_rtkit *rtk, const struct apple_rtkit_adopted_session *session) +{ + static const u8 system_endpoints[] = { + APPLE_RTKIT_EP_MGMT, APPLE_RTKIT_EP_CRASHLOG, + APPLE_RTKIT_EP_SYSLOG, APPLE_RTKIT_EP_DEBUG, + APPLE_RTKIT_EP_IOREPORT, APPLE_RTKIT_EP_COREANALYTICS, + APPLE_RTKIT_EP_OSLOG, APPLE_RTKIT_EP_TRACEKIT, + }; + DECLARE_BITMAP(known, APPLE_RTKIT_APP_ENDPOINT_START) = {}; + DECLARE_BITMAP(map, APPLE_RTKIT_MAX_ENDPOINTS); + unsigned int i; + + BUILD_BUG_ON(APPLE_RTKIT_ADOPTED_EPMAP_WORDS * 32 != + APPLE_RTKIT_MAX_ENDPOINTS); + + if (session->protocol_version < APPLE_RTKIT_MIN_SUPPORTED_VERSION || + session->protocol_version > APPLE_RTKIT_MAX_SUPPORTED_VERSION || + (rtk->ops->protocol_version && + session->protocol_version != rtk->ops->protocol_version)) + return -EINVAL; + + bitmap_from_arr32(map, session->epmap, APPLE_RTKIT_MAX_ENDPOINTS); + for (i = 0; i < ARRAY_SIZE(system_endpoints); i++) + set_bit(system_endpoints[i], known); + if (!test_bit(APPLE_RTKIT_EP_MGMT, map)) + return -EINVAL; + for (i = 0; i < APPLE_RTKIT_APP_ENDPOINT_START; i++) + if (test_bit(i, map) && !test_bit(i, known)) + return -EINVAL; + + bitmap_copy(rtk->endpoints, map, APPLE_RTKIT_MAX_ENDPOINTS); + rtk->version = session->protocol_version; + return 0; +} + static struct apple_rtkit *__apple_rtkit_init(struct device *dev, void *cookie, const char *mbox_name, int mbox_idx, const struct apple_rtkit_ops *ops, bool adopted, const struct apple_rtkit_inherited_buffer *buffers, - unsigned int count, bool track_saved) + unsigned int count, bool track_saved, + const struct apple_rtkit_adopted_session *session) { struct apple_rtkit *rtk; int ret; @@ -2376,6 +2418,12 @@ static struct apple_rtkit *__apple_rtkit_init(struct device *dev, void *cookie, /* Inherited system traffic may arrive as soon as mailbox RX is armed. */ if (adopted) apple_rtkit_mark_running(rtk); + /* The firmware's own endpoint map replaces the assumed one. */ + if (session) { + ret = apple_rtkit_inherit_endpoints(rtk, session); + if (ret) + goto destroy_wq; + } ret = apple_rtkit_claim_rx(rtk); if (ret) @@ -2403,7 +2451,7 @@ struct apple_rtkit *apple_rtkit_init(struct device *dev, void *cookie, const struct apple_rtkit_ops *ops) { return __apple_rtkit_init(dev, cookie, mbox_name, mbox_idx, ops, false, - NULL, 0, false); + NULL, 0, false, NULL); } EXPORT_SYMBOL_GPL(apple_rtkit_init); @@ -2412,7 +2460,7 @@ struct apple_rtkit *apple_rtkit_init_adopted(struct device *dev, void *cookie, const struct apple_rtkit_ops *ops) { return __apple_rtkit_init(dev, cookie, mbox_name, mbox_idx, ops, true, - NULL, 0, false); + NULL, 0, false, NULL); } EXPORT_SYMBOL_GPL(apple_rtkit_init_adopted); @@ -2471,10 +2519,24 @@ struct apple_rtkit *apple_rtkit_init_adopted_with_buffers( const struct apple_rtkit_inherited_buffer *buffers, unsigned int count) { return __apple_rtkit_init(dev, cookie, mbox_name, mbox_idx, ops, true, - buffers, count, false); + buffers, count, false, NULL); } EXPORT_SYMBOL_GPL(apple_rtkit_init_adopted_with_buffers); +struct apple_rtkit *apple_rtkit_init_adopted_with_session( + struct device *dev, void *cookie, const char *mbox_name, int mbox_idx, + const struct apple_rtkit_ops *ops, + const struct apple_rtkit_adopted_session *session) +{ + if (!session) + return ERR_PTR(-EINVAL); + + return __apple_rtkit_init(dev, cookie, mbox_name, mbox_idx, ops, true, + session->buffers, session->num_buffers, false, + session); +} +EXPORT_SYMBOL_GPL(apple_rtkit_init_adopted_with_session); + static int apple_rtkit_wait_for_completion(struct apple_rtkit *rtk, struct completion *c) { @@ -3528,7 +3590,7 @@ struct apple_rtkit *devm_apple_rtkit_init_m5_saved(struct device *dev, void *coo int ret; rtk = __apple_rtkit_init(dev, cookie, mbox_name, mbox_idx, ops, false, - NULL, 0, true); + NULL, 0, true, NULL); if (IS_ERR(rtk)) return rtk; ret = devm_add_action_or_reset(dev, apple_rtkit_free_wrapper, rtk); diff --git a/include/linux/soc/apple/rtkit.h b/include/linux/soc/apple/rtkit.h index 4db916bb89f09..0e604bf2b5932 100644 --- a/include/linux/soc/apple/rtkit.h +++ b/include/linux/soc/apple/rtkit.h @@ -186,6 +186,28 @@ struct apple_rtkit *apple_rtkit_init_adopted_with_buffers( const struct apple_rtkit_ops *ops, const struct apple_rtkit_inherited_buffer *buffers, unsigned int count); +#define APPLE_RTKIT_ADOPTED_EPMAP_WORDS 8 + +/* + * Negotiated state from the previous owner of a running session: the + * protocol version, the endpoint map the firmware advertised (word i holds + * endpoints 32i..32i+31) and the retained system buffers. The parent driver + * verifies that the co-processor runs and the backing of each buffer. + * Application endpoints in the map each need a start from the new owner. + * Everything is copied before mailbox RX starts. + */ +struct apple_rtkit_adopted_session { + const struct apple_rtkit_inherited_buffer *buffers; + unsigned int num_buffers; + u32 epmap[APPLE_RTKIT_ADOPTED_EPMAP_WORDS]; + u16 protocol_version; +}; + +struct apple_rtkit *apple_rtkit_init_adopted_with_session( + struct device *dev, void *cookie, const char *mbox_name, int mbox_idx, + const struct apple_rtkit_ops *ops, + const struct apple_rtkit_adopted_session *session); + /* * Free an instance of apple_rtkit. */ From abea85f0c40b673e2c8f76e7f71c5eb6b3b09721 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 05:57:15 +1100 Subject: [PATCH 02/16] drm/apple: dcp: admit a firmware-27 DCP by its method table dcp_check_firmware_version() admits the 27.x firmware ABI per SoC (T8122, T6041, the firmware-27 match data). A DCP whose loader reports a 27.x firmware-compat with a complete method table on another SoC, such as the M2 Mac mini's on the 27.2 stub, is refused with "firmware-compat 27.2.0 is not supported" although the table exists. When no legacy implementation matched, accept the reported ABI if iomfb_v27_methods() has a table for it. Nothing changes for a version a legacy path already handles or for one without a table. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 39bccc811e160..317752aa45c20 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -6120,6 +6120,14 @@ static enum dcp_firmware_version dcp_check_firmware_version(struct device *dev) (strncmp(fw_str, "14.7.0", sizeof(compat_str)) == 0)) return DCP_FIRMWARE_V_14_7_TEMPLATE; + /* + * The loader reports the method ABI for each DCP. Legacy match data + * leaves the ABI to this property, so accept a complete table here + * when the reported ABI has no legacy implementation. + */ + if (iomfb_v27_methods(compat_str)) + return dcp_v27_method_table(dev, compat_str); + dev_err(dev, "DCP firmware-compat %s (FW: %s) is not supported\n", compat_str, fw_str); From 3563449568b92e5fa7265af96826737e3ef1e7b6 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 05:57:30 +1100 Subject: [PATCH 03/16] drm/apple: dcp: adopt a DCP that a boot stage handed over running A boot stage that drives a display through a DCP can hand the DCP on running, its RTKit session negotiated and its system buffers mapped. Such firmware does not repeat HELLO or EPMAP, so apple_rtkit_wake() times out in endpoint discovery (-ETIME) and the DRM device does not bind. The boot stage describes the session on the DCP node: apple,rtkit-live (layout 1), apple,rtkit-version, apple,rtkit-epmap (eight cells, cell i = endpoints 32i..32i+31) and apple,rtkit-live-buffers ( for each system buffer). When the node has it, check that the co-processor runs, that each buffer lies inside one of the node's reserved-memory carveouts (the regions the IOMMU core keeps mapped when it takes over a locked display DART) and that the DART translates its IOVA to that memory. Then initialise RTKit with the adopted session and skip the wake. An unknown layout or a buffer that fails a check fails the bind instead of starting the firmware a second time. Behaviour follows the description, not the SoC or firmware version: hw.adopt_live_session is set from the property, and a DCP without it boots as before. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp-internal.h | 2 + drivers/gpu/drm/apple/dcp.c | 179 ++++++++++++++++++++++++++- 2 files changed, 179 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 515e6bf065f09..68ccf32aad930 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -473,6 +473,8 @@ struct apple_dcp { struct iomfb_m4 *v26_6; /* An adopted session has no confirmed firmware DMA stop boundary. */ bool retain_dma; + /* RTKit session handed over running by a boot stage (apple,rtkit-live) */ + bool rtkit_adopted; /* * Allocates AFK rings where the DMA API cannot, on an adopted * J713 external DCP whose DART only takes the retained allocator. diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 317752aa45c20..bd8eb7c6a368a 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -1843,6 +1844,160 @@ static int dcp_check_iova_contiguous(struct iommu_domain *domain, return 0; } +#define DCP_RTKIT_LIVE_V1 1 +#define DCP_RTKIT_LIVE_BUFFER_CELLS 8 +#define DCP_RTKIT_LIVE_MAX_BUFFERS 4 +#define DCP_RTKIT_LIVE_LOADER_OWNED BIT(0) + +struct dcp_rtkit_live { + struct apple_rtkit_adopted_session session; + struct apple_rtkit_inherited_buffer buffers[DCP_RTKIT_LIVE_MAX_BUFFERS]; +}; + +/* + * Inside one of this DCP's reserved-memory carveouts. Those are also what the IOMMU + * core rebuilds the DCP's DART mappings from when it takes over a locked + * root, so a buffer outside them would lose its mapping at attach. + */ +static bool dcp_rtkit_live_carveout(struct device_node *np, phys_addr_t phys, + size_t size) +{ + int i, count = of_count_phandle_with_args(np, "memory-region", NULL); + bool found = false; + + for (i = 0; !found && i < count; i++) { + struct device_node *mem = of_parse_phandle(np, "memory-region", i); + struct reserved_mem *rmem; + + if (!mem) + break; + rmem = of_reserved_mem_lookup(mem); + /* A reusable (CMA) region could be handed out by the kernel. */ + found = rmem && !of_property_present(mem, "reusable") && + phys >= rmem->base && size <= rmem->size && + phys - rmem->base <= rmem->size - size; + of_node_put(mem); + } + return found; +} + +static void dcp_rtkit_live_unmap(struct dcp_rtkit_live *live) +{ + unsigned int i; + + for (i = 0; i < live->session.num_buffers; i++) + vunmap(live->buffers[i].shmem.private); + live->session.num_buffers = 0; +} + +/* + * A boot stage that negotiated RTKit with this DCP and handed it over running + * describes the session on the node: apple,rtkit-live (layout version), + * apple,rtkit-version, apple,rtkit-epmap (word i = endpoints 32i..32i+31) and + * apple,rtkit-live-buffers ( per system buffer, each inside one of the node's memory-region + * carveouts and mapped there through its iommu-addresses). Such a firmware + * does not repeat HELLO or EPMAP. Returns 1 with the session filled in, 0 without a description, or an + * error for one that cannot be adopted safely. + */ +static int dcp_rtkit_live_parse(struct apple_dcp *dcp, struct dcp_rtkit_live *live) +{ + u32 cells[DCP_RTKIT_LIVE_MAX_BUFFERS * DCP_RTKIT_LIVE_BUFFER_CELLS]; + struct device_node *np = dcp->dev->of_node; + struct iommu_domain *domain; + u32 layout, version; + int count, i, ret; + + if (!of_property_present(np, "apple,rtkit-live")) + return 0; + ret = of_property_read_u32(np, "apple,rtkit-live", &layout); + if (ret) + return ret; + if (layout != DCP_RTKIT_LIVE_V1) { + dev_err(dcp->dev, "unknown live RTKit layout %u\n", layout); + return -EINVAL; + } + if (!(readl_relaxed(dcp->coproc_reg + APPLE_DCP_COPROC_CPU_CONTROL) & + APPLE_DCP_COPROC_CPU_CONTROL_RUN)) { + dev_err(dcp->dev, "live RTKit session without a running CPU\n"); + return -ENODEV; + } + ret = of_property_read_u32(np, "apple,rtkit-version", &version); + if (ret || version > U16_MAX) + return ret ?: -EINVAL; + live->session.protocol_version = version; + ret = of_property_read_u32_array(np, "apple,rtkit-epmap", + live->session.epmap, + APPLE_RTKIT_ADOPTED_EPMAP_WORDS); + if (ret) + return ret; + + count = of_property_count_u32_elems(np, "apple,rtkit-live-buffers"); + if (count == -EINVAL) + count = 0; + if (count < 0 || count > ARRAY_SIZE(cells) || + count % DCP_RTKIT_LIVE_BUFFER_CELLS) + return -EINVAL; + if (count) { + ret = of_property_read_u32_array(np, "apple,rtkit-live-buffers", + cells, count); + if (ret) + return ret; + } + count /= DCP_RTKIT_LIVE_BUFFER_CELLS; + + domain = iommu_get_domain_for_dev(dcp->dev); + if (count && !domain) + return -ENODEV; + + live->session.buffers = live->buffers; + for (i = 0; i < count; i++) { + const u32 *t = &cells[i * DCP_RTKIT_LIVE_BUFFER_CELLS]; + struct apple_rtkit_inherited_buffer *b = &live->buffers[i]; + u64 iova = (u64)t[2] << 32 | t[3]; + u64 phys = (u64)t[4] << 32 | t[5]; + u64 size = (u64)t[6] << 32 | t[7]; + + if (t[0] > U8_MAX || (t[1] & ~DCP_RTKIT_LIVE_LOADER_OWNED) || + !size || size > SZ_16M || !PAGE_ALIGNED(phys) || + !PAGE_ALIGNED(size) || iova + size < iova || + phys + size < phys) { + ret = -EINVAL; + goto fail; + } + if (!dcp_rtkit_live_carveout(np, phys, size)) { + dev_err(dcp->dev, "live RTKit buffer %#llx+%#llx is not in a DCP carveout\n", + phys, size); + ret = -EACCES; + goto fail; + } + /* The DCP's own DART must already translate it to that memory. */ + ret = dcp_check_iova_contiguous(domain, iova, size, phys); + if (ret) { + dev_err(dcp->dev, + "live RTKit buffer ep%u iova %#llx is not mapped to %#llx (DART: %pa)\n", + t[0], iova, phys, + &(phys_addr_t){ iommu_iova_to_phys(domain, iova) }); + goto fail; + } + + /* Firmware writes without CPU cache maintenance. */ + ret = dcp_vmap_wc(phys, size, &b->shmem.iomem, &b->shmem.private); + if (ret) + goto fail; + b->endpoint = t[0]; + b->shmem.iova = iova; + b->shmem.size = size; + b->shmem.is_mapped = true; + live->session.num_buffers = i + 1; + } + return 1; + +fail: + dcp_rtkit_live_unmap(live); + return ret; +} + static int dcp_rtk_shmem_setup(void *cookie, struct apple_rtkit_shmem *bfr) { struct apple_dcp *dcp = cookie; @@ -6459,7 +6614,9 @@ static int dcp_comp_bind_pipe(struct device *dev, struct device *main, void *dat { struct device_node *panel_np; struct apple_dcp *dcp = dev_get_drvdata(dev); + struct dcp_rtkit_live live_rtkit = {}; u32 cpu_ctrl; + int live = 0; int ret; if (dcp->fw_compat == DCP_FIRMWARE_V_27_0) { @@ -6719,8 +6876,18 @@ static int dcp_comp_bind_pipe(struct device *dev, struct device *main, void *dat ret = dcp_pin_live_session(dcp); if (ret) goto err_piodma; + live = dcp_rtkit_live_parse(dcp, &live_rtkit); + if (live < 0) { + ret = dev_err_probe(dev, live, "Invalid live RTKit handoff\n"); + goto err_piodma; + } /* External H17P supplies shared-buffer addresses during RTKit startup. */ - if (dcp->hw.iomfb_method_profile == + if (live) + dcp->rtk = apple_rtkit_init_adopted_with_session( + dev, dcp, "mbox", 0, + dcp->hw.link_report ? &link_report_rtkit_ops : &rtkit_ops, + &live_rtkit.session); + else if (dcp->hw.iomfb_method_profile == DCP_IOMFB_METHODS_H17P_EXTERNAL) dcp->rtk = apple_rtkit_init(dev, dcp, "mbox", 0, &external_h17p_rtkit_ops); @@ -6729,6 +6896,8 @@ static int dcp_comp_bind_pipe(struct device *dev, struct device *main, void *dat else dcp->rtk = apple_rtkit_init(dev, dcp, "mbox", 0, &rtkit_ops); if (IS_ERR(dcp->rtk)) { + if (live) + dcp_rtkit_live_unmap(&live_rtkit); ret = dev_err_probe(dev, PTR_ERR(dcp->rtk), "Failed to initialize RTKit\n"); goto err_piodma; @@ -6736,6 +6905,7 @@ static int dcp_comp_bind_pipe(struct device *dev, struct device *main, void *dat ret = devm_add_action_or_reset(dev, dcp_release_rtkit, dcp); if (ret) goto err_piodma; + dcp->rtkit_adopted = live; dcp_s2r_check_dt(dcp); /* After a warm restart its log counters need echoing, or it refuses its next idle. */ if (dcp->hw.s2r || dcp->hw.s2r_ext) @@ -6748,7 +6918,9 @@ static int dcp_comp_bind_pipe(struct device *dev, struct device *main, void *dat dev_dbg(dev, "negotiating RTKit with the running DCP\n"); /* Announce host readiness before awaiting external IOP readiness. */ - if (dcp->hw.iomfb_method_profile == + if (live) + ret = 0; /* HELLO and EPMAP happened before the handoff */ + else if (dcp->hw.iomfb_method_profile == DCP_IOMFB_METHODS_H17P_EXTERNAL) ret = apple_rtkit_wake_early_ap(dcp->rtk); else if (dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP) @@ -7319,6 +7491,9 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) if (ret) return ret; dcp->hw = *(struct apple_dcp_hw_data *)of_device_get_match_data(dev); + /* A boot stage handed this DCP over running: keep its session. */ + if (of_property_present(dev->of_node, "apple,rtkit-live")) + dcp->hw.adopt_live_session = true; /* The link report: on the board it has run on (dcp_j714s_ext()). */ if (!dcp_j714s_ext(dev)) dcp->hw.link_report = false; From 86f405f50a5b23ff84be530fea02e6d0ad9e732c Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 05:57:30 +1100 Subject: [PATCH 04/16] drm/apple: dcp: retrain an adopted DP2HDMI port's link A boot stage that handed a DCP over running left its DPTX port's display up, on a link it trained. The firmware then has no sink: it lists its default modes (640x480, 800x600, 1024x768) and no EDID. It sends no link configuration for a link that is already trained, so dcp_dptx_connect() withdrew the display after its timeout. On an adopted session, drop the port's HPD and release its display when the endpoints start. The next connect then trains the link and the firmware reads the sink again. Raise HPD after the link wait on an adopted DP2HDMI port, so that the firmware sees the display plugged (HPD is otherwise left to the converter on that output). The link wait on a DP2HDMI output was non-fatal only on the 13.5 firmware line. The reason is the output, not the firmware: the converter holds HPD and the firmware is not asked to detect the sink. So key it on the output alone. This only affects a wait that used to time out and withdraw the display. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp.c | 38 ++++++++++++++----- .../drivers/gpu/apple-dcp/lifecycle.py | 2 +- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index bd8eb7c6a368a..a2ad08dbbef9c 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -2467,16 +2467,15 @@ static int dcp_dptx_connect_raw(struct apple_dcp *dcp, u32 port, bool *retryable bool late_hpd = dcp_ext_dptx_607(dcp); bool t8132 = dcp_is_t8132_ext(dcp); /* - * A DP2HDMI output on the 13.5 firmware line asserts its own HPD, in - * dcp_enable_dp2hdmi_hpd(), and the connect asks the firmware for HPD - * only on a DisplayPort connector or a late-HPD path, so this firmware - * is never asked to detect the sink and never sends the link - * configuration the wait below looks for. Treat the timeout as - * non-fatal, as the compact and late-HPD cases do, instead of - * withdrawing the display. + * A DP2HDMI output asserts its own HPD, in dcp_enable_dp2hdmi_hpd(), + * and the connect asks the firmware for HPD only on a DisplayPort + * connector or a late-HPD path, so the firmware is never asked to + * detect the sink and need not send the link configuration the wait + * below looks for (nor does one whose link a boot stage already + * trained). Treat the timeout as non-fatal, as the compact and + * late-HPD cases do, instead of withdrawing the display. */ - bool dp2hdmi = dcp->hdmi_hpd && !dcp_is_typec_output(dcp) && - dcp->fw_compat == DCP_FIRMWARE_V_13_5; + bool dp2hdmi = dcp->hdmi_hpd && !dcp_is_typec_output(dcp); bool compact, withdrawn; unsigned long timeout; u64 generation; @@ -2674,7 +2673,8 @@ static int dcp_dptx_connect_raw(struct apple_dcp *dcp, u32 port, bool *retryable usleep_range(5, 10); - if (dcp->connector_type == DRM_MODE_CONNECTOR_DisplayPort || late_hpd) { + if (dcp->connector_type == DRM_MODE_CONNECTOR_DisplayPort || late_hpd || + (dp2hdmi && dcp->rtkit_adopted)) { ret = dptxport_set_hpd(dcp->dptxport[port].service, true); if (ret && late_hpd) dev_err(dcp->dev, @@ -4915,6 +4915,24 @@ int dcp_start(struct platform_device *pdev) if (ret) { dev_warn(dcp->dev, "Failed to start DPTX endpoint: %d\n", ret); + } else if (dcp->rtkit_adopted && + dptx_service_available(&dcp->dptxport[0])) { + /* + * The boot stage that handed this DCP over left the + * port's display up on a link it trained. Release it, + * so that the next connect trains the link and reads + * the sink again: until then the firmware only has its + * default modes and no EDID. Its HPD goes low as well; + * dcp_dptx_connect() raises it again after the link wait, + * so that the firmware sees the display plugged. + */ + ret = dptxport_set_hpd(dcp->dptxport[0].service, false); + if (!ret) + ret = dptxport_release_display(dcp->dptxport[0].service); + if (ret) + dev_warn(dcp->dev, "adopted DPTX display not released: %d\n", + ret); + ret = 0; #ifdef DCP_DPTX_DISCONNECT_ON_INIT /* * This disconnect / connect cycle on init is only necessary diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py index e41e10447eb22..bd749368aa820 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py @@ -595,7 +595,7 @@ def swap(old, new): ' struct { bool connected, closed, tile_hint; void *service, *atcphy; int linkcfg_completion; } dptxport[1];\n' ' void *phy, *dev, *active_typec_route;\n' ' int dptx_die, dptx_phy, dptx_dfp_port, connector_type;\n' - ' bool external, external_link_ready, crashed;\n' + ' bool external, external_link_ready, crashed, rtkit_adopted;\n' ' bool typec_work_enabled;' + ('' if '\n int fw_compat;' in unit else ' int fw_compat;') + ' struct { bool fw_14_7_endpoints; } hw;\n' ' struct { bool active; } split;\n' From 8ee2b0b9cc273d765d99858dba17ad57fc12e766 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 05:47:05 +1100 Subject: [PATCH 05/16] dt-bindings: display: apple,dcp: describe a session handed over running A boot stage that lit a display may leave its display processor running with the RTKit session it negotiated. That firmware does not repeat HELLO or its endpoint map, so the operating system can only continue the session if the boot stage describes it. Document the properties the boot stage sets on the DCP node for that. apple,rtkit-handoff ("dcp-live-v1") and apple,rtkit-buffers follow the RTKit handoff of other co-processors handed over running; for a DCP the buffer's device address is the DART input address, and each buffer lies in a memory-region carveout that maps it through iommu-addresses. apple,rtkit-version and apple,rtkit-epmap carry the negotiated protocol version and endpoint map a DCP needs on top. Signed-off-by: Ryan Murray --- .../bindings/display/apple,dcp.yaml | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/Documentation/devicetree/bindings/display/apple,dcp.yaml b/Documentation/devicetree/bindings/display/apple,dcp.yaml index 193ceda46427f..c0395f922f097 100644 --- a/Documentation/devicetree/bindings/display/apple,dcp.yaml +++ b/Documentation/devicetree/bindings/display/apple,dcp.yaml @@ -279,6 +279,50 @@ properties: maxItems: 5 description: Loader-provided firmware ABI version used for IOMFB selection. + apple,rtkit-handoff: + $ref: /schemas/types.yaml#/definitions/string + enum: + - dcp-live-v1 + description: | + Added by a boot stage that negotiated RTKit with this processor and + handed it over running. Such a firmware does not repeat HELLO or its + endpoint map, so the operating system takes over the session as + described by apple,rtkit-version, apple,rtkit-epmap and + apple,rtkit-buffers instead of starting RTKit again. Absent when the + processor was not left running. + + apple,rtkit-version: + $ref: /schemas/types.yaml#/definitions/uint32 + description: RTKit protocol version of the handed-over session. + + apple,rtkit-epmap: + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 8 + maxItems: 8 + description: | + Endpoints the firmware advertised for the handed-over session; word i + holds endpoints 32i to 32i + 31. Application endpoints are stopped at + the handover and are started again by the new owner. + + apple,rtkit-buffers: + oneOf: + - type: boolean + - $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 5 + maxItems: 20 + description: | + The shared buffers of the handed-over session, in groups of five + cells as for other co-processors handed over running: system endpoint + number (1 crashlog, 2 syslog, 4 IOReport, 8 OSLog, each at most once), + device address high cell, device address low cell, size in bytes, and + 1 if the firmware supplied the address (0 if the boot stage allocated + the buffer). The device address is the DART input address. Every + buffer lies inside one of the reserved-memory regions referenced by + memory-region, and that region maps it at the same address through + iommu-addresses, so the mapping survives the IOMMU taking over the + processor's page tables. An empty property records that the session + has no shared buffers. + apple,j613-25g83-dcpext-handoff: $ref: /schemas/types.yaml#/definitions/uint32 const: 1 From e59f0246ce81567316fc384781aecd5241923102 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 06:09:54 +1100 Subject: [PATCH 06/16] drm/apple: dpavservep: admit the MCDP29xx converters' AV service On the 27.2 firmware the M2 Mac mini's DCPs announce the AV service of their DP-to-HDMI converter on the classic DPAV endpoint, EPICUnit 0, with the converter's part as its class: AppleDCPMCDP29XX for the built-in HDMI port and AppleDCPMCDP2900 for a USB-C to HDMI adapter. Neither class is admitted, so the service is refused with -ENODEV, its EDID is never read and the HDMI connector reports a 0-byte EDID. Admit both classes under the same rules as AppleDCPDP2HDMI and DCPDP13Service. With it the M2 Mac mini's HDMI connector gets the monitor's 256-byte EDID (name, BT.2020 colorimetry, ST 2084). New identity cases cover both classes, a non-zero unit and another part. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/epic/dpavservep-identity-test.c | 8 ++++++++ drivers/gpu/drm/apple/epic/dpavservep.c | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/apple/epic/dpavservep-identity-test.c b/drivers/gpu/drm/apple/epic/dpavservep-identity-test.c index 4f36cc35758b4..5f3732eecf7a9 100644 --- a/drivers/gpu/drm/apple/epic/dpavservep-identity-test.c +++ b/drivers/gpu/drm/apple/epic/dpavservep-identity-test.c @@ -65,6 +65,14 @@ static const struct dpavid_case dpavid_cases[] = { "DCPDP13Service", 0, 7, true }, { "v2 ep 0x28: DP2HDMI unit 0", DPAVID_V2, DPAVSERV_ENDPOINT, DPAVID_NAME, "AppleDCPDP2HDMI", 0, 1, true }, + { "v2 ep 0x28: MCDP29XX unit 0", DPAVID_V2, DPAVSERV_ENDPOINT, DPAVID_NAME, + "AppleDCPMCDP29XX", 0, 5, true }, + { "v2 ep 0x28: MCDP2900 unit 0", DPAVID_V2, DPAVSERV_ENDPOINT, DPAVID_NAME, + "AppleDCPMCDP2900", 0, 1, true }, + { "v2 ep 0x28: MCDP2900 unit 1", DPAVID_V2, DPAVSERV_ENDPOINT, DPAVID_NAME, + "AppleDCPMCDP2900", 1, 1, false }, + { "v2 ep 0x28: other MCDP part", DPAVID_V2, DPAVSERV_ENDPOINT, DPAVID_NAME, + "AppleDCPMCDP2800", 0, 1, false }, { "v2 ep 0x28: unit 0, channel at u16 max", DPAVID_V2, DPAVSERV_ENDPOINT, DPAVID_NAME, "DCPDP13Service", 0, 0xffff, true }, { "v2 ep 0x28: unit == channel", DPAVID_V2, DPAVSERV_ENDPOINT, DPAVID_NAME, diff --git a/drivers/gpu/drm/apple/epic/dpavservep.c b/drivers/gpu/drm/apple/epic/dpavservep.c index efc3babff3cb7..5ca5e7af0370e 100644 --- a/drivers/gpu/drm/apple/epic/dpavservep.c +++ b/drivers/gpu/drm/apple/epic/dpavservep.c @@ -44,8 +44,15 @@ static bool dcpavserv_identity(struct apple_epic_service *service, const char *n class && !strcmp(class, "DCPDPService") && service->channel; if (!service->ep->wire_v2) return unit == 0; + /* + * A DP-to-HDMI converter's AV service: the generic ones, and the + * MCDP29xx converters that firmware 27 names after their part (the + * M2 Mac mini's HDMI port, and USB-C to HDMI adapters). + */ if (!class || (strcmp(class, "AppleDCPDP2HDMI") && - strcmp(class, "DCPDP13Service")) || + strcmp(class, "DCPDP13Service") && + strcmp(class, "AppleDCPMCDP29XX") && + strcmp(class, "AppleDCPMCDP2900")) || !service->channel || service->channel > U16_MAX) return false; /* H17P's lower-case interface-id is dynamic, not a physical-port unit. */ From 0ee2165c6be9448c5574c8e86cc6d65fbe2fe8c1 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 06:19:56 +1100 Subject: [PATCH 07/16] tools/asahi: check the RTKit import of an adopted session's endpoint map apple_rtkit_inherit_endpoints() decides which endpoints a session a boot stage handed over has; a wrong map either leaves application endpoints unstarted or lets RTKit accept traffic for endpoints it does not serve. Run the importer from the source on the host with the map the M2 Mac mini's HDMI display processor hands over on the 27.2 firmware, and check the version rules, the management endpoint, unknown system endpoints and the full endpoint range. The test also checks that the map replaces the assumed one before mailbox RX is claimed. One mutation per check makes sure each check is exercised. Signed-off-by: Ryan Murray --- tools/asahi/rtkit-adopted-session-tests.py | 180 +++++++++++++++++++++ tools/asahi/run-host-tests.py | 3 + 2 files changed, 183 insertions(+) create mode 100755 tools/asahi/rtkit-adopted-session-tests.py diff --git a/tools/asahi/rtkit-adopted-session-tests.py b/tools/asahi/rtkit-adopted-session-tests.py new file mode 100755 index 0000000000000..6f516abd9aac7 --- /dev/null +++ b/tools/asahi/rtkit-adopted-session-tests.py @@ -0,0 +1,180 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only OR MIT +"""Check how RTKit imports the endpoint map of a session a boot stage handed over.""" +import argparse +from pathlib import Path +import re +import subprocess +import tempfile + +ROOT = Path(__file__).resolve().parents[2] +DRIVER = 'drivers/soc/apple/rtkit.c' +INTERNAL = 'drivers/soc/apple/rtkit-internal.h' +HEADER = 'include/linux/soc/apple/rtkit.h' + +# Each mutation drops one check; an assertion must then fail. +MUTATIONS = { + 'no-management': ('if (!test_bit(APPLE_RTKIT_EP_MGMT, map))', 'if (0)'), + 'any-system': ('if (test_bit(i, map) && !test_bit(i, known))', 'if (0)'), + 'any-version': ('session->protocol_version < APPLE_RTKIT_MIN_SUPPORTED_VERSION ||', '0 ||'), + 'ignore-ops-version': ('session->protocol_version != rtk->ops->protocol_version', '0'), +} + + +def function(source, name): + match = re.search(r'^static int ' + name + r'\(', source, re.M) + assert match, name + opening = source.index('{', match.end()) + depth, end = 1, opening + 1 + while depth: + depth += (source[end] == '{') - (source[end] == '}') + end += 1 + return source[match.start():end] + '\n' + + +PREFIX = r''' +#include +#include +#include +#include +#include +#include +typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; +#define BUILD_BUG_ON(x) _Static_assert(!(x), #x) +#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) +#define DECLARE_BITMAP(n, bits) bool n[bits] +static void set_bit(unsigned int b, bool *m) { m[b] = true; } +static bool test_bit(unsigned int b, const bool *m) { return m[b]; } +static void bitmap_from_arr32(bool *m, const u32 *a, unsigned int bits) +{ for (unsigned int i = 0; i < bits; i++) m[i] = a[i / 32] >> (i % 32) & 1; } +static void bitmap_copy(bool *d, const bool *s, unsigned int bits) { memcpy(d, s, bits); } +struct apple_rtkit_inherited_buffer { int unused; }; +struct apple_rtkit_ops { u16 protocol_version; }; +''' + +TESTS = r''' +struct apple_rtkit { + const struct apple_rtkit_ops *ops; + bool endpoints[APPLE_RTKIT_MAX_ENDPOINTS]; + u16 version; +}; +''' + '%s' + r''' +static int run(u16 required, u16 version, const u32 *map, struct apple_rtkit *rtk) +{ + static struct apple_rtkit_ops ops; + struct apple_rtkit_adopted_session s = { .protocol_version = version }; + + ops.protocol_version = required; + memset(rtk, 0, sizeof(*rtk)); + rtk->ops = &ops; + memcpy(s.epmap, map, sizeof(s.epmap)); + return apple_rtkit_inherit_endpoints(rtk, &s); +} + +int main(void) +{ + /* + * An M2 Mac mini HDMI DCP on the 27.2 firmware, as its boot stage + * describes it: system endpoints 0-4 and 8, application endpoints + * 0x20-0x2c, 0x31 and 0x37. + */ + const u32 dcpext[8] = { 0x0000011f, 0x00821fff }; + struct apple_rtkit r; + u32 m[8]; + int i; + + assert(run(0, 12, dcpext, &r) == 0); + for (i = 0; i < APPLE_RTKIT_MAX_ENDPOINTS; i++) { + bool want = i <= 4 || i == 8 || (i >= 0x20 && i <= 0x2c) || + i == 0x31 || i == 0x37; + assert(r.endpoints[i] == want); + } + assert(r.version == 12); + + /* A driver that needs one protocol version takes only that one. */ + assert(run(12, 12, dcpext, &r) == 0); + assert(run(11, 12, dcpext, &r) == -EINVAL); + /* Versions RTKit does not speak are refused. */ + assert(run(0, APPLE_RTKIT_MIN_SUPPORTED_VERSION - 1, dcpext, &r) == -EINVAL); + assert(run(0, APPLE_RTKIT_MAX_SUPPORTED_VERSION + 1, dcpext, &r) == -EINVAL); + + /* Without management there is no session to adopt. */ + memcpy(m, dcpext, sizeof(m)); + m[0] &= ~1u; + assert(run(0, 12, m, &r) == -EINVAL); + /* A system endpoint RTKit does not implement is not silently ignored. */ + memcpy(m, dcpext, sizeof(m)); + m[0] |= 1u << 5; + assert(run(0, 12, m, &r) == -EINVAL); + /* Tracekit (0xa) is one RTKit knows. */ + memcpy(m, dcpext, sizeof(m)); + m[0] |= 1u << 0xa; + assert(run(0, 12, m, &r) == 0 && r.endpoints[0xa]); + /* Every known system endpoint and every application endpoint. */ + for (i = 0; i < 8; i++) + m[i] = i ? ~0u : 0x59fu; + assert(run(0, 11, m, &r) == 0 && r.endpoints[0x20] && r.endpoints[0xff]); + /* Management alone. */ + memset(m, 0, sizeof(m)); + m[0] = 1; + assert(run(0, 12, m, &r) == 0 && r.endpoints[0] && !r.endpoints[0x37]); + + puts("PASS adopted session endpoint map, protocol version and system endpoints"); + return 0; +} +''' + + +def build_source(mutation): + driver = (ROOT / DRIVER).read_text() + internal = (ROOT / INTERNAL).read_text() + header = (ROOT / HEADER).read_text() + defines = re.findall(r'^#define APPLE_RTKIT_(?:MIN_SUPPORTED_VERSION|MAX_SUPPORTED_VERSION|' + r'APP_ENDPOINT_START|MAX_ENDPOINTS)\b.*$', driver + internal, re.M) + assert len(defines) == 4, defines + words = re.search(r'^#define APPLE_RTKIT_ADOPTED_EPMAP_WORDS.*$', header, re.M) + session = re.search(r'^struct apple_rtkit_adopted_session \{.*?^\};', header, re.M | re.S) + endpoints = re.search(r'enum \{\s*APPLE_RTKIT_EP_MGMT = 0,.*?\};', driver, re.S) + assert words and session and endpoints + imported = function(driver, 'apple_rtkit_inherit_endpoints') + if mutation: + old, new = MUTATIONS[mutation] + assert old in imported, mutation + imported = imported.replace(old, new) + # The firmware's map replaces the assumed one before RX can deliver + # traffic for its endpoints. + init = re.search(r'^static struct apple_rtkit \*__apple_rtkit_init\(.*?^\}', driver, re.M | re.S) + assert init + body = init.group(0) + assert (body.index('apple_rtkit_mark_running(rtk)') < + body.index('apple_rtkit_inherit_endpoints(') < + body.index('apple_rtkit_claim_rx(')) + return (PREFIX + '\n'.join(defines) + '\n' + words.group(0) + '\n' + endpoints.group(0) + + '\n' + session.group(0) + '\n' + TESTS % imported) + + +def run(out, cc, mutation): + source = out / 'rtkit-adopted-session.c' + binary = out / 'rtkit-adopted-session' + source.write_text(build_source(mutation)) + subprocess.run([cc, '-std=gnu11', '-Wall', '-Wextra', '-Werror', '-fsanitize=address,undefined', + str(source), '-o', str(binary)], check=True) + return subprocess.run([str(binary)]).returncode + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument('--out', type=Path, help='keep build and result files here') + parser.add_argument('--cc', default='cc') + parser.add_argument('--mutation', choices=sorted(MUTATIONS), + help='drop one check (the run must fail an assertion)') + args = parser.parse_args() + with tempfile.TemporaryDirectory() as tmp: + out = args.out or Path(tmp) + out.mkdir(parents=True, exist_ok=True) + status = run(out, args.cc, args.mutation) + raise SystemExit(status) + + +if __name__ == '__main__': + main() diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index 1f0d5963f9290..03942d5188ad7 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -292,6 +292,9 @@ def mutations(flag, names, base, expect=KILL): 'mailbox-minimum', 'version-string', 'message-string'), out()), 'rtkit-oslog-tests.py': [(out(), PASS)] + mutations('--mutate', ('admission', 'channel', 'counter', 'reset', 'buffer'), out()), + 'rtkit-adopted-session-tests.py': [(out(), PASS)] + + mutations('--mutation', ('no-management', 'any-system', 'any-version', + 'ignore-ops-version'), out()), 'rtkit-retained-tests.py': [(out(), PASS)], 't6030-clock-tests.py': [(out(), PASS)], 't6030-display-admission-tests.py': [(out('--output'), PASS), (out('--output') + ['--mutations'], PASS)], From 638611e15e64549f27d46eb0aad3947bb4d8ee61 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 06:46:37 +1100 Subject: [PATCH 08/16] drm/apple: dcp: read a live DCP session from the RTKit handoff properties Describe the session a boot stage hands over with the RTKit handoff properties other co-processors use: apple,rtkit-handoff ("dcp-live-v1") and apple,rtkit-buffers in tuples, plus apple,rtkit-version and apple,rtkit-epmap, instead of a parallel set of properties with physical addresses in them. Each buffer's physical address now comes from the DCP's own DART: it must translate the whole buffer contiguously, and the result must lie in one of the node's carveouts, as before. A boot stage that publishes the old properties is not adopted and the DCP takes its normal start. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp-internal.h | 2 +- drivers/gpu/drm/apple/dcp.c | 77 ++++++++++++++-------------- 2 files changed, 40 insertions(+), 39 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 68ccf32aad930..730ca75f04d30 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -473,7 +473,7 @@ struct apple_dcp { struct iomfb_m4 *v26_6; /* An adopted session has no confirmed firmware DMA stop boundary. */ bool retain_dma; - /* RTKit session handed over running by a boot stage (apple,rtkit-live) */ + /* RTKit session handed over running by a boot stage (apple,rtkit-handoff) */ bool rtkit_adopted; /* * Allocates AFK rings where the DMA API cannot, on an adopted diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index a2ad08dbbef9c..a68631cadf0b6 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -1844,10 +1844,9 @@ static int dcp_check_iova_contiguous(struct iommu_domain *domain, return 0; } -#define DCP_RTKIT_LIVE_V1 1 -#define DCP_RTKIT_LIVE_BUFFER_CELLS 8 +#define DCP_RTKIT_HANDOFF "dcp-live-v1" +#define DCP_RTKIT_LIVE_BUFFER_CELLS 5 #define DCP_RTKIT_LIVE_MAX_BUFFERS 4 -#define DCP_RTKIT_LIVE_LOADER_OWNED BIT(0) struct dcp_rtkit_live { struct apple_rtkit_adopted_session session; @@ -1892,29 +1891,32 @@ static void dcp_rtkit_live_unmap(struct dcp_rtkit_live *live) /* * A boot stage that negotiated RTKit with this DCP and handed it over running - * describes the session on the node: apple,rtkit-live (layout version), - * apple,rtkit-version, apple,rtkit-epmap (word i = endpoints 32i..32i+31) and - * apple,rtkit-live-buffers ( per system buffer, each inside one of the node's memory-region - * carveouts and mapped there through its iommu-addresses). Such a firmware - * does not repeat HELLO or EPMAP. Returns 1 with the session filled in, 0 without a description, or an - * error for one that cannot be adopted safely. + * describes the session on the node, with the RTKit handoff properties of other + * co-processors handed over running: apple,rtkit-handoff ("dcp-live-v1") and + * apple,rtkit-buffers ( per system buffer, the + * device address being the DART input address), plus apple,rtkit-version and + * apple,rtkit-epmap (word i = endpoints 32i..32i+31). Each buffer lies in one of + * the node's memory-region carveouts, mapped there through its iommu-addresses. + * Such a firmware does not repeat HELLO or EPMAP. Returns 1 with the session + * filled in, 0 without a description, or an error for one that cannot be adopted + * safely. */ static int dcp_rtkit_live_parse(struct apple_dcp *dcp, struct dcp_rtkit_live *live) { u32 cells[DCP_RTKIT_LIVE_MAX_BUFFERS * DCP_RTKIT_LIVE_BUFFER_CELLS]; struct device_node *np = dcp->dev->of_node; struct iommu_domain *domain; - u32 layout, version; + const char *handoff; int count, i, ret; + u32 version; - if (!of_property_present(np, "apple,rtkit-live")) + if (!of_property_present(np, "apple,rtkit-handoff")) return 0; - ret = of_property_read_u32(np, "apple,rtkit-live", &layout); + ret = of_property_read_string(np, "apple,rtkit-handoff", &handoff); if (ret) return ret; - if (layout != DCP_RTKIT_LIVE_V1) { - dev_err(dcp->dev, "unknown live RTKit layout %u\n", layout); + if (strcmp(handoff, DCP_RTKIT_HANDOFF)) { + dev_err(dcp->dev, "unknown RTKit handoff \"%s\"\n", handoff); return -EINVAL; } if (!(readl_relaxed(dcp->coproc_reg + APPLE_DCP_COPROC_CPU_CONTROL) & @@ -1932,14 +1934,14 @@ static int dcp_rtkit_live_parse(struct apple_dcp *dcp, struct dcp_rtkit_live *li if (ret) return ret; - count = of_property_count_u32_elems(np, "apple,rtkit-live-buffers"); - if (count == -EINVAL) + count = of_property_count_u32_elems(np, "apple,rtkit-buffers"); + if (count == -EINVAL || count == -ENODATA) count = 0; if (count < 0 || count > ARRAY_SIZE(cells) || count % DCP_RTKIT_LIVE_BUFFER_CELLS) return -EINVAL; if (count) { - ret = of_property_read_u32_array(np, "apple,rtkit-live-buffers", + ret = of_property_read_u32_array(np, "apple,rtkit-buffers", cells, count); if (ret) return ret; @@ -1954,30 +1956,29 @@ static int dcp_rtkit_live_parse(struct apple_dcp *dcp, struct dcp_rtkit_live *li for (i = 0; i < count; i++) { const u32 *t = &cells[i * DCP_RTKIT_LIVE_BUFFER_CELLS]; struct apple_rtkit_inherited_buffer *b = &live->buffers[i]; - u64 iova = (u64)t[2] << 32 | t[3]; - u64 phys = (u64)t[4] << 32 | t[5]; - u64 size = (u64)t[6] << 32 | t[7]; - - if (t[0] > U8_MAX || (t[1] & ~DCP_RTKIT_LIVE_LOADER_OWNED) || - !size || size > SZ_16M || !PAGE_ALIGNED(phys) || - !PAGE_ALIGNED(size) || iova + size < iova || - phys + size < phys) { + u64 iova = (u64)t[1] << 32 | t[2]; + u64 size = t[3]; + phys_addr_t phys; + + /* The system endpoints with shared buffers, as for other handoffs. */ + if ((t[0] != 1 && t[0] != 2 && t[0] != 4 && t[0] != 8) || + t[4] > 1 || !size || size > SZ_16M || !PAGE_ALIGNED(iova) || + !PAGE_ALIGNED(size) || iova + size < iova) { ret = -EINVAL; goto fail; } - if (!dcp_rtkit_live_carveout(np, phys, size)) { - dev_err(dcp->dev, "live RTKit buffer %#llx+%#llx is not in a DCP carveout\n", - phys, size); - ret = -EACCES; + /* The DCP's own DART says where the buffer is; it must be contiguous. */ + phys = iommu_iova_to_phys(domain, iova); + ret = phys ? dcp_check_iova_contiguous(domain, iova, size, phys) : -ENXIO; + if (ret) { + dev_err(dcp->dev, "live RTKit buffer ep%u iova %#llx+%#llx is not mapped\n", + t[0], iova, size); goto fail; } - /* The DCP's own DART must already translate it to that memory. */ - ret = dcp_check_iova_contiguous(domain, iova, size, phys); - if (ret) { - dev_err(dcp->dev, - "live RTKit buffer ep%u iova %#llx is not mapped to %#llx (DART: %pa)\n", - t[0], iova, phys, - &(phys_addr_t){ iommu_iova_to_phys(domain, iova) }); + if (!dcp_rtkit_live_carveout(np, phys, size)) { + dev_err(dcp->dev, "live RTKit buffer %pa+%#llx is not in a DCP carveout\n", + &phys, size); + ret = -EACCES; goto fail; } @@ -7510,7 +7511,7 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) return ret; dcp->hw = *(struct apple_dcp_hw_data *)of_device_get_match_data(dev); /* A boot stage handed this DCP over running: keep its session. */ - if (of_property_present(dev->of_node, "apple,rtkit-live")) + if (of_property_present(dev->of_node, "apple,rtkit-handoff")) dcp->hw.adopt_live_session = true; /* The link report: on the board it has run on (dcp_j714s_ext()). */ if (!dcp_j714s_ext(dev)) From 63649b08eb1e5bb9973f520b714fc46d93abb44c Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 07:30:48 +1100 Subject: [PATCH 09/16] drm/apple: dcp: check a handed-over session before retaining it A DCP that a boot stage handed over running pinned its DMA resources until reboot before its description was checked, so an unknown handoff string, a bad endpoint map or a buffer outside the carveouts failed the bind with the device, module and IOMMU group already retained. Parse and check the description first and retain the session only once it passed. A description that fails leaves the DCP unbound with nothing retained. That is safe because every buffer of the session must now lie in a no-map carveout, which the kernel never hands out. A carveout in the linear map would also alias the buffer's write-combined mapping with a cacheable one, so such a carveout is refused as well. apple,rtkit-buffers must be present; a session without shared buffers has the property empty. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index a68631cadf0b6..9ec53df3dbb44 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -1854,9 +1854,11 @@ struct dcp_rtkit_live { }; /* - * Inside one of this DCP's reserved-memory carveouts. Those are also what the IOMMU - * core rebuilds the DCP's DART mappings from when it takes over a locked - * root, so a buffer outside them would lose its mapping at attach. + * Inside one of this DCP's no-map reserved-memory carveouts. Those are also what + * the IOMMU core rebuilds the DCP's DART mappings from when it takes over a + * locked root, so a buffer outside them would lose its mapping at attach. A + * region in the linear map would alias the write-combined mapping of the buffer + * with a cacheable one, and a reusable (CMA) region could be handed out. */ static bool dcp_rtkit_live_carveout(struct device_node *np, phys_addr_t phys, size_t size) @@ -1871,8 +1873,8 @@ static bool dcp_rtkit_live_carveout(struct device_node *np, phys_addr_t phys, if (!mem) break; rmem = of_reserved_mem_lookup(mem); - /* A reusable (CMA) region could be handed out by the kernel. */ - found = rmem && !of_property_present(mem, "reusable") && + found = rmem && of_property_present(mem, "no-map") && + !of_property_present(mem, "reusable") && phys >= rmem->base && size <= rmem->size && phys - rmem->base <= rmem->size - size; of_node_put(mem); @@ -1934,8 +1936,11 @@ static int dcp_rtkit_live_parse(struct apple_dcp *dcp, struct dcp_rtkit_live *li if (ret) return ret; + /* A session without shared buffers has the property, empty. */ + if (!of_find_property(np, "apple,rtkit-buffers", NULL)) + return -EINVAL; count = of_property_count_u32_elems(np, "apple,rtkit-buffers"); - if (count == -EINVAL || count == -ENODATA) + if (count == -ENODATA) count = 0; if (count < 0 || count > ARRAY_SIZE(cells) || count % DCP_RTKIT_LIVE_BUFFER_CELLS) @@ -1989,6 +1994,10 @@ static int dcp_rtkit_live_parse(struct apple_dcp *dcp, struct dcp_rtkit_live *li b->endpoint = t[0]; b->shmem.iova = iova; b->shmem.size = size; + /* + * The is_mapped cell only says who placed the buffer; Linux has + * mapped every one here, and is_mapped makes RTKit unmap it. + */ b->shmem.is_mapped = true; live->session.num_buffers = i + 1; } @@ -6891,15 +6900,23 @@ static int dcp_comp_bind_pipe(struct device *dev, struct device *main, void *dat dcp->coproc_reg + APPLE_DCP_COPROC_CPU_CONTROL); } - /* Registering the mailbox can already expose RTKit buffer requests. */ - ret = dcp_pin_live_session(dcp); - if (ret) - goto err_piodma; + /* + * Check a handed-over session before anything is retained for it: a + * description that fails leaves the DCP unbound and nothing pinned. + * Its buffers are in no-map carveouts, which the kernel never hands out. + */ live = dcp_rtkit_live_parse(dcp, &live_rtkit); if (live < 0) { ret = dev_err_probe(dev, live, "Invalid live RTKit handoff\n"); goto err_piodma; } + /* Registering the mailbox can already expose RTKit buffer requests. */ + ret = dcp_pin_live_session(dcp); + if (ret) { + if (live) + dcp_rtkit_live_unmap(&live_rtkit); + goto err_piodma; + } /* External H17P supplies shared-buffer addresses during RTKit startup. */ if (live) dcp->rtk = apple_rtkit_init_adopted_with_session( From c170bcf22d127afb4e9b918e146b96ff03b36d17 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 07:30:49 +1100 Subject: [PATCH 10/16] drm/apple: dcp: keep the DP2HDMI link wait fatal on a cold start "drm/apple: dcp: retrain an adopted DP2HDMI port's link" made a link configuration timeout non-fatal on every DP2HDMI output. On a cold start a real training failure then no longer withdrew the display. Keep the timeout non-fatal only where no link configuration is to be expected: on the 13.5 firmware line, which is never asked to detect the sink, and on a session a boot stage handed over, whose link it already trained. Fix the comment on the HPD that follows the wait. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 9ec53df3dbb44..c30a7e5c4a38c 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -2477,15 +2477,15 @@ static int dcp_dptx_connect_raw(struct apple_dcp *dcp, u32 port, bool *retryable bool late_hpd = dcp_ext_dptx_607(dcp); bool t8132 = dcp_is_t8132_ext(dcp); /* - * A DP2HDMI output asserts its own HPD, in dcp_enable_dp2hdmi_hpd(), - * and the connect asks the firmware for HPD only on a DisplayPort - * connector or a late-HPD path, so the firmware is never asked to - * detect the sink and need not send the link configuration the wait - * below looks for (nor does one whose link a boot stage already - * trained). Treat the timeout as non-fatal, as the compact and - * late-HPD cases do, instead of withdrawing the display. + * A DP2HDMI output asserts its own HPD, in dcp_enable_dp2hdmi_hpd(). + * The 13.5 firmware line is then never asked to detect the sink and + * never sends the link configuration the wait below looks for, and a + * session a boot stage handed over has a link it already trained. + * Treat the timeout as non-fatal there, as the compact and late-HPD + * cases do, instead of withdrawing the display. */ - bool dp2hdmi = dcp->hdmi_hpd && !dcp_is_typec_output(dcp); + bool dp2hdmi = dcp->hdmi_hpd && !dcp_is_typec_output(dcp) && + (dcp->fw_compat == DCP_FIRMWARE_V_13_5 || dcp->rtkit_adopted); bool compact, withdrawn; unsigned long timeout; u64 generation; @@ -2659,8 +2659,9 @@ static int dcp_dptx_connect_raw(struct apple_dcp *dcp, u32 port, bool *retryable ret = 0; } else if (!ret && dp2hdmi) { /* - * The converter holds HPD itself, and dptxport_set_hpd() below runs - * only for a DisplayPort connector, so nothing is asserted here. + * The converter holds HPD itself; dptxport_set_hpd() below raises + * the firmware's HPD only on an adopted session, whose release at + * start dropped it. */ dev_dbg(dcp->dev, "dcp_dptx_connect: no link configuration on port %u, HPD is the converter's\n", From 3fa6ec52c752656207fa3ef5a7aebda937636a0e Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 07:30:49 +1100 Subject: [PATCH 11/16] drm/apple: dcp: stop a retained DCP's HDMI HPD interrupt at unbind An unbind that retains a live DCP session returned before disabling the HDMI HPD interrupt and the swap watchdog. An HPD edge after the unbind then ran its handler against a session the driver had left, and the watchdog could still fire. Disable both on that path too, before the endpoints are quiesced. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/dcp.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index c30a7e5c4a38c..eb0387edc1dbc 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -7096,6 +7096,9 @@ VISIBLE_IF_KUNIT void dcp_comp_unbind(struct device *dev, struct device *main, v drm_dev_get(dcp->crtc->base.dev); dcp->drm_retained = true; } + /* Its handler talks to the session this unbind leaves behind. */ + if (dcp->hdmi_hpd_irq) + disable_irq(dcp->hdmi_hpd_irq); iomfb_queue_stop(dcp); afk_quiesce(dcp->avep); afk_quiesce(dcp->dptxep); @@ -7122,6 +7125,7 @@ VISIBLE_IF_KUNIT void dcp_comp_unbind(struct device *dev, struct device *main, v dcp->announce.stopped = true; disable_delayed_work_sync(&dcp->announce_wq); dcp_test_point(dcp, DCP_TEST_UNBIND_ANNOUNCE_STOPPED); + disable_delayed_work_sync(&dcp->swap_watchdog_wq); cancel_work_sync(&dcp->vblank_wq); if (dcp->connector) cancel_work_sync(&dcp->connector->hotplug_wq); From b659e739160bb4b87c81767998bc5153749ca9fc Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 07:30:50 +1100 Subject: [PATCH 12/16] soc: apple: rtkit: refuse a retained buffer without its endpoint An adopted session's retained buffers were not checked against the endpoint map the session came with: a crashlog, syslog, IOReport or OSLog buffer could be inherited for an endpoint the firmware does not have. Refuse such a session. The host test checks the M2 Mac mini's three buffers against its map, a map without the IOReport or OSLog endpoint, and drops the check in one new mutation. Signed-off-by: Ryan Murray --- drivers/soc/apple/rtkit.c | 6 ++++ tools/asahi/rtkit-adopted-session-tests.py | 32 +++++++++++++++++++++- tools/asahi/run-host-tests.py | 2 +- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c index 541f842840264..533fa40c10f57 100644 --- a/drivers/soc/apple/rtkit.c +++ b/drivers/soc/apple/rtkit.c @@ -2324,6 +2324,12 @@ static int apple_rtkit_inherit_endpoints( for (i = 0; i < APPLE_RTKIT_APP_ENDPOINT_START; i++) if (test_bit(i, map) && !test_bit(i, known)) return -EINVAL; + /* A retained buffer belongs to an endpoint the session has. */ + if ((rtk->crashlog_buffer.size && !test_bit(APPLE_RTKIT_EP_CRASHLOG, map)) || + (rtk->syslog_buffer.size && !test_bit(APPLE_RTKIT_EP_SYSLOG, map)) || + (rtk->ioreport_buffer.size && !test_bit(APPLE_RTKIT_EP_IOREPORT, map)) || + (rtk->oslog_buffer.size && !test_bit(APPLE_RTKIT_EP_OSLOG, map))) + return -EINVAL; bitmap_copy(rtk->endpoints, map, APPLE_RTKIT_MAX_ENDPOINTS); rtk->version = session->protocol_version; diff --git a/tools/asahi/rtkit-adopted-session-tests.py b/tools/asahi/rtkit-adopted-session-tests.py index 6f516abd9aac7..a43f60b841bba 100755 --- a/tools/asahi/rtkit-adopted-session-tests.py +++ b/tools/asahi/rtkit-adopted-session-tests.py @@ -18,6 +18,7 @@ 'any-system': ('if (test_bit(i, map) && !test_bit(i, known))', 'if (0)'), 'any-version': ('session->protocol_version < APPLE_RTKIT_MIN_SUPPORTED_VERSION ||', '0 ||'), 'ignore-ops-version': ('session->protocol_version != rtk->ops->protocol_version', '0'), + 'any-buffer-endpoint': ('rtk->ioreport_buffer.size && !test_bit(APPLE_RTKIT_EP_IOREPORT, map)', '0'), } @@ -53,20 +54,29 @@ def function(source, name): ''' TESTS = r''' +struct apple_rtkit_shmem { unsigned long size; }; struct apple_rtkit { const struct apple_rtkit_ops *ops; bool endpoints[APPLE_RTKIT_MAX_ENDPOINTS]; u16 version; + struct apple_rtkit_shmem crashlog_buffer, syslog_buffer, ioreport_buffer, oslog_buffer; }; ''' + '%s' + r''' static int run(u16 required, u16 version, const u32 *map, struct apple_rtkit *rtk) { static struct apple_rtkit_ops ops; struct apple_rtkit_adopted_session s = { .protocol_version = version }; + struct apple_rtkit_shmem crashlog = rtk->crashlog_buffer, syslog = rtk->syslog_buffer; + struct apple_rtkit_shmem ioreport = rtk->ioreport_buffer, oslog = rtk->oslog_buffer; ops.protocol_version = required; memset(rtk, 0, sizeof(*rtk)); rtk->ops = &ops; + /* The buffers the session retained, set by the caller. */ + rtk->crashlog_buffer = crashlog; + rtk->syslog_buffer = syslog; + rtk->ioreport_buffer = ioreport; + rtk->oslog_buffer = oslog; memcpy(s.epmap, map, sizeof(s.epmap)); return apple_rtkit_inherit_endpoints(rtk, &s); } @@ -79,7 +89,7 @@ def function(source, name): * 0x20-0x2c, 0x31 and 0x37. */ const u32 dcpext[8] = { 0x0000011f, 0x00821fff }; - struct apple_rtkit r; + struct apple_rtkit r = {}; u32 m[8]; int i; @@ -119,6 +129,26 @@ def function(source, name): m[0] = 1; assert(run(0, 12, m, &r) == 0 && r.endpoints[0] && !r.endpoints[0x37]); + /* + * The J473 retains crashlog, syslog and ioreport buffers: all three + * endpoints are in its map. A buffer for an endpoint the map lacks + * is refused. + */ + memset(&r, 0, sizeof(r)); + r.crashlog_buffer.size = 0x10000; + r.syslog_buffer.size = 0x4000; + r.ioreport_buffer.size = 0x4000; + assert(run(0, 12, dcpext, &r) == 0); + memcpy(m, dcpext, sizeof(m)); + m[0] &= ~(1u << 4); + assert(run(0, 12, m, &r) == -EINVAL); + memset(&r, 0, sizeof(r)); + r.oslog_buffer.size = 0x4000; + assert(run(0, 12, dcpext, &r) == 0); + memcpy(m, dcpext, sizeof(m)); + m[0] &= ~(1u << 8); + assert(run(0, 12, m, &r) == -EINVAL); + puts("PASS adopted session endpoint map, protocol version and system endpoints"); return 0; } diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index 03942d5188ad7..e7a1e5b940bc8 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -294,7 +294,7 @@ def mutations(flag, names, base, expect=KILL): + mutations('--mutate', ('admission', 'channel', 'counter', 'reset', 'buffer'), out()), 'rtkit-adopted-session-tests.py': [(out(), PASS)] + mutations('--mutation', ('no-management', 'any-system', 'any-version', - 'ignore-ops-version'), out()), + 'ignore-ops-version', 'any-buffer-endpoint'), out()), 'rtkit-retained-tests.py': [(out(), PASS)], 't6030-clock-tests.py': [(out(), PASS)], 't6030-display-admission-tests.py': [(out('--output'), PASS), (out('--output') + ['--mutations'], PASS)], From e2cc4ab5174d5ac8f6ea85b6ba5fb476db39d81a Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Mon, 23 Nov 2026 07:30:50 +1100 Subject: [PATCH 13/16] dt-bindings: display: apple,dcp: require the handed-over session's properties A handed-over session needs its protocol version, endpoint map and buffers; require them with apple,rtkit-handoff. State that the regions the buffers lie in are no-map. Signed-off-by: Ryan Murray --- Documentation/devicetree/bindings/display/apple,dcp.yaml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/display/apple,dcp.yaml b/Documentation/devicetree/bindings/display/apple,dcp.yaml index c0395f922f097..6867256ee228e 100644 --- a/Documentation/devicetree/bindings/display/apple,dcp.yaml +++ b/Documentation/devicetree/bindings/display/apple,dcp.yaml @@ -320,8 +320,8 @@ properties: buffer lies inside one of the reserved-memory regions referenced by memory-region, and that region maps it at the same address through iommu-addresses, so the mapping survives the IOMMU taking over the - processor's page tables. An empty property records that the session - has no shared buffers. + processor's page tables. Those regions are no-map. An empty property + records that the session has no shared buffers. apple,j613-25g83-dcpext-handoff: $ref: /schemas/types.yaml#/definitions/uint32 @@ -622,6 +622,9 @@ required: - mboxes - iommus +dependentRequired: + apple,rtkit-handoff: [ 'apple,rtkit-version', 'apple,rtkit-epmap', 'apple,rtkit-buffers' ] + allOf: - if: not: From 7fa1b919892457dd443ea7d2947909a1cbac8be3 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Tue, 24 Nov 2026 15:38:05 +1100 Subject: [PATCH 14/16] drm/apple: dpavservep: take a fixed output's AV service again after a sleep A DP AV service is taken only while the attachment it was announced for is current: the announcement's generation must be the DCP's, and once the generation has moved on, a Type-C output waits for its cable again. Every sleep and DPMS cycle moves the generation on (dcp_disable_typec_work()), also on a DCP whose output is fixed and has no Type-C cable at all. On the M2 Mac mini the HDMI port is such a fixed output: its MCDP29xx converter's AV service was admitted at boot, but after the first s2idle the re-announced service was refused (-ENODEV, generation 2, no cable) on every wake, so HDMI lost the service that publishes its EDID. A fixed output that no Type-C display has borrowed has no cable to wait for. Admit its services from the current generation; one announced before the sleep still is not taken after it. Signed-off-by: Ryan Murray --- drivers/gpu/drm/apple/epic/dpavservep.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/apple/epic/dpavservep.c b/drivers/gpu/drm/apple/epic/dpavservep.c index 655fe1e5e58cd..b3460c45c1f56 100644 --- a/drivers/gpu/drm/apple/epic/dpavservep.c +++ b/drivers/gpu/drm/apple/epic/dpavservep.c @@ -17,6 +17,7 @@ #include "../afk.h" #include "../dcp.h" #include "../dcp-internal.h" +#include "../dcp-fabric.h" #include "../connector.h" #include "../trace.h" @@ -66,10 +67,15 @@ static bool dcpavserv_identity(struct apple_epic_service *service, const char *n static bool dcpavserv_admission_current(struct apple_dcp *dcp, u64 generation) { lockdep_assert_held(&dcp->hpd_mutex); - /* Initial service discovery may precede the first Type-C attachment. */ + /* + * Initial service discovery may precede the first Type-C attachment. A + * fixed output that no Type-C display has borrowed (the HDMI port) has no + * Type-C cable to wait for: every sleep and DPMS cycle still moves the + * generation on, so a service announced before it is not taken after it. + */ return !READ_ONCE(dcp->quiescing) && !READ_ONCE(dcp->external_physically_absent) && generation == dcp->typec_generation && - (!generation || dcp->typec_cable_connected); + (!generation || dcp->typec_cable_connected || !dcp_is_typec_output(dcp)); } /* Admission runs before AFKV2 OPEN and before readers can pin the service. */ From 06e155e8efacb74ddef7d1ebf3af5ba9c5d68f8e Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Tue, 24 Nov 2026 15:38:06 +1100 Subject: [PATCH 15/16] tools/asahi: test the DP AV service admission across sleeps Build the real dcpavserv_admission_current() and dcp_is_typec_output() against a small model: a fixed HDMI output at boot and after a sleep, a stale announcement, quiescing, a physically absent display, a Type-C output before attach, unplugged and plugged, an HDMI port a Type-C display borrowed, and a fixed USB-C output. Four mutations (the old cable wait, no generation check, no cable check, no quiescing check) must fail. Signed-off-by: Ryan Murray --- tools/asahi/dpavserv-admission-tests.py | 117 ++++++++++++++++++++++++ tools/asahi/run-host-tests.py | 4 + 2 files changed, 121 insertions(+) create mode 100755 tools/asahi/dpavserv-admission-tests.py diff --git a/tools/asahi/dpavserv-admission-tests.py b/tools/asahi/dpavserv-admission-tests.py new file mode 100755 index 0000000000000..22e200283b483 --- /dev/null +++ b/tools/asahi/dpavserv-admission-tests.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only +"""Run the actual DP AV service admission check over the output states. + +A DCP takes a DP AV service only while the attachment it was announced for +is current. Every sleep and DPMS cycle moves the DCP's generation on; a +Type-C output then waits for its cable again. A fixed output that no Type-C +display has borrowed (the M2 Mac mini's HDMI port) has no Type-C cable: once +the generation had moved, its converter's AV service was refused for good, +so HDMI lost its EDID and stayed dark after the first sleep. The fixture +builds the real dcpavserv_admission_current() from epic/dpavservep.c and the +real dcp_is_typec_output() from dcp-fabric.c against a small model. + +--mutation names a change to the production function that the matrix must +kill. +""" +import argparse +import os +import re +import subprocess +import sys +import tempfile +from pathlib import Path + +ROOT = Path(__file__).resolve().parents[2] +DPAV = "drivers/gpu/drm/apple/epic/dpavservep.c" +FABRIC = "drivers/gpu/drm/apple/dcp-fabric.c" + +MUTATIONS = { + # The old check: a fixed output waits for a Type-C cable it never gets. + "old-cable-wait": (DPAV, " || !dcp_is_typec_output(dcp))", ")"), + # Admit a stale announcement from before a sleep. + "ignore-generation": (DPAV, "generation == dcp->typec_generation &&", ""), + # Admit on a borrowed (Type-C) route without its cable. + "ignore-cable": (DPAV, "dcp->typec_cable_connected ||", "true ||"), + # Admit while the DCP is quiescing. + "ignore-quiescing": (DPAV, "!READ_ONCE(dcp->quiescing) && ", ""), +} + +HARNESS = r''' +#include +#include +#include +typedef uint64_t u64; +#define READ_ONCE(x) (x) +#define lockdep_assert_held(x) ((void)(x)) +#define DRM_MODE_CONNECTOR_HDMIA 11 +#define DRM_MODE_CONNECTOR_USB 20 +struct apple_dcp { + int hpd_mutex; + bool quiescing, external_physically_absent, typec_cable_connected; + u64 typec_generation; + void *active_typec_route; + int fixed_connector_type; +}; +@@FUNCS@@ +int main(void) +{ + int route, fail = 0; + struct apple_dcp d; +#define CASE(name, expect, ...) do { d = (struct apple_dcp){ __VA_ARGS__ }; \ + bool got = dcpavserv_admission_current(&d, d.typec_generation); \ + if (got != (expect)) { printf("FAIL line %d %s: got %d\n", __LINE__, name, got); fail++; } \ + else printf("ok %s\n", name); } while (0) +#define STALE(name, ...) do { d = (struct apple_dcp){ __VA_ARGS__ }; \ + bool got = dcpavserv_admission_current(&d, d.typec_generation - 1); \ + if (got) { printf("FAIL line %d %s: stale admitted\n", __LINE__, name); fail++; } \ + else printf("ok %s\n", name); } while (0) + CASE("hdmi at boot", true, .fixed_connector_type = DRM_MODE_CONNECTOR_HDMIA); + CASE("hdmi after a sleep", true, .fixed_connector_type = DRM_MODE_CONNECTOR_HDMIA, .typec_generation = 3); + STALE("hdmi stale announcement", .fixed_connector_type = DRM_MODE_CONNECTOR_HDMIA, .typec_generation = 3); + CASE("hdmi quiescing", false, .fixed_connector_type = DRM_MODE_CONNECTOR_HDMIA, .typec_generation = 3, .quiescing = true); + CASE("hdmi physically absent", false, .fixed_connector_type = DRM_MODE_CONNECTOR_HDMIA, .external_physically_absent = true); + CASE("typec before first attach", true, .active_typec_route = &route); + CASE("typec unplugged", false, .active_typec_route = &route, .typec_generation = 2); + CASE("typec plugged", true, .active_typec_route = &route, .typec_generation = 2, .typec_cable_connected = true); + STALE("typec stale announcement", .active_typec_route = &route, .typec_generation = 2, .typec_cable_connected = true); + CASE("hdmi borrowed by typec, unplugged", false, .fixed_connector_type = DRM_MODE_CONNECTOR_HDMIA, .active_typec_route = &route, .typec_generation = 2); + CASE("fixed usb-c output unplugged", false, .fixed_connector_type = DRM_MODE_CONNECTOR_USB, .typec_generation = 2); + printf("%d failures\n", fail); + return fail != 0; +} +''' + +def extract(path, sig): + src = (ROOT / path).read_text() + m = re.search(r'^%s\(struct apple_dcp \*dcp[^)]*\)\n\{.*?^\}\n' % re.escape(sig), src, re.S | re.M) + if not m: + sys.exit(f"{sig} not found in {path}") + return path, m.group(0) + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--mutation", choices=sorted(MUTATIONS)) + a = ap.parse_args() + parts = [extract(FABRIC, "bool dcp_is_typec_output"), + extract(DPAV, "static bool dcpavserv_admission_current")] + code = [] + for path, text in parts: + if a.mutation and MUTATIONS[a.mutation][0] == path: + old, new = MUTATIONS[a.mutation][1:] + if text.count(old) != 1: + sys.exit(f"mutation {a.mutation} does not apply exactly once") + text = text.replace(old, new) + code.append(text) + with tempfile.TemporaryDirectory() as tmp: + c = Path(tmp) / "t.c" + exe = Path(tmp) / "t" + c.write_text(HARNESS.replace("@@FUNCS@@", "\n".join(code))) + flags = ["-std=gnu11", "-Wall"] + ([] if a.mutation else ["-Werror"]) + subprocess.run([os.environ.get("CC", "cc"), *flags, "-o", exe, c], check=True) + r = subprocess.run([exe], capture_output=True, text=True) + print(r.stdout + r.stderr, end="") + sys.exit(r.returncode) + +if __name__ == "__main__": + main() diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index 3d4e02c2ce8f5..20563ad452f74 100755 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -177,6 +177,10 @@ def mutations(flag, names, base, expect=KILL): 'missing-control-firmware', 'missing-control-descriptor', 'missing-owner-ipc', 'missing-owner-firmware', 'missing-owner-descriptor', 'missing-owner-arena'), out()), + # A fixed (non-Type-C) output takes its DP AV service again after a sleep. + 'dpavserv-admission-tests.py': [([], PASS)] + + mutations('--mutation', ('old-cable-wait', 'ignore-generation', 'ignore-cable', + 'ignore-quiescing'), []), 'dcp-bw-scratch-window-tests.py': [([], PASS)] + mutations('--mutation', ('old-check', 'start-only'), []), 'clpc-gpu-demand-tests.py': [([], PASS)], 'clpc-high-power-cleanup-tests.py': [(out(), PASS), From 2e95be317a1bb370e4ca64b8db15100c7c9df4aa Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Tue, 24 Nov 2026 16:25:41 +1100 Subject: [PATCH 16/16] selftests: apple-dcp: give the AV admission scenarios their output kind dcpavserv_admission_current() now asks dcp_is_typec_output() whether the output waits for a Type-C cable. The service-rebind, provider-admission, publication-hpd and panel-dimensions units build it from dpavservep.c and model a Type-C output: declare the helper there, and define it as such where the scenario does not already. Signed-off-by: Ryan Murray --- tools/testing/selftests/drivers/gpu/apple-dcp/edid.py | 4 ++-- tools/testing/selftests/drivers/gpu/apple-dcp/rate.py | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py b/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py index 6898b7b368801..476c35ff89f7d 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py @@ -173,7 +173,7 @@ def function(file,signature): function('afk.h','static inline bool\nafk_service_reinit('),function('afk.h','static inline void afk_service_discard('), function('afk.h','static inline void afk_service_publish('), function('epic/dpavservep.c','static void dcpavserv_notify_edid('),function('epic/dpavservep.c','static bool dcpavserv_identity('), - function('epic/dpavservep.c','static bool dcpavserv_admission_current('),function('epic/dpavservep.c','static int dcpavserv_prepare('), + '/* These scenarios model a Type-C output (dcp-fabric.c decides it in the driver). */\nstatic bool dcp_is_typec_output(struct apple_dcp *d) { (void)d; return true; }\n'+function('epic/dpavservep.c','static bool dcpavserv_admission_current('),function('epic/dpavservep.c','static int dcpavserv_prepare('), function('epic/dpavservep.c','static int dcpavserv_revalidate('),function('epic/dpavservep.c','static void dcpavserv_init('),function('epic/dpavservep.c','static void dcpavserv_invalidate_edid('), function('epic/dpavservep.c','static void dcpavserv_teardown('),function('epic/dpavservep.c','void dpavservep_detach('), function('afk.c','static const struct apple_epic_service_ops *\nafk_match_service('), @@ -698,7 +698,7 @@ def function(file, signature): function('dcp.c', 'static struct apple_dcp_afkep *dcp_afkep('), function('dcp.c', 'static void dcp_recv_msg('), function('epic/dpavservep.c', 'static bool dcpavserv_identity('), - function('epic/dpavservep.c', 'static bool dcpavserv_admission_current('), + '/* These scenarios model a Type-C output (dcp-fabric.c decides it in the driver). */\nstatic bool dcp_is_typec_output(struct apple_dcp *d) { (void)d; return true; }\n' + function('epic/dpavservep.c', 'static bool dcpavserv_admission_current('), function('epic/dpavservep.c', 'static int dcpavserv_prepare('), function('epic/dpavservep.c', 'static int dcpdpserv_prepare('), function('epic/dpavservep.c', 'static void dcpavserv_init('), diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py b/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py index 1df2c17f68a9a..7a0ee164cf859 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/rate.py @@ -920,6 +920,10 @@ def publication(root): 'static void dcpavserv_teardown(', 'void dpavservep_detach(', 'bool dcpavserv_edid_current(', 'bool dcpavserv_edid_service_current(', ]) + # dcp-fabric.c decides it in the driver; each scenario below defines it. + transport = transport.replace('static bool dcpavserv_admission_current(', + 'static bool dcp_is_typec_output(struct apple_dcp *d);\n' + 'static bool dcpavserv_admission_current(', 1) mode_helpers = iomfb[iomfb.index('static struct dcp_display_mode *dcp_modes_snapshot('):iomfb.index('int dcp_get_modes(')] # The link line of a processor whose hardware description asks for it # (hw.link_report, T6050's external ones): no processor here does. @@ -1251,8 +1255,10 @@ def panel_dimensions(root): puts("PASS: internal panel dimensions survive repeated EDID clears; firmware size and DT fallback; external EDID size preserved"); } """ + # The panel scenarios model a Type-C output, as the hotplug ones. unit = unit.replace('int main(int argc,char **argv) {', - checks + 'int main(int argc,char **argv) {') + 'static bool dcp_is_typec_output(struct apple_dcp *d) { (void)d; return true; }\n' + + checks + 'int main(int argc,char **argv) {') return unit.replace(' transport_edid=raw;', ' transport_edid=raw;panel_dimension_probes();', 1)