• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**************************************************************************
2  *
3  * Copyright (C) 2020 Chromium
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a
6  * copy of this software and associated documentation files (the "Software"),
7  * to deal in the Software without restriction, including without limitation
8  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9  * and/or sell copies of the Software, and to permit persons to whom the
10  * Software is furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be included
13  * in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21  * OTHER DEALINGS IN THE SOFTWARE.
22  *
23  **************************************************************************/
24 
25 #ifndef VIRGL_RESOURCE_H
26 #define VIRGL_RESOURCE_H
27 
28 #include <stdint.h>
29 
30 struct iovec;
31 struct pipe_resource;
32 
33 enum virgl_resource_fd_type {
34    VIRGL_RESOURCE_FD_DMABUF,
35    VIRGL_RESOURCE_FD_OPAQUE,
36 
37    VIRGL_RESOURCE_FD_INVALID = -1,
38 };
39 
40 /**
41  * A global cross-context resource.  A virgl_resource is not directly usable
42  * by renderer contexts, but must be attached and imported into renderer
43  * contexts to create context objects first.  For example, it can be attached
44  * and imported into a vrend_decode_ctx to create a vrend_resource.
45  *
46  * It is also possible to create a virgl_resource from a context object.
47  *
48  * The underlying storage of a virgl_resource is provided by a pipe_resource
49  * and/or a fd.  When it is provided by a pipe_resource, the virgl_resource is
50  * said to be typed because pipe_resource also provides the type information.
51  *
52  * Conventional resources are always typed.  Blob resources by definition do
53  * not have nor need type information, but those created from vrend_decode_ctx
54  * objects are typed.  That should be considered a convenience rather than
55  * something to be relied upon.  Contexts must not assume that every resource is
56  * typed when interop is expected.
57  */
58 struct virgl_resource {
59    uint32_t res_id;
60 
61    struct pipe_resource *pipe_resource;
62 
63    enum virgl_resource_fd_type fd_type;
64    int fd;
65 
66    const struct iovec *iov;
67    int iov_count;
68 
69    uint32_t map_info;
70 
71    void *private_data;
72 };
73 
74 struct virgl_resource_pipe_callbacks {
75    void *data;
76 
77    void (*unref)(struct pipe_resource *pres, void *data);
78 
79    void (*attach_iov)(struct pipe_resource *pres,
80                       const struct iovec *iov,
81                       int iov_count,
82                       void *data);
83    void (*detach_iov)(struct pipe_resource *pres, void *data);
84 
85    enum virgl_resource_fd_type (*export_fd)(struct pipe_resource *pres,
86                                             int *fd,
87                                             void *data);
88 };
89 
90 int
91 virgl_resource_table_init(const struct virgl_resource_pipe_callbacks *callbacks);
92 
93 void
94 virgl_resource_table_cleanup(void);
95 
96 void
97 virgl_resource_table_reset(void);
98 
99 struct virgl_resource *
100 virgl_resource_create_from_pipe(uint32_t res_id,
101                                 struct pipe_resource *pres,
102                                 const struct iovec *iov,
103                                 int iov_count);
104 
105 struct virgl_resource *
106 virgl_resource_create_from_fd(uint32_t res_id,
107                               enum virgl_resource_fd_type fd_type,
108                               int fd,
109                               const struct iovec *iov,
110                               int iov_count);
111 
112 struct virgl_resource *
113 virgl_resource_create_from_iov(uint32_t res_id,
114                                const struct iovec *iov,
115                                int iov_count);
116 
117 void
118 virgl_resource_remove(uint32_t res_id);
119 
120 struct virgl_resource *
121 virgl_resource_lookup(uint32_t res_id);
122 
123 int
124 virgl_resource_attach_iov(struct virgl_resource *res,
125                           const struct iovec *iov,
126                           int iov_count);
127 
128 void
129 virgl_resource_detach_iov(struct virgl_resource *res);
130 
131 enum virgl_resource_fd_type
132 virgl_resource_export_fd(struct virgl_resource *res, int *fd);
133 
134 #endif /* VIRGL_RESOURCE_H */
135