diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 81de9acc87461..2bec104e06138 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -1444,6 +1444,7 @@ void dcp_platform_shutdown(struct platform_device *pdev); void dcp_disable_typec_work(struct apple_dcp *dcp, bool release_cable); void dcp_enable_typec_work(struct apple_dcp *dcp); void dcp_swap_watchdog(struct work_struct *work); +void disconnected_hpd_event(struct apple_connector *con); void iomfb_scanout_put_h17p(struct apple_dcp *dcp, struct iomfb_scanout_h17p *scanout); #endif diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 6abd5cc9fda60..b4226799366ba 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -852,7 +852,7 @@ static int dcp_desktop_shmem_setup(struct apple_dcp *dcp, return 0; } -static void disconnected_hpd_event(struct apple_connector *connector); +VISIBLE_IF_KUNIT void disconnected_hpd_event(struct apple_connector *con); bool dcp_is_external_h17p(struct apple_dcp *dcp) { @@ -4181,7 +4181,7 @@ static void dcp_typec_relink_work(struct work_struct *work) spin_unlock_irqrestore(&dcp->relink_lock, flags); } -static void disconnected_hpd_event(struct apple_connector *con) +VISIBLE_IF_KUNIT void disconnected_hpd_event(struct apple_connector *con) { struct platform_device *pdev; @@ -4192,6 +4192,14 @@ static void disconnected_hpd_event(struct apple_connector *con) if (pdev) { struct apple_dcp *dcp = platform_get_drvdata(pdev); + /* + * Userspace can disable the CRTC from the hotplug notification + * below before the firmware finishes tearing down the link and + * reports cb_hotplug(0). Invalidate the mode now so the CRTC + * power-off leaves the unplugged pipe to the firmware instead + * of submitting a clear swap that gets swallowed. + */ + dcp_mode_invalidate(&dcp->mode_state); WRITE_ONCE(dcp->ext_backlight, false); /* Nothing else reports an HDMI unplug to the firmware metadata. */ if (dcp_sink_metadata(dcp)) diff --git a/drivers/gpu/drm/apple/hotplug-test.c b/drivers/gpu/drm/apple/hotplug-test.c index 15ca6291bf495..5df27fc9cc271 100644 --- a/drivers/gpu/drm/apple/hotplug-test.c +++ b/drivers/gpu/drm/apple/hotplug-test.c @@ -273,11 +273,45 @@ static void hotplug_coalesced_ready(struct kunit *test) KUNIT_EXPECT_EQ(test, fixture->notifications, 2U); } +static void hotplug_disconnected_hpd_invalidates_mode(struct kunit *test) +{ + struct hotplug_fixture *fixture = test->priv; + + fixture->connector.base.status = connector_status_connected; + fixture->connector.connected = true; + fixture->dcp.mode_state.valid = true; + /* Hold hotplug_wq so we inspect state before userspace is notified. */ + disable_work_sync(&fixture->connector.hotplug_wq); + disconnected_hpd_event(&fixture->connector); + KUNIT_EXPECT_FALSE(test, READ_ONCE(fixture->connector.connected)); + KUNIT_EXPECT_FALSE(test, READ_ONCE(fixture->dcp.mode_state.valid)); + enable_work(&fixture->connector.hotplug_wq); + schedule_work(&fixture->connector.hotplug_wq); + flush_work(&fixture->connector.hotplug_wq); + hotplug_expect_notification(test, connector_status_disconnected); +} + +static void hotplug_disconnected_hpd_invalidates_inflight_modeset(struct kunit *test) +{ + struct hotplug_fixture *fixture = test->priv; + + fixture->connector.base.status = connector_status_connected; + fixture->connector.connected = true; + dcp_mode_begin(&fixture->dcp.mode_state); + disconnected_hpd_event(&fixture->connector); + dcp_mode_finish(&fixture->dcp.mode_state, true, &fixture->connector.connected); + KUNIT_EXPECT_FALSE(test, READ_ONCE(fixture->dcp.mode_state.valid)); + flush_work(&fixture->connector.hotplug_wq); + hotplug_expect_notification(test, connector_status_disconnected); +} + static struct kunit_case hotplug_test_cases[] = { KUNIT_CASE(hotplug_route_failure_notify), KUNIT_CASE(hotplug_coalesced_ready), KUNIT_CASE(hotplug_connected), KUNIT_CASE(hotplug_disconnected), + KUNIT_CASE(hotplug_disconnected_hpd_invalidates_mode), + KUNIT_CASE(hotplug_disconnected_hpd_invalidates_inflight_modeset), KUNIT_CASE(hotplug_retrain), KUNIT_CASE(hotplug_unrouted), KUNIT_CASE(hotplug_forced_on),