Subversion Repositories Kolibri OS

Rev

Rev 4569 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /**************************************************************************
  2.  *
  3.  * Copyright © 2009 VMware, Inc., Palo Alto, CA., USA
  4.  * All Rights Reserved.
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the
  8.  * "Software"), to deal in the Software without restriction, including
  9.  * without limitation the rights to use, copy, modify, merge, publish,
  10.  * distribute, sub license, and/or sell copies of the Software, and to
  11.  * permit persons to whom the Software is furnished to do so, subject to
  12.  * the following conditions:
  13.  *
  14.  * The above copyright notice and this permission notice (including the
  15.  * next paragraph) shall be included in all copies or substantial portions
  16.  * of the Software.
  17.  *
  18.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20.  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  21.  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
  22.  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  23.  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  24.  * USE OR OTHER DEALINGS IN THE SOFTWARE.
  25.  *
  26.  **************************************************************************/
  27.  
  28. #ifndef _VMWGFX_DRV_H_
  29. #define _VMWGFX_DRV_H_
  30.  
  31. #include "vmwgfx_reg.h"
  32. #include <drm/drmP.h>
  33. #include <drm/vmwgfx_drm.h>
  34. #include <drm/drm_hashtab.h>
  35. #include <linux/scatterlist.h>
  36. //#include <linux/suspend.h>
  37. #include <drm/ttm/ttm_bo_driver.h>
  38. #include <drm/ttm/ttm_object.h>
  39. #include <drm/ttm/ttm_lock.h>
  40. #include <drm/ttm/ttm_execbuf_util.h>
  41. //#include <drm/ttm/ttm_module.h>
  42. #include "vmwgfx_fence.h"
  43.  
  44. #define VMWGFX_DRIVER_DATE "20140704"
  45. #define VMWGFX_DRIVER_MAJOR 2
  46. #define VMWGFX_DRIVER_MINOR 6
  47. #define VMWGFX_DRIVER_PATCHLEVEL 1
  48. #define VMWGFX_FILE_PAGE_OFFSET 0x00100000
  49. #define VMWGFX_FIFO_STATIC_SIZE (1024*1024)
  50. #define VMWGFX_MAX_RELOCATIONS 2048
  51. #define VMWGFX_MAX_VALIDATIONS 2048
  52. #define VMWGFX_MAX_DISPLAYS 16
  53. #define VMWGFX_CMD_BOUNCE_INIT_SIZE 32768
  54. #define VMWGFX_ENABLE_SCREEN_TARGET_OTABLE 0
  55.  
  56. /*
  57.  * Perhaps we should have sysfs entries for these.
  58.  */
  59. #define VMWGFX_NUM_GB_CONTEXT 256
  60. #define VMWGFX_NUM_GB_SHADER 20000
  61. #define VMWGFX_NUM_GB_SURFACE 32768
  62. #define VMWGFX_NUM_GB_SCREEN_TARGET VMWGFX_MAX_DISPLAYS
  63. #define VMWGFX_NUM_MOB (VMWGFX_NUM_GB_CONTEXT +\
  64.                         VMWGFX_NUM_GB_SHADER +\
  65.                         VMWGFX_NUM_GB_SURFACE +\
  66.                         VMWGFX_NUM_GB_SCREEN_TARGET)
  67.  
  68. #define VMW_PL_GMR TTM_PL_PRIV0
  69. #define VMW_PL_FLAG_GMR TTM_PL_FLAG_PRIV0
  70. #define VMW_PL_MOB TTM_PL_PRIV1
  71. #define VMW_PL_FLAG_MOB TTM_PL_FLAG_PRIV1
  72.  
  73. #define VMW_RES_CONTEXT ttm_driver_type0
  74. #define VMW_RES_SURFACE ttm_driver_type1
  75. #define VMW_RES_STREAM ttm_driver_type2
  76. #define VMW_RES_FENCE ttm_driver_type3
  77. #define VMW_RES_SHADER ttm_driver_type4
  78.  
  79. #define ioread32(addr)          readl(addr)
  80.  
  81. static inline void outl(u32 v, u16 port)
  82. {
  83.     asm volatile("outl %0,%1" : : "a" (v), "dN" (port));
  84. }
  85. static inline u32 inl(u16 port)
  86. {
  87.     u32 v;
  88.     asm volatile("inl %1,%0" : "=a" (v) : "dN" (port));
  89.     return v;
  90. }
  91.  
  92.  
  93. struct vmw_fpriv {
  94. //   struct drm_master *locked_master;
  95.    struct ttm_object_file *tfile;
  96.    struct list_head fence_events;
  97.         bool gb_aware;
  98. };
  99.  
  100. struct vmw_dma_buffer {
  101.    struct ttm_buffer_object base;
  102.    struct list_head res_list;
  103. };
  104.  
  105. /**
  106.  * struct vmw_validate_buffer - Carries validation info about buffers.
  107.  *
  108.  * @base: Validation info for TTM.
  109.  * @hash: Hash entry for quick lookup of the TTM buffer object.
  110.  *
  111.  * This structure contains also driver private validation info
  112.  * on top of the info needed by TTM.
  113.  */
  114. struct vmw_validate_buffer {
  115.    struct ttm_validate_buffer base;
  116.    struct drm_hash_item hash;
  117.         bool validate_as_mob;
  118. };
  119.  
  120. struct vmw_res_func;
  121. struct vmw_resource {
  122.         struct kref kref;
  123.         struct vmw_private *dev_priv;
  124.         int id;
  125.         bool avail;
  126.         unsigned long backup_size;
  127.         bool res_dirty; /* Protected by backup buffer reserved */
  128.         bool backup_dirty; /* Protected by backup buffer reserved */
  129.     struct vmw_dma_buffer *backup;
  130.         unsigned long backup_offset;
  131.         const struct vmw_res_func *func;
  132.         struct list_head lru_head; /* Protected by the resource lock */
  133.         struct list_head mob_head; /* Protected by @backup reserved */
  134.         struct list_head binding_head; /* Protected by binding_mutex */
  135.         void (*res_free) (struct vmw_resource *res);
  136.         void (*hw_destroy) (struct vmw_resource *res);
  137. };
  138.  
  139.  
  140. /*
  141.  * Resources that are managed using ioctls.
  142.  */
  143. enum vmw_res_type {
  144.         vmw_res_context,
  145.         vmw_res_surface,
  146.         vmw_res_stream,
  147.         vmw_res_shader,
  148.         vmw_res_max
  149. };
  150.  
  151. /*
  152.  * Resources that are managed using command streams.
  153.  */
  154. enum vmw_cmdbuf_res_type {
  155.         vmw_cmdbuf_res_compat_shader
  156. };
  157.  
  158. struct vmw_cmdbuf_res_manager;
  159.  
  160. struct vmw_cursor_snooper {
  161.         struct drm_crtc *crtc;
  162.         size_t age;
  163.         uint32_t *image;
  164. };
  165.  
  166. struct vmw_framebuffer;
  167. struct vmw_surface_offset;
  168.  
  169. struct vmw_surface {
  170.     struct vmw_resource res;
  171.         uint32_t flags;
  172.         uint32_t format;
  173.         uint32_t mip_levels[DRM_VMW_MAX_SURFACE_FACES];
  174.         struct drm_vmw_size base_size;
  175.         struct drm_vmw_size *sizes;
  176.         uint32_t num_sizes;
  177.         bool scanout;
  178.         /* TODO so far just a extra pointer */
  179.         struct vmw_cursor_snooper snooper;
  180.         struct vmw_surface_offset *offsets;
  181.         SVGA3dTextureFilter autogen_filter;
  182.         uint32_t multisample_count;
  183. };
  184.  
  185. struct vmw_marker_queue {
  186.         struct list_head head;
  187.         u64 lag;
  188.         u64 lag_time;
  189.         spinlock_t lock;
  190. };
  191.  
  192. struct vmw_fifo_state {
  193.         unsigned long reserved_size;
  194.         __le32 *dynamic_buffer;
  195.         __le32 *static_buffer;
  196.         unsigned long static_buffer_size;
  197.         bool using_bounce_buffer;
  198.         uint32_t capabilities;
  199.         struct mutex fifo_mutex;
  200.         struct rw_semaphore rwsem;
  201.         struct vmw_marker_queue marker_queue;
  202. };
  203.  
  204. struct vmw_relocation {
  205.         SVGAMobId *mob_loc;
  206.         SVGAGuestPtr *location;
  207.         uint32_t index;
  208. };
  209.  
  210. /**
  211.  * struct vmw_res_cache_entry - resource information cache entry
  212.  *
  213.  * @valid: Whether the entry is valid, which also implies that the execbuf
  214.  * code holds a reference to the resource, and it's placed on the
  215.  * validation list.
  216.  * @handle: User-space handle of a resource.
  217.  * @res: Non-ref-counted pointer to the resource.
  218.  *
  219.  * Used to avoid frequent repeated user-space handle lookups of the
  220.  * same resource.
  221.  */
  222. struct vmw_res_cache_entry {
  223.         bool valid;
  224.         uint32_t handle;
  225.         struct vmw_resource *res;
  226.         struct vmw_resource_val_node *node;
  227. };
  228.  
  229. /**
  230.  * enum vmw_dma_map_mode - indicate how to perform TTM page dma mappings.
  231.  */
  232. enum vmw_dma_map_mode {
  233.         vmw_dma_phys,           /* Use physical page addresses */
  234.         vmw_dma_alloc_coherent, /* Use TTM coherent pages */
  235.         vmw_dma_map_populate,   /* Unmap from DMA just after unpopulate */
  236.         vmw_dma_map_bind,       /* Unmap from DMA just before unbind */
  237.         vmw_dma_map_max
  238. };
  239.  
  240. /**
  241.  * struct vmw_sg_table - Scatter/gather table for binding, with additional
  242.  * device-specific information.
  243.  *
  244.  * @sgt: Pointer to a struct sg_table with binding information
  245.  * @num_regions: Number of regions with device-address contigous pages
  246.  */
  247. struct vmw_sg_table {
  248.         enum vmw_dma_map_mode mode;
  249.         struct page **pages;
  250.         const dma_addr_t *addrs;
  251.         struct sg_table *sgt;
  252.         unsigned long num_regions;
  253.         unsigned long num_pages;
  254. };
  255.  
  256. /**
  257.  * struct vmw_piter - Page iterator that iterates over a list of pages
  258.  * and DMA addresses that could be either a scatter-gather list or
  259.  * arrays
  260.  *
  261.  * @pages: Array of page pointers to the pages.
  262.  * @addrs: DMA addresses to the pages if coherent pages are used.
  263.  * @iter: Scatter-gather page iterator. Current position in SG list.
  264.  * @i: Current position in arrays.
  265.  * @num_pages: Number of pages total.
  266.  * @next: Function to advance the iterator. Returns false if past the list
  267.  * of pages, true otherwise.
  268.  * @dma_address: Function to return the DMA address of the current page.
  269.  */
  270. struct vmw_piter {
  271.         struct page **pages;
  272.         const dma_addr_t *addrs;
  273.         struct sg_page_iter iter;
  274.         unsigned long i;
  275.         unsigned long num_pages;
  276.         bool (*next)(struct vmw_piter *);
  277.         dma_addr_t (*dma_address)(struct vmw_piter *);
  278.         struct page *(*page)(struct vmw_piter *);
  279. };
  280.  
  281. /*
  282.  * enum vmw_ctx_binding_type - abstract resource to context binding types
  283.  */
  284. enum vmw_ctx_binding_type {
  285.         vmw_ctx_binding_shader,
  286.         vmw_ctx_binding_rt,
  287.         vmw_ctx_binding_tex,
  288.         vmw_ctx_binding_max
  289. };
  290.  
  291. /**
  292.  * struct vmw_ctx_bindinfo - structure representing a single context binding
  293.  *
  294.  * @ctx: Pointer to the context structure. NULL means the binding is not
  295.  * active.
  296.  * @res: Non ref-counted pointer to the bound resource.
  297.  * @bt: The binding type.
  298.  * @i1: Union of information needed to unbind.
  299.  */
  300. struct vmw_ctx_bindinfo {
  301.         struct vmw_resource *ctx;
  302.         struct vmw_resource *res;
  303.         enum vmw_ctx_binding_type bt;
  304.         bool scrubbed;
  305.         union {
  306.                 SVGA3dShaderType shader_type;
  307.                 SVGA3dRenderTargetType rt_type;
  308.                 uint32 texture_stage;
  309.         } i1;
  310. };
  311.  
  312. /**
  313.  * struct vmw_ctx_binding - structure representing a single context binding
  314.  *                        - suitable for tracking in a context
  315.  *
  316.  * @ctx_list: List head for context.
  317.  * @res_list: List head for bound resource.
  318.  * @bi: Binding info
  319.  */
  320. struct vmw_ctx_binding {
  321.         struct list_head ctx_list;
  322.         struct list_head res_list;
  323.         struct vmw_ctx_bindinfo bi;
  324. };
  325.  
  326.  
  327. /**
  328.  * struct vmw_ctx_binding_state - context binding state
  329.  *
  330.  * @list: linked list of individual bindings.
  331.  * @render_targets: Render target bindings.
  332.  * @texture_units: Texture units/samplers bindings.
  333.  * @shaders: Shader bindings.
  334.  *
  335.  * Note that this structure also provides storage space for the individual
  336.  * struct vmw_ctx_binding objects, so that no dynamic allocation is needed
  337.  * for individual bindings.
  338.  *
  339.  */
  340. struct vmw_ctx_binding_state {
  341.         struct list_head list;
  342.         struct vmw_ctx_binding render_targets[SVGA3D_RT_MAX];
  343.         struct vmw_ctx_binding texture_units[SVGA3D_NUM_TEXTURE_UNITS];
  344.         struct vmw_ctx_binding shaders[SVGA3D_SHADERTYPE_MAX];
  345. };
  346.  
  347. struct vmw_sw_context{
  348.         struct drm_open_hash res_ht;
  349.         bool res_ht_initialized;
  350.         bool kernel; /**< is the called made from the kernel */
  351.         struct vmw_fpriv *fp;
  352.         struct list_head validate_nodes;
  353.         struct vmw_relocation relocs[VMWGFX_MAX_RELOCATIONS];
  354.         uint32_t cur_reloc;
  355.     struct vmw_validate_buffer val_bufs[VMWGFX_MAX_VALIDATIONS];
  356.         uint32_t cur_val_buf;
  357.         uint32_t *cmd_bounce;
  358.         uint32_t cmd_bounce_size;
  359.         struct list_head resource_list;
  360.         uint32_t fence_flags;
  361.         struct ttm_buffer_object *cur_query_bo;
  362.         struct list_head res_relocations;
  363.         uint32_t *buf_start;
  364.         struct vmw_res_cache_entry res_cache[vmw_res_max];
  365.         struct vmw_resource *last_query_ctx;
  366.         bool needs_post_query_barrier;
  367.         struct vmw_resource *error_resource;
  368.         struct vmw_ctx_binding_state staged_bindings;
  369.         struct list_head staged_cmd_res;
  370. };
  371.  
  372. struct vmw_legacy_display;
  373. struct vmw_overlay;
  374.  
  375. struct vmw_master {
  376.     struct ttm_lock lock;
  377.         struct mutex fb_surf_mutex;
  378.         struct list_head fb_surf;
  379. };
  380.  
  381. struct vmw_vga_topology_state {
  382.         uint32_t width;
  383.         uint32_t height;
  384.         uint32_t primary;
  385.         uint32_t pos_x;
  386.         uint32_t pos_y;
  387. };
  388.  
  389. struct vmw_private {
  390.     struct ttm_bo_device bdev;
  391.     struct ttm_bo_global_ref bo_global_ref;
  392.     struct drm_global_reference mem_global_ref;
  393.  
  394.         struct vmw_fifo_state fifo;
  395.  
  396.         struct drm_device *dev;
  397.         unsigned long vmw_chipset;
  398.         unsigned int io_start;
  399.         uint32_t vram_start;
  400.         uint32_t vram_size;
  401.         uint32_t prim_bb_mem;
  402.         uint32_t mmio_start;
  403.         uint32_t mmio_size;
  404.         uint32_t fb_max_width;
  405.         uint32_t fb_max_height;
  406.         uint32_t initial_width;
  407.         uint32_t initial_height;
  408.         __le32 __iomem *mmio_virt;
  409.         int mmio_mtrr;
  410.         uint32_t capabilities;
  411.         uint32_t max_gmr_ids;
  412.         uint32_t max_gmr_pages;
  413.         uint32_t max_mob_pages;
  414.         uint32_t max_mob_size;
  415.         uint32_t memory_size;
  416.         bool has_gmr;
  417.         bool has_mob;
  418.         struct mutex hw_mutex;
  419.  
  420.         /*
  421.          * VGA registers.
  422.          */
  423.  
  424.         struct vmw_vga_topology_state vga_save[VMWGFX_MAX_DISPLAYS];
  425.         uint32_t vga_width;
  426.         uint32_t vga_height;
  427.         uint32_t vga_bpp;
  428.         uint32_t vga_bpl;
  429.         uint32_t vga_pitchlock;
  430.  
  431.         uint32_t num_displays;
  432.  
  433.         /*
  434.          * Framebuffer info.
  435.          */
  436.  
  437.         void *fb_info;
  438.         struct vmw_legacy_display *ldu_priv;
  439.         struct vmw_screen_object_display *sou_priv;
  440.         struct vmw_overlay *overlay_priv;
  441.  
  442.         /*
  443.          * Context and surface management.
  444.          */
  445.  
  446.         rwlock_t resource_lock;
  447.         struct idr res_idr[vmw_res_max];
  448.         /*
  449.          * Block lastclose from racing with firstopen.
  450.          */
  451.  
  452.         struct mutex init_mutex;
  453.  
  454.         /*
  455.          * A resource manager for kernel-only surfaces and
  456.          * contexts.
  457.          */
  458.  
  459.         struct ttm_object_device *tdev;
  460.  
  461.         /*
  462.          * Fencing and IRQs.
  463.          */
  464.  
  465.         atomic_t marker_seq;
  466.         wait_queue_head_t fence_queue;
  467.         wait_queue_head_t fifo_queue;
  468.         int fence_queue_waiters; /* Protected by hw_mutex */
  469.         int goal_queue_waiters; /* Protected by hw_mutex */
  470.         atomic_t fifo_queue_waiters;
  471.         uint32_t last_read_seqno;
  472.         spinlock_t irq_lock;
  473.         struct vmw_fence_manager *fman;
  474.         uint32_t irq_mask;
  475.  
  476.         /*
  477.          * Device state
  478.          */
  479.  
  480.         uint32_t traces_state;
  481.         uint32_t enable_state;
  482.         uint32_t config_done_state;
  483.  
  484.         /**
  485.          * Execbuf
  486.          */
  487.         /**
  488.          * Protected by the cmdbuf mutex.
  489.          */
  490.  
  491.         struct vmw_sw_context ctx;
  492.         struct mutex cmdbuf_mutex;
  493.         struct mutex binding_mutex;
  494.  
  495.         /**
  496.          * Operating mode.
  497.          */
  498.  
  499.         bool stealth;
  500.         bool enable_fb;
  501.  
  502.         /**
  503.          * Master management.
  504.          */
  505.  
  506.         struct vmw_master *active_master;
  507.         struct vmw_master fbdev_master;
  508. //      struct notifier_block pm_nb;
  509.         bool suspended;
  510.  
  511.         struct mutex release_mutex;
  512.         uint32_t num_3d_resources;
  513.  
  514.         /*
  515.          * Replace this with an rwsem as soon as we have down_xx_interruptible()
  516.          */
  517.         struct ttm_lock reservation_sem;
  518.  
  519.         /*
  520.          * Query processing. These members
  521.          * are protected by the cmdbuf mutex.
  522.          */
  523.  
  524.     struct ttm_buffer_object *dummy_query_bo;
  525.     struct ttm_buffer_object *pinned_bo;
  526.         uint32_t query_cid;
  527.         uint32_t query_cid_valid;
  528.         bool dummy_query_bo_pinned;
  529.  
  530.         /*
  531.          * Surface swapping. The "surface_lru" list is protected by the
  532.          * resource lock in order to be able to destroy a surface and take
  533.          * it off the lru atomically. "used_memory_size" is currently
  534.          * protected by the cmdbuf mutex for simplicity.
  535.          */
  536.  
  537.         struct list_head res_lru[vmw_res_max];
  538.         uint32_t used_memory_size;
  539.  
  540.         /*
  541.          * DMA mapping stuff.
  542.          */
  543.         enum vmw_dma_map_mode map_mode;
  544.  
  545.         /*
  546.          * Guest Backed stuff
  547.          */
  548.         struct ttm_buffer_object *otable_bo;
  549.         struct vmw_otable *otables;
  550. };
  551.  
  552. static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res)
  553. {
  554.         return container_of(res, struct vmw_surface, res);
  555. }
  556.  
  557. static inline struct vmw_private *vmw_priv(struct drm_device *dev)
  558. {
  559.         return (struct vmw_private *)dev->dev_private;
  560. }
  561.  
  562. static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
  563. {
  564.         return (struct vmw_fpriv *)file_priv->driver_priv;
  565. }
  566.  
  567. static inline struct vmw_master *vmw_master(struct drm_master *master)
  568. {
  569.         return (struct vmw_master *) master->driver_priv;
  570. }
  571.  
  572. static inline void vmw_write(struct vmw_private *dev_priv,
  573.                              unsigned int offset, uint32_t value)
  574. {
  575.         outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
  576.         outl(value, dev_priv->io_start + VMWGFX_VALUE_PORT);
  577. }
  578.  
  579. static inline uint32_t vmw_read(struct vmw_private *dev_priv,
  580.                                 unsigned int offset)
  581. {
  582.         uint32_t val;
  583.  
  584.         outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
  585.         val = inl(dev_priv->io_start + VMWGFX_VALUE_PORT);
  586.         return val;
  587. }
  588.  
  589. int vmw_3d_resource_inc(struct vmw_private *dev_priv, bool unhide_svga);
  590. void vmw_3d_resource_dec(struct vmw_private *dev_priv, bool hide_svga);
  591.  
  592. /**
  593.  * GMR utilities - vmwgfx_gmr.c
  594.  */
  595.  
  596. extern int vmw_gmr_bind(struct vmw_private *dev_priv,
  597.                         const struct vmw_sg_table *vsgt,
  598.                         unsigned long num_pages,
  599.                         int gmr_id);
  600. extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
  601.  
  602. /**
  603.  * Resource utilities - vmwgfx_resource.c
  604.  */
  605. struct vmw_user_resource_conv;
  606.  
  607. extern void vmw_resource_unreference(struct vmw_resource **p_res);
  608. extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
  609. extern struct vmw_resource *
  610. vmw_resource_reference_unless_doomed(struct vmw_resource *res);
  611. extern int vmw_resource_validate(struct vmw_resource *res);
  612. extern int vmw_resource_reserve(struct vmw_resource *res, bool no_backup);
  613. extern bool vmw_resource_needs_backup(const struct vmw_resource *res);
  614. extern int vmw_user_lookup_handle(struct vmw_private *dev_priv,
  615.                                   struct ttm_object_file *tfile,
  616.                                   uint32_t handle,
  617.                                   struct vmw_surface **out_surf,
  618.                                   struct vmw_dma_buffer **out_buf);
  619. extern int vmw_user_resource_lookup_handle(
  620.         struct vmw_private *dev_priv,
  621.         struct ttm_object_file *tfile,
  622.         uint32_t handle,
  623.         const struct vmw_user_resource_conv *converter,
  624.         struct vmw_resource **p_res);
  625. extern void vmw_dmabuf_bo_free(struct ttm_buffer_object *bo);
  626. extern int vmw_dmabuf_init(struct vmw_private *dev_priv,
  627.                            struct vmw_dma_buffer *vmw_bo,
  628.                            size_t size, struct ttm_placement *placement,
  629.                            bool interuptable,
  630.                            void (*bo_free) (struct ttm_buffer_object *bo));
  631. extern int vmw_user_dmabuf_verify_access(struct ttm_buffer_object *bo,
  632.                                   struct ttm_object_file *tfile);
  633. extern int vmw_user_dmabuf_alloc(struct vmw_private *dev_priv,
  634.                                  struct ttm_object_file *tfile,
  635.                                  uint32_t size,
  636.                                  bool shareable,
  637.                                  uint32_t *handle,
  638.                                  struct vmw_dma_buffer **p_dma_buf);
  639. extern int vmw_user_dmabuf_reference(struct ttm_object_file *tfile,
  640.                                      struct vmw_dma_buffer *dma_buf,
  641.                                      uint32_t *handle);
  642. extern int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data,
  643.                                   struct drm_file *file_priv);
  644. extern int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data,
  645.                                   struct drm_file *file_priv);
  646. extern int vmw_user_dmabuf_synccpu_ioctl(struct drm_device *dev, void *data,
  647.                                          struct drm_file *file_priv);
  648. extern uint32_t vmw_dmabuf_validate_node(struct ttm_buffer_object *bo,
  649.                                          uint32_t cur_validate_node);
  650. extern void vmw_dmabuf_validate_clear(struct ttm_buffer_object *bo);
  651. extern int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile,
  652.                                   uint32_t id, struct vmw_dma_buffer **out);
  653. extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
  654.                                   struct drm_file *file_priv);
  655. extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
  656.                                   struct drm_file *file_priv);
  657. extern int vmw_user_stream_lookup(struct vmw_private *dev_priv,
  658.                                   struct ttm_object_file *tfile,
  659.                                   uint32_t *inout_id,
  660.                                   struct vmw_resource **out);
  661. extern void vmw_resource_unreserve(struct vmw_resource *res,
  662.                                    struct vmw_dma_buffer *new_backup,
  663.                                    unsigned long new_backup_offset);
  664. extern void vmw_resource_move_notify(struct ttm_buffer_object *bo,
  665.                                      struct ttm_mem_reg *mem);
  666. extern void vmw_fence_single_bo(struct ttm_buffer_object *bo,
  667.                                 struct vmw_fence_obj *fence);
  668. extern void vmw_resource_evict_all(struct vmw_private *dev_priv);
  669.  
  670. /**
  671.  * DMA buffer helper routines - vmwgfx_dmabuf.c
  672.  */
  673. extern int vmw_dmabuf_to_placement(struct vmw_private *vmw_priv,
  674.                                    struct vmw_dma_buffer *bo,
  675.                                    struct ttm_placement *placement,
  676.                                    bool interruptible);
  677. extern int vmw_dmabuf_to_vram(struct vmw_private *dev_priv,
  678.                               struct vmw_dma_buffer *buf,
  679.                               bool pin, bool interruptible);
  680. extern int vmw_dmabuf_to_vram_or_gmr(struct vmw_private *dev_priv,
  681.                                      struct vmw_dma_buffer *buf,
  682.                                      bool pin, bool interruptible);
  683. extern int vmw_dmabuf_to_start_of_vram(struct vmw_private *vmw_priv,
  684.                                        struct vmw_dma_buffer *bo,
  685.                                        bool pin, bool interruptible);
  686. extern int vmw_dmabuf_unpin(struct vmw_private *vmw_priv,
  687.                             struct vmw_dma_buffer *bo,
  688.                             bool interruptible);
  689. extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf,
  690.                                  SVGAGuestPtr *ptr);
  691. extern void vmw_bo_pin(struct ttm_buffer_object *bo, bool pin);
  692.  
  693. /**
  694.  * Misc Ioctl functionality - vmwgfx_ioctl.c
  695.  */
  696.  
  697. extern int vmw_getparam_ioctl(struct drm_device *dev, void *data,
  698.                               struct drm_file *file_priv);
  699. extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
  700.                                 struct drm_file *file_priv);
  701. extern int vmw_present_ioctl(struct drm_device *dev, void *data,
  702.                              struct drm_file *file_priv);
  703. extern int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
  704.                                       struct drm_file *file_priv);
  705. extern ssize_t vmw_fops_read(struct file *filp, char __user *buffer,
  706.                              size_t count, loff_t *offset);
  707.  
  708. /**
  709.  * Fifo utilities - vmwgfx_fifo.c
  710.  */
  711.  
  712. extern int vmw_fifo_init(struct vmw_private *dev_priv,
  713.                          struct vmw_fifo_state *fifo);
  714. extern void vmw_fifo_release(struct vmw_private *dev_priv,
  715.                              struct vmw_fifo_state *fifo);
  716. extern void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes);
  717. extern void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes);
  718. extern int vmw_fifo_send_fence(struct vmw_private *dev_priv,
  719.                                uint32_t *seqno);
  720. extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
  721. extern bool vmw_fifo_have_3d(struct vmw_private *dev_priv);
  722. extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv);
  723. extern int vmw_fifo_emit_dummy_query(struct vmw_private *dev_priv,
  724.                                      uint32_t cid);
  725.  
  726. /**
  727.  * TTM glue - vmwgfx_ttm_glue.c
  728.  */
  729.  
  730. extern int vmw_ttm_global_init(struct vmw_private *dev_priv);
  731. extern void vmw_ttm_global_release(struct vmw_private *dev_priv);
  732. extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma);
  733.  
  734. /**
  735.  * TTM buffer object driver - vmwgfx_buffer.c
  736.  */
  737.  
  738. extern const size_t vmw_tt_size;
  739. extern struct ttm_placement vmw_vram_placement;
  740. extern struct ttm_placement vmw_vram_ne_placement;
  741. extern struct ttm_placement vmw_vram_sys_placement;
  742. extern struct ttm_placement vmw_vram_gmr_placement;
  743. extern struct ttm_placement vmw_vram_gmr_ne_placement;
  744. extern struct ttm_placement vmw_sys_placement;
  745. extern struct ttm_placement vmw_sys_ne_placement;
  746. extern struct ttm_placement vmw_evictable_placement;
  747. extern struct ttm_placement vmw_srf_placement;
  748. extern struct ttm_placement vmw_mob_placement;
  749. extern struct ttm_bo_driver vmw_bo_driver;
  750. extern int vmw_dma_quiescent(struct drm_device *dev);
  751. extern int vmw_bo_map_dma(struct ttm_buffer_object *bo);
  752. extern void vmw_bo_unmap_dma(struct ttm_buffer_object *bo);
  753. extern const struct vmw_sg_table *
  754. vmw_bo_sg_table(struct ttm_buffer_object *bo);
  755. extern void vmw_piter_start(struct vmw_piter *viter,
  756.                             const struct vmw_sg_table *vsgt,
  757.                             unsigned long p_offs);
  758.  
  759. /**
  760.  * vmw_piter_next - Advance the iterator one page.
  761.  *
  762.  * @viter: Pointer to the iterator to advance.
  763.  *
  764.  * Returns false if past the list of pages, true otherwise.
  765.  */
  766. static inline bool vmw_piter_next(struct vmw_piter *viter)
  767. {
  768.         return viter->next(viter);
  769. }
  770.  
  771. /**
  772.  * vmw_piter_dma_addr - Return the DMA address of the current page.
  773.  *
  774.  * @viter: Pointer to the iterator
  775.  *
  776.  * Returns the DMA address of the page pointed to by @viter.
  777.  */
  778. static inline dma_addr_t vmw_piter_dma_addr(struct vmw_piter *viter)
  779. {
  780.         return viter->dma_address(viter);
  781. }
  782.  
  783. /**
  784.  * vmw_piter_page - Return a pointer to the current page.
  785.  *
  786.  * @viter: Pointer to the iterator
  787.  *
  788.  * Returns the DMA address of the page pointed to by @viter.
  789.  */
  790. static inline struct page *vmw_piter_page(struct vmw_piter *viter)
  791. {
  792.         return viter->page(viter);
  793. }
  794.  
  795. /**
  796.  * Command submission - vmwgfx_execbuf.c
  797.  */
  798.  
  799. extern int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
  800.                              struct drm_file *file_priv);
  801. extern int vmw_execbuf_process(struct drm_file *file_priv,
  802.                                struct vmw_private *dev_priv,
  803.                                void __user *user_commands,
  804.                                void *kernel_commands,
  805.                                uint32_t command_size,
  806.                                uint64_t throttle_us,
  807.                                struct drm_vmw_fence_rep __user
  808.                                *user_fence_rep,
  809.                                struct vmw_fence_obj **out_fence);
  810. extern void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv,
  811.                                             struct vmw_fence_obj *fence);
  812. extern void vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv);
  813.  
  814. extern int vmw_execbuf_fence_commands(struct drm_file *file_priv,
  815.                                       struct vmw_private *dev_priv,
  816.                                       struct vmw_fence_obj **p_fence,
  817.                                       uint32_t *p_handle);
  818. extern void vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
  819.                                         struct vmw_fpriv *vmw_fp,
  820.                                         int ret,
  821.                                         struct drm_vmw_fence_rep __user
  822.                                         *user_fence_rep,
  823.                                         struct vmw_fence_obj *fence,
  824.                                         uint32_t fence_handle);
  825.  
  826. /**
  827.  * IRQs and wating - vmwgfx_irq.c
  828.  */
  829.  
  830. extern irqreturn_t vmw_irq_handler(int irq, void *arg);
  831. extern int vmw_wait_seqno(struct vmw_private *dev_priv, bool lazy,
  832.                              uint32_t seqno, bool interruptible,
  833.                              unsigned long timeout);
  834. extern void vmw_irq_preinstall(struct drm_device *dev);
  835. extern int vmw_irq_postinstall(struct drm_device *dev);
  836. extern void vmw_irq_uninstall(struct drm_device *dev);
  837. extern bool vmw_seqno_passed(struct vmw_private *dev_priv,
  838.                                 uint32_t seqno);
  839. extern int vmw_fallback_wait(struct vmw_private *dev_priv,
  840.                              bool lazy,
  841.                              bool fifo_idle,
  842.                              uint32_t seqno,
  843.                              bool interruptible,
  844.                              unsigned long timeout);
  845. extern void vmw_update_seqno(struct vmw_private *dev_priv,
  846.                                 struct vmw_fifo_state *fifo_state);
  847. extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
  848. extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
  849. extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
  850. extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv);
  851.  
  852. /**
  853.  * Rudimentary fence-like objects currently used only for throttling -
  854.  * vmwgfx_marker.c
  855.  */
  856.  
  857. extern void vmw_marker_queue_init(struct vmw_marker_queue *queue);
  858. extern void vmw_marker_queue_takedown(struct vmw_marker_queue *queue);
  859. extern int vmw_marker_push(struct vmw_marker_queue *queue,
  860.                           uint32_t seqno);
  861. extern int vmw_marker_pull(struct vmw_marker_queue *queue,
  862.                           uint32_t signaled_seqno);
  863. extern int vmw_wait_lag(struct vmw_private *dev_priv,
  864.                         struct vmw_marker_queue *queue, uint32_t us);
  865.  
  866. /**
  867.  * Kernel framebuffer - vmwgfx_fb.c
  868.  */
  869.  
  870. int vmw_fb_init(struct vmw_private *vmw_priv);
  871. int vmw_fb_close(struct vmw_private *dev_priv);
  872. int vmw_fb_off(struct vmw_private *vmw_priv);
  873. int vmw_fb_on(struct vmw_private *vmw_priv);
  874.  
  875. /**
  876.  * Kernel modesetting - vmwgfx_kms.c
  877.  */
  878.  
  879. int vmw_kms_init(struct vmw_private *dev_priv);
  880. int vmw_kms_close(struct vmw_private *dev_priv);
  881. int vmw_kms_save_vga(struct vmw_private *vmw_priv);
  882. int vmw_kms_restore_vga(struct vmw_private *vmw_priv);
  883. int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
  884.                                 struct drm_file *file_priv);
  885. void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
  886. void vmw_kms_cursor_snoop(struct vmw_surface *srf,
  887.                           struct ttm_object_file *tfile,
  888.                           struct ttm_buffer_object *bo,
  889.                           SVGA3dCmdHeader *header);
  890. int vmw_kms_write_svga(struct vmw_private *vmw_priv,
  891.                        unsigned width, unsigned height, unsigned pitch,
  892.                        unsigned bpp, unsigned depth);
  893. void vmw_kms_idle_workqueues(struct vmw_master *vmaster);
  894. bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
  895.                                 uint32_t pitch,
  896.                                 uint32_t height);
  897. u32 vmw_get_vblank_counter(struct drm_device *dev, int crtc);
  898. int vmw_enable_vblank(struct drm_device *dev, int crtc);
  899. void vmw_disable_vblank(struct drm_device *dev, int crtc);
  900. int vmw_kms_present(struct vmw_private *dev_priv,
  901.                     struct drm_file *file_priv,
  902.                     struct vmw_framebuffer *vfb,
  903.                     struct vmw_surface *surface,
  904.                     uint32_t sid, int32_t destX, int32_t destY,
  905.                     struct drm_vmw_rect *clips,
  906.                     uint32_t num_clips);
  907. int vmw_kms_readback(struct vmw_private *dev_priv,
  908.                      struct drm_file *file_priv,
  909.                      struct vmw_framebuffer *vfb,
  910.                      struct drm_vmw_fence_rep __user *user_fence_rep,
  911.                      struct drm_vmw_rect *clips,
  912.                      uint32_t num_clips);
  913. int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
  914.                                 struct drm_file *file_priv);
  915.  
  916. int vmw_dumb_create(struct drm_file *file_priv,
  917.                     struct drm_device *dev,
  918.                     struct drm_mode_create_dumb *args);
  919.  
  920. int vmw_dumb_map_offset(struct drm_file *file_priv,
  921.                         struct drm_device *dev, uint32_t handle,
  922.                         uint64_t *offset);
  923. int vmw_dumb_destroy(struct drm_file *file_priv,
  924.                      struct drm_device *dev,
  925.                      uint32_t handle);
  926. /**
  927.  * Overlay control - vmwgfx_overlay.c
  928.  */
  929.  
  930. int vmw_overlay_init(struct vmw_private *dev_priv);
  931. int vmw_overlay_close(struct vmw_private *dev_priv);
  932. int vmw_overlay_ioctl(struct drm_device *dev, void *data,
  933.                       struct drm_file *file_priv);
  934. int vmw_overlay_stop_all(struct vmw_private *dev_priv);
  935. int vmw_overlay_resume_all(struct vmw_private *dev_priv);
  936. int vmw_overlay_pause_all(struct vmw_private *dev_priv);
  937. int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
  938. int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
  939. int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
  940. int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
  941.  
  942. /**
  943.  * GMR Id manager
  944.  */
  945.  
  946. extern const struct ttm_mem_type_manager_func vmw_gmrid_manager_func;
  947.  
  948. /**
  949. /*
  950.  * MemoryOBject management -  vmwgfx_mob.c
  951.  */
  952. struct vmw_mob;
  953. extern int vmw_mob_bind(struct vmw_private *dev_priv, struct vmw_mob *mob,
  954.                         const struct vmw_sg_table *vsgt,
  955.                         unsigned long num_data_pages, int32_t mob_id);
  956. extern void vmw_mob_unbind(struct vmw_private *dev_priv,
  957.                            struct vmw_mob *mob);
  958. extern void vmw_mob_destroy(struct vmw_mob *mob);
  959. extern struct vmw_mob *vmw_mob_create(unsigned long data_pages);
  960. extern int vmw_otables_setup(struct vmw_private *dev_priv);
  961. extern void vmw_otables_takedown(struct vmw_private *dev_priv);
  962.  
  963. /*
  964.  * Context management - vmwgfx_context.c
  965.  */
  966.  
  967. extern const struct vmw_user_resource_conv *user_context_converter;
  968.  
  969. extern struct vmw_resource *vmw_context_alloc(struct vmw_private *dev_priv);
  970.  
  971. extern int vmw_context_check(struct vmw_private *dev_priv,
  972.                              struct ttm_object_file *tfile,
  973.                              int id,
  974.                              struct vmw_resource **p_res);
  975. extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
  976.                                     struct drm_file *file_priv);
  977. extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
  978.                                      struct drm_file *file_priv);
  979. extern int vmw_context_binding_add(struct vmw_ctx_binding_state *cbs,
  980.                                    const struct vmw_ctx_bindinfo *ci);
  981. extern void
  982. vmw_context_binding_state_transfer(struct vmw_resource *res,
  983.                                    struct vmw_ctx_binding_state *cbs);
  984. extern void vmw_context_binding_res_list_kill(struct list_head *head);
  985. extern void vmw_context_binding_res_list_scrub(struct list_head *head);
  986. extern int vmw_context_rebind_all(struct vmw_resource *ctx);
  987. extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
  988.  
  989. /*
  990.  * Surface management - vmwgfx_surface.c
  991.  */
  992.  
  993. extern const struct vmw_user_resource_conv *user_surface_converter;
  994.  
  995. extern void vmw_surface_res_free(struct vmw_resource *res);
  996. extern int vmw_surface_check(struct vmw_private *dev_priv,
  997.                              struct ttm_object_file *tfile,
  998.                              uint32_t handle, int *id);
  999. extern int vmw_surface_validate(struct vmw_private *dev_priv,
  1000.                                 struct vmw_surface *srf);
  1001.  
  1002. /*
  1003.  * Shader management - vmwgfx_shader.c
  1004.  */
  1005.  
  1006. extern const struct vmw_user_resource_conv *user_shader_converter;
  1007. extern struct vmw_cmdbuf_res_manager *
  1008. vmw_cmdbuf_res_man_create(struct vmw_private *dev_priv);
  1009. extern void vmw_cmdbuf_res_man_destroy(struct vmw_cmdbuf_res_manager *man);
  1010. extern size_t vmw_cmdbuf_res_man_size(void);
  1011. extern struct vmw_resource *
  1012. vmw_cmdbuf_res_lookup(struct vmw_cmdbuf_res_manager *man,
  1013.                       enum vmw_cmdbuf_res_type res_type,
  1014.                       u32 user_key);
  1015. extern void vmw_cmdbuf_res_revert(struct list_head *list);
  1016. extern void vmw_cmdbuf_res_commit(struct list_head *list);
  1017. extern int vmw_cmdbuf_res_add(struct vmw_cmdbuf_res_manager *man,
  1018.                               enum vmw_cmdbuf_res_type res_type,
  1019.                               u32 user_key,
  1020.                               struct vmw_resource *res,
  1021.                               struct list_head *list);
  1022. extern int vmw_cmdbuf_res_remove(struct vmw_cmdbuf_res_manager *man,
  1023.                                  enum vmw_cmdbuf_res_type res_type,
  1024.                                  u32 user_key,
  1025.                                  struct list_head *list);
  1026.  
  1027.  
  1028. /**
  1029.  * Inline helper functions
  1030.  */
  1031.  
  1032. static inline void vmw_surface_unreference(struct vmw_surface **srf)
  1033. {
  1034.         struct vmw_surface *tmp_srf = *srf;
  1035.         struct vmw_resource *res = &tmp_srf->res;
  1036.         *srf = NULL;
  1037.  
  1038.         vmw_resource_unreference(&res);
  1039. }
  1040.  
  1041. static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
  1042. {
  1043.         (void) vmw_resource_reference(&srf->res);
  1044.         return srf;
  1045. }
  1046.  
  1047. static inline void vmw_dmabuf_unreference(struct vmw_dma_buffer **buf)
  1048. {
  1049.         struct vmw_dma_buffer *tmp_buf = *buf;
  1050.  
  1051.         *buf = NULL;
  1052.         if (tmp_buf != NULL) {
  1053.                 struct ttm_buffer_object *bo = &tmp_buf->base;
  1054.  
  1055.                 ttm_bo_unref(&bo);
  1056.         }
  1057. }
  1058.  
  1059. static inline struct vmw_dma_buffer *vmw_dmabuf_reference(struct vmw_dma_buffer *buf)
  1060. {
  1061.     if (ttm_bo_reference(&buf->base))
  1062.                 return buf;
  1063.         return NULL;
  1064. }
  1065.  
  1066. static inline struct ttm_mem_global *vmw_mem_glob(struct vmw_private *dev_priv)
  1067. {
  1068.         return (struct ttm_mem_global *) dev_priv->mem_global_ref.object;
  1069. }
  1070.  
  1071. extern struct drm_device *main_device;
  1072. extern struct drm_file   *drm_file_handlers[256];
  1073.  
  1074. typedef struct
  1075. {
  1076.   int width;
  1077.   int height;
  1078.   int bpp;
  1079.   int freq;
  1080. }videomode_t;
  1081.  
  1082. #endif
  1083.