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 "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
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
;
98 * struct vmw_validate_buffer - Carries validation info about buffers.
100 * @base: Validation info for TTM.
101 * @hash: Hash entry for quick lookup of the TTM buffer object.
103 * This structure contains also driver private validation info
104 * on top of the info needed by TTM.
106 struct vmw_validate_buffer
{
107 struct ttm_validate_buffer base
;
108 struct drm_hash_item hash
;
109 bool validate_as_mob
;
113 struct vmw_resource
{
115 struct vmw_private
*dev_priv
;
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
);
134 * Resources that are managed using ioctls.
148 * Resources that are managed using command streams.
150 enum vmw_cmdbuf_res_type
{
151 vmw_cmdbuf_res_shader
,
155 struct vmw_cmdbuf_res_manager
;
157 struct vmw_cursor_snooper
{
162 struct vmw_framebuffer
;
163 struct vmw_surface_offset
;
166 struct vmw_resource res
;
169 uint32_t mip_levels
[DRM_VMW_MAX_SURFACE_FACES
];
170 struct drm_vmw_size base_size
;
171 struct drm_vmw_size
*sizes
;
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
;
183 struct vmw_marker_queue
{
184 struct list_head head
;
190 struct vmw_fifo_state
{
191 unsigned long reserved_size
;
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
;
203 struct vmw_relocation
{
205 SVGAGuestPtr
*location
;
210 * struct vmw_res_cache_entry - resource information cache entry
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
215 * @handle: User-space handle of a resource.
216 * @res: Non-ref-counted pointer to the resource.
218 * Used to avoid frequent repeated user-space handle lookups of the
221 struct vmw_res_cache_entry
{
224 struct vmw_resource
*res
;
225 struct vmw_resource_val_node
*node
;
229 * enum vmw_dma_map_mode - indicate how to perform TTM page dma mappings.
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 */
240 * struct vmw_sg_table - Scatter/gather table for binding, with additional
241 * device-specific information.
243 * @sgt: Pointer to a struct sg_table with binding information
244 * @num_regions: Number of regions with device-address contiguous pages
246 struct vmw_sg_table
{
247 enum vmw_dma_map_mode mode
;
249 const dma_addr_t
*addrs
;
250 struct sg_table
*sgt
;
251 unsigned long num_regions
;
252 unsigned long num_pages
;
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
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.
271 const dma_addr_t
*addrs
;
272 struct sg_page_iter iter
;
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
*);
281 * enum vmw_display_unit_type - Describes the display unit
283 enum vmw_display_unit_type
{
286 vmw_du_screen_object
,
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
];
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
;
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
;
321 struct vmw_legacy_display
;
325 struct ttm_lock lock
;
328 struct vmw_vga_topology_state
{
338 * struct vmw_otable - Guest Memory OBject table metadata
340 * @size: Size of the table (page-aligned).
341 * @page_table: Pointer to a struct vmw_mob holding the page table.
345 struct vmw_mob
*page_table
;
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
;
358 VMW_IRQTHREAD_CMDBUF
,
363 struct ttm_bo_device bdev
;
364 struct ttm_bo_global_ref bo_global_ref
;
365 struct drm_global_reference mem_global_ref
;
367 struct vmw_fifo_state fifo
;
369 struct drm_device
*dev
;
370 unsigned long vmw_chipset
;
371 unsigned int io_start
;
374 uint32_t prim_bb_mem
;
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
;
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
;
403 struct vmw_vga_topology_state vga_save
[VMWGFX_MAX_DISPLAYS
];
408 uint32_t vga_pitchlock
;
410 uint32_t num_displays
;
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
;
428 * Context and surface management.
431 rwlock_t resource_lock
;
432 struct idr res_idr
[vmw_res_max
];
434 * Block lastclose from racing with firstopen.
437 struct mutex init_mutex
;
440 * A resource manager for kernel-only surfaces and
444 struct ttm_object_device
*tdev
;
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 */
467 uint32_t traces_state
;
468 uint32_t enable_state
;
469 uint32_t config_done_state
;
475 * Protected by the cmdbuf mutex.
478 struct vmw_sw_context ctx
;
479 struct mutex cmdbuf_mutex
;
480 struct mutex binding_mutex
;
488 spinlock_t svga_lock
;
494 struct vmw_master
*active_master
;
495 struct vmw_master fbdev_master
;
496 struct notifier_block pm_nb
;
498 bool refuse_hibernation
;
500 struct mutex release_mutex
;
501 atomic_t num_fifo_resources
;
504 * Replace this with an rwsem as soon as we have down_xx_interruptible()
506 struct ttm_lock reservation_sem
;
509 * Query processing. These members
510 * are protected by the cmdbuf mutex.
513 struct vmw_dma_buffer
*dummy_query_bo
;
514 struct vmw_dma_buffer
*pinned_bo
;
516 uint32_t query_cid_valid
;
517 bool dummy_query_bo_pinned
;
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.
526 struct list_head res_lru
[vmw_res_max
];
527 uint32_t used_memory_size
;
532 enum vmw_dma_map_mode map_mode
;
537 struct vmw_otable_batch otable_batch
;
539 struct vmw_cmdbuf_man
*cman
;
540 DECLARE_BITMAP(irqthread_pending
, VMW_IRQTHREAD_MAX
);
543 static inline struct vmw_surface
*vmw_res_to_srf(struct vmw_resource
*res
)
545 return container_of(res
, struct vmw_surface
, res
);
548 static inline struct vmw_private
*vmw_priv(struct drm_device
*dev
)
550 return (struct vmw_private
*)dev
->dev_private
;
553 static inline struct vmw_fpriv
*vmw_fpriv(struct drm_file
*file_priv
)
555 return (struct vmw_fpriv
*)file_priv
->driver_priv
;
558 static inline struct vmw_master
*vmw_master(struct drm_master
*master
)
560 return (struct vmw_master
*) master
->driver_priv
;
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.
570 static inline void vmw_write(struct vmw_private
*dev_priv
,
571 unsigned int offset
, uint32_t value
)
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
);
579 static inline uint32_t vmw_read(struct vmw_private
*dev_priv
,
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
);
592 extern void vmw_svga_enable(struct vmw_private
*dev_priv
);
593 extern void vmw_svga_disable(struct vmw_private
*dev_priv
);
597 * GMR utilities - vmwgfx_gmr.c
600 extern int vmw_gmr_bind(struct vmw_private
*dev_priv
,
601 const struct vmw_sg_table
*vsgt
,
602 unsigned long num_pages
,
604 extern void vmw_gmr_unbind(struct vmw_private
*dev_priv
, int gmr_id
);
607 * Resource utilities - vmwgfx_resource.c
609 struct vmw_user_resource_conv
;
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
,
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
,
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
,
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
,
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
,
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
,
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
,
667 struct vmw_resource
**out
);
668 extern void vmw_resource_unreserve(struct vmw_resource
*res
,
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
);
682 * DMA buffer helper routines - vmwgfx_dmabuf.c
684 extern int vmw_dmabuf_pin_in_placement(struct vmw_private
*vmw_priv
,
685 struct vmw_dma_buffer
*bo
,
686 struct ttm_placement
*placement
,
688 extern int vmw_dmabuf_pin_in_vram(struct vmw_private
*dev_priv
,
689 struct vmw_dma_buffer
*buf
,
691 extern int vmw_dmabuf_pin_in_vram_or_gmr(struct vmw_private
*dev_priv
,
692 struct vmw_dma_buffer
*buf
,
694 extern int vmw_dmabuf_pin_in_start_of_vram(struct vmw_private
*vmw_priv
,
695 struct vmw_dma_buffer
*bo
,
697 extern int vmw_dmabuf_unpin(struct vmw_private
*vmw_priv
,
698 struct vmw_dma_buffer
*bo
,
700 extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object
*buf
,
702 extern void vmw_bo_pin_reserved(struct vmw_dma_buffer
*bo
, bool pin
);
705 * Misc Ioctl functionality - vmwgfx_ioctl.c
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
);
722 * Fifo utilities - vmwgfx_fifo.c
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
);
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
,
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
,
742 extern int vmw_fifo_flush(struct vmw_private
*dev_priv
,
746 * TTM glue - vmwgfx_ttm_glue.c
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
);
754 * TTM buffer object driver - vmwgfx_buffer.c
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
);
780 * vmw_piter_next - Advance the iterator one page.
782 * @viter: Pointer to the iterator to advance.
784 * Returns false if past the list of pages, true otherwise.
786 static inline bool vmw_piter_next(struct vmw_piter
*viter
)
788 return viter
->next(viter
);
792 * vmw_piter_dma_addr - Return the DMA address of the current page.
794 * @viter: Pointer to the iterator
796 * Returns the DMA address of the page pointed to by @viter.
798 static inline dma_addr_t
vmw_piter_dma_addr(struct vmw_piter
*viter
)
800 return viter
->dma_address(viter
);
804 * vmw_piter_page - Return a pointer to the current page.
806 * @viter: Pointer to the iterator
808 * Returns the DMA address of the page pointed to by @viter.
810 static inline struct page
*vmw_piter_page(struct vmw_piter
*viter
)
812 return viter
->page(viter
);
816 * Command submission - vmwgfx_execbuf.c
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
830 struct vmw_fence_obj
**out_fence
,
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
);
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
,
840 extern void vmw_execbuf_copy_fence_user(struct vmw_private
*dev_priv
,
841 struct vmw_fpriv
*vmw_fp
,
843 struct drm_vmw_fence_rep __user
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
,
852 bool validate_as_mob
);
853 bool vmw_cmd_describe(const void *buf
, u32
*size
, char const **cmd
);
856 * IRQs and wating - vmwgfx_irq.c
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
,
866 extern int vmw_fallback_wait(struct vmw_private
*dev_priv
,
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
,
880 extern void vmw_generic_waiter_remove(struct vmw_private
*dev_priv
,
881 u32 flag
, int *waiter_count
);
884 * Rudimentary fence-like objects currently used only for throttling -
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
,
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
);
898 * Kernel framebuffer - vmwgfx_fb.c
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
);
907 * Kernel modesetting - vmwgfx_kms.c
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
,
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
,
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
);
942 int vmw_dumb_create(struct drm_file
*file_priv
,
943 struct drm_device
*dev
,
944 struct drm_mode_create_dumb
*args
);
946 int vmw_dumb_map_offset(struct drm_file
*file_priv
,
947 struct drm_device
*dev
, uint32_t handle
,
949 int vmw_dumb_destroy(struct drm_file
*file_priv
,
950 struct drm_device
*dev
,
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
);
957 * Overlay control - vmwgfx_overlay.c
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
);
976 extern const struct ttm_mem_type_manager_func vmw_gmrid_manager_func
;
979 * Prime - vmwgfx_prime.c
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
,
992 * MemoryOBject management - vmwgfx_mob.c
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
);
1006 * Context management - vmwgfx_context.c
1009 extern const struct vmw_user_resource_conv
*user_context_converter
;
1011 extern int vmw_context_check(struct vmw_private
*dev_priv
,
1012 struct ttm_object_file
*tfile
,
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
,
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
);
1039 * Surface management - vmwgfx_surface.c
1042 extern const struct vmw_user_resource_conv
*user_surface_converter
;
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
,
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
);
1072 * Shader management - vmwgfx_shader.c
1075 extern const struct vmw_user_resource_conv
*user_shader_converter
;
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
,
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
,
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
,
1099 extern struct vmw_resource
*
1100 vmw_shader_lookup(struct vmw_cmdbuf_res_manager
*man
,
1101 u32 user_key
, SVGA3dShaderType shader_type
);
1104 * Command buffer managed resources - vmwgfx_cmdbuf_res.c
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
,
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
,
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
,
1125 struct list_head
*list
,
1126 struct vmw_resource
**res
);
1129 * COTable management - vmwgfx_cotable.c
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
,
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
);
1141 * Command buffer managerment vmwgfx_cmdbuf.c
1143 struct vmw_cmdbuf_man
;
1144 struct vmw_cmdbuf_header
;
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
,
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
);
1170 * Inline helper functions
1173 static inline void vmw_surface_unreference(struct vmw_surface
**srf
)
1175 struct vmw_surface
*tmp_srf
= *srf
;
1176 struct vmw_resource
*res
= &tmp_srf
->res
;
1179 vmw_resource_unreference(&res
);
1182 static inline struct vmw_surface
*vmw_surface_reference(struct vmw_surface
*srf
)
1184 (void) vmw_resource_reference(&srf
->res
);
1188 static inline void vmw_dmabuf_unreference(struct vmw_dma_buffer
**buf
)
1190 struct vmw_dma_buffer
*tmp_buf
= *buf
;
1193 if (tmp_buf
!= NULL
) {
1194 struct ttm_buffer_object
*bo
= &tmp_buf
->base
;
1200 static inline struct vmw_dma_buffer
*vmw_dmabuf_reference(struct vmw_dma_buffer
*buf
)
1202 if (ttm_bo_reference(&buf
->base
))
1207 static inline struct ttm_mem_global
*vmw_mem_glob(struct vmw_private
*dev_priv
)
1209 return (struct ttm_mem_global
*) dev_priv
->mem_global_ref
.object
;
1212 static inline void vmw_fifo_resource_inc(struct vmw_private
*dev_priv
)
1214 atomic_inc(&dev_priv
->num_fifo_resources
);
1217 static inline void vmw_fifo_resource_dec(struct vmw_private
*dev_priv
)
1219 atomic_dec(&dev_priv
->num_fifo_resources
);
1223 * vmw_mmio_read - Perform a MMIO read from volatile memory
1225 * @addr: The address to read from
1227 * This function is intended to be equivalent to ioread32() on
1228 * memremap'd memory, but without byteswapping.
1230 static inline u32
vmw_mmio_read(u32
*addr
)
1232 return READ_ONCE(*addr
);
1236 * vmw_mmio_write - Perform a MMIO write to volatile memory
1238 * @addr: The address to write to
1240 * This function is intended to be equivalent to iowrite32 on
1241 * memremap'd memory, but without byteswapping.
1243 static inline void vmw_mmio_write(u32 value
, u32
*addr
)
1245 WRITE_ONCE(*addr
, value
);
1249 * Add vmw_msg module function
1251 extern int vmw_host_log(const char *log
);