All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@linux.intel.com>
To: Imre Deak <imre.deak@intel.com>,
	intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org
Subject: Re: [PATCH 11/13] drm/i915/ddi_mgr: Verify and restore DDI allocations after runtime resume
Date: Thu, 26 Nov 2026 15:25:16 +0200	[thread overview]
Message-ID: <ba22619bb6a72f0148c62f1ce123fc5c67c37f53@intel.com> (raw)
In-Reply-To: <20261126100755.1252635-12-imre.deak@intel.com>

On Thu, 26 Nov 2026, Imre Deak <imre.deak@intel.com> wrote:
> Check that the IOM resource pool and recorded legacy PHY assignments are
> preserved across runtime suspend. Restore missing legacy assignments to
> their original DDIs when those DDIs are free and the PHYs have no other
> assignment.
>
> Firmware may reuse a legacy DDI while the device is suspended. Track
> allocations that could not be restored separately from the saved routes,
> and report their connectors as disconnected until the allocations can
> be restored. Reject enabling these connectors, including when the loss
> is discovered by the commit's runtime resume, while allowing them to be
> detached.
>
> Signed-off-by: Imre Deak <imre.deak@intel.com>
> ---
>  drivers/gpu/drm/i915/display/intel_ddi_mgr.c  | 123 ++++++++++++++++++
>  drivers/gpu/drm/i915/display/intel_ddi_mgr.h  |   2 +
>  drivers/gpu/drm/i915/display/intel_display.c  |  12 +-
>  .../drm/i915/display/intel_display_driver.c   |   3 +
>  drivers/gpu/drm/i915/display/intel_tc.c       |  33 ++++-
>  drivers/gpu/drm/xe/display/xe_display.c       |   3 +
>  6 files changed, 174 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/display/intel_ddi_mgr.c b/drivers/gpu/drm/i915/display/intel_ddi_mgr.c
> index 236146a37fc34..8f32e7c8dff27 100644
> --- a/drivers/gpu/drm/i915/display/intel_ddi_mgr.c
> +++ b/drivers/gpu/drm/i915/display/intel_ddi_mgr.c
> @@ -1,6 +1,7 @@
>  // SPDX-License-Identifier: MIT
>  /* Copyright © 2026 Intel Corporation */
>  
> +#include <linux/compiler.h>
>  #include <linux/iopoll.h>
>  #include <linux/seq_buf.h>
>  #include <linux/string.h>
> @@ -45,6 +46,7 @@ struct intel_ddi_mgr {
>  	struct intel_ddi_route route[INTEL_DDI_MGR_NUM_PORTS];
>  	u8 ddc_pin[INTEL_DDI_MGR_NUM_PORTS];
>  	u8 pool_ddi_mask;
> +	u8 disabled_ddi_mask;
>  	u8 legacy_phy_mask;
>  	u16 ddc_pins;
>  	bool has_hdmi;
> @@ -101,6 +103,16 @@ bool intel_ddi_mgr_is_pool_ddi(struct intel_display *display, enum port ddi)
>  		display->ddi_mgr->pool_ddi_mask & BIT(ddi - PORT_TC1);
>  }
>  
> +bool intel_ddi_mgr_is_ddi_disabled(struct intel_display *display, enum port ddi)
> +{
> +	struct intel_ddi_mgr *mgr = display->ddi_mgr;
> +
> +	if (!mgr || ddi < PORT_TC1 || ddi > PORT_TC4)
> +		return false;
> +
> +	return READ_ONCE(mgr->disabled_ddi_mask) & BIT(ddi - PORT_TC1);
> +}
> +
>  bool intel_ddi_mgr_pool_supports_hdmi(struct intel_display *display)
>  {
>  	struct intel_ddi_mgr *mgr = display->ddi_mgr;
> @@ -165,6 +177,9 @@ bool intel_ddi_mgr_aux_available(struct intel_encoder *encoder)
>  {
>  	struct intel_display *display = to_intel_display(encoder);
>  
> +	if (intel_ddi_mgr_is_ddi_disabled(display, encoder->port))
> +		return false;
> +
>  	if (!intel_ddi_mgr_is_pool_ddi(display, encoder->port))
>  		return true;
>  
> @@ -193,6 +208,9 @@ bool intel_ddi_mgr_connector_available(struct intel_connector *connector)
>  		return true;
>  
>  	encoder = &dig_port->base;
> +	if (intel_ddi_mgr_is_ddi_disabled(display, encoder->port))
> +		return false;
> +
>  	if (connector->base.connector_type == DRM_MODE_CONNECTOR_HDMIA)
>  		return intel_ddi_mgr_is_legacy_pool_encoder(encoder) &&
>  			(intel_bios_encoder_supports_hdmi(encoder->devdata) ||
> @@ -822,6 +840,111 @@ static void update_hpd_sources(struct intel_display *display)
>  	}
>  }
>  
> +static u8 legacy_ddi_mismatch_mask(const struct intel_ddi_mgr *mgr, u32 resources)
> +{
> +	u8 ddi_mask = 0;
> +	int ddi;
> +
> +	for (ddi = 0; ddi < INTEL_DDI_MGR_NUM_PORTS; ddi++) {
> +		const struct intel_ddi_route *route = &mgr->route[ddi];
> +
> +		if (!(mgr->pool_ddi_mask & BIT(ddi)) ||
> +		    route->mode != INTEL_DDI_ROUTE_LEGACY)
> +			continue;
> +
> +		if (IOM_DDI_CONSUMER_GET(resources, ddi) !=
> +		    IOM_DDI_CONSUMER_PHY(route->phy))
> +			ddi_mask |= BIT(ddi);
> +	}
> +
> +	return ddi_mask;
> +}
> +
> +static u32 restore_legacy_allocations(struct intel_display *display, u32 resources)
> +{
> +	struct intel_ddi_mgr *mgr = display->ddi_mgr;
> +	u32 new_resources = resources;
> +	u32 readback;
> +	int ddi, slot;
> +
> +	for (ddi = 0; ddi < INTEL_DDI_MGR_NUM_PORTS; ddi++) {
> +		const struct intel_ddi_route *route = &mgr->route[ddi];
> +		u32 consumer = IOM_DDI_CONSUMER_GET(resources, ddi);
> +
> +		if (!(mgr->pool_ddi_mask & BIT(ddi)) || route->mode != INTEL_DDI_ROUTE_LEGACY)
> +			continue;
> +
> +		if (consumer != IOM_DDI_CONSUMER_FREE)
> +			continue;
> +
> +		for (slot = 0; slot < IOM_DDI_NUM_SLOTS; slot++)
> +			if (IOM_DDI_CONSUMER_GET(resources, slot) ==
> +			    IOM_DDI_CONSUMER_PHY(route->phy))
> +				break;
> +
> +		if (slot < IOM_DDI_NUM_SLOTS)
> +			continue;
> +
> +		new_resources |= IOM_DDI_CONSUMER(ddi, IOM_DDI_CONSUMER_PHY(route->phy));
> +	}
> +
> +	if (new_resources == resources)
> +		return resources;
> +
> +	intel_de_write(display, IOM_DP_RESOURCE_MNG, new_resources);
> +	readback = intel_de_read(display, IOM_DP_RESOURCE_MNG);
> +	if (readback != new_resources)
> +		drm_err(display->drm,
> +			"DDIMGR: DDI restore mismatch: requested 0x%08x, read 0x%08x\n",
> +			new_resources, readback);
> +
> +	return readback;
> +}
> +
> +void intel_ddi_mgr_verify_state(struct intel_display *display)
> +{
> +	struct intel_ddi_mgr *mgr = display->ddi_mgr;
> +	u8 old_disabled_ddi_mask, disabled_ddi_mask;
> +	u32 resources;
> +	int err;
> +
> +	if (!intel_ddi_mgr_is_enabled(mgr))
> +		return;
> +
> +	old_disabled_ddi_mask = READ_ONCE(mgr->disabled_ddi_mask);
> +
> +	err = iom_lock(display);
> +	if (err)
> +		return;
> +
> +	resources = intel_de_read(display, IOM_DP_RESOURCE_MNG);
> +	verify_ddi_counts(display, resources);
> +
> +	err = verify_ddi_pool(display, resource_to_pool_ddi_mask(resources));
> +	if (err)
> +		goto out;
> +
> +	if (!legacy_ddi_mismatch_mask(mgr, resources))
> +		goto out;
> +
> +	drm_dbg_kms(display->drm,
> +		    "DDIMGR: Legacy DDI allocations changed during runtime suspend: 0x%08x\n",
> +		    resources);
> +
> +	resources = restore_legacy_allocations(display, resources);
> +
> +out:
> +	iom_unlock(display);
> +
> +	disabled_ddi_mask = legacy_ddi_mismatch_mask(mgr, resources);
> +	if (disabled_ddi_mask == old_disabled_ddi_mask)
> +		return;
> +
> +	WRITE_ONCE(mgr->disabled_ddi_mask, disabled_ddi_mask);
> +	drm_dbg_kms(display->drm, "DDIMGR: Disabled DDIs: 0x%02x -> 0x%02x\n",
> +		    old_disabled_ddi_mask, disabled_ddi_mask);
> +}
> +
>  static int init_ddi_resource(struct intel_display *display, int ddi)
>  {
>  	struct intel_ddi_mgr *mgr = display->ddi_mgr;
> diff --git a/drivers/gpu/drm/i915/display/intel_ddi_mgr.h b/drivers/gpu/drm/i915/display/intel_ddi_mgr.h
> index db10d0e8b3a97..fddd69564b84d 100644
> --- a/drivers/gpu/drm/i915/display/intel_ddi_mgr.h
> +++ b/drivers/gpu/drm/i915/display/intel_ddi_mgr.h
> @@ -14,8 +14,10 @@ struct intel_display;
>  struct intel_encoder;
>  
>  void intel_ddi_mgr_init(struct intel_display *display);
> +void intel_ddi_mgr_verify_state(struct intel_display *display);
>  
>  bool intel_ddi_mgr_is_pool_ddi(struct intel_display *display, enum port ddi);
> +bool intel_ddi_mgr_is_ddi_disabled(struct intel_display *display, enum port ddi);
>  bool intel_ddi_mgr_pool_supports_hdmi(struct intel_display *display);
>  bool intel_ddi_mgr_is_legacy_pool_encoder(struct intel_encoder *encoder);
>  bool intel_ddi_mgr_encoder_has_lane_reversal(struct intel_encoder *encoder);
> diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c
> index 19caae633d29f..1c03e801e21cd 100644
> --- a/drivers/gpu/drm/i915/display/intel_display.c
> +++ b/drivers/gpu/drm/i915/display/intel_display.c
> @@ -68,6 +68,7 @@
>  #include "intel_cursor_regs.h"
>  #include "intel_cx0_phy.h"
>  #include "intel_ddi.h"
> +#include "intel_ddi_mgr.h"
>  #include "intel_de.h"
>  #include "intel_dip.h"
>  #include "intel_display_driver.h"
> @@ -6812,7 +6813,16 @@ int intel_atomic_check(struct drm_device *dev,
>  
>  static int intel_atomic_prepare_commit(struct intel_atomic_state *state)
>  {
> -	int ret;
> +	struct drm_connector *connector;
> +	struct drm_connector_state *conn_state;
> +	int i, ret;
> +
> +	/* Runtime resume may have invalidated a DDI after atomic check. */
> +	for_each_new_connector_in_state(&state->base, connector, conn_state, i) {
> +		if (conn_state->crtc &&
> +		    !intel_ddi_mgr_connector_available(to_intel_connector(connector)))
> +			return -ENODEV;
> +	}
>  
>  	ret = drm_atomic_helper_prepare_planes(state->base.dev, &state->base);
>  	if (ret < 0)
> diff --git a/drivers/gpu/drm/i915/display/intel_display_driver.c b/drivers/gpu/drm/i915/display/intel_display_driver.c
> index c13471a5a10e7..b018608eae032 100644
> --- a/drivers/gpu/drm/i915/display/intel_display_driver.c
> +++ b/drivers/gpu/drm/i915/display/intel_display_driver.c
> @@ -30,6 +30,7 @@
>  #include "intel_crtc.h"
>  #include "intel_cursor.h"
>  #include "intel_dbuf_bw.h"
> +#include "intel_ddi_mgr.h"
>  #include "intel_de.h"
>  #include "intel_display_clock_gating.h"
>  #include "intel_display_core.h"
> @@ -962,6 +963,8 @@ void intel_display_driver_pm_runtime_resume_early(struct intel_display *display)
>  /* after irq resume */
>  void intel_display_driver_pm_runtime_resume(struct intel_display *display)
>  {
> +	intel_ddi_mgr_verify_state(display);
> +
>  	/*
>  	 * On VLV/CHV display interrupts are part of the display
>  	 * power well, so hpd is reinitialized from there. For
> diff --git a/drivers/gpu/drm/i915/display/intel_tc.c b/drivers/gpu/drm/i915/display/intel_tc.c
> index f878494bcb388..e01f367007424 100644
> --- a/drivers/gpu/drm/i915/display/intel_tc.c
> +++ b/drivers/gpu/drm/i915/display/intel_tc.c
> @@ -10,6 +10,7 @@
>  #include "intel_atomic.h"
>  #include "intel_cx0_phy_regs.h"
>  #include "intel_ddi.h"
> +#include "intel_ddi_mgr.h"
>  #include "intel_de.h"
>  #include "intel_display.h"
>  #include "intel_display_driver.h"
> @@ -1173,6 +1174,17 @@ static void xelpdp_tc_phy_get_hw_state(struct intel_tc_port *tc)
>  
>  	tc_cold_wref = __tc_cold_block(tc, &domain);
>  
> +	if (intel_ddi_mgr_is_ddi_disabled(display, tc->dig_port->base.port)) {
> +		tc->mode = TC_PORT_DISCONNECTED;
> +		drm_dbg_kms(display->drm,
> +			    "Port %s: skipping PHY readout, legacy DDI allocation unavailable\n",
> +			    tc->port_name);
> +
> +		__tc_cold_unblock(tc, domain, tc_cold_wref);
> +
> +		return;
> +	}
> +
>  	tc->mode = tc_phy_get_current_mode(tc);
>  	if (tc->mode != TC_PORT_DISCONNECTED) {
>  		tc->lock_wakeref = tc_cold_block(tc);
> @@ -1195,6 +1207,8 @@ static void xelpdp_tc_phy_get_hw_state(struct intel_tc_port *tc)
>  
>  static bool xelpdp_tc_phy_connect(struct intel_tc_port *tc, int required_lanes)
>  {
> +	struct intel_display *display = to_intel_display(tc->dig_port);
> +
>  	tc->lock_wakeref = tc_cold_block(tc);
>  
>  	if (tc->mode == TC_PORT_TBT_ALT) {
> @@ -1203,6 +1217,10 @@ static bool xelpdp_tc_phy_connect(struct intel_tc_port *tc, int required_lanes)
>  		return true;
>  	}
>  
> +	/* AUX transfers and modesets reject DDIs without their legacy allocation. */
> +	if (intel_ddi_mgr_is_ddi_disabled(display, tc->dig_port->base.port))
> +		return true;
> +
>  	if (!xelpdp_tc_phy_enable_tcss_power(tc, true))
>  		goto out_unblock_tccold;
>  
> @@ -1227,6 +1245,14 @@ static bool xelpdp_tc_phy_connect(struct intel_tc_port *tc, int required_lanes)
>  
>  static void xelpdp_tc_phy_disconnect(struct intel_tc_port *tc)
>  {
> +	struct intel_display *display = to_intel_display(tc->dig_port);
> +
> +	if (intel_ddi_mgr_is_ddi_disabled(display, tc->dig_port->base.port)) {
> +		tc_cold_unblock(tc, fetch_and_zero(&tc->lock_wakeref));
> +
> +		return;
> +	}
> +
>  	switch (tc->mode) {
>  	case TC_PORT_LEGACY:
>  	case TC_PORT_DP_ALT:
> @@ -1733,6 +1759,9 @@ bool intel_tc_port_connected(struct intel_encoder *encoder)
>  
>  	drm_WARN_ON(display->drm, !intel_tc_port_ref_held(dig_port));
>  
> +	if (intel_ddi_mgr_is_ddi_disabled(display, encoder->port))
> +		return false;
> +
>  	if (tc->mode != TC_PORT_DISCONNECTED)
>  		mask = BIT(tc->mode);
>  
> @@ -1880,7 +1909,9 @@ static void __intel_tc_port_lock(struct intel_tc_port *tc,
>  					  false);
>  
>  	drm_WARN_ON(display->drm, tc->mode == TC_PORT_DISCONNECTED);
> -	drm_WARN_ON(display->drm, tc->mode != TC_PORT_TBT_ALT && !tc_phy_is_owned(tc));
> +	drm_WARN_ON(display->drm,
> +		    !intel_ddi_mgr_is_ddi_disabled(display, tc->dig_port->base.port) &&
> +		    tc->mode != TC_PORT_TBT_ALT && !tc_phy_is_owned(tc));
>  }
>  
>  void intel_tc_port_lock(struct intel_digital_port *dig_port)
> diff --git a/drivers/gpu/drm/xe/display/xe_display.c b/drivers/gpu/drm/xe/display/xe_display.c
> index f757cfad4bd6e..b36a7cc83420d 100644
> --- a/drivers/gpu/drm/xe/display/xe_display.c
> +++ b/drivers/gpu/drm/xe/display/xe_display.c
> @@ -13,6 +13,7 @@
>  #include <drm/intel/display_member.h>
>  #include <drm/intel/display_parent_interface.h>
>  
> +#include "intel_ddi_mgr.h"
>  #include "intel_display.h"
>  #include "intel_display_core.h"
>  #include "intel_display_device.h"
> @@ -340,6 +341,8 @@ static void xe_display_disable_d3cold(struct xe_device *xe)
>  
>  	intel_dmc_resume(display);
>  
> +	intel_ddi_mgr_verify_state(display);

The direction *must* be to add all of this stuff to display, not diverge
i915 and xe more.


> +
>  	if (intel_display_device_present(display))
>  		drm_mode_config_reset(&xe->drm);

-- 
Jani Nikula, Intel

  reply	other threads:[~2026-11-26 13:25 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26 10:07 [PATCH 00/13] drm/i915/ddi_mgr: Add support for dynamic DDI allocation Imre Deak
2026-11-26 10:07 ` [PATCH 01/13] drm/i915/dp: Allow rebuilding the source rate list Imre Deak
2026-11-26 10:07 ` [PATCH 02/13] drm/i915/hotplug: Set detector enable bits without a clear mask Imre Deak
2026-11-26 10:07 ` [PATCH 03/13] drm/i915/nvl+: Add support for remapping logical HPD pins to HW pins Imre Deak
2026-11-26 10:07 ` [PATCH 04/13] drm/xe/display: Distinguish failed system suspend recovery Imre Deak
2026-11-26 13:22   ` Jani Nikula
2026-11-26 10:07 ` [PATCH 05/13] drm/i915/gmbus: Extract a helper for Type-C DDC pin mapping Imre Deak
2026-11-26 10:07 ` [PATCH 06/13] drm/i915/ddi_mgr: Add support for dynamic DDI allocation Imre Deak
2026-11-26 13:23   ` Jani Nikula
2026-11-26 16:51     ` Imre Deak
2026-11-26 10:07 ` [PATCH 07/13] drm/i915/gmbus: Extract adapter creation and destruction Imre Deak
2026-11-26 10:07 ` [PATCH 08/13] drm/i915/gmbus: Add stable DDC adapters for the DDI pool Imre Deak
2026-11-26 10:07 ` [PATCH 09/13] drm/i915/ddi_mgr: Register encoders with dynamic DDI support Imre Deak
2026-11-26 10:26   ` sashiko-bot
2026-11-26 10:07 ` [PATCH 10/13] drm/i915/ddi_mgr: Keep AUX access consistent with DDI pool routes Imre Deak
2026-11-26 10:07 ` [PATCH 11/13] drm/i915/ddi_mgr: Verify and restore DDI allocations after runtime resume Imre Deak
2026-11-26 13:25   ` Jani Nikula [this message]
2026-11-26 10:07 ` [PATCH 12/13] drm/i915/ddi_mgr: Handle DDI pool system suspend and resume Imre Deak
2026-11-26 10:41   ` sashiko-bot
2026-11-26 13:25   ` Jani Nikula
2026-11-26 10:07 ` [PATCH 13/13] drm/i915/ddi_mgr: Enable dynamic DDI allocation at load Imre Deak
2026-11-26 11:15 ` ✗ i915.CI.BAT: failure for drm/i915/ddi_mgr: Add support for dynamic DDI allocation Patchwork
2026-11-26 14:08 ` ✗ CI.checkpatch: warning " Patchwork
2026-11-26 14:10 ` ✓ CI.KUnit: success " Patchwork
2026-11-26 14:49 ` ✓ Xe.CI.BAT: " Patchwork
2026-11-26 21:32 ` ✓ Xe.CI.FULL: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ba22619bb6a72f0148c62f1ce123fc5c67c37f53@intel.com \
    --to=jani.nikula@linux.intel.com \
    --cc=imre.deak@intel.com \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.