drm/rockchip: vop2: RK3588 clocking, sync polarity, AXI port and window fixes
Subsystems (5)
v2 cover drm/rockchip: vop2: RK3588 clocking, sync polarity, AXI port and window fixes
This series collects fixes for the RK3588 VOP2 found while bringing up HDMI and DisplayPort output on an Orange Pi 5 (RK3588S).
Patch 1 is new in v2 and fixes a bug that is as old as the driver:
the chroma plane of a multi-planar YUV framebuffer is fetched from the GEM object of the luma plane, which is wrong when the planes are in different objects (two handles in ADDFB2).
Patches 2 and 3 fix the RK3588 interface setup: rk3588_calc_cru_cfg() leaves dividers it does not use uninitialised and the garbage ends up in VP_CLK_CTRL, and rk3588_get_hdmi_pol() decodes the POLFLAG bits it is handed as DRM mode flags, so the GRF sync polarity bits are wrong for most modes.
Patch 4 stops the RK3588 Cluster windows from advertising AFBC with the lossless colour transform (YTR) for RGB565/BGR565, which the decoder cannot display (black picture plus POST_BUF_EMPTY).
Patches 5 and 6 deal with POST_BUF_EMPTY underflows. The VOP2 fetches through two AXI read ports but the port of each window is fixed in the window table, so the usual primary plane plus overlay configuration of a video port puts both layers on one port while the other sits idle. One port cannot sustain two full screen 4K@120Hz layers (measured: the fetch rate collapses from ~6 GB/s to ~3 GB/s and about half of all lines underflow). ACLK_VOP was 750 MHz in the 4K@120Hz measurements (the HDMI FRL patches on the test kernel raise it from the default 500 MHz for these modes), and raising it to 850 MHz changes nothing, while moving one of the two windows to the other port removes the underflows. Patch 5 assigns the port of a window when it starts fetching, balancing the estimated load, in the atomic check from the whole new state; patch 6 limits the POST_BUF_EMPTY interrupt to once per frame, since an underflowing port otherwise keeps the CPU in the interrupt handler 50000 to 300000 times per second.
Patches 7 to 9 are smaller fixes: the start mixer search skipped Esmart3 (for_each_set_bit() was given the highest window id as the bit count), a gamma LUT update cleared the other fields of LUT_PORT_SEL (the VP0/VP2 dclk source selection and the VP0/VP1 merge enable), and the AFBC tile count and transform offset were wrong for a source that starts inside a 16 pixel superblock.
Tested on an Orange Pi 5 (RK3588S) with an HDMI 2.1 TV and a DisplayPort monitor, pictures judged with a camera. Patches 2 and 3:VP0_CLK_CTRL reads back without the garbage dclk_out divider, the sync polarities seen by the HDMI controller (VIDEO_INTERFACE_STATUS0) match the mode flags for +/+ (1080p, 2160p) and -/- (720x480, 640x480) modes, and the picture is correct over TMDS and FRL modes from 27 to 1188 MHz. Patch 4: RGB565 is offered on the Cluster windows only without YTR, and those planes scan out correctly on three Cluster windows. Patches 7 to 9 were found while driving Esmart3 and partial AFBC overlays: an AFBC overlay placed at x=1001 shows correctly. v1 of patches 5 and 6: 3840x2160@120 with a full screen overlay (previously ~120000 POST_BUF_EMPTY per second and a scrambled picture) and a dual-display session (HDMI 4K@60 plus DP 4K@30, two video players, ten minutes) ran with zero underflows.
v2 of patches 1, 5 and 6 on the same board: an NV12 overlay with luma and chroma in two GEM objects shows correctly; at 3840x2160@120 the overlay is assigned the port the primary plane is not on, also when another overlay is switched off in the same commit, with zero POST_BUF_EMPTY; a window started on the DisplayPort video port avoids the port of a window with the same read IDs that is switched off on HDMI in the same commit; after a forced underflow and an HDMI off/on cycle the video port raises no frame start interrupts while vblank reporting is off.
The DRM KUnit tests pass (they don't cover this driver), and every patch builds with W=1 on arm64.
This series was developed with Claude (Anthropic) as a coding assistant:
it wrote the code and the commit messages, and I reviewed and tested every change as described above.
---
Changes in v2:
- New patch 1: take the UV plane address from fb->obj[1] (pre-existing bug reported by the Sashiko review of v1 patch 4).
- Patch 5 (AXI ports), after the Sashiko review:
- The ports are assigned in the CRTC atomic check from the whole new state and kept in a private object; the plane update only programs them. v1 chose the port in the plane update, in plane order, so a window saw the stale state of windows switched off later in the
same commit (Sashiko: commit order skews vop2_win_get_axi_bus()).
- The load counts all planes of the framebuffer, e.g. 12 bpp for NV12 instead of 8 (Sashiko: UV plane AXI load omitted).
- A switched off window keeps its read IDs in use until the frame start of its own video port, or until the commit that switched it off is done, instead of releasing them in atomic_disable (Sashiko:
premature AXI bus release).
- The windows that start fetching are assigned busiest first.
- The plane update takes the port from the plane state (new struct vop2_plane_state), not from the private state: commits on
different video ports aren't ordered against each other, so a
later one may have freed the private state by then.
- Patch 6 (POST_BUF_EMPTY), after the v1 reviews:
- Clear the stale FS status before enabling FS while vblank reporting is off, so it doesn't fire mid-frame (Sashiko).
- Disable POST_BUF_EMPTY and a pending FS re-arm when the CRTC is switched off and on the atomic_enable error path (Sashiko).
- enable_vblank() doesn't clear a pending FS while POST_BUF_EMPTY waits to be re-armed (Sashiko).
- Fixes: tag added (Sashiko).
- The comment above the FS enable says why it is there: masking POST_BUF_EMPTY does not touch FS, since VP_INT_EN is
write-masked, but POST_BUF_EMPTY is unmasked again from the FS interrupt at the next frame start, so FS has to be on. It is
only enabled here when vblank reporting has it off; v1 wrote it unconditionally and its comment hid the reason (Chaoyi Chen).
- Patches 7 and 8: Fixes: tags added (Sashiko).
- Patch 7: ROCKCHIP_VOP2_MAX_LAYER_ID added after the last window id and used as the bound of the search instead of ROCKCHIP_VOP2_ESMART3 + 1 (Chaoyi Chen).
- Patch 8: Reviewed-by added (Chaoyi Chen).
- Cover letter: says what ACLK_VOP was during the measurements and that raising it doesn't help (Chaoyi Chen asked; the details are in the commit message of patch 5).
- Patch 9: the x offset in the superblock is taken modulo the
superblock width, 32 with AFBC_FORMAT_MOD_BLOCK_SIZE_32x8 (Sashiko), and a Fixes: tag added (Sashiko).
- Cc Piotr Zalewski (author of the commit patch 8 fixes).
- Link to v1: https://patch.msgid.link/[email protected]
---
Arun Iyengar (9):
drm/rockchip: vop2: Take the UV plane address from the second GEM object drm/rockchip: vop2: Don't use uninitialised dividers on RK3588 drm/rockchip: vop2: Fix the HDMI sync polarity on RK3588 drm/rockchip: vop2: Don't accept AFBC YTR for RGB565 on RK3588 drm/rockchip: vop2: Balance window fetches across both AXI ports on RK3588 drm/rockchip: vop2: Report POST_BUF_EMPTY at most once per frame drm/rockchip: vop2: Find the first mixer of a video port with Esmart3 too drm/rockchip: vop2: Keep the other LUT_PORT_SEL fields on gamma LUT updates drm/rockchip: vop2: Fix the AFBC offsets of a source that starts inside a superblock
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 453 ++++++++++++++++++++++++++- drivers/gpu/drm/rockchip/rockchip_drm_vop2.h | 53 ++++ drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 27 +- 3 files changed, 512 insertions(+), 21 deletions(-)
---
base-commit: 8deaade4a5a4ff635df91e246e42139ab2b33f6d
change-id: 20261110-vop2-fixes-fa45142799c1
Best regards,
Signature · 1 line
Arun Iyengar <[email protected]>
PATCH v2 1/9 drm/rockchip: vop2: Take the UV plane address from the second GEM object
vop2_plane_atomic_update() computes the address of the chroma plane of a multi-planar YUV framebuffer from fb->obj[0], the object of the luma plane, plus the offset of the chroma plane. A framebuffer may have its planes in different GEM objects though (DRM_IOCTL_MODE_ADDFB2 with two handles, as with an NV12M buffer from a V4L2 decoder imported as two DMA-BUFs). The window then fetches the chroma plane from the luma buffer, at an offset meant for another buffer, which shows a wrong picture or reads past the end of the luma buffer.
Use fb->obj[1] for the chroma plane. Single plane YUV formats like DRM_FORMAT_YUV420_8BIT have no second object and keep using fb->obj[0]. This is also what the vendor kernel does.
--- drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +3 -1
@@ -1369,7 +1369,9 @@ static void vop2_plane_atomic_update(struct drm_plane *plane,if ((pstate->rotation &DRM_MODE_REFLECT_Y ) && !afbc_en) offset += fb->pitches[1 ] * ((pstate->src_h >>16 ) -2 ) / vsub; - rk_obj =to_rockchip_obj (fb->obj[0 ]); +/* Single plane formats like YUV420_8BIT have no second object */ +if (fb->format->num_planes >1 ) + rk_obj =to_rockchip_obj (fb->obj[1 ]); uv_mst = rk_obj->dma_addr + offset + fb->offsets[1 ]; }
Signature · 1 line
2.55.0
Re: [PATCH v2 1/9] drm/rockchip: vop2: Take the UV plane address from the second GEM object
Hi Arun,
Quoted 29 lines · On 11/12/2026 4:33 PM, Arun Iyengar via B4 Relay wrote:
From: Arun Iyengar <[email protected]>
vop2_plane_atomic_update()computes the address of the chroma plane of a multi-planar YUV framebuffer from fb->obj[0], the object of the luma plane, plus the offset of the chroma plane. A framebuffer may have its planes in different GEM objects though (DRM_IOCTL_MODE_ADDFB2with two handles, as with an NV12M buffer from a V4L2 decoder imported as two DMA-BUFs). The window then fetches the chroma plane from the luma buffer, at an offset meant for another buffer, which shows a wrong picture or reads past the end of the luma buffer.Use fb->obj[1] for the chroma plane. Single plane YUV formats like
DRM_FORMAT_YUV420_8BIThave no second object and keep using fb->obj[0]. This is also what the vendor kernel does.Fixes 604be85547ce ("drm/rockchip: Add VOP2 driver")Reported-by Sashiko <[email protected]>Signed-off-by Arun Iyengar <[email protected]>--- drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +0
-0
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c static void vop2_plane_atomic_update(struct drm_plane *plane, · line 1372
Quoted 5 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +1
-1@@ -1369,7 +1369,9 @@ static void vop2_plane_atomic_update(struct drm_plane *plane,if ((pstate->rotation &DRM_MODE_REFLECT_Y ) && !afbc_en) offset += fb->pitches[1 ] * ((pstate->src_h >>16 ) -2 ) / vsub; - rk_obj =to_rockchip_obj (fb->obj[0 ]); +/* Single plane formats like YUV420_8BIT have no second object */
Drop this comment.
Quoted 6 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +2
-0+if (fb->format->num_planes >1 ) + rk_obj =to_rockchip_obj (fb->obj[1 ]); uv_mst = rk_obj->dma_addr + offset + fb->offsets[1 ]; }
Signature · 2 lines
Best, Chaoyi
PATCH v2 2/9 drm/rockchip: vop2: Don't use uninitialised dividers on RK3588
In reply to Arun Iyengarrk3588_calc_cru_cfg() converts all four dividers to their register encoding with ilog2(), but only sets the ones the interface uses:dclk_out_div is left uninitialised for HDMI, eDP and DPI, and if_pixclk_div/if_dclk_div for DP and DPI. The garbage is then written to RK3588_VP_CLK_CTRL; on an Orange Pi 5 the dclk_out divider of the HDMI video port reads back as 3 (/8) in every mode.
Start all dividers at 1. dclk_out only feeds DP and MIPI (and HDMI with DSC, which is not supported), so for the other interfaces keep it at the dclk_core rate, as the vendor kernel does for HDMI with DSC, instead of letting it run at the full DCLK rate.
--- drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +12 -0
@@ -1579,6 +1579,15 @@ static unsigned long rk3588_calc_cru_cfg(struct vop2_video_port *vp, int id,unsigned long if_pixclk_rate;int K =1 ; +/* +* Not every interface uses every divider: dclk_out only feeds DP and +* MIPI, the interface dividers are unused for DP. Start from 1 so that +* no divider is left uninitialised when its value is converted below. +*/ + *dclk_out_div =1 ; + *if_pixclk_div =1 ; + *if_dclk_div =1 ; +if (vop2_output_if_is_hdmi (id)) {/* * K = 2: dclk_core = if_pixclk_rate > if_dclk_rate
@@ -1648,6 +1657,9 @@ static unsigned long rk3588_calc_cru_cfg(struct vop2_video_port *vp, int id, } *dclk_core_div = dclk_rate / dclk_core_rate; +/* An unused dclk_out must not run faster than dclk_core */ +if (!vop2_output_if_is_dp (id) && !vop2_output_if_is_mipi (id)) + *dclk_out_div = *dclk_core_div; *if_pixclk_div =ilog2 (*if_pixclk_div); *if_dclk_div =ilog2 (*if_dclk_div); *dclk_core_div =ilog2 (*dclk_core_div);
Signature · 1 line
2.55.0
Re: [PATCH v2 2/9] drm/rockchip: vop2: Don't use uninitialised dividers on RK3588
Hi Arun,
Quoted 9 lines · On 11/12/2026 4:33 PM, Arun Iyengar via B4 Relay wrote:
From: Arun Iyengar <[email protected]>
rk3588_calc_cru_cfg()converts all four dividers to their register encoding withilog2(), but only sets the ones the interface uses:dclk_out_divis left uninitialised for HDMI, eDP and DPI, and if_pixclk_div/if_dclk_div for DP and DPI. The garbage is then written toRK3588_VP_CLK_CTRL; on an Orange Pi 5 thedclk_outdivider of the HDMI video port reads back as 3 (/8) in every mode.
The comments are not entirely accurate. The divider relationship is:
dclk_out_div: HDMI(dsc mode), DP and MIPIif_pixclk_div: All interfacesif_dclk_div: HDMI and eDP
Quoted 33 lines
Start all dividers at 1.
dclk_outonly feeds DP and MIPI (and HDMI with DSC, which is not supported), so for the other interfaces keep it at thedclk_corerate, as the vendor kernel does for HDMI with DSC, instead of letting it run at the full DCLK rate.Fixes 5a028e8f062f ("drm/rockchip: vop2: Add support for rk3588")Signed-off-by Arun Iyengar <[email protected]>--- drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +9
-0@@ -1579,6 +1579,15 @@ static unsigned long rk3588_calc_cru_cfg(struct vop2_video_port *vp, int id,unsigned long if_pixclk_rate;int K =1 ; +/* +* Not every interface uses every divider: dclk_out only feeds DP and +* MIPI, the interface dividers are unused for DP. Start from 1 so that +* no divider is left uninitialised when its value is converted below. +*/ + *dclk_out_div =1 ; + *if_pixclk_div =1 ; + *if_dclk_div =1 ; +if (vop2_output_if_is_hdmi (id)) {/* * K = 2: dclk_core = if_pixclk_rate > if_dclk_rate
drivers/gpu/drm/rockchip/rockchip_vop2_reg.c static unsigned long rk3588_calc_cru_cfg(struct vop2_video_port *vp, int id, · line 1665
Quoted 9 lines
drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +3
-0@@ -1648,6 +1657,9 @@ static unsigned long rk3588_calc_cru_cfg(struct vop2_video_port *vp, int id, } *dclk_core_div = dclk_rate / dclk_core_rate; +/* An unused dclk_out must not run faster than dclk_core */ +if (!vop2_output_if_is_dp (id) && !vop2_output_if_is_mipi (id)) + *dclk_out_div = *dclk_core_div; *if_pixclk_div =ilog2 (*if_pixclk_div); *if_dclk_div =ilog2 (*if_dclk_div); *dclk_core_div =ilog2 (*dclk_core_div);
I think we can drop the previous divider initialization, and configure the correct dividers for specific interfaces.
- dclk_core_div and if_pixclk_div just remain unchanged.
- if_dclk_div is set for HDMI and eDP interfaces; all others are set to 0.
- dclk_out_div is set for DP and MIPI interfaces; the rest are set to 0.
Best regards,
Damon
Re: [PATCH v2 2/9] drm/rockchip: vop2: Don't use uninitialised dividers on RK3588
Hi Damon,
Quoted 2 lines
I think we can drop the previous divider initialization, and configure the correct dividers for specific interfaces.
Thanks, v3 does it this way. One difference: if_pixclk_div isn't set for DP and DPI today, so v3 sets it to 1 there as well; nothing is written for it in those cases. HDMI with DSC isn't supported by the driver, so dclk_out_div is 1 for HDMI.
v3 2/8: https://lore.kernel.org/r/[email protected]
Best regards,
Arun
PATCH v2 3/9 drm/rockchip: vop2: Fix the HDMI sync polarity on RK3588
In reply to Arun Iyengarrk3588_set_intf_mux() passes the POLFLAG bits of the mode to rk3588_get_hdmi_pol(), which decodes them as DRM mode flags: the VSYNC_POSITIVE bit is taken for DRM_MODE_FLAG_NHSYNC and POLFLAG_DCLK_INV for DRM_MODE_FLAG_NVSYNC. As a result GRF_VO1_CON0 marks the HSYNC of every +HSync/+VSync mode (e.g. all 1080p, 2160p CTA modes) as negative and both syncs of -HSync/-VSync modes (e.g. 720x480, 640x480) as positive.
The bits in GRF_VO1_CON0 are set for a negative sync; that is how the vendor kernel programs them (vop2_get_hdmi_pol(), called with the mode flags, sets them for DRM_MODE_FLAG_NHSYNC/NVSYNC on RK3588). Decode the POLFLAG bits accordingly.
--- drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +7 -3
@@ -1687,12 +1687,16 @@ static u32 rk3588_get_mipi_port_mux(int vp_id)return 0 ; } -static u32 rk3588_get_hdmi_pol (u32 flags) +/* +* The HDMI sync polarity bits in GRF_VO1_CON0 are set for an active low +* (negative) sync. +*/ +static u32 rk3588_get_hdmi_pol (u32 polflags) {u32 val; - val = (flags &DRM_MODE_FLAG_NHSYNC ) ?BIT (HSYNC_POSITIVE ) :0 ; - val |= (flags &DRM_MODE_FLAG_NVSYNC ) ?BIT (VSYNC_POSITIVE ) :0 ; + val = (polflags &BIT (HSYNC_POSITIVE )) ?0 :BIT (HSYNC_POSITIVE ); + val |= (polflags &BIT (VSYNC_POSITIVE )) ?0 :BIT (VSYNC_POSITIVE );return val; }
Signature · 1 line
2.55.0
Re: [PATCH v2 3/9] drm/rockchip: vop2: Fix the HDMI sync polarity on RK3588
Oh wow, nobody even noticed this.
Quoted 10 lines · On 11/12/2026 4:33 PM, Arun Iyengar via B4 Relay wrote:
From: Arun Iyengar <[email protected]>
rk3588_set_intf_mux()passes the POLFLAG bits of the mode tork3588_get_hdmi_pol(), which decodes them as DRM mode flags: theVSYNC_POSITIVEbit is taken forDRM_MODE_FLAG_NHSYNCandPOLFLAG_DCLK_INVforDRM_MODE_FLAG_NVSYNC. As a resultGRF_VO1_CON0marks the HSYNC of every +HSync/+VSync mode (e.g. all 1080p, 2160p CTA modes) as negative and both syncs of -HSync/-VSync modes (e.g. 720x480, 640x480) as positive.
Quoted 7 lines
The bits in
GRF_VO1_CON0are set for a negative sync; that is how the vendor kernel programs them (vop2_get_hdmi_pol(), called with the mode flags, sets them for DRM_MODE_FLAG_NHSYNC/NVSYNC on RK3588). Decode the POLFLAG bits accordingly.Fixes 5a028e8f062f ("drm/rockchip: vop2: Add support for rk3588")Signed-off-by Arun Iyengar <[email protected]>
Quoted 29 lines
--- drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +7
-3@@ -1687,12 +1687,16 @@ static u32 rk3588_get_mipi_port_mux(int vp_id)return 0 ; } -static u32 rk3588_get_hdmi_pol (u32 flags) +/* +* The HDMI sync polarity bits in GRF_VO1_CON0 are set for an active low +* (negative) sync. +*/ +static u32 rk3588_get_hdmi_pol (u32 polflags) {u32 val; - val = (flags &DRM_MODE_FLAG_NHSYNC ) ?BIT (HSYNC_POSITIVE ) :0 ; - val |= (flags &DRM_MODE_FLAG_NVSYNC ) ?BIT (VSYNC_POSITIVE ) :0 ; + val = (polflags &BIT (HSYNC_POSITIVE )) ?0 :BIT (HSYNC_POSITIVE ); + val |= (polflags &BIT (VSYNC_POSITIVE )) ?0 :BIT (VSYNC_POSITIVE );return val; }
Signature · 2 lines
Best, Chaoyi
Re: [PATCH v2 3/9] drm/rockchip: vop2: Fix the HDMI sync polarity on RK3588
In reply to Arun IyengarHi Arun,
Quoted 9 lines · On 11/12/2026 4:33 PM, Arun Iyengar via B4 Relay wrote:
From: Arun Iyengar <[email protected]>
rk3588_set_intf_mux()passes the POLFLAG bits of the mode tork3588_get_hdmi_pol(), which decodes them as DRM mode flags: theVSYNC_POSITIVEbit is taken forDRM_MODE_FLAG_NHSYNCandPOLFLAG_DCLK_INVforDRM_MODE_FLAG_NVSYNC. As a resultGRF_VO1_CON0marks the HSYNC of every +HSync/+VSync mode (e.g. all 1080p, 2160p CTA modes) as negative and both syncs of -HSync/-VSync modes (e.g. 720x480, 640x480) as positive.
The commit msg confuses me. POLFLAG_DCLK_INV has no relation to DRM_MODE_FLAG_NVSYNC.
For the RK3588, the polarity relationship is:
DRM_MODE_FLAG_NHSYNC -> Set HDMI hsync polarity bit DRM_MODE_FLAG_NVSYNC -> Set HDMI vsync polarity bit DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE -> No valid HDMI dclk polarity bit
Quoted 27 lines
The bits in
GRF_VO1_CON0are set for a negative sync; that is how the vendor kernel programs them (vop2_get_hdmi_pol(), called with the mode flags, sets them for DRM_MODE_FLAG_NHSYNC/NVSYNC on RK3588). Decode the POLFLAG bits accordingly.Fixes 5a028e8f062f ("drm/rockchip: vop2: Add support for rk3588")Signed-off-by Arun Iyengar <[email protected]>--- drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +5
-1@@ -1687,12 +1687,16 @@ static u32 rk3588_get_mipi_port_mux(int vp_id)return 0 ; } -static u32 rk3588_get_hdmi_pol (u32 flags) +/* +* The HDMI sync polarity bits in GRF_VO1_CON0 are set for an active low +* (negative) sync. +*/ +static u32 rk3588_get_hdmi_pol (u32 polflags)
drivers/gpu/drm/rockchip/rockchip_vop2_reg.c static u32 rk3588_get_mipi_port_mux(int vp_id) · line 1702
Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +2
-2{u32 val; - val = (flags &DRM_MODE_FLAG_NHSYNC ) ?BIT (HSYNC_POSITIVE ) :0 ; - val |= (flags &DRM_MODE_FLAG_NVSYNC ) ?BIT (VSYNC_POSITIVE ) :0 ; + val = (polflags &BIT (HSYNC_POSITIVE )) ?0 :BIT (HSYNC_POSITIVE ); + val |= (polflags &BIT (VSYNC_POSITIVE )) ?0 :BIT (VSYNC_POSITIVE );return val; }
With the commit msg modification:
Best regards,
Damon
Re: [PATCH v2 3/9] drm/rockchip: vop2: Fix the HDMI sync polarity on RK3588
Hi Damon, Chaoyi,
The TRM names GRF_VO1_CON0 bit 5 the HDMI0 vsync polarity and bit 6 hsync (7 and 8 for HDMI1); the driver, like the vendor kernel, uses them the other way round.
The HDMI controller agrees with the TRM. With patch 3 and 1920x1080@144 +HSync -VSync the driver sets bit 6, and VIDEO_INTERFACE_STATUS0 reports -HSync +VSync; with 1600x1280@60 -HSync +VSync it sets bit 5 and the controller sees +HSync -VSync.
v3 keeps patch 3 as you reviewed it and adds patch 4, which swaps the two bits; with it the controller reports both modes as set. Please shout if the TRM is wrong here.
v3 4/8: https://lore.kernel.org/r/[email protected]
Best regards,
Arun
PATCH v2 4/9 drm/rockchip: vop2: Don't accept AFBC YTR for RGB565 on RK3588
In reply to Arun IyengarThe Cluster windows of the RK3588 VOP2 advertise every AFBC modifier of format_modifiers_afbc for RGB565 and BGR565, including the ones with the lossless colour transform (YTR). Scanning out an RGB565 buffer rendered by the Mali-G610 (panfrost) with AFBC(16x16 | SPARSE | YTR) gives a black picture and POST_BUF_EMPTY on the video port, on every Cluster window, while the same buffer rendered with AFBC(16x16 | SPARSE) displays correctly, as do 32 bpp formats with YTR.
YTR on RGB565 is also a questionable pairing to start with:Documentation/gpu/afbc.rst requires the R, G, B component order when YTR is used, with component 0 in the least significant bits, which DRM_FORMAT_RGB565 (B in the low bits) doesn't have, and the Arm Mali-D71 (komeda) only accepts AFBC for BGR565.
Stop advertising and accepting YTR for the two 16 bpp RGB formats on RK3588, so that userspace picks a modifier the decoder handles. The BGR565 case could not be tested (Mesa can't import BGR565 dma-bufs), it's rejected as well because the decoder is configured identically for both formats, apart from the R/B swap after decoding.
--- drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +12 -0
@@ -404,6 +404,18 @@ static bool rockchip_vop2_mod_supported(struct drm_plane *plane, u32 format,if (vop2_convert_afbc_format (format) ==VOP2_AFBC_FMT_INVALID )return false; +/* +* The AFBC decoder of the RK3588 Cluster windows can't decode 16 bpp +* RGB that uses the lossless colour transform: the picture stays +* black and the video port reports POST_BUF_EMPTY, while the same +* buffers without YTR display fine. +*/ +if (vop2->version ==VOP_VERSION_RK3588 && (modifier &AFBC_FORMAT_MOD_YTR ) && + (format ==DRM_FORMAT_RGB565 || format ==DRM_FORMAT_BGR565 )) { +drm_dbg_kms (vop2->drm,"No AFBC YTR support for 16 bpp RGB\n" ); +return false; + } +/* Different windows have different format/modifier support */ for (i =0 ; i < plane->modifier_count; i++) {if (plane->modifiers[i] == modifier)
Signature · 1 line
2.55.0
Re: [PATCH v2 4/9] drm/rockchip: vop2: Don't accept AFBC YTR for RGB565 on RK3588
Hi Arun,
Quoted 10 lines · On 11/12/2026 4:33 PM, Arun Iyengar via B4 Relay wrote:
From: Arun Iyengar <[email protected]>
The Cluster windows of the RK3588 VOP2 advertise every AFBC modifier of
format_modifiers_afbcfor RGB565 and BGR565, including the ones with the lossless colour transform (YTR). Scanning out an RGB565 buffer rendered by the Mali-G610 (panfrost) with AFBC(16x16 | SPARSE | YTR) gives a black picture andPOST_BUF_EMPTYon the video port, on every Cluster window, while the same buffer rendered with AFBC(16x16 | SPARSE) displays correctly, as do 32 bpp formats with YTR.
That' true. The TRM says RK3588 only support XRGB888/RGB888 AFBC YTR format.
Quoted 24 lines
YTR on RGB565 is also a questionable pairing to start with:
Documentation/gpu/afbc.rstrequires the R, G, B component order when YTR is used, with component 0 in the least significant bits, whichDRM_FORMAT_RGB565(B in the low bits) doesn't have, and the Arm Mali-D71 (komeda) only accepts AFBC for BGR565.Stop advertising and accepting YTR for the two 16 bpp RGB formats on RK3588, so that userspace picks a modifier the decoder handles. The BGR565 case could not be tested (Mesa can't import BGR565 dma-bufs), it's rejected as well because the decoder is configured identically for both formats, apart from the R/B swap after decoding.
Fixes 5a028e8f062f ("drm/rockchip: vop2: Add support for rk3588")Signed-off-by Arun Iyengar <[email protected]>--- drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 12 ++++++++++++ 1 file changed, 12 insertions(+)drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +0
-0
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c static bool rockchip_vop2_mod_supported(struct drm_plane *plane, u32 format, · line 412
Quoted 9 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +6
-0@@ -404,6 +404,18 @@ static bool rockchip_vop2_mod_supported(struct drm_plane *plane, u32 format,if (vop2_convert_afbc_format (format) ==VOP2_AFBC_FMT_INVALID )return false; +/* +* The AFBC decoder of the RK3588 Cluster windows can't decode 16 bpp +* RGB that uses the lossless colour transform: the picture stays +* black and the video port reports POST_BUF_EMPTY, while the same +* buffers without YTR display fine. +*/
Drop this comment.
Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +6
-0+if (vop2->version ==VOP_VERSION_RK3588 && (modifier &AFBC_FORMAT_MOD_YTR ) && + (format ==DRM_FORMAT_RGB565 || format ==DRM_FORMAT_BGR565 )) { +drm_dbg_kms (vop2->drm,"No AFBC YTR support for 16 bpp RGB\n" ); +return false; + } +/* Different windows have different format/modifier support */ for (i =0 ; i < plane->modifier_count; i++) {if (plane->modifiers[i] == modifier)
Signature · 2 lines
Best, Chaoyi
Re: [PATCH v2 4/9] drm/rockchip: vop2: Don't accept AFBC YTR for RGB565 on RK3588
Hi Chaoyi,
Quoted 1 line
That' true. The TRM says RK3588 only support XRGB888/RGB888 AFBC YTR format.
v3 follows the TRM: YTR is only accepted for the 8 bit RGB formats, and the comment is gone.
That also refuses XRGB2101010 with YTR, which displays correctly on my board (AFBC 16x16 | SPARSE | YTR from the Mali-G610, HDMI and DP). May the 10 bit formats keep YTR?
v3 5/8: https://lore.kernel.org/r/[email protected]
Best regards,
Arun
PATCH v2 5/9 drm/rockchip: vop2: Balance window fetches across both AXI ports on RK3588
In reply to Arun IyengarThe RK3588 VOP2 fetches through two AXI read ports. Every window has a fixed default port in rk3588_vop_win_data: Cluster0/1 and Esmart0/1 use AXI0, Cluster2/3 and Esmart2/3 use AXI1. The port is chosen by a per window register (CLUSTER_CTRL[13] / ESMART_AXI_CTRL[1]), though, and it is programmed on every plane update.
One port can't sustain two full screen 4K@120Hz layers. With the console on Cluster0 (the primary plane of video port 0) and a video on Esmart0 (its overlay plane), both on AXI0, HDMI 3840x2160@120 reports POST_BUF_EMPTY on about half of all lines (~120000 per second) and the picture is scrambled. The VOP read rate measured with the DDR PMU drops from the expected 6.3 GB/s to 3.2 GB/s: the fetch collapses instead of merely saturating. Measured at 4K@120Hz, XR24 primary plane:
Cluster0 + Esmart0 (AXI0 + AXI0) ~120k POST_BUF_EMPTY/s
Cluster2 + Esmart2 (AXI1 + AXI1) ~100k/s
Esmart0 + Esmart1 (AXI0 + AXI0) ~90k/s (XR24 both)
Cluster0 + Esmart2 (AXI0 + AXI1) 0, 9.2 GB/s read
Cluster0 + Cluster2 (AXI0 + AXI1) 0, 8.6 GB/s read
Moving Esmart0 to AXI1 at runtime (with no other change) makes the first case clean. Raising ACLK_VOP from 750 to 850 MHz, or changing the NoC QoS priority or mode of the VOP ports, makes no difference, and neither does the buffer placement (both planes scanning out the same buffer fail the same way). So the limit is per port, and the fixed assignment puts both layers of the most common configuration on the same port while the other one sits idle. Lower modes are affected
too: the same port also carries Cluster1 for a second display, and under DDR contention from other masters a 4K@60Hz port with the console, an overlay and a second display underflows for short bursts.
Choose the port of a window when it starts fetching instead. The atomic check assigns the ports from the whole new state and keeps the assignment in a private object for the next check. The port of a window is also stored in its plane state, and that is what the plane update
programs: commits on different video ports aren't ordered against each other, so the private state of a commit may already be replaced and freed when its planes are updated. A window that keeps fetching keeps its port, so an active layer is never moved. The windows that start fetching, the busiest first, each get the port that leaves the busier port least loaded, preferring the default one on a tie. The load of a window is its estimated fetch rate: source size x bits per pixel of all its planes x refresh rate.
A window must not share an AXI read ID with another window on the same port. The IDs in the table are unique per default port, and mirrored between the two ports (Cluster0/Cluster2, Esmart0/Esmart2, ...), so a window can always use the port its mirror isn't on. A window that is switched off keeps fetching until the next frame start of its video port, so its read IDs stay in use for a window that starts on another video port in the same commit, and until the commit that switched it off is done.
This is only enabled for RK3588, where it was measured.
--- drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 330 ++++++++++++++++++++++++++- drivers/gpu/drm/rockchip/rockchip_drm_vop2.h | 42 ++++ drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 3 +- 3 files changed, 370 insertions(+), 5 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +326 -4
@@ -23,6 +23,7 @@#include <drm/drm.h> #include <drm/drm_atomic.h> +#include <drm/drm_atomic_state_helper.h> #include <drm/drm_atomic_uapi.h> #include <drm/drm_blend.h> #include <drm/drm_crtc.h>
@@ -1231,6 +1232,314 @@ static int vop2_plane_atomic_check(struct drm_plane *plane,return 0 ; } +static bool vop2_win_axi_ids_clash (const struct vop2_win *a,const struct vop2_win *b) +{ +u8 ida[] = { a->data->axi_yrgb_r_id, a->data->axi_uv_r_id }; +u8 idb[] = { b->data->axi_yrgb_r_id, b->data->axi_uv_r_id }; +int i, j; + +for (i =0 ; i <ARRAY_SIZE (ida); i++) +for (j =0 ; j <ARRAY_SIZE (idb); j++) +if (ida[i] == idb[j]) +return true; + +return false; +} + +/* +* The VOP2 on RK3588 has two AXI read ports. Each window has a default port +* (&vop2_win_data.axi_bus_id), but the port is selected by a per window +* register, so any window can fetch through either one as long as its read +* IDs are unique on that port. +* +* A single port can't sustain much more than one full screen 4K@120Hz +* layer: two such layers on the same port (e.g. Cluster0 and Esmart0, the +* default primary and overlay planes of video port 0) make the window +* line buffers run dry, the fetch rate collapses and the video port +* reports POST_BUF_EMPTY on most lines, which scrambles the picture. The +* same layers fetched through different ports are fine. Raising ACLK or +* the NoC priority of the VOP doesn't help, the limit is per port. +* +* So the atomic check assigns a port to every window that starts fetching, +* from the whole new state: a window that keeps fetching keeps its port, +* and the new ones, the busiest first, get the port that leaves the busier +* of the two ports least loaded, preferring the default one. A window +* never gets a port on which another window may still fetch with one of +* its read IDs. +* +* The assignment of all windows is kept in a private object for the next +* atomic check. The plane update takes the port of its window from the +* plane state instead: commits on different video ports aren't ordered +* against each other, so a later one may have replaced and freed the +* private state by the time the planes of this one are updated. +*/ +#define to_vop2_axi_state (s) container_of(s, struct vop2_axi_state, base) +#define to_vop2_plane_state (s) container_of(s, struct vop2_plane_state, base) + +static struct drm_private_state *vop2_axi_duplicate_state (struct drm_private_obj *obj) +{ + struct vop2 *vop2 = container_of(obj, struct vop2, axi_obj); +struct vop2_axi_state *state; + + state =kmemdup (to_vop2_axi_state (obj->state), +struct_size (state, win, vop2->registered_num_wins), +GFP_KERNEL ); +if (!state) +return NULL ; + +__drm_atomic_helper_private_obj_duplicate_state (obj, &state->base); + +return &state->base; +} + +static void vop2_axi_destroy_state (struct drm_private_obj *obj, +struct drm_private_state *state) +{ +kfree (to_vop2_axi_state (state)); +} + +static struct drm_private_state *vop2_axi_create_state (struct drm_private_obj *obj) +{ + struct vop2 *vop2 = container_of(obj, struct vop2, axi_obj); +struct vop2_axi_state *state; +int i; + + state =kzalloc (struct_size (state, win, vop2->registered_num_wins), +GFP_KERNEL ); +if (!state) +return ERR_PTR (-ENOMEM ); + +for (i =0 ; i < vop2->registered_num_wins; i++) + state->win[i].bus = vop2->win[i].data->axi_bus_id; + +__drm_atomic_helper_private_obj_create_state (obj, &state->base); + +return &state->base; +} + +static const struct drm_private_state_funcs vop2_axi_state_funcs = { + .atomic_create_state = vop2_axi_create_state, + .atomic_duplicate_state = vop2_axi_duplicate_state, + .atomic_destroy_state = vop2_axi_destroy_state, +}; + +/* Bytes per second the window fetches, from all planes of the framebuffer */ +static u64 vop2_plane_axi_load (const struct drm_plane_state *pstate, +const struct drm_display_mode *mode) +{ +const struct drm_format_info *info = pstate->fb->format; +u64 pixels = (u64)(drm_rect_width (&pstate->src) >>16 ) * + (drm_rect_height (&pstate->src) >>16 ) * +drm_mode_vrefresh (mode); +u32 bits =0 ; +int i; + +/* Single plane formats like YUV420_8BIT have no cpp */ +if (info->num_planes ==1 ) +return div_u64 (pixels *vop2_get_bpp (info),8 ); + +for (i =0 ; i < info->num_planes; i++) + bits +=drm_format_info_bpp (info, i) / + (i ? info->hsub * info->vsub :1 ); + +return div_u64 (pixels * bits,8 ); +} + +/* The CRTC state of the plane if its window fetches in the new state */ +static const struct drm_crtc_state * +vop2_plane_fetch_crtc_state (struct drm_atomic_commit *state, +const struct drm_plane_state *pstate) +{ +const struct drm_crtc_state *cstate; + +if (!pstate->crtc || !pstate->fb || !pstate->visible) +return NULL ; + + cstate =drm_atomic_get_new_crtc_state (state, pstate->crtc); + +return cstate && cstate->active ? cstate :NULL ; +} + +/* +* Whether a window that doesn't fetch in the new state may still fetch while +* a window starts on @crtc. The window registers are latched at the frame +* start of their video port: a window switched off in this commit stops +* together with the new one only on the same video port, and one switched +* off in an earlier commit once that commit is done. +*/ +static int vop2_win_may_fetch (struct drm_atomic_commit *state, +struct vop2_win *win,const struct drm_crtc *crtc, +bool *fetching) +{ +const struct drm_plane_state *old =drm_atomic_get_old_plane_state (state, &win->base); +struct drm_crtc_commit *commit; +int ret; + +if (old) { + *fetching = old->crtc && old->crtc != crtc; +return 0 ; + } + + ret =drm_modeset_lock (&win->base.mutex, state->acquire_ctx); +if (ret) +return ret; + + commit = win->base.state->commit; + *fetching = commit && !try_wait_for_completion (&commit->flip_done); + +return 0 ; +} + +static u8 vop2_axi_pick_bus (u8 def,const u64 *bus_load,const bool *clash,u64 load) +{ +if (!clash[def ^1 ] && + (clash[def] ||max (bus_load[def ^1 ] + load, bus_load[def]) < +max (bus_load[def] + load, bus_load[def ^1 ]))) +return def ^1 ; + +return def; +} + +static int vop2_axi_check (struct vop2 *vop2,struct drm_atomic_commit *state) +{ +unsigned int n = vop2->registered_num_wins; +const struct vop2_axi_state *old; +struct drm_private_state *priv; +struct vop2_axi_state *new; +unsigned long start =0 ; +bool changed = false; +unsigned int i, j; +int ret; + +if (!(vop2->data->feature &VOP2_FEATURE_AXI_BALANCE )) +return 0 ; + +for (i =0 ; i < n; i++) +if (drm_atomic_get_new_plane_state (state, &vop2->win[i].base)) + changed = true; + +if (!changed) +return 0 ; + + priv =drm_atomic_get_private_obj_state (state, &vop2->axi_obj); +if (IS_ERR (priv)) +return PTR_ERR (priv); + + new =to_vop2_axi_state (priv); + old =to_vop2_axi_state (drm_atomic_get_old_private_obj_state (state, + &vop2->axi_obj)); + +for (i =0 ; i < n; i++) { +const struct drm_plane_state *pstate; +const struct drm_crtc_state *cstate; + + new->win[i] = old->win[i]; + + pstate =drm_atomic_get_new_plane_state (state, &vop2->win[i].base); +if (!pstate) +continue ; + + cstate =vop2_plane_fetch_crtc_state (state, pstate); + new->win[i].load = cstate ?vop2_plane_axi_load (pstate, &cstate->adjusted_mode) :0 ; + new->win[i].active = cstate && old->win[i].active; +if (cstate && !old->win[i].active) + start |=BIT (i); + } + +while (start) { +u64 bus_load[VOP2_SYS_AXI_BUS_NUM ] = { }; +bool clash[VOP2_SYS_AXI_BUS_NUM ] = { }; +const struct drm_plane_state *pstate; +struct vop2_win *win; +unsigned int k = n; +u8 bus; + +for_each_set_bit (j, &start, n) +if (k == n || new->win[j].load > new->win[k].load) + k = j; + + win = &vop2->win[k]; + pstate =drm_atomic_get_new_plane_state (state, &win->base); + +for (j =0 ; j < n; j++) { +struct vop2_win *w = &vop2->win[j]; +bool fetching = new->win[j].active; + +if (j == k || (start &BIT (j))) +continue ; + +if (fetching) + bus_load[new->win[j].bus] += new->win[j].load; + +if (!vop2_win_axi_ids_clash (win, w)) +continue ; + +if (!fetching) { + ret =vop2_win_may_fetch (state, w, pstate->crtc, &fetching); +if (ret) +return ret; + } + +if (fetching) + clash[new->win[j].bus] = true; + } + + bus =vop2_axi_pick_bus (win->data->axi_bus_id, bus_load, clash, + new->win[k].load); +if (clash[bus]) { +drm_dbg_kms (vop2->drm,"%s: no AXI port with free read IDs\n" , + win->data->name); +return -EINVAL ; + } + + new->win[k].bus = bus; + new->win[k].active = true; + start &= ~BIT (k); + } + +/* The plane update programs the port from the plane state */ +for (i =0 ; i < n; i++) { +struct drm_plane_state *pstate; + + pstate =drm_atomic_get_new_plane_state (state, &vop2->win[i].base); +if (pstate) +to_vop2_plane_state (pstate)->axi_bus = new->win[i].bus; + } + +return 0 ; +} + +static struct drm_plane_state *vop2_plane_create_state (struct drm_plane *plane) +{ +struct vop2_plane_state *vpstate; + + vpstate =kzalloc_obj (*vpstate); +if (!vpstate) +return ERR_PTR (-ENOMEM ); + +__drm_atomic_helper_plane_state_init (&vpstate->base, plane); + vpstate->axi_bus =to_vop2_win (plane)->data->axi_bus_id; + +return &vpstate->base; +} + +static struct drm_plane_state *vop2_plane_duplicate_state (struct drm_plane *plane) +{ +struct vop2_plane_state *vpstate; + +if (WARN_ON (!plane->state)) +return NULL ; + + vpstate =kmemdup (to_vop2_plane_state (plane->state),sizeof (*vpstate), +GFP_KERNEL ); +if (!vpstate) +return NULL ; + +__drm_atomic_helper_plane_duplicate_state (plane, &vpstate->base); + +return &vpstate->base; +} +static void vop2_plane_atomic_disable (struct drm_plane *plane,struct drm_atomic_commit *state) {
@@ -1418,7 +1727,8 @@ static void vop2_plane_atomic_update(struct drm_plane *plane, afbc_en ? "AFBC" : "", &yrgb_mst);if (vop2->version >VOP_VERSION_RK3568 ) { -vop2_win_write (win,VOP2_WIN_AXI_BUS_ID , win->data->axi_bus_id); +vop2_win_write (win,VOP2_WIN_AXI_BUS_ID , +to_vop2_plane_state (pstate)->axi_bus);vop2_win_write (win,VOP2_WIN_AXI_YRGB_R_ID , win->data->axi_yrgb_r_id);vop2_win_write (win,VOP2_WIN_AXI_UV_R_ID , win->data->axi_uv_r_id); }
@@ -1565,8 +1875,8 @@ static const struct drm_plane_funcs vop2_plane_funcs = { .update_plane = drm_atomic_helper_update_plane, .disable_plane = drm_atomic_helper_disable_plane, .destroy = drm_plane_cleanup, - .atomic_create_state = drm_atomic_helper_plane_create_state, - .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, + .atomic_create_state = vop2_plane_create_state, + .atomic_duplicate_state = vop2_plane_duplicate_state, .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, .format_mod_supported = rockchip_vop2_mod_supported, };
@@ -2086,7 +2396,7 @@ static int vop2_crtc_atomic_check(struct drm_crtc *crtc,if (nplanes > vp->nlayers)return -EINVAL ; -return 0 ; +return vop2_axi_check (vp->vop2, state); } static void vop2_crtc_atomic_begin(struct drm_crtc *crtc,
@@ -3016,6 +3326,13 @@ static int vop2_bind(struct device *dev, struct device *master, void *data)if (ret)return ret; +if (vop2_data->feature &VOP2_FEATURE_AXI_BALANCE ) { + ret =drm_atomic_private_obj_init (drm, &vop2->axi_obj, + &vop2_axi_state_funcs); +if (ret) + goto err_crtcs; + } +if (vop2->version >=VOP_VERSION_RK3576 ) {struct drm_crtc *crtc;
@@ -3060,6 +3377,8 @@ static int vop2_bind(struct device *dev, struct device *master, void *data)return 0 ; err_crtcs: +if (vop2->axi_obj.state) +drm_atomic_private_obj_fini (&vop2->axi_obj);vop2_destroy_crtcs (vop2);return ret;
@@ -3074,6 +3393,9 @@ static void vop2_unbind(struct device *dev, struct device *master, void *data)if (vop2->rgb)rockchip_rgb_fini (vop2->rgb); +if (vop2->axi_obj.state) +drm_atomic_private_obj_fini (&vop2->axi_obj); +vop2_destroy_crtcs (vop2); }
drivers/gpu/drm/rockchip/rockchip_drm_vop2.h +42 -0
66 lines not on this page · raw message
drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +2 -1
@@ -2577,7 +2577,8 @@ static const struct vop2_data rk3576_vop = {static const struct vop2_data rk3588_vop = { .version =VOP_VERSION_RK3588 , .feature =VOP2_FEATURE_HAS_SYS_GRF |VOP2_FEATURE_HAS_VO1_GRF | -VOP2_FEATURE_HAS_VOP_GRF |VOP2_FEATURE_HAS_SYS_PMU , +VOP2_FEATURE_HAS_VOP_GRF |VOP2_FEATURE_HAS_SYS_PMU | +VOP2_FEATURE_AXI_BALANCE , .nr_vps =4 , .max_input = {4096 ,4320 }, .max_output = {4096 ,4320 },
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v2 5/9] drm/rockchip: vop2: Balance window fetches across both AXI ports on RK3588
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] drm/rockchip: vop2: wrong AXI clash checks in vop2_win_may_fetch() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] drm/rockchip: vop2: wrong AXI clash checks in vop2_win_may_fetch()
--
commit 73d9c526a345979a18aa8e0e398a482c59cd3a4f
Author: Arun Iyengar <[email protected]>
drm/rockchip: vop2: Balance window fetches across both AXI ports on RK3588
This commit dynamically assigns AXI read ports to VOP2 windows on RK3588 during atomic check to balance memory bandwidth across both ports while avoiding AXI read ID collisions.
Quoted 4 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +0
-0
[ ... ]
Quoted 29 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +29
-0+/* +* Whether a window that doesn't fetch in the new state may still fetch while +* a window starts on @crtc. The window registers are latched at the frame +* start of their video port: a window switched off in this commit stops +* together with the new one only on the same video port, and one switched +* off in an earlier commit once that commit is done. +*/ +static int vop2_win_may_fetch (struct drm_atomic_commit *state, +struct vop2_win *win,const struct drm_crtc *crtc, +bool *fetching) +{ +const struct drm_plane_state *old =drm_atomic_get_old_plane_state (state, &win->base); +struct drm_crtc_commit *commit; +int ret; + +if (old) { + *fetching = old->crtc && old->crtc != crtc; +return 0 ; + } + + ret =drm_modeset_lock (&win->base.mutex, state->acquire_ctx); +if (ret) +return ret; + + commit = win->base.state->commit; + *fetching = commit && !try_wait_for_completion (&commit->flip_done); + +return 0 ; +}
[ ... ]
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c static int vop2_plane_atomic_check(struct drm_plane *plane, · line 1484
Quoted 8 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +8
-0+if (!fetching) { + ret =vop2_win_may_fetch (state, w, pstate->crtc, &fetching); +if (ret) +return ret; + } + +if (fetching) + clash[new->win[j].bus] = true;
[Severity: Medium]
Does vop2_win_may_fetch() misidentify whether a clashing window w is still fetching by branching on whether w is in @state (old != NULL) instead of whether w was active in the old AXI state (old->win[j].active)?
When old != NULL, *fetching is set to old->crtc && old->crtc != crtc without checking old->win[j].active. If w is attached to another CRTC that is in DPMS off, or w is clipped off-screen (!old->visible), w is already disabled in hardware, yet pulling w into @state (for instance via drm_atomic_normalize_zpos()) marks its AXI port as clashing and forces the new window onto the other, potentially saturated port. Conversely, if w was disabled in an earlier non-blocking commit that has not completed flip_done and w is included in @state with old->crtc == NULL, the old != NULL branch returns *fetching = false without checking old->commit->flip_done.
When old == NULL, the fallback checks win->base.state->commit->flip_done without checking commit->crtc != crtc, so an earlier non-blocking disable on the same video port is treated as clashing even though its registers latch at the same frame start. In addition, drm_atomic_helper_setup_commit() sets plane_state->commit on every plane in a commit's state, so an in-flight commit on another CRTC that included an already-inactive plane w causes vop2_win_may_fetch() to report w as fetching.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
Re: [PATCH v2 5/9] drm/rockchip: vop2: Balance window fetches across both AXI ports on RK3588
In reply to Arun IyengarHi Arun,
Quoted 55 lines · On 11/12/2026 4:33 PM, Arun Iyengar via B4 Relay wrote:
From: Arun Iyengar <[email protected]>
The RK3588 VOP2 fetches through two AXI read ports. Every window has a fixed default port in
rk3588_vop_win_data: Cluster0/1 and Esmart0/1 use AXI0, Cluster2/3 and Esmart2/3 use AXI1. The port is chosen by a per window register (CLUSTER_CTRL[13] / ESMART_AXI_CTRL[1]), though, and it is programmed on every plane update.One port can't sustain two full screen 4K@120Hz layers. With the console on Cluster0 (the primary plane of video port 0) and a video on Esmart0 (its overlay plane), both on AXI0, HDMI 3840x2160@120 reports
POST_BUF_EMPTYon about half of all lines (~120000 per second) and the picture is scrambled. The VOP read rate measured with the DDR PMU drops from the expected 6.3 GB/s to 3.2 GB/s: the fetch collapses instead of merely saturating. Measured at 4K@120Hz, XR24 primary plane:Cluster0 + Esmart0 (AXI0 + AXI0) ~120k POST_BUF_EMPTY/s
Cluster2 + Esmart2 (AXI1 + AXI1) ~100k/s
Esmart0 + Esmart1 (AXI0 + AXI0) ~90k/s (XR24 both)
Cluster0 + Esmart2 (AXI0 + AXI1) 0, 9.2 GB/s read
Cluster0 + Cluster2 (AXI0 + AXI1) 0, 8.6 GB/s readMoving Esmart0 to AXI1 at runtime (with no other change) makes the first case clean. Raising
ACLK_VOPfrom 750 to 850 MHz, or changing the NoC QoS priority or mode of the VOP ports, makes no difference, and neither does the buffer placement (both planes scanning out the same buffer fail the same way). So the limit is per port, and the fixed assignment puts both layers of the most common configuration on the same port while the other one sits idle. Lower modes are affected
too: the same port also carries Cluster1 for a second display, and under DDR contention from other masters a 4K@60Hz port with the console, an overlay and a second display underflows for short bursts.Choose the port of a window when it starts fetching instead. The atomic check assigns the ports from the whole new state and keeps the assignment in a private object for the next check. The port of a window is also stored in its plane state, and that is what the plane update
programs: commits on different video ports aren't ordered against each other, so the private state of a commit may already be replaced and freed when its planes are updated. A window that keeps fetching keeps its port, so an active layer is never moved. The windows that start fetching, the busiest first, each get the port that leaves the busier port least loaded, preferring the default one on a tie. The load of a window is its estimated fetch rate: source size x bits per pixel of all its planes x refresh rate.A window must not share an AXI read ID with another window on the same port. The IDs in the table are unique per default port, and mirrored between the two ports (Cluster0/Cluster2, Esmart0/Esmart2, ...), so a window can always use the port its mirror isn't on. A window that is switched off keeps fetching until the next frame start of its video port, so its read IDs stay in use for a window that starts on another video port in the same commit, and until the commit that switched it off is done.
Quoted 1 line
This is only enabled for RK3588, where it was measured.
According to TRM, "In order to maintain synchronization between layers, allocationg the layers used by the one port on AXI0 and AXI buses respectively is not allowed."
Fortunately, we have another way to accomplish this: use the VP merge feature. Please refer to the patch below.
https://lore.kernel.org/all/[email protected]/
Signature · 2 lines
Best, Chaoyi
PATCH v2 6/9 drm/rockchip: vop2: Report POST_BUF_EMPTY at most once per frame
In reply to Arun IyengarPOST_BUF_EMPTY is raised for every line on which the post processing stage of a video port finds no data. The interrupt handler only rate-limits the error message and leaves the interrupt enabled, so an underflowing video port keeps the CPU in the interrupt handler 50000 to 300000 times per second, for as long as the configuration that causes the underflow stays in place (e.g. 120000 interrupts per second for 3840x2160@120 with two full screen layers on one AXI port).
Mask POST_BUF_EMPTY when it fires and unmask it at the next frame start. The frame start (FS) interrupt is enabled for that frame even when vblank reporting is off, and disabled again once POST_BUF_EMPTY is re-armed or the video port is switched off. VP_INT_EN is write-masked, so masking POST_BUF_EMPTY leaves FS alone; FS only needs enabling here while vblank reporting has it off. A new per video port lock serialises the interrupt enable bookkeeping between the interrupt handler and the vblank callbacks. The error is still reported, now at most once per frame and video port.
--- drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 91 ++++++++++++++++++++++++++-- drivers/gpu/drm/rockchip/rockchip_drm_vop2.h | 10 +++ 2 files changed, 97 insertions(+), 4 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +87 -4
@@ -842,6 +842,70 @@ static void vop2_crtc_disable_irq(struct vop2_video_port *vp, u32 irq)vop2_writel (vop2,RK3568_VP_INT_EN (vp->id), irq <<16 ); } +/* +* POST_BUF_EMPTY is raised for every line the post processing stage finds +* no data for, so an underflowing video port can raise it 100000 times per +* second. Report it at most once per frame: mask it when it fires and +* unmask it at the next frame start, using the FS interrupt even when +* vblank reporting is off. +*/ +/* Forget a pending re-arm, called with vp->irq_lock held */ +static void vop2_crtc_unmask_post_buf_empty (struct vop2_video_port *vp) +{ +if (vp->post_buf_empty_masked && !vp->vblank_enabled) +vop2_crtc_disable_irq (vp,VP_INT_FS_FIELD ); + vp->post_buf_empty_masked = false; +} + +static void vop2_crtc_enable_post_buf_empty_irq (struct vop2_video_port *vp) +{ +unsigned long flags; + +spin_lock_irqsave (&vp->irq_lock, flags); +vop2_crtc_unmask_post_buf_empty (vp); +vop2_crtc_enable_irq (vp,VP_INT_POST_BUF_EMPTY ); +spin_unlock_irqrestore (&vp->irq_lock, flags); +} + +static void vop2_crtc_disable_post_buf_empty_irq (struct vop2_video_port *vp) +{ +unsigned long flags; + +spin_lock_irqsave (&vp->irq_lock, flags); +vop2_crtc_disable_irq (vp,VP_INT_POST_BUF_EMPTY ); +vop2_crtc_unmask_post_buf_empty (vp); +spin_unlock_irqrestore (&vp->irq_lock, flags); +} + +static void vop2_crtc_handle_post_buf_empty (struct vop2_video_port *vp) +{ +spin_lock (&vp->irq_lock); +vop2_crtc_disable_irq (vp,VP_INT_POST_BUF_EMPTY ); + vp->post_buf_empty_masked = true; +/* +* POST_BUF_EMPTY is unmasked again by the FS interrupt at the next +* frame start, so FS must be enabled. With vblank reporting on it +* is already, and a pending FS may carry a vblank event. Otherwise +* enable it here, clearing the FS status of the current frame so +* that FS fires at the next frame start only. +*/ +if (!vp->vblank_enabled) +vop2_crtc_enable_irq (vp,VP_INT_FS_FIELD ); +spin_unlock (&vp->irq_lock); +} + +static void vop2_crtc_rearm_post_buf_empty (struct vop2_video_port *vp) +{ +spin_lock (&vp->irq_lock); +if (vp->post_buf_empty_masked) { + vp->post_buf_empty_masked = false; +vop2_crtc_enable_irq (vp,VP_INT_POST_BUF_EMPTY ); +if (!vp->vblank_enabled) +vop2_crtc_disable_irq (vp,VP_INT_FS_FIELD ); + } +spin_unlock (&vp->irq_lock); +} +static int vop2_core_clks_prepare_enable (struct vop2 *vop2) {int ret;
@@ -1095,6 +1159,7 @@ static void vop2_crtc_atomic_disable(struct drm_crtc *crtc,drm_info (vop2->drm,"wait for vp%d dsp_hold timeout\n" , vp->id);vop2_crtc_disable_irq (vp,VP_INT_DSP_HOLD_VALID ); +vop2_crtc_disable_post_buf_empty_irq (vp);if (vp->dclk_src)clk_set_parent (vp->dclk, vp->dclk_src);
@@ -1884,8 +1949,14 @@ static const struct drm_plane_funcs vop2_plane_funcs = {static int vop2_crtc_enable_vblank (struct drm_crtc *crtc) {struct vop2_video_port *vp =to_vop2_video_port (crtc); +unsigned long flags; -vop2_crtc_enable_irq (vp,VP_INT_FS_FIELD ); +spin_lock_irqsave (&vp->irq_lock, flags); + vp->vblank_enabled = true; +/* FS is enabled already while POST_BUF_EMPTY waits to be re-armed */ +if (!vp->post_buf_empty_masked) +vop2_crtc_enable_irq (vp,VP_INT_FS_FIELD ); +spin_unlock_irqrestore (&vp->irq_lock, flags);return 0 ; }
@@ -1893,8 +1964,13 @@ static int vop2_crtc_enable_vblank(struct drm_crtc *crtc)static void vop2_crtc_disable_vblank (struct drm_crtc *crtc) {struct vop2_video_port *vp =to_vop2_video_port (crtc); +unsigned long flags; -vop2_crtc_disable_irq (vp,VP_INT_FS_FIELD ); +spin_lock_irqsave (&vp->irq_lock, flags); + vp->vblank_enabled = false; +if (!vp->post_buf_empty_masked) +vop2_crtc_disable_irq (vp,VP_INT_FS_FIELD ); +spin_unlock_irqrestore (&vp->irq_lock, flags); } static enum drm_mode_status vop2_crtc_mode_valid(struct drm_crtc *crtc,
@@ -2193,7 +2269,7 @@ static void vop2_crtc_atomic_enable(struct drm_crtc *crtc, vcstate->yuv_overlay =is_yuv_output (vcstate->bus_format); -vop2_crtc_enable_irq (vp,VP_INT_POST_BUF_EMPTY ); +vop2_crtc_enable_post_buf_empty_irq (vp); polflags =0 ;if (vcstate->bus_flags &DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE )
@@ -2342,6 +2418,7 @@ static void vop2_crtc_atomic_enable(struct drm_crtc *crtc,return ; err_put_enable_count: +vop2_crtc_disable_post_buf_empty_irq (vp);if (!--vop2->enable_count)vop2_disable (vop2);
@@ -2751,6 +2828,7 @@ static irqreturn_t rk3576_vp_isr(int irq, void *data) }if (irqs &VP_INT_FS_FIELD ) { +vop2_crtc_rearm_post_buf_empty (vp);drm_crtc_handle_vblank (crtc);spin_lock (&crtc->dev->event_lock);if (vp->event) {
@@ -2768,6 +2846,7 @@ static irqreturn_t rk3576_vp_isr(int irq, void *data) }if (irqs &VP_INT_POST_BUF_EMPTY ) { +vop2_crtc_handle_post_buf_empty (vp);drm_err_ratelimited (vop2->drm,"POST_BUF_EMPTY irq err at vp%d\n" , vp->id); ret =IRQ_HANDLED ; }
@@ -2807,6 +2886,7 @@ static irqreturn_t vop2_isr(int irq, void *data) }if (irqs &VP_INT_FS_FIELD ) { +vop2_crtc_rearm_post_buf_empty (vp);drm_crtc_handle_vblank (crtc);spin_lock (&crtc->dev->event_lock);if (vp->event) {
@@ -2824,6 +2904,7 @@ static irqreturn_t vop2_isr(int irq, void *data) }if (irqs &VP_INT_POST_BUF_EMPTY ) { +vop2_crtc_handle_post_buf_empty (vp);drm_err_ratelimited (vop2->drm,"POST_BUF_EMPTY irq err at vp%d\n" , vp->id);
@@ -3200,7 +3281,7 @@ static int vop2_bind(struct device *dev, struct device *master, void *data)struct vop2 *vop2;struct resource *res;size_t alloc_size; -int ret; +int ret, i; vop2_data =of_device_get_match_data (dev);if (!vop2_data)
@@ -3317,6 +3398,8 @@ static int vop2_bind(struct device *dev, struct device *master, void *data)mutex_init (&vop2->vop2_lock);mutex_init (&vop2->ovl_lock); +for (i =0 ; i <ARRAY_SIZE (vop2->vps); i++) +spin_lock_init (&vop2->vps[i].irq_lock); ret =devm_request_irq (dev, vop2->irq, vop2_isr,IRQF_SHARED ,dev_name (dev), vop2);if (ret)
drivers/gpu/drm/rockchip/rockchip_drm_vop2.h +10 -0
@@ -297,6 +297,16 @@ struct vop2_video_port {struct drm_pending_vblank_event *event;unsigned int nlayers; + +/** @irq_lock: protects @vblank_enabled and @post_buf_empty_masked */ +spinlock_t irq_lock; +/** @vblank_enabled: the FS interrupt is enabled for vblank reporting */ +bool vblank_enabled; +/** +* @post_buf_empty_masked: POST_BUF_EMPTY is masked until the next +* frame start +*/ +bool post_buf_empty_masked; };/**
Signature · 1 line
2.55.0
[email protected]
AI reviewRe: [PATCH v2 6/9] drm/rockchip: vop2: Report POST_BUF_EMPTY at most once per frame
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] drm/rockchip: vop2: race in vop2_crtc_handle_post_buf_empty() on disable --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] drm/rockchip: vop2: race in vop2_crtc_handle_post_buf_empty() on disable
--
commit 06ecad385f4f1417ba151eac3f81400c9be27660
Author: Arun Iyengar <[email protected]>
drm/rockchip: vop2: Report POST_BUF_EMPTY at most once per frame
This commit masks the POST_BUF_EMPTY interrupt when it fires and re-arms it on the next frame start interrupt to avoid interrupt storms during video port underflows.
Quoted 49 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +41
-0@@ -842,6 +842,70 @@ static void vop2_crtc_disable_irq(struct vop2_video_port *vp, u32 irq)vop2_writel (vop2,RK3568_VP_INT_EN (vp->id), irq <<16 ); } +/* +* POST_BUF_EMPTY is raised for every line the post processing stage finds +* no data for, so an underflowing video port can raise it 100000 times per +* second. Report it at most once per frame: mask it when it fires and +* unmask it at the next frame start, using the FS interrupt even when +* vblank reporting is off. +*/ +/* Forget a pending re-arm, called with vp->irq_lock held */ +static void vop2_crtc_unmask_post_buf_empty (struct vop2_video_port *vp) +{ +if (vp->post_buf_empty_masked && !vp->vblank_enabled) +vop2_crtc_disable_irq (vp,VP_INT_FS_FIELD ); + vp->post_buf_empty_masked = false; +} + +static void vop2_crtc_enable_post_buf_empty_irq (struct vop2_video_port *vp) +{ +unsigned long flags; + +spin_lock_irqsave (&vp->irq_lock, flags); +vop2_crtc_unmask_post_buf_empty (vp); +vop2_crtc_enable_irq (vp,VP_INT_POST_BUF_EMPTY ); +spin_unlock_irqrestore (&vp->irq_lock, flags); +} + +static void vop2_crtc_disable_post_buf_empty_irq (struct vop2_video_port *vp) +{ +unsigned long flags; + +spin_lock_irqsave (&vp->irq_lock, flags); +vop2_crtc_disable_irq (vp,VP_INT_POST_BUF_EMPTY ); +vop2_crtc_unmask_post_buf_empty (vp); +spin_unlock_irqrestore (&vp->irq_lock, flags); +} + +static void vop2_crtc_handle_post_buf_empty (struct vop2_video_port *vp) +{ +spin_lock (&vp->irq_lock); +vop2_crtc_disable_irq (vp,VP_INT_POST_BUF_EMPTY ); + vp->post_buf_empty_masked = true; +/*
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c static void vop2_crtc_disable_irq(struct vop2_video_port *vp, u32 irq) · line 895
Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +10
-0+* POST_BUF_EMPTY is unmasked again by the FS interrupt at the next +* frame start, so FS must be enabled. With vblank reporting on it +* is already, and a pending FS may carry a vblank event. Otherwise +* enable it here, clearing the FS status of the current frame so +* that FS fires at the next frame start only. +*/ +if (!vp->vblank_enabled) +vop2_crtc_enable_irq (vp,VP_INT_FS_FIELD ); +spin_unlock (&vp->irq_lock); +}
[Severity: Medium]
Can vop2_crtc_handle_post_buf_empty() run after vop2_crtc_disable_post_buf_empty_irq() during CRTC disable and re-enable VP_INT_FS_FIELD while VOP2 clocks are being turned off?
In vop2_crtc_atomic_disable(), VP_INT_POST_BUF_EMPTY stays enabled while waiting on vp->dsp_hold_completion. In both rk3576_vp_isr() and vop2_isr(), VP_INT_STATUS is read once and complete(&vp->dsp_hold_completion) runs before vop2_crtc_handle_post_buf_empty():
CPU0 CPU1 (<hardirq>)vop2_crtc_atomic_disable()
wait_for_completion_timeout(...)
vop2_isr() / rk3576_vp_isr()
irqs = vop2_readl(...);
/* DSP_HOLD_VALID | POST_BUF_EMPTY */
complete(&vp->dsp_hold_completion);
vop2_crtc_disable_post_buf_empty_irq()
spin_lock_irqsave(&vp->irq_lock)
/* disables POST_BUF_EMPTY & FS */
vp->post_buf_empty_masked = false;
spin_unlock_irqrestore(&vp->irq_lock)
vop2_disable()
vop2_core_clks_disable_unprepare()
vop2_crtc_handle_post_buf_empty()
spin_lock(&vp->irq_lock)
vp->post_buf_empty_masked = true;
vop2_crtc_enable_irq(...,
VP_INT_FS_FIELD);
<-- MMIO write with clocks offUnlike vop2_crtc_rearm_post_buf_empty(), vop2_crtc_handle_post_buf_empty() does not check whether POST_BUF_EMPTY reporting is still enabled on the video port, so it leaves vp->post_buf_empty_masked set and VP_INT_FS_FIELD enabled on a disabled CRTC, or performs unclocked MMIO writes if the last CRTC disables VOP2 core clocks concurrently.
Disabling POST_BUF_EMPTY before waiting for dsp_hold_completion, or tracking under vp->irq_lock whether POST_BUF_EMPTY is enabled so vop2_crtc_handle_post_buf_empty() becomes a no-op once disabled, would avoid this race.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
Re: [PATCH v2 6/9] drm/rockchip: vop2: Report POST_BUF_EMPTY at most once per frame
In reply to Arun IyengarHi Arun,
Quoted 20 lines · On 11/12/2026 4:33 PM, Arun Iyengar via B4 Relay wrote:
From: Arun Iyengar <[email protected]>
POST_BUF_EMPTYis raised for every line on which the post processing stage of a video port finds no data. The interrupt handler only rate-limits the error message and leaves the interrupt enabled, so an underflowing video port keeps the CPU in the interrupt handler 50000 to 300000 times per second, for as long as the configuration that causes the underflow stays in place (e.g. 120000 interrupts per second for 3840x2160@120 with two full screen layers on one AXI port).Mask
POST_BUF_EMPTYwhen it fires and unmask it at the next frame start. The frame start (FS) interrupt is enabled for that frame even when vblank reporting is off, and disabled again oncePOST_BUF_EMPTYis re-armed or the video port is switched off.VP_INT_ENis write-masked, so maskingPOST_BUF_EMPTYleaves FS alone; FS only needs enabling here while vblank reporting has it off. A new per video port lock serialises the interrupt enable bookkeeping between the interrupt handler and the vblank callbacks. The error is still reported, now at most once per frame and video port.
Quoted 6 lines
Fixes 604be85547ce ("drm/rockchip: Add VOP2 driver")Signed-off-by Arun Iyengar <[email protected]>--- drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 91 ++++++++++++++++++++++++++-- drivers/gpu/drm/rockchip/rockchip_drm_vop2.h | 10 +++ 2 files changed, 97 insertions(+), 4 deletions(-)
Well. This change can indeed reduce CPU interrupt pressure when occasional POST_BUF_EMPTY occurs. However, we do not expect this error to happen during normal system operation: if POST_BUF_EMPTY shows up, it should be resolved by adjusting layers configurations or improving DDR bandwidth, rather than being masked.
On the other hand, this approach drops the per-line POST_BUF_EMPTY
information. In complex debugging scenarios we still need the per-line
error reports to locate issues, for example partial line data corruption
with AFBC on Cluster planes. Reporting only one interrupt per frame would hide these critical debug details.
So in my opinion, we should keep POST_BUF_EMPTY handling as it is.
Best regards,
Damon
PATCH v2 7/9 drm/rockchip: vop2: Find the first mixer of a video port with Esmart3 too
In reply to Arun Iyengarvop2_find_start_mixer_id_for_vp() looks for the first layer that holds a window of the video port, but for_each_set_bit() takes the number of bits to search, and ROCKCHIP_VOP2_ESMART3 is the highest window id, so Esmart3 is never found. A video port whose bottom layer shows Esmart3 then starts its alpha setup at the mixer of a higher layer, or, if Esmart3 is its only window, past all layers, and programs mixers of other video ports.
Add ROCKCHIP_VOP2_MAX_LAYER_ID after the last window id and search up to it.
--- drivers/gpu/drm/rockchip/rockchip_drm_vop2.h | 1 + drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/rockchip/rockchip_drm_vop2.h +1 -0
@@ -857,6 +857,7 @@ enum vop2_layer_phy_id {ROCKCHIP_VOP2_CLUSTER3 ,ROCKCHIP_VOP2_ESMART2 ,ROCKCHIP_VOP2_ESMART3 , +ROCKCHIP_VOP2_MAX_LAYER_ID , ROCKCHIP_VOP2_PHY_ID_INVALID = -1, };
drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +1 -1
@@ -1889,7 +1889,7 @@ static int vop2_find_start_mixer_id_for_vp(struct vop2_video_port *vp)for (i =0 ; i <31 ; i +=4 ) { match = false; -for_each_set_bit (phys_id, &win_mask,ROCKCHIP_VOP2_ESMART3 ) { +for_each_set_bit (phys_id, &win_mask,ROCKCHIP_VOP2_MAX_LAYER_ID ) { win =vop2_find_win_by_phys_id (vop2, phys_id);if (win->data->layer_sel_id[vp->id] == ((layer_sel >> i) &0xf )) { match = true;
Signature · 1 line
2.55.0
Re: [PATCH v2 7/9] drm/rockchip: vop2: Find the first mixer of a video port with Esmart3 too
Quoted 9 lines · On 11/12/2026 4:33 PM, Arun Iyengar via B4 Relay wrote:
From: Arun Iyengar <[email protected]>
vop2_find_start_mixer_id_for_vp()looks for the first layer that holds a window of the video port, butfor_each_set_bit()takes the number of bits to search, andROCKCHIP_VOP2_ESMART3is the highest window id, so Esmart3 is never found. A video port whose bottom layer shows Esmart3 then starts its alpha setup at the mixer of a higher layer, or, if Esmart3 is its only window, past all layers, and programs mixers of other video ports.
Quoted 5 lines
Add
ROCKCHIP_VOP2_MAX_LAYER_IDafter the last window id and search up to it.Fixes d3fe9aa49585 ("drm/rockchip: vop2: Use OVL_LAYER_SEL configuration instead of use win_mask calculate used layers")Signed-off-by Arun Iyengar <[email protected]>
Quoted 31 lines
--- drivers/gpu/drm/rockchip/rockchip_drm_vop2.h | 1 + drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)drivers/gpu/drm/rockchip/rockchip_drm_vop2.h +1
-0@@ -857,6 +857,7 @@ enum vop2_layer_phy_id {ROCKCHIP_VOP2_CLUSTER3 ,ROCKCHIP_VOP2_ESMART2 ,ROCKCHIP_VOP2_ESMART3 , +ROCKCHIP_VOP2_MAX_LAYER_ID , ROCKCHIP_VOP2_PHY_ID_INVALID = -1, };drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +1
-1@@ -1889,7 +1889,7 @@ static int vop2_find_start_mixer_id_for_vp(struct vop2_video_port *vp)for (i =0 ; i <31 ; i +=4 ) { match = false; -for_each_set_bit (phys_id, &win_mask,ROCKCHIP_VOP2_ESMART3 ) { +for_each_set_bit (phys_id, &win_mask,ROCKCHIP_VOP2_MAX_LAYER_ID ) { win =vop2_find_win_by_phys_id (vop2, phys_id);if (win->data->layer_sel_id[vp->id] == ((layer_sel >> i) &0xf )) { match = true;
Signature · 2 lines
Best, Chaoyi
Re: [PATCH v2 7/9] drm/rockchip: vop2: Find the first mixer of a video port with Esmart3 too
In reply to Arun IyengarQuoted 37 lines · On 11/12/2026 4:33 PM, Arun Iyengar via B4 Relay wrote:
From: Arun Iyengar <[email protected]>
vop2_find_start_mixer_id_for_vp()looks for the first layer that holds a window of the video port, butfor_each_set_bit()takes the number of bits to search, andROCKCHIP_VOP2_ESMART3is the highest window id, so Esmart3 is never found. A video port whose bottom layer shows Esmart3 then starts its alpha setup at the mixer of a higher layer, or, if Esmart3 is its only window, past all layers, and programs mixers of other video ports.Add
ROCKCHIP_VOP2_MAX_LAYER_IDafter the last window id and search up to it.Fixes d3fe9aa49585 ("drm/rockchip: vop2: Use OVL_LAYER_SEL configuration instead of use win_mask calculate used layers")Signed-off-by Arun Iyengar <[email protected]>--- drivers/gpu/drm/rockchip/rockchip_drm_vop2.h | 1 + drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-)drivers/gpu/drm/rockchip/rockchip_drm_vop2.h +1
-0@@ -857,6 +857,7 @@ enum vop2_layer_phy_id {ROCKCHIP_VOP2_CLUSTER3 ,ROCKCHIP_VOP2_ESMART2 ,ROCKCHIP_VOP2_ESMART3 , +ROCKCHIP_VOP2_MAX_LAYER_ID , ROCKCHIP_VOP2_PHY_ID_INVALID = -1, };drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +0
-0
drivers/gpu/drm/rockchip/rockchip_vop2_reg.c static int vop2_find_start_mixer_id_for_vp(struct vop2_video_port *vp) · line 1895
Quoted 8 lines
drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +1
-1@@ -1889,7 +1889,7 @@ static int vop2_find_start_mixer_id_for_vp(struct vop2_video_port *vp)for (i =0 ; i <31 ; i +=4 ) { match = false; -for_each_set_bit (phys_id, &win_mask,ROCKCHIP_VOP2_ESMART3 ) { +for_each_set_bit (phys_id, &win_mask,ROCKCHIP_VOP2_MAX_LAYER_ID ) { win =vop2_find_win_by_phys_id (vop2, phys_id);if (win->data->layer_sel_id[vp->id] == ((layer_sel >> i) &0xf )) { match = true;
Best regards,
Damon
PATCH v2 8/9 drm/rockchip: vop2: Keep the other LUT_PORT_SEL fields on gamma LUT updates
In reply to Arun IyengarOn RK3588 the gamma LUT of a video port is written through a window that GAMMA_AHB_WRITE_SEL in SYS_CTRL_LUT_PORT_SEL selects. The register also holds the dclk source selection of video ports 0 and 2 and the enable of the video port 0/1 merge for modes wider than 4096 pixels, which writing the whole register clears.
Only update the write select field.
--- drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +3 -2
@@ -2015,8 +2015,9 @@ static void vop2_crtc_atomic_set_gamma_seamless(struct vop2 *vop2,struct vop2_video_port *vp, struct drm_crtc *crtc) { -vop2_writel (vop2 ,RK3568_LUT_PORT_SEL , - FIELD_PREP(RK3588_LUT_PORT_SEL__GAMMA_AHB_WRITE_SEL, vp->id)); + regmap_update_bits(vop2->map, RK3568_LUT_PORT_SEL, +RK3588_LUT_PORT_SEL__GAMMA_AHB_WRITE_SEL , + FIELD_PREP(RK3588_LUT_PORT_SEL__GAMMA_AHB_WRITE_SEL, vp->id));vop2_vp_dsp_lut_enable (vp);vop2_crtc_write_gamma_lut (vop2, crtc);vop2_vp_dsp_lut_update_enable (vp);
Signature · 1 line
2.55.0
Re: [PATCH v2 8/9] drm/rockchip: vop2: Keep the other LUT_PORT_SEL fields on gamma LUT updates
Quoted 24 lines · On 11/12/2026 4:33 PM, Arun Iyengar via B4 Relay wrote:
From: Arun Iyengar <[email protected]>
On RK3588 the gamma LUT of a video port is written through a window that
GAMMA_AHB_WRITE_SELinSYS_CTRL_LUT_PORT_SELselects. The register also holds the dclk source selection of video ports 0 and 2 and the enable of the video port 0/1 merge for modes wider than 4096 pixels, which writing the whole register clears.Only update the write select field.
Fixes 4f537776340d ("rockchip/drm: vop2: add support for gamma LUT")Reviewed-by Chaoyi Chen <[email protected]>Signed-off-by Arun Iyengar <[email protected]>--- drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +0
-0@@ -2015,8 +2015,9 @@ static void vop2_crtc_atomic_set_gamma_seamless(struct vop2 *vop2, struct vop2_video_port *vp,
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c static void vop2_crtc_atomic_set_gamma_seamless(struct vop2 *vop2, · line 2023
Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +3
-2struct drm_crtc *crtc) { -vop2_writel (vop2,RK3568_LUT_PORT_SEL , -FIELD_PREP (RK3588_LUT_PORT_SEL__GAMMA_AHB_WRITE_SEL , vp->id)); +regmap_update_bits (vop2->map,RK3568_LUT_PORT_SEL , +RK3588_LUT_PORT_SEL__GAMMA_AHB_WRITE_SEL , +FIELD_PREP (RK3588_LUT_PORT_SEL__GAMMA_AHB_WRITE_SEL , vp->id));vop2_vp_dsp_lut_enable (vp);vop2_crtc_write_gamma_lut (vop2, crtc);vop2_vp_dsp_lut_update_enable (vp);
Best regards,
Damon
PATCH v2 9/9 drm/rockchip: vop2: Fix the AFBC offsets of a source that starts inside a superblock
In reply to Arun IyengarThe AFBC decoder of a window takes the position of the source in the framebuffer (AFBC_PIC_OFFSET), the number of superblock columns to decode (AFBC_TILE_NUM) and the offset of the first pixel inside its superblock (the transform offset). For a source that doesn't start at x = 0:
- The tile number only counts the superblocks of the source width, one short when the source starts inside a superblock and ends inside another one.
- The transform offset is the whole x position, truncated to the 8 bit field, instead of the position in the superblock (16 pixels wide, or 32 with AFBC_FORMAT_MOD_BLOCK_SIZE_32x8 on RK3576).
Count the superblock columns from the first one the source touches, and take the x offset in the superblock, like the vendor kernel does for the not mirrored cases. The X mirrored and rotated cases are left as they are.
--- drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +6 -5
@@ -439,7 +439,7 @@ static bool vop2_half_block_enable(struct drm_plane_state *pstate) }static u32 vop2_afbc_transform_offset (struct drm_plane_state *pstate, -bool afbc_half_block_en) +bool afbc_half_block_en,u32 block_w) {struct drm_rect *src = &pstate->src;struct drm_framebuffer *fb = pstate->fb;
@@ -487,7 +487,7 @@ static u32 vop2_afbc_transform_offset(struct drm_plane_state *pstate, ty = act_yoffset;break ;case DRM_MODE_REFLECT_Y : - tx = act_xoffset; + tx = act_xoffset % block_w; ty = bottom_crop_line_num - act_yoffset;break ;case DRM_MODE_ROTATE_90 :
@@ -499,7 +499,7 @@ static u32 vop2_afbc_transform_offset(struct drm_plane_state *pstate, ty = vir_width - width - act_xoffset;break ;case 0 : - tx = act_xoffset; + tx = act_xoffset % block_w; ty = act_yoffset;break ; }
@@ -1816,7 +1816,8 @@ static void vop2_plane_atomic_update(struct drm_plane *plane,if (fb->modifier &AFBC_FORMAT_MOD_YTR ) afbc_format |= (1 <<4 ); - afbc_tile_num =ALIGN (src_w, block_w) / block_w; +/* Superblock columns the source covers, the first one partly */ + afbc_tile_num =ALIGN (src_w + (src->x1 >>16 ) % block_w, block_w) / block_w;/* * AFBC pic_vir_width is count by pixel, this is different
@@ -1867,7 +1868,7 @@ static void vop2_plane_atomic_update(struct drm_plane *plane,vop2_win_write (win,VOP2_WIN_AFBC_PLD_OFFSET , yrgb_mst); } - transform_offset =vop2_afbc_transform_offset (pstate, half_block_en); + transform_offset =vop2_afbc_transform_offset (pstate, half_block_en, block_w);vop2_win_write (win,VOP2_WIN_AFBC_HDR_PTR , yrgb_mst);vop2_win_write (win,VOP2_WIN_AFBC_PIC_SIZE , act_info);vop2_win_write (win,VOP2_WIN_TRANSFORM_OFFSET , transform_offset);
Signature · 1 line
2.55.0