Back to home page

LXR

 
 

    


0001 /**************************************************************************
0002  *
0003  * Copyright © 2009-2015 VMware, Inc., Palo Alto, CA., USA
0004  * All Rights Reserved.
0005  *
0006  * Permission is hereby granted, free of charge, to any person obtaining a
0007  * copy of this software and associated documentation files (the
0008  * "Software"), to deal in the Software without restriction, including
0009  * without limitation the rights to use, copy, modify, merge, publish,
0010  * distribute, sub license, and/or sell copies of the Software, and to
0011  * permit persons to whom the Software is furnished to do so, subject to
0012  * the following conditions:
0013  *
0014  * The above copyright notice and this permission notice (including the
0015  * next paragraph) shall be included in all copies or substantial portions
0016  * of the Software.
0017  *
0018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0019  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0020  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
0021  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
0022  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
0023  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
0024  * USE OR OTHER DEALINGS IN THE SOFTWARE.
0025  *
0026  **************************************************************************/
0027 
0028 #ifndef _VMWGFX_DRV_H_
0029 #define _VMWGFX_DRV_H_
0030 
0031 #include "vmwgfx_reg.h"
0032 #include <drm/drmP.h>
0033 #include <drm/vmwgfx_drm.h>
0034 #include <drm/drm_hashtab.h>
0035 #include <drm/drm_auth.h>
0036 #include <linux/suspend.h>
0037 #include <drm/ttm/ttm_bo_driver.h>
0038 #include <drm/ttm/ttm_object.h>
0039 #include <drm/ttm/ttm_lock.h>
0040 #include <drm/ttm/ttm_execbuf_util.h>
0041 #include <drm/ttm/ttm_module.h>
0042 #include "vmwgfx_fence.h"
0043 
0044 #define VMWGFX_DRIVER_DATE "20160210"
0045 #define VMWGFX_DRIVER_MAJOR 2
0046 #define VMWGFX_DRIVER_MINOR 11
0047 #define VMWGFX_DRIVER_PATCHLEVEL 0
0048 #define VMWGFX_FILE_PAGE_OFFSET 0x00100000
0049 #define VMWGFX_FIFO_STATIC_SIZE (1024*1024)
0050 #define VMWGFX_MAX_RELOCATIONS 2048
0051 #define VMWGFX_MAX_VALIDATIONS 2048
0052 #define VMWGFX_MAX_DISPLAYS 16
0053 #define VMWGFX_CMD_BOUNCE_INIT_SIZE 32768
0054 #define VMWGFX_ENABLE_SCREEN_TARGET_OTABLE 1
0055 
0056 /*
0057  * Perhaps we should have sysfs entries for these.
0058  */
0059 #define VMWGFX_NUM_GB_CONTEXT 256
0060 #define VMWGFX_NUM_GB_SHADER 20000
0061 #define VMWGFX_NUM_GB_SURFACE 32768
0062 #define VMWGFX_NUM_GB_SCREEN_TARGET VMWGFX_MAX_DISPLAYS
0063 #define VMWGFX_NUM_DXCONTEXT 256
0064 #define VMWGFX_NUM_DXQUERY 512
0065 #define VMWGFX_NUM_MOB (VMWGFX_NUM_GB_CONTEXT +\
0066             VMWGFX_NUM_GB_SHADER +\
0067             VMWGFX_NUM_GB_SURFACE +\
0068             VMWGFX_NUM_GB_SCREEN_TARGET)
0069 
0070 #define VMW_PL_GMR (TTM_PL_PRIV + 0)
0071 #define VMW_PL_FLAG_GMR (TTM_PL_FLAG_PRIV << 0)
0072 #define VMW_PL_MOB (TTM_PL_PRIV + 1)
0073 #define VMW_PL_FLAG_MOB (TTM_PL_FLAG_PRIV << 1)
0074 
0075 #define VMW_RES_CONTEXT ttm_driver_type0
0076 #define VMW_RES_SURFACE ttm_driver_type1
0077 #define VMW_RES_STREAM ttm_driver_type2
0078 #define VMW_RES_FENCE ttm_driver_type3
0079 #define VMW_RES_SHADER ttm_driver_type4
0080 
0081 struct vmw_fpriv {
0082     struct drm_master *locked_master;
0083     struct ttm_object_file *tfile;
0084     bool gb_aware;
0085 };
0086 
0087 struct vmw_dma_buffer {
0088     struct ttm_buffer_object base;
0089     struct list_head res_list;
0090     s32 pin_count;
0091     /* Not ref-counted.  Protected by binding_mutex */
0092     struct vmw_resource *dx_query_ctx;
0093 };
0094 
0095 /**
0096  * struct vmw_validate_buffer - Carries validation info about buffers.
0097  *
0098  * @base: Validation info for TTM.
0099  * @hash: Hash entry for quick lookup of the TTM buffer object.
0100  *
0101  * This structure contains also driver private validation info
0102  * on top of the info needed by TTM.
0103  */
0104 struct vmw_validate_buffer {
0105     struct ttm_validate_buffer base;
0106     struct drm_hash_item hash;
0107     bool validate_as_mob;
0108 };
0109 
0110 struct vmw_res_func;
0111 struct vmw_resource {
0112     struct kref kref;
0113     struct vmw_private *dev_priv;
0114     int id;
0115     bool avail;
0116     unsigned long backup_size;
0117     bool res_dirty; /* Protected by backup buffer reserved */
0118     bool backup_dirty; /* Protected by backup buffer reserved */
0119     struct vmw_dma_buffer *backup;
0120     unsigned long backup_offset;
0121     unsigned long pin_count; /* Protected by resource reserved */
0122     const struct vmw_res_func *func;
0123     struct list_head lru_head; /* Protected by the resource lock */
0124     struct list_head mob_head; /* Protected by @backup reserved */
0125     struct list_head binding_head; /* Protected by binding_mutex */
0126     void (*res_free) (struct vmw_resource *res);
0127     void (*hw_destroy) (struct vmw_resource *res);
0128 };
0129 
0130 
0131 /*
0132  * Resources that are managed using ioctls.
0133  */
0134 enum vmw_res_type {
0135     vmw_res_context,
0136     vmw_res_surface,
0137     vmw_res_stream,
0138     vmw_res_shader,
0139     vmw_res_dx_context,
0140     vmw_res_cotable,
0141     vmw_res_view,
0142     vmw_res_max
0143 };
0144 
0145 /*
0146  * Resources that are managed using command streams.
0147  */
0148 enum vmw_cmdbuf_res_type {
0149     vmw_cmdbuf_res_shader,
0150     vmw_cmdbuf_res_view
0151 };
0152 
0153 struct vmw_cmdbuf_res_manager;
0154 
0155 struct vmw_cursor_snooper {
0156     struct drm_crtc *crtc;
0157     size_t age;
0158     uint32_t *image;
0159 };
0160 
0161 struct vmw_framebuffer;
0162 struct vmw_surface_offset;
0163 
0164 struct vmw_surface {
0165     struct vmw_resource res;
0166     uint32_t flags;
0167     uint32_t format;
0168     uint32_t mip_levels[DRM_VMW_MAX_SURFACE_FACES];
0169     struct drm_vmw_size base_size;
0170     struct drm_vmw_size *sizes;
0171     uint32_t num_sizes;
0172     bool scanout;
0173     uint32_t array_size;
0174     /* TODO so far just a extra pointer */
0175     struct vmw_cursor_snooper snooper;
0176     struct vmw_surface_offset *offsets;
0177     SVGA3dTextureFilter autogen_filter;
0178     uint32_t multisample_count;
0179     struct list_head view_list;
0180 };
0181 
0182 struct vmw_marker_queue {
0183     struct list_head head;
0184     u64 lag;
0185     u64 lag_time;
0186     spinlock_t lock;
0187 };
0188 
0189 struct vmw_fifo_state {
0190     unsigned long reserved_size;
0191     u32 *dynamic_buffer;
0192     u32 *static_buffer;
0193     unsigned long static_buffer_size;
0194     bool using_bounce_buffer;
0195     uint32_t capabilities;
0196     struct mutex fifo_mutex;
0197     struct rw_semaphore rwsem;
0198     struct vmw_marker_queue marker_queue;
0199     bool dx;
0200 };
0201 
0202 struct vmw_relocation {
0203     SVGAMobId *mob_loc;
0204     SVGAGuestPtr *location;
0205     uint32_t index;
0206 };
0207 
0208 /**
0209  * struct vmw_res_cache_entry - resource information cache entry
0210  *
0211  * @valid: Whether the entry is valid, which also implies that the execbuf
0212  * code holds a reference to the resource, and it's placed on the
0213  * validation list.
0214  * @handle: User-space handle of a resource.
0215  * @res: Non-ref-counted pointer to the resource.
0216  *
0217  * Used to avoid frequent repeated user-space handle lookups of the
0218  * same resource.
0219  */
0220 struct vmw_res_cache_entry {
0221     bool valid;
0222     uint32_t handle;
0223     struct vmw_resource *res;
0224     struct vmw_resource_val_node *node;
0225 };
0226 
0227 /**
0228  * enum vmw_dma_map_mode - indicate how to perform TTM page dma mappings.
0229  */
0230 enum vmw_dma_map_mode {
0231     vmw_dma_phys,           /* Use physical page addresses */
0232     vmw_dma_alloc_coherent, /* Use TTM coherent pages */
0233     vmw_dma_map_populate,   /* Unmap from DMA just after unpopulate */
0234     vmw_dma_map_bind,       /* Unmap from DMA just before unbind */
0235     vmw_dma_map_max
0236 };
0237 
0238 /**
0239  * struct vmw_sg_table - Scatter/gather table for binding, with additional
0240  * device-specific information.
0241  *
0242  * @sgt: Pointer to a struct sg_table with binding information
0243  * @num_regions: Number of regions with device-address contiguous pages
0244  */
0245 struct vmw_sg_table {
0246     enum vmw_dma_map_mode mode;
0247     struct page **pages;
0248     const dma_addr_t *addrs;
0249     struct sg_table *sgt;
0250     unsigned long num_regions;
0251     unsigned long num_pages;
0252 };
0253 
0254 /**
0255  * struct vmw_piter - Page iterator that iterates over a list of pages
0256  * and DMA addresses that could be either a scatter-gather list or
0257  * arrays
0258  *
0259  * @pages: Array of page pointers to the pages.
0260  * @addrs: DMA addresses to the pages if coherent pages are used.
0261  * @iter: Scatter-gather page iterator. Current position in SG list.
0262  * @i: Current position in arrays.
0263  * @num_pages: Number of pages total.
0264  * @next: Function to advance the iterator. Returns false if past the list
0265  * of pages, true otherwise.
0266  * @dma_address: Function to return the DMA address of the current page.
0267  */
0268 struct vmw_piter {
0269     struct page **pages;
0270     const dma_addr_t *addrs;
0271     struct sg_page_iter iter;
0272     unsigned long i;
0273     unsigned long num_pages;
0274     bool (*next)(struct vmw_piter *);
0275     dma_addr_t (*dma_address)(struct vmw_piter *);
0276     struct page *(*page)(struct vmw_piter *);
0277 };
0278 
0279 /*
0280  * enum vmw_display_unit_type - Describes the display unit
0281  */
0282 enum vmw_display_unit_type {
0283     vmw_du_invalid = 0,
0284     vmw_du_legacy,
0285     vmw_du_screen_object,
0286     vmw_du_screen_target
0287 };
0288 
0289 
0290 struct vmw_sw_context{
0291     struct drm_open_hash res_ht;
0292     bool res_ht_initialized;
0293     bool kernel; /**< is the called made from the kernel */
0294     struct vmw_fpriv *fp;
0295     struct list_head validate_nodes;
0296     struct vmw_relocation relocs[VMWGFX_MAX_RELOCATIONS];
0297     uint32_t cur_reloc;
0298     struct vmw_validate_buffer val_bufs[VMWGFX_MAX_VALIDATIONS];
0299     uint32_t cur_val_buf;
0300     uint32_t *cmd_bounce;
0301     uint32_t cmd_bounce_size;
0302     struct list_head resource_list;
0303     struct list_head ctx_resource_list; /* For contexts and cotables */
0304     struct vmw_dma_buffer *cur_query_bo;
0305     struct list_head res_relocations;
0306     uint32_t *buf_start;
0307     struct vmw_res_cache_entry res_cache[vmw_res_max];
0308     struct vmw_resource *last_query_ctx;
0309     bool needs_post_query_barrier;
0310     struct vmw_resource *error_resource;
0311     struct vmw_ctx_binding_state *staged_bindings;
0312     bool staged_bindings_inuse;
0313     struct list_head staged_cmd_res;
0314     struct vmw_resource_val_node *dx_ctx_node;
0315     struct vmw_dma_buffer *dx_query_mob;
0316     struct vmw_resource *dx_query_ctx;
0317     struct vmw_cmdbuf_res_manager *man;
0318 };
0319 
0320 struct vmw_legacy_display;
0321 struct vmw_overlay;
0322 
0323 struct vmw_master {
0324     struct ttm_lock lock;
0325 };
0326 
0327 struct vmw_vga_topology_state {
0328     uint32_t width;
0329     uint32_t height;
0330     uint32_t primary;
0331     uint32_t pos_x;
0332     uint32_t pos_y;
0333 };
0334 
0335 
0336 /*
0337  * struct vmw_otable - Guest Memory OBject table metadata
0338  *
0339  * @size:           Size of the table (page-aligned).
0340  * @page_table:     Pointer to a struct vmw_mob holding the page table.
0341  */
0342 struct vmw_otable {
0343     unsigned long size;
0344     struct vmw_mob *page_table;
0345     bool enabled;
0346 };
0347 
0348 struct vmw_otable_batch {
0349     unsigned num_otables;
0350     struct vmw_otable *otables;
0351     struct vmw_resource *context;
0352     struct ttm_buffer_object *otable_bo;
0353 };
0354 
0355 struct vmw_private {
0356     struct ttm_bo_device bdev;
0357     struct ttm_bo_global_ref bo_global_ref;
0358     struct drm_global_reference mem_global_ref;
0359 
0360     struct vmw_fifo_state fifo;
0361 
0362     struct drm_device *dev;
0363     unsigned long vmw_chipset;
0364     unsigned int io_start;
0365     uint32_t vram_start;
0366     uint32_t vram_size;
0367     uint32_t prim_bb_mem;
0368     uint32_t mmio_start;
0369     uint32_t mmio_size;
0370     uint32_t fb_max_width;
0371     uint32_t fb_max_height;
0372     uint32_t texture_max_width;
0373     uint32_t texture_max_height;
0374     uint32_t stdu_max_width;
0375     uint32_t stdu_max_height;
0376     uint32_t initial_width;
0377     uint32_t initial_height;
0378     u32 *mmio_virt;
0379     uint32_t capabilities;
0380     uint32_t max_gmr_ids;
0381     uint32_t max_gmr_pages;
0382     uint32_t max_mob_pages;
0383     uint32_t max_mob_size;
0384     uint32_t memory_size;
0385     bool has_gmr;
0386     bool has_mob;
0387     spinlock_t hw_lock;
0388     spinlock_t cap_lock;
0389     bool has_dx;
0390     bool assume_16bpp;
0391 
0392     /*
0393      * VGA registers.
0394      */
0395 
0396     struct vmw_vga_topology_state vga_save[VMWGFX_MAX_DISPLAYS];
0397     uint32_t vga_width;
0398     uint32_t vga_height;
0399     uint32_t vga_bpp;
0400     uint32_t vga_bpl;
0401     uint32_t vga_pitchlock;
0402 
0403     uint32_t num_displays;
0404 
0405     /*
0406      * Framebuffer info.
0407      */
0408 
0409     void *fb_info;
0410     enum vmw_display_unit_type active_display_unit;
0411     struct vmw_legacy_display *ldu_priv;
0412     struct vmw_overlay *overlay_priv;
0413     struct drm_property *hotplug_mode_update_property;
0414     struct drm_property *implicit_placement_property;
0415     unsigned num_implicit;
0416     struct vmw_framebuffer *implicit_fb;
0417     struct mutex global_kms_state_mutex;
0418 
0419     /*
0420      * Context and surface management.
0421      */
0422 
0423     rwlock_t resource_lock;
0424     struct idr res_idr[vmw_res_max];
0425     /*
0426      * Block lastclose from racing with firstopen.
0427      */
0428 
0429     struct mutex init_mutex;
0430 
0431     /*
0432      * A resource manager for kernel-only surfaces and
0433      * contexts.
0434      */
0435 
0436     struct ttm_object_device *tdev;
0437 
0438     /*
0439      * Fencing and IRQs.
0440      */
0441 
0442     atomic_t marker_seq;
0443     wait_queue_head_t fence_queue;
0444     wait_queue_head_t fifo_queue;
0445     spinlock_t waiter_lock;
0446     int fence_queue_waiters; /* Protected by waiter_lock */
0447     int goal_queue_waiters; /* Protected by waiter_lock */
0448     int cmdbuf_waiters; /* Protected by waiter_lock */
0449     int error_waiters; /* Protected by waiter_lock */
0450     int fifo_queue_waiters; /* Protected by waiter_lock */
0451     uint32_t last_read_seqno;
0452     struct vmw_fence_manager *fman;
0453     uint32_t irq_mask; /* Updates protected by waiter_lock */
0454 
0455     /*
0456      * Device state
0457      */
0458 
0459     uint32_t traces_state;
0460     uint32_t enable_state;
0461     uint32_t config_done_state;
0462 
0463     /**
0464      * Execbuf
0465      */
0466     /**
0467      * Protected by the cmdbuf mutex.
0468      */
0469 
0470     struct vmw_sw_context ctx;
0471     struct mutex cmdbuf_mutex;
0472     struct mutex binding_mutex;
0473 
0474     /**
0475      * Operating mode.
0476      */
0477 
0478     bool stealth;
0479     bool enable_fb;
0480     spinlock_t svga_lock;
0481 
0482     /**
0483      * Master management.
0484      */
0485 
0486     struct vmw_master *active_master;
0487     struct vmw_master fbdev_master;
0488     struct notifier_block pm_nb;
0489     bool suspended;
0490     bool refuse_hibernation;
0491 
0492     struct mutex release_mutex;
0493     atomic_t num_fifo_resources;
0494 
0495     /*
0496      * Replace this with an rwsem as soon as we have down_xx_interruptible()
0497      */
0498     struct ttm_lock reservation_sem;
0499 
0500     /*
0501      * Query processing. These members
0502      * are protected by the cmdbuf mutex.
0503      */
0504 
0505     struct vmw_dma_buffer *dummy_query_bo;
0506     struct vmw_dma_buffer *pinned_bo;
0507     uint32_t query_cid;
0508     uint32_t query_cid_valid;
0509     bool dummy_query_bo_pinned;
0510 
0511     /*
0512      * Surface swapping. The "surface_lru" list is protected by the
0513      * resource lock in order to be able to destroy a surface and take
0514      * it off the lru atomically. "used_memory_size" is currently
0515      * protected by the cmdbuf mutex for simplicity.
0516      */
0517 
0518     struct list_head res_lru[vmw_res_max];
0519     uint32_t used_memory_size;
0520 
0521     /*
0522      * DMA mapping stuff.
0523      */
0524     enum vmw_dma_map_mode map_mode;
0525 
0526     /*
0527      * Guest Backed stuff
0528      */
0529     struct vmw_otable_batch otable_batch;
0530 
0531     struct vmw_cmdbuf_man *cman;
0532 };
0533 
0534 static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res)
0535 {
0536     return container_of(res, struct vmw_surface, res);
0537 }
0538 
0539 static inline struct vmw_private *vmw_priv(struct drm_device *dev)
0540 {
0541     return (struct vmw_private *)dev->dev_private;
0542 }
0543 
0544 static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
0545 {
0546     return (struct vmw_fpriv *)file_priv->driver_priv;
0547 }
0548 
0549 static inline struct vmw_master *vmw_master(struct drm_master *master)
0550 {
0551     return (struct vmw_master *) master->driver_priv;
0552 }
0553 
0554 /*
0555  * The locking here is fine-grained, so that it is performed once
0556  * for every read- and write operation. This is of course costly, but we
0557  * don't perform much register access in the timing critical paths anyway.
0558  * Instead we have the extra benefit of being sure that we don't forget
0559  * the hw lock around register accesses.
0560  */
0561 static inline void vmw_write(struct vmw_private *dev_priv,
0562                  unsigned int offset, uint32_t value)
0563 {
0564     unsigned long irq_flags;
0565 
0566     spin_lock_irqsave(&dev_priv->hw_lock, irq_flags);
0567     outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
0568     outl(value, dev_priv->io_start + VMWGFX_VALUE_PORT);
0569     spin_unlock_irqrestore(&dev_priv->hw_lock, irq_flags);
0570 }
0571 
0572 static inline uint32_t vmw_read(struct vmw_private *dev_priv,
0573                 unsigned int offset)
0574 {
0575     unsigned long irq_flags;
0576     u32 val;
0577 
0578     spin_lock_irqsave(&dev_priv->hw_lock, irq_flags);
0579     outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
0580     val = inl(dev_priv->io_start + VMWGFX_VALUE_PORT);
0581     spin_unlock_irqrestore(&dev_priv->hw_lock, irq_flags);
0582 
0583     return val;
0584 }
0585 
0586 extern void vmw_svga_enable(struct vmw_private *dev_priv);
0587 extern void vmw_svga_disable(struct vmw_private *dev_priv);
0588 
0589 
0590 /**
0591  * GMR utilities - vmwgfx_gmr.c
0592  */
0593 
0594 extern int vmw_gmr_bind(struct vmw_private *dev_priv,
0595             const struct vmw_sg_table *vsgt,
0596             unsigned long num_pages,
0597             int gmr_id);
0598 extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
0599 
0600 /**
0601  * Resource utilities - vmwgfx_resource.c
0602  */
0603 struct vmw_user_resource_conv;
0604 
0605 extern void vmw_resource_unreference(struct vmw_resource **p_res);
0606 extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
0607 extern struct vmw_resource *
0608 vmw_resource_reference_unless_doomed(struct vmw_resource *res);
0609 extern int vmw_resource_validate(struct vmw_resource *res);
0610 extern int vmw_resource_reserve(struct vmw_resource *res, bool interruptible,
0611                 bool no_backup);
0612 extern bool vmw_resource_needs_backup(const struct vmw_resource *res);
0613 extern int vmw_user_lookup_handle(struct vmw_private *dev_priv,
0614                   struct ttm_object_file *tfile,
0615                   uint32_t handle,
0616                   struct vmw_surface **out_surf,
0617                   struct vmw_dma_buffer **out_buf);
0618 extern int vmw_user_resource_lookup_handle(
0619     struct vmw_private *dev_priv,
0620     struct ttm_object_file *tfile,
0621     uint32_t handle,
0622     const struct vmw_user_resource_conv *converter,
0623     struct vmw_resource **p_res);
0624 extern void vmw_dmabuf_bo_free(struct ttm_buffer_object *bo);
0625 extern int vmw_dmabuf_init(struct vmw_private *dev_priv,
0626                struct vmw_dma_buffer *vmw_bo,
0627                size_t size, struct ttm_placement *placement,
0628                bool interuptable,
0629                void (*bo_free) (struct ttm_buffer_object *bo));
0630 extern int vmw_user_dmabuf_verify_access(struct ttm_buffer_object *bo,
0631                   struct ttm_object_file *tfile);
0632 extern int vmw_user_dmabuf_alloc(struct vmw_private *dev_priv,
0633                  struct ttm_object_file *tfile,
0634                  uint32_t size,
0635                  bool shareable,
0636                  uint32_t *handle,
0637                  struct vmw_dma_buffer **p_dma_buf,
0638                  struct ttm_base_object **p_base);
0639 extern int vmw_user_dmabuf_reference(struct ttm_object_file *tfile,
0640                      struct vmw_dma_buffer *dma_buf,
0641                      uint32_t *handle);
0642 extern int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data,
0643                   struct drm_file *file_priv);
0644 extern int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data,
0645                   struct drm_file *file_priv);
0646 extern int vmw_user_dmabuf_synccpu_ioctl(struct drm_device *dev, void *data,
0647                      struct drm_file *file_priv);
0648 extern uint32_t vmw_dmabuf_validate_node(struct ttm_buffer_object *bo,
0649                      uint32_t cur_validate_node);
0650 extern void vmw_dmabuf_validate_clear(struct ttm_buffer_object *bo);
0651 extern int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile,
0652                   uint32_t id, struct vmw_dma_buffer **out,
0653                   struct ttm_base_object **base);
0654 extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
0655                   struct drm_file *file_priv);
0656 extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
0657                   struct drm_file *file_priv);
0658 extern int vmw_user_stream_lookup(struct vmw_private *dev_priv,
0659                   struct ttm_object_file *tfile,
0660                   uint32_t *inout_id,
0661                   struct vmw_resource **out);
0662 extern void vmw_resource_unreserve(struct vmw_resource *res,
0663                    bool switch_backup,
0664                    struct vmw_dma_buffer *new_backup,
0665                    unsigned long new_backup_offset);
0666 extern void vmw_resource_move_notify(struct ttm_buffer_object *bo,
0667                      struct ttm_mem_reg *mem);
0668 extern void vmw_query_move_notify(struct ttm_buffer_object *bo,
0669                   struct ttm_mem_reg *mem);
0670 extern int vmw_query_readback_all(struct vmw_dma_buffer *dx_query_mob);
0671 extern void vmw_fence_single_bo(struct ttm_buffer_object *bo,
0672                 struct vmw_fence_obj *fence);
0673 extern void vmw_resource_evict_all(struct vmw_private *dev_priv);
0674 
0675 /**
0676  * DMA buffer helper routines - vmwgfx_dmabuf.c
0677  */
0678 extern int vmw_dmabuf_pin_in_placement(struct vmw_private *vmw_priv,
0679                        struct vmw_dma_buffer *bo,
0680                        struct ttm_placement *placement,
0681                        bool interruptible);
0682 extern int vmw_dmabuf_pin_in_vram(struct vmw_private *dev_priv,
0683                   struct vmw_dma_buffer *buf,
0684                   bool interruptible);
0685 extern int vmw_dmabuf_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
0686                      struct vmw_dma_buffer *buf,
0687                      bool interruptible);
0688 extern int vmw_dmabuf_pin_in_start_of_vram(struct vmw_private *vmw_priv,
0689                        struct vmw_dma_buffer *bo,
0690                        bool interruptible);
0691 extern int vmw_dmabuf_unpin(struct vmw_private *vmw_priv,
0692                 struct vmw_dma_buffer *bo,
0693                 bool interruptible);
0694 extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf,
0695                  SVGAGuestPtr *ptr);
0696 extern void vmw_bo_pin_reserved(struct vmw_dma_buffer *bo, bool pin);
0697 
0698 /**
0699  * Misc Ioctl functionality - vmwgfx_ioctl.c
0700  */
0701 
0702 extern int vmw_getparam_ioctl(struct drm_device *dev, void *data,
0703                   struct drm_file *file_priv);
0704 extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
0705                 struct drm_file *file_priv);
0706 extern int vmw_present_ioctl(struct drm_device *dev, void *data,
0707                  struct drm_file *file_priv);
0708 extern int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
0709                       struct drm_file *file_priv);
0710 extern unsigned int vmw_fops_poll(struct file *filp,
0711                   struct poll_table_struct *wait);
0712 extern ssize_t vmw_fops_read(struct file *filp, char __user *buffer,
0713                  size_t count, loff_t *offset);
0714 
0715 /**
0716  * Fifo utilities - vmwgfx_fifo.c
0717  */
0718 
0719 extern int vmw_fifo_init(struct vmw_private *dev_priv,
0720              struct vmw_fifo_state *fifo);
0721 extern void vmw_fifo_release(struct vmw_private *dev_priv,
0722                  struct vmw_fifo_state *fifo);
0723 extern void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes);
0724 extern void *
0725 vmw_fifo_reserve_dx(struct vmw_private *dev_priv, uint32_t bytes, int ctx_id);
0726 extern void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes);
0727 extern void vmw_fifo_commit_flush(struct vmw_private *dev_priv, uint32_t bytes);
0728 extern int vmw_fifo_send_fence(struct vmw_private *dev_priv,
0729                    uint32_t *seqno);
0730 extern void vmw_fifo_ping_host_locked(struct vmw_private *, uint32_t reason);
0731 extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
0732 extern bool vmw_fifo_have_3d(struct vmw_private *dev_priv);
0733 extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv);
0734 extern int vmw_fifo_emit_dummy_query(struct vmw_private *dev_priv,
0735                      uint32_t cid);
0736 extern int vmw_fifo_flush(struct vmw_private *dev_priv,
0737               bool interruptible);
0738 
0739 /**
0740  * TTM glue - vmwgfx_ttm_glue.c
0741  */
0742 
0743 extern int vmw_ttm_global_init(struct vmw_private *dev_priv);
0744 extern void vmw_ttm_global_release(struct vmw_private *dev_priv);
0745 extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma);
0746 
0747 /**
0748  * TTM buffer object driver - vmwgfx_buffer.c
0749  */
0750 
0751 extern const size_t vmw_tt_size;
0752 extern struct ttm_placement vmw_vram_placement;
0753 extern struct ttm_placement vmw_vram_ne_placement;
0754 extern struct ttm_placement vmw_vram_sys_placement;
0755 extern struct ttm_placement vmw_vram_gmr_placement;
0756 extern struct ttm_placement vmw_vram_gmr_ne_placement;
0757 extern struct ttm_placement vmw_sys_placement;
0758 extern struct ttm_placement vmw_sys_ne_placement;
0759 extern struct ttm_placement vmw_evictable_placement;
0760 extern struct ttm_placement vmw_srf_placement;
0761 extern struct ttm_placement vmw_mob_placement;
0762 extern struct ttm_placement vmw_mob_ne_placement;
0763 extern struct ttm_bo_driver vmw_bo_driver;
0764 extern int vmw_dma_quiescent(struct drm_device *dev);
0765 extern int vmw_bo_map_dma(struct ttm_buffer_object *bo);
0766 extern void vmw_bo_unmap_dma(struct ttm_buffer_object *bo);
0767 extern const struct vmw_sg_table *
0768 vmw_bo_sg_table(struct ttm_buffer_object *bo);
0769 extern void vmw_piter_start(struct vmw_piter *viter,
0770                 const struct vmw_sg_table *vsgt,
0771                 unsigned long p_offs);
0772 
0773 /**
0774  * vmw_piter_next - Advance the iterator one page.
0775  *
0776  * @viter: Pointer to the iterator to advance.
0777  *
0778  * Returns false if past the list of pages, true otherwise.
0779  */
0780 static inline bool vmw_piter_next(struct vmw_piter *viter)
0781 {
0782     return viter->next(viter);
0783 }
0784 
0785 /**
0786  * vmw_piter_dma_addr - Return the DMA address of the current page.
0787  *
0788  * @viter: Pointer to the iterator
0789  *
0790  * Returns the DMA address of the page pointed to by @viter.
0791  */
0792 static inline dma_addr_t vmw_piter_dma_addr(struct vmw_piter *viter)
0793 {
0794     return viter->dma_address(viter);
0795 }
0796 
0797 /**
0798  * vmw_piter_page - Return a pointer to the current page.
0799  *
0800  * @viter: Pointer to the iterator
0801  *
0802  * Returns the DMA address of the page pointed to by @viter.
0803  */
0804 static inline struct page *vmw_piter_page(struct vmw_piter *viter)
0805 {
0806     return viter->page(viter);
0807 }
0808 
0809 /**
0810  * Command submission - vmwgfx_execbuf.c
0811  */
0812 
0813 extern int vmw_execbuf_ioctl(struct drm_device *dev, unsigned long data,
0814                  struct drm_file *file_priv, size_t size);
0815 extern int vmw_execbuf_process(struct drm_file *file_priv,
0816                    struct vmw_private *dev_priv,
0817                    void __user *user_commands,
0818                    void *kernel_commands,
0819                    uint32_t command_size,
0820                    uint64_t throttle_us,
0821                    uint32_t dx_context_handle,
0822                    struct drm_vmw_fence_rep __user
0823                    *user_fence_rep,
0824                    struct vmw_fence_obj **out_fence);
0825 extern void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv,
0826                         struct vmw_fence_obj *fence);
0827 extern void vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv);
0828 
0829 extern int vmw_execbuf_fence_commands(struct drm_file *file_priv,
0830                       struct vmw_private *dev_priv,
0831                       struct vmw_fence_obj **p_fence,
0832                       uint32_t *p_handle);
0833 extern void vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
0834                     struct vmw_fpriv *vmw_fp,
0835                     int ret,
0836                     struct drm_vmw_fence_rep __user
0837                     *user_fence_rep,
0838                     struct vmw_fence_obj *fence,
0839                     uint32_t fence_handle);
0840 extern int vmw_validate_single_buffer(struct vmw_private *dev_priv,
0841                       struct ttm_buffer_object *bo,
0842                       bool interruptible,
0843                       bool validate_as_mob);
0844 
0845 
0846 /**
0847  * IRQs and wating - vmwgfx_irq.c
0848  */
0849 
0850 extern irqreturn_t vmw_irq_handler(int irq, void *arg);
0851 extern int vmw_wait_seqno(struct vmw_private *dev_priv, bool lazy,
0852               uint32_t seqno, bool interruptible,
0853               unsigned long timeout);
0854 extern void vmw_irq_preinstall(struct drm_device *dev);
0855 extern int vmw_irq_postinstall(struct drm_device *dev);
0856 extern void vmw_irq_uninstall(struct drm_device *dev);
0857 extern bool vmw_seqno_passed(struct vmw_private *dev_priv,
0858                 uint32_t seqno);
0859 extern int vmw_fallback_wait(struct vmw_private *dev_priv,
0860                  bool lazy,
0861                  bool fifo_idle,
0862                  uint32_t seqno,
0863                  bool interruptible,
0864                  unsigned long timeout);
0865 extern void vmw_update_seqno(struct vmw_private *dev_priv,
0866                 struct vmw_fifo_state *fifo_state);
0867 extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
0868 extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
0869 extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
0870 extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv);
0871 extern void vmw_generic_waiter_add(struct vmw_private *dev_priv, u32 flag,
0872                    int *waiter_count);
0873 extern void vmw_generic_waiter_remove(struct vmw_private *dev_priv,
0874                       u32 flag, int *waiter_count);
0875 
0876 /**
0877  * Rudimentary fence-like objects currently used only for throttling -
0878  * vmwgfx_marker.c
0879  */
0880 
0881 extern void vmw_marker_queue_init(struct vmw_marker_queue *queue);
0882 extern void vmw_marker_queue_takedown(struct vmw_marker_queue *queue);
0883 extern int vmw_marker_push(struct vmw_marker_queue *queue,
0884                uint32_t seqno);
0885 extern int vmw_marker_pull(struct vmw_marker_queue *queue,
0886                uint32_t signaled_seqno);
0887 extern int vmw_wait_lag(struct vmw_private *dev_priv,
0888             struct vmw_marker_queue *queue, uint32_t us);
0889 
0890 /**
0891  * Kernel framebuffer - vmwgfx_fb.c
0892  */
0893 
0894 int vmw_fb_init(struct vmw_private *vmw_priv);
0895 int vmw_fb_close(struct vmw_private *dev_priv);
0896 int vmw_fb_off(struct vmw_private *vmw_priv);
0897 int vmw_fb_on(struct vmw_private *vmw_priv);
0898 
0899 /**
0900  * Kernel modesetting - vmwgfx_kms.c
0901  */
0902 
0903 int vmw_kms_init(struct vmw_private *dev_priv);
0904 int vmw_kms_close(struct vmw_private *dev_priv);
0905 int vmw_kms_save_vga(struct vmw_private *vmw_priv);
0906 int vmw_kms_restore_vga(struct vmw_private *vmw_priv);
0907 int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
0908                 struct drm_file *file_priv);
0909 void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
0910 void vmw_kms_cursor_snoop(struct vmw_surface *srf,
0911               struct ttm_object_file *tfile,
0912               struct ttm_buffer_object *bo,
0913               SVGA3dCmdHeader *header);
0914 int vmw_kms_write_svga(struct vmw_private *vmw_priv,
0915                unsigned width, unsigned height, unsigned pitch,
0916                unsigned bpp, unsigned depth);
0917 void vmw_kms_idle_workqueues(struct vmw_master *vmaster);
0918 bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
0919                 uint32_t pitch,
0920                 uint32_t height);
0921 u32 vmw_get_vblank_counter(struct drm_device *dev, unsigned int pipe);
0922 int vmw_enable_vblank(struct drm_device *dev, unsigned int pipe);
0923 void vmw_disable_vblank(struct drm_device *dev, unsigned int pipe);
0924 int vmw_kms_present(struct vmw_private *dev_priv,
0925             struct drm_file *file_priv,
0926             struct vmw_framebuffer *vfb,
0927             struct vmw_surface *surface,
0928             uint32_t sid, int32_t destX, int32_t destY,
0929             struct drm_vmw_rect *clips,
0930             uint32_t num_clips);
0931 int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
0932                 struct drm_file *file_priv);
0933 void vmw_kms_legacy_hotspot_clear(struct vmw_private *dev_priv);
0934 
0935 int vmw_dumb_create(struct drm_file *file_priv,
0936             struct drm_device *dev,
0937             struct drm_mode_create_dumb *args);
0938 
0939 int vmw_dumb_map_offset(struct drm_file *file_priv,
0940             struct drm_device *dev, uint32_t handle,
0941             uint64_t *offset);
0942 int vmw_dumb_destroy(struct drm_file *file_priv,
0943              struct drm_device *dev,
0944              uint32_t handle);
0945 extern int vmw_resource_pin(struct vmw_resource *res, bool interruptible);
0946 extern void vmw_resource_unpin(struct vmw_resource *res);
0947 extern enum vmw_res_type vmw_res_type(const struct vmw_resource *res);
0948 
0949 /**
0950  * Overlay control - vmwgfx_overlay.c
0951  */
0952 
0953 int vmw_overlay_init(struct vmw_private *dev_priv);
0954 int vmw_overlay_close(struct vmw_private *dev_priv);
0955 int vmw_overlay_ioctl(struct drm_device *dev, void *data,
0956               struct drm_file *file_priv);
0957 int vmw_overlay_stop_all(struct vmw_private *dev_priv);
0958 int vmw_overlay_resume_all(struct vmw_private *dev_priv);
0959 int vmw_overlay_pause_all(struct vmw_private *dev_priv);
0960 int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
0961 int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
0962 int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
0963 int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
0964 
0965 /**
0966  * GMR Id manager
0967  */
0968 
0969 extern const struct ttm_mem_type_manager_func vmw_gmrid_manager_func;
0970 
0971 /**
0972  * Prime - vmwgfx_prime.c
0973  */
0974 
0975 extern const struct dma_buf_ops vmw_prime_dmabuf_ops;
0976 extern int vmw_prime_fd_to_handle(struct drm_device *dev,
0977                   struct drm_file *file_priv,
0978                   int fd, u32 *handle);
0979 extern int vmw_prime_handle_to_fd(struct drm_device *dev,
0980                   struct drm_file *file_priv,
0981                   uint32_t handle, uint32_t flags,
0982                   int *prime_fd);
0983 
0984 /*
0985  * MemoryOBject management -  vmwgfx_mob.c
0986  */
0987 struct vmw_mob;
0988 extern int vmw_mob_bind(struct vmw_private *dev_priv, struct vmw_mob *mob,
0989             const struct vmw_sg_table *vsgt,
0990             unsigned long num_data_pages, int32_t mob_id);
0991 extern void vmw_mob_unbind(struct vmw_private *dev_priv,
0992                struct vmw_mob *mob);
0993 extern void vmw_mob_destroy(struct vmw_mob *mob);
0994 extern struct vmw_mob *vmw_mob_create(unsigned long data_pages);
0995 extern int vmw_otables_setup(struct vmw_private *dev_priv);
0996 extern void vmw_otables_takedown(struct vmw_private *dev_priv);
0997 
0998 /*
0999  * Context management - vmwgfx_context.c
1000  */
1001 
1002 extern const struct vmw_user_resource_conv *user_context_converter;
1003 
1004 extern int vmw_context_check(struct vmw_private *dev_priv,
1005                  struct ttm_object_file *tfile,
1006                  int id,
1007                  struct vmw_resource **p_res);
1008 extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
1009                     struct drm_file *file_priv);
1010 extern int vmw_extended_context_define_ioctl(struct drm_device *dev, void *data,
1011                          struct drm_file *file_priv);
1012 extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
1013                      struct drm_file *file_priv);
1014 extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
1015 extern struct vmw_cmdbuf_res_manager *
1016 vmw_context_res_man(struct vmw_resource *ctx);
1017 extern struct vmw_resource *vmw_context_cotable(struct vmw_resource *ctx,
1018                         SVGACOTableType cotable_type);
1019 extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
1020 struct vmw_ctx_binding_state;
1021 extern struct vmw_ctx_binding_state *
1022 vmw_context_binding_state(struct vmw_resource *ctx);
1023 extern void vmw_dx_context_scrub_cotables(struct vmw_resource *ctx,
1024                       bool readback);
1025 extern int vmw_context_bind_dx_query(struct vmw_resource *ctx_res,
1026                      struct vmw_dma_buffer *mob);
1027 extern struct vmw_dma_buffer *
1028 vmw_context_get_dx_query_mob(struct vmw_resource *ctx_res);
1029 
1030 
1031 /*
1032  * Surface management - vmwgfx_surface.c
1033  */
1034 
1035 extern const struct vmw_user_resource_conv *user_surface_converter;
1036 
1037 extern void vmw_surface_res_free(struct vmw_resource *res);
1038 extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data,
1039                      struct drm_file *file_priv);
1040 extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
1041                     struct drm_file *file_priv);
1042 extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,
1043                        struct drm_file *file_priv);
1044 extern int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data,
1045                        struct drm_file *file_priv);
1046 extern int vmw_gb_surface_reference_ioctl(struct drm_device *dev, void *data,
1047                       struct drm_file *file_priv);
1048 extern int vmw_surface_check(struct vmw_private *dev_priv,
1049                  struct ttm_object_file *tfile,
1050                  uint32_t handle, int *id);
1051 extern int vmw_surface_validate(struct vmw_private *dev_priv,
1052                 struct vmw_surface *srf);
1053 int vmw_surface_gb_priv_define(struct drm_device *dev,
1054                    uint32_t user_accounting_size,
1055                    uint32_t svga3d_flags,
1056                    SVGA3dSurfaceFormat format,
1057                    bool for_scanout,
1058                    uint32_t num_mip_levels,
1059                    uint32_t multisample_count,
1060                    uint32_t array_size,
1061                    struct drm_vmw_size size,
1062                    struct vmw_surface **srf_out);
1063 
1064 /*
1065  * Shader management - vmwgfx_shader.c
1066  */
1067 
1068 extern const struct vmw_user_resource_conv *user_shader_converter;
1069 
1070 extern int vmw_shader_define_ioctl(struct drm_device *dev, void *data,
1071                    struct drm_file *file_priv);
1072 extern int vmw_shader_destroy_ioctl(struct drm_device *dev, void *data,
1073                     struct drm_file *file_priv);
1074 extern int vmw_compat_shader_add(struct vmw_private *dev_priv,
1075                  struct vmw_cmdbuf_res_manager *man,
1076                  u32 user_key, const void *bytecode,
1077                  SVGA3dShaderType shader_type,
1078                  size_t size,
1079                  struct list_head *list);
1080 extern int vmw_shader_remove(struct vmw_cmdbuf_res_manager *man,
1081                  u32 user_key, SVGA3dShaderType shader_type,
1082                  struct list_head *list);
1083 extern int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,
1084                  struct vmw_resource *ctx,
1085                  u32 user_key,
1086                  SVGA3dShaderType shader_type,
1087                  struct list_head *list);
1088 extern void vmw_dx_shader_cotable_list_scrub(struct vmw_private *dev_priv,
1089                          struct list_head *list,
1090                          bool readback);
1091 
1092 extern struct vmw_resource *
1093 vmw_shader_lookup(struct vmw_cmdbuf_res_manager *man,
1094           u32 user_key, SVGA3dShaderType shader_type);
1095 
1096 /*
1097  * Command buffer managed resources - vmwgfx_cmdbuf_res.c
1098  */
1099 
1100 extern struct vmw_cmdbuf_res_manager *
1101 vmw_cmdbuf_res_man_create(struct vmw_private *dev_priv);
1102 extern void vmw_cmdbuf_res_man_destroy(struct vmw_cmdbuf_res_manager *man);
1103 extern size_t vmw_cmdbuf_res_man_size(void);
1104 extern struct vmw_resource *
1105 vmw_cmdbuf_res_lookup(struct vmw_cmdbuf_res_manager *man,
1106               enum vmw_cmdbuf_res_type res_type,
1107               u32 user_key);
1108 extern void vmw_cmdbuf_res_revert(struct list_head *list);
1109 extern void vmw_cmdbuf_res_commit(struct list_head *list);
1110 extern int vmw_cmdbuf_res_add(struct vmw_cmdbuf_res_manager *man,
1111                   enum vmw_cmdbuf_res_type res_type,
1112                   u32 user_key,
1113                   struct vmw_resource *res,
1114                   struct list_head *list);
1115 extern int vmw_cmdbuf_res_remove(struct vmw_cmdbuf_res_manager *man,
1116                  enum vmw_cmdbuf_res_type res_type,
1117                  u32 user_key,
1118                  struct list_head *list,
1119                  struct vmw_resource **res);
1120 
1121 /*
1122  * COTable management - vmwgfx_cotable.c
1123  */
1124 extern const SVGACOTableType vmw_cotable_scrub_order[];
1125 extern struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv,
1126                           struct vmw_resource *ctx,
1127                           u32 type);
1128 extern int vmw_cotable_notify(struct vmw_resource *res, int id);
1129 extern int vmw_cotable_scrub(struct vmw_resource *res, bool readback);
1130 extern void vmw_cotable_add_resource(struct vmw_resource *ctx,
1131                      struct list_head *head);
1132 
1133 /*
1134  * Command buffer managerment vmwgfx_cmdbuf.c
1135  */
1136 struct vmw_cmdbuf_man;
1137 struct vmw_cmdbuf_header;
1138 
1139 extern struct vmw_cmdbuf_man *
1140 vmw_cmdbuf_man_create(struct vmw_private *dev_priv);
1141 extern int vmw_cmdbuf_set_pool_size(struct vmw_cmdbuf_man *man,
1142                     size_t size, size_t default_size);
1143 extern void vmw_cmdbuf_remove_pool(struct vmw_cmdbuf_man *man);
1144 extern void vmw_cmdbuf_man_destroy(struct vmw_cmdbuf_man *man);
1145 extern int vmw_cmdbuf_idle(struct vmw_cmdbuf_man *man, bool interruptible,
1146                unsigned long timeout);
1147 extern void *vmw_cmdbuf_reserve(struct vmw_cmdbuf_man *man, size_t size,
1148                 int ctx_id, bool interruptible,
1149                 struct vmw_cmdbuf_header *header);
1150 extern void vmw_cmdbuf_commit(struct vmw_cmdbuf_man *man, size_t size,
1151                   struct vmw_cmdbuf_header *header,
1152                   bool flush);
1153 extern void vmw_cmdbuf_tasklet_schedule(struct vmw_cmdbuf_man *man);
1154 extern void *vmw_cmdbuf_alloc(struct vmw_cmdbuf_man *man,
1155                   size_t size, bool interruptible,
1156                   struct vmw_cmdbuf_header **p_header);
1157 extern void vmw_cmdbuf_header_free(struct vmw_cmdbuf_header *header);
1158 extern int vmw_cmdbuf_cur_flush(struct vmw_cmdbuf_man *man,
1159                 bool interruptible);
1160 
1161 
1162 /**
1163  * Inline helper functions
1164  */
1165 
1166 static inline void vmw_surface_unreference(struct vmw_surface **srf)
1167 {
1168     struct vmw_surface *tmp_srf = *srf;
1169     struct vmw_resource *res = &tmp_srf->res;
1170     *srf = NULL;
1171 
1172     vmw_resource_unreference(&res);
1173 }
1174 
1175 static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
1176 {
1177     (void) vmw_resource_reference(&srf->res);
1178     return srf;
1179 }
1180 
1181 static inline void vmw_dmabuf_unreference(struct vmw_dma_buffer **buf)
1182 {
1183     struct vmw_dma_buffer *tmp_buf = *buf;
1184 
1185     *buf = NULL;
1186     if (tmp_buf != NULL) {
1187         struct ttm_buffer_object *bo = &tmp_buf->base;
1188 
1189         ttm_bo_unref(&bo);
1190     }
1191 }
1192 
1193 static inline struct vmw_dma_buffer *vmw_dmabuf_reference(struct vmw_dma_buffer *buf)
1194 {
1195     if (ttm_bo_reference(&buf->base))
1196         return buf;
1197     return NULL;
1198 }
1199 
1200 static inline struct ttm_mem_global *vmw_mem_glob(struct vmw_private *dev_priv)
1201 {
1202     return (struct ttm_mem_global *) dev_priv->mem_global_ref.object;
1203 }
1204 
1205 static inline void vmw_fifo_resource_inc(struct vmw_private *dev_priv)
1206 {
1207     atomic_inc(&dev_priv->num_fifo_resources);
1208 }
1209 
1210 static inline void vmw_fifo_resource_dec(struct vmw_private *dev_priv)
1211 {
1212     atomic_dec(&dev_priv->num_fifo_resources);
1213 }
1214 
1215 /**
1216  * vmw_mmio_read - Perform a MMIO read from volatile memory
1217  *
1218  * @addr: The address to read from
1219  *
1220  * This function is intended to be equivalent to ioread32() on
1221  * memremap'd memory, but without byteswapping.
1222  */
1223 static inline u32 vmw_mmio_read(u32 *addr)
1224 {
1225     return READ_ONCE(*addr);
1226 }
1227 
1228 /**
1229  * vmw_mmio_write - Perform a MMIO write to volatile memory
1230  *
1231  * @addr: The address to write to
1232  *
1233  * This function is intended to be equivalent to iowrite32 on
1234  * memremap'd memory, but without byteswapping.
1235  */
1236 static inline void vmw_mmio_write(u32 value, u32 *addr)
1237 {
1238     WRITE_ONCE(*addr, value);
1239 }
1240 
1241 /**
1242  * Add vmw_msg module function
1243  */
1244 extern int vmw_host_log(const char *log);
1245 
1246 #endif