drm/vc4: dsi: Make failed reads visible and recoverable
Subsystems (3)
cover drm/vc4: dsi: Make failed reads visible and recoverable
DSI reads on the Raspberry Pi 4 (vc4, DSI1) can fail in two ways that the caller cannot handle:
- A peripheral that detected an error answers a read with an Acknowledge and Error Report. vc4 copies its two bytes into the caller's buffer and returns success, so the error bits look like register contents (patch 1).
- After a read whose bus turnaround times out, every following DSI transfer times out as well, until the display is switched off and on (patch 2).
These patches do not prevent the timeouts. With video running, vc4 does not keep commands within vertical blanking, so a read can still collide with active video and time out. That is a separate issue; this series makes such failures visible to the caller and recoverable without a modeset.
Tested on a Raspberry Pi 4 with a 2-lane video mode panel at 120 Hz, using a backport of this series to the Raspberry Pi 6.18 kernel and a panel driver that retries failed reads up to 8 times: 499 of 500 reads with video running and 1000 of 1000 with video stopped returned the expected data, with no lock-up. Without the series, the first timeout left DSI unusable.
Compile-tested on drm-misc-next (arm64 defconfig, DRM_VC4=m, W=1), each patch on its own.
Henry Zhang (2):
drm/vc4: dsi: Don't return error reports as read data drm/vc4: dsi: Recover from a timed-out transfer
drivers/gpu/drm/vc4/vc4_dsi.c | 114 ++++++++++++++++++++++++++++++++-- 1 file changed, 109 insertions(+), 5 deletions(-)
base-commit: 3e32932d3626d0279f9b3531bd648f8c0a16cb08
Signature · 1 line
2.47.3
PATCH 1/2 drm/vc4: dsi: Don't return error reports as read data
When a DSI peripheral detects an error, for example contention during the bus turnaround, it may answer a read request with an Acknowledge and Error Report short packet instead of the read response.
vc4_dsi_host_transfer() does not check the type of the received packet (there is a FINISHME for it). It copies the two bytes of the error report into the caller's buffer and returns success, so the caller gets the error bits as if they were register contents. Packets received with a checksum error, an uncorrectable ECC error or incomplete are passed on the same way.
Return -EIO in these cases so that callers can tell a failed read from data, and retry if they want to.
--- drivers/gpu/drm/vc4/vc4_dsi.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
drivers/gpu/drm/vc4/vc4_dsi.c +20 -2
@@ -40,6 +40,8 @@#include <drm/drm_probe_helper.h> #include <drm/drm_simple_kms_helper.h> +#include <video/mipi_display.h> +#include "vc4_drv.h" #include "vc4_regs.h"
@@ -1300,6 +1302,24 @@ static ssize_t vc4_dsi_host_transfer(struct mipi_dsi_host *host,u32 rxpkt1h =DSI_PORT_READ (RXPKT1H );u8 *msg_rx = msg->rx_buf; +/* +* A peripheral that detected an error, e.g. contention during +* the bus turnaround, may answer with an Acknowledge and Error +* Report instead of the read response. Don't hand that, or a +* packet received with errors, to the caller as read data. +* Bits 7:6 of the Data ID are the virtual channel. +*/ +if ((rxpkt1h & (DSI_RXPKT1H_CRC_ERR |DSI_RXPKT1H_DET_ERR | +DSI_RXPKT1H_INCOMP_PKT )) || + (!(rxpkt1h &DSI_RXPKT1H_PKT_TYPE_LONG ) && + (VC4_GET_FIELD (rxpkt1h,DSI_RXPKT1H_DT_LP_CMD ) &0x3f ) == +MIPI_DSI_RX_ACKNOWLEDGE_AND_ERROR_REPORT )) { +drm_dbg_driver (drm,"DSI read rejected, RXPKT1H 0x%08x\n" , + rxpkt1h); + ret = -EIO ; + goto reset_fifo_and_return; + } +if (rxpkt1h &DSI_RXPKT1H_PKT_TYPE_LONG ) {u32 rxlen =VC4_GET_FIELD (rxpkt1h,DSI_RXPKT1H_BC_PARAM );
@@ -1314,8 +1334,6 @@ static ssize_t vc4_dsi_host_transfer(struct mipi_dsi_host *host,for (i =0 ; i < msg->rx_len; i++) msg_rx[i] =DSI_READ (DSI1_RXPKT_FIFO ); }else { -/* FINISHME: Handle AWER */ - msg_rx[0 ] =VC4_GET_FIELD (rxpkt1h,DSI_RXPKT1H_SHORT_0 );if (msg->rx_len >1 ) {
Signature · 1 line
2.47.3
PATCH 2/2 drm/vc4: dsi: Recover from a timed-out transfer
In reply to Henry ZhangWhen a transfer times out, vc4_dsi_host_transfer() disables the command, resets the FIFOs and returns -ETIMEDOUT. That is not always
enough: after an LP receive timeout during a read (the peripheral did not complete the bus turnaround), every following transfer times out as well, with no interrupt and STAT reading back 0. Only a modeset, which goes through post_disable/pre_enable, brings the block back.
Reset the DSI block and its analog front end after a timeout and restore the configuration programmed in pre_enable, so that DSI keeps working without a modeset. The timed-out message is not resent, as it may already have been executed by the peripheral; the error is returned and the caller decides whether to retry.
This does not prevent the timeouts themselves. With video running, vc4 does not keep commands within vertical blanking, and transfers can still time out, sometimes several in a row after a reset. That is a separate issue.
Tested on a Raspberry Pi 4 (DSI1, 2 lanes, video mode at 120 Hz) with a panel driver that retries failed reads up to 8 times. Without this change, the first timed-out transfer left DSI unusable until the display was switched off and on. With it, 499 of 500 reads with video running (77 transfers timed out, 71 of them writes, all followed by working transfers) and 1000 of 1000 reads with video stopped returned the expected data.
--- drivers/gpu/drm/vc4/vc4_dsi.c | 92 +++++++++++++++++++++++++++++++++-- 1 file changed, 89 insertions(+), 3 deletions(-)
drivers/gpu/drm/vc4/vc4_dsi.c +89 -3
@@ -1171,10 +1171,9 @@ static int vc4_dsi_bridge_attach(struct drm_bridge *bridge, &dsi->bridge, flags); } -static ssize_t vc4_dsi_host_transfer (struct mipi_dsi_host *host, -const struct mipi_dsi_msg *msg) +static ssize_t vc4_dsi_transfer (struct vc4_dsi *dsi, +const struct mipi_dsi_msg *msg) { -struct vc4_dsi *dsi =host_to_dsi (host);struct drm_device *drm = dsi->bridge.dev;struct mipi_dsi_packet packet;u32 pkth =0 , pktc =0 ;
@@ -1359,6 +1358,93 @@ reset_fifo_and_return:return ret; } +/* +* Reset the DSI block and its analog front end, then restore the +* configuration done in pre_enable. Resetting the FIFOs alone does not +* clear the state the block can be left in after a transfer timed out +* (e.g. on an LP receive timeout): every following transfer then times +* out as well, until the next modeset. +*/ +static void vc4_dsi_reset_and_restore (struct vc4_dsi *dsi) +{ +u32 ctrl =DSI_PORT_READ (CTRL ); +u32 afec0 =DSI_PORT_READ (PHY_AFEC0 ); +u32 afec1 =DSI_PORT_READ (PHY_AFEC1 ); +u32 disp0 =DSI_PORT_READ (DISP0_CTRL ) & ~DSI_DISP0_ENABLE ; +u32 disp1 =DSI_PORT_READ (DISP1_CTRL ); +u32 hstx_to =DSI_PORT_READ (HSTX_TO_CNT ); +u32 lprx_to =DSI_PORT_READ (LPRX_TO_CNT ); +u32 ta_to =DSI_PORT_READ (TA_TO_CNT ); +u32 pr_to =DSI_PORT_READ (PR_TO_CNT ); +u32 phyc =DSI_PORT_READ (PHYC ); +u32 clt0 =DSI_PORT_READ (HS_CLT0 ); +u32 clt1 =DSI_PORT_READ (HS_CLT1 ); +u32 clt2 =DSI_PORT_READ (HS_CLT2 ); +u32 dlt3 =DSI_PORT_READ (HS_DLT3 ); +u32 dlt4 =DSI_PORT_READ (HS_DLT4 ); +u32 dlt5 =DSI_PORT_READ (HS_DLT5 ); +u32 dlt6 =DSI_PORT_READ (HS_DLT6 ); +u32 dlt7 =DSI_PORT_READ (HS_DLT7 ); + +DSI_PORT_WRITE (DISP0_CTRL , disp0); +DSI_PORT_WRITE (TXPKT1C ,0 ); +DSI_PORT_WRITE (CTRL ,DSI_CTRL_SOFT_RESET_CFG | +DSI_PORT_BIT (CTRL_RESET_FIFOS )); +DSI_PORT_WRITE (PHY_AFEC0 , afec0 |DSI_PORT_BIT (PHY_AFEC0_RESET )); +/* AFEC reset hold time */ +mdelay (1 ); + +DSI_PORT_WRITE (CTRL , ctrl & ~DSI_CTRL_CAL_BYTE ); +DSI_PORT_WRITE (HSTX_TO_CNT , hstx_to); +DSI_PORT_WRITE (LPRX_TO_CNT , lprx_to); +DSI_PORT_WRITE (TA_TO_CNT , ta_to); +DSI_PORT_WRITE (PR_TO_CNT , pr_to); +DSI_PORT_WRITE (PHYC , phyc); +DSI_PORT_WRITE (HS_CLT0 , clt0); +DSI_PORT_WRITE (HS_CLT1 , clt1); +DSI_PORT_WRITE (HS_CLT2 , clt2); +DSI_PORT_WRITE (HS_DLT3 , dlt3); +DSI_PORT_WRITE (HS_DLT4 , dlt4); +DSI_PORT_WRITE (HS_DLT5 , dlt5); +DSI_PORT_WRITE (HS_DLT6 , dlt6); +DSI_PORT_WRITE (HS_DLT7 , dlt7); +DSI_PORT_WRITE (PHY_AFEC1 , afec1); +DSI_PORT_WRITE (CTRL , ctrl); +DSI_PORT_WRITE (DISP1_CTRL , disp1); +DSI_PORT_WRITE (DISP0_CTRL , disp0); +DSI_PORT_WRITE (PHY_AFEC0 , afec0 & ~DSI_PORT_BIT (PHY_AFEC0_RESET )); + +DSI_PORT_WRITE (STAT ,DSI_PORT_READ (STAT )); +DSI_PORT_WRITE (INT_STAT ,DSI_PORT_READ (INT_STAT )); +DSI_PORT_WRITE (INT_EN ,DSI_PORT_BIT (INTERRUPTS_ALWAYS_ENABLED )); +} + +static ssize_t vc4_dsi_host_transfer (struct mipi_dsi_host *host, +const struct mipi_dsi_msg *msg) +{ +struct vc4_dsi *dsi =host_to_dsi (host); +u32 disp0_ctrl; +ssize_t ret; + + ret =vc4_dsi_transfer (dsi, msg); +if (ret != -ETIMEDOUT ) +return ret; + +/* +* Leave the block usable for the next transfer. The message is not +* resent: it may already have reached the peripheral, and only the +* caller knows whether it is safe to repeat. +*/ + disp0_ctrl =DSI_PORT_READ (DISP0_CTRL ); +dev_warn (&dsi->pdev->dev, +"transfer timed out (stat 0x%08x), resetting DSI\n" , +DSI_PORT_READ (STAT )); +vc4_dsi_reset_and_restore (dsi); +DSI_PORT_WRITE (DISP0_CTRL , disp0_ctrl); + +return ret; +} +static const struct component_ops vc4_dsi_ops;static int vc4_dsi_host_attach (struct mipi_dsi_host *host,struct mipi_dsi_device *device)
Signature · 1 line
2.47.3
[email protected]
AI reviewRe: [PATCH 2/2] drm/vc4: dsi: Recover from a timed-out transfer
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider: - [High] drm/vc4: dsi: premature controller enable during timeout reset causes hardware instability…
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] drm/vc4: dsi: premature controller enable during timeout reset causes hardware instability
- [High] drm/vc4: dsi: spurious completion due to IRQ handler TOCTOU race
- [Medium] drm/vc4: missing mutex serialization in DSI host transfer
--
commit b73bc40cfc01c81e251315be152ff0c2c6aa9361
Author: Henry Zhang <[email protected]>
drm/vc4: dsi: Recover from a timed-out transfer
When a transfer times out, vc4_dsi_host_transfer() disables the command, resets the FIFOs and returns -ETIMEDOUT. This commit adds a recovery mechanism that resets the DSI block and its analog front end after a timeout and restores the configuration so DSI keeps working without a modeset.
drivers/gpu/drm/vc4/vc4_dsi.c +0 -0
[ ... ]
@@ -1359,6 +1358,93 @@ static ssize_t vc4_dsi_host_transfer(struct mipi_dsi_host *host,
return ret;
}
+/*
+ * Reset the DSI block and its analog front end, then restore the
+ * configuration done in pre_enable. Resetting the FIFOs alone does not
+ * clear the state the block can be left in after a transfer timed out
+ * (e.g. on an LP receive timeout): every following transfer then times
+ * out as well, until the next modeset.
+ */
+static void vc4_dsi_reset_and_restore(struct vc4_dsi *dsi) +{
+ u32 ctrl = DSI_PORT_READ(CTRL);
+ u32 afec0 = DSI_PORT_READ(PHY_AFEC0);
[ ... ]
+ DSI_PORT_WRITE(DISP0_CTRL, disp0);
+ DSI_PORT_WRITE(TXPKT1C, 0);
+ DSI_PORT_WRITE(CTRL, DSI_CTRL_SOFT_RESET_CFG |
+ DSI_PORT_BIT(CTRL_RESET_FIFOS));
+ DSI_PORT_WRITE(PHY_AFEC0, afec0 | DSI_PORT_BIT(PHY_AFEC0_RESET));
+ /* AFEC reset hold time */
+ mdelay(1);
+
+ DSI_PORT_WRITE(CTRL, ctrl & ~DSI_CTRL_CAL_BYTE);
+ DSI_PORT_WRITE(HSTX_TO_CNT, hstx_to);
+ DSI_PORT_WRITE(LPRX_TO_CNT, lprx_to);
[Severity: High]
Can writing ctrl & ~DSI_CTRL_CAL_BYTE back to CTRL prematurely un-gate and enable the controller before the subsequent writes to timing and PHY configuration registers?
Since ctrl was read while a transfer was in progress, it contains the enable bit (DSI0_CTRL_CTRL0 or DSI1_CTRL_EN).
Writing it back here enables the hardware block before its timings (HSTX_TO_CNT, HS_CLT0, PHYC, etc.) are restored, which could cause erratic bus behavior and unrecoverable hardware states.
Review
Quoted 1 line
(quoted diff) +1
-0+ DSI_PORT_WRITE(TA_TO_CNT, ta_to);
[ ... ]
+static ssize_t vc4_dsi_host_transfer(struct mipi_dsi_host *host,
+ const struct mipi_dsi_msg *msg)
+{
+ struct vc4_dsi *dsi = host_to_dsi(host);
+ u32 disp0_ctrl;
+ ssize_t ret;
+
+ ret = vc4_dsi_transfer(dsi, msg);
[Severity: Medium]
Does this entry point need a mutex to serialize concurrent transfers?
If user-space concurrently triggers DCS commands (e.g., via sysfs backlight updates and DRM KMS modesets), they can race because vc4_dsi_transfer() modifies shared variables like dsi->xfer_completion without a lock.
With this patch, a timeout caused by such a race now triggers a full block reset in vc4_dsi_reset_and_restore(), disrupting any interleaved concurrent transfer.
+ if (ret != -ETIMEDOUT)
+ return ret;
+
+ /*
+ * Leave the block usable for the next transfer. The message is not
+ * resent: it may already have reached the peripheral, and only the
+ * caller knows whether it is safe to repeat.
+ */
+ disp0_ctrl = DSI_PORT_READ(DISP0_CTRL);
+ dev_warn(&dsi->pdev->dev,
+ "transfer timed out (stat 0x%08x), resetting DSI\n",
+ DSI_PORT_READ(STAT));
+ vc4_dsi_reset_and_restore(dsi);
+ DSI_PORT_WRITE(DISP0_CTRL, disp0_ctrl);
+
+ return ret;
+}
[Severity: High]
Can a timed-out transfer cause a spurious completion of a subsequent transfer?
If vc4_dsi_transfer() times out, wait_for_completion_timeout() returns. However, if the hardware interrupt had fired and the threaded IRQ handler (vc4_dsi_irq_handler) was preempted before calling complete(&dsi->xfer_completion), it could still be pending.
Since there is no synchronization (like synchronize_irq()) in this timeout recovery path to wait for the IRQ handler to finish, it returns immediately.
The caller might retry the transfer, reinitializing dsi->xfer_completion. The preempted IRQ thread could then resume, calling complete() and falsely waking up the new transfer prematurely while the hardware is still busy.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH 2/2] drm/vc4: dsi: Recover from a timed-out transfer
Quoted 6 lines · On Mon, Oct 12, 2026 at 12:16 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] drm/vc4: dsi: premature controller enable during timeout reset causes hardware instability
- [High] drm/vc4: dsi: spurious completion due to IRQ handler TOCTOU race
- [Medium] drm/vc4: missing mutex serialization in DSI host transfer
--
Thanks for the review.
1. Agreed. Mainline's pre_enable ungates the block only after the PHY timings, timeouts and DISP1 are programmed; the restore must follow the same order. Will fix in v2.
2. Agreed. The race predates this patch, but the timeout path is the right place to close it; v2 will call synchronize_irq() before the reset.
3. vc4_dsi_host_transfer() has never serialized transfers. I'll add a separate patch in v2 that takes a mutex around host transfers.
Henry
Quoted 113 lines
commit
b73bc40cfc01c81e251315be152ff0c2c6aa9361
Author: Henry Zhang <[email protected]>drm/vc4: dsi: Recover from a timed-out transfer
When a transfer times out,
vc4_dsi_host_transfer()disables the command, resets the FIFOs and returns-ETIMEDOUT. This commit adds a recovery mechanism that resets the DSI block and its analog front end after a timeout and restores the configuration so DSI keeps working without a modeset.drivers/gpu/drm/vc4/vc4_dsi.c +22
-0@@ -1359,6 +1358,93 @@ static ssize_t vc4_dsi_host_transfer(struct mipi_dsi_host *host,return ret; } +/* +* Reset the DSI block and its analog front end, then restore the +* configuration done in pre_enable. Resetting the FIFOs alone does not +* clear the state the block can be left in after a transfer timed out +* (e.g. on an LP receive timeout): every following transfer then times +* out as well, until the next modeset. +*/ +static void vc4_dsi_reset_and_restore (struct vc4_dsi *dsi) +{ +u32 ctrl =DSI_PORT_READ (CTRL ); +u32 afec0 =DSI_PORT_READ (PHY_AFEC0 ); +DSI_PORT_WRITE (DISP0_CTRL , disp0); +DSI_PORT_WRITE (TXPKT1C ,0 ); +DSI_PORT_WRITE (CTRL ,DSI_CTRL_SOFT_RESET_CFG | +DSI_PORT_BIT (CTRL_RESET_FIFOS )); +DSI_PORT_WRITE (PHY_AFEC0 , afec0 |DSI_PORT_BIT (PHY_AFEC0_RESET )); +/* AFEC reset hold time */ +mdelay (1 ); + +DSI_PORT_WRITE (CTRL , ctrl & ~DSI_CTRL_CAL_BYTE ); +DSI_PORT_WRITE (HSTX_TO_CNT , hstx_to); +DSI_PORT_WRITE (LPRX_TO_CNT , lprx_to);[Severity: High]
Can writing ctrl & ~DSI_CTRL_CAL_BYTE back to CTRL prematurely un-gate and enable the controller before the subsequent writes to timing and PHY configuration registers?Since ctrl was read while a transfer was in progress, it contains the enable bit (
DSI0_CTRL_CTRL0orDSI1_CTRL_EN).Writing it back here enables the hardware block before its timings (
HSTX_TO_CNT,HS_CLT0, PHYC, etc.) are restored, which could cause erratic bus behavior and unrecoverable hardware states.Quoted 1 line
+
DSI_PORT_WRITE(TA_TO_CNT, ta_to);[ ... ]
drivers/gpu/drm/vc4/vc4_dsi.c +8
-0+static ssize_t vc4_dsi_host_transfer (struct mipi_dsi_host *host, +const struct mipi_dsi_msg *msg) +{ +struct vc4_dsi *dsi =host_to_dsi (host); +u32 disp0_ctrl; +ssize_t ret; + + ret =vc4_dsi_transfer (dsi, msg);[Severity: Medium]
Does this entry point need a mutex to serialize concurrent transfers?If user-space concurrently triggers DCS commands (e.g., via sysfs backlight updates and DRM KMS modesets), they can race because
vc4_dsi_transfer()modifies shared variables likedsi->xfer_completionwithout a lock.With this patch, a timeout caused by such a race now triggers a full block reset in
vc4_dsi_reset_and_restore(), disrupting any interleaved concurrent transfer.drivers/gpu/drm/vc4/vc4_dsi.c +17
-0+if (ret != -ETIMEDOUT ) +return ret; + +/* +* Leave the block usable for the next transfer. The message is not +* resent: it may already have reached the peripheral, and only the +* caller knows whether it is safe to repeat. +*/ + disp0_ctrl =DSI_PORT_READ (DISP0_CTRL ); +dev_warn (&dsi->pdev->dev, +"transfer timed out (stat 0x%08x), resetting DSI\n" , +DSI_PORT_READ (STAT )); +vc4_dsi_reset_and_restore (dsi); +DSI_PORT_WRITE (DISP0_CTRL , disp0_ctrl); + +return ret; +}[Severity: High]
Can a timed-out transfer cause a spurious completion of a subsequent transfer?If
vc4_dsi_transfer()times out,wait_for_completion_timeout()returns. However, if the hardware interrupt had fired and the threaded IRQ handler (vc4_dsi_irq_handler) was preempted before callingcomplete(&dsi->xfer_completion), it could still be pending.Since there is no synchronization (like
synchronize_irq()) in this timeout recovery path to wait for the IRQ handler to finish, it returns immediately.The caller might retry the transfer, reinitializing
dsi->xfer_completion. The preempted IRQ thread could then resume, callingcomplete()and falsely waking up the new transfer prematurely while the hardware is still busy.--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH 2/2] drm/vc4: dsi: Recover from a timed-out transfer
In reply to [email protected]Quoted 145 lines · On Mon, Oct 12, 2026 at 12:16 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] drm/vc4: dsi: premature controller enable during timeout reset causes hardware instability
- [High] drm/vc4: dsi: spurious completion due to IRQ handler TOCTOU race
- [Medium] drm/vc4: missing mutex serialization in DSI host transfer --
Thanks for the review.1. Agreed. Mainline's
pre_enableungates the block only after the PHY timings, timeouts and DISP1 are programmed; the restore must follow the same order. Will fix in v2.
2. Agreed. The race predates this patch, but the timeout path is the right place to close it; v2 will callsynchronize_irq()before the reset.
3.vc4_dsi_host_transfer()has never serialized transfers. I'll add a separate patch in v2 that takes a mutex around host transfers.Henry
commit
b73bc40cfc01c81e251315be152ff0c2c6aa9361
Author: Henry Zhang <[email protected]>drm/vc4: dsi: Recover from a timed-out transfer
When a transfer times out,
vc4_dsi_host_transfer()disables the command, resets the FIFOs and returns-ETIMEDOUT. This commit adds a recovery mechanism that resets the DSI block and its analog front end after a timeout and restores the configuration so DSI keeps working without a modeset.drivers/gpu/drm/vc4/vc4_dsi.c +22
-0@@ -1359,6 +1358,93 @@ static ssize_t vc4_dsi_host_transfer(structmipi_dsi_host *host, return ret; } +/* +* Reset the DSI block and its analog front end, then restore the +* configuration done in pre_enable. Resetting the FIFOs alone does not +* clear the state the block can be left in after a transfer timed out +* (e.g. on an LP receive timeout): every following transfer then times +* out as well, until the next modeset. +*/ +static void vc4_dsi_reset_and_restore (struct vc4_dsi *dsi) +{ +u32 ctrl =DSI_PORT_READ (CTRL ); +u32 afec0 =DSI_PORT_READ (PHY_AFEC0 ); +DSI_PORT_WRITE (DISP0_CTRL , disp0); +DSI_PORT_WRITE (TXPKT1C ,0 ); +DSI_PORT_WRITE (CTRL ,DSI_CTRL_SOFT_RESET_CFG | +DSI_PORT_BIT (CTRL_RESET_FIFOS )); +DSI_PORT_WRITE (PHY_AFEC0 , afec0 |DSI_PORT_BIT (PHY_AFEC0_RESET )); +/* AFEC reset hold time */ +mdelay (1 ); + +DSI_PORT_WRITE (CTRL , ctrl & ~DSI_CTRL_CAL_BYTE ); +DSI_PORT_WRITE (HSTX_TO_CNT , hstx_to); +DSI_PORT_WRITE (LPRX_TO_CNT , lprx_to);[Severity: High]
Can writing ctrl & ~DSI_CTRL_CAL_BYTE back to CTRL prematurely un-gate and enable the controller before the subsequent writes to timing and PHY configuration registers?Since ctrl was read while a transfer was in progress, it contains the enable
bit (DSI0_CTRL_CTRL0orDSI1_CTRL_EN).Writing it back here enables the hardware block before its timings (
HSTX_TO_CNT,HS_CLT0, PHYC, etc.) are restored, which could cause erratic bus
behavior and unrecoverable hardware states.Quoted 1 line
+
DSI_PORT_WRITE(TA_TO_CNT, ta_to);[ ... ]
drivers/gpu/drm/vc4/vc4_dsi.c +8
-0+static ssize_t vc4_dsi_host_transfer (struct mipi_dsi_host *host, +const struct mipi_dsi_msg *msg) +{ +struct vc4_dsi *dsi =host_to_dsi (host); +u32 disp0_ctrl; +ssize_t ret; + + ret =vc4_dsi_transfer (dsi, msg);[Severity: Medium]
Does this entry point need a mutex to serialize concurrent transfers?If user-space concurrently triggers DCS commands (e.g., via sysfs backlight updates and DRM KMS modesets), they can race because
vc4_dsi_transfer()modifies shared variables likedsi->xfer_completionwithout a lock.With this patch, a timeout caused by such a race now triggers a full block reset in
vc4_dsi_reset_and_restore(), disrupting any interleaved concurrent transfer.drivers/gpu/drm/vc4/vc4_dsi.c +17
-0+if (ret != -ETIMEDOUT ) +return ret; + +/* +* Leave the block usable for the next transfer. The message is not +* resent: it may already have reached the peripheral, and only the +* caller knows whether it is safe to repeat. +*/ + disp0_ctrl =DSI_PORT_READ (DISP0_CTRL ); +dev_warn (&dsi->pdev->dev, +"transfer timed out (stat 0x%08x), resetting DSI\n" , +DSI_PORT_READ (STAT )); +vc4_dsi_reset_and_restore (dsi); +DSI_PORT_WRITE (DISP0_CTRL , disp0_ctrl); + +return ret; +}[Severity: High]
Can a timed-out transfer cause a spurious completion of a subsequent transfer?If
vc4_dsi_transfer()times out,wait_for_completion_timeout()returns. However, if the hardware interrupt had fired and the threaded IRQ handler (vc4_dsi_irq_handler) was preempted before callingcomplete(&dsi->xfer_completion), it could still be pending.Since there is no synchronization (like
synchronize_irq()) in this timeout recovery path to wait for the IRQ handler to finish, it returns immediately.The caller might retry the transfer, reinitializing
dsi->xfer_completion. The
preempted IRQ thread could then resume, callingcomplete()and falsely waking up
the new transfer prematurely while the hardware is still busy.--
Sashiko AI review ·
https://sashiko.dev/#/patchset/[email protected]?part=2