All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH for drm-misc-fixes v6 0/2] Fix some bugs in the hibmc DP
@ 2026-11-26  3:06 Yongbang Shi
  2026-11-26  3:06 ` [PATCH for drm-misc-fixes v6 1/2] drm/hisilicon/hibmc: Modify the method of obtaining the hpd_status Yongbang Shi
  2026-11-26  3:06 ` [PATCH for drm-misc-fixes v6 2/2] drm/hisilicon/hibmc: Add a flag to indicate whether the OS-side driver has been loaded Yongbang Shi
  0 siblings, 2 replies; 5+ messages in thread
From: Yongbang Shi @ 2026-11-26  3:06 UTC (permalink / raw)
  To: tzimmermann, dmitry.baryshkov, tiantao6, maarten.lankhorst,
	mripard, airlied, daniel, kong.kongxinwei
  Cc: liangjian010, shuliubin, chenjianmin, fengsheng5, shiyongbang,
	helin52, shenjian15, shaojijie, dri-devel, linux-kernel

From: Lin He <helin52@huawei.com>

Fix some bugs in the hibmc DP driver.

---
ChangeLog:
v5 -> v6:
  - Use a cleanup-based lock guard for aux_lock. (Thomas Zimmermann)
  - Use cleanup-based lock guards for gpio_lock. (Thomas Zimmermann)
v4 -> v5:
  - Invalidate the link in the hardirq when an unplug is sampled, and
    stop clearing the latched HPD status in hibmc_dp_hpd_cfg().
    (sashiko-bot)
  - Serialize a whole AUX transfer with hibmc_dp_hpd_cfg().
    (sashiko-bot)
  - Append HIBMC_HPD_UNKNOWN to the enum instead of prepending it, so
    the existing HIBMC_HPD_OUT/HIBMC_HPD_IN values do not change.
  - Only set the enable flag when DP was initialized, clear it only when
    it was set, and do not request the DP interrupt if DP initialization
    failed. (sashiko-bot)
v3 -> v4:
  - Fix the data race on hpd_status between hardirq and process
    contexts with WRITE_ONCE()/READ_ONCE(). (sashiko-bot)
  - Delete the HPD_IN early return in encoder_enable that breaks KMS
    forced modesets. (sashiko-bot)
v2 -> v3:
  - Delete irq_status and use hpd_status directly for hotplug
    detection. (sashiko-bot)
  - Add debug logs when hpd_status is not HPD_IN in detect and
    encoder_enable.
  - Move hibmc_set_enable_flag() before drm_dev_register() and
    hibmc_set_disable_flag() after drm_dev_unregister() to narrow the
    race window. (sashiko-bot)
  - Add spinlock_t gpio_lock to hibmc_drm_private to protect all
    operations on 0x0802A4. (sashiko-bot)
v1 -> v2:
  - More states in HIBMC_DP_HPD_STATUS are added to the
    'hibmc_dp_get_hpd_status'.
  - The call to `hibmc_set_enable_flag()` has been moved before
    `drm_client_setup()`, specifically before the connector detection
    triggers the I2C bit operation. (sashiko-bot)
  - A read-modify-write operation has been implemented instead of directly
    writing to prevent clearing the I2C mask bits. (sashiko-bot)
---

Lin He (2):
  drm/hisilicon/hibmc: Modify the method of obtaining the hpd_status
  drm/hisilicon/hibmc: Add a flag to indicate whether the OS-side driver
    has been loaded

 drivers/gpu/drm/hisilicon/hibmc/dp/dp_aux.c   |  2 +
 drivers/gpu/drm/hisilicon/hibmc/dp/dp_comm.h  |  2 +-
 drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c    | 38 ++++++++------
 drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h    |  6 ++-
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c    | 32 ++++++------
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c   | 50 +++++++++++++++++--
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h   |  2 +
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_i2c.c   | 10 +++-
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h  |  3 ++
 9 files changed, 108 insertions(+), 37 deletions(-)

-- 
2.33.0


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH for drm-misc-fixes v6 1/2] drm/hisilicon/hibmc: Modify the method of obtaining the hpd_status
  2026-11-26  3:06 [PATCH for drm-misc-fixes v6 0/2] Fix some bugs in the hibmc DP Yongbang Shi
@ 2026-11-26  3:06 ` Yongbang Shi
  2026-11-26  3:32   ` sashiko-bot
  2026-11-26  3:06 ` [PATCH for drm-misc-fixes v6 2/2] drm/hisilicon/hibmc: Add a flag to indicate whether the OS-side driver has been loaded Yongbang Shi
  1 sibling, 1 reply; 5+ messages in thread
From: Yongbang Shi @ 2026-11-26  3:06 UTC (permalink / raw)
  To: tzimmermann, dmitry.baryshkov, tiantao6, maarten.lankhorst,
	mripard, airlied, daniel, kong.kongxinwei
  Cc: liangjian010, shuliubin, chenjianmin, fengsheng5, shiyongbang,
	helin52, shenjian15, shaojijie, dri-devel, linux-kernel

From: Lin He <helin52@huawei.com>

To more accurately determine whether the current HPD status matches the
interrupt status, the polling mechanism in the lower half of the HPD
interrupt (via hibmc_dp_check_hpd_status) has been replaced with directly
retrieving the interrupt status in the upper half of the interrupt (via
hibmc_dp_get_hpd_status).

* Connector detection is skipped when hpd_status is not HPD_IN.

* Set the initial status of hpd_status to HPD_OUT.

* Wait 100 ms after enabling the DP block, so a sink that is already
  connected can latch its HPD interrupt before the first detect.

* Invalidate the link as soon as an unplug is sampled in the hardirq,
  so an unplug that is followed by a plug before the threaded handler
  runs is not lost.

Fixes: 3906e7a3b26d ("drm/hisilicon/hibmc: fix dp probabilistical detect errors after HPD irq")
Fixes: b11bc1ae4658 ("drm/hisilicon/hibmc: Add MSI irq getting and requesting for HPD")
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Lin He <helin52@huawei.com>
Signed-off-by: Yongbang Shi <shiyongbang@huawei.com>
---
ChangeLog:
v5 -> v6:
  - Use a cleanup-based lock guard for aux_lock. (Thomas Zimmermann)
v4 -> v5:
  - Invalidate the link in the hardirq when an unplug is sampled, and
    stop clearing the latched HPD status in hibmc_dp_hpd_cfg().
    (sashiko-bot)
  - Serialize a whole AUX transfer with hibmc_dp_hpd_cfg().
    (sashiko-bot)
  - Append HIBMC_HPD_UNKNOWN to the enum instead of prepending it, so
    the existing HIBMC_HPD_OUT/HIBMC_HPD_IN values do not change.
v3 -> v4:
  - Fix the data race on hpd_status between hardirq and process
    contexts with WRITE_ONCE()/READ_ONCE(). (sashiko-bot)
  - Delete the HPD_IN early return in encoder_enable that breaks KMS
    forced modesets. (sashiko-bot)
v2 -> v3:
  - Delete irq_status and use hpd_status directly for hotplug
    detection. (sashiko-bot)
  - Add debug logs when hpd_status is not HPD_IN in detect and
    encoder_enable.
v1 -> v2:
  - More states in HIBMC_DP_HPD_STATUS are added to the
    'hibmc_dp_get_hpd_status'.
---
 drivers/gpu/drm/hisilicon/hibmc/dp/dp_aux.c   |  2 +
 drivers/gpu/drm/hisilicon/hibmc/dp/dp_comm.h  |  2 +-
 drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c    | 38 ++++++++++++-------
 drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h    |  5 ++-
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c    | 31 +++++++--------
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c   |  9 ++++-
 6 files changed, 54 insertions(+), 33 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_aux.c b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_aux.c
index 8732cd1d8cb6..d90a714402a6 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_aux.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_aux.c
@@ -131,6 +131,8 @@ static ssize_t hibmc_dp_aux_xfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *
 	int ret;
 	u32 val; /* val will be assigned at the beginning of readl_poll_timeout function */
 
+	guard(mutex)(&dp->aux_lock);
+
 	writel(0, dp->base + HIBMC_DP_AUX_WR_DATA0);
 	writel(0, dp->base + HIBMC_DP_AUX_WR_DATA1);
 	writel(0, dp->base + HIBMC_DP_AUX_WR_DATA2);
diff --git a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_comm.h b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_comm.h
index f53dac256ee0..e56bfca886cb 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_comm.h
+++ b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_comm.h
@@ -38,12 +38,12 @@ struct hibmc_dp_dev {
 	struct drm_device *dev;
 	void __iomem *base;
 	struct mutex lock; /* protects concurrent RW in hibmc_dp_reg_write_field() */
+	struct mutex aux_lock; /* serializes AUX transfers with hpd_cfg() */
 	struct hibmc_dp_link link;
 	u8 dpcd[DP_RECEIVER_CAP_SIZE];
 	u8 downstream_ports[DP_MAX_DOWNSTREAM_PORTS];
 	struct drm_dp_desc desc;
 	bool is_branch;
-	int hpd_status;
 	void __iomem *serdes_base;
 };
 
diff --git a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c
index d5bd3c45649b..e3f70a367af7 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c
@@ -162,6 +162,7 @@ int hibmc_dp_hw_init(struct hibmc_dp *dp)
 		return -ENOMEM;
 
 	mutex_init(&dp_dev->lock);
+	mutex_init(&dp_dev->aux_lock);
 
 	dp->dp_dev = dp_dev;
 
@@ -191,6 +192,10 @@ int hibmc_dp_hw_init(struct hibmc_dp *dp)
 	writel(HIBMC_DP_HDCP, dp_dev->base + HIBMC_DP_HDCP_CFG);
 	/* clock enable */
 	writel(HIBMC_DP_CLK_EN, dp_dev->base + HIBMC_DP_DPTX_CLK_CTRL);
+	/* To latch the HPD interrupt, ensuring that DP can support more modes
+	 * within the fbcon framework when connected alone.
+	 */
+	msleep(100);
 
 	return 0;
 }
@@ -214,13 +219,12 @@ void hibmc_dp_hpd_cfg(struct hibmc_dp *dp)
 {
 	struct hibmc_dp_dev *dp_dev = dp->dp_dev;
 
+	guard(mutex)(&dp_dev->aux_lock);
+
 	hibmc_dp_reg_write_field(dp_dev, HIBMC_DP_AUX_REQ, HIBMC_DP_CFG_AUX_SYNC_LEN_SEL, 0x0);
 	hibmc_dp_reg_write_field(dp_dev, HIBMC_DP_AUX_REQ, HIBMC_DP_CFG_AUX_TIMER_TIMEOUT, 0x1);
 	hibmc_dp_reg_write_field(dp->dp_dev, HIBMC_DP_AUX_REQ, HIBMC_DP_CFG_AUX_MIN_PULSE_NUM, 0x9);
 	writel(HIBMC_DP_HDCP, dp_dev->base + HIBMC_DP_HDCP_CFG);
-	writel(0, dp_dev->base + HIBMC_DP_INTR_ENABLE);
-	writel(HIBMC_DP_INT_RST, dp_dev->base + HIBMC_DP_INTR_ORIGINAL_STATUS);
-	writel(HIBMC_DP_INT_ENABLE, dp_dev->base + HIBMC_DP_INTR_ENABLE);
 	writel(HIBMC_DP_DPTX_RST, dp_dev->base + HIBMC_DP_DPTX_RST_CTRL);
 	writel(HIBMC_DP_CLK_EN, dp_dev->base + HIBMC_DP_DPTX_CLK_CTRL);
 }
@@ -322,20 +326,26 @@ void hibmc_dp_set_cbar(struct hibmc_dp *dp, const struct hibmc_dp_cbar_cfg *cfg)
 	writel(HIBMC_DP_SYNC_EN_MASK, dp_dev->base + HIBMC_DP_TIMING_SYNC_CTRL);
 }
 
-bool hibmc_dp_check_hpd_status(struct hibmc_dp *dp, int exp_status)
+int hibmc_dp_get_hpd_status(struct hibmc_dp *dp)
 {
+	int hpd_status = HIBMC_HPD_UNKNOWN;
 	u32 status;
-	int ret;
 
-	ret = readl_poll_timeout(dp->dp_dev->base + HIBMC_DP_HPD_STATUS, status,
-				 FIELD_GET(HIBMC_DP_HPD_CUR_STATE, status) == exp_status,
-				 1000, 100000); /* DP spec says 100ms */
-	if (ret) {
-		drm_dbg_dp(dp->drm_dev, "wait hpd status timeout");
-		return false;
+	status = FIELD_GET(HIBMC_DP_HPD_CUR_STATE,
+			   readl(dp->dp_dev->base + HIBMC_DP_HPD_STATUS));
+	switch (status) {
+	case 0: /* idle */
+	case 3: /* unplug */
+	case 4: /* unplug intermediate */
+		hpd_status = HIBMC_HPD_OUT;
+		break;
+	case 1: /* plug */
+	case 2: /* plug intermediate */
+		hpd_status = HIBMC_HPD_IN;
+		break;
+	default:
+		break;
 	}
 
-	dp->dp_dev->hpd_status = exp_status;
-
-	return true;
+	return hpd_status;
 }
diff --git a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h
index 0f3662d8737e..84faa1a7439d 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h
+++ b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h
@@ -17,6 +17,7 @@ struct hibmc_dp_dev;
 enum hibmc_hpd_status {
 	HIBMC_HPD_OUT,
 	HIBMC_HPD_IN,
+	HIBMC_HPD_UNKNOWN,
 };
 
 enum hibmc_dp_cbar_pattern {
@@ -54,7 +55,7 @@ struct hibmc_dp {
 	void __iomem *mmio;
 	struct drm_dp_aux aux;
 	struct hibmc_dp_cbar_cfg cfg;
-	u32 irq_status;
+	int hpd_status;
 	int phys_status;
 };
 
@@ -66,7 +67,7 @@ void hibmc_dp_reset_link(struct hibmc_dp *dp);
 void hibmc_dp_hpd_cfg(struct hibmc_dp *dp);
 void hibmc_dp_enable_int(struct hibmc_dp *dp);
 void hibmc_dp_disable_int(struct hibmc_dp *dp);
-bool hibmc_dp_check_hpd_status(struct hibmc_dp *dp, int exp_status);
+int hibmc_dp_get_hpd_status(struct hibmc_dp *dp);
 u8 hibmc_dp_get_link_rate(struct hibmc_dp *dp);
 u8 hibmc_dp_get_lanes(struct hibmc_dp *dp);
 
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c
index 2e9403b8bf3c..6ea70c31d1a9 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c
@@ -15,8 +15,6 @@
 #include "dp/dp_comm.h"
 #include "dp/dp_config.h"
 
-#define DP_MASKED_SINK_HPD_PLUG_INT	BIT(2)
-
 static int hibmc_dp_connector_get_modes(struct drm_connector *connector)
 {
 	const struct drm_edid *drm_edid;
@@ -61,13 +59,13 @@ static int hibmc_dp_detect(struct drm_connector *connector,
 {
 	struct hibmc_dp *dp = to_hibmc_dp(connector);
 	struct hibmc_dp_dev *dp_dev = dp->dp_dev;
+	int hpd_status = READ_ONCE(dp->hpd_status);
 	int ret = connector_status_disconnected;
 
-	if (dp->irq_status) {
-		if (dp_dev->hpd_status != HIBMC_HPD_IN) {
-			ret = connector_status_disconnected;
-			goto exit;
-		}
+	if (hpd_status != HIBMC_HPD_IN) {
+		drm_dbg_dp(dp->drm_dev, "dp detect skipped, hpd (%d)\n",
+			   hpd_status);
+		goto exit;
 	}
 
 	if (!hibmc_dp_get_dpcd(dp_dev)) {
@@ -189,24 +187,26 @@ irqreturn_t hibmc_dp_hpd_isr(int irq, void *arg)
 {
 	struct drm_device *dev = (struct drm_device *)arg;
 	struct hibmc_drm_private *priv = to_hibmc_drm_private(dev);
-	int idx, exp_status;
+	int status = READ_ONCE(priv->dp.hpd_status);
+	int idx;
 
 	if (!drm_dev_enter(dev, &idx))
 		return -ENODEV;
 
-	if (priv->dp.irq_status & DP_MASKED_SINK_HPD_PLUG_INT) {
+	if (status == HIBMC_HPD_IN) {
+		/* Plug takes aux_lock, so it must run in the thread. */
 		drm_dbg_dp(&priv->dev, "HPD IN isr occur!\n");
 		hibmc_dp_hpd_cfg(&priv->dp);
-		exp_status = HIBMC_HPD_IN;
-	} else {
+	} else if (status == HIBMC_HPD_OUT) {
 		drm_dbg_dp(&priv->dev, "HPD OUT isr occur!\n");
-		hibmc_dp_reset_link(&priv->dp);
-		exp_status = HIBMC_HPD_OUT;
+	} else {
+		drm_err(&priv->dev, "HPD status (%d) error\n", status);
+		goto exit;
 	}
 
-	if (hibmc_dp_check_hpd_status(&priv->dp, exp_status))
-		drm_connector_helper_hpd_irq_event(&priv->dp.connector);
+	drm_connector_helper_hpd_irq_event(&priv->dp.connector);
 
+exit:
 	drm_dev_exit(idx);
 
 	return IRQ_HANDLED;
@@ -223,6 +223,7 @@ int hibmc_dp_init(struct hibmc_drm_private *priv)
 
 	dp->mmio = priv->mmio;
 	dp->drm_dev = dev;
+	dp->hpd_status = HIBMC_HPD_OUT;
 
 	ret = hibmc_dp_hw_init(&priv->dp);
 	if (ret) {
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
index 4d85c89f3f88..7920f03895fe 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
@@ -58,11 +58,18 @@ static irqreturn_t hibmc_dp_interrupt(int irq, void *arg)
 {
 	struct drm_device *dev = (struct drm_device *)arg;
 	struct hibmc_drm_private *priv = to_hibmc_drm_private(dev);
+	int hpd_status;
 	u32 status;
 
 	status = readl(priv->mmio + HIBMC_DP_INTSTAT);
 	if (status) {
-		priv->dp.irq_status = status;
+		hpd_status = hibmc_dp_get_hpd_status(&priv->dp);
+		WRITE_ONCE(priv->dp.hpd_status, hpd_status);
+
+		/* Reset here so a later plug cannot hide this unplug. */
+		if (hpd_status == HIBMC_HPD_OUT)
+			hibmc_dp_reset_link(&priv->dp);
+
 		writel(status, priv->mmio + HIBMC_DP_INTCLR);
 		return IRQ_WAKE_THREAD;
 	}
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH for drm-misc-fixes v6 2/2] drm/hisilicon/hibmc: Add a flag to indicate whether the OS-side driver has been loaded
  2026-11-26  3:06 [PATCH for drm-misc-fixes v6 0/2] Fix some bugs in the hibmc DP Yongbang Shi
  2026-11-26  3:06 ` [PATCH for drm-misc-fixes v6 1/2] drm/hisilicon/hibmc: Modify the method of obtaining the hpd_status Yongbang Shi
@ 2026-11-26  3:06 ` Yongbang Shi
  2026-11-26  3:25   ` sashiko-bot
  1 sibling, 1 reply; 5+ messages in thread
From: Yongbang Shi @ 2026-11-26  3:06 UTC (permalink / raw)
  To: tzimmermann, dmitry.baryshkov, tiantao6, maarten.lankhorst,
	mripard, airlied, daniel, kong.kongxinwei
  Cc: liangjian010, shuliubin, chenjianmin, fengsheng5, shiyongbang,
	helin52, shenjian15, shaojijie, dri-devel, linux-kernel

From: Lin He <helin52@huawei.com>

Add a flag to indicate whether the OS-side driver has been loaded to
prevent the BMC from enabling DP if the driver is not loaded, which could
lead to system failure in handling interrupts and generate error messages
like:

irq xx: nobody cared (try booting with the "irqpoll" option)
...
Call Trace:
<TRQ>
...

The flag is set only after hibmc_dp_init() succeeded, so it also means
that the DP block is ready.  If DP initialization fails, only the vblank
MSI vector is requested, so the DP interrupt is not registered at all.

Fixes: 0ab6ea261c1f ("drm/hisilicon/hibmc: add dp module in hibmc")
Acked-by: Thomas Zimmermann <tzimmermann@suse.de>
Signed-off-by: Lin He <helin52@huawei.com>
Signed-off-by: Yongbang Shi <shiyongbang@huawei.com>
---
ChangeLog:
v5 -> v6:
  - Use cleanup-based lock guards for gpio_lock. (Thomas Zimmermann)
v4 -> v5:
  - Only set the enable flag when DP was initialized, clear it only when
    it was set, and do not request the DP interrupt if DP initialization
    failed. (sashiko-bot)
v2 -> v3:
  - Move hibmc_set_enable_flag() before drm_dev_register() and
    hibmc_set_disable_flag() after drm_dev_unregister() to narrow the
    race window. (sashiko-bot)
  - Add spinlock_t gpio_lock to hibmc_drm_private to protect all
    operations on 0x0802A4. (sashiko-bot)
v1 -> v2:
  - The call to `hibmc_set_enable_flag()` has been moved before
    `drm_client_setup()`, specifically before the connector detection
    triggers the I2C bit operation. (sashiko-bot)
  - A read-modify-write operation has been implemented instead of directly
    writing to prevent clearing the I2C mask bits. (sashiko-bot)
---
 drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h    |  1 +
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c    |  1 +
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c   | 41 ++++++++++++++++++-
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h   |  2 +
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_i2c.c   | 10 ++++-
 .../gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h  |  3 ++
 6 files changed, 54 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h
index 84faa1a7439d..10772cddcfc8 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h
+++ b/drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h
@@ -57,6 +57,7 @@ struct hibmc_dp {
 	struct hibmc_dp_cbar_cfg cfg;
 	int hpd_status;
 	int phys_status;
+	bool initialized;
 };
 
 int hibmc_dp_hw_init(struct hibmc_dp *dp);
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c
index 6ea70c31d1a9..9fa49a2ba093 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c
@@ -256,6 +256,7 @@ int hibmc_dp_init(struct hibmc_drm_private *priv)
 	connector->polled = DRM_CONNECTOR_POLL_HPD;
 
 	dp->phys_status = connector_status_disconnected;
+	dp->initialized = true;
 
 	return 0;
 }
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
index 7920f03895fe..5334edf8f88a 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
@@ -174,6 +174,8 @@ static int hibmc_kms_init(struct hibmc_drm_private *priv)
 	if (ret)
 		return ret;
 
+	spin_lock_init(&priv->gpio_lock);
+
 	dev->mode_config.min_width = 0;
 	dev->mode_config.min_height = 0;
 	dev->mode_config.max_width = 1920;
@@ -346,12 +348,17 @@ static void hibmc_unload(struct drm_device *dev)
 static int hibmc_msi_init(struct drm_device *dev)
 {
 	struct pci_dev *pdev = to_pci_dev(dev->dev);
+	struct hibmc_drm_private *priv = to_hibmc_drm_private(dev);
+	int max_vectors = HIBMC_MIN_VECTORS;
 	int valid_irq_num;
 	int irq;
 	int ret;
 
-	ret = pci_alloc_irq_vectors(pdev, HIBMC_MIN_VECTORS,
-				    HIBMC_MAX_VECTORS, PCI_IRQ_MSI);
+	if (priv->dp.initialized)
+		max_vectors = HIBMC_MAX_VECTORS;
+
+	ret = pci_alloc_irq_vectors(pdev, HIBMC_MIN_VECTORS, max_vectors,
+				    PCI_IRQ_MSI);
 	if (ret < 0) {
 		drm_err(dev, "enabling MSI failed: %d\n", ret);
 		return ret;
@@ -430,6 +437,32 @@ static int hibmc_load(struct drm_device *dev)
 	return ret;
 }
 
+static inline void hibmc_set_enable_flag(struct hibmc_drm_private *priv)
+{
+	u32 value;
+
+	if (!priv->dp.initialized)
+		return;
+
+	guard(spinlock_irqsave)(&priv->gpio_lock);
+	value = readl(priv->mmio + HIBMC_ENABLE_FLAG);
+	value |= HIBMC_ENABLE_STATE;
+	writel(value, priv->mmio + HIBMC_ENABLE_FLAG);
+}
+
+static inline void hibmc_set_disable_flag(struct hibmc_drm_private *priv)
+{
+	u32 value;
+
+	if (!priv->dp.initialized)
+		return;
+
+	guard(spinlock_irqsave)(&priv->gpio_lock);
+	value = readl(priv->mmio + HIBMC_ENABLE_FLAG);
+	value &= ~HIBMC_ENABLE_STATE;
+	writel(value, priv->mmio + HIBMC_ENABLE_FLAG);
+}
+
 static int hibmc_pci_probe(struct pci_dev *pdev,
 			   const struct pci_device_id *ent)
 {
@@ -465,6 +498,8 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
 		goto err_return;
 	}
 
+	hibmc_set_enable_flag(priv);
+
 	ret = drm_dev_register(dev, 0);
 	if (ret) {
 		drm_err(dev, "failed to register drv for userspace access: %d\n",
@@ -477,6 +512,7 @@ static int hibmc_pci_probe(struct pci_dev *pdev,
 	return 0;
 
 err_unload:
+	hibmc_set_disable_flag(priv);
 	hibmc_unload(dev);
 err_return:
 	return ret;
@@ -487,6 +523,7 @@ static void hibmc_pci_remove(struct pci_dev *pdev)
 	struct drm_device *dev = pci_get_drvdata(pdev);
 
 	drm_dev_unregister(dev);
+	hibmc_set_disable_flag(to_hibmc_drm_private(dev));
 	hibmc_unload(dev);
 }
 
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
index dce8572bf63e..c2a82000ea7f 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h
@@ -49,6 +49,8 @@ struct hibmc_drm_private {
 	struct drm_crtc crtc;
 	struct hibmc_vdac vdac;
 	struct hibmc_dp dp;
+
+	spinlock_t gpio_lock; /* protects RMW on I2C/ENABLE_FLAG (0x0802A4) */
 };
 
 static inline struct hibmc_vdac *to_hibmc_vdac(struct drm_connector *connector)
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_i2c.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_i2c.c
index 44860011855e..6d158b8ad7fa 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_i2c.c
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_i2c.c
@@ -27,7 +27,10 @@ static void hibmc_set_i2c_signal(void *data, u32 mask, int value)
 {
 	struct hibmc_vdac *vdac = data;
 	struct hibmc_drm_private *priv = to_hibmc_drm_private(vdac->connector.dev);
-	u32 tmp_dir = readl(priv->mmio + GPIO_DATA_DIRECTION);
+	u32 tmp_dir;
+
+	guard(spinlock_irqsave)(&priv->gpio_lock);
+	tmp_dir = readl(priv->mmio + GPIO_DATA_DIRECTION);
 
 	if (value) {
 		tmp_dir &= ~mask;
@@ -47,7 +50,10 @@ static int hibmc_get_i2c_signal(void *data, u32 mask)
 {
 	struct hibmc_vdac *vdac = data;
 	struct hibmc_drm_private *priv = to_hibmc_drm_private(vdac->connector.dev);
-	u32 tmp_dir = readl(priv->mmio + GPIO_DATA_DIRECTION);
+	u32 tmp_dir;
+
+	guard(spinlock_irqsave)(&priv->gpio_lock);
+	tmp_dir = readl(priv->mmio + GPIO_DATA_DIRECTION);
 
 	if ((tmp_dir & mask) != mask) {
 		tmp_dir &= ~mask;
diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h
index 17b30c393b10..b95add5b253c 100644
--- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h
+++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h
@@ -200,5 +200,8 @@
 
 #define HIBMC_CRT_PALETTE                       0x80C00
 
+#define HIBMC_ENABLE_FLAG			0x802A4
+#define HIBMC_ENABLE_STATE			BIT(2)
+
 #define HIBMC_FIELD(field, value) (field(value) & field##_MASK)
 #endif
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH for drm-misc-fixes v6 2/2] drm/hisilicon/hibmc: Add a flag to indicate whether the OS-side driver has been loaded
  2026-11-26  3:06 ` [PATCH for drm-misc-fixes v6 2/2] drm/hisilicon/hibmc: Add a flag to indicate whether the OS-side driver has been loaded Yongbang Shi
@ 2026-11-26  3:25   ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-26  3:25 UTC (permalink / raw)
  To: Yongbang Shi; +Cc: dri-devel

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/hisilicon/hibmc: missing DP IRQ in hibmc_msi_init() on
  1-MSI fallback
--

commit 69a03a5b7c8791a711817f3c15bf41b6de54192a
Author: Lin He <helin52@huawei.com>

drm/hisilicon/hibmc: Add a flag to indicate whether the OS-side driver has been loaded

This commit tracks DisplayPort initialization with a flag, only requests
the DP MSI vector when DP is initialized, and updates HIBMC_ENABLE_FLAG
under a spinlock to tell the BMC when the driver is ready.

> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
> index a110b5e15e596..1e01a210b047d 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c

[ ... ]

> @@ -347,12 +349,17 @@ static void hibmc_unload(struct drm_device *dev)
>  static int hibmc_msi_init(struct drm_device *dev)
>  {
>  	struct pci_dev *pdev = to_pci_dev(dev->dev);
> +	struct hibmc_drm_private *priv = to_hibmc_drm_private(dev);
> +	int max_vectors = HIBMC_MIN_VECTORS;
>  	int valid_irq_num;
>  	int irq;
>  	int ret;
>  
> -	ret = pci_alloc_irq_vectors(pdev, HIBMC_MIN_VECTORS,
> -				    HIBMC_MAX_VECTORS, PCI_IRQ_MSI);
> +	if (priv->dp.initialized)
> +		max_vectors = HIBMC_MAX_VECTORS;
> +
> +	ret = pci_alloc_irq_vectors(pdev, HIBMC_MIN_VECTORS, max_vectors,
> +				    PCI_IRQ_MSI);
>  	if (ret < 0) {
>  		drm_err(dev, "enabling MSI failed: %d\n", ret);
>  		return ret;

[Severity: Medium]
Can pci_alloc_irq_vectors() succeed with only 1 MSI vector when
priv->dp.initialized is true?

Passing HIBMC_MIN_VECTORS (1) as min_vecs allows pci_alloc_irq_vectors()
to fall back to a single vector when multi-MSI is unavailable or vectors
are constrained.  In that case the loop below only registers
hibmc_interrupt() on vector 0 and never installs hibmc_dp_interrupt(),
yet hibmc_set_enable_flag() still sets HIBMC_ENABLE_STATE and
hibmc_dp_late_register() unmasks DP interrupts, leaving DP HPD broken and
DP interrupts unhandled on vector 0.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126030648.3231196-1-shiyongbang@huawei.com?part=2

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH for drm-misc-fixes v6 1/2] drm/hisilicon/hibmc: Modify the method of obtaining the hpd_status
  2026-11-26  3:06 ` [PATCH for drm-misc-fixes v6 1/2] drm/hisilicon/hibmc: Modify the method of obtaining the hpd_status Yongbang Shi
@ 2026-11-26  3:32   ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-11-26  3:32 UTC (permalink / raw)
  To: Yongbang Shi; +Cc: dri-devel

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] drm/hisilicon/hibmc: lost hotplug event on unplug+plug in
  hibmc_dp_hpd_isr()
- [Medium] drm/hisilicon/hibmc: race on link.status in
  hibmc_dp_reset_link()
- [Medium] drm/hisilicon/hibmc: stale HIBMC_HPD_OUT breaks
  hibmc_dp_detect()
--

commit be71ebe3ac9a8ced23cdd19669fbac348e9d77c8
Author: Lin He <helin52@huawei.com>

drm/hisilicon/hibmc: Modify the method of obtaining the hpd_status

This commit samples the DisplayPort HPD state in the hardirq handler
hibmc_dp_interrupt() via hibmc_dp_get_hpd_status() instead of polling in
the threaded handler, and serializes AUX transfers against
hibmc_dp_hpd_cfg() with aux_lock.

> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c
> index 9cf0b6be15bdc..245d6b9e2836a 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c
> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c
[ ... ]
> @@ -60,13 +58,13 @@ static int hibmc_dp_detect(struct drm_connector *connector,
>  {
>  	struct hibmc_dp *dp = to_hibmc_dp(connector);
>  	struct hibmc_dp_dev *dp_dev = dp->dp_dev;
> +	int hpd_status = READ_ONCE(dp->hpd_status);
>  	int ret = connector_status_disconnected;
>  
> -	if (dp->irq_status) {
> -		if (dp_dev->hpd_status != HIBMC_HPD_IN) {
> -			ret = connector_status_disconnected;
> -			goto exit;
> -		}
> +	if (hpd_status != HIBMC_HPD_IN) {
> +		drm_dbg_dp(dp->drm_dev, "dp detect skipped, hpd (%d)\n",
> +			   hpd_status);
> +		goto exit;
>  	}

[Severity: Medium]
Can dp->hpd_status remain stuck at HIBMC_HPD_OUT when hibmc_dp_detect()
runs, causing connected monitors to be reported as disconnected?

Previously, hibmc_dp_detect() only checked hpd_status after an HPD
interrupt had set dp->irq_status, and otherwise probed DPCD directly.
Now hibmc_dp_init() sets dp->hpd_status = HIBMC_HPD_OUT,
hibmc_dp_hw_init() sleeps 100 ms with HIBMC_DP_INTR_ENABLE masked without
calling hibmc_dp_get_hpd_status(), and only hibmc_dp_interrupt() ever
updates dp->hpd_status.

If pci_alloc_irq_vectors() in hibmc_msi_init() only allocates
HIBMC_MIN_VECTORS (1 vector), only the vblank interrupt is requested and
hibmc_dp_interrupt() is never registered, leaving dp->hpd_status at
HIBMC_HPD_OUT permanently.  dp->hpd_status is also not refreshed across
hibmc_pm_suspend() and hibmc_pm_resume() if a monitor is connected or
disconnected while suspended, or if connector detection runs during
registration before the HPD MSI fires.

> @@ -188,24 +186,26 @@ irqreturn_t hibmc_dp_hpd_isr(int irq, void *arg)
>  {
>  	struct drm_device *dev = (struct drm_device *)arg;
>  	struct hibmc_drm_private *priv = to_hibmc_drm_private(dev);
> -	int idx, exp_status;
> +	int status = READ_ONCE(priv->dp.hpd_status);
> +	int idx;
>  
>  	if (!drm_dev_enter(dev, &idx))
>  		return -ENODEV;
>  
> -	if (priv->dp.irq_status & DP_MASKED_SINK_HPD_PLUG_INT) {
> +	if (status == HIBMC_HPD_IN) {
> +		/* Plug takes aux_lock, so it must run in the thread. */
>  		drm_dbg_dp(&priv->dev, "HPD IN isr occur!\n");
>  		hibmc_dp_hpd_cfg(&priv->dp);
> -		exp_status = HIBMC_HPD_IN;
> -	} else {
> +	} else if (status == HIBMC_HPD_OUT) {
>  		drm_dbg_dp(&priv->dev, "HPD OUT isr occur!\n");
> -		hibmc_dp_reset_link(&priv->dp);
> -		exp_status = HIBMC_HPD_OUT;
> +	} else {
> +		drm_err(&priv->dev, "HPD status (%d) error\n", status);
> +		goto exit;
>  	}
>  
> -	if (hibmc_dp_check_hpd_status(&priv->dp, exp_status))
> -		drm_connector_helper_hpd_irq_event(&priv->dp.connector);
> +	drm_connector_helper_hpd_irq_event(&priv->dp.connector);

[Severity: Medium]
Can an unplug followed by a plug before hibmc_dp_hpd_isr() runs still lose
the hotplug notification and leave the link untrained?

<hardirq>                             irq/hibmc-hpd
hibmc_dp_interrupt() [unplug]
  priv->dp.hpd_status = HIBMC_HPD_OUT
  hibmc_dp_reset_link(&priv->dp)
    channel_equalized = false
hibmc_dp_interrupt() [plug]
  priv->dp.hpd_status = HIBMC_HPD_IN
                                      hibmc_dp_hpd_isr()
                                        hibmc_dp_hpd_cfg()
                                        drm_connector_helper_hpd_irq_event()
                                          check_connector_changed()
                                            hibmc_dp_detect()
                                              returns connected
                                            old_status == connected
                                            --> returns false (event dropped)

Because hibmc_dp_detect() never ran while priv->dp.hpd_status was
HIBMC_HPD_OUT, connector->status is still connector_status_connected when
hibmc_dp_detect() runs for the new plug.  drm_helper_probe_detect_ctx()
only increments connector->epoch_counter when the status changes, so
check_connector_changed() returns false and
drm_connector_helper_hpd_irq_event() suppresses the hotplug event.
Without a hotplug event to trigger a modeset, hibmc_dp_mode_set() does not
run to re-train the link after hibmc_dp_reset_link() cleared
channel_equalized.

Also, if hibmc_dp_hpd_isr() reads status == HIBMC_HPD_OUT at entry and the
plug hardirq updates priv->dp.hpd_status to HIBMC_HPD_IN before
hibmc_dp_detect() runs, hibmc_dp_detect() will perform DPCD AUX reads for
the newly plugged sink without hibmc_dp_hpd_cfg() having configured the
AUX and DPTX registers first.

[ ... ]

> diff --git a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
> index 602930964e930..a110b5e15e596 100644
> --- a/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
> +++ b/drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c
> @@ -59,11 +59,18 @@ static irqreturn_t hibmc_dp_interrupt(int irq, void *arg)
>  {
>  	struct drm_device *dev = (struct drm_device *)arg;
>  	struct hibmc_drm_private *priv = to_hibmc_drm_private(dev);
> +	int hpd_status;
>  	u32 status;
>  
>  	status = readl(priv->mmio + HIBMC_DP_INTSTAT);
>  	if (status) {
> -		priv->dp.irq_status = status;
> +		hpd_status = hibmc_dp_get_hpd_status(&priv->dp);
> +		WRITE_ONCE(priv->dp.hpd_status, hpd_status);
> +
> +		/* Reset here so a later plug cannot hide this unplug. */
> +		if (hpd_status == HIBMC_HPD_OUT)
> +			hibmc_dp_reset_link(&priv->dp);

[Severity: Medium]
Can calling hibmc_dp_reset_link() from hardirq context race with ongoing
link training in hibmc_dp_mode_set()?

hibmc_dp_mode_set()
  hibmc_dp_link_training()
    hibmc_dp_link_training_channel_eq()
      drm_dp_dpcd_read_link_status(dp->aux, lane_status)
      <hardirq>
        hibmc_dp_interrupt()
          hibmc_dp_reset_link(&priv->dp)
            dp->link.status.clock_recovered = false
            dp->link.status.channel_equalized = false
      if (drm_dp_channel_eq_ok(lane_status, ...))
        dp->link.status.channel_equalized = true  <-- overwrites reset

hibmc_dp_reset_link() and hibmc_dp_link_training_channel_eq() update
dp->link.status without synchronization.  If an unplug interrupt arrives
just after drm_dp_dpcd_read_link_status() finishes,
hibmc_dp_link_training_channel_eq() sets channel_equalized back to true
from the pre-unplug lane_status.  Because hibmc_dp_reset_link() only runs
on HIBMC_HPD_OUT, channel_equalized stays true across a subsequent plug,
and hibmc_dp_mode_set() skips hibmc_dp_link_training().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261126030648.3231196-1-shiyongbang@huawei.com?part=1

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-26  3:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26  3:06 [PATCH for drm-misc-fixes v6 0/2] Fix some bugs in the hibmc DP Yongbang Shi
2026-11-26  3:06 ` [PATCH for drm-misc-fixes v6 1/2] drm/hisilicon/hibmc: Modify the method of obtaining the hpd_status Yongbang Shi
2026-11-26  3:32   ` sashiko-bot
2026-11-26  3:06 ` [PATCH for drm-misc-fixes v6 2/2] drm/hisilicon/hibmc: Add a flag to indicate whether the OS-side driver has been loaded Yongbang Shi
2026-11-26  3:25   ` sashiko-bot

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.