[PATCH 15/22] drm/i915/intel_fb: Factor out calc_plane_normal_size()

Imre Deak imre.deak at intel.com
Wed Mar 10 10:07:40 UTC 2021


Signed-off-by: Imre Deak <imre.deak at intel.com>
---
 drivers/gpu/drm/i915/display/intel_fb.c | 82 ++++++++++++++++++-------
 1 file changed, 61 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/i915/display/intel_fb.c b/drivers/gpu/drm/i915/display/intel_fb.c
index 62a8e37dca38..b54c36e7199f 100644
--- a/drivers/gpu/drm/i915/display/intel_fb.c
+++ b/drivers/gpu/drm/i915/display/intel_fb.c
@@ -520,6 +520,37 @@ static bool intel_plane_needs_remap(const struct intel_plane_state *plane_state)
 	return stride > max_stride;
 }
 
+struct fb_plane_view_dims {
+	unsigned int width, height;
+	unsigned int tile_width, tile_height;
+};
+
+static void init_plane_view_dims(const struct intel_framebuffer *fb, int color_plane,
+				 unsigned int width, unsigned int height,
+				 struct fb_plane_view_dims *dims)
+{
+	dims->width = width;
+	dims->height = height;
+
+	intel_tile_dims(&fb->base, color_plane, &dims->tile_width, &dims->tile_height);
+}
+
+static unsigned int plane_view_pitch_tiles(const struct intel_framebuffer *fb, int color_plane,
+					   const struct fb_plane_view_dims *dims)
+{
+	const struct drm_framebuffer *drm_fb = &fb->base;
+
+	return DIV_ROUND_UP(drm_fb->pitches[color_plane],
+			    dims->tile_width * drm_fb->format->cpp[color_plane]);
+}
+
+static unsigned int plane_view_tile_rows(const struct intel_framebuffer *fb, int color_plane,
+					 const struct fb_plane_view_dims *dims,
+					 int y)
+{
+	return DIV_ROUND_UP(y + dims->height, dims->tile_height);
+}
+
 static int convert_plane_offset_to_xy(const struct intel_framebuffer *fb, int color_plane,
 				      int plane_width, int *x, int *y)
 {
@@ -634,6 +665,28 @@ static u32 setup_fb_rotation(int plane, const struct intel_remapped_plane_info *
 	return plane_info->width * plane_info->height;
 }
 
+static int calc_plane_normal_size(const struct intel_framebuffer *fb, int color_plane,
+				  const struct fb_plane_view_dims *dims,
+				  int x, int y)
+{
+	const struct drm_framebuffer *drm_fb = &fb->base;
+	struct drm_i915_private *i915 = to_i915(drm_fb->dev);
+	int pages;
+
+	if (is_surface_linear(drm_fb, color_plane)) {
+		unsigned int size;
+
+		size = (y + dims->height) * drm_fb->pitches[color_plane] +
+		       x * drm_fb->format->cpp[color_plane];
+		pages = DIV_ROUND_UP(size, intel_tile_size(i915));
+	} else {
+		pages = plane_view_pitch_tiles(fb, color_plane, dims) *
+			plane_view_tile_rows(fb, color_plane, dims, y);
+	}
+
+	return pages;
+}
+
 int intel_fill_fb_info(struct drm_i915_private *i915, struct drm_framebuffer *fb)
 {
 	struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb);
@@ -644,6 +697,7 @@ int intel_fill_fb_info(struct drm_i915_private *i915, struct drm_framebuffer *fb
 	unsigned int tile_size = intel_tile_size(i915);
 
 	for (i = 0; i < num_planes; i++) {
+		struct fb_plane_view_dims view_dims;
 		unsigned int width, height;
 		unsigned int cpp, size;
 		u32 offset;
@@ -669,6 +723,8 @@ int intel_fill_fb_info(struct drm_i915_private *i915, struct drm_framebuffer *fb
 		if (ret)
 			return ret;
 
+		init_plane_view_dims(intel_fb, i, width, height, &view_dims);
+
 		/*
 		 * First pixel of the framebuffer from
 		 * the start of the normal gtt mapping.
@@ -680,38 +736,22 @@ int intel_fill_fb_info(struct drm_i915_private *i915, struct drm_framebuffer *fb
 
 		if (!is_surface_linear(fb, i)) {
 			struct intel_remapped_plane_info plane_info;
-			unsigned int tile_width, tile_height;
-
-			intel_tile_dims(fb, i, &tile_width, &tile_height);
 
 			plane_info.offset = offset;
-			plane_info.stride = DIV_ROUND_UP(fb->pitches[i],
-							 tile_width * cpp);
-			plane_info.width = DIV_ROUND_UP(x + width, tile_width);
-			plane_info.height = DIV_ROUND_UP(y + height,
-							 tile_height);
-
-			/* how many tiles does this plane need */
-			size = plane_info.stride * plane_info.height;
-			/*
-			 * If the plane isn't horizontally tile aligned,
-			 * we need one more tile.
-			 */
-			if (x != 0)
-				size++;
+			plane_info.stride = plane_view_pitch_tiles(intel_fb, i, &view_dims);
+			plane_info.width = DIV_ROUND_UP(x + width, view_dims.tile_width);
+			plane_info.height = plane_view_tile_rows(intel_fb, i, &view_dims, y);
 
 			gtt_offset_rotated +=
 				setup_fb_rotation(i, &plane_info,
 						  gtt_offset_rotated,
 						  x, y, width, height,
 						  tile_size,
-						  tile_width, tile_height,
+						  view_dims.tile_width, view_dims.tile_height,
 						  fb);
-		} else {
-			size = DIV_ROUND_UP((y + height) * fb->pitches[i] +
-					    x * cpp, tile_size);
 		}
 
+		size = calc_plane_normal_size(intel_fb, i, &view_dims, x, y);
 		/* how many tiles in total needed in the bo */
 		max_size = max(max_size, offset + size);
 	}
-- 
2.25.1



More information about the Intel-gfx-trybot mailing list