gpu: drm: verisilicon: Fix the build error about vs_gem
authorJaehoon Chung <jh80.chung@samsung.com>
Wed, 17 Jan 2024 05:01:45 +0000 (14:01 +0900)
committerJaehoon Chung <jh80.chung@samsung.com>
Mon, 19 Feb 2024 00:14:00 +0000 (09:14 +0900)
Fix the build error about vs_gem.
During updating to v6.6, some callback functions are deprecated.
To fix the call sequence, add the vs_gem_dmabuf-mmap function.

Change-Id: I80a5715924c77faf7a7b68b17ddc6063e2f4333a
Signed-off-by: Jaehoon Chung <jh80.chung@samsung.com>
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
drivers/gpu/drm/verisilicon/Kconfig
drivers/gpu/drm/verisilicon/Makefile
drivers/gpu/drm/verisilicon/vs_drv.c
drivers/gpu/drm/verisilicon/vs_fb.c [new file with mode: 0644]
drivers/gpu/drm/verisilicon/vs_fb.h [new file with mode: 0644]
drivers/gpu/drm/verisilicon/vs_gem.c
drivers/gpu/drm/verisilicon/vs_gem.h
drivers/gpu/drm/verisilicon/vs_modeset.c
drivers/gpu/drm/verisilicon/vs_plane.c

index 122c786e394864d777bd2e9a3d336916b0560882..89c86f96cd0e1d5189b96c766e178a0d6484dd77 100644 (file)
@@ -3,7 +3,6 @@ config DRM_VERISILICON
        tristate "DRM Support for VeriSilicon"
        depends on DRM
        select DRM_KMS_HELPER
-       select DRM_GEM_DMA_HELPER
        select CMA
        select DMA_CMA
        help
index 7d720e06c107cbdbd3a580663d10e42b683f1bb7..db74ad0a874e3740d6610597df57a8cf6b16e38b 100644 (file)
@@ -7,6 +7,7 @@ vs_drm-objs := vs_dc_hw.o \
                vs_modeset.o \
                vs_plane.o \
                vs_simple_enc.o \
+               vs_fb.o \
                vs_gem.o
 
 vs_drm-$(CONFIG_DRM_VERISILICON_STARFIVE_HDMI) += starfive_hdmi.o starfive_hdmi_audio.o
index d0e952812495e3897d95acc9f596852b417766e4..9ca5d01a28ff688e0e90d99903807b608f486454 100644 (file)
 #include <drm/drm_fb_helper.h>
 #include <drm/drm_fbdev_generic.h>
 #include <drm/drm_file.h>
-#include <drm/drm_gem_dma_helper.h>
 #include <drm/drm_module.h>
 #include <drm/drm_of.h>
 #include <drm/drm_probe_helper.h>
 #include <drm/drm_vblank.h>
+#include <drm/drm_ioctl.h>
 
 #include "vs_drv.h"
 #include "vs_modeset.h"
 #define DRV_MAJOR      1
 #define DRV_MINOR      0
 
-static int vs_gem_dumb_create(struct drm_file *file, struct drm_device *dev,
-                             struct drm_mode_create_dumb *args)
-{
-       struct vs_drm_device *priv = to_vs_drm_private(dev);
-       unsigned int pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
-
-       args->pitch = ALIGN(pitch, priv->pitch_alignment);
-       return drm_gem_dma_dumb_create_internal(file, dev, args);
-}
-
-DEFINE_DRM_GEM_FOPS(vs_drm_fops);
+static const struct file_operations vs_drm_fops = {
+       .owner                  = THIS_MODULE,
+       .open                   = drm_open,
+       .release                = drm_release,
+       .unlocked_ioctl = drm_ioctl,
+       .compat_ioctl   = drm_compat_ioctl,
+       .poll                   = drm_poll,
+       .read                   = drm_read,
+       .mmap                   = vs_gem_mmap,
+};
 
 static struct drm_driver vs_drm_driver = {
        .driver_features        = DRIVER_MODESET | DRIVER_ATOMIC | DRIVER_GEM,
-
-       DRM_GEM_DMA_DRIVER_OPS_WITH_DUMB_CREATE(vs_gem_dumb_create),
-
+       .lastclose              = drm_fb_helper_lastclose,
+       .gem_prime_import       = vs_gem_prime_import,
+       .gem_prime_import_sg_table = vs_gem_prime_import_sg_table,
+       .dumb_create            = vs_gem_dumb_create_old,
        .fops                   = &vs_drm_fops,
        .name                   = DRV_NAME,
        .desc                   = DRV_DESC,
@@ -170,6 +170,7 @@ static int vs_drm_bind(struct device *dev)
                return ret;
 
        drm_dev = &priv->base;
+
        platform_set_drvdata(pdev, drm_dev);
 
        ret = vs_drm_device_init_clocks(priv);
diff --git a/drivers/gpu/drm/verisilicon/vs_fb.c b/drivers/gpu/drm/verisilicon/vs_fb.c
new file mode 100644 (file)
index 0000000..464e6cc
--- /dev/null
@@ -0,0 +1,122 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2023 VeriSilicon Holdings Co., Ltd.
+ */
+
+#include <linux/module.h>
+#include <linux/version.h>
+
+#include <drm/drm_damage_helper.h>
+#include <drm/drm_fb_helper.h>
+#include <drm/drm_crtc.h>
+#include <drm/drm_crtc_helper.h>
+#include <drm/drm_fourcc.h>
+#include <drm/drm_framebuffer.h>
+#include <drm/drm_gem.h>
+#include <drm/drm_gem_framebuffer_helper.h>
+
+#include "vs_fb.h"
+#include "vs_gem.h"
+
+#define fourcc_mod_vs_get_type(val) \
+       (((val) & DRM_FORMAT_MOD_VS_TYPE_MASK) >> 54)
+
+static struct drm_framebuffer_funcs vs_fb_funcs = {
+       .create_handle  = drm_gem_fb_create_handle,
+       .destroy        = drm_gem_fb_destroy,
+       .dirty          = drm_atomic_helper_dirtyfb,
+};
+
+static struct drm_framebuffer *
+vs_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd,
+           struct vs_gem_object **obj, unsigned int num_planes)
+{
+       struct drm_framebuffer *fb;
+       int ret, i;
+
+       fb = kzalloc(sizeof(*fb), GFP_KERNEL);
+       if (!fb)
+               return ERR_PTR(-ENOMEM);
+
+       drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd);
+
+       for (i = 0; i < num_planes; i++)
+               fb->obj[i] = &obj[i]->base;
+
+       ret = drm_framebuffer_init(dev, fb, &vs_fb_funcs);
+       if (ret) {
+               dev_err(dev->dev, "Failed to initialize framebuffer: %d\n",
+                       ret);
+               kfree(fb);
+               return ERR_PTR(ret);
+       }
+
+       return fb;
+}
+
+struct drm_framebuffer *vs_fb_create(struct drm_device *dev,
+                                           struct drm_file *file_priv,
+                                           const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+       struct drm_framebuffer *fb;
+       const struct drm_format_info *info;
+       struct vs_gem_object *objs[MAX_NUM_PLANES];
+       struct drm_gem_object *obj;
+       unsigned int height, size;
+       unsigned char i, num_planes;
+       int ret = 0;
+
+       info = drm_get_format_info(dev, mode_cmd);
+       if (!info)
+               return ERR_PTR(-EINVAL);
+
+       num_planes = info->num_planes;
+       if (num_planes > MAX_NUM_PLANES)
+               return ERR_PTR(-EINVAL);
+
+       for (i = 0; i < num_planes; i++) {
+               obj = drm_gem_object_lookup(file_priv, mode_cmd->handles[i]);
+               if (!obj) {
+                       dev_err(dev->dev, "Failed to lookup GEM object.\n");
+                       ret = -ENXIO;
+                       goto err;
+               }
+
+               height = drm_format_info_plane_height(info,
+                                                     mode_cmd->height, i);
+
+               size = height * mode_cmd->pitches[i] + mode_cmd->offsets[i];
+
+               if (obj->size < size) {
+                       drm_gem_object_put(obj);
+
+                       ret = -EINVAL;
+                       goto err;
+               }
+
+               objs[i] = to_vs_gem_object(obj);
+       }
+
+       fb = vs_fb_alloc(dev, mode_cmd, objs, i);
+       if (IS_ERR(fb)) {
+               ret = PTR_ERR(fb);
+               goto err;
+       }
+
+       return fb;
+
+err:
+       for (; i > 0; i--)
+               drm_gem_object_put(&objs[i - 1]->base);
+
+       return ERR_PTR(ret);
+}
+
+struct vs_gem_object *vs_fb_get_gem_obj(struct drm_framebuffer *fb,
+                                       unsigned int plane)
+{
+       if (plane > MAX_NUM_PLANES)
+               return NULL;
+
+       return to_vs_gem_object(fb->obj[plane]);
+}
diff --git a/drivers/gpu/drm/verisilicon/vs_fb.h b/drivers/gpu/drm/verisilicon/vs_fb.h
new file mode 100644 (file)
index 0000000..15e734b
--- /dev/null
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2023 VeriSilicon Holdings Co., Ltd.
+ */
+
+#ifndef __VS_FB_H__
+#define __VS_FB_H__
+
+#define MAX_NUM_PLANES         3 /* colour format plane */
+
+struct drm_framebuffer *vs_fb_create(struct drm_device *dev,
+                                           struct drm_file *file_priv,
+                                           const struct drm_mode_fb_cmd2 *mode_cmd);
+
+struct vs_gem_object *vs_fb_get_gem_obj(struct drm_framebuffer *fb,
+                                       unsigned int plane);
+#endif /* __VS_FB_H__ */
index 5b76bf6765b44f9925ee35c1839866ff04d80095..bc1a516abdac437d0ce9158467ec3bad7dcab7e4 100644 (file)
@@ -5,7 +5,6 @@
 
 #include <linux/dma-buf.h>
 #include <linux/of_reserved_mem.h>
-#include <drm/drm_gem_dma_helper.h>
 
 #include "vs_drv.h"
 #include "vs_gem.h"
 
 static const struct drm_gem_object_funcs vs_gem_default_funcs;
 
+static struct device *to_dma_dev(struct drm_device *dev)
+{
+       struct vs_drm_device *priv = to_vs_drm_private(dev);
+
+       return priv->base.dev;
+}
+
 static int vs_gem_alloc_buf(struct vs_gem_object *vs_obj)
 {
        struct drm_device *dev = vs_obj->base.dev;
@@ -236,6 +242,13 @@ static int vs_gem_prime_end_cpu_access(struct dma_buf *buf,
        return 0;
 }
 
+static int vs_gem_dmabuf_mmap(struct dma_buf *dma_buf, struct vm_area_struct *vma)
+{
+       struct drm_gem_object *obj = dma_buf->priv;
+
+       return vs_gem_prime_mmap(obj, vma);
+}
+
 static struct dma_buf_ops vs_gem_prime_dmabuf_ops =  {
        .cache_sgt_mapping = true,
        .attach = drm_gem_map_attach,
@@ -243,7 +256,7 @@ static struct dma_buf_ops vs_gem_prime_dmabuf_ops =  {
        .map_dma_buf = drm_gem_map_dma_buf,
        .unmap_dma_buf = drm_gem_unmap_dma_buf,
        .release = drm_gem_dmabuf_release,
-       .mmap = drm_gem_dmabuf_mmap,
+       .mmap = vs_gem_dmabuf_mmap,
        .vmap = drm_gem_dmabuf_vmap,
        .vunmap = drm_gem_dmabuf_vunmap,
        .end_cpu_access = vs_gem_prime_end_cpu_access,
@@ -299,11 +312,11 @@ static const struct drm_gem_object_funcs vs_gem_default_funcs = {
        .vm_ops = &vs_vm_ops,
 };
 
-int vs_gem_dumb_create(struct drm_file *file,
+int vs_gem_dumb_create_old(struct drm_file *file,
                       struct drm_device *dev,
                       struct drm_mode_create_dumb *args)
 {
-       struct vs_drm_private *priv = dev->dev_private;
+       struct vs_drm_device *priv = to_vs_drm_private(dev);
        struct vs_gem_object *vs_obj;
        unsigned int pitch = DIV_ROUND_UP(args->width * args->bpp, 8);
 
index 3a6d7452cb06976aafe2c564559924e7dd4d39ad..a9fc50345105f8aed7329eeeb4e3761c9679dbfd 100644 (file)
@@ -32,7 +32,7 @@ struct vs_gem_object {
        size_t                  size;
        void                    *cookie;
        dma_addr_t              dma_addr;
-       u32                             iova;
+       unsigned long           iova;
        unsigned long   dma_attrs;
        bool                    get_pages;
        struct page             **pages;
@@ -54,7 +54,7 @@ void vs_gem_prime_vunmap(struct drm_gem_object *obj, struct iosys_map *map);
 int vs_gem_prime_mmap(struct drm_gem_object *obj,
                      struct vm_area_struct *vma);
 
-int vs_gem_dumb_create(struct drm_file *file_priv,
+int vs_gem_dumb_create_old(struct drm_file *file_priv,
                       struct drm_device *drm,
                       struct drm_mode_create_dumb *args);
 
index eaf406c1b7c717f8abde45b120c390765ac12a13..2745657efd01d606d757c425c9dc6a448e78859a 100644 (file)
 #include <drm/drm_gem_framebuffer_helper.h>
 
 #include "vs_modeset.h"
+#include "vs_fb.h"
 
 static const struct drm_mode_config_funcs vs_mode_config_funcs = {
-       .fb_create                       = drm_gem_fb_create,
+       .fb_create                       = vs_fb_create,
+       .output_poll_changed     = drm_fb_helper_output_poll_changed,
        .atomic_check            = drm_atomic_helper_check,
        .atomic_commit           = drm_atomic_helper_commit,
 };
index 53580fbe05b14cf3c84c4dde3eb41dd18da13dc1..9592de5b2c48a72e4df7e5496374116dc9f64a82 100644 (file)
@@ -6,8 +6,6 @@
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_blend.h>
-#include <drm/drm_gem_dma_helper.h>
-#include <drm/drm_fb_dma_helper.h>
 #include <drm/drm_framebuffer.h>
 #include <drm/drm_plane.h>
 #include <drm/drm_plane_helper.h>
@@ -15,6 +13,8 @@
 #include "vs_plane.h"
 #include "vs_drv.h"
 #include "vs_dc.h"
+#include "vs_gem.h"
+#include "vs_fb.h"
 
 static void vs_plane_atomic_destroy_state(struct drm_plane *plane,
                                          struct drm_plane_state *state)
@@ -127,10 +127,10 @@ static int vs_plane_atomic_check(struct drm_plane *plane,
        num_planes = vs_get_plane_number(fb);
 
        for (i = 0; i < num_planes; i++) {
-               dma_addr_t dma_addr;
+               struct vs_gem_object *vs_obj;
 
-               dma_addr = drm_fb_dma_get_gem_addr(fb, new_plane_state, i);
-               plane_state->dma_addr[i] = dma_addr;
+               vs_obj = vs_fb_get_gem_obj(fb, i);
+               plane_state->dma_addr[i] = vs_obj->iova + fb->offsets[i];
        }
 
        return vs_dc_check_plane(dc, plane, state);
@@ -154,10 +154,10 @@ static int vs_cursor_plane_atomic_check(struct drm_plane *plane,
        num_planes = vs_get_plane_number(fb);
 
        for (i = 0; i < num_planes; i++) {
-               dma_addr_t dma_addr;
+               struct vs_gem_object *vs_obj;
 
-               dma_addr = drm_fb_dma_get_gem_addr(fb, new_plane_state, i);
-               plane_state->dma_addr[i] = dma_addr;
+               vs_obj = vs_fb_get_gem_obj(fb, i);
+               plane_state->dma_addr[i] = vs_obj->iova + fb->offsets[i];
        }
 
        return vs_dc_check_cursor_plane(dc, plane, state);
@@ -168,8 +168,6 @@ static void vs_plane_atomic_update(struct drm_plane *plane,
 {
        struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
                                                                          plane);
-       struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state,
-                                                                         plane);
 
        unsigned char i, num_planes;
        struct drm_framebuffer *fb;
@@ -183,15 +181,14 @@ static void vs_plane_atomic_update(struct drm_plane *plane,
 
        fb = new_state->fb;
 
-       drm_fb_dma_sync_non_coherent(fb->dev, old_state, new_state);
 
        num_planes = vs_get_plane_number(fb);
 
        for (i = 0; i < num_planes; i++) {
-               dma_addr_t dma_addr;
+               struct vs_gem_object *vs_obj;
 
-               dma_addr = drm_fb_dma_get_gem_addr(fb, new_state, i);
-               plane_state->dma_addr[i] = dma_addr;
+               vs_obj = vs_fb_get_gem_obj(fb, i);
+               plane_state->dma_addr[i] = vs_obj->iova + fb->offsets[i];
        }
 
        vs_dc_update_plane(dc, vs_plane, plane, state);
@@ -202,8 +199,6 @@ static void vs_cursor_plane_atomic_update(struct drm_plane *plane,
 {
        struct drm_plane_state *new_state = drm_atomic_get_new_plane_state(state,
                                                                           plane);
-       struct drm_plane_state *old_state = drm_atomic_get_old_plane_state(state,
-                                                                          plane);
        unsigned char i, num_planes;
        struct drm_framebuffer *fb;
        struct vs_plane *vs_plane = to_vs_plane(plane);
@@ -215,15 +210,14 @@ static void vs_cursor_plane_atomic_update(struct drm_plane *plane,
                return;
 
        fb = new_state->fb;
-       drm_fb_dma_sync_non_coherent(fb->dev, old_state, new_state);
 
        num_planes = vs_get_plane_number(fb);
 
        for (i = 0; i < num_planes; i++) {
-               dma_addr_t dma_addr;
+               struct vs_gem_object *vs_obj;
 
-               dma_addr = drm_fb_dma_get_gem_addr(fb, new_state, i);
-               plane_state->dma_addr[i] = dma_addr;
+               vs_obj = vs_fb_get_gem_obj(fb, i);
+               plane_state->dma_addr[i] = vs_obj->iova + fb->offsets[i];
        }
 
        vs_dc_update_cursor_plane(dc, vs_plane, plane, state);