drm/rockchip: vop2: Add 8K support for RK3588 vop2
Subsystems (4)
v2 cover drm/rockchip: vop2: Add 8K support for RK3588 vop2
From: Chaoyi Chen <[email protected]>
Hi,
This series adds support for 8K output on the RK3588 VOP2. HDMI is not ready yet, but I believe many people might be interested in this.
8K output on the RK3588 is done by splicing two VPs together, with VP0 outputting the left half of the screen and VP1 the right half. In addition, 8K planes have to be split in half as well to stay within the width limit of a single plane. Similarly, there are a few post-processing details that need to be handled.
Note that splice mode is not only usable for 8K output. This means the mode can be tested at 4K and even lower resolutions, by simply changing this one line:
-#define VOP2_MAX_VP_OUTPUT_WIDTH 4096
+#define VOP2_MAX_VP_OUTPUT_WIDTH (3840 / 2) /* for 4K test */
And yes, this has been tested at 4K over HDMI on the RK3588 EVB1 :)
Changes in v2:
- Link to v1: https://lore.kernel.org/all/[email protected]/
- Missing removal of the replaced line(Heiko).
- vop2_win_get_pstate(): use the left window's state only in splice mode(Sashiko).
- Reject splice windows already in use by another CRTC(Sashiko).
- Check the splice partner via drm_atomic_get_crtc_state() instead of the runtime flag and unlocked read(Sashiko).
- Set splice_mode_right/left_vp before the error paths of vop2_crtc_atomic_enable()(Sashiko).
- Validate each split half against the min width 4 and max input width; align NV20/NV30 like NV15(Sashiko).
- Latch overlay registers at the left VP's vsync; don't wait for the partner's own cfg-done(Sashiko).
- Program the color key on the window actually being updated(Sashiko).
---
Chaoyi Chen (3):
drm/rockchip: vop2: Use drm_format_info_min_pitch() for plane offsets drm/rockchip: vop2: Skip UV plane setup for packed YUV formats drm/rockchip: vop2: Support 8K output by splicing two video ports
drivers/gpu/drm/rockchip/rockchip_drm_drv.h | 5 + drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 535 +++++++++++++++++-- drivers/gpu/drm/rockchip/rockchip_drm_vop2.h | 66 ++- drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 204 +++++-- 4 files changed, 721 insertions(+), 89 deletions(-)
Signature · 1 line
2.53.0
PATCH v2 1/3 drm/rockchip: vop2: Use drm_format_info_min_pitch() for plane offsets
From: Chaoyi Chen <[email protected]>
Use the block aware helper instead of cpp[], the latter aliases char_per_block and is wrong for packed 10-bit formats like NV15, NV20 and NV30.
Tested with modetest[0]:
``` modetest -s 86:3840x2160 -P \ 59@83:3940x2160~96,0,3840,2160+0+0@NV20 -a ```
fb size (3940x2160), src at (96, 0) with size (3840x2160), dst at (0, 0) with size (3840x2160)
[0]: https://github.com/windowsair/libdrm/tree/src-pos-support
---
Changes in v2:
- Missing removal of the replaced line(Heiko).
--- drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +2 -2
@@ -1290,7 +1290,7 @@ static void vop2_plane_atomic_update(struct drm_plane *plane, afbc_en =drm_is_afbc (fb->modifier); - offset = (src->x1 >>16 ) * fb->format->cpp[0 ]; + offset =drm_format_info_min_pitch (fb->format,0 , src->x1 >>16 );/* * AFBC HDR_PTR must set to the zero offset of the framebuffer.
@@ -1309,7 +1309,7 @@ static void vop2_plane_atomic_update(struct drm_plane *plane,int hsub = fb->format->hsub;int vsub = fb->format->vsub; - offset = (src->x1 >>16 ) * fb->format->cpp[1 ] / hsub; + offset =drm_format_info_min_pitch (fb->format,1 , src->x1 >>16 ) / hsub; offset += (src->y1 >>16 ) * fb->pitches[1 ] / vsub;if ((pstate->rotation &DRM_MODE_REFLECT_Y ) && !afbc_en)
Signature · 1 line
2.53.0
PATCH v2 2/3 drm/rockchip: vop2: Skip UV plane setup for packed YUV formats
In reply to Chaoyi ChenFrom: Chaoyi Chen <[email protected]>
Packed YUV formats store chroma interleaved with luma in the same plane, so they have no plane 1 that the UV address registers could point at.
Restrict both the plane 1 offset calculation and the UV register writes to formats with more than one plane.
---
(no changes since v1)
--- drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +2 -2
@@ -1305,7 +1305,7 @@ static void vop2_plane_atomic_update(struct drm_plane *plane, rk_obj =to_rockchip_obj (fb->obj[0 ]); yrgb_mst = rk_obj->dma_addr + offset + fb->offsets[0 ]; -if (fb->format->is_yuv) { +if (fb->format->is_yuv && fb->format->num_planes >1 ) {int hsub = fb->format->hsub;int vsub = fb->format->vsub;
@@ -1460,7 +1460,7 @@ static void vop2_plane_atomic_update(struct drm_plane *plane, uv_swap =vop2_win_uv_swap (fb->format->format);vop2_win_write (win,VOP2_WIN_UV_SWAP , uv_swap); -if (fb->format->is_yuv) { +if (fb->format->is_yuv && fb->format->num_planes >1 ) {vop2_win_write (win,VOP2_WIN_UV_VIR ,DIV_ROUND_UP (fb->pitches[1 ],4 ));vop2_win_write (win,VOP2_WIN_UV_MST , uv_mst); }
Signature · 1 line
2.53.0
PATCH v2 3/3 drm/rockchip: vop2: Support 8K output by splicing two video ports
In reply to Chaoyi ChenFrom: Chaoyi Chen <[email protected]>
A single RK3588 video port can only drive 4096 pixels per line, so modes wider than that (e.g. 7680x4320) cannot be output by one video port alone. The VOP2 can instead merge video ports and two windows:
VP0 drives the left half of the screen, VP1 the right half, and each plane of the CRTC is split horizontally between a window pair (Cluster0/1, Cluster2/3, Esmart0/1, Esmart2/3).
Three components need to be configured: the CRTC, the plane and the post-processing block.
1. For CRTC
In splice mode the CRTC reserved for VP1 is taken over, so make the following changes:
vop2_crtc_atomic_check() sets the new splice_mode flag for modes wider than VOP2_MAX_VP_OUTPUT_WIDTH, reserves the partner video port (rejecting the commit if it is already active) and verifies that both video ports have enough layers for the planes of the CRTC. The reserved video port is taken into account when the layers are distributed over the video ports, and it is registered so that its windows exist, but its own CRTC is kept unusable while it serves as the right half.
2. For Plane
To avoid requiring additional userspace changes, the plane split is performed in the driver. Userspace can thereforekeep updating a single plane that is 8K wide. To do so, make the following changes:
vop2_plane_atomic_check() accepts a source width of twice the maximum input width and validates the split: the plane must use a window with the WIN_FEATURE_SPLICE_LEFT flag, must not be rotated or x-mirrored, and cluster windows that scale down may only do so centred on the screen with a factor below 1.2.
vop2_plane_atomic_update() calculates the left and right source and destination rectangles and programs both windows of a plane pair from the same plane state.
3. For post-processing block
The overlay, alpha and layer mixer setup iterate over the window mask of a video port instead of the planes of its CRTC, because the right video port has no planes of its own. A right window resolves its plane state through left_win.
Gamma LUT and background colour setup are applied to the partner video port as well.
---
Changes since v2:
- vop2_win_get_pstate(): use the left window's state only in splice mode(Sashiko).
- Reject splice windows already in use by another CRTC(Sashiko).
- Check the splice partner via drm_atomic_get_crtc_state() instead of the runtime flag and unlocked read(Sashiko).
- Set splice_mode_right/left_vp before the error paths of vop2_crtc_atomic_enable()(Sashiko).
- Validate each split half against the min width 4 and max input width; align NV20/NV30 like NV15(Sashiko).
- Latch overlay registers at the left VP's vsync; don't wait for the partner's own cfg-done(Sashiko).
- Program the color key on the window actually being updated(Sashiko).
--- drivers/gpu/drm/rockchip/rockchip_drm_drv.h | 5 + drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 527 +++++++++++++++++-- drivers/gpu/drm/rockchip/rockchip_drm_vop2.h | 66 ++- drivers/gpu/drm/rockchip/rockchip_vop2_reg.c | 204 +++++-- 4 files changed, 717 insertions(+), 85 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_drv.h +5 -0
@@ -54,6 +54,11 @@ struct rockchip_crtc_state {int output_flags;bool enable_afbc;bool yuv_overlay; +/** +* @splice_mode: two video ports are joined together to drive a +* display that is wider than a single video port can handle. +*/ +bool splice_mode;u32 bus_format;u32 bus_flags;int color_space;
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +493 -34
803 lines not on this page · raw message
drivers/gpu/drm/rockchip/rockchip_drm_vop2.h +65 -1
132 lines not on this page · raw message
drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +154 -50
438 lines not on this page · raw message
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v2 1/3] drm/rockchip: vop2: Use drm_format_info_min_pitch() for plane offsets
In reply to Chaoyi ChenThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] drm/rockchip: vop2: 64-bit division by hsub in vop2_plane_atomic_update() --
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] drm/rockchip: vop2: 64-bit division by hsub in vop2_plane_atomic_update() --
commit 6053e1180bcd99e2d0019c04165b9318bc1a9fc3
Author: Chaoyi Chen <[email protected]>
drm/rockchip: vop2: Use drm_format_info_min_pitch() for plane offsets
This commit replaces fb->format->cpp[] with drm_format_info_min_pitch() when computing horizontal plane offsets in vop2_plane_atomic_update() to support packed 10-bit formats such as NV15, NV20, and NV30.
Quoted 4 lines
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 1312
Quoted 6 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +1
-1@@ -1309,7 +1309,7 @@ static void vop2_plane_atomic_update(struct drm_plane *plane,int hsub = fb->format->hsub;int vsub = fb->format->vsub; - offset = (src->x1 >>16 ) * fb->format->cpp[1 ] / hsub; + offset =drm_format_info_min_pitch (fb->format,1 , src->x1 >>16 ) / hsub;
[Severity: Medium]
Does dividing the return value of drm_format_info_min_pitch() by hsub in vop2_plane_atomic_update() cause a 64-bit division linker regression on 32-bit architectures?
drm_format_info_min_pitch() returns a uint64_t:
drivers/gpu/drm/drm_fourcc.c:drm_format_info_min_pitch() {
if (!info || plane < 0 || plane >= info->num_planes)
return 0;
return DIV_ROUND_UP_ULL((u64)buffer_width * info->char_per_block[plane],
drm_format_info_block_width(info, plane) *
drm_format_info_block_height(info, plane));
}Because hsub is a runtime int variable, dividing the uint64_t result directly with '/' promotes the expression to a 64-bit unsigned division before assigning to unsigned long offset. Since CONFIG_ROCKCHIP_VOP2 can be built on 32-bit targets (via 32-bit ARM ARCH_ROCKCHIP or COMPILE_TEST), this emits an unresolved call to __aeabi_uldivmod or __udivdi3 at link time.
Additionally, drm_format_info.block_w[1] is defined in units of subsampled chroma pixels (for example, block_w is { 4, 2, 0 } for NV15 and NV20), so drm_format_info_min_pitch() expects buffer_width for plane 1 to already be subsampled. Dividing by hsub after DIV_ROUND_UP_ULL() rounds up before subsampling and then truncates.
Should (src->x1 >> 16) / hsub be passed as the buffer_width argument to drm_format_info_min_pitch(), or should offset be assigned before dividing by hsub as is done in vop_plane_atomic_update() in rockchip_drm_vop.c?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
[email protected]
AI reviewRe: [PATCH v2 3/3] drm/rockchip: vop2: Support 8K output by splicing two video ports
In reply to Chaoyi ChenThank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider: - [High] drm/rockchip: vop2: vop2_plane_atomic_check() adds unrelated CRTC on pageflips - [High]…
Thank you for your contribution! Sashiko AI review found 7 potential issue(s) to consider:
- [High] drm/rockchip: vop2: vop2_plane_atomic_check() adds unrelated CRTC on pageflips
- [High] drm/rockchip: vop2: stale splice_mode and incomplete plane conflict checks
- [High] drm/rockchip: vop2: vop2_create_crtcs() binds splice_win as VP2 primary plane
- [High] drm/rockchip: vop2: broken CFG_DONE latching on splice disable and modeset
- [High] drm/rockchip: vop2: back-to-back rk3568_vop2_setup_layer_mixer() times out
- [Medium] drm/rockchip: vop2: vop2_crtc_mode_valid() checks runtime splice_mode_right
- [Medium] drm/rockchip: vop2: unaligned Esmart downscale and NV15/20/30 split rects --
commit fb88a534f1ee73c5e200206f6544bce1ff6db310
Author: Chaoyi Chen <[email protected]>
drm/rockchip: vop2: Support 8K output by splicing two video ports
This commit adds support for 8K display modes on RK3588 VOP2 by splicing two video ports and splitting each plane horizontally across a pair of hardware windows. It updates CRTC, plane, and overlay post-processing configuration to reserve and program the partner video port and windows.
Quoted 4 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +0
-0
[ ... ]
Quoted 41 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +22
-0@@ -1012,13 +1013,32 @@ static void vop2_crtc_atomic_disable(struct drm_crtc *crtc, struct drm_atomic_commit *state) {struct vop2_video_port *vp =to_vop2_video_port (crtc); +struct rockchip_crtc_state *old_vcstate; +struct vop2_video_port *splice_vp =NULL ;struct vop2 *vop2 = vp->vop2;struct drm_crtc_state *old_crtc_state; +struct drm_plane *plane;int ret;vop2_lock (vop2); old_crtc_state =drm_atomic_get_old_crtc_state (state, crtc); + old_vcstate =to_rockchip_crtc_state (old_crtc_state); + splice_vp = old_vcstate->splice_mode ?vop2_get_splice_vp (vp) :NULL ; + +/* +* The right windows are not tracked by the plane states, disable +* them before the video ports are put into standby. +*/ +if (splice_vp) { +drm_atomic_crtc_state_for_each_plane (plane, old_crtc_state) { +struct vop2_win *win =to_vop2_win (plane)->splice_win; + +if (win) +vop2_win_disable (win); + } + } +drm_atomic_helper_disable_planes_on_crtc (old_crtc_state, false);drm_crtc_vblank_off (crtc);@@ -1034,6 +1054,9 @@ static void vop2_crtc_atomic_disable(struct drm_crtc *crtc,vop2_crtc_enable_irq (vp,VP_INT_DSP_HOLD_VALID ); +if (splice_vp) + vop2->ops->setup_splice (vp, false); +vop2_vp_write (vp,RK3568_VP_DSP_CTRL ,RK3568_VP_DSP_CTRL__STANDBY );
[ ... ]
Quoted 1 line
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +0
-0@@ -1064,6 +1092,202 @@ static void vop2_crtc_atomic_disable(struct drm_crtc *crtc,
[ ... ]
Quoted 31 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +31
-0+static int vop2_calc_splice_rects (struct drm_plane_state *pstate, +struct drm_crtc_state *cstate, +struct drm_rect *left_src, +struct drm_rect *left_dst, +struct drm_rect *right_src, +struct drm_rect *right_dst) +{ +struct drm_rect *src = &pstate->src; +struct drm_rect *dst = &pstate->dst; +struct drm_framebuffer *fb = pstate->fb; +int half_hdisplay = cstate->adjusted_mode.crtc_hdisplay >>1 ; +int hscale =drm_rect_calc_hscale (src, dst,0 ,INT_MAX ); +int dst_w =drm_rect_width (dst); +int src_w =drm_rect_width (src) >>16 ; +int left_dst_w, left_src_w, right_dst_w; + +if (hscale <0 ) +return hscale; + + left_dst_w =min (half_hdisplay, dst->x2) - dst->x1; +if (left_dst_w <0 ) + left_dst_w =0 ; + right_dst_w = dst_w - left_dst_w; + +if (!right_dst_w) + left_src_w = src_w; +else + left_src_w = (left_dst_w * hscale) >>16 ; + +/* +* Make sure the yrgb/uv mst of the right window are byte aligned
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c static void vop2_crtc_atomic_disable(struct drm_crtc *crtc, · line 1166
Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +10
-0+* with full pixel. +*/ +if (right_dst_w) { +if (fb->format->format ==DRM_FORMAT_NV15 || + fb->format->format ==DRM_FORMAT_NV20 || + fb->format->format ==DRM_FORMAT_NV30 ) + left_src_w &= ~0x7 ; +else if (fb->format->is_yuv) + left_src_w &= ~0x1 ; + }
[Severity: Medium]
Can vop2_calc_splice_rects() in drivers/gpu/drm/rockchip/rockchip_drm_vop2.c produce unaligned split rectangles for Esmart downscaling and NV15/NV20/NV30 formats?
First, in vop2_plane_atomic_check(), Esmart windows reject downscaling when the source width is odd:
if (!vop2_cluster_window(win) && src_w > dest_w && (src_w & 1)) {
drm_dbg_kms(vop2->drm,
"Esmart windows cannot downscale odd-width source regions\n");
return -EINVAL;
}That check only inspects the unsplit plane's src_w and dest_w. When right_dst_w > 0 and !fb->format->is_yuv (RGB formats), vop2_calc_splice_rects() computes left_src_w = (left_dst_w * hscale) >> 16 without rounding it to an even width. An even total src_w downscaled on Esmart0/1 or Esmart2/3 can split into an odd left_src_w and an odd right_src_w, bypassing the check in vop2_plane_atomic_check() and programming both Esmart hardware windows to downscale odd-width source regions.
Second, for DRM_FORMAT_NV15, DRM_FORMAT_NV20, and DRM_FORMAT_NV30 (10-bit packed YUV where 8 pixels occupy 10 bytes), vop2_calc_splice_rects() masks left_src_w &= ~0x7 so the right window's start offset is byte-aligned on an 8-pixel boundary. However, right_src->x1 is set to src->x1 + (left_src_w << 16), and vop2_plane_atomic_check() only checks (src->x1 >> 16) % 2. When src->x1 >> 16 is 2, 4, or 6, neither left_src->x1 >> 16 nor right_src->x1 >> 16 is a multiple of 8, causing drm_format_info_min_pitch() in vop2_win_atomic_update() to compute non-byte-aligned yrgb_mst and uv_mst DMA addresses.
Should vop2_calc_splice_rects() and vop2_plane_atomic_check() enforce 8-pixel alignment on src_x for NV15/NV20/NV30 and ensure split Esmart downscale source widths are even?
[ ... ]
Quoted 35 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +22
-5@@ -1122,15 +1347,43 @@ static int vop2_plane_atomic_check(struct drm_plane *plane,return -EINVAL ; } -if (src_w > vop2_data->max_input.width || - src_h > vop2_data->max_input.height) { + max_src_w = vop2_data->max_input.width; +if (vop2_vp_uses_splice (vp, cstate)) + max_src_w *=2 ; + +if (src_w > max_src_w || src_h > vop2_data->max_input.height) {drm_dbg_kms (vop2->drm,"Invalid source: %dx%d. max input: %dx%d\n" , - src_w, src_h, - vop2_data->max_input.width, - vop2_data->max_input.height); + src_w, src_h, max_src_w, vop2_data->max_input.height);return -EINVAL ; } +if (vop2_vp_uses_splice (vp, cstate)) { + ret =vop2_plane_splice_check (pstate, cstate); +if (ret) +return ret; + } + +if (win->left_win) { +struct drm_plane_state *lstate; +struct drm_crtc_state *lcstate; + + lstate =drm_atomic_get_plane_state (astate, &win->left_win->base); +if (IS_ERR (lstate)) +return PTR_ERR (lstate); + +if (lstate->crtc) { + lcstate =drm_atomic_get_crtc_state (astate, lstate->crtc);
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c static int vop2_plane_atomic_check(struct drm_plane *plane, · line 1385
Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +10
-0+if (IS_ERR (lcstate)) +return PTR_ERR (lcstate); + +if (to_rockchip_crtc_state (lcstate)->splice_mode) { +drm_dbg_kms (vop2->drm,"%s is in use by %s in splice mode\n" , + win->left_win->data->name, win->data->name); +return -EBUSY ; + } + } + }
[Severity: High]
Does vop2_plane_atomic_check() in drivers/gpu/drm/rockchip/rockchip_drm_vop2.c pull an unrelated CRTC into non-modeset pageflip commits whenever win->left_win is set?
In vop2_win_init(), win->left_win is permanently populated at probe time for Cluster1-win0, Cluster3-win0, Esmart1-win0, and Esmart3-win0. When userspace submits a normal non-modeset plane update or pageflip (where astate->allow_modeset is false) using any of those planes (for example, VP1's primary plane Cluster1-win0 or VP3's primary plane Cluster3-win0, even when no CRTC is using splice mode), vop2_plane_atomic_check() unconditionally calls drm_atomic_get_plane_state(astate, &win->left_win->base) and, when lstate->crtc is non-NULL, drm_atomic_get_crtc_state(astate, lstate->crtc).
When win->left_win is active on another CRTC (such as Cluster0-win0 on VP0), adding that unrelated CRTC state to a commit with allow_modeset == false triggers the kernel warning in drm_atomic_check_only():
if (affected_crtc != requested_crtc) {
drm_dbg_atomic(dev,
"driver added CRTC to commit: requested 0x%x, affected 0x%0x\n",
requested_crtc, affected_crtc);
WARN(!state->allow_modeset, "adding CRTC not allowed without modesets: requested 0x%x, affected 0x%0x\n",
requested_crtc, affected_crtc);
}In addition, pulling the other CRTC and plane into astate causes stall_checks() in drm_atomic_helper_setup_commit() to fail independent non-blocking pageflips with -EBUSY whenever the other CRTC has an in-flight flip, and attaches a new drm_crtc_commit to the other CRTC so that drm_atomic_helper_commit_planes() reprograms and waits for vblank on the unrelated CRTC on every flip.
[ ... ]
Quoted 6 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +2
-0@@ -1524,6 +1824,16 @@ static enum drm_mode_status vop2_crtc_mode_valid(struct drm_crtc *crtc, {struct vop2_video_port *vp =to_vop2_video_port (crtc); +/* +* For RK3588, VP0 and VP1 will be both used in splice mode. All display
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c static enum drm_mode_status vop2_crtc_mode_valid(struct drm_crtc *crtc, · line 1838
Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +8
-0+* modes of the right VP should be set as invalid when vop2 is working in +* splice mode. +*/ +if (vp->splice_mode_right) { +DRM_DEV_DEBUG (vp->vop2->dev,"vp%d is in splice mode right\n" , vp->id); +return MODE_BAD ; + } +if (mode->hdisplay > vp->data->max_output.width)return MODE_BAD_HVALUE ;
[Severity: Medium]
Is it safe for vop2_crtc_mode_valid() in drivers/gpu/drm/rockchip/rockchip_drm_vop2.c to reject modes based on the runtime vp->splice_mode_right flag?
vp->splice_mode_right is updated under vop2_lock(vop2) during commit_tail in vop2_crtc_atomic_enable() and vop2_crtc_atomic_disable(). Reading it unlocked in vop2_crtc_mode_valid() causes drm_helper_probe_single_connector_modes() to prune all modes on VP1's connector while VP0 is running in 8K splice mode.
Furthermore, because drm_atomic_helper_check_modeset() invokes mode_valid() before atomic_check and before commit_tail clears vp->splice_mode_right, any atomic commit (or DRM_MODE_ATOMIC_TEST_ONLY check) that switches VP0 out of 8K splice mode and enables VP1 in the same transaction will be rejected by vop2_crtc_mode_valid() with MODE_BAD (-EINVAL).
[ ... ]
Quoted 27 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +14
-1@@ -1984,21 +2319,100 @@ static int vop2_crtc_atomic_check(struct drm_crtc *crtc, struct drm_atomic_commit *state) {struct vop2_video_port *vp =to_vop2_video_port (crtc); +struct vop2 *vop2 = vp->vop2; +const struct vop2_video_port_data *vp_data = &vop2->data->vp[vp->id]; +struct drm_crtc_state *crtc_state =drm_atomic_get_new_crtc_state (state, crtc); +struct rockchip_crtc_state *vcstate =to_rockchip_crtc_state (crtc_state); +struct vop2_video_port *splice_vp;struct drm_plane *plane;int nplanes =0 ; -struct drm_crtc_state *crtc_state =drm_atomic_get_new_crtc_state (state, crtc);int ret; ret =vop2_crtc_atomic_check_gamma (vp, crtc, state, crtc_state);if (ret)return ret; +/* Check if left_vp is in use */ +if (crtc_state->enable &&drm_atomic_crtc_needs_modeset (crtc_state)) { +struct vop2_video_port *left_vp =vop2_find_left_splice_vp (vop2, vp->id); + +if (left_vp && left_vp->crtc.state) { +struct drm_crtc_state *lstate, *lold; + + lstate =drm_atomic_get_crtc_state (state, &left_vp->crtc); +if (IS_ERR (lstate))
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c static int vop2_crtc_atomic_check(struct drm_crtc *crtc, · line 2353
Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +10
-0+return PTR_ERR (lstate); + + lold =drm_atomic_get_old_crtc_state (state, &left_vp->crtc); +if (to_rockchip_crtc_state (lold)->splice_mode) { +drm_dbg_kms (vop2->drm,"vp%d is in use by vp%d in splice mode\n" , + vp->id, left_vp->id); +return -EBUSY ; + } + } + }
[Severity: High]
Can the splice conflict checks across vop2_plane_atomic_check() and vop2_crtc_atomic_check() in drivers/gpu/drm/rockchip/rockchip_drm_vop2.c examine stale splice_mode state or miss plane conflicts?
There appear to be four related issues in these checks:
1. In drm_atomic_helper_check_planes(), all plane->atomic_check() callbacks (vop2_plane_atomic_check()) run before any crtc->atomic_check() callbacks (vop2_crtc_atomic_check()). Because vcstate->splice_mode is only updated in vop2_crtc_atomic_check(), when vop2_plane_atomic_check() checks to_rockchip_crtc_state(lcstate)->splice_mode, it reads the stale splice_mode value duplicated from the previous commit rather than whether lstate->crtc uses splice mode in the new commit.
2. In vop2_crtc_atomic_check() above, lstate is fetched via drm_atomic_get_crtc_state(state, &left_vp->crtc) and left unused, while the check inspects to_rockchip_crtc_state(lold)->splice_mode on the old CRTC state. If userspace switches left_vp (VP0) from an 8K splice mode to a non-splice mode (or disables VP0) and enables vp (VP1) in the same atomic commit, both vop2_crtc_atomic_check() and vop2_plane_atomic_check() falsely reject the commit with -EBUSY.
3. In vop2_plane_atomic_check(), the early return for invisible planes:
if (!pstate->visible) return 0;
runs before vop2_plane_splice_check() and before the if (win->left_win) check. A plane attached to a CRTC (pstate->crtc != NULL) that is clipped off-screen (!pstate->visible) remains in crtc_state->plane_mask. During commit, rk3568_vop2_setup_overlay() in drivers/gpu/drm/rockchip/rockchip_vop2_reg.c iterates over crtc->state->plane_mask via drm_atomic_crtc_for_each_plane() and reassigns the window in RK3568_OVL_PORT_SEL, while vop2_plane_atomic_update() calls vop2_plane_atomic_disable() -> vop2_win_disable(win) on the active right splice window.
4. Unlike vop2_crtc_atomic_check() (which checks both rstate->crtc and old_rstate->crtc), vop2_plane_atomic_check() only checks if (lstate->crtc) and does not check old_lstate->crtc. If win->left_win is disabled on an active splice CRTC in the same commit that win is enabled on another CRTC, vop2_crtc_atomic_begin() on the other CRTC can migrate win's RK3568_OVL_PORT_SEL before win->left_win is disabled, and vop2_plane_atomic_disable(win->left_win) will race with vop2_plane_atomic_update(win) on the shared hardware window.
[ ... ]
Quoted 9 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +1
-0@@ -2018,6 +2432,7 @@ static void vop2_crtc_atomic_flush(struct drm_crtc *crtc,struct drm_crtc_state *old_crtc_state =drm_atomic_get_old_crtc_state (state, crtc);struct vop2_video_port *vp =to_vop2_video_port (crtc);struct vop2 *vop2 = vp->vop2; +bool splice = false;/* In case of modeset, gamma lut update already happened in atomic enable */ if (!drm_atomic_crtc_needs_modeset (crtc_state) && crtc_state->color_mgmt_changed)
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c static void vop2_crtc_atomic_flush(struct drm_crtc *crtc, · line 2448
Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +6
-1@@ -2025,7 +2440,12 @@ static void vop2_crtc_atomic_flush(struct drm_crtc *crtc,vop2_post_config (crtc, false, crtc_state, old_crtc_state); -vop2_cfg_done (vp); +/* When the splice_mode state changes, an update is also required */ +if (to_rockchip_crtc_state (crtc_state)->splice_mode || +to_rockchip_crtc_state (old_crtc_state)->splice_mode) + splice = true; + +vop2_cfg_done (vp, splice);
[Severity: High]
What happens to RK3568_REG_CFG_DONE when disabling a spliced CRTC or modesetting it from an 8K splice mode to a non-splice mode?
In vop2_crtc_atomic_disable() in drivers/gpu/drm/rockchip/rockchip_drm_vop2.c, when old_vcstate->splice_mode is true, the function disables the right windows via vop2_win_disable(win), disables the left windows via drm_atomic_helper_disable_planes_on_crtc(old_crtc_state, false), and clears RK3568_LUT_PORT_SEL__SPLICE_EN via vop2->ops->setup_splice(vp, false) before writing RK3568_VP_DSP_CTRL__STANDBY, without calling vop2_cfg_done().
If the CRTC is being disabled (crtc_state->active == false), drm_atomic_helper_commit_planes() is called with DRM_PLANE_COMMIT_ACTIVE_ONLY, so vop2_crtc_atomic_flush() is skipped and vop2_cfg_done() is never called to latch the disabled windows.
Conversely, if the CRTC is modesetting from an 8K splice mode (old_crtc_state->splice_mode == true) to a non-splice mode (crtc_state->splice_mode == false, crtc_state->active == true), vop2_crtc_atomic_disable() has already cleared RK3568_LUT_PORT_SEL__SPLICE_EN and splice_vp (VP1) remains in standby with no running dclk or vsync. When vop2_crtc_atomic_flush() then sets splice = true because to_rockchip_crtc_state(old_crtc_state)->splice_mode is true, vop2_cfg_done(vp, true) sets BIT(splice_vp_id) in RK3568_REG_CFG_DONE. Because SPLICE_EN is already 0 and splice_vp is in standby, BIT(splice_vp_id) in RK3568_REG_CFG_DONE will never clear, causing subsequent layer updates in rk3568_vop2_setup_layer_mixer() to see cfg_done & ~own_cfg_done_mask != 0 and busy-wait for 50 ms until timeout in rk3568_vop2_wait_for_layer_cfg_done().
[ ... ]
Quoted 23 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +9
-1@@ -2510,6 +2930,7 @@ static int vop2_create_crtcs(struct vop2 *vop2)struct device_node *port;struct vop2_video_port *vp;struct vop2_win *win; +bool vp_used[ROCKCHIP_MAX_CRTC ] = {};u32 possible_crtcs;int i, j, nvp, nvps =0 ;int ret;@@ -2543,9 +2964,23 @@ static int vop2_create_crtcs(struct vop2 *vop2)return dev_err_probe (drm->dev, -ENOENT ,"no port node found for video_port%d\n" , i); vp->crtc.port = port; - nvps++; + vp_used[i] = true; } +/* reserved vp for 8K mode */ +for (i =0 ; i < vop2_data->nr_vps; i++) { +if (!(vop2_data->feature &VOP2_FEATURE_SPLICE ) || !vp_used[i]) +continue ; +if (vop2->vps[i].data->max_output.width <=VOP2_MAX_VP_OUTPUT_WIDTH ) +continue ; +
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c static int vop2_create_crtcs(struct vop2 *vop2) · line 2986
Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +7
-0+ vp_used[vop2->vps[i].data->splice_vp_id] = true; + } + +for (i =0 ; i < vop2_data->nr_vps; i++) +if (vp_used[i]) + nvps++; + nvp =0 ;/* Register a primary plane for every crtc */ for (i =0 ; i < vop2_data->nr_vps; i++) {
[Severity: High]
In vop2_create_crtcs() in drivers/gpu/drm/rockchip/rockchip_drm_vop2.c, what happens on RK3588 boards where VP0 and VP2 (or VP3) are enabled in device tree while VP1 is unconnected?
The loop above marks vp_used[1] = true for VP1 (splice_vp_id = 1), but vp1->crtc.port remains NULL when VP1 has no DT remote node. In the primary plane registration loop immediately following:
for (i = 0; i < vop2_data->nr_vps; i++) {
vp = &vop2->vps[i];
if (!vp->crtc.port)
continue;
for (j = 0; j < vop2->registered_num_wins; j++) {
win = &vop2->win[j];VP0 (i = 0) gets Cluster0-win0 as its primary plane, VP1 (i = 1) is skipped because !vp->crtc.port, and then VP2 (i = 2) or VP3 (i = 3) is assigned the next unregistered DRM_PLANE_TYPE_PRIMARY window, which is Cluster1-win0 (Cluster0-win0's splice_win), with possible_crtcs restricted exclusively to that CRTC, while Cluster2-win0 becomes an overlay plane.
Because Cluster1-win0 is the right splice partner of VP0's primary plane Cluster0-win0, won't this make 8K splice mode on VP0 and normal display output on VP2/VP3 mutually exclusive (-EBUSY) on boards with unconnected VP1?
[ ... ]
Quoted 4 lines
drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +0
-0
[ ... ]
Quoted 24 lines
drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +3
-3@@ -2286,7 +2331,7 @@ static void rk3568_vop2_setup_layer_mixer(struct vop2_video_port *vp)if (layer_sel != vop2->old_layer_sel && atv_layer_sel != vop2->old_layer_sel) { cfg_done =vop2_readl (vop2,RK3568_REG_CFG_DONE ); cfg_done &= (BIT (vop2->data->nr_vps) -1 ); - cfg_done &= ~BIT (vp->id); + cfg_done &= ~own_cfg_done_mask;/* * Changes of other VPs' overlays have not taken effect */ @@ -2295,13 +2340,13 @@ static void rk3568_vop2_setup_layer_mixer(struct vop2_video_port *vp) }if (layer_sel != vop2->old_layer_sel || port_sel != vop2->old_port_sel) - ovl_ctrl |=FIELD_PREP (RK3568_OVL_CTRL__LAYERSEL_REGDONE_SEL , vp->id); + ovl_ctrl |=FIELD_PREP (RK3568_OVL_CTRL__LAYERSEL_REGDONE_SEL , main_vp->id);vop2_writel (vop2,RK3568_OVL_CTRL , ovl_ctrl);if (port_sel != vop2->old_port_sel) { vop2->old_port_sel = port_sel;vop2_writel (vop2,RK3568_OVL_PORT_SEL , port_sel); -vop2_cfg_done (vp); +vop2_cfg_done (main_vp, vcstate->splice_mode);rk3568_vop2_wait_for_port_mux_done (vop2); }
[ ... ]
Quoted 1 line
drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +0
-0@@ -2354,33 +2399,59 @@ static void rk3568_vop2_setup_dly_for_windows(struct vop2_video_port *vp)
[ ... ]
Quoted 15 lines
drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +15
-0+static void rk3568_vop2_setup_overlay (struct vop2_video_port *vp) +{ +struct rockchip_crtc_state *vcstate =to_rockchip_crtc_state (vp->crtc.state); +struct vop2_video_port *splice_vp =NULL ; +struct drm_plane *plane; + + vp->win_mask =0 ; +if (vcstate->splice_mode) { + splice_vp =vop2_get_splice_vp (vp); + splice_vp->win_mask =0 ; + } + +/* The right video port shares the plane state of the left one */ +drm_atomic_crtc_for_each_plane (plane, &vp->crtc) { +struct vop2_win *win =to_vop2_win (plane);
drivers/gpu/drm/rockchip/rockchip_vop2_reg.c static void rk3568_vop2_setup_dly_for_windows(struct vop2_video_port *vp) · line 2453
Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_vop2_reg.c +10
-0+ + vp->win_mask |=BIT (win->data->phys_id); +if (splice_vp && win->splice_win) + splice_vp->win_mask |=BIT (win->splice_win->data->phys_id); + } + +rk3568_vop2_setup_overlay_for_vp (vp); +if (splice_vp) +rk3568_vop2_setup_overlay_for_vp (splice_vp); +}
[Severity: High]
Does calling rk3568_vop2_setup_overlay_for_vp(vp) followed immediately by rk3568_vop2_setup_overlay_for_vp(splice_vp) in rk3568_vop2_setup_overlay() in drivers/gpu/drm/rockchip/rockchip_vop2_reg.c cause a 50 ms busy-wait timeout in rk3568_vop2_setup_layer_mixer()?
During vop2_crtc_atomic_begin(), the first call to rk3568_vop2_setup_layer_mixer(vp) updates vop2->old_layer_sel = layer_sel and writes the shadowed register RK3568_OVL_LAYER_SEL. Because vop2_cfg_done() is not called until vop2_crtc_atomic_flush(), reading RK3568_OVL_LAYER_SEL still returns the pre-commit active hardware value.
In the immediate second call to rk3568_vop2_setup_layer_mixer(splice_vp):
1. atv_layer_sel = vop2_readl(vop2, RK3568_OVL_LAYER_SEL) still equals the old hardware value, so atv_layer_sel != vop2->old_layer_sel is true, and layer_sel != vop2->old_layer_sel is also true when splice_vp updates its right-half layers. If any other video port (such as VP2 or VP3) has a pending CFG_DONE bit in RK3568_REG_CFG_DONE, rk3568_vop2_setup_layer_mixer(splice_vp) calls rk3568_vop2_wait_for_layer_cfg_done(vop2), which busy-polls for vop2_readl(vop2, RK3568_OVL_LAYER_SEL) == vop2->old_layer_sel. Because RK3568_OVL_CTRL__LAYERSEL_REGDONE_SEL was set to main_vp->id by the first call and vop2_cfg_done(main_vp, ...) has not been called yet, vop2->old_layer_sel cannot latch during vop2_crtc_atomic_begin(), guaranteeing a 50 ms spin timeout.
2. If port_sel != vop2->old_port_sel in the second call rk3568_vop2_setup_layer_mixer(splice_vp), it calls vop2_cfg_done(main_vp, vcstate->splice_mode) and waits for vsync in rk3568_vop2_wait_for_port_mux_done(vop2), which latches the first call's left-half RK3568_OVL_LAYER_SEL a frame early before splice_vp's RK3568_OVL_LAYER_SEL and window registers have been programmed.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
kernel test robot
build botRe: [PATCH v2 1/3] drm/rockchip: vop2: Use drm_format_info_min_pitch() for plane offsets
In reply to Chaoyi Chenkernel test robot noticed the following build errors:
Hi Chaoyi,
kernel test robot noticed the following build errors:
[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on rockchip/for-next linus/master v7.3 next-20261029]
[cannot apply to linux-review/Chaoyi-Chen/drm-rockchip-vop2-Use-drm_format_info_min_pitch-for-plane-offsets/20261022-151735] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Chaoyi-Chen/drm-rockchip-vop2-Use-drm_format_info_min_pitch-for-plane-offsets/20261029-161427 base: https://gitlab.freedesktop.org/drm/misc/kernel.git drm-misc-next patch link: https://lore.kernel.org/r/20261029081429.862-2-kernel%40airkyi.com patch subject: [PATCH v2 1/3] drm/rockchip: vop2: Use drm_format_info_min_pitch() for plane offsets config: hexagon-randconfig-1001-20261030 (https://download.01.org/0day-ci/archive/20261030/[email protected]/config) compiler: clang version 24.0.0git (https://github.com/llvm/llvm-project c2ea4440d4b64c148de4fdfca1fc2c437a0701e4) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261030/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>, old ones prefixed by <<):
>> ERROR: modpost: drivers/gpu/drm/rockchip/rockchipdrm.ko: symbol '__hexagon_udivdi3' undefined!
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v2 1/3] drm/rockchip: vop2: Use drm_format_info_min_pitch() for plane offsets
In reply to Chaoyi Chenkernel test robot noticed the following build errors:
Hi Chaoyi,
kernel test robot noticed the following build errors:
[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on rockchip/for-next linus/master v7.3 next-20261029]
[cannot apply to linux-review/Chaoyi-Chen/drm-rockchip-vop2-Use-drm_format_info_min_pitch-for-plane-offsets/20261022-151735] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Chaoyi-Chen/drm-rockchip-vop2-Use-drm_format_info_min_pitch-for-plane-offsets/20261029-161427 base: https://gitlab.freedesktop.org/drm/misc/kernel.git drm-misc-next patch link: https://lore.kernel.org/r/20261029081429.862-2-kernel%40airkyi.com patch subject: [PATCH v2 1/3] drm/rockchip: vop2: Use drm_format_info_min_pitch() for plane offsets config: nios2-allmodconfig (https://download.01.org/0day-ci/archive/20261031/[email protected]/config) compiler: nios2-linux-gcc (GCC) 11.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261031/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>, old ones prefixed by <<):
>> ERROR: modpost: drivers/gpu/drm/rockchip/rockchipdrm.ko: symbol '__udivdi3' undefined!
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki