1 /* $NetBSD: vmwgfx_prime.c,v 1.3 2021/12/18 23:45:45 riastradh Exp $ */
2
3 // SPDX-License-Identifier: GPL-2.0 OR MIT
4 /**************************************************************************
5 *
6 * Copyright 2013 VMware, Inc., Palo Alto, CA., USA
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
18 * of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
23 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
24 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
25 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
26 * USE OR OTHER DEALINGS IN THE SOFTWARE.
27 *
28 **************************************************************************/
29 /*
30 * Authors:
31 * Thomas Hellstrom <thellstrom@vmware.com>
32 *
33 */
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: vmwgfx_prime.c,v 1.3 2021/12/18 23:45:45 riastradh Exp $");
37
38 #include "vmwgfx_drv.h"
39 #include "ttm_object.h"
40 #include <linux/dma-buf.h>
41
42 /*
43 * DMA-BUF attach- and mapping methods. No need to implement
44 * these until we have other virtual devices use them.
45 */
46
vmw_prime_map_attach(struct dma_buf * dma_buf,struct dma_buf_attachment * attach)47 static int vmw_prime_map_attach(struct dma_buf *dma_buf,
48 struct dma_buf_attachment *attach)
49 {
50 return -ENOSYS;
51 }
52
vmw_prime_map_detach(struct dma_buf * dma_buf,struct dma_buf_attachment * attach)53 static void vmw_prime_map_detach(struct dma_buf *dma_buf,
54 struct dma_buf_attachment *attach)
55 {
56 }
57
vmw_prime_map_dma_buf(struct dma_buf_attachment * attach,enum dma_data_direction dir)58 static struct sg_table *vmw_prime_map_dma_buf(struct dma_buf_attachment *attach,
59 enum dma_data_direction dir)
60 {
61 return ERR_PTR(-ENOSYS);
62 }
63
vmw_prime_unmap_dma_buf(struct dma_buf_attachment * attach,struct sg_table * sgb,enum dma_data_direction dir)64 static void vmw_prime_unmap_dma_buf(struct dma_buf_attachment *attach,
65 struct sg_table *sgb,
66 enum dma_data_direction dir)
67 {
68 }
69
70 const struct dma_buf_ops vmw_prime_dmabuf_ops = {
71 .attach = vmw_prime_map_attach,
72 .detach = vmw_prime_map_detach,
73 .map_dma_buf = vmw_prime_map_dma_buf,
74 .unmap_dma_buf = vmw_prime_unmap_dma_buf,
75 .release = NULL,
76 };
77
vmw_prime_fd_to_handle(struct drm_device * dev,struct drm_file * file_priv,int fd,u32 * handle)78 int vmw_prime_fd_to_handle(struct drm_device *dev,
79 struct drm_file *file_priv,
80 int fd, u32 *handle)
81 {
82 struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
83
84 return ttm_prime_fd_to_handle(tfile, fd, handle);
85 }
86
vmw_prime_handle_to_fd(struct drm_device * dev,struct drm_file * file_priv,uint32_t handle,uint32_t flags,int * prime_fd)87 int vmw_prime_handle_to_fd(struct drm_device *dev,
88 struct drm_file *file_priv,
89 uint32_t handle, uint32_t flags,
90 int *prime_fd)
91 {
92 struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
93
94 return ttm_prime_handle_to_fd(tfile, handle, flags, prime_fd);
95 }
96