Merge tag 'vfs-6.10.rw' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs
[sfrench/cifs-2.6.git] / drivers / gpu / drm / vmwgfx / vmwgfx_prime.c
1 // SPDX-License-Identifier: GPL-2.0 OR MIT
2 /**************************************************************************
3  *
4  * Copyright 2013 VMware, Inc., Palo Alto, CA., USA
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 "ttm_object.h"
35 #include <linux/dma-buf.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
42 static int vmw_prime_map_attach(struct dma_buf *dma_buf,
43                                 struct dma_buf_attachment *attach)
44 {
45         return -ENOSYS;
46 }
47
48 static void vmw_prime_map_detach(struct dma_buf *dma_buf,
49                                  struct dma_buf_attachment *attach)
50 {
51 }
52
53 static struct sg_table *vmw_prime_map_dma_buf(struct dma_buf_attachment *attach,
54                                               enum dma_data_direction dir)
55 {
56         return ERR_PTR(-ENOSYS);
57 }
58
59 static void vmw_prime_unmap_dma_buf(struct dma_buf_attachment *attach,
60                                     struct sg_table *sgb,
61                                     enum dma_data_direction dir)
62 {
63 }
64
65 const struct dma_buf_ops vmw_prime_dmabuf_ops =  {
66         .attach = vmw_prime_map_attach,
67         .detach = vmw_prime_map_detach,
68         .map_dma_buf = vmw_prime_map_dma_buf,
69         .unmap_dma_buf = vmw_prime_unmap_dma_buf,
70         .release = NULL,
71 };
72
73 int vmw_prime_fd_to_handle(struct drm_device *dev,
74                            struct drm_file *file_priv,
75                            int fd, u32 *handle)
76 {
77         struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
78         int ret = ttm_prime_fd_to_handle(tfile, fd, handle);
79
80         if (ret)
81                 ret = drm_gem_prime_fd_to_handle(dev, file_priv, fd, handle);
82
83         return ret;
84 }
85
86 int vmw_prime_handle_to_fd(struct drm_device *dev,
87                            struct drm_file *file_priv,
88                            uint32_t handle, uint32_t flags,
89                            int *prime_fd)
90 {
91         struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile;
92         int ret;
93
94         if (handle > VMWGFX_NUM_MOB)
95                 ret = ttm_prime_handle_to_fd(tfile, handle, flags, prime_fd);
96         else
97                 ret = drm_gem_prime_handle_to_fd(dev, file_priv, handle, flags, prime_fd);
98
99         return ret;
100 }