Fix some bugs in the hibmc DP
Subsystems (3)
Yongbang Shi
maintainerv3 cover Fix some bugs in the hibmc DP
From: Lin He <[email protected]>
Fix some bugs in the hibmc DP driver.
---
ChangeLog:
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_comm.h | 1 - drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c | 32 +++++++++++------ drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h | 5 +-- .../gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c | 34 +++++++++++-------- .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 32 ++++++++++++++++- .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 2 ++ .../gpu/drm/hisilicon/hibmc/hibmc_drm_i2c.c | 19 +++++++++-- .../gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h | 3 ++ 8 files changed, 96 insertions(+), 32 deletions(-)
Signature · 1 line
2.43.0
Yongbang Shi
maintainerPATCH v3 1/2 drm/hisilicon/hibmc: Modify the method of obtaining the hpd_status
From: Lin He <[email protected]>
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).
* Detection and training are not performed if hpd_status is not HPD_IN.
* Set the initial status of hpd_status to HPD_OUT.
---
ChangeLog:
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_comm.h | 1 - drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c | 32 +++++++++++------ drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h | 5 +-- .../gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c | 34 +++++++++++-------- .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 2 +- 5 files changed, 45 insertions(+), 29 deletions(-)
drivers/gpu/drm/hisilicon/hibmc/dp/dp_comm.h +0 -1
@@ -43,7 +43,6 @@ struct hibmc_dp_dev {u8 downstream_ports[DP_MAX_DOWNSTREAM_PORTS ];struct drm_dp_desc desc;bool is_branch; -int hpd_status;void __iomem *serdes_base; };
drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c +21 -11
@@ -191,6 +191,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 ; }
@@ -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; }
drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.h +3 -2
@@ -15,6 +15,7 @@struct hibmc_dp_dev ;enum hibmc_hpd_status { +HIBMC_HPD_UNKNOWN ,HIBMC_HPD_OUT ,HIBMC_HPD_IN , };
@@ -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);
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c +20 -14
@@ -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;
@@ -63,11 +61,10 @@ static int hibmc_dp_detect(struct drm_connector *connector,struct hibmc_dp_dev *dp_dev = dp->dp_dev;int ret = connector_status_disconnected; -if (dp->irq_status) { -if (dp_dev->hpd_status !=HIBMC_HPD_IN ) { - ret = connector_status_disconnected; - goto exit; - } +if (dp->hpd_status !=HIBMC_HPD_IN ) { +drm_dbg_dp (dp->drm_dev,"dp detect skipped, hpd (%d)\n" , + dp->hpd_status); + goto exit; }if (!hibmc_dp_get_dpcd (dp_dev)) {
@@ -166,6 +163,12 @@ static void hibmc_dp_encoder_enable(struct drm_encoder *drm_encoder, struct hibmc_dp *dp = container_of(drm_encoder, struct hibmc_dp, encoder);struct drm_display_mode *mode = &drm_encoder->crtc->state->mode; +if (dp->hpd_status !=HIBMC_HPD_IN ) { +drm_dbg_dp (dp->drm_dev,"dp encoder enable skipped, hpd (%d)\n" , + dp->hpd_status); +return ; + } +if (hibmc_dp_prepare (dp, mode))return ;
@@ -189,24 +192,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 = 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 ) {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 +228,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) {
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c +1 -1
@@ -62,7 +62,7 @@ static irqreturn_t hibmc_dp_interrupt(int irq, void *arg) status =readl (priv->mmio +HIBMC_DP_INTSTAT );if (status) { - priv->dp.irq_status = status; + priv->dp.hpd_status =hibmc_dp_get_hpd_status (&priv->dp);writel (status, priv->mmio +HIBMC_DP_INTCLR );return IRQ_WAKE_THREAD ; }
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH for drm-misc-fixes v3 1/2] drm/hisilicon/hibmc: Modify the method of obtaining the hpd_status
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider: - [High] drm/hisilicon: Hardcoded initial HPD_OUT state breaks boot display detection - [High]…
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] drm/hisilicon: Hardcoded initial HPD_OUT state breaks boot display detection
- [High] drm/hisilicon: Removal of HPD debounce causes DPCD read failures on hotplug
- [Medium] drm/hisilicon: Early exit in encoder_enable breaks KMS forced modesets
- [Low] drm/hisilicon: Data race on dp->hpd_status between hardirq and process contexts --
commit 19dc442443127128a0c2f9bcb0ceca722bb81f14
Author: Lin He <[email protected]>
drm/hisilicon/hibmc: Modify the method of obtaining the hpd_status
This commit replaces the polling mechanism in the lower half of the HPD interrupt with a direct read of the interrupt status in the upper half. It also skips detection and training if the status is not HPD_IN, and initializes the state to HPD_OUT.
Quoted 4 lines
drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c +0
-0
[ ... ]
Quoted 18 lines
drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c +3
-8@@ -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,
drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c void hibmc_dp_set_cbar(struct hibmc_dp *dp, const struct hibmc_dp_cbar_cfg *cfg) · line 344
Quoted 10 lines
drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c +10
-0+ 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 ;
[Severity: High]
Does mapping the 'plug intermediate' state (value 2) directly to HIBMC_HPD_IN without the previous 100ms debounce loop cause DPCD read failures?
When the link is physically bouncing during a hotplug event, returning HIBMC_HPD_IN immediately schedules hibmc_dp_detect(). The immediate AUX transaction in hibmc_dp_get_dpcd() can then fail because the connection has not stabilized, causing the hotplug event to be dropped.
Quoted 13 lines
drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c +3
-3+break ; +default : +break ; } - dp->dp_dev->hpd_status = exp_status; - -return true; }drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c +0
-0
[ ... ]
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c static int hibmc_dp_detect(struct drm_connector *connector, · line 64
Quoted 10 lines
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c +1
-5@@ -63,11 +61,10 @@ static int hibmc_dp_detect(struct drm_connector *connector,struct hibmc_dp_dev *dp_dev = dp->dp_dev;int ret = connector_status_disconnected; -if (dp->irq_status) { -if (dp_dev->hpd_status !=HIBMC_HPD_IN ) { - ret = connector_status_disconnected; - goto exit; - } +if (dp->hpd_status !=HIBMC_HPD_IN ) {
[Severity: Low]
Is there a theoretical data race here when reading dp->hpd_status?
It appears to be modified in hardirq context by hibmc_dp_interrupt() and read here in process context without WRITE_ONCE()/READ_ONCE() annotations or locking.
Quoted 6 lines
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c +3
-0+drm_dbg_dp (dp->drm_dev,"dp detect skipped, hpd (%d)\n" , + dp->hpd_status); + goto exit; }if (!hibmc_dp_get_dpcd (dp_dev)) {
[ ... ]
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c static void hibmc_dp_encoder_enable(struct drm_encoder *drm_encoder, · line 166
Quoted 5 lines
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c +1
-0@@ -166,6 +163,12 @@ static void hibmc_dp_encoder_enable(struct drm_encoder *drm_encoder, struct hibmc_dp *dp = container_of(drm_encoder, struct hibmc_dp, encoder);struct drm_display_mode *mode = &drm_encoder->crtc->state->mode; +if (dp->hpd_status !=HIBMC_HPD_IN ) {
[Severity: Medium]
Does this early exit break KMS forced modesets?
If a user overrides the connector to 'connected' (e.g., via sysfs or kernel command line) and the DRM core attempts an atomic commit, this check will refuse to program the hardware. This would desynchronize the KMS software state from the actual hardware state.
Quoted 7 lines
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c +5
-0+drm_dbg_dp (dp->drm_dev,"dp encoder enable skipped, hpd (%d)\n" , + dp->hpd_status); +return ; + } +if (hibmc_dp_prepare (dp, mode))return ;
[ ... ]
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c int hibmc_dp_init(struct hibmc_drm_private *priv) · line 231
Quoted 5 lines
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c +1
-0@@ -223,6 +228,7 @@ int hibmc_dp_init(struct hibmc_drm_private *priv) dp->mmio = priv->mmio; dp->drm_dev = dev; + dp->hpd_status =HIBMC_HPD_OUT ;
[Severity: High]
Will hardcoding the initial state to HIBMC_HPD_OUT break display detection at boot?
During boot, drm_client_setup() runs detect() before or immediately after interrupts are enabled in late_register(). Because detect() no longer queries the live hardware register and relies only on this cached value, it will read HPD_OUT and silently force a disconnected state even if a monitor is already connected.
Quoted 3 lines
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c +0
-0ret =hibmc_dp_hw_init (&priv->dp);if (ret) {
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Yongbang Shi
maintainerRe: [PATCH for drm-misc-fixes v3 1/2] drm/hisilicon/hibmc: Modify the method of obtaining the hpd_status
Quoted 55 lines
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] drm/hisilicon: Hardcoded initialHPD_OUTstate breaks boot display detection
- [High] drm/hisilicon: Removal of HPD debounce causes DPCD read failures on hotplug
- [Medium] drm/hisilicon: Early exit inencoder_enablebreaks KMS forced modesets
- [Low] drm/hisilicon: Data race ondp->hpd_statusbetween hardirq and process contexts --commit
19dc442443127128a0c2f9bcb0ceca722bb81f14
Author: Lin He <[email protected]>drm/hisilicon/hibmc: Modify the method of obtaining the
hpd_statusThis commit replaces the polling mechanism in the lower half of the HPD interrupt with a direct read of the interrupt status in the upper half. It also skips detection and training if the status is not
HPD_IN, and initializes the state toHPD_OUT.Quoted 4 lines
drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c +0
-0[ ... ]
Quoted 18 lines
drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c +3
-8@@ -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,drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c void hibmc_dp_set_cbar(struct hibmc_dp *dp, const struct hibmc_dp_cbar_cfg *cfg) · line 344
Quoted 10 lines
drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c +10
-0+ 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 ;[Severity: High]
Does mapping the 'plug intermediate' state (value 2) directly toHIBMC_HPD_INwithout the previous 100ms debounce loop cause DPCD read failures?
Quoted 5 lines
When the link is physically bouncing during a hotplug event, returning
HIBMC_HPD_INimmediately scheduleshibmc_dp_detect(). The immediate AUX transaction inhibmc_dp_get_dpcd()can then fail because the connection has not stabilized, causing the hotplug event to be dropped.
As answered in [1]: debouncing is implemented on-chip. The driver reads the debounced HPD state-machine output (HIBMC_DP_HPD_CUR_STATE in HIBMC_DP_HPD_STATUS), never the raw HPD pin, so mechanical contact bounce is filtered by hardware before software can observe it.
Regarding 'plug intermediate' (state 2): despite the name, this is not an unstable plug. The state machine enters state 2 only from the stable plug state, to debounce a possible unplug; the sink remains connected throughout. So mapping it to HIBMC_HPD_IN is consistent with the plug interrupt that fired.
Note also that the removed loop was not a debounce: our hardware already implements the debouncing, so the software 100 ms loop served no purpose.
Quoted 28 lines
Quoted 13 lines
drivers/gpu/drm/hisilicon/hibmc/dp/dp_hw.c +3
-3+break ; +default : +break ; } - dp->dp_dev->hpd_status = exp_status; - -return true; }drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c +0
-0[ ... ]
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c static int hibmc_dp_detect(struct drm_connector *connector, · line 64
Quoted 10 lines
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c +1
-5@@ -63,11 +61,10 @@ static int hibmc_dp_detect(struct drm_connector *connector,struct hibmc_dp_dev *dp_dev = dp->dp_dev;int ret = connector_status_disconnected; -if (dp->irq_status) { -if (dp_dev->hpd_status !=HIBMC_HPD_IN ) { - ret = connector_status_disconnected; - goto exit; - } +if (dp->hpd_status !=HIBMC_HPD_IN ) {[Severity: Low]
Is there a theoretical data race here when readingdp->hpd_status?
Quoted 4 lines
It appears to be modified in hardirq context by
hibmc_dp_interrupt()and read here in process context without WRITE_ONCE()/READ_ONCE() annotations or locking.
Okay, I'll change it to use READ_ONCE and WRITE_ONCE; they are indeed more secure.
Quoted 16 lines
Quoted 6 lines
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c +3
-0+drm_dbg_dp (dp->drm_dev,"dp detect skipped, hpd (%d)\n" , + dp->hpd_status); + goto exit; }if (!hibmc_dp_get_dpcd (dp_dev)) {[ ... ]
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c static void hibmc_dp_encoder_enable(struct drm_encoder *drm_encoder, · line 166
Quoted 5 lines
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c +1
-0@@ -166,6 +163,12 @@ static void hibmc_dp_encoder_enable(struct drm_encoder *drm_encoder, struct hibmc_dp *dp = container_of(drm_encoder, struct hibmc_dp, encoder);struct drm_display_mode *mode = &drm_encoder->crtc->state->mode; +if (dp->hpd_status !=HIBMC_HPD_IN ) {[Severity: Medium]
Does this early exit break KMS forced modesets?
Quoted 5 lines
If a user overrides the connector to 'connected' (e.g., via sysfs or kernel command line) and the DRM core attempts an atomic commit, this check will refuse to program the hardware. This would desynchronize the KMS software state from the actual hardware state.
Okay, the original purpose of this interceptor was to reduce the number of exception logs when HPD_OUT; it serves no other purpose. I will remove it in v4.
Quoted 18 lines
Quoted 7 lines
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c +5
-0+drm_dbg_dp (dp->drm_dev,"dp encoder enable skipped, hpd (%d)\n" , + dp->hpd_status); +return ; + } +if (hibmc_dp_prepare (dp, mode))return ;[ ... ]
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c int hibmc_dp_init(struct hibmc_drm_private *priv) · line 231
Quoted 5 lines
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_dp.c +1
-0@@ -223,6 +228,7 @@ int hibmc_dp_init(struct hibmc_drm_private *priv) dp->mmio = priv->mmio; dp->drm_dev = dev; + dp->hpd_status =HIBMC_HPD_OUT ;[Severity: High]
Will hardcoding the initial state toHIBMC_HPD_OUTbreak display detection at boot?
Quoted 6 lines
During boot,
drm_client_setup()runsdetect()before or immediately after interrupts are enabled inlate_register(). Becausedetect()no longer queries the live hardware register and relies only on this cached value, it will readHPD_OUTand silently force a disconnected state even if a monitor is already connected.
As explained in [1], a monitor connected before boot does trigger an HPD interrupt: the event is latched by hardware while DP interrupts are still masked. hibmc_dp_hw_init() ends with a 100 ms delay, which gives the hardware time to complete the debouncing and latch the interrupt; this already detects the plug-in in the vast majority of cases.
Moreover, even if a transient or sporadic hardware issue prevents the plug-in from being recognized within the 100 ms window, or even by the time drm_client_setup() runs, hibmc_dp_hpd_isr(), the threaded bottom half of the HPD interrupt, re-triggers the hotplug flow via drm_connector_helper_hpd_irq_event(), so the DP plug-in event is never lost.
[1] https://lore.kernel.org/all/[email protected]/
Thanks,
Yongbang.
Yongbang Shi
maintainerPATCH v3 2/2 drm/hisilicon/hibmc: Add a flag to indicate whether the OS-side driver has been loaded
In reply to Yongbang ShiFrom: Lin He <[email protected]>
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>
...
---
ChangeLog:
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)
--- .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c | 30 +++++++++++++++++++ .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 2 ++ .../gpu/drm/hisilicon/hibmc/hibmc_drm_i2c.c | 19 ++++++++++-- .../gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h | 3 ++ 4 files changed, 51 insertions(+), 3 deletions(-)
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.c +30 -0
@@ -167,6 +167,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 ;
@@ -423,6 +425,30 @@ static int hibmc_load(struct drm_device *dev)return ret; } +static inline void hibmc_set_enable_flag (struct hibmc_drm_private *priv) +{ +unsigned long flags; +u32 value; + +spin_lock_irqsave (&priv->gpio_lock, flags); + value =readl (priv->mmio +HIBMC_ENABLE_FLAG ); + value |=HIBMC_ENABLE_STATE ; +writel (value, priv->mmio +HIBMC_ENABLE_FLAG ); +spin_unlock_irqrestore (&priv->gpio_lock, flags); +} + +static inline void hibmc_set_disable_flag (struct hibmc_drm_private *priv) +{ +unsigned long flags; +u32 value; + +spin_lock_irqsave (&priv->gpio_lock, flags); + value =readl (priv->mmio +HIBMC_ENABLE_FLAG ); + value &= ~HIBMC_ENABLE_STATE ; +writel (value, priv->mmio +HIBMC_ENABLE_FLAG ); +spin_unlock_irqrestore (&priv->gpio_lock, flags); +} +static int hibmc_pci_probe (struct pci_dev *pdev,const struct pci_device_id *ent) {
@@ -458,6 +484,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",
@@ -470,6 +498,7 @@ static int hibmc_pci_probe(struct pci_dev *pdev,return 0 ; err_unload: +hibmc_set_disable_flag (to_hibmc_drm_private (dev));hibmc_unload (dev); err_return:return ret;
@@ -480,6 +509,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); }
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h +2 -0
@@ -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)
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_i2c.c +16 -3
@@ -27,7 +27,11 @@ 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 ); +unsigned long flags; +u32 tmp_dir; + +spin_lock_irqsave (&priv->gpio_lock, flags); + tmp_dir =readl (priv->mmio +GPIO_DATA_DIRECTION );if (value) { tmp_dir &= ~mask;
@@ -41,20 +45,29 @@ static void hibmc_set_i2c_signal(void *data, u32 mask, int value) tmp_dir |= mask;writel (tmp_dir, priv->mmio +GPIO_DATA_DIRECTION ); } +spin_unlock_irqrestore (&priv->gpio_lock, flags); }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 ); +unsigned long flags; +u32 tmp_dir; +int ret; + +spin_lock_irqsave (&priv->gpio_lock, flags); + tmp_dir =readl (priv->mmio +GPIO_DATA_DIRECTION );if ((tmp_dir & mask) != mask) { tmp_dir &= ~mask;writel (tmp_dir, priv->mmio +GPIO_DATA_DIRECTION ); } -return (readl (priv->mmio +GPIO_DATA ) & mask) ?1 :0 ; + ret = (readl (priv->mmio +GPIO_DATA ) & mask) ?1 :0 ; +spin_unlock_irqrestore (&priv->gpio_lock, flags); + +return ret; }static void hibmc_ddc_setsda (void *data,int state)
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_regs.h +3 -0
@@ -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
Signature · 1 line
2.43.0