svga/winsys: implement GBS support
[mesa.git] / src / gallium / winsys / svga / drm / vmw_screen.h
1 /**********************************************************
2 * Copyright 2009 VMware, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 **********************************************************/
25
26 /**
27 * @file
28 * Common definitions for the VMware SVGA winsys.
29 *
30 * @author Jose Fonseca <jfonseca@vmware.com>
31 */
32
33
34 #ifndef VMW_SCREEN_H_
35 #define VMW_SCREEN_H_
36
37
38 #include "pipe/p_compiler.h"
39 #include "pipe/p_state.h"
40
41 #include "svga_winsys.h"
42 #include "pipebuffer/pb_buffer_fenced.h"
43
44
45 #define VMW_GMR_POOL_SIZE (16*1024*1024)
46 #define VMW_QUERY_POOL_SIZE (8192)
47 #define VMW_DEBUG_FLUSH_STACK 10
48
49 /*
50 * Something big, but arbitrary. The kernel reports an error if it can't
51 * handle this, and the svga driver will resort to multiple partial
52 * uploads.
53 */
54 #define VMW_MAX_BUFFER_SIZE (512*1024*1024)
55
56 struct pb_manager;
57 struct vmw_region;
58
59 struct vmw_cap_3d {
60 boolean has_cap;
61 SVGA3dDevCapResult result;
62 };
63
64 struct vmw_winsys_screen
65 {
66 struct svga_winsys_screen base;
67
68 boolean use_old_scanout_flag;
69
70 struct {
71 int drm_fd;
72 uint32_t hwversion;
73 uint32_t num_cap_3d;
74 struct vmw_cap_3d *cap_3d;
75 uint64_t max_mob_memory;
76 uint64_t max_surface_memory;
77 } ioctl;
78
79 struct {
80 struct pb_manager *gmr;
81 struct pb_manager *gmr_mm;
82 struct pb_manager *gmr_fenced;
83 struct pb_manager *gmr_slab;
84 struct pb_manager *gmr_slab_fenced;
85 struct pb_manager *query_mm;
86 struct pb_manager *query_fenced;
87 struct pb_manager *mob_fenced;
88 struct pb_manager *mob_cache;
89 struct pb_manager *mob_shader_slab;
90 struct pb_manager *mob_shader_slab_fenced;
91 } pools;
92
93 struct pb_fence_ops *fence_ops;
94
95 /*
96 * Screen instances
97 */
98 dev_t device;
99 int open_count;
100 };
101
102
103 static INLINE struct vmw_winsys_screen *
104 vmw_winsys_screen(struct svga_winsys_screen *base)
105 {
106 return (struct vmw_winsys_screen *)base;
107 }
108
109 /* */
110 uint32_t
111 vmw_region_size(struct vmw_region *region);
112
113 uint32
114 vmw_ioctl_context_create(struct vmw_winsys_screen *vws);
115
116 void
117 vmw_ioctl_context_destroy(struct vmw_winsys_screen *vws,
118 uint32 cid);
119
120 uint32
121 vmw_ioctl_surface_create(struct vmw_winsys_screen *vws,
122 SVGA3dSurfaceFlags flags,
123 SVGA3dSurfaceFormat format,
124 SVGA3dSize size,
125 uint32 numFaces,
126 uint32 numMipLevels);
127 uint32
128 vmw_ioctl_gb_surface_create(struct vmw_winsys_screen *vws,
129 SVGA3dSurfaceFlags flags,
130 SVGA3dSurfaceFormat format,
131 SVGA3dSize size,
132 uint32 numFaces,
133 uint32 numMipLevels,
134 uint32 buffer_handle,
135 struct vmw_region **p_region);
136
137 int
138 vmw_ioctl_gb_surface_ref(struct vmw_winsys_screen *vws,
139 uint32_t handle,
140 SVGA3dSurfaceFlags *flags,
141 SVGA3dSurfaceFormat *format,
142 uint32_t *numMipLevels,
143 struct vmw_region **p_region);
144
145 void
146 vmw_ioctl_surface_destroy(struct vmw_winsys_screen *vws,
147 uint32 sid);
148
149 void
150 vmw_ioctl_command(struct vmw_winsys_screen *vws,
151 int32_t cid,
152 uint32_t throttle_us,
153 void *commands,
154 uint32_t size,
155 struct pipe_fence_handle **fence);
156
157 struct vmw_region *
158 vmw_ioctl_region_create(struct vmw_winsys_screen *vws, uint32_t size);
159
160 void
161 vmw_ioctl_region_destroy(struct vmw_region *region);
162
163 struct SVGAGuestPtr
164 vmw_ioctl_region_ptr(struct vmw_region *region);
165
166 void *
167 vmw_ioctl_region_map(struct vmw_region *region);
168 void
169 vmw_ioctl_region_unmap(struct vmw_region *region);
170
171
172 int
173 vmw_ioctl_fence_finish(struct vmw_winsys_screen *vws,
174 uint32_t handle, uint32_t flags);
175
176 int
177 vmw_ioctl_fence_signalled(struct vmw_winsys_screen *vws,
178 uint32_t handle, uint32_t flags);
179
180 void
181 vmw_ioctl_fence_unref(struct vmw_winsys_screen *vws,
182 uint32_t handle);
183
184 uint32
185 vmw_ioctl_shader_create(struct vmw_winsys_screen *vws,
186 SVGA3dShaderType type,
187 uint32 code_len);
188 void
189 vmw_ioctl_shader_destroy(struct vmw_winsys_screen *vws, uint32 shid);
190
191 int
192 vmw_ioctl_syncforcpu(struct vmw_region *region,
193 boolean dont_block,
194 boolean readonly,
195 boolean allow_cs);
196 void
197 vmw_ioctl_releasefromcpu(struct vmw_region *region,
198 boolean readonly,
199 boolean allow_cs);
200 /* Initialize parts of vmw_winsys_screen at startup:
201 */
202 boolean vmw_ioctl_init(struct vmw_winsys_screen *vws);
203 boolean vmw_pools_init(struct vmw_winsys_screen *vws);
204 boolean vmw_query_pools_init(struct vmw_winsys_screen *vws);
205 boolean vmw_mob_pools_init(struct vmw_winsys_screen *vws);
206 boolean vmw_winsys_screen_init_svga(struct vmw_winsys_screen *vws);
207
208 void vmw_ioctl_cleanup(struct vmw_winsys_screen *vws);
209 void vmw_pools_cleanup(struct vmw_winsys_screen *vws);
210
211 struct vmw_winsys_screen *vmw_winsys_create(int fd, boolean use_old_scanout_flag);
212 void vmw_winsys_destroy(struct vmw_winsys_screen *sws);
213 void vmw_winsys_screen_set_throttling(struct pipe_screen *screen,
214 uint32_t throttle_us);
215
216 struct pb_manager *
217 simple_fenced_bufmgr_create(struct pb_manager *provider,
218 struct pb_fence_ops *ops);
219 void
220 vmw_fences_signal(struct pb_fence_ops *fence_ops,
221 uint32_t signaled,
222 uint32_t emitted,
223 boolean has_emitted);
224
225 #endif /* VMW_SCREEN_H_ */