1 /**************************************************************************
2  *
3  * Copyright © 2009-2015 VMware, Inc., Palo Alto, CA., USA
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"
32 #include <drm/drmP.h>
33 #include <drm/vmwgfx_drm.h>
34 #include <drm/drm_hashtab.h>
35 #include <drm/drm_auth.h>
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>
42 #include "vmwgfx_fence.h"
43 #include <linux/sync_file.h>
44 
45 #define VMWGFX_DRIVER_NAME "vmwgfx"
46 #define VMWGFX_DRIVER_DATE "20170612"
47 #define VMWGFX_DRIVER_MAJOR 2
48 #define VMWGFX_DRIVER_MINOR 14
49 #define VMWGFX_DRIVER_PATCHLEVEL 0
50 #define VMWGFX_FILE_PAGE_OFFSET 0x00100000
51 #define VMWGFX_FIFO_STATIC_SIZE (1024*1024)
52 #define VMWGFX_MAX_RELOCATIONS 2048
53 #define VMWGFX_MAX_VALIDATIONS 2048
54 #define VMWGFX_MAX_DISPLAYS 16
55 #define VMWGFX_CMD_BOUNCE_INIT_SIZE 32768
56 #define VMWGFX_ENABLE_SCREEN_TARGET_OTABLE 1
57 
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
64 #define VMWGFX_NUM_GB_SCREEN_TARGET VMWGFX_MAX_DISPLAYS
65 #define VMWGFX_NUM_DXCONTEXT 256
66 #define VMWGFX_NUM_DXQUERY 512
67 #define VMWGFX_NUM_MOB (VMWGFX_NUM_GB_CONTEXT +\
68 			VMWGFX_NUM_GB_SHADER +\
69 			VMWGFX_NUM_GB_SURFACE +\
70 			VMWGFX_NUM_GB_SCREEN_TARGET)
71 
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)
76 
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
81 #define VMW_RES_SHADER ttm_driver_type4
82 
83 struct vmw_fpriv {
84 	struct drm_master *locked_master;
85 	struct ttm_object_file *tfile;
86 	bool gb_aware;
87 };
88 
89 struct vmw_dma_buffer {
90 	struct ttm_buffer_object base;
91 	struct list_head res_list;
92 	s32 pin_count;
93 	/* Not ref-counted.  Protected by binding_mutex */
94 	struct vmw_resource *dx_query_ctx;
95 };
96 
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;
109 	bool validate_as_mob;
110 };
111 
112 struct vmw_res_func;
113 struct vmw_resource {
114 	struct kref kref;
115 	struct vmw_private *dev_priv;
116 	int id;
117 	bool avail;
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;
123 	unsigned long pin_count; /* Protected by resource reserved */
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 */
127 	struct list_head binding_head; /* Protected by binding_mutex */
128 	void (*res_free) (struct vmw_resource *res);
129 	void (*hw_destroy) (struct vmw_resource *res);
130 };
131 
132 
133 /*
134  * Resources that are managed using ioctls.
135  */
136 enum vmw_res_type {
137 	vmw_res_context,
138 	vmw_res_surface,
139 	vmw_res_stream,
140 	vmw_res_shader,
141 	vmw_res_dx_context,
142 	vmw_res_cotable,
143 	vmw_res_view,
144 	vmw_res_max
145 };
146 
147 /*
148  * Resources that are managed using command streams.
149  */
150 enum vmw_cmdbuf_res_type {
151 	vmw_cmdbuf_res_shader,
152 	vmw_cmdbuf_res_view
153 };
154 
155 struct vmw_cmdbuf_res_manager;
156 
157 struct vmw_cursor_snooper {
158 	size_t age;
159 	uint32_t *image;
160 };
161 
162 struct vmw_framebuffer;
163 struct vmw_surface_offset;
164 
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];
170 	struct drm_vmw_size base_size;
171 	struct drm_vmw_size *sizes;
172 	uint32_t num_sizes;
173 	bool scanout;
174 	uint32_t array_size;
175 	/* TODO so far just a extra pointer */
176 	struct vmw_cursor_snooper snooper;
177 	struct vmw_surface_offset *offsets;
178 	SVGA3dTextureFilter autogen_filter;
179 	uint32_t multisample_count;
180 	struct list_head view_list;
181 };
182 
183 struct vmw_marker_queue {
184 	struct list_head head;
185 	u64 lag;
186 	u64 lag_time;
187 	spinlock_t lock;
188 };
189 
190 struct vmw_fifo_state {
191 	unsigned long reserved_size;
192 	u32 *dynamic_buffer;
193 	u32 *static_buffer;
194 	unsigned long static_buffer_size;
195 	bool using_bounce_buffer;
196 	uint32_t capabilities;
197 	struct mutex fifo_mutex;
198 	struct rw_semaphore rwsem;
199 	struct vmw_marker_queue marker_queue;
200 	bool dx;
201 };
202 
203 struct vmw_relocation {
204 	SVGAMobId *mob_loc;
205 	SVGAGuestPtr *location;
206 	uint32_t index;
207 };
208 
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 
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
244  * @num_regions: Number of regions with device-address contiguous pages
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 
280 /*
281  * enum vmw_display_unit_type - Describes the display unit
282  */
283 enum vmw_display_unit_type {
284 	vmw_du_invalid = 0,
285 	vmw_du_legacy,
286 	vmw_du_screen_object,
287 	vmw_du_screen_target
288 };
289 
290 
291 struct vmw_sw_context{
292 	struct drm_open_hash res_ht;
293 	bool res_ht_initialized;
294 	bool kernel; /**< is the called made from the kernel */
295 	struct vmw_fpriv *fp;
296 	struct list_head validate_nodes;
297 	struct vmw_relocation relocs[VMWGFX_MAX_RELOCATIONS];
298 	uint32_t cur_reloc;
299 	struct vmw_validate_buffer val_bufs[VMWGFX_MAX_VALIDATIONS];
300 	uint32_t cur_val_buf;
301 	uint32_t *cmd_bounce;
302 	uint32_t cmd_bounce_size;
303 	struct list_head resource_list;
304 	struct list_head ctx_resource_list; /* For contexts and cotables */
305 	struct vmw_dma_buffer *cur_query_bo;
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;
312 	struct vmw_ctx_binding_state *staged_bindings;
313 	bool staged_bindings_inuse;
314 	struct list_head staged_cmd_res;
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;
319 };
320 
321 struct vmw_legacy_display;
322 struct vmw_overlay;
323 
324 struct vmw_master {
325 	struct ttm_lock lock;
326 };
327 
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 
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 
356 enum {
357 	VMW_IRQTHREAD_FENCE,
358 	VMW_IRQTHREAD_CMDBUF,
359 	VMW_IRQTHREAD_MAX
360 };
361 
362 struct vmw_private {
363 	struct ttm_bo_device bdev;
364 	struct ttm_bo_global_ref bo_global_ref;
365 	struct drm_global_reference mem_global_ref;
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;
374 	uint32_t prim_bb_mem;
375 	uint32_t mmio_start;
376 	uint32_t mmio_size;
377 	uint32_t fb_max_width;
378 	uint32_t fb_max_height;
379 	uint32_t texture_max_width;
380 	uint32_t texture_max_height;
381 	uint32_t stdu_max_width;
382 	uint32_t stdu_max_height;
383 	uint32_t initial_width;
384 	uint32_t initial_height;
385 	u32 *mmio_virt;
386 	uint32_t capabilities;
387 	uint32_t max_gmr_ids;
388 	uint32_t max_gmr_pages;
389 	uint32_t max_mob_pages;
390 	uint32_t max_mob_size;
391 	uint32_t memory_size;
392 	bool has_gmr;
393 	bool has_mob;
394 	spinlock_t hw_lock;
395 	spinlock_t cap_lock;
396 	bool has_dx;
397 	bool assume_16bpp;
398 
399 	/*
400 	 * VGA registers.
401 	 */
402 
403 	struct vmw_vga_topology_state vga_save[VMWGFX_MAX_DISPLAYS];
404 	uint32_t vga_width;
405 	uint32_t vga_height;
406 	uint32_t vga_bpp;
407 	uint32_t vga_bpl;
408 	uint32_t vga_pitchlock;
409 
410 	uint32_t num_displays;
411 
412 	/*
413 	 * Framebuffer info.
414 	 */
415 
416 	void *fb_info;
417 	enum vmw_display_unit_type active_display_unit;
418 	struct vmw_legacy_display *ldu_priv;
419 	struct vmw_overlay *overlay_priv;
420 	struct drm_property *hotplug_mode_update_property;
421 	struct drm_property *implicit_placement_property;
422 	unsigned num_implicit;
423 	struct vmw_framebuffer *implicit_fb;
424 	struct mutex global_kms_state_mutex;
425 	spinlock_t cursor_lock;
426 
427 	/*
428 	 * Context and surface management.
429 	 */
430 
431 	rwlock_t resource_lock;
432 	struct idr res_idr[vmw_res_max];
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 
450 	atomic_t marker_seq;
451 	wait_queue_head_t fence_queue;
452 	wait_queue_head_t fifo_queue;
453 	spinlock_t waiter_lock;
454 	int fence_queue_waiters; /* Protected by waiter_lock */
455 	int goal_queue_waiters; /* Protected by waiter_lock */
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 */
459 	uint32_t last_read_seqno;
460 	struct vmw_fence_manager *fman;
461 	uint32_t irq_mask; /* Updates protected by waiter_lock */
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;
479 	struct mutex cmdbuf_mutex;
480 	struct mutex binding_mutex;
481 
482 	/**
483 	 * Operating mode.
484 	 */
485 
486 	bool stealth;
487 	bool enable_fb;
488 	spinlock_t svga_lock;
489 
490 	/**
491 	 * Master management.
492 	 */
493 
494 	struct vmw_master *active_master;
495 	struct vmw_master fbdev_master;
496 	struct notifier_block pm_nb;
497 	bool suspended;
498 	bool refuse_hibernation;
499 
500 	struct mutex release_mutex;
501 	atomic_t num_fifo_resources;
502 
503 	/*
504 	 * Replace this with an rwsem as soon as we have down_xx_interruptible()
505 	 */
506 	struct ttm_lock reservation_sem;
507 
508 	/*
509 	 * Query processing. These members
510 	 * are protected by the cmdbuf mutex.
511 	 */
512 
513 	struct vmw_dma_buffer *dummy_query_bo;
514 	struct vmw_dma_buffer *pinned_bo;
515 	uint32_t query_cid;
516 	uint32_t query_cid_valid;
517 	bool dummy_query_bo_pinned;
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 
526 	struct list_head res_lru[vmw_res_max];
527 	uint32_t used_memory_size;
528 
529 	/*
530 	 * DMA mapping stuff.
531 	 */
532 	enum vmw_dma_map_mode map_mode;
533 
534 	/*
535 	 * Guest Backed stuff
536 	 */
537 	struct vmw_otable_batch otable_batch;
538 
539 	struct vmw_cmdbuf_man *cman;
540 	DECLARE_BITMAP(irqthread_pending, VMW_IRQTHREAD_MAX);
541 };
542 
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 
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 
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  */
570 static inline void vmw_write(struct vmw_private *dev_priv,
571 			     unsigned int offset, uint32_t value)
572 {
573 	spin_lock(&dev_priv->hw_lock);
574 	outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
575 	outl(value, dev_priv->io_start + VMWGFX_VALUE_PORT);
576 	spin_unlock(&dev_priv->hw_lock);
577 }
578 
579 static inline uint32_t vmw_read(struct vmw_private *dev_priv,
580 				unsigned int offset)
581 {
582 	u32 val;
583 
584 	spin_lock(&dev_priv->hw_lock);
585 	outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
586 	val = inl(dev_priv->io_start + VMWGFX_VALUE_PORT);
587 	spin_unlock(&dev_priv->hw_lock);
588 
589 	return val;
590 }
591 
592 extern void vmw_svga_enable(struct vmw_private *dev_priv);
593 extern void vmw_svga_disable(struct vmw_private *dev_priv);
594 
595 
596 /**
597  * GMR utilities - vmwgfx_gmr.c
598  */
599 
600 extern int vmw_gmr_bind(struct vmw_private *dev_priv,
601 			const struct vmw_sg_table *vsgt,
602 			unsigned long num_pages,
603 			int gmr_id);
604 extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
605 
606 /**
607  * Resource utilities - vmwgfx_resource.c
608  */
609 struct vmw_user_resource_conv;
610 
611 extern void vmw_resource_unreference(struct vmw_resource **p_res);
612 extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
613 extern struct vmw_resource *
614 vmw_resource_reference_unless_doomed(struct vmw_resource *res);
615 extern int vmw_resource_validate(struct vmw_resource *res);
616 extern int vmw_resource_reserve(struct vmw_resource *res, bool interruptible,
617 				bool no_backup);
618 extern bool vmw_resource_needs_backup(const struct vmw_resource *res);
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);
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);
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));
636 extern int vmw_user_dmabuf_verify_access(struct ttm_buffer_object *bo,
637 				  struct ttm_object_file *tfile);
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,
643 				 struct vmw_dma_buffer **p_dma_buf,
644 				 struct ttm_base_object **p_base);
645 extern int vmw_user_dmabuf_reference(struct ttm_object_file *tfile,
646 				     struct vmw_dma_buffer *dma_buf,
647 				     uint32_t *handle);
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);
652 extern int vmw_user_dmabuf_synccpu_ioctl(struct drm_device *dev, void *data,
653 					 struct drm_file *file_priv);
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,
658 				  uint32_t id, struct vmw_dma_buffer **out,
659 				  struct ttm_base_object **base);
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);
668 extern void vmw_resource_unreserve(struct vmw_resource *res,
669 				   bool switch_backup,
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);
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);
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);
680 
681 /**
682  * DMA buffer helper routines - vmwgfx_dmabuf.c
683  */
684 extern int vmw_dmabuf_pin_in_placement(struct vmw_private *vmw_priv,
685 				       struct vmw_dma_buffer *bo,
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);
697 extern int vmw_dmabuf_unpin(struct vmw_private *vmw_priv,
698 			    struct vmw_dma_buffer *bo,
699 			    bool interruptible);
700 extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf,
701 				 SVGAGuestPtr *ptr);
702 extern void vmw_bo_pin_reserved(struct vmw_dma_buffer *bo, bool pin);
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);
710 extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
711 				struct drm_file *file_priv);
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);
716 extern __poll_t vmw_fops_poll(struct file *filp,
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);
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);
730 extern void *
731 vmw_fifo_reserve_dx(struct vmw_private *dev_priv, uint32_t bytes, int ctx_id);
732 extern void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes);
733 extern void vmw_fifo_commit_flush(struct vmw_private *dev_priv, uint32_t bytes);
734 extern int vmw_fifo_send_fence(struct vmw_private *dev_priv,
735 			       uint32_t *seqno);
736 extern void vmw_fifo_ping_host_locked(struct vmw_private *, uint32_t reason);
737 extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
738 extern bool vmw_fifo_have_3d(struct vmw_private *dev_priv);
739 extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv);
740 extern int vmw_fifo_emit_dummy_query(struct vmw_private *dev_priv,
741 				     uint32_t cid);
742 extern int vmw_fifo_flush(struct vmw_private *dev_priv,
743 			  bool interruptible);
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 
757 extern const size_t vmw_tt_size;
758 extern struct ttm_placement vmw_vram_placement;
759 extern struct ttm_placement vmw_vram_ne_placement;
760 extern struct ttm_placement vmw_vram_sys_placement;
761 extern struct ttm_placement vmw_vram_gmr_placement;
762 extern struct ttm_placement vmw_vram_gmr_ne_placement;
763 extern struct ttm_placement vmw_sys_placement;
764 extern struct ttm_placement vmw_sys_ne_placement;
765 extern struct ttm_placement vmw_evictable_placement;
766 extern struct ttm_placement vmw_srf_placement;
767 extern struct ttm_placement vmw_mob_placement;
768 extern struct ttm_placement vmw_mob_ne_placement;
769 extern struct ttm_bo_driver vmw_bo_driver;
770 extern int vmw_dma_quiescent(struct drm_device *dev);
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);
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 }
814 
815 /**
816  * Command submission - vmwgfx_execbuf.c
817  */
818 
819 extern int vmw_execbuf_ioctl(struct drm_device *dev, unsigned long data,
820 			     struct drm_file *file_priv, size_t size);
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,
827 			       uint32_t dx_context_handle,
828 			       struct drm_vmw_fence_rep __user
829 			       *user_fence_rep,
830 			       struct vmw_fence_obj **out_fence,
831 			       uint32_t flags);
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);
835 
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);
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,
846 					uint32_t fence_handle,
847 					int32_t out_fence_fd,
848 					struct sync_file *sync_file);
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);
853 bool vmw_cmd_describe(const void *buf, u32 *size, char const **cmd);
854 
855 /**
856  * IRQs and wating - vmwgfx_irq.c
857  */
858 
859 extern int vmw_wait_seqno(struct vmw_private *dev_priv, bool lazy,
860 			  uint32_t seqno, bool interruptible,
861 			  unsigned long timeout);
862 extern int vmw_irq_install(struct drm_device *dev, int irq);
863 extern void vmw_irq_uninstall(struct drm_device *dev);
864 extern bool vmw_seqno_passed(struct vmw_private *dev_priv,
865 				uint32_t seqno);
866 extern int vmw_fallback_wait(struct vmw_private *dev_priv,
867 			     bool lazy,
868 			     bool fifo_idle,
869 			     uint32_t seqno,
870 			     bool interruptible,
871 			     unsigned long timeout);
872 extern void vmw_update_seqno(struct vmw_private *dev_priv,
873 				struct vmw_fifo_state *fifo_state);
874 extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
875 extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
876 extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
877 extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv);
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);
882 
883 /**
884  * Rudimentary fence-like objects currently used only for throttling -
885  * vmwgfx_marker.c
886  */
887 
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,
891 			   uint32_t seqno);
892 extern int vmw_marker_pull(struct vmw_marker_queue *queue,
893 			   uint32_t signaled_seqno);
894 extern int vmw_wait_lag(struct vmw_private *dev_priv,
895 			struct vmw_marker_queue *queue, uint32_t us);
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);
921 int vmw_kms_write_svga(struct vmw_private *vmw_priv,
922 		       unsigned width, unsigned height, unsigned pitch,
923 		       unsigned bpp, unsigned depth);
924 void vmw_kms_idle_workqueues(struct vmw_master *vmaster);
925 bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
926 				uint32_t pitch,
927 				uint32_t height);
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);
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);
938 int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
939 				struct drm_file *file_priv);
940 void vmw_kms_legacy_hotspot_clear(struct vmw_private *dev_priv);
941 
942 int vmw_dumb_create(struct drm_file *file_priv,
943 		    struct drm_device *dev,
944 		    struct drm_mode_create_dumb *args);
945 
946 int vmw_dumb_map_offset(struct drm_file *file_priv,
947 			struct drm_device *dev, uint32_t handle,
948 			uint64_t *offset);
949 int vmw_dumb_destroy(struct drm_file *file_priv,
950 		     struct drm_device *dev,
951 		     uint32_t handle);
952 extern int vmw_resource_pin(struct vmw_resource *res, bool interruptible);
953 extern void vmw_resource_unpin(struct vmw_resource *res);
954 extern enum vmw_res_type vmw_res_type(const struct vmw_resource *res);
955 
956 /**
957  * Overlay control - vmwgfx_overlay.c
958  */
959 
960 int vmw_overlay_init(struct vmw_private *dev_priv);
961 int vmw_overlay_close(struct vmw_private *dev_priv);
962 int vmw_overlay_ioctl(struct drm_device *dev, void *data,
963 		      struct drm_file *file_priv);
964 int vmw_overlay_stop_all(struct vmw_private *dev_priv);
965 int vmw_overlay_resume_all(struct vmw_private *dev_priv);
966 int vmw_overlay_pause_all(struct vmw_private *dev_priv);
967 int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
968 int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
969 int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
970 int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
971 
972 /**
973  * GMR Id manager
974  */
975 
976 extern const struct ttm_mem_type_manager_func vmw_gmrid_manager_func;
977 
978 /**
979  * Prime - vmwgfx_prime.c
980  */
981 
982 extern const struct dma_buf_ops vmw_prime_dmabuf_ops;
983 extern int vmw_prime_fd_to_handle(struct drm_device *dev,
984 				  struct drm_file *file_priv,
985 				  int fd, u32 *handle);
986 extern int vmw_prime_handle_to_fd(struct drm_device *dev,
987 				  struct drm_file *file_priv,
988 				  uint32_t handle, uint32_t flags,
989 				  int *prime_fd);
990 
991 /*
992  * MemoryOBject management -  vmwgfx_mob.c
993  */
994 struct vmw_mob;
995 extern int vmw_mob_bind(struct vmw_private *dev_priv, struct vmw_mob *mob,
996 			const struct vmw_sg_table *vsgt,
997 			unsigned long num_data_pages, int32_t mob_id);
998 extern void vmw_mob_unbind(struct vmw_private *dev_priv,
999 			   struct vmw_mob *mob);
1000 extern void vmw_mob_destroy(struct vmw_mob *mob);
1001 extern struct vmw_mob *vmw_mob_create(unsigned long data_pages);
1002 extern int vmw_otables_setup(struct vmw_private *dev_priv);
1003 extern void vmw_otables_takedown(struct vmw_private *dev_priv);
1004 
1005 /*
1006  * Context management - vmwgfx_context.c
1007  */
1008 
1009 extern const struct vmw_user_resource_conv *user_context_converter;
1010 
1011 extern int vmw_context_check(struct vmw_private *dev_priv,
1012 			     struct ttm_object_file *tfile,
1013 			     int id,
1014 			     struct vmw_resource **p_res);
1015 extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
1016 				    struct drm_file *file_priv);
1017 extern int vmw_extended_context_define_ioctl(struct drm_device *dev, void *data,
1018 					     struct drm_file *file_priv);
1019 extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
1020 				     struct drm_file *file_priv);
1021 extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
1022 extern struct vmw_cmdbuf_res_manager *
1023 vmw_context_res_man(struct vmw_resource *ctx);
1024 extern struct vmw_resource *vmw_context_cotable(struct vmw_resource *ctx,
1025 						SVGACOTableType cotable_type);
1026 extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
1027 struct vmw_ctx_binding_state;
1028 extern struct vmw_ctx_binding_state *
1029 vmw_context_binding_state(struct vmw_resource *ctx);
1030 extern void vmw_dx_context_scrub_cotables(struct vmw_resource *ctx,
1031 					  bool readback);
1032 extern int vmw_context_bind_dx_query(struct vmw_resource *ctx_res,
1033 				     struct vmw_dma_buffer *mob);
1034 extern struct vmw_dma_buffer *
1035 vmw_context_get_dx_query_mob(struct vmw_resource *ctx_res);
1036 
1037 
1038 /*
1039  * Surface management - vmwgfx_surface.c
1040  */
1041 
1042 extern const struct vmw_user_resource_conv *user_surface_converter;
1043 
1044 extern void vmw_surface_res_free(struct vmw_resource *res);
1045 extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data,
1046 				     struct drm_file *file_priv);
1047 extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
1048 				    struct drm_file *file_priv);
1049 extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,
1050 				       struct drm_file *file_priv);
1051 extern int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data,
1052 				       struct drm_file *file_priv);
1053 extern int vmw_gb_surface_reference_ioctl(struct drm_device *dev, void *data,
1054 					  struct drm_file *file_priv);
1055 extern int vmw_surface_check(struct vmw_private *dev_priv,
1056 			     struct ttm_object_file *tfile,
1057 			     uint32_t handle, int *id);
1058 extern int vmw_surface_validate(struct vmw_private *dev_priv,
1059 				struct vmw_surface *srf);
1060 int vmw_surface_gb_priv_define(struct drm_device *dev,
1061 			       uint32_t user_accounting_size,
1062 			       uint32_t svga3d_flags,
1063 			       SVGA3dSurfaceFormat format,
1064 			       bool for_scanout,
1065 			       uint32_t num_mip_levels,
1066 			       uint32_t multisample_count,
1067 			       uint32_t array_size,
1068 			       struct drm_vmw_size size,
1069 			       struct vmw_surface **srf_out);
1070 
1071 /*
1072  * Shader management - vmwgfx_shader.c
1073  */
1074 
1075 extern const struct vmw_user_resource_conv *user_shader_converter;
1076 
1077 extern int vmw_shader_define_ioctl(struct drm_device *dev, void *data,
1078 				   struct drm_file *file_priv);
1079 extern int vmw_shader_destroy_ioctl(struct drm_device *dev, void *data,
1080 				    struct drm_file *file_priv);
1081 extern int vmw_compat_shader_add(struct vmw_private *dev_priv,
1082 				 struct vmw_cmdbuf_res_manager *man,
1083 				 u32 user_key, const void *bytecode,
1084 				 SVGA3dShaderType shader_type,
1085 				 size_t size,
1086 				 struct list_head *list);
1087 extern int vmw_shader_remove(struct vmw_cmdbuf_res_manager *man,
1088 			     u32 user_key, SVGA3dShaderType shader_type,
1089 			     struct list_head *list);
1090 extern int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,
1091 			     struct vmw_resource *ctx,
1092 			     u32 user_key,
1093 			     SVGA3dShaderType shader_type,
1094 			     struct list_head *list);
1095 extern void vmw_dx_shader_cotable_list_scrub(struct vmw_private *dev_priv,
1096 					     struct list_head *list,
1097 					     bool readback);
1098 
1099 extern struct vmw_resource *
1100 vmw_shader_lookup(struct vmw_cmdbuf_res_manager *man,
1101 		  u32 user_key, SVGA3dShaderType shader_type);
1102 
1103 /*
1104  * Command buffer managed resources - vmwgfx_cmdbuf_res.c
1105  */
1106 
1107 extern struct vmw_cmdbuf_res_manager *
1108 vmw_cmdbuf_res_man_create(struct vmw_private *dev_priv);
1109 extern void vmw_cmdbuf_res_man_destroy(struct vmw_cmdbuf_res_manager *man);
1110 extern size_t vmw_cmdbuf_res_man_size(void);
1111 extern struct vmw_resource *
1112 vmw_cmdbuf_res_lookup(struct vmw_cmdbuf_res_manager *man,
1113 		      enum vmw_cmdbuf_res_type res_type,
1114 		      u32 user_key);
1115 extern void vmw_cmdbuf_res_revert(struct list_head *list);
1116 extern void vmw_cmdbuf_res_commit(struct list_head *list);
1117 extern int vmw_cmdbuf_res_add(struct vmw_cmdbuf_res_manager *man,
1118 			      enum vmw_cmdbuf_res_type res_type,
1119 			      u32 user_key,
1120 			      struct vmw_resource *res,
1121 			      struct list_head *list);
1122 extern int vmw_cmdbuf_res_remove(struct vmw_cmdbuf_res_manager *man,
1123 				 enum vmw_cmdbuf_res_type res_type,
1124 				 u32 user_key,
1125 				 struct list_head *list,
1126 				 struct vmw_resource **res);
1127 
1128 /*
1129  * COTable management - vmwgfx_cotable.c
1130  */
1131 extern const SVGACOTableType vmw_cotable_scrub_order[];
1132 extern struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv,
1133 					      struct vmw_resource *ctx,
1134 					      u32 type);
1135 extern int vmw_cotable_notify(struct vmw_resource *res, int id);
1136 extern int vmw_cotable_scrub(struct vmw_resource *res, bool readback);
1137 extern void vmw_cotable_add_resource(struct vmw_resource *ctx,
1138 				     struct list_head *head);
1139 
1140 /*
1141  * Command buffer managerment vmwgfx_cmdbuf.c
1142  */
1143 struct vmw_cmdbuf_man;
1144 struct vmw_cmdbuf_header;
1145 
1146 extern struct vmw_cmdbuf_man *
1147 vmw_cmdbuf_man_create(struct vmw_private *dev_priv);
1148 extern int vmw_cmdbuf_set_pool_size(struct vmw_cmdbuf_man *man,
1149 				    size_t size, size_t default_size);
1150 extern void vmw_cmdbuf_remove_pool(struct vmw_cmdbuf_man *man);
1151 extern void vmw_cmdbuf_man_destroy(struct vmw_cmdbuf_man *man);
1152 extern int vmw_cmdbuf_idle(struct vmw_cmdbuf_man *man, bool interruptible,
1153 			   unsigned long timeout);
1154 extern void *vmw_cmdbuf_reserve(struct vmw_cmdbuf_man *man, size_t size,
1155 				int ctx_id, bool interruptible,
1156 				struct vmw_cmdbuf_header *header);
1157 extern void vmw_cmdbuf_commit(struct vmw_cmdbuf_man *man, size_t size,
1158 			      struct vmw_cmdbuf_header *header,
1159 			      bool flush);
1160 extern void *vmw_cmdbuf_alloc(struct vmw_cmdbuf_man *man,
1161 			      size_t size, bool interruptible,
1162 			      struct vmw_cmdbuf_header **p_header);
1163 extern void vmw_cmdbuf_header_free(struct vmw_cmdbuf_header *header);
1164 extern int vmw_cmdbuf_cur_flush(struct vmw_cmdbuf_man *man,
1165 				bool interruptible);
1166 extern void vmw_cmdbuf_irqthread(struct vmw_cmdbuf_man *man);
1167 
1168 
1169 /**
1170  * Inline helper functions
1171  */
1172 
1173 static inline void vmw_surface_unreference(struct vmw_surface **srf)
1174 {
1175 	struct vmw_surface *tmp_srf = *srf;
1176 	struct vmw_resource *res = &tmp_srf->res;
1177 	*srf = NULL;
1178 
1179 	vmw_resource_unreference(&res);
1180 }
1181 
1182 static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
1183 {
1184 	(void) vmw_resource_reference(&srf->res);
1185 	return srf;
1186 }
1187 
1188 static inline void vmw_dmabuf_unreference(struct vmw_dma_buffer **buf)
1189 {
1190 	struct vmw_dma_buffer *tmp_buf = *buf;
1191 
1192 	*buf = NULL;
1193 	if (tmp_buf != NULL) {
1194 		struct ttm_buffer_object *bo = &tmp_buf->base;
1195 
1196 		ttm_bo_unref(&bo);
1197 	}
1198 }
1199 
1200 static inline struct vmw_dma_buffer *vmw_dmabuf_reference(struct vmw_dma_buffer *buf)
1201 {
1202 	if (ttm_bo_reference(&buf->base))
1203 		return buf;
1204 	return NULL;
1205 }
1206 
1207 static inline struct ttm_mem_global *vmw_mem_glob(struct vmw_private *dev_priv)
1208 {
1209 	return (struct ttm_mem_global *) dev_priv->mem_global_ref.object;
1210 }
1211 
1212 static inline void vmw_fifo_resource_inc(struct vmw_private *dev_priv)
1213 {
1214 	atomic_inc(&dev_priv->num_fifo_resources);
1215 }
1216 
1217 static inline void vmw_fifo_resource_dec(struct vmw_private *dev_priv)
1218 {
1219 	atomic_dec(&dev_priv->num_fifo_resources);
1220 }
1221 
1222 /**
1223  * vmw_mmio_read - Perform a MMIO read from volatile memory
1224  *
1225  * @addr: The address to read from
1226  *
1227  * This function is intended to be equivalent to ioread32() on
1228  * memremap'd memory, but without byteswapping.
1229  */
1230 static inline u32 vmw_mmio_read(u32 *addr)
1231 {
1232 	return READ_ONCE(*addr);
1233 }
1234 
1235 /**
1236  * vmw_mmio_write - Perform a MMIO write to volatile memory
1237  *
1238  * @addr: The address to write to
1239  *
1240  * This function is intended to be equivalent to iowrite32 on
1241  * memremap'd memory, but without byteswapping.
1242  */
1243 static inline void vmw_mmio_write(u32 value, u32 *addr)
1244 {
1245 	WRITE_ONCE(*addr, value);
1246 }
1247 
1248 /**
1249  * Add vmw_msg module function
1250  */
1251 extern int vmw_host_log(const char *log);
1252 
1253 #endif
1254