diff --git a/Documentation/devicetree/bindings/display/apple,dcp.yaml b/Documentation/devicetree/bindings/display/apple,dcp.yaml index 13cf27fb69f44..bdf23cf5272ae 100644 --- a/Documentation/devicetree/bindings/display/apple,dcp.yaml +++ b/Documentation/devicetree/bindings/display/apple,dcp.yaml @@ -127,6 +127,9 @@ properties: memory-region: minItems: 1 maxItems: 64 + description: + Boot framebuffer and reserved mappings. A T6050 external processor + without a boot framebuffer may omit these regions and their names. memory-region-names: minItems: 1 @@ -314,17 +317,18 @@ properties: mux-controls: $ref: /schemas/types.yaml#/definitions/phandle-array minItems: 1 - maxItems: 10 + maxItems: 21 description: | T6030 and T8132 external DCPs may also name the two DP IN tunnel states of each Type-C crossbar, in addition to the fixed output and Type-C - routes. + routes. T6050 has four DP IN states per crossbar and up to four + Type-C routes, plus a fixed output. mux-control-names: minItems: 1 - maxItems: 10 + maxItems: 21 items: - pattern: '^(dp-xbar|typec[0-9]+(-dpin[01])?)$' + pattern: '^(dp-xbar|typec[0-9]+(-dpin[0-3])?)$' mux-index: $ref: /schemas/types.yaml#/definitions/uint32 @@ -430,7 +434,24 @@ allOf: properties: compatible: contains: - enum: ['apple,t6030-dcpext', 'apple,t8132-dcpext'] + enum: ['apple,t6050-dcp', 'apple,t6050-dcpext'] + required: + - compatible + then: + properties: + mux-controls: + maxItems: 10 + mux-control-names: + maxItems: 10 + items: + pattern: '^(dp-xbar|typec[0-9]+(-dpin[01])?)$' + - if: + not: + properties: + compatible: + contains: + enum: ['apple,t6030-dcpext', 'apple,t8132-dcpext', + 'apple,t6050-dcp', 'apple,t6050-dcpext'] required: - compatible then: @@ -465,9 +486,20 @@ allOf: then: required: - apple,clock-ids - - memory-region - - memory-region-names - apple,firmware-compat + dependencies: + memory-region: [memory-region-names] + memory-region-names: [memory-region] + allOf: + - if: + properties: + compatible: + contains: + const: apple,t6050-dcp + then: + required: + - memory-region + - memory-region-names properties: apple,firmware-compat: items: diff --git a/drivers/gpu/drm/apple/apple_drv.c b/drivers/gpu/drm/apple/apple_drv.c index 44506be09989a..2465674132283 100644 --- a/drivers/gpu/drm/apple/apple_drv.c +++ b/drivers/gpu/drm/apple/apple_drv.c @@ -1002,23 +1002,27 @@ static int apple_probe_per_dcp(struct device *dev, * Create a connector per physical Type-C port and attach it to every * pipeline that can drive it. The M2 Pro/Max laptops append a second * connector per port for a dock's second DP tunnel, preserving primary - * connector names. + * connector names. T6050 instead exposes one connector per port/pipeline + * pair: tunnel allocation chooses which connector is connected, without + * changing any encoder's advertised CRTC mask after registration. */ static int apple_probe_typec_ports(struct drm_device *drm, struct platform_device **dcp, u32 *crtc_mask, int num_dcp) { unsigned int idx, nr_ports = dcp_typec_nr_ports(); + bool fixed = dcp_typec_fixed_crtcs(); + unsigned int slots = fixed ? num_dcp : (dcp_typec_dual_stream() ? 2 : 1); int i, ret; /* Keep the existing physical-port connector numbers stable. On the * M2 Pro/Max laptops, append one more connector per port for a second * USB4 DP tunnel. */ - for (idx = 0; idx < nr_ports * (dcp_typec_dual_stream() ? 2 : 1); - idx++) { + for (idx = 0; idx < nr_ports * slots; idx++) { struct apple_connector *connector; struct apple_encoder *enc; + struct platform_device *pipeline = fixed ? dcp[idx / nr_ports] : NULL; unsigned int port_idx = idx % nr_ports; bool secondary = idx >= nr_ports; u32 mask = 0; @@ -1030,6 +1034,29 @@ static int apple_probe_typec_ports(struct drm_device *drm, continue; } + if (fixed) { + if (!dcp_typec_port_has_candidate(port_idx, pipeline)) + continue; + mask = crtc_mask[idx / nr_ports]; + if (!mask) + continue; + } else { + for (i = 0; i < num_dcp; i++) { + if (!dcp_typec_port_has_candidate(port_idx, dcp[i])) + continue; + /* Ordered dual-stream docks reserve the Type-C-only pipe. */ + mask = dcp_fabric_port_crtc_mask(secondary, + dcp_typec_ordered_dual_stream(), + dcp_is_typec_only(dcp[i]), + mask, crtc_mask[i]); + } + if (!mask) { + drm_warn(drm, "Type-C port %u has no display pipeline\n", + port_idx); + return -ENODEV; + } + } + connector = kzalloc_obj(*connector); if (!connector) return -ENOMEM; @@ -1061,32 +1088,10 @@ static int apple_probe_typec_ports(struct drm_device *drm, connector->connected = false; connector->dcp = NULL; - for (i = 0; i < num_dcp; i++) { - if (!dcp_typec_port_has_candidate(port_idx, dcp[i])) - continue; - /* - * A dock's second stream (DPIN1) always runs on the - * lowest-indexed Type-C-only pipeline (dcpext1). Fix the - * connector to it: compositors read possible_crtcs once - * and would otherwise pair it with a pipeline the stream - * can never be routed to. T6030 instead narrows both - * connectors to the native processor holding their route. - */ - mask = dcp_fabric_port_crtc_mask(secondary, - dcp_typec_ordered_dual_stream(), - dcp_is_typec_only(dcp[i]), - mask, crtc_mask[i]); - } - - if (!mask) { - drm_warn(drm, "Type-C port %u has no display pipeline\n", - port_idx); - return -ENODEV; - } - /* - * One encoder for the port, spanning every pipeline that can - * drive it. Attaching one encoder per pipeline would describe + * One encoder per connector, covering its allowed pipelines. + * T6050 connectors each cover exactly one. Attaching several + * encoders to the same connector would describe * the same hardware, but userspace takes the CRTCs a connector * can use to be what all of its encoders have in common, and * single-pipeline encoders have nothing in common -- the port @@ -1104,7 +1109,7 @@ static int apple_probe_typec_ports(struct drm_device *drm, connector->port_encoder = &enc->base; connector->candidate_crtcs = mask; - dcp_typec_port_set_connector(port_idx, secondary, connector); + dcp_typec_port_set_connector(port_idx, secondary, connector, pipeline); } return 0; diff --git a/drivers/gpu/drm/apple/connector.h b/drivers/gpu/drm/apple/connector.h index 6e7ec1badc321..b68ef2c8dcdb7 100644 --- a/drivers/gpu/drm/apple/connector.h +++ b/drivers/gpu/drm/apple/connector.h @@ -39,8 +39,9 @@ struct apple_connector { struct platform_device *dcp; /* - * A Type-C connector is a physical port rather than a fixed pipeline, - * and it has one encoder covering every pipeline that can drive it. + * A Type-C connector has one encoder covering its allowed pipelines. + * T6050 has a connector per port/pipeline pair with a single CRTC; + * other platforms have a connector per port or USB4 stream. * One encoder per pipeline would describe the same hardware, but * userspace takes the CRTCs a connector can use to be what all of its * encoders have in common, and single-pipeline encoders have nothing diff --git a/drivers/gpu/drm/apple/dcp-fabric-core.c b/drivers/gpu/drm/apple/dcp-fabric-core.c index f703ea061fb50..6a7fab89c1908 100644 --- a/drivers/gpu/drm/apple/dcp-fabric-core.c +++ b/drivers/gpu/drm/apple/dcp-fabric-core.c @@ -41,7 +41,7 @@ int dcp_fabric_tunnel_request(const struct dcp_fabric_port *ports, const struct dcp_fabric_port *port; *found = NULL; - if (!key || dpin > 1) + if (!key || dpin >= DCP_FABRIC_DPIN_MAX) return -EINVAL; for (port = ports; port; port = port->next) { if (port->key != key) @@ -292,7 +292,7 @@ EXPORT_SYMBOL_GPL(dcp_fabric_plan); int dcp_fabric_tunnel_slot(const struct dcp_fabric_port *port, unsigned int dpin) { - const struct dcp_fabric_route *slot = port->owner[dpin]; + const struct dcp_fabric_route *slot = port->owner[dcp_fabric_dpin_slot(dpin)]; if (slot) return slot->tunnel && slot->dpin == dpin ? 1 : -EADDRINUSE; @@ -313,7 +313,7 @@ dcp_fabric_tunnel_candidate(const struct dcp_fabric_port *port, unsigned int best_score = UINT_MAX; bool waiting = false, clock_blocked = false, clock_capable = false; - if (dpin > 1) { + if (dpin >= DCP_FABRIC_DPIN_MAX) { *error = -EINVAL; return NULL; } @@ -331,7 +331,7 @@ dcp_fabric_tunnel_candidate(const struct dcp_fabric_port *port, !dcp_fabric_available(pipeline, policy)) continue; if (!dcp_fabric_fits(pipeline, policy, - port->candidate_crtcs[dpin], + port->candidate_crtcs[dcp_fabric_dpin_slot(dpin)], connector_present)) continue; if (pipeline->terminal) { @@ -343,7 +343,8 @@ dcp_fabric_tunnel_candidate(const struct dcp_fabric_port *port, continue; } score = dcp_fabric_score(pipeline, policy); - if (policy->dual_stream && !dpin && !pipeline->has_fixed && + if (policy->dual_stream && !dcp_fabric_dpin_slot(dpin) && + !pipeline->has_fixed && score < UINT_MAX - 100) score += 100; if (score < best_score) { @@ -384,10 +385,10 @@ dcp_fabric_follow(const struct dcp_fabric_route *from, return DCP_FABRIC_FOLLOW_REFUSE; if (from == to) return DCP_FABRIC_FOLLOW_STAY; - if ((from->tunnel && (from->dpin > 1 || + if ((from->tunnel && (from->dpin >= DCP_FABRIC_DPIN_MAX || (to->tunnel_clock_blocked & BIT(from->dpin)))) || (holder && holder->tunnel && holder_back && - (holder->dpin > 1 || + (holder->dpin >= DCP_FABRIC_DPIN_MAX || (holder_back->tunnel_clock_blocked & BIT(holder->dpin))))) return DCP_FABRIC_FOLLOW_REFUSE; pipeline = to->pipeline; diff --git a/drivers/gpu/drm/apple/dcp-fabric-core.h b/drivers/gpu/drm/apple/dcp-fabric-core.h index dc85dbc40c15b..602e7b2efb7f6 100644 --- a/drivers/gpu/drm/apple/dcp-fabric-core.h +++ b/drivers/gpu/drm/apple/dcp-fabric-core.h @@ -5,6 +5,19 @@ #include #include +/* + * A Thunderbolt DP tunnel enters through one of up to four DP IN adapters of + * the port's host router, each behind a crossbar output of its own. A port + * carries at most two streams, primary and secondary: DP IN n and n + 2 share + * a stream slot. + */ +#define DCP_FABRIC_DPIN_MAX 4 + +static inline unsigned int dcp_fabric_dpin_slot(unsigned int dpin) +{ + return dpin & 1; +} + enum dcp_fabric_presence_state { DCP_FABRIC_ABSENT, DCP_FABRIC_SETTLING, diff --git a/drivers/gpu/drm/apple/dcp-fabric-test.c b/drivers/gpu/drm/apple/dcp-fabric-test.c index f2d2fd40593fc..ef6381b159073 100644 --- a/drivers/gpu/drm/apple/dcp-fabric-test.c +++ b/drivers/gpu/drm/apple/dcp-fabric-test.c @@ -478,7 +478,8 @@ static void fabric_scenario_test(struct kunit *test) KUNIT_EXPECT_PTR_EQ(test, found, NULL); KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_request(f.port, 3, 0, &found), -ENODEV); KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_request(f.port, 0, 0, &found), -EINVAL); - KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_request(f.port, 1, 2, &found), -EINVAL); + KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_request(f.port, 1, DCP_FABRIC_DPIN_MAX, + &found), -EINVAL); break; } } diff --git a/drivers/gpu/drm/apple/dcp-fabric-topology-test.c b/drivers/gpu/drm/apple/dcp-fabric-topology-test.c new file mode 100644 index 0000000000000..a9e4c3d95e3a7 --- /dev/null +++ b/drivers/gpu/drm/apple/dcp-fabric-topology-test.c @@ -0,0 +1,179 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* Included by dcp-fabric.c to exercise its connector publication paths. */ +#include +#include + +struct dcp_topology_test { + struct apple_dcp_typec_port port[3]; + struct apple_dcp_typec_route route[3][2]; + struct apple_connector connector[3][2]; + struct drm_encoder encoder[3][2]; + struct apple_dcp dcp[2]; + struct apple_crtc crtc[2]; + struct platform_device *pdev[2]; + struct drm_device drm; +}; + +static bool topology_fixed_crtcs(void) +{ + return true; +} + +static void topology_noop(struct work_struct *work) +{ +} + +static void topology_cleanup(void *data) +{ + struct dcp_topology_test *t = data; + unsigned int p, i; + + for (i = 0; i < 2; i++) + cancel_work_sync(&t->dcp[i].tb_event_work); + for (p = 0; p < 3; p++) + for (i = 0; i < 2; i++) + cancel_work_sync(&t->connector[p][i].bl_sync_wq); +} + +static struct dcp_topology_test *topology_init(struct kunit *test) +{ + struct dcp_topology_test *t; + unsigned int p, i; + + t = kunit_kzalloc(test, sizeof(*t), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, t); + kunit_activate_static_stub(test, dcp_typec_fixed_crtcs, topology_fixed_crtcs); + for (i = 0; i < 2; i++) { + struct apple_dcp *dcp = &t->dcp[i]; + + t->pdev[i] = kunit_platform_device_alloc(test, "dcp-topology", + PLATFORM_DEVID_AUTO); + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, t->pdev[i]); + KUNIT_ASSERT_EQ(test, kunit_platform_device_add(test, t->pdev[i]), 0); + platform_set_drvdata(t->pdev[i], dcp); + dcp->dev = &t->pdev[i]->dev; + dcp->crtc = &t->crtc[i]; + t->crtc[i].base.index = 1 + 2 * i; + t->crtc[i].base.dev = &t->drm; + dcp->fixed_connector_type = DRM_MODE_CONNECTOR_USB; + mutex_init(&dcp->tb_event_lock); + mutex_init(&dcp->tb_lock); + mutex_init(&dcp->external_lock); + mutex_init(&dcp->modes_lock); + spin_lock_init(&dcp->metadata.lock); + INIT_WORK(&dcp->tb_event_work, topology_noop); + } + for (p = 0; p < 3; p++) { + INIT_LIST_HEAD(&t->port[p].routes); + for (i = 0; i < 2; i++) { + struct apple_connector *connector = &t->connector[p][i]; + struct apple_dcp_typec_route *route = &t->route[p][i]; + + route->dcp = &t->dcp[i]; + route->port = &t->port[p]; + list_add_tail(&route->port_link, &t->port[p].routes); + connector->base.dev = &t->drm; + connector->port_encoder = &t->encoder[p][i]; + connector->candidate_crtcs = drm_crtc_mask(&t->crtc[i].base); + t->encoder[p][i].possible_crtcs = connector->candidate_crtcs; + apple_connector_edid_init(connector); + INIT_WORK(&connector->bl_sync_wq, topology_noop); + } + } + KUNIT_ASSERT_EQ(test, kunit_add_action_or_reset(test, topology_cleanup, t), 0); + return t; +} + +/* The DP IN ordinal must never choose the connector on fixed-CRTC ports. */ +static void topology_pipeline_identity_test(struct kunit *test) +{ + struct dcp_topology_test *t = topology_init(test); + unsigned int p, i, dpin; + + guard(mutex)(&dcp_typec_fabric_lock); + for (p = 0; p < 3; p++) { + for (i = 0; i < 2; i++) { + struct apple_dcp_typec_route *route = &t->route[p][i]; + struct apple_connector *connector = &t->connector[p][i]; + + dcp_typec_port_bind_connector(&t->port[p], false, connector, t->pdev[i]); + KUNIT_EXPECT_PTR_EQ(test, connector->dcp, NULL); + KUNIT_EXPECT_FALSE(test, dcp_typec_narrows(&t->dcp[i])); + for (dpin = 0; dpin < DCP_FABRIC_DPIN_MAX; dpin++) { + route->tunnel_dpin = dpin; + KUNIT_EXPECT_PTR_EQ(test, + dcp_typec_route_connector(route, true), + connector); + KUNIT_EXPECT_PTR_EQ(test, + dcp_typec_route_connector(route, false), + connector); + } + } + } +} + +/* Boot adoption and replug can put either tunnel slot on either processor. */ +static void topology_adopt_release_test(struct kunit *test) +{ + struct dcp_topology_test *t = topology_init(test); + unsigned int p, i; + + guard(mutex)(&dcp_typec_fabric_lock); + for (p = 0; p < 3; p++) { + for (i = 0; i < 2; i++) { + struct apple_dcp_typec_route *route = &t->route[p][i]; + struct apple_connector *connector = &t->connector[p][i]; + u32 mask = connector->port_encoder->possible_crtcs; + + /* Opposite of the connector creation order, as after replug. */ + t->port[p].owner = &t->route[p][1]; + t->port[p].secondary_owner = &t->route[p][0]; + t->dcp[i].active_typec_route = route; + dcp_typec_port_bind_connector(&t->port[p], false, connector, t->pdev[i]); + KUNIT_EXPECT_PTR_EQ(test, t->dcp[i].typec_connector, connector); + KUNIT_EXPECT_PTR_EQ(test, connector->dcp, t->pdev[i]); + KUNIT_EXPECT_EQ(test, connector->port_encoder->possible_crtcs, mask); + connector->connected = true; + /* The hardware has acknowledged release before this retry. */ + route->deactivate_xbar_done = true; + KUNIT_ASSERT_EQ(test, dcp_typec_route_deactivate(route), 0); + KUNIT_EXPECT_FALSE(test, connector->connected); + KUNIT_EXPECT_PTR_EQ(test, connector->dcp, NULL); + KUNIT_EXPECT_PTR_EQ(test, t->dcp[i].typec_connector, NULL); + KUNIT_EXPECT_EQ(test, connector->port_encoder->possible_crtcs, mask); + KUNIT_EXPECT_PTR_EQ(test, route->connector, connector); + } + t->port[p].owner = NULL; + t->port[p].secondary_owner = NULL; + } +} + +static void topology_unbind_test(struct kunit *test) +{ + struct dcp_topology_test *t = topology_init(test); + unsigned int p, i; + + guard(mutex)(&dcp_typec_fabric_lock); + for (p = 0; p < 3; p++) { + for (i = 0; i < 2; i++) + dcp_typec_port_bind_connector(&t->port[p], false, + &t->connector[p][i], t->pdev[i]); + dcp_typec_port_unlink(&t->port[p], &t->drm); + for (i = 0; i < 2; i++) + KUNIT_EXPECT_PTR_EQ(test, t->route[p][i].connector, NULL); + } +} + +static struct kunit_case dcp_topology_cases[] = { + KUNIT_CASE(topology_pipeline_identity_test), + KUNIT_CASE(topology_adopt_release_test), + KUNIT_CASE(topology_unbind_test), + {} +}; + +static struct kunit_suite dcp_topology_suite = { + .name = "apple-dcp-topology", + .test_cases = dcp_topology_cases, +}; + +kunit_test_suite(dcp_topology_suite); diff --git a/drivers/gpu/drm/apple/dcp-fabric.c b/drivers/gpu/drm/apple/dcp-fabric.c index eb11794f62cf3..de538ed801846 100644 --- a/drivers/gpu/drm/apple/dcp-fabric.c +++ b/drivers/gpu/drm/apple/dcp-fabric.c @@ -28,6 +28,7 @@ #include "dcpext_scanout.h" #include "ibootep.h" #include "dcp-internal.h" +#include "dptx-service.h" #include "iomfb_m4.h" #include "parser.h" #include "t8132_ext_drm.h" @@ -301,11 +302,16 @@ bool dcp_typec_dual_stream(void) return atomic_read(&dcp_dual_stream_routes) > 0; } -/* Keep native T6030 routes pinned to their owning processor, on either DPIN. */ +/* + * Keep native T6030 and T6050 routes pinned to their owning processor, on + * any DPIN: their external processors are interchangeable, so no ordering + * pass pairs streams with pipelines. + */ bool dcp_typec_ordered_dual_stream(void) { return dcp_fabric_ordered_dual_stream(dcp_typec_dual_stream(), - of_machine_is_compatible("apple,t6030")); + of_machine_is_compatible("apple,t6030") || + of_machine_is_compatible("apple,t6050")); } /* @@ -336,7 +342,28 @@ static bool dcp_typec_port_follows(struct apple_dcp_typec_port *port) static bool dcp_typec_narrows(struct apple_dcp *dcp) { /* This tree narrows on dual-stream machines too. */ - return !dcp_typec_follows_crtc(dcp); + return !dcp_typec_fixed_crtcs() && !dcp_typec_follows_crtc(dcp); +} + +/* + * T6050 establishes a tunnel on a processor before KMS sees its monitor. + * Give each port/pipeline pair a connector whose capabilities stay fixed, + * rather than publishing the current tunnel owner in possible_crtcs. + */ +bool dcp_typec_fixed_crtcs(void) +{ + KUNIT_STATIC_STUB_REDIRECT(dcp_typec_fixed_crtcs); + + return of_machine_is_compatible("apple,t6050"); +} + +static struct apple_connector * +dcp_typec_route_connector(struct apple_dcp_typec_route *route, bool tunnel) +{ + if (dcp_typec_fixed_crtcs()) + return route->connector; + return tunnel && dcp_fabric_dpin_slot(route->tunnel_dpin) ? + route->port->secondary_connector : route->port->connector; } bool dcp_is_typec_only(struct platform_device *pdev) @@ -352,6 +379,23 @@ static int dcp_route_clock_rate(struct apple_dcp_typec_route *route, bool t8132 = dcp_is_t8132_ext(route->dcp); int ret; + /* + * T6050: DP IN n has the PHY's tunnel clock n + 1, which feeds the + * crossbar's pixel clock n + 1. Each clock has its own source. + */ + if (of_machine_is_compatible("apple,t6050")) { + typeof(apple_t6050_dp_tunnel_clock) *fn = + symbol_get(apple_t6050_dp_tunnel_clock); + + if (!fn) + return rate ? -EOPNOTSUPP : 0; + ret = fn(phy, dpin + 1, rate); + symbol_put(apple_t6050_dp_tunnel_clock); + if (!ret) + route->tunnel_rate = rate; + return ret; + } + /* A T8132 dcpext names its source (2 or 4), as T6030 does. */ if (of_machine_is_compatible("apple,t6030") || t8132) { typeof(apple_atc_dp_tunnel_rate_source) *fn; @@ -381,10 +425,27 @@ static int dcp_route_clock_rate(struct apple_dcp_typec_route *route, return ret; } +/* + * The fabric lock excludes new event admission while a route is retired. + * Delivery holds tb_event_lock through its RPC, drops tb_lock before the RPC, + * and never takes the fabric lock. Drain it before changing the route or its binding. + */ +static void dcp_tb_events_retire(struct apple_dcp *dcp) +{ + lockdep_assert_held(&dcp_typec_fabric_lock); + scoped_guard(mutex, &dcp->tb_event_lock) { + dcp->tb_events = 0; + dcp->tb_event_route = NULL; + dcp->tb_event_generation = 0; + } + cancel_work_sync(&dcp->tb_event_work); +} + static int dcp_typec_route_activate(struct apple_dcp_typec_route *route, struct mux_control *xbar); static int dcp_typec_route_deactivate(struct apple_dcp_typec_route *route); static int dcp_dpxbar_preselect(struct mux_control *mux, int state); +static bool dcp_xbar_t8142(struct mux_control *mux); static int dcp_dpxbar_tunnel_select_source(struct mux_control *mux, int state) { @@ -466,10 +527,11 @@ static int dcp_typec_route_activate(struct apple_dcp_typec_route *route, { struct apple_dcp *dcp = route->dcp; struct apple_connector *connector = - xbar != route->xbar && route->tunnel_dpin == 1 ? - route->port->secondary_connector : route->port->connector; + dcp_typec_route_connector(route, xbar != route->xbar); int ret; + dcp_tb_events_retire(dcp); + /* Never select a DP PHY output that has no DP PHY behind it. */ if (xbar == route->xbar && dcp_typec_route_no_dp_alt(route)) return -EOPNOTSUPP; @@ -598,7 +660,7 @@ static int dcp_typec_route_activate(struct apple_dcp_typec_route *route, /* A newly selected output starts with its clocks off. */ dcp->direct_xbar_up = NULL; dcp->dptx_tunnel = route->tunnel; - /* crossbar controls are dpphy, dpin0, dpin1: same order as the DFP port */ + /* crossbar controls are dpphy, then dpin0..3: same order as the DFP port */ dcp->dptx_dfp_port = route->tunnel ? xbar - &route->xbar->chip->mux[0] : 0; dcp->tb_clock_ok = false; } @@ -617,6 +679,8 @@ static int dcp_typec_route_deactivate(struct apple_dcp_typec_route *route) bool ended_attachment; int ret = 0; + dcp_tb_events_retire(dcp); + WRITE_ONCE(dcp->peer_starved, false); WRITE_ONCE(dcp->typec_narrow, false); /* A peer reserved for this route's display is not needed any more. */ @@ -639,18 +703,19 @@ static int dcp_typec_route_deactivate(struct apple_dcp_typec_route *route) return route->deactivate_error; if (!route->deactivate_xbar_done) { dcp_typec_route_phy_off(route); - if (!route->tunnel || route->xbar_up) + if (!route->tunnel || route->xbar_up) { ret = mux_control_deselect(route->active_xbar ?: route->xbar); - else + } else { ret = dcp_dpxbar_preselect(route->active_xbar, MUX_IDLE_DISCONNECT); - /* - * A T602X crossbar has no preselection, and a T8132 - * tunnel output that never came up was never selected: - * it is idle. - */ - if (ret == -EOPNOTSUPP && route->tunnel && !route->xbar_up && - dcp_typec_route_no_dp_alt(route)) - ret = 0; + /* + * The T8142-layout crossbar writes an output only when it + * is selected: one never selected is idle already. + */ + if (ret == -EOPNOTSUPP && + (dcp_xbar_t8142(route->active_xbar) || + dcp_typec_route_no_dp_alt(route))) + ret = 0; + } /* Deselect always unlocks: never consume that selection twice. */ route->deactivate_xbar_done = true; route->xbar_up = false; @@ -711,7 +776,7 @@ static int dcp_typec_route_deactivate(struct apple_dcp_typec_route *route) schedule_work(&connector->bl_sync_wq); /* Unrouted: the port could go to any of its pipelines again. */ - if (connector->port_encoder) + if (connector->port_encoder && !dcp_typec_fixed_crtcs()) connector->port_encoder->possible_crtcs = connector->candidate_crtcs; } @@ -2006,11 +2071,27 @@ static int dcp_typec_route_set(struct typec_mux_dev *mux, return 0; } -/* Limited to the T6030 14.7 pipeline; other T602X tunnels keep their order. */ +/* The T8142-layout crossbar (one per ATC on T6050) */ +static bool dcp_xbar_t8142(struct mux_control *mux) +{ + return mux && of_device_is_compatible(mux->chip->dev.parent->of_node, + "apple,t8142-display-crossbar"); +} + +/* + * Tunnel routes whose crossbar must point the DP IN output at its pipeline + * before the firmware uses AUX through it, i.e. from DCP's Activate: the T6030 + * 14.7 pipeline on its T602X crossbar (other T602X tunnels keep their order) + * and firmware 27 on the T8142-layout crossbar. Selecting routes the output + * only; its clocks follow the link. + */ static bool dcp_t602x_tunnel_route(struct apple_dcp_typec_route *route) { - return route && route->tunnel && route->active_xbar && - route->dcp->fw_compat == DCP_FIRMWARE_V_14_7 && + if (!route || !route->tunnel || !route->active_xbar) + return false; + if (route->dcp->fw_compat == DCP_FIRMWARE_V_27_0) + return dcp_xbar_t8142(route->active_xbar); + return route->dcp->fw_compat == DCP_FIRMWARE_V_14_7 && of_device_is_compatible(route->active_xbar->chip->dev.parent->of_node, "apple,t6020-display-crossbar"); } @@ -2206,6 +2287,27 @@ static int dcp_t8132_crossbar_up_locked(struct apple_dcp *dcp, u32 unit) return ret; } +/* + * The T8142-layout crossbar takes the pixel clock and coding of an output + * before its link comes up: the tunnel's own clock, DP IN n + 1. A running + * link keeps its configuration. + */ +static int dcp_tunnel_xbar_configure(struct apple_dcp_typec_route *route) +{ + typeof(&apple_dpxbar_link_configure) configure; + int ret; + + if (!dcp_xbar_t8142(route->active_xbar)) + return 0; + configure = symbol_get(apple_dpxbar_link_configure); + if (!configure) + return -ENODEV; + ret = configure(route->active_xbar, route->tunnel_dpin + 1, + route->tunnel_rate == 0x81 || route->tunnel_rate == 0x82); + symbol_put(apple_dpxbar_link_configure); + return ret == -EBUSY ? 0 : ret; +} + int dcp_tunnel_crossbar_up(struct apple_dcp *dcp, u32 unit) { struct apple_dcp_typec_route *route; @@ -2232,15 +2334,23 @@ int dcp_tunnel_crossbar_up(struct apple_dcp *dcp, u32 unit) if (!ret) route->xbar_up = true; /* T602X DP IN selection reserves and routes the mux only. */ - if (!ret && dcp_t602x_tunnel_route(route)) - ret = dcp_dpxbar_link(route->active_xbar, true); + if (!ret && dcp_t602x_tunnel_route(route)) { + ret = dcp_tunnel_xbar_configure(route); + if (!ret) + ret = dcp_dpxbar_link(route->active_xbar, true); + } } else { - ret = dcp_dpxbar_link(route->active_xbar, true); + ret = dcp_tunnel_xbar_configure(route); + if (!ret) + ret = dcp_dpxbar_link(route->active_xbar, true); } if (ret) { dev_warn(dcp->dev, "DP tunnel crossbar up failed: %d\n", ret); return ret; } + /* T8142 layout: let the connection settle before the DP IN takes it. */ + if (dcp_xbar_t8142(route->active_xbar)) + usleep_range(5000, 6000); return dcp_tunnel_dpin_locked(dcp, true); } @@ -2252,6 +2362,7 @@ int dcp_tunnel_crossbar_up(struct apple_dcp *dcp, u32 unit) int dcp_tunnel_crossbar_down(struct apple_dcp *dcp, u32 unit) { struct apple_dcp_typec_route *route; + int ret; guard(mutex)(&dcp->tb_lock); /* A T8132 dcpext has no second tile. */ @@ -2273,7 +2384,14 @@ int dcp_tunnel_crossbar_down(struct apple_dcp *dcp, u32 unit) if (dcp_is_t8132_ext(dcp)) return dcp_t8132_crossbar_down_locked(dcp, route, "WillChangeLinkConfiguration"); dcp_tunnel_dpin_locked(dcp, false); - return dcp_dpxbar_link(route->active_xbar, false); + ret = dcp_dpxbar_link(route->active_xbar, false); + /* + * T8142 layout (T6050): the DP IN goes active again at once, so its + * AUX path is there while DCP trains the new link configuration. + */ + if (dcp_xbar_t8142(route->active_xbar)) + dcp_tunnel_dpin_locked(dcp, true); + return ret; } /* @@ -2431,7 +2549,10 @@ int dcp_tunnel_set_rate(struct apple_dcp *dcp, struct phy *phy, u32 unit, dcp_dpxbar_link(route->active_xbar, false); ret = dcp_route_clock_rate(route, phy, route->tunnel_dpin, link_rate); dcp->tb_clock_ok = !ret && link_rate; - if (ret) + if (ret == -EOPNOTSUPP) + dev_warn(dcp->dev, "no DP tunnel pixel clock on dpin%u: link rate 0x%x refused\n", + route->tunnel_dpin, link_rate); + else if (ret) dev_warn(dcp->dev, "DP tunnel pixel clock (rate 0x%x) failed: %d\n", link_rate, ret); return ret; @@ -2484,7 +2605,8 @@ int dcp_tunnel_dpin_activate(struct apple_dcp *dcp, u32 unit, bool active) return dcp->split.set_active(dcp->split.binding, active); } /* Route the upstream engine before firmware begins AUX negotiation. - * T602X DP IN .set does not enable clocks; DidChange does that later. + * Selecting a T602X or T8142-layout DP IN output does not enable its + * clocks; DidChange does that later. */ route = dcp->active_typec_route; if (!route || !dcp_fabric_callback_valid(route->tunnel_generation, dcp->tb_generation)) @@ -2552,13 +2674,14 @@ struct dcp_tb_attach_context { static struct mux_control * dcp_typec_tunnel_ctl(struct apple_dcp_typec_route *route, unsigned int dpin) { - if (dpin > 1 || (dcp_route_tunnel_clock_blocked(route) & BIT(dpin))) + if (dpin >= DCP_FABRIC_DPIN_MAX || (dcp_route_tunnel_clock_blocked(route) & BIT(dpin))) return NULL; if (route->dpin[dpin]) return route->dpin[dpin]; /* Legacy DT ABI: unnamed DPIN controls share the DP-alt chip. */ if (route->xbar != &route->xbar->chip->mux[0] || - route->xbar->chip->controllers < 3) + route->xbar->chip->controllers < 3 || + route->xbar->chip->controllers < 2 + dpin) return NULL; return &route->xbar->chip->mux[1 + dpin]; } @@ -2570,6 +2693,7 @@ static int dcp_tb_candidate(void *data) struct apple_dcp_typec_route *best, *planned = NULL; struct mux_control *ctl; unsigned int dpin = ctx->dpin; + unsigned int stream = dcp_fabric_dpin_slot(dpin); bool ordered; int ret; @@ -2580,7 +2704,7 @@ static int dcp_tb_candidate(void *data) */ ordered = dcp_typec_keep_order(); if (ordered) - planned = dcp_typec_rebalance_locked(port, dpin); + planned = dcp_typec_rebalance_locked(port, stream); ctx->planned = planned; { @@ -2590,7 +2714,8 @@ static int dcp_tb_candidate(void *data) .hybrid_first = dcp_typec_hybrid_first(), }; struct dcp_fabric_route *chosen; - bool connector_present = dpin ? !!port->secondary_connector : !!port->connector; + bool connector_present = stream ? !!port->secondary_connector : + !!port->connector; dcp_fabric_snapshot_port(port, true); chosen = dcp_fabric_tunnel_candidate(&port->core, @@ -2633,6 +2758,7 @@ static void dcp_tb_rollback(void *data) struct dcp_tb_attach_context *ctx = data; struct apple_dcp *dcp = ctx->best->dcp; + dcp_tb_events_retire(dcp); /* The failed attempt's binding is retired before the provider hears of it. */ guard(mutex)(&dcp->tb_lock); dcp->tb_dpin_set_active = NULL; @@ -2732,6 +2858,7 @@ static void dcp_tb_binding_retire(struct apple_dcp *dcp, struct apple_dcp_typec_route *route) { lockdep_assert_held(&dcp_typec_fabric_lock); + dcp_tb_events_retire(dcp); scoped_guard(mutex, &dcp->tb_lock) { dcp->tb_generation = 0; if (route) @@ -2860,13 +2987,20 @@ static int dcp_tb_split_join_locked(struct apple_dcp_typec_port *port, * holds before any of its services are up. On T6030 every Type-C pipeline is * an external processor. A port with no routes is not judged here. */ +/* + * Ports whose pipelines cannot take a tile on their second DPTX port: the + * T6030 external processors, and firmware 27 (T6050), whose pipelines drive + * one DP IN each, so that two monitors behind a dock get two processors. + */ static bool dcp_typec_port_untileable(struct apple_dcp_typec_port *port) { struct apple_dcp_typec_route *route; /* No tiles on a T8132 dcpext. */ list_for_each_entry(route, &port->routes, port_link) - if (!route->dcp->external && !dcp_typec_route_no_dp_alt(route)) + if (!route->dcp->external && + !dcp_typec_route_no_dp_alt(route) && + route->dcp->fw_compat != DCP_FIRMWARE_V_27_0) return false; return !list_empty(&port->routes); } @@ -2955,7 +3089,8 @@ static int dcp_tb_split_locked(struct apple_dcp_typec_port *port, static int dcp_tb_release_locked(struct apple_dcp_typec_port *port, unsigned int dpin) { - struct apple_dcp_typec_route **slot = dpin ? &port->secondary_owner : &port->owner; + struct apple_dcp_typec_route **slot = dcp_fabric_dpin_slot(dpin) ? + &port->secondary_owner : &port->owner; struct apple_dcp *dcp; int ret; @@ -2966,6 +3101,7 @@ static int dcp_tb_release_locked(struct apple_dcp_typec_port *port, return ret; } dcp = (*slot)->dcp; + dcp_tb_events_retire(dcp); /* * A refused display release keeps the route and its binding owned. * port->hpd is the port's, and stays set while the other DP IN @@ -3015,7 +3151,7 @@ static int dcp_tb_dispatch_request(void *data, const struct dcp_fabric_port *fou unsigned int dpin = ctx->dpin; int ret; - slot = dpin ? &port->secondary_owner : &port->owner; + slot = dcp_fabric_dpin_slot(dpin) ? &port->secondary_owner : &port->owner; if (dpin == 1 && (tiled_split || port->split_dcp)) { ret = dcp_tb_split_locked(port, ctx); @@ -3099,7 +3235,7 @@ static int dcp_tb_dispatch_request(void *data, const struct dcp_fabric_port *fou static void dcp_tb_finish_request(struct apple_dcp_typec_port *port, const struct dcp_tb_attach_context *request) { - struct apple_dcp_typec_route *route = request->dpin ? + struct apple_dcp_typec_route *route = dcp_fabric_dpin_slot(request->dpin) ? port->secondary_owner : port->owner; struct apple_dcp *dcp; bool matching; @@ -3156,7 +3292,8 @@ int apple_dcp_tb_dp_tunnel(struct device_node *connector_np, unsigned int dpin, .binding = binding, }; - if (!connector_np || dpin > 1 || !generation || (active && !set_active)) + if (!connector_np || dpin >= DCP_FABRIC_DPIN_MAX || !generation || + (active && !set_active)) return -EINVAL; guard(mutex)(&dcp_typec_fabric_lock); list_for_each_entry(pos, &dcp_typec_ports, link) { @@ -3170,6 +3307,118 @@ int apple_dcp_tb_dp_tunnel(struct device_node *connector_np, unsigned int dpin, } EXPORT_SYMBOL_GPL(apple_dcp_tb_dp_tunnel); +enum { + DCP_TB_EVENT_IRQ_HPD, + DCP_TB_EVENT_HPD, +}; + +/* + * A DP source learns of a sink's request through IRQ_HPD and of a sink that + * went away or came back through the HPD level. On a tunnel, both arrive at + * the DP IN adapter: pass them to the DPTX port as its HPD input would, so + * that DCP services the request (and retrains a link the sink lost). + */ +void dcp_tb_event_work(struct work_struct *work) +{ + struct apple_dcp *dcp = container_of(work, struct apple_dcp, tb_event_work); + struct dptx_port *dptx = &dcp->dptxport[0]; + struct apple_epic_service *service; + struct apple_dcp_typec_route *route; + bool irq, changed, hpd, valid; + ktime_t now = ktime_get(); + int ret; + + /* Keep the identity check and RPC ordered before attachment retirement. */ + guard(mutex)(&dcp->tb_event_lock); + route = dcp->tb_event_route; + irq = test_and_clear_bit(DCP_TB_EVENT_IRQ_HPD, &dcp->tb_events); + changed = test_and_clear_bit(DCP_TB_EVENT_HPD, &dcp->tb_events); + hpd = dcp->tb_event_hpd; + if ((!irq && !changed) || !route) + return; + scoped_guard(mutex, &dcp->tb_lock) + valid = dcp->active_typec_route == route && route->tunnel && + dcp_fabric_callback_valid(route->tunnel_generation, + dcp->tb_event_generation) && + dcp->tb_generation == dcp->tb_event_generation; + if (!valid) + return; + service = READ_ONCE(dptx->service); + if (!service || !dptx_service_available(dptx) || !READ_ONCE(dptx->connected)) { + dev_info(dcp->dev, "DP tunnel:%s%s with no connected link: not passed\n", + irq ? " IRQ_HPD" : "", changed ? (hpd ? " HPD high" : " HPD low") : ""); + return; + } + if (changed) { + dcp->tb_hpd_count++; + ret = dptxport_set_hpd(service, hpd); + dev_info(dcp->dev, "DP tunnel: HPD %s (#%u) passed to the firmware: %d\n", + hpd ? "high" : "low", dcp->tb_hpd_count, ret); + } + if (irq && hpd) { + s64 since = dcp->tb_irq_hpd_count ? + ktime_ms_delta(now, dcp->tb_irq_hpd_last) : -1; + + dcp->tb_irq_hpd_count++; + dcp->tb_irq_hpd_last = now; + /* + * The firmware may answer the request by dropping the sink, with + * the tunnel and its HPD still there. Count that as a link coming + * up, so that the drop gets a relink; see dcp_typec_relink(). + */ + scoped_guard(spinlock_irqsave, &dcp->relink_lock) + dcp_relink_link_up(&dcp->relink, + READ_ONCE(dcp->typec_generation), jiffies); + ret = dptxport_sink_irq(service); + dev_info(dcp->dev, "DP tunnel: sink IRQ_HPD (#%u, %lld ms after the last) passed to the firmware: %d\n", + dcp->tb_irq_hpd_count, since, ret); + } +} + +int apple_dcp_tb_dp_event(struct device_node *connector_np, unsigned int dpin, + u64 generation, unsigned int events, bool hpd) +{ + struct apple_dcp_typec_port *pos; + struct apple_dcp_typec_route *attachment = NULL; + struct apple_dcp *dcp = NULL; + + if (!connector_np || dpin >= DCP_FABRIC_DPIN_MAX || !generation) + return -EINVAL; + guard(mutex)(&dcp_typec_fabric_lock); + list_for_each_entry(pos, &dcp_typec_ports, link) { + struct apple_dcp_typec_route *route; + + if (pos->connector_np != connector_np) + continue; + route = dcp_fabric_dpin_slot(dpin) ? pos->secondary_owner : pos->owner; + if (route && route->tunnel && route->tunnel_dpin == dpin && + route->tunnel_generation == generation) { + dcp = route->dcp; + attachment = route; + break; + } + } + if (!dcp) + return -ESTALE; + guard(mutex)(&dcp->tb_event_lock); + if (dcp->tb_event_route != attachment || dcp->tb_event_generation != generation) + dcp->tb_events = 0; + dcp->tb_event_route = attachment; + dcp->tb_event_generation = generation; + if (events & APPLE_DP_TUNNEL_HPD_CHANGED) { + WRITE_ONCE(dcp->tb_event_hpd, hpd); + set_bit(DCP_TB_EVENT_HPD, &dcp->tb_events); + } + if (events & APPLE_DP_TUNNEL_IRQ_HPD) { + if (!(events & APPLE_DP_TUNNEL_HPD_CHANGED)) + WRITE_ONCE(dcp->tb_event_hpd, true); + set_bit(DCP_TB_EVENT_IRQ_HPD, &dcp->tb_events); + } + queue_work(system_dfl_wq, &dcp->tb_event_work); + return 0; +} +EXPORT_SYMBOL_GPL(apple_dcp_tb_dp_event); + /* * Direct DP-alt routes and Thunderbolt tunnels follow the CRTC selected by * a modeset on 12.3/13.5. A tunnel keeps its Thunderbolt binding: only the @@ -3458,6 +3707,7 @@ static int dcp_follow_release(struct apple_dcp_typec_route *route) bool tunnel = route->tunnel; int ret; + dcp_tb_events_retire(dcp); /* Revoked sessions cannot touch the new route after a reconnect wait. */ ret = dcp_dptx_park(dcp); if (ret) @@ -3981,19 +4231,25 @@ bool dcp_typec_port_unusable(unsigned int idx) return true; } -void dcp_typec_port_set_connector(unsigned int idx, bool secondary, - struct apple_connector *connector) +static void dcp_typec_port_bind_connector(struct apple_dcp_typec_port *port, + bool secondary, + struct apple_connector *connector, + struct platform_device *pipeline) { - struct apple_dcp_typec_port *port; struct apple_dcp_typec_route *owner; - guard(mutex)(&dcp_typec_fabric_lock); + lockdep_assert_held(&dcp_typec_fabric_lock); - port = dcp_typec_port_by_index(idx); - if (!port) - return; + if (pipeline) { + struct apple_dcp *dcp = platform_get_drvdata(pipeline); + struct apple_dcp_typec_route *route = dcp_typec_port_route(port, dcp); - if (secondary) { + if (WARN_ON(!route)) + return; + route->connector = connector; + owner = route == port->owner || route == port->secondary_owner ? + route : NULL; + } else if (secondary) { port->secondary_connector = connector; owner = port->secondary_owner; } else { @@ -4024,6 +4280,18 @@ void dcp_typec_port_set_connector(unsigned int idx, bool secondary, } } +void dcp_typec_port_set_connector(unsigned int idx, bool secondary, + struct apple_connector *connector, + struct platform_device *pipeline) +{ + struct apple_dcp_typec_port *port; + + guard(mutex)(&dcp_typec_fabric_lock); + port = dcp_typec_port_by_index(idx); + if (port) + dcp_typec_port_bind_connector(port, secondary, connector, pipeline); +} + static void dcp_typec_route_unregister(void *data) { struct apple_dcp_typec_route *route = data; @@ -4073,7 +4341,7 @@ static void dcp_typec_route_unregister(void *data) static unsigned int dcp_typec_route_endpoints(struct device_node *connector_np) { struct device_node *port __free(device_node) = - of_graph_get_port_by_id(connector_np, 3); + apple_dp_tunnel_routes_port(connector_np); unsigned int count = 0; if (!port) @@ -4092,9 +4360,10 @@ static int dcp_typec_route_wiring(struct apple_dcp_typec_route *route, enum dcp_fabric_wiring wiring; char name[24]; unsigned int i; - bool named[2]; + bool named[DCP_FABRIC_DPIN_MAX]; - for (i = 0; i < 2; i++) { + /* DP IN 0/1 decide the stream wiring; DP IN 2/3 only add outputs. */ + for (i = 0; i < DCP_FABRIC_DPIN_MAX; i++) { snprintf(name, sizeof(name), "typec%u-dpin%u", index, i); named[i] = of_property_match_string(dev->of_node, "mux-control-names", name) >= 0; if (!named[i]) @@ -4104,9 +4373,12 @@ static int dcp_typec_route_wiring(struct apple_dcp_typec_route *route, return PTR_ERR(route->dpin[i]); if (route->xbar != &route->xbar->chip->mux[0] || route->xbar->chip->controllers < 3 || + route->xbar->chip->controllers < 2 + i || route->dpin[i] != &route->xbar->chip->mux[1 + i]) return -EINVAL; } + if ((named[2] || named[3]) && !(named[0] && named[1])) + return -EINVAL; if (!named[0] && !named[1]) { snprintf(name, sizeof(name), "typec%u-usb4", index); if (of_property_match_string(dev->of_node, "mux-control-names", name) >= 0) { @@ -4905,6 +5177,21 @@ void dcp_link(struct platform_device *pdev, struct apple_crtc *crtc, WRITE_ONCE(connector->connected, !iomfb_m4_error(dcp) && dcp->active); } +static void dcp_typec_port_unlink(struct apple_dcp_typec_port *port, + struct drm_device *drm) +{ + struct apple_dcp_typec_route *route; + + lockdep_assert_held(&dcp_typec_fabric_lock); + list_for_each_entry(route, &port->routes, port_link) + if (route->connector && route->connector->base.dev == drm) + route->connector = NULL; + if (port->connector && port->connector->base.dev == drm) + port->connector = NULL; + if (port->secondary_connector && port->secondary_connector->base.dev == drm) + port->secondary_connector = NULL; +} + /* Called after component unbind has drained all firmware callbacks. The * platform devices and their Type-C muxes can outlive this DRM instance. */ @@ -4915,13 +5202,8 @@ void dcp_unlink(struct drm_device *drm) guard(mutex)(&dcp_typec_fabric_lock); - list_for_each_entry(port, &dcp_typec_ports, link) { - if (port->connector && port->connector->base.dev == drm) - port->connector = NULL; - if (port->secondary_connector && - port->secondary_connector->base.dev == drm) - port->secondary_connector = NULL; - } + list_for_each_entry(port, &dcp_typec_ports, link) + dcp_typec_port_unlink(port, drm); drm_for_each_crtc(crtc, drm) { struct apple_crtc *apple_crtc = to_apple_crtc(crtc); @@ -4972,3 +5254,7 @@ int dcp_typec_test_link(struct platform_device *pdev, bool enabled) return enabled ? dcp_dptx_connect_oob(pdev, 0) : dcp_dptx_disconnect_oob(pdev, 0); } + +#if IS_ENABLED(CONFIG_DRM_APPLE_KUNIT_TEST) +#include "dcp-fabric-topology-test.c" +#endif diff --git a/drivers/gpu/drm/apple/dcp-fabric.h b/drivers/gpu/drm/apple/dcp-fabric.h index 2db549172d1d5..0805c54d39051 100644 --- a/drivers/gpu/drm/apple/dcp-fabric.h +++ b/drivers/gpu/drm/apple/dcp-fabric.h @@ -30,10 +30,12 @@ struct apple_dcp_typec_route { struct dcp_fabric_route core; struct apple_dcp *dcp; struct apple_dcp_typec_port *port; + /* T6050: this port/pipeline pair has a connector with a fixed CRTC. */ + struct apple_connector *connector; struct list_head port_link; struct phy *phy; struct mux_control *xbar; - struct mux_control *dpin[2]; + struct mux_control *dpin[DCP_FABRIC_DPIN_MAX]; bool dual_stream; struct typec_mux_dev *typec_mux; u32 dptx_phy; @@ -43,6 +45,8 @@ struct apple_dcp_typec_route { bool phy_powered; /* crossbar output actually selected: xbar (dpphy) or a Thunderbolt dpin */ unsigned int tunnel_dpin; + /* T6050: DP link rate code the tunnel's pixel clock runs at, 0 if stopped */ + u8 tunnel_rate; u64 tunnel_generation; struct mux_control *active_xbar; bool tunnel; @@ -72,7 +76,9 @@ struct device_node *dcp_typec_port_of_node(unsigned int idx); bool dcp_typec_port_has_candidate(unsigned int idx, struct platform_device *pdev); bool dcp_typec_port_unusable(unsigned int idx); void dcp_typec_port_set_connector(unsigned int idx, bool secondary, - struct apple_connector *connector); + struct apple_connector *connector, + struct platform_device *pipeline); +bool dcp_typec_fixed_crtcs(void); bool dcp_typec_dual_stream(void); bool dcp_typec_ordered_dual_stream(void); void dcp_typec_reorder(void); diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 689dc4d3ac3a3..a510190923ebf 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -903,6 +903,21 @@ struct apple_dcp { /* T6030 HDMI converter service requests, see dcp-hdmi.c */ struct dcp_hdmi *hdmi; + /* + * Interrupts of a Thunderbolt DP tunnel's DP IN adapter, to pass to + * the DPTX port; see apple_dcp_tb_dp_event(). + */ + struct work_struct tb_event_work; + /* Serializes event delivery against attachment retirement. */ + struct mutex tb_event_lock; + struct apple_dcp_typec_route *tb_event_route; + u64 tb_event_generation; + unsigned long tb_events; + bool tb_event_hpd; + unsigned int tb_irq_hpd_count; + unsigned int tb_hpd_count; + ktime_t tb_irq_hpd_last; + /* Kept last: the template instances share the layout above. */ struct dcp_desktop_state *desktop; /* Internal panel identity; NULL without an internal panel. */ diff --git a/drivers/gpu/drm/apple/dcp-peer-runtime-v27.inc b/drivers/gpu/drm/apple/dcp-peer-runtime-v27.inc index b1f99d6ddd651..67401e465fcca 100644 --- a/drivers/gpu/drm/apple/dcp-peer-runtime-v27.inc +++ b/drivers/gpu/drm/apple/dcp-peer-runtime-v27.inc @@ -1,8 +1,8 @@ /* SPDX-License-Identifier: GPL-2.0-only OR MIT */ -/* Kept opt-in while paired DRM lifecycle is being validated on T6050. */ -static bool peer_scanout; +/* Paired DRM scanout of a mode one firmware-27 pipe cannot drive alone. */ +static bool peer_scanout = true; module_param(peer_scanout, bool, 0444); -MODULE_PARM_DESC(peer_scanout, "Enable firmware27 paired DRM scanout bring-up"); +MODULE_PARM_DESC(peer_scanout, "Firmware27 paired DRM scanout (default: on)"); static bool dcp_peer_transport_idle(struct apple_dcp *dcp) { diff --git a/drivers/gpu/drm/apple/dcp-peer-v27.inc b/drivers/gpu/drm/apple/dcp-peer-v27.inc index 9bae0594b5843..604e0935c5846 100644 --- a/drivers/gpu/drm/apple/dcp-peer-v27.inc +++ b/drivers/gpu/drm/apple/dcp-peer-v27.inc @@ -1,11 +1,11 @@ /* SPDX-License-Identifier: GPL-2.0-only OR MIT */ -/* Bring-up gate until the framebuffer merge lifecycle is implemented. This - * only reserves an otherwise unrouted DCP; it never replaces a physical route. +/* Logical peer allocation for a merged mode. This only reserves an otherwise + * unrouted DCP; it never replaces a physical route. */ -static bool peer_allocation_probe; +static bool peer_allocation_probe = true; module_param(peer_allocation_probe, bool, 0444); -MODULE_PARM_DESC(peer_allocation_probe, "Test firmware27 logical peer allocation (merge bring-up)"); +MODULE_PARM_DESC(peer_allocation_probe, "Firmware27 logical peer allocation for merged modes (default: on)"); bool dcp_peer_tiling_state_v27(struct apple_dcp *dcp, bool write, u32 event, u32 param, u32 *value) diff --git a/drivers/gpu/drm/apple/dcp-peer-video-probe-v27.inc b/drivers/gpu/drm/apple/dcp-peer-video-probe-v27.inc index 24c985a91195f..e45561945803e 100644 --- a/drivers/gpu/drm/apple/dcp-peer-video-probe-v27.inc +++ b/drivers/gpu/drm/apple/dcp-peer-video-probe-v27.inc @@ -50,8 +50,19 @@ static int dcp_peer_video_call_stream(struct apple_dcp *dcp, bool independent, init_completion(&wait->done); kref_init(&wait->refs); kref_get(&wait->refs); - dcp_push(dcp, independent, &method, in_size, out_size, in, - dcp_peer_video_done, wait); + if (independent) { + /* Not behind the pending primary A413: it waits for this handoff. */ + ret = dcp_push_oob_concurrent(dcp, &method, in_size, out_size, in, + dcp_peer_video_done, wait); + if (ret) { + kref_put(&wait->refs, dcp_peer_video_free); + kref_put(&wait->refs, dcp_peer_video_free); + return ret; + } + } else { + dcp_push(dcp, false, &method, in_size, out_size, in, + dcp_peer_video_done, wait); + } if (!wait_for_completion_timeout(&wait->done, msecs_to_jiffies(!memcmp(tag, "A413", 4) ? 8500 : 2000))) ret = -ETIMEDOUT; diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 1e2bbe6f0ed05..b2de314cb5baf 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -2933,13 +2933,25 @@ static int dcp_dptx_connect_attached(struct apple_dcp *dcp, u32 port) * does not reset them, dcp_poweron() does. dcp-relink.h holds the * decisions; relink_lock protects their state. */ +/* + * A T6050 tunnel keeps its Thunderbolt binding and its HPD when the firmware + * drops the sink after servicing its IRQ_HPD (see dcp_tb_event_work()): + * nothing else connects it again. Other tunnels are left to their owners. + */ +static bool dcp_tunnel_relinks(struct apple_dcp *dcp) +{ + return of_device_is_compatible(dcp->dev->of_node, "apple,t6050-dcpext") && + READ_ONCE(dcp->tb_event_hpd); +} + static bool dcp_typec_relink_eligible(struct apple_dcp *dcp) { struct apple_connector *connector = READ_ONCE(dcp->connector); /* H17P and native external pipes recover through their own lifecycle */ if (dcp->fw_compat == DCP_FIRMWARE_H17P || dcp->external_native || - !dcp_is_typec_output(dcp) || dcp_is_usb4_output(dcp) || + !dcp_is_typec_output(dcp) || + (dcp_is_usb4_output(dcp) && !dcp_tunnel_relinks(dcp)) || dcp_is_external_h17p(dcp) || !dcp->typec_connector) return false; /* @@ -2947,7 +2959,7 @@ static bool dcp_typec_relink_eligible(struct apple_dcp *dcp) * not one the driver itself let go, holds HPD low for (see * dcp_placeholder_edid_work()) or moves to another pipeline. */ - /* Tunnels are excluded above; direct follows use the carried gate. */ + /* Most tunnels are excluded above; direct follows use the carried gate. */ return READ_ONCE(dcp->typec_work_enabled) && READ_ONCE(dcp->typec_cable_connected) && !READ_ONCE(dcp->typec_crtc_off) && @@ -5098,6 +5110,12 @@ VISIBLE_IF_KUNIT void dcp_disable_typec_work(struct apple_dcp *dcp, bool release disable_delayed_work_sync(&dcp->hdmi_settle_wq); disable_delayed_work_sync(&dcp->hdmi_recheck_wq); disable_delayed_work_sync(&dcp->link_recovery_wq); + disable_work_sync(&dcp->tb_event_work); + scoped_guard(mutex, &dcp->tb_event_lock) { + dcp->tb_events = 0; + dcp->tb_event_route = NULL; + dcp->tb_event_generation = 0; + } disable_delayed_work_sync(&dcp->hybrid_wq); dcp_hdmi_disable(dcp); } @@ -5113,6 +5131,7 @@ VISIBLE_IF_KUNIT void dcp_enable_typec_work(struct apple_dcp *dcp) enable_delayed_work(&dcp->hdmi_settle_wq); enable_delayed_work(&dcp->hdmi_recheck_wq); enable_delayed_work(&dcp->link_recovery_wq); + enable_work(&dcp->tb_event_work); enable_delayed_work(&dcp->hybrid_wq); dcp_hdmi_enable(dcp); scoped_guard(mutex, &dcp->hpd_mutex) @@ -6082,6 +6101,8 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) INIT_DELAYED_WORK(&dcp->typec_reconnect_wq, dcp_typec_reconnect_work); INIT_DELAYED_WORK(&dcp->link_recovery_wq, dcp_link_recovery_work); + mutex_init(&dcp->tb_event_lock); + INIT_WORK(&dcp->tb_event_work, dcp_tb_event_work); INIT_DELAYED_WORK(&dcp->placeholder_edid_wq, dcp_placeholder_edid_work); INIT_DELAYED_WORK(&dcp->typec_relink_wq, dcp_typec_relink_work); @@ -6100,6 +6121,7 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) disable_delayed_work(&dcp->typec_relink_wq); disable_delayed_work(&dcp->announce_wq); disable_delayed_work(&dcp->link_recovery_wq); + disable_work(&dcp->tb_event_work); dcp->announce.stopped = true; /* * A native external pipe's bind enables these; firmware callbacks may diff --git a/drivers/gpu/drm/apple/dcp.h b/drivers/gpu/drm/apple/dcp.h index 8e15f72fc11fa..20fd3ec5f59cb 100644 --- a/drivers/gpu/drm/apple/dcp.h +++ b/drivers/gpu/drm/apple/dcp.h @@ -127,6 +127,7 @@ void dcp_external_retry(struct apple_dcp *dcp, const char *why, int error, unsigned int base_ms); void dcp_external_retry_work(struct work_struct *work); void dcp_external_sink_irq(struct apple_dcp *dcp); +void dcp_tb_event_work(struct work_struct *work); void dcp_queue_typec_reconnect(struct apple_dcp *dcp, unsigned long delay); int dcp_dptx_recover_irq(struct apple_dcp *dcp); int dcp_dptx_park(struct apple_dcp *dcp); diff --git a/drivers/gpu/drm/apple/dcp_external_announce_test.c b/drivers/gpu/drm/apple/dcp_external_announce_test.c index a1bd2dcd4b2ab..f07b3777cc751 100644 --- a/drivers/gpu/drm/apple/dcp_external_announce_test.c +++ b/drivers/gpu/drm/apple/dcp_external_announce_test.c @@ -102,6 +102,7 @@ static struct announce_test *announce_test_init(struct kunit *test) dcp->hw.iomfb_method_profile = DCP_IOMFB_METHODS_H17P_EXTERNAL; iomfb_queue_init(dcp); mutex_init(&dcp->hpd_mutex); + mutex_init(&dcp->tb_event_lock); spin_lock_init(&dcp->relink_lock); mutex_init(&dcp->dcpavserv.lock); spin_lock_init(&dcp->metadata.lock); @@ -115,11 +116,13 @@ static struct announce_test *announce_test_init(struct kunit *test) INIT_DELAYED_WORK(&dcp->hybrid_wq, announce_test_noop); INIT_DELAYED_WORK(&dcp->bl_fallback_wq, announce_test_noop); INIT_DELAYED_WORK(&dcp->backlight.fade_work, announce_test_noop); + INIT_DELAYED_WORK(&dcp->brightness.fade_work, announce_test_noop); INIT_DELAYED_WORK(&dcp->backlight.retry_work, announce_test_noop); INIT_WORK(&dcp->external_stop_work, announce_test_noop); INIT_DELAYED_WORK(&dcp->external_stop_retry_wq, announce_test_noop); INIT_WORK(&dcp->vblank_wq, announce_test_noop); INIT_WORK(&dcp->dimensions_wq, announce_test_noop); + INIT_WORK(&dcp->tb_event_work, announce_test_noop); INIT_WORK(&t->con.hotplug_wq, announce_test_event); mutex_init(&t->drm.mode_config.mutex); diff --git a/drivers/gpu/drm/apple/dptx-drive-v27.inc b/drivers/gpu/drm/apple/dptx-drive-v27.inc index 9b8c3e6af1fa2..4fabf1347a8cd 100644 --- a/drivers/gpu/drm/apple/dptx-drive-v27.inc +++ b/drivers/gpu/drm/apple/dptx-drive-v27.inc @@ -12,6 +12,54 @@ struct dptxport_drive_v27 { } lane[]; } __packed; +/* + * A Thunderbolt DP tunnel has no PHY lanes to drive. DCP still trains the + * link through it: SetDriveSettings (count at +0x10, entries at +0x20) is + * answered with status 0 at +0x00 and its entries are kept as sent; + * GetDriveSettings (count at +0x00) returns status 0 at +0x10 and the kept + * entries at +0x20, mode words included. Every other byte is the request's, + * and any value is accepted, so DCP always gets its reply. + */ +static int dptxport_call_drive_tunnel_v27(struct dptx_port *dptx, bool set, + const void *data, size_t data_size, + void *reply_, size_t reply_size) +{ + const u8 *request = data; + u8 *reply = reply_; + u32 count, i; + + if (reply_size < 0x20) + return -EINVAL; + memset(reply, 0, reply_size); + memcpy(reply, request, min(data_size, reply_size)); + + if (set) { + count = data_size >= 0x14 ? get_unaligned_le32(request + 0x10) : 0; + dptx->tunnel_drive_count = 0; + for (i = 0; i < count && i < ARRAY_SIZE(dptx->tunnel_drive) && + data_size >= 0x20 + 12 * (i + 1); i++) { + dptx->tunnel_drive[i][0] = get_unaligned_le32(request + 0x20 + 12 * i); + dptx->tunnel_drive[i][1] = get_unaligned_le32(request + 0x24 + 12 * i); + dptx->tunnel_drive[i][2] = get_unaligned_le32(request + 0x28 + 12 * i); + dptx->tunnel_drive_count = i + 1; + } + put_unaligned_le32(0, reply); + return 0; + } + + count = data_size >= 4 ? get_unaligned_le32(request) : 0; + put_unaligned_le32(0, reply + 0x10); + for (i = 0; i < count && i < ARRAY_SIZE(dptx->tunnel_drive) && + reply_size >= 0x20 + 12 * (i + 1); i++) { + bool kept = i < dptx->tunnel_drive_count; + + put_unaligned_le32(kept ? dptx->tunnel_drive[i][0] : 0, reply + 0x20 + 12 * i); + put_unaligned_le32(kept ? dptx->tunnel_drive[i][1] : 0, reply + 0x24 + 12 * i); + put_unaligned_le32(kept ? dptx->tunnel_drive[i][2] : 0, reply + 0x28 + 12 * i); + } + return 0; +} + static int dptxport_call_drive_v27(struct apple_epic_service *service, bool set, const void *data, size_t data_size, void *reply_, size_t reply_size) @@ -24,6 +72,9 @@ static int dptxport_call_drive_v27(struct apple_epic_service *service, bool set, size_t size; int ret; + if (service->ep->dcp->dptx_tunnel) + return dptxport_call_drive_tunnel_v27(dptx, set, data, data_size, + reply_, reply_size); if (data_size < sizeof(*request) || reply_size < sizeof(*reply)) return -EINVAL; count = le32_to_cpu(set ? request->count_or_status : request->status_or_count); diff --git a/drivers/gpu/drm/apple/dptxep.c b/drivers/gpu/drm/apple/dptxep.c index 54464ddf1e9de..394e22fba90b1 100644 --- a/drivers/gpu/drm/apple/dptxep.c +++ b/drivers/gpu/drm/apple/dptxep.c @@ -104,8 +104,9 @@ struct dptxport_apcall_set_tiled { /* * A Thunderbolt DP tunnel uses the same CORE|ATC|DIE|CONNECTED target as a - * direct alt-mode PHY: CORE is the DFP port (0 = dpphy, 1/2 = dpin0/dpin1) - * and ATC the route's own ATC index. + * direct alt-mode PHY: CORE is the DFP port (0 = dpphy, 1..4 = dpin0..3) + * and ATC the route's own ATC index. ATC2's DP IN 0 is 0x8021, its DP-alt + * PHY 0x8020. */ static u32 dptxport_remote_target(struct apple_dcp *dcp, u8 core, u8 atc, u8 die) @@ -125,9 +126,10 @@ int dptxport_validate_connection(struct apple_epic_service *service, u8 core, u32 target = dptxport_remote_target(service->ep->dcp, core, atc, die); /* - * Attributes: role (0 = direct PHY, 1 = Thunderbolt/USB4 DP IN) | - * supports HPD << 8. Without the DP IN role DCP gives up on a tunnel - * whose AUX channel is slower to answer than a direct PHY's. + * Attributes: role (bits 7:0; 0 = direct PHY, 1 = Thunderbolt/USB4 + * DP IN) | supports HPD (bit 8): 0x101 for a tunnel, 0x100 for a PHY. + * Without the DP IN role DCP gives up on a tunnel whose AUX channel is + * slower to answer than a direct PHY's. */ u32 attrs = 0x100 | (dcp_is_usb4_output(service->ep->dcp) ? 1 : 0); @@ -358,12 +360,22 @@ static int dptxport_call_get_max_link_rate(struct apple_epic_service *service, void *reply_, size_t reply_size) { struct dptxport_apcall_link_rate *reply = reply_; + struct apple_dcp *dcp = service->ep->dcp; + u32 link_rate = LINK_RATE_HBR3; if (reply_size < sizeof(*reply)) return -EINVAL; + /* + * A T6050 DP tunnel's pixel clock runs UHBR10 and UHBR20 as well + * (not UHBR13.5); DCP picks the 128b/132b rates the sink and the + * tunnel's capabilities allow, up to this one. + */ + if (dcp->dptx_tunnel && of_device_is_compatible(dcp->dev->of_node, "apple,t6050-dcpext")) + link_rate = LINK_RATE_UHBR20; + reply->retcode = cpu_to_le32(0); - reply->link_rate = cpu_to_le32(LINK_RATE_HBR3); + reply->link_rate = cpu_to_le32(link_rate); return 0; } @@ -380,8 +392,11 @@ static int dptxport_call_get_max_lane_count(struct apple_epic_service *service, if (reply_size < sizeof(*reply)) return -EINVAL; - if (!dptx->atcphy) { - /* USB4 DP IN: no ATC DP PHY to validate. */ + if (!dptx->atcphy || dcp->dptx_tunnel) { + /* + * USB4 DP IN: nothing to validate. A T6050 tunnel's ATC PHY only + * provides its pixel clock. + */ dptx->lane_count = 4; reply->retcode = cpu_to_le32(0); reply->lane_count = cpu_to_le64(4); @@ -592,11 +607,20 @@ static int dptxport_call_set_link_rate(struct apple_epic_service *service, phy_link_rate = 8100; phy_set_rate = true; break; + case LINK_RATE_UHBR10: + case LINK_RATE_UHBR20: + /* Only a tunnel's pixel clock takes a 128b/132b rate. */ + if (!service->ep->dcp->dptx_tunnel) + goto unsupported; + phy_link_rate = link_rate == LINK_RATE_UHBR10 ? 10000 : 20000; + phy_set_rate = true; + break; case 0: phy_link_rate = 0; phy_set_rate = true; break; default: +unsupported: dev_err(service->ep->dcp->dev, "DPTXPort: Unsupported link rate 0x%x requested\n", link_rate); @@ -615,8 +639,9 @@ static int dptxport_call_set_link_rate(struct apple_epic_service *service, if (dptx->atcphy && service->ep->dcp->dptx_tunnel) { ret = dcp_tunnel_set_rate(service->ep->dcp, dptx->atcphy, dptx->unit, link_rate); - /* T6030 14.7: refuse a rate whose tunnel clock failed. */ - if (ret && service->ep->dcp->fw_compat == DCP_FIRMWARE_V_14_7) { + /* 14.7 and 27: refuse a rate whose tunnel clock failed. */ + if (ret && (service->ep->dcp->fw_compat == DCP_FIRMWARE_V_14_7 || + service->ep->dcp->fw_compat == DCP_FIRMWARE_V_27_0)) { reply->retcode = cpu_to_le32(1); reply->link_rate = cpu_to_le32(dptx->link_rate); return 0; @@ -767,9 +792,10 @@ dptxport_call_activate(struct apple_epic_service *service, } if (dcp->dptx_tunnel) { ret = dcp_tunnel_dpin_activate(dcp, dptx->unit, true); + if (ret) + dev_err(dcp->dev, "DPTX tunnel activation failed: %d\n", ret); /* T6030 14.7: report a failed tunnel activation to DCP. */ if (ret && dcp->fw_compat == DCP_FIRMWARE_V_14_7) { - dev_err(dcp->dev, "DPTX tunnel activation failed: %d\n", ret); if (reply_size < sizeof(__le32)) return -EINVAL; memcpy(reply, data, min(reply_size, data_size)); @@ -874,6 +900,9 @@ static int dptxport_call(struct apple_epic_service *service, u32 idx, if (!ret && service->ep->dcp->dptx_tunnel && dptx->link_rate) { int xret = dcp_tunnel_crossbar_up(service->ep->dcp, dptx->unit); + if (xret) + dev_err(service->ep->dcp->dev, + "DPTX tunnel crossbar up failed: %d\n", xret); /* T6030 14.7: fail the link config without a crossbar. */ if (service->ep->dcp->fw_compat == DCP_FIRMWARE_V_14_7) ret = xret; @@ -920,6 +949,19 @@ static int dptxport_call(struct apple_epic_service *service, u32 idx, case DPTX_APCALL_GET_MAX_DRIVE_SETTINGS: return dptxport_call_get_max_drive_settings(service, reply, reply_size); + case DPTX_APCALL_SET_RESOURCE_AVAILABLE: + /* Firmware 27 reports that a DPTX resource is available again. */ + dev_dbg(service->ep->dcp->dev, "DPTXPort: SET_RESOURCE_AVAILABLE\n"); + memcpy(reply, data, min(reply_size, data_size)); + if (reply_size >= 4) + memset(reply, 0, 4); + return 0; + case DPTX_APCALL_GET_VIRTUAL_DEVICE_MODE: + /* Asked on every connect: a real display, no virtual device mode. */ + if (reply_size < sizeof(struct dptxport_apcall_get_support)) + return -EINVAL; + memset(reply, 0, reply_size); + return 0; case DPTX_APCALL_DEVICE_NOT_RESPONDING: case DPTX_APCALL_DEVICE_BUSY_TIMEOUT: case DPTX_APCALL_DEVICE_NOT_STARTED: @@ -1087,12 +1129,6 @@ static int dptxport_v2_group_call(struct apple_epic_service *service, u16 group, return -EOPNOTSUPP; if (command == DPTX_APCALL_SET_DRIVE_SETTINGS) return -EOPNOTSUPP; - if (command == DPTX_APCALL_GET_VIRTUAL_DEVICE_MODE) { - if (room < sizeof(struct dptxport_apcall_get_support)) - return -EINVAL; - memset(reply, 0, room); - return 0; - } if (command == DPTX_APCALL_GET_DRIVE_SETTINGS) return dptx_j700_training(service, false, data, size, reply, room); return dptxport_call(service, command, data, size, reply, room); @@ -1138,6 +1174,13 @@ static int dptxport_group_call(struct apple_epic_service *service, u16 group, return dptxport_v2_group_call(service, group, command, data, size, reply, room); + /* + * Firmware 27: bit 0 of the group word only flags a variable-length + * payload. Both share one call table, so dispatch by command. + */ + if (service->ep->dcp->fw_compat == DCP_FIRMWARE_V_27_0) + group &= ~1; + /* Legacy dispatch is by command, except the tested 13.5 group-1 calls. */ if (service->ep->dcp->fw_compat == DCP_FIRMWARE_V_13_5 && group == 1 && (command == 3 || command == 4)) @@ -1183,6 +1226,7 @@ static const struct apple_epic_service_ops dptxep_ops[] = { .prepare = dptxport_prepare, .teardown = dptxport_teardown, .init = dptxport_init, + .init_props = dptxport_init_props, .call = dptxport_call, .call_v2 = dptxport_group_call, }, @@ -1238,13 +1282,6 @@ static int dptxport_compact_call(struct apple_epic_service *service, u16 group, return dptxport_compact_group1(command, data, size, reply, room); if (group) return -EOPNOTSUPP; - /* Asked on every connect; no virtual device is supported. */ - if (command == DPTX_APCALL_GET_VIRTUAL_DEVICE_MODE) { - if (room < sizeof(struct dptxport_apcall_get_support)) - return -EINVAL; - memset(reply, 0, room); - return 0; - } return dptxport_call(service, command, data, size, reply, room); } diff --git a/drivers/gpu/drm/apple/dptxep.h b/drivers/gpu/drm/apple/dptxep.h index 11cd860f9ee34..a088727c57a98 100644 --- a/drivers/gpu/drm/apple/dptxep.h +++ b/drivers/gpu/drm/apple/dptxep.h @@ -31,6 +31,7 @@ enum dptx_apcall { DPTX_APCALL_DEVICE_NOT_RESPONDING = 22, DPTX_APCALL_DEVICE_BUSY_TIMEOUT = 23, DPTX_APCALL_DEVICE_NOT_STARTED = 24, + DPTX_APCALL_SET_RESOURCE_AVAILABLE = 25, DPTX_APCALL_GET_VIRTUAL_DEVICE_MODE = 26, }; @@ -45,6 +46,9 @@ enum dptx_link_rate { LINK_RATE_HBR = 0x0a, LINK_RATE_HBR2 = 0x14, LINK_RATE_HBR3 = 0x1e, + /* 128b/132b: 0x80 | the rate's DPCD 0x2215 bit */ + LINK_RATE_UHBR10 = 0x81, + LINK_RATE_UHBR20 = 0x82, }; struct apple_epic_service; @@ -66,6 +70,13 @@ struct dptx_port { u32 drive_settings[2]; u32 trained_voltage[4], trained_pre[4]; u32 drive_voltage[4], drive_pre[4]; + /* + * Firmware 27 on a Thunderbolt DP tunnel: the drive settings DCP last + * set, {mode, voltage swing, pre-emphasis} per lane, as it sent them. + * Nothing applies them; GetDriveSettings returns them. + */ + u32 tunnel_drive[4][3]; + u32 tunnel_drive_count; /* * The sink's tile topology as DCP reports it in SetTiledDisplayHints: * tiles across and down, and this stream's tile. Valid once diff --git a/drivers/gpu/drm/apple/iomfb.c b/drivers/gpu/drm/apple/iomfb.c index 5a660cb495dc2..b88a5bde04216 100644 --- a/drivers/gpu/drm/apple/iomfb.c +++ b/drivers/gpu/drm/apple/iomfb.c @@ -941,6 +941,34 @@ void dcp_push(struct apple_dcp *dcp, bool oob, in_len, out_len, data, cb, cookie); } +/* + * Push one command on the independent OOB command stream while a transaction + * on the command stream is still pending (dcp_push() would queue it behind + * that transaction). For queries the firmware serves concurrently, such as a + * paired modeset's DSC handoff while the primary's A413 waits for its peer. + */ +int dcp_push_oob_concurrent(struct apple_dcp *dcp, const struct dcp_method_entry *call, + u32 in_len, u32 out_len, void *data, dcp_callback_t cb, + void *cookie) +{ + int ret = 0; + + mutex_lock(&dcp->iomfb.lock); + if (READ_ONCE(dcp->crashed) || dcp->iomfb.stopped) { + ret = -ESHUTDOWN; + } else if (dcp->ch_oobcmd.depth || dcp->ch_oobcb.depth || dcp->ch_oobasync.depth || + READ_ONCE(dcp->iomfb.owner)) { + ret = -EBUSY; + } else { + WRITE_ONCE(dcp->iomfb.owner, current); + dcp_push_context(dcp, dcp_call_context(dcp, true), call, + in_len, out_len, data, cb, cookie); + WRITE_ONCE(dcp->iomfb.owner, NULL); + } + mutex_unlock(&dcp->iomfb.lock); + return ret; +} + /* A nested query must return on the firmware-initiated stream it answers. */ int dcp_push_nested(struct apple_dcp *dcp, enum dcp_context_id origin, const struct dcp_method_entry *call, u32 in_len, u32 out_len, diff --git a/drivers/gpu/drm/apple/iomfb_internal.h b/drivers/gpu/drm/apple/iomfb_internal.h index 5d32a1c034e91..9bb6323d49c79 100644 --- a/drivers/gpu/drm/apple/iomfb_internal.h +++ b/drivers/gpu/drm/apple/iomfb_internal.h @@ -100,6 +100,9 @@ typedef void (*dcp_callback_t)(struct apple_dcp *, void *, void *); } /* Call a DCP function given by a tag */ +int dcp_push_oob_concurrent(struct apple_dcp *dcp, const struct dcp_method_entry *call, + u32 in_len, u32 out_len, void *data, dcp_callback_t cb, + void *cookie); void dcp_push(struct apple_dcp *dcp, bool oob, const struct dcp_method_entry *call, u32 in_len, u32 out_len, void *data, dcp_callback_t cb, void *cookie); diff --git a/drivers/gpu/drm/apple/iomfb_template.c b/drivers/gpu/drm/apple/iomfb_template.c index 165d864ff3302..88aa5ef951b82 100644 --- a/drivers/gpu/drm/apple/iomfb_template.c +++ b/drivers/gpu/drm/apple/iomfb_template.c @@ -2530,6 +2530,21 @@ void DCP_FW_NAME(iomfb_poweroff)(struct apple_dcp *dcp) struct dcp_wait_cookie *poff_cookie; typeof(DCP_FW_SWAP(dcp)) *swap = &DCP_FW_SWAP(dcp); +#if (DCP_FW_H17(DCP_FW_VER) && DCP_FW_VER >= DCP_FW_VERSION(27, 0, 0)) + /* + * Firmware 27 has its own paired stop sequence. Its hardware profile + * does not use H17G's single-pipe methods, so stop an active pair + * before applying the guard for the single-pipe path below. + */ + ret = dcp_peer_stop_v27(dcp); + if (ret < 0) { + dev_err(dcp->dev, "paired power-off failed: %d\n", ret); + return; + } + if (ret > 0) + goto close_client; +#endif + #if DCP_FW_H17(DCP_FW_VER) /* H17P has no known safe pipe-off or surface-free transition. */ if (dcp->hw.iomfb_method_profile != DCP_IOMFB_METHODS_H17G) @@ -2544,17 +2559,6 @@ void DCP_FW_NAME(iomfb_poweroff)(struct apple_dcp *dcp) if (ret > 0) goto peer_stopped; #endif - -#if (DCP_FW_H17(DCP_FW_VER) && DCP_FW_VER >= DCP_FW_VERSION(27, 0, 0)) - ret = dcp_peer_stop_v27(dcp); - if (ret < 0) { - dev_err(dcp->dev, "paired power-off failed: %d\n", ret); - return; - } - if (ret > 0) - goto close_client; -#endif - cookie = kzalloc(sizeof(*cookie), GFP_KERNEL); if (!cookie) return; diff --git a/include/linux/soc/apple/dp-tunnel.h b/include/linux/soc/apple/dp-tunnel.h index 1597e338eca45..8b0eb38ceb099 100644 --- a/include/linux/soc/apple/dp-tunnel.h +++ b/include/linux/soc/apple/dp-tunnel.h @@ -19,7 +19,7 @@ struct phy; /* * appledrm: route a display pipeline to (active) or away from (!active) the - * crossbar output of DP IN adapter @dpin (0/1) of the router wired to + * crossbar output of DP IN adapter @dpin (0-3) of the router wired to * @connector_np. @set_active(@binding, active) runs the DP IN adapter's * DPTX_INACTIVE handshake and is called back from DCP's link activation. * Activation returns -EBUSY while no pipeline is free for the stream (or a @@ -38,6 +38,21 @@ int apple_dcp_tb_dp_tunnel(struct device_node *connector_np, unsigned int dpin, u64 generation, bool active, int (*set_active)(void *binding, bool active), void *binding); +/* The sink raised IRQ_HPD on the tunnel's DP IN adapter. */ +#define APPLE_DP_TUNNEL_IRQ_HPD BIT(0) +/* The HPD level of the tunnel's DP IN adapter changed to @hpd. */ +#define APPLE_DP_TUNNEL_HPD_CHANGED BIT(1) + +/* + * appledrm: pass interrupt @events (APPLE_DP_TUNNEL_*) of DP IN adapter + * @dpin of the router wired to @connector_np to the display pipeline that + * holds the tunnel handed over with @generation. The pipeline's DPTX port + * gets them as a DP source's HPD input does. Returns -ESTALE if no + * pipeline holds that tunnel. Does not wait for DCP; may sleep. + */ +int apple_dcp_tb_dp_event(struct device_node *connector_np, unsigned int dpin, + u64 generation, unsigned int events, bool hpd); + /* * ATC PHY: start the pixel clock for a DP tunnel at DP link rate code @rate, * or stop it (@rate == 0). The PHY must be in Thunderbolt/USB4 mode. @@ -214,6 +229,32 @@ static inline bool apple_dp_tunnel_route_wired(struct device_node *route, return wired && apple_dp_tunnel_wiring_dual(endpoints, named[0], named[1], legacy); } +/* + * The graph port of USB-C connector @connector_np that carries its display + * routes: the first port with an endpoint leading to a route of a display + * pipeline's "typec-routes" node. Most boards put them on port 3; a board + * whose port 3 is taken by the USB4 router uses another one. Without such an + * endpoint, port 3, if present. Returns a reference to the port node, or NULL. + */ +static inline struct device_node * +apple_dp_tunnel_routes_port(struct device_node *connector_np) +{ + if (!connector_np) + return NULL; + for_each_of_graph_port(connector_np, port) { + for_each_of_graph_port_endpoint(port, endpoint) { + struct device_node *route __free(device_node) = + of_graph_get_remote_port_parent(endpoint); + struct device_node *routes __free(device_node) = + route ? of_get_parent(route) : NULL; + + if (routes && of_node_name_eq(routes, "typec-routes")) + return of_node_get(port); + } + } + return of_graph_get_port_by_id(connector_np, 3); +} + /* * DT wiring only: no DCP registration, firmware or display status. * Two candidates alone (e.g. j314) are single-stream. Named DPIN0/1 controls, @@ -228,7 +269,7 @@ static inline bool apple_dp_tunnel_dual_stream(struct device_node *connector_np) if (!connector_np) return false; - port = of_graph_get_port_by_id(connector_np, 3); + port = apple_dp_tunnel_routes_port(connector_np); for_each_child_of_node_scoped(port, endpoint) endpoints++; if (endpoints < 2)