Thank you for your contribution! Sashiko AI review found 4 potential issues to consider: - [High] drm/rockchip: vop2: vop2_plane_atomic_check() skips splice check if invisible - [High] drm/rockchip: vop2: vop2_plane_atomic_update() leaks enabled splice_win - [Medium] drm/rockchip: vop2: vop2_plane_left_in_splice() ignores old plane/CRTC state - [Medium] drm/rockchip: vop2: unaligned Esmart downscale and NV15/20/30 split rects --
commit d894ca3d47163eb563dfd331fbbaf4120ecda639 Author: Chaoyi Chen <[email protected]> drm/rockchip: vop2: Support 8K output by splicing two video ports This commit adds splice mode support to the VOP2 driver so that modes wider than 4096 pixels on RK3588 are split horizontally across two video ports and paired hardware windows. > diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c > b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c > index e811709bdc725..c8bf397da7059 100644 > --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c > +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop2.c [ ... ] > @@ -1064,6 +1092,244 @@ static void vop2_crtc_atomic_disable(struct drm_crtc > *crtc, > } > } > > +static bool vop2_vp_uses_splice(struct vop2_video_port *vp, > + struct drm_crtc_state *cstate) > +{ > + if (!(vp->vop2->data->feature & VOP2_FEATURE_SPLICE)) > + return false; > + > + return cstate->adjusted_mode.hdisplay > VOP2_MAX_VP_OUTPUT_WIDTH; > +} > + > +static struct vop2_video_port * > +vop2_find_left_splice_vp(struct vop2 *vop2, int right_vp_id) > +{ > + const struct vop2_data *vop2_data = vop2->data; > + int i; > + > + if (!(vop2_data->feature & VOP2_FEATURE_SPLICE)) > + return NULL; > + > + for (i = 0; i < vop2_data->nr_vps; i++) { > + const struct vop2_video_port_data *vp_data = &vop2_data->vp[i]; > + > + if (vp_data->max_output.width <= VOP2_MAX_VP_OUTPUT_WIDTH) > + continue; > + > + if (vp_data->splice_vp_id == right_vp_id) > + return &vop2->vps[i]; > + } > + > + return NULL; > +} > + > +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 > + * 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() produce odd-width source rectangles when downscaling RGB planes on Esmart windows, or misaligned DMA start addresses for NV15, NV20 and NV30? vop2_plane_atomic_check() rejects odd src_w when downscaling on Esmart windows, but only checks the unsplit src_w. Because left_src_w &= ~0x1 is only applied when fb->format->is_yuv, an even RGB source width split across two Esmart windows can still give both halves odd widths. Also, for NV15, NV20 and NV30 (where 8 luma pixels pack into 10 bytes), masking left_src_w with ~0x7 only aligns right_src->x1 = src->x1 + (left_src_w << 16) when src->x1 >> 16 is already a multiple of 8, whereas vop2_plane_atomic_check() only enforces src_x % 2 == 0. A src_x of 2, 4 or 6 leaves both windows' yrgb_mst and uv_mst unaligned. [ ... ] > +static int vop2_plane_left_in_splice(struct drm_plane *plane, > + struct drm_atomic_commit *state) > +{ > + struct vop2_win *win = to_vop2_win(plane); > + struct drm_plane_state *lstate; > + struct drm_crtc_state *lcstate; > + struct drm_crtc *lcrtc; > + int ret; > + > + if (!win->left_win) > + return 0; > + > + lstate = drm_atomic_get_new_plane_state(state, &win->left_win->base); > + if (!lstate) { > + ret = drm_modeset_lock(&win->left_win->base.mutex, > + state->acquire_ctx); > + if (ret && ret != -EALREADY) > + return ret; > + > + lstate = win->left_win->base.state; > + } > + > + if (!lstate || !lstate->crtc) > + return 0; > + > + lcrtc = lstate->crtc; > + > + lcstate = drm_atomic_get_new_crtc_state(state, lcrtc); > + if (!lcstate) { > + ret = drm_modeset_lock(&lcrtc->mutex, state->acquire_ctx); > + if (ret && ret != -EALREADY) > + return ret; > + > + lcstate = lcrtc->state; > + } > + > + if (!lcstate || !lcstate->enable) > + return 0; > + > + return vop2_vp_uses_splice(to_vop2_video_port(lcrtc), lcstate); > +} [Severity: Medium] Does vop2_plane_left_in_splice() miss the case where win->left_win was active in splice mode in the old state and is being disabled or detached in the same commit that enables win on another CRTC? Unlike vop2_crtc_atomic_check(), which checks both rstate->crtc and old_rstate->crtc when entering splice mode, vop2_plane_left_in_splice() only checks the new plane and CRTC states. If a single commit detaches win->left_win from the spliced CRTC and enables win on another CRTC, the second CRTC's atomic_begin() runs before vop2_plane_atomic_disable(), so rk3568_vop2_setup_layer_mixer() overwrites RK3568_OVL_CTRL__LAYERSEL_REGDONE_SEL and migrates win's port mux in RK3568_OVL_PORT_SEL while win is still enabled with the spliced CRTC's buffer. [ ... ] > @@ -1122,15 +1389,33 @@ 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) { > + ret = vop2_plane_left_in_splice(plane, astate); > + if (ret < 0) > + return ret; > + if (ret) { > + 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] Can an off-screen plane bypass vop2_plane_left_in_splice() and vop2_plane_splice_check()? vop2_plane_atomic_check() returns 0 when !pstate->visible before reaching these checks, even though pstate->crtc is set and the plane remains in cstate->plane_mask. If a right-half splice window is attached to another CRTC at off-screen coordinates while splice mode is active, rk3568_vop2_setup_overlay() still iterates over crtc->state->plane_mask and reassigns the window's port and layer muxing in RK3568_OVL_PORT_SEL and RK3568_OVL_LAYER_SEL, and vop2_plane_atomic_update() then calls vop2_plane_atomic_disable(), turning off the active right-half window. [ ... ] > @@ -1487,6 +1780,45 @@ static void vop2_plane_atomic_update(struct drm_plane > *plane, > } > } > > +static void vop2_plane_atomic_update(struct drm_plane *plane, > + struct drm_atomic_commit *state) > +{ > + struct drm_plane_state *pstate = plane->state; > + struct drm_crtc *crtc = pstate->crtc; > + struct vop2_win *win = to_vop2_win(plane); > + struct drm_crtc_state *cstate; > + struct rockchip_crtc_state *vcstate; > + struct drm_rect left_src, left_dst, right_src, right_dst; > + > + if (WARN_ON(!crtc)) > + return; > + > + if (!pstate->visible) { > + vop2_plane_atomic_disable(plane, state); > + return; > + } > + > + cstate = drm_atomic_get_new_crtc_state(state, crtc); > + if (!cstate) > + cstate = crtc->state; > + vcstate = to_rockchip_crtc_state(cstate); > + > + if (!vcstate->splice_mode) { > + vop2_win_atomic_update(win, &pstate->src, &pstate->dst, pstate); > + return; > + } [Severity: High] Does vop2_plane_atomic_update() leave win->splice_win enabled when a visible plane moves from a spliced CRTC to a non-spliced CRTC, or when its CRTC switches out of splice mode? When the plane stays visible across the commit, vop2_plane_atomic_disable() is not called. vop2_plane_atomic_update() sees !vcstate->splice_mode on the new CRTC state, updates only win, and returns without disabling win->splice_win, leaving the right-half window enabled and scanning out the old framebuffer DMA address after the old framebuffer is unreferenced and freed. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=3
