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 <linux/suspend.h>
32#include <linux/sync_file.h>
33
34#include <drm/drm_auth.h>
35#include <drm/drm_device.h>
36#include <drm/drm_file.h>
37#include <drm/drm_hashtab.h>
38#include <drm/drm_rect.h>
39
40#include <drm/ttm/ttm_bo_driver.h>
41#include <drm/ttm/ttm_execbuf_util.h>
42
43#include "ttm_object.h"
44
45#include "vmwgfx_fence.h"
46#include "vmwgfx_reg.h"
47#include "vmwgfx_validation.h"
48
49
50
51
52
53#include <drm/vmwgfx_drm.h>
54
55
56#define VMWGFX_DRIVER_NAME "vmwgfx"
57#define VMWGFX_DRIVER_DATE "20210218"
58#define VMWGFX_DRIVER_MAJOR 2
59#define VMWGFX_DRIVER_MINOR 18
60#define VMWGFX_DRIVER_PATCHLEVEL 1
61#define VMWGFX_FIFO_STATIC_SIZE (1024*1024)
62#define VMWGFX_MAX_RELOCATIONS 2048
63#define VMWGFX_MAX_VALIDATIONS 2048
64#define VMWGFX_MAX_DISPLAYS 16
65#define VMWGFX_CMD_BOUNCE_INIT_SIZE 32768
66#define VMWGFX_ENABLE_SCREEN_TARGET_OTABLE 1
67
68#define VMWGFX_PCI_ID_SVGA2 0x0405
69#define VMWGFX_PCI_ID_SVGA3 0x0406
70
71
72
73
74#define VMWGFX_NUM_GB_CONTEXT 256
75#define VMWGFX_NUM_GB_SHADER 20000
76#define VMWGFX_NUM_GB_SURFACE 32768
77#define VMWGFX_NUM_GB_SCREEN_TARGET VMWGFX_MAX_DISPLAYS
78#define VMWGFX_NUM_DXCONTEXT 256
79#define VMWGFX_NUM_DXQUERY 512
80#define VMWGFX_NUM_MOB (VMWGFX_NUM_GB_CONTEXT +\
81 VMWGFX_NUM_GB_SHADER +\
82 VMWGFX_NUM_GB_SURFACE +\
83 VMWGFX_NUM_GB_SCREEN_TARGET)
84
85#define VMW_PL_GMR (TTM_PL_PRIV + 0)
86#define VMW_PL_MOB (TTM_PL_PRIV + 1)
87#define VMW_PL_SYSTEM (TTM_PL_PRIV + 2)
88
89#define VMW_RES_CONTEXT ttm_driver_type0
90#define VMW_RES_SURFACE ttm_driver_type1
91#define VMW_RES_STREAM ttm_driver_type2
92#define VMW_RES_FENCE ttm_driver_type3
93#define VMW_RES_SHADER ttm_driver_type4
94
95struct vmw_fpriv {
96 struct ttm_object_file *tfile;
97 bool gb_aware;
98};
99
100
101
102
103
104
105
106
107
108
109
110
111struct vmw_buffer_object {
112 struct ttm_buffer_object base;
113 struct rb_root res_tree;
114 atomic_t cpu_writers;
115
116 struct vmw_resource *dx_query_ctx;
117
118 struct ttm_bo_kmap_obj map;
119 u32 res_prios[TTM_MAX_BO_PRIORITY];
120 struct vmw_bo_dirty *dirty;
121};
122
123
124
125
126
127
128
129
130
131
132struct vmw_validate_buffer {
133 struct ttm_validate_buffer base;
134 struct drm_hash_item hash;
135 bool validate_as_mob;
136};
137
138struct vmw_res_func;
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169struct vmw_resource_dirty;
170struct vmw_resource {
171 struct kref kref;
172 struct vmw_private *dev_priv;
173 int id;
174 u32 used_prio;
175 unsigned long backup_size;
176 u32 res_dirty : 1;
177 u32 backup_dirty : 1;
178 u32 coherent : 1;
179 struct vmw_buffer_object *backup;
180 unsigned long backup_offset;
181 unsigned long pin_count;
182 const struct vmw_res_func *func;
183 struct rb_node mob_node;
184 struct list_head lru_head;
185 struct list_head binding_head;
186 struct vmw_resource_dirty *dirty;
187 void (*res_free) (struct vmw_resource *res);
188 void (*hw_destroy) (struct vmw_resource *res);
189};
190
191
192
193
194
195enum vmw_res_type {
196 vmw_res_context,
197 vmw_res_surface,
198 vmw_res_stream,
199 vmw_res_shader,
200 vmw_res_dx_context,
201 vmw_res_cotable,
202 vmw_res_view,
203 vmw_res_streamoutput,
204 vmw_res_max
205};
206
207
208
209
210enum vmw_cmdbuf_res_type {
211 vmw_cmdbuf_res_shader,
212 vmw_cmdbuf_res_view,
213 vmw_cmdbuf_res_streamoutput
214};
215
216struct vmw_cmdbuf_res_manager;
217
218struct vmw_cursor_snooper {
219 size_t age;
220 uint32_t *image;
221};
222
223struct vmw_framebuffer;
224struct vmw_surface_offset;
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247struct vmw_surface_metadata {
248 u64 flags;
249 u32 format;
250 u32 mip_levels[DRM_VMW_MAX_SURFACE_FACES];
251 u32 multisample_count;
252 u32 multisample_pattern;
253 u32 quality_level;
254 u32 autogen_filter;
255 u32 array_size;
256 u32 num_sizes;
257 u32 buffer_byte_stride;
258 struct drm_vmw_size base_size;
259 struct drm_vmw_size *sizes;
260 bool scanout;
261};
262
263
264
265
266
267
268
269
270
271
272struct vmw_surface {
273 struct vmw_resource res;
274 struct vmw_surface_metadata metadata;
275 struct vmw_cursor_snooper snooper;
276 struct vmw_surface_offset *offsets;
277 struct list_head view_list;
278};
279
280struct vmw_fifo_state {
281 unsigned long reserved_size;
282 u32 *dynamic_buffer;
283 u32 *static_buffer;
284 unsigned long static_buffer_size;
285 bool using_bounce_buffer;
286 uint32_t capabilities;
287 struct mutex fifo_mutex;
288 struct rw_semaphore rwsem;
289};
290
291
292
293
294
295
296
297
298
299
300
301
302
303struct vmw_res_cache_entry {
304 uint32_t handle;
305 struct vmw_resource *res;
306 void *private;
307 unsigned short valid_handle;
308 unsigned short valid;
309};
310
311
312
313
314enum vmw_dma_map_mode {
315 vmw_dma_phys,
316 vmw_dma_alloc_coherent,
317 vmw_dma_map_populate,
318 vmw_dma_map_bind,
319 vmw_dma_map_max
320};
321
322
323
324
325
326
327
328
329struct vmw_sg_table {
330 enum vmw_dma_map_mode mode;
331 struct page **pages;
332 const dma_addr_t *addrs;
333 struct sg_table *sgt;
334 unsigned long num_regions;
335 unsigned long num_pages;
336};
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352struct vmw_piter {
353 struct page **pages;
354 const dma_addr_t *addrs;
355 struct sg_dma_page_iter iter;
356 unsigned long i;
357 unsigned long num_pages;
358 bool (*next)(struct vmw_piter *);
359 dma_addr_t (*dma_address)(struct vmw_piter *);
360 struct page *(*page)(struct vmw_piter *);
361};
362
363
364
365
366enum vmw_display_unit_type {
367 vmw_du_invalid = 0,
368 vmw_du_legacy,
369 vmw_du_screen_object,
370 vmw_du_screen_target
371};
372
373struct vmw_validation_context;
374struct vmw_ctx_validation_info;
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407struct vmw_sw_context{
408 struct drm_open_hash res_ht;
409 bool res_ht_initialized;
410 bool kernel;
411 struct vmw_fpriv *fp;
412 uint32_t *cmd_bounce;
413 uint32_t cmd_bounce_size;
414 struct vmw_buffer_object *cur_query_bo;
415 struct list_head bo_relocations;
416 struct list_head res_relocations;
417 uint32_t *buf_start;
418 struct vmw_res_cache_entry res_cache[vmw_res_max];
419 struct vmw_resource *last_query_ctx;
420 bool needs_post_query_barrier;
421 struct vmw_ctx_binding_state *staged_bindings;
422 bool staged_bindings_inuse;
423 struct list_head staged_cmd_res;
424 struct list_head ctx_list;
425 struct vmw_ctx_validation_info *dx_ctx_node;
426 struct vmw_buffer_object *dx_query_mob;
427 struct vmw_resource *dx_query_ctx;
428 struct vmw_cmdbuf_res_manager *man;
429 struct vmw_validation_context *ctx;
430};
431
432struct vmw_legacy_display;
433struct vmw_overlay;
434
435struct vmw_vga_topology_state {
436 uint32_t width;
437 uint32_t height;
438 uint32_t primary;
439 uint32_t pos_x;
440 uint32_t pos_y;
441};
442
443
444
445
446
447
448
449
450struct vmw_otable {
451 unsigned long size;
452 struct vmw_mob *page_table;
453 bool enabled;
454};
455
456struct vmw_otable_batch {
457 unsigned num_otables;
458 struct vmw_otable *otables;
459 struct vmw_resource *context;
460 struct ttm_buffer_object *otable_bo;
461};
462
463enum {
464 VMW_IRQTHREAD_FENCE,
465 VMW_IRQTHREAD_CMDBUF,
466 VMW_IRQTHREAD_MAX
467};
468
469
470
471
472
473
474
475
476
477enum vmw_sm_type {
478 VMW_SM_LEGACY = 0,
479 VMW_SM_4,
480 VMW_SM_4_1,
481 VMW_SM_5,
482 VMW_SM_MAX
483};
484
485struct vmw_private {
486 struct drm_device drm;
487 struct ttm_device bdev;
488
489 struct drm_vma_offset_manager vma_manager;
490 unsigned long pci_id;
491 u32 vmw_chipset;
492 resource_size_t io_start;
493 resource_size_t vram_start;
494 resource_size_t vram_size;
495 resource_size_t prim_bb_mem;
496 u32 __iomem *rmmio;
497 u32 *fifo_mem;
498 resource_size_t fifo_mem_size;
499 uint32_t fb_max_width;
500 uint32_t fb_max_height;
501 uint32_t texture_max_width;
502 uint32_t texture_max_height;
503 uint32_t stdu_max_width;
504 uint32_t stdu_max_height;
505 uint32_t initial_width;
506 uint32_t initial_height;
507 uint32_t capabilities;
508 uint32_t capabilities2;
509 uint32_t max_gmr_ids;
510 uint32_t max_gmr_pages;
511 uint32_t max_mob_pages;
512 uint32_t max_mob_size;
513 uint32_t memory_size;
514 bool has_gmr;
515 bool has_mob;
516 spinlock_t hw_lock;
517 spinlock_t cap_lock;
518 bool assume_16bpp;
519
520 enum vmw_sm_type sm_type;
521
522
523
524
525
526 void *fb_info;
527 enum vmw_display_unit_type active_display_unit;
528 struct vmw_legacy_display *ldu_priv;
529 struct vmw_overlay *overlay_priv;
530 struct drm_property *hotplug_mode_update_property;
531 struct drm_property *implicit_placement_property;
532 spinlock_t cursor_lock;
533 struct drm_atomic_state *suspend_state;
534
535
536
537
538
539 spinlock_t resource_lock;
540 struct idr res_idr[vmw_res_max];
541
542
543
544
545
546
547 struct ttm_object_device *tdev;
548
549
550
551
552
553 atomic_t marker_seq;
554 wait_queue_head_t fence_queue;
555 wait_queue_head_t fifo_queue;
556 spinlock_t waiter_lock;
557 int fence_queue_waiters;
558 int goal_queue_waiters;
559 int cmdbuf_waiters;
560 int error_waiters;
561 int fifo_queue_waiters;
562 uint32_t last_read_seqno;
563 struct vmw_fence_manager *fman;
564 uint32_t irq_mask;
565
566
567
568
569
570 uint32_t traces_state;
571 uint32_t enable_state;
572 uint32_t config_done_state;
573
574
575
576
577
578
579
580
581 struct vmw_sw_context ctx;
582 struct mutex cmdbuf_mutex;
583 struct mutex binding_mutex;
584
585 bool enable_fb;
586
587
588
589
590 struct notifier_block pm_nb;
591 bool refuse_hibernation;
592 bool suspend_locked;
593
594 atomic_t num_fifo_resources;
595
596
597
598
599
600
601 struct vmw_buffer_object *dummy_query_bo;
602 struct vmw_buffer_object *pinned_bo;
603 uint32_t query_cid;
604 uint32_t query_cid_valid;
605 bool dummy_query_bo_pinned;
606
607
608
609
610
611
612
613
614 struct list_head res_lru[vmw_res_max];
615 uint32_t used_memory_size;
616
617
618
619
620 enum vmw_dma_map_mode map_mode;
621
622
623
624
625 struct vmw_otable_batch otable_batch;
626
627 struct vmw_fifo_state *fifo;
628 struct vmw_cmdbuf_man *cman;
629 DECLARE_BITMAP(irqthread_pending, VMW_IRQTHREAD_MAX);
630
631
632 struct vmw_validation_mem vvm;
633};
634
635static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res)
636{
637 return container_of(res, struct vmw_surface, res);
638}
639
640static inline struct vmw_private *vmw_priv(struct drm_device *dev)
641{
642 return (struct vmw_private *)dev->dev_private;
643}
644
645static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
646{
647 return (struct vmw_fpriv *)file_priv->driver_priv;
648}
649
650
651
652
653static inline bool vmw_is_svga_v3(const struct vmw_private *dev)
654{
655 return dev->pci_id == VMWGFX_PCI_ID_SVGA3;
656}
657
658
659
660
661
662
663
664
665static inline void vmw_write(struct vmw_private *dev_priv,
666 unsigned int offset, uint32_t value)
667{
668 if (vmw_is_svga_v3(dev_priv)) {
669 iowrite32(value, dev_priv->rmmio + offset);
670 } else {
671 spin_lock(&dev_priv->hw_lock);
672 outl(offset, dev_priv->io_start + SVGA_INDEX_PORT);
673 outl(value, dev_priv->io_start + SVGA_VALUE_PORT);
674 spin_unlock(&dev_priv->hw_lock);
675 }
676}
677
678static inline uint32_t vmw_read(struct vmw_private *dev_priv,
679 unsigned int offset)
680{
681 u32 val;
682
683 if (vmw_is_svga_v3(dev_priv)) {
684 val = ioread32(dev_priv->rmmio + offset);
685 } else {
686 spin_lock(&dev_priv->hw_lock);
687 outl(offset, dev_priv->io_start + SVGA_INDEX_PORT);
688 val = inl(dev_priv->io_start + SVGA_VALUE_PORT);
689 spin_unlock(&dev_priv->hw_lock);
690 }
691
692 return val;
693}
694
695
696
697
698
699
700
701static inline bool has_sm4_context(const struct vmw_private *dev_priv)
702{
703 return (dev_priv->sm_type >= VMW_SM_4);
704}
705
706
707
708
709
710
711
712static inline bool has_sm4_1_context(const struct vmw_private *dev_priv)
713{
714 return (dev_priv->sm_type >= VMW_SM_4_1);
715}
716
717
718
719
720
721
722
723static inline bool has_sm5_context(const struct vmw_private *dev_priv)
724{
725 return (dev_priv->sm_type >= VMW_SM_5);
726}
727
728extern void vmw_svga_enable(struct vmw_private *dev_priv);
729extern void vmw_svga_disable(struct vmw_private *dev_priv);
730
731
732
733
734
735
736extern int vmw_gmr_bind(struct vmw_private *dev_priv,
737 const struct vmw_sg_table *vsgt,
738 unsigned long num_pages,
739 int gmr_id);
740extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
741
742
743
744
745struct vmw_user_resource_conv;
746
747extern void vmw_resource_unreference(struct vmw_resource **p_res);
748extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
749extern struct vmw_resource *
750vmw_resource_reference_unless_doomed(struct vmw_resource *res);
751extern int vmw_resource_validate(struct vmw_resource *res, bool intr,
752 bool dirtying);
753extern int vmw_resource_reserve(struct vmw_resource *res, bool interruptible,
754 bool no_backup);
755extern bool vmw_resource_needs_backup(const struct vmw_resource *res);
756extern int vmw_user_lookup_handle(struct vmw_private *dev_priv,
757 struct ttm_object_file *tfile,
758 uint32_t handle,
759 struct vmw_surface **out_surf,
760 struct vmw_buffer_object **out_buf);
761extern int vmw_user_resource_lookup_handle(
762 struct vmw_private *dev_priv,
763 struct ttm_object_file *tfile,
764 uint32_t handle,
765 const struct vmw_user_resource_conv *converter,
766 struct vmw_resource **p_res);
767extern struct vmw_resource *
768vmw_user_resource_noref_lookup_handle(struct vmw_private *dev_priv,
769 struct ttm_object_file *tfile,
770 uint32_t handle,
771 const struct vmw_user_resource_conv *
772 converter);
773extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
774 struct drm_file *file_priv);
775extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
776 struct drm_file *file_priv);
777extern int vmw_user_stream_lookup(struct vmw_private *dev_priv,
778 struct ttm_object_file *tfile,
779 uint32_t *inout_id,
780 struct vmw_resource **out);
781extern void vmw_resource_unreserve(struct vmw_resource *res,
782 bool dirty_set,
783 bool dirty,
784 bool switch_backup,
785 struct vmw_buffer_object *new_backup,
786 unsigned long new_backup_offset);
787extern void vmw_query_move_notify(struct ttm_buffer_object *bo,
788 struct ttm_resource *old_mem,
789 struct ttm_resource *new_mem);
790extern int vmw_query_readback_all(struct vmw_buffer_object *dx_query_mob);
791extern void vmw_resource_evict_all(struct vmw_private *dev_priv);
792extern void vmw_resource_unbind_list(struct vmw_buffer_object *vbo);
793void vmw_resource_mob_attach(struct vmw_resource *res);
794void vmw_resource_mob_detach(struct vmw_resource *res);
795void vmw_resource_dirty_update(struct vmw_resource *res, pgoff_t start,
796 pgoff_t end);
797int vmw_resources_clean(struct vmw_buffer_object *vbo, pgoff_t start,
798 pgoff_t end, pgoff_t *num_prefault);
799
800
801
802
803
804
805
806static inline bool vmw_resource_mob_attached(const struct vmw_resource *res)
807{
808 return !RB_EMPTY_NODE(&res->mob_node);
809}
810
811
812
813
814
815static inline void vmw_user_resource_noref_release(void)
816{
817 ttm_base_object_noref_release();
818}
819
820
821
822
823extern int vmw_bo_pin_in_placement(struct vmw_private *vmw_priv,
824 struct vmw_buffer_object *bo,
825 struct ttm_placement *placement,
826 bool interruptible);
827extern int vmw_bo_pin_in_vram(struct vmw_private *dev_priv,
828 struct vmw_buffer_object *buf,
829 bool interruptible);
830extern int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
831 struct vmw_buffer_object *buf,
832 bool interruptible);
833extern int vmw_bo_pin_in_start_of_vram(struct vmw_private *vmw_priv,
834 struct vmw_buffer_object *bo,
835 bool interruptible);
836extern int vmw_bo_unpin(struct vmw_private *vmw_priv,
837 struct vmw_buffer_object *bo,
838 bool interruptible);
839extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf,
840 SVGAGuestPtr *ptr);
841extern void vmw_bo_pin_reserved(struct vmw_buffer_object *bo, bool pin);
842extern void vmw_bo_bo_free(struct ttm_buffer_object *bo);
843extern int vmw_bo_create_kernel(struct vmw_private *dev_priv,
844 unsigned long size,
845 struct ttm_placement *placement,
846 struct ttm_buffer_object **p_bo);
847extern int vmw_bo_init(struct vmw_private *dev_priv,
848 struct vmw_buffer_object *vmw_bo,
849 size_t size, struct ttm_placement *placement,
850 bool interruptible, bool pin,
851 void (*bo_free)(struct ttm_buffer_object *bo));
852extern int vmw_user_bo_verify_access(struct ttm_buffer_object *bo,
853 struct ttm_object_file *tfile);
854extern int vmw_user_bo_alloc(struct vmw_private *dev_priv,
855 struct ttm_object_file *tfile,
856 uint32_t size,
857 bool shareable,
858 uint32_t *handle,
859 struct vmw_buffer_object **p_dma_buf,
860 struct ttm_base_object **p_base);
861extern int vmw_user_bo_reference(struct ttm_object_file *tfile,
862 struct vmw_buffer_object *dma_buf,
863 uint32_t *handle);
864extern int vmw_bo_alloc_ioctl(struct drm_device *dev, void *data,
865 struct drm_file *file_priv);
866extern int vmw_bo_unref_ioctl(struct drm_device *dev, void *data,
867 struct drm_file *file_priv);
868extern int vmw_user_bo_synccpu_ioctl(struct drm_device *dev, void *data,
869 struct drm_file *file_priv);
870extern int vmw_user_bo_lookup(struct ttm_object_file *tfile,
871 uint32_t id, struct vmw_buffer_object **out,
872 struct ttm_base_object **base);
873extern void vmw_bo_fence_single(struct ttm_buffer_object *bo,
874 struct vmw_fence_obj *fence);
875extern void *vmw_bo_map_and_cache(struct vmw_buffer_object *vbo);
876extern void vmw_bo_unmap(struct vmw_buffer_object *vbo);
877extern void vmw_bo_move_notify(struct ttm_buffer_object *bo,
878 struct ttm_resource *mem);
879extern void vmw_bo_swap_notify(struct ttm_buffer_object *bo);
880extern struct vmw_buffer_object *
881vmw_user_bo_noref_lookup(struct ttm_object_file *tfile, u32 handle);
882
883
884
885
886
887static inline void vmw_user_bo_noref_release(void)
888{
889 ttm_base_object_noref_release();
890}
891
892
893
894
895
896
897static inline void vmw_bo_prio_adjust(struct vmw_buffer_object *vbo)
898{
899 int i = ARRAY_SIZE(vbo->res_prios);
900
901 while (i--) {
902 if (vbo->res_prios[i]) {
903 vbo->base.priority = i;
904 return;
905 }
906 }
907
908 vbo->base.priority = 3;
909}
910
911
912
913
914
915
916
917
918
919
920static inline void vmw_bo_prio_add(struct vmw_buffer_object *vbo, int prio)
921{
922 if (vbo->res_prios[prio]++ == 0)
923 vmw_bo_prio_adjust(vbo);
924}
925
926
927
928
929
930
931
932
933
934
935static inline void vmw_bo_prio_del(struct vmw_buffer_object *vbo, int prio)
936{
937 if (--vbo->res_prios[prio] == 0)
938 vmw_bo_prio_adjust(vbo);
939}
940
941
942
943
944
945extern int vmw_getparam_ioctl(struct drm_device *dev, void *data,
946 struct drm_file *file_priv);
947extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
948 struct drm_file *file_priv);
949extern int vmw_present_ioctl(struct drm_device *dev, void *data,
950 struct drm_file *file_priv);
951extern int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
952 struct drm_file *file_priv);
953
954
955
956
957
958extern struct vmw_fifo_state *vmw_fifo_create(struct vmw_private *dev_priv);
959extern void vmw_fifo_destroy(struct vmw_private *dev_priv);
960extern bool vmw_cmd_supported(struct vmw_private *vmw);
961extern void *
962vmw_cmd_ctx_reserve(struct vmw_private *dev_priv, uint32_t bytes, int ctx_id);
963extern void vmw_cmd_commit(struct vmw_private *dev_priv, uint32_t bytes);
964extern void vmw_cmd_commit_flush(struct vmw_private *dev_priv, uint32_t bytes);
965extern int vmw_cmd_send_fence(struct vmw_private *dev_priv, uint32_t *seqno);
966extern bool vmw_supports_3d(struct vmw_private *dev_priv);
967extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
968extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv);
969extern int vmw_cmd_emit_dummy_query(struct vmw_private *dev_priv,
970 uint32_t cid);
971extern int vmw_cmd_flush(struct vmw_private *dev_priv,
972 bool interruptible);
973
974#define VMW_CMD_CTX_RESERVE(__priv, __bytes, __ctx_id) \
975({ \
976 vmw_cmd_ctx_reserve(__priv, __bytes, __ctx_id) ? : ({ \
977 DRM_ERROR("FIFO reserve failed at %s for %u bytes\n", \
978 __func__, (unsigned int) __bytes); \
979 NULL; \
980 }); \
981})
982
983#define VMW_CMD_RESERVE(__priv, __bytes) \
984 VMW_CMD_CTX_RESERVE(__priv, __bytes, SVGA3D_INVALID_ID)
985
986
987
988
989
990
991
992static inline uint32_t vmw_fifo_caps(const struct vmw_private *dev_priv)
993{
994 if (!dev_priv->fifo_mem || !dev_priv->fifo)
995 return 0;
996 return dev_priv->fifo->capabilities;
997}
998
999
1000
1001
1002
1003
1004
1005static inline bool
1006vmw_is_cursor_bypass3_enabled(const struct vmw_private *dev_priv)
1007{
1008 return (vmw_fifo_caps(dev_priv) & SVGA_FIFO_CAP_CURSOR_BYPASS_3) != 0;
1009}
1010
1011
1012
1013
1014
1015extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma);
1016
1017extern void vmw_validation_mem_init_ttm(struct vmw_private *dev_priv,
1018 size_t gran);
1019
1020
1021
1022
1023
1024extern const size_t vmw_tt_size;
1025extern struct ttm_placement vmw_vram_placement;
1026extern struct ttm_placement vmw_vram_sys_placement;
1027extern struct ttm_placement vmw_vram_gmr_placement;
1028extern struct ttm_placement vmw_sys_placement;
1029extern struct ttm_placement vmw_srf_placement;
1030extern struct ttm_placement vmw_mob_placement;
1031extern struct ttm_placement vmw_nonfixed_placement;
1032extern struct ttm_device_funcs vmw_bo_driver;
1033extern const struct vmw_sg_table *
1034vmw_bo_sg_table(struct ttm_buffer_object *bo);
1035extern int vmw_bo_create_and_populate(struct vmw_private *dev_priv,
1036 unsigned long bo_size,
1037 struct ttm_buffer_object **bo_p);
1038
1039extern void vmw_piter_start(struct vmw_piter *viter,
1040 const struct vmw_sg_table *vsgt,
1041 unsigned long p_offs);
1042
1043
1044
1045
1046
1047
1048
1049
1050static inline bool vmw_piter_next(struct vmw_piter *viter)
1051{
1052 return viter->next(viter);
1053}
1054
1055
1056
1057
1058
1059
1060
1061
1062static inline dma_addr_t vmw_piter_dma_addr(struct vmw_piter *viter)
1063{
1064 return viter->dma_address(viter);
1065}
1066
1067
1068
1069
1070
1071
1072
1073
1074static inline struct page *vmw_piter_page(struct vmw_piter *viter)
1075{
1076 return viter->page(viter);
1077}
1078
1079
1080
1081
1082
1083extern int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
1084 struct drm_file *file_priv);
1085extern int vmw_execbuf_process(struct drm_file *file_priv,
1086 struct vmw_private *dev_priv,
1087 void __user *user_commands,
1088 void *kernel_commands,
1089 uint32_t command_size,
1090 uint64_t throttle_us,
1091 uint32_t dx_context_handle,
1092 struct drm_vmw_fence_rep __user
1093 *user_fence_rep,
1094 struct vmw_fence_obj **out_fence,
1095 uint32_t flags);
1096extern void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv,
1097 struct vmw_fence_obj *fence);
1098extern void vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv);
1099
1100extern int vmw_execbuf_fence_commands(struct drm_file *file_priv,
1101 struct vmw_private *dev_priv,
1102 struct vmw_fence_obj **p_fence,
1103 uint32_t *p_handle);
1104extern int vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
1105 struct vmw_fpriv *vmw_fp,
1106 int ret,
1107 struct drm_vmw_fence_rep __user
1108 *user_fence_rep,
1109 struct vmw_fence_obj *fence,
1110 uint32_t fence_handle,
1111 int32_t out_fence_fd);
1112bool vmw_cmd_describe(const void *buf, u32 *size, char const **cmd);
1113
1114
1115
1116
1117
1118extern int vmw_irq_install(struct drm_device *dev, int irq);
1119extern void vmw_irq_uninstall(struct drm_device *dev);
1120extern bool vmw_seqno_passed(struct vmw_private *dev_priv,
1121 uint32_t seqno);
1122extern int vmw_fallback_wait(struct vmw_private *dev_priv,
1123 bool lazy,
1124 bool fifo_idle,
1125 uint32_t seqno,
1126 bool interruptible,
1127 unsigned long timeout);
1128extern void vmw_update_seqno(struct vmw_private *dev_priv);
1129extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
1130extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
1131extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
1132extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv);
1133extern void vmw_generic_waiter_add(struct vmw_private *dev_priv, u32 flag,
1134 int *waiter_count);
1135extern void vmw_generic_waiter_remove(struct vmw_private *dev_priv,
1136 u32 flag, int *waiter_count);
1137
1138
1139
1140
1141
1142
1143#ifdef CONFIG_DRM_FBDEV_EMULATION
1144int vmw_fb_init(struct vmw_private *vmw_priv);
1145int vmw_fb_close(struct vmw_private *dev_priv);
1146int vmw_fb_off(struct vmw_private *vmw_priv);
1147int vmw_fb_on(struct vmw_private *vmw_priv);
1148#else
1149static inline int vmw_fb_init(struct vmw_private *vmw_priv)
1150{
1151 return 0;
1152}
1153static inline int vmw_fb_close(struct vmw_private *dev_priv)
1154{
1155 return 0;
1156}
1157static inline int vmw_fb_off(struct vmw_private *vmw_priv)
1158{
1159 return 0;
1160}
1161static inline int vmw_fb_on(struct vmw_private *vmw_priv)
1162{
1163 return 0;
1164}
1165#endif
1166
1167
1168
1169
1170
1171int vmw_kms_init(struct vmw_private *dev_priv);
1172int vmw_kms_close(struct vmw_private *dev_priv);
1173int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
1174 struct drm_file *file_priv);
1175void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
1176void vmw_kms_cursor_snoop(struct vmw_surface *srf,
1177 struct ttm_object_file *tfile,
1178 struct ttm_buffer_object *bo,
1179 SVGA3dCmdHeader *header);
1180int vmw_kms_write_svga(struct vmw_private *vmw_priv,
1181 unsigned width, unsigned height, unsigned pitch,
1182 unsigned bpp, unsigned depth);
1183bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
1184 uint32_t pitch,
1185 uint32_t height);
1186u32 vmw_get_vblank_counter(struct drm_crtc *crtc);
1187int vmw_enable_vblank(struct drm_crtc *crtc);
1188void vmw_disable_vblank(struct drm_crtc *crtc);
1189int vmw_kms_present(struct vmw_private *dev_priv,
1190 struct drm_file *file_priv,
1191 struct vmw_framebuffer *vfb,
1192 struct vmw_surface *surface,
1193 uint32_t sid, int32_t destX, int32_t destY,
1194 struct drm_vmw_rect *clips,
1195 uint32_t num_clips);
1196int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
1197 struct drm_file *file_priv);
1198void vmw_kms_legacy_hotspot_clear(struct vmw_private *dev_priv);
1199int vmw_kms_suspend(struct drm_device *dev);
1200int vmw_kms_resume(struct drm_device *dev);
1201void vmw_kms_lost_device(struct drm_device *dev);
1202
1203int vmw_dumb_create(struct drm_file *file_priv,
1204 struct drm_device *dev,
1205 struct drm_mode_create_dumb *args);
1206
1207int vmw_dumb_map_offset(struct drm_file *file_priv,
1208 struct drm_device *dev, uint32_t handle,
1209 uint64_t *offset);
1210int vmw_dumb_destroy(struct drm_file *file_priv,
1211 struct drm_device *dev,
1212 uint32_t handle);
1213extern int vmw_resource_pin(struct vmw_resource *res, bool interruptible);
1214extern void vmw_resource_unpin(struct vmw_resource *res);
1215extern enum vmw_res_type vmw_res_type(const struct vmw_resource *res);
1216
1217
1218
1219
1220
1221int vmw_overlay_init(struct vmw_private *dev_priv);
1222int vmw_overlay_close(struct vmw_private *dev_priv);
1223int vmw_overlay_ioctl(struct drm_device *dev, void *data,
1224 struct drm_file *file_priv);
1225int vmw_overlay_resume_all(struct vmw_private *dev_priv);
1226int vmw_overlay_pause_all(struct vmw_private *dev_priv);
1227int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
1228int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
1229int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
1230int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
1231
1232
1233
1234
1235
1236int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type);
1237void vmw_gmrid_man_fini(struct vmw_private *dev_priv, int type);
1238
1239
1240
1241
1242int vmw_sys_man_init(struct vmw_private *dev_priv);
1243void vmw_sys_man_fini(struct vmw_private *dev_priv);
1244
1245
1246
1247
1248
1249extern const struct dma_buf_ops vmw_prime_dmabuf_ops;
1250extern int vmw_prime_fd_to_handle(struct drm_device *dev,
1251 struct drm_file *file_priv,
1252 int fd, u32 *handle);
1253extern int vmw_prime_handle_to_fd(struct drm_device *dev,
1254 struct drm_file *file_priv,
1255 uint32_t handle, uint32_t flags,
1256 int *prime_fd);
1257
1258
1259
1260
1261struct vmw_mob;
1262extern int vmw_mob_bind(struct vmw_private *dev_priv, struct vmw_mob *mob,
1263 const struct vmw_sg_table *vsgt,
1264 unsigned long num_data_pages, int32_t mob_id);
1265extern void vmw_mob_unbind(struct vmw_private *dev_priv,
1266 struct vmw_mob *mob);
1267extern void vmw_mob_destroy(struct vmw_mob *mob);
1268extern struct vmw_mob *vmw_mob_create(unsigned long data_pages);
1269extern int vmw_otables_setup(struct vmw_private *dev_priv);
1270extern void vmw_otables_takedown(struct vmw_private *dev_priv);
1271
1272
1273
1274
1275
1276extern const struct vmw_user_resource_conv *user_context_converter;
1277
1278extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
1279 struct drm_file *file_priv);
1280extern int vmw_extended_context_define_ioctl(struct drm_device *dev, void *data,
1281 struct drm_file *file_priv);
1282extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
1283 struct drm_file *file_priv);
1284extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
1285extern struct vmw_cmdbuf_res_manager *
1286vmw_context_res_man(struct vmw_resource *ctx);
1287extern struct vmw_resource *vmw_context_cotable(struct vmw_resource *ctx,
1288 SVGACOTableType cotable_type);
1289extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
1290struct vmw_ctx_binding_state;
1291extern struct vmw_ctx_binding_state *
1292vmw_context_binding_state(struct vmw_resource *ctx);
1293extern void vmw_dx_context_scrub_cotables(struct vmw_resource *ctx,
1294 bool readback);
1295extern int vmw_context_bind_dx_query(struct vmw_resource *ctx_res,
1296 struct vmw_buffer_object *mob);
1297extern struct vmw_buffer_object *
1298vmw_context_get_dx_query_mob(struct vmw_resource *ctx_res);
1299
1300
1301
1302
1303
1304
1305extern const struct vmw_user_resource_conv *user_surface_converter;
1306
1307extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data,
1308 struct drm_file *file_priv);
1309extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
1310 struct drm_file *file_priv);
1311extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,
1312 struct drm_file *file_priv);
1313extern int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data,
1314 struct drm_file *file_priv);
1315extern int vmw_gb_surface_reference_ioctl(struct drm_device *dev, void *data,
1316 struct drm_file *file_priv);
1317int vmw_surface_gb_priv_define(struct drm_device *dev,
1318 uint32_t user_accounting_size,
1319 SVGA3dSurfaceAllFlags svga3d_flags,
1320 SVGA3dSurfaceFormat format,
1321 bool for_scanout,
1322 uint32_t num_mip_levels,
1323 uint32_t multisample_count,
1324 uint32_t array_size,
1325 struct drm_vmw_size size,
1326 SVGA3dMSPattern multisample_pattern,
1327 SVGA3dMSQualityLevel quality_level,
1328 struct vmw_surface **srf_out);
1329extern int vmw_gb_surface_define_ext_ioctl(struct drm_device *dev,
1330 void *data,
1331 struct drm_file *file_priv);
1332extern int vmw_gb_surface_reference_ext_ioctl(struct drm_device *dev,
1333 void *data,
1334 struct drm_file *file_priv);
1335
1336int vmw_gb_surface_define(struct vmw_private *dev_priv,
1337 uint32_t user_accounting_size,
1338 const struct vmw_surface_metadata *req,
1339 struct vmw_surface **srf_out);
1340
1341
1342
1343
1344
1345extern const struct vmw_user_resource_conv *user_shader_converter;
1346
1347extern int vmw_shader_define_ioctl(struct drm_device *dev, void *data,
1348 struct drm_file *file_priv);
1349extern int vmw_shader_destroy_ioctl(struct drm_device *dev, void *data,
1350 struct drm_file *file_priv);
1351extern int vmw_compat_shader_add(struct vmw_private *dev_priv,
1352 struct vmw_cmdbuf_res_manager *man,
1353 u32 user_key, const void *bytecode,
1354 SVGA3dShaderType shader_type,
1355 size_t size,
1356 struct list_head *list);
1357extern int vmw_shader_remove(struct vmw_cmdbuf_res_manager *man,
1358 u32 user_key, SVGA3dShaderType shader_type,
1359 struct list_head *list);
1360extern int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,
1361 struct vmw_resource *ctx,
1362 u32 user_key,
1363 SVGA3dShaderType shader_type,
1364 struct list_head *list);
1365extern void vmw_dx_shader_cotable_list_scrub(struct vmw_private *dev_priv,
1366 struct list_head *list,
1367 bool readback);
1368
1369extern struct vmw_resource *
1370vmw_shader_lookup(struct vmw_cmdbuf_res_manager *man,
1371 u32 user_key, SVGA3dShaderType shader_type);
1372
1373
1374
1375
1376struct vmw_resource *
1377vmw_dx_streamoutput_lookup(struct vmw_cmdbuf_res_manager *man,
1378 u32 user_key);
1379int vmw_dx_streamoutput_add(struct vmw_cmdbuf_res_manager *man,
1380 struct vmw_resource *ctx,
1381 SVGA3dStreamOutputId user_key,
1382 struct list_head *list);
1383void vmw_dx_streamoutput_set_size(struct vmw_resource *res, u32 size);
1384int vmw_dx_streamoutput_remove(struct vmw_cmdbuf_res_manager *man,
1385 SVGA3dStreamOutputId user_key,
1386 struct list_head *list);
1387void vmw_dx_streamoutput_cotable_list_scrub(struct vmw_private *dev_priv,
1388 struct list_head *list,
1389 bool readback);
1390
1391
1392
1393
1394
1395extern struct vmw_cmdbuf_res_manager *
1396vmw_cmdbuf_res_man_create(struct vmw_private *dev_priv);
1397extern void vmw_cmdbuf_res_man_destroy(struct vmw_cmdbuf_res_manager *man);
1398extern size_t vmw_cmdbuf_res_man_size(void);
1399extern struct vmw_resource *
1400vmw_cmdbuf_res_lookup(struct vmw_cmdbuf_res_manager *man,
1401 enum vmw_cmdbuf_res_type res_type,
1402 u32 user_key);
1403extern void vmw_cmdbuf_res_revert(struct list_head *list);
1404extern void vmw_cmdbuf_res_commit(struct list_head *list);
1405extern int vmw_cmdbuf_res_add(struct vmw_cmdbuf_res_manager *man,
1406 enum vmw_cmdbuf_res_type res_type,
1407 u32 user_key,
1408 struct vmw_resource *res,
1409 struct list_head *list);
1410extern int vmw_cmdbuf_res_remove(struct vmw_cmdbuf_res_manager *man,
1411 enum vmw_cmdbuf_res_type res_type,
1412 u32 user_key,
1413 struct list_head *list,
1414 struct vmw_resource **res);
1415
1416
1417
1418
1419extern const SVGACOTableType vmw_cotable_scrub_order[];
1420extern struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv,
1421 struct vmw_resource *ctx,
1422 u32 type);
1423extern int vmw_cotable_notify(struct vmw_resource *res, int id);
1424extern int vmw_cotable_scrub(struct vmw_resource *res, bool readback);
1425extern void vmw_cotable_add_resource(struct vmw_resource *ctx,
1426 struct list_head *head);
1427
1428
1429
1430
1431struct vmw_cmdbuf_man;
1432struct vmw_cmdbuf_header;
1433
1434extern struct vmw_cmdbuf_man *
1435vmw_cmdbuf_man_create(struct vmw_private *dev_priv);
1436extern int vmw_cmdbuf_set_pool_size(struct vmw_cmdbuf_man *man, size_t size);
1437extern void vmw_cmdbuf_remove_pool(struct vmw_cmdbuf_man *man);
1438extern void vmw_cmdbuf_man_destroy(struct vmw_cmdbuf_man *man);
1439extern int vmw_cmdbuf_idle(struct vmw_cmdbuf_man *man, bool interruptible,
1440 unsigned long timeout);
1441extern void *vmw_cmdbuf_reserve(struct vmw_cmdbuf_man *man, size_t size,
1442 int ctx_id, bool interruptible,
1443 struct vmw_cmdbuf_header *header);
1444extern void vmw_cmdbuf_commit(struct vmw_cmdbuf_man *man, size_t size,
1445 struct vmw_cmdbuf_header *header,
1446 bool flush);
1447extern void *vmw_cmdbuf_alloc(struct vmw_cmdbuf_man *man,
1448 size_t size, bool interruptible,
1449 struct vmw_cmdbuf_header **p_header);
1450extern void vmw_cmdbuf_header_free(struct vmw_cmdbuf_header *header);
1451extern int vmw_cmdbuf_cur_flush(struct vmw_cmdbuf_man *man,
1452 bool interruptible);
1453extern void vmw_cmdbuf_irqthread(struct vmw_cmdbuf_man *man);
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466struct vmw_diff_cpy {
1467 struct drm_rect rect;
1468 size_t line;
1469 size_t line_offset;
1470 int cpp;
1471 void (*do_cpy)(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src,
1472 size_t n);
1473};
1474
1475#define VMW_CPU_BLIT_INITIALIZER { \
1476 .do_cpy = vmw_memcpy, \
1477}
1478
1479#define VMW_CPU_BLIT_DIFF_INITIALIZER(_cpp) { \
1480 .line = 0, \
1481 .line_offset = 0, \
1482 .rect = { .x1 = INT_MAX/2, \
1483 .y1 = INT_MAX/2, \
1484 .x2 = INT_MIN/2, \
1485 .y2 = INT_MIN/2 \
1486 }, \
1487 .cpp = _cpp, \
1488 .do_cpy = vmw_diff_memcpy, \
1489}
1490
1491void vmw_diff_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src,
1492 size_t n);
1493
1494void vmw_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src, size_t n);
1495
1496int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
1497 u32 dst_offset, u32 dst_stride,
1498 struct ttm_buffer_object *src,
1499 u32 src_offset, u32 src_stride,
1500 u32 w, u32 h,
1501 struct vmw_diff_cpy *diff);
1502
1503
1504int vmw_host_get_guestinfo(const char *guest_info_param,
1505 char *buffer, size_t *length);
1506__printf(1, 2) int vmw_host_printf(const char *fmt, ...);
1507int vmw_msg_ioctl(struct drm_device *dev, void *data,
1508 struct drm_file *file_priv);
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521#define VMW_DEBUG_USER(fmt, ...) \
1522 DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__)
1523
1524
1525void vmw_bo_dirty_scan(struct vmw_buffer_object *vbo);
1526int vmw_bo_dirty_add(struct vmw_buffer_object *vbo);
1527void vmw_bo_dirty_transfer_to_res(struct vmw_resource *res);
1528void vmw_bo_dirty_clear_res(struct vmw_resource *res);
1529void vmw_bo_dirty_release(struct vmw_buffer_object *vbo);
1530void vmw_bo_dirty_unmap(struct vmw_buffer_object *vbo,
1531 pgoff_t start, pgoff_t end);
1532vm_fault_t vmw_bo_vm_fault(struct vm_fault *vmf);
1533vm_fault_t vmw_bo_vm_mkwrite(struct vm_fault *vmf);
1534
1535
1536
1537
1538
1539
1540
1541#define VMW_DEBUG_KMS(fmt, ...) \
1542 DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__)
1543
1544
1545
1546
1547
1548static inline void vmw_surface_unreference(struct vmw_surface **srf)
1549{
1550 struct vmw_surface *tmp_srf = *srf;
1551 struct vmw_resource *res = &tmp_srf->res;
1552 *srf = NULL;
1553
1554 vmw_resource_unreference(&res);
1555}
1556
1557static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
1558{
1559 (void) vmw_resource_reference(&srf->res);
1560 return srf;
1561}
1562
1563static inline void vmw_bo_unreference(struct vmw_buffer_object **buf)
1564{
1565 struct vmw_buffer_object *tmp_buf = *buf;
1566
1567 *buf = NULL;
1568 if (tmp_buf != NULL)
1569 ttm_bo_put(&tmp_buf->base);
1570}
1571
1572static inline struct vmw_buffer_object *
1573vmw_bo_reference(struct vmw_buffer_object *buf)
1574{
1575 ttm_bo_get(&buf->base);
1576 return buf;
1577}
1578
1579static inline struct ttm_mem_global *vmw_mem_glob(struct vmw_private *dev_priv)
1580{
1581 return &ttm_mem_glob;
1582}
1583
1584static inline void vmw_fifo_resource_inc(struct vmw_private *dev_priv)
1585{
1586 atomic_inc(&dev_priv->num_fifo_resources);
1587}
1588
1589static inline void vmw_fifo_resource_dec(struct vmw_private *dev_priv)
1590{
1591 atomic_dec(&dev_priv->num_fifo_resources);
1592}
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602static inline u32 vmw_fifo_mem_read(struct vmw_private *vmw, uint32 fifo_reg)
1603{
1604 BUG_ON(vmw_is_svga_v3(vmw));
1605 return READ_ONCE(*(vmw->fifo_mem + fifo_reg));
1606}
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616static inline void vmw_fifo_mem_write(struct vmw_private *vmw, u32 fifo_reg,
1617 u32 value)
1618{
1619 BUG_ON(vmw_is_svga_v3(vmw));
1620 WRITE_ONCE(*(vmw->fifo_mem + fifo_reg), value);
1621}
1622
1623static inline u32 vmw_fence_read(struct vmw_private *dev_priv)
1624{
1625 u32 fence;
1626 if (vmw_is_svga_v3(dev_priv))
1627 fence = vmw_read(dev_priv, SVGA_REG_FENCE);
1628 else
1629 fence = vmw_fifo_mem_read(dev_priv, SVGA_FIFO_FENCE);
1630 return fence;
1631}
1632
1633static inline void vmw_fence_write(struct vmw_private *dev_priv,
1634 u32 fence)
1635{
1636 BUG_ON(vmw_is_svga_v3(dev_priv));
1637 vmw_fifo_mem_write(dev_priv, SVGA_FIFO_FENCE, fence);
1638}
1639
1640static inline u32 vmw_irq_status_read(struct vmw_private *vmw)
1641{
1642 u32 status;
1643 if (vmw_is_svga_v3(vmw))
1644 status = vmw_read(vmw, SVGA_REG_IRQ_STATUS);
1645 else
1646 status = inl(vmw->io_start + SVGA_IRQSTATUS_PORT);
1647 return status;
1648}
1649
1650static inline void vmw_irq_status_write(struct vmw_private *vmw,
1651 uint32 status)
1652{
1653 if (vmw_is_svga_v3(vmw))
1654 vmw_write(vmw, SVGA_REG_IRQ_STATUS, status);
1655 else
1656 outl(status, vmw->io_start + SVGA_IRQSTATUS_PORT);
1657}
1658
1659#endif
1660