Commit | Line | Data |
---|---|---|
fb1d9738 JB |
1 | /************************************************************************** |
2 | * | |
54fbde8a | 3 | * Copyright © 2009-2015 VMware, Inc., Palo Alto, CA., USA |
fb1d9738 JB |
4 | * All Rights Reserved. |
5 | * | |
6 | * Permission is hereby granted, free of charge, to any person obtaining a | |
7 | * copy of this software and associated documentation files (the | |
8 | * "Software"), to deal in the Software without restriction, including | |
9 | * without limitation the rights to use, copy, modify, merge, publish, | |
10 | * distribute, sub license, and/or sell copies of the Software, and to | |
11 | * permit persons to whom the Software is furnished to do so, subject to | |
12 | * the following conditions: | |
13 | * | |
14 | * The above copyright notice and this permission notice (including the | |
15 | * next paragraph) shall be included in all copies or substantial portions | |
16 | * of the Software. | |
17 | * | |
18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
20 | * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL | |
21 | * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, | |
22 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR | |
23 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE | |
24 | * USE OR OTHER DEALINGS IN THE SOFTWARE. | |
25 | * | |
26 | **************************************************************************/ | |
27 | ||
28 | #ifndef _VMWGFX_DRV_H_ | |
29 | #define _VMWGFX_DRV_H_ | |
30 | ||
31 | #include "vmwgfx_reg.h" | |
760285e7 DH |
32 | #include <drm/drmP.h> |
33 | #include <drm/vmwgfx_drm.h> | |
34 | #include <drm/drm_hashtab.h> | |
3b96a0b1 | 35 | #include <drm/drm_auth.h> |
760285e7 DH |
36 | #include <linux/suspend.h> |
37 | #include <drm/ttm/ttm_bo_driver.h> | |
38 | #include <drm/ttm/ttm_object.h> | |
39 | #include <drm/ttm/ttm_lock.h> | |
40 | #include <drm/ttm/ttm_execbuf_util.h> | |
41 | #include <drm/ttm/ttm_module.h> | |
ae2a1040 | 42 | #include "vmwgfx_fence.h" |
c906965d | 43 | #include <linux/sync_file.h> |
fb1d9738 | 44 | |
e300173f | 45 | #define VMWGFX_DRIVER_NAME "vmwgfx" |
d78acfe9 | 46 | #define VMWGFX_DRIVER_DATE "20170612" |
2ae7b03c | 47 | #define VMWGFX_DRIVER_MAJOR 2 |
d78acfe9 | 48 | #define VMWGFX_DRIVER_MINOR 14 |
35c05125 | 49 | #define VMWGFX_DRIVER_PATCHLEVEL 0 |
fb1d9738 JB |
50 | #define VMWGFX_FILE_PAGE_OFFSET 0x00100000 |
51 | #define VMWGFX_FIFO_STATIC_SIZE (1024*1024) | |
52 | #define VMWGFX_MAX_RELOCATIONS 2048 | |
be38ab6e | 53 | #define VMWGFX_MAX_VALIDATIONS 2048 |
7c4f7780 | 54 | #define VMWGFX_MAX_DISPLAYS 16 |
be38ab6e | 55 | #define VMWGFX_CMD_BOUNCE_INIT_SIZE 32768 |
35c05125 | 56 | #define VMWGFX_ENABLE_SCREEN_TARGET_OTABLE 1 |
fb1d9738 | 57 | |
3530bdc3 TH |
58 | /* |
59 | * Perhaps we should have sysfs entries for these. | |
60 | */ | |
61 | #define VMWGFX_NUM_GB_CONTEXT 256 | |
62 | #define VMWGFX_NUM_GB_SHADER 20000 | |
63 | #define VMWGFX_NUM_GB_SURFACE 32768 | |
7cba9062 | 64 | #define VMWGFX_NUM_GB_SCREEN_TARGET VMWGFX_MAX_DISPLAYS |
d80efd5c TH |
65 | #define VMWGFX_NUM_DXCONTEXT 256 |
66 | #define VMWGFX_NUM_DXQUERY 512 | |
3530bdc3 TH |
67 | #define VMWGFX_NUM_MOB (VMWGFX_NUM_GB_CONTEXT +\ |
68 | VMWGFX_NUM_GB_SHADER +\ | |
7cba9062 TH |
69 | VMWGFX_NUM_GB_SURFACE +\ |
70 | VMWGFX_NUM_GB_SCREEN_TARGET) | |
3530bdc3 | 71 | |
283cde69 CK |
72 | #define VMW_PL_GMR (TTM_PL_PRIV + 0) |
73 | #define VMW_PL_FLAG_GMR (TTM_PL_FLAG_PRIV << 0) | |
74 | #define VMW_PL_MOB (TTM_PL_PRIV + 1) | |
75 | #define VMW_PL_FLAG_MOB (TTM_PL_FLAG_PRIV << 1) | |
135cba0d | 76 | |
ae2a1040 TH |
77 | #define VMW_RES_CONTEXT ttm_driver_type0 |
78 | #define VMW_RES_SURFACE ttm_driver_type1 | |
79 | #define VMW_RES_STREAM ttm_driver_type2 | |
80 | #define VMW_RES_FENCE ttm_driver_type3 | |
c74c162f | 81 | #define VMW_RES_SHADER ttm_driver_type4 |
ae2a1040 | 82 | |
fb1d9738 JB |
83 | struct vmw_fpriv { |
84 | struct drm_master *locked_master; | |
85 | struct ttm_object_file *tfile; | |
d5bde956 | 86 | bool gb_aware; |
fb1d9738 JB |
87 | }; |
88 | ||
89 | struct vmw_dma_buffer { | |
90 | struct ttm_buffer_object base; | |
c0951b79 | 91 | struct list_head res_list; |
459d0fa7 | 92 | s32 pin_count; |
fd11a3c0 SY |
93 | /* Not ref-counted. Protected by binding_mutex */ |
94 | struct vmw_resource *dx_query_ctx; | |
fb1d9738 JB |
95 | }; |
96 | ||
c0951b79 TH |
97 | /** |
98 | * struct vmw_validate_buffer - Carries validation info about buffers. | |
99 | * | |
100 | * @base: Validation info for TTM. | |
101 | * @hash: Hash entry for quick lookup of the TTM buffer object. | |
102 | * | |
103 | * This structure contains also driver private validation info | |
104 | * on top of the info needed by TTM. | |
105 | */ | |
106 | struct vmw_validate_buffer { | |
107 | struct ttm_validate_buffer base; | |
108 | struct drm_hash_item hash; | |
96c5f0df | 109 | bool validate_as_mob; |
c0951b79 TH |
110 | }; |
111 | ||
112 | struct vmw_res_func; | |
fb1d9738 JB |
113 | struct vmw_resource { |
114 | struct kref kref; | |
115 | struct vmw_private *dev_priv; | |
fb1d9738 | 116 | int id; |
fb1d9738 | 117 | bool avail; |
c0951b79 TH |
118 | unsigned long backup_size; |
119 | bool res_dirty; /* Protected by backup buffer reserved */ | |
120 | bool backup_dirty; /* Protected by backup buffer reserved */ | |
121 | struct vmw_dma_buffer *backup; | |
122 | unsigned long backup_offset; | |
ed93394c | 123 | unsigned long pin_count; /* Protected by resource reserved */ |
c0951b79 TH |
124 | const struct vmw_res_func *func; |
125 | struct list_head lru_head; /* Protected by the resource lock */ | |
126 | struct list_head mob_head; /* Protected by @backup reserved */ | |
173fb7d4 | 127 | struct list_head binding_head; /* Protected by binding_mutex */ |
fb1d9738 | 128 | void (*res_free) (struct vmw_resource *res); |
c0951b79 TH |
129 | void (*hw_destroy) (struct vmw_resource *res); |
130 | }; | |
131 | ||
18e4a466 TH |
132 | |
133 | /* | |
134 | * Resources that are managed using ioctls. | |
135 | */ | |
c0951b79 TH |
136 | enum vmw_res_type { |
137 | vmw_res_context, | |
138 | vmw_res_surface, | |
139 | vmw_res_stream, | |
c74c162f | 140 | vmw_res_shader, |
d80efd5c TH |
141 | vmw_res_dx_context, |
142 | vmw_res_cotable, | |
143 | vmw_res_view, | |
c0951b79 | 144 | vmw_res_max |
fb1d9738 JB |
145 | }; |
146 | ||
18e4a466 TH |
147 | /* |
148 | * Resources that are managed using command streams. | |
149 | */ | |
150 | enum vmw_cmdbuf_res_type { | |
d80efd5c TH |
151 | vmw_cmdbuf_res_shader, |
152 | vmw_cmdbuf_res_view | |
18e4a466 TH |
153 | }; |
154 | ||
155 | struct vmw_cmdbuf_res_manager; | |
156 | ||
fb1d9738 | 157 | struct vmw_cursor_snooper { |
fb1d9738 JB |
158 | size_t age; |
159 | uint32_t *image; | |
160 | }; | |
161 | ||
2fcd5a73 | 162 | struct vmw_framebuffer; |
5bb39e81 | 163 | struct vmw_surface_offset; |
2fcd5a73 | 164 | |
fb1d9738 JB |
165 | struct vmw_surface { |
166 | struct vmw_resource res; | |
167 | uint32_t flags; | |
168 | uint32_t format; | |
169 | uint32_t mip_levels[DRM_VMW_MAX_SURFACE_FACES]; | |
c0951b79 | 170 | struct drm_vmw_size base_size; |
fb1d9738 JB |
171 | struct drm_vmw_size *sizes; |
172 | uint32_t num_sizes; | |
5ffdb658 | 173 | bool scanout; |
d80efd5c | 174 | uint32_t array_size; |
fb1d9738 JB |
175 | /* TODO so far just a extra pointer */ |
176 | struct vmw_cursor_snooper snooper; | |
5bb39e81 | 177 | struct vmw_surface_offset *offsets; |
c0951b79 TH |
178 | SVGA3dTextureFilter autogen_filter; |
179 | uint32_t multisample_count; | |
d80efd5c | 180 | struct list_head view_list; |
fb1d9738 JB |
181 | }; |
182 | ||
6bcd8d3c | 183 | struct vmw_marker_queue { |
1925d456 | 184 | struct list_head head; |
f166e6dc TG |
185 | u64 lag; |
186 | u64 lag_time; | |
1925d456 TH |
187 | spinlock_t lock; |
188 | }; | |
189 | ||
fb1d9738 JB |
190 | struct vmw_fifo_state { |
191 | unsigned long reserved_size; | |
b9eb1a61 TH |
192 | u32 *dynamic_buffer; |
193 | u32 *static_buffer; | |
fb1d9738 JB |
194 | unsigned long static_buffer_size; |
195 | bool using_bounce_buffer; | |
196 | uint32_t capabilities; | |
85b9e487 | 197 | struct mutex fifo_mutex; |
fb1d9738 | 198 | struct rw_semaphore rwsem; |
6bcd8d3c | 199 | struct vmw_marker_queue marker_queue; |
d80efd5c | 200 | bool dx; |
fb1d9738 JB |
201 | }; |
202 | ||
203 | struct vmw_relocation { | |
ddcda24e | 204 | SVGAMobId *mob_loc; |
fb1d9738 JB |
205 | SVGAGuestPtr *location; |
206 | uint32_t index; | |
207 | }; | |
208 | ||
c0951b79 TH |
209 | /** |
210 | * struct vmw_res_cache_entry - resource information cache entry | |
211 | * | |
212 | * @valid: Whether the entry is valid, which also implies that the execbuf | |
213 | * code holds a reference to the resource, and it's placed on the | |
214 | * validation list. | |
215 | * @handle: User-space handle of a resource. | |
216 | * @res: Non-ref-counted pointer to the resource. | |
217 | * | |
218 | * Used to avoid frequent repeated user-space handle lookups of the | |
219 | * same resource. | |
220 | */ | |
221 | struct vmw_res_cache_entry { | |
222 | bool valid; | |
223 | uint32_t handle; | |
224 | struct vmw_resource *res; | |
225 | struct vmw_resource_val_node *node; | |
226 | }; | |
227 | ||
d92d9851 TH |
228 | /** |
229 | * enum vmw_dma_map_mode - indicate how to perform TTM page dma mappings. | |
230 | */ | |
231 | enum vmw_dma_map_mode { | |
232 | vmw_dma_phys, /* Use physical page addresses */ | |
233 | vmw_dma_alloc_coherent, /* Use TTM coherent pages */ | |
234 | vmw_dma_map_populate, /* Unmap from DMA just after unpopulate */ | |
235 | vmw_dma_map_bind, /* Unmap from DMA just before unbind */ | |
236 | vmw_dma_map_max | |
237 | }; | |
238 | ||
239 | /** | |
240 | * struct vmw_sg_table - Scatter/gather table for binding, with additional | |
241 | * device-specific information. | |
242 | * | |
243 | * @sgt: Pointer to a struct sg_table with binding information | |
e1c05067 | 244 | * @num_regions: Number of regions with device-address contiguous pages |
d92d9851 TH |
245 | */ |
246 | struct vmw_sg_table { | |
247 | enum vmw_dma_map_mode mode; | |
248 | struct page **pages; | |
249 | const dma_addr_t *addrs; | |
250 | struct sg_table *sgt; | |
251 | unsigned long num_regions; | |
252 | unsigned long num_pages; | |
253 | }; | |
254 | ||
255 | /** | |
256 | * struct vmw_piter - Page iterator that iterates over a list of pages | |
257 | * and DMA addresses that could be either a scatter-gather list or | |
258 | * arrays | |
259 | * | |
260 | * @pages: Array of page pointers to the pages. | |
261 | * @addrs: DMA addresses to the pages if coherent pages are used. | |
262 | * @iter: Scatter-gather page iterator. Current position in SG list. | |
263 | * @i: Current position in arrays. | |
264 | * @num_pages: Number of pages total. | |
265 | * @next: Function to advance the iterator. Returns false if past the list | |
266 | * of pages, true otherwise. | |
267 | * @dma_address: Function to return the DMA address of the current page. | |
268 | */ | |
269 | struct vmw_piter { | |
270 | struct page **pages; | |
271 | const dma_addr_t *addrs; | |
272 | struct sg_page_iter iter; | |
273 | unsigned long i; | |
274 | unsigned long num_pages; | |
275 | bool (*next)(struct vmw_piter *); | |
276 | dma_addr_t (*dma_address)(struct vmw_piter *); | |
277 | struct page *(*page)(struct vmw_piter *); | |
278 | }; | |
279 | ||
b5c3b1a6 | 280 | /* |
c8261a96 | 281 | * enum vmw_display_unit_type - Describes the display unit |
b5c3b1a6 | 282 | */ |
c8261a96 SY |
283 | enum vmw_display_unit_type { |
284 | vmw_du_invalid = 0, | |
285 | vmw_du_legacy, | |
35c05125 SY |
286 | vmw_du_screen_object, |
287 | vmw_du_screen_target | |
b5c3b1a6 TH |
288 | }; |
289 | ||
b5c3b1a6 | 290 | |
fb1d9738 | 291 | struct vmw_sw_context{ |
c0951b79 TH |
292 | struct drm_open_hash res_ht; |
293 | bool res_ht_initialized; | |
922ade0d | 294 | bool kernel; /**< is the called made from the kernel */ |
d5bde956 | 295 | struct vmw_fpriv *fp; |
fb1d9738 JB |
296 | struct list_head validate_nodes; |
297 | struct vmw_relocation relocs[VMWGFX_MAX_RELOCATIONS]; | |
298 | uint32_t cur_reloc; | |
c0951b79 | 299 | struct vmw_validate_buffer val_bufs[VMWGFX_MAX_VALIDATIONS]; |
fb1d9738 | 300 | uint32_t cur_val_buf; |
be38ab6e TH |
301 | uint32_t *cmd_bounce; |
302 | uint32_t cmd_bounce_size; | |
f18c8840 | 303 | struct list_head resource_list; |
d80efd5c | 304 | struct list_head ctx_resource_list; /* For contexts and cotables */ |
459d0fa7 | 305 | struct vmw_dma_buffer *cur_query_bo; |
c0951b79 TH |
306 | struct list_head res_relocations; |
307 | uint32_t *buf_start; | |
308 | struct vmw_res_cache_entry res_cache[vmw_res_max]; | |
309 | struct vmw_resource *last_query_ctx; | |
310 | bool needs_post_query_barrier; | |
311 | struct vmw_resource *error_resource; | |
d80efd5c TH |
312 | struct vmw_ctx_binding_state *staged_bindings; |
313 | bool staged_bindings_inuse; | |
18e4a466 | 314 | struct list_head staged_cmd_res; |
d80efd5c TH |
315 | struct vmw_resource_val_node *dx_ctx_node; |
316 | struct vmw_dma_buffer *dx_query_mob; | |
317 | struct vmw_resource *dx_query_ctx; | |
318 | struct vmw_cmdbuf_res_manager *man; | |
fb1d9738 JB |
319 | }; |
320 | ||
321 | struct vmw_legacy_display; | |
322 | struct vmw_overlay; | |
323 | ||
324 | struct vmw_master { | |
325 | struct ttm_lock lock; | |
326 | }; | |
327 | ||
7c4f7780 TH |
328 | struct vmw_vga_topology_state { |
329 | uint32_t width; | |
330 | uint32_t height; | |
331 | uint32_t primary; | |
332 | uint32_t pos_x; | |
333 | uint32_t pos_y; | |
334 | }; | |
335 | ||
d80efd5c TH |
336 | |
337 | /* | |
338 | * struct vmw_otable - Guest Memory OBject table metadata | |
339 | * | |
340 | * @size: Size of the table (page-aligned). | |
341 | * @page_table: Pointer to a struct vmw_mob holding the page table. | |
342 | */ | |
343 | struct vmw_otable { | |
344 | unsigned long size; | |
345 | struct vmw_mob *page_table; | |
346 | bool enabled; | |
347 | }; | |
348 | ||
349 | struct vmw_otable_batch { | |
350 | unsigned num_otables; | |
351 | struct vmw_otable *otables; | |
352 | struct vmw_resource *context; | |
353 | struct ttm_buffer_object *otable_bo; | |
354 | }; | |
355 | ||
ef369904 TH |
356 | enum { |
357 | VMW_IRQTHREAD_FENCE, | |
358 | VMW_IRQTHREAD_CMDBUF, | |
359 | VMW_IRQTHREAD_MAX | |
360 | }; | |
361 | ||
fb1d9738 JB |
362 | struct vmw_private { |
363 | struct ttm_bo_device bdev; | |
364 | struct ttm_bo_global_ref bo_global_ref; | |
ba4420c2 | 365 | struct drm_global_reference mem_global_ref; |
fb1d9738 JB |
366 | |
367 | struct vmw_fifo_state fifo; | |
368 | ||
369 | struct drm_device *dev; | |
370 | unsigned long vmw_chipset; | |
371 | unsigned int io_start; | |
372 | uint32_t vram_start; | |
373 | uint32_t vram_size; | |
bc2d6508 | 374 | uint32_t prim_bb_mem; |
fb1d9738 JB |
375 | uint32_t mmio_start; |
376 | uint32_t mmio_size; | |
377 | uint32_t fb_max_width; | |
378 | uint32_t fb_max_height; | |
35c05125 SY |
379 | uint32_t texture_max_width; |
380 | uint32_t texture_max_height; | |
381 | uint32_t stdu_max_width; | |
382 | uint32_t stdu_max_height; | |
eb4f923b JB |
383 | uint32_t initial_width; |
384 | uint32_t initial_height; | |
b76ff5ea | 385 | u32 *mmio_virt; |
fb1d9738 | 386 | uint32_t capabilities; |
fb1d9738 | 387 | uint32_t max_gmr_ids; |
fb17f189 | 388 | uint32_t max_gmr_pages; |
6da768aa | 389 | uint32_t max_mob_pages; |
857aea1c | 390 | uint32_t max_mob_size; |
fb17f189 | 391 | uint32_t memory_size; |
135cba0d | 392 | bool has_gmr; |
3530bdc3 | 393 | bool has_mob; |
496eb6fd TH |
394 | spinlock_t hw_lock; |
395 | spinlock_t cap_lock; | |
d80efd5c | 396 | bool has_dx; |
04319d89 | 397 | bool assume_16bpp; |
fb1d9738 JB |
398 | |
399 | /* | |
400 | * VGA registers. | |
401 | */ | |
402 | ||
7c4f7780 | 403 | struct vmw_vga_topology_state vga_save[VMWGFX_MAX_DISPLAYS]; |
fb1d9738 JB |
404 | uint32_t vga_width; |
405 | uint32_t vga_height; | |
fb1d9738 | 406 | uint32_t vga_bpp; |
7c4f7780 | 407 | uint32_t vga_bpl; |
d7e1958d | 408 | uint32_t vga_pitchlock; |
fb1d9738 | 409 | |
7c4f7780 TH |
410 | uint32_t num_displays; |
411 | ||
fb1d9738 JB |
412 | /* |
413 | * Framebuffer info. | |
414 | */ | |
415 | ||
416 | void *fb_info; | |
c8261a96 | 417 | enum vmw_display_unit_type active_display_unit; |
fb1d9738 JB |
418 | struct vmw_legacy_display *ldu_priv; |
419 | struct vmw_overlay *overlay_priv; | |
578e609a | 420 | struct drm_property *hotplug_mode_update_property; |
76404ac0 | 421 | struct drm_property *implicit_placement_property; |
75c06855 TH |
422 | unsigned num_implicit; |
423 | struct vmw_framebuffer *implicit_fb; | |
93cd1681 | 424 | struct mutex global_kms_state_mutex; |
36cc79bc | 425 | spinlock_t cursor_lock; |
fb1d9738 JB |
426 | |
427 | /* | |
428 | * Context and surface management. | |
429 | */ | |
430 | ||
431 | rwlock_t resource_lock; | |
c0951b79 | 432 | struct idr res_idr[vmw_res_max]; |
fb1d9738 JB |
433 | /* |
434 | * Block lastclose from racing with firstopen. | |
435 | */ | |
436 | ||
437 | struct mutex init_mutex; | |
438 | ||
439 | /* | |
440 | * A resource manager for kernel-only surfaces and | |
441 | * contexts. | |
442 | */ | |
443 | ||
444 | struct ttm_object_device *tdev; | |
445 | ||
446 | /* | |
447 | * Fencing and IRQs. | |
448 | */ | |
449 | ||
6bcd8d3c | 450 | atomic_t marker_seq; |
fb1d9738 JB |
451 | wait_queue_head_t fence_queue; |
452 | wait_queue_head_t fifo_queue; | |
496eb6fd TH |
453 | spinlock_t waiter_lock; |
454 | int fence_queue_waiters; /* Protected by waiter_lock */ | |
455 | int goal_queue_waiters; /* Protected by waiter_lock */ | |
d2e8851a TH |
456 | int cmdbuf_waiters; /* Protected by waiter_lock */ |
457 | int error_waiters; /* Protected by waiter_lock */ | |
458 | int fifo_queue_waiters; /* Protected by waiter_lock */ | |
6bcd8d3c | 459 | uint32_t last_read_seqno; |
ae2a1040 | 460 | struct vmw_fence_manager *fman; |
d2e8851a | 461 | uint32_t irq_mask; /* Updates protected by waiter_lock */ |
fb1d9738 JB |
462 | |
463 | /* | |
464 | * Device state | |
465 | */ | |
466 | ||
467 | uint32_t traces_state; | |
468 | uint32_t enable_state; | |
469 | uint32_t config_done_state; | |
470 | ||
471 | /** | |
472 | * Execbuf | |
473 | */ | |
474 | /** | |
475 | * Protected by the cmdbuf mutex. | |
476 | */ | |
477 | ||
478 | struct vmw_sw_context ctx; | |
fb1d9738 | 479 | struct mutex cmdbuf_mutex; |
173fb7d4 | 480 | struct mutex binding_mutex; |
fb1d9738 | 481 | |
fb1d9738 JB |
482 | /** |
483 | * Operating mode. | |
484 | */ | |
485 | ||
486 | bool stealth; | |
30c78bb8 | 487 | bool enable_fb; |
153b3d5b | 488 | spinlock_t svga_lock; |
fb1d9738 JB |
489 | |
490 | /** | |
491 | * Master management. | |
492 | */ | |
493 | ||
494 | struct vmw_master *active_master; | |
495 | struct vmw_master fbdev_master; | |
d9f36a00 | 496 | struct notifier_block pm_nb; |
094e0fa8 | 497 | bool suspended; |
153b3d5b | 498 | bool refuse_hibernation; |
30c78bb8 TH |
499 | |
500 | struct mutex release_mutex; | |
153b3d5b | 501 | atomic_t num_fifo_resources; |
e2fa3a76 | 502 | |
294adf7d TH |
503 | /* |
504 | * Replace this with an rwsem as soon as we have down_xx_interruptible() | |
505 | */ | |
506 | struct ttm_lock reservation_sem; | |
507 | ||
e2fa3a76 TH |
508 | /* |
509 | * Query processing. These members | |
510 | * are protected by the cmdbuf mutex. | |
511 | */ | |
512 | ||
459d0fa7 TH |
513 | struct vmw_dma_buffer *dummy_query_bo; |
514 | struct vmw_dma_buffer *pinned_bo; | |
e2fa3a76 | 515 | uint32_t query_cid; |
c0951b79 | 516 | uint32_t query_cid_valid; |
e2fa3a76 | 517 | bool dummy_query_bo_pinned; |
5bb39e81 TH |
518 | |
519 | /* | |
520 | * Surface swapping. The "surface_lru" list is protected by the | |
521 | * resource lock in order to be able to destroy a surface and take | |
522 | * it off the lru atomically. "used_memory_size" is currently | |
523 | * protected by the cmdbuf mutex for simplicity. | |
524 | */ | |
525 | ||
c0951b79 | 526 | struct list_head res_lru[vmw_res_max]; |
5bb39e81 | 527 | uint32_t used_memory_size; |
d92d9851 TH |
528 | |
529 | /* | |
530 | * DMA mapping stuff. | |
531 | */ | |
532 | enum vmw_dma_map_mode map_mode; | |
3530bdc3 TH |
533 | |
534 | /* | |
535 | * Guest Backed stuff | |
536 | */ | |
d80efd5c | 537 | struct vmw_otable_batch otable_batch; |
3eab3d9e TH |
538 | |
539 | struct vmw_cmdbuf_man *cman; | |
ef369904 | 540 | DECLARE_BITMAP(irqthread_pending, VMW_IRQTHREAD_MAX); |
fb1d9738 JB |
541 | }; |
542 | ||
c0951b79 TH |
543 | static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res) |
544 | { | |
545 | return container_of(res, struct vmw_surface, res); | |
546 | } | |
547 | ||
fb1d9738 JB |
548 | static inline struct vmw_private *vmw_priv(struct drm_device *dev) |
549 | { | |
550 | return (struct vmw_private *)dev->dev_private; | |
551 | } | |
552 | ||
553 | static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv) | |
554 | { | |
555 | return (struct vmw_fpriv *)file_priv->driver_priv; | |
556 | } | |
557 | ||
558 | static inline struct vmw_master *vmw_master(struct drm_master *master) | |
559 | { | |
560 | return (struct vmw_master *) master->driver_priv; | |
561 | } | |
562 | ||
496eb6fd TH |
563 | /* |
564 | * The locking here is fine-grained, so that it is performed once | |
565 | * for every read- and write operation. This is of course costly, but we | |
566 | * don't perform much register access in the timing critical paths anyway. | |
567 | * Instead we have the extra benefit of being sure that we don't forget | |
568 | * the hw lock around register accesses. | |
569 | */ | |
fb1d9738 JB |
570 | static inline void vmw_write(struct vmw_private *dev_priv, |
571 | unsigned int offset, uint32_t value) | |
572 | { | |
ef369904 | 573 | spin_lock(&dev_priv->hw_lock); |
fb1d9738 JB |
574 | outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT); |
575 | outl(value, dev_priv->io_start + VMWGFX_VALUE_PORT); | |
ef369904 | 576 | spin_unlock(&dev_priv->hw_lock); |
fb1d9738 JB |
577 | } |
578 | ||
579 | static inline uint32_t vmw_read(struct vmw_private *dev_priv, | |
580 | unsigned int offset) | |
581 | { | |
496eb6fd | 582 | u32 val; |
fb1d9738 | 583 | |
ef369904 | 584 | spin_lock(&dev_priv->hw_lock); |
fb1d9738 JB |
585 | outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT); |
586 | val = inl(dev_priv->io_start + VMWGFX_VALUE_PORT); | |
ef369904 | 587 | spin_unlock(&dev_priv->hw_lock); |
496eb6fd | 588 | |
fb1d9738 JB |
589 | return val; |
590 | } | |
591 | ||
153b3d5b TH |
592 | extern void vmw_svga_enable(struct vmw_private *dev_priv); |
593 | extern void vmw_svga_disable(struct vmw_private *dev_priv); | |
594 | ||
30c78bb8 | 595 | |
fb1d9738 JB |
596 | /** |
597 | * GMR utilities - vmwgfx_gmr.c | |
598 | */ | |
599 | ||
600 | extern int vmw_gmr_bind(struct vmw_private *dev_priv, | |
d92d9851 | 601 | const struct vmw_sg_table *vsgt, |
135cba0d TH |
602 | unsigned long num_pages, |
603 | int gmr_id); | |
fb1d9738 JB |
604 | extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id); |
605 | ||
606 | /** | |
607 | * Resource utilities - vmwgfx_resource.c | |
608 | */ | |
c0951b79 | 609 | struct vmw_user_resource_conv; |
fb1d9738 | 610 | |
fb1d9738 JB |
611 | extern void vmw_resource_unreference(struct vmw_resource **p_res); |
612 | extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res); | |
30f82d81 TH |
613 | extern struct vmw_resource * |
614 | vmw_resource_reference_unless_doomed(struct vmw_resource *res); | |
c0951b79 | 615 | extern int vmw_resource_validate(struct vmw_resource *res); |
1a4b172a TH |
616 | extern int vmw_resource_reserve(struct vmw_resource *res, bool interruptible, |
617 | bool no_backup); | |
c0951b79 | 618 | extern bool vmw_resource_needs_backup(const struct vmw_resource *res); |
551a6697 JB |
619 | extern int vmw_user_lookup_handle(struct vmw_private *dev_priv, |
620 | struct ttm_object_file *tfile, | |
621 | uint32_t handle, | |
622 | struct vmw_surface **out_surf, | |
623 | struct vmw_dma_buffer **out_buf); | |
c0951b79 TH |
624 | extern int vmw_user_resource_lookup_handle( |
625 | struct vmw_private *dev_priv, | |
626 | struct ttm_object_file *tfile, | |
627 | uint32_t handle, | |
628 | const struct vmw_user_resource_conv *converter, | |
629 | struct vmw_resource **p_res); | |
fb1d9738 JB |
630 | extern void vmw_dmabuf_bo_free(struct ttm_buffer_object *bo); |
631 | extern int vmw_dmabuf_init(struct vmw_private *dev_priv, | |
632 | struct vmw_dma_buffer *vmw_bo, | |
633 | size_t size, struct ttm_placement *placement, | |
634 | bool interuptable, | |
635 | void (*bo_free) (struct ttm_buffer_object *bo)); | |
d08a9b9c TH |
636 | extern int vmw_user_dmabuf_verify_access(struct ttm_buffer_object *bo, |
637 | struct ttm_object_file *tfile); | |
a97e2192 TH |
638 | extern int vmw_user_dmabuf_alloc(struct vmw_private *dev_priv, |
639 | struct ttm_object_file *tfile, | |
640 | uint32_t size, | |
641 | bool shareable, | |
642 | uint32_t *handle, | |
54c12bc3 TH |
643 | struct vmw_dma_buffer **p_dma_buf, |
644 | struct ttm_base_object **p_base); | |
a97e2192 TH |
645 | extern int vmw_user_dmabuf_reference(struct ttm_object_file *tfile, |
646 | struct vmw_dma_buffer *dma_buf, | |
647 | uint32_t *handle); | |
fb1d9738 JB |
648 | extern int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data, |
649 | struct drm_file *file_priv); | |
650 | extern int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data, | |
651 | struct drm_file *file_priv); | |
1d7a5cbf TH |
652 | extern int vmw_user_dmabuf_synccpu_ioctl(struct drm_device *dev, void *data, |
653 | struct drm_file *file_priv); | |
fb1d9738 JB |
654 | extern uint32_t vmw_dmabuf_validate_node(struct ttm_buffer_object *bo, |
655 | uint32_t cur_validate_node); | |
656 | extern void vmw_dmabuf_validate_clear(struct ttm_buffer_object *bo); | |
657 | extern int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile, | |
54c12bc3 TH |
658 | uint32_t id, struct vmw_dma_buffer **out, |
659 | struct ttm_base_object **base); | |
fb1d9738 JB |
660 | extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data, |
661 | struct drm_file *file_priv); | |
662 | extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data, | |
663 | struct drm_file *file_priv); | |
664 | extern int vmw_user_stream_lookup(struct vmw_private *dev_priv, | |
665 | struct ttm_object_file *tfile, | |
666 | uint32_t *inout_id, | |
667 | struct vmw_resource **out); | |
c0951b79 | 668 | extern void vmw_resource_unreserve(struct vmw_resource *res, |
d80efd5c | 669 | bool switch_backup, |
c0951b79 TH |
670 | struct vmw_dma_buffer *new_backup, |
671 | unsigned long new_backup_offset); | |
672 | extern void vmw_resource_move_notify(struct ttm_buffer_object *bo, | |
673 | struct ttm_mem_reg *mem); | |
fd11a3c0 SY |
674 | extern void vmw_query_move_notify(struct ttm_buffer_object *bo, |
675 | struct ttm_mem_reg *mem); | |
676 | extern int vmw_query_readback_all(struct vmw_dma_buffer *dx_query_mob); | |
c0951b79 TH |
677 | extern void vmw_fence_single_bo(struct ttm_buffer_object *bo, |
678 | struct vmw_fence_obj *fence); | |
679 | extern void vmw_resource_evict_all(struct vmw_private *dev_priv); | |
fb1d9738 | 680 | |
d991ef03 JB |
681 | /** |
682 | * DMA buffer helper routines - vmwgfx_dmabuf.c | |
683 | */ | |
459d0fa7 | 684 | extern int vmw_dmabuf_pin_in_placement(struct vmw_private *vmw_priv, |
d991ef03 | 685 | struct vmw_dma_buffer *bo, |
459d0fa7 TH |
686 | struct ttm_placement *placement, |
687 | bool interruptible); | |
688 | extern int vmw_dmabuf_pin_in_vram(struct vmw_private *dev_priv, | |
689 | struct vmw_dma_buffer *buf, | |
690 | bool interruptible); | |
691 | extern int vmw_dmabuf_pin_in_vram_or_gmr(struct vmw_private *dev_priv, | |
692 | struct vmw_dma_buffer *buf, | |
693 | bool interruptible); | |
694 | extern int vmw_dmabuf_pin_in_start_of_vram(struct vmw_private *vmw_priv, | |
695 | struct vmw_dma_buffer *bo, | |
696 | bool interruptible); | |
d991ef03 JB |
697 | extern int vmw_dmabuf_unpin(struct vmw_private *vmw_priv, |
698 | struct vmw_dma_buffer *bo, | |
699 | bool interruptible); | |
b37a6b9a TH |
700 | extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf, |
701 | SVGAGuestPtr *ptr); | |
459d0fa7 | 702 | extern void vmw_bo_pin_reserved(struct vmw_dma_buffer *bo, bool pin); |
fb1d9738 JB |
703 | |
704 | /** | |
705 | * Misc Ioctl functionality - vmwgfx_ioctl.c | |
706 | */ | |
707 | ||
708 | extern int vmw_getparam_ioctl(struct drm_device *dev, void *data, | |
709 | struct drm_file *file_priv); | |
f63f6a59 TH |
710 | extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data, |
711 | struct drm_file *file_priv); | |
2fcd5a73 JB |
712 | extern int vmw_present_ioctl(struct drm_device *dev, void *data, |
713 | struct drm_file *file_priv); | |
714 | extern int vmw_present_readback_ioctl(struct drm_device *dev, void *data, | |
715 | struct drm_file *file_priv); | |
afc9a42b | 716 | extern __poll_t vmw_fops_poll(struct file *filp, |
5438ae88 TH |
717 | struct poll_table_struct *wait); |
718 | extern ssize_t vmw_fops_read(struct file *filp, char __user *buffer, | |
719 | size_t count, loff_t *offset); | |
fb1d9738 JB |
720 | |
721 | /** | |
722 | * Fifo utilities - vmwgfx_fifo.c | |
723 | */ | |
724 | ||
725 | extern int vmw_fifo_init(struct vmw_private *dev_priv, | |
726 | struct vmw_fifo_state *fifo); | |
727 | extern void vmw_fifo_release(struct vmw_private *dev_priv, | |
728 | struct vmw_fifo_state *fifo); | |
729 | extern void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes); | |
d80efd5c TH |
730 | extern void * |
731 | vmw_fifo_reserve_dx(struct vmw_private *dev_priv, uint32_t bytes, int ctx_id); | |
fb1d9738 | 732 | extern void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes); |
d80efd5c | 733 | extern void vmw_fifo_commit_flush(struct vmw_private *dev_priv, uint32_t bytes); |
fb1d9738 | 734 | extern int vmw_fifo_send_fence(struct vmw_private *dev_priv, |
6bcd8d3c | 735 | uint32_t *seqno); |
2298e804 | 736 | extern void vmw_fifo_ping_host_locked(struct vmw_private *, uint32_t reason); |
fb1d9738 | 737 | extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason); |
8e19a951 | 738 | extern bool vmw_fifo_have_3d(struct vmw_private *dev_priv); |
d7e1958d | 739 | extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv); |
e2fa3a76 TH |
740 | extern int vmw_fifo_emit_dummy_query(struct vmw_private *dev_priv, |
741 | uint32_t cid); | |
3eab3d9e TH |
742 | extern int vmw_fifo_flush(struct vmw_private *dev_priv, |
743 | bool interruptible); | |
fb1d9738 JB |
744 | |
745 | /** | |
746 | * TTM glue - vmwgfx_ttm_glue.c | |
747 | */ | |
748 | ||
749 | extern int vmw_ttm_global_init(struct vmw_private *dev_priv); | |
750 | extern void vmw_ttm_global_release(struct vmw_private *dev_priv); | |
751 | extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma); | |
752 | ||
753 | /** | |
754 | * TTM buffer object driver - vmwgfx_buffer.c | |
755 | */ | |
756 | ||
308d17ef | 757 | extern const size_t vmw_tt_size; |
fb1d9738 JB |
758 | extern struct ttm_placement vmw_vram_placement; |
759 | extern struct ttm_placement vmw_vram_ne_placement; | |
8ba5152a | 760 | extern struct ttm_placement vmw_vram_sys_placement; |
135cba0d | 761 | extern struct ttm_placement vmw_vram_gmr_placement; |
d991ef03 | 762 | extern struct ttm_placement vmw_vram_gmr_ne_placement; |
fb1d9738 | 763 | extern struct ttm_placement vmw_sys_placement; |
3530bdc3 | 764 | extern struct ttm_placement vmw_sys_ne_placement; |
d991ef03 | 765 | extern struct ttm_placement vmw_evictable_placement; |
5bb39e81 | 766 | extern struct ttm_placement vmw_srf_placement; |
96c5f0df | 767 | extern struct ttm_placement vmw_mob_placement; |
3eab3d9e | 768 | extern struct ttm_placement vmw_mob_ne_placement; |
fb1d9738 JB |
769 | extern struct ttm_bo_driver vmw_bo_driver; |
770 | extern int vmw_dma_quiescent(struct drm_device *dev); | |
0fd53cfb TH |
771 | extern int vmw_bo_map_dma(struct ttm_buffer_object *bo); |
772 | extern void vmw_bo_unmap_dma(struct ttm_buffer_object *bo); | |
773 | extern const struct vmw_sg_table * | |
774 | vmw_bo_sg_table(struct ttm_buffer_object *bo); | |
d92d9851 TH |
775 | extern void vmw_piter_start(struct vmw_piter *viter, |
776 | const struct vmw_sg_table *vsgt, | |
777 | unsigned long p_offs); | |
778 | ||
779 | /** | |
780 | * vmw_piter_next - Advance the iterator one page. | |
781 | * | |
782 | * @viter: Pointer to the iterator to advance. | |
783 | * | |
784 | * Returns false if past the list of pages, true otherwise. | |
785 | */ | |
786 | static inline bool vmw_piter_next(struct vmw_piter *viter) | |
787 | { | |
788 | return viter->next(viter); | |
789 | } | |
790 | ||
791 | /** | |
792 | * vmw_piter_dma_addr - Return the DMA address of the current page. | |
793 | * | |
794 | * @viter: Pointer to the iterator | |
795 | * | |
796 | * Returns the DMA address of the page pointed to by @viter. | |
797 | */ | |
798 | static inline dma_addr_t vmw_piter_dma_addr(struct vmw_piter *viter) | |
799 | { | |
800 | return viter->dma_address(viter); | |
801 | } | |
802 | ||
803 | /** | |
804 | * vmw_piter_page - Return a pointer to the current page. | |
805 | * | |
806 | * @viter: Pointer to the iterator | |
807 | * | |
808 | * Returns the DMA address of the page pointed to by @viter. | |
809 | */ | |
810 | static inline struct page *vmw_piter_page(struct vmw_piter *viter) | |
811 | { | |
812 | return viter->page(viter); | |
813 | } | |
fb1d9738 JB |
814 | |
815 | /** | |
816 | * Command submission - vmwgfx_execbuf.c | |
817 | */ | |
818 | ||
d80efd5c TH |
819 | extern int vmw_execbuf_ioctl(struct drm_device *dev, unsigned long data, |
820 | struct drm_file *file_priv, size_t size); | |
922ade0d TH |
821 | extern int vmw_execbuf_process(struct drm_file *file_priv, |
822 | struct vmw_private *dev_priv, | |
823 | void __user *user_commands, | |
824 | void *kernel_commands, | |
825 | uint32_t command_size, | |
826 | uint64_t throttle_us, | |
d80efd5c | 827 | uint32_t dx_context_handle, |
922ade0d | 828 | struct drm_vmw_fence_rep __user |
bb1bd2f4 | 829 | *user_fence_rep, |
c906965d SY |
830 | struct vmw_fence_obj **out_fence, |
831 | uint32_t flags); | |
c0951b79 TH |
832 | extern void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv, |
833 | struct vmw_fence_obj *fence); | |
834 | extern void vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv); | |
e2fa3a76 | 835 | |
5bb39e81 TH |
836 | extern int vmw_execbuf_fence_commands(struct drm_file *file_priv, |
837 | struct vmw_private *dev_priv, | |
838 | struct vmw_fence_obj **p_fence, | |
839 | uint32_t *p_handle); | |
57c5ee79 TH |
840 | extern void vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv, |
841 | struct vmw_fpriv *vmw_fp, | |
842 | int ret, | |
843 | struct drm_vmw_fence_rep __user | |
844 | *user_fence_rep, | |
845 | struct vmw_fence_obj *fence, | |
c906965d SY |
846 | uint32_t fence_handle, |
847 | int32_t out_fence_fd, | |
848 | struct sync_file *sync_file); | |
1a4b172a TH |
849 | extern int vmw_validate_single_buffer(struct vmw_private *dev_priv, |
850 | struct ttm_buffer_object *bo, | |
851 | bool interruptible, | |
852 | bool validate_as_mob); | |
65b97a2b | 853 | bool vmw_cmd_describe(const void *buf, u32 *size, char const **cmd); |
5bb39e81 | 854 | |
fb1d9738 JB |
855 | /** |
856 | * IRQs and wating - vmwgfx_irq.c | |
857 | */ | |
858 | ||
6bcd8d3c | 859 | extern int vmw_wait_seqno(struct vmw_private *dev_priv, bool lazy, |
c8261a96 SY |
860 | uint32_t seqno, bool interruptible, |
861 | unsigned long timeout); | |
e300173f | 862 | extern int vmw_irq_install(struct drm_device *dev, int irq); |
fb1d9738 | 863 | extern void vmw_irq_uninstall(struct drm_device *dev); |
6bcd8d3c TH |
864 | extern bool vmw_seqno_passed(struct vmw_private *dev_priv, |
865 | uint32_t seqno); | |
fb1d9738 JB |
866 | extern int vmw_fallback_wait(struct vmw_private *dev_priv, |
867 | bool lazy, | |
868 | bool fifo_idle, | |
6bcd8d3c | 869 | uint32_t seqno, |
fb1d9738 JB |
870 | bool interruptible, |
871 | unsigned long timeout); | |
6bcd8d3c | 872 | extern void vmw_update_seqno(struct vmw_private *dev_priv, |
1925d456 | 873 | struct vmw_fifo_state *fifo_state); |
ae2a1040 TH |
874 | extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv); |
875 | extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv); | |
57c5ee79 TH |
876 | extern void vmw_goal_waiter_add(struct vmw_private *dev_priv); |
877 | extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv); | |
3eab3d9e TH |
878 | extern void vmw_generic_waiter_add(struct vmw_private *dev_priv, u32 flag, |
879 | int *waiter_count); | |
880 | extern void vmw_generic_waiter_remove(struct vmw_private *dev_priv, | |
881 | u32 flag, int *waiter_count); | |
1925d456 TH |
882 | |
883 | /** | |
6bcd8d3c TH |
884 | * Rudimentary fence-like objects currently used only for throttling - |
885 | * vmwgfx_marker.c | |
1925d456 TH |
886 | */ |
887 | ||
6bcd8d3c TH |
888 | extern void vmw_marker_queue_init(struct vmw_marker_queue *queue); |
889 | extern void vmw_marker_queue_takedown(struct vmw_marker_queue *queue); | |
890 | extern int vmw_marker_push(struct vmw_marker_queue *queue, | |
c8261a96 | 891 | uint32_t seqno); |
6bcd8d3c | 892 | extern int vmw_marker_pull(struct vmw_marker_queue *queue, |
c8261a96 | 893 | uint32_t signaled_seqno); |
1925d456 | 894 | extern int vmw_wait_lag(struct vmw_private *dev_priv, |
6bcd8d3c | 895 | struct vmw_marker_queue *queue, uint32_t us); |
fb1d9738 JB |
896 | |
897 | /** | |
898 | * Kernel framebuffer - vmwgfx_fb.c | |
899 | */ | |
900 | ||
901 | int vmw_fb_init(struct vmw_private *vmw_priv); | |
902 | int vmw_fb_close(struct vmw_private *dev_priv); | |
903 | int vmw_fb_off(struct vmw_private *vmw_priv); | |
904 | int vmw_fb_on(struct vmw_private *vmw_priv); | |
905 | ||
906 | /** | |
907 | * Kernel modesetting - vmwgfx_kms.c | |
908 | */ | |
909 | ||
910 | int vmw_kms_init(struct vmw_private *dev_priv); | |
911 | int vmw_kms_close(struct vmw_private *dev_priv); | |
912 | int vmw_kms_save_vga(struct vmw_private *vmw_priv); | |
913 | int vmw_kms_restore_vga(struct vmw_private *vmw_priv); | |
914 | int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data, | |
915 | struct drm_file *file_priv); | |
916 | void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv); | |
917 | void vmw_kms_cursor_snoop(struct vmw_surface *srf, | |
918 | struct ttm_object_file *tfile, | |
919 | struct ttm_buffer_object *bo, | |
920 | SVGA3dCmdHeader *header); | |
0bef23f9 MD |
921 | int vmw_kms_write_svga(struct vmw_private *vmw_priv, |
922 | unsigned width, unsigned height, unsigned pitch, | |
923 | unsigned bpp, unsigned depth); | |
3a939a5e | 924 | void vmw_kms_idle_workqueues(struct vmw_master *vmaster); |
e133e737 TH |
925 | bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv, |
926 | uint32_t pitch, | |
927 | uint32_t height); | |
88e72717 TR |
928 | u32 vmw_get_vblank_counter(struct drm_device *dev, unsigned int pipe); |
929 | int vmw_enable_vblank(struct drm_device *dev, unsigned int pipe); | |
930 | void vmw_disable_vblank(struct drm_device *dev, unsigned int pipe); | |
2fcd5a73 JB |
931 | int vmw_kms_present(struct vmw_private *dev_priv, |
932 | struct drm_file *file_priv, | |
933 | struct vmw_framebuffer *vfb, | |
934 | struct vmw_surface *surface, | |
935 | uint32_t sid, int32_t destX, int32_t destY, | |
936 | struct drm_vmw_rect *clips, | |
937 | uint32_t num_clips); | |
cd2b89e7 TH |
938 | int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data, |
939 | struct drm_file *file_priv); | |
8fbf9d92 | 940 | void vmw_kms_legacy_hotspot_clear(struct vmw_private *dev_priv); |
140bcaa2 | 941 | void vmw_kms_lost_device(struct drm_device *dev); |
fb1d9738 | 942 | |
5e1782d2 DA |
943 | int vmw_dumb_create(struct drm_file *file_priv, |
944 | struct drm_device *dev, | |
945 | struct drm_mode_create_dumb *args); | |
946 | ||
947 | int vmw_dumb_map_offset(struct drm_file *file_priv, | |
948 | struct drm_device *dev, uint32_t handle, | |
949 | uint64_t *offset); | |
950 | int vmw_dumb_destroy(struct drm_file *file_priv, | |
951 | struct drm_device *dev, | |
952 | uint32_t handle); | |
1a4b172a | 953 | extern int vmw_resource_pin(struct vmw_resource *res, bool interruptible); |
ed93394c | 954 | extern void vmw_resource_unpin(struct vmw_resource *res); |
d80efd5c | 955 | extern enum vmw_res_type vmw_res_type(const struct vmw_resource *res); |
ed93394c | 956 | |
fb1d9738 JB |
957 | /** |
958 | * Overlay control - vmwgfx_overlay.c | |
959 | */ | |
960 | ||
961 | int vmw_overlay_init(struct vmw_private *dev_priv); | |
962 | int vmw_overlay_close(struct vmw_private *dev_priv); | |
963 | int vmw_overlay_ioctl(struct drm_device *dev, void *data, | |
964 | struct drm_file *file_priv); | |
965 | int vmw_overlay_stop_all(struct vmw_private *dev_priv); | |
966 | int vmw_overlay_resume_all(struct vmw_private *dev_priv); | |
967 | int vmw_overlay_pause_all(struct vmw_private *dev_priv); | |
968 | int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out); | |
969 | int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id); | |
970 | int vmw_overlay_num_overlays(struct vmw_private *dev_priv); | |
971 | int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv); | |
972 | ||
135cba0d TH |
973 | /** |
974 | * GMR Id manager | |
975 | */ | |
976 | ||
977 | extern const struct ttm_mem_type_manager_func vmw_gmrid_manager_func; | |
978 | ||
69977ff5 TH |
979 | /** |
980 | * Prime - vmwgfx_prime.c | |
981 | */ | |
982 | ||
983 | extern const struct dma_buf_ops vmw_prime_dmabuf_ops; | |
984 | extern int vmw_prime_fd_to_handle(struct drm_device *dev, | |
985 | struct drm_file *file_priv, | |
986 | int fd, u32 *handle); | |
987 | extern int vmw_prime_handle_to_fd(struct drm_device *dev, | |
988 | struct drm_file *file_priv, | |
989 | uint32_t handle, uint32_t flags, | |
990 | int *prime_fd); | |
991 | ||
3530bdc3 TH |
992 | /* |
993 | * MemoryOBject management - vmwgfx_mob.c | |
994 | */ | |
995 | struct vmw_mob; | |
996 | extern int vmw_mob_bind(struct vmw_private *dev_priv, struct vmw_mob *mob, | |
0fd53cfb TH |
997 | const struct vmw_sg_table *vsgt, |
998 | unsigned long num_data_pages, int32_t mob_id); | |
3530bdc3 TH |
999 | extern void vmw_mob_unbind(struct vmw_private *dev_priv, |
1000 | struct vmw_mob *mob); | |
1001 | extern void vmw_mob_destroy(struct vmw_mob *mob); | |
1002 | extern struct vmw_mob *vmw_mob_create(unsigned long data_pages); | |
1003 | extern int vmw_otables_setup(struct vmw_private *dev_priv); | |
1004 | extern void vmw_otables_takedown(struct vmw_private *dev_priv); | |
69977ff5 | 1005 | |
7086d099 TH |
1006 | /* |
1007 | * Context management - vmwgfx_context.c | |
1008 | */ | |
1009 | ||
1010 | extern const struct vmw_user_resource_conv *user_context_converter; | |
1011 | ||
7086d099 TH |
1012 | extern int vmw_context_check(struct vmw_private *dev_priv, |
1013 | struct ttm_object_file *tfile, | |
1014 | int id, | |
1015 | struct vmw_resource **p_res); | |
1016 | extern int vmw_context_define_ioctl(struct drm_device *dev, void *data, | |
1017 | struct drm_file *file_priv); | |
d80efd5c TH |
1018 | extern int vmw_extended_context_define_ioctl(struct drm_device *dev, void *data, |
1019 | struct drm_file *file_priv); | |
7086d099 TH |
1020 | extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data, |
1021 | struct drm_file *file_priv); | |
30f82d81 | 1022 | extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx); |
18e4a466 TH |
1023 | extern struct vmw_cmdbuf_res_manager * |
1024 | vmw_context_res_man(struct vmw_resource *ctx); | |
d80efd5c TH |
1025 | extern struct vmw_resource *vmw_context_cotable(struct vmw_resource *ctx, |
1026 | SVGACOTableType cotable_type); | |
1027 | extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx); | |
1028 | struct vmw_ctx_binding_state; | |
1029 | extern struct vmw_ctx_binding_state * | |
1030 | vmw_context_binding_state(struct vmw_resource *ctx); | |
1031 | extern void vmw_dx_context_scrub_cotables(struct vmw_resource *ctx, | |
1032 | bool readback); | |
fd11a3c0 SY |
1033 | extern int vmw_context_bind_dx_query(struct vmw_resource *ctx_res, |
1034 | struct vmw_dma_buffer *mob); | |
1035 | extern struct vmw_dma_buffer * | |
1036 | vmw_context_get_dx_query_mob(struct vmw_resource *ctx_res); | |
1037 | ||
d80efd5c | 1038 | |
7086d099 TH |
1039 | /* |
1040 | * Surface management - vmwgfx_surface.c | |
1041 | */ | |
1042 | ||
1043 | extern const struct vmw_user_resource_conv *user_surface_converter; | |
1044 | ||
1045 | extern void vmw_surface_res_free(struct vmw_resource *res); | |
1046 | extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data, | |
1047 | struct drm_file *file_priv); | |
1048 | extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data, | |
1049 | struct drm_file *file_priv); | |
1050 | extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data, | |
1051 | struct drm_file *file_priv); | |
1052 | extern int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data, | |
1053 | struct drm_file *file_priv); | |
1054 | extern int vmw_gb_surface_reference_ioctl(struct drm_device *dev, void *data, | |
1055 | struct drm_file *file_priv); | |
1056 | extern int vmw_surface_check(struct vmw_private *dev_priv, | |
1057 | struct ttm_object_file *tfile, | |
1058 | uint32_t handle, int *id); | |
1059 | extern int vmw_surface_validate(struct vmw_private *dev_priv, | |
1060 | struct vmw_surface *srf); | |
233826a7 SY |
1061 | int vmw_surface_gb_priv_define(struct drm_device *dev, |
1062 | uint32_t user_accounting_size, | |
1063 | uint32_t svga3d_flags, | |
1064 | SVGA3dSurfaceFormat format, | |
1065 | bool for_scanout, | |
1066 | uint32_t num_mip_levels, | |
1067 | uint32_t multisample_count, | |
d80efd5c | 1068 | uint32_t array_size, |
233826a7 SY |
1069 | struct drm_vmw_size size, |
1070 | struct vmw_surface **srf_out); | |
7086d099 | 1071 | |
c74c162f TH |
1072 | /* |
1073 | * Shader management - vmwgfx_shader.c | |
1074 | */ | |
1075 | ||
7086d099 TH |
1076 | extern const struct vmw_user_resource_conv *user_shader_converter; |
1077 | ||
c74c162f TH |
1078 | extern int vmw_shader_define_ioctl(struct drm_device *dev, void *data, |
1079 | struct drm_file *file_priv); | |
1080 | extern int vmw_shader_destroy_ioctl(struct drm_device *dev, void *data, | |
1081 | struct drm_file *file_priv); | |
18e4a466 TH |
1082 | extern int vmw_compat_shader_add(struct vmw_private *dev_priv, |
1083 | struct vmw_cmdbuf_res_manager *man, | |
d5bde956 TH |
1084 | u32 user_key, const void *bytecode, |
1085 | SVGA3dShaderType shader_type, | |
1086 | size_t size, | |
d5bde956 | 1087 | struct list_head *list); |
d80efd5c TH |
1088 | extern int vmw_shader_remove(struct vmw_cmdbuf_res_manager *man, |
1089 | u32 user_key, SVGA3dShaderType shader_type, | |
1090 | struct list_head *list); | |
1091 | extern int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man, | |
1092 | struct vmw_resource *ctx, | |
1093 | u32 user_key, | |
1094 | SVGA3dShaderType shader_type, | |
1095 | struct list_head *list); | |
1096 | extern void vmw_dx_shader_cotable_list_scrub(struct vmw_private *dev_priv, | |
1097 | struct list_head *list, | |
1098 | bool readback); | |
1099 | ||
18e4a466 | 1100 | extern struct vmw_resource * |
d80efd5c TH |
1101 | vmw_shader_lookup(struct vmw_cmdbuf_res_manager *man, |
1102 | u32 user_key, SVGA3dShaderType shader_type); | |
18e4a466 TH |
1103 | |
1104 | /* | |
1105 | * Command buffer managed resources - vmwgfx_cmdbuf_res.c | |
1106 | */ | |
1107 | ||
1108 | extern struct vmw_cmdbuf_res_manager * | |
1109 | vmw_cmdbuf_res_man_create(struct vmw_private *dev_priv); | |
1110 | extern void vmw_cmdbuf_res_man_destroy(struct vmw_cmdbuf_res_manager *man); | |
1111 | extern size_t vmw_cmdbuf_res_man_size(void); | |
1112 | extern struct vmw_resource * | |
1113 | vmw_cmdbuf_res_lookup(struct vmw_cmdbuf_res_manager *man, | |
1114 | enum vmw_cmdbuf_res_type res_type, | |
1115 | u32 user_key); | |
1116 | extern void vmw_cmdbuf_res_revert(struct list_head *list); | |
1117 | extern void vmw_cmdbuf_res_commit(struct list_head *list); | |
1118 | extern int vmw_cmdbuf_res_add(struct vmw_cmdbuf_res_manager *man, | |
1119 | enum vmw_cmdbuf_res_type res_type, | |
1120 | u32 user_key, | |
1121 | struct vmw_resource *res, | |
1122 | struct list_head *list); | |
1123 | extern int vmw_cmdbuf_res_remove(struct vmw_cmdbuf_res_manager *man, | |
1124 | enum vmw_cmdbuf_res_type res_type, | |
1125 | u32 user_key, | |
d80efd5c TH |
1126 | struct list_head *list, |
1127 | struct vmw_resource **res); | |
d5bde956 | 1128 | |
d80efd5c TH |
1129 | /* |
1130 | * COTable management - vmwgfx_cotable.c | |
1131 | */ | |
1132 | extern const SVGACOTableType vmw_cotable_scrub_order[]; | |
1133 | extern struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv, | |
1134 | struct vmw_resource *ctx, | |
1135 | u32 type); | |
1136 | extern int vmw_cotable_notify(struct vmw_resource *res, int id); | |
1137 | extern int vmw_cotable_scrub(struct vmw_resource *res, bool readback); | |
1138 | extern void vmw_cotable_add_resource(struct vmw_resource *ctx, | |
1139 | struct list_head *head); | |
c74c162f | 1140 | |
3eab3d9e TH |
1141 | /* |
1142 | * Command buffer managerment vmwgfx_cmdbuf.c | |
1143 | */ | |
1144 | struct vmw_cmdbuf_man; | |
1145 | struct vmw_cmdbuf_header; | |
1146 | ||
1147 | extern struct vmw_cmdbuf_man * | |
1148 | vmw_cmdbuf_man_create(struct vmw_private *dev_priv); | |
1149 | extern int vmw_cmdbuf_set_pool_size(struct vmw_cmdbuf_man *man, | |
1150 | size_t size, size_t default_size); | |
1151 | extern void vmw_cmdbuf_remove_pool(struct vmw_cmdbuf_man *man); | |
1152 | extern void vmw_cmdbuf_man_destroy(struct vmw_cmdbuf_man *man); | |
1153 | extern int vmw_cmdbuf_idle(struct vmw_cmdbuf_man *man, bool interruptible, | |
1154 | unsigned long timeout); | |
1155 | extern void *vmw_cmdbuf_reserve(struct vmw_cmdbuf_man *man, size_t size, | |
1156 | int ctx_id, bool interruptible, | |
1157 | struct vmw_cmdbuf_header *header); | |
1158 | extern void vmw_cmdbuf_commit(struct vmw_cmdbuf_man *man, size_t size, | |
1159 | struct vmw_cmdbuf_header *header, | |
1160 | bool flush); | |
3eab3d9e TH |
1161 | extern void *vmw_cmdbuf_alloc(struct vmw_cmdbuf_man *man, |
1162 | size_t size, bool interruptible, | |
1163 | struct vmw_cmdbuf_header **p_header); | |
1164 | extern void vmw_cmdbuf_header_free(struct vmw_cmdbuf_header *header); | |
1165 | extern int vmw_cmdbuf_cur_flush(struct vmw_cmdbuf_man *man, | |
1166 | bool interruptible); | |
ef369904 | 1167 | extern void vmw_cmdbuf_irqthread(struct vmw_cmdbuf_man *man); |
d5bde956 | 1168 | |
c74c162f | 1169 | |
fb1d9738 JB |
1170 | /** |
1171 | * Inline helper functions | |
1172 | */ | |
1173 | ||
1174 | static inline void vmw_surface_unreference(struct vmw_surface **srf) | |
1175 | { | |
1176 | struct vmw_surface *tmp_srf = *srf; | |
1177 | struct vmw_resource *res = &tmp_srf->res; | |
1178 | *srf = NULL; | |
1179 | ||
1180 | vmw_resource_unreference(&res); | |
1181 | } | |
1182 | ||
1183 | static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf) | |
1184 | { | |
1185 | (void) vmw_resource_reference(&srf->res); | |
1186 | return srf; | |
1187 | } | |
1188 | ||
1189 | static inline void vmw_dmabuf_unreference(struct vmw_dma_buffer **buf) | |
1190 | { | |
1191 | struct vmw_dma_buffer *tmp_buf = *buf; | |
bf6f0368 | 1192 | |
fb1d9738 | 1193 | *buf = NULL; |
bf6f0368 TH |
1194 | if (tmp_buf != NULL) { |
1195 | struct ttm_buffer_object *bo = &tmp_buf->base; | |
fb1d9738 | 1196 | |
bf6f0368 TH |
1197 | ttm_bo_unref(&bo); |
1198 | } | |
fb1d9738 JB |
1199 | } |
1200 | ||
1201 | static inline struct vmw_dma_buffer *vmw_dmabuf_reference(struct vmw_dma_buffer *buf) | |
1202 | { | |
1203 | if (ttm_bo_reference(&buf->base)) | |
1204 | return buf; | |
1205 | return NULL; | |
1206 | } | |
1207 | ||
ae2a1040 TH |
1208 | static inline struct ttm_mem_global *vmw_mem_glob(struct vmw_private *dev_priv) |
1209 | { | |
1210 | return (struct ttm_mem_global *) dev_priv->mem_global_ref.object; | |
1211 | } | |
153b3d5b TH |
1212 | |
1213 | static inline void vmw_fifo_resource_inc(struct vmw_private *dev_priv) | |
1214 | { | |
1215 | atomic_inc(&dev_priv->num_fifo_resources); | |
1216 | } | |
1217 | ||
1218 | static inline void vmw_fifo_resource_dec(struct vmw_private *dev_priv) | |
1219 | { | |
1220 | atomic_dec(&dev_priv->num_fifo_resources); | |
1221 | } | |
b76ff5ea TH |
1222 | |
1223 | /** | |
1224 | * vmw_mmio_read - Perform a MMIO read from volatile memory | |
1225 | * | |
1226 | * @addr: The address to read from | |
1227 | * | |
1228 | * This function is intended to be equivalent to ioread32() on | |
1229 | * memremap'd memory, but without byteswapping. | |
1230 | */ | |
1231 | static inline u32 vmw_mmio_read(u32 *addr) | |
1232 | { | |
1233 | return READ_ONCE(*addr); | |
1234 | } | |
1235 | ||
1236 | /** | |
1237 | * vmw_mmio_write - Perform a MMIO write to volatile memory | |
1238 | * | |
1239 | * @addr: The address to write to | |
1240 | * | |
1241 | * This function is intended to be equivalent to iowrite32 on | |
1242 | * memremap'd memory, but without byteswapping. | |
1243 | */ | |
1244 | static inline void vmw_mmio_write(u32 value, u32 *addr) | |
1245 | { | |
1246 | WRITE_ONCE(*addr, value); | |
1247 | } | |
f9217913 SY |
1248 | |
1249 | /** | |
1250 | * Add vmw_msg module function | |
1251 | */ | |
1252 | extern int vmw_host_log(const char *log); | |
1253 | ||
fb1d9738 | 1254 | #endif |