aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Hellstrom <thellstrom@vmware.com>2013-11-13 04:50:46 -0500
committerThomas Hellstrom <thellstrom@vmware.com>2013-11-18 07:11:53 -0500
commit69977ff55eac7fc26fb78de5ec1d9a9ab802d9fd (patch)
treef0002adc0a8bc0b417b7b99e8f405e53dc267a25
parent65981f7681abdf92b25942222b629b9c512d0705 (diff)
drm/vmwgfx: Hook up the prime ioctls
Also provide a completely dumb dma-buf ops implementation. Once we have other virtual dma-buf aware devices, we need to provide something better. Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com> Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
-rw-r--r--drivers/gpu/drm/vmwgfx/Makefile2
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.c7
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_drv.h14
-rw-r--r--drivers/gpu/drm/vmwgfx/vmwgfx_prime.c137
4 files changed, 157 insertions, 3 deletions
diff --git a/drivers/gpu/drm/vmwgfx/Makefile b/drivers/gpu/drm/vmwgfx/Makefile
index 2cc6cd91ac11..9f8b690bcf52 100644
--- a/drivers/gpu/drm/vmwgfx/Makefile
+++ b/drivers/gpu/drm/vmwgfx/Makefile
@@ -6,6 +6,6 @@ vmwgfx-y := vmwgfx_execbuf.o vmwgfx_gmr.o vmwgfx_kms.o vmwgfx_drv.o \
6 vmwgfx_fifo.o vmwgfx_irq.o vmwgfx_ldu.o vmwgfx_ttm_glue.o \ 6 vmwgfx_fifo.o vmwgfx_irq.o vmwgfx_ldu.o vmwgfx_ttm_glue.o \
7 vmwgfx_overlay.o vmwgfx_marker.o vmwgfx_gmrid_manager.o \ 7 vmwgfx_overlay.o vmwgfx_marker.o vmwgfx_gmrid_manager.o \
8 vmwgfx_fence.o vmwgfx_dmabuf.o vmwgfx_scrn.o vmwgfx_context.o \ 8 vmwgfx_fence.o vmwgfx_dmabuf.o vmwgfx_scrn.o vmwgfx_context.o \
9 vmwgfx_surface.o 9 vmwgfx_surface.o vmwgfx_prime.o
10 10
11obj-$(CONFIG_DRM_VMWGFX) := vmwgfx.o 11obj-$(CONFIG_DRM_VMWGFX) := vmwgfx.o
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 20d5485eaf98..c7a549694e59 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -677,7 +677,7 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
677 } 677 }
678 678
679 dev_priv->tdev = ttm_object_device_init 679 dev_priv->tdev = ttm_object_device_init
680 (dev_priv->mem_global_ref.object, 12); 680 (dev_priv->mem_global_ref.object, 12, &vmw_prime_dmabuf_ops);
681 681
682 if (unlikely(dev_priv->tdev == NULL)) { 682 if (unlikely(dev_priv->tdev == NULL)) {
683 DRM_ERROR("Unable to initialize TTM object management.\n"); 683 DRM_ERROR("Unable to initialize TTM object management.\n");
@@ -1210,7 +1210,7 @@ static const struct file_operations vmwgfx_driver_fops = {
1210 1210
1211static struct drm_driver driver = { 1211static struct drm_driver driver = {
1212 .driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED | 1212 .driver_features = DRIVER_HAVE_IRQ | DRIVER_IRQ_SHARED |
1213 DRIVER_MODESET, 1213 DRIVER_MODESET | DRIVER_PRIME,
1214 .load = vmw_driver_load, 1214 .load = vmw_driver_load,
1215 .unload = vmw_driver_unload, 1215 .unload = vmw_driver_unload,
1216 .lastclose = vmw_lastclose, 1216 .lastclose = vmw_lastclose,
@@ -1235,6 +1235,9 @@ static struct drm_driver driver = {
1235 .dumb_map_offset = vmw_dumb_map_offset, 1235 .dumb_map_offset = vmw_dumb_map_offset,
1236 .dumb_destroy = vmw_dumb_destroy, 1236 .dumb_destroy = vmw_dumb_destroy,
1237 1237
1238 .prime_fd_to_handle = vmw_prime_fd_to_handle,
1239 .prime_handle_to_fd = vmw_prime_handle_to_fd,
1240
1238 .fops = &vmwgfx_driver_fops, 1241 .fops = &vmwgfx_driver_fops,
1239 .name = VMWGFX_DRIVER_NAME, 1242 .name = VMWGFX_DRIVER_NAME,
1240 .desc = VMWGFX_DRIVER_DESC, 1243 .desc = VMWGFX_DRIVER_DESC,
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index e401d5dbcb96..db85985c7086 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -819,6 +819,20 @@ int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
819extern const struct ttm_mem_type_manager_func vmw_gmrid_manager_func; 819extern const struct ttm_mem_type_manager_func vmw_gmrid_manager_func;
820 820
821/** 821/**
822 * Prime - vmwgfx_prime.c
823 */
824
825extern const struct dma_buf_ops vmw_prime_dmabuf_ops;
826extern int vmw_prime_fd_to_handle(struct drm_device *dev,
827 struct drm_file *file_priv,
828 int fd, u32 *handle);
829extern int vmw_prime_handle_to_fd(struct drm_device *dev,
830 struct drm_file *file_priv,
831 uint32_t handle, uint32_t flags,
832 int *prime_fd);
833
834
835/**
822 * Inline helper functions 836 * Inline helper functions
823 */ 837 */
824 838
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_prime.c b/drivers/gpu/drm/vmwgfx/vmwgfx_prime.c
new file mode 100644
index 000000000000..31fe32d8d65a
--- /dev/null
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_prime.c
@@ -0,0 +1,137 @@
1/**************************************************************************
2 *
3 * Copyright © 2013 VMware, Inc., Palo Alto, CA., USA
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27/*
28 * Authors:
29 * Thomas Hellstrom <thellstrom@vmware.com>
30 *
31 */
32
33#include "vmwgfx_drv.h"
34#include <linux/dma-buf.h>
35#include <drm/ttm/ttm_object.h>
36
37/*
38 * DMA-BUF attach- and mapping methods. No need to implement
39 * these until we have other virtual devices use them.
40 */
41
42static int vmw_prime_map_attach(struct dma_buf *dma_buf,
43 struct device *target_dev,
44 struct dma_buf_attachment *attach)
45{
46 return -ENOSYS;
47}
48
49static void vmw_prime_map_detach(struct dma_buf *dma_buf,
50 struct dma_buf_attachment *attach)
51{
52}
53
54static struct sg_table *vmw_prime_map_dma_buf(struct dma_buf_attachment *attach,
55 enum dma_data_direction dir)
56{
57 return ERR_PTR(-ENOSYS);
58}
59
60static void vmw_prime_unmap_dma_buf(struct dma_buf_attachment *attach,
61 struct sg_table *sgb,
62 enum dma_data_direction dir)
63{
64}
65
66static void *vmw_prime_dmabuf_vmap(struct dma_buf *dma_buf)
67{
68 return NULL;
69}
70
71static void vmw_prime_dmabuf_vunmap(struct dma_buf *dma_buf, void *vaddr)
72{
73}
74
75static void *vmw_prime_dmabuf_kmap_atomic(struct dma_buf *dma_buf,
76 unsigned long page_num)
77{
78 return NULL;
79}
80
81static void vmw_prime_dmabuf_kunmap_atomic(struct dma_buf *dma_buf,
82 unsigned long page_num, void *addr)
83{
84
85}
86static void *vmw_prime_dmabuf_kmap(struct dma_buf *dma_buf,
87 unsigned long page_num)
88{
89 return NULL;
90}
91
92static void vmw_prime_dmabuf_kunmap(struct dma_buf *dma_buf,
93 unsigned long page_num, void *addr)
94{
95
96}
97
98static int vmw_prime_dmabuf_mmap(struct dma_buf *dma_buf,
99 struct vm_area_struct *vma)
100{
101 WARN_ONCE(true, "Attempted use of dmabuf mmap. Bad.\n");
102 return -ENOSYS;
103}
104
105const struct dma_buf_ops vmw_prime_dmabuf_ops = {
106 .attach = vmw_prime_map_attach,
107 .detach = vmw_prime_map_detach,
108 .map_dma_buf = vmw_prime_map_dma_buf,
109 .unmap_dma_buf = vmw_prime_unmap_dma_buf,
110 .release = NULL,
111 .kmap = vmw_prime_dmabuf_kmap,
112 .kmap_atomic = vmw_prime_dmabuf_kmap_atomic,
113 .kunmap = vmw_prime_dmabuf_kunmap,
114 .kunmap_atomic = vmw_prime_dmabuf_kunmap_atomic,
115 .mmap = vmw_prime_dmabuf_mmap,
116 .vmap = vmw_prime_dmabuf_vmap,
117 .vunmap = vmw_prime_dmabuf_vunmap,
118};
119
120int vmw_prime_fd_to_handle(struct drm_device *dev,
121 struct drm_file *file_priv,
122 int fd, u32 *handle)
123{
124 struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
125
126 return ttm_prime_fd_to_handle(tfile, fd, handle);
127}
128
129int vmw_prime_handle_to_fd(struct drm_device *dev,
130 struct drm_file *file_priv,
131 uint32_t handle, uint32_t flags,
132 int *prime_fd)
133{
134 struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
135
136 return ttm_prime_handle_to_fd(tfile, handle, flags, prime_fd);
137}