diff --git a/Documentation/devicetree/bindings/display/apple,dcp.yaml b/Documentation/devicetree/bindings/display/apple,dcp.yaml index 193ceda46427f..6867256ee228e 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. 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 const: 1 @@ -578,6 +622,9 @@ required: - mboxes - iommus +dependentRequired: + apple,rtkit-handoff: [ 'apple,rtkit-version', 'apple,rtkit-epmap', 'apple,rtkit-buffers' ] + allOf: - if: not: diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index f55c05d9f1793..f9159957e8e83 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -498,6 +498,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-handoff) */ + 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 0666748f436d0..f9560092a758c 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 @@ -1855,6 +1856,170 @@ static int dcp_check_iova_contiguous(struct iommu_domain *domain, return 0; } +#define DCP_RTKIT_HANDOFF "dcp-live-v1" +#define DCP_RTKIT_LIVE_BUFFER_CELLS 5 +#define DCP_RTKIT_LIVE_MAX_BUFFERS 4 + +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 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) +{ + 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); + 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); + } + 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, 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; + const char *handoff; + int count, i, ret; + u32 version; + + if (!of_property_present(np, "apple,rtkit-handoff")) + return 0; + ret = of_property_read_string(np, "apple,rtkit-handoff", &handoff); + if (ret) + return ret; + 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) & + 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; + + /* 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 == -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-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[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; + } + /* 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; + } + 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; + } + + /* 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; + /* + * 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; + } + return 1; + +fail: + dcp_rtkit_live_unmap(live); + return ret; +} + int dcp_rtk_shmem_setup(void *cookie, struct apple_rtkit_shmem *bfr) { struct apple_dcp *dcp = cookie; @@ -2324,16 +2489,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(). + * 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) && - dcp->fw_compat == DCP_FIRMWARE_V_13_5; + (dcp->fw_compat == DCP_FIRMWARE_V_13_5 || dcp->rtkit_adopted); bool compact, withdrawn; unsigned long timeout; u64 generation; @@ -2507,8 +2671,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", @@ -2531,7 +2696,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, @@ -4772,6 +4938,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 @@ -6136,6 +6320,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); @@ -6474,7 +6666,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) { @@ -6730,12 +6924,30 @@ static int dcp_comp_bind_pipe(struct device *dev, struct device *main, void *dat dcp->coproc_reg + APPLE_DCP_COPROC_CPU_CONTROL); } + /* + * 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 (ret) { + if (live) + dcp_rtkit_live_unmap(&live_rtkit); 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); @@ -6744,6 +6956,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; @@ -6751,6 +6965,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) @@ -6763,7 +6978,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) @@ -6902,6 +7119,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); @@ -6928,6 +7148,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); @@ -7334,6 +7555,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-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)) dcp->hw.link_report = false; diff --git a/drivers/gpu/drm/apple/epic/dpavservep-identity-test.c b/drivers/gpu/drm/apple/epic/dpavservep-identity-test.c index 6cdee1ac5881f..96a6003a88cbc 100644 --- a/drivers/gpu/drm/apple/epic/dpavservep-identity-test.c +++ b/drivers/gpu/drm/apple/epic/dpavservep-identity-test.c @@ -68,6 +68,14 @@ static const struct dpavid_case dpavid_cases[] = { "DCPDP13Service", 0, 7, false }, { "v2 ep 0x28: DP2HDMI unit 0", DPAVID_V2, DPAVSERV_ENDPOINT, DPAVID_NAME, "AppleDCPDP2HDMI", 0, 1, false }, + { "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, false }, { "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 37038852e5ca4..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" @@ -44,20 +45,37 @@ 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; + if (!class || !service->channel || service->channel > U16_MAX) + return false; /* H17P's lower-case interface-id is dynamic, not a physical-port unit. */ - return service->ep->endpoint == DPAVSERV_ENDPOINT_V2 && class && - (!strcmp(class, "AppleDCPDP2HDMI") || - !strcmp(class, "DCPDP13Service")) && service->channel && - service->channel <= U16_MAX && unit == service->channel; + if (service->ep->endpoint == DPAVSERV_ENDPOINT_V2) + return (!strcmp(class, "AppleDCPDP2HDMI") || + !strcmp(class, "DCPDP13Service")) && unit == service->channel; + /* + * Firmware 27 names an MCDP29xx DP-to-HDMI converter's AV service after + * its part (the M2 Mac mini's HDMI port, USB-C to HDMI adapters) and + * announces it on the classic DPAV endpoint with EPICUnit 0; its + * interface-id (the channel) is dynamic across reconnects. The generic + * services stay refused there: using them resets the M4 Air when the + * external processor releases its link. + */ + return service->ep->endpoint == DPAVSERV_ENDPOINT && unit == 0 && + (!strcmp(class, "AppleDCPMCDP29XX") || + !strcmp(class, "AppleDCPMCDP2900")); } 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. */ diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c index e516f9d6cb6a9..d25c7e2f106f5 100644 --- a/drivers/soc/apple/rtkit.c +++ b/drivers/soc/apple/rtkit.c @@ -2301,12 +2301,60 @@ 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; + /* 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; + 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; @@ -2388,6 +2436,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) @@ -2415,7 +2469,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); @@ -2424,7 +2478,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); @@ -2483,10 +2537,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) { @@ -3540,7 +3608,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 c76e50bd67d59..7017f1786373c 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. */ 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/rtkit-adopted-session-tests.py b/tools/asahi/rtkit-adopted-session-tests.py new file mode 100755 index 0000000000000..a43f60b841bba --- /dev/null +++ b/tools/asahi/rtkit-adopted-session-tests.py @@ -0,0 +1,210 @@ +#!/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'), + 'any-buffer-endpoint': ('rtk->ioreport_buffer.size && !test_bit(APPLE_RTKIT_EP_IOREPORT, map)', '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_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); +} + +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]); + + /* + * 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; +} +''' + + +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 326dccb7b8573..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), @@ -292,6 +296,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', '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)], 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/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' 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)