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
29 changes: 20 additions & 9 deletions drivers/gpu/drm/apple/afk.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ static void afk_release_context(void *data)
struct apple_dcp_afkep *afkep = data;

afk_quiesce(afkep);
/* A superseded endpoint's devres must not erase its replacement route. */
if (afkep->dcp->v27_sleep_transport &&
afkep->endpoint >= 0x20 && afkep->endpoint < 0x40)
cmpxchg(&afkep->dcp->sleep_v27_ep[afkep->endpoint - 0x20], afkep, NULL);
if (!afkep->dcp->retain_dma) {
kvfree(afkep->command_tags);
kfree(afkep);
Expand Down Expand Up @@ -136,8 +140,7 @@ struct apple_dcp_afkep *afk_init(struct apple_dcp *dcp, u32 endpoint,
if (ret)
return ERR_PTR(ret);

if (IS_ENABLED(CONFIG_APPLE_SOC_SLEEP) &&
dcp->v27_j714s && endpoint >= 0x20 && endpoint < 0x40)
if (dcp->v27_sleep_transport && endpoint >= 0x20 && endpoint < 0x40)
WRITE_ONCE(dcp->sleep_v27_ep[endpoint - 0x20], afkep);
return afkep;

Expand Down Expand Up @@ -1114,7 +1117,7 @@ static void afk_compact_reply_worker(struct work_struct *work)
dev_err(r->ep->dcp->dev,
"AFK[ep:%02x]: failed to reply to compact service call: %d\n",
r->ep->endpoint, ret);
if (ret && r->ep->dcp->v27_j714s) {
if (ret && r->ep->dcp->v27_sleep_transport) {
guard(spinlock_irqsave)(&r->ep->lock);
r->ep->sleep_poisoned = true;
}
Expand Down Expand Up @@ -1511,12 +1514,18 @@ int afk_v27_sleep_control(struct apple_dcp_afkep *ep, bool open)
int ret;

if (!IS_ENABLED(CONFIG_APPLE_SOC_SLEEP) ||
!ep || ep->dcp->fw_compat != DCP_FIRMWARE_V_27_0)
!ep || !ep->dcp->v27_sleep_transport ||
ep->dcp->fw_compat != DCP_FIRMWARE_V_27_0)
return -EOPNOTSUPP;
ret = afk_v27_sleep_check(ep);
if (ret)
return ret;
spin_lock_irqsave(&ep->lock, flags);
/* A callback reply may have failed since the inventory check. */
if (ep->stopping || ep->sleep_poisoned || ep->sleep_waiting) {
ret = -EBUSY;
goto out;
}
if (ep->sleep_closed == !open) {
ret = -EALREADY;
goto out;
Expand Down Expand Up @@ -1733,14 +1742,15 @@ static void afk_recv_handle_init(struct apple_dcp_afkep *ep, u32 channel,
}
if (ret == -ENOENT &&
(ep->dcp->hw.iomfb_method_profile == DCP_IOMFB_METHODS_H17G ||
ep->dcp->v27_j714s)) {
ep->dcp->v27_j714s ||
(ep->dcp->v27_sleep_transport && !strcmp(name, "md-manager")))) {
/*
* M5 (H17G) announces powerlog-service with only
* ep-has-desc-mgr and interface-id, and firmware 27
* its descriptor manager (md-manager) without EPIC
* keys; match them by the announced name, as for
* props-less announces. The second on the J714s only,
* where its endpoints are started.
* props-less announces. J716c admits only md-manager
* here; its normal service matching stays unchanged.
*/
epic_name = NULL;
epic_class = NULL;
Expand Down Expand Up @@ -2448,15 +2458,16 @@ static bool afk_v27_sleep_reply(struct apple_dcp_afkep *ep, u32 channel,
u8 code;

if (!IS_ENABLED(CONFIG_APPLE_SOC_SLEEP) ||
!ep->dcp->v27_j714s || channel || type ||
!ep->dcp->v27_sleep_transport || channel || type ||
size != 12 || get_unaligned_le32(data + 4) != 4 ||
get_unaligned_le16(data + 2))
return false;
code = data[8];
if (code != 3 && code != 5)
return false;
spin_lock_irqsave(&ep->lock, flags);
if (ep->sleep_waiting && code == ep->sleep_expected) {
if (!ep->stopping && !ep->sleep_poisoned &&
ep->sleep_waiting && code == ep->sleep_expected) {
ep->sleep_waiting = false;
ep->sleep_closed = code == 3;
complete(&ep->sleep_done);
Expand Down
42 changes: 36 additions & 6 deletions drivers/gpu/drm/apple/dcp-fabric.c
Original file line number Diff line number Diff line change
Expand Up @@ -3257,6 +3257,16 @@ static int dcp_tb_split_locked(struct apple_dcp_typec_port *port,
return 0;
}

static void dcp_tb_clear_owner_locked(struct apple_dcp_typec_port *port,
struct apple_dcp_typec_route **slot)
{
lockdep_assert_held(&dcp_typec_fabric_lock);
*slot = NULL;
port->hpd = dcp_typec_port_owned(port);
/* Re-apply the next Type-C mux state in full. */
port->applied_valid = false;
}

static int dcp_tb_release_locked(struct apple_dcp_typec_port *port,
unsigned int dpin)
{
Expand Down Expand Up @@ -3305,7 +3315,7 @@ static int dcp_tb_release_locked(struct apple_dcp_typec_port *port,
port->tb_last[dcp_fabric_dpin_slot(dpin)] = *slot;
port->tb_last_until[dcp_fabric_dpin_slot(dpin)] = jiffies + msecs_to_jiffies(DCP_TB_STICKY_MS);
}
*slot = NULL;
dcp_tb_clear_owner_locked(port, slot);
/*
* A tunnel taken down at a deep sleep's entry (a USB4 router that sleeps takes its
* tunnels down after user space is frozen) is a display released for the sleep, as a
Expand All @@ -3318,9 +3328,6 @@ static int dcp_tb_release_locked(struct apple_dcp_typec_port *port,
WRITE_ONCE(dcp->sleep_v27_torn, true);
dev_info(dcp->dev, "tunnel display released for the sleep\n");
}
port->hpd = dcp_typec_port_owned(port);
/* re-apply the next Type-C mux state in full */
port->applied_valid = false;
if (dcp->hdmi_hpd && dcp->active &&
gpiod_get_value_cansleep(dcp->hdmi_hpd))
dcp_dptx_connect(dcp, 0);
Expand Down Expand Up @@ -4870,8 +4877,31 @@ int dcp_fabric_sleep_release(struct apple_dcp *dcp, s64 ms[2])
if (!route)
return 0;
port = route->port;
if (route->tunnel || port->owner != route || port->secondary_owner ||
port->split_dcp)
/*
* A USB4 router that sleeps in place has its DP IN's display torn down
* at its entry (the DPTX port disconnected, the tunnel clock stopped),
* but the tunnel route stays owned. Release it as a DP IN detach does;
* the router hands the display back once the sleep is over.
*/
if (route->tunnel) {
unsigned int dpin = route->tunnel_dpin;
struct apple_dcp_typec_route **slot;

if (READ_ONCE(dcp->dptxport[0].connected) || port->split_dcp ||
dpin >= DCP_FABRIC_DPIN_MAX)
return -EBUSY;
slot = dcp_tb_slot(port, dpin);
if (*slot != route)
return -EBUSY;
dcp_tb_binding_retire(dcp, route);
start = ktime_get();
ret = dcp_typec_route_deactivate(route);
ms[1] = ktime_ms_delta(ktime_get(), start);
if (!ret)
dcp_tb_clear_owner_locked(port, slot);
return ret ?: 1;
}
if (port->owner != route || port->secondary_owner || port->split_dcp)
return -EBUSY;
if (port->safe_pending)
return -EAGAIN;
Expand Down
8 changes: 3 additions & 5 deletions drivers/gpu/drm/apple/dcp-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -759,12 +759,10 @@ struct apple_dcp {

/* A firmware-driven suspend stops the firmware, see dcp_s2r_suspend(). */
struct apple_dcp_afkep *sleep_v27_ep[0x20];
/*
* Firmware 27.0 on the J714s, the board the firmware 27 sleep and what it needs of the
* shared paths have run on. Every other machine on firmware 27, other T6050 boards and
* T8142 included, takes the paths it took before.
*/
/* The J714s normal method table, panel services and swap profile. */
bool v27_j714s;
/* Sleep endpoint inventory and control replies; not a normal RPC profile. */
bool v27_sleep_transport;
struct dcp_v27_sleep *sleep_v27;
bool sleep_v27_closed;
/*
Expand Down
62 changes: 53 additions & 9 deletions drivers/gpu/drm/apple/dcp-v27-sleep.inc
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,13 @@ static int dcp_v27_rtkit_cycle(struct apple_dcp *dcp, unsigned int pause_ms)
u32 status, run_status = 0;
int ret;

/*
* A cancelled suspend must keep the inherited firmware session running, unless the
* processor already took its sleep step: that session neither reports a display plugged
* again nor completes the panel's power-on until it is restarted, as after a real wake.
*/
if (!pm_resume_via_firmware() && !(s && s->phase == V27_PREPARED))
return -EPERM;
if (s && s->cycle_failed)
return -ECANCELED;
dcp_v27_sessions(dcp, false);
Expand Down Expand Up @@ -388,7 +395,7 @@ static int dcp_v27_rtkit_cycle(struct apple_dcp *dcp, unsigned int pause_ms)

static bool dcp_v27_sleep_selected(struct apple_dcp *dcp)
{
return apple_sleep_v27_late() &&
return apple_sleep_v27_late() && dcp->v27_sleep_transport &&
(of_device_is_compatible(dcp->dev->of_node, "apple,t6050-dcp") ||
of_device_is_compatible(dcp->dev->of_node, "apple,t6050-dcpext")) &&
dcp->hw.adopt_live_session && dcp->fw_compat == DCP_FIRMWARE_V_27_0 &&
Expand Down Expand Up @@ -579,7 +586,7 @@ static unsigned long dcp_v27_ext_round(struct apple_dcp *dcp)
* sessions opened. Here with its DART, PMC bits and power words as there
* (dcp_v27_rtkit_cycle()), and without the pause.
*/
if (v27_ext_cycles) {
if ((pm_resume_via_firmware() || dcp->sleep_v27->phase == V27_PREPARED) && v27_ext_cycles) {
int ret = dcp_v27_ext_cycle_ready(dcp);

if (!ret) {
Expand Down Expand Up @@ -909,6 +916,30 @@ static const struct apple_epic_service_ops dcp_v27_ext_services[] = {
{},
};

static void dcp_v27_ext_av_teardown(struct apple_epic_service *service)
{
afk_service_disable(service);
}

/*
* The same holds for the AV interfaces (compact, cut to "dcpav-video-interface-" and
* so on) on endpoint 0x2b, which the sleep step starts when no audio did: left
* unanswered, the firmware never reports a display plugged after the sleep. One of
* each is live, re-announced at every plug.
*/
static const struct apple_epic_service_ops dcp_v27_ext_av_services[] = {
{ .name = "dcpav-video-interface-epic", .compact_full = "dcpav-video-interface-epic:0",
.singleton = true, .init = dcp_v27_ext_service_init,
.teardown = dcp_v27_ext_av_teardown },
{ .name = "dcpav-audio-interface-epic", .compact_full = "dcpav-audio-interface-epic:0",
.singleton = true, .init = dcp_v27_ext_service_init,
.teardown = dcp_v27_ext_av_teardown },
{ .name = "dcpav-cec-interface-epic", .compact_full = "dcpav-cec-interface-epic:0",
.singleton = true, .init = dcp_v27_ext_service_init,
.teardown = dcp_v27_ext_av_teardown },
{},
};

static void dcp_v27_ext_wq_destroy(void *data)
{
destroy_workqueue(data);
Expand All @@ -928,8 +959,9 @@ static int dcp_v27_sleep_endpoints_open(struct apple_dcp *dcp)

for (i = 0; i < ARRAY_SIZE(v27_sleep_endpoints); i++) {
u8 id = v27_sleep_endpoints[i];
bool served = s && dcp_v27_external(dcp) && t6050_ext_services &&
(id == 0x29 || id == 0x2a);
bool ext = s && dcp_v27_external(dcp) && t6050_ext_services;
bool served = ext && (id == 0x29 || id == 0x2a);
const struct apple_epic_service_ops *ops = no_services;

if (!apple_rtkit_has_endpoint(dcp->rtk, id))
return -ENODEV;
Expand All @@ -942,7 +974,11 @@ static int dcp_v27_sleep_endpoints_open(struct apple_dcp *dcp)
if (!s->ext_wq)
return -ENOMEM;
}
ep = afk_init(dcp, id, served ? dcp_v27_ext_services : no_services);
if (served)
ops = dcp_v27_ext_services;
else if (ext && id == AV_AUDIO_ENDPOINT_DESKTOP)
ops = dcp_v27_ext_av_services;
ep = afk_init(dcp, id, ops);
if (IS_ERR(ep))
return PTR_ERR(ep);
if (served) {
Expand Down Expand Up @@ -1058,10 +1094,13 @@ static int dcp_v27_disp_dart_release(struct dcp_v27_sleep *s)
return ret;
}

/* Normal process-context cancellation: firmware was NEVER idled or stopped. */
/* Reopen after cancellation, or after restarting the firmware on a real wake. */
static int dcp_v27_reopen_live(struct apple_dcp *dcp)
{
struct dcp_v27_sleep *s = dcp->sleep_v27;
/* Undoing a partial preparation never stops the firmware; a completed sleep step does. */
unsigned int cycles = pm_resume_via_firmware() || s->phase == V27_PREPARED ?
v27_rtkit_cycles : 0;
unsigned int i;
bool per_call;
int ret;
Expand All @@ -1086,7 +1125,7 @@ static int dcp_v27_reopen_live(struct apple_dcp *dcp)
/* A500's wake form first; its failure does not stop the power-on. */
iomfb_v27_sleep_rpc(dcp, true, true);
/* The wake's one restart: the rest of the wake runs in the session it starts. */
if (s->soft_off && v27_rtkit_cycles >= 1)
if (s->soft_off && cycles >= 1)
dcp_v27_rtkit_cycle(dcp, 0);
if (s->soft_off && v27_a115)
iomfb_v27_sleep_call(dcp, "A489", NULL, 0, 4);
Expand All @@ -1101,7 +1140,7 @@ static int dcp_v27_reopen_live(struct apple_dcp *dcp)
dev_warn(dcp->dev, "V27 wake: A115(1): %d\n", ret);
}
/* The dark-wake forms only: a restart, or a pause, before the display stage. */
if (v27_rtkit_cycles >= 2) {
if (cycles >= 2) {
iomfb_v27_sleep_rpc(dcp, true, true);
dcp_v27_rtkit_cycle(dcp, v27_lit_delay_ms);
} else if (v27_lit_delay_ms) {
Expand All @@ -1115,7 +1154,7 @@ static int dcp_v27_reopen_live(struct apple_dcp *dcp)
* Back to back with the hard power-on; only the dark-to-lit form idles
* the DCP, with A500 first, between the calls.
*/
per_call = v27_rtkit_cycles >= 3;
per_call = cycles >= 3;
if (!per_call)
dcp_v27_sessions(dcp, true);
dcp_v27_display_stage(dcp, per_call, per_call && v27_session_rounds, per_call);
Expand Down Expand Up @@ -1422,6 +1461,11 @@ static int dcp_v27_sleep_prepare(struct apple_dcp *dcp)
}
if (!dcp_v27_external(dcp) && !dcp->crtc)
return -ENODEV;
/* The sleep turns the panel's backlight off: without a level it stays off after it. */
if (!dcp_v27_external(dcp) && dcp_has_panel(dcp) && !dcp_backlight_level_known(dcp)) {
dev_info(dcp->dev, "V27 sleep: no backlight level to light the panel again\n");
return -EBUSY;
}
if (!dcp_v27_external(dcp) && !READ_ONCE(dcp->pipe_enabled_h17p))
return -EAGAIN; /* require the actual normal driver pipe-on ACK */
s->scanout = dcp->crtc ? dcp->crtc->base.dev->dev : NULL;
Expand Down
Loading
Loading