1 /**************************************************************************
3 * Copyright © 2009-2015 VMware, Inc., Palo Alto, CA., USA
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #ifndef _VMWGFX_DRV_H_
29 #define _VMWGFX_DRV_H_
31 #include "vmwgfx_reg.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>
45 #define VMWGFX_DRIVER_NAME "vmwgfx"
46 #define VMWGFX_DRIVER_DATE "20180322"
47 #define VMWGFX_DRIVER_MAJOR 2
48 #define VMWGFX_DRIVER_MINOR 14
49 #define VMWGFX_DRIVER_PATCHLEVEL 1
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
59 * Perhaps we should have sysfs entries for these.
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)
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)
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
84 struct drm_master *locked_master;
85 struct ttm_object_file *tfile;
89 struct vmw_dma_buffer {
90 struct ttm_buffer_object base;
91 struct list_head res_list;
93 /* Not ref-counted. Protected by binding_mutex */
94 struct vmw_resource *dx_query_ctx;
95 /* Protected by reservation */
96 struct ttm_bo_kmap_obj map;
100 * struct vmw_validate_buffer - Carries validation info about buffers.
102 * @base: Validation info for TTM.
103 * @hash: Hash entry for quick lookup of the TTM buffer object.
105 * This structure contains also driver private validation info
106 * on top of the info needed by TTM.
108 struct vmw_validate_buffer {
109 struct ttm_validate_buffer base;
110 struct drm_hash_item hash;
111 bool validate_as_mob;
115 struct vmw_resource {
117 struct vmw_private *dev_priv;
120 unsigned long backup_size;
121 bool res_dirty; /* Protected by backup buffer reserved */
122 bool backup_dirty; /* Protected by backup buffer reserved */
123 struct vmw_dma_buffer *backup;
124 unsigned long backup_offset;
125 unsigned long pin_count; /* Protected by resource reserved */
126 const struct vmw_res_func *func;
127 struct list_head lru_head; /* Protected by the resource lock */
128 struct list_head mob_head; /* Protected by @backup reserved */
129 struct list_head binding_head; /* Protected by binding_mutex */
130 void (*res_free) (struct vmw_resource *res);
131 void (*hw_destroy) (struct vmw_resource *res);
136 * Resources that are managed using ioctls.
150 * Resources that are managed using command streams.
152 enum vmw_cmdbuf_res_type {
153 vmw_cmdbuf_res_shader,
157 struct vmw_cmdbuf_res_manager;
159 struct vmw_cursor_snooper {
164 struct vmw_framebuffer;
165 struct vmw_surface_offset;
168 struct vmw_resource res;
171 uint32_t mip_levels[DRM_VMW_MAX_SURFACE_FACES];
172 struct drm_vmw_size base_size;
173 struct drm_vmw_size *sizes;
177 /* TODO so far just a extra pointer */
178 struct vmw_cursor_snooper snooper;
179 struct vmw_surface_offset *offsets;
180 SVGA3dTextureFilter autogen_filter;
181 uint32_t multisample_count;
182 struct list_head view_list;
185 struct vmw_marker_queue {
186 struct list_head head;
192 struct vmw_fifo_state {
193 unsigned long reserved_size;
196 unsigned long static_buffer_size;
197 bool using_bounce_buffer;
198 uint32_t capabilities;
199 struct mutex fifo_mutex;
200 struct rw_semaphore rwsem;
201 struct vmw_marker_queue marker_queue;
205 struct vmw_relocation {
207 SVGAGuestPtr *location;
212 * struct vmw_res_cache_entry - resource information cache entry
214 * @valid: Whether the entry is valid, which also implies that the execbuf
215 * code holds a reference to the resource, and it's placed on the
217 * @handle: User-space handle of a resource.
218 * @res: Non-ref-counted pointer to the resource.
220 * Used to avoid frequent repeated user-space handle lookups of the
223 struct vmw_res_cache_entry {
226 struct vmw_resource *res;
227 struct vmw_resource_val_node *node;
231 * enum vmw_dma_map_mode - indicate how to perform TTM page dma mappings.
233 enum vmw_dma_map_mode {
234 vmw_dma_phys, /* Use physical page addresses */
235 vmw_dma_alloc_coherent, /* Use TTM coherent pages */
236 vmw_dma_map_populate, /* Unmap from DMA just after unpopulate */
237 vmw_dma_map_bind, /* Unmap from DMA just before unbind */
242 * struct vmw_sg_table - Scatter/gather table for binding, with additional
243 * device-specific information.
245 * @sgt: Pointer to a struct sg_table with binding information
246 * @num_regions: Number of regions with device-address contiguous pages
248 struct vmw_sg_table {
249 enum vmw_dma_map_mode mode;
251 const dma_addr_t *addrs;
252 struct sg_table *sgt;
253 unsigned long num_regions;
254 unsigned long num_pages;
258 * struct vmw_piter - Page iterator that iterates over a list of pages
259 * and DMA addresses that could be either a scatter-gather list or
262 * @pages: Array of page pointers to the pages.
263 * @addrs: DMA addresses to the pages if coherent pages are used.
264 * @iter: Scatter-gather page iterator. Current position in SG list.
265 * @i: Current position in arrays.
266 * @num_pages: Number of pages total.
267 * @next: Function to advance the iterator. Returns false if past the list
268 * of pages, true otherwise.
269 * @dma_address: Function to return the DMA address of the current page.
273 const dma_addr_t *addrs;
274 struct sg_page_iter iter;
276 unsigned long num_pages;
277 bool (*next)(struct vmw_piter *);
278 dma_addr_t (*dma_address)(struct vmw_piter *);
279 struct page *(*page)(struct vmw_piter *);
283 * enum vmw_display_unit_type - Describes the display unit
285 enum vmw_display_unit_type {
288 vmw_du_screen_object,
293 struct vmw_sw_context{
294 struct drm_open_hash res_ht;
295 bool res_ht_initialized;
296 bool kernel; /**< is the called made from the kernel */
297 struct vmw_fpriv *fp;
298 struct list_head validate_nodes;
299 struct vmw_relocation relocs[VMWGFX_MAX_RELOCATIONS];
301 struct vmw_validate_buffer val_bufs[VMWGFX_MAX_VALIDATIONS];
302 uint32_t cur_val_buf;
303 uint32_t *cmd_bounce;
304 uint32_t cmd_bounce_size;
305 struct list_head resource_list;
306 struct list_head ctx_resource_list; /* For contexts and cotables */
307 struct vmw_dma_buffer *cur_query_bo;
308 struct list_head res_relocations;
310 struct vmw_res_cache_entry res_cache[vmw_res_max];
311 struct vmw_resource *last_query_ctx;
312 bool needs_post_query_barrier;
313 struct vmw_resource *error_resource;
314 struct vmw_ctx_binding_state *staged_bindings;
315 bool staged_bindings_inuse;
316 struct list_head staged_cmd_res;
317 struct vmw_resource_val_node *dx_ctx_node;
318 struct vmw_dma_buffer *dx_query_mob;
319 struct vmw_resource *dx_query_ctx;
320 struct vmw_cmdbuf_res_manager *man;
323 struct vmw_legacy_display;
327 struct ttm_lock lock;
330 struct vmw_vga_topology_state {
340 * struct vmw_otable - Guest Memory OBject table metadata
342 * @size: Size of the table (page-aligned).
343 * @page_table: Pointer to a struct vmw_mob holding the page table.
347 struct vmw_mob *page_table;
351 struct vmw_otable_batch {
352 unsigned num_otables;
353 struct vmw_otable *otables;
354 struct vmw_resource *context;
355 struct ttm_buffer_object *otable_bo;
360 VMW_IRQTHREAD_CMDBUF,
365 struct ttm_bo_device bdev;
366 struct ttm_bo_global_ref bo_global_ref;
367 struct drm_global_reference mem_global_ref;
369 struct vmw_fifo_state fifo;
371 struct drm_device *dev;
372 unsigned long vmw_chipset;
373 unsigned int io_start;
376 uint32_t prim_bb_mem;
379 uint32_t fb_max_width;
380 uint32_t fb_max_height;
381 uint32_t texture_max_width;
382 uint32_t texture_max_height;
383 uint32_t stdu_max_width;
384 uint32_t stdu_max_height;
385 uint32_t initial_width;
386 uint32_t initial_height;
388 uint32_t capabilities;
389 uint32_t max_gmr_ids;
390 uint32_t max_gmr_pages;
391 uint32_t max_mob_pages;
392 uint32_t max_mob_size;
393 uint32_t memory_size;
405 struct vmw_vga_topology_state vga_save[VMWGFX_MAX_DISPLAYS];
410 uint32_t vga_pitchlock;
412 uint32_t num_displays;
419 enum vmw_display_unit_type active_display_unit;
420 struct vmw_legacy_display *ldu_priv;
421 struct vmw_overlay *overlay_priv;
422 struct drm_property *hotplug_mode_update_property;
423 struct drm_property *implicit_placement_property;
424 unsigned num_implicit;
425 struct vmw_framebuffer *implicit_fb;
426 struct mutex global_kms_state_mutex;
427 spinlock_t cursor_lock;
428 struct drm_atomic_state *suspend_state;
431 * Context and surface management.
434 rwlock_t resource_lock;
435 struct idr res_idr[vmw_res_max];
437 * Block lastclose from racing with firstopen.
440 struct mutex init_mutex;
443 * A resource manager for kernel-only surfaces and
447 struct ttm_object_device *tdev;
454 wait_queue_head_t fence_queue;
455 wait_queue_head_t fifo_queue;
456 spinlock_t waiter_lock;
457 int fence_queue_waiters; /* Protected by waiter_lock */
458 int goal_queue_waiters; /* Protected by waiter_lock */
459 int cmdbuf_waiters; /* Protected by waiter_lock */
460 int error_waiters; /* Protected by waiter_lock */
461 int fifo_queue_waiters; /* Protected by waiter_lock */
462 uint32_t last_read_seqno;
463 struct vmw_fence_manager *fman;
464 uint32_t irq_mask; /* Updates protected by waiter_lock */
470 uint32_t traces_state;
471 uint32_t enable_state;
472 uint32_t config_done_state;
478 * Protected by the cmdbuf mutex.
481 struct vmw_sw_context ctx;
482 struct mutex cmdbuf_mutex;
483 struct mutex binding_mutex;
491 spinlock_t svga_lock;
497 struct vmw_master *active_master;
498 struct vmw_master fbdev_master;
499 struct notifier_block pm_nb;
500 bool refuse_hibernation;
503 struct mutex release_mutex;
504 atomic_t num_fifo_resources;
507 * Replace this with an rwsem as soon as we have down_xx_interruptible()
509 struct ttm_lock reservation_sem;
512 * Query processing. These members
513 * are protected by the cmdbuf mutex.
516 struct vmw_dma_buffer *dummy_query_bo;
517 struct vmw_dma_buffer *pinned_bo;
519 uint32_t query_cid_valid;
520 bool dummy_query_bo_pinned;
523 * Surface swapping. The "surface_lru" list is protected by the
524 * resource lock in order to be able to destroy a surface and take
525 * it off the lru atomically. "used_memory_size" is currently
526 * protected by the cmdbuf mutex for simplicity.
529 struct list_head res_lru[vmw_res_max];
530 uint32_t used_memory_size;
535 enum vmw_dma_map_mode map_mode;
540 struct vmw_otable_batch otable_batch;
542 struct vmw_cmdbuf_man *cman;
543 DECLARE_BITMAP(irqthread_pending, VMW_IRQTHREAD_MAX);
546 static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res)
548 return container_of(res, struct vmw_surface, res);
551 static inline struct vmw_private *vmw_priv(struct drm_device *dev)
553 return (struct vmw_private *)dev->dev_private;
556 static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
558 return (struct vmw_fpriv *)file_priv->driver_priv;
561 static inline struct vmw_master *vmw_master(struct drm_master *master)
563 return (struct vmw_master *) master->driver_priv;
567 * The locking here is fine-grained, so that it is performed once
568 * for every read- and write operation. This is of course costly, but we
569 * don't perform much register access in the timing critical paths anyway.
570 * Instead we have the extra benefit of being sure that we don't forget
571 * the hw lock around register accesses.
573 static inline void vmw_write(struct vmw_private *dev_priv,
574 unsigned int offset, uint32_t value)
576 spin_lock(&dev_priv->hw_lock);
577 outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
578 outl(value, dev_priv->io_start + VMWGFX_VALUE_PORT);
579 spin_unlock(&dev_priv->hw_lock);
582 static inline uint32_t vmw_read(struct vmw_private *dev_priv,
587 spin_lock(&dev_priv->hw_lock);
588 outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
589 val = inl(dev_priv->io_start + VMWGFX_VALUE_PORT);
590 spin_unlock(&dev_priv->hw_lock);
595 extern void vmw_svga_enable(struct vmw_private *dev_priv);
596 extern void vmw_svga_disable(struct vmw_private *dev_priv);
600 * GMR utilities - vmwgfx_gmr.c
603 extern int vmw_gmr_bind(struct vmw_private *dev_priv,
604 const struct vmw_sg_table *vsgt,
605 unsigned long num_pages,
607 extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
610 * Resource utilities - vmwgfx_resource.c
612 struct vmw_user_resource_conv;
614 extern void vmw_resource_unreference(struct vmw_resource **p_res);
615 extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
616 extern struct vmw_resource *
617 vmw_resource_reference_unless_doomed(struct vmw_resource *res);
618 extern int vmw_resource_validate(struct vmw_resource *res);
619 extern int vmw_resource_reserve(struct vmw_resource *res, bool interruptible,
621 extern bool vmw_resource_needs_backup(const struct vmw_resource *res);
622 extern int vmw_user_lookup_handle(struct vmw_private *dev_priv,
623 struct ttm_object_file *tfile,
625 struct vmw_surface **out_surf,
626 struct vmw_dma_buffer **out_buf);
627 extern int vmw_user_resource_lookup_handle(
628 struct vmw_private *dev_priv,
629 struct ttm_object_file *tfile,
631 const struct vmw_user_resource_conv *converter,
632 struct vmw_resource **p_res);
633 extern void vmw_dmabuf_bo_free(struct ttm_buffer_object *bo);
634 extern int vmw_dmabuf_init(struct vmw_private *dev_priv,
635 struct vmw_dma_buffer *vmw_bo,
636 size_t size, struct ttm_placement *placement,
638 void (*bo_free) (struct ttm_buffer_object *bo));
639 extern int vmw_user_dmabuf_verify_access(struct ttm_buffer_object *bo,
640 struct ttm_object_file *tfile);
641 extern int vmw_user_dmabuf_alloc(struct vmw_private *dev_priv,
642 struct ttm_object_file *tfile,
646 struct vmw_dma_buffer **p_dma_buf,
647 struct ttm_base_object **p_base);
648 extern int vmw_user_dmabuf_reference(struct ttm_object_file *tfile,
649 struct vmw_dma_buffer *dma_buf,
651 extern int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data,
652 struct drm_file *file_priv);
653 extern int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data,
654 struct drm_file *file_priv);
655 extern int vmw_user_dmabuf_synccpu_ioctl(struct drm_device *dev, void *data,
656 struct drm_file *file_priv);
657 extern uint32_t vmw_dmabuf_validate_node(struct ttm_buffer_object *bo,
658 uint32_t cur_validate_node);
659 extern void vmw_dmabuf_validate_clear(struct ttm_buffer_object *bo);
660 extern int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile,
661 uint32_t id, struct vmw_dma_buffer **out,
662 struct ttm_base_object **base);
663 extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
664 struct drm_file *file_priv);
665 extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
666 struct drm_file *file_priv);
667 extern int vmw_user_stream_lookup(struct vmw_private *dev_priv,
668 struct ttm_object_file *tfile,
670 struct vmw_resource **out);
671 extern void vmw_resource_unreserve(struct vmw_resource *res,
673 struct vmw_dma_buffer *new_backup,
674 unsigned long new_backup_offset);
675 extern void vmw_resource_move_notify(struct ttm_buffer_object *bo,
676 struct ttm_mem_reg *mem);
677 extern void vmw_query_move_notify(struct ttm_buffer_object *bo,
678 struct ttm_mem_reg *mem);
679 extern void vmw_resource_swap_notify(struct ttm_buffer_object *bo);
680 extern int vmw_query_readback_all(struct vmw_dma_buffer *dx_query_mob);
681 extern void vmw_fence_single_bo(struct ttm_buffer_object *bo,
682 struct vmw_fence_obj *fence);
683 extern void vmw_resource_evict_all(struct vmw_private *dev_priv);
687 * DMA buffer helper routines - vmwgfx_dmabuf.c
689 extern int vmw_dmabuf_pin_in_placement(struct vmw_private *vmw_priv,
690 struct vmw_dma_buffer *bo,
691 struct ttm_placement *placement,
693 extern int vmw_dmabuf_pin_in_vram(struct vmw_private *dev_priv,
694 struct vmw_dma_buffer *buf,
696 extern int vmw_dmabuf_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
697 struct vmw_dma_buffer *buf,
699 extern int vmw_dmabuf_pin_in_start_of_vram(struct vmw_private *vmw_priv,
700 struct vmw_dma_buffer *bo,
702 extern int vmw_dmabuf_unpin(struct vmw_private *vmw_priv,
703 struct vmw_dma_buffer *bo,
705 extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf,
707 extern void vmw_bo_pin_reserved(struct vmw_dma_buffer *bo, bool pin);
708 extern void *vmw_dma_buffer_map_and_cache(struct vmw_dma_buffer *vbo);
709 extern void vmw_dma_buffer_unmap(struct vmw_dma_buffer *vbo);
712 * Misc Ioctl functionality - vmwgfx_ioctl.c
715 extern int vmw_getparam_ioctl(struct drm_device *dev, void *data,
716 struct drm_file *file_priv);
717 extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
718 struct drm_file *file_priv);
719 extern int vmw_present_ioctl(struct drm_device *dev, void *data,
720 struct drm_file *file_priv);
721 extern int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
722 struct drm_file *file_priv);
723 extern __poll_t vmw_fops_poll(struct file *filp,
724 struct poll_table_struct *wait);
725 extern ssize_t vmw_fops_read(struct file *filp, char __user *buffer,
726 size_t count, loff_t *offset);
729 * Fifo utilities - vmwgfx_fifo.c
732 extern int vmw_fifo_init(struct vmw_private *dev_priv,
733 struct vmw_fifo_state *fifo);
734 extern void vmw_fifo_release(struct vmw_private *dev_priv,
735 struct vmw_fifo_state *fifo);
736 extern void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes);
738 vmw_fifo_reserve_dx(struct vmw_private *dev_priv, uint32_t bytes, int ctx_id);
739 extern void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes);
740 extern void vmw_fifo_commit_flush(struct vmw_private *dev_priv, uint32_t bytes);
741 extern int vmw_fifo_send_fence(struct vmw_private *dev_priv,
743 extern void vmw_fifo_ping_host_locked(struct vmw_private *, uint32_t reason);
744 extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
745 extern bool vmw_fifo_have_3d(struct vmw_private *dev_priv);
746 extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv);
747 extern int vmw_fifo_emit_dummy_query(struct vmw_private *dev_priv,
749 extern int vmw_fifo_flush(struct vmw_private *dev_priv,
753 * TTM glue - vmwgfx_ttm_glue.c
756 extern int vmw_ttm_global_init(struct vmw_private *dev_priv);
757 extern void vmw_ttm_global_release(struct vmw_private *dev_priv);
758 extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma);
761 * TTM buffer object driver - vmwgfx_buffer.c
764 extern const size_t vmw_tt_size;
765 extern struct ttm_placement vmw_vram_placement;
766 extern struct ttm_placement vmw_vram_ne_placement;
767 extern struct ttm_placement vmw_vram_sys_placement;
768 extern struct ttm_placement vmw_vram_gmr_placement;
769 extern struct ttm_placement vmw_vram_gmr_ne_placement;
770 extern struct ttm_placement vmw_sys_placement;
771 extern struct ttm_placement vmw_sys_ne_placement;
772 extern struct ttm_placement vmw_evictable_placement;
773 extern struct ttm_placement vmw_srf_placement;
774 extern struct ttm_placement vmw_mob_placement;
775 extern struct ttm_placement vmw_mob_ne_placement;
776 extern struct ttm_placement vmw_nonfixed_placement;
777 extern struct ttm_bo_driver vmw_bo_driver;
778 extern int vmw_dma_quiescent(struct drm_device *dev);
779 extern int vmw_bo_map_dma(struct ttm_buffer_object *bo);
780 extern void vmw_bo_unmap_dma(struct ttm_buffer_object *bo);
781 extern const struct vmw_sg_table *
782 vmw_bo_sg_table(struct ttm_buffer_object *bo);
783 extern void vmw_piter_start(struct vmw_piter *viter,
784 const struct vmw_sg_table *vsgt,
785 unsigned long p_offs);
788 * vmw_piter_next - Advance the iterator one page.
790 * @viter: Pointer to the iterator to advance.
792 * Returns false if past the list of pages, true otherwise.
794 static inline bool vmw_piter_next(struct vmw_piter *viter)
796 return viter->next(viter);
800 * vmw_piter_dma_addr - Return the DMA address of the current page.
802 * @viter: Pointer to the iterator
804 * Returns the DMA address of the page pointed to by @viter.
806 static inline dma_addr_t vmw_piter_dma_addr(struct vmw_piter *viter)
808 return viter->dma_address(viter);
812 * vmw_piter_page - Return a pointer to the current page.
814 * @viter: Pointer to the iterator
816 * Returns the DMA address of the page pointed to by @viter.
818 static inline struct page *vmw_piter_page(struct vmw_piter *viter)
820 return viter->page(viter);
824 * Command submission - vmwgfx_execbuf.c
827 extern int vmw_execbuf_ioctl(struct drm_device *dev, unsigned long data,
828 struct drm_file *file_priv, size_t size);
829 extern int vmw_execbuf_process(struct drm_file *file_priv,
830 struct vmw_private *dev_priv,
831 void __user *user_commands,
832 void *kernel_commands,
833 uint32_t command_size,
834 uint64_t throttle_us,
835 uint32_t dx_context_handle,
836 struct drm_vmw_fence_rep __user
838 struct vmw_fence_obj **out_fence,
840 extern void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv,
841 struct vmw_fence_obj *fence);
842 extern void vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv);
844 extern int vmw_execbuf_fence_commands(struct drm_file *file_priv,
845 struct vmw_private *dev_priv,
846 struct vmw_fence_obj **p_fence,
848 extern void vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
849 struct vmw_fpriv *vmw_fp,
851 struct drm_vmw_fence_rep __user
853 struct vmw_fence_obj *fence,
854 uint32_t fence_handle,
855 int32_t out_fence_fd,
856 struct sync_file *sync_file);
857 extern int vmw_validate_single_buffer(struct vmw_private *dev_priv,
858 struct ttm_buffer_object *bo,
860 bool validate_as_mob);
861 bool vmw_cmd_describe(const void *buf, u32 *size, char const **cmd);
864 * IRQs and wating - vmwgfx_irq.c
867 extern int vmw_wait_seqno(struct vmw_private *dev_priv, bool lazy,
868 uint32_t seqno, bool interruptible,
869 unsigned long timeout);
870 extern int vmw_irq_install(struct drm_device *dev, int irq);
871 extern void vmw_irq_uninstall(struct drm_device *dev);
872 extern bool vmw_seqno_passed(struct vmw_private *dev_priv,
874 extern int vmw_fallback_wait(struct vmw_private *dev_priv,
879 unsigned long timeout);
880 extern void vmw_update_seqno(struct vmw_private *dev_priv,
881 struct vmw_fifo_state *fifo_state);
882 extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
883 extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
884 extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
885 extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv);
886 extern void vmw_generic_waiter_add(struct vmw_private *dev_priv, u32 flag,
888 extern void vmw_generic_waiter_remove(struct vmw_private *dev_priv,
889 u32 flag, int *waiter_count);
892 * Rudimentary fence-like objects currently used only for throttling -
896 extern void vmw_marker_queue_init(struct vmw_marker_queue *queue);
897 extern void vmw_marker_queue_takedown(struct vmw_marker_queue *queue);
898 extern int vmw_marker_push(struct vmw_marker_queue *queue,
900 extern int vmw_marker_pull(struct vmw_marker_queue *queue,
901 uint32_t signaled_seqno);
902 extern int vmw_wait_lag(struct vmw_private *dev_priv,
903 struct vmw_marker_queue *queue, uint32_t us);
906 * Kernel framebuffer - vmwgfx_fb.c
909 int vmw_fb_init(struct vmw_private *vmw_priv);
910 int vmw_fb_close(struct vmw_private *dev_priv);
911 int vmw_fb_off(struct vmw_private *vmw_priv);
912 int vmw_fb_on(struct vmw_private *vmw_priv);
915 * Kernel modesetting - vmwgfx_kms.c
918 int vmw_kms_init(struct vmw_private *dev_priv);
919 int vmw_kms_close(struct vmw_private *dev_priv);
920 int vmw_kms_save_vga(struct vmw_private *vmw_priv);
921 int vmw_kms_restore_vga(struct vmw_private *vmw_priv);
922 int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
923 struct drm_file *file_priv);
924 void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
925 void vmw_kms_cursor_snoop(struct vmw_surface *srf,
926 struct ttm_object_file *tfile,
927 struct ttm_buffer_object *bo,
928 SVGA3dCmdHeader *header);
929 int vmw_kms_write_svga(struct vmw_private *vmw_priv,
930 unsigned width, unsigned height, unsigned pitch,
931 unsigned bpp, unsigned depth);
932 void vmw_kms_idle_workqueues(struct vmw_master *vmaster);
933 bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
936 u32 vmw_get_vblank_counter(struct drm_device *dev, unsigned int pipe);
937 int vmw_enable_vblank(struct drm_device *dev, unsigned int pipe);
938 void vmw_disable_vblank(struct drm_device *dev, unsigned int pipe);
939 int vmw_kms_present(struct vmw_private *dev_priv,
940 struct drm_file *file_priv,
941 struct vmw_framebuffer *vfb,
942 struct vmw_surface *surface,
943 uint32_t sid, int32_t destX, int32_t destY,
944 struct drm_vmw_rect *clips,
946 int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
947 struct drm_file *file_priv);
948 void vmw_kms_legacy_hotspot_clear(struct vmw_private *dev_priv);
949 int vmw_kms_suspend(struct drm_device *dev);
950 int vmw_kms_resume(struct drm_device *dev);
951 void vmw_kms_lost_device(struct drm_device *dev);
953 int vmw_dumb_create(struct drm_file *file_priv,
954 struct drm_device *dev,
955 struct drm_mode_create_dumb *args);
957 int vmw_dumb_map_offset(struct drm_file *file_priv,
958 struct drm_device *dev, uint32_t handle,
960 int vmw_dumb_destroy(struct drm_file *file_priv,
961 struct drm_device *dev,
963 extern int vmw_resource_pin(struct vmw_resource *res, bool interruptible);
964 extern void vmw_resource_unpin(struct vmw_resource *res);
965 extern enum vmw_res_type vmw_res_type(const struct vmw_resource *res);
968 * Overlay control - vmwgfx_overlay.c
971 int vmw_overlay_init(struct vmw_private *dev_priv);
972 int vmw_overlay_close(struct vmw_private *dev_priv);
973 int vmw_overlay_ioctl(struct drm_device *dev, void *data,
974 struct drm_file *file_priv);
975 int vmw_overlay_stop_all(struct vmw_private *dev_priv);
976 int vmw_overlay_resume_all(struct vmw_private *dev_priv);
977 int vmw_overlay_pause_all(struct vmw_private *dev_priv);
978 int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
979 int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
980 int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
981 int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
987 extern const struct ttm_mem_type_manager_func vmw_gmrid_manager_func;
990 * Prime - vmwgfx_prime.c
993 extern const struct dma_buf_ops vmw_prime_dmabuf_ops;
994 extern int vmw_prime_fd_to_handle(struct drm_device *dev,
995 struct drm_file *file_priv,
996 int fd, u32 *handle);
997 extern int vmw_prime_handle_to_fd(struct drm_device *dev,
998 struct drm_file *file_priv,
999 uint32_t handle, uint32_t flags,
1003 * MemoryOBject management - vmwgfx_mob.c
1006 extern int vmw_mob_bind(struct vmw_private *dev_priv, struct vmw_mob *mob,
1007 const struct vmw_sg_table *vsgt,
1008 unsigned long num_data_pages, int32_t mob_id);
1009 extern void vmw_mob_unbind(struct vmw_private *dev_priv,
1010 struct vmw_mob *mob);
1011 extern void vmw_mob_destroy(struct vmw_mob *mob);
1012 extern struct vmw_mob *vmw_mob_create(unsigned long data_pages);
1013 extern int vmw_otables_setup(struct vmw_private *dev_priv);
1014 extern void vmw_otables_takedown(struct vmw_private *dev_priv);
1017 * Context management - vmwgfx_context.c
1020 extern const struct vmw_user_resource_conv *user_context_converter;
1022 extern int vmw_context_check(struct vmw_private *dev_priv,
1023 struct ttm_object_file *tfile,
1025 struct vmw_resource **p_res);
1026 extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
1027 struct drm_file *file_priv);
1028 extern int vmw_extended_context_define_ioctl(struct drm_device *dev, void *data,
1029 struct drm_file *file_priv);
1030 extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
1031 struct drm_file *file_priv);
1032 extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
1033 extern struct vmw_cmdbuf_res_manager *
1034 vmw_context_res_man(struct vmw_resource *ctx);
1035 extern struct vmw_resource *vmw_context_cotable(struct vmw_resource *ctx,
1036 SVGACOTableType cotable_type);
1037 extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
1038 struct vmw_ctx_binding_state;
1039 extern struct vmw_ctx_binding_state *
1040 vmw_context_binding_state(struct vmw_resource *ctx);
1041 extern void vmw_dx_context_scrub_cotables(struct vmw_resource *ctx,
1043 extern int vmw_context_bind_dx_query(struct vmw_resource *ctx_res,
1044 struct vmw_dma_buffer *mob);
1045 extern struct vmw_dma_buffer *
1046 vmw_context_get_dx_query_mob(struct vmw_resource *ctx_res);
1050 * Surface management - vmwgfx_surface.c
1053 extern const struct vmw_user_resource_conv *user_surface_converter;
1055 extern void vmw_surface_res_free(struct vmw_resource *res);
1056 extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data,
1057 struct drm_file *file_priv);
1058 extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
1059 struct drm_file *file_priv);
1060 extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,
1061 struct drm_file *file_priv);
1062 extern int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data,
1063 struct drm_file *file_priv);
1064 extern int vmw_gb_surface_reference_ioctl(struct drm_device *dev, void *data,
1065 struct drm_file *file_priv);
1066 extern int vmw_surface_check(struct vmw_private *dev_priv,
1067 struct ttm_object_file *tfile,
1068 uint32_t handle, int *id);
1069 extern int vmw_surface_validate(struct vmw_private *dev_priv,
1070 struct vmw_surface *srf);
1071 int vmw_surface_gb_priv_define(struct drm_device *dev,
1072 uint32_t user_accounting_size,
1073 uint32_t svga3d_flags,
1074 SVGA3dSurfaceFormat format,
1076 uint32_t num_mip_levels,
1077 uint32_t multisample_count,
1078 uint32_t array_size,
1079 struct drm_vmw_size size,
1080 struct vmw_surface **srf_out);
1083 * Shader management - vmwgfx_shader.c
1086 extern const struct vmw_user_resource_conv *user_shader_converter;
1088 extern int vmw_shader_define_ioctl(struct drm_device *dev, void *data,
1089 struct drm_file *file_priv);
1090 extern int vmw_shader_destroy_ioctl(struct drm_device *dev, void *data,
1091 struct drm_file *file_priv);
1092 extern int vmw_compat_shader_add(struct vmw_private *dev_priv,
1093 struct vmw_cmdbuf_res_manager *man,
1094 u32 user_key, const void *bytecode,
1095 SVGA3dShaderType shader_type,
1097 struct list_head *list);
1098 extern int vmw_shader_remove(struct vmw_cmdbuf_res_manager *man,
1099 u32 user_key, SVGA3dShaderType shader_type,
1100 struct list_head *list);
1101 extern int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,
1102 struct vmw_resource *ctx,
1104 SVGA3dShaderType shader_type,
1105 struct list_head *list);
1106 extern void vmw_dx_shader_cotable_list_scrub(struct vmw_private *dev_priv,
1107 struct list_head *list,
1110 extern struct vmw_resource *
1111 vmw_shader_lookup(struct vmw_cmdbuf_res_manager *man,
1112 u32 user_key, SVGA3dShaderType shader_type);
1115 * Command buffer managed resources - vmwgfx_cmdbuf_res.c
1118 extern struct vmw_cmdbuf_res_manager *
1119 vmw_cmdbuf_res_man_create(struct vmw_private *dev_priv);
1120 extern void vmw_cmdbuf_res_man_destroy(struct vmw_cmdbuf_res_manager *man);
1121 extern size_t vmw_cmdbuf_res_man_size(void);
1122 extern struct vmw_resource *
1123 vmw_cmdbuf_res_lookup(struct vmw_cmdbuf_res_manager *man,
1124 enum vmw_cmdbuf_res_type res_type,
1126 extern void vmw_cmdbuf_res_revert(struct list_head *list);
1127 extern void vmw_cmdbuf_res_commit(struct list_head *list);
1128 extern int vmw_cmdbuf_res_add(struct vmw_cmdbuf_res_manager *man,
1129 enum vmw_cmdbuf_res_type res_type,
1131 struct vmw_resource *res,
1132 struct list_head *list);
1133 extern int vmw_cmdbuf_res_remove(struct vmw_cmdbuf_res_manager *man,
1134 enum vmw_cmdbuf_res_type res_type,
1136 struct list_head *list,
1137 struct vmw_resource **res);
1140 * COTable management - vmwgfx_cotable.c
1142 extern const SVGACOTableType vmw_cotable_scrub_order[];
1143 extern struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv,
1144 struct vmw_resource *ctx,
1146 extern int vmw_cotable_notify(struct vmw_resource *res, int id);
1147 extern int vmw_cotable_scrub(struct vmw_resource *res, bool readback);
1148 extern void vmw_cotable_add_resource(struct vmw_resource *ctx,
1149 struct list_head *head);
1152 * Command buffer managerment vmwgfx_cmdbuf.c
1154 struct vmw_cmdbuf_man;
1155 struct vmw_cmdbuf_header;
1157 extern struct vmw_cmdbuf_man *
1158 vmw_cmdbuf_man_create(struct vmw_private *dev_priv);
1159 extern int vmw_cmdbuf_set_pool_size(struct vmw_cmdbuf_man *man,
1160 size_t size, size_t default_size);
1161 extern void vmw_cmdbuf_remove_pool(struct vmw_cmdbuf_man *man);
1162 extern void vmw_cmdbuf_man_destroy(struct vmw_cmdbuf_man *man);
1163 extern int vmw_cmdbuf_idle(struct vmw_cmdbuf_man *man, bool interruptible,
1164 unsigned long timeout);
1165 extern void *vmw_cmdbuf_reserve(struct vmw_cmdbuf_man *man, size_t size,
1166 int ctx_id, bool interruptible,
1167 struct vmw_cmdbuf_header *header);
1168 extern void vmw_cmdbuf_commit(struct vmw_cmdbuf_man *man, size_t size,
1169 struct vmw_cmdbuf_header *header,
1171 extern void *vmw_cmdbuf_alloc(struct vmw_cmdbuf_man *man,
1172 size_t size, bool interruptible,
1173 struct vmw_cmdbuf_header **p_header);
1174 extern void vmw_cmdbuf_header_free(struct vmw_cmdbuf_header *header);
1175 extern int vmw_cmdbuf_cur_flush(struct vmw_cmdbuf_man *man,
1176 bool interruptible);
1177 extern void vmw_cmdbuf_irqthread(struct vmw_cmdbuf_man *man);
1179 /* CPU blit utilities - vmwgfx_blit.c */
1182 * struct vmw_diff_cpy - CPU blit information structure
1184 * @rect: The output bounding box rectangle.
1185 * @line: The current line of the blit.
1186 * @line_offset: Offset of the current line segment.
1187 * @cpp: Bytes per pixel (granularity information).
1188 * @memcpy: Which memcpy function to use.
1190 struct vmw_diff_cpy {
1191 struct drm_rect rect;
1195 void (*do_cpy)(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src,
1199 #define VMW_CPU_BLIT_INITIALIZER { \
1200 .do_cpy = vmw_memcpy, \
1203 #define VMW_CPU_BLIT_DIFF_INITIALIZER(_cpp) { \
1206 .rect = { .x1 = INT_MAX/2, \
1212 .do_cpy = vmw_diff_memcpy, \
1215 void vmw_diff_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src,
1218 void vmw_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src, size_t n);
1220 int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
1221 u32 dst_offset, u32 dst_stride,
1222 struct ttm_buffer_object *src,
1223 u32 src_offset, u32 src_stride,
1225 struct vmw_diff_cpy *diff);
1228 * Inline helper functions
1231 static inline void vmw_surface_unreference(struct vmw_surface **srf)
1233 struct vmw_surface *tmp_srf = *srf;
1234 struct vmw_resource *res = &tmp_srf->res;
1237 vmw_resource_unreference(&res);
1240 static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
1242 (void) vmw_resource_reference(&srf->res);
1246 static inline void vmw_dmabuf_unreference(struct vmw_dma_buffer **buf)
1248 struct vmw_dma_buffer *tmp_buf = *buf;
1251 if (tmp_buf != NULL) {
1252 struct ttm_buffer_object *bo = &tmp_buf->base;
1258 static inline struct vmw_dma_buffer *vmw_dmabuf_reference(struct vmw_dma_buffer *buf)
1260 if (ttm_bo_reference(&buf->base))
1265 static inline struct ttm_mem_global *vmw_mem_glob(struct vmw_private *dev_priv)
1267 return (struct ttm_mem_global *) dev_priv->mem_global_ref.object;
1270 static inline void vmw_fifo_resource_inc(struct vmw_private *dev_priv)
1272 atomic_inc(&dev_priv->num_fifo_resources);
1275 static inline void vmw_fifo_resource_dec(struct vmw_private *dev_priv)
1277 atomic_dec(&dev_priv->num_fifo_resources);
1281 * vmw_mmio_read - Perform a MMIO read from volatile memory
1283 * @addr: The address to read from
1285 * This function is intended to be equivalent to ioread32() on
1286 * memremap'd memory, but without byteswapping.
1288 static inline u32 vmw_mmio_read(u32 *addr)
1290 return READ_ONCE(*addr);
1294 * vmw_mmio_write - Perform a MMIO write to volatile memory
1296 * @addr: The address to write to
1298 * This function is intended to be equivalent to iowrite32 on
1299 * memremap'd memory, but without byteswapping.
1301 static inline void vmw_mmio_write(u32 value, u32 *addr)
1303 WRITE_ONCE(*addr, value);
1307 * Add vmw_msg module function
1309 extern int vmw_host_log(const char *log);