diff --git a/Documentation/devicetree/bindings/display/apple,dcp.yaml b/Documentation/devicetree/bindings/display/apple,dcp.yaml index ec3251e7c4fcaa..1b0e7f8b36ed6d 100644 --- a/Documentation/devicetree/bindings/display/apple,dcp.yaml +++ b/Documentation/devicetree/bindings/display/apple,dcp.yaml @@ -258,6 +258,42 @@ 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. + + 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: + 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: diff --git a/arch/arm64/boot/dts/apple/t8122-j615.dts b/arch/arm64/boot/dts/apple/t8122-j615.dts index 5e52cd3046e713..4aab4022c44f64 100644 --- a/arch/arm64/boot/dts/apple/t8122-j615.dts +++ b/arch/arm64/boot/dts/apple/t8122-j615.dts @@ -262,3 +262,91 @@ }; #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,no-shared-display-dart), 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; + apple,no-shared-display-dart; + + 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>; + }; + }; + }; +}; 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 3eac22a57aa069..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 @@ -231,6 +232,18 @@ struct apple_dcp { struct platform_device *piodma; bool piodma_created; struct iommu_domain *iommu_dom; + /* + * 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 8cb040d16d552c..1ce6408befaafe 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 @@ -3067,12 +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; if (dcp->piodma) { if (dcp->piodma_created) of_platform_device_destroy(&dcp->piodma->dev, NULL); @@ -3084,6 +3108,143 @@ static void dcp_release_piodma_iommu_dev(struct apple_dcp *dcp) dcp->piodma_created = false; } +/* + * 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. 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) +{ + struct device_node *node; + struct iommu_domain *dom; + int ret; + + if (!dcp->ext_failsafe || dcp->fbdma) + return; + 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); + 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; + } + 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 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() + * removes it when the object is freed. + */ +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 || 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; + int ret; + + if (!obj || xa_load(&dcp->fb_mirrors, index)) + continue; + 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 (ret) + dev_warn_ratelimited(dcp->dev, + "fbdma: %pad (%zu bytes, %s) not mirrored: %d\n", + &obj->dma_addr, obj->base.size, + obj->sgt ? "imported" : "native", ret); + } +} + +/* @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) { @@ -3918,6 +4079,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"); @@ -4318,6 +4481,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 baff04ee201e72..284259f2804824 100644 --- a/drivers/gpu/drm/apple/dcp.h +++ b/drivers/gpu/drm/apple/dcp.h @@ -72,6 +72,9 @@ 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); +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); 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) 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 07ba8b9f60f571..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 @@ -1858,6 +1863,28 @@ static int __init gate_t8122_dcpext_setup(char *arg) } early_param("apple_t8122_display.dcpext", gate_t8122_dcpext_setup); +/* + * 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. 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; + +static int __init gate_t8122_dcpext_disp_dart_setup(char *arg) +{ + 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); + /* The most display crossbars a T8122 dcpext's routes switch: ATC0's and ATC1's. */ #define GATE_T8122_XBARS 2 @@ -1906,16 +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? 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) +{ + 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 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; - int ret, i, nxbar = 0; + int share_dart, ret, i, nxbar = 0; u32 ready; if (!gate_disabled(np)) { @@ -1923,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; } @@ -1935,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"); @@ -2028,8 +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) + if (!ret && share_dart) { ret = gate_display_add_dart(cs, disp_dart); + /* 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) { @@ -2038,13 +2101,15 @@ 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_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: for (i = 0; i < GATE_T8122_XBARS; i++) { 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>;