Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 39 additions & 7 deletions Documentation/devicetree/bindings/display/apple,dcp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
63 changes: 34 additions & 29 deletions drivers/gpu/drm/apple/apple_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions drivers/gpu/drm/apple/connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions drivers/gpu/drm/apple/dcp-fabric-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
13 changes: 13 additions & 0 deletions drivers/gpu/drm/apple/dcp-fabric-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@
#include <linux/errno.h>
#include <linux/types.h>

/*
* 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,
Expand Down
3 changes: 2 additions & 1 deletion drivers/gpu/drm/apple/dcp-fabric-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Loading