From 2831ee2b5aea4df4633167176bdf6437fca89702 Mon Sep 17 00:00:00 2001 From: Vasiliy Ulyanov Date: Fri, 27 Mar 2015 14:44:35 +0300 Subject: [PATCH] VIGS: add base dmabuf import/export support Change-Id: I04b3c9558d99b096a8a54b57ab89a7a8b5b225b6 Signed-off-by: Vasiliy Ulyanov --- drivers/gpu/drm/vigs/Makefile | 2 +- drivers/gpu/drm/vigs/vigs_device.c | 4 +- drivers/gpu/drm/vigs/vigs_dmabuf.c | 206 +++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/vigs/vigs_dmabuf.h | 29 ++++++ drivers/gpu/drm/vigs/vigs_driver.c | 9 +- drivers/gpu/drm/vigs/vigs_prime.c | 115 --------------------- 6 files changed, 246 insertions(+), 119 deletions(-) create mode 100644 drivers/gpu/drm/vigs/vigs_dmabuf.c create mode 100644 drivers/gpu/drm/vigs/vigs_dmabuf.h delete mode 100644 drivers/gpu/drm/vigs/vigs_prime.c diff --git a/drivers/gpu/drm/vigs/Makefile b/drivers/gpu/drm/vigs/Makefile index 008fd72..2ba4d75 100644 --- a/drivers/gpu/drm/vigs/Makefile +++ b/drivers/gpu/drm/vigs/Makefile @@ -21,6 +21,6 @@ vigs_drm-y := main.o \ vigs_file.o \ vigs_plane.o \ vigs_dp.o \ - vigs_prime.o + vigs_dmabuf.o obj-$(CONFIG_DRM_VIGS) += vigs_drm.o diff --git a/drivers/gpu/drm/vigs/vigs_device.c b/drivers/gpu/drm/vigs/vigs_device.c index 7ed84fd..e944f4c 100644 --- a/drivers/gpu/drm/vigs/vigs_device.c +++ b/drivers/gpu/drm/vigs/vigs_device.c @@ -12,7 +12,7 @@ #include "vigs_dp.h" #include -extern const struct dma_buf_ops vigs_prime_dmabuf_ops; +extern const struct dma_buf_ops vigs_dmabuf_ops; static void vigs_device_mman_vram_to_gpu(void *user_data, struct ttm_buffer_object *bo) @@ -159,7 +159,7 @@ int vigs_device_init(struct vigs_device *vigs_dev, } vigs_dev->obj_dev = ttm_object_device_init(vigs_dev->mman->mem_global_ref.object, - 12, &vigs_prime_dmabuf_ops); + 12, &vigs_dmabuf_ops); if (!vigs_dev->obj_dev) { DRM_ERROR("Unable to initialize obj_dev\n"); diff --git a/drivers/gpu/drm/vigs/vigs_dmabuf.c b/drivers/gpu/drm/vigs/vigs_dmabuf.c new file mode 100644 index 0000000..ba47bca --- /dev/null +++ b/drivers/gpu/drm/vigs/vigs_dmabuf.c @@ -0,0 +1,206 @@ +/************************************************************************** + * + * Based on drivers/gpu/drm/vmwgfx/vmwgfx_prime.c + * + * Copyright © 2013 VMware, Inc., Palo Alto, CA., USA + * Copyright © 2014 Samsung Electronics Co., Ltd. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL + * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + * USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "vigs_gem.h" +#include + +static int vigs_dmabuf_attach(struct dma_buf *dma_buf, + struct device *target_dev, + struct dma_buf_attachment *attach) +{ + DRM_DEBUG_PRIME("enter"); + + return -ENOSYS; +} + +static void vigs_dmabuf_detach(struct dma_buf *dma_buf, + struct dma_buf_attachment *attach) +{ + DRM_DEBUG_PRIME("enter"); +} + +static struct sg_table *vigs_dmabuf_map(struct dma_buf_attachment *attach, + enum dma_data_direction dir) +{ + DRM_DEBUG_PRIME("enter"); + + return ERR_PTR(-ENOSYS); +} + +static void vigs_dmabuf_unmap(struct dma_buf_attachment *attach, + struct sg_table *sgb, + enum dma_data_direction dir) +{ + DRM_DEBUG_PRIME("enter"); +} + +static void *vigs_dmabuf_kmap(struct dma_buf *dma_buf, + unsigned long page_num) +{ + DRM_DEBUG_PRIME("enter"); + + return NULL; +} + +static void *vigs_dmabuf_kmap_atomic(struct dma_buf *dma_buf, + unsigned long page_num) +{ + DRM_DEBUG_PRIME("enter"); + + return NULL; +} + +static void vigs_dmabuf_kunmap(struct dma_buf *dma_buf, + unsigned long page_num, + void *addr) +{ + DRM_DEBUG_PRIME("enter"); +} + +static void vigs_dmabuf_kunmap_atomic(struct dma_buf *dma_buf, + unsigned long page_num, + void *addr) +{ + DRM_DEBUG_PRIME("enter"); +} + +static int vigs_dmabuf_mmap(struct dma_buf *dma_buf, + struct vm_area_struct *vma) +{ + DRM_DEBUG_PRIME("enter"); + + return -ENOSYS; +} + +static void *vigs_dmabuf_vmap(struct dma_buf *dma_buf) +{ + DRM_DEBUG_PRIME("enter"); + + return NULL; +} + +static void vigs_dmabuf_vunmap(struct dma_buf *dma_buf, + void *vaddr) +{ + DRM_DEBUG_PRIME("enter"); +} + +static int vigs_dmabuf_begin_cpu_access(struct dma_buf *dma_buf, + size_t start, + size_t length, + enum dma_data_direction direction) +{ + DRM_DEBUG_PRIME("enter"); + + return 0; +} + +static void vigs_dmabuf_end_cpu_access(struct dma_buf *dma_buf, + size_t start, + size_t length, + enum dma_data_direction direction) +{ + DRM_DEBUG_PRIME("enter"); +} + +const struct dma_buf_ops vigs_dmabuf_ops = { + .attach = vigs_dmabuf_attach, + .detach = vigs_dmabuf_detach, + .map_dma_buf = vigs_dmabuf_map, + .unmap_dma_buf = vigs_dmabuf_unmap, + .release = drm_gem_dmabuf_release, + .kmap = vigs_dmabuf_kmap, + .kmap_atomic = vigs_dmabuf_kmap_atomic, + .kunmap = vigs_dmabuf_kunmap, + .kunmap_atomic = vigs_dmabuf_kunmap_atomic, + .mmap = vigs_dmabuf_mmap, + .vmap = vigs_dmabuf_vmap, + .vunmap = vigs_dmabuf_vunmap, + .begin_cpu_access = vigs_dmabuf_begin_cpu_access, + .end_cpu_access = vigs_dmabuf_end_cpu_access, +}; + +int vigs_prime_handle_to_fd(struct drm_device *dev, + struct drm_file *file_priv, + uint32_t handle, + uint32_t flags, + int *prime_fd) +{ + DRM_DEBUG_PRIME("enter"); + + return drm_gem_prime_handle_to_fd(dev, file_priv, handle, flags, prime_fd); +} + +int vigs_prime_fd_to_handle(struct drm_device *dev, + struct drm_file *file_priv, + int fd, + uint32_t *handle) +{ + DRM_DEBUG_PRIME("enter"); + + return drm_gem_prime_fd_to_handle(dev, file_priv, fd, handle); +} + +struct dma_buf *vigs_dmabuf_prime_export(struct drm_device *dev, + struct drm_gem_object *gem_obj, + int flags) +{ + struct vigs_gem_object *vigs_gem = gem_to_vigs_gem(gem_obj); + + DRM_DEBUG_PRIME("enter"); + + return dma_buf_export(gem_obj, + &vigs_dmabuf_ops, + vigs_gem_size(vigs_gem), + flags); +} + +struct drm_gem_object *vigs_dmabuf_prime_import(struct drm_device *dev, + struct dma_buf *dma_buf) +{ + struct drm_gem_object *obj; + + DRM_DEBUG_PRIME("enter"); + + if (dma_buf->ops == &vigs_dmabuf_ops) { + obj = dma_buf->priv; + + if (obj->dev == dev) { + /* + * Importing dmabuf exported from our own gem increases + * refcount on gem itself instead of f_count of dmabuf. + */ + drm_gem_object_reference(obj); + return obj; + } + } + + return ERR_PTR(-ENOSYS); +} diff --git a/drivers/gpu/drm/vigs/vigs_dmabuf.h b/drivers/gpu/drm/vigs/vigs_dmabuf.h new file mode 100644 index 0000000..6e0f819 --- /dev/null +++ b/drivers/gpu/drm/vigs/vigs_dmabuf.h @@ -0,0 +1,29 @@ +#ifndef _VIGS_DMABUF_H_ +#define _VIGS_DMABUF_H_ + +#include + +struct drm_device; +struct drm_file; +struct dma_buf; +struct drm_gem_object; + +int vigs_prime_handle_to_fd(struct drm_device *dev, + struct drm_file *file_priv, + uint32_t handle, + uint32_t flags, + int *prime_fd); + +int vigs_prime_fd_to_handle(struct drm_device *dev, + struct drm_file *file_priv, + int fd, + uint32_t *handle); + +struct dma_buf *vigs_dmabuf_prime_export(struct drm_device *dev, + struct drm_gem_object *gem_obj, + int flags); + +struct drm_gem_object *vigs_dmabuf_prime_import(struct drm_device *dev, + struct dma_buf *dma_buf); + +#endif /* _VIGS_DMABUF_H_ */ diff --git a/drivers/gpu/drm/vigs/vigs_driver.c b/drivers/gpu/drm/vigs/vigs_driver.c index b67c128..4b10f7c 100644 --- a/drivers/gpu/drm/vigs/vigs_driver.c +++ b/drivers/gpu/drm/vigs/vigs_driver.c @@ -11,6 +11,7 @@ #include "vigs_plane.h" #include "vigs_mman.h" #include "vigs_dp.h" +#include "vigs_dmabuf.h" #include #include #include @@ -204,7 +205,7 @@ static struct drm_driver vigs_drm_driver = { .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | - DRIVER_RENDER, + DRIVER_RENDER | DRIVER_PRIME, .load = vigs_drm_load, .unload = vigs_drm_unload, .open = vigs_drm_open, @@ -218,6 +219,12 @@ static struct drm_driver vigs_drm_driver = .gem_free_object = vigs_gem_free_object, .gem_open_object = vigs_gem_open_object, .gem_close_object = vigs_gem_close_object, + + .prime_handle_to_fd = vigs_prime_handle_to_fd, + .prime_fd_to_handle = vigs_prime_fd_to_handle, + .gem_prime_export = vigs_dmabuf_prime_export, + .gem_prime_import = vigs_dmabuf_prime_import, + .dumb_create = vigs_gem_dumb_create, .dumb_map_offset = vigs_gem_dumb_map_offset, .dumb_destroy = vigs_gem_dumb_destroy, diff --git a/drivers/gpu/drm/vigs/vigs_prime.c b/drivers/gpu/drm/vigs/vigs_prime.c deleted file mode 100644 index e6409c1..0000000 --- a/drivers/gpu/drm/vigs/vigs_prime.c +++ /dev/null @@ -1,115 +0,0 @@ -/************************************************************************** - * - * Based on drivers/gpu/drm/vmwgfx/vmwgfx_prime.c - * - * Copyright © 2013 VMware, Inc., Palo Alto, CA., USA - * Copyright © 2014 Samsung Electronics Co., Ltd. - * All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sub license, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial portions - * of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL - * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - * USE OR OTHER DEALINGS IN THE SOFTWARE. - * - **************************************************************************/ - -#include -#include - -/* - * DMA-BUF attach- and mapping methods. No need to implement - * these until we have other virtual devices use them. - */ - -static int vigs_prime_map_attach(struct dma_buf *dma_buf, - struct device *target_dev, - struct dma_buf_attachment *attach) -{ - return -ENOSYS; -} - -static void vigs_prime_map_detach(struct dma_buf *dma_buf, - struct dma_buf_attachment *attach) -{ -} - -static struct sg_table *vigs_prime_map_dma_buf(struct dma_buf_attachment *attach, - enum dma_data_direction dir) -{ - return ERR_PTR(-ENOSYS); -} - -static void vigs_prime_unmap_dma_buf(struct dma_buf_attachment *attach, - struct sg_table *sgb, - enum dma_data_direction dir) -{ -} - -static void *vigs_prime_dmabuf_vmap(struct dma_buf *dma_buf) -{ - return NULL; -} - -static void vigs_prime_dmabuf_vunmap(struct dma_buf *dma_buf, void *vaddr) -{ -} - -static void *vigs_prime_dmabuf_kmap_atomic(struct dma_buf *dma_buf, - unsigned long page_num) -{ - return NULL; -} - -static void vigs_prime_dmabuf_kunmap_atomic(struct dma_buf *dma_buf, - unsigned long page_num, void *addr) -{ - -} -static void *vigs_prime_dmabuf_kmap(struct dma_buf *dma_buf, - unsigned long page_num) -{ - return NULL; -} - -static void vigs_prime_dmabuf_kunmap(struct dma_buf *dma_buf, - unsigned long page_num, void *addr) -{ - -} - -static int vigs_prime_dmabuf_mmap(struct dma_buf *dma_buf, - struct vm_area_struct *vma) -{ - WARN_ONCE(true, "Attempted use of dmabuf mmap. Bad.\n"); - return -ENOSYS; -} - -const struct dma_buf_ops vigs_prime_dmabuf_ops = { - .attach = vigs_prime_map_attach, - .detach = vigs_prime_map_detach, - .map_dma_buf = vigs_prime_map_dma_buf, - .unmap_dma_buf = vigs_prime_unmap_dma_buf, - .release = NULL, - .kmap = vigs_prime_dmabuf_kmap, - .kmap_atomic = vigs_prime_dmabuf_kmap_atomic, - .kunmap = vigs_prime_dmabuf_kunmap, - .kunmap_atomic = vigs_prime_dmabuf_kunmap_atomic, - .mmap = vigs_prime_dmabuf_mmap, - .vmap = vigs_prime_dmabuf_vmap, - .vunmap = vigs_prime_dmabuf_vunmap, -}; -- 2.7.4