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
28 changes: 5 additions & 23 deletions drivers/gpu/drm/apple/afk.c
Original file line number Diff line number Diff line change
Expand Up @@ -1127,24 +1127,11 @@ static void afk_recv_handle_compact_init(struct apple_dcp_afkep *ep,
ep->endpoint);
return;
}
service = afk_epic_find_service(ep, channel);
if (service) {
u32 gen = READ_ONCE(ep->dcp->afk_power_gen);

if (service->power_gen == gen ||
READ_ONCE(ep->compact_rebind_gen) != gen) {
dev_warn(ep->dcp->dev,
"AFK[ep:%02x]: duplicate compact service on interface %u\n",
ep->endpoint, channel);
return;
}
dev_info(ep->dcp->dev,
"AFK[ep:%02x]: retiring stale compact service %s on interface %u\n",
ep->endpoint, service->name, channel);
afk_remove_service_debugfs(service);
afk_service_retire(service);
if (service->ops->teardown)
service->ops->teardown(service);
if (afk_epic_find_service(ep, channel)) {
dev_warn(ep->dcp->dev,
"AFK[ep:%02x]: duplicate compact service on interface %u\n",
ep->endpoint, channel);
return;
}
memcpy(wire_name, payload, AFK_COMPACT_NAME_LEN);
wire_name[AFK_COMPACT_NAME_LEN] = '\0';
Expand Down Expand Up @@ -1206,12 +1193,7 @@ static void afk_recv_handle_compact_init(struct apple_dcp_afkep *ep,
dev_err(ep->dcp->dev,
"AFK[ep:%02x]: failed to start compact service %u: %d\n",
ep->endpoint, channel, ret);
spin_lock_irqsave(&ep->lock, flags);
if (!ep->compact_start_err)
WRITE_ONCE(ep->compact_start_err, ret);
spin_unlock_irqrestore(&ep->lock, flags);
afk_service_discard(service);
wake_up_all(&ep->service_wq);
return;
}
}
Expand Down
2 changes: 0 additions & 2 deletions drivers/gpu/drm/apple/afk.h
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,6 @@ struct apple_dcp_afkep {
u32 rx_admitted; /* lock: prefix of rx_ring admitted before rx_paused. */
bool rx_work_queued; /* lock */
bool rx_failed; /* lock: early RX ring overflowed; never reopen TX. */
int compact_start_err; /* lock: first compact protocol start failure. */
u32 compact_rebind_gen; /* power_gen authorized to retire same-channel services. */

/* Compact EPIC, detected from the first compact message (desktop 26.x). */
bool compact;
Expand Down
14 changes: 10 additions & 4 deletions drivers/gpu/drm/apple/dcp-fabric-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ bool dcp_fabric_movable(const struct dcp_fabric_route *owner,
}
EXPORT_SYMBOL_GPL(dcp_fabric_movable);

/* Can a direct DP-alt stream take @route now? */
static bool dcp_fabric_direct_available(const struct dcp_fabric_route *route,
const struct dcp_fabric_policy *policy)
{
return !route->tunnel_only && route->pipeline->services_ready &&
dcp_fabric_available(route->pipeline, policy);
}

struct dcp_fabric_route *
dcp_fabric_free_route(const struct dcp_fabric_port *port,
const struct dcp_fabric_policy *policy)
Expand All @@ -186,17 +194,15 @@ dcp_fabric_free_route(const struct dcp_fabric_port *port,
for (route = port->routes; route; route = route->next) {
unsigned int score;

if (route->tunnel_only ||
!dcp_fabric_available(route->pipeline, policy))
if (!dcp_fabric_direct_available(route, policy))
continue;
score = dcp_fabric_score(route->pipeline, policy);
if (score < best_score) {
best = route;
best_score = score;
}
}
if (!last || last->tunnel_only ||
!dcp_fabric_available(last->pipeline, policy))
if (!last || !dcp_fabric_direct_available(last, policy))
return best;
if (!policy->dual_stream && best &&
best_score < dcp_fabric_score(last->pipeline, policy))
Expand Down
23 changes: 23 additions & 0 deletions drivers/gpu/drm/apple/dcp-fabric-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -2115,6 +2115,28 @@ static void fabric_per_dpin_slot_test(struct kunit *test)
KUNIT_EXPECT_EQ(test, dcp_fabric_tunnel_slot(&port, 3, true), -EBUSY);
}

/* A pipeline whose services are gone never takes a direct DP-alt stream. */
static void fabric_direct_services_test(struct kunit *test)
{
struct fabric_fixture f;

/* Pipeline 1 would win, also as the port's last one. */
fabric_init(&f, false);
f.port[0].preferred = &f.route[0][1];
f.pipeline[1].services_ready = false;
KUNIT_EXPECT_PTR_EQ(test, dcp_fabric_free_route(&f.port[0], &f.policy),
&f.route[0][0]);
/* Its peer drives another display: the stream waits. */
f.pipeline[0].owned = true;
KUNIT_EXPECT_PTR_EQ(test, dcp_fabric_free_route(&f.port[0], &f.policy),
NULL);
/* A modeset does not move the stream there either. */
KUNIT_EXPECT_EQ(test,
dcp_fabric_follow(&f.route[0][0], &f.route[0][1],
NULL, NULL, false, &f.policy),
DCP_FABRIC_FOLLOW_REFUSE);
}

/* A tunnel-only route never takes a direct DP-alt stream. */
static void fabric_tunnel_only_test(struct kunit *test)
{
Expand Down Expand Up @@ -2667,6 +2689,7 @@ static struct kunit_case fabric_tests[] = {
KUNIT_CASE(fabric_t6030_plan_test),
KUNIT_CASE(fabric_t6030_follow_test),
KUNIT_CASE(fabric_per_dpin_slot_test),
KUNIT_CASE(fabric_direct_services_test),
KUNIT_CASE(fabric_tunnel_only_test),
KUNIT_CASE(fabric_tunnel_only_first_test),
KUNIT_CASE(fabric_reclaim_transaction_test),
Expand Down
6 changes: 3 additions & 3 deletions drivers/gpu/drm/apple/dcp-fabric.c
Original file line number Diff line number Diff line change
Expand Up @@ -1600,8 +1600,8 @@ static void dcp_fabric_snapshot_port(struct apple_dcp_typec_port *port,
dcp_typec_safe_held(dcp);
pipeline->tunnel_held = dcp_typec_tunnel_held(dcp);
pipeline->presence = dcp_hdmi_presence(dcp);
pipeline->services_ready = !tunnel ||
dcp_tb_services_ready(dcp);
pipeline->services_ready = tunnel ? dcp_tb_services_ready(dcp) :
!iomfb_m4_ext_failed(dcp);
pipeline->external = dcp->external;
route->core.pipeline = pipeline;
route->core.tunnel = route->tunnel;
Expand Down Expand Up @@ -2098,7 +2098,7 @@ static int dcp_typec_port_busy(struct apple_dcp_typec_port *port,
port->busy_noted = true;
of_property_read_string(port->connector_np, "label", &label);
dev_info(dcp->dev,
"display on %s waits for a free external display pipeline (each one drives another display); it lights up on its own when one of those displays is unplugged\n",
"display on %s waits for a free external display pipeline (each one drives another display or has failed); it lights up on its own when one of those displays is unplugged\n",
label ?: "a USB-C port");
return -ENOSPC;
}
Expand Down
13 changes: 1 addition & 12 deletions drivers/gpu/drm/apple/dptx-service.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ static inline int dptx_service_bind(struct apple_epic_service *service,
return 0;
}

static inline int dptx_service_rebind(struct apple_epic_service *service,
struct dptx_port *port, s64 unit)
{
port->unit = unit;
/* No owner is published until OPEN and AFK publication succeed. */
service->cookie = port;
return 0;
}

static inline void dptx_service_publish(struct apple_epic_service *service)
{
struct dptx_port *port = service->cookie;
Expand All @@ -65,9 +56,7 @@ static inline void dptx_service_unbind(struct apple_epic_service *service)

spin_lock_irqsave(&service->lock, flags);
if (port && port->service == service) {
/* Retain route eligibility across an authorized reset rebind. */
if (!READ_ONCE(port->rebind_allowed))
WRITE_ONCE(port->closed, true);
WRITE_ONCE(port->closed, true);
/* Make terminal state visible to readers of availability. */
smp_store_release(&port->enabled, false);
WRITE_ONCE(port->connected, false);
Expand Down
9 changes: 1 addition & 8 deletions drivers/gpu/drm/apple/dptxep.c
Original file line number Diff line number Diff line change
Expand Up @@ -1120,19 +1120,12 @@ static int dptxport_prepare(struct apple_epic_service *service, const char *name
* without a class. Unit 0 is opened last, see dptxep_init_desktop().
*/
if (READ_ONCE(service->ep->compact)) {
bool rebind;

/* Bind by name: another service on this endpoint is not a port. */
if ((unit != 0 && unit != 1) || !name || strcmp(name, "dcpdptx-port-epic"))
return -EINVAL;
rebind = READ_ONCE(dcp->dptxport[unit].rebind_allowed);
if (!unit && !rebind)
if (!unit)
service->defer_start = true;
trace_dptxport_init(dcp, unit);
if (rebind) {
WRITE_ONCE(dcp->dptxport[unit].rebind_allowed, false);
return dptx_service_rebind(service, &dcp->dptxport[unit], unit);
}
return dptx_service_bind(service, &dcp->dptxport[unit], unit);
}

Expand Down
2 changes: 0 additions & 2 deletions drivers/gpu/drm/apple/dptxep.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ struct dptx_port {
bool enabled, connected;
/* A published session closed; unlike initial discovery, this is terminal. */
bool closed;
/* T8132 dcpext restarted from CPU reset: allow rebinding on fresh announcement. */
bool rebind_allowed;
/* Compact initial discovery: hold port->enabled until startup completes. */
bool staged;
struct completion enable_completion;
Expand Down
107 changes: 21 additions & 86 deletions drivers/gpu/drm/apple/iomfb_m4.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,8 +387,6 @@ static void iomfb_m4_ext_afk_block_tx(struct iomfb_m4 *dcp, unsigned int count);

static void dcp_m4_failed(struct iomfb_m4 *dcp, int error)
{
/* Pairs with smp_store_release() in dptxep_init_desktop(). */
struct apple_dcp_afkep *dptxep = smp_load_acquire(&dcp->owner->dptxep);
unsigned long flags;
bool first;

Expand All @@ -409,8 +407,6 @@ static void dcp_m4_failed(struct iomfb_m4 *dcp, int error)
dev_err(dcp->dev, "Retained DCP session quarantined: %d\n", error);
complete_all(&dcp->reply);
dcp_m4_runtime_wake(dcp);
if (dptxep)
wake_up_all(&dptxep->service_wq);
}

static int dcp_m4_shmem_setup(void *cookie, struct apple_rtkit_shmem *bfr)
Expand Down Expand Up @@ -5875,26 +5871,6 @@ static void iomfb_m4_ext_afk_resume_rx(struct iomfb_m4 *dcp, bool replay)
afk_resume_rx(iomfb_m4_ext_afk_ep(dcp, i), replay);
}

static bool iomfb_m4_ext_dptx0_started(struct iomfb_m4 *dcp, u32 gen)
{
struct dptx_port *port = &dcp->owner->dptxport[0];
struct apple_epic_service *service;

if (!dptx_service_available(port))
return false;
service = READ_ONCE(port->service);
return service && READ_ONCE(service->power_gen) == gen &&
READ_ONCE(service->started);
}

static bool iomfb_m4_ext_dptx0_ready(struct iomfb_m4 *dcp,
struct apple_dcp_afkep *dptxep, u32 gen)
{
return READ_ONCE(dcp->error) ||
READ_ONCE(dptxep->compact_start_err) ||
iomfb_m4_ext_dptx0_started(dcp, gen);
}

static void dcp_m4_ext_reset_swap_state(struct dcp_m4_runtime *r)
{
if (!r)
Expand All @@ -5916,65 +5892,29 @@ static void dcp_m4_ext_reset_swap_state(struct dcp_m4_runtime *r)
r->ext_win[i].on_screen = false;
}

/*
* The CPU came from reset, but its firmware goes on with the image it kept:
* the AFK endpoints and the DPTX port services on them are as they were, and
* are not announced again. A sink's AV service is, once its link is back.
*/
static int iomfb_m4_ext_reset_finish(struct iomfb_m4 *dcp)
{
struct apple_dcp_afkep *dptxep =
iomfb_m4_ext_afk_ep(dcp, ARRAY_SIZE(dcp->probe_ep));
bool wait_dptx = dptxep && READ_ONCE(dptxep->compact);
unsigned long flags;
u32 gen;

spin_lock_irqsave(&dcp->state_lock, flags);
dcp->ext_avserv = NULL;
spin_unlock_irqrestore(&dcp->state_lock, flags);
dcp_m4_ext_reset_swap_state(dcp->runtime);
if (dptxep) {
if (dptxep)
afk_compact_orphans_drop(dptxep);
spin_lock_irqsave(&dptxep->lock, flags);
WRITE_ONCE(dptxep->compact_start_err, 0);
spin_unlock_irqrestore(&dptxep->lock, flags);
}
WRITE_ONCE(dcp->owner->t8132_release_late, false);
gen = READ_ONCE(dcp->owner->afk_power_gen) + 1;
WRITE_ONCE(dcp->owner->afk_power_gen, gen);
for (unsigned int i = 0; i < DCP_M4_EXT_AFK_SLOTS; i++) {
struct apple_dcp_afkep *ep = iomfb_m4_ext_afk_ep(dcp, i);

if (ep) {
afk_compact_rx_reset(ep);
WRITE_ONCE(ep->compact_rebind_gen, gen);
}
}
for (unsigned int i = 0; i < ARRAY_SIZE(dcp->owner->dptxport); i++) {
struct dptx_port *port = &dcp->owner->dptxport[i];

if (wait_dptx) {
/* Pairs with smp_load_acquire() in dptx_service_available(). */
smp_store_release(&port->enabled, false);
WRITE_ONCE(port->connected, false);
reinit_completion(&port->enable_completion);
}
WRITE_ONCE(port->rebind_allowed, true);
}
/* Replay new-session AFK words deferred during retained wake once RTKit is ON. */
for (unsigned int i = 0; i < DCP_M4_EXT_AFK_SLOTS; i++)
afk_compact_rx_reset(iomfb_m4_ext_afk_ep(dcp, i));
/* Replay AFK words deferred during retained wake once RTKit is ON. */
iomfb_m4_ext_afk_resume_rx(dcp, true);
if (wait_dptx) {
long left = wait_event_timeout(dptxep->service_wq,
iomfb_m4_ext_dptx0_ready(dcp, dptxep, gen),
msecs_to_jiffies(1000));
int err;

afk_flush_rx(dptxep);
err = READ_ONCE(dcp->error);
if (!err)
err = READ_ONCE(dptxep->compact_start_err);
if (err)
return err;
if (!iomfb_m4_ext_dptx0_started(dcp, gen))
return left ? -EIO : -ETIMEDOUT;
} else {
afk_flush_rx(dptxep);
}
afk_flush_rx(dptxep);
return READ_ONCE(dcp->error);
}

Expand Down Expand Up @@ -6102,24 +6042,11 @@ static int iomfb_m4_ext_stop(struct iomfb_m4 *dcp, bool runtime)
}
if (ret)
goto unwind;
/*
* Publish ext_idle_stopped before clearing port->enabled so route
* selection never observes a gap while the DCP transitions to idle.
*/
smp_store_release(&dcp->ext_idle_stopped, runtime);
/* The restarted firmware announces the sink's AV and DPTX services anew. */
WRITE_ONCE(dcp->ext_idle_stopped, runtime);
/* The restarted firmware announces the sink's AV service anew. */
spin_lock_irqsave(&dcp->state_lock, flags);
dcp->ext_avserv = NULL;
spin_unlock_irqrestore(&dcp->state_lock, flags);
if (dcp->owner->dptxep && READ_ONCE(dcp->owner->dptxep->compact)) {
for (unsigned int i = 0; i < ARRAY_SIZE(dcp->owner->dptxport); i++) {
struct dptx_port *port = &dcp->owner->dptxport[i];

/* Pairs with smp_load_acquire() in dptx_service_available(). */
smp_store_release(&port->enabled, false);
WRITE_ONCE(port->connected, false);
}
}
dcp->gate_cycles++;
dcp->gate_off_us = ktime_us_delta(ktime_get(), start);
if (runtime) {
Expand Down Expand Up @@ -6248,7 +6175,7 @@ static int iomfb_m4_ext_start(struct iomfb_m4 *dcp, bool runtime)
}
dcp->ext_stopped = false;
if (!ret) {
step = "DPTX ready";
step = "AFK resume";
ret = iomfb_m4_ext_reset_finish(dcp);
}
if (!ret) {
Expand Down Expand Up @@ -6363,6 +6290,14 @@ void iomfb_m4_ext_idle_kick(struct apple_dcp *owner)
mutex_unlock(&dcp->lock);
}

/* An external DCP whose session was quarantined: no display until a reboot. */
bool iomfb_m4_ext_failed(struct apple_dcp *owner)
{
struct iomfb_m4 *dcp = owner->v26_6;

return dcp && dcp->external && READ_ONCE(dcp->error);
}

bool iomfb_m4_ext_route_ready(struct apple_dcp *owner)
{
struct iomfb_m4 *dcp = owner->v26_6;
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/apple/iomfb_m4.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ void iomfb_m4_ext_relink_wait(struct apple_dcp *dcp, unsigned long deadline);
int iomfb_m4_ext_relink_end(struct apple_dcp *dcp);
bool iomfb_m4_ext_stopped(struct apple_dcp *dcp);
bool iomfb_m4_sleep_stopped(struct apple_dcp *dcp);
bool iomfb_m4_ext_failed(struct apple_dcp *dcp);
bool iomfb_m4_ext_route_ready(struct apple_dcp *dcp);
void iomfb_m4_ext_idle_kick(struct apple_dcp *dcp);
int iomfb_m4_ext_idle_wake(struct apple_dcp *dcp);
Expand Down Expand Up @@ -173,6 +174,7 @@ static inline void iomfb_m4_ext_relink_wait(struct apple_dcp *dcp, unsigned long
static inline int iomfb_m4_ext_relink_end(struct apple_dcp *dcp) { return 0; }
static inline bool iomfb_m4_ext_stopped(struct apple_dcp *dcp) { return false; }
static inline bool iomfb_m4_sleep_stopped(struct apple_dcp *dcp) { return false; }
static inline bool iomfb_m4_ext_failed(struct apple_dcp *dcp) { return false; }
static inline bool iomfb_m4_ext_route_ready(struct apple_dcp *dcp) { return false; }
static inline void iomfb_m4_ext_idle_kick(struct apple_dcp *dcp) { }
static inline int iomfb_m4_ext_idle_wake(struct apple_dcp *dcp) { return 0; }
Expand Down
Loading
Loading