1 /*
2  * Copyright 2014, 2015 Red Hat.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * on the rights to use, copy, modify, merge, publish, distribute, sub
8  * license, and/or sell copies of the Software, and to permit persons to whom
9  * the Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18  * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21  * USE OR OTHER DEALINGS IN THE SOFTWARE.
22  */
23 #ifndef VIRGL_DRM_WINSYS_H
24 #define VIRGL_DRM_WINSYS_H
25 
26 #include <stdint.h>
27 #include "os/os_thread.h"
28 #include "pipe/p_state.h"
29 #include "util/list.h"
30 
31 #include "virgl/virgl_winsys.h"
32 #include "virgl_resource_cache.h"
33 
34 struct pipe_fence_handle;
35 struct hash_table;
36 
37 struct virgl_hw_res {
38    struct pipe_reference reference;
39    enum pipe_texture_target target;
40    uint32_t res_handle;
41    uint32_t bo_handle;
42    int num_cs_references;
43    uint32_t size;
44    void *ptr;
45 
46    struct virgl_resource_cache_entry cache_entry;
47    uint32_t bind;
48    uint32_t flags;
49    uint32_t flink_name;
50 
51    /* true when the resource is imported or exported */
52    int external;
53 
54    /* false when the resource is known to be idle */
55    int maybe_busy;
56    uint32_t blob_mem;
57 };
58 
59 
60 struct param {
61    uint64_t param;
62    const char *name;
63    uint64_t value;
64 };
65 
66 enum param_id {
67    param_3d_features,
68    param_capset_fix,
69    param_resource_blob,
70    param_host_visible,
71    param_max,
72 };
73 
74 #define PARAM(x) (struct param) { x, #x, 0 }
75 
76 struct param params[] = { PARAM(VIRTGPU_PARAM_3D_FEATURES),
77                           PARAM(VIRTGPU_PARAM_CAPSET_QUERY_FIX),
78                           PARAM(VIRTGPU_PARAM_RESOURCE_BLOB),
79                           PARAM(VIRTGPU_PARAM_HOST_VISIBLE),
80                           PARAM(VIRTGPU_PARAM_CROSS_DEVICE)
81 };
82 
83 struct virgl_drm_winsys
84 {
85    struct virgl_winsys base;
86    int fd;
87    struct virgl_resource_cache cache;
88    mtx_t mutex;
89 
90    int32_t blob_id;
91    struct hash_table *bo_handles;
92    struct hash_table *bo_names;
93    mtx_t bo_handles_mutex;
94 };
95 
96 struct virgl_drm_fence {
97    struct pipe_reference reference;
98    bool external;
99    int fd;
100    struct virgl_hw_res *hw_res;
101 };
102 
103 struct virgl_drm_cmd_buf {
104    struct virgl_cmd_buf base;
105 
106    uint32_t *buf;
107 
108    int in_fence_fd;
109 
110    unsigned nres;
111    unsigned cres;
112    struct virgl_hw_res **res_bo;
113    struct virgl_winsys *ws;
114    uint32_t *res_hlist;
115 
116    char                        is_handle_added[512];
117    unsigned                    reloc_indices_hashlist[512];
118 
119 };
120 
121 static inline struct virgl_drm_winsys *
virgl_drm_winsys(struct virgl_winsys * iws)122 virgl_drm_winsys(struct virgl_winsys *iws)
123 {
124    return (struct virgl_drm_winsys *)iws;
125 }
126 
127 static inline struct virgl_drm_fence *
virgl_drm_fence(struct pipe_fence_handle * f)128 virgl_drm_fence(struct pipe_fence_handle *f)
129 {
130    return (struct virgl_drm_fence *)f;
131 }
132 
133 static inline struct virgl_drm_cmd_buf *
virgl_drm_cmd_buf(struct virgl_cmd_buf * cbuf)134 virgl_drm_cmd_buf(struct virgl_cmd_buf *cbuf)
135 {
136    return (struct virgl_drm_cmd_buf *)cbuf;
137 }
138 
139 #endif
140