Skip to contentSkip to conversation

drm/rockchip: vop2: Give each RK3588 video port its own cluster

PATCH New Arun Iyengar 1 participant 3 messages Dec 1

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover drm/rockchip: vop2: Give each RK3588 video port its own cluster

Tested on Orange Pi 5, HDMI 4K120 + DP 4K60, v7.3 plus local HDMI FRL and 750 MHz aclk_vop (not in mainline): 7207 bad frames in 60 s before, 0 after. With KASAN, an injected vop2_create_crtcs() failure binds on retry without a splat (the use-after-free itself was not reproduced), and with VP0 + VP2 Cluster1 defaults above VP2's primary.

This does not enforce the TRM rule Chaoyi Chen quoted (one video port's layers on one AXI port); overlay planes are unchanged.
Applies with Chaoyi Chen's 8K series [1]: VP0 keeps Cluster0 and Cluster1.

[1] https://lore.kernel.org/all/[email protected]/

Developed with Claude (Anthropic), which wrote the code and the commit messages. I reviewed every change.

---
Changes in v2:
- New patch 1: clean up after a failed vop2_create_crtcs() (Sashiko).
- Patch 2: primary planes get the lowest default zpos (Sashiko).
- Patch 2: commit message states overlays and VP0+VP1 boards are
unchanged (Sashiko).
- Patch 2: drop the Fixes tag; mainline cannot reach this load.
- Link to v1: https://patch.msgid.link/[email protected]

---
Arun Iyengar (2):
drm/rockchip: vop2: Clean up after a failed vop2_create_crtcs() drm/rockchip: vop2: Give each RK3588 video port its own cluster

 drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 43 +++++++++++++++++++---------
 1 file changed, 30 insertions(+), 13 deletions(-)

---
base-commit: c408466a4dfaee4b12587e926c5b85e68c8b3c40
change-id: 20261121-vop2-axi-primary-971fcba0d98e

Best regards,

Signature · 1 line
Arun Iyengar <[email protected]>
#1 lore raw

PATCH v2 1/2 drm/rockchip: vop2: Clean up after a failed vop2_create_crtcs()

vop2_create_crtcs() returns errors without dropping the port nodes or the planes and CRTCs it registered. component_bind() then frees struct vop2 and rockchip_drm_bind() unwinds through drm_mode_config_cleanup() on the freed planes and CRTCs. The RK3576 interrupt setup after it does the same.

Call vop2_destroy_crtcs() on these errors and drop every port node there, not only those of initialised CRTCs.

Fixes 604be85547ce ("drm/rockchip: Add VOP2 driver")
---
 drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 24 +++++++++++++++---------
 1 file changed, 15 insertions(+), 9 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +15 -9
index 76d151b8bc52b..bbe86aecf9039 100644
@@ -2757,18 +2757,20 @@ static void vop2_destroy_crtcs(struct vop2 *vop2)
 	struct list_head *plane_list = &drm->mode_config.plane_list;
 	struct drm_crtc *crtc, *tmpc;
 	struct drm_plane *plane, *tmpp;
+	int i;
 
 	list_for_each_entry_safe(plane, tmpp, plane_list, head)
 		drm_plane_cleanup(plane);
 
+	for (i = 0; i < vop2->data->nr_vps; i++)
+		of_node_put(vop2->vps[i].crtc.port);
+
 	/*
 	 * Destroy CRTC after vop2_plane_destroy() since vop2_disable_plane()
 	 * references the CRTC.
 	 */
-	list_for_each_entry_safe(crtc, tmpc, crtc_list, head) {
-		of_node_put(crtc->port);
+	list_for_each_entry_safe(crtc, tmpc, crtc_list, head)
 		drm_crtc_cleanup(crtc);
-	}
 }
 
 static int vop2_find_rgb_encoder(struct vop2 *vop2)
@@ -3000,7 +3002,7 @@ static int vop2_bind(struct device *dev, struct device *master, void *data)
 
 	ret = vop2_create_crtcs(vop2);
 	if (ret)
-		return ret;
+		goto err_crtcs;
 
 	if (vop2->version >= VOP_VERSION_RK3576) {
 		struct drm_crtc *crtc;
@@ -3010,13 +3012,17 @@ static int vop2_bind(struct device *dev, struct device *master, void *data)
 			int vp_irq;
 			const char *irq_name = devm_kasprintf(dev, GFP_KERNEL, "vp%d", vp->id);
 
-			if (!irq_name)
-				return -ENOMEM;
+			if (!irq_name) {
+				ret = -ENOMEM;
+				goto err_crtcs;
+			}
 
 			vp_irq = platform_get_irq_byname(pdev, irq_name);
-			if (vp_irq < 0)
-				return dev_err_probe(drm->dev, vp_irq,
-						     "cannot find irq for vop2 vp%d\n", vp->id);
+			if (vp_irq < 0) {
+				ret = dev_err_probe(drm->dev, vp_irq,
+						    "cannot find irq for vop2 vp%d\n", vp->id);
+				goto err_crtcs;
+			}
 
 			ret = devm_request_irq(dev, vp_irq, rk3576_vp_isr, IRQF_SHARED, irq_name,
 					       vp);
Signature · 1 line
2.55.0
#2 lore raw

PATCH v2 2/2 drm/rockchip: vop2: Give each RK3588 video port its own cluster

In reply to Arun Iyengar

Damon Ding asked for POST_BUF_EMPTY to be fixed in the layer setup. On RK3588 Cluster0/1 fetch through AXI0 and Cluster2/3 through AXI1. Each video port takes the first free primary window, so VP0 and VP2 get Cluster0 and Cluster1, both on AXI0. A 4K120 and a 4K60 XR24 primary need about 6 GB/s there, one port delivers about 4.5 GB/s, and VP0 underflows in every frame. aclk_vop at 750 or 850 MHz is the same.

On RK3588 give VP N Cluster N as primary plane. Boards that skip a lower video port get a different primary: without VP1, VP2 gets Cluster2 instead of Cluster1. VP0 and VP1 still share AXI0, and overlay planes can still go on any video port. RK3568 and RK3576 are unchanged.

A skipped cluster would default below VP2's primary, so give primary planes the lowest default zpos.

---
 drivers/gpu/drm/rockchip/rockchip_drm_vop2.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_vop2.c +15 -4
index bbe86aecf9039..4d054c41baca1 100644
@@ -2526,7 +2526,7 @@ static irqreturn_t vop2_isr(int irq, void *data)
 }
 
 static int vop2_plane_init(struct vop2 *vop2, struct vop2_win *win,
-			   unsigned long possible_crtcs)
+			   unsigned long possible_crtcs, unsigned int zpos)
 {
 	const struct vop2_win_data *win_data = win->data;
 	unsigned int blend_caps = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
@@ -2552,7 +2552,7 @@ static int vop2_plane_init(struct vop2 *vop2, struct vop2_win *win,
 						   win->data->supported_rotations);
 	drm_plane_create_alpha_property(&win->base);
 	drm_plane_create_blend_mode_property(&win->base, blend_caps);
-	drm_plane_create_zpos_property(&win->base, win->win_id, 0,
+	drm_plane_create_zpos_property(&win->base, zpos, 0,
 				       vop2->registered_num_wins - 1);
 
 	return 0;
@@ -2583,6 +2583,11 @@ static bool vop2_is_mirror_win(struct vop2_win *win)
 	}
 }
 
+static const u8 rk3588_vp_primary[] = {
+	ROCKCHIP_VOP2_CLUSTER0, ROCKCHIP_VOP2_CLUSTER1,
+	ROCKCHIP_VOP2_CLUSTER2, ROCKCHIP_VOP2_CLUSTER3,
+};
+
 static int vop2_create_crtcs(struct vop2 *vop2)
 {
 	const struct vop2_data *vop2_data = vop2->data;
@@ -2594,6 +2599,7 @@ static int vop2_create_crtcs(struct vop2 *vop2)
 	struct vop2_win *win;
 	u32 possible_crtcs;
 	int i, j, nvp, nvps = 0;
+	unsigned int zpos;
 	int ret;
 
 	for (i = 0; i < vop2_data->nr_vps; i++) {
@@ -2655,13 +2661,17 @@ static int vop2_create_crtcs(struct vop2 *vop2)
 			if (!(win->data->possible_vp_mask & BIT(vp->id)))
 				continue;
 
+			if (vop2->version == VOP_VERSION_RK3588 &&
+			    win->data->phys_id != rk3588_vp_primary[vp->id])
+				continue;
+
 			if (vop2_is_mirror_win(win))
 				continue;
 
 			if (win->type == DRM_PLANE_TYPE_PRIMARY) {
 				possible_crtcs = BIT(nvp);
 				vp->primary_plane = win;
-				ret = vop2_plane_init(vop2, win, possible_crtcs);
+				ret = vop2_plane_init(vop2, win, possible_crtcs, nvp);
 				if (ret)
 					return dev_err_probe(drm->dev, ret,
 							     "failed to init primary plane %s\n",
@@ -2677,6 +2687,7 @@ static int vop2_create_crtcs(struct vop2 *vop2)
 	}
 
 	/* Register all unused window as overlay plane */
+	zpos = nvp;
 	for (i = 0; i < vop2->registered_num_wins; i++) {
 		win = &vop2->win[i];
 
@@ -2702,7 +2713,7 @@ static int vop2_create_crtcs(struct vop2 *vop2)
 			nvp++;
 		}
 
-		ret = vop2_plane_init(vop2, win, possible_crtcs);
+		ret = vop2_plane_init(vop2, win, possible_crtcs, zpos++);
 		if (ret)
 			return dev_err_probe(drm->dev, ret, "failed to init overlay plane %s\n",
 					     win->data->name);
Signature · 1 line
2.55.0