1bf215546Sopenharmony_ci/**********************************************************
2bf215546Sopenharmony_ci * Copyright 2009-2015 VMware, Inc.  All rights reserved.
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person
5bf215546Sopenharmony_ci * obtaining a copy of this software and associated documentation
6bf215546Sopenharmony_ci * files (the "Software"), to deal in the Software without
7bf215546Sopenharmony_ci * restriction, including without limitation the rights to use, copy,
8bf215546Sopenharmony_ci * modify, merge, publish, distribute, sublicense, and/or sell copies
9bf215546Sopenharmony_ci * of the Software, and to permit persons to whom the Software is
10bf215546Sopenharmony_ci * furnished to do so, subject to the following conditions:
11bf215546Sopenharmony_ci *
12bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be
13bf215546Sopenharmony_ci * included in all copies or substantial portions of the Software.
14bf215546Sopenharmony_ci *
15bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16bf215546Sopenharmony_ci * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17bf215546Sopenharmony_ci * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18bf215546Sopenharmony_ci * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19bf215546Sopenharmony_ci * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20bf215546Sopenharmony_ci * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21bf215546Sopenharmony_ci * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22bf215546Sopenharmony_ci * SOFTWARE.
23bf215546Sopenharmony_ci *
24bf215546Sopenharmony_ci **********************************************************/
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci/**
27bf215546Sopenharmony_ci * @file
28bf215546Sopenharmony_ci * Common definitions for the VMware SVGA winsys.
29bf215546Sopenharmony_ci *
30bf215546Sopenharmony_ci * @author Jose Fonseca <jfonseca@vmware.com>
31bf215546Sopenharmony_ci */
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci
34bf215546Sopenharmony_ci#ifndef VMW_SCREEN_H_
35bf215546Sopenharmony_ci#define VMW_SCREEN_H_
36bf215546Sopenharmony_ci
37bf215546Sopenharmony_ci
38bf215546Sopenharmony_ci#include "pipe/p_compiler.h"
39bf215546Sopenharmony_ci#include "pipe/p_state.h"
40bf215546Sopenharmony_ci
41bf215546Sopenharmony_ci#include "svga_winsys.h"
42bf215546Sopenharmony_ci#include "pipebuffer/pb_buffer_fenced.h"
43bf215546Sopenharmony_ci#include <os/os_thread.h>
44bf215546Sopenharmony_ci#include <sys/types.h>
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_ci#define VMW_GMR_POOL_SIZE (16*1024*1024)
47bf215546Sopenharmony_ci#define VMW_QUERY_POOL_SIZE (8192)
48bf215546Sopenharmony_ci#define VMW_DEBUG_FLUSH_STACK 10
49bf215546Sopenharmony_ci
50bf215546Sopenharmony_ci/*
51bf215546Sopenharmony_ci * Something big, but arbitrary. The kernel reports an error if it can't
52bf215546Sopenharmony_ci * handle this, and the svga driver will resort to multiple partial
53bf215546Sopenharmony_ci * uploads.
54bf215546Sopenharmony_ci */
55bf215546Sopenharmony_ci#define VMW_MAX_BUFFER_SIZE (512*1024*1024)
56bf215546Sopenharmony_ci
57bf215546Sopenharmony_cistruct pb_manager;
58bf215546Sopenharmony_cistruct vmw_region;
59bf215546Sopenharmony_ci
60bf215546Sopenharmony_cistruct vmw_cap_3d {
61bf215546Sopenharmony_ci   boolean has_cap;
62bf215546Sopenharmony_ci   SVGA3dDevCapResult result;
63bf215546Sopenharmony_ci};
64bf215546Sopenharmony_ci
65bf215546Sopenharmony_cistruct vmw_winsys_screen
66bf215546Sopenharmony_ci{
67bf215546Sopenharmony_ci   struct svga_winsys_screen base;
68bf215546Sopenharmony_ci
69bf215546Sopenharmony_ci   struct {
70bf215546Sopenharmony_ci      int drm_fd;
71bf215546Sopenharmony_ci      uint32_t hwversion;
72bf215546Sopenharmony_ci      uint32_t num_cap_3d;
73bf215546Sopenharmony_ci      struct vmw_cap_3d *cap_3d;
74bf215546Sopenharmony_ci      uint64_t max_mob_memory;
75bf215546Sopenharmony_ci      uint64_t max_surface_memory;
76bf215546Sopenharmony_ci      uint64_t max_texture_size;
77bf215546Sopenharmony_ci      boolean have_drm_2_6;
78bf215546Sopenharmony_ci      boolean have_drm_2_9;
79bf215546Sopenharmony_ci      uint32_t drm_execbuf_version;
80bf215546Sopenharmony_ci      boolean have_drm_2_15;
81bf215546Sopenharmony_ci      boolean have_drm_2_16;
82bf215546Sopenharmony_ci      boolean have_drm_2_17;
83bf215546Sopenharmony_ci      boolean have_drm_2_18;
84bf215546Sopenharmony_ci      boolean have_drm_2_19;
85bf215546Sopenharmony_ci      boolean have_drm_2_20;
86bf215546Sopenharmony_ci   } ioctl;
87bf215546Sopenharmony_ci
88bf215546Sopenharmony_ci   struct {
89bf215546Sopenharmony_ci      struct pb_manager *gmr;
90bf215546Sopenharmony_ci      struct pb_manager *gmr_mm;
91bf215546Sopenharmony_ci      struct pb_manager *gmr_fenced;
92bf215546Sopenharmony_ci      struct pb_manager *gmr_slab;
93bf215546Sopenharmony_ci      struct pb_manager *gmr_slab_fenced;
94bf215546Sopenharmony_ci      struct pb_manager *query_mm;
95bf215546Sopenharmony_ci      struct pb_manager *query_fenced;
96bf215546Sopenharmony_ci      struct pb_manager *mob_fenced;
97bf215546Sopenharmony_ci      struct pb_manager *mob_cache;
98bf215546Sopenharmony_ci      struct pb_manager *mob_shader_slab;
99bf215546Sopenharmony_ci      struct pb_manager *mob_shader_slab_fenced;
100bf215546Sopenharmony_ci   } pools;
101bf215546Sopenharmony_ci
102bf215546Sopenharmony_ci   struct pb_fence_ops *fence_ops;
103bf215546Sopenharmony_ci
104bf215546Sopenharmony_ci#ifdef VMX86_STATS
105bf215546Sopenharmony_ci   /*
106bf215546Sopenharmony_ci    * mksGuestStats TLS array; length must be power of two
107bf215546Sopenharmony_ci    */
108bf215546Sopenharmony_ci   struct {
109bf215546Sopenharmony_ci      void *     stat_pages;
110bf215546Sopenharmony_ci      uint64_t   stat_id;
111bf215546Sopenharmony_ci      uint32_t   pid;
112bf215546Sopenharmony_ci   } mksstat_tls[64];
113bf215546Sopenharmony_ci
114bf215546Sopenharmony_ci#endif
115bf215546Sopenharmony_ci   /*
116bf215546Sopenharmony_ci    * Screen instances
117bf215546Sopenharmony_ci    */
118bf215546Sopenharmony_ci   dev_t device;
119bf215546Sopenharmony_ci   int open_count;
120bf215546Sopenharmony_ci
121bf215546Sopenharmony_ci   cnd_t cs_cond;
122bf215546Sopenharmony_ci   mtx_t cs_mutex;
123bf215546Sopenharmony_ci
124bf215546Sopenharmony_ci   boolean force_coherent;
125bf215546Sopenharmony_ci   boolean cache_maps;
126bf215546Sopenharmony_ci};
127bf215546Sopenharmony_ci
128bf215546Sopenharmony_ci
129bf215546Sopenharmony_cistatic inline struct vmw_winsys_screen *
130bf215546Sopenharmony_civmw_winsys_screen(struct svga_winsys_screen *base)
131bf215546Sopenharmony_ci{
132bf215546Sopenharmony_ci   return (struct vmw_winsys_screen *)base;
133bf215546Sopenharmony_ci}
134bf215546Sopenharmony_ci
135bf215546Sopenharmony_ci/*  */
136bf215546Sopenharmony_ciuint32_t
137bf215546Sopenharmony_civmw_region_size(struct vmw_region *region);
138bf215546Sopenharmony_ci
139bf215546Sopenharmony_ciuint32
140bf215546Sopenharmony_civmw_ioctl_context_create(struct vmw_winsys_screen *vws);
141bf215546Sopenharmony_ci
142bf215546Sopenharmony_ciuint32
143bf215546Sopenharmony_civmw_ioctl_extended_context_create(struct vmw_winsys_screen *vws,
144bf215546Sopenharmony_ci                                  boolean vgpu10);
145bf215546Sopenharmony_ci
146bf215546Sopenharmony_civoid
147bf215546Sopenharmony_civmw_ioctl_context_destroy(struct vmw_winsys_screen *vws,
148bf215546Sopenharmony_ci                          uint32 cid);
149bf215546Sopenharmony_ci
150bf215546Sopenharmony_ciuint32
151bf215546Sopenharmony_civmw_ioctl_surface_create(struct vmw_winsys_screen *vws,
152bf215546Sopenharmony_ci                         SVGA3dSurface1Flags flags,
153bf215546Sopenharmony_ci                         SVGA3dSurfaceFormat format,
154bf215546Sopenharmony_ci                         unsigned usage,
155bf215546Sopenharmony_ci                         SVGA3dSize size,
156bf215546Sopenharmony_ci                         uint32 numFaces,
157bf215546Sopenharmony_ci                         uint32 numMipLevels,
158bf215546Sopenharmony_ci                         unsigned sampleCount);
159bf215546Sopenharmony_ciuint32
160bf215546Sopenharmony_civmw_ioctl_gb_surface_create(struct vmw_winsys_screen *vws,
161bf215546Sopenharmony_ci                            SVGA3dSurfaceAllFlags flags,
162bf215546Sopenharmony_ci                            SVGA3dSurfaceFormat format,
163bf215546Sopenharmony_ci                            unsigned usage,
164bf215546Sopenharmony_ci                            SVGA3dSize size,
165bf215546Sopenharmony_ci                            uint32 numFaces,
166bf215546Sopenharmony_ci                            uint32 numMipLevels,
167bf215546Sopenharmony_ci                            unsigned sampleCount,
168bf215546Sopenharmony_ci                            uint32 buffer_handle,
169bf215546Sopenharmony_ci                            SVGA3dMSPattern multisamplePattern,
170bf215546Sopenharmony_ci                            SVGA3dMSQualityLevel qualityLevel,
171bf215546Sopenharmony_ci                            struct vmw_region **p_region);
172bf215546Sopenharmony_ci
173bf215546Sopenharmony_ciint
174bf215546Sopenharmony_civmw_ioctl_gb_surface_ref(struct vmw_winsys_screen *vws,
175bf215546Sopenharmony_ci                         const struct winsys_handle *whandle,
176bf215546Sopenharmony_ci                         SVGA3dSurfaceAllFlags *flags,
177bf215546Sopenharmony_ci                         SVGA3dSurfaceFormat *format,
178bf215546Sopenharmony_ci                         uint32_t *numMipLevels,
179bf215546Sopenharmony_ci                         uint32_t *handle,
180bf215546Sopenharmony_ci                         struct vmw_region **p_region);
181bf215546Sopenharmony_ci
182bf215546Sopenharmony_civoid
183bf215546Sopenharmony_civmw_ioctl_surface_destroy(struct vmw_winsys_screen *vws,
184bf215546Sopenharmony_ci                          uint32 sid);
185bf215546Sopenharmony_ci
186bf215546Sopenharmony_civoid
187bf215546Sopenharmony_civmw_ioctl_command(struct vmw_winsys_screen *vws,
188bf215546Sopenharmony_ci                  int32_t cid,
189bf215546Sopenharmony_ci                  uint32_t throttle_us,
190bf215546Sopenharmony_ci                  void *commands,
191bf215546Sopenharmony_ci                  uint32_t size,
192bf215546Sopenharmony_ci                  struct pipe_fence_handle **fence,
193bf215546Sopenharmony_ci                  int32_t imported_fence_fd,
194bf215546Sopenharmony_ci                  uint32_t flags);
195bf215546Sopenharmony_ci
196bf215546Sopenharmony_cistruct vmw_region *
197bf215546Sopenharmony_civmw_ioctl_region_create(struct vmw_winsys_screen *vws, uint32_t size);
198bf215546Sopenharmony_ci
199bf215546Sopenharmony_civoid
200bf215546Sopenharmony_civmw_ioctl_region_destroy(struct vmw_region *region);
201bf215546Sopenharmony_ci
202bf215546Sopenharmony_cistruct SVGAGuestPtr
203bf215546Sopenharmony_civmw_ioctl_region_ptr(struct vmw_region *region);
204bf215546Sopenharmony_ci
205bf215546Sopenharmony_civoid *
206bf215546Sopenharmony_civmw_ioctl_region_map(struct vmw_region *region);
207bf215546Sopenharmony_civoid
208bf215546Sopenharmony_civmw_ioctl_region_unmap(struct vmw_region *region);
209bf215546Sopenharmony_ci
210bf215546Sopenharmony_ci
211bf215546Sopenharmony_ciint
212bf215546Sopenharmony_civmw_ioctl_fence_finish(struct vmw_winsys_screen *vws,
213bf215546Sopenharmony_ci                       uint32_t handle, uint32_t flags);
214bf215546Sopenharmony_ci
215bf215546Sopenharmony_ciint
216bf215546Sopenharmony_civmw_ioctl_fence_signalled(struct vmw_winsys_screen *vws,
217bf215546Sopenharmony_ci                          uint32_t handle, uint32_t flags);
218bf215546Sopenharmony_ci
219bf215546Sopenharmony_civoid
220bf215546Sopenharmony_civmw_ioctl_fence_unref(struct vmw_winsys_screen *vws,
221bf215546Sopenharmony_ci		      uint32_t handle);
222bf215546Sopenharmony_ci
223bf215546Sopenharmony_ciuint32
224bf215546Sopenharmony_civmw_ioctl_shader_create(struct vmw_winsys_screen *vws,
225bf215546Sopenharmony_ci			SVGA3dShaderType type,
226bf215546Sopenharmony_ci			uint32 code_len);
227bf215546Sopenharmony_civoid
228bf215546Sopenharmony_civmw_ioctl_shader_destroy(struct vmw_winsys_screen *vws, uint32 shid);
229bf215546Sopenharmony_ci
230bf215546Sopenharmony_ciint
231bf215546Sopenharmony_civmw_ioctl_syncforcpu(struct vmw_region *region,
232bf215546Sopenharmony_ci                     boolean dont_block,
233bf215546Sopenharmony_ci                     boolean readonly,
234bf215546Sopenharmony_ci                     boolean allow_cs);
235bf215546Sopenharmony_civoid
236bf215546Sopenharmony_civmw_ioctl_releasefromcpu(struct vmw_region *region,
237bf215546Sopenharmony_ci                         boolean readonly,
238bf215546Sopenharmony_ci                         boolean allow_cs);
239bf215546Sopenharmony_ci/* Initialize parts of vmw_winsys_screen at startup:
240bf215546Sopenharmony_ci */
241bf215546Sopenharmony_ciboolean vmw_ioctl_init(struct vmw_winsys_screen *vws);
242bf215546Sopenharmony_ciboolean vmw_pools_init(struct vmw_winsys_screen *vws);
243bf215546Sopenharmony_ciboolean vmw_query_pools_init(struct vmw_winsys_screen *vws);
244bf215546Sopenharmony_ciboolean vmw_mob_pools_init(struct vmw_winsys_screen *vws);
245bf215546Sopenharmony_ciboolean vmw_winsys_screen_init_svga(struct vmw_winsys_screen *vws);
246bf215546Sopenharmony_ci
247bf215546Sopenharmony_civoid vmw_ioctl_cleanup(struct vmw_winsys_screen *vws);
248bf215546Sopenharmony_civoid vmw_pools_cleanup(struct vmw_winsys_screen *vws);
249bf215546Sopenharmony_ci
250bf215546Sopenharmony_cistruct vmw_winsys_screen *vmw_winsys_create(int fd);
251bf215546Sopenharmony_civoid vmw_winsys_destroy(struct vmw_winsys_screen *sws);
252bf215546Sopenharmony_civoid vmw_winsys_screen_set_throttling(struct pipe_screen *screen,
253bf215546Sopenharmony_ci				      uint32_t throttle_us);
254bf215546Sopenharmony_ci
255bf215546Sopenharmony_cistruct pb_manager *
256bf215546Sopenharmony_cisimple_fenced_bufmgr_create(struct pb_manager *provider,
257bf215546Sopenharmony_ci			    struct pb_fence_ops *ops);
258bf215546Sopenharmony_civoid
259bf215546Sopenharmony_civmw_fences_signal(struct pb_fence_ops *fence_ops,
260bf215546Sopenharmony_ci                  uint32_t signaled,
261bf215546Sopenharmony_ci                  uint32_t emitted,
262bf215546Sopenharmony_ci                  boolean has_emitted);
263bf215546Sopenharmony_ci
264bf215546Sopenharmony_cistruct svga_winsys_gb_shader *
265bf215546Sopenharmony_civmw_svga_winsys_shader_create(struct svga_winsys_screen *sws,
266bf215546Sopenharmony_ci			      SVGA3dShaderType type,
267bf215546Sopenharmony_ci			      const uint32 *bytecode,
268bf215546Sopenharmony_ci			      uint32 bytecodeLen);
269bf215546Sopenharmony_civoid
270bf215546Sopenharmony_civmw_svga_winsys_shader_destroy(struct svga_winsys_screen *sws,
271bf215546Sopenharmony_ci			       struct svga_winsys_gb_shader *shader);
272bf215546Sopenharmony_ci
273bf215546Sopenharmony_cisize_t
274bf215546Sopenharmony_civmw_svga_winsys_stats_len(void);
275bf215546Sopenharmony_ci
276bf215546Sopenharmony_ci#endif /* VMW_SCREEN_H_ */
277