From 47b174291c29b6641d5c7cff82f02a55199c8794 Mon Sep 17 00:00:00 2001 From: Eric Juta Date: Wed, 4 Nov 2026 21:06:32 +0000 Subject: [PATCH 01/11] soc: apple: t8122 display gate: dcpext_disp_dart switch apple_t8122_display.dcpext_disp_dart=0 enables the T8122 dcpext without appending its display DART to the display subsystem's iommus. On the J615 the shared domain faults the internal DCP's DART (NO PMD/PTE FOR IOVA at 0x1000a000000..) and crashes the internal DCP about 2 s into boot. Signed-off-by: Eric Juta --- drivers/soc/apple/t6030-display-gate.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/soc/apple/t6030-display-gate.c b/drivers/soc/apple/t6030-display-gate.c index 07ba8b9f60f571..e067ae0b06a1bc 100644 --- a/drivers/soc/apple/t6030-display-gate.c +++ b/drivers/soc/apple/t6030-display-gate.c @@ -1858,6 +1858,19 @@ static int __init gate_t8122_dcpext_setup(char *arg) } early_param("apple_t8122_display.dcpext", gate_t8122_dcpext_setup); +/* + * Experiment (J615): apple_t8122_display.dcpext_disp_dart=0 enables dcpext + * without appending its display DART to the display subsystem's iommus, to + * tell whether that shared domain is what faults the internal DCP's DART. + */ +static bool gate_t8122_dcpext_disp_dart __initdata = true; + +static int __init gate_t8122_dcpext_disp_dart_setup(char *arg) +{ + return kstrtobool(arg, &gate_t8122_dcpext_disp_dart); +} +early_param("apple_t8122_display.dcpext_disp_dart", gate_t8122_dcpext_disp_dart_setup); + /* The most display crossbars a T8122 dcpext's routes switch: ATC0's and ATC1's. */ #define GATE_T8122_XBARS 2 @@ -2028,8 +2041,11 @@ static void __init gate_t8122_dcpext_one(struct device_node *np) ret = of_changeset_update_prop_string(cs, np, "status", "okay"); if (!ret) ret = gate_ext_routes(cs, np, "okay"); - if (!ret) + if (!ret && gate_t8122_dcpext_disp_dart) ret = gate_display_add_dart(cs, disp_dart); + else if (!ret) + gate_info("%pOF: display DART %pOF not added to the display subsystem (dcpext_disp_dart=0)\n", + np, disp_dart); if (!ret) ret = of_changeset_apply(cs); if (ret) { From 626410acd34a6006932a4cf76f3aa3b0704529c7 Mon Sep 17 00:00:00 2001 From: Eric Juta Date: Wed, 4 Nov 2026 21:06:32 +0000 Subject: [PATCH 02/11] drm: apple: dcp: mirror framebuffers into the T8122 dcpext fbdma domain With the dcpext display DART out of the display subsystem's domain, the external pipe scans framebuffers through a DART stream nothing maps. An optional fbdma child of the dcpext (display DART stream 0, the display subsystem's DVA window) gets its own domain, and each swapped framebuffer is mapped read-only there at its display DVA. Imported (GPU) buffers use the importer's sg table. Signed-off-by: Eric Juta --- drivers/gpu/drm/apple/dcp-internal.h | 7 +++ drivers/gpu/drm/apple/dcp.c | 87 ++++++++++++++++++++++++++ drivers/gpu/drm/apple/dcp.h | 1 + drivers/gpu/drm/apple/iomfb_template.c | 1 + 4 files changed, 96 insertions(+) diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 3eac22a57aa069..8f3da321619673 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -231,6 +231,13 @@ struct apple_dcp { struct platform_device *piodma; bool piodma_created; struct iommu_domain *iommu_dom; + /* + * Experiment (J615 dcpext): a child device on the display DART stream + * the external pipe scans framebuffers through. Framebuffers are + * mirrored into its domain at the display subsystem's addresses. + */ + struct platform_device *fbdma; + struct iommu_domain *fb_dom; /* which of the nine cumulative A031 notify-client states to send next */ unsigned int a031_step; struct apple_rtkit *rtk; diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 8cb040d16d552c..b5457cd3b188ab 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -3073,6 +3074,10 @@ static void dcp_release_piodma_iommu_dev(struct apple_dcp *dcp) WRITE_ONCE(dcp->quiescing, true); return; } + if (dcp->fbdma) + of_platform_device_destroy(&dcp->fbdma->dev, NULL); + dcp->fbdma = NULL; + dcp->fb_dom = NULL; if (dcp->piodma) { if (dcp->piodma_created) of_platform_device_destroy(&dcp->piodma->dev, NULL); @@ -3084,6 +3089,86 @@ static void dcp_release_piodma_iommu_dev(struct apple_dcp *dcp) dcp->piodma_created = false; } +/* + * Experiment (J615 dcpext): the external pipe reads framebuffers through its + * own display DART, not the internal one the display subsystem's domain + * covers. An "fbdma" child, on that DART's stream 0 with the display + * subsystem's DVA window, gets a domain the framebuffers are mirrored into. + * Without the node nothing changes. + */ +static void dcp_create_fbdma_dev(struct apple_dcp *dcp) +{ + struct device_node *node; + struct iommu_domain *dom; + int ret; + + if (!dcp->ext_failsafe || dcp->fbdma) + return; + node = of_get_child_by_name(dcp->dev->of_node, "fbdma"); + if (!node) + return; + dcp->fbdma = of_platform_device_create(node, NULL, dcp->dev); + if (!dcp->fbdma) { + dev_warn(dcp->dev, "fbdma: could not create %pOF\n", node); + goto out; + } + ret = dma_set_mask_and_coherent(&dcp->fbdma->dev, DMA_BIT_MASK(42)); + if (!ret) + ret = of_dma_configure(&dcp->fbdma->dev, node, true); + dom = ret ? NULL : iommu_get_domain_for_dev(&dcp->fbdma->dev); + if (IS_ERR_OR_NULL(dom)) { + dev_warn(dcp->dev, "fbdma: no IOMMU domain (%d)\n", ret); + of_platform_device_destroy(&dcp->fbdma->dev, NULL); + dcp->fbdma = NULL; + goto out; + } + dcp->fb_dom = dom; + dev_info(dcp->dev, "fbdma: framebuffers mirrored through %pOF\n", node); +out: + of_node_put(node); +} + +/* Map @fb's GEM objects into the fbdma domain at their display DVAs. */ +void dcp_fb_mirror(struct apple_dcp *dcp, struct drm_framebuffer *fb) +{ + unsigned int i; + + if (!dcp->fb_dom || !fb) + return; + for (i = 0; i < fb->format->num_planes; i++) { + struct drm_gem_dma_object *obj = drm_fb_dma_get_gem_obj(fb, i); + struct sg_table *sgt; + size_t size; + ssize_t mapped; + phys_addr_t phys; + + if (!obj) + continue; + /* Imported (GPU) buffers carry their pages in obj->sgt. */ + sgt = obj->sgt ? obj->sgt : drm_gem_dma_get_sg_table(obj); + if (IS_ERR_OR_NULL(sgt)) + continue; + size = ALIGN(obj->base.size, SZ_16K); + phys = iommu_iova_to_phys(dcp->fb_dom, obj->dma_addr); + if (phys != sg_phys(sgt->sgl)) { + /* A DVA the display subsystem reused for another buffer. */ + if (phys) + iommu_unmap(dcp->fb_dom, obj->dma_addr, size); + mapped = iommu_map_sgtable(dcp->fb_dom, obj->dma_addr, sgt, + IOMMU_READ); + dev_info_ratelimited(dcp->dev, + "fbdma: %pad (%zu bytes, %s, pa %pa) mapped %zd\n", + &obj->dma_addr, obj->base.size, + obj->sgt ? "imported" : "native", &(phys_addr_t){ sg_phys(sgt->sgl) }, + mapped); + } + if (sgt != obj->sgt) { + sg_free_table(sgt); + kfree(sgt); + } + } +} + void dcp_retain_framebuffer(struct platform_device *pdev, struct dcp_fb_reference *entry) { @@ -3918,6 +4003,8 @@ static int dcp_comp_bind_pipe(struct device *dev, struct device *main, void *dat } ret = dcp_create_piodma_iommu_dev(dcp); + if (!ret) + dcp_create_fbdma_dev(dcp); if (ret) return dev_err_probe(dev, ret, "Failed to create PIODMA iommu child device\n"); diff --git a/drivers/gpu/drm/apple/dcp.h b/drivers/gpu/drm/apple/dcp.h index baff04ee201e72..92600177244a2f 100644 --- a/drivers/gpu/drm/apple/dcp.h +++ b/drivers/gpu/drm/apple/dcp.h @@ -72,6 +72,7 @@ void dcp_retain_framebuffer(struct platform_device *pdev, struct dcp_fb_reference *entry); void dcp_arm_retained_framebuffers(struct apple_dcp *dcp, u32 swap_id); void dcp_unarm_retained_framebuffers(struct apple_dcp *dcp, u32 swap_id); +void dcp_fb_mirror(struct apple_dcp *dcp, struct drm_framebuffer *fb); void dcp_release_retained_framebuffers(struct apple_dcp *dcp, u32 swap_id); void dcp_release_all_retained_framebuffers(struct apple_dcp *dcp); bool dcp_is_initialized(struct platform_device *pdev); diff --git a/drivers/gpu/drm/apple/iomfb_template.c b/drivers/gpu/drm/apple/iomfb_template.c index 78162bdb805dba..c879b3b0a8db3d 100644 --- a/drivers/gpu/drm/apple/iomfb_template.c +++ b/drivers/gpu/drm/apple/iomfb_template.c @@ -2502,6 +2502,7 @@ void DCP_FW_NAME(iomfb_flush)(struct apple_dcp *dcp, struct drm_crtc *crtc, stru if (dcp->notch_height > 0) req->swap.dst_rect[l].y += dcp->notch_height; + dcp_fb_mirror(dcp, new_state->fb); req->surf_iova[l] = apple_state->iova; req->surf[l].base = apple_state->surf; #if DCP_FW_VER >= DCP_FW_VERSION(26, 0, 0) From c67955d5f52228f2a5328d6c879c9c900fa621dc Mon Sep 17 00:00:00 2001 From: Eric Juta Date: Wed, 4 Nov 2026 21:07:10 +0000 Subject: [PATCH 03/11] arm64: dts: apple: t8122-j615: external display over USB-C (dcpext) The J613 dcpext routes, carried to the J615 (same T8122 Type-C wiring: usb-pd@c Left-back/ATC0, usb-pd@a Left-front/ATC1), plus an fbdma child on dispext0_dart stream 0 for the framebuffer mirror. Signed-off-by: Eric Juta --- arch/arm64/boot/dts/apple/t8122-j615.dts | 87 ++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8122-j615.dts b/arch/arm64/boot/dts/apple/t8122-j615.dts index 5e52cd3046e713..cf92e7f6349508 100644 --- a/arch/arm64/boot/dts/apple/t8122-j615.dts +++ b/arch/arm64/boot/dts/apple/t8122-j615.dts @@ -262,3 +262,90 @@ }; #include "hwmon-laptop.dtsi" + +/* + * External display on both USB-C ports, wired as on the J613 (see + * t8122-j613.dts): usb-pd@c is USB-C Left-back (typec0, ATC0) and usb-pd@a is + * USB-C Left-front (typec1, ATC1). Everything stays disabled until the boot + * loader marks the dcpext firmware reserved and the display gate enables it. + * + * fbdma is the display DART stream the dcpext scans framebuffers through, + * with the display subsystem's DVA window: on the J615 the gate must not add + * dispext0_dart to the display subsystem (apple_t8122_display.dcpext_disp_dart=0), + * so appledrm mirrors framebuffers there instead. + */ +/ { + aliases { + dcpext = &dcpext; + }; +}; + +&dcpext { + apple,connector-type = "USB-C"; + phys = <&atcphy0 PHY_TYPE_DP>, <&atcphy1 PHY_TYPE_DP>; + phy-names = "typec0", "typec1"; + mux-controls = <&atcphy0_xbar 0>, <&atcphy1_xbar 0>; + mux-control-names = "typec0", "typec1"; + apple,typec-mux-indices = <2 2>; + apple,typec-dptx-phys = <0 1>; + /* RTKit quirks of AsahiLinux/linux#607 (syslog/ioreport acks, kdebug). */ + apple,sync-syslog-ack; + + fbdma { + iommus = <&dispext0_dart 0>; + apple,dma-range = /bits/ 64 <0x10000000000 0x1000000000>; + }; + + typec-routes { + #address-cells = <1>; + #size-cells = <0>; + + route@0 { + reg = <0>; + mode-switch; + status = "disabled"; + + port { + dcpext_typec0: endpoint { + remote-endpoint = <&typec0_dcpext>; + }; + }; + }; + + route@1 { + reg = <1>; + mode-switch; + status = "disabled"; + + port { + dcpext_typec1: endpoint { + remote-endpoint = <&typec1_dcpext>; + }; + }; + }; + }; +}; + +&typec0 { + ports { + port@3 { + reg = <3>; + + typec0_dcpext: endpoint { + remote-endpoint = <&dcpext_typec0>; + }; + }; + }; +}; + +&typec1 { + ports { + port@3 { + reg = <3>; + + typec1_dcpext: endpoint { + remote-endpoint = <&dcpext_typec1>; + }; + }; + }; +}; From dc601fb6654fda325c0f8f8ad8db1fe959c1d7e6 Mon Sep 17 00:00:00 2001 From: Eric Juta Date: Wed, 11 Nov 2026 17:09:15 +0000 Subject: [PATCH 04/11] dt-bindings: display: apple,dcp: fbdma child and apple,no-shared-display-dart Describe the fbdma child an external coprocessor scans mirrored framebuffers through, and the marker that keeps its display DART out of the display subsystem's IOMMU domain. Signed-off-by: Eric Juta --- .../bindings/display/apple,dcp.yaml | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Documentation/devicetree/bindings/display/apple,dcp.yaml b/Documentation/devicetree/bindings/display/apple,dcp.yaml index ec3251e7c4fcaa..e12645c5b2f8fe 100644 --- a/Documentation/devicetree/bindings/display/apple,dcp.yaml +++ b/Documentation/devicetree/bindings/display/apple,dcp.yaml @@ -258,6 +258,32 @@ properties: - iommus additionalProperties: false + apple,no-shared-display-dart: + type: boolean + description: + The external coprocessor's display DART must stay out of the display + subsystem's IOMMU domain. Framebuffers are mirrored through the fbdma + child instead, which must be present. + + fbdma: + type: object + description: + The display DART stream an external coprocessor scans framebuffers + through, with the display subsystem's DVA window. + properties: + iommus: + maxItems: 1 + apple,dma-range: + $ref: /schemas/types.yaml#/definitions/uint64-array + description: + Base and size of the display subsystem's DVA window on this stream. + minItems: 2 + maxItems: 2 + required: + - iommus + - apple,dma-range + additionalProperties: false + panel: type: object properties: From 4cb95a0326a9f076dcaa91d39a8be5fbe6002af7 Mon Sep 17 00:00:00 2001 From: Eric Juta Date: Wed, 11 Nov 2026 17:09:15 +0000 Subject: [PATCH 05/11] drm: apple: dcp: unmap fbdma framebuffer mirrors when their buffer is freed dcp_fb_mirror() mapped each framebuffer read-only into the fbdma domain and never unmapped it, so freed pages stayed readable by the external DCP until their DVA was reused. Track each mirrored GEM object in an xarray and remove its mapping from the GEM free hook, before the pages and the DVA are released, and drop all mirrors when the fbdma device goes away. The xarray also answers "already mapped" before any sg_table is built, so a flush of a mapped native buffer no longer allocates. Only a failed mapping is logged. Signed-off-by: Eric Juta --- drivers/gpu/drm/apple/apple_drv.c | 34 +++++++++++ drivers/gpu/drm/apple/dcp-internal.h | 12 +++- drivers/gpu/drm/apple/dcp.c | 84 +++++++++++++++++++++------- drivers/gpu/drm/apple/dcp.h | 2 + 4 files changed, 108 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/apple/apple_drv.c b/drivers/gpu/drm/apple/apple_drv.c index 9028388b33915b..8bfc569b8d3846 100644 --- a/drivers/gpu/drm/apple/apple_drv.c +++ b/drivers/gpu/drm/apple/apple_drv.c @@ -163,6 +163,39 @@ static int apple_drm_gem_dumb_create(struct drm_file *file_priv, return drm_gem_dma_dumb_create_internal(file_priv, drm, args); } +/* + * A T8122 dcpext mirrors framebuffers into its own display DART domain. + * Remove a buffer's mirror before its pages and its DVA are released. + */ +static void apple_drm_gem_free(struct drm_gem_object *gem) +{ + struct drm_crtc *crtc; + + drm_for_each_crtc(crtc, gem->dev) + dcp_fb_unmirror(to_apple_crtc(crtc)->dcp, to_drm_gem_dma_obj(gem)); + drm_gem_dma_object_free(gem); +} + +static const struct drm_gem_object_funcs apple_drm_gem_funcs = { + .free = apple_drm_gem_free, + .print_info = drm_gem_dma_object_print_info, + .get_sg_table = drm_gem_dma_object_get_sg_table, + .vmap = drm_gem_dma_object_vmap, + .mmap = drm_gem_dma_object_mmap, + .vm_ops = &drm_gem_dma_vm_ops, +}; + +static struct drm_gem_object *apple_drm_gem_create_object(struct drm_device *drm, + size_t size) +{ + struct drm_gem_dma_object *obj = kzalloc_obj(*obj); + + if (!obj) + return ERR_PTR(-ENOMEM); + obj->base.funcs = &apple_drm_gem_funcs; + return &obj->base; +} + #ifdef CONFIG_DRM_FBDEV_EMULATION static int apple_drm_fbdev_probe(struct drm_fb_helper *helper, struct drm_fb_helper_surface_size *sizes) @@ -205,6 +238,7 @@ static const struct drm_driver apple_drm_driver = { DRM_FBDEV_DMA_DRIVER_OPS, #endif .postclose = apple_drm_postclose, + .gem_create_object = apple_drm_gem_create_object, .name = DRIVER_NAME, .desc = DRIVER_DESC, .major = 1, diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 8f3da321619673..a6784101d4a23a 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -232,12 +233,17 @@ struct apple_dcp { bool piodma_created; struct iommu_domain *iommu_dom; /* - * Experiment (J615 dcpext): a child device on the display DART stream - * the external pipe scans framebuffers through. Framebuffers are - * mirrored into its domain at the display subsystem's addresses. + * J615 dcpext: a child device on the display DART stream the external + * pipe scans framebuffers through. Framebuffers are mirrored into its + * domain at the display subsystem's addresses. fb_mirrors holds the + * mapped length of every mirrored GEM object, indexed by the object's + * address, until the object is freed; fb_mirror_lock protects it and + * fb_dom. */ struct platform_device *fbdma; struct iommu_domain *fb_dom; + struct xarray fb_mirrors; + struct mutex fb_mirror_lock; /* which of the nine cumulative A031 notify-client states to send next */ unsigned int a031_step; struct apple_rtkit *rtk; diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index b5457cd3b188ab..7e1e151487061c 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -3068,16 +3068,35 @@ static void dcp_work_backlight_fallback(struct work_struct *work) dev_warn(dcp->dev, "backlight registration failed: %d\n", ret); } +/* Drop every framebuffer mirror before the fbdma domain goes away. */ +static void dcp_fb_unmirror_all(struct apple_dcp *dcp) +{ + unsigned long index; + void *entry; + + guard(mutex)(&dcp->fb_mirror_lock); + if (dcp->fb_dom) { + xa_for_each(&dcp->fb_mirrors, index, entry) { + /* An object stays in fb_mirrors only while it is alive. */ + struct drm_gem_dma_object *obj = (void *)index; + + iommu_unmap(dcp->fb_dom, obj->dma_addr, xa_to_value(entry)); + } + } + xa_destroy(&dcp->fb_mirrors); + dcp->fb_dom = NULL; +} + static void dcp_release_piodma_iommu_dev(struct apple_dcp *dcp) { if (dcp->retain_dma) { WRITE_ONCE(dcp->quiescing, true); return; } + dcp_fb_unmirror_all(dcp); if (dcp->fbdma) of_platform_device_destroy(&dcp->fbdma->dev, NULL); dcp->fbdma = NULL; - dcp->fb_dom = NULL; if (dcp->piodma) { if (dcp->piodma_created) of_platform_device_destroy(&dcp->piodma->dev, NULL); @@ -3090,7 +3109,7 @@ static void dcp_release_piodma_iommu_dev(struct apple_dcp *dcp) } /* - * Experiment (J615 dcpext): the external pipe reads framebuffers through its + * J615 dcpext: the external pipe reads framebuffers through its * own display DART, not the internal one the display subsystem's domain * covers. An "fbdma" child, on that DART's stream 0 with the display * subsystem's DVA window, gets a domain the framebuffers are mirrored into. @@ -3122,46 +3141,52 @@ static void dcp_create_fbdma_dev(struct apple_dcp *dcp) dcp->fbdma = NULL; goto out; } - dcp->fb_dom = dom; + scoped_guard(mutex, &dcp->fb_mirror_lock) + dcp->fb_dom = dom; dev_info(dcp->dev, "fbdma: framebuffers mirrored through %pOF\n", node); out: of_node_put(node); } -/* Map @fb's GEM objects into the fbdma domain at their display DVAs. */ +/* + * Map @fb's GEM objects into the fbdma domain at their display DVAs. A + * mapping lasts as long as its object and its DVA do: dcp_fb_unmirror() + * removes it when the object is freed. + */ void dcp_fb_mirror(struct apple_dcp *dcp, struct drm_framebuffer *fb) { unsigned int i; - if (!dcp->fb_dom || !fb) + if (!fb || !READ_ONCE(dcp->fb_dom)) + return; + guard(mutex)(&dcp->fb_mirror_lock); + if (!dcp->fb_dom) return; for (i = 0; i < fb->format->num_planes; i++) { struct drm_gem_dma_object *obj = drm_fb_dma_get_gem_obj(fb, i); + unsigned long index = (unsigned long)obj; struct sg_table *sgt; - size_t size; ssize_t mapped; - phys_addr_t phys; - if (!obj) + if (!obj || xa_load(&dcp->fb_mirrors, index)) continue; /* Imported (GPU) buffers carry their pages in obj->sgt. */ sgt = obj->sgt ? obj->sgt : drm_gem_dma_get_sg_table(obj); if (IS_ERR_OR_NULL(sgt)) continue; - size = ALIGN(obj->base.size, SZ_16K); - phys = iommu_iova_to_phys(dcp->fb_dom, obj->dma_addr); - if (phys != sg_phys(sgt->sgl)) { - /* A DVA the display subsystem reused for another buffer. */ - if (phys) - iommu_unmap(dcp->fb_dom, obj->dma_addr, size); - mapped = iommu_map_sgtable(dcp->fb_dom, obj->dma_addr, sgt, - IOMMU_READ); - dev_info_ratelimited(dcp->dev, - "fbdma: %pad (%zu bytes, %s, pa %pa) mapped %zd\n", - &obj->dma_addr, obj->base.size, - obj->sgt ? "imported" : "native", &(phys_addr_t){ sg_phys(sgt->sgl) }, - mapped); + mapped = iommu_map_sgtable(dcp->fb_dom, obj->dma_addr, sgt, + IOMMU_READ); + if (mapped > 0 && + xa_err(xa_store(&dcp->fb_mirrors, index, xa_mk_value(mapped), + GFP_KERNEL))) { + iommu_unmap(dcp->fb_dom, obj->dma_addr, mapped); + mapped = -ENOMEM; } + if (mapped <= 0) + dev_warn_ratelimited(dcp->dev, + "fbdma: %pad (%zu bytes, %s) not mirrored: %zd\n", + &obj->dma_addr, obj->base.size, + obj->sgt ? "imported" : "native", mapped); if (sgt != obj->sgt) { sg_free_table(sgt); kfree(sgt); @@ -3169,6 +3194,21 @@ void dcp_fb_mirror(struct apple_dcp *dcp, struct drm_framebuffer *fb) } } +/* @obj is being freed: the external pipe must not read its pages any more. */ +void dcp_fb_unmirror(struct platform_device *pdev, struct drm_gem_dma_object *obj) +{ + struct apple_dcp *dcp = platform_get_drvdata(pdev); + void *entry; + + if (!dcp) + return; + guard(mutex)(&dcp->fb_mirror_lock); + entry = xa_erase(&dcp->fb_mirrors, (unsigned long)obj); + if (entry && dcp->fb_dom) + iommu_unmap(dcp->fb_dom, obj->dma_addr, xa_to_value(entry)); +} +EXPORT_SYMBOL_GPL(dcp_fb_unmirror); + void dcp_retain_framebuffer(struct platform_device *pdev, struct dcp_fb_reference *entry) { @@ -4405,6 +4445,8 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) INIT_LIST_HEAD(&dcp->swapped_out_fbs); mutex_init(&dcp->swapped_out_fbs_lock); + xa_init(&dcp->fb_mirrors); + mutex_init(&dcp->fb_mirror_lock); ret = dcp_backlight_init(dcp, dev); if (ret) return ret; diff --git a/drivers/gpu/drm/apple/dcp.h b/drivers/gpu/drm/apple/dcp.h index 92600177244a2f..284259f2804824 100644 --- a/drivers/gpu/drm/apple/dcp.h +++ b/drivers/gpu/drm/apple/dcp.h @@ -73,6 +73,8 @@ void dcp_retain_framebuffer(struct platform_device *pdev, void dcp_arm_retained_framebuffers(struct apple_dcp *dcp, u32 swap_id); void dcp_unarm_retained_framebuffers(struct apple_dcp *dcp, u32 swap_id); void dcp_fb_mirror(struct apple_dcp *dcp, struct drm_framebuffer *fb); +struct drm_gem_dma_object; +void dcp_fb_unmirror(struct platform_device *pdev, struct drm_gem_dma_object *obj); void dcp_release_retained_framebuffers(struct apple_dcp *dcp, u32 swap_id); void dcp_release_all_retained_framebuffers(struct apple_dcp *dcp); bool dcp_is_initialized(struct platform_device *pdev); From 8d70118cbf6242341ae4c1a079b576a60aaf2efc Mon Sep 17 00:00:00 2001 From: Eric Juta Date: Wed, 11 Nov 2026 17:09:15 +0000 Subject: [PATCH 06/11] soc: apple: t8122 display gate: board default for the dcpext display DART apple,no-shared-display-dart on a dcpext node that has an fbdma child keeps its display DART out of the display subsystem's domain, so a J615 needs no kernel argument. Without the fbdma child the gate warns and shares. apple_t8122_display.dcpext_disp_dart becomes tri-state: unset lets the board decide, =0 and =1 override. Signed-off-by: Eric Juta --- drivers/soc/apple/t6030-display-gate.c | 44 ++++++++++++++++++++------ 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/drivers/soc/apple/t6030-display-gate.c b/drivers/soc/apple/t6030-display-gate.c index e067ae0b06a1bc..d89cf05aae4109 100644 --- a/drivers/soc/apple/t6030-display-gate.c +++ b/drivers/soc/apple/t6030-display-gate.c @@ -1859,15 +1859,22 @@ static int __init gate_t8122_dcpext_setup(char *arg) early_param("apple_t8122_display.dcpext", gate_t8122_dcpext_setup); /* - * Experiment (J615): apple_t8122_display.dcpext_disp_dart=0 enables dcpext - * without appending its display DART to the display subsystem's iommus, to - * tell whether that shared domain is what faults the internal DCP's DART. + * Whether the dcpext's display DART joins the display subsystem's iommus. + * On the J615 that shared domain faults the internal DCP's DART, so its + * dcpext node carries apple,no-shared-display-dart and an fbdma child the + * display driver mirrors framebuffers through instead. The board decides + * unless apple_t8122_display.dcpext_disp_dart=0 or =1 overrides it. */ -static bool gate_t8122_dcpext_disp_dart __initdata = true; +static int gate_t8122_dcpext_disp_dart __initdata = -1; static int __init gate_t8122_dcpext_disp_dart_setup(char *arg) { - return kstrtobool(arg, &gate_t8122_dcpext_disp_dart); + bool share; + int ret = kstrtobool(arg, &share); + + if (!ret) + gate_t8122_dcpext_disp_dart = share; + return ret; } early_param("apple_t8122_display.dcpext_disp_dart", gate_t8122_dcpext_disp_dart_setup); @@ -1919,6 +1926,24 @@ static bool __init gate_node_in(struct device_node *const *nodes, int n, return false; } +/* Does @np's display DART go into the display subsystem's domain? */ +static bool __init gate_t8122_dcpext_shares_dart(struct device_node *np) +{ + struct device_node *fbdma; + + if (gate_t8122_dcpext_disp_dart >= 0) + return gate_t8122_dcpext_disp_dart; + if (!of_property_read_bool(np, "apple,no-shared-display-dart")) + return true; + fbdma = of_get_child_by_name(np, "fbdma"); + of_node_put(fbdma); + if (fbdma) + return false; + gate_warn("%pOF: apple,no-shared-display-dart without an fbdma child; display DART shared\n", + np); + return true; +} + static void __init gate_t8122_dcpext_one(struct device_node *np) { struct device_node *dart = NULL, *mbox = NULL, *piodma = NULL; @@ -1928,6 +1953,7 @@ static void __init gate_t8122_dcpext_one(struct device_node *np) struct of_phandle_args args; struct of_changeset *cs; const char *label; + bool share_dart = gate_t8122_dcpext_shares_dart(np); int ret, i, nxbar = 0; u32 ready; @@ -2041,10 +2067,10 @@ static void __init gate_t8122_dcpext_one(struct device_node *np) ret = of_changeset_update_prop_string(cs, np, "status", "okay"); if (!ret) ret = gate_ext_routes(cs, np, "okay"); - if (!ret && gate_t8122_dcpext_disp_dart) + if (!ret && share_dart) ret = gate_display_add_dart(cs, disp_dart); else if (!ret) - gate_info("%pOF: display DART %pOF not added to the display subsystem (dcpext_disp_dart=0)\n", + gate_info("%pOF: display DART %pOF kept out of the display subsystem; framebuffers are mirrored\n", np, disp_dart); if (!ret) ret = of_changeset_apply(cs); @@ -2054,8 +2080,8 @@ static void __init gate_t8122_dcpext_one(struct device_node *np) gate_ext_refuse(np, "the gate could not enable it"); goto put; } - gate_info("enabled %pOF with its Type-C routes, DARTs, mailbox, %d display crossbar(s) with ATC common power kept on, display DART %pOF in the display subsystem, CPU power floor and PMP DISPEXT request; started by the display driver\n", - np, nxbar, disp_dart); + gate_info("enabled %pOF with its Type-C routes, DARTs, mailbox, %d display crossbar(s) with ATC common power kept on, display DART %pOF %s the display subsystem, CPU power floor and PMP DISPEXT request; started by the display driver\n", + np, nxbar, disp_dart, share_dart ? "in" : "kept out of"); put: for (i = 0; i < GATE_T8122_XBARS; i++) { of_node_put(common[i]); From f4b475ca128231cb630c7decc0f23a15a5890ef1 Mon Sep 17 00:00:00 2001 From: Eric Juta Date: Wed, 11 Nov 2026 17:09:15 +0000 Subject: [PATCH 07/11] arm64: dts: apple: t8122-j615: keep the dcpext display DART unshared by default Signed-off-by: Eric Juta --- arch/arm64/boot/dts/apple/t8122-j615.dts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8122-j615.dts b/arch/arm64/boot/dts/apple/t8122-j615.dts index cf92e7f6349508..4aab4022c44f64 100644 --- a/arch/arm64/boot/dts/apple/t8122-j615.dts +++ b/arch/arm64/boot/dts/apple/t8122-j615.dts @@ -271,8 +271,8 @@ * * fbdma is the display DART stream the dcpext scans framebuffers through, * with the display subsystem's DVA window: on the J615 the gate must not add - * dispext0_dart to the display subsystem (apple_t8122_display.dcpext_disp_dart=0), - * so appledrm mirrors framebuffers there instead. + * dispext0_dart to the display subsystem (apple,no-shared-display-dart), so + * appledrm mirrors framebuffers there instead. */ / { aliases { @@ -290,6 +290,7 @@ apple,typec-dptx-phys = <0 1>; /* RTKit quirks of AsahiLinux/linux#607 (syslog/ioreport acks, kdebug). */ apple,sync-syslog-ack; + apple,no-shared-display-dart; fbdma { iommus = <&dispext0_dart 0>; From cd8b81f144ec1efc66f9a3c9e657512b5b8d2979 Mon Sep 17 00:00:00 2001 From: Eric Juta Date: Mon, 16 Nov 2026 00:10:37 +0000 Subject: [PATCH 08/11] dt-bindings: display: apple,dcp: apple,t8122-dcpext-firmware-ready The boot loader marks a T8122 external coprocessor whose firmware it has reserved. One device tree serves every installed kernel, and kernels that share the display DART unconditionally enable the coprocessor on <1>, which takes the internal panel down on a J615. Document the property and add <2> for the boot loader's default: those kernels refuse it. <1> stays for an owner's explicit boot loader configuration. Signed-off-by: Eric Juta --- .../devicetree/bindings/display/apple,dcp.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Documentation/devicetree/bindings/display/apple,dcp.yaml b/Documentation/devicetree/bindings/display/apple,dcp.yaml index e12645c5b2f8fe..1b0e7f8b36ed6d 100644 --- a/Documentation/devicetree/bindings/display/apple,dcp.yaml +++ b/Documentation/devicetree/bindings/display/apple,dcp.yaml @@ -265,6 +265,16 @@ properties: subsystem's IOMMU domain. Framebuffers are mirrored through the fbdma child instead, which must be present. + apple,t8122-dcpext-firmware-ready: + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [1, 2] + description: + Set by the boot loader on a T8122 external coprocessor whose firmware + it has reserved. 2 is the boot loader's default. 1 is set only when + the owner asked for the coprocessor in the boot loader configuration, + because kernels that share the display DART unconditionally accept 1 + and nothing else. + fbdma: type: object description: From 74387d02f0e598fcaab8a53e1b1fe737f72869a5 Mon Sep 17 00:00:00 2001 From: Eric Juta Date: Mon, 16 Nov 2026 00:10:37 +0000 Subject: [PATCH 09/11] drm: apple: dcp: no fbdma mirror through a disabled fbdma node The display gate disables the fbdma child when it shares the dcpext's display DART with the display subsystem. The shared domain already maps every framebuffer on that DART, and mirroring the same addresses through the fbdma stream as well hits the WARN_ON in dart_init_pte() on every flush. Signed-off-by: Eric Juta --- drivers/gpu/drm/apple/dcp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 7e1e151487061c..1edca110835c9b 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -3113,7 +3113,9 @@ static void dcp_release_piodma_iommu_dev(struct apple_dcp *dcp) * own display DART, not the internal one the display subsystem's domain * covers. An "fbdma" child, on that DART's stream 0 with the display * subsystem's DVA window, gets a domain the framebuffers are mirrored into. - * Without the node nothing changes. + * Without the node nothing changes. The display gate disables the node when + * it shares that DART with the display subsystem instead, whose domain then + * already maps every framebuffer there. */ static void dcp_create_fbdma_dev(struct apple_dcp *dcp) { @@ -3123,7 +3125,7 @@ static void dcp_create_fbdma_dev(struct apple_dcp *dcp) if (!dcp->ext_failsafe || dcp->fbdma) return; - node = of_get_child_by_name(dcp->dev->of_node, "fbdma"); + node = of_get_available_child_by_name(dcp->dev->of_node, "fbdma"); if (!node) return; dcp->fbdma = of_platform_device_create(node, NULL, dcp->dev); From b74aa065c7bafa44710a5462abf6197d5898355b Mon Sep 17 00:00:00 2001 From: Eric Juta Date: Mon, 16 Nov 2026 00:10:37 +0000 Subject: [PATCH 10/11] soc: apple: t8122 display gate: loader-default dcpext marker, share or mirror Accept apple,t8122-dcpext-firmware-ready = <2>, the boot loader's default, beside <1>, the owner's explicit request. Older gates enable the dcpext only on <1> and always share its display DART, so a default of <2> keeps them from taking a J615 panel down when they boot from the same device tree. A node with apple,no-shared-display-dart and no fbdma child is now refused instead of shared with a warning: the board says sharing is unsafe, and without fbdma nothing can reach the external pipe. When the DART is shared, by the board or by apple_t8122_display.dcpext_disp_dart=1, the gate disables the fbdma child, so framebuffers are never mapped on that DART twice. The T8122 KUnit tree gains a J615-like dcpext, and cases for both marker values, a wrong and a missing marker, the board default with and without fbdma, a board that shares, and dcpext_disp_dart=0 and =1. Signed-off-by: Eric Juta --- drivers/soc/apple/t6030-display-gate-test.c | 128 +++++++++++++++++++- drivers/soc/apple/t6030-display-gate.c | 65 ++++++---- drivers/soc/apple/t8122-gate-test.dtso | 74 ++++++++++- 3 files changed, 243 insertions(+), 24 deletions(-) diff --git a/drivers/soc/apple/t6030-display-gate-test.c b/drivers/soc/apple/t6030-display-gate-test.c index fc68bb6208a6e0..6a5cf7f9891c58 100644 --- a/drivers/soc/apple/t6030-display-gate-test.c +++ b/drivers/soc/apple/t6030-display-gate-test.c @@ -14,7 +14,9 @@ * changed when a check fails. * - T8122 (t8122-gate-test.dtso): on by default, with the full handoff, * and nothing changed when a check of the handoff or of the reused PMP - * topology fails. + * topology fails. Its external display processor is enabled with either + * firmware marker value, and its display DART is shared with the display + * subsystem or left to the fbdma child, never both. * Included at the end of t6030-display-gate.c. * * The test trees are applied once and stay: the gate gives some properties @@ -142,6 +144,7 @@ static int gt_fixture_t8122 __initdata = -1; static int gt_live_soc __initdata = -1; struct gate_test { + int dcpext_disp_dart; /* apple_t8122_display.dcpext_disp_dart, as booted */ const struct gt_soc *s; struct of_changeset cs; /* this case's own edits to the test tree */ bool requested, t6031_requested; @@ -403,6 +406,9 @@ static int __init gt_init(struct kunit *test, const struct gt_soc *s) return -ENOMEM; test->priv = t; t->s = s; + t->dcpext_disp_dart = gate_t8122_dcpext_disp_dart; + gate_t8122_dcpext_disp_dart = -1; + gate_t8122_dcpext_cs = NULL; /* As the boot left them: the test kernel's command line sets neither. */ t->requested = gate_requested; t->t6031_requested = gate_t6031_requested; @@ -440,6 +446,13 @@ static void __init gt_exit(struct kunit *test) { struct gate_test *t = test->priv; + /* The external display processor was enabled last. */ + if (gate_t8122_dcpext_cs) { + of_changeset_revert(gate_t8122_dcpext_cs); + gate_cs_free(gate_t8122_dcpext_cs); + gate_t8122_dcpext_cs = NULL; + } + gate_t8122_dcpext_disp_dart = t->dcpext_disp_dart; /* The gate leaves its changes applied only when it enabled the display. */ if (gate_pmp_ovcs) { of_changeset_revert(&gate_pmp_cs); @@ -902,6 +915,110 @@ static void __init gate_t8122_enabled_again(struct kunit *test) gt_expect_enabled(test); } +/* T8122 external display processor (dcpext) */ + +#define GT_DCPEXT "/t8122-soc/dcp@31ac00000" +#define GT_DCPEXT_MARKER "apple,t8122-dcpext-firmware-ready" + +/* Is the dcpext's display DART among the display subsystem's iommus? */ +static bool __init gt_dcpext_dart_shared(struct kunit *test) +{ + return of_count_phandle_with_args(gt_node(test, gt_t8122.display), "iommus", + "#iommu-cells") == 2; +} + +/* The dcpext is on, with exactly one way for framebuffers to reach its DART. */ +static void __init gt_expect_dcpext(struct kunit *test, bool shared) +{ + gt_expect_enabled(test); + KUNIT_EXPECT_TRUE(test, gt_okay(test, GT_DCPEXT)); + KUNIT_EXPECT_TRUE(test, gt_okay(test, "/t8122-soc/iommu@319304000")); + KUNIT_EXPECT_EQ(test, gt_dcpext_dart_shared(test), shared); + KUNIT_EXPECT_EQ(test, gt_okay(test, GT_DCPEXT "/fbdma"), !shared); +} + +/* The panel is on and nothing of the dcpext is. */ +static void __init gt_expect_dcpext_off(struct kunit *test) +{ + gt_expect_enabled(test); + KUNIT_EXPECT_FALSE(test, gt_okay(test, GT_DCPEXT)); + KUNIT_EXPECT_FALSE(test, gt_okay(test, "/t8122-soc/iommu@319304000")); + KUNIT_EXPECT_FALSE(test, gt_okay(test, "/t8122-soc/iommu@31930c000")); + KUNIT_EXPECT_FALSE(test, gt_okay(test, "/t8122-soc/mailbox@31ac08000")); + KUNIT_EXPECT_FALSE(test, gt_dcpext_dart_shared(test)); +} + +/* The boot loader's default marker, a board that mirrors: DART not shared. */ +static void __init gate_t8122_dcpext_board_mirrors(struct kunit *test) +{ + gt_run(test); + gt_expect_dcpext(test, false); +} + +/* The owner's explicit marker is accepted as before. */ +static void __init gate_t8122_dcpext_owner_marker(struct kunit *test) +{ + gt_set_u32(test, GT_DCPEXT, GT_DCPEXT_MARKER, 1); + gt_run(test); + gt_expect_dcpext(test, false); +} + +static void __init gate_t8122_dcpext_other_marker(struct kunit *test) +{ + gt_set_u32(test, GT_DCPEXT, GT_DCPEXT_MARKER, 3); + gt_run(test); + gt_expect_dcpext_off(test); +} + +static void __init gate_t8122_dcpext_no_marker(struct kunit *test) +{ + gt_remove(test, GT_DCPEXT, GT_DCPEXT_MARKER); + gt_run(test); + gt_expect_dcpext_off(test); +} + +/* A board that must not share and has nothing to mirror through: refused. */ +static void __init gate_t8122_dcpext_board_no_fbdma(struct kunit *test) +{ + gt_detach(test, GT_DCPEXT "/fbdma"); + gt_run(test); + gt_expect_dcpext_off(test); +} + +/* A board without the property shares, as on a J613, and fbdma goes off. */ +static void __init gate_t8122_dcpext_board_shares(struct kunit *test) +{ + gt_remove(test, GT_DCPEXT, "apple,no-shared-display-dart"); + gt_run(test); + gt_expect_dcpext(test, true); +} + +/* =0 keeps the DART out on a board that would share. */ +static void __init gate_t8122_dcpext_forced_unshared(struct kunit *test) +{ + gt_remove(test, GT_DCPEXT, "apple,no-shared-display-dart"); + KUNIT_ASSERT_EQ(test, gate_t8122_dcpext_disp_dart_setup("0"), 0); + gt_run(test); + gt_expect_dcpext(test, false); +} + +/* =1 shares on a board that mirrors, and takes its fbdma child away. */ +static void __init gate_t8122_dcpext_forced_shared(struct kunit *test) +{ + KUNIT_ASSERT_EQ(test, gate_t8122_dcpext_disp_dart_setup("1"), 0); + gt_run(test); + gt_expect_dcpext(test, true); +} + +/* Without the panel there is no dcpext either. */ +static void __init gate_t8122_dcpext_no_panel(struct kunit *test) +{ + gt_remove(test, gt_t8122.display, "apple,t8122-handoff"); + gt_run(test); + gt_expect_untouched(test); + KUNIT_EXPECT_FALSE(test, gt_okay(test, GT_DCPEXT)); +} + /* The case and suite structs outlive init: only the functions are init code. */ static struct kunit_case gate_t6031_cases[] __refdata = { KUNIT_CASE(gate_t6031_param), @@ -975,6 +1092,15 @@ static struct kunit_case gate_t8122_cases[] __refdata = { KUNIT_CASE(gate_t8122_disp_no_ack), KUNIT_CASE(gate_t8122_no_storage_request), KUNIT_CASE(gate_t8122_not_inherited_on), + KUNIT_CASE(gate_t8122_dcpext_board_mirrors), + KUNIT_CASE(gate_t8122_dcpext_owner_marker), + KUNIT_CASE(gate_t8122_dcpext_other_marker), + KUNIT_CASE(gate_t8122_dcpext_no_marker), + KUNIT_CASE(gate_t8122_dcpext_board_no_fbdma), + KUNIT_CASE(gate_t8122_dcpext_board_shares), + KUNIT_CASE(gate_t8122_dcpext_forced_unshared), + KUNIT_CASE(gate_t8122_dcpext_forced_shared), + KUNIT_CASE(gate_t8122_dcpext_no_panel), KUNIT_CASE(gate_t8122_enabled_again), {} }; diff --git a/drivers/soc/apple/t6030-display-gate.c b/drivers/soc/apple/t6030-display-gate.c index d89cf05aae4109..ed2bea6c2f1e11 100644 --- a/drivers/soc/apple/t6030-display-gate.c +++ b/drivers/soc/apple/t6030-display-gate.c @@ -1820,8 +1820,12 @@ static void __init gate_describe(void) * boot loader does not hand it over: the display driver starts its firmware * itself, as on M1/M2 (DCP_FIRMWARE_V_14_7_TEMPLATE). The boot loader only * reserves that firmware (memory-region and iommu-addresses), sets its - * firmware version and marks the node apple,t8122-dcpext-firmware-ready = - * <1>. The node stays disabled in the device tree, so a kernel that cannot + * firmware version and marks the node apple,t8122-dcpext-firmware-ready: + * <2> when it does so by default, <1> when the owner asked for it in the + * boot loader's configuration. Kernels whose gate always shares the display + * DART accept only <1>, so a default of <2> leaves the dcpext off on those + * when one device tree serves several installed kernels. This gate accepts + * both. The node stays disabled in the device tree, so a kernel that cannot * drive it never sees it, and neither does a USB-C port controller waiting * for its Type-C display route. So do its DARTs, its mailbox and the display * crossbars of its routes, and the ATC power states are left as they are: @@ -1837,7 +1841,8 @@ static void __init gate_describe(void) * the M1/M2 laptops have for DP alt mode across suspend; * - <&dispextN_dart 0> in the display subsystem's iommus, so that every * framebuffer is mapped for the external pipe too, as on M1/M2 (the - * display DART is the one the dcpext's piodma child names); + * display DART is the one the dcpext's piodma child names), unless the + * board mirrors framebuffers instead (see gate_t8122_dcpext_shares_dart()); * - an active floor on the dcpext's CPU power state, as on T6030, so that * the running PMP cannot power the processor down under its firmware; * - its DISPEXT request, the report entry the dcpext names in @@ -1863,7 +1868,9 @@ early_param("apple_t8122_display.dcpext", gate_t8122_dcpext_setup); * On the J615 that shared domain faults the internal DCP's DART, so its * dcpext node carries apple,no-shared-display-dart and an fbdma child the * display driver mirrors framebuffers through instead. The board decides - * unless apple_t8122_display.dcpext_disp_dart=0 or =1 overrides it. + * unless apple_t8122_display.dcpext_disp_dart=0 or =1 overrides it. The + * fbdma stream is on the same DART at the same addresses, so the two never + * go together: when the DART is shared, the gate disables the fbdma child. */ static int gate_t8122_dcpext_disp_dart __initdata = -1; @@ -1926,35 +1933,35 @@ static bool __init gate_node_in(struct device_node *const *nodes, int n, return false; } -/* Does @np's display DART go into the display subsystem's domain? */ -static bool __init gate_t8122_dcpext_shares_dart(struct device_node *np) +/* + * Does @np's display DART go into the display subsystem's domain? 1 or 0, + * or -ENODEV on a board that forbids it and has no @fbdma child to mirror + * framebuffers through: the dcpext then has no way to scan them out. + */ +static int __init gate_t8122_dcpext_shares_dart(struct device_node *np, + struct device_node *fbdma) { - struct device_node *fbdma; - if (gate_t8122_dcpext_disp_dart >= 0) return gate_t8122_dcpext_disp_dart; if (!of_property_read_bool(np, "apple,no-shared-display-dart")) - return true; - fbdma = of_get_child_by_name(np, "fbdma"); - of_node_put(fbdma); - if (fbdma) - return false; - gate_warn("%pOF: apple,no-shared-display-dart without an fbdma child; display DART shared\n", - np); - return true; + return 1; + return fbdma ? 0 : -ENODEV; } +/* The last dcpext changeset applied, for the KUnit test to revert. */ +static struct of_changeset *gate_t8122_dcpext_cs __initdata; + static void __init gate_t8122_dcpext_one(struct device_node *np) { struct device_node *dart = NULL, *mbox = NULL, *piodma = NULL; struct device_node *disp_dart = NULL, *ps = NULL, *entry = NULL, *link; + struct device_node *fbdma = NULL; struct device_node *xbar[GATE_T8122_XBARS] = {}; struct device_node *common[GATE_T8122_XBARS] = {}; struct of_phandle_args args; struct of_changeset *cs; const char *label; - bool share_dart = gate_t8122_dcpext_shares_dart(np); - int ret, i, nxbar = 0; + int share_dart, ret, i, nxbar = 0; u32 ready; if (!gate_disabled(np)) { @@ -1962,7 +1969,7 @@ static void __init gate_t8122_dcpext_one(struct device_node *np) return; } if (of_property_read_u32(np, "apple,t8122-dcpext-firmware-ready", &ready) || - ready != 1) { + (ready != 1 && ready != 2)) { gate_ext_refuse(np, "the boot loader did not reserve its firmware"); return; } @@ -1974,6 +1981,13 @@ static void __init gate_t8122_dcpext_one(struct device_node *np) gate_ext_refuse(np, "it has no firmware memory"); goto put; } + fbdma = of_get_available_child_by_name(np, "fbdma"); + share_dart = gate_t8122_dcpext_shares_dart(np, fbdma); + if (share_dart < 0) { + gate_ext_refuse(np, + "apple,no-shared-display-dart without an fbdma child to mirror framebuffers through"); + goto put; + } dart = gate_target(np, "iommus", "#iommu-cells", 1, 5, "apple,t8110-dart"); mbox = gate_target(np, "mboxes", "#mbox-cells", 0, 0, "apple,asc-mailbox-v4"); piodma = of_get_child_by_name(np, "piodma"); @@ -2067,11 +2081,18 @@ static void __init gate_t8122_dcpext_one(struct device_node *np) ret = of_changeset_update_prop_string(cs, np, "status", "okay"); if (!ret) ret = gate_ext_routes(cs, np, "okay"); - if (!ret && share_dart) + if (!ret && share_dart) { ret = gate_display_add_dart(cs, disp_dart); - else if (!ret) + /* The shared domain maps what fbdma would, at the same addresses. */ + if (!ret && fbdma) { + ret = of_changeset_update_prop_string(cs, fbdma, "status", "disabled"); + gate_warn("%pOF: display DART %pOF shared with the display subsystem; %pOF disabled\n", + np, disp_dart, fbdma); + } + } else if (!ret) { gate_info("%pOF: display DART %pOF kept out of the display subsystem; framebuffers are mirrored\n", np, disp_dart); + } if (!ret) ret = of_changeset_apply(cs); if (ret) { @@ -2080,6 +2101,7 @@ static void __init gate_t8122_dcpext_one(struct device_node *np) gate_ext_refuse(np, "the gate could not enable it"); goto put; } + gate_t8122_dcpext_cs = cs; gate_info("enabled %pOF with its Type-C routes, DARTs, mailbox, %d display crossbar(s) with ATC common power kept on, display DART %pOF %s the display subsystem, CPU power floor and PMP DISPEXT request; started by the display driver\n", np, nxbar, disp_dart, share_dart ? "in" : "kept out of"); put: @@ -2087,6 +2109,7 @@ static void __init gate_t8122_dcpext_one(struct device_node *np) of_node_put(common[i]); of_node_put(xbar[i]); } + of_node_put(fbdma); of_node_put(entry); of_node_put(ps); of_node_put(disp_dart); diff --git a/drivers/soc/apple/t8122-gate-test.dtso b/drivers/soc/apple/t8122-gate-test.dtso index beee48ab0afd9d..01a0ab9d0fb9df 100644 --- a/drivers/soc/apple/t8122-gate-test.dtso +++ b/drivers/soc/apple/t8122-gate-test.dtso @@ -4,7 +4,9 @@ * nodes of t8122-dcp.dtsi with the boot loader's handoff applied, the power * states they hang from, the PMP topology of t8122.dtsi that the gate * reuses, and PMP values. The values are made up: only their presence and - * the PMP image UUID matter to the gate. + * the PMP image UUID matter to the gate. The external display processor is + * a J615's: firmware reserved by default, its display DART kept out of the + * display subsystem and an fbdma child. It has no Type-C routes. * * The nodes live under their own disabled bus, not /soc, so that they do * not collide with the T6030 test tree (both SoCs put the DCP at @@ -79,6 +81,13 @@ apple,always-on; }; + t8122_ps_dispext_cpu: power-controller@10008 { + compatible = "apple,t8122-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x10008 4>; + #power-domain-cells = <0>; + label = "dispext_cpu"; + }; + t8122_ps_disp_cpu: power-controller@10000 { compatible = "apple,t8122-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; reg = <0x10000 4>; @@ -117,7 +126,7 @@ apple,always-on; }; - report@8 { + t8122_report_dispext: report@8 { compatible = "apple,t8122-pmp-v2-report-entry", "apple,t6000-pmp-v2-report-entry"; reg = <0x8>; @@ -209,6 +218,67 @@ }; }; + t8122_dcpext_mbox: mailbox@31ac08000 { + compatible = "apple,t8122-asc-mailbox", "apple,asc-mailbox-v4"; + reg = <0x3 0x1ac08000 0x0 0x4000>; + interrupt-parent = <&t8122_aic>; + interrupts = <0 582 4>, <0 583 4>, <0 584 4>, <0 585 4>; + interrupt-names = "send-empty", "send-not-empty", + "recv-empty", "recv-not-empty"; + power-domains = <&t8122_ps_dispext_cpu>; + #mbox-cells = <0>; + status = "disabled"; + }; + + t8122_dcpext_dart: iommu@31930c000 { + compatible = "apple,t8122-dart", "apple,t8110-dart"; + reg = <0x3 0x1930c000 0x0 0x4000>; + interrupt-parent = <&t8122_aic>; + interrupts = <0 599 4>; + #iommu-cells = <1>; + power-domains = <&t8122_ps_dispext_cpu>; + status = "disabled"; + }; + + t8122_dispext0_dart: iommu@319304000 { + compatible = "apple,t8122-dart", "apple,t8110-dart"; + reg = <0x3 0x19304000 0x0 0x4000>; + interrupt-parent = <&t8122_aic>; + interrupts = <0 599 4>; + #iommu-cells = <1>; + power-domains = <&t8122_ps_dispext_cpu>; + status = "disabled"; + }; + + t8122_dcpext_fw: dcpext-firmware@1000000000 { + reg = <0x10 0x0 0x0 0x4000>; + }; + + dcp@31ac00000 { + compatible = "apple,t8122-dcpext"; + mboxes = <&t8122_dcpext_mbox>; + mbox-names = "mbox"; + iommus = <&t8122_dcpext_dart 5>; + reg-names = "coproc"; + reg = <0x3 0x1ac00000 0x0 0x4000>; + power-domains = <&t8122_ps_dispext_cpu>; + memory-region = <&t8122_dcpext_fw>; + apple,pmp-report = <&t8122_report_dispext>; + status = "disabled"; + apple,t8122-dcpext-firmware-ready = <2>; + apple,firmware-compat = <14 7 0>; + apple,no-shared-display-dart; + + piodma { + iommus = <&t8122_dispext0_dart 4>; + }; + + fbdma { + iommus = <&t8122_dispext0_dart 0>; + apple,dma-range = /bits/ 64 <0x10000000000 0x1000000000>; + }; + }; + display-subsystem { compatible = "apple,t8122-display-subsystem"; iommus = <&t8122_disp0_dart 0>; From b4cc668a6802a6811c1d99fabaf131d8abc522be Mon Sep 17 00:00:00 2001 From: Eric Juta Date: Mon, 16 Nov 2026 00:10:38 +0000 Subject: [PATCH 11/11] drm: apple: dcp: mirror framebuffers from the display domain's translations dcp_fb_mirror() mapped an imported buffer from its exporter's sg_table with sg_phys(), which an importer must not do and CONFIG_DMABUF_DEBUG would catch, and built a new sg_table for every native buffer. Every framebuffer already has a display DVA, so read the pages behind it with iommu_iova_to_phys() on the display subsystem's domain and map them into the fbdma domain at the same addresses, for native and imported buffers alike. Signed-off-by: Eric Juta --- drivers/gpu/drm/apple/dcp.c | 76 +++++++++++++++++++++++++++---------- 1 file changed, 55 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 1edca110835c9b..1ce6408befaafe 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -3150,6 +3150,48 @@ static void dcp_create_fbdma_dev(struct apple_dcp *dcp) of_node_put(node); } +/* + * Map the pages behind [@iova, @iova + @size) of @src into the fbdma domain + * at the same addresses, read-only. The pages are taken from @src's own + * translations, so this needs no scatterlist: an imported buffer's belongs + * to its exporter. Each step looks up one of @src's smallest pages, so a hole + * cannot hide inside a step; that needs both domains to share that page size. + * Returns 0, or a negative errno with nothing left mapped. + */ +static int dcp_fb_mirror_range(struct apple_dcp *dcp, struct iommu_domain *src, + dma_addr_t iova, size_t size) +{ + unsigned long pgsize = 1UL << __ffs(src->pgsize_bitmap); + phys_addr_t phys, run_phys = 0; + size_t off, run_len = 0, mapped = 0; + int ret = 0; + + if (pgsize != 1UL << __ffs(dcp->fb_dom->pgsize_bitmap) || + !IS_ALIGNED(iova | size, pgsize)) + return -EINVAL; + for (off = 0; off <= size && !ret; off += pgsize) { + phys = off < size ? iommu_iova_to_phys(src, iova + off) : 0; + if (run_len && phys && phys == run_phys + run_len) { + run_len += pgsize; + continue; + } + /* The run of physically contiguous pages ends here. */ + if (run_len) { + ret = iommu_map(dcp->fb_dom, iova + mapped, run_phys, run_len, + IOMMU_READ, GFP_KERNEL); + if (!ret) + mapped += run_len; + } + if (!ret && off < size && !phys) + ret = -EFAULT; + run_phys = phys; + run_len = pgsize; + } + if (ret && mapped) + iommu_unmap(dcp->fb_dom, iova, mapped); + return ret; +} + /* * Map @fb's GEM objects into the fbdma domain at their display DVAs. A * mapping lasts as long as its object and its DVA do: dcp_fb_unmirror() @@ -3157,42 +3199,34 @@ static void dcp_create_fbdma_dev(struct apple_dcp *dcp) */ void dcp_fb_mirror(struct apple_dcp *dcp, struct drm_framebuffer *fb) { + struct iommu_domain *src; unsigned int i; if (!fb || !READ_ONCE(dcp->fb_dom)) return; + src = iommu_get_domain_for_dev(drm_dev_dma_dev(fb->dev)); guard(mutex)(&dcp->fb_mirror_lock); - if (!dcp->fb_dom) + if (!dcp->fb_dom || IS_ERR_OR_NULL(src)) return; for (i = 0; i < fb->format->num_planes; i++) { struct drm_gem_dma_object *obj = drm_fb_dma_get_gem_obj(fb, i); unsigned long index = (unsigned long)obj; - struct sg_table *sgt; - ssize_t mapped; + int ret; if (!obj || xa_load(&dcp->fb_mirrors, index)) continue; - /* Imported (GPU) buffers carry their pages in obj->sgt. */ - sgt = obj->sgt ? obj->sgt : drm_gem_dma_get_sg_table(obj); - if (IS_ERR_OR_NULL(sgt)) - continue; - mapped = iommu_map_sgtable(dcp->fb_dom, obj->dma_addr, sgt, - IOMMU_READ); - if (mapped > 0 && - xa_err(xa_store(&dcp->fb_mirrors, index, xa_mk_value(mapped), - GFP_KERNEL))) { - iommu_unmap(dcp->fb_dom, obj->dma_addr, mapped); - mapped = -ENOMEM; + ret = dcp_fb_mirror_range(dcp, src, obj->dma_addr, obj->base.size); + if (!ret) { + ret = xa_err(xa_store(&dcp->fb_mirrors, index, + xa_mk_value(obj->base.size), GFP_KERNEL)); + if (ret) + iommu_unmap(dcp->fb_dom, obj->dma_addr, obj->base.size); } - if (mapped <= 0) + if (ret) dev_warn_ratelimited(dcp->dev, - "fbdma: %pad (%zu bytes, %s) not mirrored: %zd\n", + "fbdma: %pad (%zu bytes, %s) not mirrored: %d\n", &obj->dma_addr, obj->base.size, - obj->sgt ? "imported" : "native", mapped); - if (sgt != obj->sgt) { - sg_free_table(sgt); - kfree(sgt); - } + obj->sgt ? "imported" : "native", ret); } }