1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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 <drm/drm_auth.h>
36#include <linux/suspend.h>
37#include <drm/ttm/ttm_bo_driver.h>
38#include <drm/ttm/ttm_object.h>
39#include <drm/ttm/ttm_lock.h>
40#include <drm/ttm/ttm_execbuf_util.h>
41#include <drm/ttm/ttm_module.h>
42#include "vmwgfx_fence.h"
43#include <linux/sync_file.h>
44
45#define VMWGFX_DRIVER_NAME "vmwgfx"
46#define VMWGFX_DRIVER_DATE "20180322"
47#define VMWGFX_DRIVER_MAJOR 2
48#define VMWGFX_DRIVER_MINOR 14
49#define VMWGFX_DRIVER_PATCHLEVEL 1
50#define VMWGFX_FILE_PAGE_OFFSET 0x00100000
51#define VMWGFX_FIFO_STATIC_SIZE (1024*1024)
52#define VMWGFX_MAX_RELOCATIONS 2048
53#define VMWGFX_MAX_VALIDATIONS 2048
54#define VMWGFX_MAX_DISPLAYS 16
55#define VMWGFX_CMD_BOUNCE_INIT_SIZE 32768
56#define VMWGFX_ENABLE_SCREEN_TARGET_OTABLE 1
57
58
59
60
61#define VMWGFX_NUM_GB_CONTEXT 256
62#define VMWGFX_NUM_GB_SHADER 20000
63#define VMWGFX_NUM_GB_SURFACE 32768
64#define VMWGFX_NUM_GB_SCREEN_TARGET VMWGFX_MAX_DISPLAYS
65#define VMWGFX_NUM_DXCONTEXT 256
66#define VMWGFX_NUM_DXQUERY 512
67#define VMWGFX_NUM_MOB (VMWGFX_NUM_GB_CONTEXT +\
68 VMWGFX_NUM_GB_SHADER +\
69 VMWGFX_NUM_GB_SURFACE +\
70 VMWGFX_NUM_GB_SCREEN_TARGET)
71
72#define VMW_PL_GMR (TTM_PL_PRIV + 0)
73#define VMW_PL_FLAG_GMR (TTM_PL_FLAG_PRIV << 0)
74#define VMW_PL_MOB (TTM_PL_PRIV + 1)
75#define VMW_PL_FLAG_MOB (TTM_PL_FLAG_PRIV << 1)
76
77#define VMW_RES_CONTEXT ttm_driver_type0
78#define VMW_RES_SURFACE ttm_driver_type1
79#define VMW_RES_STREAM ttm_driver_type2
80#define VMW_RES_FENCE ttm_driver_type3
81#define VMW_RES_SHADER ttm_driver_type4
82
83struct vmw_fpriv {
84 struct drm_master *locked_master;
85 struct ttm_object_file *tfile;
86 bool gb_aware;
87};
88
89struct vmw_dma_buffer {
90 struct ttm_buffer_object base;
91 struct list_head res_list;
92 s32 pin_count;
93
94 struct vmw_resource *dx_query_ctx;
95
96 struct ttm_bo_kmap_obj map;
97};
98
99
100
101
102
103
104
105
106
107
108struct vmw_validate_buffer {
109 struct ttm_validate_buffer base;
110 struct drm_hash_item hash;
111 bool validate_as_mob;
112};
113
114struct vmw_res_func;
115struct vmw_resource {
116 struct kref kref;
117 struct vmw_private *dev_priv;
118 int id;
119 bool avail;
120 unsigned long backup_size;
121 bool res_dirty;
122 bool backup_dirty;
123 struct vmw_dma_buffer *backup;
124 unsigned long backup_offset;
125 unsigned long pin_count;
126 const struct vmw_res_func *func;
127 struct list_head lru_head;
128 struct list_head mob_head;
129 struct list_head binding_head;
130 void (*res_free) (struct vmw_resource *res);
131 void (*hw_destroy) (struct vmw_resource *res);
132};
133
134
135
136
137
138enum vmw_res_type {
139 vmw_res_context,
140 vmw_res_surface,
141 vmw_res_stream,
142 vmw_res_shader,
143 vmw_res_dx_context,
144 vmw_res_cotable,
145 vmw_res_view,
146 vmw_res_max
147};
148
149
150
151
152enum vmw_cmdbuf_res_type {
153 vmw_cmdbuf_res_shader,
154 vmw_cmdbuf_res_view
155};
156
157struct vmw_cmdbuf_res_manager;
158
159struct vmw_cursor_snooper {
160 size_t age;
161 uint32_t *image;
162};
163
164struct vmw_framebuffer;
165struct vmw_surface_offset;
166
167struct vmw_surface {
168 struct vmw_resource res;
169 uint32_t flags;
170 uint32_t format;
171 uint32_t mip_levels[DRM_VMW_MAX_SURFACE_FACES];
172 struct drm_vmw_size base_size;
173 struct drm_vmw_size *sizes;
174 uint32_t num_sizes;
175 bool scanout;
176 uint32_t array_size;
177
178 struct vmw_cursor_snooper snooper;
179 struct vmw_surface_offset *offsets;
180 SVGA3dTextureFilter autogen_filter;
181 uint32_t multisample_count;
182 struct list_head view_list;
183};
184
185struct vmw_marker_queue {
186 struct list_head head;
187 u64 lag;
188 u64 lag_time;
189 spinlock_t lock;
190};
191
192struct vmw_fifo_state {
193 unsigned long reserved_size;
194 u32 *dynamic_buffer;
195 u32 *static_buffer;
196 unsigned long static_buffer_size;
197 bool using_bounce_buffer;
198 uint32_t capabilities;
199 struct mutex fifo_mutex;
200 struct rw_semaphore rwsem;
201 struct vmw_marker_queue marker_queue;
202 bool dx;
203};
204
205struct vmw_relocation {
206 SVGAMobId *mob_loc;
207 SVGAGuestPtr *location;
208 uint32_t index;
209};
210
211
212
213
214
215
216
217
218
219
220
221
222
223struct vmw_res_cache_entry {
224 bool valid;
225 uint32_t handle;
226 struct vmw_resource *res;
227 struct vmw_resource_val_node *node;
228};
229
230
231
232
233enum vmw_dma_map_mode {
234 vmw_dma_phys,
235 vmw_dma_alloc_coherent,
236 vmw_dma_map_populate,
237 vmw_dma_map_bind,
238 vmw_dma_map_max
239};
240
241
242
243
244
245
246
247
248struct vmw_sg_table {
249 enum vmw_dma_map_mode mode;
250 struct page **pages;
251 const dma_addr_t *addrs;
252 struct sg_table *sgt;
253 unsigned long num_regions;
254 unsigned long num_pages;
255};
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271struct vmw_piter {
272 struct page **pages;
273 const dma_addr_t *addrs;
274 struct sg_page_iter iter;
275 unsigned long i;
276 unsigned long num_pages;
277 bool (*next)(struct vmw_piter *);
278 dma_addr_t (*dma_address)(struct vmw_piter *);
279 struct page *(*page)(struct vmw_piter *);
280};
281
282
283
284
285enum vmw_display_unit_type {
286 vmw_du_invalid = 0,
287 vmw_du_legacy,
288 vmw_du_screen_object,
289 vmw_du_screen_target
290};
291
292
293struct vmw_sw_context{
294 struct drm_open_hash res_ht;
295 bool res_ht_initialized;
296 bool kernel;
297 struct vmw_fpriv *fp;
298 struct list_head validate_nodes;
299 struct vmw_relocation relocs[VMWGFX_MAX_RELOCATIONS];
300 uint32_t cur_reloc;
301 struct vmw_validate_buffer val_bufs[VMWGFX_MAX_VALIDATIONS];
302 uint32_t cur_val_buf;
303 uint32_t *cmd_bounce;
304 uint32_t cmd_bounce_size;
305 struct list_head resource_list;
306 struct list_head ctx_resource_list;
307 struct vmw_dma_buffer *cur_query_bo;
308 struct list_head res_relocations;
309 uint32_t *buf_start;
310 struct vmw_res_cache_entry res_cache[vmw_res_max];
311 struct vmw_resource *last_query_ctx;
312 bool needs_post_query_barrier;
313 struct vmw_resource *error_resource;
314 struct vmw_ctx_binding_state *staged_bindings;
315 bool staged_bindings_inuse;
316 struct list_head staged_cmd_res;
317 struct vmw_resource_val_node *dx_ctx_node;
318 struct vmw_dma_buffer *dx_query_mob;
319 struct vmw_resource *dx_query_ctx;
320 struct vmw_cmdbuf_res_manager *man;
321};
322
323struct vmw_legacy_display;
324struct vmw_overlay;
325
326struct vmw_master {
327 struct ttm_lock lock;
328};
329
330struct vmw_vga_topology_state {
331 uint32_t width;
332 uint32_t height;
333 uint32_t primary;
334 uint32_t pos_x;
335 uint32_t pos_y;
336};
337
338
339
340
341
342
343
344
345struct vmw_otable {
346 unsigned long size;
347 struct vmw_mob *page_table;
348 bool enabled;
349};
350
351struct vmw_otable_batch {
352 unsigned num_otables;
353 struct vmw_otable *otables;
354 struct vmw_resource *context;
355 struct ttm_buffer_object *otable_bo;
356};
357
358enum {
359 VMW_IRQTHREAD_FENCE,
360 VMW_IRQTHREAD_CMDBUF,
361 VMW_IRQTHREAD_MAX
362};
363
364struct vmw_private {
365 struct ttm_bo_device bdev;
366 struct ttm_bo_global_ref bo_global_ref;
367 struct drm_global_reference mem_global_ref;
368
369 struct vmw_fifo_state fifo;
370
371 struct drm_device *dev;
372 unsigned long vmw_chipset;
373 unsigned int io_start;
374 uint32_t vram_start;
375 uint32_t vram_size;
376 uint32_t prim_bb_mem;
377 uint32_t mmio_start;
378 uint32_t mmio_size;
379 uint32_t fb_max_width;
380 uint32_t fb_max_height;
381 uint32_t texture_max_width;
382 uint32_t texture_max_height;
383 uint32_t stdu_max_width;
384 uint32_t stdu_max_height;
385 uint32_t initial_width;
386 uint32_t initial_height;
387 u32 *mmio_virt;
388 uint32_t capabilities;
389 uint32_t max_gmr_ids;
390 uint32_t max_gmr_pages;
391 uint32_t max_mob_pages;
392 uint32_t max_mob_size;
393 uint32_t memory_size;
394 bool has_gmr;
395 bool has_mob;
396 spinlock_t hw_lock;
397 spinlock_t cap_lock;
398 bool has_dx;
399 bool assume_16bpp;
400
401
402
403
404
405 struct vmw_vga_topology_state vga_save[VMWGFX_MAX_DISPLAYS];
406 uint32_t vga_width;
407 uint32_t vga_height;
408 uint32_t vga_bpp;
409 uint32_t vga_bpl;
410 uint32_t vga_pitchlock;
411
412 uint32_t num_displays;
413
414
415
416
417
418 void *fb_info;
419 enum vmw_display_unit_type active_display_unit;
420 struct vmw_legacy_display *ldu_priv;
421 struct vmw_overlay *overlay_priv;
422 struct drm_property *hotplug_mode_update_property;
423 struct drm_property *implicit_placement_property;
424 unsigned num_implicit;
425 struct vmw_framebuffer *implicit_fb;
426 struct mutex global_kms_state_mutex;
427 spinlock_t cursor_lock;
428 struct drm_atomic_state *suspend_state;
429
430
431
432
433
434 rwlock_t resource_lock;
435 struct idr res_idr[vmw_res_max];
436
437
438
439
440 struct mutex init_mutex;
441
442
443
444
445
446
447 struct ttm_object_device *tdev;
448
449
450
451
452
453 atomic_t marker_seq;
454 wait_queue_head_t fence_queue;
455 wait_queue_head_t fifo_queue;
456 spinlock_t waiter_lock;
457 int fence_queue_waiters;
458 int goal_queue_waiters;
459 int cmdbuf_waiters;
460 int error_waiters;
461 int fifo_queue_waiters;
462 uint32_t last_read_seqno;
463 struct vmw_fence_manager *fman;
464 uint32_t irq_mask;
465
466
467
468
469
470 uint32_t traces_state;
471 uint32_t enable_state;
472 uint32_t config_done_state;
473
474
475
476
477
478
479
480
481 struct vmw_sw_context ctx;
482 struct mutex cmdbuf_mutex;
483 struct mutex binding_mutex;
484
485
486
487
488
489 bool stealth;
490 bool enable_fb;
491 spinlock_t svga_lock;
492
493
494
495
496
497 struct vmw_master *active_master;
498 struct vmw_master fbdev_master;
499 struct notifier_block pm_nb;
500 bool refuse_hibernation;
501 bool suspend_locked;
502
503 struct mutex release_mutex;
504 atomic_t num_fifo_resources;
505
506
507
508
509 struct ttm_lock reservation_sem;
510
511
512
513
514
515
516 struct vmw_dma_buffer *dummy_query_bo;
517 struct vmw_dma_buffer *pinned_bo;
518 uint32_t query_cid;
519 uint32_t query_cid_valid;
520 bool dummy_query_bo_pinned;
521
522
523
524
525
526
527
528
529 struct list_head res_lru[vmw_res_max];
530 uint32_t used_memory_size;
531
532
533
534
535 enum vmw_dma_map_mode map_mode;
536
537
538
539
540 struct vmw_otable_batch otable_batch;
541
542 struct vmw_cmdbuf_man *cman;
543 DECLARE_BITMAP(irqthread_pending, VMW_IRQTHREAD_MAX);
544};
545
546static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res)
547{
548 return container_of(res, struct vmw_surface, res);
549}
550
551static inline struct vmw_private *vmw_priv(struct drm_device *dev)
552{
553 return (struct vmw_private *)dev->dev_private;
554}
555
556static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
557{
558 return (struct vmw_fpriv *)file_priv->driver_priv;
559}
560
561static inline struct vmw_master *vmw_master(struct drm_master *master)
562{
563 return (struct vmw_master *) master->driver_priv;
564}
565
566
567
568
569
570
571
572
573static inline void vmw_write(struct vmw_private *dev_priv,
574 unsigned int offset, uint32_t value)
575{
576 spin_lock(&dev_priv->hw_lock);
577 outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
578 outl(value, dev_priv->io_start + VMWGFX_VALUE_PORT);
579 spin_unlock(&dev_priv->hw_lock);
580}
581
582static inline uint32_t vmw_read(struct vmw_private *dev_priv,
583 unsigned int offset)
584{
585 u32 val;
586
587 spin_lock(&dev_priv->hw_lock);
588 outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
589 val = inl(dev_priv->io_start + VMWGFX_VALUE_PORT);
590 spin_unlock(&dev_priv->hw_lock);
591
592 return val;
593}
594
595extern void vmw_svga_enable(struct vmw_private *dev_priv);
596extern void vmw_svga_disable(struct vmw_private *dev_priv);
597
598
599
600
601
602
603extern int vmw_gmr_bind(struct vmw_private *dev_priv,
604 const struct vmw_sg_table *vsgt,
605 unsigned long num_pages,
606 int gmr_id);
607extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
608
609
610
611
612struct vmw_user_resource_conv;
613
614extern void vmw_resource_unreference(struct vmw_resource **p_res);
615extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
616extern struct vmw_resource *
617vmw_resource_reference_unless_doomed(struct vmw_resource *res);
618extern int vmw_resource_validate(struct vmw_resource *res);
619extern int vmw_resource_reserve(struct vmw_resource *res, bool interruptible,
620 bool no_backup);
621extern bool vmw_resource_needs_backup(const struct vmw_resource *res);
622extern int vmw_user_lookup_handle(struct vmw_private *dev_priv,
623 struct ttm_object_file *tfile,
624 uint32_t handle,
625 struct vmw_surface **out_surf,
626 struct vmw_dma_buffer **out_buf);
627extern int vmw_user_resource_lookup_handle(
628 struct vmw_private *dev_priv,
629 struct ttm_object_file *tfile,
630 uint32_t handle,
631 const struct vmw_user_resource_conv *converter,
632 struct vmw_resource **p_res);
633extern void vmw_dmabuf_bo_free(struct ttm_buffer_object *bo);
634extern int vmw_dmabuf_init(struct vmw_private *dev_priv,
635 struct vmw_dma_buffer *vmw_bo,
636 size_t size, struct ttm_placement *placement,
637 bool interuptable,
638 void (*bo_free) (struct ttm_buffer_object *bo));
639extern int vmw_user_dmabuf_verify_access(struct ttm_buffer_object *bo,
640 struct ttm_object_file *tfile);
641extern int vmw_user_dmabuf_alloc(struct vmw_private *dev_priv,
642 struct ttm_object_file *tfile,
643 uint32_t size,
644 bool shareable,
645 uint32_t *handle,
646 struct vmw_dma_buffer **p_dma_buf,
647 struct ttm_base_object **p_base);
648extern int vmw_user_dmabuf_reference(struct ttm_object_file *tfile,
649 struct vmw_dma_buffer *dma_buf,
650 uint32_t *handle);
651extern int vmw_dmabuf_alloc_ioctl(struct drm_device *dev, void *data,
652 struct drm_file *file_priv);
653extern int vmw_dmabuf_unref_ioctl(struct drm_device *dev, void *data,
654 struct drm_file *file_priv);
655extern int vmw_user_dmabuf_synccpu_ioctl(struct drm_device *dev, void *data,
656 struct drm_file *file_priv);
657extern uint32_t vmw_dmabuf_validate_node(struct ttm_buffer_object *bo,
658 uint32_t cur_validate_node);
659extern void vmw_dmabuf_validate_clear(struct ttm_buffer_object *bo);
660extern int vmw_user_dmabuf_lookup(struct ttm_object_file *tfile,
661 uint32_t id, struct vmw_dma_buffer **out,
662 struct ttm_base_object **base);
663extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
664 struct drm_file *file_priv);
665extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
666 struct drm_file *file_priv);
667extern int vmw_user_stream_lookup(struct vmw_private *dev_priv,
668 struct ttm_object_file *tfile,
669 uint32_t *inout_id,
670 struct vmw_resource **out);
671extern void vmw_resource_unreserve(struct vmw_resource *res,
672 bool switch_backup,
673 struct vmw_dma_buffer *new_backup,
674 unsigned long new_backup_offset);
675extern void vmw_resource_move_notify(struct ttm_buffer_object *bo,
676 struct ttm_mem_reg *mem);
677extern void vmw_query_move_notify(struct ttm_buffer_object *bo,
678 struct ttm_mem_reg *mem);
679extern void vmw_resource_swap_notify(struct ttm_buffer_object *bo);
680extern int vmw_query_readback_all(struct vmw_dma_buffer *dx_query_mob);
681extern void vmw_fence_single_bo(struct ttm_buffer_object *bo,
682 struct vmw_fence_obj *fence);
683extern void vmw_resource_evict_all(struct vmw_private *dev_priv);
684
685
686
687
688
689extern int vmw_dmabuf_pin_in_placement(struct vmw_private *vmw_priv,
690 struct vmw_dma_buffer *bo,
691 struct ttm_placement *placement,
692 bool interruptible);
693extern int vmw_dmabuf_pin_in_vram(struct vmw_private *dev_priv,
694 struct vmw_dma_buffer *buf,
695 bool interruptible);
696extern int vmw_dmabuf_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
697 struct vmw_dma_buffer *buf,
698 bool interruptible);
699extern int vmw_dmabuf_pin_in_start_of_vram(struct vmw_private *vmw_priv,
700 struct vmw_dma_buffer *bo,
701 bool interruptible);
702extern int vmw_dmabuf_unpin(struct vmw_private *vmw_priv,
703 struct vmw_dma_buffer *bo,
704 bool interruptible);
705extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf,
706 SVGAGuestPtr *ptr);
707extern void vmw_bo_pin_reserved(struct vmw_dma_buffer *bo, bool pin);
708extern void *vmw_dma_buffer_map_and_cache(struct vmw_dma_buffer *vbo);
709extern void vmw_dma_buffer_unmap(struct vmw_dma_buffer *vbo);
710
711
712
713
714
715extern int vmw_getparam_ioctl(struct drm_device *dev, void *data,
716 struct drm_file *file_priv);
717extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
718 struct drm_file *file_priv);
719extern int vmw_present_ioctl(struct drm_device *dev, void *data,
720 struct drm_file *file_priv);
721extern int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
722 struct drm_file *file_priv);
723extern unsigned int vmw_fops_poll(struct file *filp,
724 struct poll_table_struct *wait);
725extern ssize_t vmw_fops_read(struct file *filp, char __user *buffer,
726 size_t count, loff_t *offset);
727
728
729
730
731
732extern int vmw_fifo_init(struct vmw_private *dev_priv,
733 struct vmw_fifo_state *fifo);
734extern void vmw_fifo_release(struct vmw_private *dev_priv,
735 struct vmw_fifo_state *fifo);
736extern void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes);
737extern void *
738vmw_fifo_reserve_dx(struct vmw_private *dev_priv, uint32_t bytes, int ctx_id);
739extern void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes);
740extern void vmw_fifo_commit_flush(struct vmw_private *dev_priv, uint32_t bytes);
741extern int vmw_fifo_send_fence(struct vmw_private *dev_priv,
742 uint32_t *seqno);
743extern void vmw_fifo_ping_host_locked(struct vmw_private *, uint32_t reason);
744extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
745extern bool vmw_fifo_have_3d(struct vmw_private *dev_priv);
746extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv);
747extern int vmw_fifo_emit_dummy_query(struct vmw_private *dev_priv,
748 uint32_t cid);
749extern int vmw_fifo_flush(struct vmw_private *dev_priv,
750 bool interruptible);
751
752
753
754
755
756extern int vmw_ttm_global_init(struct vmw_private *dev_priv);
757extern void vmw_ttm_global_release(struct vmw_private *dev_priv);
758extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma);
759
760
761
762
763
764extern const size_t vmw_tt_size;
765extern struct ttm_placement vmw_vram_placement;
766extern struct ttm_placement vmw_vram_ne_placement;
767extern struct ttm_placement vmw_vram_sys_placement;
768extern struct ttm_placement vmw_vram_gmr_placement;
769extern struct ttm_placement vmw_vram_gmr_ne_placement;
770extern struct ttm_placement vmw_sys_placement;
771extern struct ttm_placement vmw_sys_ne_placement;
772extern struct ttm_placement vmw_evictable_placement;
773extern struct ttm_placement vmw_srf_placement;
774extern struct ttm_placement vmw_mob_placement;
775extern struct ttm_placement vmw_mob_ne_placement;
776extern struct ttm_placement vmw_nonfixed_placement;
777extern struct ttm_bo_driver vmw_bo_driver;
778extern int vmw_dma_quiescent(struct drm_device *dev);
779extern int vmw_bo_map_dma(struct ttm_buffer_object *bo);
780extern void vmw_bo_unmap_dma(struct ttm_buffer_object *bo);
781extern const struct vmw_sg_table *
782vmw_bo_sg_table(struct ttm_buffer_object *bo);
783extern void vmw_piter_start(struct vmw_piter *viter,
784 const struct vmw_sg_table *vsgt,
785 unsigned long p_offs);
786
787
788
789
790
791
792
793
794static inline bool vmw_piter_next(struct vmw_piter *viter)
795{
796 return viter->next(viter);
797}
798
799
800
801
802
803
804
805
806static inline dma_addr_t vmw_piter_dma_addr(struct vmw_piter *viter)
807{
808 return viter->dma_address(viter);
809}
810
811
812
813
814
815
816
817
818static inline struct page *vmw_piter_page(struct vmw_piter *viter)
819{
820 return viter->page(viter);
821}
822
823
824
825
826
827extern int vmw_execbuf_ioctl(struct drm_device *dev, unsigned long data,
828 struct drm_file *file_priv, size_t size);
829extern int vmw_execbuf_process(struct drm_file *file_priv,
830 struct vmw_private *dev_priv,
831 void __user *user_commands,
832 void *kernel_commands,
833 uint32_t command_size,
834 uint64_t throttle_us,
835 uint32_t dx_context_handle,
836 struct drm_vmw_fence_rep __user
837 *user_fence_rep,
838 struct vmw_fence_obj **out_fence,
839 uint32_t flags);
840extern void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv,
841 struct vmw_fence_obj *fence);
842extern void vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv);
843
844extern int vmw_execbuf_fence_commands(struct drm_file *file_priv,
845 struct vmw_private *dev_priv,
846 struct vmw_fence_obj **p_fence,
847 uint32_t *p_handle);
848extern void vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
849 struct vmw_fpriv *vmw_fp,
850 int ret,
851 struct drm_vmw_fence_rep __user
852 *user_fence_rep,
853 struct vmw_fence_obj *fence,
854 uint32_t fence_handle,
855 int32_t out_fence_fd,
856 struct sync_file *sync_file);
857extern int vmw_validate_single_buffer(struct vmw_private *dev_priv,
858 struct ttm_buffer_object *bo,
859 bool interruptible,
860 bool validate_as_mob);
861bool vmw_cmd_describe(const void *buf, u32 *size, char const **cmd);
862
863
864
865
866
867extern int vmw_wait_seqno(struct vmw_private *dev_priv, bool lazy,
868 uint32_t seqno, bool interruptible,
869 unsigned long timeout);
870extern int vmw_irq_install(struct drm_device *dev, int irq);
871extern void vmw_irq_uninstall(struct drm_device *dev);
872extern bool vmw_seqno_passed(struct vmw_private *dev_priv,
873 uint32_t seqno);
874extern int vmw_fallback_wait(struct vmw_private *dev_priv,
875 bool lazy,
876 bool fifo_idle,
877 uint32_t seqno,
878 bool interruptible,
879 unsigned long timeout);
880extern void vmw_update_seqno(struct vmw_private *dev_priv,
881 struct vmw_fifo_state *fifo_state);
882extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
883extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
884extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
885extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv);
886extern void vmw_generic_waiter_add(struct vmw_private *dev_priv, u32 flag,
887 int *waiter_count);
888extern void vmw_generic_waiter_remove(struct vmw_private *dev_priv,
889 u32 flag, int *waiter_count);
890
891
892
893
894
895
896extern void vmw_marker_queue_init(struct vmw_marker_queue *queue);
897extern void vmw_marker_queue_takedown(struct vmw_marker_queue *queue);
898extern int vmw_marker_push(struct vmw_marker_queue *queue,
899 uint32_t seqno);
900extern int vmw_marker_pull(struct vmw_marker_queue *queue,
901 uint32_t signaled_seqno);
902extern int vmw_wait_lag(struct vmw_private *dev_priv,
903 struct vmw_marker_queue *queue, uint32_t us);
904
905
906
907
908
909int vmw_fb_init(struct vmw_private *vmw_priv);
910int vmw_fb_close(struct vmw_private *dev_priv);
911int vmw_fb_off(struct vmw_private *vmw_priv);
912int vmw_fb_on(struct vmw_private *vmw_priv);
913
914
915
916
917
918int vmw_kms_init(struct vmw_private *dev_priv);
919int vmw_kms_close(struct vmw_private *dev_priv);
920int vmw_kms_save_vga(struct vmw_private *vmw_priv);
921int vmw_kms_restore_vga(struct vmw_private *vmw_priv);
922int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
923 struct drm_file *file_priv);
924void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
925void vmw_kms_cursor_snoop(struct vmw_surface *srf,
926 struct ttm_object_file *tfile,
927 struct ttm_buffer_object *bo,
928 SVGA3dCmdHeader *header);
929int vmw_kms_write_svga(struct vmw_private *vmw_priv,
930 unsigned width, unsigned height, unsigned pitch,
931 unsigned bpp, unsigned depth);
932void vmw_kms_idle_workqueues(struct vmw_master *vmaster);
933bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
934 uint32_t pitch,
935 uint32_t height);
936u32 vmw_get_vblank_counter(struct drm_device *dev, unsigned int pipe);
937int vmw_enable_vblank(struct drm_device *dev, unsigned int pipe);
938void vmw_disable_vblank(struct drm_device *dev, unsigned int pipe);
939int vmw_kms_present(struct vmw_private *dev_priv,
940 struct drm_file *file_priv,
941 struct vmw_framebuffer *vfb,
942 struct vmw_surface *surface,
943 uint32_t sid, int32_t destX, int32_t destY,
944 struct drm_vmw_rect *clips,
945 uint32_t num_clips);
946int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
947 struct drm_file *file_priv);
948void vmw_kms_legacy_hotspot_clear(struct vmw_private *dev_priv);
949int vmw_kms_suspend(struct drm_device *dev);
950int vmw_kms_resume(struct drm_device *dev);
951void vmw_kms_lost_device(struct drm_device *dev);
952
953int vmw_dumb_create(struct drm_file *file_priv,
954 struct drm_device *dev,
955 struct drm_mode_create_dumb *args);
956
957int vmw_dumb_map_offset(struct drm_file *file_priv,
958 struct drm_device *dev, uint32_t handle,
959 uint64_t *offset);
960int vmw_dumb_destroy(struct drm_file *file_priv,
961 struct drm_device *dev,
962 uint32_t handle);
963extern int vmw_resource_pin(struct vmw_resource *res, bool interruptible);
964extern void vmw_resource_unpin(struct vmw_resource *res);
965extern enum vmw_res_type vmw_res_type(const struct vmw_resource *res);
966
967
968
969
970
971int vmw_overlay_init(struct vmw_private *dev_priv);
972int vmw_overlay_close(struct vmw_private *dev_priv);
973int vmw_overlay_ioctl(struct drm_device *dev, void *data,
974 struct drm_file *file_priv);
975int vmw_overlay_stop_all(struct vmw_private *dev_priv);
976int vmw_overlay_resume_all(struct vmw_private *dev_priv);
977int vmw_overlay_pause_all(struct vmw_private *dev_priv);
978int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
979int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
980int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
981int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
982
983
984
985
986
987extern const struct ttm_mem_type_manager_func vmw_gmrid_manager_func;
988
989
990
991
992
993extern const struct dma_buf_ops vmw_prime_dmabuf_ops;
994extern int vmw_prime_fd_to_handle(struct drm_device *dev,
995 struct drm_file *file_priv,
996 int fd, u32 *handle);
997extern int vmw_prime_handle_to_fd(struct drm_device *dev,
998 struct drm_file *file_priv,
999 uint32_t handle, uint32_t flags,
1000 int *prime_fd);
1001
1002
1003
1004
1005struct vmw_mob;
1006extern int vmw_mob_bind(struct vmw_private *dev_priv, struct vmw_mob *mob,
1007 const struct vmw_sg_table *vsgt,
1008 unsigned long num_data_pages, int32_t mob_id);
1009extern void vmw_mob_unbind(struct vmw_private *dev_priv,
1010 struct vmw_mob *mob);
1011extern void vmw_mob_destroy(struct vmw_mob *mob);
1012extern struct vmw_mob *vmw_mob_create(unsigned long data_pages);
1013extern int vmw_otables_setup(struct vmw_private *dev_priv);
1014extern void vmw_otables_takedown(struct vmw_private *dev_priv);
1015
1016
1017
1018
1019
1020extern const struct vmw_user_resource_conv *user_context_converter;
1021
1022extern int vmw_context_check(struct vmw_private *dev_priv,
1023 struct ttm_object_file *tfile,
1024 int id,
1025 struct vmw_resource **p_res);
1026extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
1027 struct drm_file *file_priv);
1028extern int vmw_extended_context_define_ioctl(struct drm_device *dev, void *data,
1029 struct drm_file *file_priv);
1030extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
1031 struct drm_file *file_priv);
1032extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
1033extern struct vmw_cmdbuf_res_manager *
1034vmw_context_res_man(struct vmw_resource *ctx);
1035extern struct vmw_resource *vmw_context_cotable(struct vmw_resource *ctx,
1036 SVGACOTableType cotable_type);
1037extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
1038struct vmw_ctx_binding_state;
1039extern struct vmw_ctx_binding_state *
1040vmw_context_binding_state(struct vmw_resource *ctx);
1041extern void vmw_dx_context_scrub_cotables(struct vmw_resource *ctx,
1042 bool readback);
1043extern int vmw_context_bind_dx_query(struct vmw_resource *ctx_res,
1044 struct vmw_dma_buffer *mob);
1045extern struct vmw_dma_buffer *
1046vmw_context_get_dx_query_mob(struct vmw_resource *ctx_res);
1047
1048
1049
1050
1051
1052
1053extern const struct vmw_user_resource_conv *user_surface_converter;
1054
1055extern void vmw_surface_res_free(struct vmw_resource *res);
1056extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data,
1057 struct drm_file *file_priv);
1058extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
1059 struct drm_file *file_priv);
1060extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,
1061 struct drm_file *file_priv);
1062extern int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data,
1063 struct drm_file *file_priv);
1064extern int vmw_gb_surface_reference_ioctl(struct drm_device *dev, void *data,
1065 struct drm_file *file_priv);
1066extern int vmw_surface_check(struct vmw_private *dev_priv,
1067 struct ttm_object_file *tfile,
1068 uint32_t handle, int *id);
1069extern int vmw_surface_validate(struct vmw_private *dev_priv,
1070 struct vmw_surface *srf);
1071int vmw_surface_gb_priv_define(struct drm_device *dev,
1072 uint32_t user_accounting_size,
1073 uint32_t svga3d_flags,
1074 SVGA3dSurfaceFormat format,
1075 bool for_scanout,
1076 uint32_t num_mip_levels,
1077 uint32_t multisample_count,
1078 uint32_t array_size,
1079 struct drm_vmw_size size,
1080 struct vmw_surface **srf_out);
1081
1082
1083
1084
1085
1086extern const struct vmw_user_resource_conv *user_shader_converter;
1087
1088extern int vmw_shader_define_ioctl(struct drm_device *dev, void *data,
1089 struct drm_file *file_priv);
1090extern int vmw_shader_destroy_ioctl(struct drm_device *dev, void *data,
1091 struct drm_file *file_priv);
1092extern int vmw_compat_shader_add(struct vmw_private *dev_priv,
1093 struct vmw_cmdbuf_res_manager *man,
1094 u32 user_key, const void *bytecode,
1095 SVGA3dShaderType shader_type,
1096 size_t size,
1097 struct list_head *list);
1098extern int vmw_shader_remove(struct vmw_cmdbuf_res_manager *man,
1099 u32 user_key, SVGA3dShaderType shader_type,
1100 struct list_head *list);
1101extern int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,
1102 struct vmw_resource *ctx,
1103 u32 user_key,
1104 SVGA3dShaderType shader_type,
1105 struct list_head *list);
1106extern void vmw_dx_shader_cotable_list_scrub(struct vmw_private *dev_priv,
1107 struct list_head *list,
1108 bool readback);
1109
1110extern struct vmw_resource *
1111vmw_shader_lookup(struct vmw_cmdbuf_res_manager *man,
1112 u32 user_key, SVGA3dShaderType shader_type);
1113
1114
1115
1116
1117
1118extern struct vmw_cmdbuf_res_manager *
1119vmw_cmdbuf_res_man_create(struct vmw_private *dev_priv);
1120extern void vmw_cmdbuf_res_man_destroy(struct vmw_cmdbuf_res_manager *man);
1121extern size_t vmw_cmdbuf_res_man_size(void);
1122extern struct vmw_resource *
1123vmw_cmdbuf_res_lookup(struct vmw_cmdbuf_res_manager *man,
1124 enum vmw_cmdbuf_res_type res_type,
1125 u32 user_key);
1126extern void vmw_cmdbuf_res_revert(struct list_head *list);
1127extern void vmw_cmdbuf_res_commit(struct list_head *list);
1128extern int vmw_cmdbuf_res_add(struct vmw_cmdbuf_res_manager *man,
1129 enum vmw_cmdbuf_res_type res_type,
1130 u32 user_key,
1131 struct vmw_resource *res,
1132 struct list_head *list);
1133extern int vmw_cmdbuf_res_remove(struct vmw_cmdbuf_res_manager *man,
1134 enum vmw_cmdbuf_res_type res_type,
1135 u32 user_key,
1136 struct list_head *list,
1137 struct vmw_resource **res);
1138
1139
1140
1141
1142extern const SVGACOTableType vmw_cotable_scrub_order[];
1143extern struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv,
1144 struct vmw_resource *ctx,
1145 u32 type);
1146extern int vmw_cotable_notify(struct vmw_resource *res, int id);
1147extern int vmw_cotable_scrub(struct vmw_resource *res, bool readback);
1148extern void vmw_cotable_add_resource(struct vmw_resource *ctx,
1149 struct list_head *head);
1150
1151
1152
1153
1154struct vmw_cmdbuf_man;
1155struct vmw_cmdbuf_header;
1156
1157extern struct vmw_cmdbuf_man *
1158vmw_cmdbuf_man_create(struct vmw_private *dev_priv);
1159extern int vmw_cmdbuf_set_pool_size(struct vmw_cmdbuf_man *man,
1160 size_t size, size_t default_size);
1161extern void vmw_cmdbuf_remove_pool(struct vmw_cmdbuf_man *man);
1162extern void vmw_cmdbuf_man_destroy(struct vmw_cmdbuf_man *man);
1163extern int vmw_cmdbuf_idle(struct vmw_cmdbuf_man *man, bool interruptible,
1164 unsigned long timeout);
1165extern void *vmw_cmdbuf_reserve(struct vmw_cmdbuf_man *man, size_t size,
1166 int ctx_id, bool interruptible,
1167 struct vmw_cmdbuf_header *header);
1168extern void vmw_cmdbuf_commit(struct vmw_cmdbuf_man *man, size_t size,
1169 struct vmw_cmdbuf_header *header,
1170 bool flush);
1171extern void *vmw_cmdbuf_alloc(struct vmw_cmdbuf_man *man,
1172 size_t size, bool interruptible,
1173 struct vmw_cmdbuf_header **p_header);
1174extern void vmw_cmdbuf_header_free(struct vmw_cmdbuf_header *header);
1175extern int vmw_cmdbuf_cur_flush(struct vmw_cmdbuf_man *man,
1176 bool interruptible);
1177extern void vmw_cmdbuf_irqthread(struct vmw_cmdbuf_man *man);
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190struct vmw_diff_cpy {
1191 struct drm_rect rect;
1192 size_t line;
1193 size_t line_offset;
1194 int cpp;
1195 void (*do_cpy)(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src,
1196 size_t n);
1197};
1198
1199#define VMW_CPU_BLIT_INITIALIZER { \
1200 .do_cpy = vmw_memcpy, \
1201}
1202
1203#define VMW_CPU_BLIT_DIFF_INITIALIZER(_cpp) { \
1204 .line = 0, \
1205 .line_offset = 0, \
1206 .rect = { .x1 = INT_MAX/2, \
1207 .y1 = INT_MAX/2, \
1208 .x2 = INT_MIN/2, \
1209 .y2 = INT_MIN/2 \
1210 }, \
1211 .cpp = _cpp, \
1212 .do_cpy = vmw_diff_memcpy, \
1213}
1214
1215void vmw_diff_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src,
1216 size_t n);
1217
1218void vmw_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src, size_t n);
1219
1220int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
1221 u32 dst_offset, u32 dst_stride,
1222 struct ttm_buffer_object *src,
1223 u32 src_offset, u32 src_stride,
1224 u32 w, u32 h,
1225 struct vmw_diff_cpy *diff);
1226
1227
1228
1229
1230
1231static inline void vmw_surface_unreference(struct vmw_surface **srf)
1232{
1233 struct vmw_surface *tmp_srf = *srf;
1234 struct vmw_resource *res = &tmp_srf->res;
1235 *srf = NULL;
1236
1237 vmw_resource_unreference(&res);
1238}
1239
1240static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
1241{
1242 (void) vmw_resource_reference(&srf->res);
1243 return srf;
1244}
1245
1246static inline void vmw_dmabuf_unreference(struct vmw_dma_buffer **buf)
1247{
1248 struct vmw_dma_buffer *tmp_buf = *buf;
1249
1250 *buf = NULL;
1251 if (tmp_buf != NULL) {
1252 struct ttm_buffer_object *bo = &tmp_buf->base;
1253
1254 ttm_bo_unref(&bo);
1255 }
1256}
1257
1258static inline struct vmw_dma_buffer *vmw_dmabuf_reference(struct vmw_dma_buffer *buf)
1259{
1260 if (ttm_bo_reference(&buf->base))
1261 return buf;
1262 return NULL;
1263}
1264
1265static inline struct ttm_mem_global *vmw_mem_glob(struct vmw_private *dev_priv)
1266{
1267 return (struct ttm_mem_global *) dev_priv->mem_global_ref.object;
1268}
1269
1270static inline void vmw_fifo_resource_inc(struct vmw_private *dev_priv)
1271{
1272 atomic_inc(&dev_priv->num_fifo_resources);
1273}
1274
1275static inline void vmw_fifo_resource_dec(struct vmw_private *dev_priv)
1276{
1277 atomic_dec(&dev_priv->num_fifo_resources);
1278}
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288static inline u32 vmw_mmio_read(u32 *addr)
1289{
1290 return READ_ONCE(*addr);
1291}
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301static inline void vmw_mmio_write(u32 value, u32 *addr)
1302{
1303 WRITE_ONCE(*addr, value);
1304}
1305
1306
1307
1308
1309extern int vmw_host_log(const char *log);
1310
1311#endif
1312