• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 OR MIT */
2 /**************************************************************************
3  *
4  * Copyright 2009-2022 VMware, Inc., Palo Alto, CA., USA
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 <linux/suspend.h>
32 #include <linux/sync_file.h>
33 #include <linux/hashtable.h>
34 
35 #include <drm/drm_auth.h>
36 #include <drm/drm_device.h>
37 #include <drm/drm_file.h>
38 #include <drm/drm_rect.h>
39 
40 #include <drm/ttm/ttm_bo_driver.h>
41 #include <drm/ttm/ttm_execbuf_util.h>
42 
43 #include "ttm_object.h"
44 
45 #include "vmwgfx_fence.h"
46 #include "vmwgfx_reg.h"
47 #include "vmwgfx_validation.h"
48 
49 /*
50  * FIXME: vmwgfx_drm.h needs to be last due to dependencies.
51  * uapi headers should not depend on header files outside uapi/.
52  */
53 #include <drm/vmwgfx_drm.h>
54 
55 
56 #define VMWGFX_DRIVER_NAME "vmwgfx"
57 #define VMWGFX_DRIVER_DATE "20211206"
58 #define VMWGFX_DRIVER_MAJOR 2
59 #define VMWGFX_DRIVER_MINOR 20
60 #define VMWGFX_DRIVER_PATCHLEVEL 0
61 #define VMWGFX_FIFO_STATIC_SIZE (1024*1024)
62 #define VMWGFX_MAX_DISPLAYS 16
63 #define VMWGFX_CMD_BOUNCE_INIT_SIZE 32768
64 
65 #define VMWGFX_PCI_ID_SVGA2              0x0405
66 #define VMWGFX_PCI_ID_SVGA3              0x0406
67 
68 /*
69  * This has to match get_count_order(SVGA_IRQFLAG_MAX)
70  */
71 #define VMWGFX_MAX_NUM_IRQS 6
72 
73 /*
74  * Perhaps we should have sysfs entries for these.
75  */
76 #define VMWGFX_NUM_GB_CONTEXT 256
77 #define VMWGFX_NUM_GB_SHADER 20000
78 #define VMWGFX_NUM_GB_SURFACE 32768
79 #define VMWGFX_NUM_GB_SCREEN_TARGET VMWGFX_MAX_DISPLAYS
80 #define VMWGFX_NUM_DXCONTEXT 256
81 #define VMWGFX_NUM_DXQUERY 512
82 #define VMWGFX_NUM_MOB (VMWGFX_NUM_GB_CONTEXT +\
83 			VMWGFX_NUM_GB_SHADER +\
84 			VMWGFX_NUM_GB_SURFACE +\
85 			VMWGFX_NUM_GB_SCREEN_TARGET)
86 
87 #define VMW_PL_GMR      (TTM_PL_PRIV + 0)
88 #define VMW_PL_MOB      (TTM_PL_PRIV + 1)
89 #define VMW_PL_SYSTEM   (TTM_PL_PRIV + 2)
90 
91 #define VMW_RES_CONTEXT ttm_driver_type0
92 #define VMW_RES_SURFACE ttm_driver_type1
93 #define VMW_RES_STREAM ttm_driver_type2
94 #define VMW_RES_FENCE ttm_driver_type3
95 #define VMW_RES_SHADER ttm_driver_type4
96 #define VMW_RES_HT_ORDER 12
97 
98 #define MKSSTAT_CAPACITY_LOG2 5U
99 #define MKSSTAT_CAPACITY (1U << MKSSTAT_CAPACITY_LOG2)
100 
101 struct vmw_fpriv {
102 	struct ttm_object_file *tfile;
103 	bool gb_aware; /* user-space is guest-backed aware */
104 };
105 
106 struct vmwgfx_hash_item {
107 	struct hlist_node head;
108 	unsigned long key;
109 };
110 
111 /**
112  * struct vmw_buffer_object - TTM buffer object with vmwgfx additions
113  * @base: The TTM buffer object
114  * @res_tree: RB tree of resources using this buffer object as a backing MOB
115  * @base_mapped_count: ttm BO mapping count; used by KMS atomic helpers.
116  * @cpu_writers: Number of synccpu write grabs. Protected by reservation when
117  * increased. May be decreased without reservation.
118  * @dx_query_ctx: DX context if this buffer object is used as a DX query MOB
119  * @map: Kmap object for semi-persistent mappings
120  * @res_prios: Eviction priority counts for attached resources
121  * @dirty: structure for user-space dirty-tracking
122  */
123 struct vmw_buffer_object {
124 	struct ttm_buffer_object base;
125 	struct rb_root res_tree;
126 	/* For KMS atomic helpers: ttm bo mapping count */
127 	atomic_t base_mapped_count;
128 
129 	atomic_t cpu_writers;
130 	/* Not ref-counted.  Protected by binding_mutex */
131 	struct vmw_resource *dx_query_ctx;
132 	/* Protected by reservation */
133 	struct ttm_bo_kmap_obj map;
134 	u32 res_prios[TTM_MAX_BO_PRIORITY];
135 	struct vmw_bo_dirty *dirty;
136 };
137 
138 /**
139  * struct vmw_validate_buffer - Carries validation info about buffers.
140  *
141  * @base: Validation info for TTM.
142  * @hash: Hash entry for quick lookup of the TTM buffer object.
143  *
144  * This structure contains also driver private validation info
145  * on top of the info needed by TTM.
146  */
147 struct vmw_validate_buffer {
148 	struct ttm_validate_buffer base;
149 	struct vmwgfx_hash_item hash;
150 	bool validate_as_mob;
151 };
152 
153 struct vmw_res_func;
154 
155 
156 /**
157  * struct vmw-resource - base class for hardware resources
158  *
159  * @kref: For refcounting.
160  * @dev_priv: Pointer to the device private for this resource. Immutable.
161  * @id: Device id. Protected by @dev_priv::resource_lock.
162  * @backup_size: Backup buffer size. Immutable.
163  * @res_dirty: Resource contains data not yet in the backup buffer. Protected
164  * by resource reserved.
165  * @backup_dirty: Backup buffer contains data not yet in the HW resource.
166  * Protected by resource reserved.
167  * @coherent: Emulate coherency by tracking vm accesses.
168  * @backup: The backup buffer if any. Protected by resource reserved.
169  * @backup_offset: Offset into the backup buffer if any. Protected by resource
170  * reserved. Note that only a few resource types can have a @backup_offset
171  * different from zero.
172  * @pin_count: The pin count for this resource. A pinned resource has a
173  * pin-count greater than zero. It is not on the resource LRU lists and its
174  * backup buffer is pinned. Hence it can't be evicted.
175  * @func: Method vtable for this resource. Immutable.
176  * @mob_node; Node for the MOB backup rbtree. Protected by @backup reserved.
177  * @lru_head: List head for the LRU list. Protected by @dev_priv::resource_lock.
178  * @binding_head: List head for the context binding list. Protected by
179  * the @dev_priv::binding_mutex
180  * @res_free: The resource destructor.
181  * @hw_destroy: Callback to destroy the resource on the device, as part of
182  * resource destruction.
183  */
184 struct vmw_resource_dirty;
185 struct vmw_resource {
186 	struct kref kref;
187 	struct vmw_private *dev_priv;
188 	int id;
189 	u32 used_prio;
190 	unsigned long backup_size;
191 	u32 res_dirty : 1;
192 	u32 backup_dirty : 1;
193 	u32 coherent : 1;
194 	struct vmw_buffer_object *backup;
195 	unsigned long backup_offset;
196 	unsigned long pin_count;
197 	const struct vmw_res_func *func;
198 	struct rb_node mob_node;
199 	struct list_head lru_head;
200 	struct list_head binding_head;
201 	struct vmw_resource_dirty *dirty;
202 	void (*res_free) (struct vmw_resource *res);
203 	void (*hw_destroy) (struct vmw_resource *res);
204 };
205 
206 
207 /*
208  * Resources that are managed using ioctls.
209  */
210 enum vmw_res_type {
211 	vmw_res_context,
212 	vmw_res_surface,
213 	vmw_res_stream,
214 	vmw_res_shader,
215 	vmw_res_dx_context,
216 	vmw_res_cotable,
217 	vmw_res_view,
218 	vmw_res_streamoutput,
219 	vmw_res_max
220 };
221 
222 /*
223  * Resources that are managed using command streams.
224  */
225 enum vmw_cmdbuf_res_type {
226 	vmw_cmdbuf_res_shader,
227 	vmw_cmdbuf_res_view,
228 	vmw_cmdbuf_res_streamoutput
229 };
230 
231 struct vmw_cmdbuf_res_manager;
232 
233 struct vmw_cursor_snooper {
234 	size_t age;
235 	uint32_t *image;
236 };
237 
238 struct vmw_framebuffer;
239 struct vmw_surface_offset;
240 
241 /**
242  * struct vmw_surface_metadata - Metadata describing a surface.
243  *
244  * @flags: Device flags.
245  * @format: Surface SVGA3D_x format.
246  * @mip_levels: Mip level for each face. For GB first index is used only.
247  * @multisample_count: Sample count.
248  * @multisample_pattern: Sample patterns.
249  * @quality_level: Quality level.
250  * @autogen_filter: Filter for automatically generated mipmaps.
251  * @array_size: Number of array elements for a 1D/2D texture. For cubemap
252                 texture number of faces * array_size. This should be 0 for pre
253 		SM4 device.
254  * @buffer_byte_stride: Buffer byte stride.
255  * @num_sizes: Size of @sizes. For GB surface this should always be 1.
256  * @base_size: Surface dimension.
257  * @sizes: Array representing mip sizes. Legacy only.
258  * @scanout: Whether this surface will be used for scanout.
259  *
260  * This tracks metadata for both legacy and guest backed surface.
261  */
262 struct vmw_surface_metadata {
263 	u64 flags;
264 	u32 format;
265 	u32 mip_levels[DRM_VMW_MAX_SURFACE_FACES];
266 	u32 multisample_count;
267 	u32 multisample_pattern;
268 	u32 quality_level;
269 	u32 autogen_filter;
270 	u32 array_size;
271 	u32 num_sizes;
272 	u32 buffer_byte_stride;
273 	struct drm_vmw_size base_size;
274 	struct drm_vmw_size *sizes;
275 	bool scanout;
276 };
277 
278 /**
279  * struct vmw_surface: Resource structure for a surface.
280  *
281  * @res: The base resource for this surface.
282  * @metadata: Metadata for this surface resource.
283  * @snooper: Cursor data. Legacy surface only.
284  * @offsets: Legacy surface only.
285  * @view_list: List of views bound to this surface.
286  */
287 struct vmw_surface {
288 	struct vmw_resource res;
289 	struct vmw_surface_metadata metadata;
290 	struct vmw_cursor_snooper snooper;
291 	struct vmw_surface_offset *offsets;
292 	struct list_head view_list;
293 };
294 
295 struct vmw_fifo_state {
296 	unsigned long reserved_size;
297 	u32 *dynamic_buffer;
298 	u32 *static_buffer;
299 	unsigned long static_buffer_size;
300 	bool using_bounce_buffer;
301 	uint32_t capabilities;
302 	struct mutex fifo_mutex;
303 	struct rw_semaphore rwsem;
304 };
305 
306 /**
307  * struct vmw_res_cache_entry - resource information cache entry
308  * @handle: User-space handle of a resource.
309  * @res: Non-ref-counted pointer to the resource.
310  * @valid_handle: Whether the @handle member is valid.
311  * @valid: Whether the entry is valid, which also implies that the execbuf
312  * code holds a reference to the resource, and it's placed on the
313  * validation list.
314  *
315  * Used to avoid frequent repeated user-space handle lookups of the
316  * same resource.
317  */
318 struct vmw_res_cache_entry {
319 	uint32_t handle;
320 	struct vmw_resource *res;
321 	void *private;
322 	unsigned short valid_handle;
323 	unsigned short valid;
324 };
325 
326 /**
327  * enum vmw_dma_map_mode - indicate how to perform TTM page dma mappings.
328  */
329 enum vmw_dma_map_mode {
330 	vmw_dma_alloc_coherent, /* Use TTM coherent pages */
331 	vmw_dma_map_populate,   /* Unmap from DMA just after unpopulate */
332 	vmw_dma_map_bind,       /* Unmap from DMA just before unbind */
333 	vmw_dma_map_max
334 };
335 
336 /**
337  * struct vmw_sg_table - Scatter/gather table for binding, with additional
338  * device-specific information.
339  *
340  * @sgt: Pointer to a struct sg_table with binding information
341  * @num_regions: Number of regions with device-address contiguous pages
342  */
343 struct vmw_sg_table {
344 	enum vmw_dma_map_mode mode;
345 	struct page **pages;
346 	const dma_addr_t *addrs;
347 	struct sg_table *sgt;
348 	unsigned long num_pages;
349 };
350 
351 /**
352  * struct vmw_piter - Page iterator that iterates over a list of pages
353  * and DMA addresses that could be either a scatter-gather list or
354  * arrays
355  *
356  * @pages: Array of page pointers to the pages.
357  * @addrs: DMA addresses to the pages if coherent pages are used.
358  * @iter: Scatter-gather page iterator. Current position in SG list.
359  * @i: Current position in arrays.
360  * @num_pages: Number of pages total.
361  * @next: Function to advance the iterator. Returns false if past the list
362  * of pages, true otherwise.
363  * @dma_address: Function to return the DMA address of the current page.
364  */
365 struct vmw_piter {
366 	struct page **pages;
367 	const dma_addr_t *addrs;
368 	struct sg_dma_page_iter iter;
369 	unsigned long i;
370 	unsigned long num_pages;
371 	bool (*next)(struct vmw_piter *);
372 	dma_addr_t (*dma_address)(struct vmw_piter *);
373 };
374 
375 
376 struct vmw_ttm_tt {
377 	struct ttm_tt dma_ttm;
378 	struct vmw_private *dev_priv;
379 	int gmr_id;
380 	struct vmw_mob *mob;
381 	int mem_type;
382 	struct sg_table sgt;
383 	struct vmw_sg_table vsgt;
384 	bool mapped;
385 	bool bound;
386 };
387 
388 /*
389  * enum vmw_display_unit_type - Describes the display unit
390  */
391 enum vmw_display_unit_type {
392 	vmw_du_invalid = 0,
393 	vmw_du_legacy,
394 	vmw_du_screen_object,
395 	vmw_du_screen_target,
396 	vmw_du_max
397 };
398 
399 struct vmw_validation_context;
400 struct vmw_ctx_validation_info;
401 
402 /**
403  * struct vmw_sw_context - Command submission context
404  * @res_ht: Pointer hash table used to find validation duplicates
405  * @kernel: Whether the command buffer originates from kernel code rather
406  * than from user-space
407  * @fp: If @kernel is false, points to the file of the client. Otherwise
408  * NULL
409  * @cmd_bounce: Command bounce buffer used for command validation before
410  * copying to fifo space
411  * @cmd_bounce_size: Current command bounce buffer size
412  * @cur_query_bo: Current buffer object used as query result buffer
413  * @bo_relocations: List of buffer object relocations
414  * @res_relocations: List of resource relocations
415  * @buf_start: Pointer to start of memory where command validation takes
416  * place
417  * @res_cache: Cache of recently looked up resources
418  * @last_query_ctx: Last context that submitted a query
419  * @needs_post_query_barrier: Whether a query barrier is needed after
420  * command submission
421  * @staged_bindings: Cached per-context binding tracker
422  * @staged_bindings_inuse: Whether the cached per-context binding tracker
423  * is in use
424  * @staged_cmd_res: List of staged command buffer managed resources in this
425  * command buffer
426  * @ctx_list: List of context resources referenced in this command buffer
427  * @dx_ctx_node: Validation metadata of the current DX context
428  * @dx_query_mob: The MOB used for DX queries
429  * @dx_query_ctx: The DX context used for the last DX query
430  * @man: Pointer to the command buffer managed resource manager
431  * @ctx: The validation context
432  */
433 struct vmw_sw_context{
434 	DECLARE_HASHTABLE(res_ht, VMW_RES_HT_ORDER);
435 	bool kernel;
436 	struct vmw_fpriv *fp;
437 	struct drm_file *filp;
438 	uint32_t *cmd_bounce;
439 	uint32_t cmd_bounce_size;
440 	struct vmw_buffer_object *cur_query_bo;
441 	struct list_head bo_relocations;
442 	struct list_head res_relocations;
443 	uint32_t *buf_start;
444 	struct vmw_res_cache_entry res_cache[vmw_res_max];
445 	struct vmw_resource *last_query_ctx;
446 	bool needs_post_query_barrier;
447 	struct vmw_ctx_binding_state *staged_bindings;
448 	bool staged_bindings_inuse;
449 	struct list_head staged_cmd_res;
450 	struct list_head ctx_list;
451 	struct vmw_ctx_validation_info *dx_ctx_node;
452 	struct vmw_buffer_object *dx_query_mob;
453 	struct vmw_resource *dx_query_ctx;
454 	struct vmw_cmdbuf_res_manager *man;
455 	struct vmw_validation_context *ctx;
456 };
457 
458 struct vmw_legacy_display;
459 struct vmw_overlay;
460 
461 struct vmw_vga_topology_state {
462 	uint32_t width;
463 	uint32_t height;
464 	uint32_t primary;
465 	uint32_t pos_x;
466 	uint32_t pos_y;
467 };
468 
469 
470 /*
471  * struct vmw_otable - Guest Memory OBject table metadata
472  *
473  * @size:           Size of the table (page-aligned).
474  * @page_table:     Pointer to a struct vmw_mob holding the page table.
475  */
476 struct vmw_otable {
477 	unsigned long size;
478 	struct vmw_mob *page_table;
479 	bool enabled;
480 };
481 
482 struct vmw_otable_batch {
483 	unsigned num_otables;
484 	struct vmw_otable *otables;
485 	struct vmw_resource *context;
486 	struct ttm_buffer_object *otable_bo;
487 };
488 
489 enum {
490 	VMW_IRQTHREAD_FENCE,
491 	VMW_IRQTHREAD_CMDBUF,
492 	VMW_IRQTHREAD_MAX
493 };
494 
495 /**
496  * enum vmw_sm_type - Graphics context capability supported by device.
497  * @VMW_SM_LEGACY: Pre DX context.
498  * @VMW_SM_4: Context support upto SM4.
499  * @VMW_SM_4_1: Context support upto SM4_1.
500  * @VMW_SM_5: Context support up to SM5.
501  * @VMW_SM_5_1X: Adds support for sm5_1 and gl43 extensions.
502  * @VMW_SM_MAX: Should be the last.
503  */
504 enum vmw_sm_type {
505 	VMW_SM_LEGACY = 0,
506 	VMW_SM_4,
507 	VMW_SM_4_1,
508 	VMW_SM_5,
509 	VMW_SM_5_1X,
510 	VMW_SM_MAX
511 };
512 
513 struct vmw_private {
514 	struct drm_device drm;
515 	struct ttm_device bdev;
516 
517 	struct drm_vma_offset_manager vma_manager;
518 	u32 pci_id;
519 	resource_size_t io_start;
520 	resource_size_t vram_start;
521 	resource_size_t vram_size;
522 	resource_size_t max_primary_mem;
523 	u32 __iomem *rmmio;
524 	u32 *fifo_mem;
525 	resource_size_t fifo_mem_size;
526 	uint32_t fb_max_width;
527 	uint32_t fb_max_height;
528 	uint32_t texture_max_width;
529 	uint32_t texture_max_height;
530 	uint32_t stdu_max_width;
531 	uint32_t stdu_max_height;
532 	uint32_t initial_width;
533 	uint32_t initial_height;
534 	uint32_t capabilities;
535 	uint32_t capabilities2;
536 	uint32_t max_gmr_ids;
537 	uint32_t max_gmr_pages;
538 	uint32_t max_mob_pages;
539 	uint32_t max_mob_size;
540 	uint32_t memory_size;
541 	bool has_gmr;
542 	bool has_mob;
543 	spinlock_t hw_lock;
544 	bool assume_16bpp;
545 	u32 irqs[VMWGFX_MAX_NUM_IRQS];
546 	u32 num_irq_vectors;
547 
548 	enum vmw_sm_type sm_type;
549 
550 	/*
551 	 * Framebuffer info.
552 	 */
553 
554 	void *fb_info;
555 	enum vmw_display_unit_type active_display_unit;
556 	struct vmw_legacy_display *ldu_priv;
557 	struct vmw_overlay *overlay_priv;
558 	struct drm_property *hotplug_mode_update_property;
559 	struct drm_property *implicit_placement_property;
560 	spinlock_t cursor_lock;
561 	struct drm_atomic_state *suspend_state;
562 
563 	/*
564 	 * Context and surface management.
565 	 */
566 
567 	spinlock_t resource_lock;
568 	struct idr res_idr[vmw_res_max];
569 
570 	/*
571 	 * A resource manager for kernel-only surfaces and
572 	 * contexts.
573 	 */
574 
575 	struct ttm_object_device *tdev;
576 
577 	/*
578 	 * Fencing and IRQs.
579 	 */
580 
581 	atomic_t marker_seq;
582 	wait_queue_head_t fence_queue;
583 	wait_queue_head_t fifo_queue;
584 	spinlock_t waiter_lock;
585 	int fence_queue_waiters; /* Protected by waiter_lock */
586 	int goal_queue_waiters; /* Protected by waiter_lock */
587 	int cmdbuf_waiters; /* Protected by waiter_lock */
588 	int error_waiters; /* Protected by waiter_lock */
589 	int fifo_queue_waiters; /* Protected by waiter_lock */
590 	uint32_t last_read_seqno;
591 	struct vmw_fence_manager *fman;
592 	uint32_t irq_mask; /* Updates protected by waiter_lock */
593 
594 	/*
595 	 * Device state
596 	 */
597 
598 	uint32_t traces_state;
599 	uint32_t enable_state;
600 	uint32_t config_done_state;
601 
602 	/**
603 	 * Execbuf
604 	 */
605 	/**
606 	 * Protected by the cmdbuf mutex.
607 	 */
608 
609 	struct vmw_sw_context ctx;
610 	struct mutex cmdbuf_mutex;
611 	struct mutex binding_mutex;
612 
613 	bool enable_fb;
614 
615 	/**
616 	 * PM management.
617 	 */
618 	struct notifier_block pm_nb;
619 	bool refuse_hibernation;
620 	bool suspend_locked;
621 
622 	atomic_t num_fifo_resources;
623 
624 	/*
625 	 * Query processing. These members
626 	 * are protected by the cmdbuf mutex.
627 	 */
628 
629 	struct vmw_buffer_object *dummy_query_bo;
630 	struct vmw_buffer_object *pinned_bo;
631 	uint32_t query_cid;
632 	uint32_t query_cid_valid;
633 	bool dummy_query_bo_pinned;
634 
635 	/*
636 	 * Surface swapping. The "surface_lru" list is protected by the
637 	 * resource lock in order to be able to destroy a surface and take
638 	 * it off the lru atomically. "used_memory_size" is currently
639 	 * protected by the cmdbuf mutex for simplicity.
640 	 */
641 
642 	struct list_head res_lru[vmw_res_max];
643 	uint32_t used_memory_size;
644 
645 	/*
646 	 * DMA mapping stuff.
647 	 */
648 	enum vmw_dma_map_mode map_mode;
649 
650 	/*
651 	 * Guest Backed stuff
652 	 */
653 	struct vmw_otable_batch otable_batch;
654 
655 	struct vmw_fifo_state *fifo;
656 	struct vmw_cmdbuf_man *cman;
657 	DECLARE_BITMAP(irqthread_pending, VMW_IRQTHREAD_MAX);
658 
659 	uint32 *devcaps;
660 
661 	/*
662 	 * mksGuestStat instance-descriptor and pid arrays
663 	 */
664 	struct page *mksstat_user_pages[MKSSTAT_CAPACITY];
665 	atomic_t mksstat_user_pids[MKSSTAT_CAPACITY];
666 
667 #if IS_ENABLED(CONFIG_DRM_VMWGFX_MKSSTATS)
668 	struct page *mksstat_kern_pages[MKSSTAT_CAPACITY];
669 	u8 mksstat_kern_top_timer[MKSSTAT_CAPACITY];
670 	atomic_t mksstat_kern_pids[MKSSTAT_CAPACITY];
671 #endif
672 };
673 
gem_to_vmw_bo(struct drm_gem_object * gobj)674 static inline struct vmw_buffer_object *gem_to_vmw_bo(struct drm_gem_object *gobj)
675 {
676 	return container_of((gobj), struct vmw_buffer_object, base.base);
677 }
678 
vmw_res_to_srf(struct vmw_resource * res)679 static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res)
680 {
681 	return container_of(res, struct vmw_surface, res);
682 }
683 
vmw_priv(struct drm_device * dev)684 static inline struct vmw_private *vmw_priv(struct drm_device *dev)
685 {
686 	return (struct vmw_private *)dev->dev_private;
687 }
688 
vmw_fpriv(struct drm_file * file_priv)689 static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
690 {
691 	return (struct vmw_fpriv *)file_priv->driver_priv;
692 }
693 
694 /*
695  * SVGA v3 has mmio register access and lacks fifo cmds
696  */
vmw_is_svga_v3(const struct vmw_private * dev)697 static inline bool vmw_is_svga_v3(const struct vmw_private *dev)
698 {
699 	return dev->pci_id == VMWGFX_PCI_ID_SVGA3;
700 }
701 
702 /*
703  * The locking here is fine-grained, so that it is performed once
704  * for every read- and write operation. This is of course costly, but we
705  * don't perform much register access in the timing critical paths anyway.
706  * Instead we have the extra benefit of being sure that we don't forget
707  * the hw lock around register accesses.
708  */
vmw_write(struct vmw_private * dev_priv,unsigned int offset,uint32_t value)709 static inline void vmw_write(struct vmw_private *dev_priv,
710 			     unsigned int offset, uint32_t value)
711 {
712 	if (vmw_is_svga_v3(dev_priv)) {
713 		iowrite32(value, dev_priv->rmmio + offset);
714 	} else {
715 		spin_lock(&dev_priv->hw_lock);
716 		outl(offset, dev_priv->io_start + SVGA_INDEX_PORT);
717 		outl(value, dev_priv->io_start + SVGA_VALUE_PORT);
718 		spin_unlock(&dev_priv->hw_lock);
719 	}
720 }
721 
vmw_read(struct vmw_private * dev_priv,unsigned int offset)722 static inline uint32_t vmw_read(struct vmw_private *dev_priv,
723 				unsigned int offset)
724 {
725 	u32 val;
726 
727 	if (vmw_is_svga_v3(dev_priv)) {
728 		val = ioread32(dev_priv->rmmio + offset);
729 	} else {
730 		spin_lock(&dev_priv->hw_lock);
731 		outl(offset, dev_priv->io_start + SVGA_INDEX_PORT);
732 		val = inl(dev_priv->io_start + SVGA_VALUE_PORT);
733 		spin_unlock(&dev_priv->hw_lock);
734 	}
735 
736 	return val;
737 }
738 
739 /**
740  * has_sm4_context - Does the device support SM4 context.
741  * @dev_priv: Device private.
742  *
743  * Return: Bool value if device support SM4 context or not.
744  */
has_sm4_context(const struct vmw_private * dev_priv)745 static inline bool has_sm4_context(const struct vmw_private *dev_priv)
746 {
747 	return (dev_priv->sm_type >= VMW_SM_4);
748 }
749 
750 /**
751  * has_sm4_1_context - Does the device support SM4_1 context.
752  * @dev_priv: Device private.
753  *
754  * Return: Bool value if device support SM4_1 context or not.
755  */
has_sm4_1_context(const struct vmw_private * dev_priv)756 static inline bool has_sm4_1_context(const struct vmw_private *dev_priv)
757 {
758 	return (dev_priv->sm_type >= VMW_SM_4_1);
759 }
760 
761 /**
762  * has_sm5_context - Does the device support SM5 context.
763  * @dev_priv: Device private.
764  *
765  * Return: Bool value if device support SM5 context or not.
766  */
has_sm5_context(const struct vmw_private * dev_priv)767 static inline bool has_sm5_context(const struct vmw_private *dev_priv)
768 {
769 	return (dev_priv->sm_type >= VMW_SM_5);
770 }
771 
772 /**
773  * has_gl43_context - Does the device support GL43 context.
774  * @dev_priv: Device private.
775  *
776  * Return: Bool value if device support SM5 context or not.
777  */
has_gl43_context(const struct vmw_private * dev_priv)778 static inline bool has_gl43_context(const struct vmw_private *dev_priv)
779 {
780 	return (dev_priv->sm_type >= VMW_SM_5_1X);
781 }
782 
783 
vmw_max_num_uavs(struct vmw_private * dev_priv)784 static inline u32 vmw_max_num_uavs(struct vmw_private *dev_priv)
785 {
786 	return (has_gl43_context(dev_priv) ?
787 			SVGA3D_DX11_1_MAX_UAVIEWS : SVGA3D_MAX_UAVIEWS);
788 }
789 
790 extern void vmw_svga_enable(struct vmw_private *dev_priv);
791 extern void vmw_svga_disable(struct vmw_private *dev_priv);
792 
793 
794 /**
795  * GMR utilities - vmwgfx_gmr.c
796  */
797 
798 extern int vmw_gmr_bind(struct vmw_private *dev_priv,
799 			const struct vmw_sg_table *vsgt,
800 			unsigned long num_pages,
801 			int gmr_id);
802 extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
803 
804 /**
805  * Resource utilities - vmwgfx_resource.c
806  */
807 struct vmw_user_resource_conv;
808 
809 extern void vmw_resource_unreference(struct vmw_resource **p_res);
810 extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
811 extern struct vmw_resource *
812 vmw_resource_reference_unless_doomed(struct vmw_resource *res);
813 extern int vmw_resource_validate(struct vmw_resource *res, bool intr,
814 				 bool dirtying);
815 extern int vmw_resource_reserve(struct vmw_resource *res, bool interruptible,
816 				bool no_backup);
817 extern bool vmw_resource_needs_backup(const struct vmw_resource *res);
818 extern int vmw_user_lookup_handle(struct vmw_private *dev_priv,
819 				  struct drm_file *filp,
820 				  uint32_t handle,
821 				  struct vmw_surface **out_surf,
822 				  struct vmw_buffer_object **out_buf);
823 extern int vmw_user_resource_lookup_handle(
824 	struct vmw_private *dev_priv,
825 	struct ttm_object_file *tfile,
826 	uint32_t handle,
827 	const struct vmw_user_resource_conv *converter,
828 	struct vmw_resource **p_res);
829 
830 extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
831 				  struct drm_file *file_priv);
832 extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
833 				  struct drm_file *file_priv);
834 extern int vmw_user_stream_lookup(struct vmw_private *dev_priv,
835 				  struct ttm_object_file *tfile,
836 				  uint32_t *inout_id,
837 				  struct vmw_resource **out);
838 extern void vmw_resource_unreserve(struct vmw_resource *res,
839 				   bool dirty_set,
840 				   bool dirty,
841 				   bool switch_backup,
842 				   struct vmw_buffer_object *new_backup,
843 				   unsigned long new_backup_offset);
844 extern void vmw_query_move_notify(struct ttm_buffer_object *bo,
845 				  struct ttm_resource *old_mem,
846 				  struct ttm_resource *new_mem);
847 extern int vmw_query_readback_all(struct vmw_buffer_object *dx_query_mob);
848 extern void vmw_resource_evict_all(struct vmw_private *dev_priv);
849 extern void vmw_resource_unbind_list(struct vmw_buffer_object *vbo);
850 void vmw_resource_mob_attach(struct vmw_resource *res);
851 void vmw_resource_mob_detach(struct vmw_resource *res);
852 void vmw_resource_dirty_update(struct vmw_resource *res, pgoff_t start,
853 			       pgoff_t end);
854 int vmw_resources_clean(struct vmw_buffer_object *vbo, pgoff_t start,
855 			pgoff_t end, pgoff_t *num_prefault);
856 
857 /**
858  * vmw_resource_mob_attached - Whether a resource currently has a mob attached
859  * @res: The resource
860  *
861  * Return: true if the resource has a mob attached, false otherwise.
862  */
vmw_resource_mob_attached(const struct vmw_resource * res)863 static inline bool vmw_resource_mob_attached(const struct vmw_resource *res)
864 {
865 	return !RB_EMPTY_NODE(&res->mob_node);
866 }
867 
868 /**
869  * Buffer object helper functions - vmwgfx_bo.c
870  */
871 extern int vmw_bo_pin_in_placement(struct vmw_private *vmw_priv,
872 				   struct vmw_buffer_object *bo,
873 				   struct ttm_placement *placement,
874 				   bool interruptible);
875 extern int vmw_bo_pin_in_vram(struct vmw_private *dev_priv,
876 			      struct vmw_buffer_object *buf,
877 			      bool interruptible);
878 extern int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
879 				     struct vmw_buffer_object *buf,
880 				     bool interruptible);
881 extern int vmw_bo_pin_in_start_of_vram(struct vmw_private *vmw_priv,
882 				       struct vmw_buffer_object *bo,
883 				       bool interruptible);
884 extern int vmw_bo_unpin(struct vmw_private *vmw_priv,
885 			struct vmw_buffer_object *bo,
886 			bool interruptible);
887 extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf,
888 				 SVGAGuestPtr *ptr);
889 extern void vmw_bo_pin_reserved(struct vmw_buffer_object *bo, bool pin);
890 extern void vmw_bo_bo_free(struct ttm_buffer_object *bo);
891 extern int vmw_bo_create_kernel(struct vmw_private *dev_priv,
892 				unsigned long size,
893 				struct ttm_placement *placement,
894 				struct ttm_buffer_object **p_bo);
895 extern int vmw_bo_create(struct vmw_private *dev_priv,
896 			 size_t size, struct ttm_placement *placement,
897 			 bool interruptible, bool pin,
898 			 void (*bo_free)(struct ttm_buffer_object *bo),
899 			 struct vmw_buffer_object **p_bo);
900 extern int vmw_bo_init(struct vmw_private *dev_priv,
901 		       struct vmw_buffer_object *vmw_bo,
902 		       size_t size, struct ttm_placement *placement,
903 		       bool interruptible, bool pin,
904 		       void (*bo_free)(struct ttm_buffer_object *bo));
905 extern int vmw_bo_unref_ioctl(struct drm_device *dev, void *data,
906 			      struct drm_file *file_priv);
907 extern int vmw_user_bo_synccpu_ioctl(struct drm_device *dev, void *data,
908 				     struct drm_file *file_priv);
909 extern int vmw_user_bo_lookup(struct drm_file *filp,
910 			      uint32_t handle,
911 			      struct vmw_buffer_object **out);
912 extern void vmw_bo_fence_single(struct ttm_buffer_object *bo,
913 				struct vmw_fence_obj *fence);
914 extern void *vmw_bo_map_and_cache(struct vmw_buffer_object *vbo);
915 extern void vmw_bo_unmap(struct vmw_buffer_object *vbo);
916 extern void vmw_bo_move_notify(struct ttm_buffer_object *bo,
917 			       struct ttm_resource *mem);
918 extern void vmw_bo_swap_notify(struct ttm_buffer_object *bo);
919 
920 /**
921  * vmw_bo_adjust_prio - Adjust the buffer object eviction priority
922  * according to attached resources
923  * @vbo: The struct vmw_buffer_object
924  */
vmw_bo_prio_adjust(struct vmw_buffer_object * vbo)925 static inline void vmw_bo_prio_adjust(struct vmw_buffer_object *vbo)
926 {
927 	int i = ARRAY_SIZE(vbo->res_prios);
928 
929 	while (i--) {
930 		if (vbo->res_prios[i]) {
931 			vbo->base.priority = i;
932 			return;
933 		}
934 	}
935 
936 	vbo->base.priority = 3;
937 }
938 
939 /**
940  * vmw_bo_prio_add - Notify a buffer object of a newly attached resource
941  * eviction priority
942  * @vbo: The struct vmw_buffer_object
943  * @prio: The resource priority
944  *
945  * After being notified, the code assigns the highest resource eviction priority
946  * to the backing buffer object (mob).
947  */
vmw_bo_prio_add(struct vmw_buffer_object * vbo,int prio)948 static inline void vmw_bo_prio_add(struct vmw_buffer_object *vbo, int prio)
949 {
950 	if (vbo->res_prios[prio]++ == 0)
951 		vmw_bo_prio_adjust(vbo);
952 }
953 
954 /**
955  * vmw_bo_prio_del - Notify a buffer object of a resource with a certain
956  * priority being removed
957  * @vbo: The struct vmw_buffer_object
958  * @prio: The resource priority
959  *
960  * After being notified, the code assigns the highest resource eviction priority
961  * to the backing buffer object (mob).
962  */
vmw_bo_prio_del(struct vmw_buffer_object * vbo,int prio)963 static inline void vmw_bo_prio_del(struct vmw_buffer_object *vbo, int prio)
964 {
965 	if (--vbo->res_prios[prio] == 0)
966 		vmw_bo_prio_adjust(vbo);
967 }
968 
969 /**
970  * GEM related functionality - vmwgfx_gem.c
971  */
972 extern int vmw_gem_object_create(struct vmw_private *dev_priv,
973 				  size_t size, struct ttm_placement *placement,
974 				  bool interruptible, bool pin,
975 				  void (*bo_free)(struct ttm_buffer_object *bo),
976 				  struct vmw_buffer_object **p_bo);
977 extern int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv,
978 					     struct drm_file *filp,
979 					     uint32_t size,
980 					     uint32_t *handle,
981 					     struct vmw_buffer_object **p_vbo);
982 extern int vmw_gem_object_create_ioctl(struct drm_device *dev, void *data,
983 				       struct drm_file *filp);
984 extern void vmw_gem_destroy(struct ttm_buffer_object *bo);
985 extern void vmw_debugfs_gem_init(struct vmw_private *vdev);
986 
987 /**
988  * Misc Ioctl functionality - vmwgfx_ioctl.c
989  */
990 
991 extern int vmw_getparam_ioctl(struct drm_device *dev, void *data,
992 			      struct drm_file *file_priv);
993 extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
994 				struct drm_file *file_priv);
995 extern int vmw_present_ioctl(struct drm_device *dev, void *data,
996 			     struct drm_file *file_priv);
997 extern int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
998 				      struct drm_file *file_priv);
999 
1000 /**
1001  * Fifo utilities - vmwgfx_fifo.c
1002  */
1003 
1004 extern struct vmw_fifo_state *vmw_fifo_create(struct vmw_private *dev_priv);
1005 extern void vmw_fifo_destroy(struct vmw_private *dev_priv);
1006 extern bool vmw_cmd_supported(struct vmw_private *vmw);
1007 extern void *
1008 vmw_cmd_ctx_reserve(struct vmw_private *dev_priv, uint32_t bytes, int ctx_id);
1009 extern void vmw_cmd_commit(struct vmw_private *dev_priv, uint32_t bytes);
1010 extern void vmw_cmd_commit_flush(struct vmw_private *dev_priv, uint32_t bytes);
1011 extern int vmw_cmd_send_fence(struct vmw_private *dev_priv, uint32_t *seqno);
1012 extern bool vmw_supports_3d(struct vmw_private *dev_priv);
1013 extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
1014 extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv);
1015 extern int vmw_cmd_emit_dummy_query(struct vmw_private *dev_priv,
1016 				    uint32_t cid);
1017 extern int vmw_cmd_flush(struct vmw_private *dev_priv,
1018 			 bool interruptible);
1019 
1020 #define VMW_CMD_CTX_RESERVE(__priv, __bytes, __ctx_id)                        \
1021 ({                                                                            \
1022 	vmw_cmd_ctx_reserve(__priv, __bytes, __ctx_id) ? : ({                 \
1023 		DRM_ERROR("FIFO reserve failed at %s for %u bytes\n",         \
1024 			  __func__, (unsigned int) __bytes);                  \
1025 		NULL;                                                         \
1026 	});                                                                   \
1027 })
1028 
1029 #define VMW_CMD_RESERVE(__priv, __bytes)                                     \
1030 	VMW_CMD_CTX_RESERVE(__priv, __bytes, SVGA3D_INVALID_ID)
1031 
1032 
1033 /**
1034  * vmw_fifo_caps - Returns the capabilities of the FIFO command
1035  * queue or 0 if fifo memory isn't present.
1036  * @dev_priv: The device private context
1037  */
vmw_fifo_caps(const struct vmw_private * dev_priv)1038 static inline uint32_t vmw_fifo_caps(const struct vmw_private *dev_priv)
1039 {
1040 	if (!dev_priv->fifo_mem || !dev_priv->fifo)
1041 		return 0;
1042 	return dev_priv->fifo->capabilities;
1043 }
1044 
1045 
1046 /**
1047  * vmw_is_cursor_bypass3_enabled - Returns TRUE iff Cursor Bypass 3
1048  * is enabled in the FIFO.
1049  * @dev_priv: The device private context
1050  */
1051 static inline bool
vmw_is_cursor_bypass3_enabled(const struct vmw_private * dev_priv)1052 vmw_is_cursor_bypass3_enabled(const struct vmw_private *dev_priv)
1053 {
1054 	return (vmw_fifo_caps(dev_priv) & SVGA_FIFO_CAP_CURSOR_BYPASS_3) != 0;
1055 }
1056 
1057 /**
1058  * TTM glue - vmwgfx_ttm_glue.c
1059  */
1060 
1061 extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma);
1062 
1063 /**
1064  * TTM buffer object driver - vmwgfx_ttm_buffer.c
1065  */
1066 
1067 extern const size_t vmw_tt_size;
1068 extern struct ttm_placement vmw_vram_placement;
1069 extern struct ttm_placement vmw_vram_sys_placement;
1070 extern struct ttm_placement vmw_vram_gmr_placement;
1071 extern struct ttm_placement vmw_sys_placement;
1072 extern struct ttm_placement vmw_srf_placement;
1073 extern struct ttm_placement vmw_mob_placement;
1074 extern struct ttm_placement vmw_nonfixed_placement;
1075 extern struct ttm_device_funcs vmw_bo_driver;
1076 extern const struct vmw_sg_table *
1077 vmw_bo_sg_table(struct ttm_buffer_object *bo);
1078 extern int vmw_bo_create_and_populate(struct vmw_private *dev_priv,
1079 				      unsigned long bo_size,
1080 				      struct ttm_buffer_object **bo_p);
1081 
1082 extern void vmw_piter_start(struct vmw_piter *viter,
1083 			    const struct vmw_sg_table *vsgt,
1084 			    unsigned long p_offs);
1085 
1086 /**
1087  * vmw_piter_next - Advance the iterator one page.
1088  *
1089  * @viter: Pointer to the iterator to advance.
1090  *
1091  * Returns false if past the list of pages, true otherwise.
1092  */
vmw_piter_next(struct vmw_piter * viter)1093 static inline bool vmw_piter_next(struct vmw_piter *viter)
1094 {
1095 	return viter->next(viter);
1096 }
1097 
1098 /**
1099  * vmw_piter_dma_addr - Return the DMA address of the current page.
1100  *
1101  * @viter: Pointer to the iterator
1102  *
1103  * Returns the DMA address of the page pointed to by @viter.
1104  */
vmw_piter_dma_addr(struct vmw_piter * viter)1105 static inline dma_addr_t vmw_piter_dma_addr(struct vmw_piter *viter)
1106 {
1107 	return viter->dma_address(viter);
1108 }
1109 
1110 /**
1111  * vmw_piter_page - Return a pointer to the current page.
1112  *
1113  * @viter: Pointer to the iterator
1114  *
1115  * Returns the DMA address of the page pointed to by @viter.
1116  */
vmw_piter_page(struct vmw_piter * viter)1117 static inline struct page *vmw_piter_page(struct vmw_piter *viter)
1118 {
1119 	return viter->pages[viter->i];
1120 }
1121 
1122 /**
1123  * Command submission - vmwgfx_execbuf.c
1124  */
1125 
1126 extern int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
1127 			     struct drm_file *file_priv);
1128 extern int vmw_execbuf_process(struct drm_file *file_priv,
1129 			       struct vmw_private *dev_priv,
1130 			       void __user *user_commands,
1131 			       void *kernel_commands,
1132 			       uint32_t command_size,
1133 			       uint64_t throttle_us,
1134 			       uint32_t dx_context_handle,
1135 			       struct drm_vmw_fence_rep __user
1136 			       *user_fence_rep,
1137 			       struct vmw_fence_obj **out_fence,
1138 			       uint32_t flags);
1139 extern void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv,
1140 					    struct vmw_fence_obj *fence);
1141 extern void vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv);
1142 
1143 extern int vmw_execbuf_fence_commands(struct drm_file *file_priv,
1144 				      struct vmw_private *dev_priv,
1145 				      struct vmw_fence_obj **p_fence,
1146 				      uint32_t *p_handle);
1147 extern int vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
1148 					struct vmw_fpriv *vmw_fp,
1149 					int ret,
1150 					struct drm_vmw_fence_rep __user
1151 					*user_fence_rep,
1152 					struct vmw_fence_obj *fence,
1153 					uint32_t fence_handle,
1154 					int32_t out_fence_fd);
1155 bool vmw_cmd_describe(const void *buf, u32 *size, char const **cmd);
1156 
1157 /**
1158  * IRQs and wating - vmwgfx_irq.c
1159  */
1160 
1161 extern int vmw_irq_install(struct vmw_private *dev_priv);
1162 extern void vmw_irq_uninstall(struct drm_device *dev);
1163 extern bool vmw_seqno_passed(struct vmw_private *dev_priv,
1164 				uint32_t seqno);
1165 extern int vmw_fallback_wait(struct vmw_private *dev_priv,
1166 			     bool lazy,
1167 			     bool fifo_idle,
1168 			     uint32_t seqno,
1169 			     bool interruptible,
1170 			     unsigned long timeout);
1171 extern void vmw_update_seqno(struct vmw_private *dev_priv);
1172 extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
1173 extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
1174 extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
1175 extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv);
1176 extern void vmw_generic_waiter_add(struct vmw_private *dev_priv, u32 flag,
1177 				   int *waiter_count);
1178 extern void vmw_generic_waiter_remove(struct vmw_private *dev_priv,
1179 				      u32 flag, int *waiter_count);
1180 
1181 
1182 /**
1183  * Kernel framebuffer - vmwgfx_fb.c
1184  */
1185 
1186 #ifdef CONFIG_DRM_FBDEV_EMULATION
1187 int vmw_fb_init(struct vmw_private *vmw_priv);
1188 int vmw_fb_close(struct vmw_private *dev_priv);
1189 int vmw_fb_off(struct vmw_private *vmw_priv);
1190 int vmw_fb_on(struct vmw_private *vmw_priv);
1191 #else
vmw_fb_init(struct vmw_private * vmw_priv)1192 static inline int vmw_fb_init(struct vmw_private *vmw_priv)
1193 {
1194 	return 0;
1195 }
vmw_fb_close(struct vmw_private * dev_priv)1196 static inline int vmw_fb_close(struct vmw_private *dev_priv)
1197 {
1198 	return 0;
1199 }
vmw_fb_off(struct vmw_private * vmw_priv)1200 static inline int vmw_fb_off(struct vmw_private *vmw_priv)
1201 {
1202 	return 0;
1203 }
vmw_fb_on(struct vmw_private * vmw_priv)1204 static inline int vmw_fb_on(struct vmw_private *vmw_priv)
1205 {
1206 	return 0;
1207 }
1208 #endif
1209 
1210 /**
1211  * Kernel modesetting - vmwgfx_kms.c
1212  */
1213 
1214 int vmw_kms_init(struct vmw_private *dev_priv);
1215 int vmw_kms_close(struct vmw_private *dev_priv);
1216 int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
1217 				struct drm_file *file_priv);
1218 void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
1219 void vmw_kms_cursor_snoop(struct vmw_surface *srf,
1220 			  struct ttm_object_file *tfile,
1221 			  struct ttm_buffer_object *bo,
1222 			  SVGA3dCmdHeader *header);
1223 int vmw_kms_write_svga(struct vmw_private *vmw_priv,
1224 		       unsigned width, unsigned height, unsigned pitch,
1225 		       unsigned bpp, unsigned depth);
1226 bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
1227 				uint32_t pitch,
1228 				uint32_t height);
1229 int vmw_kms_present(struct vmw_private *dev_priv,
1230 		    struct drm_file *file_priv,
1231 		    struct vmw_framebuffer *vfb,
1232 		    struct vmw_surface *surface,
1233 		    uint32_t sid, int32_t destX, int32_t destY,
1234 		    struct drm_vmw_rect *clips,
1235 		    uint32_t num_clips);
1236 int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
1237 				struct drm_file *file_priv);
1238 void vmw_kms_legacy_hotspot_clear(struct vmw_private *dev_priv);
1239 int vmw_kms_suspend(struct drm_device *dev);
1240 int vmw_kms_resume(struct drm_device *dev);
1241 void vmw_kms_lost_device(struct drm_device *dev);
1242 
1243 int vmw_dumb_create(struct drm_file *file_priv,
1244 		    struct drm_device *dev,
1245 		    struct drm_mode_create_dumb *args);
1246 extern int vmw_resource_pin(struct vmw_resource *res, bool interruptible);
1247 extern void vmw_resource_unpin(struct vmw_resource *res);
1248 extern enum vmw_res_type vmw_res_type(const struct vmw_resource *res);
1249 
1250 /**
1251  * Overlay control - vmwgfx_overlay.c
1252  */
1253 
1254 int vmw_overlay_init(struct vmw_private *dev_priv);
1255 int vmw_overlay_close(struct vmw_private *dev_priv);
1256 int vmw_overlay_ioctl(struct drm_device *dev, void *data,
1257 		      struct drm_file *file_priv);
1258 int vmw_overlay_resume_all(struct vmw_private *dev_priv);
1259 int vmw_overlay_pause_all(struct vmw_private *dev_priv);
1260 int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
1261 int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
1262 int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
1263 int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
1264 
1265 /**
1266  * GMR Id manager
1267  */
1268 
1269 int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type);
1270 void vmw_gmrid_man_fini(struct vmw_private *dev_priv, int type);
1271 
1272 /**
1273  * System memory manager
1274  */
1275 int vmw_sys_man_init(struct vmw_private *dev_priv);
1276 void vmw_sys_man_fini(struct vmw_private *dev_priv);
1277 
1278 /**
1279  * Prime - vmwgfx_prime.c
1280  */
1281 
1282 extern const struct dma_buf_ops vmw_prime_dmabuf_ops;
1283 extern int vmw_prime_fd_to_handle(struct drm_device *dev,
1284 				  struct drm_file *file_priv,
1285 				  int fd, u32 *handle);
1286 extern int vmw_prime_handle_to_fd(struct drm_device *dev,
1287 				  struct drm_file *file_priv,
1288 				  uint32_t handle, uint32_t flags,
1289 				  int *prime_fd);
1290 
1291 /*
1292  * MemoryOBject management -  vmwgfx_mob.c
1293  */
1294 struct vmw_mob;
1295 extern int vmw_mob_bind(struct vmw_private *dev_priv, struct vmw_mob *mob,
1296 			const struct vmw_sg_table *vsgt,
1297 			unsigned long num_data_pages, int32_t mob_id);
1298 extern void vmw_mob_unbind(struct vmw_private *dev_priv,
1299 			   struct vmw_mob *mob);
1300 extern void vmw_mob_destroy(struct vmw_mob *mob);
1301 extern struct vmw_mob *vmw_mob_create(unsigned long data_pages);
1302 extern int vmw_otables_setup(struct vmw_private *dev_priv);
1303 extern void vmw_otables_takedown(struct vmw_private *dev_priv);
1304 
1305 /*
1306  * Context management - vmwgfx_context.c
1307  */
1308 
1309 extern const struct vmw_user_resource_conv *user_context_converter;
1310 
1311 extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
1312 				    struct drm_file *file_priv);
1313 extern int vmw_extended_context_define_ioctl(struct drm_device *dev, void *data,
1314 					     struct drm_file *file_priv);
1315 extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
1316 				     struct drm_file *file_priv);
1317 extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
1318 extern struct vmw_cmdbuf_res_manager *
1319 vmw_context_res_man(struct vmw_resource *ctx);
1320 extern struct vmw_resource *vmw_context_cotable(struct vmw_resource *ctx,
1321 						SVGACOTableType cotable_type);
1322 struct vmw_ctx_binding_state;
1323 extern struct vmw_ctx_binding_state *
1324 vmw_context_binding_state(struct vmw_resource *ctx);
1325 extern void vmw_dx_context_scrub_cotables(struct vmw_resource *ctx,
1326 					  bool readback);
1327 extern int vmw_context_bind_dx_query(struct vmw_resource *ctx_res,
1328 				     struct vmw_buffer_object *mob);
1329 extern struct vmw_buffer_object *
1330 vmw_context_get_dx_query_mob(struct vmw_resource *ctx_res);
1331 
1332 
1333 /*
1334  * Surface management - vmwgfx_surface.c
1335  */
1336 
1337 extern const struct vmw_user_resource_conv *user_surface_converter;
1338 
1339 extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data,
1340 				     struct drm_file *file_priv);
1341 extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
1342 				    struct drm_file *file_priv);
1343 extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,
1344 				       struct drm_file *file_priv);
1345 extern int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data,
1346 				       struct drm_file *file_priv);
1347 extern int vmw_gb_surface_reference_ioctl(struct drm_device *dev, void *data,
1348 					  struct drm_file *file_priv);
1349 extern int vmw_gb_surface_define_ext_ioctl(struct drm_device *dev,
1350 					   void *data,
1351 					   struct drm_file *file_priv);
1352 extern int vmw_gb_surface_reference_ext_ioctl(struct drm_device *dev,
1353 					      void *data,
1354 					      struct drm_file *file_priv);
1355 
1356 int vmw_gb_surface_define(struct vmw_private *dev_priv,
1357 			  const struct vmw_surface_metadata *req,
1358 			  struct vmw_surface **srf_out);
1359 
1360 /*
1361  * Shader management - vmwgfx_shader.c
1362  */
1363 
1364 extern const struct vmw_user_resource_conv *user_shader_converter;
1365 
1366 extern int vmw_shader_define_ioctl(struct drm_device *dev, void *data,
1367 				   struct drm_file *file_priv);
1368 extern int vmw_shader_destroy_ioctl(struct drm_device *dev, void *data,
1369 				    struct drm_file *file_priv);
1370 extern int vmw_compat_shader_add(struct vmw_private *dev_priv,
1371 				 struct vmw_cmdbuf_res_manager *man,
1372 				 u32 user_key, const void *bytecode,
1373 				 SVGA3dShaderType shader_type,
1374 				 size_t size,
1375 				 struct list_head *list);
1376 extern int vmw_shader_remove(struct vmw_cmdbuf_res_manager *man,
1377 			     u32 user_key, SVGA3dShaderType shader_type,
1378 			     struct list_head *list);
1379 extern int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,
1380 			     struct vmw_resource *ctx,
1381 			     u32 user_key,
1382 			     SVGA3dShaderType shader_type,
1383 			     struct list_head *list);
1384 extern void vmw_dx_shader_cotable_list_scrub(struct vmw_private *dev_priv,
1385 					     struct list_head *list,
1386 					     bool readback);
1387 
1388 extern struct vmw_resource *
1389 vmw_shader_lookup(struct vmw_cmdbuf_res_manager *man,
1390 		  u32 user_key, SVGA3dShaderType shader_type);
1391 
1392 /*
1393  * Streamoutput management
1394  */
1395 struct vmw_resource *
1396 vmw_dx_streamoutput_lookup(struct vmw_cmdbuf_res_manager *man,
1397 			   u32 user_key);
1398 int vmw_dx_streamoutput_add(struct vmw_cmdbuf_res_manager *man,
1399 			    struct vmw_resource *ctx,
1400 			    SVGA3dStreamOutputId user_key,
1401 			    struct list_head *list);
1402 void vmw_dx_streamoutput_set_size(struct vmw_resource *res, u32 size);
1403 int vmw_dx_streamoutput_remove(struct vmw_cmdbuf_res_manager *man,
1404 			       SVGA3dStreamOutputId user_key,
1405 			       struct list_head *list);
1406 void vmw_dx_streamoutput_cotable_list_scrub(struct vmw_private *dev_priv,
1407 					    struct list_head *list,
1408 					    bool readback);
1409 
1410 /*
1411  * Command buffer managed resources - vmwgfx_cmdbuf_res.c
1412  */
1413 
1414 extern struct vmw_cmdbuf_res_manager *
1415 vmw_cmdbuf_res_man_create(struct vmw_private *dev_priv);
1416 extern void vmw_cmdbuf_res_man_destroy(struct vmw_cmdbuf_res_manager *man);
1417 extern struct vmw_resource *
1418 vmw_cmdbuf_res_lookup(struct vmw_cmdbuf_res_manager *man,
1419 		      enum vmw_cmdbuf_res_type res_type,
1420 		      u32 user_key);
1421 extern void vmw_cmdbuf_res_revert(struct list_head *list);
1422 extern void vmw_cmdbuf_res_commit(struct list_head *list);
1423 extern int vmw_cmdbuf_res_add(struct vmw_cmdbuf_res_manager *man,
1424 			      enum vmw_cmdbuf_res_type res_type,
1425 			      u32 user_key,
1426 			      struct vmw_resource *res,
1427 			      struct list_head *list);
1428 extern int vmw_cmdbuf_res_remove(struct vmw_cmdbuf_res_manager *man,
1429 				 enum vmw_cmdbuf_res_type res_type,
1430 				 u32 user_key,
1431 				 struct list_head *list,
1432 				 struct vmw_resource **res);
1433 
1434 /*
1435  * COTable management - vmwgfx_cotable.c
1436  */
1437 extern const SVGACOTableType vmw_cotable_scrub_order[];
1438 extern struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv,
1439 					      struct vmw_resource *ctx,
1440 					      u32 type);
1441 extern int vmw_cotable_notify(struct vmw_resource *res, int id);
1442 extern int vmw_cotable_scrub(struct vmw_resource *res, bool readback);
1443 extern void vmw_cotable_add_resource(struct vmw_resource *ctx,
1444 				     struct list_head *head);
1445 
1446 /*
1447  * Command buffer managerment vmwgfx_cmdbuf.c
1448  */
1449 struct vmw_cmdbuf_man;
1450 struct vmw_cmdbuf_header;
1451 
1452 extern struct vmw_cmdbuf_man *
1453 vmw_cmdbuf_man_create(struct vmw_private *dev_priv);
1454 extern int vmw_cmdbuf_set_pool_size(struct vmw_cmdbuf_man *man, size_t size);
1455 extern void vmw_cmdbuf_remove_pool(struct vmw_cmdbuf_man *man);
1456 extern void vmw_cmdbuf_man_destroy(struct vmw_cmdbuf_man *man);
1457 extern int vmw_cmdbuf_idle(struct vmw_cmdbuf_man *man, bool interruptible,
1458 			   unsigned long timeout);
1459 extern void *vmw_cmdbuf_reserve(struct vmw_cmdbuf_man *man, size_t size,
1460 				int ctx_id, bool interruptible,
1461 				struct vmw_cmdbuf_header *header);
1462 extern void vmw_cmdbuf_commit(struct vmw_cmdbuf_man *man, size_t size,
1463 			      struct vmw_cmdbuf_header *header,
1464 			      bool flush);
1465 extern void *vmw_cmdbuf_alloc(struct vmw_cmdbuf_man *man,
1466 			      size_t size, bool interruptible,
1467 			      struct vmw_cmdbuf_header **p_header);
1468 extern void vmw_cmdbuf_header_free(struct vmw_cmdbuf_header *header);
1469 extern int vmw_cmdbuf_cur_flush(struct vmw_cmdbuf_man *man,
1470 				bool interruptible);
1471 extern void vmw_cmdbuf_irqthread(struct vmw_cmdbuf_man *man);
1472 
1473 /* CPU blit utilities - vmwgfx_blit.c */
1474 
1475 /**
1476  * struct vmw_diff_cpy - CPU blit information structure
1477  *
1478  * @rect: The output bounding box rectangle.
1479  * @line: The current line of the blit.
1480  * @line_offset: Offset of the current line segment.
1481  * @cpp: Bytes per pixel (granularity information).
1482  * @memcpy: Which memcpy function to use.
1483  */
1484 struct vmw_diff_cpy {
1485 	struct drm_rect rect;
1486 	size_t line;
1487 	size_t line_offset;
1488 	int cpp;
1489 	void (*do_cpy)(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src,
1490 		       size_t n);
1491 };
1492 
1493 #define VMW_CPU_BLIT_INITIALIZER {	\
1494 	.do_cpy = vmw_memcpy,		\
1495 }
1496 
1497 #define VMW_CPU_BLIT_DIFF_INITIALIZER(_cpp) {	  \
1498 	.line = 0,				  \
1499 	.line_offset = 0,			  \
1500 	.rect = { .x1 = INT_MAX/2,		  \
1501 		  .y1 = INT_MAX/2,		  \
1502 		  .x2 = INT_MIN/2,		  \
1503 		  .y2 = INT_MIN/2		  \
1504 	},					  \
1505 	.cpp = _cpp,				  \
1506 	.do_cpy = vmw_diff_memcpy,		  \
1507 }
1508 
1509 void vmw_diff_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src,
1510 		     size_t n);
1511 
1512 void vmw_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src, size_t n);
1513 
1514 int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
1515 		    u32 dst_offset, u32 dst_stride,
1516 		    struct ttm_buffer_object *src,
1517 		    u32 src_offset, u32 src_stride,
1518 		    u32 w, u32 h,
1519 		    struct vmw_diff_cpy *diff);
1520 
1521 /* Host messaging -vmwgfx_msg.c: */
1522 int vmw_host_get_guestinfo(const char *guest_info_param,
1523 			   char *buffer, size_t *length);
1524 __printf(1, 2) int vmw_host_printf(const char *fmt, ...);
1525 int vmw_msg_ioctl(struct drm_device *dev, void *data,
1526 		  struct drm_file *file_priv);
1527 
1528 /* Host mksGuestStats -vmwgfx_msg.c: */
1529 int vmw_mksstat_get_kern_slot(pid_t pid, struct vmw_private *dev_priv);
1530 
1531 int vmw_mksstat_reset_ioctl(struct drm_device *dev, void *data,
1532 		      struct drm_file *file_priv);
1533 int vmw_mksstat_add_ioctl(struct drm_device *dev, void *data,
1534 		      struct drm_file *file_priv);
1535 int vmw_mksstat_remove_ioctl(struct drm_device *dev, void *data,
1536 		      struct drm_file *file_priv);
1537 int vmw_mksstat_remove_all(struct vmw_private *dev_priv);
1538 
1539 /* VMW logging */
1540 
1541 /**
1542  * VMW_DEBUG_USER - Debug output for user-space debugging.
1543  *
1544  * @fmt: printf() like format string.
1545  *
1546  * This macro is for logging user-space error and debugging messages for e.g.
1547  * command buffer execution errors due to malformed commands, invalid context,
1548  * etc.
1549  */
1550 #define VMW_DEBUG_USER(fmt, ...)                                              \
1551 	DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__)
1552 
1553 /* Resource dirtying - vmwgfx_page_dirty.c */
1554 void vmw_bo_dirty_scan(struct vmw_buffer_object *vbo);
1555 int vmw_bo_dirty_add(struct vmw_buffer_object *vbo);
1556 void vmw_bo_dirty_transfer_to_res(struct vmw_resource *res);
1557 void vmw_bo_dirty_clear_res(struct vmw_resource *res);
1558 void vmw_bo_dirty_release(struct vmw_buffer_object *vbo);
1559 void vmw_bo_dirty_unmap(struct vmw_buffer_object *vbo,
1560 			pgoff_t start, pgoff_t end);
1561 vm_fault_t vmw_bo_vm_fault(struct vm_fault *vmf);
1562 vm_fault_t vmw_bo_vm_mkwrite(struct vm_fault *vmf);
1563 
1564 
1565 /**
1566  * VMW_DEBUG_KMS - Debug output for kernel mode-setting
1567  *
1568  * This macro is for debugging vmwgfx mode-setting code.
1569  */
1570 #define VMW_DEBUG_KMS(fmt, ...)                                               \
1571 	DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__)
1572 
1573 /**
1574  * Inline helper functions
1575  */
1576 
vmw_surface_unreference(struct vmw_surface ** srf)1577 static inline void vmw_surface_unreference(struct vmw_surface **srf)
1578 {
1579 	struct vmw_surface *tmp_srf = *srf;
1580 	struct vmw_resource *res = &tmp_srf->res;
1581 	*srf = NULL;
1582 
1583 	vmw_resource_unreference(&res);
1584 }
1585 
vmw_surface_reference(struct vmw_surface * srf)1586 static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
1587 {
1588 	(void) vmw_resource_reference(&srf->res);
1589 	return srf;
1590 }
1591 
vmw_bo_unreference(struct vmw_buffer_object ** buf)1592 static inline void vmw_bo_unreference(struct vmw_buffer_object **buf)
1593 {
1594 	struct vmw_buffer_object *tmp_buf = *buf;
1595 
1596 	*buf = NULL;
1597 	if (tmp_buf != NULL)
1598 		ttm_bo_put(&tmp_buf->base);
1599 }
1600 
1601 static inline struct vmw_buffer_object *
vmw_bo_reference(struct vmw_buffer_object * buf)1602 vmw_bo_reference(struct vmw_buffer_object *buf)
1603 {
1604 	ttm_bo_get(&buf->base);
1605 	return buf;
1606 }
1607 
vmw_user_bo_ref(struct vmw_buffer_object * vbo)1608 static inline struct vmw_buffer_object *vmw_user_bo_ref(struct vmw_buffer_object *vbo)
1609 {
1610 	drm_gem_object_get(&vbo->base.base);
1611 	return vbo;
1612 }
1613 
vmw_user_bo_unref(struct vmw_buffer_object ** buf)1614 static inline void vmw_user_bo_unref(struct vmw_buffer_object **buf)
1615 {
1616 	struct vmw_buffer_object *tmp_buf = *buf;
1617 
1618 	*buf = NULL;
1619 	if (tmp_buf)
1620 		drm_gem_object_put(&tmp_buf->base.base);
1621 }
1622 
vmw_fifo_resource_inc(struct vmw_private * dev_priv)1623 static inline void vmw_fifo_resource_inc(struct vmw_private *dev_priv)
1624 {
1625 	atomic_inc(&dev_priv->num_fifo_resources);
1626 }
1627 
vmw_fifo_resource_dec(struct vmw_private * dev_priv)1628 static inline void vmw_fifo_resource_dec(struct vmw_private *dev_priv)
1629 {
1630 	atomic_dec(&dev_priv->num_fifo_resources);
1631 }
1632 
1633 /**
1634  * vmw_fifo_mem_read - Perform a MMIO read from the fifo memory
1635  *
1636  * @fifo_reg: The fifo register to read from
1637  *
1638  * This function is intended to be equivalent to ioread32() on
1639  * memremap'd memory, but without byteswapping.
1640  */
vmw_fifo_mem_read(struct vmw_private * vmw,uint32 fifo_reg)1641 static inline u32 vmw_fifo_mem_read(struct vmw_private *vmw, uint32 fifo_reg)
1642 {
1643 	BUG_ON(vmw_is_svga_v3(vmw));
1644 	return READ_ONCE(*(vmw->fifo_mem + fifo_reg));
1645 }
1646 
1647 /**
1648  * vmw_fifo_mem_write - Perform a MMIO write to volatile memory
1649  *
1650  * @addr: The fifo register to write to
1651  *
1652  * This function is intended to be equivalent to iowrite32 on
1653  * memremap'd memory, but without byteswapping.
1654  */
vmw_fifo_mem_write(struct vmw_private * vmw,u32 fifo_reg,u32 value)1655 static inline void vmw_fifo_mem_write(struct vmw_private *vmw, u32 fifo_reg,
1656 				      u32 value)
1657 {
1658 	BUG_ON(vmw_is_svga_v3(vmw));
1659 	WRITE_ONCE(*(vmw->fifo_mem + fifo_reg), value);
1660 }
1661 
vmw_fence_read(struct vmw_private * dev_priv)1662 static inline u32 vmw_fence_read(struct vmw_private *dev_priv)
1663 {
1664 	u32 fence;
1665 	if (vmw_is_svga_v3(dev_priv))
1666 		fence = vmw_read(dev_priv, SVGA_REG_FENCE);
1667 	else
1668 		fence = vmw_fifo_mem_read(dev_priv, SVGA_FIFO_FENCE);
1669 	return fence;
1670 }
1671 
vmw_fence_write(struct vmw_private * dev_priv,u32 fence)1672 static inline void vmw_fence_write(struct vmw_private *dev_priv,
1673 				  u32 fence)
1674 {
1675 	BUG_ON(vmw_is_svga_v3(dev_priv));
1676 	vmw_fifo_mem_write(dev_priv, SVGA_FIFO_FENCE, fence);
1677 }
1678 
vmw_irq_status_read(struct vmw_private * vmw)1679 static inline u32 vmw_irq_status_read(struct vmw_private *vmw)
1680 {
1681 	u32 status;
1682 	if (vmw_is_svga_v3(vmw))
1683 		status = vmw_read(vmw, SVGA_REG_IRQ_STATUS);
1684 	else
1685 		status = inl(vmw->io_start + SVGA_IRQSTATUS_PORT);
1686 	return status;
1687 }
1688 
vmw_irq_status_write(struct vmw_private * vmw,uint32 status)1689 static inline void vmw_irq_status_write(struct vmw_private *vmw,
1690 					uint32 status)
1691 {
1692 	if (vmw_is_svga_v3(vmw))
1693 		vmw_write(vmw, SVGA_REG_IRQ_STATUS, status);
1694 	else
1695 		outl(status, vmw->io_start + SVGA_IRQSTATUS_PORT);
1696 }
1697 
vmw_has_fences(struct vmw_private * vmw)1698 static inline bool vmw_has_fences(struct vmw_private *vmw)
1699 {
1700 	if ((vmw->capabilities & (SVGA_CAP_COMMAND_BUFFERS |
1701 				  SVGA_CAP_CMD_BUFFERS_2)) != 0)
1702 		return true;
1703 	return (vmw_fifo_caps(vmw) & SVGA_FIFO_CAP_FENCE) != 0;
1704 }
1705 
vmw_shadertype_is_valid(enum vmw_sm_type shader_model,u32 shader_type)1706 static inline bool vmw_shadertype_is_valid(enum vmw_sm_type shader_model,
1707 					   u32 shader_type)
1708 {
1709 	SVGA3dShaderType max_allowed = SVGA3D_SHADERTYPE_PREDX_MAX;
1710 
1711 	if (shader_model >= VMW_SM_5)
1712 		max_allowed = SVGA3D_SHADERTYPE_MAX;
1713 	else if (shader_model >= VMW_SM_4)
1714 		max_allowed = SVGA3D_SHADERTYPE_DX10_MAX;
1715 	return shader_type >= SVGA3D_SHADERTYPE_MIN && shader_type < max_allowed;
1716 }
1717 
1718 #endif
1719