vmwgfx: Make it possible to get fence from execbuf
[linux-2.6.git] / drivers / gpu / drm / vmwgfx / vmwgfx_drv.h
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"
35 #include "linux/suspend.h"
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"
41 #include "vmwgfx_fence.h"
42
43 #define VMWGFX_DRIVER_DATE "20111025"
44 #define VMWGFX_DRIVER_MAJOR 2
45 #define VMWGFX_DRIVER_MINOR 3
46 #define VMWGFX_DRIVER_PATCHLEVEL 0
47 #define VMWGFX_FILE_PAGE_OFFSET 0x00100000
48 #define VMWGFX_FIFO_STATIC_SIZE (1024*1024)
49 #define VMWGFX_MAX_RELOCATIONS 2048
50 #define VMWGFX_MAX_VALIDATIONS 2048
51 #define VMWGFX_MAX_DISPLAYS 16
52 #define VMWGFX_CMD_BOUNCE_INIT_SIZE 32768
53
54 #define VMW_PL_GMR TTM_PL_PRIV0
55 #define VMW_PL_FLAG_GMR TTM_PL_FLAG_PRIV0
56
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
62 struct vmw_fpriv {
63         struct drm_master *locked_master;
64         struct ttm_object_file *tfile;
65         struct list_head fence_events;
66 };
67
68 struct vmw_dma_buffer {
69         struct ttm_buffer_object base;
70         struct list_head validate_list;
71         bool gmr_bound;
72         uint32_t cur_validate_node;
73         bool on_validate_list;
74 };
75
76 struct 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;
83         void (*remove_from_lists) (struct vmw_resource *res);
84         void (*hw_destroy) (struct vmw_resource *res);
85         void (*res_free) (struct vmw_resource *res);
86         struct list_head validate_head;
87         struct list_head query_head; /* Protected by the cmdbuf mutex */
88         /* 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
97 struct vmw_cursor_snooper {
98         struct drm_crtc *crtc;
99         size_t age;
100         uint32_t *image;
101 };
102
103 struct vmw_framebuffer;
104 struct vmw_surface_offset;
105
106 struct vmw_surface {
107         struct vmw_resource res;
108         struct list_head lru_head; /* Protected by the resource lock */
109         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
115         bool scanout;
116
117         /* TODO so far just a extra pointer */
118         struct vmw_cursor_snooper snooper;
119         struct ttm_buffer_object *backup;
120         struct vmw_surface_offset *offsets;
121         uint32_t backup_size;
122 };
123
124 struct vmw_marker_queue {
125         struct list_head head;
126         struct timespec lag;
127         struct timespec lag_time;
128         spinlock_t lock;
129 };
130
131 struct vmw_fifo_state {
132         unsigned long reserved_size;
133         __le32 *dynamic_buffer;
134         __le32 *static_buffer;
135         unsigned long static_buffer_size;
136         bool using_bounce_buffer;
137         uint32_t capabilities;
138         struct mutex fifo_mutex;
139         struct rw_semaphore rwsem;
140         struct vmw_marker_queue marker_queue;
141 };
142
143 struct vmw_relocation {
144         SVGAGuestPtr *location;
145         uint32_t index;
146 };
147
148 struct vmw_sw_context{
149         struct ida bo_list;
150         uint32_t last_cid;
151         bool cid_valid;
152         bool kernel; /**< is the called made from the kernel */
153         struct vmw_resource *cur_ctx;
154         uint32_t last_sid;
155         uint32_t sid_translation;
156         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;
161         struct ttm_validate_buffer val_bufs[VMWGFX_MAX_VALIDATIONS];
162         uint32_t cur_val_buf;
163         uint32_t *cmd_bounce;
164         uint32_t cmd_bounce_size;
165         struct list_head resource_list;
166         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;
171 };
172
173 struct vmw_legacy_display;
174 struct vmw_overlay;
175
176 struct vmw_master {
177         struct ttm_lock lock;
178         struct mutex fb_surf_mutex;
179         struct list_head fb_surf;
180 };
181
182 struct 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
190 struct vmw_private {
191         struct ttm_bo_device bdev;
192         struct ttm_bo_global_ref bo_global_ref;
193         struct drm_global_reference mem_global_ref;
194
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;
211         uint32_t max_gmr_pages;
212         uint32_t memory_size;
213         bool has_gmr;
214         struct mutex hw_mutex;
215
216         /*
217          * VGA registers.
218          */
219
220         struct vmw_vga_topology_state vga_save[VMWGFX_MAX_DISPLAYS];
221         uint32_t vga_width;
222         uint32_t vga_height;
223         uint32_t vga_bpp;
224         uint32_t vga_bpl;
225         uint32_t vga_pitchlock;
226
227         uint32_t num_displays;
228
229         /*
230          * Framebuffer info.
231          */
232
233         void *fb_info;
234         struct vmw_legacy_display *ldu_priv;
235         struct vmw_screen_object_display *sou_priv;
236         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
264         atomic_t marker_seq;
265         wait_queue_head_t fence_queue;
266         wait_queue_head_t fifo_queue;
267         int fence_queue_waiters; /* Protected by hw_mutex */
268         int goal_queue_waiters; /* Protected by hw_mutex */
269         atomic_t fifo_queue_waiters;
270         uint32_t last_read_seqno;
271         spinlock_t irq_lock;
272         struct vmw_fence_manager *fman;
273         uint32_t irq_mask;
274
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;
291         struct mutex cmdbuf_mutex;
292
293         /**
294          * Operating mode.
295          */
296
297         bool stealth;
298         bool is_opened;
299         bool enable_fb;
300
301         /**
302          * Master management.
303          */
304
305         struct vmw_master *active_master;
306         struct vmw_master fbdev_master;
307         struct notifier_block pm_nb;
308         bool suspended;
309
310         struct mutex release_mutex;
311         uint32_t num_3d_resources;
312
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;
322
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;
332 };
333
334 static inline struct vmw_private *vmw_priv(struct drm_device *dev)
335 {
336         return (struct vmw_private *)dev->dev_private;
337 }
338
339 static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
340 {
341         return (struct vmw_fpriv *)file_priv->driver_priv;
342 }
343
344 static inline struct vmw_master *vmw_master(struct drm_master *master)
345 {
346         return (struct vmw_master *) master->driver_priv;
347 }
348
349 static 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
356 static 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
366 int vmw_3d_resource_inc(struct vmw_private *dev_priv, bool unhide_svga);
367 void vmw_3d_resource_dec(struct vmw_private *dev_priv, bool hide_svga);
368
369 /**
370  * GMR utilities - vmwgfx_gmr.c
371  */
372
373 extern int vmw_gmr_bind(struct vmw_private *dev_priv,
374                         struct page *pages[],
375                         unsigned long num_pages,
376                         int gmr_id);
377 extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
378
379 /**
380  * Resource utilities - vmwgfx_resource.c
381  */
382
383 extern struct vmw_resource *vmw_context_alloc(struct vmw_private *dev_priv);
384 extern void vmw_resource_unreference(struct vmw_resource **p_res);
385 extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
386 extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
387                                      struct drm_file *file_priv);
388 extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
389                                     struct drm_file *file_priv);
390 extern int vmw_context_check(struct vmw_private *dev_priv,
391                              struct ttm_object_file *tfile,
392                              int id,
393                              struct vmw_resource **p_res);
394 extern 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);
399 extern void vmw_surface_res_free(struct vmw_resource *res);
400 extern int vmw_surface_init(struct vmw_private *dev_priv,
401                             struct vmw_surface *srf,
402                             void (*res_free) (struct vmw_resource *res));
403 extern 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);
407 extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data,
408                                      struct drm_file *file_priv);
409 extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
410                                     struct drm_file *file_priv);
411 extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,
412                                        struct drm_file *file_priv);
413 extern int vmw_surface_check(struct vmw_private *dev_priv,
414                              struct ttm_object_file *tfile,
415                              uint32_t handle, int *id);
416 extern int vmw_surface_validate(struct vmw_private *dev_priv,
417                                 struct vmw_surface *srf);
418 extern void vmw_dmabuf_bo_free(struct ttm_buffer_object *bo);
419 extern 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));
424 extern int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data,
425                                   struct drm_file *file_priv);
426 extern int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data,
427                                   struct drm_file *file_priv);
428 extern uint32_t vmw_dmabuf_validate_node(struct ttm_buffer_object *bo,
429                                          uint32_t cur_validate_node);
430 extern void vmw_dmabuf_validate_clear(struct ttm_buffer_object *bo);
431 extern int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile,
432                                   uint32_t id, struct vmw_dma_buffer **out);
433 extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
434                                   struct drm_file *file_priv);
435 extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
436                                   struct drm_file *file_priv);
437 extern 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);
441 extern void vmw_resource_unreserve(struct list_head *list);
442
443 /**
444  * DMA buffer helper routines - vmwgfx_dmabuf.c
445  */
446 extern int vmw_dmabuf_to_placement(struct vmw_private *vmw_priv,
447                                    struct vmw_dma_buffer *bo,
448                                    struct ttm_placement *placement,
449                                    bool interruptible);
450 extern int vmw_dmabuf_to_vram(struct vmw_private *dev_priv,
451                               struct vmw_dma_buffer *buf,
452                               bool pin, bool interruptible);
453 extern int vmw_dmabuf_to_vram_or_gmr(struct vmw_private *dev_priv,
454                                      struct vmw_dma_buffer *buf,
455                                      bool pin, bool interruptible);
456 extern int vmw_dmabuf_to_start_of_vram(struct vmw_private *vmw_priv,
457                                        struct vmw_dma_buffer *bo,
458                                        bool pin, bool interruptible);
459 extern int vmw_dmabuf_unpin(struct vmw_private *vmw_priv,
460                             struct vmw_dma_buffer *bo,
461                             bool interruptible);
462 extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf,
463                                  SVGAGuestPtr *ptr);
464 extern void vmw_bo_pin(struct ttm_buffer_object *bo, bool pin);
465
466 /**
467  * Misc Ioctl functionality - vmwgfx_ioctl.c
468  */
469
470 extern int vmw_getparam_ioctl(struct drm_device *dev, void *data,
471                               struct drm_file *file_priv);
472 extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
473                                 struct drm_file *file_priv);
474 extern int vmw_present_ioctl(struct drm_device *dev, void *data,
475                              struct drm_file *file_priv);
476 extern int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
477                                       struct drm_file *file_priv);
478 extern unsigned int vmw_fops_poll(struct file *filp,
479                                   struct poll_table_struct *wait);
480 extern ssize_t vmw_fops_read(struct file *filp, char __user *buffer,
481                              size_t count, loff_t *offset);
482
483 /**
484  * Fifo utilities - vmwgfx_fifo.c
485  */
486
487 extern int vmw_fifo_init(struct vmw_private *dev_priv,
488                          struct vmw_fifo_state *fifo);
489 extern void vmw_fifo_release(struct vmw_private *dev_priv,
490                              struct vmw_fifo_state *fifo);
491 extern void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes);
492 extern void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes);
493 extern int vmw_fifo_send_fence(struct vmw_private *dev_priv,
494                                uint32_t *seqno);
495 extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
496 extern bool vmw_fifo_have_3d(struct vmw_private *dev_priv);
497 extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv);
498 extern int vmw_fifo_emit_dummy_query(struct vmw_private *dev_priv,
499                                      uint32_t cid);
500
501 /**
502  * TTM glue - vmwgfx_ttm_glue.c
503  */
504
505 extern int vmw_ttm_global_init(struct vmw_private *dev_priv);
506 extern void vmw_ttm_global_release(struct vmw_private *dev_priv);
507 extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma);
508
509 /**
510  * TTM buffer object driver - vmwgfx_buffer.c
511  */
512
513 extern struct ttm_placement vmw_vram_placement;
514 extern struct ttm_placement vmw_vram_ne_placement;
515 extern struct ttm_placement vmw_vram_sys_placement;
516 extern struct ttm_placement vmw_vram_gmr_placement;
517 extern struct ttm_placement vmw_vram_gmr_ne_placement;
518 extern struct ttm_placement vmw_sys_placement;
519 extern struct ttm_placement vmw_evictable_placement;
520 extern struct ttm_placement vmw_srf_placement;
521 extern struct ttm_bo_driver vmw_bo_driver;
522 extern int vmw_dma_quiescent(struct drm_device *dev);
523
524 /**
525  * Command submission - vmwgfx_execbuf.c
526  */
527
528 extern int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
529                              struct drm_file *file_priv);
530 extern 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
537                                *user_fence_rep,
538                                struct vmw_fence_obj **out_fence);
539
540 extern void
541 vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv,
542                               bool only_on_cid_match, uint32_t cid);
543
544 extern 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);
548 extern 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);
555
556 /**
557  * IRQs and wating - vmwgfx_irq.c
558  */
559
560 extern irqreturn_t vmw_irq_handler(DRM_IRQ_ARGS);
561 extern int vmw_wait_seqno(struct vmw_private *dev_priv, bool lazy,
562                              uint32_t seqno, bool interruptible,
563                              unsigned long timeout);
564 extern void vmw_irq_preinstall(struct drm_device *dev);
565 extern int vmw_irq_postinstall(struct drm_device *dev);
566 extern void vmw_irq_uninstall(struct drm_device *dev);
567 extern bool vmw_seqno_passed(struct vmw_private *dev_priv,
568                                 uint32_t seqno);
569 extern int vmw_fallback_wait(struct vmw_private *dev_priv,
570                              bool lazy,
571                              bool fifo_idle,
572                              uint32_t seqno,
573                              bool interruptible,
574                              unsigned long timeout);
575 extern void vmw_update_seqno(struct vmw_private *dev_priv,
576                                 struct vmw_fifo_state *fifo_state);
577 extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
578 extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
579 extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
580 extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv);
581
582 /**
583  * Rudimentary fence-like objects currently used only for throttling -
584  * vmwgfx_marker.c
585  */
586
587 extern void vmw_marker_queue_init(struct vmw_marker_queue *queue);
588 extern void vmw_marker_queue_takedown(struct vmw_marker_queue *queue);
589 extern int vmw_marker_push(struct vmw_marker_queue *queue,
590                           uint32_t seqno);
591 extern int vmw_marker_pull(struct vmw_marker_queue *queue,
592                           uint32_t signaled_seqno);
593 extern int vmw_wait_lag(struct vmw_private *dev_priv,
594                         struct vmw_marker_queue *queue, uint32_t us);
595
596 /**
597  * Kernel framebuffer - vmwgfx_fb.c
598  */
599
600 int vmw_fb_init(struct vmw_private *vmw_priv);
601 int vmw_fb_close(struct vmw_private *dev_priv);
602 int vmw_fb_off(struct vmw_private *vmw_priv);
603 int vmw_fb_on(struct vmw_private *vmw_priv);
604
605 /**
606  * Kernel modesetting - vmwgfx_kms.c
607  */
608
609 int vmw_kms_init(struct vmw_private *dev_priv);
610 int vmw_kms_close(struct vmw_private *dev_priv);
611 int vmw_kms_save_vga(struct vmw_private *vmw_priv);
612 int vmw_kms_restore_vga(struct vmw_private *vmw_priv);
613 int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
614                                 struct drm_file *file_priv);
615 void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
616 void vmw_kms_cursor_snoop(struct vmw_surface *srf,
617                           struct ttm_object_file *tfile,
618                           struct ttm_buffer_object *bo,
619                           SVGA3dCmdHeader *header);
620 int vmw_kms_write_svga(struct vmw_private *vmw_priv,
621                        unsigned width, unsigned height, unsigned pitch,
622                        unsigned bpp, unsigned depth);
623 void vmw_kms_idle_workqueues(struct vmw_master *vmaster);
624 bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
625                                 uint32_t pitch,
626                                 uint32_t height);
627 u32 vmw_get_vblank_counter(struct drm_device *dev, int crtc);
628 int vmw_enable_vblank(struct drm_device *dev, int crtc);
629 void vmw_disable_vblank(struct drm_device *dev, int crtc);
630 int 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);
637 int 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);
643 int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
644                                 struct drm_file *file_priv);
645
646 /**
647  * Overlay control - vmwgfx_overlay.c
648  */
649
650 int vmw_overlay_init(struct vmw_private *dev_priv);
651 int vmw_overlay_close(struct vmw_private *dev_priv);
652 int vmw_overlay_ioctl(struct drm_device *dev, void *data,
653                       struct drm_file *file_priv);
654 int vmw_overlay_stop_all(struct vmw_private *dev_priv);
655 int vmw_overlay_resume_all(struct vmw_private *dev_priv);
656 int vmw_overlay_pause_all(struct vmw_private *dev_priv);
657 int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
658 int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
659 int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
660 int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
661
662 /**
663  * Fence function - vmwgfx_fence.c
664  */
665
666 int 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 /**
675  * GMR Id manager
676  */
677
678 extern const struct ttm_mem_type_manager_func vmw_gmrid_manager_func;
679
680 /**
681  * Inline helper functions
682  */
683
684 static 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
693 static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
694 {
695         (void) vmw_resource_reference(&srf->res);
696         return srf;
697 }
698
699 static 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
708 static 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
715 static 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 }
719 #endif