Home | History | Annotate | Line # | Download | only in vmwgfx
      1  1.9  riastrad /*	$NetBSD: vmwgfx_drv.h,v 1.9 2022/10/25 23:36:21 riastradh Exp $	*/
      2  1.2  riastrad 
      3  1.4  riastrad /* SPDX-License-Identifier: GPL-2.0 OR MIT */
      4  1.1  riastrad /**************************************************************************
      5  1.1  riastrad  *
      6  1.4  riastrad  * Copyright 2009-2015 VMware, Inc., Palo Alto, CA., USA
      7  1.1  riastrad  *
      8  1.1  riastrad  * Permission is hereby granted, free of charge, to any person obtaining a
      9  1.1  riastrad  * copy of this software and associated documentation files (the
     10  1.1  riastrad  * "Software"), to deal in the Software without restriction, including
     11  1.1  riastrad  * without limitation the rights to use, copy, modify, merge, publish,
     12  1.1  riastrad  * distribute, sub license, and/or sell copies of the Software, and to
     13  1.1  riastrad  * permit persons to whom the Software is furnished to do so, subject to
     14  1.1  riastrad  * the following conditions:
     15  1.1  riastrad  *
     16  1.1  riastrad  * The above copyright notice and this permission notice (including the
     17  1.1  riastrad  * next paragraph) shall be included in all copies or substantial portions
     18  1.1  riastrad  * of the Software.
     19  1.1  riastrad  *
     20  1.1  riastrad  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     21  1.1  riastrad  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     22  1.1  riastrad  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
     23  1.1  riastrad  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
     24  1.1  riastrad  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
     25  1.1  riastrad  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
     26  1.1  riastrad  * USE OR OTHER DEALINGS IN THE SOFTWARE.
     27  1.1  riastrad  *
     28  1.1  riastrad  **************************************************************************/
     29  1.1  riastrad 
     30  1.1  riastrad #ifndef _VMWGFX_DRV_H_
     31  1.1  riastrad #define _VMWGFX_DRV_H_
     32  1.1  riastrad 
     33  1.9  riastrad #ifdef __NetBSD__
     34  1.9  riastrad #include <sys/workqueue.h>
     35  1.9  riastrad #endif
     36  1.9  riastrad 
     37  1.6  riastrad #include <linux/notifier.h>
     38  1.4  riastrad #include <linux/suspend.h>
     39  1.4  riastrad #include <linux/sync_file.h>
     40  1.8  riastrad #include <linux/uaccess.h>
     41  1.4  riastrad 
     42  1.4  riastrad #include <drm/drm_auth.h>
     43  1.4  riastrad #include <drm/drm_device.h>
     44  1.4  riastrad #include <drm/drm_file.h>
     45  1.1  riastrad #include <drm/drm_hashtab.h>
     46  1.4  riastrad #include <drm/drm_rect.h>
     47  1.4  riastrad 
     48  1.1  riastrad #include <drm/ttm/ttm_bo_driver.h>
     49  1.1  riastrad #include <drm/ttm/ttm_execbuf_util.h>
     50  1.1  riastrad #include <drm/ttm/ttm_module.h>
     51  1.4  riastrad 
     52  1.4  riastrad #include "ttm_lock.h"
     53  1.4  riastrad #include "ttm_object.h"
     54  1.4  riastrad 
     55  1.1  riastrad #include "vmwgfx_fence.h"
     56  1.4  riastrad #include "vmwgfx_reg.h"
     57  1.4  riastrad #include "vmwgfx_validation.h"
     58  1.1  riastrad 
     59  1.4  riastrad /*
     60  1.4  riastrad  * FIXME: vmwgfx_drm.h needs to be last due to dependencies.
     61  1.4  riastrad  * uapi headers should not depend on header files outside uapi/.
     62  1.4  riastrad  */
     63  1.4  riastrad #include <drm/vmwgfx_drm.h>
     64  1.4  riastrad 
     65  1.4  riastrad 
     66  1.4  riastrad #define VMWGFX_DRIVER_NAME "vmwgfx"
     67  1.4  riastrad #define VMWGFX_DRIVER_DATE "20200114"
     68  1.1  riastrad #define VMWGFX_DRIVER_MAJOR 2
     69  1.4  riastrad #define VMWGFX_DRIVER_MINOR 17
     70  1.1  riastrad #define VMWGFX_DRIVER_PATCHLEVEL 0
     71  1.1  riastrad #define VMWGFX_FIFO_STATIC_SIZE (1024*1024)
     72  1.1  riastrad #define VMWGFX_MAX_RELOCATIONS 2048
     73  1.1  riastrad #define VMWGFX_MAX_VALIDATIONS 2048
     74  1.1  riastrad #define VMWGFX_MAX_DISPLAYS 16
     75  1.1  riastrad #define VMWGFX_CMD_BOUNCE_INIT_SIZE 32768
     76  1.2  riastrad #define VMWGFX_ENABLE_SCREEN_TARGET_OTABLE 1
     77  1.2  riastrad 
     78  1.2  riastrad /*
     79  1.2  riastrad  * Perhaps we should have sysfs entries for these.
     80  1.2  riastrad  */
     81  1.2  riastrad #define VMWGFX_NUM_GB_CONTEXT 256
     82  1.2  riastrad #define VMWGFX_NUM_GB_SHADER 20000
     83  1.2  riastrad #define VMWGFX_NUM_GB_SURFACE 32768
     84  1.2  riastrad #define VMWGFX_NUM_GB_SCREEN_TARGET VMWGFX_MAX_DISPLAYS
     85  1.2  riastrad #define VMWGFX_NUM_DXCONTEXT 256
     86  1.2  riastrad #define VMWGFX_NUM_DXQUERY 512
     87  1.2  riastrad #define VMWGFX_NUM_MOB (VMWGFX_NUM_GB_CONTEXT +\
     88  1.2  riastrad 			VMWGFX_NUM_GB_SHADER +\
     89  1.2  riastrad 			VMWGFX_NUM_GB_SURFACE +\
     90  1.2  riastrad 			VMWGFX_NUM_GB_SCREEN_TARGET)
     91  1.1  riastrad 
     92  1.4  riastrad #define VMW_PL_GMR (TTM_PL_PRIV + 0)
     93  1.4  riastrad #define VMW_PL_FLAG_GMR (TTM_PL_FLAG_PRIV << 0)
     94  1.4  riastrad #define VMW_PL_MOB (TTM_PL_PRIV + 1)
     95  1.4  riastrad #define VMW_PL_FLAG_MOB (TTM_PL_FLAG_PRIV << 1)
     96  1.1  riastrad 
     97  1.1  riastrad #define VMW_RES_CONTEXT ttm_driver_type0
     98  1.1  riastrad #define VMW_RES_SURFACE ttm_driver_type1
     99  1.1  riastrad #define VMW_RES_STREAM ttm_driver_type2
    100  1.1  riastrad #define VMW_RES_FENCE ttm_driver_type3
    101  1.2  riastrad #define VMW_RES_SHADER ttm_driver_type4
    102  1.1  riastrad 
    103  1.1  riastrad struct vmw_fpriv {
    104  1.1  riastrad 	struct ttm_object_file *tfile;
    105  1.4  riastrad 	bool gb_aware; /* user-space is guest-backed aware */
    106  1.1  riastrad };
    107  1.1  riastrad 
    108  1.4  riastrad /**
    109  1.4  riastrad  * struct vmw_buffer_object - TTM buffer object with vmwgfx additions
    110  1.4  riastrad  * @base: The TTM buffer object
    111  1.4  riastrad  * @res_tree: RB tree of resources using this buffer object as a backing MOB
    112  1.4  riastrad  * @pin_count: pin depth
    113  1.4  riastrad  * @cpu_writers: Number of synccpu write grabs. Protected by reservation when
    114  1.4  riastrad  * increased. May be decreased without reservation.
    115  1.4  riastrad  * @dx_query_ctx: DX context if this buffer object is used as a DX query MOB
    116  1.4  riastrad  * @map: Kmap object for semi-persistent mappings
    117  1.4  riastrad  * @res_prios: Eviction priority counts for attached resources
    118  1.4  riastrad  * @dirty: structure for user-space dirty-tracking
    119  1.4  riastrad  */
    120  1.4  riastrad struct vmw_buffer_object {
    121  1.1  riastrad 	struct ttm_buffer_object base;
    122  1.4  riastrad 	struct rb_root res_tree;
    123  1.2  riastrad 	s32 pin_count;
    124  1.4  riastrad 	atomic_t cpu_writers;
    125  1.2  riastrad 	/* Not ref-counted.  Protected by binding_mutex */
    126  1.2  riastrad 	struct vmw_resource *dx_query_ctx;
    127  1.4  riastrad 	/* Protected by reservation */
    128  1.4  riastrad 	struct ttm_bo_kmap_obj map;
    129  1.4  riastrad 	u32 res_prios[TTM_MAX_BO_PRIORITY];
    130  1.4  riastrad 	struct vmw_bo_dirty *dirty;
    131  1.1  riastrad };
    132  1.1  riastrad 
    133  1.1  riastrad /**
    134  1.1  riastrad  * struct vmw_validate_buffer - Carries validation info about buffers.
    135  1.1  riastrad  *
    136  1.1  riastrad  * @base: Validation info for TTM.
    137  1.1  riastrad  * @hash: Hash entry for quick lookup of the TTM buffer object.
    138  1.1  riastrad  *
    139  1.1  riastrad  * This structure contains also driver private validation info
    140  1.1  riastrad  * on top of the info needed by TTM.
    141  1.1  riastrad  */
    142  1.1  riastrad struct vmw_validate_buffer {
    143  1.1  riastrad 	struct ttm_validate_buffer base;
    144  1.1  riastrad 	struct drm_hash_item hash;
    145  1.2  riastrad 	bool validate_as_mob;
    146  1.1  riastrad };
    147  1.1  riastrad 
    148  1.1  riastrad struct vmw_res_func;
    149  1.4  riastrad 
    150  1.4  riastrad 
    151  1.4  riastrad /**
    152  1.4  riastrad  * struct vmw-resource - base class for hardware resources
    153  1.4  riastrad  *
    154  1.4  riastrad  * @kref: For refcounting.
    155  1.4  riastrad  * @dev_priv: Pointer to the device private for this resource. Immutable.
    156  1.4  riastrad  * @id: Device id. Protected by @dev_priv::resource_lock.
    157  1.4  riastrad  * @backup_size: Backup buffer size. Immutable.
    158  1.4  riastrad  * @res_dirty: Resource contains data not yet in the backup buffer. Protected
    159  1.4  riastrad  * by resource reserved.
    160  1.4  riastrad  * @backup_dirty: Backup buffer contains data not yet in the HW resource.
    161  1.4  riastrad  * Protected by resource reserved.
    162  1.4  riastrad  * @coherent: Emulate coherency by tracking vm accesses.
    163  1.4  riastrad  * @backup: The backup buffer if any. Protected by resource reserved.
    164  1.4  riastrad  * @backup_offset: Offset into the backup buffer if any. Protected by resource
    165  1.4  riastrad  * reserved. Note that only a few resource types can have a @backup_offset
    166  1.4  riastrad  * different from zero.
    167  1.4  riastrad  * @pin_count: The pin count for this resource. A pinned resource has a
    168  1.4  riastrad  * pin-count greater than zero. It is not on the resource LRU lists and its
    169  1.4  riastrad  * backup buffer is pinned. Hence it can't be evicted.
    170  1.4  riastrad  * @func: Method vtable for this resource. Immutable.
    171  1.4  riastrad  * @mob_node; Node for the MOB backup rbtree. Protected by @backup reserved.
    172  1.4  riastrad  * @lru_head: List head for the LRU list. Protected by @dev_priv::resource_lock.
    173  1.4  riastrad  * @binding_head: List head for the context binding list. Protected by
    174  1.4  riastrad  * the @dev_priv::binding_mutex
    175  1.4  riastrad  * @res_free: The resource destructor.
    176  1.4  riastrad  * @hw_destroy: Callback to destroy the resource on the device, as part of
    177  1.4  riastrad  * resource destruction.
    178  1.4  riastrad  */
    179  1.4  riastrad struct vmw_resource_dirty;
    180  1.1  riastrad struct vmw_resource {
    181  1.1  riastrad 	struct kref kref;
    182  1.1  riastrad 	struct vmw_private *dev_priv;
    183  1.1  riastrad 	int id;
    184  1.4  riastrad 	u32 used_prio;
    185  1.1  riastrad 	unsigned long backup_size;
    186  1.4  riastrad 	u32 res_dirty : 1;
    187  1.4  riastrad 	u32 backup_dirty : 1;
    188  1.4  riastrad 	u32 coherent : 1;
    189  1.4  riastrad 	struct vmw_buffer_object *backup;
    190  1.1  riastrad 	unsigned long backup_offset;
    191  1.4  riastrad 	unsigned long pin_count;
    192  1.1  riastrad 	const struct vmw_res_func *func;
    193  1.4  riastrad 	struct rb_node mob_node;
    194  1.6  riastrad 	bool mob_attached;
    195  1.4  riastrad 	struct list_head lru_head;
    196  1.4  riastrad 	struct list_head binding_head;
    197  1.4  riastrad 	struct vmw_resource_dirty *dirty;
    198  1.1  riastrad 	void (*res_free) (struct vmw_resource *res);
    199  1.1  riastrad 	void (*hw_destroy) (struct vmw_resource *res);
    200  1.1  riastrad };
    201  1.1  riastrad 
    202  1.2  riastrad 
    203  1.2  riastrad /*
    204  1.2  riastrad  * Resources that are managed using ioctls.
    205  1.2  riastrad  */
    206  1.1  riastrad enum vmw_res_type {
    207  1.1  riastrad 	vmw_res_context,
    208  1.1  riastrad 	vmw_res_surface,
    209  1.1  riastrad 	vmw_res_stream,
    210  1.2  riastrad 	vmw_res_shader,
    211  1.2  riastrad 	vmw_res_dx_context,
    212  1.2  riastrad 	vmw_res_cotable,
    213  1.2  riastrad 	vmw_res_view,
    214  1.1  riastrad 	vmw_res_max
    215  1.1  riastrad };
    216  1.1  riastrad 
    217  1.2  riastrad /*
    218  1.2  riastrad  * Resources that are managed using command streams.
    219  1.2  riastrad  */
    220  1.2  riastrad enum vmw_cmdbuf_res_type {
    221  1.2  riastrad 	vmw_cmdbuf_res_shader,
    222  1.2  riastrad 	vmw_cmdbuf_res_view
    223  1.2  riastrad };
    224  1.2  riastrad 
    225  1.2  riastrad struct vmw_cmdbuf_res_manager;
    226  1.2  riastrad 
    227  1.1  riastrad struct vmw_cursor_snooper {
    228  1.1  riastrad 	size_t age;
    229  1.1  riastrad 	uint32_t *image;
    230  1.1  riastrad };
    231  1.1  riastrad 
    232  1.1  riastrad struct vmw_framebuffer;
    233  1.1  riastrad struct vmw_surface_offset;
    234  1.1  riastrad 
    235  1.1  riastrad struct vmw_surface {
    236  1.1  riastrad 	struct vmw_resource res;
    237  1.4  riastrad 	SVGA3dSurfaceAllFlags flags;
    238  1.1  riastrad 	uint32_t format;
    239  1.1  riastrad 	uint32_t mip_levels[DRM_VMW_MAX_SURFACE_FACES];
    240  1.1  riastrad 	struct drm_vmw_size base_size;
    241  1.1  riastrad 	struct drm_vmw_size *sizes;
    242  1.1  riastrad 	uint32_t num_sizes;
    243  1.1  riastrad 	bool scanout;
    244  1.2  riastrad 	uint32_t array_size;
    245  1.1  riastrad 	/* TODO so far just a extra pointer */
    246  1.1  riastrad 	struct vmw_cursor_snooper snooper;
    247  1.1  riastrad 	struct vmw_surface_offset *offsets;
    248  1.1  riastrad 	SVGA3dTextureFilter autogen_filter;
    249  1.1  riastrad 	uint32_t multisample_count;
    250  1.2  riastrad 	struct list_head view_list;
    251  1.4  riastrad 	SVGA3dMSPattern multisample_pattern;
    252  1.4  riastrad 	SVGA3dMSQualityLevel quality_level;
    253  1.1  riastrad };
    254  1.1  riastrad 
    255  1.1  riastrad struct vmw_marker_queue {
    256  1.1  riastrad 	struct list_head head;
    257  1.2  riastrad 	u64 lag;
    258  1.2  riastrad 	u64 lag_time;
    259  1.1  riastrad 	spinlock_t lock;
    260  1.1  riastrad };
    261  1.1  riastrad 
    262  1.1  riastrad struct vmw_fifo_state {
    263  1.1  riastrad 	unsigned long reserved_size;
    264  1.2  riastrad 	u32 *dynamic_buffer;
    265  1.2  riastrad 	u32 *static_buffer;
    266  1.1  riastrad 	unsigned long static_buffer_size;
    267  1.1  riastrad 	bool using_bounce_buffer;
    268  1.1  riastrad 	uint32_t capabilities;
    269  1.1  riastrad 	struct mutex fifo_mutex;
    270  1.1  riastrad 	struct rw_semaphore rwsem;
    271  1.1  riastrad 	struct vmw_marker_queue marker_queue;
    272  1.2  riastrad 	bool dx;
    273  1.1  riastrad };
    274  1.1  riastrad 
    275  1.1  riastrad /**
    276  1.1  riastrad  * struct vmw_res_cache_entry - resource information cache entry
    277  1.4  riastrad  * @handle: User-space handle of a resource.
    278  1.4  riastrad  * @res: Non-ref-counted pointer to the resource.
    279  1.4  riastrad  * @valid_handle: Whether the @handle member is valid.
    280  1.1  riastrad  * @valid: Whether the entry is valid, which also implies that the execbuf
    281  1.1  riastrad  * code holds a reference to the resource, and it's placed on the
    282  1.1  riastrad  * validation list.
    283  1.1  riastrad  *
    284  1.1  riastrad  * Used to avoid frequent repeated user-space handle lookups of the
    285  1.1  riastrad  * same resource.
    286  1.1  riastrad  */
    287  1.1  riastrad struct vmw_res_cache_entry {
    288  1.1  riastrad 	uint32_t handle;
    289  1.1  riastrad 	struct vmw_resource *res;
    290  1.4  riastrad 	void *private;
    291  1.4  riastrad 	unsigned short valid_handle;
    292  1.4  riastrad 	unsigned short valid;
    293  1.1  riastrad };
    294  1.1  riastrad 
    295  1.2  riastrad /**
    296  1.2  riastrad  * enum vmw_dma_map_mode - indicate how to perform TTM page dma mappings.
    297  1.2  riastrad  */
    298  1.2  riastrad enum vmw_dma_map_mode {
    299  1.2  riastrad 	vmw_dma_phys,           /* Use physical page addresses */
    300  1.2  riastrad 	vmw_dma_alloc_coherent, /* Use TTM coherent pages */
    301  1.2  riastrad 	vmw_dma_map_populate,   /* Unmap from DMA just after unpopulate */
    302  1.2  riastrad 	vmw_dma_map_bind,       /* Unmap from DMA just before unbind */
    303  1.2  riastrad 	vmw_dma_map_max
    304  1.2  riastrad };
    305  1.2  riastrad 
    306  1.2  riastrad /**
    307  1.2  riastrad  * struct vmw_sg_table - Scatter/gather table for binding, with additional
    308  1.2  riastrad  * device-specific information.
    309  1.2  riastrad  *
    310  1.2  riastrad  * @sgt: Pointer to a struct sg_table with binding information
    311  1.2  riastrad  * @num_regions: Number of regions with device-address contiguous pages
    312  1.2  riastrad  */
    313  1.2  riastrad struct vmw_sg_table {
    314  1.2  riastrad 	enum vmw_dma_map_mode mode;
    315  1.2  riastrad 	struct page **pages;
    316  1.2  riastrad 	const dma_addr_t *addrs;
    317  1.2  riastrad 	struct sg_table *sgt;
    318  1.2  riastrad 	unsigned long num_regions;
    319  1.2  riastrad 	unsigned long num_pages;
    320  1.2  riastrad };
    321  1.2  riastrad 
    322  1.2  riastrad /**
    323  1.2  riastrad  * struct vmw_piter - Page iterator that iterates over a list of pages
    324  1.2  riastrad  * and DMA addresses that could be either a scatter-gather list or
    325  1.2  riastrad  * arrays
    326  1.2  riastrad  *
    327  1.2  riastrad  * @pages: Array of page pointers to the pages.
    328  1.2  riastrad  * @addrs: DMA addresses to the pages if coherent pages are used.
    329  1.2  riastrad  * @iter: Scatter-gather page iterator. Current position in SG list.
    330  1.2  riastrad  * @i: Current position in arrays.
    331  1.2  riastrad  * @num_pages: Number of pages total.
    332  1.2  riastrad  * @next: Function to advance the iterator. Returns false if past the list
    333  1.2  riastrad  * of pages, true otherwise.
    334  1.2  riastrad  * @dma_address: Function to return the DMA address of the current page.
    335  1.2  riastrad  */
    336  1.2  riastrad struct vmw_piter {
    337  1.2  riastrad 	struct page **pages;
    338  1.2  riastrad 	const dma_addr_t *addrs;
    339  1.6  riastrad #ifndef __NetBSD__		/* XXX */
    340  1.4  riastrad 	struct sg_dma_page_iter iter;
    341  1.6  riastrad #endif
    342  1.2  riastrad 	unsigned long i;
    343  1.2  riastrad 	unsigned long num_pages;
    344  1.2  riastrad 	bool (*next)(struct vmw_piter *);
    345  1.2  riastrad 	dma_addr_t (*dma_address)(struct vmw_piter *);
    346  1.2  riastrad 	struct page *(*page)(struct vmw_piter *);
    347  1.2  riastrad };
    348  1.2  riastrad 
    349  1.2  riastrad /*
    350  1.2  riastrad  * enum vmw_display_unit_type - Describes the display unit
    351  1.2  riastrad  */
    352  1.2  riastrad enum vmw_display_unit_type {
    353  1.2  riastrad 	vmw_du_invalid = 0,
    354  1.2  riastrad 	vmw_du_legacy,
    355  1.2  riastrad 	vmw_du_screen_object,
    356  1.2  riastrad 	vmw_du_screen_target
    357  1.2  riastrad };
    358  1.2  riastrad 
    359  1.4  riastrad struct vmw_validation_context;
    360  1.4  riastrad struct vmw_ctx_validation_info;
    361  1.2  riastrad 
    362  1.4  riastrad /**
    363  1.4  riastrad  * struct vmw_sw_context - Command submission context
    364  1.4  riastrad  * @res_ht: Pointer hash table used to find validation duplicates
    365  1.4  riastrad  * @kernel: Whether the command buffer originates from kernel code rather
    366  1.4  riastrad  * than from user-space
    367  1.4  riastrad  * @fp: If @kernel is false, points to the file of the client. Otherwise
    368  1.4  riastrad  * NULL
    369  1.4  riastrad  * @cmd_bounce: Command bounce buffer used for command validation before
    370  1.4  riastrad  * copying to fifo space
    371  1.4  riastrad  * @cmd_bounce_size: Current command bounce buffer size
    372  1.4  riastrad  * @cur_query_bo: Current buffer object used as query result buffer
    373  1.4  riastrad  * @bo_relocations: List of buffer object relocations
    374  1.4  riastrad  * @res_relocations: List of resource relocations
    375  1.4  riastrad  * @buf_start: Pointer to start of memory where command validation takes
    376  1.4  riastrad  * place
    377  1.4  riastrad  * @res_cache: Cache of recently looked up resources
    378  1.4  riastrad  * @last_query_ctx: Last context that submitted a query
    379  1.4  riastrad  * @needs_post_query_barrier: Whether a query barrier is needed after
    380  1.4  riastrad  * command submission
    381  1.4  riastrad  * @staged_bindings: Cached per-context binding tracker
    382  1.4  riastrad  * @staged_bindings_inuse: Whether the cached per-context binding tracker
    383  1.4  riastrad  * is in use
    384  1.4  riastrad  * @staged_cmd_res: List of staged command buffer managed resources in this
    385  1.4  riastrad  * command buffer
    386  1.4  riastrad  * @ctx_list: List of context resources referenced in this command buffer
    387  1.4  riastrad  * @dx_ctx_node: Validation metadata of the current DX context
    388  1.4  riastrad  * @dx_query_mob: The MOB used for DX queries
    389  1.4  riastrad  * @dx_query_ctx: The DX context used for the last DX query
    390  1.4  riastrad  * @man: Pointer to the command buffer managed resource manager
    391  1.4  riastrad  * @ctx: The validation context
    392  1.4  riastrad  */
    393  1.1  riastrad struct vmw_sw_context{
    394  1.1  riastrad 	struct drm_open_hash res_ht;
    395  1.1  riastrad 	bool res_ht_initialized;
    396  1.4  riastrad 	bool kernel;
    397  1.2  riastrad 	struct vmw_fpriv *fp;
    398  1.1  riastrad 	uint32_t *cmd_bounce;
    399  1.1  riastrad 	uint32_t cmd_bounce_size;
    400  1.4  riastrad 	struct vmw_buffer_object *cur_query_bo;
    401  1.4  riastrad 	struct list_head bo_relocations;
    402  1.1  riastrad 	struct list_head res_relocations;
    403  1.1  riastrad 	uint32_t *buf_start;
    404  1.1  riastrad 	struct vmw_res_cache_entry res_cache[vmw_res_max];
    405  1.1  riastrad 	struct vmw_resource *last_query_ctx;
    406  1.1  riastrad 	bool needs_post_query_barrier;
    407  1.2  riastrad 	struct vmw_ctx_binding_state *staged_bindings;
    408  1.2  riastrad 	bool staged_bindings_inuse;
    409  1.2  riastrad 	struct list_head staged_cmd_res;
    410  1.4  riastrad 	struct list_head ctx_list;
    411  1.4  riastrad 	struct vmw_ctx_validation_info *dx_ctx_node;
    412  1.4  riastrad 	struct vmw_buffer_object *dx_query_mob;
    413  1.2  riastrad 	struct vmw_resource *dx_query_ctx;
    414  1.2  riastrad 	struct vmw_cmdbuf_res_manager *man;
    415  1.4  riastrad 	struct vmw_validation_context *ctx;
    416  1.1  riastrad };
    417  1.1  riastrad 
    418  1.1  riastrad struct vmw_legacy_display;
    419  1.1  riastrad struct vmw_overlay;
    420  1.1  riastrad 
    421  1.1  riastrad struct vmw_vga_topology_state {
    422  1.1  riastrad 	uint32_t width;
    423  1.1  riastrad 	uint32_t height;
    424  1.1  riastrad 	uint32_t primary;
    425  1.1  riastrad 	uint32_t pos_x;
    426  1.1  riastrad 	uint32_t pos_y;
    427  1.1  riastrad };
    428  1.1  riastrad 
    429  1.2  riastrad 
    430  1.2  riastrad /*
    431  1.2  riastrad  * struct vmw_otable - Guest Memory OBject table metadata
    432  1.2  riastrad  *
    433  1.2  riastrad  * @size:           Size of the table (page-aligned).
    434  1.2  riastrad  * @page_table:     Pointer to a struct vmw_mob holding the page table.
    435  1.2  riastrad  */
    436  1.2  riastrad struct vmw_otable {
    437  1.2  riastrad 	unsigned long size;
    438  1.2  riastrad 	struct vmw_mob *page_table;
    439  1.2  riastrad 	bool enabled;
    440  1.2  riastrad };
    441  1.2  riastrad 
    442  1.2  riastrad struct vmw_otable_batch {
    443  1.2  riastrad 	unsigned num_otables;
    444  1.2  riastrad 	struct vmw_otable *otables;
    445  1.2  riastrad 	struct vmw_resource *context;
    446  1.2  riastrad 	struct ttm_buffer_object *otable_bo;
    447  1.2  riastrad };
    448  1.2  riastrad 
    449  1.4  riastrad enum {
    450  1.4  riastrad 	VMW_IRQTHREAD_FENCE,
    451  1.4  riastrad 	VMW_IRQTHREAD_CMDBUF,
    452  1.4  riastrad 	VMW_IRQTHREAD_MAX
    453  1.4  riastrad };
    454  1.4  riastrad 
    455  1.1  riastrad struct vmw_private {
    456  1.1  riastrad 	struct ttm_bo_device bdev;
    457  1.1  riastrad 
    458  1.1  riastrad 	struct vmw_fifo_state fifo;
    459  1.1  riastrad 
    460  1.1  riastrad 	struct drm_device *dev;
    461  1.4  riastrad 	struct drm_vma_offset_manager vma_manager;
    462  1.1  riastrad 	unsigned long vmw_chipset;
    463  1.6  riastrad #ifdef __NetBSD__
    464  1.6  riastrad 	bus_space_tag_t iot;
    465  1.6  riastrad 	bus_space_handle_t ioh;
    466  1.8  riastrad #endif
    467  1.1  riastrad 	unsigned int io_start;
    468  1.1  riastrad 	uint32_t vram_start;
    469  1.1  riastrad 	uint32_t vram_size;
    470  1.2  riastrad 	uint32_t prim_bb_mem;
    471  1.1  riastrad 	uint32_t mmio_start;
    472  1.1  riastrad 	uint32_t mmio_size;
    473  1.1  riastrad 	uint32_t fb_max_width;
    474  1.1  riastrad 	uint32_t fb_max_height;
    475  1.2  riastrad 	uint32_t texture_max_width;
    476  1.2  riastrad 	uint32_t texture_max_height;
    477  1.2  riastrad 	uint32_t stdu_max_width;
    478  1.2  riastrad 	uint32_t stdu_max_height;
    479  1.1  riastrad 	uint32_t initial_width;
    480  1.1  riastrad 	uint32_t initial_height;
    481  1.8  riastrad #ifdef __NetBSD__
    482  1.8  riastrad 	bus_space_tag_t mmio_bst;
    483  1.8  riastrad 	bus_space_handle_t mmio_bsh;
    484  1.8  riastrad #endif
    485  1.2  riastrad 	u32 *mmio_virt;
    486  1.1  riastrad 	uint32_t capabilities;
    487  1.4  riastrad 	uint32_t capabilities2;
    488  1.1  riastrad 	uint32_t max_gmr_ids;
    489  1.1  riastrad 	uint32_t max_gmr_pages;
    490  1.2  riastrad 	uint32_t max_mob_pages;
    491  1.2  riastrad 	uint32_t max_mob_size;
    492  1.1  riastrad 	uint32_t memory_size;
    493  1.1  riastrad 	bool has_gmr;
    494  1.2  riastrad 	bool has_mob;
    495  1.2  riastrad 	spinlock_t hw_lock;
    496  1.2  riastrad 	spinlock_t cap_lock;
    497  1.2  riastrad 	bool has_dx;
    498  1.2  riastrad 	bool assume_16bpp;
    499  1.4  riastrad 	bool has_sm4_1;
    500  1.1  riastrad 
    501  1.1  riastrad 	/*
    502  1.1  riastrad 	 * VGA registers.
    503  1.1  riastrad 	 */
    504  1.1  riastrad 
    505  1.1  riastrad 	struct vmw_vga_topology_state vga_save[VMWGFX_MAX_DISPLAYS];
    506  1.1  riastrad 	uint32_t vga_width;
    507  1.1  riastrad 	uint32_t vga_height;
    508  1.1  riastrad 	uint32_t vga_bpp;
    509  1.1  riastrad 	uint32_t vga_bpl;
    510  1.1  riastrad 	uint32_t vga_pitchlock;
    511  1.1  riastrad 
    512  1.1  riastrad 	uint32_t num_displays;
    513  1.1  riastrad 
    514  1.1  riastrad 	/*
    515  1.1  riastrad 	 * Framebuffer info.
    516  1.1  riastrad 	 */
    517  1.1  riastrad 
    518  1.1  riastrad 	void *fb_info;
    519  1.2  riastrad 	enum vmw_display_unit_type active_display_unit;
    520  1.1  riastrad 	struct vmw_legacy_display *ldu_priv;
    521  1.1  riastrad 	struct vmw_overlay *overlay_priv;
    522  1.4  riastrad 	struct drm_property *hotplug_mode_update_property;
    523  1.4  riastrad 	struct drm_property *implicit_placement_property;
    524  1.4  riastrad 	struct mutex global_kms_state_mutex;
    525  1.4  riastrad 	spinlock_t cursor_lock;
    526  1.4  riastrad 	struct drm_atomic_state *suspend_state;
    527  1.1  riastrad 
    528  1.1  riastrad 	/*
    529  1.1  riastrad 	 * Context and surface management.
    530  1.1  riastrad 	 */
    531  1.1  riastrad 
    532  1.4  riastrad 	spinlock_t resource_lock;
    533  1.1  riastrad 	struct idr res_idr[vmw_res_max];
    534  1.1  riastrad 
    535  1.1  riastrad 	/*
    536  1.1  riastrad 	 * A resource manager for kernel-only surfaces and
    537  1.1  riastrad 	 * contexts.
    538  1.1  riastrad 	 */
    539  1.1  riastrad 
    540  1.1  riastrad 	struct ttm_object_device *tdev;
    541  1.1  riastrad 
    542  1.1  riastrad 	/*
    543  1.1  riastrad 	 * Fencing and IRQs.
    544  1.1  riastrad 	 */
    545  1.1  riastrad 
    546  1.1  riastrad 	atomic_t marker_seq;
    547  1.6  riastrad 	drm_waitqueue_t fence_queue;
    548  1.7  riastrad 	spinlock_t fence_lock;
    549  1.6  riastrad 	drm_waitqueue_t fifo_queue;
    550  1.7  riastrad 	spinlock_t fifo_lock;
    551  1.2  riastrad 	spinlock_t waiter_lock;
    552  1.2  riastrad 	int fence_queue_waiters; /* Protected by waiter_lock */
    553  1.2  riastrad 	int goal_queue_waiters; /* Protected by waiter_lock */
    554  1.2  riastrad 	int cmdbuf_waiters; /* Protected by waiter_lock */
    555  1.2  riastrad 	int error_waiters; /* Protected by waiter_lock */
    556  1.2  riastrad 	int fifo_queue_waiters; /* Protected by waiter_lock */
    557  1.1  riastrad 	uint32_t last_read_seqno;
    558  1.1  riastrad 	struct vmw_fence_manager *fman;
    559  1.2  riastrad 	uint32_t irq_mask; /* Updates protected by waiter_lock */
    560  1.1  riastrad 
    561  1.1  riastrad 	/*
    562  1.1  riastrad 	 * Device state
    563  1.1  riastrad 	 */
    564  1.1  riastrad 
    565  1.1  riastrad 	uint32_t traces_state;
    566  1.1  riastrad 	uint32_t enable_state;
    567  1.1  riastrad 	uint32_t config_done_state;
    568  1.1  riastrad 
    569  1.1  riastrad 	/**
    570  1.1  riastrad 	 * Execbuf
    571  1.1  riastrad 	 */
    572  1.1  riastrad 	/**
    573  1.1  riastrad 	 * Protected by the cmdbuf mutex.
    574  1.1  riastrad 	 */
    575  1.1  riastrad 
    576  1.1  riastrad 	struct vmw_sw_context ctx;
    577  1.1  riastrad 	struct mutex cmdbuf_mutex;
    578  1.2  riastrad 	struct mutex binding_mutex;
    579  1.1  riastrad 
    580  1.1  riastrad 	/**
    581  1.1  riastrad 	 * Operating mode.
    582  1.1  riastrad 	 */
    583  1.1  riastrad 
    584  1.1  riastrad 	bool stealth;
    585  1.1  riastrad 	bool enable_fb;
    586  1.2  riastrad 	spinlock_t svga_lock;
    587  1.1  riastrad 
    588  1.1  riastrad 	/**
    589  1.4  riastrad 	 * PM management.
    590  1.1  riastrad 	 */
    591  1.1  riastrad 	struct notifier_block pm_nb;
    592  1.2  riastrad 	bool refuse_hibernation;
    593  1.4  riastrad 	bool suspend_locked;
    594  1.1  riastrad 
    595  1.1  riastrad 	struct mutex release_mutex;
    596  1.2  riastrad 	atomic_t num_fifo_resources;
    597  1.2  riastrad 
    598  1.2  riastrad 	/*
    599  1.2  riastrad 	 * Replace this with an rwsem as soon as we have down_xx_interruptible()
    600  1.2  riastrad 	 */
    601  1.2  riastrad 	struct ttm_lock reservation_sem;
    602  1.1  riastrad 
    603  1.1  riastrad 	/*
    604  1.1  riastrad 	 * Query processing. These members
    605  1.1  riastrad 	 * are protected by the cmdbuf mutex.
    606  1.1  riastrad 	 */
    607  1.1  riastrad 
    608  1.4  riastrad 	struct vmw_buffer_object *dummy_query_bo;
    609  1.4  riastrad 	struct vmw_buffer_object *pinned_bo;
    610  1.1  riastrad 	uint32_t query_cid;
    611  1.1  riastrad 	uint32_t query_cid_valid;
    612  1.1  riastrad 	bool dummy_query_bo_pinned;
    613  1.1  riastrad 
    614  1.1  riastrad 	/*
    615  1.1  riastrad 	 * Surface swapping. The "surface_lru" list is protected by the
    616  1.1  riastrad 	 * resource lock in order to be able to destroy a surface and take
    617  1.1  riastrad 	 * it off the lru atomically. "used_memory_size" is currently
    618  1.1  riastrad 	 * protected by the cmdbuf mutex for simplicity.
    619  1.1  riastrad 	 */
    620  1.1  riastrad 
    621  1.1  riastrad 	struct list_head res_lru[vmw_res_max];
    622  1.1  riastrad 	uint32_t used_memory_size;
    623  1.2  riastrad 
    624  1.2  riastrad 	/*
    625  1.2  riastrad 	 * DMA mapping stuff.
    626  1.2  riastrad 	 */
    627  1.2  riastrad 	enum vmw_dma_map_mode map_mode;
    628  1.2  riastrad 
    629  1.2  riastrad 	/*
    630  1.2  riastrad 	 * Guest Backed stuff
    631  1.2  riastrad 	 */
    632  1.2  riastrad 	struct vmw_otable_batch otable_batch;
    633  1.2  riastrad 
    634  1.2  riastrad 	struct vmw_cmdbuf_man *cman;
    635  1.4  riastrad 	DECLARE_BITMAP(irqthread_pending, VMW_IRQTHREAD_MAX);
    636  1.9  riastrad #ifdef __NetBSD__
    637  1.9  riastrad 	struct workqueue *irqthread_wq;
    638  1.9  riastrad 	struct work irqthread_work;
    639  1.9  riastrad 	volatile unsigned irqthread_scheduled;
    640  1.9  riastrad #endif
    641  1.4  riastrad 
    642  1.4  riastrad 	/* Validation memory reservation */
    643  1.4  riastrad 	struct vmw_validation_mem vvm;
    644  1.1  riastrad };
    645  1.1  riastrad 
    646  1.1  riastrad static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res)
    647  1.1  riastrad {
    648  1.1  riastrad 	return container_of(res, struct vmw_surface, res);
    649  1.1  riastrad }
    650  1.1  riastrad 
    651  1.1  riastrad static inline struct vmw_private *vmw_priv(struct drm_device *dev)
    652  1.1  riastrad {
    653  1.1  riastrad 	return (struct vmw_private *)dev->dev_private;
    654  1.1  riastrad }
    655  1.1  riastrad 
    656  1.1  riastrad static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
    657  1.1  riastrad {
    658  1.1  riastrad 	return (struct vmw_fpriv *)file_priv->driver_priv;
    659  1.1  riastrad }
    660  1.1  riastrad 
    661  1.2  riastrad /*
    662  1.2  riastrad  * The locking here is fine-grained, so that it is performed once
    663  1.2  riastrad  * for every read- and write operation. This is of course costly, but we
    664  1.2  riastrad  * don't perform much register access in the timing critical paths anyway.
    665  1.2  riastrad  * Instead we have the extra benefit of being sure that we don't forget
    666  1.2  riastrad  * the hw lock around register accesses.
    667  1.2  riastrad  */
    668  1.1  riastrad static inline void vmw_write(struct vmw_private *dev_priv,
    669  1.1  riastrad 			     unsigned int offset, uint32_t value)
    670  1.1  riastrad {
    671  1.4  riastrad 	spin_lock(&dev_priv->hw_lock);
    672  1.6  riastrad #ifdef __NetBSD__
    673  1.6  riastrad 	bus_space_write_4(dev_priv->iot, dev_priv->ioh, VMWGFX_INDEX_PORT,
    674  1.6  riastrad 	    offset);
    675  1.6  riastrad 	bus_space_write_4(dev_priv->iot, dev_priv->ioh, VMWGFX_VALUE_PORT,
    676  1.6  riastrad 	    value);
    677  1.6  riastrad #else
    678  1.1  riastrad 	outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
    679  1.1  riastrad 	outl(value, dev_priv->io_start + VMWGFX_VALUE_PORT);
    680  1.6  riastrad #endif
    681  1.4  riastrad 	spin_unlock(&dev_priv->hw_lock);
    682  1.1  riastrad }
    683  1.1  riastrad 
    684  1.1  riastrad static inline uint32_t vmw_read(struct vmw_private *dev_priv,
    685  1.1  riastrad 				unsigned int offset)
    686  1.1  riastrad {
    687  1.2  riastrad 	u32 val;
    688  1.1  riastrad 
    689  1.4  riastrad 	spin_lock(&dev_priv->hw_lock);
    690  1.6  riastrad #ifdef __NetBSD__
    691  1.6  riastrad 	bus_space_write_4(dev_priv->iot, dev_priv->ioh, VMWGFX_INDEX_PORT,
    692  1.6  riastrad 	    offset);
    693  1.6  riastrad 	val = bus_space_read_4(dev_priv->iot, dev_priv->ioh,
    694  1.6  riastrad 	    VMWGFX_VALUE_PORT);
    695  1.6  riastrad #else
    696  1.1  riastrad 	outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
    697  1.1  riastrad 	val = inl(dev_priv->io_start + VMWGFX_VALUE_PORT);
    698  1.6  riastrad #endif
    699  1.4  riastrad 	spin_unlock(&dev_priv->hw_lock);
    700  1.2  riastrad 
    701  1.1  riastrad 	return val;
    702  1.1  riastrad }
    703  1.1  riastrad 
    704  1.2  riastrad extern void vmw_svga_enable(struct vmw_private *dev_priv);
    705  1.2  riastrad extern void vmw_svga_disable(struct vmw_private *dev_priv);
    706  1.2  riastrad 
    707  1.1  riastrad 
    708  1.1  riastrad /**
    709  1.1  riastrad  * GMR utilities - vmwgfx_gmr.c
    710  1.1  riastrad  */
    711  1.1  riastrad 
    712  1.1  riastrad extern int vmw_gmr_bind(struct vmw_private *dev_priv,
    713  1.2  riastrad 			const struct vmw_sg_table *vsgt,
    714  1.1  riastrad 			unsigned long num_pages,
    715  1.1  riastrad 			int gmr_id);
    716  1.1  riastrad extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
    717  1.1  riastrad 
    718  1.1  riastrad /**
    719  1.1  riastrad  * Resource utilities - vmwgfx_resource.c
    720  1.1  riastrad  */
    721  1.1  riastrad struct vmw_user_resource_conv;
    722  1.1  riastrad 
    723  1.1  riastrad extern void vmw_resource_unreference(struct vmw_resource **p_res);
    724  1.1  riastrad extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
    725  1.2  riastrad extern struct vmw_resource *
    726  1.2  riastrad vmw_resource_reference_unless_doomed(struct vmw_resource *res);
    727  1.4  riastrad extern int vmw_resource_validate(struct vmw_resource *res, bool intr,
    728  1.4  riastrad 				 bool dirtying);
    729  1.2  riastrad extern int vmw_resource_reserve(struct vmw_resource *res, bool interruptible,
    730  1.2  riastrad 				bool no_backup);
    731  1.1  riastrad extern bool vmw_resource_needs_backup(const struct vmw_resource *res);
    732  1.1  riastrad extern int vmw_user_lookup_handle(struct vmw_private *dev_priv,
    733  1.1  riastrad 				  struct ttm_object_file *tfile,
    734  1.1  riastrad 				  uint32_t handle,
    735  1.1  riastrad 				  struct vmw_surface **out_surf,
    736  1.4  riastrad 				  struct vmw_buffer_object **out_buf);
    737  1.1  riastrad extern int vmw_user_resource_lookup_handle(
    738  1.1  riastrad 	struct vmw_private *dev_priv,
    739  1.1  riastrad 	struct ttm_object_file *tfile,
    740  1.1  riastrad 	uint32_t handle,
    741  1.1  riastrad 	const struct vmw_user_resource_conv *converter,
    742  1.1  riastrad 	struct vmw_resource **p_res);
    743  1.4  riastrad extern struct vmw_resource *
    744  1.4  riastrad vmw_user_resource_noref_lookup_handle(struct vmw_private *dev_priv,
    745  1.4  riastrad 				      struct ttm_object_file *tfile,
    746  1.4  riastrad 				      uint32_t handle,
    747  1.4  riastrad 				      const struct vmw_user_resource_conv *
    748  1.4  riastrad 				      converter);
    749  1.1  riastrad extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
    750  1.1  riastrad 				  struct drm_file *file_priv);
    751  1.1  riastrad extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
    752  1.1  riastrad 				  struct drm_file *file_priv);
    753  1.1  riastrad extern int vmw_user_stream_lookup(struct vmw_private *dev_priv,
    754  1.1  riastrad 				  struct ttm_object_file *tfile,
    755  1.1  riastrad 				  uint32_t *inout_id,
    756  1.1  riastrad 				  struct vmw_resource **out);
    757  1.1  riastrad extern void vmw_resource_unreserve(struct vmw_resource *res,
    758  1.4  riastrad 				   bool dirty_set,
    759  1.4  riastrad 				   bool dirty,
    760  1.2  riastrad 				   bool switch_backup,
    761  1.4  riastrad 				   struct vmw_buffer_object *new_backup,
    762  1.1  riastrad 				   unsigned long new_backup_offset);
    763  1.2  riastrad extern void vmw_query_move_notify(struct ttm_buffer_object *bo,
    764  1.2  riastrad 				  struct ttm_mem_reg *mem);
    765  1.4  riastrad extern int vmw_query_readback_all(struct vmw_buffer_object *dx_query_mob);
    766  1.1  riastrad extern void vmw_resource_evict_all(struct vmw_private *dev_priv);
    767  1.4  riastrad extern void vmw_resource_unbind_list(struct vmw_buffer_object *vbo);
    768  1.4  riastrad void vmw_resource_mob_attach(struct vmw_resource *res);
    769  1.4  riastrad void vmw_resource_mob_detach(struct vmw_resource *res);
    770  1.4  riastrad void vmw_resource_dirty_update(struct vmw_resource *res, pgoff_t start,
    771  1.4  riastrad 			       pgoff_t end);
    772  1.4  riastrad int vmw_resources_clean(struct vmw_buffer_object *vbo, pgoff_t start,
    773  1.4  riastrad 			pgoff_t end, pgoff_t *num_prefault);
    774  1.4  riastrad 
    775  1.4  riastrad /**
    776  1.4  riastrad  * vmw_resource_mob_attached - Whether a resource currently has a mob attached
    777  1.4  riastrad  * @res: The resource
    778  1.4  riastrad  *
    779  1.4  riastrad  * Return: true if the resource has a mob attached, false otherwise.
    780  1.4  riastrad  */
    781  1.4  riastrad static inline bool vmw_resource_mob_attached(const struct vmw_resource *res)
    782  1.4  riastrad {
    783  1.6  riastrad 	return res->mob_attached;
    784  1.4  riastrad }
    785  1.1  riastrad 
    786  1.1  riastrad /**
    787  1.4  riastrad  * vmw_user_resource_noref_release - release a user resource pointer looked up
    788  1.4  riastrad  * without reference
    789  1.1  riastrad  */
    790  1.4  riastrad static inline void vmw_user_resource_noref_release(void)
    791  1.4  riastrad {
    792  1.4  riastrad 	ttm_base_object_noref_release();
    793  1.4  riastrad }
    794  1.4  riastrad 
    795  1.4  riastrad /**
    796  1.4  riastrad  * Buffer object helper functions - vmwgfx_bo.c
    797  1.4  riastrad  */
    798  1.4  riastrad extern int vmw_bo_pin_in_placement(struct vmw_private *vmw_priv,
    799  1.4  riastrad 				   struct vmw_buffer_object *bo,
    800  1.4  riastrad 				   struct ttm_placement *placement,
    801  1.4  riastrad 				   bool interruptible);
    802  1.4  riastrad extern int vmw_bo_pin_in_vram(struct vmw_private *dev_priv,
    803  1.4  riastrad 			      struct vmw_buffer_object *buf,
    804  1.4  riastrad 			      bool interruptible);
    805  1.4  riastrad extern int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
    806  1.4  riastrad 				     struct vmw_buffer_object *buf,
    807  1.4  riastrad 				     bool interruptible);
    808  1.4  riastrad extern int vmw_bo_pin_in_start_of_vram(struct vmw_private *vmw_priv,
    809  1.4  riastrad 				       struct vmw_buffer_object *bo,
    810  1.2  riastrad 				       bool interruptible);
    811  1.4  riastrad extern int vmw_bo_unpin(struct vmw_private *vmw_priv,
    812  1.4  riastrad 			struct vmw_buffer_object *bo,
    813  1.4  riastrad 			bool interruptible);
    814  1.1  riastrad extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf,
    815  1.1  riastrad 				 SVGAGuestPtr *ptr);
    816  1.4  riastrad extern void vmw_bo_pin_reserved(struct vmw_buffer_object *bo, bool pin);
    817  1.4  riastrad extern void vmw_bo_bo_free(struct ttm_buffer_object *bo);
    818  1.4  riastrad extern int vmw_bo_init(struct vmw_private *dev_priv,
    819  1.4  riastrad 		       struct vmw_buffer_object *vmw_bo,
    820  1.4  riastrad 		       size_t size, struct ttm_placement *placement,
    821  1.5  riastrad 		       bool interuptable,
    822  1.4  riastrad 		       void (*bo_free)(struct ttm_buffer_object *bo));
    823  1.4  riastrad extern int vmw_user_bo_verify_access(struct ttm_buffer_object *bo,
    824  1.4  riastrad 				     struct ttm_object_file *tfile);
    825  1.4  riastrad extern int vmw_user_bo_alloc(struct vmw_private *dev_priv,
    826  1.4  riastrad 			     struct ttm_object_file *tfile,
    827  1.4  riastrad 			     uint32_t size,
    828  1.4  riastrad 			     bool shareable,
    829  1.4  riastrad 			     uint32_t *handle,
    830  1.4  riastrad 			     struct vmw_buffer_object **p_dma_buf,
    831  1.4  riastrad 			     struct ttm_base_object **p_base);
    832  1.4  riastrad extern int vmw_user_bo_reference(struct ttm_object_file *tfile,
    833  1.4  riastrad 				 struct vmw_buffer_object *dma_buf,
    834  1.4  riastrad 				 uint32_t *handle);
    835  1.4  riastrad extern int vmw_bo_alloc_ioctl(struct drm_device *dev, void *data,
    836  1.4  riastrad 			      struct drm_file *file_priv);
    837  1.4  riastrad extern int vmw_bo_unref_ioctl(struct drm_device *dev, void *data,
    838  1.4  riastrad 			      struct drm_file *file_priv);
    839  1.4  riastrad extern int vmw_user_bo_synccpu_ioctl(struct drm_device *dev, void *data,
    840  1.4  riastrad 				     struct drm_file *file_priv);
    841  1.4  riastrad extern int vmw_user_bo_lookup(struct ttm_object_file *tfile,
    842  1.4  riastrad 			      uint32_t id, struct vmw_buffer_object **out,
    843  1.4  riastrad 			      struct ttm_base_object **base);
    844  1.4  riastrad extern void vmw_bo_fence_single(struct ttm_buffer_object *bo,
    845  1.4  riastrad 				struct vmw_fence_obj *fence);
    846  1.4  riastrad extern void *vmw_bo_map_and_cache(struct vmw_buffer_object *vbo);
    847  1.4  riastrad extern void vmw_bo_unmap(struct vmw_buffer_object *vbo);
    848  1.4  riastrad extern void vmw_bo_move_notify(struct ttm_buffer_object *bo,
    849  1.4  riastrad 			       struct ttm_mem_reg *mem);
    850  1.4  riastrad extern void vmw_bo_swap_notify(struct ttm_buffer_object *bo);
    851  1.4  riastrad extern struct vmw_buffer_object *
    852  1.4  riastrad vmw_user_bo_noref_lookup(struct ttm_object_file *tfile, u32 handle);
    853  1.4  riastrad 
    854  1.4  riastrad /**
    855  1.4  riastrad  * vmw_user_bo_noref_release - release a buffer object pointer looked up
    856  1.4  riastrad  * without reference
    857  1.4  riastrad  */
    858  1.4  riastrad static inline void vmw_user_bo_noref_release(void)
    859  1.4  riastrad {
    860  1.4  riastrad 	ttm_base_object_noref_release();
    861  1.4  riastrad }
    862  1.4  riastrad 
    863  1.4  riastrad /**
    864  1.4  riastrad  * vmw_bo_adjust_prio - Adjust the buffer object eviction priority
    865  1.4  riastrad  * according to attached resources
    866  1.4  riastrad  * @vbo: The struct vmw_buffer_object
    867  1.4  riastrad  */
    868  1.4  riastrad static inline void vmw_bo_prio_adjust(struct vmw_buffer_object *vbo)
    869  1.4  riastrad {
    870  1.4  riastrad 	int i = ARRAY_SIZE(vbo->res_prios);
    871  1.4  riastrad 
    872  1.4  riastrad 	while (i--) {
    873  1.4  riastrad 		if (vbo->res_prios[i]) {
    874  1.4  riastrad 			vbo->base.priority = i;
    875  1.4  riastrad 			return;
    876  1.4  riastrad 		}
    877  1.4  riastrad 	}
    878  1.4  riastrad 
    879  1.4  riastrad 	vbo->base.priority = 3;
    880  1.4  riastrad }
    881  1.4  riastrad 
    882  1.4  riastrad /**
    883  1.4  riastrad  * vmw_bo_prio_add - Notify a buffer object of a newly attached resource
    884  1.4  riastrad  * eviction priority
    885  1.4  riastrad  * @vbo: The struct vmw_buffer_object
    886  1.4  riastrad  * @prio: The resource priority
    887  1.4  riastrad  *
    888  1.4  riastrad  * After being notified, the code assigns the highest resource eviction priority
    889  1.4  riastrad  * to the backing buffer object (mob).
    890  1.4  riastrad  */
    891  1.4  riastrad static inline void vmw_bo_prio_add(struct vmw_buffer_object *vbo, int prio)
    892  1.4  riastrad {
    893  1.4  riastrad 	if (vbo->res_prios[prio]++ == 0)
    894  1.4  riastrad 		vmw_bo_prio_adjust(vbo);
    895  1.4  riastrad }
    896  1.4  riastrad 
    897  1.4  riastrad /**
    898  1.4  riastrad  * vmw_bo_prio_del - Notify a buffer object of a resource with a certain
    899  1.4  riastrad  * priority being removed
    900  1.4  riastrad  * @vbo: The struct vmw_buffer_object
    901  1.4  riastrad  * @prio: The resource priority
    902  1.4  riastrad  *
    903  1.4  riastrad  * After being notified, the code assigns the highest resource eviction priority
    904  1.4  riastrad  * to the backing buffer object (mob).
    905  1.4  riastrad  */
    906  1.4  riastrad static inline void vmw_bo_prio_del(struct vmw_buffer_object *vbo, int prio)
    907  1.4  riastrad {
    908  1.4  riastrad 	if (--vbo->res_prios[prio] == 0)
    909  1.4  riastrad 		vmw_bo_prio_adjust(vbo);
    910  1.4  riastrad }
    911  1.1  riastrad 
    912  1.1  riastrad /**
    913  1.1  riastrad  * Misc Ioctl functionality - vmwgfx_ioctl.c
    914  1.1  riastrad  */
    915  1.1  riastrad 
    916  1.1  riastrad extern int vmw_getparam_ioctl(struct drm_device *dev, void *data,
    917  1.1  riastrad 			      struct drm_file *file_priv);
    918  1.1  riastrad extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
    919  1.1  riastrad 				struct drm_file *file_priv);
    920  1.1  riastrad extern int vmw_present_ioctl(struct drm_device *dev, void *data,
    921  1.1  riastrad 			     struct drm_file *file_priv);
    922  1.1  riastrad extern int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
    923  1.1  riastrad 				      struct drm_file *file_priv);
    924  1.6  riastrad #ifdef __NetBSD__
    925  1.6  riastrad #else
    926  1.4  riastrad extern __poll_t vmw_fops_poll(struct file *filp,
    927  1.1  riastrad 				  struct poll_table_struct *wait);
    928  1.1  riastrad extern ssize_t vmw_fops_read(struct file *filp, char __user *buffer,
    929  1.1  riastrad 			     size_t count, loff_t *offset);
    930  1.6  riastrad #endif
    931  1.1  riastrad 
    932  1.1  riastrad /**
    933  1.1  riastrad  * Fifo utilities - vmwgfx_fifo.c
    934  1.1  riastrad  */
    935  1.1  riastrad 
    936  1.1  riastrad extern int vmw_fifo_init(struct vmw_private *dev_priv,
    937  1.1  riastrad 			 struct vmw_fifo_state *fifo);
    938  1.1  riastrad extern void vmw_fifo_release(struct vmw_private *dev_priv,
    939  1.1  riastrad 			     struct vmw_fifo_state *fifo);
    940  1.2  riastrad extern void *
    941  1.2  riastrad vmw_fifo_reserve_dx(struct vmw_private *dev_priv, uint32_t bytes, int ctx_id);
    942  1.1  riastrad extern void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes);
    943  1.2  riastrad extern void vmw_fifo_commit_flush(struct vmw_private *dev_priv, uint32_t bytes);
    944  1.1  riastrad extern int vmw_fifo_send_fence(struct vmw_private *dev_priv,
    945  1.1  riastrad 			       uint32_t *seqno);
    946  1.2  riastrad extern void vmw_fifo_ping_host_locked(struct vmw_private *, uint32_t reason);
    947  1.1  riastrad extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
    948  1.1  riastrad extern bool vmw_fifo_have_3d(struct vmw_private *dev_priv);
    949  1.1  riastrad extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv);
    950  1.1  riastrad extern int vmw_fifo_emit_dummy_query(struct vmw_private *dev_priv,
    951  1.1  riastrad 				     uint32_t cid);
    952  1.2  riastrad extern int vmw_fifo_flush(struct vmw_private *dev_priv,
    953  1.2  riastrad 			  bool interruptible);
    954  1.1  riastrad 
    955  1.4  riastrad #define VMW_FIFO_RESERVE_DX(__priv, __bytes, __ctx_id)                        \
    956  1.4  riastrad ({                                                                            \
    957  1.4  riastrad 	vmw_fifo_reserve_dx(__priv, __bytes, __ctx_id) ? : ({                 \
    958  1.4  riastrad 		DRM_ERROR("FIFO reserve failed at %s for %u bytes\n",         \
    959  1.4  riastrad 			  __func__, (unsigned int) __bytes);                  \
    960  1.4  riastrad 		NULL;                                                         \
    961  1.4  riastrad 	});                                                                   \
    962  1.4  riastrad })
    963  1.4  riastrad 
    964  1.4  riastrad #define VMW_FIFO_RESERVE(__priv, __bytes)                                     \
    965  1.4  riastrad 	VMW_FIFO_RESERVE_DX(__priv, __bytes, SVGA3D_INVALID_ID)
    966  1.4  riastrad 
    967  1.1  riastrad /**
    968  1.1  riastrad  * TTM glue - vmwgfx_ttm_glue.c
    969  1.1  riastrad  */
    970  1.1  riastrad 
    971  1.6  riastrad #ifdef __NetBSD__
    972  1.6  riastrad struct uvm_object;
    973  1.6  riastrad extern int vmw_mmap_object(struct drm_device *, off_t, size_t, vm_prot_t,
    974  1.6  riastrad     struct uvm_object **, voff_t, struct file *);
    975  1.6  riastrad #else
    976  1.1  riastrad extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma);
    977  1.6  riastrad #endif
    978  1.1  riastrad 
    979  1.4  riastrad extern void vmw_validation_mem_init_ttm(struct vmw_private *dev_priv,
    980  1.4  riastrad 					size_t gran);
    981  1.1  riastrad /**
    982  1.4  riastrad  * TTM buffer object driver - vmwgfx_ttm_buffer.c
    983  1.1  riastrad  */
    984  1.1  riastrad 
    985  1.2  riastrad extern const size_t vmw_tt_size;
    986  1.1  riastrad extern struct ttm_placement vmw_vram_placement;
    987  1.1  riastrad extern struct ttm_placement vmw_vram_ne_placement;
    988  1.1  riastrad extern struct ttm_placement vmw_vram_sys_placement;
    989  1.1  riastrad extern struct ttm_placement vmw_vram_gmr_placement;
    990  1.1  riastrad extern struct ttm_placement vmw_vram_gmr_ne_placement;
    991  1.1  riastrad extern struct ttm_placement vmw_sys_placement;
    992  1.2  riastrad extern struct ttm_placement vmw_sys_ne_placement;
    993  1.1  riastrad extern struct ttm_placement vmw_evictable_placement;
    994  1.1  riastrad extern struct ttm_placement vmw_srf_placement;
    995  1.2  riastrad extern struct ttm_placement vmw_mob_placement;
    996  1.2  riastrad extern struct ttm_placement vmw_mob_ne_placement;
    997  1.4  riastrad extern struct ttm_placement vmw_nonfixed_placement;
    998  1.1  riastrad extern struct ttm_bo_driver vmw_bo_driver;
    999  1.1  riastrad extern int vmw_dma_quiescent(struct drm_device *dev);
   1000  1.2  riastrad extern int vmw_bo_map_dma(struct ttm_buffer_object *bo);
   1001  1.2  riastrad extern void vmw_bo_unmap_dma(struct ttm_buffer_object *bo);
   1002  1.2  riastrad extern const struct vmw_sg_table *
   1003  1.2  riastrad vmw_bo_sg_table(struct ttm_buffer_object *bo);
   1004  1.2  riastrad extern void vmw_piter_start(struct vmw_piter *viter,
   1005  1.2  riastrad 			    const struct vmw_sg_table *vsgt,
   1006  1.2  riastrad 			    unsigned long p_offs);
   1007  1.2  riastrad 
   1008  1.2  riastrad /**
   1009  1.2  riastrad  * vmw_piter_next - Advance the iterator one page.
   1010  1.2  riastrad  *
   1011  1.2  riastrad  * @viter: Pointer to the iterator to advance.
   1012  1.2  riastrad  *
   1013  1.2  riastrad  * Returns false if past the list of pages, true otherwise.
   1014  1.2  riastrad  */
   1015  1.2  riastrad static inline bool vmw_piter_next(struct vmw_piter *viter)
   1016  1.2  riastrad {
   1017  1.2  riastrad 	return viter->next(viter);
   1018  1.2  riastrad }
   1019  1.2  riastrad 
   1020  1.2  riastrad /**
   1021  1.2  riastrad  * vmw_piter_dma_addr - Return the DMA address of the current page.
   1022  1.2  riastrad  *
   1023  1.2  riastrad  * @viter: Pointer to the iterator
   1024  1.2  riastrad  *
   1025  1.2  riastrad  * Returns the DMA address of the page pointed to by @viter.
   1026  1.2  riastrad  */
   1027  1.2  riastrad static inline dma_addr_t vmw_piter_dma_addr(struct vmw_piter *viter)
   1028  1.2  riastrad {
   1029  1.2  riastrad 	return viter->dma_address(viter);
   1030  1.2  riastrad }
   1031  1.2  riastrad 
   1032  1.2  riastrad /**
   1033  1.2  riastrad  * vmw_piter_page - Return a pointer to the current page.
   1034  1.2  riastrad  *
   1035  1.2  riastrad  * @viter: Pointer to the iterator
   1036  1.2  riastrad  *
   1037  1.2  riastrad  * Returns the DMA address of the page pointed to by @viter.
   1038  1.2  riastrad  */
   1039  1.2  riastrad static inline struct page *vmw_piter_page(struct vmw_piter *viter)
   1040  1.2  riastrad {
   1041  1.2  riastrad 	return viter->page(viter);
   1042  1.2  riastrad }
   1043  1.1  riastrad 
   1044  1.1  riastrad /**
   1045  1.1  riastrad  * Command submission - vmwgfx_execbuf.c
   1046  1.1  riastrad  */
   1047  1.1  riastrad 
   1048  1.4  riastrad extern int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
   1049  1.4  riastrad 			     struct drm_file *file_priv);
   1050  1.1  riastrad extern int vmw_execbuf_process(struct drm_file *file_priv,
   1051  1.1  riastrad 			       struct vmw_private *dev_priv,
   1052  1.1  riastrad 			       void __user *user_commands,
   1053  1.1  riastrad 			       void *kernel_commands,
   1054  1.1  riastrad 			       uint32_t command_size,
   1055  1.1  riastrad 			       uint64_t throttle_us,
   1056  1.2  riastrad 			       uint32_t dx_context_handle,
   1057  1.1  riastrad 			       struct drm_vmw_fence_rep __user
   1058  1.1  riastrad 			       *user_fence_rep,
   1059  1.4  riastrad 			       struct vmw_fence_obj **out_fence,
   1060  1.4  riastrad 			       uint32_t flags);
   1061  1.1  riastrad extern void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv,
   1062  1.1  riastrad 					    struct vmw_fence_obj *fence);
   1063  1.1  riastrad extern void vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv);
   1064  1.1  riastrad 
   1065  1.1  riastrad extern int vmw_execbuf_fence_commands(struct drm_file *file_priv,
   1066  1.1  riastrad 				      struct vmw_private *dev_priv,
   1067  1.1  riastrad 				      struct vmw_fence_obj **p_fence,
   1068  1.1  riastrad 				      uint32_t *p_handle);
   1069  1.1  riastrad extern void vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
   1070  1.1  riastrad 					struct vmw_fpriv *vmw_fp,
   1071  1.1  riastrad 					int ret,
   1072  1.1  riastrad 					struct drm_vmw_fence_rep __user
   1073  1.1  riastrad 					*user_fence_rep,
   1074  1.1  riastrad 					struct vmw_fence_obj *fence,
   1075  1.4  riastrad 					uint32_t fence_handle,
   1076  1.4  riastrad 					int32_t out_fence_fd,
   1077  1.4  riastrad 					struct sync_file *sync_file);
   1078  1.4  riastrad bool vmw_cmd_describe(const void *buf, u32 *size, char const **cmd);
   1079  1.1  riastrad 
   1080  1.1  riastrad /**
   1081  1.1  riastrad  * IRQs and wating - vmwgfx_irq.c
   1082  1.1  riastrad  */
   1083  1.1  riastrad 
   1084  1.1  riastrad extern int vmw_wait_seqno(struct vmw_private *dev_priv, bool lazy,
   1085  1.2  riastrad 			  uint32_t seqno, bool interruptible,
   1086  1.2  riastrad 			  unsigned long timeout);
   1087  1.4  riastrad extern int vmw_irq_install(struct drm_device *dev, int irq);
   1088  1.1  riastrad extern void vmw_irq_uninstall(struct drm_device *dev);
   1089  1.1  riastrad extern bool vmw_seqno_passed(struct vmw_private *dev_priv,
   1090  1.1  riastrad 				uint32_t seqno);
   1091  1.1  riastrad extern int vmw_fallback_wait(struct vmw_private *dev_priv,
   1092  1.1  riastrad 			     bool lazy,
   1093  1.1  riastrad 			     bool fifo_idle,
   1094  1.1  riastrad 			     uint32_t seqno,
   1095  1.1  riastrad 			     bool interruptible,
   1096  1.1  riastrad 			     unsigned long timeout);
   1097  1.1  riastrad extern void vmw_update_seqno(struct vmw_private *dev_priv,
   1098  1.1  riastrad 				struct vmw_fifo_state *fifo_state);
   1099  1.1  riastrad extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
   1100  1.1  riastrad extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
   1101  1.1  riastrad extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
   1102  1.1  riastrad extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv);
   1103  1.2  riastrad extern void vmw_generic_waiter_add(struct vmw_private *dev_priv, u32 flag,
   1104  1.2  riastrad 				   int *waiter_count);
   1105  1.2  riastrad extern void vmw_generic_waiter_remove(struct vmw_private *dev_priv,
   1106  1.2  riastrad 				      u32 flag, int *waiter_count);
   1107  1.1  riastrad 
   1108  1.1  riastrad /**
   1109  1.1  riastrad  * Rudimentary fence-like objects currently used only for throttling -
   1110  1.1  riastrad  * vmwgfx_marker.c
   1111  1.1  riastrad  */
   1112  1.1  riastrad 
   1113  1.1  riastrad extern void vmw_marker_queue_init(struct vmw_marker_queue *queue);
   1114  1.1  riastrad extern void vmw_marker_queue_takedown(struct vmw_marker_queue *queue);
   1115  1.1  riastrad extern int vmw_marker_push(struct vmw_marker_queue *queue,
   1116  1.2  riastrad 			   uint32_t seqno);
   1117  1.1  riastrad extern int vmw_marker_pull(struct vmw_marker_queue *queue,
   1118  1.2  riastrad 			   uint32_t signaled_seqno);
   1119  1.1  riastrad extern int vmw_wait_lag(struct vmw_private *dev_priv,
   1120  1.1  riastrad 			struct vmw_marker_queue *queue, uint32_t us);
   1121  1.1  riastrad 
   1122  1.1  riastrad /**
   1123  1.1  riastrad  * Kernel framebuffer - vmwgfx_fb.c
   1124  1.1  riastrad  */
   1125  1.1  riastrad 
   1126  1.1  riastrad int vmw_fb_init(struct vmw_private *vmw_priv);
   1127  1.1  riastrad int vmw_fb_close(struct vmw_private *dev_priv);
   1128  1.1  riastrad int vmw_fb_off(struct vmw_private *vmw_priv);
   1129  1.1  riastrad int vmw_fb_on(struct vmw_private *vmw_priv);
   1130  1.1  riastrad 
   1131  1.1  riastrad /**
   1132  1.1  riastrad  * Kernel modesetting - vmwgfx_kms.c
   1133  1.1  riastrad  */
   1134  1.1  riastrad 
   1135  1.1  riastrad int vmw_kms_init(struct vmw_private *dev_priv);
   1136  1.1  riastrad int vmw_kms_close(struct vmw_private *dev_priv);
   1137  1.1  riastrad int vmw_kms_save_vga(struct vmw_private *vmw_priv);
   1138  1.1  riastrad int vmw_kms_restore_vga(struct vmw_private *vmw_priv);
   1139  1.1  riastrad int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
   1140  1.1  riastrad 				struct drm_file *file_priv);
   1141  1.1  riastrad void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
   1142  1.1  riastrad void vmw_kms_cursor_snoop(struct vmw_surface *srf,
   1143  1.1  riastrad 			  struct ttm_object_file *tfile,
   1144  1.1  riastrad 			  struct ttm_buffer_object *bo,
   1145  1.1  riastrad 			  SVGA3dCmdHeader *header);
   1146  1.1  riastrad int vmw_kms_write_svga(struct vmw_private *vmw_priv,
   1147  1.1  riastrad 		       unsigned width, unsigned height, unsigned pitch,
   1148  1.1  riastrad 		       unsigned bpp, unsigned depth);
   1149  1.1  riastrad bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
   1150  1.1  riastrad 				uint32_t pitch,
   1151  1.1  riastrad 				uint32_t height);
   1152  1.2  riastrad u32 vmw_get_vblank_counter(struct drm_device *dev, unsigned int pipe);
   1153  1.2  riastrad int vmw_enable_vblank(struct drm_device *dev, unsigned int pipe);
   1154  1.2  riastrad void vmw_disable_vblank(struct drm_device *dev, unsigned int pipe);
   1155  1.1  riastrad int vmw_kms_present(struct vmw_private *dev_priv,
   1156  1.1  riastrad 		    struct drm_file *file_priv,
   1157  1.1  riastrad 		    struct vmw_framebuffer *vfb,
   1158  1.1  riastrad 		    struct vmw_surface *surface,
   1159  1.1  riastrad 		    uint32_t sid, int32_t destX, int32_t destY,
   1160  1.1  riastrad 		    struct drm_vmw_rect *clips,
   1161  1.1  riastrad 		    uint32_t num_clips);
   1162  1.1  riastrad int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
   1163  1.1  riastrad 				struct drm_file *file_priv);
   1164  1.2  riastrad void vmw_kms_legacy_hotspot_clear(struct vmw_private *dev_priv);
   1165  1.4  riastrad int vmw_kms_suspend(struct drm_device *dev);
   1166  1.4  riastrad int vmw_kms_resume(struct drm_device *dev);
   1167  1.4  riastrad void vmw_kms_lost_device(struct drm_device *dev);
   1168  1.1  riastrad 
   1169  1.1  riastrad int vmw_dumb_create(struct drm_file *file_priv,
   1170  1.1  riastrad 		    struct drm_device *dev,
   1171  1.1  riastrad 		    struct drm_mode_create_dumb *args);
   1172  1.1  riastrad 
   1173  1.1  riastrad int vmw_dumb_map_offset(struct drm_file *file_priv,
   1174  1.1  riastrad 			struct drm_device *dev, uint32_t handle,
   1175  1.1  riastrad 			uint64_t *offset);
   1176  1.1  riastrad int vmw_dumb_destroy(struct drm_file *file_priv,
   1177  1.1  riastrad 		     struct drm_device *dev,
   1178  1.1  riastrad 		     uint32_t handle);
   1179  1.2  riastrad extern int vmw_resource_pin(struct vmw_resource *res, bool interruptible);
   1180  1.2  riastrad extern void vmw_resource_unpin(struct vmw_resource *res);
   1181  1.2  riastrad extern enum vmw_res_type vmw_res_type(const struct vmw_resource *res);
   1182  1.2  riastrad 
   1183  1.1  riastrad /**
   1184  1.1  riastrad  * Overlay control - vmwgfx_overlay.c
   1185  1.1  riastrad  */
   1186  1.1  riastrad 
   1187  1.1  riastrad int vmw_overlay_init(struct vmw_private *dev_priv);
   1188  1.1  riastrad int vmw_overlay_close(struct vmw_private *dev_priv);
   1189  1.1  riastrad int vmw_overlay_ioctl(struct drm_device *dev, void *data,
   1190  1.1  riastrad 		      struct drm_file *file_priv);
   1191  1.1  riastrad int vmw_overlay_stop_all(struct vmw_private *dev_priv);
   1192  1.1  riastrad int vmw_overlay_resume_all(struct vmw_private *dev_priv);
   1193  1.1  riastrad int vmw_overlay_pause_all(struct vmw_private *dev_priv);
   1194  1.1  riastrad int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
   1195  1.1  riastrad int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
   1196  1.1  riastrad int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
   1197  1.1  riastrad int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
   1198  1.1  riastrad 
   1199  1.1  riastrad /**
   1200  1.1  riastrad  * GMR Id manager
   1201  1.1  riastrad  */
   1202  1.1  riastrad 
   1203  1.1  riastrad extern const struct ttm_mem_type_manager_func vmw_gmrid_manager_func;
   1204  1.1  riastrad 
   1205  1.1  riastrad /**
   1206  1.2  riastrad  * Prime - vmwgfx_prime.c
   1207  1.2  riastrad  */
   1208  1.2  riastrad 
   1209  1.2  riastrad extern const struct dma_buf_ops vmw_prime_dmabuf_ops;
   1210  1.2  riastrad extern int vmw_prime_fd_to_handle(struct drm_device *dev,
   1211  1.2  riastrad 				  struct drm_file *file_priv,
   1212  1.2  riastrad 				  int fd, u32 *handle);
   1213  1.2  riastrad extern int vmw_prime_handle_to_fd(struct drm_device *dev,
   1214  1.2  riastrad 				  struct drm_file *file_priv,
   1215  1.2  riastrad 				  uint32_t handle, uint32_t flags,
   1216  1.2  riastrad 				  int *prime_fd);
   1217  1.2  riastrad 
   1218  1.2  riastrad /*
   1219  1.2  riastrad  * MemoryOBject management -  vmwgfx_mob.c
   1220  1.2  riastrad  */
   1221  1.2  riastrad struct vmw_mob;
   1222  1.2  riastrad extern int vmw_mob_bind(struct vmw_private *dev_priv, struct vmw_mob *mob,
   1223  1.2  riastrad 			const struct vmw_sg_table *vsgt,
   1224  1.2  riastrad 			unsigned long num_data_pages, int32_t mob_id);
   1225  1.2  riastrad extern void vmw_mob_unbind(struct vmw_private *dev_priv,
   1226  1.2  riastrad 			   struct vmw_mob *mob);
   1227  1.2  riastrad extern void vmw_mob_destroy(struct vmw_mob *mob);
   1228  1.2  riastrad extern struct vmw_mob *vmw_mob_create(unsigned long data_pages);
   1229  1.2  riastrad extern int vmw_otables_setup(struct vmw_private *dev_priv);
   1230  1.2  riastrad extern void vmw_otables_takedown(struct vmw_private *dev_priv);
   1231  1.2  riastrad 
   1232  1.2  riastrad /*
   1233  1.2  riastrad  * Context management - vmwgfx_context.c
   1234  1.2  riastrad  */
   1235  1.2  riastrad 
   1236  1.2  riastrad extern const struct vmw_user_resource_conv *user_context_converter;
   1237  1.2  riastrad 
   1238  1.2  riastrad extern int vmw_context_check(struct vmw_private *dev_priv,
   1239  1.2  riastrad 			     struct ttm_object_file *tfile,
   1240  1.2  riastrad 			     int id,
   1241  1.2  riastrad 			     struct vmw_resource **p_res);
   1242  1.2  riastrad extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
   1243  1.2  riastrad 				    struct drm_file *file_priv);
   1244  1.2  riastrad extern int vmw_extended_context_define_ioctl(struct drm_device *dev, void *data,
   1245  1.2  riastrad 					     struct drm_file *file_priv);
   1246  1.2  riastrad extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
   1247  1.2  riastrad 				     struct drm_file *file_priv);
   1248  1.2  riastrad extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
   1249  1.2  riastrad extern struct vmw_cmdbuf_res_manager *
   1250  1.2  riastrad vmw_context_res_man(struct vmw_resource *ctx);
   1251  1.2  riastrad extern struct vmw_resource *vmw_context_cotable(struct vmw_resource *ctx,
   1252  1.2  riastrad 						SVGACOTableType cotable_type);
   1253  1.2  riastrad extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
   1254  1.2  riastrad struct vmw_ctx_binding_state;
   1255  1.2  riastrad extern struct vmw_ctx_binding_state *
   1256  1.2  riastrad vmw_context_binding_state(struct vmw_resource *ctx);
   1257  1.2  riastrad extern void vmw_dx_context_scrub_cotables(struct vmw_resource *ctx,
   1258  1.2  riastrad 					  bool readback);
   1259  1.2  riastrad extern int vmw_context_bind_dx_query(struct vmw_resource *ctx_res,
   1260  1.4  riastrad 				     struct vmw_buffer_object *mob);
   1261  1.4  riastrad extern struct vmw_buffer_object *
   1262  1.2  riastrad vmw_context_get_dx_query_mob(struct vmw_resource *ctx_res);
   1263  1.2  riastrad 
   1264  1.2  riastrad 
   1265  1.2  riastrad /*
   1266  1.2  riastrad  * Surface management - vmwgfx_surface.c
   1267  1.2  riastrad  */
   1268  1.2  riastrad 
   1269  1.2  riastrad extern const struct vmw_user_resource_conv *user_surface_converter;
   1270  1.2  riastrad 
   1271  1.2  riastrad extern void vmw_surface_res_free(struct vmw_resource *res);
   1272  1.2  riastrad extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data,
   1273  1.2  riastrad 				     struct drm_file *file_priv);
   1274  1.2  riastrad extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
   1275  1.2  riastrad 				    struct drm_file *file_priv);
   1276  1.2  riastrad extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,
   1277  1.2  riastrad 				       struct drm_file *file_priv);
   1278  1.2  riastrad extern int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data,
   1279  1.2  riastrad 				       struct drm_file *file_priv);
   1280  1.2  riastrad extern int vmw_gb_surface_reference_ioctl(struct drm_device *dev, void *data,
   1281  1.2  riastrad 					  struct drm_file *file_priv);
   1282  1.2  riastrad extern int vmw_surface_check(struct vmw_private *dev_priv,
   1283  1.2  riastrad 			     struct ttm_object_file *tfile,
   1284  1.2  riastrad 			     uint32_t handle, int *id);
   1285  1.2  riastrad extern int vmw_surface_validate(struct vmw_private *dev_priv,
   1286  1.2  riastrad 				struct vmw_surface *srf);
   1287  1.2  riastrad int vmw_surface_gb_priv_define(struct drm_device *dev,
   1288  1.2  riastrad 			       uint32_t user_accounting_size,
   1289  1.4  riastrad 			       SVGA3dSurfaceAllFlags svga3d_flags,
   1290  1.2  riastrad 			       SVGA3dSurfaceFormat format,
   1291  1.2  riastrad 			       bool for_scanout,
   1292  1.2  riastrad 			       uint32_t num_mip_levels,
   1293  1.2  riastrad 			       uint32_t multisample_count,
   1294  1.2  riastrad 			       uint32_t array_size,
   1295  1.2  riastrad 			       struct drm_vmw_size size,
   1296  1.4  riastrad 			       SVGA3dMSPattern multisample_pattern,
   1297  1.4  riastrad 			       SVGA3dMSQualityLevel quality_level,
   1298  1.2  riastrad 			       struct vmw_surface **srf_out);
   1299  1.4  riastrad extern int vmw_gb_surface_define_ext_ioctl(struct drm_device *dev,
   1300  1.4  riastrad 					   void *data,
   1301  1.4  riastrad 					   struct drm_file *file_priv);
   1302  1.4  riastrad extern int vmw_gb_surface_reference_ext_ioctl(struct drm_device *dev,
   1303  1.4  riastrad 					      void *data,
   1304  1.4  riastrad 					      struct drm_file *file_priv);
   1305  1.2  riastrad 
   1306  1.2  riastrad /*
   1307  1.2  riastrad  * Shader management - vmwgfx_shader.c
   1308  1.2  riastrad  */
   1309  1.2  riastrad 
   1310  1.2  riastrad extern const struct vmw_user_resource_conv *user_shader_converter;
   1311  1.2  riastrad 
   1312  1.2  riastrad extern int vmw_shader_define_ioctl(struct drm_device *dev, void *data,
   1313  1.2  riastrad 				   struct drm_file *file_priv);
   1314  1.2  riastrad extern int vmw_shader_destroy_ioctl(struct drm_device *dev, void *data,
   1315  1.2  riastrad 				    struct drm_file *file_priv);
   1316  1.2  riastrad extern int vmw_compat_shader_add(struct vmw_private *dev_priv,
   1317  1.2  riastrad 				 struct vmw_cmdbuf_res_manager *man,
   1318  1.2  riastrad 				 u32 user_key, const void *bytecode,
   1319  1.2  riastrad 				 SVGA3dShaderType shader_type,
   1320  1.2  riastrad 				 size_t size,
   1321  1.2  riastrad 				 struct list_head *list);
   1322  1.2  riastrad extern int vmw_shader_remove(struct vmw_cmdbuf_res_manager *man,
   1323  1.2  riastrad 			     u32 user_key, SVGA3dShaderType shader_type,
   1324  1.2  riastrad 			     struct list_head *list);
   1325  1.2  riastrad extern int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,
   1326  1.2  riastrad 			     struct vmw_resource *ctx,
   1327  1.2  riastrad 			     u32 user_key,
   1328  1.2  riastrad 			     SVGA3dShaderType shader_type,
   1329  1.2  riastrad 			     struct list_head *list);
   1330  1.2  riastrad extern void vmw_dx_shader_cotable_list_scrub(struct vmw_private *dev_priv,
   1331  1.2  riastrad 					     struct list_head *list,
   1332  1.2  riastrad 					     bool readback);
   1333  1.2  riastrad 
   1334  1.2  riastrad extern struct vmw_resource *
   1335  1.2  riastrad vmw_shader_lookup(struct vmw_cmdbuf_res_manager *man,
   1336  1.2  riastrad 		  u32 user_key, SVGA3dShaderType shader_type);
   1337  1.2  riastrad 
   1338  1.2  riastrad /*
   1339  1.2  riastrad  * Command buffer managed resources - vmwgfx_cmdbuf_res.c
   1340  1.2  riastrad  */
   1341  1.2  riastrad 
   1342  1.2  riastrad extern struct vmw_cmdbuf_res_manager *
   1343  1.2  riastrad vmw_cmdbuf_res_man_create(struct vmw_private *dev_priv);
   1344  1.2  riastrad extern void vmw_cmdbuf_res_man_destroy(struct vmw_cmdbuf_res_manager *man);
   1345  1.2  riastrad extern size_t vmw_cmdbuf_res_man_size(void);
   1346  1.2  riastrad extern struct vmw_resource *
   1347  1.2  riastrad vmw_cmdbuf_res_lookup(struct vmw_cmdbuf_res_manager *man,
   1348  1.2  riastrad 		      enum vmw_cmdbuf_res_type res_type,
   1349  1.2  riastrad 		      u32 user_key);
   1350  1.2  riastrad extern void vmw_cmdbuf_res_revert(struct list_head *list);
   1351  1.2  riastrad extern void vmw_cmdbuf_res_commit(struct list_head *list);
   1352  1.2  riastrad extern int vmw_cmdbuf_res_add(struct vmw_cmdbuf_res_manager *man,
   1353  1.2  riastrad 			      enum vmw_cmdbuf_res_type res_type,
   1354  1.2  riastrad 			      u32 user_key,
   1355  1.2  riastrad 			      struct vmw_resource *res,
   1356  1.2  riastrad 			      struct list_head *list);
   1357  1.2  riastrad extern int vmw_cmdbuf_res_remove(struct vmw_cmdbuf_res_manager *man,
   1358  1.2  riastrad 				 enum vmw_cmdbuf_res_type res_type,
   1359  1.2  riastrad 				 u32 user_key,
   1360  1.2  riastrad 				 struct list_head *list,
   1361  1.2  riastrad 				 struct vmw_resource **res);
   1362  1.2  riastrad 
   1363  1.2  riastrad /*
   1364  1.2  riastrad  * COTable management - vmwgfx_cotable.c
   1365  1.2  riastrad  */
   1366  1.2  riastrad extern const SVGACOTableType vmw_cotable_scrub_order[];
   1367  1.2  riastrad extern struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv,
   1368  1.2  riastrad 					      struct vmw_resource *ctx,
   1369  1.2  riastrad 					      u32 type);
   1370  1.2  riastrad extern int vmw_cotable_notify(struct vmw_resource *res, int id);
   1371  1.2  riastrad extern int vmw_cotable_scrub(struct vmw_resource *res, bool readback);
   1372  1.2  riastrad extern void vmw_cotable_add_resource(struct vmw_resource *ctx,
   1373  1.2  riastrad 				     struct list_head *head);
   1374  1.2  riastrad 
   1375  1.2  riastrad /*
   1376  1.2  riastrad  * Command buffer managerment vmwgfx_cmdbuf.c
   1377  1.2  riastrad  */
   1378  1.2  riastrad struct vmw_cmdbuf_man;
   1379  1.2  riastrad struct vmw_cmdbuf_header;
   1380  1.2  riastrad 
   1381  1.2  riastrad extern struct vmw_cmdbuf_man *
   1382  1.2  riastrad vmw_cmdbuf_man_create(struct vmw_private *dev_priv);
   1383  1.2  riastrad extern int vmw_cmdbuf_set_pool_size(struct vmw_cmdbuf_man *man,
   1384  1.2  riastrad 				    size_t size, size_t default_size);
   1385  1.2  riastrad extern void vmw_cmdbuf_remove_pool(struct vmw_cmdbuf_man *man);
   1386  1.2  riastrad extern void vmw_cmdbuf_man_destroy(struct vmw_cmdbuf_man *man);
   1387  1.2  riastrad extern int vmw_cmdbuf_idle(struct vmw_cmdbuf_man *man, bool interruptible,
   1388  1.2  riastrad 			   unsigned long timeout);
   1389  1.2  riastrad extern void *vmw_cmdbuf_reserve(struct vmw_cmdbuf_man *man, size_t size,
   1390  1.2  riastrad 				int ctx_id, bool interruptible,
   1391  1.2  riastrad 				struct vmw_cmdbuf_header *header);
   1392  1.2  riastrad extern void vmw_cmdbuf_commit(struct vmw_cmdbuf_man *man, size_t size,
   1393  1.2  riastrad 			      struct vmw_cmdbuf_header *header,
   1394  1.2  riastrad 			      bool flush);
   1395  1.2  riastrad extern void *vmw_cmdbuf_alloc(struct vmw_cmdbuf_man *man,
   1396  1.2  riastrad 			      size_t size, bool interruptible,
   1397  1.2  riastrad 			      struct vmw_cmdbuf_header **p_header);
   1398  1.2  riastrad extern void vmw_cmdbuf_header_free(struct vmw_cmdbuf_header *header);
   1399  1.2  riastrad extern int vmw_cmdbuf_cur_flush(struct vmw_cmdbuf_man *man,
   1400  1.2  riastrad 				bool interruptible);
   1401  1.4  riastrad extern void vmw_cmdbuf_irqthread(struct vmw_cmdbuf_man *man);
   1402  1.2  riastrad 
   1403  1.4  riastrad /* CPU blit utilities - vmwgfx_blit.c */
   1404  1.4  riastrad 
   1405  1.4  riastrad /**
   1406  1.4  riastrad  * struct vmw_diff_cpy - CPU blit information structure
   1407  1.4  riastrad  *
   1408  1.4  riastrad  * @rect: The output bounding box rectangle.
   1409  1.4  riastrad  * @line: The current line of the blit.
   1410  1.4  riastrad  * @line_offset: Offset of the current line segment.
   1411  1.4  riastrad  * @cpp: Bytes per pixel (granularity information).
   1412  1.4  riastrad  * @memcpy: Which memcpy function to use.
   1413  1.4  riastrad  */
   1414  1.4  riastrad struct vmw_diff_cpy {
   1415  1.4  riastrad 	struct drm_rect rect;
   1416  1.4  riastrad 	size_t line;
   1417  1.4  riastrad 	size_t line_offset;
   1418  1.4  riastrad 	int cpp;
   1419  1.4  riastrad 	void (*do_cpy)(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src,
   1420  1.4  riastrad 		       size_t n);
   1421  1.4  riastrad };
   1422  1.4  riastrad 
   1423  1.4  riastrad #define VMW_CPU_BLIT_INITIALIZER {	\
   1424  1.4  riastrad 	.do_cpy = vmw_memcpy,		\
   1425  1.4  riastrad }
   1426  1.4  riastrad 
   1427  1.4  riastrad #define VMW_CPU_BLIT_DIFF_INITIALIZER(_cpp) {	  \
   1428  1.4  riastrad 	.line = 0,				  \
   1429  1.4  riastrad 	.line_offset = 0,			  \
   1430  1.4  riastrad 	.rect = { .x1 = INT_MAX/2,		  \
   1431  1.4  riastrad 		  .y1 = INT_MAX/2,		  \
   1432  1.4  riastrad 		  .x2 = INT_MIN/2,		  \
   1433  1.4  riastrad 		  .y2 = INT_MIN/2		  \
   1434  1.4  riastrad 	},					  \
   1435  1.4  riastrad 	.cpp = _cpp,				  \
   1436  1.4  riastrad 	.do_cpy = vmw_diff_memcpy,		  \
   1437  1.4  riastrad }
   1438  1.4  riastrad 
   1439  1.4  riastrad void vmw_diff_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src,
   1440  1.4  riastrad 		     size_t n);
   1441  1.4  riastrad 
   1442  1.4  riastrad void vmw_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src, size_t n);
   1443  1.4  riastrad 
   1444  1.4  riastrad int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
   1445  1.4  riastrad 		    u32 dst_offset, u32 dst_stride,
   1446  1.4  riastrad 		    struct ttm_buffer_object *src,
   1447  1.4  riastrad 		    u32 src_offset, u32 src_stride,
   1448  1.4  riastrad 		    u32 w, u32 h,
   1449  1.4  riastrad 		    struct vmw_diff_cpy *diff);
   1450  1.4  riastrad 
   1451  1.4  riastrad /* Host messaging -vmwgfx_msg.c: */
   1452  1.4  riastrad int vmw_host_get_guestinfo(const char *guest_info_param,
   1453  1.4  riastrad 			   char *buffer, size_t *length);
   1454  1.4  riastrad int vmw_host_log(const char *log);
   1455  1.4  riastrad int vmw_msg_ioctl(struct drm_device *dev, void *data,
   1456  1.4  riastrad 		  struct drm_file *file_priv);
   1457  1.4  riastrad 
   1458  1.4  riastrad /* VMW logging */
   1459  1.4  riastrad 
   1460  1.4  riastrad /**
   1461  1.4  riastrad  * VMW_DEBUG_USER - Debug output for user-space debugging.
   1462  1.4  riastrad  *
   1463  1.4  riastrad  * @fmt: printf() like format string.
   1464  1.4  riastrad  *
   1465  1.4  riastrad  * This macro is for logging user-space error and debugging messages for e.g.
   1466  1.4  riastrad  * command buffer execution errors due to malformed commands, invalid context,
   1467  1.4  riastrad  * etc.
   1468  1.4  riastrad  */
   1469  1.4  riastrad #define VMW_DEBUG_USER(fmt, ...)                                              \
   1470  1.4  riastrad 	DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__)
   1471  1.4  riastrad 
   1472  1.4  riastrad /* Resource dirtying - vmwgfx_page_dirty.c */
   1473  1.4  riastrad void vmw_bo_dirty_scan(struct vmw_buffer_object *vbo);
   1474  1.4  riastrad int vmw_bo_dirty_add(struct vmw_buffer_object *vbo);
   1475  1.4  riastrad void vmw_bo_dirty_transfer_to_res(struct vmw_resource *res);
   1476  1.4  riastrad void vmw_bo_dirty_clear_res(struct vmw_resource *res);
   1477  1.4  riastrad void vmw_bo_dirty_release(struct vmw_buffer_object *vbo);
   1478  1.4  riastrad void vmw_bo_dirty_unmap(struct vmw_buffer_object *vbo,
   1479  1.4  riastrad 			pgoff_t start, pgoff_t end);
   1480  1.6  riastrad #ifdef __NetBSD__
   1481  1.6  riastrad struct uvm_fault_info;
   1482  1.6  riastrad struct vm_page;
   1483  1.6  riastrad int vmw_bo_vm_fault(struct uvm_fault_info *, vaddr_t, struct vm_page **,
   1484  1.6  riastrad     int, int, vm_prot_t, int);
   1485  1.6  riastrad int vmw_bo_vm_mkwrite(struct uvm_fault_info *, vaddr_t, struct vm_page **,
   1486  1.6  riastrad     int, int, vm_prot_t, int);
   1487  1.6  riastrad #else
   1488  1.4  riastrad vm_fault_t vmw_bo_vm_fault(struct vm_fault *vmf);
   1489  1.4  riastrad vm_fault_t vmw_bo_vm_mkwrite(struct vm_fault *vmf);
   1490  1.6  riastrad #endif
   1491  1.4  riastrad 
   1492  1.4  riastrad /**
   1493  1.4  riastrad  * VMW_DEBUG_KMS - Debug output for kernel mode-setting
   1494  1.4  riastrad  *
   1495  1.4  riastrad  * This macro is for debugging vmwgfx mode-setting code.
   1496  1.4  riastrad  */
   1497  1.4  riastrad #define VMW_DEBUG_KMS(fmt, ...)                                               \
   1498  1.4  riastrad 	DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__)
   1499  1.2  riastrad 
   1500  1.2  riastrad /**
   1501  1.1  riastrad  * Inline helper functions
   1502  1.1  riastrad  */
   1503  1.1  riastrad 
   1504  1.1  riastrad static inline void vmw_surface_unreference(struct vmw_surface **srf)
   1505  1.1  riastrad {
   1506  1.1  riastrad 	struct vmw_surface *tmp_srf = *srf;
   1507  1.1  riastrad 	struct vmw_resource *res = &tmp_srf->res;
   1508  1.1  riastrad 	*srf = NULL;
   1509  1.1  riastrad 
   1510  1.1  riastrad 	vmw_resource_unreference(&res);
   1511  1.1  riastrad }
   1512  1.1  riastrad 
   1513  1.1  riastrad static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
   1514  1.1  riastrad {
   1515  1.1  riastrad 	(void) vmw_resource_reference(&srf->res);
   1516  1.1  riastrad 	return srf;
   1517  1.1  riastrad }
   1518  1.1  riastrad 
   1519  1.4  riastrad static inline void vmw_bo_unreference(struct vmw_buffer_object **buf)
   1520  1.1  riastrad {
   1521  1.4  riastrad 	struct vmw_buffer_object *tmp_buf = *buf;
   1522  1.1  riastrad 
   1523  1.1  riastrad 	*buf = NULL;
   1524  1.1  riastrad 	if (tmp_buf != NULL) {
   1525  1.4  riastrad 		ttm_bo_put(&tmp_buf->base);
   1526  1.1  riastrad 	}
   1527  1.1  riastrad }
   1528  1.1  riastrad 
   1529  1.4  riastrad static inline struct vmw_buffer_object *
   1530  1.4  riastrad vmw_bo_reference(struct vmw_buffer_object *buf)
   1531  1.1  riastrad {
   1532  1.4  riastrad 	ttm_bo_get(&buf->base);
   1533  1.4  riastrad 	return buf;
   1534  1.1  riastrad }
   1535  1.1  riastrad 
   1536  1.1  riastrad static inline struct ttm_mem_global *vmw_mem_glob(struct vmw_private *dev_priv)
   1537  1.1  riastrad {
   1538  1.4  riastrad 	return &ttm_mem_glob;
   1539  1.1  riastrad }
   1540  1.2  riastrad 
   1541  1.2  riastrad static inline void vmw_fifo_resource_inc(struct vmw_private *dev_priv)
   1542  1.2  riastrad {
   1543  1.2  riastrad 	atomic_inc(&dev_priv->num_fifo_resources);
   1544  1.2  riastrad }
   1545  1.2  riastrad 
   1546  1.2  riastrad static inline void vmw_fifo_resource_dec(struct vmw_private *dev_priv)
   1547  1.2  riastrad {
   1548  1.2  riastrad 	atomic_dec(&dev_priv->num_fifo_resources);
   1549  1.2  riastrad }
   1550  1.2  riastrad 
   1551  1.2  riastrad /**
   1552  1.2  riastrad  * vmw_mmio_read - Perform a MMIO read from volatile memory
   1553  1.2  riastrad  *
   1554  1.2  riastrad  * @addr: The address to read from
   1555  1.2  riastrad  *
   1556  1.2  riastrad  * This function is intended to be equivalent to ioread32() on
   1557  1.2  riastrad  * memremap'd memory, but without byteswapping.
   1558  1.2  riastrad  */
   1559  1.2  riastrad static inline u32 vmw_mmio_read(u32 *addr)
   1560  1.2  riastrad {
   1561  1.2  riastrad 	return READ_ONCE(*addr);
   1562  1.2  riastrad }
   1563  1.2  riastrad 
   1564  1.2  riastrad /**
   1565  1.2  riastrad  * vmw_mmio_write - Perform a MMIO write to volatile memory
   1566  1.2  riastrad  *
   1567  1.2  riastrad  * @addr: The address to write to
   1568  1.2  riastrad  *
   1569  1.2  riastrad  * This function is intended to be equivalent to iowrite32 on
   1570  1.2  riastrad  * memremap'd memory, but without byteswapping.
   1571  1.2  riastrad  */
   1572  1.2  riastrad static inline void vmw_mmio_write(u32 value, u32 *addr)
   1573  1.2  riastrad {
   1574  1.2  riastrad 	WRITE_ONCE(*addr, value);
   1575  1.2  riastrad }
   1576  1.1  riastrad #endif
   1577