drm/vmwgfx: Make sure that the multisampling is off
[linux-2.6-block.git] / drivers / gpu / drm / vmwgfx / vmwgfx_drv.h
CommitLineData
fb1d9738
JB
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"
760285e7
DH
32#include <drm/drmP.h>
33#include <drm/vmwgfx_drm.h>
34#include <drm/drm_hashtab.h>
35#include <linux/suspend.h>
36#include <drm/ttm/ttm_bo_driver.h>
37#include <drm/ttm/ttm_object.h>
38#include <drm/ttm/ttm_lock.h>
39#include <drm/ttm/ttm_execbuf_util.h>
40#include <drm/ttm/ttm_module.h>
ae2a1040 41#include "vmwgfx_fence.h"
fb1d9738 42
0a240ec4 43#define VMWGFX_DRIVER_DATE "20120209"
2ae7b03c 44#define VMWGFX_DRIVER_MAJOR 2
0a240ec4 45#define VMWGFX_DRIVER_MINOR 4
f77cef3d 46#define VMWGFX_DRIVER_PATCHLEVEL 0
fb1d9738
JB
47#define VMWGFX_FILE_PAGE_OFFSET 0x00100000
48#define VMWGFX_FIFO_STATIC_SIZE (1024*1024)
49#define VMWGFX_MAX_RELOCATIONS 2048
be38ab6e 50#define VMWGFX_MAX_VALIDATIONS 2048
7c4f7780 51#define VMWGFX_MAX_DISPLAYS 16
be38ab6e 52#define VMWGFX_CMD_BOUNCE_INIT_SIZE 32768
fb1d9738 53
3530bdc3
TH
54/*
55 * Perhaps we should have sysfs entries for these.
56 */
57#define VMWGFX_NUM_GB_CONTEXT 256
58#define VMWGFX_NUM_GB_SHADER 20000
59#define VMWGFX_NUM_GB_SURFACE 32768
60#define VMWGFX_NUM_MOB (VMWGFX_NUM_GB_CONTEXT +\
61 VMWGFX_NUM_GB_SHADER +\
62 VMWGFX_NUM_GB_SURFACE)
63
135cba0d
TH
64#define VMW_PL_GMR TTM_PL_PRIV0
65#define VMW_PL_FLAG_GMR TTM_PL_FLAG_PRIV0
6da768aa
TH
66#define VMW_PL_MOB TTM_PL_PRIV1
67#define VMW_PL_FLAG_MOB TTM_PL_FLAG_PRIV1
135cba0d 68
ae2a1040
TH
69#define VMW_RES_CONTEXT ttm_driver_type0
70#define VMW_RES_SURFACE ttm_driver_type1
71#define VMW_RES_STREAM ttm_driver_type2
72#define VMW_RES_FENCE ttm_driver_type3
c74c162f 73#define VMW_RES_SHADER ttm_driver_type4
ae2a1040 74
fb1d9738
JB
75struct vmw_fpriv {
76 struct drm_master *locked_master;
77 struct ttm_object_file *tfile;
6b82ef50 78 struct list_head fence_events;
fb1d9738
JB
79};
80
81struct vmw_dma_buffer {
82 struct ttm_buffer_object base;
c0951b79 83 struct list_head res_list;
fb1d9738
JB
84};
85
c0951b79
TH
86/**
87 * struct vmw_validate_buffer - Carries validation info about buffers.
88 *
89 * @base: Validation info for TTM.
90 * @hash: Hash entry for quick lookup of the TTM buffer object.
91 *
92 * This structure contains also driver private validation info
93 * on top of the info needed by TTM.
94 */
95struct vmw_validate_buffer {
96 struct ttm_validate_buffer base;
97 struct drm_hash_item hash;
96c5f0df 98 bool validate_as_mob;
c0951b79
TH
99};
100
101struct vmw_res_func;
fb1d9738
JB
102struct vmw_resource {
103 struct kref kref;
104 struct vmw_private *dev_priv;
fb1d9738 105 int id;
fb1d9738 106 bool avail;
c0951b79
TH
107 unsigned long backup_size;
108 bool res_dirty; /* Protected by backup buffer reserved */
109 bool backup_dirty; /* Protected by backup buffer reserved */
110 struct vmw_dma_buffer *backup;
111 unsigned long backup_offset;
112 const struct vmw_res_func *func;
113 struct list_head lru_head; /* Protected by the resource lock */
114 struct list_head mob_head; /* Protected by @backup reserved */
fb1d9738 115 void (*res_free) (struct vmw_resource *res);
c0951b79
TH
116 void (*hw_destroy) (struct vmw_resource *res);
117};
118
119enum vmw_res_type {
120 vmw_res_context,
121 vmw_res_surface,
122 vmw_res_stream,
c74c162f 123 vmw_res_shader,
c0951b79 124 vmw_res_max
fb1d9738
JB
125};
126
127struct vmw_cursor_snooper {
128 struct drm_crtc *crtc;
129 size_t age;
130 uint32_t *image;
131};
132
2fcd5a73 133struct vmw_framebuffer;
5bb39e81 134struct vmw_surface_offset;
2fcd5a73 135
fb1d9738
JB
136struct vmw_surface {
137 struct vmw_resource res;
138 uint32_t flags;
139 uint32_t format;
140 uint32_t mip_levels[DRM_VMW_MAX_SURFACE_FACES];
c0951b79 141 struct drm_vmw_size base_size;
fb1d9738
JB
142 struct drm_vmw_size *sizes;
143 uint32_t num_sizes;
5ffdb658 144 bool scanout;
fb1d9738
JB
145 /* TODO so far just a extra pointer */
146 struct vmw_cursor_snooper snooper;
5bb39e81 147 struct vmw_surface_offset *offsets;
c0951b79
TH
148 SVGA3dTextureFilter autogen_filter;
149 uint32_t multisample_count;
fb1d9738
JB
150};
151
6bcd8d3c 152struct vmw_marker_queue {
1925d456
TH
153 struct list_head head;
154 struct timespec lag;
155 struct timespec lag_time;
156 spinlock_t lock;
157};
158
fb1d9738
JB
159struct vmw_fifo_state {
160 unsigned long reserved_size;
161 __le32 *dynamic_buffer;
162 __le32 *static_buffer;
fb1d9738
JB
163 unsigned long static_buffer_size;
164 bool using_bounce_buffer;
165 uint32_t capabilities;
85b9e487 166 struct mutex fifo_mutex;
fb1d9738 167 struct rw_semaphore rwsem;
6bcd8d3c 168 struct vmw_marker_queue marker_queue;
fb1d9738
JB
169};
170
171struct vmw_relocation {
ddcda24e 172 SVGAMobId *mob_loc;
fb1d9738
JB
173 SVGAGuestPtr *location;
174 uint32_t index;
175};
176
c0951b79
TH
177/**
178 * struct vmw_res_cache_entry - resource information cache entry
179 *
180 * @valid: Whether the entry is valid, which also implies that the execbuf
181 * code holds a reference to the resource, and it's placed on the
182 * validation list.
183 * @handle: User-space handle of a resource.
184 * @res: Non-ref-counted pointer to the resource.
185 *
186 * Used to avoid frequent repeated user-space handle lookups of the
187 * same resource.
188 */
189struct vmw_res_cache_entry {
190 bool valid;
191 uint32_t handle;
192 struct vmw_resource *res;
193 struct vmw_resource_val_node *node;
194};
195
d92d9851
TH
196/**
197 * enum vmw_dma_map_mode - indicate how to perform TTM page dma mappings.
198 */
199enum vmw_dma_map_mode {
200 vmw_dma_phys, /* Use physical page addresses */
201 vmw_dma_alloc_coherent, /* Use TTM coherent pages */
202 vmw_dma_map_populate, /* Unmap from DMA just after unpopulate */
203 vmw_dma_map_bind, /* Unmap from DMA just before unbind */
204 vmw_dma_map_max
205};
206
207/**
208 * struct vmw_sg_table - Scatter/gather table for binding, with additional
209 * device-specific information.
210 *
211 * @sgt: Pointer to a struct sg_table with binding information
212 * @num_regions: Number of regions with device-address contigous pages
213 */
214struct vmw_sg_table {
215 enum vmw_dma_map_mode mode;
216 struct page **pages;
217 const dma_addr_t *addrs;
218 struct sg_table *sgt;
219 unsigned long num_regions;
220 unsigned long num_pages;
221};
222
223/**
224 * struct vmw_piter - Page iterator that iterates over a list of pages
225 * and DMA addresses that could be either a scatter-gather list or
226 * arrays
227 *
228 * @pages: Array of page pointers to the pages.
229 * @addrs: DMA addresses to the pages if coherent pages are used.
230 * @iter: Scatter-gather page iterator. Current position in SG list.
231 * @i: Current position in arrays.
232 * @num_pages: Number of pages total.
233 * @next: Function to advance the iterator. Returns false if past the list
234 * of pages, true otherwise.
235 * @dma_address: Function to return the DMA address of the current page.
236 */
237struct vmw_piter {
238 struct page **pages;
239 const dma_addr_t *addrs;
240 struct sg_page_iter iter;
241 unsigned long i;
242 unsigned long num_pages;
243 bool (*next)(struct vmw_piter *);
244 dma_addr_t (*dma_address)(struct vmw_piter *);
245 struct page *(*page)(struct vmw_piter *);
246};
247
fb1d9738 248struct vmw_sw_context{
c0951b79
TH
249 struct drm_open_hash res_ht;
250 bool res_ht_initialized;
922ade0d 251 bool kernel; /**< is the called made from the kernel */
fb1d9738
JB
252 struct ttm_object_file *tfile;
253 struct list_head validate_nodes;
254 struct vmw_relocation relocs[VMWGFX_MAX_RELOCATIONS];
255 uint32_t cur_reloc;
c0951b79 256 struct vmw_validate_buffer val_bufs[VMWGFX_MAX_VALIDATIONS];
fb1d9738 257 uint32_t cur_val_buf;
be38ab6e
TH
258 uint32_t *cmd_bounce;
259 uint32_t cmd_bounce_size;
f18c8840 260 struct list_head resource_list;
e2fa3a76 261 uint32_t fence_flags;
e2fa3a76 262 struct ttm_buffer_object *cur_query_bo;
c0951b79
TH
263 struct list_head res_relocations;
264 uint32_t *buf_start;
265 struct vmw_res_cache_entry res_cache[vmw_res_max];
266 struct vmw_resource *last_query_ctx;
267 bool needs_post_query_barrier;
268 struct vmw_resource *error_resource;
fb1d9738
JB
269};
270
271struct vmw_legacy_display;
272struct vmw_overlay;
273
274struct vmw_master {
275 struct ttm_lock lock;
3a939a5e
TH
276 struct mutex fb_surf_mutex;
277 struct list_head fb_surf;
fb1d9738
JB
278};
279
7c4f7780
TH
280struct vmw_vga_topology_state {
281 uint32_t width;
282 uint32_t height;
283 uint32_t primary;
284 uint32_t pos_x;
285 uint32_t pos_y;
286};
287
fb1d9738
JB
288struct vmw_private {
289 struct ttm_bo_device bdev;
290 struct ttm_bo_global_ref bo_global_ref;
ba4420c2 291 struct drm_global_reference mem_global_ref;
fb1d9738
JB
292
293 struct vmw_fifo_state fifo;
294
295 struct drm_device *dev;
296 unsigned long vmw_chipset;
297 unsigned int io_start;
298 uint32_t vram_start;
299 uint32_t vram_size;
bc2d6508 300 uint32_t prim_bb_mem;
fb1d9738
JB
301 uint32_t mmio_start;
302 uint32_t mmio_size;
303 uint32_t fb_max_width;
304 uint32_t fb_max_height;
eb4f923b
JB
305 uint32_t initial_width;
306 uint32_t initial_height;
fb1d9738
JB
307 __le32 __iomem *mmio_virt;
308 int mmio_mtrr;
309 uint32_t capabilities;
fb1d9738 310 uint32_t max_gmr_ids;
fb17f189 311 uint32_t max_gmr_pages;
6da768aa 312 uint32_t max_mob_pages;
fb17f189 313 uint32_t memory_size;
135cba0d 314 bool has_gmr;
3530bdc3 315 bool has_mob;
fb1d9738
JB
316 struct mutex hw_mutex;
317
318 /*
319 * VGA registers.
320 */
321
7c4f7780 322 struct vmw_vga_topology_state vga_save[VMWGFX_MAX_DISPLAYS];
fb1d9738
JB
323 uint32_t vga_width;
324 uint32_t vga_height;
fb1d9738 325 uint32_t vga_bpp;
7c4f7780 326 uint32_t vga_bpl;
d7e1958d 327 uint32_t vga_pitchlock;
fb1d9738 328
7c4f7780
TH
329 uint32_t num_displays;
330
fb1d9738
JB
331 /*
332 * Framebuffer info.
333 */
334
335 void *fb_info;
336 struct vmw_legacy_display *ldu_priv;
56d1c78d 337 struct vmw_screen_object_display *sou_priv;
fb1d9738
JB
338 struct vmw_overlay *overlay_priv;
339
340 /*
341 * Context and surface management.
342 */
343
344 rwlock_t resource_lock;
c0951b79 345 struct idr res_idr[vmw_res_max];
fb1d9738
JB
346 /*
347 * Block lastclose from racing with firstopen.
348 */
349
350 struct mutex init_mutex;
351
352 /*
353 * A resource manager for kernel-only surfaces and
354 * contexts.
355 */
356
357 struct ttm_object_device *tdev;
358
359 /*
360 * Fencing and IRQs.
361 */
362
6bcd8d3c 363 atomic_t marker_seq;
fb1d9738
JB
364 wait_queue_head_t fence_queue;
365 wait_queue_head_t fifo_queue;
4f73a96b 366 int fence_queue_waiters; /* Protected by hw_mutex */
57c5ee79 367 int goal_queue_waiters; /* Protected by hw_mutex */
fb1d9738 368 atomic_t fifo_queue_waiters;
6bcd8d3c 369 uint32_t last_read_seqno;
fb1d9738 370 spinlock_t irq_lock;
ae2a1040 371 struct vmw_fence_manager *fman;
57c5ee79 372 uint32_t irq_mask;
fb1d9738
JB
373
374 /*
375 * Device state
376 */
377
378 uint32_t traces_state;
379 uint32_t enable_state;
380 uint32_t config_done_state;
381
382 /**
383 * Execbuf
384 */
385 /**
386 * Protected by the cmdbuf mutex.
387 */
388
389 struct vmw_sw_context ctx;
fb1d9738
JB
390 struct mutex cmdbuf_mutex;
391
fb1d9738
JB
392 /**
393 * Operating mode.
394 */
395
396 bool stealth;
30c78bb8 397 bool enable_fb;
fb1d9738
JB
398
399 /**
400 * Master management.
401 */
402
403 struct vmw_master *active_master;
404 struct vmw_master fbdev_master;
d9f36a00 405 struct notifier_block pm_nb;
094e0fa8 406 bool suspended;
30c78bb8
TH
407
408 struct mutex release_mutex;
409 uint32_t num_3d_resources;
e2fa3a76
TH
410
411 /*
412 * Query processing. These members
413 * are protected by the cmdbuf mutex.
414 */
415
416 struct ttm_buffer_object *dummy_query_bo;
417 struct ttm_buffer_object *pinned_bo;
418 uint32_t query_cid;
c0951b79 419 uint32_t query_cid_valid;
e2fa3a76 420 bool dummy_query_bo_pinned;
5bb39e81
TH
421
422 /*
423 * Surface swapping. The "surface_lru" list is protected by the
424 * resource lock in order to be able to destroy a surface and take
425 * it off the lru atomically. "used_memory_size" is currently
426 * protected by the cmdbuf mutex for simplicity.
427 */
428
c0951b79 429 struct list_head res_lru[vmw_res_max];
5bb39e81 430 uint32_t used_memory_size;
d92d9851
TH
431
432 /*
433 * DMA mapping stuff.
434 */
435 enum vmw_dma_map_mode map_mode;
3530bdc3
TH
436
437 /*
438 * Guest Backed stuff
439 */
440 struct ttm_buffer_object *otable_bo;
441 struct vmw_otable *otables;
fb1d9738
JB
442};
443
c0951b79
TH
444static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res)
445{
446 return container_of(res, struct vmw_surface, res);
447}
448
fb1d9738
JB
449static inline struct vmw_private *vmw_priv(struct drm_device *dev)
450{
451 return (struct vmw_private *)dev->dev_private;
452}
453
454static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
455{
456 return (struct vmw_fpriv *)file_priv->driver_priv;
457}
458
459static inline struct vmw_master *vmw_master(struct drm_master *master)
460{
461 return (struct vmw_master *) master->driver_priv;
462}
463
464static inline void vmw_write(struct vmw_private *dev_priv,
465 unsigned int offset, uint32_t value)
466{
467 outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
468 outl(value, dev_priv->io_start + VMWGFX_VALUE_PORT);
469}
470
471static inline uint32_t vmw_read(struct vmw_private *dev_priv,
472 unsigned int offset)
473{
474 uint32_t val;
475
476 outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
477 val = inl(dev_priv->io_start + VMWGFX_VALUE_PORT);
478 return val;
479}
480
05730b32
TH
481int vmw_3d_resource_inc(struct vmw_private *dev_priv, bool unhide_svga);
482void vmw_3d_resource_dec(struct vmw_private *dev_priv, bool hide_svga);
30c78bb8 483
fb1d9738
JB
484/**
485 * GMR utilities - vmwgfx_gmr.c
486 */
487
488extern int vmw_gmr_bind(struct vmw_private *dev_priv,
d92d9851 489 const struct vmw_sg_table *vsgt,
135cba0d
TH
490 unsigned long num_pages,
491 int gmr_id);
fb1d9738
JB
492extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
493
494/**
495 * Resource utilities - vmwgfx_resource.c
496 */
c0951b79 497struct vmw_user_resource_conv;
fb1d9738 498
fb1d9738
JB
499extern void vmw_resource_unreference(struct vmw_resource **p_res);
500extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
c0951b79
TH
501extern int vmw_resource_validate(struct vmw_resource *res);
502extern int vmw_resource_reserve(struct vmw_resource *res, bool no_backup);
503extern bool vmw_resource_needs_backup(const struct vmw_resource *res);
551a6697
JB
504extern int vmw_user_lookup_handle(struct vmw_private *dev_priv,
505 struct ttm_object_file *tfile,
506 uint32_t handle,
507 struct vmw_surface **out_surf,
508 struct vmw_dma_buffer **out_buf);
c0951b79
TH
509extern int vmw_user_resource_lookup_handle(
510 struct vmw_private *dev_priv,
511 struct ttm_object_file *tfile,
512 uint32_t handle,
513 const struct vmw_user_resource_conv *converter,
514 struct vmw_resource **p_res);
fb1d9738
JB
515extern void vmw_dmabuf_bo_free(struct ttm_buffer_object *bo);
516extern int vmw_dmabuf_init(struct vmw_private *dev_priv,
517 struct vmw_dma_buffer *vmw_bo,
518 size_t size, struct ttm_placement *placement,
519 bool interuptable,
520 void (*bo_free) (struct ttm_buffer_object *bo));
d08a9b9c
TH
521extern int vmw_user_dmabuf_verify_access(struct ttm_buffer_object *bo,
522 struct ttm_object_file *tfile);
a97e2192
TH
523extern int vmw_user_dmabuf_alloc(struct vmw_private *dev_priv,
524 struct ttm_object_file *tfile,
525 uint32_t size,
526 bool shareable,
527 uint32_t *handle,
528 struct vmw_dma_buffer **p_dma_buf);
529extern int vmw_user_dmabuf_reference(struct ttm_object_file *tfile,
530 struct vmw_dma_buffer *dma_buf,
531 uint32_t *handle);
fb1d9738
JB
532extern int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data,
533 struct drm_file *file_priv);
534extern int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data,
535 struct drm_file *file_priv);
536extern uint32_t vmw_dmabuf_validate_node(struct ttm_buffer_object *bo,
537 uint32_t cur_validate_node);
538extern void vmw_dmabuf_validate_clear(struct ttm_buffer_object *bo);
539extern int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile,
540 uint32_t id, struct vmw_dma_buffer **out);
fb1d9738
JB
541extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
542 struct drm_file *file_priv);
543extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
544 struct drm_file *file_priv);
545extern int vmw_user_stream_lookup(struct vmw_private *dev_priv,
546 struct ttm_object_file *tfile,
547 uint32_t *inout_id,
548 struct vmw_resource **out);
c0951b79
TH
549extern void vmw_resource_unreserve(struct vmw_resource *res,
550 struct vmw_dma_buffer *new_backup,
551 unsigned long new_backup_offset);
552extern void vmw_resource_move_notify(struct ttm_buffer_object *bo,
553 struct ttm_mem_reg *mem);
554extern void vmw_fence_single_bo(struct ttm_buffer_object *bo,
555 struct vmw_fence_obj *fence);
556extern void vmw_resource_evict_all(struct vmw_private *dev_priv);
fb1d9738 557
d991ef03
JB
558/**
559 * DMA buffer helper routines - vmwgfx_dmabuf.c
560 */
561extern int vmw_dmabuf_to_placement(struct vmw_private *vmw_priv,
562 struct vmw_dma_buffer *bo,
563 struct ttm_placement *placement,
564 bool interruptible);
565extern int vmw_dmabuf_to_vram(struct vmw_private *dev_priv,
566 struct vmw_dma_buffer *buf,
567 bool pin, bool interruptible);
568extern int vmw_dmabuf_to_vram_or_gmr(struct vmw_private *dev_priv,
569 struct vmw_dma_buffer *buf,
570 bool pin, bool interruptible);
571extern int vmw_dmabuf_to_start_of_vram(struct vmw_private *vmw_priv,
572 struct vmw_dma_buffer *bo,
573 bool pin, bool interruptible);
574extern int vmw_dmabuf_unpin(struct vmw_private *vmw_priv,
575 struct vmw_dma_buffer *bo,
576 bool interruptible);
b37a6b9a
TH
577extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf,
578 SVGAGuestPtr *ptr);
e2fa3a76 579extern void vmw_bo_pin(struct ttm_buffer_object *bo, bool pin);
fb1d9738
JB
580
581/**
582 * Misc Ioctl functionality - vmwgfx_ioctl.c
583 */
584
585extern int vmw_getparam_ioctl(struct drm_device *dev, void *data,
586 struct drm_file *file_priv);
f63f6a59
TH
587extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
588 struct drm_file *file_priv);
2fcd5a73
JB
589extern int vmw_present_ioctl(struct drm_device *dev, void *data,
590 struct drm_file *file_priv);
591extern int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
592 struct drm_file *file_priv);
5438ae88
TH
593extern unsigned int vmw_fops_poll(struct file *filp,
594 struct poll_table_struct *wait);
595extern ssize_t vmw_fops_read(struct file *filp, char __user *buffer,
596 size_t count, loff_t *offset);
fb1d9738
JB
597
598/**
599 * Fifo utilities - vmwgfx_fifo.c
600 */
601
602extern int vmw_fifo_init(struct vmw_private *dev_priv,
603 struct vmw_fifo_state *fifo);
604extern void vmw_fifo_release(struct vmw_private *dev_priv,
605 struct vmw_fifo_state *fifo);
606extern void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes);
607extern void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes);
608extern int vmw_fifo_send_fence(struct vmw_private *dev_priv,
6bcd8d3c 609 uint32_t *seqno);
fb1d9738 610extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
8e19a951 611extern bool vmw_fifo_have_3d(struct vmw_private *dev_priv);
d7e1958d 612extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv);
e2fa3a76
TH
613extern int vmw_fifo_emit_dummy_query(struct vmw_private *dev_priv,
614 uint32_t cid);
fb1d9738
JB
615
616/**
617 * TTM glue - vmwgfx_ttm_glue.c
618 */
619
620extern int vmw_ttm_global_init(struct vmw_private *dev_priv);
621extern void vmw_ttm_global_release(struct vmw_private *dev_priv);
622extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma);
623
624/**
625 * TTM buffer object driver - vmwgfx_buffer.c
626 */
627
308d17ef 628extern const size_t vmw_tt_size;
fb1d9738
JB
629extern struct ttm_placement vmw_vram_placement;
630extern struct ttm_placement vmw_vram_ne_placement;
8ba5152a 631extern struct ttm_placement vmw_vram_sys_placement;
135cba0d 632extern struct ttm_placement vmw_vram_gmr_placement;
d991ef03 633extern struct ttm_placement vmw_vram_gmr_ne_placement;
fb1d9738 634extern struct ttm_placement vmw_sys_placement;
3530bdc3 635extern struct ttm_placement vmw_sys_ne_placement;
d991ef03 636extern struct ttm_placement vmw_evictable_placement;
5bb39e81 637extern struct ttm_placement vmw_srf_placement;
96c5f0df 638extern struct ttm_placement vmw_mob_placement;
fb1d9738
JB
639extern struct ttm_bo_driver vmw_bo_driver;
640extern int vmw_dma_quiescent(struct drm_device *dev);
d92d9851
TH
641extern void vmw_piter_start(struct vmw_piter *viter,
642 const struct vmw_sg_table *vsgt,
643 unsigned long p_offs);
644
645/**
646 * vmw_piter_next - Advance the iterator one page.
647 *
648 * @viter: Pointer to the iterator to advance.
649 *
650 * Returns false if past the list of pages, true otherwise.
651 */
652static inline bool vmw_piter_next(struct vmw_piter *viter)
653{
654 return viter->next(viter);
655}
656
657/**
658 * vmw_piter_dma_addr - Return the DMA address of the current page.
659 *
660 * @viter: Pointer to the iterator
661 *
662 * Returns the DMA address of the page pointed to by @viter.
663 */
664static inline dma_addr_t vmw_piter_dma_addr(struct vmw_piter *viter)
665{
666 return viter->dma_address(viter);
667}
668
669/**
670 * vmw_piter_page - Return a pointer to the current page.
671 *
672 * @viter: Pointer to the iterator
673 *
674 * Returns the DMA address of the page pointed to by @viter.
675 */
676static inline struct page *vmw_piter_page(struct vmw_piter *viter)
677{
678 return viter->page(viter);
679}
fb1d9738
JB
680
681/**
682 * Command submission - vmwgfx_execbuf.c
683 */
684
685extern int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
686 struct drm_file *file_priv);
922ade0d
TH
687extern int vmw_execbuf_process(struct drm_file *file_priv,
688 struct vmw_private *dev_priv,
689 void __user *user_commands,
690 void *kernel_commands,
691 uint32_t command_size,
692 uint64_t throttle_us,
693 struct drm_vmw_fence_rep __user
bb1bd2f4
JB
694 *user_fence_rep,
695 struct vmw_fence_obj **out_fence);
c0951b79
TH
696extern void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv,
697 struct vmw_fence_obj *fence);
698extern void vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv);
e2fa3a76 699
5bb39e81
TH
700extern int vmw_execbuf_fence_commands(struct drm_file *file_priv,
701 struct vmw_private *dev_priv,
702 struct vmw_fence_obj **p_fence,
703 uint32_t *p_handle);
57c5ee79
TH
704extern void vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
705 struct vmw_fpriv *vmw_fp,
706 int ret,
707 struct drm_vmw_fence_rep __user
708 *user_fence_rep,
709 struct vmw_fence_obj *fence,
710 uint32_t fence_handle);
5bb39e81 711
fb1d9738
JB
712/**
713 * IRQs and wating - vmwgfx_irq.c
714 */
715
e9f0d76f 716extern irqreturn_t vmw_irq_handler(int irq, void *arg);
6bcd8d3c
TH
717extern int vmw_wait_seqno(struct vmw_private *dev_priv, bool lazy,
718 uint32_t seqno, bool interruptible,
719 unsigned long timeout);
fb1d9738
JB
720extern void vmw_irq_preinstall(struct drm_device *dev);
721extern int vmw_irq_postinstall(struct drm_device *dev);
722extern void vmw_irq_uninstall(struct drm_device *dev);
6bcd8d3c
TH
723extern bool vmw_seqno_passed(struct vmw_private *dev_priv,
724 uint32_t seqno);
fb1d9738
JB
725extern int vmw_fallback_wait(struct vmw_private *dev_priv,
726 bool lazy,
727 bool fifo_idle,
6bcd8d3c 728 uint32_t seqno,
fb1d9738
JB
729 bool interruptible,
730 unsigned long timeout);
6bcd8d3c 731extern void vmw_update_seqno(struct vmw_private *dev_priv,
1925d456 732 struct vmw_fifo_state *fifo_state);
ae2a1040
TH
733extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
734extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
57c5ee79
TH
735extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
736extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv);
1925d456
TH
737
738/**
6bcd8d3c
TH
739 * Rudimentary fence-like objects currently used only for throttling -
740 * vmwgfx_marker.c
1925d456
TH
741 */
742
6bcd8d3c
TH
743extern void vmw_marker_queue_init(struct vmw_marker_queue *queue);
744extern void vmw_marker_queue_takedown(struct vmw_marker_queue *queue);
745extern int vmw_marker_push(struct vmw_marker_queue *queue,
746 uint32_t seqno);
747extern int vmw_marker_pull(struct vmw_marker_queue *queue,
748 uint32_t signaled_seqno);
1925d456 749extern int vmw_wait_lag(struct vmw_private *dev_priv,
6bcd8d3c 750 struct vmw_marker_queue *queue, uint32_t us);
fb1d9738
JB
751
752/**
753 * Kernel framebuffer - vmwgfx_fb.c
754 */
755
756int vmw_fb_init(struct vmw_private *vmw_priv);
757int vmw_fb_close(struct vmw_private *dev_priv);
758int vmw_fb_off(struct vmw_private *vmw_priv);
759int vmw_fb_on(struct vmw_private *vmw_priv);
760
761/**
762 * Kernel modesetting - vmwgfx_kms.c
763 */
764
765int vmw_kms_init(struct vmw_private *dev_priv);
766int vmw_kms_close(struct vmw_private *dev_priv);
767int vmw_kms_save_vga(struct vmw_private *vmw_priv);
768int vmw_kms_restore_vga(struct vmw_private *vmw_priv);
769int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
770 struct drm_file *file_priv);
771void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
772void vmw_kms_cursor_snoop(struct vmw_surface *srf,
773 struct ttm_object_file *tfile,
774 struct ttm_buffer_object *bo,
775 SVGA3dCmdHeader *header);
0bef23f9
MD
776int vmw_kms_write_svga(struct vmw_private *vmw_priv,
777 unsigned width, unsigned height, unsigned pitch,
778 unsigned bpp, unsigned depth);
3a939a5e 779void vmw_kms_idle_workqueues(struct vmw_master *vmaster);
e133e737
TH
780bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
781 uint32_t pitch,
782 uint32_t height);
7a1c2f6c 783u32 vmw_get_vblank_counter(struct drm_device *dev, int crtc);
1c482ab3
JB
784int vmw_enable_vblank(struct drm_device *dev, int crtc);
785void vmw_disable_vblank(struct drm_device *dev, int crtc);
2fcd5a73
JB
786int vmw_kms_present(struct vmw_private *dev_priv,
787 struct drm_file *file_priv,
788 struct vmw_framebuffer *vfb,
789 struct vmw_surface *surface,
790 uint32_t sid, int32_t destX, int32_t destY,
791 struct drm_vmw_rect *clips,
792 uint32_t num_clips);
793int vmw_kms_readback(struct vmw_private *dev_priv,
794 struct drm_file *file_priv,
795 struct vmw_framebuffer *vfb,
796 struct drm_vmw_fence_rep __user *user_fence_rep,
797 struct drm_vmw_rect *clips,
798 uint32_t num_clips);
cd2b89e7
TH
799int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
800 struct drm_file *file_priv);
fb1d9738 801
5e1782d2
DA
802int vmw_dumb_create(struct drm_file *file_priv,
803 struct drm_device *dev,
804 struct drm_mode_create_dumb *args);
805
806int vmw_dumb_map_offset(struct drm_file *file_priv,
807 struct drm_device *dev, uint32_t handle,
808 uint64_t *offset);
809int vmw_dumb_destroy(struct drm_file *file_priv,
810 struct drm_device *dev,
811 uint32_t handle);
fb1d9738
JB
812/**
813 * Overlay control - vmwgfx_overlay.c
814 */
815
816int vmw_overlay_init(struct vmw_private *dev_priv);
817int vmw_overlay_close(struct vmw_private *dev_priv);
818int vmw_overlay_ioctl(struct drm_device *dev, void *data,
819 struct drm_file *file_priv);
820int vmw_overlay_stop_all(struct vmw_private *dev_priv);
821int vmw_overlay_resume_all(struct vmw_private *dev_priv);
822int vmw_overlay_pause_all(struct vmw_private *dev_priv);
823int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
824int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
825int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
826int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
827
135cba0d
TH
828/**
829 * GMR Id manager
830 */
831
832extern const struct ttm_mem_type_manager_func vmw_gmrid_manager_func;
833
69977ff5
TH
834/**
835 * Prime - vmwgfx_prime.c
836 */
837
838extern const struct dma_buf_ops vmw_prime_dmabuf_ops;
839extern int vmw_prime_fd_to_handle(struct drm_device *dev,
840 struct drm_file *file_priv,
841 int fd, u32 *handle);
842extern int vmw_prime_handle_to_fd(struct drm_device *dev,
843 struct drm_file *file_priv,
844 uint32_t handle, uint32_t flags,
845 int *prime_fd);
846
3530bdc3
TH
847/*
848 * MemoryOBject management - vmwgfx_mob.c
849 */
850struct vmw_mob;
851extern int vmw_mob_bind(struct vmw_private *dev_priv, struct vmw_mob *mob,
852 struct page **data_pages, unsigned long num_data_pages,
853 int32_t mob_id);
854extern void vmw_mob_unbind(struct vmw_private *dev_priv,
855 struct vmw_mob *mob);
856extern void vmw_mob_destroy(struct vmw_mob *mob);
857extern struct vmw_mob *vmw_mob_create(unsigned long data_pages);
858extern int vmw_otables_setup(struct vmw_private *dev_priv);
859extern void vmw_otables_takedown(struct vmw_private *dev_priv);
69977ff5 860
7086d099
TH
861/*
862 * Context management - vmwgfx_context.c
863 */
864
865extern const struct vmw_user_resource_conv *user_context_converter;
866
867extern struct vmw_resource *vmw_context_alloc(struct vmw_private *dev_priv);
868
869extern int vmw_context_check(struct vmw_private *dev_priv,
870 struct ttm_object_file *tfile,
871 int id,
872 struct vmw_resource **p_res);
873extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
874 struct drm_file *file_priv);
875extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
876 struct drm_file *file_priv);
877
878/*
879 * Surface management - vmwgfx_surface.c
880 */
881
882extern const struct vmw_user_resource_conv *user_surface_converter;
883
884extern void vmw_surface_res_free(struct vmw_resource *res);
885extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data,
886 struct drm_file *file_priv);
887extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
888 struct drm_file *file_priv);
889extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,
890 struct drm_file *file_priv);
891extern int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data,
892 struct drm_file *file_priv);
893extern int vmw_gb_surface_reference_ioctl(struct drm_device *dev, void *data,
894 struct drm_file *file_priv);
895extern int vmw_surface_check(struct vmw_private *dev_priv,
896 struct ttm_object_file *tfile,
897 uint32_t handle, int *id);
898extern int vmw_surface_validate(struct vmw_private *dev_priv,
899 struct vmw_surface *srf);
900
c74c162f
TH
901/*
902 * Shader management - vmwgfx_shader.c
903 */
904
7086d099
TH
905extern const struct vmw_user_resource_conv *user_shader_converter;
906
c74c162f
TH
907extern int vmw_shader_define_ioctl(struct drm_device *dev, void *data,
908 struct drm_file *file_priv);
909extern int vmw_shader_destroy_ioctl(struct drm_device *dev, void *data,
910 struct drm_file *file_priv);
911
fb1d9738
JB
912/**
913 * Inline helper functions
914 */
915
916static inline void vmw_surface_unreference(struct vmw_surface **srf)
917{
918 struct vmw_surface *tmp_srf = *srf;
919 struct vmw_resource *res = &tmp_srf->res;
920 *srf = NULL;
921
922 vmw_resource_unreference(&res);
923}
924
925static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
926{
927 (void) vmw_resource_reference(&srf->res);
928 return srf;
929}
930
931static inline void vmw_dmabuf_unreference(struct vmw_dma_buffer **buf)
932{
933 struct vmw_dma_buffer *tmp_buf = *buf;
bf6f0368 934
fb1d9738 935 *buf = NULL;
bf6f0368
TH
936 if (tmp_buf != NULL) {
937 struct ttm_buffer_object *bo = &tmp_buf->base;
fb1d9738 938
bf6f0368
TH
939 ttm_bo_unref(&bo);
940 }
fb1d9738
JB
941}
942
943static inline struct vmw_dma_buffer *vmw_dmabuf_reference(struct vmw_dma_buffer *buf)
944{
945 if (ttm_bo_reference(&buf->base))
946 return buf;
947 return NULL;
948}
949
ae2a1040
TH
950static inline struct ttm_mem_global *vmw_mem_glob(struct vmw_private *dev_priv)
951{
952 return (struct ttm_mem_global *) dev_priv->mem_global_ref.object;
953}
fb1d9738 954#endif