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
35 changes: 35 additions & 0 deletions drivers/gpu/drm/apple/dcp-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ void dcp_retry_placeholder_edid(struct apple_dcp *dcp,
const struct drm_edid *drm_edid);
bool dcp_typec_relink(struct apple_dcp *dcp);
bool dcp_typec_sink_relink(struct apple_dcp *dcp);
void dcp_typec_fw_hotplug(struct apple_dcp *dcp, bool connected);
void dcp_typec_claim(struct apple_dcp *dcp);
u32 dcp_typec_fw_unplugs(struct apple_dcp *dcp);
void dcp_typec_end_unplugged_for_sleep(struct apple_dcp *dcp);

/* The Type-C display of the CRTC's session, as the firmware reported it. */
enum dcp_typec_fw_display {
/* Its unplug not both announced by the Type-C mux and reported */
DCP_TYPEC_FW_SESSION,
/* Its unplug reported, and no display since */
DCP_TYPEC_FW_UNPLUGGED,
/* Its unplug reported, and another display since */
DCP_TYPEC_FW_REPLACED,
};

enum dcp_typec_fw_display dcp_typec_fw_display(struct apple_dcp *dcp);

struct dcpav_service_epic;

Expand Down Expand Up @@ -921,6 +937,22 @@ struct apple_dcp {
u64 typec_unplugs;
/* typec_unplugs when the CRTC last claimed its display session */
u64 crtc_unplugs;
/*
* The firmware's own reports of the Type-C display, written by its
* receive path only (dcp_typec_fw_hotplug()), in one word so that it
* is read whole: the unplugs it reported, and whether its last report
* had a display (DCP_TYPEC_FW_CONNECTED).
*/
u32 typec_fw_state;
wait_queue_head_t typec_fw_wq;
/* The unplugs in typec_fw_state at the CRTC's claim (dcp_typec_claim()) */
u32 crtc_fw_unplugs;
/*
* The unplugs in typec_fw_state when the present in flight was begun,
* on the same receive path as the reports: a present begun before the
* last unplug report belongs to a display that went.
*/
u32 present_fw_unplugs;
u64 placeholder_generation;
struct delayed_work placeholder_edid_wq;
/* replugs replayed for a Type-C sink that lost its link */
Expand Down Expand Up @@ -1489,6 +1521,9 @@ bool iomfb_present_complete_h17p(struct apple_dcp *dcp);
void iomfb_present_failed_h17p(struct apple_dcp *dcp);
bool iomfb_retire_dropped_present_h17p(struct apple_dcp *dcp);
bool iomfb_retire_stalled_present_h17p(struct apple_dcp *dcp);
bool iomfb_uses_queue(struct apple_dcp *dcp);
bool iomfb_end_unplugged_session_h17p(struct apple_dcp *dcp);
void iomfb_watch_unplugged_present_h17p(struct apple_dcp *dcp);
bool iomfb_present_has_surface_h17p(const struct dcp_swap_submit_req_h17p *request);
bool iomfb_apply_backlight_h17p(struct apple_dcp *dcp,
const struct dcp_swap_submit_req_h17p *request,
Expand Down
140 changes: 130 additions & 10 deletions drivers/gpu/drm/apple/dcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -5406,7 +5406,14 @@ static void dcp_external_audio_init(struct apple_dcp *dcp)
disable_work(&dcp->external_audio_work);
}

static void _dcp_poweroff(struct apple_dcp *dcp)
/*
* @pipe_unplugged: the firmware reported the unplug of the CRTC's display,
* and powered the pipe off with it (dcp_typec_fw_display()). On firmware with
* the IOMFB queue, the presents of the departing session end then, and the
* pipe is sent nothing unless another display is on it since
* (iomfb_end_unplugged_session_h17p()).
*/
static void _dcp_poweroff(struct apple_dcp *dcp, bool pipe_unplugged)
{
switch (dcp->fw_compat) {
case DCP_FIRMWARE_V_12_3:
Expand All @@ -5430,10 +5437,12 @@ static void _dcp_poweroff(struct apple_dcp *dcp)
iomfb_v14_7_poweroff(dcp);
break;
case DCP_FIRMWARE_H17P:
iomfb_poweroff_h17p(dcp);
if (!pipe_unplugged || !iomfb_end_unplugged_session_h17p(dcp))
iomfb_poweroff_h17p(dcp);
break;
case DCP_FIRMWARE_V_27_0:
iomfb_poweroff_v27(dcp);
if (!pipe_unplugged || !iomfb_end_unplugged_session_h17p(dcp))
iomfb_poweroff_v27(dcp);
if (dcp->edr_hm)
dcp->edr_restart = true;
WRITE_ONCE(dcp->edr_ramping, false);
Expand Down Expand Up @@ -5493,7 +5502,7 @@ static void dcp_fixed_hdmi_reconnect(struct apple_dcp *dcp, bool poweroff_unplug
dev_warn(dcp->dev, "HDMI DPTX connect failed: %d\n", ret);
} else if (!connected) {
if (poweroff_unplugged)
_dcp_poweroff(dcp);
_dcp_poweroff(dcp, false);
else if (dcp->connector)
disconnected_hpd_event(dcp->connector);
}
Expand Down Expand Up @@ -5711,8 +5720,7 @@ void dcp_poweron(struct platform_device *pdev)

if (dcp_is_typec_output(dcp)) {
/* This CRTC now owns the current Type-C display session. */
scoped_guard(mutex, &dcp->hpd_mutex)
dcp->crtc_unplugs = dcp->typec_unplugs;
dcp_typec_claim(dcp);
wait_for_typec_hpd = READ_ONCE(dcp->typec_crtc_off) &&
READ_ONCE(dcp->typec_cable_connected);
WRITE_ONCE(dcp->typec_crtc_off, false);
Expand Down Expand Up @@ -5831,6 +5839,113 @@ void dcp_external_recover(struct platform_device *pdev)
dcp_poweron(pdev);
}

#define DCP_TYPEC_FW_CONNECTED BIT(0)
#define DCP_TYPEC_FW_UNPLUGS(state) ((state) >> 1)

/*
* How long the firmware may take to report the unplug of a display whose HPD
* low it was sent (dcp_dptx_disconnect_oob()), after the desktop, told of the
* unplug first, turned its CRTC off. Without the report by then, the CRTC
* powers the pipe off as for a display still there; the report, when it
* comes, still recovers a present the pipe swallowed.
*/
#define DCP_TYPEC_FW_UNPLUG_MS 500

/*
* The firmware's report of the Type-C display, once the reports that are not
* a display change have been filtered out (dcpep_cb_hotplug()). It sends it
* after acting on the change: for an unplug, once it has powered the pipe
* off. Called on its receive path only, the one writer.
*/
void dcp_typec_fw_hotplug(struct apple_dcp *dcp, bool connected)
{
u32 unplugs = DCP_TYPEC_FW_UNPLUGS(READ_ONCE(dcp->typec_fw_state)) + !connected;

WRITE_ONCE(dcp->typec_fw_state,
unplugs << 1 | (connected ? DCP_TYPEC_FW_CONNECTED : 0));
wake_up_all(&dcp->typec_fw_wq);
if (!connected)
iomfb_watch_unplugged_present_h17p(dcp);
}

/*
* The CRTC claims the current Type-C display session: at its power-on
* (dcp_poweron()), and at a mode set that succeeds with the CRTC kept on
* (dcp_crtc_atomic_modeset()). Both the mux's and the firmware's unplugs are
* counted from here.
*/
void dcp_typec_claim(struct apple_dcp *dcp)
{
scoped_guard(mutex, &dcp->hpd_mutex)
dcp->crtc_unplugs = dcp->typec_unplugs;
WRITE_ONCE(dcp->crtc_fw_unplugs, DCP_TYPEC_FW_UNPLUGS(READ_ONCE(dcp->typec_fw_state)));
}

/* The unplugs the firmware reported so far. */
u32 dcp_typec_fw_unplugs(struct apple_dcp *dcp)
{
return DCP_TYPEC_FW_UNPLUGS(READ_ONCE(dcp->typec_fw_state));
}

/*
* The display of the CRTC's session is gone, and its pipe with it, once both
* have happened since the CRTC claimed it (dcp_poweron()): the Type-C mux
* announced its unplug (dcp_dptx_disconnect_oob()), and the firmware reported
* an unplug. They come in either order: the USB4 port's teardown takes the
* display away before the mux announces it. An unplug of the previous
* display reported only after the claim would count for this session once
* this session's own mux unplug comes: its display is physically gone then,
* and its HPD low is sent or about to be; the pipe is sent nothing, and the
* framebuffers stay referenced until a later present completes.
*/
enum dcp_typec_fw_display dcp_typec_fw_display(struct apple_dcp *dcp)
{
u32 state = READ_ONCE(dcp->typec_fw_state);

if (!dcp_is_typec_output(dcp) ||
READ_ONCE(dcp->typec_unplugs) == READ_ONCE(dcp->crtc_unplugs) ||
DCP_TYPEC_FW_UNPLUGS(state) == READ_ONCE(dcp->crtc_fw_unplugs))
return DCP_TYPEC_FW_SESSION;
return state & DCP_TYPEC_FW_CONNECTED ? DCP_TYPEC_FW_REPLACED :
DCP_TYPEC_FW_UNPLUGGED;
}

/*
* The CRTC of a display the Type-C mux announced unplugged turns off: the
* desktop heard of the unplug before the firmware was sent its HPD low. Wait
* for the firmware's report. True once it reported the unplug.
*/
static bool dcp_typec_fw_unplug_wait(struct apple_dcp *dcp)
{
/* Only firmware with the IOMFB queue acts on it (_dcp_poweroff()). */
if (!iomfb_uses_queue(dcp))
return false;
return wait_event_timeout(dcp->typec_fw_wq,
dcp_typec_fw_display(dcp) != DCP_TYPEC_FW_SESSION,
msecs_to_jiffies(DCP_TYPEC_FW_UNPLUG_MS)) > 0;
}

/*
* A system sleep, with the display unplugged under a lit CRTC: its suspend
* cancelled the swap watchdog, and a present the pipe accepted would hold
* the queue's settle until it refuses the sleep. The mux announced the
* unplug at the sleep's start; the firmware's report may still be on its
* way, as at a CRTC's power-off.
*/
void dcp_typec_end_unplugged_for_sleep(struct apple_dcp *dcp)
{
bool announced;

if (!dcp_is_typec_output(dcp))
return;
scoped_guard(mutex, &dcp->hpd_mutex)
announced = dcp->typec_unplugs != dcp->crtc_unplugs;
if (announced)
dcp_typec_fw_unplug_wait(dcp);
if (dcp_typec_fw_display(dcp) != DCP_TYPEC_FW_SESSION)
iomfb_end_unplugged_session_h17p(dcp);
}

void dcp_poweroff(struct platform_device *pdev)
{
struct apple_dcp *dcp = platform_get_drvdata(pdev);
Expand Down Expand Up @@ -5908,9 +6023,12 @@ void dcp_poweroff(struct platform_device *pdev)
scoped_guard(mutex, &dcp->hpd_mutex)
display_gone = dcp->typec_unplugs != dcp->crtc_unplugs;
if (display_gone) {
bool pipe_unplugged = dcp_typec_fw_unplug_wait(dcp);

dev_dbg(dcp->dev,
"CRTC off after its display was unplugged: leaving the current connection alone\n");
_dcp_poweroff(dcp);
"CRTC off after its display was unplugged: leaving the current connection alone%s\n",
pipe_unplugged ? ", and the pipe the unplug powered off" : "");
_dcp_poweroff(dcp, pipe_unplugged);
return;
}
}
Expand All @@ -5932,7 +6050,7 @@ void dcp_poweroff(struct platform_device *pdev)
cancel_delayed_work(&dcp->typec_reconnect_wq);
}

_dcp_poweroff(dcp);
_dcp_poweroff(dcp, false);

if (dcp_is_typec_output(dcp)) {
ret = 0;
Expand Down Expand Up @@ -8934,6 +9052,7 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev)
init_completion(&dcp->s2r_dart_done);
init_completion(&dcp->s2r_hpd_done);
init_waitqueue_head(&dcp->channels_idle_wq);
init_waitqueue_head(&dcp->typec_fw_wq);
init_completion(&dcp->typec_iomfb_hpd_ready);
INIT_DELAYED_WORK(&dcp->typec_reconnect_wq,
dcp_typec_reconnect_work);
Expand Down Expand Up @@ -10480,6 +10599,7 @@ static int dcp_s2r_ext_suspend(struct apple_dcp *dcp)
dcp_drain_for_sleep(dcp);
cancel_delayed_work_sync(&dcp->swap_watchdog_wq);
iomfb_pause_presentation(dcp, true);
dcp_typec_end_unplugged_for_sleep(dcp);
if (iomfb_queue_settle(dcp, msecs_to_jiffies(500))) {
iomfb_pause_presentation(dcp, false);
dcp_enable_typec_work(dcp);
Expand Down Expand Up @@ -12496,7 +12616,7 @@ static int dcp_t6041_stop_one(struct device *dev, void *data)
goto err_unwind;
}
} else {
_dcp_poweroff(dcp);
_dcp_poweroff(dcp, false);
}
powered_off = true;
if (t6040) {
Expand Down
Loading
Loading