Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/arm/nvidia Use DRM GEM/CMA helper.



details:   https://anonhg.NetBSD.org/src/rev/af528863a89d
branches:  trunk
changeset: 828677:af528863a89d
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Tue Dec 26 14:54:52 2017 +0000

description:
Use DRM GEM/CMA helper.

diffstat:

 sys/arch/arm/nvidia/files.tegra      |    3 +-
 sys/arch/arm/nvidia/tegra_drm.c      |   82 +----------------
 sys/arch/arm/nvidia/tegra_drm.h      |   26 +----
 sys/arch/arm/nvidia/tegra_drm_fb.c   |    6 +-
 sys/arch/arm/nvidia/tegra_drm_gem.c  |  157 -----------------------------------
 sys/arch/arm/nvidia/tegra_drm_mode.c |   18 ++--
 sys/arch/arm/nvidia/tegra_fb.c       |    8 +-
 7 files changed, 27 insertions(+), 273 deletions(-)

diffs (truncated from 505 to 300 lines):

diff -r 3cfd334b7868 -r af528863a89d sys/arch/arm/nvidia/files.tegra
--- a/sys/arch/arm/nvidia/files.tegra   Tue Dec 26 14:53:12 2017 +0000
+++ b/sys/arch/arm/nvidia/files.tegra   Tue Dec 26 14:54:52 2017 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.tegra,v 1.45 2017/09/26 16:12:45 jmcneill Exp $
+#      $NetBSD: files.tegra,v 1.46 2017/12/26 14:54:52 jmcneill Exp $
 #
 # Configuration info for NVIDIA Tegra ARM Peripherals
 #
@@ -157,7 +157,6 @@
 file   arch/arm/nvidia/tegra_drm.c             tegra_drm
 file   arch/arm/nvidia/tegra_drm_mode.c        tegra_drm
 file   arch/arm/nvidia/tegra_drm_fb.c          tegra_drm
-file   arch/arm/nvidia/tegra_drm_gem.c         tegra_drm
 
 # Framebuffer console
 device tegrafb: tegrafbbus, drmfb, wsemuldisplaydev
diff -r 3cfd334b7868 -r af528863a89d sys/arch/arm/nvidia/tegra_drm.c
--- a/sys/arch/arm/nvidia/tegra_drm.c   Tue Dec 26 14:53:12 2017 +0000
+++ b/sys/arch/arm/nvidia/tegra_drm.c   Tue Dec 26 14:54:52 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tegra_drm.c,v 1.7 2017/04/16 12:28:21 jmcneill Exp $ */
+/* $NetBSD: tegra_drm.c,v 1.8 2017/12/26 14:54:52 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tegra_drm.c,v 1.7 2017/04/16 12:28:21 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tegra_drm.c,v 1.8 2017/12/26 14:54:52 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -57,29 +57,18 @@
 static int     tegra_drm_load(struct drm_device *, unsigned long);
 static int     tegra_drm_unload(struct drm_device *);
 
-static int     tegra_drm_dumb_create(struct drm_file *, struct drm_device *,
-                   struct drm_mode_create_dumb *);
-static int     tegra_drm_dumb_map_offset(struct drm_file *,
-                   struct drm_device *, uint32_t, uint64_t *);
-
-static const struct uvm_pagerops tegra_drm_gem_uvm_ops = {
-       .pgo_reference = drm_gem_pager_reference,
-       .pgo_detach = drm_gem_pager_detach,
-       .pgo_fault = tegra_drm_gem_fault,
-};
-
 static struct drm_driver tegra_drm_driver = {
        .driver_features = DRIVER_MODESET | DRIVER_GEM,
        .dev_priv_size = 0,
        .load = tegra_drm_load,
        .unload = tegra_drm_unload,
 
-       .gem_free_object = tegra_drm_gem_free_object,
+       .gem_free_object = drm_gem_cma_free_object,
        .mmap_object = drm_gem_or_legacy_mmap_object,
-       .gem_uvm_ops = &tegra_drm_gem_uvm_ops,
+       .gem_uvm_ops = &drm_gem_cma_uvm_ops,
 
-       .dumb_create = tegra_drm_dumb_create,
-       .dumb_map_offset = tegra_drm_dumb_map_offset,
+       .dumb_create = drm_gem_cma_dumb_create,
+       .dumb_map_offset = drm_gem_cma_dumb_map_offset,
        .dumb_destroy = drm_gem_dumb_destroy,
 
        .get_vblank_counter = tegra_drm_get_vblank_counter,
@@ -283,62 +272,3 @@
 
        return 0;
 }
-
-static int
-tegra_drm_dumb_create(struct drm_file *file_priv, struct drm_device *ddev,
-    struct drm_mode_create_dumb *args)
-{
-       struct tegra_gem_object *obj;
-       uint32_t handle;
-       int error;
-
-       args->pitch = args->width * ((args->bpp + 7) / 8);
-       args->size = args->pitch * args->height;
-       args->size = roundup(args->size, PAGE_SIZE);
-       args->handle = 0;
-
-       obj = tegra_drm_obj_alloc(ddev, args->size);
-       if (obj == NULL)
-               return -ENOMEM;
-
-       error = drm_gem_handle_create(file_priv, &obj->base, &handle);
-       drm_gem_object_unreference_unlocked(&obj->base);
-       if (error) {
-               tegra_drm_obj_free(obj);
-               return error;
-       }
-
-       args->handle = handle;
-
-       return 0;
-}
-
-static int
-tegra_drm_dumb_map_offset(struct drm_file *file_priv,
-    struct drm_device *ddev, uint32_t handle, uint64_t *offset)
-{
-       struct drm_gem_object *gem_obj;
-       struct tegra_gem_object *obj;
-       int error;
-
-       gem_obj = drm_gem_object_lookup(ddev, file_priv, handle);
-       if (gem_obj == NULL)
-               return -ENOENT;
-
-       obj = to_tegra_gem_obj(gem_obj);
-
-       if (drm_vma_node_has_offset(&obj->base.vma_node) == 0) {
-               error = drm_gem_create_mmap_offset(&obj->base);
-               if (error)
-                       goto done;
-       } else {
-               error = 0;
-       }
-
-       *offset = drm_vma_node_offset_addr(&obj->base.vma_node);
-
-done:
-       drm_gem_object_unreference_unlocked(&obj->base);
-
-       return error;
-}
diff -r 3cfd334b7868 -r af528863a89d sys/arch/arm/nvidia/tegra_drm.h
--- a/sys/arch/arm/nvidia/tegra_drm.h   Tue Dec 26 14:53:12 2017 +0000
+++ b/sys/arch/arm/nvidia/tegra_drm.h   Tue Dec 26 14:54:52 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tegra_drm.h,v 1.7 2016/12/17 12:11:38 maya Exp $ */
+/* $NetBSD: tegra_drm.h,v 1.8 2017/12/26 14:54:52 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -30,6 +30,7 @@
 #define _ARM_TEGRA_DRM_H
 
 #include <drm/drm_fb_helper.h>
+#include <drm/drm_gem_cma_helper.h>
 
 #define DRIVER_AUTHOR          "Jared McNeill"
 
@@ -43,8 +44,6 @@
 
 struct tegra_framebuffer;
 
-struct tegra_gem_object;
-
 struct tegra_drm_softc {
        device_t                sc_dev;
        struct drm_device       *sc_ddev;
@@ -93,7 +92,7 @@
        bool                    enabled;
        struct clk              *clk_parent;
 
-       struct tegra_gem_object *cursor_obj;
+       struct drm_gem_cma_object       *cursor_obj;
        int                     cursor_x;
        int                     cursor_y;
 };
@@ -115,18 +114,9 @@
        bool                    has_audio;
 };
 
-struct tegra_gem_object {
-       struct drm_gem_object   base;
-       bus_dma_tag_t           dmat;
-       bus_dma_segment_t       dmasegs[1];
-       bus_size_t              dmasize;
-       bus_dmamap_t            dmamap;
-       void                    *dmap;
-};
-
 struct tegra_framebuffer {
        struct drm_framebuffer  base;
-       struct tegra_gem_object *obj;
+       struct drm_gem_cma_object *obj;
 };
 
 struct tegra_fbdev {
@@ -155,7 +145,6 @@
 #define to_tegra_connector(x)  container_of(x, struct tegra_connector, base)
 #define to_tegra_framebuffer(x)        container_of(x, struct tegra_framebuffer, base)
 #define to_tegra_fbdev(x)      container_of(x, struct tegra_fbdev, helper)
-#define to_tegra_gem_obj(x)    container_of(x, struct tegra_gem_object, base)
 
 int    tegra_drm_mode_init(struct drm_device *);
 int    tegra_drm_fb_init(struct drm_device *);
@@ -165,11 +154,4 @@
 int    tegra_drm_framebuffer_init(struct drm_device *,
            struct tegra_framebuffer *);
 
-struct tegra_gem_object *tegra_drm_obj_alloc(struct drm_device *, size_t);
-void   tegra_drm_obj_free(struct tegra_gem_object *);
-
-int    tegra_drm_gem_fault(struct uvm_faultinfo *, vaddr_t, struct vm_page **,
-           int, int, vm_prot_t, int);
-void   tegra_drm_gem_free_object(struct drm_gem_object *);
-
 #endif /* _ARM_TEGRA_DRM_H */
diff -r 3cfd334b7868 -r af528863a89d sys/arch/arm/nvidia/tegra_drm_fb.c
--- a/sys/arch/arm/nvidia/tegra_drm_fb.c        Tue Dec 26 14:53:12 2017 +0000
+++ b/sys/arch/arm/nvidia/tegra_drm_fb.c        Tue Dec 26 14:54:52 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tegra_drm_fb.c,v 1.5 2017/06/01 02:45:05 chs Exp $ */
+/* $NetBSD: tegra_drm_fb.c,v 1.6 2017/12/26 14:54:52 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tegra_drm_fb.c,v 1.5 2017/06/01 02:45:05 chs Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tegra_drm_fb.c,v 1.6 2017/12/26 14:54:52 jmcneill Exp $");
 
 #include <drm/drmP.h>
 #include <drm/drm_crtc.h>
@@ -125,7 +125,7 @@
 
        const size_t size = roundup(height * pitch, PAGE_SIZE);
 
-       tegra_fb->obj = tegra_drm_obj_alloc(ddev, size);
+       tegra_fb->obj = drm_gem_cma_create(ddev, size);
        if (tegra_fb->obj == NULL)
                return -ENOMEM;
 
diff -r 3cfd334b7868 -r af528863a89d sys/arch/arm/nvidia/tegra_drm_gem.c
--- a/sys/arch/arm/nvidia/tegra_drm_gem.c       Tue Dec 26 14:53:12 2017 +0000
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,157 +0,0 @@
-/* $NetBSD: tegra_drm_gem.c,v 1.3 2017/06/01 02:45:05 chs Exp $ */
-
-/*-
- * Copyright (c) 2015 Jared D. McNeill <jmcneill%invisible.ca@localhost>
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tegra_drm_gem.c,v 1.3 2017/06/01 02:45:05 chs Exp $");
-
-#include <drm/drmP.h>
-#include <uvm/uvm.h>
-
-#include <arm/nvidia/tegra_drm.h>
-
-struct tegra_gem_object *
-tegra_drm_obj_alloc(struct drm_device *ddev, size_t size)
-{
-       struct tegra_drm_softc * const sc = tegra_drm_private(ddev);
-       struct tegra_gem_object *obj;
-       int error, nsegs;
-
-       obj = kmem_zalloc(sizeof(*obj), KM_SLEEP);
-       obj->dmat = sc->sc_dmat;
-       obj->dmasize = size;
-
-        error = bus_dmamem_alloc(obj->dmat, obj->dmasize, PAGE_SIZE, 0,
-           obj->dmasegs, 1, &nsegs, BUS_DMA_WAITOK);
-       if (error)
-               goto failed;
-       error = bus_dmamem_map(obj->dmat, obj->dmasegs, nsegs,
-           obj->dmasize, &obj->dmap, BUS_DMA_WAITOK | BUS_DMA_COHERENT);
-       if (error)
-               goto free;
-       error = bus_dmamap_create(obj->dmat, obj->dmasize, 1,
-           obj->dmasize, 0, BUS_DMA_WAITOK, &obj->dmamap);
-       if (error)
-               goto unmap;
-       error = bus_dmamap_load(obj->dmat, obj->dmamap, obj->dmap,
-           obj->dmasize, NULL, BUS_DMA_WAITOK);
-       if (error)



Home | Main Index | Thread Index | Old Index