blob: 14c2f49b21ea23d6fcc049d09395d742a803955e [file] [log] [blame]
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001/**************************************************************************
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 Hellstromd9f36a02010-01-13 22:28:43 +010035#include "linux/suspend.h"
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000036#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 Hellstromae2a1042011-09-01 20:18:44 +000041#include "vmwgfx_fence.h"
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000042
Thomas Hellstromcd2b89e2011-10-25 23:35:53 +020043#define VMWGFX_DRIVER_DATE "20111025"
Thomas Hellstrom2ae7b032011-09-01 20:18:45 +000044#define VMWGFX_DRIVER_MAJOR 2
Thomas Hellstromcd2b89e2011-10-25 23:35:53 +020045#define VMWGFX_DRIVER_MINOR 3
Thomas Hellstromf77cef32010-02-09 19:41:55 +000046#define VMWGFX_DRIVER_PATCHLEVEL 0
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000047#define VMWGFX_FILE_PAGE_OFFSET 0x00100000
48#define VMWGFX_FIFO_STATIC_SIZE (1024*1024)
49#define VMWGFX_MAX_RELOCATIONS 2048
Thomas Hellstrombe38ab62011-08-31 07:42:54 +000050#define VMWGFX_MAX_VALIDATIONS 2048
Thomas Hellstrom7c4f7782010-06-01 11:38:17 +020051#define VMWGFX_MAX_DISPLAYS 16
Thomas Hellstrombe38ab62011-08-31 07:42:54 +000052#define VMWGFX_CMD_BOUNCE_INIT_SIZE 32768
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000053
Thomas Hellstrom135cba02010-10-26 21:21:47 +020054#define VMW_PL_GMR TTM_PL_PRIV0
55#define VMW_PL_FLAG_GMR TTM_PL_FLAG_PRIV0
56
Thomas Hellstromae2a1042011-09-01 20:18:44 +000057#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 Bornecrantzfb1d9732009-12-10 00:19:58 +000062struct vmw_fpriv {
63 struct drm_master *locked_master;
64 struct ttm_object_file *tfile;
Thomas Hellstrom6b82ef52012-02-09 16:56:42 +010065 struct list_head fence_events;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000066};
67
68struct vmw_dma_buffer {
69 struct ttm_buffer_object base;
70 struct list_head validate_list;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000071 bool gmr_bound;
72 uint32_t cur_validate_node;
73 bool on_validate_list;
74};
75
76struct vmw_resource {
77 struct kref kref;
78 struct vmw_private *dev_priv;
79 struct idr *idr;
80 int id;
81 enum ttm_object_type res_type;
82 bool avail;
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +020083 void (*remove_from_lists) (struct vmw_resource *res);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000084 void (*hw_destroy) (struct vmw_resource *res);
85 void (*res_free) (struct vmw_resource *res);
Thomas Hellstromf18c8842011-10-04 20:13:31 +020086 struct list_head validate_head;
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +020087 struct list_head query_head; /* Protected by the cmdbuf mutex */
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000088 /* TODO is a generic snooper needed? */
89#if 0
90 void (*snoop)(struct vmw_resource *res,
91 struct ttm_object_file *tfile,
92 SVGA3dCmdHeader *header);
93 void *snoop_priv;
94#endif
95};
96
97struct vmw_cursor_snooper {
98 struct drm_crtc *crtc;
99 size_t age;
100 uint32_t *image;
101};
102
Jakob Bornecrantz2fcd5a72011-10-04 20:13:26 +0200103struct vmw_framebuffer;
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +0200104struct vmw_surface_offset;
Jakob Bornecrantz2fcd5a72011-10-04 20:13:26 +0200105
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000106struct vmw_surface {
107 struct vmw_resource res;
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +0200108 struct list_head lru_head; /* Protected by the resource lock */
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000109 uint32_t flags;
110 uint32_t format;
111 uint32_t mip_levels[DRM_VMW_MAX_SURFACE_FACES];
112 struct drm_vmw_size *sizes;
113 uint32_t num_sizes;
114
Jakob Bornecrantz5ffdb652010-01-30 03:38:08 +0000115 bool scanout;
116
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000117 /* TODO so far just a extra pointer */
118 struct vmw_cursor_snooper snooper;
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +0200119 struct ttm_buffer_object *backup;
120 struct vmw_surface_offset *offsets;
121 uint32_t backup_size;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000122};
123
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +0000124struct vmw_marker_queue {
Thomas Hellstrom1925d452010-05-28 11:21:57 +0200125 struct list_head head;
126 struct timespec lag;
127 struct timespec lag_time;
128 spinlock_t lock;
129};
130
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000131struct vmw_fifo_state {
132 unsigned long reserved_size;
133 __le32 *dynamic_buffer;
134 __le32 *static_buffer;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000135 unsigned long static_buffer_size;
136 bool using_bounce_buffer;
137 uint32_t capabilities;
Thomas Hellstrom85b9e482010-02-08 09:57:25 +0000138 struct mutex fifo_mutex;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000139 struct rw_semaphore rwsem;
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +0000140 struct vmw_marker_queue marker_queue;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000141};
142
143struct vmw_relocation {
144 SVGAGuestPtr *location;
145 uint32_t index;
146};
147
148struct vmw_sw_context{
149 struct ida bo_list;
150 uint32_t last_cid;
151 bool cid_valid;
Thomas Hellstrom922ade02011-10-04 20:13:17 +0200152 bool kernel; /**< is the called made from the kernel */
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +0200153 struct vmw_resource *cur_ctx;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000154 uint32_t last_sid;
Thomas Hellstrom7a73ba72009-12-22 16:53:41 +0100155 uint32_t sid_translation;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000156 bool sid_valid;
157 struct ttm_object_file *tfile;
158 struct list_head validate_nodes;
159 struct vmw_relocation relocs[VMWGFX_MAX_RELOCATIONS];
160 uint32_t cur_reloc;
Thomas Hellstrombe38ab62011-08-31 07:42:54 +0000161 struct ttm_validate_buffer val_bufs[VMWGFX_MAX_VALIDATIONS];
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000162 uint32_t cur_val_buf;
Thomas Hellstrombe38ab62011-08-31 07:42:54 +0000163 uint32_t *cmd_bounce;
164 uint32_t cmd_bounce_size;
Thomas Hellstromf18c8842011-10-04 20:13:31 +0200165 struct list_head resource_list;
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +0200166 uint32_t fence_flags;
167 struct list_head query_list;
168 struct ttm_buffer_object *cur_query_bo;
169 uint32_t cur_query_cid;
170 bool query_cid_valid;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000171};
172
173struct vmw_legacy_display;
174struct vmw_overlay;
175
176struct vmw_master {
177 struct ttm_lock lock;
Thomas Hellstrom3a939a52010-10-05 12:43:03 +0200178 struct mutex fb_surf_mutex;
179 struct list_head fb_surf;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000180};
181
Thomas Hellstrom7c4f7782010-06-01 11:38:17 +0200182struct vmw_vga_topology_state {
183 uint32_t width;
184 uint32_t height;
185 uint32_t primary;
186 uint32_t pos_x;
187 uint32_t pos_y;
188};
189
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000190struct vmw_private {
191 struct ttm_bo_device bdev;
192 struct ttm_bo_global_ref bo_global_ref;
Dave Airlieba4420c2010-03-09 10:56:52 +1000193 struct drm_global_reference mem_global_ref;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000194
195 struct vmw_fifo_state fifo;
196
197 struct drm_device *dev;
198 unsigned long vmw_chipset;
199 unsigned int io_start;
200 uint32_t vram_start;
201 uint32_t vram_size;
202 uint32_t mmio_start;
203 uint32_t mmio_size;
204 uint32_t fb_max_width;
205 uint32_t fb_max_height;
206 __le32 __iomem *mmio_virt;
207 int mmio_mtrr;
208 uint32_t capabilities;
209 uint32_t max_gmr_descriptors;
210 uint32_t max_gmr_ids;
Thomas Hellstromfb17f182011-08-31 07:42:53 +0000211 uint32_t max_gmr_pages;
212 uint32_t memory_size;
Thomas Hellstrom135cba02010-10-26 21:21:47 +0200213 bool has_gmr;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000214 struct mutex hw_mutex;
215
216 /*
217 * VGA registers.
218 */
219
Thomas Hellstrom7c4f7782010-06-01 11:38:17 +0200220 struct vmw_vga_topology_state vga_save[VMWGFX_MAX_DISPLAYS];
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000221 uint32_t vga_width;
222 uint32_t vga_height;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000223 uint32_t vga_bpp;
Thomas Hellstrom7c4f7782010-06-01 11:38:17 +0200224 uint32_t vga_bpl;
Jakob Bornecrantzd7e19582010-05-28 11:21:59 +0200225 uint32_t vga_pitchlock;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000226
Thomas Hellstrom7c4f7782010-06-01 11:38:17 +0200227 uint32_t num_displays;
228
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000229 /*
230 * Framebuffer info.
231 */
232
233 void *fb_info;
234 struct vmw_legacy_display *ldu_priv;
Jakob Bornecrantz56d1c782011-10-04 20:13:22 +0200235 struct vmw_screen_object_display *sou_priv;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000236 struct vmw_overlay *overlay_priv;
237
238 /*
239 * Context and surface management.
240 */
241
242 rwlock_t resource_lock;
243 struct idr context_idr;
244 struct idr surface_idr;
245 struct idr stream_idr;
246
247 /*
248 * Block lastclose from racing with firstopen.
249 */
250
251 struct mutex init_mutex;
252
253 /*
254 * A resource manager for kernel-only surfaces and
255 * contexts.
256 */
257
258 struct ttm_object_device *tdev;
259
260 /*
261 * Fencing and IRQs.
262 */
263
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +0000264 atomic_t marker_seq;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000265 wait_queue_head_t fence_queue;
266 wait_queue_head_t fifo_queue;
Thomas Hellstrom4f73a962011-09-01 20:18:43 +0000267 int fence_queue_waiters; /* Protected by hw_mutex */
Thomas Hellstrom57c5ee72011-10-10 12:23:26 +0200268 int goal_queue_waiters; /* Protected by hw_mutex */
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000269 atomic_t fifo_queue_waiters;
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +0000270 uint32_t last_read_seqno;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000271 spinlock_t irq_lock;
Thomas Hellstromae2a1042011-09-01 20:18:44 +0000272 struct vmw_fence_manager *fman;
Thomas Hellstrom57c5ee72011-10-10 12:23:26 +0200273 uint32_t irq_mask;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000274
275 /*
276 * Device state
277 */
278
279 uint32_t traces_state;
280 uint32_t enable_state;
281 uint32_t config_done_state;
282
283 /**
284 * Execbuf
285 */
286 /**
287 * Protected by the cmdbuf mutex.
288 */
289
290 struct vmw_sw_context ctx;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000291 struct mutex cmdbuf_mutex;
292
293 /**
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000294 * Operating mode.
295 */
296
297 bool stealth;
298 bool is_opened;
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200299 bool enable_fb;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000300
301 /**
302 * Master management.
303 */
304
305 struct vmw_master *active_master;
306 struct vmw_master fbdev_master;
Thomas Hellstromd9f36a02010-01-13 22:28:43 +0100307 struct notifier_block pm_nb;
Thomas Hellstrom094e0fa2010-10-05 12:43:00 +0200308 bool suspended;
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200309
310 struct mutex release_mutex;
311 uint32_t num_3d_resources;
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +0200312
313 /*
314 * Query processing. These members
315 * are protected by the cmdbuf mutex.
316 */
317
318 struct ttm_buffer_object *dummy_query_bo;
319 struct ttm_buffer_object *pinned_bo;
320 uint32_t query_cid;
321 bool dummy_query_bo_pinned;
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +0200322
323 /*
324 * Surface swapping. The "surface_lru" list is protected by the
325 * resource lock in order to be able to destroy a surface and take
326 * it off the lru atomically. "used_memory_size" is currently
327 * protected by the cmdbuf mutex for simplicity.
328 */
329
330 struct list_head surface_lru;
331 uint32_t used_memory_size;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000332};
333
334static inline struct vmw_private *vmw_priv(struct drm_device *dev)
335{
336 return (struct vmw_private *)dev->dev_private;
337}
338
339static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
340{
341 return (struct vmw_fpriv *)file_priv->driver_priv;
342}
343
344static inline struct vmw_master *vmw_master(struct drm_master *master)
345{
346 return (struct vmw_master *) master->driver_priv;
347}
348
349static inline void vmw_write(struct vmw_private *dev_priv,
350 unsigned int offset, uint32_t value)
351{
352 outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
353 outl(value, dev_priv->io_start + VMWGFX_VALUE_PORT);
354}
355
356static inline uint32_t vmw_read(struct vmw_private *dev_priv,
357 unsigned int offset)
358{
359 uint32_t val;
360
361 outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
362 val = inl(dev_priv->io_start + VMWGFX_VALUE_PORT);
363 return val;
364}
365
Thomas Hellstrom05730b32011-08-31 07:42:52 +0000366int vmw_3d_resource_inc(struct vmw_private *dev_priv, bool unhide_svga);
367void vmw_3d_resource_dec(struct vmw_private *dev_priv, bool hide_svga);
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200368
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000369/**
370 * GMR utilities - vmwgfx_gmr.c
371 */
372
373extern int vmw_gmr_bind(struct vmw_private *dev_priv,
Thomas Hellstrom135cba02010-10-26 21:21:47 +0200374 struct page *pages[],
375 unsigned long num_pages,
376 int gmr_id);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000377extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
378
379/**
380 * Resource utilities - vmwgfx_resource.c
381 */
382
383extern struct vmw_resource *vmw_context_alloc(struct vmw_private *dev_priv);
384extern void vmw_resource_unreference(struct vmw_resource **p_res);
385extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
386extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
387 struct drm_file *file_priv);
388extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
389 struct drm_file *file_priv);
390extern int vmw_context_check(struct vmw_private *dev_priv,
391 struct ttm_object_file *tfile,
Thomas Hellstrombe38ab62011-08-31 07:42:54 +0000392 int id,
393 struct vmw_resource **p_res);
Jakob Bornecrantz551a6692011-11-28 13:19:11 +0100394extern int vmw_user_lookup_handle(struct vmw_private *dev_priv,
395 struct ttm_object_file *tfile,
396 uint32_t handle,
397 struct vmw_surface **out_surf,
398 struct vmw_dma_buffer **out_buf);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000399extern void vmw_surface_res_free(struct vmw_resource *res);
400extern int vmw_surface_init(struct vmw_private *dev_priv,
401 struct vmw_surface *srf,
402 void (*res_free) (struct vmw_resource *res));
Thomas Hellstrom7a73ba72009-12-22 16:53:41 +0100403extern int vmw_user_surface_lookup_handle(struct vmw_private *dev_priv,
404 struct ttm_object_file *tfile,
405 uint32_t handle,
406 struct vmw_surface **out);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000407extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data,
408 struct drm_file *file_priv);
409extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
410 struct drm_file *file_priv);
411extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,
412 struct drm_file *file_priv);
413extern int vmw_surface_check(struct vmw_private *dev_priv,
414 struct ttm_object_file *tfile,
Thomas Hellstrom7a73ba72009-12-22 16:53:41 +0100415 uint32_t handle, int *id);
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +0200416extern int vmw_surface_validate(struct vmw_private *dev_priv,
417 struct vmw_surface *srf);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000418extern void vmw_dmabuf_bo_free(struct ttm_buffer_object *bo);
419extern int vmw_dmabuf_init(struct vmw_private *dev_priv,
420 struct vmw_dma_buffer *vmw_bo,
421 size_t size, struct ttm_placement *placement,
422 bool interuptable,
423 void (*bo_free) (struct ttm_buffer_object *bo));
424extern int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data,
425 struct drm_file *file_priv);
426extern int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data,
427 struct drm_file *file_priv);
428extern uint32_t vmw_dmabuf_validate_node(struct ttm_buffer_object *bo,
429 uint32_t cur_validate_node);
430extern void vmw_dmabuf_validate_clear(struct ttm_buffer_object *bo);
431extern int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile,
432 uint32_t id, struct vmw_dma_buffer **out);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000433extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
434 struct drm_file *file_priv);
435extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
436 struct drm_file *file_priv);
437extern int vmw_user_stream_lookup(struct vmw_private *dev_priv,
438 struct ttm_object_file *tfile,
439 uint32_t *inout_id,
440 struct vmw_resource **out);
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +0200441extern void vmw_resource_unreserve(struct list_head *list);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000442
Jakob Bornecrantzd991ef02011-10-04 20:13:21 +0200443/**
444 * DMA buffer helper routines - vmwgfx_dmabuf.c
445 */
446extern int vmw_dmabuf_to_placement(struct vmw_private *vmw_priv,
447 struct vmw_dma_buffer *bo,
448 struct ttm_placement *placement,
449 bool interruptible);
450extern int vmw_dmabuf_to_vram(struct vmw_private *dev_priv,
451 struct vmw_dma_buffer *buf,
452 bool pin, bool interruptible);
453extern int vmw_dmabuf_to_vram_or_gmr(struct vmw_private *dev_priv,
454 struct vmw_dma_buffer *buf,
455 bool pin, bool interruptible);
456extern int vmw_dmabuf_to_start_of_vram(struct vmw_private *vmw_priv,
457 struct vmw_dma_buffer *bo,
458 bool pin, bool interruptible);
459extern int vmw_dmabuf_unpin(struct vmw_private *vmw_priv,
460 struct vmw_dma_buffer *bo,
461 bool interruptible);
Thomas Hellstromb37a6b92011-10-04 20:13:28 +0200462extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf,
463 SVGAGuestPtr *ptr);
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +0200464extern void vmw_bo_pin(struct ttm_buffer_object *bo, bool pin);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000465
466/**
467 * Misc Ioctl functionality - vmwgfx_ioctl.c
468 */
469
470extern int vmw_getparam_ioctl(struct drm_device *dev, void *data,
471 struct drm_file *file_priv);
Thomas Hellstromf63f6a52011-09-01 20:18:41 +0000472extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
473 struct drm_file *file_priv);
Jakob Bornecrantz2fcd5a72011-10-04 20:13:26 +0200474extern int vmw_present_ioctl(struct drm_device *dev, void *data,
475 struct drm_file *file_priv);
476extern int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
477 struct drm_file *file_priv);
Thomas Hellstrom5438ae82011-10-10 12:23:27 +0200478extern unsigned int vmw_fops_poll(struct file *filp,
479 struct poll_table_struct *wait);
480extern ssize_t vmw_fops_read(struct file *filp, char __user *buffer,
481 size_t count, loff_t *offset);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000482
483/**
484 * Fifo utilities - vmwgfx_fifo.c
485 */
486
487extern int vmw_fifo_init(struct vmw_private *dev_priv,
488 struct vmw_fifo_state *fifo);
489extern void vmw_fifo_release(struct vmw_private *dev_priv,
490 struct vmw_fifo_state *fifo);
491extern void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes);
492extern void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes);
493extern int vmw_fifo_send_fence(struct vmw_private *dev_priv,
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +0000494 uint32_t *seqno);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000495extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
Jakob Bornecrantz8e19a952010-01-30 03:38:06 +0000496extern bool vmw_fifo_have_3d(struct vmw_private *dev_priv);
Jakob Bornecrantzd7e19582010-05-28 11:21:59 +0200497extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv);
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +0200498extern int vmw_fifo_emit_dummy_query(struct vmw_private *dev_priv,
499 uint32_t cid);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000500
501/**
502 * TTM glue - vmwgfx_ttm_glue.c
503 */
504
505extern int vmw_ttm_global_init(struct vmw_private *dev_priv);
506extern void vmw_ttm_global_release(struct vmw_private *dev_priv);
507extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma);
508
509/**
510 * TTM buffer object driver - vmwgfx_buffer.c
511 */
512
513extern struct ttm_placement vmw_vram_placement;
514extern struct ttm_placement vmw_vram_ne_placement;
Thomas Hellstrom8ba51522010-01-16 16:05:05 +0100515extern struct ttm_placement vmw_vram_sys_placement;
Thomas Hellstrom135cba02010-10-26 21:21:47 +0200516extern struct ttm_placement vmw_vram_gmr_placement;
Jakob Bornecrantzd991ef02011-10-04 20:13:21 +0200517extern struct ttm_placement vmw_vram_gmr_ne_placement;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000518extern struct ttm_placement vmw_sys_placement;
Jakob Bornecrantzd991ef02011-10-04 20:13:21 +0200519extern struct ttm_placement vmw_evictable_placement;
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +0200520extern struct ttm_placement vmw_srf_placement;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000521extern struct ttm_bo_driver vmw_bo_driver;
522extern int vmw_dma_quiescent(struct drm_device *dev);
523
524/**
525 * Command submission - vmwgfx_execbuf.c
526 */
527
528extern int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
529 struct drm_file *file_priv);
Thomas Hellstrom922ade02011-10-04 20:13:17 +0200530extern int vmw_execbuf_process(struct drm_file *file_priv,
531 struct vmw_private *dev_priv,
532 void __user *user_commands,
533 void *kernel_commands,
534 uint32_t command_size,
535 uint64_t throttle_us,
536 struct drm_vmw_fence_rep __user
Jakob Bornecrantzbb1bd2f2012-02-09 16:56:43 +0100537 *user_fence_rep,
538 struct vmw_fence_obj **out_fence);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000539
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +0200540extern void
541vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv,
542 bool only_on_cid_match, uint32_t cid);
543
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +0200544extern int vmw_execbuf_fence_commands(struct drm_file *file_priv,
545 struct vmw_private *dev_priv,
546 struct vmw_fence_obj **p_fence,
547 uint32_t *p_handle);
Thomas Hellstrom57c5ee72011-10-10 12:23:26 +0200548extern void vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
549 struct vmw_fpriv *vmw_fp,
550 int ret,
551 struct drm_vmw_fence_rep __user
552 *user_fence_rep,
553 struct vmw_fence_obj *fence,
554 uint32_t fence_handle);
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +0200555
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000556/**
557 * IRQs and wating - vmwgfx_irq.c
558 */
559
560extern irqreturn_t vmw_irq_handler(DRM_IRQ_ARGS);
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +0000561extern int vmw_wait_seqno(struct vmw_private *dev_priv, bool lazy,
562 uint32_t seqno, bool interruptible,
563 unsigned long timeout);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000564extern void vmw_irq_preinstall(struct drm_device *dev);
565extern int vmw_irq_postinstall(struct drm_device *dev);
566extern void vmw_irq_uninstall(struct drm_device *dev);
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +0000567extern bool vmw_seqno_passed(struct vmw_private *dev_priv,
568 uint32_t seqno);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000569extern int vmw_fallback_wait(struct vmw_private *dev_priv,
570 bool lazy,
571 bool fifo_idle,
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +0000572 uint32_t seqno,
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000573 bool interruptible,
574 unsigned long timeout);
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +0000575extern void vmw_update_seqno(struct vmw_private *dev_priv,
Thomas Hellstrom1925d452010-05-28 11:21:57 +0200576 struct vmw_fifo_state *fifo_state);
Thomas Hellstromae2a1042011-09-01 20:18:44 +0000577extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
578extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
Thomas Hellstrom57c5ee72011-10-10 12:23:26 +0200579extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
580extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv);
Thomas Hellstrom1925d452010-05-28 11:21:57 +0200581
582/**
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +0000583 * Rudimentary fence-like objects currently used only for throttling -
584 * vmwgfx_marker.c
Thomas Hellstrom1925d452010-05-28 11:21:57 +0200585 */
586
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +0000587extern void vmw_marker_queue_init(struct vmw_marker_queue *queue);
588extern void vmw_marker_queue_takedown(struct vmw_marker_queue *queue);
589extern int vmw_marker_push(struct vmw_marker_queue *queue,
590 uint32_t seqno);
591extern int vmw_marker_pull(struct vmw_marker_queue *queue,
592 uint32_t signaled_seqno);
Thomas Hellstrom1925d452010-05-28 11:21:57 +0200593extern int vmw_wait_lag(struct vmw_private *dev_priv,
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +0000594 struct vmw_marker_queue *queue, uint32_t us);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000595
596/**
597 * Kernel framebuffer - vmwgfx_fb.c
598 */
599
600int vmw_fb_init(struct vmw_private *vmw_priv);
601int vmw_fb_close(struct vmw_private *dev_priv);
602int vmw_fb_off(struct vmw_private *vmw_priv);
603int vmw_fb_on(struct vmw_private *vmw_priv);
604
605/**
606 * Kernel modesetting - vmwgfx_kms.c
607 */
608
609int vmw_kms_init(struct vmw_private *dev_priv);
610int vmw_kms_close(struct vmw_private *dev_priv);
611int vmw_kms_save_vga(struct vmw_private *vmw_priv);
612int vmw_kms_restore_vga(struct vmw_private *vmw_priv);
613int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
614 struct drm_file *file_priv);
615void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
616void vmw_kms_cursor_snoop(struct vmw_surface *srf,
617 struct ttm_object_file *tfile,
618 struct ttm_buffer_object *bo,
619 SVGA3dCmdHeader *header);
Michel Dänzer0bef23f2011-08-31 07:42:50 +0000620int vmw_kms_write_svga(struct vmw_private *vmw_priv,
621 unsigned width, unsigned height, unsigned pitch,
622 unsigned bpp, unsigned depth);
Thomas Hellstrom3a939a52010-10-05 12:43:03 +0200623void vmw_kms_idle_workqueues(struct vmw_master *vmaster);
Thomas Hellstrome133e7372010-10-05 12:43:04 +0200624bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
625 uint32_t pitch,
626 uint32_t height);
Thomas Hellstrom7a1c2f62010-10-01 10:21:49 +0200627u32 vmw_get_vblank_counter(struct drm_device *dev, int crtc);
Jakob Bornecrantz1c482ab2011-10-17 11:59:45 +0200628int vmw_enable_vblank(struct drm_device *dev, int crtc);
629void vmw_disable_vblank(struct drm_device *dev, int crtc);
Jakob Bornecrantz2fcd5a72011-10-04 20:13:26 +0200630int vmw_kms_present(struct vmw_private *dev_priv,
631 struct drm_file *file_priv,
632 struct vmw_framebuffer *vfb,
633 struct vmw_surface *surface,
634 uint32_t sid, int32_t destX, int32_t destY,
635 struct drm_vmw_rect *clips,
636 uint32_t num_clips);
637int vmw_kms_readback(struct vmw_private *dev_priv,
638 struct drm_file *file_priv,
639 struct vmw_framebuffer *vfb,
640 struct drm_vmw_fence_rep __user *user_fence_rep,
641 struct drm_vmw_rect *clips,
642 uint32_t num_clips);
Thomas Hellstromcd2b89e2011-10-25 23:35:53 +0200643int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
644 struct drm_file *file_priv);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000645
646/**
647 * Overlay control - vmwgfx_overlay.c
648 */
649
650int vmw_overlay_init(struct vmw_private *dev_priv);
651int vmw_overlay_close(struct vmw_private *dev_priv);
652int vmw_overlay_ioctl(struct drm_device *dev, void *data,
653 struct drm_file *file_priv);
654int vmw_overlay_stop_all(struct vmw_private *dev_priv);
655int vmw_overlay_resume_all(struct vmw_private *dev_priv);
656int vmw_overlay_pause_all(struct vmw_private *dev_priv);
657int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
658int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
659int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
660int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
661
662/**
Jakob Bornecrantz8b7de6a2012-02-09 16:56:41 +0100663 * Fence function - vmwgfx_fence.c
664 */
665
666int vmw_event_fence_action_queue(struct drm_file *file_priv,
667 struct vmw_fence_obj *fence,
668 struct drm_pending_event *event,
669 uint32_t *tv_sec,
670 uint32_t *tv_usec,
671 bool interruptible);
672
673
674/**
Thomas Hellstrom135cba02010-10-26 21:21:47 +0200675 * GMR Id manager
676 */
677
678extern const struct ttm_mem_type_manager_func vmw_gmrid_manager_func;
679
680/**
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000681 * Inline helper functions
682 */
683
684static inline void vmw_surface_unreference(struct vmw_surface **srf)
685{
686 struct vmw_surface *tmp_srf = *srf;
687 struct vmw_resource *res = &tmp_srf->res;
688 *srf = NULL;
689
690 vmw_resource_unreference(&res);
691}
692
693static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
694{
695 (void) vmw_resource_reference(&srf->res);
696 return srf;
697}
698
699static inline void vmw_dmabuf_unreference(struct vmw_dma_buffer **buf)
700{
701 struct vmw_dma_buffer *tmp_buf = *buf;
702 struct ttm_buffer_object *bo = &tmp_buf->base;
703 *buf = NULL;
704
705 ttm_bo_unref(&bo);
706}
707
708static inline struct vmw_dma_buffer *vmw_dmabuf_reference(struct vmw_dma_buffer *buf)
709{
710 if (ttm_bo_reference(&buf->base))
711 return buf;
712 return NULL;
713}
714
Thomas Hellstromae2a1042011-09-01 20:18:44 +0000715static inline struct ttm_mem_global *vmw_mem_glob(struct vmw_private *dev_priv)
716{
717 return (struct ttm_mem_global *) dev_priv->mem_global_ref.object;
718}
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000719#endif