From 3c1ece5c617be90fc9920a8d732832aeeb9acb5d Mon Sep 17 00:00:00 2001
From: Dave Stevenson <dave.stevenson@raspberrypi.com>
Date: Mon, 16 Oct 2023 12:13:38 +0100
Subject: [PATCH 0675/1085] drm/vc4: Correct address offset for planes with
 src_[xy] offsets

11cf37e741b4 switched to using drm_fb_dma_get_gem_addr instead of
drm_fb_dma_get_gem_obj and adding fb->offset[].

However the tiled formats need to compute the offset in a more
involved manner than drm_fb_dma_get_gem_addr applies, and we
were ending up with the offset for src_[xy] being applied twice.

Switch back to using drm_fb_dma_get_gem_obj and fully computing
the offsets ourselves.

Fixes: 11cf37e741b4 ("drm/vc4: Move the buffer offset out of the vc4_plane_state")
Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
---
 drivers/gpu/drm/vc4/vc4_plane.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

--- a/drivers/gpu/drm/vc4/vc4_plane.c
+++ b/drivers/gpu/drm/vc4/vc4_plane.c
@@ -1473,9 +1473,9 @@ static int vc4_plane_mode_set(struct drm
 	vc4_state->ptr0_offset[0] = vc4_state->dlist_count;
 
 	for (i = 0; i < num_planes; i++) {
-		dma_addr_t paddr = drm_fb_dma_get_gem_addr(fb, state, i);
+		struct drm_gem_dma_object *bo = drm_fb_dma_get_gem_obj(fb, i);
 
-		vc4_dlist_write(vc4_state, paddr + offsets[i]);
+		vc4_dlist_write(vc4_state, bo->dma_addr + fb->offsets[i] + offsets[i]);
 	}
 
 	/* Pointer Context Word 0/1/2: Written by the HVS */
@@ -1868,9 +1868,8 @@ static int vc6_plane_mode_set(struct drm
 	 * TODO: This only covers Raster Scan Order planes
 	 */
 	for (i = 0; i < num_planes; i++) {
-		dma_addr_t paddr = drm_fb_dma_get_gem_addr(fb, state, i);
-
-		paddr += offsets[i];
+		struct drm_gem_dma_object *bo = drm_fb_dma_get_gem_obj(fb, i);
+		dma_addr_t paddr = bo->dma_addr + fb->offsets[i] + offsets[i];
 
 		/* Pointer Word 0 */
 		vc4_state->ptr0_offset[i] = vc4_state->dlist_count;
