drm/ast: Allocate HW cursor BOs during cursor-plane initialization
authorThomas Zimmermann <tzimmermann@suse.de>
Tue, 9 Feb 2021 13:46:26 +0000 (14:46 +0100)
committerThomas Zimmermann <tzimmermann@suse.de>
Wed, 17 Feb 2021 11:40:01 +0000 (12:40 +0100)
The BOs are eventually released by the cursor plane's destroy callback.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210209134632.12157-5-tzimmermann@suse.de
drivers/gpu/drm/ast/ast_cursor.c
drivers/gpu/drm/ast/ast_drv.h
drivers/gpu/drm/ast/ast_mode.c

index 0248583..31c3529 100644 (file)
 
 #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 {
index 1575e8e..c9c3950 100644 (file)
@@ -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,
index f86773a..99b6f7c 100644 (file)
@@ -736,10 +736,25 @@ static const struct drm_plane_helper_funcs ast_cursor_plane_helper_funcs = {
        .atomic_disable = ast_cursor_plane_helper_atomic_disable,
 };
 
+static void ast_cursor_plane_destroy(struct drm_plane *plane)
+{
+       struct ast_private *ast = to_ast_private(plane->dev);
+       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);
+       }
+
+       drm_plane_cleanup(plane);
+}
+
 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 = drm_plane_cleanup,
+       .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,
@@ -749,20 +764,57 @@ static int ast_cursor_plane_init(struct ast_private *ast)
 {
        struct drm_device *dev = &ast->base;
        struct drm_plane *cursor_plane = &ast->cursor_plane;
+       size_t size, i;
+       struct drm_gem_vram_object *gbo;
        int ret;
 
+       /*
+        * Allocate backing storage for cursors. The BOs are permanently
+        * pinned to the top end of the VRAM.
+        */
+
+       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_hwc;
+               }
+               ret = drm_gem_vram_pin(gbo, DRM_GEM_VRAM_PL_FLAG_VRAM |
+                                           DRM_GEM_VRAM_PL_FLAG_TOPDOWN);
+               if (ret)
+                       goto err_drm_gem_vram_put;
+               ast->cursor.gbo[i] = gbo;
+       }
+
+       /*
+        * Create the cursor plane. The plane's destroy callback will release
+        * the backing storages' BO memory.
+        */
+
        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_err(dev, "drm_universal_plane failed(): %d\n", ret);
+               goto err_hwc;
        }
        drm_plane_helper_add(cursor_plane, &ast_cursor_plane_helper_funcs);
 
        return 0;
+
+err_hwc:
+       while (i) {
+               --i;
+               gbo = ast->cursor.gbo[i];
+               drm_gem_vram_unpin(gbo);
+err_drm_gem_vram_put:
+               drm_gem_vram_put(gbo);
+       }
+       return ret;
 }
 
 /*
@@ -1149,10 +1201,6 @@ int ast_mode_config_init(struct ast_private *ast)
        struct pci_dev *pdev = to_pci_dev(dev->dev);
        int ret;
 
-       ret = ast_cursor_init(ast);
-       if (ret)
-               return ret;
-
        ret = drmm_mode_config_init(dev);
        if (ret)
                return ret;