Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 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 "drmP.h" |
| 33 | #include "vmwgfx_drm.h" |
| 34 | #include "drm_hashtab.h" |
Thomas Hellstrom | d9f36a0 | 2010-01-13 22:28:43 +0100 | [diff] [blame] | 35 | #include "linux/suspend.h" |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 36 | #include "ttm/ttm_bo_driver.h" |
| 37 | #include "ttm/ttm_object.h" |
| 38 | #include "ttm/ttm_lock.h" |
| 39 | #include "ttm/ttm_execbuf_util.h" |
| 40 | #include "ttm/ttm_module.h" |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 41 | #include "vmwgfx_fence.h" |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 42 | |
Thomas Hellstrom | 2ae7b03 | 2011-09-01 20:18:45 +0000 | [diff] [blame] | 43 | #define VMWGFX_DRIVER_DATE "20110901" |
| 44 | #define VMWGFX_DRIVER_MAJOR 2 |
| 45 | #define VMWGFX_DRIVER_MINOR 0 |
Thomas Hellstrom | f77cef3 | 2010-02-09 19:41:55 +0000 | [diff] [blame] | 46 | #define VMWGFX_DRIVER_PATCHLEVEL 0 |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 47 | #define VMWGFX_FILE_PAGE_OFFSET 0x00100000 |
| 48 | #define VMWGFX_FIFO_STATIC_SIZE (1024*1024) |
| 49 | #define VMWGFX_MAX_RELOCATIONS 2048 |
Thomas Hellstrom | be38ab6 | 2011-08-31 07:42:54 +0000 | [diff] [blame] | 50 | #define VMWGFX_MAX_VALIDATIONS 2048 |
Thomas Hellstrom | 7c4f778 | 2010-06-01 11:38:17 +0200 | [diff] [blame] | 51 | #define VMWGFX_MAX_DISPLAYS 16 |
Thomas Hellstrom | be38ab6 | 2011-08-31 07:42:54 +0000 | [diff] [blame] | 52 | #define VMWGFX_CMD_BOUNCE_INIT_SIZE 32768 |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 53 | |
Thomas Hellstrom | 135cba0 | 2010-10-26 21:21:47 +0200 | [diff] [blame] | 54 | #define VMW_PL_GMR TTM_PL_PRIV0 |
| 55 | #define VMW_PL_FLAG_GMR TTM_PL_FLAG_PRIV0 |
| 56 | |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 57 | #define VMW_RES_CONTEXT ttm_driver_type0 |
| 58 | #define VMW_RES_SURFACE ttm_driver_type1 |
| 59 | #define VMW_RES_STREAM ttm_driver_type2 |
| 60 | #define VMW_RES_FENCE ttm_driver_type3 |
| 61 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 62 | struct vmw_fpriv { |
| 63 | struct drm_master *locked_master; |
| 64 | struct ttm_object_file *tfile; |
| 65 | }; |
| 66 | |
| 67 | struct vmw_dma_buffer { |
| 68 | struct ttm_buffer_object base; |
| 69 | struct list_head validate_list; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 70 | bool gmr_bound; |
| 71 | uint32_t cur_validate_node; |
| 72 | bool on_validate_list; |
| 73 | }; |
| 74 | |
| 75 | struct vmw_resource { |
| 76 | struct kref kref; |
| 77 | struct vmw_private *dev_priv; |
| 78 | struct idr *idr; |
| 79 | int id; |
| 80 | enum ttm_object_type res_type; |
| 81 | bool avail; |
| 82 | void (*hw_destroy) (struct vmw_resource *res); |
| 83 | void (*res_free) (struct vmw_resource *res); |
Thomas Hellstrom | be38ab6 | 2011-08-31 07:42:54 +0000 | [diff] [blame] | 84 | bool on_validate_list; |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame^] | 85 | struct list_head query_head; /* Protected by the cmdbuf mutex */ |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 86 | /* TODO is a generic snooper needed? */ |
| 87 | #if 0 |
| 88 | void (*snoop)(struct vmw_resource *res, |
| 89 | struct ttm_object_file *tfile, |
| 90 | SVGA3dCmdHeader *header); |
| 91 | void *snoop_priv; |
| 92 | #endif |
| 93 | }; |
| 94 | |
| 95 | struct vmw_cursor_snooper { |
| 96 | struct drm_crtc *crtc; |
| 97 | size_t age; |
| 98 | uint32_t *image; |
| 99 | }; |
| 100 | |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 101 | struct vmw_framebuffer; |
| 102 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 103 | struct vmw_surface { |
| 104 | struct vmw_resource res; |
| 105 | uint32_t flags; |
| 106 | uint32_t format; |
| 107 | uint32_t mip_levels[DRM_VMW_MAX_SURFACE_FACES]; |
| 108 | struct drm_vmw_size *sizes; |
| 109 | uint32_t num_sizes; |
| 110 | |
Jakob Bornecrantz | 5ffdb65 | 2010-01-30 03:38:08 +0000 | [diff] [blame] | 111 | bool scanout; |
| 112 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 113 | /* TODO so far just a extra pointer */ |
| 114 | struct vmw_cursor_snooper snooper; |
| 115 | }; |
| 116 | |
Thomas Hellstrom | 6bcd8d3c | 2011-09-01 20:18:42 +0000 | [diff] [blame] | 117 | struct vmw_marker_queue { |
Thomas Hellstrom | 1925d45 | 2010-05-28 11:21:57 +0200 | [diff] [blame] | 118 | struct list_head head; |
| 119 | struct timespec lag; |
| 120 | struct timespec lag_time; |
| 121 | spinlock_t lock; |
| 122 | }; |
| 123 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 124 | struct vmw_fifo_state { |
| 125 | unsigned long reserved_size; |
| 126 | __le32 *dynamic_buffer; |
| 127 | __le32 *static_buffer; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 128 | unsigned long static_buffer_size; |
| 129 | bool using_bounce_buffer; |
| 130 | uint32_t capabilities; |
Thomas Hellstrom | 85b9e48 | 2010-02-08 09:57:25 +0000 | [diff] [blame] | 131 | struct mutex fifo_mutex; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 132 | struct rw_semaphore rwsem; |
Thomas Hellstrom | 6bcd8d3c | 2011-09-01 20:18:42 +0000 | [diff] [blame] | 133 | struct vmw_marker_queue marker_queue; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 134 | }; |
| 135 | |
| 136 | struct vmw_relocation { |
| 137 | SVGAGuestPtr *location; |
| 138 | uint32_t index; |
| 139 | }; |
| 140 | |
| 141 | struct vmw_sw_context{ |
| 142 | struct ida bo_list; |
| 143 | uint32_t last_cid; |
| 144 | bool cid_valid; |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 145 | bool kernel; /**< is the called made from the kernel */ |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame^] | 146 | struct vmw_resource *cur_ctx; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 147 | uint32_t last_sid; |
Thomas Hellstrom | 7a73ba7 | 2009-12-22 16:53:41 +0100 | [diff] [blame] | 148 | uint32_t sid_translation; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 149 | bool sid_valid; |
| 150 | struct ttm_object_file *tfile; |
| 151 | struct list_head validate_nodes; |
| 152 | struct vmw_relocation relocs[VMWGFX_MAX_RELOCATIONS]; |
| 153 | uint32_t cur_reloc; |
Thomas Hellstrom | be38ab6 | 2011-08-31 07:42:54 +0000 | [diff] [blame] | 154 | struct ttm_validate_buffer val_bufs[VMWGFX_MAX_VALIDATIONS]; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 155 | uint32_t cur_val_buf; |
Thomas Hellstrom | be38ab6 | 2011-08-31 07:42:54 +0000 | [diff] [blame] | 156 | uint32_t *cmd_bounce; |
| 157 | uint32_t cmd_bounce_size; |
| 158 | struct vmw_resource *resources[VMWGFX_MAX_VALIDATIONS]; |
| 159 | uint32_t num_ref_resources; |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame^] | 160 | uint32_t fence_flags; |
| 161 | struct list_head query_list; |
| 162 | struct ttm_buffer_object *cur_query_bo; |
| 163 | uint32_t cur_query_cid; |
| 164 | bool query_cid_valid; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | struct vmw_legacy_display; |
| 168 | struct vmw_overlay; |
| 169 | |
| 170 | struct vmw_master { |
| 171 | struct ttm_lock lock; |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 172 | struct mutex fb_surf_mutex; |
| 173 | struct list_head fb_surf; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 174 | }; |
| 175 | |
Thomas Hellstrom | 7c4f778 | 2010-06-01 11:38:17 +0200 | [diff] [blame] | 176 | struct vmw_vga_topology_state { |
| 177 | uint32_t width; |
| 178 | uint32_t height; |
| 179 | uint32_t primary; |
| 180 | uint32_t pos_x; |
| 181 | uint32_t pos_y; |
| 182 | }; |
| 183 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 184 | struct vmw_private { |
| 185 | struct ttm_bo_device bdev; |
| 186 | struct ttm_bo_global_ref bo_global_ref; |
Dave Airlie | ba4420c | 2010-03-09 10:56:52 +1000 | [diff] [blame] | 187 | struct drm_global_reference mem_global_ref; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 188 | |
| 189 | struct vmw_fifo_state fifo; |
| 190 | |
| 191 | struct drm_device *dev; |
| 192 | unsigned long vmw_chipset; |
| 193 | unsigned int io_start; |
| 194 | uint32_t vram_start; |
| 195 | uint32_t vram_size; |
| 196 | uint32_t mmio_start; |
| 197 | uint32_t mmio_size; |
| 198 | uint32_t fb_max_width; |
| 199 | uint32_t fb_max_height; |
| 200 | __le32 __iomem *mmio_virt; |
| 201 | int mmio_mtrr; |
| 202 | uint32_t capabilities; |
| 203 | uint32_t max_gmr_descriptors; |
| 204 | uint32_t max_gmr_ids; |
Thomas Hellstrom | fb17f18 | 2011-08-31 07:42:53 +0000 | [diff] [blame] | 205 | uint32_t max_gmr_pages; |
| 206 | uint32_t memory_size; |
Thomas Hellstrom | 135cba0 | 2010-10-26 21:21:47 +0200 | [diff] [blame] | 207 | bool has_gmr; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 208 | struct mutex hw_mutex; |
| 209 | |
| 210 | /* |
| 211 | * VGA registers. |
| 212 | */ |
| 213 | |
Thomas Hellstrom | 7c4f778 | 2010-06-01 11:38:17 +0200 | [diff] [blame] | 214 | struct vmw_vga_topology_state vga_save[VMWGFX_MAX_DISPLAYS]; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 215 | uint32_t vga_width; |
| 216 | uint32_t vga_height; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 217 | uint32_t vga_bpp; |
Thomas Hellstrom | 7c4f778 | 2010-06-01 11:38:17 +0200 | [diff] [blame] | 218 | uint32_t vga_bpl; |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 219 | uint32_t vga_pitchlock; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 220 | |
Thomas Hellstrom | 7c4f778 | 2010-06-01 11:38:17 +0200 | [diff] [blame] | 221 | uint32_t num_displays; |
| 222 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 223 | /* |
| 224 | * Framebuffer info. |
| 225 | */ |
| 226 | |
| 227 | void *fb_info; |
| 228 | struct vmw_legacy_display *ldu_priv; |
Jakob Bornecrantz | 56d1c78 | 2011-10-04 20:13:22 +0200 | [diff] [blame] | 229 | struct vmw_screen_object_display *sou_priv; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 230 | struct vmw_overlay *overlay_priv; |
| 231 | |
| 232 | /* |
| 233 | * Context and surface management. |
| 234 | */ |
| 235 | |
| 236 | rwlock_t resource_lock; |
| 237 | struct idr context_idr; |
| 238 | struct idr surface_idr; |
| 239 | struct idr stream_idr; |
| 240 | |
| 241 | /* |
| 242 | * Block lastclose from racing with firstopen. |
| 243 | */ |
| 244 | |
| 245 | struct mutex init_mutex; |
| 246 | |
| 247 | /* |
| 248 | * A resource manager for kernel-only surfaces and |
| 249 | * contexts. |
| 250 | */ |
| 251 | |
| 252 | struct ttm_object_device *tdev; |
| 253 | |
| 254 | /* |
| 255 | * Fencing and IRQs. |
| 256 | */ |
| 257 | |
Thomas Hellstrom | 6bcd8d3c | 2011-09-01 20:18:42 +0000 | [diff] [blame] | 258 | atomic_t marker_seq; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 259 | wait_queue_head_t fence_queue; |
| 260 | wait_queue_head_t fifo_queue; |
Thomas Hellstrom | 4f73a96 | 2011-09-01 20:18:43 +0000 | [diff] [blame] | 261 | int fence_queue_waiters; /* Protected by hw_mutex */ |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 262 | atomic_t fifo_queue_waiters; |
Thomas Hellstrom | 6bcd8d3c | 2011-09-01 20:18:42 +0000 | [diff] [blame] | 263 | uint32_t last_read_seqno; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 264 | spinlock_t irq_lock; |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 265 | struct vmw_fence_manager *fman; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 266 | |
| 267 | /* |
| 268 | * Device state |
| 269 | */ |
| 270 | |
| 271 | uint32_t traces_state; |
| 272 | uint32_t enable_state; |
| 273 | uint32_t config_done_state; |
| 274 | |
| 275 | /** |
| 276 | * Execbuf |
| 277 | */ |
| 278 | /** |
| 279 | * Protected by the cmdbuf mutex. |
| 280 | */ |
| 281 | |
| 282 | struct vmw_sw_context ctx; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 283 | struct mutex cmdbuf_mutex; |
| 284 | |
| 285 | /** |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 286 | * Operating mode. |
| 287 | */ |
| 288 | |
| 289 | bool stealth; |
| 290 | bool is_opened; |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 291 | bool enable_fb; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 292 | |
| 293 | /** |
| 294 | * Master management. |
| 295 | */ |
| 296 | |
| 297 | struct vmw_master *active_master; |
| 298 | struct vmw_master fbdev_master; |
Thomas Hellstrom | d9f36a0 | 2010-01-13 22:28:43 +0100 | [diff] [blame] | 299 | struct notifier_block pm_nb; |
Thomas Hellstrom | 094e0fa | 2010-10-05 12:43:00 +0200 | [diff] [blame] | 300 | bool suspended; |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 301 | |
| 302 | struct mutex release_mutex; |
| 303 | uint32_t num_3d_resources; |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame^] | 304 | |
| 305 | /* |
| 306 | * Query processing. These members |
| 307 | * are protected by the cmdbuf mutex. |
| 308 | */ |
| 309 | |
| 310 | struct ttm_buffer_object *dummy_query_bo; |
| 311 | struct ttm_buffer_object *pinned_bo; |
| 312 | uint32_t query_cid; |
| 313 | bool dummy_query_bo_pinned; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 314 | }; |
| 315 | |
| 316 | static inline struct vmw_private *vmw_priv(struct drm_device *dev) |
| 317 | { |
| 318 | return (struct vmw_private *)dev->dev_private; |
| 319 | } |
| 320 | |
| 321 | static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv) |
| 322 | { |
| 323 | return (struct vmw_fpriv *)file_priv->driver_priv; |
| 324 | } |
| 325 | |
| 326 | static inline struct vmw_master *vmw_master(struct drm_master *master) |
| 327 | { |
| 328 | return (struct vmw_master *) master->driver_priv; |
| 329 | } |
| 330 | |
| 331 | static inline void vmw_write(struct vmw_private *dev_priv, |
| 332 | unsigned int offset, uint32_t value) |
| 333 | { |
| 334 | outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT); |
| 335 | outl(value, dev_priv->io_start + VMWGFX_VALUE_PORT); |
| 336 | } |
| 337 | |
| 338 | static inline uint32_t vmw_read(struct vmw_private *dev_priv, |
| 339 | unsigned int offset) |
| 340 | { |
| 341 | uint32_t val; |
| 342 | |
| 343 | outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT); |
| 344 | val = inl(dev_priv->io_start + VMWGFX_VALUE_PORT); |
| 345 | return val; |
| 346 | } |
| 347 | |
Thomas Hellstrom | 05730b3 | 2011-08-31 07:42:52 +0000 | [diff] [blame] | 348 | int vmw_3d_resource_inc(struct vmw_private *dev_priv, bool unhide_svga); |
| 349 | void vmw_3d_resource_dec(struct vmw_private *dev_priv, bool hide_svga); |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 350 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 351 | /** |
| 352 | * GMR utilities - vmwgfx_gmr.c |
| 353 | */ |
| 354 | |
| 355 | extern int vmw_gmr_bind(struct vmw_private *dev_priv, |
Thomas Hellstrom | 135cba0 | 2010-10-26 21:21:47 +0200 | [diff] [blame] | 356 | struct page *pages[], |
| 357 | unsigned long num_pages, |
| 358 | int gmr_id); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 359 | extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id); |
| 360 | |
| 361 | /** |
| 362 | * Resource utilities - vmwgfx_resource.c |
| 363 | */ |
| 364 | |
| 365 | extern struct vmw_resource *vmw_context_alloc(struct vmw_private *dev_priv); |
| 366 | extern void vmw_resource_unreference(struct vmw_resource **p_res); |
| 367 | extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res); |
| 368 | extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data, |
| 369 | struct drm_file *file_priv); |
| 370 | extern int vmw_context_define_ioctl(struct drm_device *dev, void *data, |
| 371 | struct drm_file *file_priv); |
| 372 | extern int vmw_context_check(struct vmw_private *dev_priv, |
| 373 | struct ttm_object_file *tfile, |
Thomas Hellstrom | be38ab6 | 2011-08-31 07:42:54 +0000 | [diff] [blame] | 374 | int id, |
| 375 | struct vmw_resource **p_res); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 376 | extern void vmw_surface_res_free(struct vmw_resource *res); |
| 377 | extern int vmw_surface_init(struct vmw_private *dev_priv, |
| 378 | struct vmw_surface *srf, |
| 379 | void (*res_free) (struct vmw_resource *res)); |
Thomas Hellstrom | 7a73ba7 | 2009-12-22 16:53:41 +0100 | [diff] [blame] | 380 | extern int vmw_user_surface_lookup_handle(struct vmw_private *dev_priv, |
| 381 | struct ttm_object_file *tfile, |
| 382 | uint32_t handle, |
| 383 | struct vmw_surface **out); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 384 | extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data, |
| 385 | struct drm_file *file_priv); |
| 386 | extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data, |
| 387 | struct drm_file *file_priv); |
| 388 | extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data, |
| 389 | struct drm_file *file_priv); |
| 390 | extern int vmw_surface_check(struct vmw_private *dev_priv, |
| 391 | struct ttm_object_file *tfile, |
Thomas Hellstrom | 7a73ba7 | 2009-12-22 16:53:41 +0100 | [diff] [blame] | 392 | uint32_t handle, int *id); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 393 | extern void vmw_dmabuf_bo_free(struct ttm_buffer_object *bo); |
| 394 | extern int vmw_dmabuf_init(struct vmw_private *dev_priv, |
| 395 | struct vmw_dma_buffer *vmw_bo, |
| 396 | size_t size, struct ttm_placement *placement, |
| 397 | bool interuptable, |
| 398 | void (*bo_free) (struct ttm_buffer_object *bo)); |
| 399 | extern int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data, |
| 400 | struct drm_file *file_priv); |
| 401 | extern int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data, |
| 402 | struct drm_file *file_priv); |
| 403 | extern uint32_t vmw_dmabuf_validate_node(struct ttm_buffer_object *bo, |
| 404 | uint32_t cur_validate_node); |
| 405 | extern void vmw_dmabuf_validate_clear(struct ttm_buffer_object *bo); |
| 406 | extern int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile, |
| 407 | uint32_t id, struct vmw_dma_buffer **out); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 408 | extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data, |
| 409 | struct drm_file *file_priv); |
| 410 | extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data, |
| 411 | struct drm_file *file_priv); |
| 412 | extern int vmw_user_stream_lookup(struct vmw_private *dev_priv, |
| 413 | struct ttm_object_file *tfile, |
| 414 | uint32_t *inout_id, |
| 415 | struct vmw_resource **out); |
| 416 | |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 417 | /** |
| 418 | * DMA buffer helper routines - vmwgfx_dmabuf.c |
| 419 | */ |
| 420 | extern int vmw_dmabuf_to_placement(struct vmw_private *vmw_priv, |
| 421 | struct vmw_dma_buffer *bo, |
| 422 | struct ttm_placement *placement, |
| 423 | bool interruptible); |
| 424 | extern int vmw_dmabuf_to_vram(struct vmw_private *dev_priv, |
| 425 | struct vmw_dma_buffer *buf, |
| 426 | bool pin, bool interruptible); |
| 427 | extern int vmw_dmabuf_to_vram_or_gmr(struct vmw_private *dev_priv, |
| 428 | struct vmw_dma_buffer *buf, |
| 429 | bool pin, bool interruptible); |
| 430 | extern int vmw_dmabuf_to_start_of_vram(struct vmw_private *vmw_priv, |
| 431 | struct vmw_dma_buffer *bo, |
| 432 | bool pin, bool interruptible); |
| 433 | extern int vmw_dmabuf_unpin(struct vmw_private *vmw_priv, |
| 434 | struct vmw_dma_buffer *bo, |
| 435 | bool interruptible); |
Thomas Hellstrom | b37a6b9 | 2011-10-04 20:13:28 +0200 | [diff] [blame] | 436 | extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf, |
| 437 | SVGAGuestPtr *ptr); |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame^] | 438 | extern void vmw_bo_pin(struct ttm_buffer_object *bo, bool pin); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 439 | |
| 440 | /** |
| 441 | * Misc Ioctl functionality - vmwgfx_ioctl.c |
| 442 | */ |
| 443 | |
| 444 | extern int vmw_getparam_ioctl(struct drm_device *dev, void *data, |
| 445 | struct drm_file *file_priv); |
Thomas Hellstrom | f63f6a5 | 2011-09-01 20:18:41 +0000 | [diff] [blame] | 446 | extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data, |
| 447 | struct drm_file *file_priv); |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 448 | extern int vmw_present_ioctl(struct drm_device *dev, void *data, |
| 449 | struct drm_file *file_priv); |
| 450 | extern int vmw_present_readback_ioctl(struct drm_device *dev, void *data, |
| 451 | struct drm_file *file_priv); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 452 | |
| 453 | /** |
| 454 | * Fifo utilities - vmwgfx_fifo.c |
| 455 | */ |
| 456 | |
| 457 | extern int vmw_fifo_init(struct vmw_private *dev_priv, |
| 458 | struct vmw_fifo_state *fifo); |
| 459 | extern void vmw_fifo_release(struct vmw_private *dev_priv, |
| 460 | struct vmw_fifo_state *fifo); |
| 461 | extern void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes); |
| 462 | extern void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes); |
| 463 | extern int vmw_fifo_send_fence(struct vmw_private *dev_priv, |
Thomas Hellstrom | 6bcd8d3c | 2011-09-01 20:18:42 +0000 | [diff] [blame] | 464 | uint32_t *seqno); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 465 | extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason); |
Jakob Bornecrantz | 8e19a95 | 2010-01-30 03:38:06 +0000 | [diff] [blame] | 466 | extern bool vmw_fifo_have_3d(struct vmw_private *dev_priv); |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 467 | extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv); |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame^] | 468 | extern int vmw_fifo_emit_dummy_query(struct vmw_private *dev_priv, |
| 469 | uint32_t cid); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 470 | |
| 471 | /** |
| 472 | * TTM glue - vmwgfx_ttm_glue.c |
| 473 | */ |
| 474 | |
| 475 | extern int vmw_ttm_global_init(struct vmw_private *dev_priv); |
| 476 | extern void vmw_ttm_global_release(struct vmw_private *dev_priv); |
| 477 | extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma); |
| 478 | |
| 479 | /** |
| 480 | * TTM buffer object driver - vmwgfx_buffer.c |
| 481 | */ |
| 482 | |
| 483 | extern struct ttm_placement vmw_vram_placement; |
| 484 | extern struct ttm_placement vmw_vram_ne_placement; |
Thomas Hellstrom | 8ba5152 | 2010-01-16 16:05:05 +0100 | [diff] [blame] | 485 | extern struct ttm_placement vmw_vram_sys_placement; |
Thomas Hellstrom | 135cba0 | 2010-10-26 21:21:47 +0200 | [diff] [blame] | 486 | extern struct ttm_placement vmw_vram_gmr_placement; |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 487 | extern struct ttm_placement vmw_vram_gmr_ne_placement; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 488 | extern struct ttm_placement vmw_sys_placement; |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 489 | extern struct ttm_placement vmw_evictable_placement; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 490 | extern struct ttm_bo_driver vmw_bo_driver; |
| 491 | extern int vmw_dma_quiescent(struct drm_device *dev); |
| 492 | |
| 493 | /** |
| 494 | * Command submission - vmwgfx_execbuf.c |
| 495 | */ |
| 496 | |
| 497 | extern int vmw_execbuf_ioctl(struct drm_device *dev, void *data, |
| 498 | struct drm_file *file_priv); |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 499 | extern int vmw_execbuf_process(struct drm_file *file_priv, |
| 500 | struct vmw_private *dev_priv, |
| 501 | void __user *user_commands, |
| 502 | void *kernel_commands, |
| 503 | uint32_t command_size, |
| 504 | uint64_t throttle_us, |
| 505 | struct drm_vmw_fence_rep __user |
| 506 | *user_fence_rep); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 507 | |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame^] | 508 | extern void |
| 509 | vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv, |
| 510 | bool only_on_cid_match, uint32_t cid); |
| 511 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 512 | /** |
| 513 | * IRQs and wating - vmwgfx_irq.c |
| 514 | */ |
| 515 | |
| 516 | extern irqreturn_t vmw_irq_handler(DRM_IRQ_ARGS); |
Thomas Hellstrom | 6bcd8d3c | 2011-09-01 20:18:42 +0000 | [diff] [blame] | 517 | extern int vmw_wait_seqno(struct vmw_private *dev_priv, bool lazy, |
| 518 | uint32_t seqno, bool interruptible, |
| 519 | unsigned long timeout); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 520 | extern void vmw_irq_preinstall(struct drm_device *dev); |
| 521 | extern int vmw_irq_postinstall(struct drm_device *dev); |
| 522 | extern void vmw_irq_uninstall(struct drm_device *dev); |
Thomas Hellstrom | 6bcd8d3c | 2011-09-01 20:18:42 +0000 | [diff] [blame] | 523 | extern bool vmw_seqno_passed(struct vmw_private *dev_priv, |
| 524 | uint32_t seqno); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 525 | extern int vmw_fallback_wait(struct vmw_private *dev_priv, |
| 526 | bool lazy, |
| 527 | bool fifo_idle, |
Thomas Hellstrom | 6bcd8d3c | 2011-09-01 20:18:42 +0000 | [diff] [blame] | 528 | uint32_t seqno, |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 529 | bool interruptible, |
| 530 | unsigned long timeout); |
Thomas Hellstrom | 6bcd8d3c | 2011-09-01 20:18:42 +0000 | [diff] [blame] | 531 | extern void vmw_update_seqno(struct vmw_private *dev_priv, |
Thomas Hellstrom | 1925d45 | 2010-05-28 11:21:57 +0200 | [diff] [blame] | 532 | struct vmw_fifo_state *fifo_state); |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 533 | extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv); |
| 534 | extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv); |
Thomas Hellstrom | 1925d45 | 2010-05-28 11:21:57 +0200 | [diff] [blame] | 535 | |
| 536 | /** |
Thomas Hellstrom | 6bcd8d3c | 2011-09-01 20:18:42 +0000 | [diff] [blame] | 537 | * Rudimentary fence-like objects currently used only for throttling - |
| 538 | * vmwgfx_marker.c |
Thomas Hellstrom | 1925d45 | 2010-05-28 11:21:57 +0200 | [diff] [blame] | 539 | */ |
| 540 | |
Thomas Hellstrom | 6bcd8d3c | 2011-09-01 20:18:42 +0000 | [diff] [blame] | 541 | extern void vmw_marker_queue_init(struct vmw_marker_queue *queue); |
| 542 | extern void vmw_marker_queue_takedown(struct vmw_marker_queue *queue); |
| 543 | extern int vmw_marker_push(struct vmw_marker_queue *queue, |
| 544 | uint32_t seqno); |
| 545 | extern int vmw_marker_pull(struct vmw_marker_queue *queue, |
| 546 | uint32_t signaled_seqno); |
Thomas Hellstrom | 1925d45 | 2010-05-28 11:21:57 +0200 | [diff] [blame] | 547 | extern int vmw_wait_lag(struct vmw_private *dev_priv, |
Thomas Hellstrom | 6bcd8d3c | 2011-09-01 20:18:42 +0000 | [diff] [blame] | 548 | struct vmw_marker_queue *queue, uint32_t us); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 549 | |
| 550 | /** |
| 551 | * Kernel framebuffer - vmwgfx_fb.c |
| 552 | */ |
| 553 | |
| 554 | int vmw_fb_init(struct vmw_private *vmw_priv); |
| 555 | int vmw_fb_close(struct vmw_private *dev_priv); |
| 556 | int vmw_fb_off(struct vmw_private *vmw_priv); |
| 557 | int vmw_fb_on(struct vmw_private *vmw_priv); |
| 558 | |
| 559 | /** |
| 560 | * Kernel modesetting - vmwgfx_kms.c |
| 561 | */ |
| 562 | |
| 563 | int vmw_kms_init(struct vmw_private *dev_priv); |
| 564 | int vmw_kms_close(struct vmw_private *dev_priv); |
| 565 | int vmw_kms_save_vga(struct vmw_private *vmw_priv); |
| 566 | int vmw_kms_restore_vga(struct vmw_private *vmw_priv); |
| 567 | int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data, |
| 568 | struct drm_file *file_priv); |
| 569 | void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv); |
| 570 | void vmw_kms_cursor_snoop(struct vmw_surface *srf, |
| 571 | struct ttm_object_file *tfile, |
| 572 | struct ttm_buffer_object *bo, |
| 573 | SVGA3dCmdHeader *header); |
Michel Dänzer | 0bef23f | 2011-08-31 07:42:50 +0000 | [diff] [blame] | 574 | int vmw_kms_write_svga(struct vmw_private *vmw_priv, |
| 575 | unsigned width, unsigned height, unsigned pitch, |
| 576 | unsigned bpp, unsigned depth); |
Thomas Hellstrom | 3a939a5 | 2010-10-05 12:43:03 +0200 | [diff] [blame] | 577 | void vmw_kms_idle_workqueues(struct vmw_master *vmaster); |
Thomas Hellstrom | e133e73 | 2010-10-05 12:43:04 +0200 | [diff] [blame] | 578 | bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv, |
| 579 | uint32_t pitch, |
| 580 | uint32_t height); |
Thomas Hellstrom | 7a1c2f6 | 2010-10-01 10:21:49 +0200 | [diff] [blame] | 581 | u32 vmw_get_vblank_counter(struct drm_device *dev, int crtc); |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 582 | int vmw_kms_present(struct vmw_private *dev_priv, |
| 583 | struct drm_file *file_priv, |
| 584 | struct vmw_framebuffer *vfb, |
| 585 | struct vmw_surface *surface, |
| 586 | uint32_t sid, int32_t destX, int32_t destY, |
| 587 | struct drm_vmw_rect *clips, |
| 588 | uint32_t num_clips); |
| 589 | int vmw_kms_readback(struct vmw_private *dev_priv, |
| 590 | struct drm_file *file_priv, |
| 591 | struct vmw_framebuffer *vfb, |
| 592 | struct drm_vmw_fence_rep __user *user_fence_rep, |
| 593 | struct drm_vmw_rect *clips, |
| 594 | uint32_t num_clips); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 595 | |
| 596 | /** |
| 597 | * Overlay control - vmwgfx_overlay.c |
| 598 | */ |
| 599 | |
| 600 | int vmw_overlay_init(struct vmw_private *dev_priv); |
| 601 | int vmw_overlay_close(struct vmw_private *dev_priv); |
| 602 | int vmw_overlay_ioctl(struct drm_device *dev, void *data, |
| 603 | struct drm_file *file_priv); |
| 604 | int vmw_overlay_stop_all(struct vmw_private *dev_priv); |
| 605 | int vmw_overlay_resume_all(struct vmw_private *dev_priv); |
| 606 | int vmw_overlay_pause_all(struct vmw_private *dev_priv); |
| 607 | int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out); |
| 608 | int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id); |
| 609 | int vmw_overlay_num_overlays(struct vmw_private *dev_priv); |
| 610 | int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv); |
| 611 | |
| 612 | /** |
Thomas Hellstrom | 135cba0 | 2010-10-26 21:21:47 +0200 | [diff] [blame] | 613 | * GMR Id manager |
| 614 | */ |
| 615 | |
| 616 | extern const struct ttm_mem_type_manager_func vmw_gmrid_manager_func; |
| 617 | |
| 618 | /** |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 619 | * Inline helper functions |
| 620 | */ |
| 621 | |
| 622 | static inline void vmw_surface_unreference(struct vmw_surface **srf) |
| 623 | { |
| 624 | struct vmw_surface *tmp_srf = *srf; |
| 625 | struct vmw_resource *res = &tmp_srf->res; |
| 626 | *srf = NULL; |
| 627 | |
| 628 | vmw_resource_unreference(&res); |
| 629 | } |
| 630 | |
| 631 | static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf) |
| 632 | { |
| 633 | (void) vmw_resource_reference(&srf->res); |
| 634 | return srf; |
| 635 | } |
| 636 | |
| 637 | static inline void vmw_dmabuf_unreference(struct vmw_dma_buffer **buf) |
| 638 | { |
| 639 | struct vmw_dma_buffer *tmp_buf = *buf; |
| 640 | struct ttm_buffer_object *bo = &tmp_buf->base; |
| 641 | *buf = NULL; |
| 642 | |
| 643 | ttm_bo_unref(&bo); |
| 644 | } |
| 645 | |
| 646 | static inline struct vmw_dma_buffer *vmw_dmabuf_reference(struct vmw_dma_buffer *buf) |
| 647 | { |
| 648 | if (ttm_bo_reference(&buf->base)) |
| 649 | return buf; |
| 650 | return NULL; |
| 651 | } |
| 652 | |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 653 | static inline struct ttm_mem_global *vmw_mem_glob(struct vmw_private *dev_priv) |
| 654 | { |
| 655 | return (struct ttm_mem_global *) dev_priv->mem_global_ref.object; |
| 656 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 657 | #endif |