forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-11 04dd17822334871b23ea2862f7798fb0e0007777
kernel/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
....@@ -28,26 +28,38 @@
2828 #ifndef _VMWGFX_DRV_H_
2929 #define _VMWGFX_DRV_H_
3030
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>
3631 #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"
4332 #include <linux/sync_file.h>
4433
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
+#include <drm/ttm/ttm_module.h>
43
+
44
+#include "ttm_lock.h"
45
+#include "ttm_object.h"
46
+
47
+#include "vmwgfx_fence.h"
48
+#include "vmwgfx_reg.h"
49
+#include "vmwgfx_validation.h"
50
+
51
+/*
52
+ * FIXME: vmwgfx_drm.h needs to be last due to dependencies.
53
+ * uapi headers should not depend on header files outside uapi/.
54
+ */
55
+#include <drm/vmwgfx_drm.h>
56
+
57
+
4558 #define VMWGFX_DRIVER_NAME "vmwgfx"
46
-#define VMWGFX_DRIVER_DATE "20180704"
59
+#define VMWGFX_DRIVER_DATE "20200114"
4760 #define VMWGFX_DRIVER_MAJOR 2
48
-#define VMWGFX_DRIVER_MINOR 15
61
+#define VMWGFX_DRIVER_MINOR 18
4962 #define VMWGFX_DRIVER_PATCHLEVEL 0
50
-#define VMWGFX_FILE_PAGE_OFFSET 0x00100000
5163 #define VMWGFX_FIFO_STATIC_SIZE (1024*1024)
5264 #define VMWGFX_MAX_RELOCATIONS 2048
5365 #define VMWGFX_MAX_VALIDATIONS 2048
....@@ -70,9 +82,7 @@
7082 VMWGFX_NUM_GB_SCREEN_TARGET)
7183
7284 #define VMW_PL_GMR (TTM_PL_PRIV + 0)
73
-#define VMW_PL_FLAG_GMR (TTM_PL_FLAG_PRIV << 0)
7485 #define VMW_PL_MOB (TTM_PL_PRIV + 1)
75
-#define VMW_PL_FLAG_MOB (TTM_PL_FLAG_PRIV << 1)
7686
7787 #define VMW_RES_CONTEXT ttm_driver_type0
7888 #define VMW_RES_SURFACE ttm_driver_type1
....@@ -81,19 +91,33 @@
8191 #define VMW_RES_SHADER ttm_driver_type4
8292
8393 struct vmw_fpriv {
84
- struct drm_master *locked_master;
8594 struct ttm_object_file *tfile;
8695 bool gb_aware; /* user-space is guest-backed aware */
8796 };
8897
98
+/**
99
+ * struct vmw_buffer_object - TTM buffer object with vmwgfx additions
100
+ * @base: The TTM buffer object
101
+ * @res_tree: RB tree of resources using this buffer object as a backing MOB
102
+ * @pin_count: pin depth
103
+ * @cpu_writers: Number of synccpu write grabs. Protected by reservation when
104
+ * increased. May be decreased without reservation.
105
+ * @dx_query_ctx: DX context if this buffer object is used as a DX query MOB
106
+ * @map: Kmap object for semi-persistent mappings
107
+ * @res_prios: Eviction priority counts for attached resources
108
+ * @dirty: structure for user-space dirty-tracking
109
+ */
89110 struct vmw_buffer_object {
90111 struct ttm_buffer_object base;
91
- struct list_head res_list;
112
+ struct rb_root res_tree;
92113 s32 pin_count;
114
+ atomic_t cpu_writers;
93115 /* Not ref-counted. Protected by binding_mutex */
94116 struct vmw_resource *dx_query_ctx;
95117 /* Protected by reservation */
96118 struct ttm_bo_kmap_obj map;
119
+ u32 res_prios[TTM_MAX_BO_PRIORITY];
120
+ struct vmw_bo_dirty *dirty;
97121 };
98122
99123 /**
....@@ -112,21 +136,54 @@
112136 };
113137
114138 struct vmw_res_func;
139
+
140
+
141
+/**
142
+ * struct vmw-resource - base class for hardware resources
143
+ *
144
+ * @kref: For refcounting.
145
+ * @dev_priv: Pointer to the device private for this resource. Immutable.
146
+ * @id: Device id. Protected by @dev_priv::resource_lock.
147
+ * @backup_size: Backup buffer size. Immutable.
148
+ * @res_dirty: Resource contains data not yet in the backup buffer. Protected
149
+ * by resource reserved.
150
+ * @backup_dirty: Backup buffer contains data not yet in the HW resource.
151
+ * Protected by resource reserved.
152
+ * @coherent: Emulate coherency by tracking vm accesses.
153
+ * @backup: The backup buffer if any. Protected by resource reserved.
154
+ * @backup_offset: Offset into the backup buffer if any. Protected by resource
155
+ * reserved. Note that only a few resource types can have a @backup_offset
156
+ * different from zero.
157
+ * @pin_count: The pin count for this resource. A pinned resource has a
158
+ * pin-count greater than zero. It is not on the resource LRU lists and its
159
+ * backup buffer is pinned. Hence it can't be evicted.
160
+ * @func: Method vtable for this resource. Immutable.
161
+ * @mob_node; Node for the MOB backup rbtree. Protected by @backup reserved.
162
+ * @lru_head: List head for the LRU list. Protected by @dev_priv::resource_lock.
163
+ * @binding_head: List head for the context binding list. Protected by
164
+ * the @dev_priv::binding_mutex
165
+ * @res_free: The resource destructor.
166
+ * @hw_destroy: Callback to destroy the resource on the device, as part of
167
+ * resource destruction.
168
+ */
169
+struct vmw_resource_dirty;
115170 struct vmw_resource {
116171 struct kref kref;
117172 struct vmw_private *dev_priv;
118173 int id;
119
- bool avail;
174
+ u32 used_prio;
120175 unsigned long backup_size;
121
- bool res_dirty; /* Protected by backup buffer reserved */
122
- bool backup_dirty; /* Protected by backup buffer reserved */
176
+ u32 res_dirty : 1;
177
+ u32 backup_dirty : 1;
178
+ u32 coherent : 1;
123179 struct vmw_buffer_object *backup;
124180 unsigned long backup_offset;
125
- unsigned long pin_count; /* Protected by resource reserved */
181
+ unsigned long pin_count;
126182 const struct vmw_res_func *func;
127
- struct list_head lru_head; /* Protected by the resource lock */
128
- struct list_head mob_head; /* Protected by @backup reserved */
129
- struct list_head binding_head; /* Protected by binding_mutex */
183
+ struct rb_node mob_node;
184
+ struct list_head lru_head;
185
+ struct list_head binding_head;
186
+ struct vmw_resource_dirty *dirty;
130187 void (*res_free) (struct vmw_resource *res);
131188 void (*hw_destroy) (struct vmw_resource *res);
132189 };
....@@ -143,6 +200,7 @@
143200 vmw_res_dx_context,
144201 vmw_res_cotable,
145202 vmw_res_view,
203
+ vmw_res_streamoutput,
146204 vmw_res_max
147205 };
148206
....@@ -151,7 +209,8 @@
151209 */
152210 enum vmw_cmdbuf_res_type {
153211 vmw_cmdbuf_res_shader,
154
- vmw_cmdbuf_res_view
212
+ vmw_cmdbuf_res_view,
213
+ vmw_cmdbuf_res_streamoutput
155214 };
156215
157216 struct vmw_cmdbuf_res_manager;
....@@ -164,24 +223,58 @@
164223 struct vmw_framebuffer;
165224 struct vmw_surface_offset;
166225
167
-struct vmw_surface {
168
- struct vmw_resource res;
169
- SVGA3dSurfaceAllFlags flags;
170
- uint32_t format;
171
- uint32_t mip_levels[DRM_VMW_MAX_SURFACE_FACES];
226
+/**
227
+ * struct vmw_surface_metadata - Metadata describing a surface.
228
+ *
229
+ * @flags: Device flags.
230
+ * @format: Surface SVGA3D_x format.
231
+ * @mip_levels: Mip level for each face. For GB first index is used only.
232
+ * @multisample_count: Sample count.
233
+ * @multisample_pattern: Sample patterns.
234
+ * @quality_level: Quality level.
235
+ * @autogen_filter: Filter for automatically generated mipmaps.
236
+ * @array_size: Number of array elements for a 1D/2D texture. For cubemap
237
+ texture number of faces * array_size. This should be 0 for pre
238
+ SM4 device.
239
+ * @buffer_byte_stride: Buffer byte stride.
240
+ * @num_sizes: Size of @sizes. For GB surface this should always be 1.
241
+ * @base_size: Surface dimension.
242
+ * @sizes: Array representing mip sizes. Legacy only.
243
+ * @scanout: Whether this surface will be used for scanout.
244
+ *
245
+ * This tracks metadata for both legacy and guest backed surface.
246
+ */
247
+struct 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;
172258 struct drm_vmw_size base_size;
173259 struct drm_vmw_size *sizes;
174
- uint32_t num_sizes;
175260 bool scanout;
176
- uint32_t array_size;
177
- /* TODO so far just a extra pointer */
261
+};
262
+
263
+/**
264
+ * struct vmw_surface: Resource structure for a surface.
265
+ *
266
+ * @res: The base resource for this surface.
267
+ * @metadata: Metadata for this surface resource.
268
+ * @snooper: Cursor data. Legacy surface only.
269
+ * @offsets: Legacy surface only.
270
+ * @view_list: List of views bound to this surface.
271
+ */
272
+struct vmw_surface {
273
+ struct vmw_resource res;
274
+ struct vmw_surface_metadata metadata;
178275 struct vmw_cursor_snooper snooper;
179276 struct vmw_surface_offset *offsets;
180
- SVGA3dTextureFilter autogen_filter;
181
- uint32_t multisample_count;
182277 struct list_head view_list;
183
- SVGA3dMSPattern multisample_pattern;
184
- SVGA3dMSQualityLevel quality_level;
185278 };
186279
187280 struct vmw_marker_queue {
....@@ -204,29 +297,24 @@
204297 bool dx;
205298 };
206299
207
-struct vmw_relocation {
208
- SVGAMobId *mob_loc;
209
- SVGAGuestPtr *location;
210
- uint32_t index;
211
-};
212
-
213300 /**
214301 * struct vmw_res_cache_entry - resource information cache entry
215
- *
302
+ * @handle: User-space handle of a resource.
303
+ * @res: Non-ref-counted pointer to the resource.
304
+ * @valid_handle: Whether the @handle member is valid.
216305 * @valid: Whether the entry is valid, which also implies that the execbuf
217306 * code holds a reference to the resource, and it's placed on the
218307 * validation list.
219
- * @handle: User-space handle of a resource.
220
- * @res: Non-ref-counted pointer to the resource.
221308 *
222309 * Used to avoid frequent repeated user-space handle lookups of the
223310 * same resource.
224311 */
225312 struct vmw_res_cache_entry {
226
- bool valid;
227313 uint32_t handle;
228314 struct vmw_resource *res;
229
- struct vmw_resource_val_node *node;
315
+ void *private;
316
+ unsigned short valid_handle;
317
+ unsigned short valid;
230318 };
231319
232320 /**
....@@ -273,7 +361,7 @@
273361 struct vmw_piter {
274362 struct page **pages;
275363 const dma_addr_t *addrs;
276
- struct sg_page_iter iter;
364
+ struct sg_dma_page_iter iter;
277365 unsigned long i;
278366 unsigned long num_pages;
279367 bool (*next)(struct vmw_piter *);
....@@ -291,43 +379,67 @@
291379 vmw_du_screen_target
292380 };
293381
382
+struct vmw_validation_context;
383
+struct vmw_ctx_validation_info;
294384
385
+/**
386
+ * struct vmw_sw_context - Command submission context
387
+ * @res_ht: Pointer hash table used to find validation duplicates
388
+ * @kernel: Whether the command buffer originates from kernel code rather
389
+ * than from user-space
390
+ * @fp: If @kernel is false, points to the file of the client. Otherwise
391
+ * NULL
392
+ * @cmd_bounce: Command bounce buffer used for command validation before
393
+ * copying to fifo space
394
+ * @cmd_bounce_size: Current command bounce buffer size
395
+ * @cur_query_bo: Current buffer object used as query result buffer
396
+ * @bo_relocations: List of buffer object relocations
397
+ * @res_relocations: List of resource relocations
398
+ * @buf_start: Pointer to start of memory where command validation takes
399
+ * place
400
+ * @res_cache: Cache of recently looked up resources
401
+ * @last_query_ctx: Last context that submitted a query
402
+ * @needs_post_query_barrier: Whether a query barrier is needed after
403
+ * command submission
404
+ * @staged_bindings: Cached per-context binding tracker
405
+ * @staged_bindings_inuse: Whether the cached per-context binding tracker
406
+ * is in use
407
+ * @staged_cmd_res: List of staged command buffer managed resources in this
408
+ * command buffer
409
+ * @ctx_list: List of context resources referenced in this command buffer
410
+ * @dx_ctx_node: Validation metadata of the current DX context
411
+ * @dx_query_mob: The MOB used for DX queries
412
+ * @dx_query_ctx: The DX context used for the last DX query
413
+ * @man: Pointer to the command buffer managed resource manager
414
+ * @ctx: The validation context
415
+ */
295416 struct vmw_sw_context{
296417 struct drm_open_hash res_ht;
297418 bool res_ht_initialized;
298
- bool kernel; /**< is the called made from the kernel */
419
+ bool kernel;
299420 struct vmw_fpriv *fp;
300
- struct list_head validate_nodes;
301
- struct vmw_relocation relocs[VMWGFX_MAX_RELOCATIONS];
302
- uint32_t cur_reloc;
303
- struct vmw_validate_buffer val_bufs[VMWGFX_MAX_VALIDATIONS];
304
- uint32_t cur_val_buf;
305421 uint32_t *cmd_bounce;
306422 uint32_t cmd_bounce_size;
307
- struct list_head resource_list;
308
- struct list_head ctx_resource_list; /* For contexts and cotables */
309423 struct vmw_buffer_object *cur_query_bo;
424
+ struct list_head bo_relocations;
310425 struct list_head res_relocations;
311426 uint32_t *buf_start;
312427 struct vmw_res_cache_entry res_cache[vmw_res_max];
313428 struct vmw_resource *last_query_ctx;
314429 bool needs_post_query_barrier;
315
- struct vmw_resource *error_resource;
316430 struct vmw_ctx_binding_state *staged_bindings;
317431 bool staged_bindings_inuse;
318432 struct list_head staged_cmd_res;
319
- struct vmw_resource_val_node *dx_ctx_node;
433
+ struct list_head ctx_list;
434
+ struct vmw_ctx_validation_info *dx_ctx_node;
320435 struct vmw_buffer_object *dx_query_mob;
321436 struct vmw_resource *dx_query_ctx;
322437 struct vmw_cmdbuf_res_manager *man;
438
+ struct vmw_validation_context *ctx;
323439 };
324440
325441 struct vmw_legacy_display;
326442 struct vmw_overlay;
327
-
328
-struct vmw_master {
329
- struct ttm_lock lock;
330
-};
331443
332444 struct vmw_vga_topology_state {
333445 uint32_t width;
....@@ -363,14 +475,29 @@
363475 VMW_IRQTHREAD_MAX
364476 };
365477
478
+/**
479
+ * enum vmw_sm_type - Graphics context capability supported by device.
480
+ * @VMW_SM_LEGACY: Pre DX context.
481
+ * @VMW_SM_4: Context support upto SM4.
482
+ * @VMW_SM_4_1: Context support upto SM4_1.
483
+ * @VMW_SM_5: Context support up to SM5.
484
+ * @VMW_SM_MAX: Should be the last.
485
+ */
486
+enum vmw_sm_type {
487
+ VMW_SM_LEGACY = 0,
488
+ VMW_SM_4,
489
+ VMW_SM_4_1,
490
+ VMW_SM_5,
491
+ VMW_SM_MAX
492
+};
493
+
366494 struct vmw_private {
367495 struct ttm_bo_device bdev;
368
- struct ttm_bo_global_ref bo_global_ref;
369
- struct drm_global_reference mem_global_ref;
370496
371497 struct vmw_fifo_state fifo;
372498
373499 struct drm_device *dev;
500
+ struct drm_vma_offset_manager vma_manager;
374501 unsigned long vmw_chipset;
375502 unsigned int io_start;
376503 uint32_t vram_start;
....@@ -398,31 +525,9 @@
398525 bool has_mob;
399526 spinlock_t hw_lock;
400527 spinlock_t cap_lock;
401
- bool has_dx;
402528 bool assume_16bpp;
403
- bool has_sm4_1;
404529
405
- /*
406
- * VGA registers.
407
- */
408
-
409
- struct vmw_vga_topology_state vga_save[VMWGFX_MAX_DISPLAYS];
410
- uint32_t vga_width;
411
- uint32_t vga_height;
412
- uint32_t vga_bpp;
413
- uint32_t vga_bpl;
414
- uint32_t vga_pitchlock;
415
-
416
- uint32_t num_displays;
417
-
418
- /*
419
- * Currently requested_layout_mutex is used to protect the gui
420
- * positionig state in display unit. With that use case currently this
421
- * mutex is only taken during layout ioctl and atomic check_modeset.
422
- * Other display unit state can be protected with this mutex but that
423
- * needs careful consideration.
424
- */
425
- struct mutex requested_layout_mutex;
530
+ enum vmw_sm_type sm_type;
426531
427532 /*
428533 * Framebuffer info.
....@@ -434,8 +539,6 @@
434539 struct vmw_overlay *overlay_priv;
435540 struct drm_property *hotplug_mode_update_property;
436541 struct drm_property *implicit_placement_property;
437
- unsigned num_implicit;
438
- struct vmw_framebuffer *implicit_fb;
439542 struct mutex global_kms_state_mutex;
440543 spinlock_t cursor_lock;
441544 struct drm_atomic_state *suspend_state;
....@@ -444,13 +547,8 @@
444547 * Context and surface management.
445548 */
446549
447
- rwlock_t resource_lock;
550
+ spinlock_t resource_lock;
448551 struct idr res_idr[vmw_res_max];
449
- /*
450
- * Block lastclose from racing with firstopen.
451
- */
452
-
453
- struct mutex init_mutex;
454552
455553 /*
456554 * A resource manager for kernel-only surfaces and
....@@ -504,11 +602,8 @@
504602 spinlock_t svga_lock;
505603
506604 /**
507
- * Master management.
605
+ * PM management.
508606 */
509
-
510
- struct vmw_master *active_master;
511
- struct vmw_master fbdev_master;
512607 struct notifier_block pm_nb;
513608 bool refuse_hibernation;
514609 bool suspend_locked;
....@@ -554,6 +649,9 @@
554649
555650 struct vmw_cmdbuf_man *cman;
556651 DECLARE_BITMAP(irqthread_pending, VMW_IRQTHREAD_MAX);
652
+
653
+ /* Validation memory reservation */
654
+ struct vmw_validation_mem vvm;
557655 };
558656
559657 static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res)
....@@ -569,11 +667,6 @@
569667 static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
570668 {
571669 return (struct vmw_fpriv *)file_priv->driver_priv;
572
-}
573
-
574
-static inline struct vmw_master *vmw_master(struct drm_master *master)
575
-{
576
- return (struct vmw_master *) master->driver_priv;
577670 }
578671
579672 /*
....@@ -605,6 +698,39 @@
605698 return val;
606699 }
607700
701
+/**
702
+ * has_sm4_context - Does the device support SM4 context.
703
+ * @dev_priv: Device private.
704
+ *
705
+ * Return: Bool value if device support SM4 context or not.
706
+ */
707
+static inline bool has_sm4_context(const struct vmw_private *dev_priv)
708
+{
709
+ return (dev_priv->sm_type >= VMW_SM_4);
710
+}
711
+
712
+/**
713
+ * has_sm4_1_context - Does the device support SM4_1 context.
714
+ * @dev_priv: Device private.
715
+ *
716
+ * Return: Bool value if device support SM4_1 context or not.
717
+ */
718
+static inline bool has_sm4_1_context(const struct vmw_private *dev_priv)
719
+{
720
+ return (dev_priv->sm_type >= VMW_SM_4_1);
721
+}
722
+
723
+/**
724
+ * has_sm5_context - Does the device support SM5 context.
725
+ * @dev_priv: Device private.
726
+ *
727
+ * Return: Bool value if device support SM5 context or not.
728
+ */
729
+static inline bool has_sm5_context(const struct vmw_private *dev_priv)
730
+{
731
+ return (dev_priv->sm_type >= VMW_SM_5);
732
+}
733
+
608734 extern void vmw_svga_enable(struct vmw_private *dev_priv);
609735 extern void vmw_svga_disable(struct vmw_private *dev_priv);
610736
....@@ -628,7 +754,8 @@
628754 extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
629755 extern struct vmw_resource *
630756 vmw_resource_reference_unless_doomed(struct vmw_resource *res);
631
-extern int vmw_resource_validate(struct vmw_resource *res);
757
+extern int vmw_resource_validate(struct vmw_resource *res, bool intr,
758
+ bool dirtying);
632759 extern int vmw_resource_reserve(struct vmw_resource *res, bool interruptible,
633760 bool no_backup);
634761 extern bool vmw_resource_needs_backup(const struct vmw_resource *res);
....@@ -643,6 +770,12 @@
643770 uint32_t handle,
644771 const struct vmw_user_resource_conv *converter,
645772 struct vmw_resource **p_res);
773
+extern struct vmw_resource *
774
+vmw_user_resource_noref_lookup_handle(struct vmw_private *dev_priv,
775
+ struct ttm_object_file *tfile,
776
+ uint32_t handle,
777
+ const struct vmw_user_resource_conv *
778
+ converter);
646779 extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
647780 struct drm_file *file_priv);
648781 extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
....@@ -652,14 +785,42 @@
652785 uint32_t *inout_id,
653786 struct vmw_resource **out);
654787 extern void vmw_resource_unreserve(struct vmw_resource *res,
788
+ bool dirty_set,
789
+ bool dirty,
655790 bool switch_backup,
656791 struct vmw_buffer_object *new_backup,
657792 unsigned long new_backup_offset);
658793 extern void vmw_query_move_notify(struct ttm_buffer_object *bo,
659
- struct ttm_mem_reg *mem);
794
+ struct ttm_resource *mem);
660795 extern int vmw_query_readback_all(struct vmw_buffer_object *dx_query_mob);
661796 extern void vmw_resource_evict_all(struct vmw_private *dev_priv);
662797 extern void vmw_resource_unbind_list(struct vmw_buffer_object *vbo);
798
+void vmw_resource_mob_attach(struct vmw_resource *res);
799
+void vmw_resource_mob_detach(struct vmw_resource *res);
800
+void vmw_resource_dirty_update(struct vmw_resource *res, pgoff_t start,
801
+ pgoff_t end);
802
+int vmw_resources_clean(struct vmw_buffer_object *vbo, pgoff_t start,
803
+ pgoff_t end, pgoff_t *num_prefault);
804
+
805
+/**
806
+ * vmw_resource_mob_attached - Whether a resource currently has a mob attached
807
+ * @res: The resource
808
+ *
809
+ * Return: true if the resource has a mob attached, false otherwise.
810
+ */
811
+static inline bool vmw_resource_mob_attached(const struct vmw_resource *res)
812
+{
813
+ return !RB_EMPTY_NODE(&res->mob_node);
814
+}
815
+
816
+/**
817
+ * vmw_user_resource_noref_release - release a user resource pointer looked up
818
+ * without reference
819
+ */
820
+static inline void vmw_user_resource_noref_release(void)
821
+{
822
+ ttm_base_object_noref_release();
823
+}
663824
664825 /**
665826 * Buffer object helper functions - vmwgfx_bo.c
....@@ -687,7 +848,7 @@
687848 extern int vmw_bo_init(struct vmw_private *dev_priv,
688849 struct vmw_buffer_object *vmw_bo,
689850 size_t size, struct ttm_placement *placement,
690
- bool interuptable,
851
+ bool interruptible,
691852 void (*bo_free)(struct ttm_buffer_object *bo));
692853 extern int vmw_user_bo_verify_access(struct ttm_buffer_object *bo,
693854 struct ttm_object_file *tfile);
....@@ -715,8 +876,68 @@
715876 extern void *vmw_bo_map_and_cache(struct vmw_buffer_object *vbo);
716877 extern void vmw_bo_unmap(struct vmw_buffer_object *vbo);
717878 extern void vmw_bo_move_notify(struct ttm_buffer_object *bo,
718
- struct ttm_mem_reg *mem);
879
+ struct ttm_resource *mem);
719880 extern void vmw_bo_swap_notify(struct ttm_buffer_object *bo);
881
+extern struct vmw_buffer_object *
882
+vmw_user_bo_noref_lookup(struct ttm_object_file *tfile, u32 handle);
883
+
884
+/**
885
+ * vmw_user_bo_noref_release - release a buffer object pointer looked up
886
+ * without reference
887
+ */
888
+static inline void vmw_user_bo_noref_release(void)
889
+{
890
+ ttm_base_object_noref_release();
891
+}
892
+
893
+/**
894
+ * vmw_bo_adjust_prio - Adjust the buffer object eviction priority
895
+ * according to attached resources
896
+ * @vbo: The struct vmw_buffer_object
897
+ */
898
+static inline void vmw_bo_prio_adjust(struct vmw_buffer_object *vbo)
899
+{
900
+ int i = ARRAY_SIZE(vbo->res_prios);
901
+
902
+ while (i--) {
903
+ if (vbo->res_prios[i]) {
904
+ vbo->base.priority = i;
905
+ return;
906
+ }
907
+ }
908
+
909
+ vbo->base.priority = 3;
910
+}
911
+
912
+/**
913
+ * vmw_bo_prio_add - Notify a buffer object of a newly attached resource
914
+ * eviction priority
915
+ * @vbo: The struct vmw_buffer_object
916
+ * @prio: The resource priority
917
+ *
918
+ * After being notified, the code assigns the highest resource eviction priority
919
+ * to the backing buffer object (mob).
920
+ */
921
+static inline void vmw_bo_prio_add(struct vmw_buffer_object *vbo, int prio)
922
+{
923
+ if (vbo->res_prios[prio]++ == 0)
924
+ vmw_bo_prio_adjust(vbo);
925
+}
926
+
927
+/**
928
+ * vmw_bo_prio_del - Notify a buffer object of a resource with a certain
929
+ * priority being removed
930
+ * @vbo: The struct vmw_buffer_object
931
+ * @prio: The resource priority
932
+ *
933
+ * After being notified, the code assigns the highest resource eviction priority
934
+ * to the backing buffer object (mob).
935
+ */
936
+static inline void vmw_bo_prio_del(struct vmw_buffer_object *vbo, int prio)
937
+{
938
+ if (--vbo->res_prios[prio] == 0)
939
+ vmw_bo_prio_adjust(vbo);
940
+}
720941
721942 /**
722943 * Misc Ioctl functionality - vmwgfx_ioctl.c
....@@ -743,14 +964,12 @@
743964 struct vmw_fifo_state *fifo);
744965 extern void vmw_fifo_release(struct vmw_private *dev_priv,
745966 struct vmw_fifo_state *fifo);
746
-extern void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes);
747967 extern void *
748968 vmw_fifo_reserve_dx(struct vmw_private *dev_priv, uint32_t bytes, int ctx_id);
749969 extern void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes);
750970 extern void vmw_fifo_commit_flush(struct vmw_private *dev_priv, uint32_t bytes);
751971 extern int vmw_fifo_send_fence(struct vmw_private *dev_priv,
752972 uint32_t *seqno);
753
-extern void vmw_fifo_ping_host_locked(struct vmw_private *, uint32_t reason);
754973 extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
755974 extern bool vmw_fifo_have_3d(struct vmw_private *dev_priv);
756975 extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv);
....@@ -759,13 +978,26 @@
759978 extern int vmw_fifo_flush(struct vmw_private *dev_priv,
760979 bool interruptible);
761980
981
+#define VMW_FIFO_RESERVE_DX(__priv, __bytes, __ctx_id) \
982
+({ \
983
+ vmw_fifo_reserve_dx(__priv, __bytes, __ctx_id) ? : ({ \
984
+ DRM_ERROR("FIFO reserve failed at %s for %u bytes\n", \
985
+ __func__, (unsigned int) __bytes); \
986
+ NULL; \
987
+ }); \
988
+})
989
+
990
+#define VMW_FIFO_RESERVE(__priv, __bytes) \
991
+ VMW_FIFO_RESERVE_DX(__priv, __bytes, SVGA3D_INVALID_ID)
992
+
762993 /**
763994 * TTM glue - vmwgfx_ttm_glue.c
764995 */
765996
766
-extern int vmw_ttm_global_init(struct vmw_private *dev_priv);
767
-extern void vmw_ttm_global_release(struct vmw_private *dev_priv);
768997 extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma);
998
+
999
+extern void vmw_validation_mem_init_ttm(struct vmw_private *dev_priv,
1000
+ size_t gran);
7691001
7701002 /**
7711003 * TTM buffer object driver - vmwgfx_ttm_buffer.c
....@@ -785,11 +1017,12 @@
7851017 extern struct ttm_placement vmw_mob_ne_placement;
7861018 extern struct ttm_placement vmw_nonfixed_placement;
7871019 extern struct ttm_bo_driver vmw_bo_driver;
788
-extern int vmw_dma_quiescent(struct drm_device *dev);
789
-extern int vmw_bo_map_dma(struct ttm_buffer_object *bo);
790
-extern void vmw_bo_unmap_dma(struct ttm_buffer_object *bo);
7911020 extern const struct vmw_sg_table *
7921021 vmw_bo_sg_table(struct ttm_buffer_object *bo);
1022
+extern int vmw_bo_create_and_populate(struct vmw_private *dev_priv,
1023
+ unsigned long bo_size,
1024
+ struct ttm_buffer_object **bo_p);
1025
+
7931026 extern void vmw_piter_start(struct vmw_piter *viter,
7941027 const struct vmw_sg_table *vsgt,
7951028 unsigned long p_offs);
....@@ -834,8 +1067,8 @@
8341067 * Command submission - vmwgfx_execbuf.c
8351068 */
8361069
837
-extern int vmw_execbuf_ioctl(struct drm_device *dev, unsigned long data,
838
- struct drm_file *file_priv, size_t size);
1070
+extern int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
1071
+ struct drm_file *file_priv);
8391072 extern int vmw_execbuf_process(struct drm_file *file_priv,
8401073 struct vmw_private *dev_priv,
8411074 void __user *user_commands,
....@@ -863,10 +1096,6 @@
8631096 struct vmw_fence_obj *fence,
8641097 uint32_t fence_handle,
8651098 int32_t out_fence_fd);
866
-extern int vmw_validate_single_buffer(struct vmw_private *dev_priv,
867
- struct ttm_buffer_object *bo,
868
- bool interruptible,
869
- bool validate_as_mob);
8701099 bool vmw_cmd_describe(const void *buf, u32 *size, char const **cmd);
8711100
8721101 /**
....@@ -926,8 +1155,6 @@
9261155
9271156 int vmw_kms_init(struct vmw_private *dev_priv);
9281157 int vmw_kms_close(struct vmw_private *dev_priv);
929
-int vmw_kms_save_vga(struct vmw_private *vmw_priv);
930
-int vmw_kms_restore_vga(struct vmw_private *vmw_priv);
9311158 int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
9321159 struct drm_file *file_priv);
9331160 void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
....@@ -938,13 +1165,12 @@
9381165 int vmw_kms_write_svga(struct vmw_private *vmw_priv,
9391166 unsigned width, unsigned height, unsigned pitch,
9401167 unsigned bpp, unsigned depth);
941
-void vmw_kms_idle_workqueues(struct vmw_master *vmaster);
9421168 bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
9431169 uint32_t pitch,
9441170 uint32_t height);
945
-u32 vmw_get_vblank_counter(struct drm_device *dev, unsigned int pipe);
946
-int vmw_enable_vblank(struct drm_device *dev, unsigned int pipe);
947
-void vmw_disable_vblank(struct drm_device *dev, unsigned int pipe);
1171
+u32 vmw_get_vblank_counter(struct drm_crtc *crtc);
1172
+int vmw_enable_vblank(struct drm_crtc *crtc);
1173
+void vmw_disable_vblank(struct drm_crtc *crtc);
9481174 int vmw_kms_present(struct vmw_private *dev_priv,
9491175 struct drm_file *file_priv,
9501176 struct vmw_framebuffer *vfb,
....@@ -981,7 +1207,6 @@
9811207 int vmw_overlay_close(struct vmw_private *dev_priv);
9821208 int vmw_overlay_ioctl(struct drm_device *dev, void *data,
9831209 struct drm_file *file_priv);
984
-int vmw_overlay_stop_all(struct vmw_private *dev_priv);
9851210 int vmw_overlay_resume_all(struct vmw_private *dev_priv);
9861211 int vmw_overlay_pause_all(struct vmw_private *dev_priv);
9871212 int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
....@@ -993,7 +1218,8 @@
9931218 * GMR Id manager
9941219 */
9951220
996
-extern const struct ttm_mem_type_manager_func vmw_gmrid_manager_func;
1221
+int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type);
1222
+void vmw_gmrid_man_fini(struct vmw_private *dev_priv, int type);
9971223
9981224 /**
9991225 * Prime - vmwgfx_prime.c
....@@ -1028,10 +1254,6 @@
10281254
10291255 extern const struct vmw_user_resource_conv *user_context_converter;
10301256
1031
-extern int vmw_context_check(struct vmw_private *dev_priv,
1032
- struct ttm_object_file *tfile,
1033
- int id,
1034
- struct vmw_resource **p_res);
10351257 extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
10361258 struct drm_file *file_priv);
10371259 extern int vmw_extended_context_define_ioctl(struct drm_device *dev, void *data,
....@@ -1061,7 +1283,6 @@
10611283
10621284 extern const struct vmw_user_resource_conv *user_surface_converter;
10631285
1064
-extern void vmw_surface_res_free(struct vmw_resource *res);
10651286 extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data,
10661287 struct drm_file *file_priv);
10671288 extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
....@@ -1072,11 +1293,6 @@
10721293 struct drm_file *file_priv);
10731294 extern int vmw_gb_surface_reference_ioctl(struct drm_device *dev, void *data,
10741295 struct drm_file *file_priv);
1075
-extern int vmw_surface_check(struct vmw_private *dev_priv,
1076
- struct ttm_object_file *tfile,
1077
- uint32_t handle, int *id);
1078
-extern int vmw_surface_validate(struct vmw_private *dev_priv,
1079
- struct vmw_surface *srf);
10801296 int vmw_surface_gb_priv_define(struct drm_device *dev,
10811297 uint32_t user_accounting_size,
10821298 SVGA3dSurfaceAllFlags svga3d_flags,
....@@ -1095,6 +1311,11 @@
10951311 extern int vmw_gb_surface_reference_ext_ioctl(struct drm_device *dev,
10961312 void *data,
10971313 struct drm_file *file_priv);
1314
+
1315
+int vmw_gb_surface_define(struct vmw_private *dev_priv,
1316
+ uint32_t user_accounting_size,
1317
+ const struct vmw_surface_metadata *req,
1318
+ struct vmw_surface **srf_out);
10981319
10991320 /*
11001321 * Shader management - vmwgfx_shader.c
....@@ -1127,6 +1348,24 @@
11271348 extern struct vmw_resource *
11281349 vmw_shader_lookup(struct vmw_cmdbuf_res_manager *man,
11291350 u32 user_key, SVGA3dShaderType shader_type);
1351
+
1352
+/*
1353
+ * Streamoutput management
1354
+ */
1355
+struct vmw_resource *
1356
+vmw_dx_streamoutput_lookup(struct vmw_cmdbuf_res_manager *man,
1357
+ u32 user_key);
1358
+int vmw_dx_streamoutput_add(struct vmw_cmdbuf_res_manager *man,
1359
+ struct vmw_resource *ctx,
1360
+ SVGA3dStreamOutputId user_key,
1361
+ struct list_head *list);
1362
+void vmw_dx_streamoutput_set_size(struct vmw_resource *res, u32 size);
1363
+int vmw_dx_streamoutput_remove(struct vmw_cmdbuf_res_manager *man,
1364
+ SVGA3dStreamOutputId user_key,
1365
+ struct list_head *list);
1366
+void vmw_dx_streamoutput_cotable_list_scrub(struct vmw_private *dev_priv,
1367
+ struct list_head *list,
1368
+ bool readback);
11301369
11311370 /*
11321371 * Command buffer managed resources - vmwgfx_cmdbuf_res.c
....@@ -1245,6 +1484,51 @@
12451484 int vmw_host_get_guestinfo(const char *guest_info_param,
12461485 char *buffer, size_t *length);
12471486 int vmw_host_log(const char *log);
1487
+int vmw_msg_ioctl(struct drm_device *dev, void *data,
1488
+ struct drm_file *file_priv);
1489
+
1490
+/* VMW logging */
1491
+
1492
+/**
1493
+ * VMW_DEBUG_USER - Debug output for user-space debugging.
1494
+ *
1495
+ * @fmt: printf() like format string.
1496
+ *
1497
+ * This macro is for logging user-space error and debugging messages for e.g.
1498
+ * command buffer execution errors due to malformed commands, invalid context,
1499
+ * etc.
1500
+ */
1501
+#define VMW_DEBUG_USER(fmt, ...) \
1502
+ DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__)
1503
+
1504
+/* Resource dirtying - vmwgfx_page_dirty.c */
1505
+void vmw_bo_dirty_scan(struct vmw_buffer_object *vbo);
1506
+int vmw_bo_dirty_add(struct vmw_buffer_object *vbo);
1507
+void vmw_bo_dirty_transfer_to_res(struct vmw_resource *res);
1508
+void vmw_bo_dirty_clear_res(struct vmw_resource *res);
1509
+void vmw_bo_dirty_release(struct vmw_buffer_object *vbo);
1510
+void vmw_bo_dirty_unmap(struct vmw_buffer_object *vbo,
1511
+ pgoff_t start, pgoff_t end);
1512
+vm_fault_t vmw_bo_vm_fault(struct vm_fault *vmf);
1513
+vm_fault_t vmw_bo_vm_mkwrite(struct vm_fault *vmf);
1514
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
1515
+vm_fault_t vmw_bo_vm_huge_fault(struct vm_fault *vmf,
1516
+ enum page_entry_size pe_size);
1517
+#endif
1518
+
1519
+/* Transparent hugepage support - vmwgfx_thp.c */
1520
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
1521
+extern int vmw_thp_init(struct vmw_private *dev_priv);
1522
+void vmw_thp_fini(struct vmw_private *dev_priv);
1523
+#endif
1524
+
1525
+/**
1526
+ * VMW_DEBUG_KMS - Debug output for kernel mode-setting
1527
+ *
1528
+ * This macro is for debugging vmwgfx mode-setting code.
1529
+ */
1530
+#define VMW_DEBUG_KMS(fmt, ...) \
1531
+ DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__)
12481532
12491533 /**
12501534 * Inline helper functions
....@@ -1271,23 +1555,20 @@
12711555
12721556 *buf = NULL;
12731557 if (tmp_buf != NULL) {
1274
- struct ttm_buffer_object *bo = &tmp_buf->base;
1275
-
1276
- ttm_bo_unref(&bo);
1558
+ ttm_bo_put(&tmp_buf->base);
12771559 }
12781560 }
12791561
12801562 static inline struct vmw_buffer_object *
12811563 vmw_bo_reference(struct vmw_buffer_object *buf)
12821564 {
1283
- if (ttm_bo_reference(&buf->base))
1284
- return buf;
1285
- return NULL;
1565
+ ttm_bo_get(&buf->base);
1566
+ return buf;
12861567 }
12871568
12881569 static inline struct ttm_mem_global *vmw_mem_glob(struct vmw_private *dev_priv)
12891570 {
1290
- return (struct ttm_mem_global *) dev_priv->mem_global_ref.object;
1571
+ return &ttm_mem_glob;
12911572 }
12921573
12931574 static inline void vmw_fifo_resource_inc(struct vmw_private *dev_priv)
....@@ -1325,4 +1606,17 @@
13251606 {
13261607 WRITE_ONCE(*addr, value);
13271608 }
1609
+
1610
+static inline bool vmw_shadertype_is_valid(enum vmw_sm_type shader_model,
1611
+ u32 shader_type)
1612
+{
1613
+ SVGA3dShaderType max_allowed = SVGA3D_SHADERTYPE_PREDX_MAX;
1614
+
1615
+ if (shader_model >= VMW_SM_5)
1616
+ max_allowed = SVGA3D_SHADERTYPE_MAX;
1617
+ else if (shader_model >= VMW_SM_4)
1618
+ max_allowed = SVGA3D_SHADERTYPE_DX10_MAX;
1619
+ return shader_type >= SVGA3D_SHADERTYPE_MIN && shader_type < max_allowed;
1620
+}
1621
+
13281622 #endif