blob: d6b66636a19b8327b2f661625630a9da5f629686 [file] [log] [blame]
Dirk Hohndel (VMware)dff96882018-05-07 01:16:26 +02001/* SPDX-License-Identifier: GPL-2.0 OR MIT */
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00002/**************************************************************************
3 *
Martin Krastev7a7a9332021-06-09 13:23:00 -04004 * Copyright 2009-2021 VMware, Inc., Palo Alto, CA., USA
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00005 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28#ifndef _VMWGFX_DRV_H_
29#define _VMWGFX_DRV_H_
30
David Howells760285e2012-10-02 18:01:07 +010031#include <linux/suspend.h>
Sam Ravnborgd5c1f012019-06-23 12:23:33 +020032#include <linux/sync_file.h>
33
34#include <drm/drm_auth.h>
35#include <drm/drm_device.h>
36#include <drm/drm_file.h>
Sam Ravnborgd5c1f012019-06-23 12:23:33 +020037#include <drm/drm_rect.h>
38
David Howells760285e2012-10-02 18:01:07 +010039#include <drm/ttm/ttm_bo_driver.h>
David Howells760285e2012-10-02 18:01:07 +010040#include <drm/ttm/ttm_execbuf_util.h>
Sam Ravnborgd5c1f012019-06-23 12:23:33 +020041
Sam Ravnborgd5c1f012019-06-23 12:23:33 +020042#include "ttm_object.h"
43
44#include "vmwgfx_fence.h"
Thomas Zimmermann2985c962021-11-29 10:48:40 +010045#include "vmwgfx_hashtab.h"
Sam Ravnborgd5c1f012019-06-23 12:23:33 +020046#include "vmwgfx_reg.h"
47#include "vmwgfx_validation.h"
48
49/*
50 * FIXME: vmwgfx_drm.h needs to be last due to dependencies.
51 * uapi headers should not depend on header files outside uapi/.
52 */
53#include <drm/vmwgfx_drm.h>
54
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000055
Thomas Hellstrome3001732017-08-24 08:06:27 +020056#define VMWGFX_DRIVER_NAME "vmwgfx"
Zack Rusin94eb7de2021-12-08 21:49:24 -050057#define VMWGFX_DRIVER_DATE "20211206"
Thomas Hellstrom2ae7b032011-09-01 20:18:45 +000058#define VMWGFX_DRIVER_MAJOR 2
Zack Rusin94eb7de2021-12-08 21:49:24 -050059#define VMWGFX_DRIVER_MINOR 20
Zack Rusinc29758c2021-07-23 12:51:53 -040060#define VMWGFX_DRIVER_PATCHLEVEL 0
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000061#define VMWGFX_FIFO_STATIC_SIZE (1024*1024)
Thomas Hellstrom7c4f7782010-06-01 11:38:17 +020062#define VMWGFX_MAX_DISPLAYS 16
Thomas Hellstrombe38ab62011-08-31 07:42:54 +000063#define VMWGFX_CMD_BOUNCE_INIT_SIZE 32768
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000064
Zack Rusin8772c0b2020-11-04 15:29:24 -050065#define VMWGFX_PCI_ID_SVGA2 0x0405
Zack Rusin2cd80db2021-05-05 15:10:07 -040066#define VMWGFX_PCI_ID_SVGA3 0x0406
Zack Rusin8772c0b2020-11-04 15:29:24 -050067
Thomas Hellstrom3530bdc2012-11-21 10:49:52 +010068/*
69 * Perhaps we should have sysfs entries for these.
70 */
71#define VMWGFX_NUM_GB_CONTEXT 256
72#define VMWGFX_NUM_GB_SHADER 20000
73#define VMWGFX_NUM_GB_SURFACE 32768
Thomas Hellstrom7cba9062014-01-09 11:03:18 +010074#define VMWGFX_NUM_GB_SCREEN_TARGET VMWGFX_MAX_DISPLAYS
Thomas Hellstromd80efd52015-08-10 10:39:35 -070075#define VMWGFX_NUM_DXCONTEXT 256
76#define VMWGFX_NUM_DXQUERY 512
Thomas Hellstrom3530bdc2012-11-21 10:49:52 +010077#define VMWGFX_NUM_MOB (VMWGFX_NUM_GB_CONTEXT +\
78 VMWGFX_NUM_GB_SHADER +\
Thomas Hellstrom7cba9062014-01-09 11:03:18 +010079 VMWGFX_NUM_GB_SURFACE +\
80 VMWGFX_NUM_GB_SCREEN_TARGET)
Thomas Hellstrom3530bdc2012-11-21 10:49:52 +010081
Zack Rusinf6be2322021-11-05 15:38:45 -040082#define VMW_PL_GMR (TTM_PL_PRIV + 0)
83#define VMW_PL_MOB (TTM_PL_PRIV + 1)
84#define VMW_PL_SYSTEM (TTM_PL_PRIV + 2)
Thomas Hellstrom135cba02010-10-26 21:21:47 +020085
Thomas Hellstromae2a1042011-09-01 20:18:44 +000086#define VMW_RES_CONTEXT ttm_driver_type0
87#define VMW_RES_SURFACE ttm_driver_type1
88#define VMW_RES_STREAM ttm_driver_type2
89#define VMW_RES_FENCE ttm_driver_type3
Thomas Hellstromc74c1622012-11-21 12:10:26 +010090#define VMW_RES_SHADER ttm_driver_type4
Thomas Hellstromae2a1042011-09-01 20:18:44 +000091
Martin Krastev7a7a9332021-06-09 13:23:00 -040092#define MKSSTAT_CAPACITY_LOG2 5U
93#define MKSSTAT_CAPACITY (1U << MKSSTAT_CAPACITY_LOG2)
94
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000095struct vmw_fpriv {
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000096 struct ttm_object_file *tfile;
Deepak Rawatf9261b32018-06-20 15:24:05 -070097 bool gb_aware; /* user-space is guest-backed aware */
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000098};
99
Thomas Hellstroma0a63942019-03-04 19:37:40 +0100100/**
101 * struct vmw_buffer_object - TTM buffer object with vmwgfx additions
102 * @base: The TTM buffer object
Thomas Hellstrom61335d72019-03-05 08:24:35 +0100103 * @res_tree: RB tree of resources using this buffer object as a backing MOB
Christian König7fb03cc2019-10-01 10:02:58 +0200104 * @cpu_writers: Number of synccpu write grabs. Protected by reservation when
105 * increased. May be decreased without reservation.
Thomas Hellstroma0a63942019-03-04 19:37:40 +0100106 * @dx_query_ctx: DX context if this buffer object is used as a DX query MOB
107 * @map: Kmap object for semi-persistent mappings
108 * @res_prios: Eviction priority counts for attached resources
Thomas Hellstromb7468b12019-03-27 10:56:08 +0100109 * @dirty: structure for user-space dirty-tracking
Thomas Hellstroma0a63942019-03-04 19:37:40 +0100110 */
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +0200111struct vmw_buffer_object {
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000112 struct ttm_buffer_object base;
Thomas Hellstrom61335d72019-03-05 08:24:35 +0100113 struct rb_root res_tree;
Christian König7fb03cc2019-10-01 10:02:58 +0200114 atomic_t cpu_writers;
Sinclair Yehfd11a3c2015-08-10 10:56:15 -0700115 /* Not ref-counted. Protected by binding_mutex */
116 struct vmw_resource *dx_query_ctx;
Thomas Hellstrombf833fd2018-03-22 10:19:01 +0100117 /* Protected by reservation */
118 struct ttm_bo_kmap_obj map;
Thomas Hellstroma0a63942019-03-04 19:37:40 +0100119 u32 res_prios[TTM_MAX_BO_PRIORITY];
Thomas Hellstromb7468b12019-03-27 10:56:08 +0100120 struct vmw_bo_dirty *dirty;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000121};
122
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000123/**
124 * struct vmw_validate_buffer - Carries validation info about buffers.
125 *
126 * @base: Validation info for TTM.
127 * @hash: Hash entry for quick lookup of the TTM buffer object.
128 *
129 * This structure contains also driver private validation info
130 * on top of the info needed by TTM.
131 */
132struct vmw_validate_buffer {
133 struct ttm_validate_buffer base;
Thomas Zimmermann2985c962021-11-29 10:48:40 +0100134 struct vmwgfx_hash_item hash;
Thomas Hellstrom96c5f0d2012-11-21 11:19:53 +0100135 bool validate_as_mob;
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000136};
137
138struct vmw_res_func;
Thomas Hellstrom13289242018-09-26 15:41:52 +0200139
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.
Thomas Hellstromb7468b12019-03-27 10:56:08 +0100151 * Protected by resource reserved.
152 * @coherent: Emulate coherency by tracking vm accesses.
Thomas Hellstrom13289242018-09-26 15:41:52 +0200153 * @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.
Thomas Hellstrom61335d72019-03-05 08:24:35 +0100161 * @mob_node; Node for the MOB backup rbtree. Protected by @backup reserved.
Thomas Hellstrom13289242018-09-26 15:41:52 +0200162 * @lru_head: List head for the LRU list. Protected by @dev_priv::resource_lock.
Thomas Hellstrom13289242018-09-26 15:41:52 +0200163 * @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 */
Thomas Hellstromb7468b12019-03-27 10:56:08 +0100169struct vmw_resource_dirty;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000170struct vmw_resource {
171 struct kref kref;
172 struct vmw_private *dev_priv;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000173 int id;
Thomas Hellstroma0a63942019-03-04 19:37:40 +0100174 u32 used_prio;
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000175 unsigned long backup_size;
Thomas Hellstromb7468b12019-03-27 10:56:08 +0100176 u32 res_dirty : 1;
177 u32 backup_dirty : 1;
178 u32 coherent : 1;
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +0200179 struct vmw_buffer_object *backup;
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000180 unsigned long backup_offset;
Thomas Hellstrom13289242018-09-26 15:41:52 +0200181 unsigned long pin_count;
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000182 const struct vmw_res_func *func;
Thomas Hellstrom61335d72019-03-05 08:24:35 +0100183 struct rb_node mob_node;
Thomas Hellstrom13289242018-09-26 15:41:52 +0200184 struct list_head lru_head;
Thomas Hellstrom13289242018-09-26 15:41:52 +0200185 struct list_head binding_head;
Thomas Hellstromb7468b12019-03-27 10:56:08 +0100186 struct vmw_resource_dirty *dirty;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000187 void (*res_free) (struct vmw_resource *res);
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000188 void (*hw_destroy) (struct vmw_resource *res);
189};
190
Thomas Hellstrom18e4a462014-06-09 12:39:22 +0200191
192/*
193 * Resources that are managed using ioctls.
194 */
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000195enum vmw_res_type {
196 vmw_res_context,
197 vmw_res_surface,
198 vmw_res_stream,
Thomas Hellstromc74c1622012-11-21 12:10:26 +0100199 vmw_res_shader,
Thomas Hellstromd80efd52015-08-10 10:39:35 -0700200 vmw_res_dx_context,
201 vmw_res_cotable,
202 vmw_res_view,
Deepak Rawate8bead92018-12-13 14:04:31 -0800203 vmw_res_streamoutput,
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000204 vmw_res_max
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000205};
206
Thomas Hellstrom18e4a462014-06-09 12:39:22 +0200207/*
208 * Resources that are managed using command streams.
209 */
210enum vmw_cmdbuf_res_type {
Thomas Hellstromd80efd52015-08-10 10:39:35 -0700211 vmw_cmdbuf_res_shader,
Deepak Rawate8bead92018-12-13 14:04:31 -0800212 vmw_cmdbuf_res_view,
213 vmw_cmdbuf_res_streamoutput
Thomas Hellstrom18e4a462014-06-09 12:39:22 +0200214};
215
216struct vmw_cmdbuf_res_manager;
217
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000218struct vmw_cursor_snooper {
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000219 size_t age;
220 uint32_t *image;
221};
222
Jakob Bornecrantz2fcd5a72011-10-04 20:13:26 +0200223struct vmw_framebuffer;
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +0200224struct vmw_surface_offset;
Jakob Bornecrantz2fcd5a72011-10-04 20:13:26 +0200225
Deepak Rawat26b82872019-04-29 11:42:45 -0700226/**
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.
Deepak Rawat2a50f062019-04-30 13:04:55 -0700239 * @buffer_byte_stride: Buffer byte stride.
Deepak Rawat26b82872019-04-29 11:42:45 -0700240 * @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 */
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;
Deepak Rawat2a50f062019-04-30 13:04:55 -0700257 u32 buffer_byte_stride;
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000258 struct drm_vmw_size base_size;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000259 struct drm_vmw_size *sizes;
Jakob Bornecrantz5ffdb652010-01-30 03:38:08 +0000260 bool scanout;
Deepak Rawat26b82872019-04-29 11:42:45 -0700261};
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 */
272struct vmw_surface {
273 struct vmw_resource res;
274 struct vmw_surface_metadata metadata;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000275 struct vmw_cursor_snooper snooper;
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +0200276 struct vmw_surface_offset *offsets;
Thomas Hellstromd80efd52015-08-10 10:39:35 -0700277 struct list_head view_list;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000278};
279
280struct vmw_fifo_state {
281 unsigned long reserved_size;
Thomas Hellstromb9eb1a62015-04-02 02:39:45 -0700282 u32 *dynamic_buffer;
283 u32 *static_buffer;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000284 unsigned long static_buffer_size;
285 bool using_bounce_buffer;
286 uint32_t capabilities;
Thomas Hellstrom85b9e482010-02-08 09:57:25 +0000287 struct mutex fifo_mutex;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000288 struct rw_semaphore rwsem;
289};
290
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000291/**
292 * struct vmw_res_cache_entry - resource information cache entry
Thomas Hellstrom9c079b82018-09-26 15:28:55 +0200293 * @handle: User-space handle of a resource.
294 * @res: Non-ref-counted pointer to the resource.
295 * @valid_handle: Whether the @handle member is valid.
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000296 * @valid: Whether the entry is valid, which also implies that the execbuf
297 * code holds a reference to the resource, and it's placed on the
298 * validation list.
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000299 *
300 * Used to avoid frequent repeated user-space handle lookups of the
301 * same resource.
302 */
303struct vmw_res_cache_entry {
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000304 uint32_t handle;
305 struct vmw_resource *res;
Thomas Hellstrom9c079b82018-09-26 15:28:55 +0200306 void *private;
307 unsigned short valid_handle;
308 unsigned short valid;
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000309};
310
Thomas Hellstromd92d9852013-10-24 01:49:26 -0700311/**
312 * enum vmw_dma_map_mode - indicate how to perform TTM page dma mappings.
313 */
314enum vmw_dma_map_mode {
Thomas Hellstromd92d9852013-10-24 01:49:26 -0700315 vmw_dma_alloc_coherent, /* Use TTM coherent pages */
316 vmw_dma_map_populate, /* Unmap from DMA just after unpopulate */
317 vmw_dma_map_bind, /* Unmap from DMA just before unbind */
318 vmw_dma_map_max
319};
320
321/**
322 * struct vmw_sg_table - Scatter/gather table for binding, with additional
323 * device-specific information.
324 *
325 * @sgt: Pointer to a struct sg_table with binding information
Masahiro Yamadae1c05062015-07-07 10:14:59 +0900326 * @num_regions: Number of regions with device-address contiguous pages
Thomas Hellstromd92d9852013-10-24 01:49:26 -0700327 */
328struct vmw_sg_table {
329 enum vmw_dma_map_mode mode;
330 struct page **pages;
331 const dma_addr_t *addrs;
332 struct sg_table *sgt;
Thomas Hellstromd92d9852013-10-24 01:49:26 -0700333 unsigned long num_pages;
334};
335
336/**
337 * struct vmw_piter - Page iterator that iterates over a list of pages
338 * and DMA addresses that could be either a scatter-gather list or
339 * arrays
340 *
341 * @pages: Array of page pointers to the pages.
342 * @addrs: DMA addresses to the pages if coherent pages are used.
343 * @iter: Scatter-gather page iterator. Current position in SG list.
344 * @i: Current position in arrays.
345 * @num_pages: Number of pages total.
346 * @next: Function to advance the iterator. Returns false if past the list
347 * of pages, true otherwise.
348 * @dma_address: Function to return the DMA address of the current page.
349 */
350struct vmw_piter {
351 struct page **pages;
352 const dma_addr_t *addrs;
Thomas Hellstrom8dc39cf2019-05-15 17:45:23 +0200353 struct sg_dma_page_iter iter;
Thomas Hellstromd92d9852013-10-24 01:49:26 -0700354 unsigned long i;
355 unsigned long num_pages;
356 bool (*next)(struct vmw_piter *);
357 dma_addr_t (*dma_address)(struct vmw_piter *);
Thomas Hellstromd92d9852013-10-24 01:49:26 -0700358};
359
Zack Rusin8afa13a2021-12-06 12:26:12 -0500360
361struct vmw_ttm_tt {
362 struct ttm_tt dma_ttm;
363 struct vmw_private *dev_priv;
364 int gmr_id;
365 struct vmw_mob *mob;
366 int mem_type;
367 struct sg_table sgt;
368 struct vmw_sg_table vsgt;
369 bool mapped;
370 bool bound;
371};
372
Thomas Hellstromb5c3b1a62013-10-08 02:27:17 -0700373/*
Sinclair Yehc8261a92015-06-26 01:23:42 -0700374 * enum vmw_display_unit_type - Describes the display unit
Thomas Hellstromb5c3b1a62013-10-08 02:27:17 -0700375 */
Sinclair Yehc8261a92015-06-26 01:23:42 -0700376enum vmw_display_unit_type {
377 vmw_du_invalid = 0,
378 vmw_du_legacy,
Sinclair Yeh35c05122015-06-26 01:42:06 -0700379 vmw_du_screen_object,
Zack Rusin2b273542021-07-23 12:51:51 -0400380 vmw_du_screen_target,
381 vmw_du_max
Thomas Hellstromb5c3b1a62013-10-08 02:27:17 -0700382};
383
Thomas Hellstrom9c079b82018-09-26 15:28:55 +0200384struct vmw_validation_context;
385struct vmw_ctx_validation_info;
Thomas Hellstromb5c3b1a62013-10-08 02:27:17 -0700386
Thomas Hellstrom9c079b82018-09-26 15:28:55 +0200387/**
388 * struct vmw_sw_context - Command submission context
389 * @res_ht: Pointer hash table used to find validation duplicates
390 * @kernel: Whether the command buffer originates from kernel code rather
391 * than from user-space
392 * @fp: If @kernel is false, points to the file of the client. Otherwise
393 * NULL
Thomas Hellstrom9c079b82018-09-26 15:28:55 +0200394 * @cmd_bounce: Command bounce buffer used for command validation before
395 * copying to fifo space
396 * @cmd_bounce_size: Current command bounce buffer size
397 * @cur_query_bo: Current buffer object used as query result buffer
Thomas Hellstromfc18afc2018-09-26 15:36:52 +0200398 * @bo_relocations: List of buffer object relocations
Thomas Hellstrom9c079b82018-09-26 15:28:55 +0200399 * @res_relocations: List of resource relocations
400 * @buf_start: Pointer to start of memory where command validation takes
401 * place
402 * @res_cache: Cache of recently looked up resources
403 * @last_query_ctx: Last context that submitted a query
404 * @needs_post_query_barrier: Whether a query barrier is needed after
405 * command submission
Thomas Hellstrom9c079b82018-09-26 15:28:55 +0200406 * @staged_bindings: Cached per-context binding tracker
407 * @staged_bindings_inuse: Whether the cached per-context binding tracker
408 * is in use
409 * @staged_cmd_res: List of staged command buffer managed resources in this
410 * command buffer
411 * @ctx_list: List of context resources referenced in this command buffer
412 * @dx_ctx_node: Validation metadata of the current DX context
413 * @dx_query_mob: The MOB used for DX queries
414 * @dx_query_ctx: The DX context used for the last DX query
415 * @man: Pointer to the command buffer managed resource manager
416 * @ctx: The validation context
417 */
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000418struct vmw_sw_context{
Thomas Zimmermann2985c962021-11-29 10:48:40 +0100419 struct vmwgfx_open_hash res_ht;
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000420 bool res_ht_initialized;
Thomas Hellstrom9c079b82018-09-26 15:28:55 +0200421 bool kernel;
Thomas Hellstromd5bde952014-01-31 10:12:10 +0100422 struct vmw_fpriv *fp;
Zack Rusin8afa13a2021-12-06 12:26:12 -0500423 struct drm_file *filp;
Thomas Hellstrombe38ab62011-08-31 07:42:54 +0000424 uint32_t *cmd_bounce;
425 uint32_t cmd_bounce_size;
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +0200426 struct vmw_buffer_object *cur_query_bo;
Thomas Hellstromfc18afc2018-09-26 15:36:52 +0200427 struct list_head bo_relocations;
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000428 struct list_head res_relocations;
429 uint32_t *buf_start;
430 struct vmw_res_cache_entry res_cache[vmw_res_max];
431 struct vmw_resource *last_query_ctx;
432 bool needs_post_query_barrier;
Thomas Hellstromd80efd52015-08-10 10:39:35 -0700433 struct vmw_ctx_binding_state *staged_bindings;
434 bool staged_bindings_inuse;
Thomas Hellstrom18e4a462014-06-09 12:39:22 +0200435 struct list_head staged_cmd_res;
Thomas Hellstrom9c079b82018-09-26 15:28:55 +0200436 struct list_head ctx_list;
437 struct vmw_ctx_validation_info *dx_ctx_node;
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +0200438 struct vmw_buffer_object *dx_query_mob;
Thomas Hellstromd80efd52015-08-10 10:39:35 -0700439 struct vmw_resource *dx_query_ctx;
440 struct vmw_cmdbuf_res_manager *man;
Thomas Hellstrom9c079b82018-09-26 15:28:55 +0200441 struct vmw_validation_context *ctx;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000442};
443
444struct vmw_legacy_display;
445struct vmw_overlay;
446
Thomas Hellstrom7c4f7782010-06-01 11:38:17 +0200447struct vmw_vga_topology_state {
448 uint32_t width;
449 uint32_t height;
450 uint32_t primary;
451 uint32_t pos_x;
452 uint32_t pos_y;
453};
454
Thomas Hellstromd80efd52015-08-10 10:39:35 -0700455
456/*
457 * struct vmw_otable - Guest Memory OBject table metadata
458 *
459 * @size: Size of the table (page-aligned).
460 * @page_table: Pointer to a struct vmw_mob holding the page table.
461 */
462struct vmw_otable {
463 unsigned long size;
464 struct vmw_mob *page_table;
465 bool enabled;
466};
467
468struct vmw_otable_batch {
469 unsigned num_otables;
470 struct vmw_otable *otables;
471 struct vmw_resource *context;
472 struct ttm_buffer_object *otable_bo;
473};
474
Thomas Hellstromef369902017-08-24 08:06:28 +0200475enum {
476 VMW_IRQTHREAD_FENCE,
477 VMW_IRQTHREAD_CMDBUF,
478 VMW_IRQTHREAD_MAX
479};
480
Deepak Rawat878c6ec2018-12-13 11:44:42 -0800481/**
482 * enum vmw_sm_type - Graphics context capability supported by device.
483 * @VMW_SM_LEGACY: Pre DX context.
484 * @VMW_SM_4: Context support upto SM4.
485 * @VMW_SM_4_1: Context support upto SM4_1.
Deepak Rawat4dec2802018-12-13 11:48:09 -0800486 * @VMW_SM_5: Context support up to SM5.
Zack Rusin4fb93262021-12-06 12:26:16 -0500487 * @VMW_SM_5_1X: Adds support for sm5_1 and gl43 extensions.
Deepak Rawat878c6ec2018-12-13 11:44:42 -0800488 * @VMW_SM_MAX: Should be the last.
489 */
490enum vmw_sm_type {
491 VMW_SM_LEGACY = 0,
492 VMW_SM_4,
493 VMW_SM_4_1,
Deepak Rawat4dec2802018-12-13 11:48:09 -0800494 VMW_SM_5,
Zack Rusin4fb93262021-12-06 12:26:16 -0500495 VMW_SM_5_1X,
Deepak Rawat878c6ec2018-12-13 11:44:42 -0800496 VMW_SM_MAX
497};
498
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000499struct vmw_private {
Zack Rusin9703bb32020-11-03 22:21:34 -0500500 struct drm_device drm;
Christian König8af8a102020-10-01 14:51:40 +0200501 struct ttm_device bdev;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000502
Gerd Hoffmann293f86b2019-09-05 09:05:08 +0200503 struct drm_vma_offset_manager vma_manager;
Zack Rusinbaee6022021-06-09 13:23:06 -0400504 u32 pci_id;
Zack Rusinbe4f77a2020-11-04 13:46:09 -0500505 resource_size_t io_start;
506 resource_size_t vram_start;
507 resource_size_t vram_size;
Zack Rusinebc9ac72021-06-15 14:23:33 -0400508 resource_size_t max_primary_mem;
Zack Rusinc2aaa372021-06-15 14:23:34 -0400509 u32 __iomem *rmmio;
Zack Rusinbe4f77a2020-11-04 13:46:09 -0500510 u32 *fifo_mem;
Zack Rusinbe4f77a2020-11-04 13:46:09 -0500511 resource_size_t fifo_mem_size;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000512 uint32_t fb_max_width;
513 uint32_t fb_max_height;
Sinclair Yeh35c05122015-06-26 01:42:06 -0700514 uint32_t texture_max_width;
515 uint32_t texture_max_height;
516 uint32_t stdu_max_width;
517 uint32_t stdu_max_height;
Jakob Bornecrantzeb4f9232012-02-09 16:56:46 +0100518 uint32_t initial_width;
519 uint32_t initial_height;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000520 uint32_t capabilities;
Neha Bhende3b4c2512018-06-18 16:44:48 -0700521 uint32_t capabilities2;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000522 uint32_t max_gmr_ids;
Thomas Hellstromfb17f182011-08-31 07:42:53 +0000523 uint32_t max_gmr_pages;
Thomas Hellstrom6da768a2012-11-21 11:06:22 +0100524 uint32_t max_mob_pages;
Charmaine Lee857aea12014-02-12 12:07:38 +0100525 uint32_t max_mob_size;
Thomas Hellstromfb17f182011-08-31 07:42:53 +0000526 uint32_t memory_size;
Thomas Hellstrom135cba02010-10-26 21:21:47 +0200527 bool has_gmr;
Thomas Hellstrom3530bdc2012-11-21 10:49:52 +0100528 bool has_mob;
Thomas Hellstrom496eb6f2015-01-14 02:33:39 -0800529 spinlock_t hw_lock;
Sinclair Yeh04319d82016-06-29 12:15:48 -0700530 bool assume_16bpp;
Deepak Rawat878c6ec2018-12-13 11:44:42 -0800531
532 enum vmw_sm_type sm_type;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000533
534 /*
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000535 * Framebuffer info.
536 */
537
538 void *fb_info;
Sinclair Yehc8261a92015-06-26 01:23:42 -0700539 enum vmw_display_unit_type active_display_unit;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000540 struct vmw_legacy_display *ldu_priv;
541 struct vmw_overlay *overlay_priv;
Thomas Hellstrom578e6092016-02-12 09:45:42 +0100542 struct drm_property *hotplug_mode_update_property;
Thomas Hellstrom76404ac2016-02-12 09:55:45 +0100543 struct drm_property *implicit_placement_property;
Sinclair Yeh36cc79b2017-03-23 11:28:11 -0700544 spinlock_t cursor_lock;
Thomas Hellstromc3b9b162018-03-22 10:26:37 +0100545 struct drm_atomic_state *suspend_state;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000546
547 /*
548 * Context and surface management.
549 */
550
Thomas Hellstrom13289242018-09-26 15:41:52 +0200551 spinlock_t resource_lock;
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000552 struct idr res_idr[vmw_res_max];
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000553
554 /*
555 * A resource manager for kernel-only surfaces and
556 * contexts.
557 */
558
559 struct ttm_object_device *tdev;
560
561 /*
562 * Fencing and IRQs.
563 */
564
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +0000565 atomic_t marker_seq;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000566 wait_queue_head_t fence_queue;
567 wait_queue_head_t fifo_queue;
Thomas Hellstrom496eb6f2015-01-14 02:33:39 -0800568 spinlock_t waiter_lock;
569 int fence_queue_waiters; /* Protected by waiter_lock */
570 int goal_queue_waiters; /* Protected by waiter_lock */
Thomas Hellstromd2e88512015-10-28 19:07:35 +0100571 int cmdbuf_waiters; /* Protected by waiter_lock */
572 int error_waiters; /* Protected by waiter_lock */
573 int fifo_queue_waiters; /* Protected by waiter_lock */
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +0000574 uint32_t last_read_seqno;
Thomas Hellstromae2a1042011-09-01 20:18:44 +0000575 struct vmw_fence_manager *fman;
Thomas Hellstromd2e88512015-10-28 19:07:35 +0100576 uint32_t irq_mask; /* Updates protected by waiter_lock */
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000577
578 /*
579 * Device state
580 */
581
582 uint32_t traces_state;
583 uint32_t enable_state;
584 uint32_t config_done_state;
585
586 /**
587 * Execbuf
588 */
589 /**
590 * Protected by the cmdbuf mutex.
591 */
592
593 struct vmw_sw_context ctx;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000594 struct mutex cmdbuf_mutex;
Thomas Hellstrom173fb7d2013-10-08 02:32:36 -0700595 struct mutex binding_mutex;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000596
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200597 bool enable_fb;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000598
599 /**
Thomas Hellstrom9c84aeb2019-05-28 08:08:55 +0200600 * PM management.
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000601 */
Thomas Hellstromd9f36a02010-01-13 22:28:43 +0100602 struct notifier_block pm_nb;
Thomas Hellstrom153b3d52015-06-25 10:47:43 -0700603 bool refuse_hibernation;
Thomas Hellstromc3b9b162018-03-22 10:26:37 +0100604 bool suspend_locked;
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200605
Thomas Hellstrom153b3d52015-06-25 10:47:43 -0700606 atomic_t num_fifo_resources;
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +0200607
608 /*
609 * Query processing. These members
610 * are protected by the cmdbuf mutex.
611 */
612
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +0200613 struct vmw_buffer_object *dummy_query_bo;
614 struct vmw_buffer_object *pinned_bo;
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +0200615 uint32_t query_cid;
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000616 uint32_t query_cid_valid;
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +0200617 bool dummy_query_bo_pinned;
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +0200618
619 /*
620 * Surface swapping. The "surface_lru" list is protected by the
621 * resource lock in order to be able to destroy a surface and take
622 * it off the lru atomically. "used_memory_size" is currently
623 * protected by the cmdbuf mutex for simplicity.
624 */
625
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000626 struct list_head res_lru[vmw_res_max];
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +0200627 uint32_t used_memory_size;
Thomas Hellstromd92d9852013-10-24 01:49:26 -0700628
629 /*
630 * DMA mapping stuff.
631 */
632 enum vmw_dma_map_mode map_mode;
Thomas Hellstrom3530bdc2012-11-21 10:49:52 +0100633
634 /*
635 * Guest Backed stuff
636 */
Thomas Hellstromd80efd52015-08-10 10:39:35 -0700637 struct vmw_otable_batch otable_batch;
Thomas Hellstrom3eab3d92015-06-25 11:57:56 -0700638
Zack Rusin2cd80db2021-05-05 15:10:07 -0400639 struct vmw_fifo_state *fifo;
Thomas Hellstrom3eab3d92015-06-25 11:57:56 -0700640 struct vmw_cmdbuf_man *cman;
Thomas Hellstromef369902017-08-24 08:06:28 +0200641 DECLARE_BITMAP(irqthread_pending, VMW_IRQTHREAD_MAX);
Thomas Hellstromfd567462018-12-12 11:52:08 +0100642
Zack Rusind92223e2021-06-09 13:22:59 -0400643 uint32 *devcaps;
Martin Krastev7a7a9332021-06-09 13:23:00 -0400644
645 /*
646 * mksGuestStat instance-descriptor and pid arrays
647 */
648 struct page *mksstat_user_pages[MKSSTAT_CAPACITY];
649 atomic_t mksstat_user_pids[MKSSTAT_CAPACITY];
650
651#if IS_ENABLED(CONFIG_DRM_VMWGFX_MKSSTATS)
652 struct page *mksstat_kern_pages[MKSSTAT_CAPACITY];
653 u8 mksstat_kern_top_timer[MKSSTAT_CAPACITY];
654 atomic_t mksstat_kern_pids[MKSSTAT_CAPACITY];
655#endif
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000656};
657
Zack Rusin8afa13a2021-12-06 12:26:12 -0500658static inline struct vmw_buffer_object *gem_to_vmw_bo(struct drm_gem_object *gobj)
659{
660 return container_of((gobj), struct vmw_buffer_object, base.base);
661}
662
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000663static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res)
664{
665 return container_of(res, struct vmw_surface, res);
666}
667
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000668static inline struct vmw_private *vmw_priv(struct drm_device *dev)
669{
670 return (struct vmw_private *)dev->dev_private;
671}
672
673static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
674{
675 return (struct vmw_fpriv *)file_priv->driver_priv;
676}
677
Thomas Hellstrom496eb6f2015-01-14 02:33:39 -0800678/*
Zack Rusin2cd80db2021-05-05 15:10:07 -0400679 * SVGA v3 has mmio register access and lacks fifo cmds
680 */
681static inline bool vmw_is_svga_v3(const struct vmw_private *dev)
682{
683 return dev->pci_id == VMWGFX_PCI_ID_SVGA3;
684}
685
686/*
Thomas Hellstrom496eb6f2015-01-14 02:33:39 -0800687 * The locking here is fine-grained, so that it is performed once
688 * for every read- and write operation. This is of course costly, but we
689 * don't perform much register access in the timing critical paths anyway.
690 * Instead we have the extra benefit of being sure that we don't forget
691 * the hw lock around register accesses.
692 */
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000693static inline void vmw_write(struct vmw_private *dev_priv,
694 unsigned int offset, uint32_t value)
695{
Zack Rusin2cd80db2021-05-05 15:10:07 -0400696 if (vmw_is_svga_v3(dev_priv)) {
697 iowrite32(value, dev_priv->rmmio + offset);
698 } else {
699 spin_lock(&dev_priv->hw_lock);
700 outl(offset, dev_priv->io_start + SVGA_INDEX_PORT);
701 outl(value, dev_priv->io_start + SVGA_VALUE_PORT);
702 spin_unlock(&dev_priv->hw_lock);
703 }
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000704}
705
706static inline uint32_t vmw_read(struct vmw_private *dev_priv,
707 unsigned int offset)
708{
Thomas Hellstrom496eb6f2015-01-14 02:33:39 -0800709 u32 val;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000710
Zack Rusin2cd80db2021-05-05 15:10:07 -0400711 if (vmw_is_svga_v3(dev_priv)) {
712 val = ioread32(dev_priv->rmmio + offset);
713 } else {
714 spin_lock(&dev_priv->hw_lock);
715 outl(offset, dev_priv->io_start + SVGA_INDEX_PORT);
716 val = inl(dev_priv->io_start + SVGA_VALUE_PORT);
717 spin_unlock(&dev_priv->hw_lock);
718 }
Thomas Hellstrom496eb6f2015-01-14 02:33:39 -0800719
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000720 return val;
721}
722
Deepak Rawat878c6ec2018-12-13 11:44:42 -0800723/**
724 * has_sm4_context - Does the device support SM4 context.
725 * @dev_priv: Device private.
726 *
727 * Return: Bool value if device support SM4 context or not.
728 */
729static inline bool has_sm4_context(const struct vmw_private *dev_priv)
730{
731 return (dev_priv->sm_type >= VMW_SM_4);
732}
733
734/**
735 * has_sm4_1_context - Does the device support SM4_1 context.
736 * @dev_priv: Device private.
737 *
738 * Return: Bool value if device support SM4_1 context or not.
739 */
740static inline bool has_sm4_1_context(const struct vmw_private *dev_priv)
741{
742 return (dev_priv->sm_type >= VMW_SM_4_1);
743}
744
Deepak Rawat4dec2802018-12-13 11:48:09 -0800745/**
746 * has_sm5_context - Does the device support SM5 context.
747 * @dev_priv: Device private.
748 *
749 * Return: Bool value if device support SM5 context or not.
750 */
751static inline bool has_sm5_context(const struct vmw_private *dev_priv)
752{
753 return (dev_priv->sm_type >= VMW_SM_5);
754}
755
Zack Rusin4fb93262021-12-06 12:26:16 -0500756/**
757 * has_gl43_context - Does the device support GL43 context.
758 * @dev_priv: Device private.
759 *
760 * Return: Bool value if device support SM5 context or not.
761 */
762static inline bool has_gl43_context(const struct vmw_private *dev_priv)
763{
764 return (dev_priv->sm_type >= VMW_SM_5_1X);
765}
766
767
768static inline u32 vmw_max_num_uavs(struct vmw_private *dev_priv)
769{
770 return (has_gl43_context(dev_priv) ?
771 SVGA3D_DX11_1_MAX_UAVIEWS : SVGA3D_MAX_UAVIEWS);
772}
773
Thomas Hellstrom153b3d52015-06-25 10:47:43 -0700774extern void vmw_svga_enable(struct vmw_private *dev_priv);
775extern void vmw_svga_disable(struct vmw_private *dev_priv);
776
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200777
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000778/**
779 * GMR utilities - vmwgfx_gmr.c
780 */
781
782extern int vmw_gmr_bind(struct vmw_private *dev_priv,
Thomas Hellstromd92d9852013-10-24 01:49:26 -0700783 const struct vmw_sg_table *vsgt,
Thomas Hellstrom135cba02010-10-26 21:21:47 +0200784 unsigned long num_pages,
785 int gmr_id);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000786extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
787
788/**
789 * Resource utilities - vmwgfx_resource.c
790 */
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000791struct vmw_user_resource_conv;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000792
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000793extern void vmw_resource_unreference(struct vmw_resource **p_res);
794extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
Thomas Hellstrom30f82d812014-02-05 08:13:56 +0100795extern struct vmw_resource *
796vmw_resource_reference_unless_doomed(struct vmw_resource *res);
Thomas Hellstromfb80edb2019-03-28 11:36:25 +0100797extern int vmw_resource_validate(struct vmw_resource *res, bool intr,
798 bool dirtying);
Thomas Hellstrom1a4b1722015-06-26 02:03:53 -0700799extern int vmw_resource_reserve(struct vmw_resource *res, bool interruptible,
800 bool no_backup);
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000801extern bool vmw_resource_needs_backup(const struct vmw_resource *res);
Jakob Bornecrantz551a6692011-11-28 13:19:11 +0100802extern int vmw_user_lookup_handle(struct vmw_private *dev_priv,
Zack Rusin8afa13a2021-12-06 12:26:12 -0500803 struct drm_file *filp,
Jakob Bornecrantz551a6692011-11-28 13:19:11 +0100804 uint32_t handle,
805 struct vmw_surface **out_surf,
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +0200806 struct vmw_buffer_object **out_buf);
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000807extern int vmw_user_resource_lookup_handle(
808 struct vmw_private *dev_priv,
809 struct ttm_object_file *tfile,
810 uint32_t handle,
811 const struct vmw_user_resource_conv *converter,
812 struct vmw_resource **p_res);
Thomas Hellstrome8c66ef2018-09-26 16:32:40 +0200813extern struct vmw_resource *
814vmw_user_resource_noref_lookup_handle(struct vmw_private *dev_priv,
815 struct ttm_object_file *tfile,
816 uint32_t handle,
817 const struct vmw_user_resource_conv *
818 converter);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000819extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
820 struct drm_file *file_priv);
821extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
822 struct drm_file *file_priv);
823extern int vmw_user_stream_lookup(struct vmw_private *dev_priv,
824 struct ttm_object_file *tfile,
825 uint32_t *inout_id,
826 struct vmw_resource **out);
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000827extern void vmw_resource_unreserve(struct vmw_resource *res,
Thomas Hellstroma9f58c42019-02-20 08:21:26 +0100828 bool dirty_set,
829 bool dirty,
Thomas Hellstromd80efd52015-08-10 10:39:35 -0700830 bool switch_backup,
Thomas Hellstrome9431ea2018-06-19 15:33:53 +0200831 struct vmw_buffer_object *new_backup,
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000832 unsigned long new_backup_offset);
Sinclair Yehfd11a3c2015-08-10 10:56:15 -0700833extern void vmw_query_move_notify(struct ttm_buffer_object *bo,
Christian König6cf9dc22021-02-11 13:00:25 +0100834 struct ttm_resource *old_mem,
835 struct ttm_resource *new_mem);
Thomas Hellstrome9431ea2018-06-19 15:33:53 +0200836extern int vmw_query_readback_all(struct vmw_buffer_object *dx_query_mob);
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000837extern void vmw_resource_evict_all(struct vmw_private *dev_priv);
Thomas Hellstrome9431ea2018-06-19 15:33:53 +0200838extern void vmw_resource_unbind_list(struct vmw_buffer_object *vbo);
Thomas Hellstroma0a63942019-03-04 19:37:40 +0100839void vmw_resource_mob_attach(struct vmw_resource *res);
840void vmw_resource_mob_detach(struct vmw_resource *res);
Thomas Hellstromb7468b12019-03-27 10:56:08 +0100841void vmw_resource_dirty_update(struct vmw_resource *res, pgoff_t start,
842 pgoff_t end);
Thomas Hellstromfb80edb2019-03-28 11:36:25 +0100843int vmw_resources_clean(struct vmw_buffer_object *vbo, pgoff_t start,
844 pgoff_t end, pgoff_t *num_prefault);
Thomas Hellstroma0a63942019-03-04 19:37:40 +0100845
846/**
847 * vmw_resource_mob_attached - Whether a resource currently has a mob attached
848 * @res: The resource
849 *
850 * Return: true if the resource has a mob attached, false otherwise.
851 */
852static inline bool vmw_resource_mob_attached(const struct vmw_resource *res)
853{
Thomas Hellstrom61335d72019-03-05 08:24:35 +0100854 return !RB_EMPTY_NODE(&res->mob_node);
Thomas Hellstroma0a63942019-03-04 19:37:40 +0100855}
Thomas Hellstrom79273e12018-01-16 09:33:27 +0100856
Jakob Bornecrantzd991ef02011-10-04 20:13:21 +0200857/**
Thomas Hellstrome8c66ef2018-09-26 16:32:40 +0200858 * vmw_user_resource_noref_release - release a user resource pointer looked up
859 * without reference
860 */
861static inline void vmw_user_resource_noref_release(void)
862{
863 ttm_base_object_noref_release();
864}
865
866/**
Thomas Hellstrome9431ea2018-06-19 15:33:53 +0200867 * Buffer object helper functions - vmwgfx_bo.c
Jakob Bornecrantzd991ef02011-10-04 20:13:21 +0200868 */
Zack Rusin8afa13a2021-12-06 12:26:12 -0500869extern bool vmw_bo_is_vmw_bo(struct ttm_buffer_object *bo);
Thomas Hellstrome9431ea2018-06-19 15:33:53 +0200870extern int vmw_bo_pin_in_placement(struct vmw_private *vmw_priv,
871 struct vmw_buffer_object *bo,
872 struct ttm_placement *placement,
873 bool interruptible);
874extern int vmw_bo_pin_in_vram(struct vmw_private *dev_priv,
875 struct vmw_buffer_object *buf,
876 bool interruptible);
877extern int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
878 struct vmw_buffer_object *buf,
879 bool interruptible);
880extern int vmw_bo_pin_in_start_of_vram(struct vmw_private *vmw_priv,
881 struct vmw_buffer_object *bo,
Thomas Hellstrom459d0fa2015-06-26 00:25:37 -0700882 bool interruptible);
Thomas Hellstrome9431ea2018-06-19 15:33:53 +0200883extern int vmw_bo_unpin(struct vmw_private *vmw_priv,
884 struct vmw_buffer_object *bo,
885 bool interruptible);
Thomas Hellstromb37a6b92011-10-04 20:13:28 +0200886extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf,
887 SVGAGuestPtr *ptr);
Thomas Hellstrome9431ea2018-06-19 15:33:53 +0200888extern void vmw_bo_pin_reserved(struct vmw_buffer_object *bo, bool pin);
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +0200889extern void vmw_bo_bo_free(struct ttm_buffer_object *bo);
Christian Königb2545572020-09-21 14:14:32 +0200890extern int vmw_bo_create_kernel(struct vmw_private *dev_priv,
891 unsigned long size,
892 struct ttm_placement *placement,
893 struct ttm_buffer_object **p_bo);
Zack Rusin8afa13a2021-12-06 12:26:12 -0500894extern int vmw_bo_create(struct vmw_private *dev_priv,
895 size_t size, struct ttm_placement *placement,
896 bool interruptible, bool pin,
897 void (*bo_free)(struct ttm_buffer_object *bo),
898 struct vmw_buffer_object **p_bo);
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +0200899extern int vmw_bo_init(struct vmw_private *dev_priv,
900 struct vmw_buffer_object *vmw_bo,
901 size_t size, struct ttm_placement *placement,
Christian Königfbe86ca52020-09-21 14:37:25 +0200902 bool interruptible, bool pin,
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +0200903 void (*bo_free)(struct ttm_buffer_object *bo));
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +0200904extern int vmw_bo_unref_ioctl(struct drm_device *dev, void *data,
905 struct drm_file *file_priv);
906extern int vmw_user_bo_synccpu_ioctl(struct drm_device *dev, void *data,
907 struct drm_file *file_priv);
Zack Rusin8afa13a2021-12-06 12:26:12 -0500908extern int vmw_user_bo_lookup(struct drm_file *filp,
909 uint32_t handle,
910 struct vmw_buffer_object **out);
Thomas Hellstrome9431ea2018-06-19 15:33:53 +0200911extern void vmw_bo_fence_single(struct ttm_buffer_object *bo,
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000912 struct vmw_fence_obj *fence);
Thomas Hellstrome9431ea2018-06-19 15:33:53 +0200913extern void *vmw_bo_map_and_cache(struct vmw_buffer_object *vbo);
914extern void vmw_bo_unmap(struct vmw_buffer_object *vbo);
915extern void vmw_bo_move_notify(struct ttm_buffer_object *bo,
Dave Airlie29661412020-08-04 12:56:32 +1000916 struct ttm_resource *mem);
Thomas Hellstrome9431ea2018-06-19 15:33:53 +0200917extern void vmw_bo_swap_notify(struct ttm_buffer_object *bo);
Thomas Hellstromb733bc22018-09-26 16:03:57 +0200918extern struct vmw_buffer_object *
Zack Rusin8afa13a2021-12-06 12:26:12 -0500919vmw_user_bo_noref_lookup(struct drm_file *filp, u32 handle);
Thomas Hellstromb733bc22018-09-26 16:03:57 +0200920
Thomas Hellstroma0a63942019-03-04 19:37:40 +0100921/**
922 * vmw_bo_adjust_prio - Adjust the buffer object eviction priority
923 * according to attached resources
924 * @vbo: The struct vmw_buffer_object
925 */
926static inline void vmw_bo_prio_adjust(struct vmw_buffer_object *vbo)
927{
928 int i = ARRAY_SIZE(vbo->res_prios);
929
930 while (i--) {
931 if (vbo->res_prios[i]) {
932 vbo->base.priority = i;
933 return;
934 }
935 }
936
937 vbo->base.priority = 3;
938}
939
940/**
941 * vmw_bo_prio_add - Notify a buffer object of a newly attached resource
942 * eviction priority
943 * @vbo: The struct vmw_buffer_object
944 * @prio: The resource priority
945 *
946 * After being notified, the code assigns the highest resource eviction priority
947 * to the backing buffer object (mob).
948 */
949static inline void vmw_bo_prio_add(struct vmw_buffer_object *vbo, int prio)
950{
951 if (vbo->res_prios[prio]++ == 0)
952 vmw_bo_prio_adjust(vbo);
953}
954
955/**
956 * vmw_bo_prio_del - Notify a buffer object of a resource with a certain
957 * priority being removed
958 * @vbo: The struct vmw_buffer_object
959 * @prio: The resource priority
960 *
961 * After being notified, the code assigns the highest resource eviction priority
962 * to the backing buffer object (mob).
963 */
964static inline void vmw_bo_prio_del(struct vmw_buffer_object *vbo, int prio)
965{
966 if (--vbo->res_prios[prio] == 0)
967 vmw_bo_prio_adjust(vbo);
968}
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000969
970/**
Zack Rusin8afa13a2021-12-06 12:26:12 -0500971 * GEM related functionality - vmwgfx_gem.c
972 */
973extern int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv,
974 struct drm_file *filp,
975 uint32_t size,
976 uint32_t *handle,
977 struct vmw_buffer_object **p_vbo);
978extern int vmw_gem_object_create_ioctl(struct drm_device *dev, void *data,
979 struct drm_file *filp);
980extern void vmw_gem_destroy(struct ttm_buffer_object *bo);
981extern void vmw_debugfs_gem_init(struct vmw_private *vdev);
982
983/**
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000984 * Misc Ioctl functionality - vmwgfx_ioctl.c
985 */
986
987extern int vmw_getparam_ioctl(struct drm_device *dev, void *data,
988 struct drm_file *file_priv);
Thomas Hellstromf63f6a52011-09-01 20:18:41 +0000989extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
990 struct drm_file *file_priv);
Jakob Bornecrantz2fcd5a72011-10-04 20:13:26 +0200991extern int vmw_present_ioctl(struct drm_device *dev, void *data,
992 struct drm_file *file_priv);
993extern int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
994 struct drm_file *file_priv);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000995
996/**
997 * Fifo utilities - vmwgfx_fifo.c
998 */
999
Zack Rusin2cd80db2021-05-05 15:10:07 -04001000extern struct vmw_fifo_state *vmw_fifo_create(struct vmw_private *dev_priv);
1001extern void vmw_fifo_destroy(struct vmw_private *dev_priv);
1002extern bool vmw_cmd_supported(struct vmw_private *vmw);
Thomas Hellstromd80efd52015-08-10 10:39:35 -07001003extern void *
Zack Rusin8426ed92020-11-18 12:54:19 -05001004vmw_cmd_ctx_reserve(struct vmw_private *dev_priv, uint32_t bytes, int ctx_id);
1005extern void vmw_cmd_commit(struct vmw_private *dev_priv, uint32_t bytes);
1006extern void vmw_cmd_commit_flush(struct vmw_private *dev_priv, uint32_t bytes);
1007extern int vmw_cmd_send_fence(struct vmw_private *dev_priv, uint32_t *seqno);
1008extern bool vmw_supports_3d(struct vmw_private *dev_priv);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001009extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
Jakob Bornecrantzd7e19582010-05-28 11:21:59 +02001010extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv);
Zack Rusin8426ed92020-11-18 12:54:19 -05001011extern int vmw_cmd_emit_dummy_query(struct vmw_private *dev_priv,
1012 uint32_t cid);
1013extern int vmw_cmd_flush(struct vmw_private *dev_priv,
1014 bool interruptible);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001015
Zack Rusin8426ed92020-11-18 12:54:19 -05001016#define VMW_CMD_CTX_RESERVE(__priv, __bytes, __ctx_id) \
Deepak Rawat11c45412019-02-14 16:15:39 -08001017({ \
Zack Rusin8426ed92020-11-18 12:54:19 -05001018 vmw_cmd_ctx_reserve(__priv, __bytes, __ctx_id) ? : ({ \
Deepak Rawat11c45412019-02-14 16:15:39 -08001019 DRM_ERROR("FIFO reserve failed at %s for %u bytes\n", \
1020 __func__, (unsigned int) __bytes); \
1021 NULL; \
1022 }); \
1023})
1024
Zack Rusin8426ed92020-11-18 12:54:19 -05001025#define VMW_CMD_RESERVE(__priv, __bytes) \
1026 VMW_CMD_CTX_RESERVE(__priv, __bytes, SVGA3D_INVALID_ID)
Deepak Rawat11c45412019-02-14 16:15:39 -08001027
Zack Rusin2cd80db2021-05-05 15:10:07 -04001028
1029/**
1030 * vmw_fifo_caps - Returns the capabilities of the FIFO command
1031 * queue or 0 if fifo memory isn't present.
1032 * @dev_priv: The device private context
1033 */
1034static inline uint32_t vmw_fifo_caps(const struct vmw_private *dev_priv)
1035{
1036 if (!dev_priv->fifo_mem || !dev_priv->fifo)
1037 return 0;
1038 return dev_priv->fifo->capabilities;
1039}
1040
1041
1042/**
1043 * vmw_is_cursor_bypass3_enabled - Returns TRUE iff Cursor Bypass 3
1044 * is enabled in the FIFO.
1045 * @dev_priv: The device private context
1046 */
1047static inline bool
1048vmw_is_cursor_bypass3_enabled(const struct vmw_private *dev_priv)
1049{
1050 return (vmw_fifo_caps(dev_priv) & SVGA_FIFO_CAP_CURSOR_BYPASS_3) != 0;
1051}
1052
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001053/**
1054 * TTM glue - vmwgfx_ttm_glue.c
1055 */
1056
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001057extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma);
1058
1059/**
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +02001060 * TTM buffer object driver - vmwgfx_ttm_buffer.c
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001061 */
1062
Thomas Hellstrom308d17e2013-11-28 01:46:56 -08001063extern const size_t vmw_tt_size;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001064extern struct ttm_placement vmw_vram_placement;
Thomas Hellstrom8ba51522010-01-16 16:05:05 +01001065extern struct ttm_placement vmw_vram_sys_placement;
Thomas Hellstrom135cba02010-10-26 21:21:47 +02001066extern struct ttm_placement vmw_vram_gmr_placement;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001067extern struct ttm_placement vmw_sys_placement;
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +02001068extern struct ttm_placement vmw_srf_placement;
Thomas Hellstrom96c5f0d2012-11-21 11:19:53 +01001069extern struct ttm_placement vmw_mob_placement;
Thomas Hellstromef86cfe2018-01-16 11:07:30 +01001070extern struct ttm_placement vmw_nonfixed_placement;
Christian König8af8a102020-10-01 14:51:40 +02001071extern struct ttm_device_funcs vmw_bo_driver;
Thomas Hellstrom0fd53cf2013-10-24 13:27:38 -07001072extern const struct vmw_sg_table *
1073vmw_bo_sg_table(struct ttm_buffer_object *bo);
Dave Airlie56dc01f2020-08-04 12:55:34 +10001074extern int vmw_bo_create_and_populate(struct vmw_private *dev_priv,
1075 unsigned long bo_size,
1076 struct ttm_buffer_object **bo_p);
1077
Thomas Hellstromd92d9852013-10-24 01:49:26 -07001078extern void vmw_piter_start(struct vmw_piter *viter,
1079 const struct vmw_sg_table *vsgt,
1080 unsigned long p_offs);
1081
1082/**
1083 * vmw_piter_next - Advance the iterator one page.
1084 *
1085 * @viter: Pointer to the iterator to advance.
1086 *
1087 * Returns false if past the list of pages, true otherwise.
1088 */
1089static inline bool vmw_piter_next(struct vmw_piter *viter)
1090{
1091 return viter->next(viter);
1092}
1093
1094/**
1095 * vmw_piter_dma_addr - Return the DMA address of the current page.
1096 *
1097 * @viter: Pointer to the iterator
1098 *
1099 * Returns the DMA address of the page pointed to by @viter.
1100 */
1101static inline dma_addr_t vmw_piter_dma_addr(struct vmw_piter *viter)
1102{
1103 return viter->dma_address(viter);
1104}
1105
1106/**
1107 * vmw_piter_page - Return a pointer to the current page.
1108 *
1109 * @viter: Pointer to the iterator
1110 *
1111 * Returns the DMA address of the page pointed to by @viter.
1112 */
1113static inline struct page *vmw_piter_page(struct vmw_piter *viter)
1114{
Zack Rusin8d9a8d92021-06-09 13:23:04 -04001115 return viter->pages[viter->i];
Thomas Hellstromd92d9852013-10-24 01:49:26 -07001116}
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001117
1118/**
1119 * Command submission - vmwgfx_execbuf.c
1120 */
1121
Emil Velikovcbfbe472019-05-22 17:41:17 +01001122extern int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
1123 struct drm_file *file_priv);
Thomas Hellstrom922ade02011-10-04 20:13:17 +02001124extern int vmw_execbuf_process(struct drm_file *file_priv,
1125 struct vmw_private *dev_priv,
1126 void __user *user_commands,
1127 void *kernel_commands,
1128 uint32_t command_size,
1129 uint64_t throttle_us,
Thomas Hellstromd80efd52015-08-10 10:39:35 -07001130 uint32_t dx_context_handle,
Thomas Hellstrom922ade02011-10-04 20:13:17 +02001131 struct drm_vmw_fence_rep __user
Jakob Bornecrantzbb1bd2f2012-02-09 16:56:43 +01001132 *user_fence_rep,
Sinclair Yehc906965d2017-07-05 01:49:32 -07001133 struct vmw_fence_obj **out_fence,
1134 uint32_t flags);
Thomas Hellstromc0951b72012-11-20 12:19:35 +00001135extern void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv,
1136 struct vmw_fence_obj *fence);
1137extern void vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv);
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +02001138
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +02001139extern int vmw_execbuf_fence_commands(struct drm_file *file_priv,
1140 struct vmw_private *dev_priv,
1141 struct vmw_fence_obj **p_fence,
1142 uint32_t *p_handle);
Thomas Hellstrom57c5ee72011-10-10 12:23:26 +02001143extern void vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
1144 struct vmw_fpriv *vmw_fp,
1145 int ret,
1146 struct drm_vmw_fence_rep __user
1147 *user_fence_rep,
1148 struct vmw_fence_obj *fence,
Sinclair Yehc906965d2017-07-05 01:49:32 -07001149 uint32_t fence_handle,
1150 int32_t out_fence_fd,
1151 struct sync_file *sync_file);
Thomas Hellstrom65b97a22017-08-24 08:06:29 +02001152bool vmw_cmd_describe(const void *buf, u32 *size, char const **cmd);
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +02001153
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001154/**
1155 * IRQs and wating - vmwgfx_irq.c
1156 */
1157
Thomas Hellstrome3001732017-08-24 08:06:27 +02001158extern int vmw_irq_install(struct drm_device *dev, int irq);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001159extern void vmw_irq_uninstall(struct drm_device *dev);
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +00001160extern bool vmw_seqno_passed(struct vmw_private *dev_priv,
1161 uint32_t seqno);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001162extern int vmw_fallback_wait(struct vmw_private *dev_priv,
1163 bool lazy,
1164 bool fifo_idle,
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +00001165 uint32_t seqno,
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001166 bool interruptible,
1167 unsigned long timeout);
Zack Rusin2cd80db2021-05-05 15:10:07 -04001168extern void vmw_update_seqno(struct vmw_private *dev_priv);
Thomas Hellstromae2a1042011-09-01 20:18:44 +00001169extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
1170extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
Thomas Hellstrom57c5ee72011-10-10 12:23:26 +02001171extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
1172extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv);
Thomas Hellstrom3eab3d92015-06-25 11:57:56 -07001173extern void vmw_generic_waiter_add(struct vmw_private *dev_priv, u32 flag,
1174 int *waiter_count);
1175extern void vmw_generic_waiter_remove(struct vmw_private *dev_priv,
1176 u32 flag, int *waiter_count);
Thomas Hellstrom1925d452010-05-28 11:21:57 +02001177
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001178
1179/**
1180 * Kernel framebuffer - vmwgfx_fb.c
1181 */
1182
Thomas Zimmermann5dbf2fc2021-04-15 13:00:37 +02001183#ifdef CONFIG_DRM_FBDEV_EMULATION
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001184int vmw_fb_init(struct vmw_private *vmw_priv);
1185int vmw_fb_close(struct vmw_private *dev_priv);
1186int vmw_fb_off(struct vmw_private *vmw_priv);
1187int vmw_fb_on(struct vmw_private *vmw_priv);
Thomas Zimmermann5dbf2fc2021-04-15 13:00:37 +02001188#else
1189static inline int vmw_fb_init(struct vmw_private *vmw_priv)
1190{
1191 return 0;
1192}
1193static inline int vmw_fb_close(struct vmw_private *dev_priv)
1194{
1195 return 0;
1196}
1197static inline int vmw_fb_off(struct vmw_private *vmw_priv)
1198{
1199 return 0;
1200}
1201static inline int vmw_fb_on(struct vmw_private *vmw_priv)
1202{
1203 return 0;
1204}
1205#endif
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001206
1207/**
1208 * Kernel modesetting - vmwgfx_kms.c
1209 */
1210
1211int vmw_kms_init(struct vmw_private *dev_priv);
1212int vmw_kms_close(struct vmw_private *dev_priv);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001213int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
1214 struct drm_file *file_priv);
1215void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
1216void vmw_kms_cursor_snoop(struct vmw_surface *srf,
1217 struct ttm_object_file *tfile,
1218 struct ttm_buffer_object *bo,
1219 SVGA3dCmdHeader *header);
Michel Dänzer0bef23f2011-08-31 07:42:50 +00001220int vmw_kms_write_svga(struct vmw_private *vmw_priv,
1221 unsigned width, unsigned height, unsigned pitch,
1222 unsigned bpp, unsigned depth);
Thomas Hellstrome133e7372010-10-05 12:43:04 +02001223bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
1224 uint32_t pitch,
1225 uint32_t height);
Thomas Zimmermann4bebe912020-01-23 14:59:41 +01001226u32 vmw_get_vblank_counter(struct drm_crtc *crtc);
1227int vmw_enable_vblank(struct drm_crtc *crtc);
1228void vmw_disable_vblank(struct drm_crtc *crtc);
Jakob Bornecrantz2fcd5a72011-10-04 20:13:26 +02001229int vmw_kms_present(struct vmw_private *dev_priv,
1230 struct drm_file *file_priv,
1231 struct vmw_framebuffer *vfb,
1232 struct vmw_surface *surface,
1233 uint32_t sid, int32_t destX, int32_t destY,
1234 struct drm_vmw_rect *clips,
1235 uint32_t num_clips);
Thomas Hellstromcd2b89e2011-10-25 23:35:53 +02001236int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
1237 struct drm_file *file_priv);
Thomas Hellstrom8fbf9d92015-11-26 19:45:16 +01001238void vmw_kms_legacy_hotspot_clear(struct vmw_private *dev_priv);
Thomas Hellstromc3b9b162018-03-22 10:26:37 +01001239int vmw_kms_suspend(struct drm_device *dev);
1240int vmw_kms_resume(struct drm_device *dev);
Thomas Hellstrom140bcaa2018-03-08 10:07:37 +01001241void vmw_kms_lost_device(struct drm_device *dev);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001242
Dave Airlie5e1782d2012-08-28 01:53:54 +00001243int vmw_dumb_create(struct drm_file *file_priv,
1244 struct drm_device *dev,
1245 struct drm_mode_create_dumb *args);
Thomas Hellstrom1a4b1722015-06-26 02:03:53 -07001246extern int vmw_resource_pin(struct vmw_resource *res, bool interruptible);
Thomas Hellstromed933942015-03-02 23:26:06 -08001247extern void vmw_resource_unpin(struct vmw_resource *res);
Thomas Hellstromd80efd52015-08-10 10:39:35 -07001248extern enum vmw_res_type vmw_res_type(const struct vmw_resource *res);
Thomas Hellstromed933942015-03-02 23:26:06 -08001249
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001250/**
1251 * Overlay control - vmwgfx_overlay.c
1252 */
1253
1254int vmw_overlay_init(struct vmw_private *dev_priv);
1255int vmw_overlay_close(struct vmw_private *dev_priv);
1256int vmw_overlay_ioctl(struct drm_device *dev, void *data,
1257 struct drm_file *file_priv);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001258int vmw_overlay_resume_all(struct vmw_private *dev_priv);
1259int vmw_overlay_pause_all(struct vmw_private *dev_priv);
1260int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
1261int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
1262int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
1263int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
1264
1265/**
Thomas Hellstrom135cba02010-10-26 21:21:47 +02001266 * GMR Id manager
1267 */
1268
Dave Airlie62161772020-08-04 12:55:54 +10001269int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type);
Dave Airlie6eee6672020-08-04 12:56:06 +10001270void vmw_gmrid_man_fini(struct vmw_private *dev_priv, int type);
Thomas Hellstrom135cba02010-10-26 21:21:47 +02001271
1272/**
Zack Rusinf6be2322021-11-05 15:38:45 -04001273 * System memory manager
1274 */
1275int vmw_sys_man_init(struct vmw_private *dev_priv);
1276void vmw_sys_man_fini(struct vmw_private *dev_priv);
1277
1278/**
Thomas Hellstrom69977ff2013-11-13 01:50:46 -08001279 * Prime - vmwgfx_prime.c
1280 */
1281
1282extern const struct dma_buf_ops vmw_prime_dmabuf_ops;
1283extern int vmw_prime_fd_to_handle(struct drm_device *dev,
1284 struct drm_file *file_priv,
1285 int fd, u32 *handle);
1286extern int vmw_prime_handle_to_fd(struct drm_device *dev,
1287 struct drm_file *file_priv,
1288 uint32_t handle, uint32_t flags,
1289 int *prime_fd);
1290
Thomas Hellstrom3530bdc2012-11-21 10:49:52 +01001291/*
1292 * MemoryOBject management - vmwgfx_mob.c
1293 */
1294struct vmw_mob;
1295extern int vmw_mob_bind(struct vmw_private *dev_priv, struct vmw_mob *mob,
Thomas Hellstrom0fd53cf2013-10-24 13:27:38 -07001296 const struct vmw_sg_table *vsgt,
1297 unsigned long num_data_pages, int32_t mob_id);
Thomas Hellstrom3530bdc2012-11-21 10:49:52 +01001298extern void vmw_mob_unbind(struct vmw_private *dev_priv,
1299 struct vmw_mob *mob);
1300extern void vmw_mob_destroy(struct vmw_mob *mob);
1301extern struct vmw_mob *vmw_mob_create(unsigned long data_pages);
1302extern int vmw_otables_setup(struct vmw_private *dev_priv);
1303extern void vmw_otables_takedown(struct vmw_private *dev_priv);
Thomas Hellstrom69977ff2013-11-13 01:50:46 -08001304
Thomas Hellstromc74c1622012-11-21 12:10:26 +01001305/*
Thomas Hellstrom7086d092012-11-21 12:20:53 +01001306 * Context management - vmwgfx_context.c
1307 */
1308
1309extern const struct vmw_user_resource_conv *user_context_converter;
1310
Thomas Hellstrom7086d092012-11-21 12:20:53 +01001311extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
1312 struct drm_file *file_priv);
Thomas Hellstromd80efd52015-08-10 10:39:35 -07001313extern int vmw_extended_context_define_ioctl(struct drm_device *dev, void *data,
1314 struct drm_file *file_priv);
Thomas Hellstrom7086d092012-11-21 12:20:53 +01001315extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
1316 struct drm_file *file_priv);
Thomas Hellstrom30f82d812014-02-05 08:13:56 +01001317extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
Thomas Hellstrom18e4a462014-06-09 12:39:22 +02001318extern struct vmw_cmdbuf_res_manager *
1319vmw_context_res_man(struct vmw_resource *ctx);
Thomas Hellstromd80efd52015-08-10 10:39:35 -07001320extern struct vmw_resource *vmw_context_cotable(struct vmw_resource *ctx,
1321 SVGACOTableType cotable_type);
Thomas Hellstromd80efd52015-08-10 10:39:35 -07001322struct vmw_ctx_binding_state;
1323extern struct vmw_ctx_binding_state *
1324vmw_context_binding_state(struct vmw_resource *ctx);
1325extern void vmw_dx_context_scrub_cotables(struct vmw_resource *ctx,
1326 bool readback);
Sinclair Yehfd11a3c2015-08-10 10:56:15 -07001327extern int vmw_context_bind_dx_query(struct vmw_resource *ctx_res,
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +02001328 struct vmw_buffer_object *mob);
1329extern struct vmw_buffer_object *
Sinclair Yehfd11a3c2015-08-10 10:56:15 -07001330vmw_context_get_dx_query_mob(struct vmw_resource *ctx_res);
1331
Thomas Hellstromd80efd52015-08-10 10:39:35 -07001332
Thomas Hellstrom7086d092012-11-21 12:20:53 +01001333/*
1334 * Surface management - vmwgfx_surface.c
1335 */
1336
1337extern const struct vmw_user_resource_conv *user_surface_converter;
1338
Thomas Hellstrom7086d092012-11-21 12:20:53 +01001339extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data,
1340 struct drm_file *file_priv);
1341extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
1342 struct drm_file *file_priv);
1343extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,
1344 struct drm_file *file_priv);
1345extern int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data,
1346 struct drm_file *file_priv);
1347extern int vmw_gb_surface_reference_ioctl(struct drm_device *dev, void *data,
1348 struct drm_file *file_priv);
Deepak Rawat14b1c332018-06-20 14:48:35 -07001349extern int vmw_gb_surface_define_ext_ioctl(struct drm_device *dev,
1350 void *data,
1351 struct drm_file *file_priv);
1352extern int vmw_gb_surface_reference_ext_ioctl(struct drm_device *dev,
1353 void *data,
1354 struct drm_file *file_priv);
Thomas Hellstrom7086d092012-11-21 12:20:53 +01001355
Deepak Rawat504901d2019-04-29 14:55:44 -07001356int vmw_gb_surface_define(struct vmw_private *dev_priv,
Deepak Rawat504901d2019-04-29 14:55:44 -07001357 const struct vmw_surface_metadata *req,
1358 struct vmw_surface **srf_out);
1359
Thomas Hellstrom7086d092012-11-21 12:20:53 +01001360/*
Thomas Hellstromc74c1622012-11-21 12:10:26 +01001361 * Shader management - vmwgfx_shader.c
1362 */
1363
Thomas Hellstrom7086d092012-11-21 12:20:53 +01001364extern const struct vmw_user_resource_conv *user_shader_converter;
1365
Thomas Hellstromc74c1622012-11-21 12:10:26 +01001366extern int vmw_shader_define_ioctl(struct drm_device *dev, void *data,
1367 struct drm_file *file_priv);
1368extern int vmw_shader_destroy_ioctl(struct drm_device *dev, void *data,
1369 struct drm_file *file_priv);
Thomas Hellstrom18e4a462014-06-09 12:39:22 +02001370extern int vmw_compat_shader_add(struct vmw_private *dev_priv,
1371 struct vmw_cmdbuf_res_manager *man,
Thomas Hellstromd5bde952014-01-31 10:12:10 +01001372 u32 user_key, const void *bytecode,
1373 SVGA3dShaderType shader_type,
1374 size_t size,
Thomas Hellstromd5bde952014-01-31 10:12:10 +01001375 struct list_head *list);
Thomas Hellstromd80efd52015-08-10 10:39:35 -07001376extern int vmw_shader_remove(struct vmw_cmdbuf_res_manager *man,
1377 u32 user_key, SVGA3dShaderType shader_type,
1378 struct list_head *list);
1379extern int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,
1380 struct vmw_resource *ctx,
1381 u32 user_key,
1382 SVGA3dShaderType shader_type,
1383 struct list_head *list);
1384extern void vmw_dx_shader_cotable_list_scrub(struct vmw_private *dev_priv,
1385 struct list_head *list,
1386 bool readback);
1387
Thomas Hellstrom18e4a462014-06-09 12:39:22 +02001388extern struct vmw_resource *
Thomas Hellstromd80efd52015-08-10 10:39:35 -07001389vmw_shader_lookup(struct vmw_cmdbuf_res_manager *man,
1390 u32 user_key, SVGA3dShaderType shader_type);
Thomas Hellstrom18e4a462014-06-09 12:39:22 +02001391
1392/*
Deepak Rawate8bead92018-12-13 14:04:31 -08001393 * Streamoutput management
1394 */
1395struct vmw_resource *
1396vmw_dx_streamoutput_lookup(struct vmw_cmdbuf_res_manager *man,
1397 u32 user_key);
1398int vmw_dx_streamoutput_add(struct vmw_cmdbuf_res_manager *man,
1399 struct vmw_resource *ctx,
1400 SVGA3dStreamOutputId user_key,
1401 struct list_head *list);
1402void vmw_dx_streamoutput_set_size(struct vmw_resource *res, u32 size);
1403int vmw_dx_streamoutput_remove(struct vmw_cmdbuf_res_manager *man,
1404 SVGA3dStreamOutputId user_key,
1405 struct list_head *list);
1406void vmw_dx_streamoutput_cotable_list_scrub(struct vmw_private *dev_priv,
1407 struct list_head *list,
1408 bool readback);
1409
1410/*
Thomas Hellstrom18e4a462014-06-09 12:39:22 +02001411 * Command buffer managed resources - vmwgfx_cmdbuf_res.c
1412 */
1413
1414extern struct vmw_cmdbuf_res_manager *
1415vmw_cmdbuf_res_man_create(struct vmw_private *dev_priv);
1416extern void vmw_cmdbuf_res_man_destroy(struct vmw_cmdbuf_res_manager *man);
Thomas Hellstrom18e4a462014-06-09 12:39:22 +02001417extern struct vmw_resource *
1418vmw_cmdbuf_res_lookup(struct vmw_cmdbuf_res_manager *man,
1419 enum vmw_cmdbuf_res_type res_type,
1420 u32 user_key);
1421extern void vmw_cmdbuf_res_revert(struct list_head *list);
1422extern void vmw_cmdbuf_res_commit(struct list_head *list);
1423extern int vmw_cmdbuf_res_add(struct vmw_cmdbuf_res_manager *man,
1424 enum vmw_cmdbuf_res_type res_type,
1425 u32 user_key,
1426 struct vmw_resource *res,
1427 struct list_head *list);
1428extern int vmw_cmdbuf_res_remove(struct vmw_cmdbuf_res_manager *man,
1429 enum vmw_cmdbuf_res_type res_type,
1430 u32 user_key,
Thomas Hellstromd80efd52015-08-10 10:39:35 -07001431 struct list_head *list,
1432 struct vmw_resource **res);
Thomas Hellstromd5bde952014-01-31 10:12:10 +01001433
Thomas Hellstromd80efd52015-08-10 10:39:35 -07001434/*
1435 * COTable management - vmwgfx_cotable.c
1436 */
1437extern const SVGACOTableType vmw_cotable_scrub_order[];
1438extern struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv,
1439 struct vmw_resource *ctx,
1440 u32 type);
1441extern int vmw_cotable_notify(struct vmw_resource *res, int id);
1442extern int vmw_cotable_scrub(struct vmw_resource *res, bool readback);
1443extern void vmw_cotable_add_resource(struct vmw_resource *ctx,
1444 struct list_head *head);
Thomas Hellstromc74c1622012-11-21 12:10:26 +01001445
Thomas Hellstrom3eab3d92015-06-25 11:57:56 -07001446/*
1447 * Command buffer managerment vmwgfx_cmdbuf.c
1448 */
1449struct vmw_cmdbuf_man;
1450struct vmw_cmdbuf_header;
1451
1452extern struct vmw_cmdbuf_man *
1453vmw_cmdbuf_man_create(struct vmw_private *dev_priv);
Zack Rusin8426ed92020-11-18 12:54:19 -05001454extern int vmw_cmdbuf_set_pool_size(struct vmw_cmdbuf_man *man, size_t size);
Thomas Hellstrom3eab3d92015-06-25 11:57:56 -07001455extern void vmw_cmdbuf_remove_pool(struct vmw_cmdbuf_man *man);
1456extern void vmw_cmdbuf_man_destroy(struct vmw_cmdbuf_man *man);
1457extern int vmw_cmdbuf_idle(struct vmw_cmdbuf_man *man, bool interruptible,
1458 unsigned long timeout);
1459extern void *vmw_cmdbuf_reserve(struct vmw_cmdbuf_man *man, size_t size,
1460 int ctx_id, bool interruptible,
1461 struct vmw_cmdbuf_header *header);
1462extern void vmw_cmdbuf_commit(struct vmw_cmdbuf_man *man, size_t size,
1463 struct vmw_cmdbuf_header *header,
1464 bool flush);
Thomas Hellstrom3eab3d92015-06-25 11:57:56 -07001465extern void *vmw_cmdbuf_alloc(struct vmw_cmdbuf_man *man,
1466 size_t size, bool interruptible,
1467 struct vmw_cmdbuf_header **p_header);
1468extern void vmw_cmdbuf_header_free(struct vmw_cmdbuf_header *header);
1469extern int vmw_cmdbuf_cur_flush(struct vmw_cmdbuf_man *man,
1470 bool interruptible);
Thomas Hellstromef369902017-08-24 08:06:28 +02001471extern void vmw_cmdbuf_irqthread(struct vmw_cmdbuf_man *man);
Thomas Hellstrombf6f0362012-11-09 12:26:15 +00001472
Thomas Hellstrom79273e12018-01-16 09:33:27 +01001473/* CPU blit utilities - vmwgfx_blit.c */
1474
1475/**
1476 * struct vmw_diff_cpy - CPU blit information structure
1477 *
1478 * @rect: The output bounding box rectangle.
1479 * @line: The current line of the blit.
1480 * @line_offset: Offset of the current line segment.
1481 * @cpp: Bytes per pixel (granularity information).
1482 * @memcpy: Which memcpy function to use.
1483 */
1484struct vmw_diff_cpy {
1485 struct drm_rect rect;
1486 size_t line;
1487 size_t line_offset;
1488 int cpp;
1489 void (*do_cpy)(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src,
1490 size_t n);
1491};
1492
1493#define VMW_CPU_BLIT_INITIALIZER { \
1494 .do_cpy = vmw_memcpy, \
1495}
1496
1497#define VMW_CPU_BLIT_DIFF_INITIALIZER(_cpp) { \
1498 .line = 0, \
1499 .line_offset = 0, \
1500 .rect = { .x1 = INT_MAX/2, \
1501 .y1 = INT_MAX/2, \
1502 .x2 = INT_MIN/2, \
1503 .y2 = INT_MIN/2 \
1504 }, \
1505 .cpp = _cpp, \
1506 .do_cpy = vmw_diff_memcpy, \
1507}
1508
1509void vmw_diff_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src,
1510 size_t n);
1511
1512void vmw_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src, size_t n);
1513
1514int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
1515 u32 dst_offset, u32 dst_stride,
1516 struct ttm_buffer_object *src,
1517 u32 src_offset, u32 src_stride,
1518 u32 w, u32 h,
1519 struct vmw_diff_cpy *diff);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001520
Thomas Hellstrom6ff67ae2018-06-21 09:39:21 +02001521/* Host messaging -vmwgfx_msg.c: */
1522int vmw_host_get_guestinfo(const char *guest_info_param,
1523 char *buffer, size_t *length);
Zack Rusin523375c2021-05-04 23:57:40 -04001524__printf(1, 2) int vmw_host_printf(const char *fmt, ...);
Roland Scheideggercb92a322019-11-21 17:44:56 +01001525int vmw_msg_ioctl(struct drm_device *dev, void *data,
1526 struct drm_file *file_priv);
Thomas Hellstrom6ff67ae2018-06-21 09:39:21 +02001527
Martin Krastev7a7a9332021-06-09 13:23:00 -04001528/* Host mksGuestStats -vmwgfx_msg.c: */
1529int vmw_mksstat_get_kern_slot(pid_t pid, struct vmw_private *dev_priv);
1530
1531int vmw_mksstat_reset_ioctl(struct drm_device *dev, void *data,
1532 struct drm_file *file_priv);
1533int vmw_mksstat_add_ioctl(struct drm_device *dev, void *data,
1534 struct drm_file *file_priv);
1535int vmw_mksstat_remove_ioctl(struct drm_device *dev, void *data,
1536 struct drm_file *file_priv);
1537int vmw_mksstat_remove_all(struct vmw_private *dev_priv);
1538
Deepak Rawat5724f892019-02-11 11:46:27 -08001539/* VMW logging */
1540
1541/**
1542 * VMW_DEBUG_USER - Debug output for user-space debugging.
1543 *
1544 * @fmt: printf() like format string.
1545 *
1546 * This macro is for logging user-space error and debugging messages for e.g.
1547 * command buffer execution errors due to malformed commands, invalid context,
1548 * etc.
1549 */
1550#define VMW_DEBUG_USER(fmt, ...) \
1551 DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__)
1552
Thomas Hellstromb7468b12019-03-27 10:56:08 +01001553/* Resource dirtying - vmwgfx_page_dirty.c */
1554void vmw_bo_dirty_scan(struct vmw_buffer_object *vbo);
1555int vmw_bo_dirty_add(struct vmw_buffer_object *vbo);
1556void vmw_bo_dirty_transfer_to_res(struct vmw_resource *res);
1557void vmw_bo_dirty_clear_res(struct vmw_resource *res);
1558void vmw_bo_dirty_release(struct vmw_buffer_object *vbo);
Thomas Hellstromfb80edb2019-03-28 11:36:25 +01001559void vmw_bo_dirty_unmap(struct vmw_buffer_object *vbo,
1560 pgoff_t start, pgoff_t end);
Thomas Hellstromb7468b12019-03-27 10:56:08 +01001561vm_fault_t vmw_bo_vm_fault(struct vm_fault *vmf);
1562vm_fault_t vmw_bo_vm_mkwrite(struct vm_fault *vmf);
1563
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001564
1565/**
1566 * VMW_DEBUG_KMS - Debug output for kernel mode-setting
1567 *
1568 * This macro is for debugging vmwgfx mode-setting code.
1569 */
1570#define VMW_DEBUG_KMS(fmt, ...) \
1571 DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__)
1572
1573/**
1574 * Inline helper functions
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +02001575 */
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001576
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +02001577static inline void vmw_surface_unreference(struct vmw_surface **srf)
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001578{
Thomas Hellstrombf6f0362012-11-09 12:26:15 +00001579 struct vmw_surface *tmp_srf = *srf;
1580 struct vmw_resource *res = &tmp_srf->res;
Thomas Zimmermann6034d9d2019-01-25 12:02:09 +01001581 *srf = NULL;
Thomas Hellstrombf6f0362012-11-09 12:26:15 +00001582
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001583 vmw_resource_unreference(&res);
1584}
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +02001585
1586static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001587{
Thomas Zimmermann2d18cb92019-01-25 12:02:08 +01001588 (void) vmw_resource_reference(&srf->res);
1589 return srf;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001590}
1591
Thomas Hellstromae2a1042011-09-01 20:18:44 +00001592static inline void vmw_bo_unreference(struct vmw_buffer_object **buf)
1593{
Christian König27eb1fa2018-10-19 13:49:05 +02001594 struct vmw_buffer_object *tmp_buf = *buf;
Thomas Hellstromae2a1042011-09-01 20:18:44 +00001595
Thomas Hellstrom153b3d52015-06-25 10:47:43 -07001596 *buf = NULL;
Zack Rusin2ef4fb92021-03-22 13:04:11 -04001597 if (tmp_buf != NULL)
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001598 ttm_bo_put(&tmp_buf->base);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001599}
1600
1601static inline struct vmw_buffer_object *
1602vmw_bo_reference(struct vmw_buffer_object *buf)
1603{
1604 ttm_bo_get(&buf->base);
1605 return buf;
1606}
1607
Thomas Hellstrom153b3d52015-06-25 10:47:43 -07001608static inline void vmw_fifo_resource_inc(struct vmw_private *dev_priv)
1609{
1610 atomic_inc(&dev_priv->num_fifo_resources);
1611}
1612
1613static inline void vmw_fifo_resource_dec(struct vmw_private *dev_priv)
1614{
1615 atomic_dec(&dev_priv->num_fifo_resources);
1616}
Thomas Hellstromb76ff5e2015-10-28 10:44:04 +01001617
1618/**
Zack Rusinbe4f77a2020-11-04 13:46:09 -05001619 * vmw_fifo_mem_read - Perform a MMIO read from the fifo memory
Thomas Hellstromb76ff5e2015-10-28 10:44:04 +01001620 *
Zack Rusinbe4f77a2020-11-04 13:46:09 -05001621 * @fifo_reg: The fifo register to read from
Thomas Hellstromb76ff5e2015-10-28 10:44:04 +01001622 *
1623 * This function is intended to be equivalent to ioread32() on
1624 * memremap'd memory, but without byteswapping.
1625 */
Zack Rusinbe4f77a2020-11-04 13:46:09 -05001626static inline u32 vmw_fifo_mem_read(struct vmw_private *vmw, uint32 fifo_reg)
Thomas Hellstromb76ff5e2015-10-28 10:44:04 +01001627{
Zack Rusin2cd80db2021-05-05 15:10:07 -04001628 BUG_ON(vmw_is_svga_v3(vmw));
Zack Rusinbe4f77a2020-11-04 13:46:09 -05001629 return READ_ONCE(*(vmw->fifo_mem + fifo_reg));
Thomas Hellstromb76ff5e2015-10-28 10:44:04 +01001630}
1631
1632/**
Zack Rusinbe4f77a2020-11-04 13:46:09 -05001633 * vmw_fifo_mem_write - Perform a MMIO write to volatile memory
Thomas Hellstromb76ff5e2015-10-28 10:44:04 +01001634 *
Zack Rusinbe4f77a2020-11-04 13:46:09 -05001635 * @addr: The fifo register to write to
Thomas Hellstromb76ff5e2015-10-28 10:44:04 +01001636 *
1637 * This function is intended to be equivalent to iowrite32 on
1638 * memremap'd memory, but without byteswapping.
1639 */
Zack Rusinbe4f77a2020-11-04 13:46:09 -05001640static inline void vmw_fifo_mem_write(struct vmw_private *vmw, u32 fifo_reg,
1641 u32 value)
Thomas Hellstromb76ff5e2015-10-28 10:44:04 +01001642{
Zack Rusin2cd80db2021-05-05 15:10:07 -04001643 BUG_ON(vmw_is_svga_v3(vmw));
Zack Rusinbe4f77a2020-11-04 13:46:09 -05001644 WRITE_ONCE(*(vmw->fifo_mem + fifo_reg), value);
Thomas Hellstromb76ff5e2015-10-28 10:44:04 +01001645}
Zack Rusin2cd80db2021-05-05 15:10:07 -04001646
1647static inline u32 vmw_fence_read(struct vmw_private *dev_priv)
1648{
1649 u32 fence;
1650 if (vmw_is_svga_v3(dev_priv))
1651 fence = vmw_read(dev_priv, SVGA_REG_FENCE);
1652 else
1653 fence = vmw_fifo_mem_read(dev_priv, SVGA_FIFO_FENCE);
1654 return fence;
1655}
1656
1657static inline void vmw_fence_write(struct vmw_private *dev_priv,
1658 u32 fence)
1659{
1660 BUG_ON(vmw_is_svga_v3(dev_priv));
1661 vmw_fifo_mem_write(dev_priv, SVGA_FIFO_FENCE, fence);
1662}
1663
1664static inline u32 vmw_irq_status_read(struct vmw_private *vmw)
1665{
1666 u32 status;
1667 if (vmw_is_svga_v3(vmw))
1668 status = vmw_read(vmw, SVGA_REG_IRQ_STATUS);
1669 else
1670 status = inl(vmw->io_start + SVGA_IRQSTATUS_PORT);
1671 return status;
1672}
1673
1674static inline void vmw_irq_status_write(struct vmw_private *vmw,
1675 uint32 status)
1676{
1677 if (vmw_is_svga_v3(vmw))
1678 vmw_write(vmw, SVGA_REG_IRQ_STATUS, status);
1679 else
1680 outl(status, vmw->io_start + SVGA_IRQSTATUS_PORT);
1681}
1682
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001683#endif