Skip to contentSkip to conversation

drm/ast: Move cursor vmap calls out of commit tail

PATCH Superseded Thomas Zimmermann 1 participant 14 messages Jan 27, 2021

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

cover drm/ast: Move cursor vmap calls out of commit tail

Ast has vmap calls in its cursor's atomic_update function. This is not supported as vmap might aquire the dma reservation lock. While at it, cleanup the whole cursor code: the patchset removes all possible runtime errors from the atomic_update function and reduces the overhead from vmap calls on the HW cursor BOs to a minimum.

Patches 1 to 3 update the cursor code and prepare before the refactoring.

Patch 4 and 5 inline the cursor update logic into the rsp cursor-plane functions. This is mostly about moving code around.

Patches 6 to 8 and 12 add a dedicated cursor plane that maintains the two BOs for HW cursors. The HW cursor BOs are permanently pinned and vmapped while the cursor plane is initialized. Thus removing the related vmap operations from atomic_update.

Patches 9 to 11 moves more vmap code out of atomic_update. BOs with cursor image data from userspace are vmapped and vunmapped in prepare_fb and cleanup_fb. Instead the actual update of the cursor image is moved from prepare_fb to atomic_update.

With the patchset applied, all cursor preparation is performed before the commit-tail functions; while the actual update is performed within.

Tested by running X11 and Weston on ast hardware.

Thomas Zimmermann (12):
drm/ast: Add constants for VGACRCB register bits
drm/ast: Fix invalid usage of AST_MAX_HWC_WIDTH in cursor atomic_check drm/ast: Initialize planes in helper functions
drm/ast: Allocate HW cursor BOs during cursor-plane initialization drm/ast: Inline ast cursor-update functions into modesetting code drm/ast: Add cursor-plane data structure
drm/ast: Store cursor BOs in cursor plane
drm/ast: Map HW cursor BOs permanently
drm/ast: Introduce dedicated cursor-plane state
drm/ast: Fix cursor BO pinning and mapping
drm/ast: Move all of the cursor-update functionality to atomic_update drm/ast: Store each HW cursor offset after pinning the rsp BO

 drivers/gpu/drm/ast/Makefile     |   3 +-
 drivers/gpu/drm/ast/ast_cursor.c | 286 ----------------------
 drivers/gpu/drm/ast/ast_drv.h    |  47 ++--
 drivers/gpu/drm/ast/ast_mode.c   | 397 +++++++++++++++++++++++++++----
 4 files changed, 389 insertions(+), 344 deletions(-)
 delete mode 100644 drivers/gpu/drm/ast/ast_cursor.c

base-commit: 3836b7fdfad40e2bac5dc882332f42bed6942cf4
prerequisite-patch-id: c2b2f08f0eccc9f5df0c0da49fa1d36267deb11d --
2.30.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

author maintainer
#1 lore raw

PATCH 1/12 drm/ast: Add constants for VGACRCB register bits

Set the bits in VGACRCB with constants. Alo move the rsp code into a helper function.

---
 drivers/gpu/drm/ast/ast_cursor.c | 21 +++++++++++++++------
 drivers/gpu/drm/ast/ast_drv.h    |  3 +++
 2 files changed, 18 insertions(+), 6 deletions(-)
drivers/gpu/drm/ast/ast_cursor.c +15 -6
index fac1ee79c372..024858371f64 100644
@@ -236,6 +236,19 @@ static void ast_cursor_set_location(struct ast_private *ast, u16 x, u16 y,
 	ast_set_index_reg(ast, AST_IO_CRTC_PORT, 0xc7, y1);
 }
 
+static void ast_set_cursor_enabled(struct ast_private *ast, bool enabled)
+{
+	static const u8 mask = (u8)~(AST_IO_VGACRCB_HWC_16BPP |
+				     AST_IO_VGACRCB_HWC_ENABLED);
+
+	u8 vgacrcb = AST_IO_VGACRCB_HWC_16BPP;
+
+	if (enabled)
+		vgacrcb |= AST_IO_VGACRCB_HWC_ENABLED;
+
+	ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xcb, mask, vgacrcb);
+}
+
 void ast_cursor_show(struct ast_private *ast, int x, int y,
 		     unsigned int offset_x, unsigned int offset_y)
 {
@@ -245,7 +258,6 @@ void ast_cursor_show(struct ast_private *ast, int x, int y,
 	u8 x_offset, y_offset;
 	u8 __iomem *dst;
 	u8 __iomem *sig;
-	u8 jreg;
 	int ret;
 
 	ret = drm_gem_vram_vmap(gbo, &map);
@@ -274,13 +286,10 @@ void ast_cursor_show(struct ast_private *ast, int x, int y,
 
 	ast_cursor_set_location(ast, x, y, x_offset, y_offset);
 
-	/* dummy write to fire HWC */
-	jreg = 0x02 |
-	       0x01; /* enable ARGB4444 cursor */
-	ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xcb, 0xfc, jreg);
+	ast_set_cursor_enabled(ast, true); /* dummy write to fire HWC */
 }
 
 void ast_cursor_hide(struct ast_private *ast)
 {
-	ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xcb, 0xfc, 0x00);
+	ast_set_cursor_enabled(ast, false);
 }
drivers/gpu/drm/ast/ast_drv.h +3 -0
index f871fc36c2f7..1575e8e636d7 100644
@@ -179,6 +179,9 @@ struct ast_private *ast_device_create(const struct drm_driver *drv,
 
 #define AST_IO_VGAIR1_VREFRESH		BIT(3)
 
+#define AST_IO_VGACRCB_HWC_ENABLED     BIT(1)
+#define AST_IO_VGACRCB_HWC_16BPP       BIT(0) /* set: ARGB4444, cleared: 2bpp palette */
+
 #define __ast_read(x) \
 static inline u##x ast_read##x(struct ast_private *ast, u32 reg) { \
 u##x val = 0;\
Signature · 6 lines
2.30.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#2 lore raw

PATCH 2/12 drm/ast: Fix invalid usage of AST_MAX_HWC_WIDTH in cursor atomic_check

In reply to Thomas Zimmermann

Use AST_MAX_HWC_HEIGHT for setting offset_y in the cursor plane's atomic_check. The code used AST_MAX_HWC_WIDTH instead. This worked because both constants has the same value.

---
 drivers/gpu/drm/ast/ast_mode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/ast/ast_mode.c +1 -1
index 988b270fea5e..758c69aa7232 100644
@@ -688,7 +688,7 @@ ast_cursor_plane_helper_atomic_update(struct drm_plane *plane,
 	unsigned int offset_x, offset_y;
 
 	offset_x = AST_MAX_HWC_WIDTH - fb->width;
-	offset_y = AST_MAX_HWC_WIDTH - fb->height;
+	offset_y = AST_MAX_HWC_HEIGHT - fb->height;
 
 	if (state->fb != old_state->fb) {
 		/* A new cursor image was installed. */
Signature · 6 lines
2.30.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#3 lore raw

PATCH 3/12 drm/ast: Initialize planes in helper functions

In reply to Thomas Zimmermann

This change will help with inlining cursor functions into modesetting code. The primary plane's field used to be cleared with memset(). This has been dropped as the memory is always allocated with kzalloc().

---
 drivers/gpu/drm/ast/ast_mode.c | 66 +++++++++++++++++++++++-----------
 1 file changed, 45 insertions(+), 21 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +45 -21
index 758c69aa7232..f86773a869f0 100644
@@ -621,6 +621,26 @@ static const struct drm_plane_funcs ast_primary_plane_funcs = {
 	.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
 };
 
+static int ast_primary_plane_init(struct ast_private *ast)
+{
+	struct drm_device *dev = &ast->base;
+	struct drm_plane *primary_plane = &ast->primary_plane;
+	int ret;
+
+	ret = drm_universal_plane_init(dev, primary_plane, 0x01,
+				       &ast_primary_plane_funcs,
+				       ast_primary_plane_formats,
+				       ARRAY_SIZE(ast_primary_plane_formats),
+				       NULL, DRM_PLANE_TYPE_PRIMARY, NULL);
+	if (ret) {
+		drm_err(dev, "drm_universal_plane_init() failed: %d\n", ret);
+		return ret;
+	}
+	drm_plane_helper_add(primary_plane, &ast_primary_plane_helper_funcs);
+
+	return 0;
+}
+
 /*
  * Cursor plane
  */
@@ -725,6 +745,26 @@ static const struct drm_plane_funcs ast_cursor_plane_funcs = {
 	.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
 };
 
+static int ast_cursor_plane_init(struct ast_private *ast)
+{
+	struct drm_device *dev = &ast->base;
+	struct drm_plane *cursor_plane = &ast->cursor_plane;
+	int ret;
+
+	ret = drm_universal_plane_init(dev, cursor_plane, 0x01,
+				       &ast_cursor_plane_funcs,
+				       ast_cursor_plane_formats,
+				       ARRAY_SIZE(ast_cursor_plane_formats),
+				       NULL, DRM_PLANE_TYPE_CURSOR, NULL);
+	if (ret) {
+		drm_err(dev, "drm_universal_plane_failed(): %d\n", ret);
+		return ret;
+	}
+	drm_plane_helper_add(cursor_plane, &ast_cursor_plane_helper_funcs);
+
+	return 0;
+}
+
 /*
  * CRTC
  */
@@ -1138,30 +1178,14 @@ int ast_mode_config_init(struct ast_private *ast)
 
 	dev->mode_config.helper_private = &ast_mode_config_helper_funcs;
 
-	memset(&ast->primary_plane, 0, sizeof(ast->primary_plane));
-	ret = drm_universal_plane_init(dev, &ast->primary_plane, 0x01,
-				       &ast_primary_plane_funcs,
-				       ast_primary_plane_formats,
-				       ARRAY_SIZE(ast_primary_plane_formats),
-				       NULL, DRM_PLANE_TYPE_PRIMARY, NULL);
-	if (ret) {
-		drm_err(dev, "ast: drm_universal_plane_init() failed: %d\n", ret);
+
+	ret = ast_primary_plane_init(ast);
+	if (ret)
 		return ret;
-	}
-	drm_plane_helper_add(&ast->primary_plane,
-			     &ast_primary_plane_helper_funcs);
 
-	ret = drm_universal_plane_init(dev, &ast->cursor_plane, 0x01,
-				       &ast_cursor_plane_funcs,
-				       ast_cursor_plane_formats,
-				       ARRAY_SIZE(ast_cursor_plane_formats),
-				       NULL, DRM_PLANE_TYPE_CURSOR, NULL);
-	if (ret) {
-		drm_err(dev, "drm_universal_plane_failed(): %d\n", ret);
+	ret = ast_cursor_plane_init(ast);
+	if (ret)
 		return ret;
-	}
-	drm_plane_helper_add(&ast->cursor_plane,
-			     &ast_cursor_plane_helper_funcs);
 
 	ast_crtc_init(dev);
 	ast_encoder_init(dev);
Signature · 6 lines
2.30.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#4 lore raw

PATCH 4/12 drm/ast: Allocate HW cursor BOs during cursor-plane initialization

In reply to Thomas Zimmermann

The BOs are eventually released by the cursor plane's destroy callback.

---
 drivers/gpu/drm/ast/ast_cursor.c | 58 ------------------------------
 drivers/gpu/drm/ast/ast_drv.h    |  1 -
 drivers/gpu/drm/ast/ast_mode.c   | 62 ++++++++++++++++++++++++++++----
 3 files changed, 55 insertions(+), 66 deletions(-)
drivers/gpu/drm/ast/ast_cursor.c +0 -58
index 024858371f64..31c35296a107 100644
@@ -32,64 +32,6 @@
 
 #include "ast_drv.h"
 
-static void ast_cursor_fini(struct ast_private *ast)
-{
-	size_t i;
-	struct drm_gem_vram_object *gbo;
-
-	for (i = 0; i < ARRAY_SIZE(ast->cursor.gbo); ++i) {
-		gbo = ast->cursor.gbo[i];
-		drm_gem_vram_unpin(gbo);
-		drm_gem_vram_put(gbo);
-	}
-}
-
-static void ast_cursor_release(struct drm_device *dev, void *ptr)
-{
-	struct ast_private *ast = to_ast_private(dev);
-
-	ast_cursor_fini(ast);
-}
-
-/*
- * Allocate cursor BOs and pin them at the end of VRAM.
- */
-int ast_cursor_init(struct ast_private *ast)
-{
-	struct drm_device *dev = &ast->base;
-	size_t size, i;
-	struct drm_gem_vram_object *gbo;
-	int ret;
-
-	size = roundup(AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE, PAGE_SIZE);
-
-	for (i = 0; i < ARRAY_SIZE(ast->cursor.gbo); ++i) {
-		gbo = drm_gem_vram_create(dev, size, 0);
-		if (IS_ERR(gbo)) {
-			ret = PTR_ERR(gbo);
-			goto err_drm_gem_vram_put;
-		}
-		ret = drm_gem_vram_pin(gbo, DRM_GEM_VRAM_PL_FLAG_VRAM |
-					    DRM_GEM_VRAM_PL_FLAG_TOPDOWN);
-		if (ret) {
-			drm_gem_vram_put(gbo);
-			goto err_drm_gem_vram_put;
-		}
-		ast->cursor.gbo[i] = gbo;
-	}
-
-	return drmm_add_action_or_reset(dev, ast_cursor_release, NULL);
-
-err_drm_gem_vram_put:
-	while (i) {
-		--i;
-		gbo = ast->cursor.gbo[i];
-		drm_gem_vram_unpin(gbo);
-		drm_gem_vram_put(gbo);
-	}
-	return ret;
-}
-
 static void update_cursor_image(u8 __iomem *dst, const u8 *src, int width, int height)
 {
 	union {
drivers/gpu/drm/ast/ast_drv.h +0 -1
index 1575e8e636d7..c9c3950449b5 100644
@@ -318,7 +318,6 @@ u8 ast_get_dp501_max_clk(struct drm_device *dev);
 void ast_init_3rdtx(struct drm_device *dev);
 
 /* ast_cursor.c */
-int ast_cursor_init(struct ast_private *ast);
 int ast_cursor_blit(struct ast_private *ast, struct drm_framebuffer *fb);
 void ast_cursor_page_flip(struct ast_private *ast);
 void ast_cursor_show(struct ast_private *ast, int x, int y,
drivers/gpu/drm/ast/ast_mode.c +55 -7

95 lines not on this page · raw message

Signature · 6 lines
2.30.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#5 lore raw

PATCH 5/12 drm/ast: Inline ast cursor-update functions into modesetting code

In reply to Thomas Zimmermann

The logic for cursor updates is now located in the cursor plane's modesetting code. A number of helper functions remain to modify the rsp registers and image.

---
 drivers/gpu/drm/ast/Makefile     |   3 +-
 drivers/gpu/drm/ast/ast_cursor.c | 237 -------------------------------
 drivers/gpu/drm/ast/ast_drv.h    |   7 -
 drivers/gpu/drm/ast/ast_mode.c   | 191 +++++++++++++++++++++++--
 4 files changed, 181 insertions(+), 257 deletions(-)
 delete mode 100644 drivers/gpu/drm/ast/ast_cursor.c
drivers/gpu/drm/ast/Makefile +1 -2
index 2265a8a624dd..438a2d05b115 100644
@@ -3,7 +3,6 @@
 # Makefile for the drm device driver.  This driver provides support for the
 # Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
 
-ast-y := ast_cursor.o ast_drv.o ast_main.o ast_mm.o ast_mode.o ast_post.o \
-	 ast_dp501.o
+ast-y := ast_drv.o ast_main.o ast_mm.o ast_mode.o ast_post.o ast_dp501.o
 
 obj-$(CONFIG_DRM_AST) := ast.o
drivers/gpu/drm/ast/ast_cursor.c deleted +0 -237

237 lines not on this page · raw message

drivers/gpu/drm/ast/ast_drv.h +0 -7
index c9c3950449b5..2761fa547c35 100644
@@ -317,11 +317,4 @@ bool ast_dp501_read_edid(struct drm_device *dev, u8 *ediddata);
 u8 ast_get_dp501_max_clk(struct drm_device *dev);
 void ast_init_3rdtx(struct drm_device *dev);
 
-/* ast_cursor.c */
-int ast_cursor_blit(struct ast_private *ast, struct drm_framebuffer *fb);
-void ast_cursor_page_flip(struct ast_private *ast);
-void ast_cursor_show(struct ast_private *ast, int x, int y,
-		     unsigned int offset_x, unsigned int offset_y);
-void ast_cursor_hide(struct ast_private *ast);
-
 #endif
drivers/gpu/drm/ast/ast_mode.c +180 -11

231 lines not on this page · raw message

Signature · 6 lines
2.30.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#6 lore raw

PATCH 6/12 drm/ast: Add cursor-plane data structure

In reply to Thomas Zimmermann

Cursor state is currently located throughout struct ast_private. Having struct ast_cursor_plane as dedicated data structure for cursors helps to organize the modesetting code.

---
 drivers/gpu/drm/ast/ast_drv.h  | 23 ++++++++++++++++++++++-
 drivers/gpu/drm/ast/ast_mode.c |  5 +++--
 2 files changed, 25 insertions(+), 3 deletions(-)
drivers/gpu/drm/ast/ast_drv.h +22 -1
index 2761fa547c35..9eefd3f01f4c 100644
@@ -81,6 +81,9 @@ enum ast_tx_chip {
 #define AST_DRAM_4Gx16   7
 #define AST_DRAM_8Gx16   8
 
+/*
+ * Cursor plane
+ */
 
 #define AST_MAX_HWC_WIDTH	64
 #define AST_MAX_HWC_HEIGHT	64
@@ -99,6 +102,20 @@ enum ast_tx_chip {
 #define AST_HWC_SIGNATURE_HOTSPOTX	0x14
 #define AST_HWC_SIGNATURE_HOTSPOTY	0x18
 
+struct ast_cursor_plane {
+	struct drm_plane base;
+};
+
+static inline struct ast_cursor_plane *
+to_ast_cursor_plane(struct drm_plane *plane)
+{
+	return container_of(plane, struct ast_cursor_plane, base);
+}
+
+/*
+ * Connector with i2c channel
+ */
+
 struct ast_i2c_chan {
 	struct i2c_adapter adapter;
 	struct drm_device *dev;
@@ -116,6 +133,10 @@ to_ast_connector(struct drm_connector *connector)
 	return container_of(connector, struct ast_connector, base);
 }
 
+/*
+ * Device
+ */
+
 struct ast_private {
 	struct drm_device base;
 
@@ -136,7 +157,7 @@ struct ast_private {
 	} cursor;
 
 	struct drm_plane primary_plane;
-	struct drm_plane cursor_plane;
+	struct ast_cursor_plane cursor_plane;
 	struct drm_crtc crtc;
 	struct drm_encoder encoder;
 	struct ast_connector connector;
drivers/gpu/drm/ast/ast_mode.c +3 -2
index 968ee0c69ec3..9dc70aa62fef 100644
@@ -932,7 +932,8 @@ static const struct drm_plane_funcs ast_cursor_plane_funcs = {
 static int ast_cursor_plane_init(struct ast_private *ast)
 {
 	struct drm_device *dev = &ast->base;
-	struct drm_plane *cursor_plane = &ast->cursor_plane;
+	struct ast_cursor_plane *ast_cursor_plane = &ast->cursor_plane;
+	struct drm_plane *cursor_plane = &ast_cursor_plane->base;
 	size_t size, i;
 	struct drm_gem_vram_object *gbo;
 	int ret;
@@ -1178,7 +1179,7 @@ static int ast_crtc_init(struct drm_device *dev)
 	int ret;
 
 	ret = drm_crtc_init_with_planes(dev, crtc, &ast->primary_plane,
-					&ast->cursor_plane, &ast_crtc_funcs,
+					&ast->cursor_plane.base, &ast_crtc_funcs,
 					NULL);
 	if (ret)
 		return ret;
Signature · 6 lines
2.30.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#7 lore raw

PATCH 7/12 drm/ast: Store cursor BOs in cursor plane

In reply to Thomas Zimmermann

The cursor uses two BOs in video RAM to implement double buffering. Store both in struct ast_cursor_plane.

---
 drivers/gpu/drm/ast/ast_drv.h  | 11 ++++++-----
 drivers/gpu/drm/ast/ast_mode.c | 27 +++++++++++++++------------
 2 files changed, 21 insertions(+), 17 deletions(-)
drivers/gpu/drm/ast/ast_drv.h +6 -5
index 9eefd3f01f4c..4117c49096d4 100644
@@ -104,6 +104,12 @@ enum ast_tx_chip {
 
 struct ast_cursor_plane {
 	struct drm_plane base;
+
+	struct {
+		struct drm_gem_vram_object *gbo;
+	} hwc[AST_DEFAULT_HWC_NUM];
+
+	unsigned int next_hwc_index;
 };
 
 static inline struct ast_cursor_plane *
@@ -151,11 +157,6 @@ struct ast_private {
 
 	int fb_mtrr;
 
-	struct {
-		struct drm_gem_vram_object *gbo[AST_DEFAULT_HWC_NUM];
-		unsigned int next_index;
-	} cursor;
-
 	struct drm_plane primary_plane;
 	struct ast_cursor_plane cursor_plane;
 	struct drm_crtc crtc;
drivers/gpu/drm/ast/ast_mode.c +15 -12
index 9dc70aa62fef..dfff30e3d411 100644
@@ -757,9 +757,10 @@ static int
 ast_cursor_plane_helper_prepare_fb(struct drm_plane *plane,
 				   struct drm_plane_state *new_state)
 {
+	struct ast_cursor_plane *ast_cursor_plane = to_ast_cursor_plane(plane);
 	struct drm_framebuffer *fb = new_state->fb;
-	struct ast_private *ast = to_ast_private(plane->dev);
-	struct drm_gem_vram_object *dst_gbo = ast->cursor.gbo[ast->cursor.next_index];
+	struct drm_gem_vram_object *dst_gbo =
+		ast_cursor_plane->hwc[ast_cursor_plane->next_hwc_index].gbo;
 	struct drm_gem_vram_object *src_gbo;
 	struct dma_buf_map src_map, dst_map;
 	void __iomem *dst;
@@ -826,11 +827,13 @@ static void
 ast_cursor_plane_helper_atomic_update(struct drm_plane *plane,
 				      struct drm_plane_state *old_state)
 {
+	struct ast_cursor_plane *ast_cursor_plane = to_ast_cursor_plane(plane);
 	struct drm_plane_state *state = plane->state;
 	struct drm_framebuffer *fb = state->fb;
 	struct ast_private *ast = to_ast_private(plane->dev);
 	struct drm_device *dev = &ast->base;
-	struct drm_gem_vram_object *gbo = ast->cursor.gbo[ast->cursor.next_index];
+	struct drm_gem_vram_object *gbo =
+		ast_cursor_plane->hwc[ast_cursor_plane->next_hwc_index].gbo;
 	unsigned int offset_x, offset_y;
 	s64 off;
 	struct dma_buf_map map;
@@ -840,7 +843,7 @@ ast_cursor_plane_helper_atomic_update(struct drm_plane *plane,
 	u8 __iomem *sig;
 	int ret;
 
-	gbo = ast->cursor.gbo[ast->cursor.next_index];
+	gbo = ast_cursor_plane->hwc[ast_cursor_plane->next_hwc_index].gbo;
 
 	if (state->fb != old_state->fb) {
 		/* A new cursor image was installed. */
@@ -849,8 +852,8 @@ ast_cursor_plane_helper_atomic_update(struct drm_plane *plane,
 			return; /* Bug: we didn't pin the cursor HW BO to VRAM. */
 		ast_set_cursor_base(ast, off);
 
-		++ast->cursor.next_index;
-		ast->cursor.next_index %= ARRAY_SIZE(ast->cursor.gbo);
+		++ast_cursor_plane->next_hwc_index;
+		ast_cursor_plane->next_hwc_index %= ARRAY_SIZE(ast_cursor_plane->hwc);
 	}
 
 	ret = drm_gem_vram_vmap(gbo, &map);
@@ -907,12 +910,12 @@ static const struct drm_plane_helper_funcs ast_cursor_plane_helper_funcs = {
 
 static void ast_cursor_plane_destroy(struct drm_plane *plane)
 {
-	struct ast_private *ast = to_ast_private(plane->dev);
+	struct ast_cursor_plane *ast_cursor_plane = to_ast_cursor_plane(plane);
 	size_t i;
 	struct drm_gem_vram_object *gbo;
 
-	for (i = 0; i < ARRAY_SIZE(ast->cursor.gbo); ++i) {
-		gbo = ast->cursor.gbo[i];
+	for (i = 0; i < ARRAY_SIZE(ast_cursor_plane->hwc); ++i) {
+		gbo = ast_cursor_plane->hwc[i].gbo;
 		drm_gem_vram_unpin(gbo);
 		drm_gem_vram_put(gbo);
 	}
@@ -945,7 +948,7 @@ static int ast_cursor_plane_init(struct ast_private *ast)
 
 	size = roundup(AST_HWC_SIZE + AST_HWC_SIGNATURE_SIZE, PAGE_SIZE);
 
-	for (i = 0; i < ARRAY_SIZE(ast->cursor.gbo); ++i) {
+	for (i = 0; i < ARRAY_SIZE(ast_cursor_plane->hwc); ++i) {
 		gbo = drm_gem_vram_create(dev, size, 0);
 		if (IS_ERR(gbo)) {
 			ret = PTR_ERR(gbo);
@@ -955,7 +958,7 @@ static int ast_cursor_plane_init(struct ast_private *ast)
 					    DRM_GEM_VRAM_PL_FLAG_TOPDOWN);
 		if (ret)
 			goto err_drm_gem_vram_put;
-		ast->cursor.gbo[i] = gbo;
+		ast_cursor_plane->hwc[i].gbo = gbo;
 	}
 
 	/*
@@ -979,7 +982,7 @@ static int ast_cursor_plane_init(struct ast_private *ast)
 err_hwc:
 	while (i) {
 		--i;
-		gbo = ast->cursor.gbo[i];
+		gbo = ast_cursor_plane->hwc[i].gbo;
 		drm_gem_vram_unpin(gbo);
 err_drm_gem_vram_put:
 		drm_gem_vram_put(gbo);
Signature · 6 lines
2.30.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#8 lore raw

PATCH 8/12 drm/ast: Map HW cursor BOs permanently

In reply to Thomas Zimmermann

The BOs of the hardware cursor are now mapped permanently while the cursor plane is being used. This reduces the CPU overhead of the cursor plane's atomic_update function.

The change also resolves a problem with the vmap call in the commit tail. The vmap implementation could acquire the DMA reservation lock on the BO, which is not allowed that late in the atomic update. Removing the vmap call from atomic_update fixes the issue.

---
 drivers/gpu/drm/ast/ast_drv.h  |  1 +
 drivers/gpu/drm/ast/ast_mode.c | 32 +++++++++++++++-----------------
 2 files changed, 16 insertions(+), 17 deletions(-)
drivers/gpu/drm/ast/ast_drv.h +1 -0
index 4117c49096d4..22193cfde255 100644
@@ -107,6 +107,7 @@ struct ast_cursor_plane {
 
 	struct {
 		struct drm_gem_vram_object *gbo;
+		struct dma_buf_map map;
 	} hwc[AST_DEFAULT_HWC_NUM];
 
 	unsigned int next_hwc_index;
drivers/gpu/drm/ast/ast_mode.c +15 -17
index dfff30e3d411..b9b9badcee00 100644
@@ -759,10 +759,10 @@ ast_cursor_plane_helper_prepare_fb(struct drm_plane *plane,
 {
 	struct ast_cursor_plane *ast_cursor_plane = to_ast_cursor_plane(plane);
 	struct drm_framebuffer *fb = new_state->fb;
-	struct drm_gem_vram_object *dst_gbo =
-		ast_cursor_plane->hwc[ast_cursor_plane->next_hwc_index].gbo;
+	struct dma_buf_map dst_map =
+		ast_cursor_plane->hwc[ast_cursor_plane->next_hwc_index].map;
 	struct drm_gem_vram_object *src_gbo;
-	struct dma_buf_map src_map, dst_map;
+	struct dma_buf_map src_map;
 	void __iomem *dst;
 	void *src;
 	int ret;
@@ -777,22 +777,14 @@ ast_cursor_plane_helper_prepare_fb(struct drm_plane *plane,
 		return ret;
 	src = src_map.vaddr; /* TODO: Use mapping abstraction properly */
 
-	ret = drm_gem_vram_vmap(dst_gbo, &dst_map);
-	if (ret)
-		goto err_drm_gem_vram_vunmap;
 	dst = dst_map.vaddr_iomem; /* TODO: Use mapping abstraction properly */
 
 	/* do data transfer to cursor BO */
 	ast_update_cursor_image(dst, src, fb->width, fb->height);
 
-	drm_gem_vram_vunmap(dst_gbo, &dst_map);
 	drm_gem_vram_vunmap(src_gbo, &src_map);
 
 	return 0;
-
-err_drm_gem_vram_vunmap:
-	drm_gem_vram_vunmap(src_gbo, &src_map);
-	return ret;
 }
 
 static int ast_cursor_plane_helper_atomic_check(struct drm_plane *plane,
@@ -841,9 +833,9 @@ ast_cursor_plane_helper_atomic_update(struct drm_plane *plane,
 	u8 x_offset, y_offset;
 	u8 __iomem *dst;
 	u8 __iomem *sig;
-	int ret;
 
 	gbo = ast_cursor_plane->hwc[ast_cursor_plane->next_hwc_index].gbo;
+	map = ast_cursor_plane->hwc[ast_cursor_plane->next_hwc_index].map;
 
 	if (state->fb != old_state->fb) {
 		/* A new cursor image was installed. */
@@ -856,17 +848,12 @@ ast_cursor_plane_helper_atomic_update(struct drm_plane *plane,
 		ast_cursor_plane->next_hwc_index %= ARRAY_SIZE(ast_cursor_plane->hwc);
 	}
 
-	ret = drm_gem_vram_vmap(gbo, &map);
-	if (drm_WARN_ONCE(dev, ret, "drm_gem_vram_vmap() failed, ret=%d\n", ret))
-		return;
 	dst = map.vaddr_iomem; /* TODO: Use mapping abstraction properly */
 
 	sig = dst + AST_HWC_SIZE;
 	writel(state->crtc_x, sig + AST_HWC_SIGNATURE_X);
 	writel(state->crtc_y, sig + AST_HWC_SIGNATURE_Y);
 
-	drm_gem_vram_vunmap(gbo, &map);
-
 	offset_x = AST_MAX_HWC_WIDTH - fb->width;
 	offset_y = AST_MAX_HWC_HEIGHT - fb->height;
 
@@ -913,9 +900,12 @@ static void ast_cursor_plane_destroy(struct drm_plane *plane)
 	struct ast_cursor_plane *ast_cursor_plane = to_ast_cursor_plane(plane);
 	size_t i;
 	struct drm_gem_vram_object *gbo;
+	struct dma_buf_map map;
 
 	for (i = 0; i < ARRAY_SIZE(ast_cursor_plane->hwc); ++i) {
 		gbo = ast_cursor_plane->hwc[i].gbo;
+		map = ast_cursor_plane->hwc[i].map;
+		drm_gem_vram_vunmap(gbo, &map);
 		drm_gem_vram_unpin(gbo);
 		drm_gem_vram_put(gbo);
 	}
@@ -939,6 +929,7 @@ static int ast_cursor_plane_init(struct ast_private *ast)
 	struct drm_plane *cursor_plane = &ast_cursor_plane->base;
 	size_t size, i;
 	struct drm_gem_vram_object *gbo;
+	struct dma_buf_map map;
 	int ret;
 
 	/*
@@ -958,7 +949,11 @@ static int ast_cursor_plane_init(struct ast_private *ast)
 					    DRM_GEM_VRAM_PL_FLAG_TOPDOWN);
 		if (ret)
 			goto err_drm_gem_vram_put;
+		ret = drm_gem_vram_vmap(gbo, &map);
+		if (ret)
+			goto err_drm_gem_vram_unpin;
 		ast_cursor_plane->hwc[i].gbo = gbo;
+		ast_cursor_plane->hwc[i].map = map;
 	}
 
 	/*
@@ -983,6 +978,9 @@ static int ast_cursor_plane_init(struct ast_private *ast)
 	while (i) {
 		--i;
 		gbo = ast_cursor_plane->hwc[i].gbo;
+		map = ast_cursor_plane->hwc[i].map;
+		drm_gem_vram_vunmap(gbo, &map);
+err_drm_gem_vram_unpin:
 		drm_gem_vram_unpin(gbo);
 err_drm_gem_vram_put:
 		drm_gem_vram_put(gbo);
Signature · 6 lines
2.30.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#9 lore raw

PATCH 9/12 drm/ast: Introduce dedicated cursor-plane state

In reply to Thomas Zimmermann

The cursor-plane state struct ast_cursor_plane_state will store the involved cursor source BO's mapping into kernel address space.

---
 drivers/gpu/drm/ast/ast_mode.c | 40 ++++++++++++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +38 -2
index b9b9badcee00..199ad9f9c932 100644
@@ -749,6 +749,16 @@ static void ast_set_cursor_enabled(struct ast_private *ast, bool enabled)
 	ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xcb, mask, vgacrcb);
 }
 
+struct ast_cursor_plane_state {
+	struct drm_plane_state base;
+};
+
+static inline struct ast_cursor_plane_state *
+to_ast_cursor_plane_state(struct drm_plane_state *state)
+{
+	return container_of(state, struct ast_cursor_plane_state, base);
+}
+
 static const uint32_t ast_cursor_plane_formats[] = {
 	DRM_FORMAT_ARGB8888,
 };
@@ -913,13 +923,39 @@ static void ast_cursor_plane_destroy(struct drm_plane *plane)
 	drm_plane_cleanup(plane);
 }
 
+static struct drm_plane_state *
+ast_cursor_plane_atomic_duplicate_state(struct drm_plane *plane)
+{
+	struct ast_cursor_plane_state *new_ast_state;
+	struct drm_device *dev = plane->dev;
+
+	if (drm_WARN_ON(dev, !plane->state))
+		return NULL;
+
+	new_ast_state = kmalloc(sizeof(*new_ast_state), GFP_KERNEL);
+	if (!new_ast_state)
+		return NULL;
+	__drm_atomic_helper_plane_duplicate_state(plane, &new_ast_state->base);
+
+	return &new_ast_state->base;
+}
+
+static void ast_cursor_plane_atomic_destroy_state(struct drm_plane *plane,
+						  struct drm_plane_state *state)
+{
+	struct ast_cursor_plane_state *ast_state = to_ast_cursor_plane_state(state);
+
+	__drm_atomic_helper_plane_destroy_state(&ast_state->base);
+	kfree(ast_state);
+}
+
 static const struct drm_plane_funcs ast_cursor_plane_funcs = {
 	.update_plane = drm_atomic_helper_update_plane,
 	.disable_plane = drm_atomic_helper_disable_plane,
 	.destroy = ast_cursor_plane_destroy,
 	.reset = drm_atomic_helper_plane_reset,
-	.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
-	.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
+	.atomic_duplicate_state = ast_cursor_plane_atomic_duplicate_state,
+	.atomic_destroy_state = ast_cursor_plane_atomic_destroy_state,
 };
 
 static int ast_cursor_plane_init(struct ast_private *ast)
Signature · 6 lines
2.30.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#10 lore raw

PATCH 10/12 drm/ast: Fix cursor BO pinning and mapping

In reply to Thomas Zimmermann

GEM vmap operations are not allowed in commit tail. Therefore, we cannot map the cursor source BO in atomic_update. Instead do this in prepare_fb. There was no pin operation for the BO, so add this as well.

Hence the cursor source BO is now mapped while it's being displayed. The change will allow us to move all cursor damage handling from prepare_fb to atomic_update.

---
 drivers/gpu/drm/ast/ast_mode.c | 37 +++++++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +34 -3
index 199ad9f9c932..192d3d34b9ed 100644
@@ -751,6 +751,10 @@ static void ast_set_cursor_enabled(struct ast_private *ast, bool enabled)
 
 struct ast_cursor_plane_state {
 	struct drm_plane_state base;
+
+	/* Transitional state - do not export or duplicate */
+
+	struct dma_buf_map map;
 };
 
 static inline struct ast_cursor_plane_state *
@@ -771,6 +775,7 @@ ast_cursor_plane_helper_prepare_fb(struct drm_plane *plane,
 	struct drm_framebuffer *fb = new_state->fb;
 	struct dma_buf_map dst_map =
 		ast_cursor_plane->hwc[ast_cursor_plane->next_hwc_index].map;
+	struct ast_cursor_plane_state *new_ast_state = to_ast_cursor_plane_state(new_state);
 	struct drm_gem_vram_object *src_gbo;
 	struct dma_buf_map src_map;
 	void __iomem *dst;
@@ -782,9 +787,13 @@ ast_cursor_plane_helper_prepare_fb(struct drm_plane *plane,
 
 	src_gbo = drm_gem_vram_of_gem(fb->obj[0]);
 
-	ret = drm_gem_vram_vmap(src_gbo, &src_map);
+	ret = drm_gem_vram_pin(src_gbo, 0);
 	if (ret)
 		return ret;
+
+	ret = drm_gem_vram_vmap(src_gbo, &src_map);
+	if (ret)
+		goto err_drm_gem_vram_unpin;
 	src = src_map.vaddr; /* TODO: Use mapping abstraction properly */
 
 	dst = dst_map.vaddr_iomem; /* TODO: Use mapping abstraction properly */
@@ -792,9 +801,31 @@ ast_cursor_plane_helper_prepare_fb(struct drm_plane *plane,
 	/* do data transfer to cursor BO */
 	ast_update_cursor_image(dst, src, fb->width, fb->height);
 
-	drm_gem_vram_vunmap(src_gbo, &src_map);
+	new_ast_state->map = src_map;
 
 	return 0;
+
+err_drm_gem_vram_unpin:
+	drm_gem_vram_unpin(src_gbo);
+	return ret;
+}
+
+static void ast_cursor_plane_helper_cleanup_fb(struct drm_plane *plane,
+					       struct drm_plane_state *old_state)
+{
+	struct ast_cursor_plane_state *old_ast_state = to_ast_cursor_plane_state(old_state);
+	struct drm_framebuffer *fb = old_state->fb;
+	struct drm_gem_vram_object *gbo;
+	struct dma_buf_map map;
+
+	if (!fb)
+		return;
+
+	gbo = drm_gem_vram_of_gem(fb->obj[0]);
+	map = old_ast_state->map;
+
+	drm_gem_vram_vunmap(gbo, &map);
+	drm_gem_vram_unpin(gbo);
 }
 
 static int ast_cursor_plane_helper_atomic_check(struct drm_plane *plane,
@@ -899,7 +930,7 @@ ast_cursor_plane_helper_atomic_disable(struct drm_plane *plane,
 
 static const struct drm_plane_helper_funcs ast_cursor_plane_helper_funcs = {
 	.prepare_fb = ast_cursor_plane_helper_prepare_fb,
-	.cleanup_fb = NULL, /* not required for cursor plane */
+	.cleanup_fb = ast_cursor_plane_helper_cleanup_fb,
 	.atomic_check = ast_cursor_plane_helper_atomic_check,
 	.atomic_update = ast_cursor_plane_helper_atomic_update,
 	.atomic_disable = ast_cursor_plane_helper_atomic_disable,
Signature · 6 lines
2.30.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#11 lore raw

Re: [PATCH 10/12] drm/ast: Fix cursor BO pinning and mapping

Am 27.01.21 um 13:03 schrieb Thomas Zimmermann:

Quoted 3 lines

GEM vmap operations are not allowed in commit tail. Therefore, we cannot map the cursor source BO in atomic_update. Instead do this in prepare_fb. There was no pin operation for the BO, so add this as well.

Reviewing drm_gem_vram_vmap() I saw that is pins implicitly. I'll remove the pinning from the driver code in the patch's next iteration.

Quoted 91 lines

Hence the cursor source BO is now mapped while it's being displayed. The change will allow us to move all cursor damage handling from prepare_fb to atomic_update.

---
  drivers/gpu/drm/ast/ast_mode.c | 37 +++++++++++++++++++++++++++++++---
  1 file changed, 34 insertions(+), 3 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +34 -3
index 199ad9f9c932..192d3d34b9ed 100644
@@ -751,6 +751,10 @@ static void ast_set_cursor_enabled(struct ast_private *ast, bool enabled)
 
  struct ast_cursor_plane_state {
  	struct drm_plane_state base;
+
+	/* Transitional state - do not export or duplicate */
+
+	struct dma_buf_map map;
  };
 
  static inline struct ast_cursor_plane_state *
@@ -771,6 +775,7 @@ ast_cursor_plane_helper_prepare_fb(struct drm_plane *plane,
  	struct drm_framebuffer *fb = new_state->fb;
  	struct dma_buf_map dst_map =
  		ast_cursor_plane->hwc[ast_cursor_plane->next_hwc_index].map;
+	struct ast_cursor_plane_state *new_ast_state = to_ast_cursor_plane_state(new_state);
  	struct drm_gem_vram_object *src_gbo;
  	struct dma_buf_map src_map;
  	void __iomem *dst;
@@ -782,9 +787,13 @@ ast_cursor_plane_helper_prepare_fb(struct drm_plane *plane,
 
  	src_gbo = drm_gem_vram_of_gem(fb->obj[0]);
 
-	ret = drm_gem_vram_vmap(src_gbo, &src_map);
+	ret = drm_gem_vram_pin(src_gbo, 0);
  	if (ret)
  		return ret;
+
+	ret = drm_gem_vram_vmap(src_gbo, &src_map);
+	if (ret)
+		goto err_drm_gem_vram_unpin;
  	src = src_map.vaddr; /* TODO: Use mapping abstraction properly */
 
  	dst = dst_map.vaddr_iomem; /* TODO: Use mapping abstraction properly */
@@ -792,9 +801,31 @@ ast_cursor_plane_helper_prepare_fb(struct drm_plane *plane,
  	/* do data transfer to cursor BO */
  	ast_update_cursor_image(dst, src, fb->width, fb->height);
 
-	drm_gem_vram_vunmap(src_gbo, &src_map);
+	new_ast_state->map = src_map;
 
  	return 0;
+
+err_drm_gem_vram_unpin:
+	drm_gem_vram_unpin(src_gbo);
+	return ret;
+}
+
+static void ast_cursor_plane_helper_cleanup_fb(struct drm_plane *plane,
+					       struct drm_plane_state *old_state)
+{
+	struct ast_cursor_plane_state *old_ast_state = to_ast_cursor_plane_state(old_state);
+	struct drm_framebuffer *fb = old_state->fb;
+	struct drm_gem_vram_object *gbo;
+	struct dma_buf_map map;
+
+	if (!fb)
+		return;
+
+	gbo = drm_gem_vram_of_gem(fb->obj[0]);
+	map = old_ast_state->map;
+
+	drm_gem_vram_vunmap(gbo, &map);
+	drm_gem_vram_unpin(gbo);
  }
 
  static int ast_cursor_plane_helper_atomic_check(struct drm_plane *plane,
@@ -899,7 +930,7 @@ ast_cursor_plane_helper_atomic_disable(struct drm_plane *plane,
 
  static const struct drm_plane_helper_funcs ast_cursor_plane_helper_funcs = {
  	.prepare_fb = ast_cursor_plane_helper_prepare_fb,
-	.cleanup_fb = NULL, /* not required for cursor plane */
+	.cleanup_fb = ast_cursor_plane_helper_cleanup_fb,
  	.atomic_check = ast_cursor_plane_helper_atomic_check,
  	.atomic_update = ast_cursor_plane_helper_atomic_update,
  	.atomic_disable = ast_cursor_plane_helper_atomic_disable,
Signature · 6 lines
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

author maintainer
#12 lore raw

PATCH 11/12 drm/ast: Move all of the cursor-update functionality to atomic_update

In reply to Thomas Zimmermann

We used to update the cursor image in prepare_fb. Move all this code to atomic_update (were it belongs). Prepare_fb only prepares the source BO.

---
 drivers/gpu/drm/ast/ast_mode.c | 56 +++++++++++++++++-----------------
 1 file changed, 28 insertions(+), 28 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +28 -28
index 192d3d34b9ed..716ed7025b41 100644
@@ -771,42 +771,30 @@ static int
 ast_cursor_plane_helper_prepare_fb(struct drm_plane *plane,
 				   struct drm_plane_state *new_state)
 {
-	struct ast_cursor_plane *ast_cursor_plane = to_ast_cursor_plane(plane);
 	struct drm_framebuffer *fb = new_state->fb;
-	struct dma_buf_map dst_map =
-		ast_cursor_plane->hwc[ast_cursor_plane->next_hwc_index].map;
 	struct ast_cursor_plane_state *new_ast_state = to_ast_cursor_plane_state(new_state);
-	struct drm_gem_vram_object *src_gbo;
-	struct dma_buf_map src_map;
-	void __iomem *dst;
-	void *src;
+	struct drm_gem_vram_object *gbo;
+	struct dma_buf_map map;
 	int ret;
 
 	if (!fb)
 		return 0;
 
-	src_gbo = drm_gem_vram_of_gem(fb->obj[0]);
+	gbo = drm_gem_vram_of_gem(fb->obj[0]);
 
-	ret = drm_gem_vram_pin(src_gbo, 0);
+	ret = drm_gem_vram_pin(gbo, 0);
 	if (ret)
 		return ret;
 
-	ret = drm_gem_vram_vmap(src_gbo, &src_map);
+	ret = drm_gem_vram_vmap(gbo, &map);
 	if (ret)
 		goto err_drm_gem_vram_unpin;
-	src = src_map.vaddr; /* TODO: Use mapping abstraction properly */
-
-	dst = dst_map.vaddr_iomem; /* TODO: Use mapping abstraction properly */
-
-	/* do data transfer to cursor BO */
-	ast_update_cursor_image(dst, src, fb->width, fb->height);
-
-	new_ast_state->map = src_map;
+	new_ast_state->map = map;
 
 	return 0;
 
 err_drm_gem_vram_unpin:
-	drm_gem_vram_unpin(src_gbo);
+	drm_gem_vram_unpin(gbo);
 	return ret;
 }
 
@@ -862,25 +850,36 @@ ast_cursor_plane_helper_atomic_update(struct drm_plane *plane,
 {
 	struct ast_cursor_plane *ast_cursor_plane = to_ast_cursor_plane(plane);
 	struct drm_plane_state *state = plane->state;
+	struct ast_cursor_plane_state *ast_state = to_ast_cursor_plane_state(state);
 	struct drm_framebuffer *fb = state->fb;
 	struct ast_private *ast = to_ast_private(plane->dev);
 	struct drm_device *dev = &ast->base;
-	struct drm_gem_vram_object *gbo =
+	struct drm_gem_vram_object *dst_gbo =
 		ast_cursor_plane->hwc[ast_cursor_plane->next_hwc_index].gbo;
+	struct dma_buf_map dst_map =
+		ast_cursor_plane->hwc[ast_cursor_plane->next_hwc_index].map;
+	struct dma_buf_map src_map = ast_state->map;
 	unsigned int offset_x, offset_y;
 	s64 off;
-	struct dma_buf_map map;
 	u16 x, y;
 	u8 x_offset, y_offset;
 	u8 __iomem *dst;
 	u8 __iomem *sig;
+	const u8 *src;
 
-	gbo = ast_cursor_plane->hwc[ast_cursor_plane->next_hwc_index].gbo;
-	map = ast_cursor_plane->hwc[ast_cursor_plane->next_hwc_index].map;
+	src = src_map.vaddr; /* TODO: Use mapping abstraction properly */
+	dst = dst_map.vaddr_iomem; /* TODO: Use mapping abstraction properly */
+	sig = dst + AST_HWC_SIZE; /* TODO: Use mapping abstraction properly */
+
+	/*
+	 * Do data transfer to HW cursor BO. If a new cursor image was installed,
+	 * point the scanout engine to dst_gbo's offset and page-flip the HWC buffers.
+	 */
+
+	ast_update_cursor_image(dst, src, fb->width, fb->height);
 
 	if (state->fb != old_state->fb) {
-		/* A new cursor image was installed. */
-		off = drm_gem_vram_offset(gbo);
+		off = drm_gem_vram_offset(dst_gbo);
 		if (drm_WARN_ON_ONCE(dev, off < 0))
 			return; /* Bug: we didn't pin the cursor HW BO to VRAM. */
 		ast_set_cursor_base(ast, off);
@@ -889,9 +888,10 @@ ast_cursor_plane_helper_atomic_update(struct drm_plane *plane,
 		ast_cursor_plane->next_hwc_index %= ARRAY_SIZE(ast_cursor_plane->hwc);
 	}
 
-	dst = map.vaddr_iomem; /* TODO: Use mapping abstraction properly */
+	/*
+	 * Update location in HWC signature and registers.
+	 */
 
-	sig = dst + AST_HWC_SIZE;
 	writel(state->crtc_x, sig + AST_HWC_SIGNATURE_X);
 	writel(state->crtc_y, sig + AST_HWC_SIGNATURE_Y);
 
@@ -915,7 +915,7 @@ ast_cursor_plane_helper_atomic_update(struct drm_plane *plane,
 
 	ast_set_cursor_location(ast, x, y, x_offset, y_offset);
 
-	/* dummy write to fire HWC */
+	/* Dummy write to enable HWC and make the HW pick-up the changes. */
 	ast_set_cursor_enabled(ast, true);
 }
 
Signature · 6 lines
2.30.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#13 lore raw

PATCH 12/12 drm/ast: Store each HW cursor offset after pinning the rsp BO

In reply to Thomas Zimmermann

As HW cursor BOs never move, we can store the offset in VRAM in the cursor-plane's HWC state. This removes the last possible source of runtime errors from atomic_update.

---
 drivers/gpu/drm/ast/ast_drv.h  |  1 +
 drivers/gpu/drm/ast/ast_mode.c | 19 +++++++++++--------
 2 files changed, 12 insertions(+), 8 deletions(-)
drivers/gpu/drm/ast/ast_drv.h +1 -0
index 22193cfde255..e82ab8628770 100644
@@ -108,6 +108,7 @@ struct ast_cursor_plane {
 	struct {
 		struct drm_gem_vram_object *gbo;
 		struct dma_buf_map map;
+		u64 off;
 	} hwc[AST_DEFAULT_HWC_NUM];
 
 	unsigned int next_hwc_index;
drivers/gpu/drm/ast/ast_mode.c +11 -8
index 716ed7025b41..6388e6364e8e 100644
@@ -853,14 +853,12 @@ ast_cursor_plane_helper_atomic_update(struct drm_plane *plane,
 	struct ast_cursor_plane_state *ast_state = to_ast_cursor_plane_state(state);
 	struct drm_framebuffer *fb = state->fb;
 	struct ast_private *ast = to_ast_private(plane->dev);
-	struct drm_device *dev = &ast->base;
-	struct drm_gem_vram_object *dst_gbo =
-		ast_cursor_plane->hwc[ast_cursor_plane->next_hwc_index].gbo;
 	struct dma_buf_map dst_map =
 		ast_cursor_plane->hwc[ast_cursor_plane->next_hwc_index].map;
+	u64 dst_off =
+		ast_cursor_plane->hwc[ast_cursor_plane->next_hwc_index].off;
 	struct dma_buf_map src_map = ast_state->map;
 	unsigned int offset_x, offset_y;
-	s64 off;
 	u16 x, y;
 	u8 x_offset, y_offset;
 	u8 __iomem *dst;
@@ -879,10 +877,7 @@ ast_cursor_plane_helper_atomic_update(struct drm_plane *plane,
 	ast_update_cursor_image(dst, src, fb->width, fb->height);
 
 	if (state->fb != old_state->fb) {
-		off = drm_gem_vram_offset(dst_gbo);
-		if (drm_WARN_ON_ONCE(dev, off < 0))
-			return; /* Bug: we didn't pin the cursor HW BO to VRAM. */
-		ast_set_cursor_base(ast, off);
+		ast_set_cursor_base(ast, dst_off);
 
 		++ast_cursor_plane->next_hwc_index;
 		ast_cursor_plane->next_hwc_index %= ARRAY_SIZE(ast_cursor_plane->hwc);
@@ -998,6 +993,7 @@ static int ast_cursor_plane_init(struct ast_private *ast)
 	struct drm_gem_vram_object *gbo;
 	struct dma_buf_map map;
 	int ret;
+	s64 off;
 
 	/*
 	 * Allocate backing storage for cursors. The BOs are permanently
@@ -1019,8 +1015,14 @@ static int ast_cursor_plane_init(struct ast_private *ast)
 		ret = drm_gem_vram_vmap(gbo, &map);
 		if (ret)
 			goto err_drm_gem_vram_unpin;
+		off = drm_gem_vram_offset(gbo);
+		if (off < 0) {
+			ret = off;
+			goto err_drm_gem_vram_vunmap;
+		}
 		ast_cursor_plane->hwc[i].gbo = gbo;
 		ast_cursor_plane->hwc[i].map = map;
+		ast_cursor_plane->hwc[i].off = off;
 	}
 
 	/*
@@ -1046,6 +1048,7 @@ static int ast_cursor_plane_init(struct ast_private *ast)
 		--i;
 		gbo = ast_cursor_plane->hwc[i].gbo;
 		map = ast_cursor_plane->hwc[i].map;
+err_drm_gem_vram_vunmap:
 		drm_gem_vram_vunmap(gbo, &map);
 err_drm_gem_vram_unpin:
 		drm_gem_vram_unpin(gbo);
Signature · 6 lines
2.30.0

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel