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
8 changes: 8 additions & 0 deletions drivers/gpu/drm/apple/dcp-fabric-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -531,5 +531,13 @@ bool dcp_fabric_t6030_link(bool tunnel, bool has_xbar, bool t6030_dpin)
}
EXPORT_SYMBOL_GPL(dcp_fabric_t6030_link);

bool dcp_fabric_merged_fits(unsigned int displays, unsigned int extra,
unsigned int engines)
{
return displays && extra && displays < engines &&
extra < engines - displays;
}
EXPORT_SYMBOL_GPL(dcp_fabric_merged_fits);

MODULE_DESCRIPTION("Apple display fabric decisions");
MODULE_LICENSE("Dual MIT/GPL");
14 changes: 14 additions & 0 deletions drivers/gpu/drm/apple/dcp-fabric-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,18 @@ u32 dcp_fabric_port_crtc_mask(bool secondary, bool ordered_dual, bool typec_only
enum dcp_fabric_attach_action dcp_fabric_attach_action(bool external);
bool dcp_fabric_t6030_link(bool tunnel, bool has_xbar, bool t6030_dpin);

/*
* T6050's platform limit on merged (dual-pipe) modes: whether a display may
* take a mode its own engine cannot drive, @extra engines more than its own,
* while @displays external displays, it included, are present on the
* platform's @engines external display engines. A full pair is given only
* while the displays and the pair leave an external engine unused; on the
* four engines of a T6050, a display pairs alone or with one other external
* display present, not with two. Otherwise the platform offers only a limited
* pipe, which the driver does not implement, and the display runs on its own
* engine at a timing that one engine drives.
*/
bool dcp_fabric_merged_fits(unsigned int displays, unsigned int extra,
unsigned int engines);

#endif /* __APPLE_DCP_FABRIC_CORE_H__ */
65 changes: 65 additions & 0 deletions drivers/gpu/drm/apple/dcp-fabric-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2345,6 +2345,70 @@ static void relink_stamp_test(struct kunit *test)
KUNIT_EXPECT_TRUE(test, dcp_relink_unplug(&s, 1, 3));
}

/*
* T6050's limit on merged modes, on its four external engines (one of them an
* unrouted peer): a display that needs a pair gets it alone and with one other
* external display present, not with two, whichever order the three come in,
* and gets it back once one of the others leaves.
*/
static void fabric_t6050_merged_limit_test(struct kunit *test)
{
/* One display on direct DP, one in the same dock as the paired one. */
enum { DIRECT, DOCK, PAIRED, NR };
static const u8 orders[][NR] = {
{ DIRECT, DOCK, PAIRED }, /* direct first, the dock's other before it */
{ DIRECT, PAIRED, DOCK }, /* the dock's other after it */
{ DOCK, PAIRED, DIRECT }, /* the dock first */
{ DOCK, DIRECT, PAIRED },
{ PAIRED, DOCK, DIRECT }, /* the paired one first */
{ PAIRED, DIRECT, DOCK },
};
const unsigned int engines = 4;
unsigned int o, i, j;

KUNIT_EXPECT_TRUE(test, dcp_fabric_merged_fits(1, 1, engines));
KUNIT_EXPECT_TRUE(test, dcp_fabric_merged_fits(2, 1, engines));
KUNIT_EXPECT_FALSE(test, dcp_fabric_merged_fits(3, 1, engines));
KUNIT_EXPECT_FALSE(test, dcp_fabric_merged_fits(4, 1, engines));
KUNIT_EXPECT_FALSE(test, dcp_fabric_merged_fits(5, 1, engines));
/* No display, no pair asked for, no engine to spare, no wrap. */
KUNIT_EXPECT_FALSE(test, dcp_fabric_merged_fits(0, 1, engines));
KUNIT_EXPECT_FALSE(test, dcp_fabric_merged_fits(1, 0, engines));
KUNIT_EXPECT_FALSE(test, dcp_fabric_merged_fits(1, 1, 2));
KUNIT_EXPECT_FALSE(test, dcp_fabric_merged_fits(1, UINT_MAX, engines));
KUNIT_EXPECT_FALSE(test, dcp_fabric_merged_fits(UINT_MAX, 1, engines));

for (o = 0; o < ARRAY_SIZE(orders); o++) {
bool present[NR] = {};

for (i = 0; i < NR; i++) {
unsigned int others;
bool fits;

present[orders[o][i]] = true;
if (!present[PAIRED])
continue;
/*
* The paired display counts itself from its display hints
* on, which come before it is reported connected.
*/
others = present[DIRECT] + present[DOCK];
fits = dcp_fabric_merged_fits(others + 1, 1, engines);
KUNIT_EXPECT_EQ_MSG(test, fits, others <= 1, "order %u, step %u", o, i);
}
/* From all three, either other one leaving gives the pair back. */
for (j = DIRECT; j <= DOCK; j++) {
unsigned int displays;

present[j] = false;
displays = present[DIRECT] + present[DOCK] + present[PAIRED];
KUNIT_EXPECT_TRUE_MSG(test, dcp_fabric_merged_fits(displays, 1, engines),
"order %u, display %u unplugged", o, j);
present[j] = true;
}
}
}

/*
* A refused T8132 tunnel clock stays refused through stops, failed or not,
* and only a nonzero rate taken clears it: refused, 0, refused is one
Expand Down Expand Up @@ -2377,6 +2441,7 @@ static void fabric_t8132_clock_refused_test(struct kunit *test)

static struct kunit_case fabric_tests[] = {
KUNIT_CASE(fabric_t8132_clock_refused_test),
KUNIT_CASE(fabric_t6050_merged_limit_test),
KUNIT_CASE(relink_unplug_test),
KUNIT_CASE(relink_running_test),
KUNIT_CASE(relink_budget_test),
Expand Down
6 changes: 6 additions & 0 deletions drivers/gpu/drm/apple/dcp-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,12 @@ struct apple_dcp {
struct delayed_work hybrid_wq;
struct dcp_peer_tiling peer_tiling;
bool peer_unbinding;
/*
* T6050: the platform limit left this display no pair when last
* evaluated (dcp_peer_hints_v27(), dcp_peer_limit_update_v27()). Under
* dcp_peer_lock.
*/
bool peer_limited;
/* Firmware display endpoint (its Disp_Index), apple,dcp-endpoint;
* separate from index, which also selects the doorbell and PHY mode. */
u32 peer_endpoint;
Expand Down
73 changes: 72 additions & 1 deletion drivers/gpu/drm/apple/dcp-peer-runtime-v27.inc
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,69 @@ static void dcp_peer_finish_v27(struct apple_dcp *dcp, struct apple_dcp *peer)
le32_to_cpu(tile[0]), le32_to_cpu(tile[1]));
}

/*
* While the platform limit leaves the display no pair, it is set one of the
* modes one engine drives (dcp_peer_check_v27()), and no paired call runs for
* it. A pair it ran is stopped first: both engines powered off, the peer left
* off and this engine powered on again. -EOPNOTSUPP then has the caller set
* the mode on this engine alone.
*/
static bool dcp_peer_limited_pair_locked(struct apple_dcp *dcp, bool *prepared)
{
struct apple_dcp *peer = dcp->peer_reserved;

lockdep_assert_held(&dcp_peer_lock);
*prepared = false;
if (!peer || !dcp_peer_limited_locked(dcp, NULL, NULL))
return false;
*prepared = dcp->peer_tiling.vftg || peer->peer_tiling.vftg;
return true;
}

static int dcp_peer_limited_stop_v27(struct apple_dcp *dcp, struct apple_dcp *peer)
{
u8 power[16] = {1}, response[8];
int ret;

ret = dcp_peer_probe_quiesce(dcp, peer);
if (ret)
return ret;
ret = dcp_peer_video_call(dcp, "A484", power, sizeof(power),
response, sizeof(response));
if (ret || get_unaligned_le32(response + 4))
return ret ?: -EIO;
dev_info(dcp->dev, "platform limit: pair stopped, its peer left off\n");
return -EOPNOTSUPP;
}

int dcp_peer_modeset_v27(struct apple_dcp *dcp, u32 timing, u32 color, u32 min_vrr)
{
struct apple_dcp *peer;
bool limited, prepared;
int ret = -EOPNOTSUPP;

if (!peer_scanout || !peer_allocation_probe ||
dcp->fw_compat != DCP_FIRMWARE_V_27_0)
return ret;
if (timing > U32_MAX - 10000 || color > U32_MAX - 10000)
return -EINVAL;
/* No paired call, nor wait for one, for a display the limit leaves no pair. */
scoped_guard(mutex, &dcp_peer_lock) {
limited = dcp_peer_limited_pair_locked(dcp, &prepared);
if (limited && !prepared)
return ret;
}
if (!device_trylock(dcp->dev))
return -EBUSY;
{
guard(mutex)(&dcp_peer_lock);
peer = dcp->peer_reserved;
if (!peer)
goto unlock;
/* The limit may have come or gone since the check above. */
limited = dcp_peer_limited_pair_locked(dcp, &prepared);
if (limited && !prepared)
goto unlock;
if (peer->peer_owner != dcp || !dcp_peer_transport_idle(dcp) ||
!dcp_peer_transport_idle(peer) || peer->fixed_phy ||
peer->nr_typec_routes || !peer->crtc ||
Expand All @@ -100,6 +146,10 @@ int dcp_peer_modeset_v27(struct apple_dcp *dcp, u32 timing, u32 color, u32 min_v
goto unlock;
}
}
if (limited) {
ret = dcp_peer_limited_stop_v27(dcp, peer);
goto peer_unlock;
}
ret = dcp_peer_prepare_v27(dcp, peer, min_vrr);
if (ret)
goto peer_unlock;
Expand Down Expand Up @@ -127,13 +177,23 @@ bool dcp_peer_needs_pair_v27(struct apple_dcp *dcp, u32 clock_khz)
return dcp->fw_compat == DCP_FIRMWARE_V_27_0 && rate && (u64)clock_khz * 1000 > rate;
}

/* A timing only a pair drives, while the platform limit leaves no pair. */
bool dcp_peer_mode_limited_v27(struct apple_dcp *dcp, u32 clock_khz)
{
if (!dcp_peer_needs_pair_v27(dcp, clock_khz))
return false;
guard(mutex)(&dcp_peer_lock);
return dcp_peer_limited_locked(dcp, NULL, NULL);
}

/*
* At atomic check: refuse a paired timing the pair cannot take, so that the
* commit fails instead of a mode set that leaves the CRTC without a timing.
* The peer's CRTC is not taken into the commit; its current state is read.
* A CRTC being enabled reserves its peer when the link comes up, in
* dcp_poweron() after this check; iomfb_modeset() refuses the timing then
* if no peer was reserved.
* if no peer was reserved. While the platform limit leaves the display no
* pair, a paired timing is refused whatever the peer's state.
*/
int dcp_peer_check_v27(struct apple_dcp *dcp, struct drm_atomic_commit *commit,
struct drm_crtc_state *crtc_state)
Expand All @@ -157,7 +217,18 @@ int dcp_peer_check_v27(struct apple_dcp *dcp, struct drm_atomic_commit *commit,
return -EINVAL;
scoped_guard(mutex, &dcp_peer_lock) {
struct apple_dcp *peer = dcp->peer_reserved;
unsigned int displays, engines;

/* Not even for a CRTC being enabled: the limit has no pair to give. */
if (dcp_peer_limited_locked(dcp, &displays, &engines)) {
dev_info_ratelimited(dcp->dev,
"mode %ux%u@%u refused: %u external displays on %u engines leave no pair\n",
crtc_state->mode.hdisplay,
crtc_state->mode.vdisplay,
drm_mode_vrefresh(&crtc_state->mode),
displays, engines);
return -EINVAL;
}
if (!peer && crtc_state->active_changed)
return 0;
if (!peer || peer->peer_owner != dcp || peer->fixed_phy ||
Expand Down
115 changes: 115 additions & 0 deletions drivers/gpu/drm/apple/dcp-peer-v27.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,105 @@ static bool peer_allocation_probe = true;
module_param(peer_allocation_probe, bool, 0444);
MODULE_PARM_DESC(peer_allocation_probe, "Firmware27 logical peer allocation for merged modes (default: on)");

/*
* The platform limit on merged modes (dcp_fabric_merged_fits()) holds on the
* board it has run on, for the J714s's T6050 external display processors.
*/
static bool dcp_peer_limit_applies(struct apple_dcp *dcp)
{
return dcp->fw_compat == DCP_FIRMWARE_V_27_0 && dcp_j714s_ext(dcp->dev);
}

/*
* Whether the platform limit leaves @dcp's display no pair. The external
* engines of its DRM device are counted, and the external displays present on
* them: its own always, since its display hints come before its connector is
* reported connected.
*/
static bool dcp_peer_limited_locked(struct apple_dcp *dcp, unsigned int *displays,
unsigned int *engines)
{
unsigned int present = 0, count = 0;
struct drm_crtc *crtc;

lockdep_assert_held(&dcp_peer_lock);
if (!dcp_peer_limit_applies(dcp) || !dcp->crtc)
return false;
drm_for_each_crtc(crtc, dcp->crtc->base.dev) {
struct apple_dcp *p = platform_get_drvdata(to_apple_crtc(crtc)->dcp);
struct apple_connector *con;

if (!p || !dcp_peer_limit_applies(p))
continue;
count++;
con = READ_ONCE(p->connector);
if (p == dcp || (con && READ_ONCE(con->connected)))
present++;
}
if (displays)
*displays = present;
if (engines)
*engines = count;
/* The pair this driver sets up takes one engine more. */
return !dcp_fabric_merged_fits(present, 1, count);
}

/* More than the display processors of any board with the limit. */
#define DCP_PEER_LIMIT_DISPLAYS 8

/*
* An external display of @drm came or went: the platform limit may now give
* another display its pair, or take it away. Have the connector of each
* display whose limit changed probed again, so that its merged modes are
* offered only while a pair fits (dcp_mode_valid()). A display that runs a
* pair when the limit takes it away is also reported with a bad link, for the
* compositor to set one of the modes it is left with.
*/
void dcp_peer_limit_update_v27(struct drm_device *drm)
{
struct apple_connector *probe[DCP_PEER_LIMIT_DISPLAYS];
bool bad[DCP_PEER_LIMIT_DISPLAYS];
unsigned int n = 0, i;
struct drm_crtc *crtc;

/* Neither a board without the limit nor a device without CRTCs. */
if (!of_machine_is_compatible("apple,j714s") || !drm->mode_config.num_crtc)
return;
scoped_guard(mutex, &dcp_peer_lock) {
drm_for_each_crtc(crtc, drm) {
struct apple_dcp *p = platform_get_drvdata(to_apple_crtc(crtc)->dcp);
unsigned int displays = 0, engines = 0;
struct apple_connector *con;
bool limited;

if (!p || !dcp_peer_limit_applies(p))
continue;
limited = dcp_peer_limited_locked(p, &displays, &engines);
if (limited == p->peer_limited)
continue;
p->peer_limited = limited;
/* Only a display with merged modes has a peer reserved. */
con = READ_ONCE(p->connector);
if (!con || !READ_ONCE(con->connected) || !p->peer_reserved ||
n == ARRAY_SIZE(probe))
continue;
dev_info(p->dev, "platform limit: %u external displays on %u engines: %s\n",
displays, engines, limited ?
"no pair, modes beyond one engine withdrawn" :
"a pair fits, modes beyond one engine offered again");
probe[n] = con;
bad[n++] = limited && (p->peer_frames.active || p->peer_tiling.vftg);
}
}
/* Outside dcp_peer_lock: atomic check takes it under the modeset locks. */
for (i = 0; i < n; i++) {
if (bad[i])
drm_connector_set_link_status_property(&probe[i]->base,
DRM_MODE_LINK_STATUS_BAD);
dcp_queue_hotplug(probe[i]);
}
}

bool dcp_peer_tiling_state_v27(struct apple_dcp *dcp, bool write,
u32 event, u32 param, u32 *value)
{
Expand Down Expand Up @@ -142,6 +241,22 @@ int dcp_peer_hints_v27(struct apple_dcp *dcp, struct dptx_port *port,
get_unaligned_le32(r->hints + 0x40),
get_unaligned_le32(r->hints + 0x44));
}
/*
* The platform limit keeps the reservation: the peer is an engine no
* display is routed to, and the firmware keeps the merged timings for
* when a pair fits again (dcp_peer_limit_update_v27()). Until then DRM
* offers only the modes one engine drives; a mode set of one of them
* runs no paired call: it stops a pair that ran, leaving the peer off,
* and sets the mode on this engine alone (dcp_peer_modeset_v27()).
*/
{
unsigned int displays, engines;

dcp->peer_limited = dcp_peer_limited_locked(dcp, &displays, &engines);
if (dcp->peer_limited)
dev_info(dcp->dev, "platform limit: %u external displays on %u engines: no pair, modes beyond one engine withheld\n",
displays, engines);
}
/* The display allocation update writes primary/peer endpoint IDs.
* The extra pipe count supplies byte8. This is full dual-pipe, so the
* T6050 limited-dual-pipe flag (byte9 bit1) remains clear.
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/apple/dcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ bool dcp_peer_tiling_state_v27(struct apple_dcp *dcp, bool write,
void dcp_peer_display_ids_v27(struct apple_dcp *dcp, u32 own, u32 related);
int dcp_peer_modeset_v27(struct apple_dcp *dcp, u32 timing, u32 color, u32 min_vrr);
bool dcp_peer_needs_pair_v27(struct apple_dcp *dcp, u32 clock_khz);
bool dcp_peer_mode_limited_v27(struct apple_dcp *dcp, u32 clock_khz);
void dcp_peer_limit_update_v27(struct drm_device *drm);
int dcp_peer_check_v27(struct apple_dcp *dcp, struct drm_atomic_commit *commit,
struct drm_crtc_state *crtc_state);
int dcp_peer_color_v27(struct apple_dcp *dcp, struct iomfb_set_matrix_req *matrix);
Expand Down
Loading
Loading