summaryrefslogtreecommitdiff
path: root/src/gallium/winsys/svga/drm/vmw_screen.h
blob: 9fd17d51574ca716e9831987ccb714f1643e2063 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/**********************************************************
 * Copyright 2009-2023 VMware, Inc.  All rights reserved.
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use, copy,
 * modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 **********************************************************/

/**
 * @file
 * Common definitions for the VMware SVGA winsys.
 *
 * @author Jose Fonseca <jfonseca@vmware.com>
 */


#ifndef VMW_SCREEN_H_
#define VMW_SCREEN_H_


#include "util/compiler.h"
#include "pipe/p_state.h"

#include "svga_winsys.h"
#include "pipebuffer/pb_buffer_fenced.h"
#include "util/u_thread.h"
#include <sys/types.h>

#define VMW_GMR_POOL_SIZE (16*1024*1024)
#define VMW_QUERY_POOL_SIZE (8192)
#define VMW_DEBUG_FLUSH_STACK 10

/*
 * Something big, but arbitrary. The kernel reports an error if it can't
 * handle this, and the svga driver will resort to multiple partial
 * uploads.
 */
#define VMW_MAX_BUFFER_SIZE (512*1024*1024)

struct pb_manager;
struct vmw_region;

struct vmw_cap_3d {
   bool has_cap;
   SVGA3dDevCapResult result;
};

struct vmw_winsys_screen
{
   struct svga_winsys_screen base;

   struct {
      int drm_fd;
      uint32_t hwversion;
      uint32_t num_cap_3d;
      struct vmw_cap_3d *cap_3d;
      uint64_t max_mob_memory;
      uint64_t max_surface_memory;
      uint64_t max_texture_size;
      bool have_drm_2_6;
      bool have_drm_2_9;
      uint32_t drm_execbuf_version;
      bool have_drm_2_15;
      bool have_drm_2_16;
      bool have_drm_2_17;
      bool have_drm_2_18;
      bool have_drm_2_19;
      bool have_drm_2_20;
   } ioctl;

   struct {
      struct pb_manager *dma_base;
      struct pb_manager *dma_mm;
      struct pb_manager *query_mm;
      struct pb_manager *query_fenced;
      struct pb_manager *dma_fenced;
      struct pb_manager *dma_cache;
      struct pb_manager *dma_slab;
      struct pb_manager *dma_slab_fenced;
   } pools;

   struct pb_fence_ops *fence_ops;

#ifdef VMX86_STATS
   /*
    * mksGuestStats TLS array; length must be power of two
    */
   struct {
      void *     stat_pages;
      uint64_t   stat_id;
      uint32_t   pid;
   } mksstat_tls[64];

#endif
   /*
    * Screen instances
    */
   dev_t device;
   int open_count;

   cnd_t cs_cond;
   mtx_t cs_mutex;

   bool force_coherent;
   bool cache_maps;
};


static inline struct vmw_winsys_screen *
vmw_winsys_screen(struct svga_winsys_screen *base)
{
   return (struct vmw_winsys_screen *)base;
}

/*  */
uint32_t
vmw_region_size(struct vmw_region *region);

uint32
vmw_ioctl_context_create(struct vmw_winsys_screen *vws);

uint32
vmw_ioctl_extended_context_create(struct vmw_winsys_screen *vws,
                                  bool vgpu10);

void
vmw_ioctl_context_destroy(struct vmw_winsys_screen *vws,
                          uint32 cid);

uint32
vmw_ioctl_surface_create(struct vmw_winsys_screen *vws,
                         SVGA3dSurface1Flags flags,
                         SVGA3dSurfaceFormat format,
                         unsigned usage,
                         SVGA3dSize size,
                         uint32 numFaces,
                         uint32 numMipLevels,
                         unsigned sampleCount);
uint32
vmw_ioctl_gb_surface_create(struct vmw_winsys_screen *vws,
                            SVGA3dSurfaceAllFlags flags,
                            SVGA3dSurfaceFormat format,
                            unsigned usage,
                            SVGA3dSize size,
                            uint32 numFaces,
                            uint32 numMipLevels,
                            unsigned sampleCount,
                            uint32 buffer_handle,
                            SVGA3dMSPattern multisamplePattern,
                            SVGA3dMSQualityLevel qualityLevel,
                            struct vmw_region **p_region);

int
vmw_ioctl_gb_surface_ref(struct vmw_winsys_screen *vws,
                         const struct winsys_handle *whandle,
                         SVGA3dSurfaceAllFlags *flags,
                         SVGA3dSurfaceFormat *format,
                         uint32_t *numMipLevels,
                         uint32_t *handle,
                         struct vmw_region **p_region);

void
vmw_ioctl_surface_destroy(struct vmw_winsys_screen *vws,
                          uint32 sid);

void
vmw_ioctl_command(struct vmw_winsys_screen *vws,
                  int32_t cid,
                  uint32_t throttle_us,
                  void *commands,
                  uint32_t size,
                  struct pipe_fence_handle **fence,
                  int32_t imported_fence_fd,
                  uint32_t flags);

struct vmw_region *
vmw_ioctl_region_create(struct vmw_winsys_screen *vws, uint32_t size);

void
vmw_ioctl_region_destroy(struct vmw_region *region);

struct SVGAGuestPtr
vmw_ioctl_region_ptr(struct vmw_region *region);

void *
vmw_ioctl_region_map(struct vmw_region *region);
void
vmw_ioctl_region_unmap(struct vmw_region *region);


int
vmw_ioctl_fence_finish(struct vmw_winsys_screen *vws,
                       uint32_t handle, uint32_t flags);

int
vmw_ioctl_fence_signalled(struct vmw_winsys_screen *vws,
                          uint32_t handle, uint32_t flags);

void
vmw_ioctl_fence_unref(struct vmw_winsys_screen *vws,
		      uint32_t handle);

uint32
vmw_ioctl_shader_create(struct vmw_winsys_screen *vws,
			SVGA3dShaderType type,
			uint32 code_len);
void
vmw_ioctl_shader_destroy(struct vmw_winsys_screen *vws, uint32 shid);

int
vmw_ioctl_syncforcpu(struct vmw_region *region,
                     bool dont_block,
                     bool readonly,
                     bool allow_cs);
void
vmw_ioctl_releasefromcpu(struct vmw_region *region,
                         bool readonly,
                         bool allow_cs);
/* Initialize parts of vmw_winsys_screen at startup:
 */
bool vmw_ioctl_init(struct vmw_winsys_screen *vws);
bool vmw_pools_init(struct vmw_winsys_screen *vws);
bool vmw_query_pools_init(struct vmw_winsys_screen *vws);
bool vmw_winsys_screen_init_svga(struct vmw_winsys_screen *vws);

void vmw_ioctl_cleanup(struct vmw_winsys_screen *vws);
void vmw_pools_cleanup(struct vmw_winsys_screen *vws);

struct vmw_winsys_screen *vmw_winsys_create(int fd);
void vmw_winsys_destroy(struct vmw_winsys_screen *sws);
void vmw_winsys_screen_set_throttling(struct pipe_screen *screen,
				      uint32_t throttle_us);

struct pb_manager *
simple_fenced_bufmgr_create(struct pb_manager *provider,
			    struct pb_fence_ops *ops);
void
vmw_fences_signal(struct pb_fence_ops *fence_ops,
                  uint32_t signaled,
                  uint32_t emitted,
                  bool has_emitted);

struct svga_winsys_gb_shader *
vmw_svga_winsys_shader_create(struct svga_winsys_screen *sws,
			      SVGA3dShaderType type,
			      const uint32 *bytecode,
			      uint32 bytecodeLen);
void
vmw_svga_winsys_shader_destroy(struct svga_winsys_screen *sws,
			       struct svga_winsys_gb_shader *shader);

size_t
vmw_svga_winsys_stats_len(void);

#endif /* VMW_SCREEN_H_ */