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
34struct pipe_fence_handle;
35struct hash_table;
36
37struct 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   /* false when the resource is known to be typed */
52   bool maybe_untyped;
53
54   /* true when the resource is imported or exported */
55   int external;
56
57   /* false when the resource is known to be idle */
58   int maybe_busy;
59   uint32_t blob_mem;
60};
61
62
63struct param {
64   uint64_t param;
65   const char *name;
66   uint64_t value;
67};
68
69enum param_id {
70   param_3d_features,
71   param_capset_fix,
72   param_resource_blob,
73   param_host_visible,
74   param_cross_device,
75   param_context_init,
76   param_supported_capset_ids,
77   param_max,
78};
79
80#define PARAM(x) (struct param) { x, #x, 0 }
81
82struct param params[] = { PARAM(VIRTGPU_PARAM_3D_FEATURES),
83                          PARAM(VIRTGPU_PARAM_CAPSET_QUERY_FIX),
84                          PARAM(VIRTGPU_PARAM_RESOURCE_BLOB),
85                          PARAM(VIRTGPU_PARAM_HOST_VISIBLE),
86                          PARAM(VIRTGPU_PARAM_CROSS_DEVICE),
87                          PARAM(VIRTGPU_PARAM_CONTEXT_INIT),
88                          PARAM(VIRTGPU_PARAM_SUPPORTED_CAPSET_IDs)
89};
90
91struct virgl_drm_winsys
92{
93   struct virgl_winsys base;
94   int fd;
95   struct virgl_resource_cache cache;
96   mtx_t mutex;
97
98   int32_t blob_id;
99   struct hash_table *bo_handles;
100   struct hash_table *bo_names;
101   mtx_t bo_handles_mutex;
102};
103
104struct virgl_drm_fence {
105   struct pipe_reference reference;
106   bool external;
107   int fd;
108   struct virgl_hw_res *hw_res;
109};
110
111struct virgl_drm_cmd_buf {
112   struct virgl_cmd_buf base;
113
114   uint32_t *buf;
115
116   int in_fence_fd;
117
118   unsigned nres;
119   unsigned cres;
120   struct virgl_hw_res **res_bo;
121   struct virgl_winsys *ws;
122   uint32_t *res_hlist;
123
124   char                        is_handle_added[512];
125   unsigned                    reloc_indices_hashlist[512];
126
127};
128
129static inline struct virgl_drm_winsys *
130virgl_drm_winsys(struct virgl_winsys *iws)
131{
132   return (struct virgl_drm_winsys *)iws;
133}
134
135static inline struct virgl_drm_fence *
136virgl_drm_fence(struct pipe_fence_handle *f)
137{
138   return (struct virgl_drm_fence *)f;
139}
140
141static inline struct virgl_drm_cmd_buf *
142virgl_drm_cmd_buf(struct virgl_cmd_buf *cbuf)
143{
144   return (struct virgl_drm_cmd_buf *)cbuf;
145}
146
147#endif
148