From 44cf209fa5318770f6d53e36d7fb28ce4ef801a8 Mon Sep 17 00:00:00 2001
From: Dave Stevenson <dave.stevenson@raspberrypi.com>
Date: Thu, 30 Mar 2023 17:18:36 +0100
Subject: [PATCH 0577/1085] drm/vc4: Fix FKMS for when the YUV chroma planes
 are different buffers

The code was assuming that it was a single buffer with offsets,
when kmstest uses separate buffers and 0 offsets for each plane.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
---
 drivers/gpu/drm/vc4/vc4_firmware_kms.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

--- a/drivers/gpu/drm/vc4/vc4_firmware_kms.c
+++ b/drivers/gpu/drm/vc4/vc4_firmware_kms.c
@@ -526,7 +526,7 @@ static int vc4_plane_to_mb(struct drm_pl
 			   struct drm_plane_state *state)
 {
 	struct drm_framebuffer *fb = state->fb;
-	struct drm_gem_dma_object *bo = drm_fb_dma_get_gem_obj(fb, 0);
+	struct drm_gem_dma_object *bo;
 	const struct drm_format_info *drm_fmt = fb->format;
 	const struct vc_image_format *vc_fmt =
 					vc4_get_vc_image_fmt(drm_fmt->format);
@@ -550,6 +550,7 @@ static int vc4_plane_to_mb(struct drm_pl
 					state->normalized_zpos : -127;
 	mb->plane.num_planes = num_planes;
 	mb->plane.is_vu = vc_fmt->is_vu;
+	bo = drm_fb_dma_get_gem_obj(fb, 0);
 	mb->plane.planes[0] = bo->dma_addr + fb->offsets[0];
 
 	rotation = drm_rotation_simplify(state->rotation,
@@ -570,11 +571,14 @@ static int vc4_plane_to_mb(struct drm_pl
 		/* Makes assumptions on the stride for the chroma planes as we
 		 * can't easily plumb in non-standard pitches.
 		 */
+		bo = drm_fb_dma_get_gem_obj(fb, 1);
 		mb->plane.planes[1] = bo->dma_addr + fb->offsets[1];
-		if (num_planes > 2)
+		if (num_planes > 2) {
+			bo = drm_fb_dma_get_gem_obj(fb, 2);
 			mb->plane.planes[2] = bo->dma_addr + fb->offsets[2];
-		else
+		} else {
 			mb->plane.planes[2] = 0;
+		}
 
 		/* Special case the YUV420 with U and V as line interleaved
 		 * planes as we have special handling for that case.