]> Pileus Git - ~andy/linux/blob - drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
drm/vmwgfx: Add guest-backed shaders
[~andy/linux] / 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 <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>
41 #include "vmwgfx_fence.h"
42
43 #define VMWGFX_DRIVER_DATE "20120209"
44 #define VMWGFX_DRIVER_MAJOR 2
45 #define VMWGFX_DRIVER_MINOR 4
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 /*
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
64 #define VMW_PL_GMR TTM_PL_PRIV0
65 #define VMW_PL_FLAG_GMR TTM_PL_FLAG_PRIV0
66 #define VMW_PL_MOB TTM_PL_PRIV1
67 #define VMW_PL_FLAG_MOB TTM_PL_FLAG_PRIV1
68
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
73 #define VMW_RES_SHADER ttm_driver_type4
74
75 struct vmw_fpriv {
76         struct drm_master *locked_master;
77         struct ttm_object_file *tfile;
78         struct list_head fence_events;
79 };
80
81 struct vmw_dma_buffer {
82         struct ttm_buffer_object base;
83         struct list_head res_list;
84 };
85
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  */
95 struct vmw_validate_buffer {
96         struct ttm_validate_buffer base;
97         struct drm_hash_item hash;
98         bool validate_as_mob;
99 };
100
101 struct vmw_res_func;
102 struct vmw_resource {
103         struct kref kref;
104         struct vmw_private *dev_priv;
105         int id;
106         bool avail;
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 */
115         void (*res_free) (struct vmw_resource *res);
116         void (*hw_destroy) (struct vmw_resource *res);
117 };
118
119 enum vmw_res_type {
120         vmw_res_context,
121         vmw_res_surface,
122         vmw_res_stream,
123         vmw_res_shader,
124         vmw_res_max
125 };
126
127 struct vmw_cursor_snooper {
128         struct drm_crtc *crtc;
129         size_t age;
130         uint32_t *image;
131 };
132
133 struct vmw_framebuffer;
134 struct vmw_surface_offset;
135
136 struct 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];
141         struct drm_vmw_size base_size;
142         struct drm_vmw_size *sizes;
143         uint32_t num_sizes;
144         bool scanout;
145         /* TODO so far just a extra pointer */
146         struct vmw_cursor_snooper snooper;
147         struct vmw_surface_offset *offsets;
148         SVGA3dTextureFilter autogen_filter;
149         uint32_t multisample_count;
150 };
151
152 struct vmw_marker_queue {
153         struct list_head head;
154         struct timespec lag;
155         struct timespec lag_time;
156         spinlock_t lock;
157 };
158
159 struct vmw_fifo_state {
160         unsigned long reserved_size;
161         __le32 *dynamic_buffer;
162         __le32 *static_buffer;
163         unsigned long static_buffer_size;
164         bool using_bounce_buffer;
165         uint32_t capabilities;
166         struct mutex fifo_mutex;
167         struct rw_semaphore rwsem;
168         struct vmw_marker_queue marker_queue;
169 };
170
171 struct vmw_relocation {
172         SVGAMobId *mob_loc;
173         SVGAGuestPtr *location;
174         uint32_t index;
175 };
176
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  */
189 struct 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
196 /**
197  * enum vmw_dma_map_mode - indicate how to perform TTM page dma mappings.
198  */
199 enum 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  */
214 struct 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  */
237 struct 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
248 struct vmw_sw_context{
249         struct drm_open_hash res_ht;
250         bool res_ht_initialized;
251         bool kernel; /**< is the called made from the kernel */
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;
256         struct vmw_validate_buffer val_bufs[VMWGFX_MAX_VALIDATIONS];
257         uint32_t cur_val_buf;
258         uint32_t *cmd_bounce;
259         uint32_t cmd_bounce_size;
260         struct list_head resource_list;
261         uint32_t fence_flags;
262         struct ttm_buffer_object *cur_query_bo;
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;
269 };
270
271 struct vmw_legacy_display;
272 struct vmw_overlay;
273
274 struct vmw_master {
275         struct ttm_lock lock;
276         struct mutex fb_surf_mutex;
277         struct list_head fb_surf;
278 };
279
280 struct 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
288 struct vmw_private {
289         struct ttm_bo_device bdev;
290         struct ttm_bo_global_ref bo_global_ref;
291         struct drm_global_reference mem_global_ref;
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;
300         uint32_t prim_bb_mem;
301         uint32_t mmio_start;
302         uint32_t mmio_size;
303         uint32_t fb_max_width;
304         uint32_t fb_max_height;
305         uint32_t initial_width;
306         uint32_t initial_height;
307         __le32 __iomem *mmio_virt;
308         int mmio_mtrr;
309         uint32_t capabilities;
310         uint32_t max_gmr_ids;
311         uint32_t max_gmr_pages;
312         uint32_t max_mob_pages;
313         uint32_t memory_size;
314         bool has_gmr;
315         bool has_mob;
316         struct mutex hw_mutex;
317
318         /*
319          * VGA registers.
320          */
321
322         struct vmw_vga_topology_state vga_save[VMWGFX_MAX_DISPLAYS];
323         uint32_t vga_width;
324         uint32_t vga_height;
325         uint32_t vga_bpp;
326         uint32_t vga_bpl;
327         uint32_t vga_pitchlock;
328
329         uint32_t num_displays;
330
331         /*
332          * Framebuffer info.
333          */
334
335         void *fb_info;
336         struct vmw_legacy_display *ldu_priv;
337         struct vmw_screen_object_display *sou_priv;
338         struct vmw_overlay *overlay_priv;
339
340         /*
341          * Context and surface management.
342          */
343
344         rwlock_t resource_lock;
345         struct idr res_idr[vmw_res_max];
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
363         atomic_t marker_seq;
364         wait_queue_head_t fence_queue;
365         wait_queue_head_t fifo_queue;
366         int fence_queue_waiters; /* Protected by hw_mutex */
367         int goal_queue_waiters; /* Protected by hw_mutex */
368         atomic_t fifo_queue_waiters;
369         uint32_t last_read_seqno;
370         spinlock_t irq_lock;
371         struct vmw_fence_manager *fman;
372         uint32_t irq_mask;
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;
390         struct mutex cmdbuf_mutex;
391
392         /**
393          * Operating mode.
394          */
395
396         bool stealth;
397         bool enable_fb;
398
399         /**
400          * Master management.
401          */
402
403         struct vmw_master *active_master;
404         struct vmw_master fbdev_master;
405         struct notifier_block pm_nb;
406         bool suspended;
407
408         struct mutex release_mutex;
409         uint32_t num_3d_resources;
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;
419         uint32_t query_cid_valid;
420         bool dummy_query_bo_pinned;
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
429         struct list_head res_lru[vmw_res_max];
430         uint32_t used_memory_size;
431
432         /*
433          * DMA mapping stuff.
434          */
435         enum vmw_dma_map_mode map_mode;
436
437         /*
438          * Guest Backed stuff
439          */
440         struct ttm_buffer_object *otable_bo;
441         struct vmw_otable *otables;
442 };
443
444 static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res)
445 {
446         return container_of(res, struct vmw_surface, res);
447 }
448
449 static inline struct vmw_private *vmw_priv(struct drm_device *dev)
450 {
451         return (struct vmw_private *)dev->dev_private;
452 }
453
454 static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
455 {
456         return (struct vmw_fpriv *)file_priv->driver_priv;
457 }
458
459 static inline struct vmw_master *vmw_master(struct drm_master *master)
460 {
461         return (struct vmw_master *) master->driver_priv;
462 }
463
464 static 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
471 static 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
481 int vmw_3d_resource_inc(struct vmw_private *dev_priv, bool unhide_svga);
482 void vmw_3d_resource_dec(struct vmw_private *dev_priv, bool hide_svga);
483
484 /**
485  * GMR utilities - vmwgfx_gmr.c
486  */
487
488 extern int vmw_gmr_bind(struct vmw_private *dev_priv,
489                         const struct vmw_sg_table *vsgt,
490                         unsigned long num_pages,
491                         int gmr_id);
492 extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
493
494 /**
495  * Resource utilities - vmwgfx_resource.c
496  */
497 struct vmw_user_resource_conv;
498 extern const struct vmw_user_resource_conv *user_surface_converter;
499 extern const struct vmw_user_resource_conv *user_context_converter;
500 extern const struct vmw_user_resource_conv *user_shader_converter;
501
502 extern struct vmw_resource *vmw_context_alloc(struct vmw_private *dev_priv);
503 extern void vmw_resource_unreference(struct vmw_resource **p_res);
504 extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
505 extern int vmw_resource_validate(struct vmw_resource *res);
506 extern int vmw_resource_reserve(struct vmw_resource *res, bool no_backup);
507 extern bool vmw_resource_needs_backup(const struct vmw_resource *res);
508 extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
509                                      struct drm_file *file_priv);
510 extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
511                                     struct drm_file *file_priv);
512 extern int vmw_context_check(struct vmw_private *dev_priv,
513                              struct ttm_object_file *tfile,
514                              int id,
515                              struct vmw_resource **p_res);
516 extern int vmw_user_lookup_handle(struct vmw_private *dev_priv,
517                                   struct ttm_object_file *tfile,
518                                   uint32_t handle,
519                                   struct vmw_surface **out_surf,
520                                   struct vmw_dma_buffer **out_buf);
521 extern int vmw_user_resource_lookup_handle(
522         struct vmw_private *dev_priv,
523         struct ttm_object_file *tfile,
524         uint32_t handle,
525         const struct vmw_user_resource_conv *converter,
526         struct vmw_resource **p_res);
527 extern void vmw_surface_res_free(struct vmw_resource *res);
528 extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data,
529                                      struct drm_file *file_priv);
530 extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
531                                     struct drm_file *file_priv);
532 extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,
533                                        struct drm_file *file_priv);
534 extern int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data,
535                                        struct drm_file *file_priv);
536 extern int vmw_gb_surface_reference_ioctl(struct drm_device *dev, void *data,
537                                           struct drm_file *file_priv);
538 extern int vmw_surface_check(struct vmw_private *dev_priv,
539                              struct ttm_object_file *tfile,
540                              uint32_t handle, int *id);
541 extern int vmw_surface_validate(struct vmw_private *dev_priv,
542                                 struct vmw_surface *srf);
543 extern void vmw_dmabuf_bo_free(struct ttm_buffer_object *bo);
544 extern int vmw_dmabuf_init(struct vmw_private *dev_priv,
545                            struct vmw_dma_buffer *vmw_bo,
546                            size_t size, struct ttm_placement *placement,
547                            bool interuptable,
548                            void (*bo_free) (struct ttm_buffer_object *bo));
549 extern int vmw_user_dmabuf_verify_access(struct ttm_buffer_object *bo,
550                                   struct ttm_object_file *tfile);
551 extern int vmw_user_dmabuf_alloc(struct vmw_private *dev_priv,
552                                  struct ttm_object_file *tfile,
553                                  uint32_t size,
554                                  bool shareable,
555                                  uint32_t *handle,
556                                  struct vmw_dma_buffer **p_dma_buf);
557 extern int vmw_user_dmabuf_reference(struct ttm_object_file *tfile,
558                                      struct vmw_dma_buffer *dma_buf,
559                                      uint32_t *handle);
560 extern int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data,
561                                   struct drm_file *file_priv);
562 extern int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data,
563                                   struct drm_file *file_priv);
564 extern uint32_t vmw_dmabuf_validate_node(struct ttm_buffer_object *bo,
565                                          uint32_t cur_validate_node);
566 extern void vmw_dmabuf_validate_clear(struct ttm_buffer_object *bo);
567 extern int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile,
568                                   uint32_t id, struct vmw_dma_buffer **out);
569 extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
570                                   struct drm_file *file_priv);
571 extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
572                                   struct drm_file *file_priv);
573 extern int vmw_user_stream_lookup(struct vmw_private *dev_priv,
574                                   struct ttm_object_file *tfile,
575                                   uint32_t *inout_id,
576                                   struct vmw_resource **out);
577 extern void vmw_resource_unreserve(struct vmw_resource *res,
578                                    struct vmw_dma_buffer *new_backup,
579                                    unsigned long new_backup_offset);
580 extern void vmw_resource_move_notify(struct ttm_buffer_object *bo,
581                                      struct ttm_mem_reg *mem);
582 extern void vmw_fence_single_bo(struct ttm_buffer_object *bo,
583                                 struct vmw_fence_obj *fence);
584 extern void vmw_resource_evict_all(struct vmw_private *dev_priv);
585
586 /**
587  * DMA buffer helper routines - vmwgfx_dmabuf.c
588  */
589 extern int vmw_dmabuf_to_placement(struct vmw_private *vmw_priv,
590                                    struct vmw_dma_buffer *bo,
591                                    struct ttm_placement *placement,
592                                    bool interruptible);
593 extern int vmw_dmabuf_to_vram(struct vmw_private *dev_priv,
594                               struct vmw_dma_buffer *buf,
595                               bool pin, bool interruptible);
596 extern int vmw_dmabuf_to_vram_or_gmr(struct vmw_private *dev_priv,
597                                      struct vmw_dma_buffer *buf,
598                                      bool pin, bool interruptible);
599 extern int vmw_dmabuf_to_start_of_vram(struct vmw_private *vmw_priv,
600                                        struct vmw_dma_buffer *bo,
601                                        bool pin, bool interruptible);
602 extern int vmw_dmabuf_unpin(struct vmw_private *vmw_priv,
603                             struct vmw_dma_buffer *bo,
604                             bool interruptible);
605 extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf,
606                                  SVGAGuestPtr *ptr);
607 extern void vmw_bo_pin(struct ttm_buffer_object *bo, bool pin);
608
609 /**
610  * Misc Ioctl functionality - vmwgfx_ioctl.c
611  */
612
613 extern int vmw_getparam_ioctl(struct drm_device *dev, void *data,
614                               struct drm_file *file_priv);
615 extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
616                                 struct drm_file *file_priv);
617 extern int vmw_present_ioctl(struct drm_device *dev, void *data,
618                              struct drm_file *file_priv);
619 extern int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
620                                       struct drm_file *file_priv);
621 extern unsigned int vmw_fops_poll(struct file *filp,
622                                   struct poll_table_struct *wait);
623 extern ssize_t vmw_fops_read(struct file *filp, char __user *buffer,
624                              size_t count, loff_t *offset);
625
626 /**
627  * Fifo utilities - vmwgfx_fifo.c
628  */
629
630 extern int vmw_fifo_init(struct vmw_private *dev_priv,
631                          struct vmw_fifo_state *fifo);
632 extern void vmw_fifo_release(struct vmw_private *dev_priv,
633                              struct vmw_fifo_state *fifo);
634 extern void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes);
635 extern void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes);
636 extern int vmw_fifo_send_fence(struct vmw_private *dev_priv,
637                                uint32_t *seqno);
638 extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
639 extern bool vmw_fifo_have_3d(struct vmw_private *dev_priv);
640 extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv);
641 extern int vmw_fifo_emit_dummy_query(struct vmw_private *dev_priv,
642                                      uint32_t cid);
643
644 /**
645  * TTM glue - vmwgfx_ttm_glue.c
646  */
647
648 extern int vmw_ttm_global_init(struct vmw_private *dev_priv);
649 extern void vmw_ttm_global_release(struct vmw_private *dev_priv);
650 extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma);
651
652 /**
653  * TTM buffer object driver - vmwgfx_buffer.c
654  */
655
656 extern const size_t vmw_tt_size;
657 extern struct ttm_placement vmw_vram_placement;
658 extern struct ttm_placement vmw_vram_ne_placement;
659 extern struct ttm_placement vmw_vram_sys_placement;
660 extern struct ttm_placement vmw_vram_gmr_placement;
661 extern struct ttm_placement vmw_vram_gmr_ne_placement;
662 extern struct ttm_placement vmw_sys_placement;
663 extern struct ttm_placement vmw_sys_ne_placement;
664 extern struct ttm_placement vmw_evictable_placement;
665 extern struct ttm_placement vmw_srf_placement;
666 extern struct ttm_placement vmw_mob_placement;
667 extern struct ttm_bo_driver vmw_bo_driver;
668 extern int vmw_dma_quiescent(struct drm_device *dev);
669 extern void vmw_piter_start(struct vmw_piter *viter,
670                             const struct vmw_sg_table *vsgt,
671                             unsigned long p_offs);
672
673 /**
674  * vmw_piter_next - Advance the iterator one page.
675  *
676  * @viter: Pointer to the iterator to advance.
677  *
678  * Returns false if past the list of pages, true otherwise.
679  */
680 static inline bool vmw_piter_next(struct vmw_piter *viter)
681 {
682         return viter->next(viter);
683 }
684
685 /**
686  * vmw_piter_dma_addr - Return the DMA address of the current page.
687  *
688  * @viter: Pointer to the iterator
689  *
690  * Returns the DMA address of the page pointed to by @viter.
691  */
692 static inline dma_addr_t vmw_piter_dma_addr(struct vmw_piter *viter)
693 {
694         return viter->dma_address(viter);
695 }
696
697 /**
698  * vmw_piter_page - Return a pointer to the current page.
699  *
700  * @viter: Pointer to the iterator
701  *
702  * Returns the DMA address of the page pointed to by @viter.
703  */
704 static inline struct page *vmw_piter_page(struct vmw_piter *viter)
705 {
706         return viter->page(viter);
707 }
708
709 /**
710  * Command submission - vmwgfx_execbuf.c
711  */
712
713 extern int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
714                              struct drm_file *file_priv);
715 extern int vmw_execbuf_process(struct drm_file *file_priv,
716                                struct vmw_private *dev_priv,
717                                void __user *user_commands,
718                                void *kernel_commands,
719                                uint32_t command_size,
720                                uint64_t throttle_us,
721                                struct drm_vmw_fence_rep __user
722                                *user_fence_rep,
723                                struct vmw_fence_obj **out_fence);
724 extern void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv,
725                                             struct vmw_fence_obj *fence);
726 extern void vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv);
727
728 extern int vmw_execbuf_fence_commands(struct drm_file *file_priv,
729                                       struct vmw_private *dev_priv,
730                                       struct vmw_fence_obj **p_fence,
731                                       uint32_t *p_handle);
732 extern void vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
733                                         struct vmw_fpriv *vmw_fp,
734                                         int ret,
735                                         struct drm_vmw_fence_rep __user
736                                         *user_fence_rep,
737                                         struct vmw_fence_obj *fence,
738                                         uint32_t fence_handle);
739
740 /**
741  * IRQs and wating - vmwgfx_irq.c
742  */
743
744 extern irqreturn_t vmw_irq_handler(int irq, void *arg);
745 extern int vmw_wait_seqno(struct vmw_private *dev_priv, bool lazy,
746                              uint32_t seqno, bool interruptible,
747                              unsigned long timeout);
748 extern void vmw_irq_preinstall(struct drm_device *dev);
749 extern int vmw_irq_postinstall(struct drm_device *dev);
750 extern void vmw_irq_uninstall(struct drm_device *dev);
751 extern bool vmw_seqno_passed(struct vmw_private *dev_priv,
752                                 uint32_t seqno);
753 extern int vmw_fallback_wait(struct vmw_private *dev_priv,
754                              bool lazy,
755                              bool fifo_idle,
756                              uint32_t seqno,
757                              bool interruptible,
758                              unsigned long timeout);
759 extern void vmw_update_seqno(struct vmw_private *dev_priv,
760                                 struct vmw_fifo_state *fifo_state);
761 extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
762 extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
763 extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
764 extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv);
765
766 /**
767  * Rudimentary fence-like objects currently used only for throttling -
768  * vmwgfx_marker.c
769  */
770
771 extern void vmw_marker_queue_init(struct vmw_marker_queue *queue);
772 extern void vmw_marker_queue_takedown(struct vmw_marker_queue *queue);
773 extern int vmw_marker_push(struct vmw_marker_queue *queue,
774                           uint32_t seqno);
775 extern int vmw_marker_pull(struct vmw_marker_queue *queue,
776                           uint32_t signaled_seqno);
777 extern int vmw_wait_lag(struct vmw_private *dev_priv,
778                         struct vmw_marker_queue *queue, uint32_t us);
779
780 /**
781  * Kernel framebuffer - vmwgfx_fb.c
782  */
783
784 int vmw_fb_init(struct vmw_private *vmw_priv);
785 int vmw_fb_close(struct vmw_private *dev_priv);
786 int vmw_fb_off(struct vmw_private *vmw_priv);
787 int vmw_fb_on(struct vmw_private *vmw_priv);
788
789 /**
790  * Kernel modesetting - vmwgfx_kms.c
791  */
792
793 int vmw_kms_init(struct vmw_private *dev_priv);
794 int vmw_kms_close(struct vmw_private *dev_priv);
795 int vmw_kms_save_vga(struct vmw_private *vmw_priv);
796 int vmw_kms_restore_vga(struct vmw_private *vmw_priv);
797 int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
798                                 struct drm_file *file_priv);
799 void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
800 void vmw_kms_cursor_snoop(struct vmw_surface *srf,
801                           struct ttm_object_file *tfile,
802                           struct ttm_buffer_object *bo,
803                           SVGA3dCmdHeader *header);
804 int vmw_kms_write_svga(struct vmw_private *vmw_priv,
805                        unsigned width, unsigned height, unsigned pitch,
806                        unsigned bpp, unsigned depth);
807 void vmw_kms_idle_workqueues(struct vmw_master *vmaster);
808 bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
809                                 uint32_t pitch,
810                                 uint32_t height);
811 u32 vmw_get_vblank_counter(struct drm_device *dev, int crtc);
812 int vmw_enable_vblank(struct drm_device *dev, int crtc);
813 void vmw_disable_vblank(struct drm_device *dev, int crtc);
814 int vmw_kms_present(struct vmw_private *dev_priv,
815                     struct drm_file *file_priv,
816                     struct vmw_framebuffer *vfb,
817                     struct vmw_surface *surface,
818                     uint32_t sid, int32_t destX, int32_t destY,
819                     struct drm_vmw_rect *clips,
820                     uint32_t num_clips);
821 int vmw_kms_readback(struct vmw_private *dev_priv,
822                      struct drm_file *file_priv,
823                      struct vmw_framebuffer *vfb,
824                      struct drm_vmw_fence_rep __user *user_fence_rep,
825                      struct drm_vmw_rect *clips,
826                      uint32_t num_clips);
827 int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
828                                 struct drm_file *file_priv);
829
830 int vmw_dumb_create(struct drm_file *file_priv,
831                     struct drm_device *dev,
832                     struct drm_mode_create_dumb *args);
833
834 int vmw_dumb_map_offset(struct drm_file *file_priv,
835                         struct drm_device *dev, uint32_t handle,
836                         uint64_t *offset);
837 int vmw_dumb_destroy(struct drm_file *file_priv,
838                      struct drm_device *dev,
839                      uint32_t handle);
840 /**
841  * Overlay control - vmwgfx_overlay.c
842  */
843
844 int vmw_overlay_init(struct vmw_private *dev_priv);
845 int vmw_overlay_close(struct vmw_private *dev_priv);
846 int vmw_overlay_ioctl(struct drm_device *dev, void *data,
847                       struct drm_file *file_priv);
848 int vmw_overlay_stop_all(struct vmw_private *dev_priv);
849 int vmw_overlay_resume_all(struct vmw_private *dev_priv);
850 int vmw_overlay_pause_all(struct vmw_private *dev_priv);
851 int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
852 int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
853 int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
854 int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
855
856 /**
857  * GMR Id manager
858  */
859
860 extern const struct ttm_mem_type_manager_func vmw_gmrid_manager_func;
861
862 /**
863  * Prime - vmwgfx_prime.c
864  */
865
866 extern const struct dma_buf_ops vmw_prime_dmabuf_ops;
867 extern int vmw_prime_fd_to_handle(struct drm_device *dev,
868                                   struct drm_file *file_priv,
869                                   int fd, u32 *handle);
870 extern int vmw_prime_handle_to_fd(struct drm_device *dev,
871                                   struct drm_file *file_priv,
872                                   uint32_t handle, uint32_t flags,
873                                   int *prime_fd);
874
875 /*
876  * MemoryOBject management -  vmwgfx_mob.c
877  */
878 struct vmw_mob;
879 extern int vmw_mob_bind(struct vmw_private *dev_priv, struct vmw_mob *mob,
880                         struct page **data_pages, unsigned long num_data_pages,
881                         int32_t mob_id);
882 extern void vmw_mob_unbind(struct vmw_private *dev_priv,
883                            struct vmw_mob *mob);
884 extern void vmw_mob_destroy(struct vmw_mob *mob);
885 extern struct vmw_mob *vmw_mob_create(unsigned long data_pages);
886 extern int vmw_otables_setup(struct vmw_private *dev_priv);
887 extern void vmw_otables_takedown(struct vmw_private *dev_priv);
888
889 /*
890  * Shader management - vmwgfx_shader.c
891  */
892
893 extern int vmw_shader_define_ioctl(struct drm_device *dev, void *data,
894                                    struct drm_file *file_priv);
895 extern int vmw_shader_destroy_ioctl(struct drm_device *dev, void *data,
896                                     struct drm_file *file_priv);
897
898 /**
899  * Inline helper functions
900  */
901
902 static inline void vmw_surface_unreference(struct vmw_surface **srf)
903 {
904         struct vmw_surface *tmp_srf = *srf;
905         struct vmw_resource *res = &tmp_srf->res;
906         *srf = NULL;
907
908         vmw_resource_unreference(&res);
909 }
910
911 static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
912 {
913         (void) vmw_resource_reference(&srf->res);
914         return srf;
915 }
916
917 static inline void vmw_dmabuf_unreference(struct vmw_dma_buffer **buf)
918 {
919         struct vmw_dma_buffer *tmp_buf = *buf;
920
921         *buf = NULL;
922         if (tmp_buf != NULL) {
923                 struct ttm_buffer_object *bo = &tmp_buf->base;
924
925                 ttm_bo_unref(&bo);
926         }
927 }
928
929 static inline struct vmw_dma_buffer *vmw_dmabuf_reference(struct vmw_dma_buffer *buf)
930 {
931         if (ttm_bo_reference(&buf->base))
932                 return buf;
933         return NULL;
934 }
935
936 static inline struct ttm_mem_global *vmw_mem_glob(struct vmw_private *dev_priv)
937 {
938         return (struct ttm_mem_global *) dev_priv->mem_global_ref.object;
939 }
940 #endif