blob: 871ad738dadbdb90ba5a63f98c6455e343771cc3 [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 *
Dirk Hohndel (VMware)dff96882018-05-07 01:16:26 +02004 * Copyright 2009-2015 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>
37#include <drm/drm_hashtab.h>
38#include <drm/drm_rect.h>
39
David Howells760285e2012-10-02 18:01:07 +010040#include <drm/ttm/ttm_bo_driver.h>
David Howells760285e2012-10-02 18:01:07 +010041#include <drm/ttm/ttm_execbuf_util.h>
42#include <drm/ttm/ttm_module.h>
Sam Ravnborgd5c1f012019-06-23 12:23:33 +020043
Thomas Hellstrom0b8762e2018-09-26 20:15:36 +020044#include "ttm_lock.h"
Sam Ravnborgd5c1f012019-06-23 12:23:33 +020045#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
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000057
Thomas Hellstrome3001732017-08-24 08:06:27 +020058#define VMWGFX_DRIVER_NAME "vmwgfx"
Thomas Hellstrom61780dd2020-01-14 11:38:19 +010059#define VMWGFX_DRIVER_DATE "20200114"
Thomas Hellstrom2ae7b032011-09-01 20:18:45 +000060#define VMWGFX_DRIVER_MAJOR 2
Thomas Hellström (VMware)f59e61a2019-10-23 08:27:18 +020061#define VMWGFX_DRIVER_MINOR 18
Deepak Rawat9b07b282018-06-20 15:09:43 -070062#define VMWGFX_DRIVER_PATCHLEVEL 0
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000063#define VMWGFX_FIFO_STATIC_SIZE (1024*1024)
64#define VMWGFX_MAX_RELOCATIONS 2048
Thomas Hellstrombe38ab62011-08-31 07:42:54 +000065#define VMWGFX_MAX_VALIDATIONS 2048
Thomas Hellstrom7c4f7782010-06-01 11:38:17 +020066#define VMWGFX_MAX_DISPLAYS 16
Thomas Hellstrombe38ab62011-08-31 07:42:54 +000067#define VMWGFX_CMD_BOUNCE_INIT_SIZE 32768
Sinclair Yeh35c05122015-06-26 01:42:06 -070068#define VMWGFX_ENABLE_SCREEN_TARGET_OTABLE 1
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +000069
Thomas Hellstrom3530bdc2012-11-21 10:49:52 +010070/*
71 * Perhaps we should have sysfs entries for these.
72 */
73#define VMWGFX_NUM_GB_CONTEXT 256
74#define VMWGFX_NUM_GB_SHADER 20000
75#define VMWGFX_NUM_GB_SURFACE 32768
Thomas Hellstrom7cba9062014-01-09 11:03:18 +010076#define VMWGFX_NUM_GB_SCREEN_TARGET VMWGFX_MAX_DISPLAYS
Thomas Hellstromd80efd52015-08-10 10:39:35 -070077#define VMWGFX_NUM_DXCONTEXT 256
78#define VMWGFX_NUM_DXQUERY 512
Thomas Hellstrom3530bdc2012-11-21 10:49:52 +010079#define VMWGFX_NUM_MOB (VMWGFX_NUM_GB_CONTEXT +\
80 VMWGFX_NUM_GB_SHADER +\
Thomas Hellstrom7cba9062014-01-09 11:03:18 +010081 VMWGFX_NUM_GB_SURFACE +\
82 VMWGFX_NUM_GB_SCREEN_TARGET)
Thomas Hellstrom3530bdc2012-11-21 10:49:52 +010083
Christian König283cde62016-09-12 13:34:37 +020084#define VMW_PL_GMR (TTM_PL_PRIV + 0)
85#define VMW_PL_FLAG_GMR (TTM_PL_FLAG_PRIV << 0)
86#define VMW_PL_MOB (TTM_PL_PRIV + 1)
87#define VMW_PL_FLAG_MOB (TTM_PL_FLAG_PRIV << 1)
Thomas Hellstrom135cba02010-10-26 21:21:47 +020088
Thomas Hellstromae2a1042011-09-01 20:18:44 +000089#define VMW_RES_CONTEXT ttm_driver_type0
90#define VMW_RES_SURFACE ttm_driver_type1
91#define VMW_RES_STREAM ttm_driver_type2
92#define VMW_RES_FENCE ttm_driver_type3
Thomas Hellstromc74c1622012-11-21 12:10:26 +010093#define VMW_RES_SHADER ttm_driver_type4
Thomas Hellstromae2a1042011-09-01 20:18:44 +000094
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
Thomas Hellstroma0a63942019-03-04 19:37:40 +0100104 * @pin_count: pin depth
Christian König7fb03cc2019-10-01 10:02:58 +0200105 * @cpu_writers: Number of synccpu write grabs. Protected by reservation when
106 * increased. May be decreased without reservation.
Thomas Hellstroma0a63942019-03-04 19:37:40 +0100107 * @dx_query_ctx: DX context if this buffer object is used as a DX query MOB
108 * @map: Kmap object for semi-persistent mappings
109 * @res_prios: Eviction priority counts for attached resources
Thomas Hellstromb7468b12019-03-27 10:56:08 +0100110 * @dirty: structure for user-space dirty-tracking
Thomas Hellstroma0a63942019-03-04 19:37:40 +0100111 */
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +0200112struct vmw_buffer_object {
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000113 struct ttm_buffer_object base;
Thomas Hellstrom61335d72019-03-05 08:24:35 +0100114 struct rb_root res_tree;
Thomas Hellstrom459d0fa2015-06-26 00:25:37 -0700115 s32 pin_count;
Christian König7fb03cc2019-10-01 10:02:58 +0200116 atomic_t cpu_writers;
Sinclair Yehfd11a3c2015-08-10 10:56:15 -0700117 /* Not ref-counted. Protected by binding_mutex */
118 struct vmw_resource *dx_query_ctx;
Thomas Hellstrombf833fd2018-03-22 10:19:01 +0100119 /* Protected by reservation */
120 struct ttm_bo_kmap_obj map;
Thomas Hellstroma0a63942019-03-04 19:37:40 +0100121 u32 res_prios[TTM_MAX_BO_PRIORITY];
Thomas Hellstromb7468b12019-03-27 10:56:08 +0100122 struct vmw_bo_dirty *dirty;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000123};
124
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000125/**
126 * struct vmw_validate_buffer - Carries validation info about buffers.
127 *
128 * @base: Validation info for TTM.
129 * @hash: Hash entry for quick lookup of the TTM buffer object.
130 *
131 * This structure contains also driver private validation info
132 * on top of the info needed by TTM.
133 */
134struct vmw_validate_buffer {
135 struct ttm_validate_buffer base;
136 struct drm_hash_item hash;
Thomas Hellstrom96c5f0d2012-11-21 11:19:53 +0100137 bool validate_as_mob;
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000138};
139
140struct vmw_res_func;
Thomas Hellstrom13289242018-09-26 15:41:52 +0200141
142
143/**
144 * struct vmw-resource - base class for hardware resources
145 *
146 * @kref: For refcounting.
147 * @dev_priv: Pointer to the device private for this resource. Immutable.
148 * @id: Device id. Protected by @dev_priv::resource_lock.
149 * @backup_size: Backup buffer size. Immutable.
150 * @res_dirty: Resource contains data not yet in the backup buffer. Protected
151 * by resource reserved.
152 * @backup_dirty: Backup buffer contains data not yet in the HW resource.
Thomas Hellstromb7468b12019-03-27 10:56:08 +0100153 * Protected by resource reserved.
154 * @coherent: Emulate coherency by tracking vm accesses.
Thomas Hellstrom13289242018-09-26 15:41:52 +0200155 * @backup: The backup buffer if any. Protected by resource reserved.
156 * @backup_offset: Offset into the backup buffer if any. Protected by resource
157 * reserved. Note that only a few resource types can have a @backup_offset
158 * different from zero.
159 * @pin_count: The pin count for this resource. A pinned resource has a
160 * pin-count greater than zero. It is not on the resource LRU lists and its
161 * backup buffer is pinned. Hence it can't be evicted.
162 * @func: Method vtable for this resource. Immutable.
Thomas Hellstrom61335d72019-03-05 08:24:35 +0100163 * @mob_node; Node for the MOB backup rbtree. Protected by @backup reserved.
Thomas Hellstrom13289242018-09-26 15:41:52 +0200164 * @lru_head: List head for the LRU list. Protected by @dev_priv::resource_lock.
Thomas Hellstrom13289242018-09-26 15:41:52 +0200165 * @binding_head: List head for the context binding list. Protected by
166 * the @dev_priv::binding_mutex
167 * @res_free: The resource destructor.
168 * @hw_destroy: Callback to destroy the resource on the device, as part of
169 * resource destruction.
170 */
Thomas Hellstromb7468b12019-03-27 10:56:08 +0100171struct vmw_resource_dirty;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000172struct vmw_resource {
173 struct kref kref;
174 struct vmw_private *dev_priv;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000175 int id;
Thomas Hellstroma0a63942019-03-04 19:37:40 +0100176 u32 used_prio;
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000177 unsigned long backup_size;
Thomas Hellstromb7468b12019-03-27 10:56:08 +0100178 u32 res_dirty : 1;
179 u32 backup_dirty : 1;
180 u32 coherent : 1;
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +0200181 struct vmw_buffer_object *backup;
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000182 unsigned long backup_offset;
Thomas Hellstrom13289242018-09-26 15:41:52 +0200183 unsigned long pin_count;
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000184 const struct vmw_res_func *func;
Thomas Hellstrom61335d72019-03-05 08:24:35 +0100185 struct rb_node mob_node;
Thomas Hellstrom13289242018-09-26 15:41:52 +0200186 struct list_head lru_head;
Thomas Hellstrom13289242018-09-26 15:41:52 +0200187 struct list_head binding_head;
Thomas Hellstromb7468b12019-03-27 10:56:08 +0100188 struct vmw_resource_dirty *dirty;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000189 void (*res_free) (struct vmw_resource *res);
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000190 void (*hw_destroy) (struct vmw_resource *res);
191};
192
Thomas Hellstrom18e4a462014-06-09 12:39:22 +0200193
194/*
195 * Resources that are managed using ioctls.
196 */
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000197enum vmw_res_type {
198 vmw_res_context,
199 vmw_res_surface,
200 vmw_res_stream,
Thomas Hellstromc74c1622012-11-21 12:10:26 +0100201 vmw_res_shader,
Thomas Hellstromd80efd52015-08-10 10:39:35 -0700202 vmw_res_dx_context,
203 vmw_res_cotable,
204 vmw_res_view,
Deepak Rawate8bead92018-12-13 14:04:31 -0800205 vmw_res_streamoutput,
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000206 vmw_res_max
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000207};
208
Thomas Hellstrom18e4a462014-06-09 12:39:22 +0200209/*
210 * Resources that are managed using command streams.
211 */
212enum vmw_cmdbuf_res_type {
Thomas Hellstromd80efd52015-08-10 10:39:35 -0700213 vmw_cmdbuf_res_shader,
Deepak Rawate8bead92018-12-13 14:04:31 -0800214 vmw_cmdbuf_res_view,
215 vmw_cmdbuf_res_streamoutput
Thomas Hellstrom18e4a462014-06-09 12:39:22 +0200216};
217
218struct vmw_cmdbuf_res_manager;
219
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000220struct vmw_cursor_snooper {
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000221 size_t age;
222 uint32_t *image;
223};
224
Jakob Bornecrantz2fcd5a72011-10-04 20:13:26 +0200225struct vmw_framebuffer;
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +0200226struct vmw_surface_offset;
Jakob Bornecrantz2fcd5a72011-10-04 20:13:26 +0200227
Deepak Rawat26b82872019-04-29 11:42:45 -0700228/**
229 * struct vmw_surface_metadata - Metadata describing a surface.
230 *
231 * @flags: Device flags.
232 * @format: Surface SVGA3D_x format.
233 * @mip_levels: Mip level for each face. For GB first index is used only.
234 * @multisample_count: Sample count.
235 * @multisample_pattern: Sample patterns.
236 * @quality_level: Quality level.
237 * @autogen_filter: Filter for automatically generated mipmaps.
238 * @array_size: Number of array elements for a 1D/2D texture. For cubemap
239 texture number of faces * array_size. This should be 0 for pre
240 SM4 device.
Deepak Rawat2a50f062019-04-30 13:04:55 -0700241 * @buffer_byte_stride: Buffer byte stride.
Deepak Rawat26b82872019-04-29 11:42:45 -0700242 * @num_sizes: Size of @sizes. For GB surface this should always be 1.
243 * @base_size: Surface dimension.
244 * @sizes: Array representing mip sizes. Legacy only.
245 * @scanout: Whether this surface will be used for scanout.
246 *
247 * This tracks metadata for both legacy and guest backed surface.
248 */
249struct vmw_surface_metadata {
250 u64 flags;
251 u32 format;
252 u32 mip_levels[DRM_VMW_MAX_SURFACE_FACES];
253 u32 multisample_count;
254 u32 multisample_pattern;
255 u32 quality_level;
256 u32 autogen_filter;
257 u32 array_size;
258 u32 num_sizes;
Deepak Rawat2a50f062019-04-30 13:04:55 -0700259 u32 buffer_byte_stride;
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000260 struct drm_vmw_size base_size;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000261 struct drm_vmw_size *sizes;
Jakob Bornecrantz5ffdb652010-01-30 03:38:08 +0000262 bool scanout;
Deepak Rawat26b82872019-04-29 11:42:45 -0700263};
264
265/**
266 * struct vmw_surface: Resource structure for a surface.
267 *
268 * @res: The base resource for this surface.
269 * @metadata: Metadata for this surface resource.
270 * @snooper: Cursor data. Legacy surface only.
271 * @offsets: Legacy surface only.
272 * @view_list: List of views bound to this surface.
273 */
274struct vmw_surface {
275 struct vmw_resource res;
276 struct vmw_surface_metadata metadata;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000277 struct vmw_cursor_snooper snooper;
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +0200278 struct vmw_surface_offset *offsets;
Thomas Hellstromd80efd52015-08-10 10:39:35 -0700279 struct list_head view_list;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000280};
281
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +0000282struct vmw_marker_queue {
Thomas Hellstrom1925d452010-05-28 11:21:57 +0200283 struct list_head head;
Thomas Gleixnerf166e6d2014-07-16 21:05:07 +0000284 u64 lag;
285 u64 lag_time;
Thomas Hellstrom1925d452010-05-28 11:21:57 +0200286 spinlock_t lock;
287};
288
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000289struct vmw_fifo_state {
290 unsigned long reserved_size;
Thomas Hellstromb9eb1a62015-04-02 02:39:45 -0700291 u32 *dynamic_buffer;
292 u32 *static_buffer;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000293 unsigned long static_buffer_size;
294 bool using_bounce_buffer;
295 uint32_t capabilities;
Thomas Hellstrom85b9e482010-02-08 09:57:25 +0000296 struct mutex fifo_mutex;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000297 struct rw_semaphore rwsem;
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +0000298 struct vmw_marker_queue marker_queue;
Thomas Hellstromd80efd52015-08-10 10:39:35 -0700299 bool dx;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000300};
301
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000302/**
303 * struct vmw_res_cache_entry - resource information cache entry
Thomas Hellstrom9c079b82018-09-26 15:28:55 +0200304 * @handle: User-space handle of a resource.
305 * @res: Non-ref-counted pointer to the resource.
306 * @valid_handle: Whether the @handle member is valid.
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000307 * @valid: Whether the entry is valid, which also implies that the execbuf
308 * code holds a reference to the resource, and it's placed on the
309 * validation list.
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000310 *
311 * Used to avoid frequent repeated user-space handle lookups of the
312 * same resource.
313 */
314struct vmw_res_cache_entry {
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000315 uint32_t handle;
316 struct vmw_resource *res;
Thomas Hellstrom9c079b82018-09-26 15:28:55 +0200317 void *private;
318 unsigned short valid_handle;
319 unsigned short valid;
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000320};
321
Thomas Hellstromd92d9852013-10-24 01:49:26 -0700322/**
323 * enum vmw_dma_map_mode - indicate how to perform TTM page dma mappings.
324 */
325enum vmw_dma_map_mode {
326 vmw_dma_phys, /* Use physical page addresses */
327 vmw_dma_alloc_coherent, /* Use TTM coherent pages */
328 vmw_dma_map_populate, /* Unmap from DMA just after unpopulate */
329 vmw_dma_map_bind, /* Unmap from DMA just before unbind */
330 vmw_dma_map_max
331};
332
333/**
334 * struct vmw_sg_table - Scatter/gather table for binding, with additional
335 * device-specific information.
336 *
337 * @sgt: Pointer to a struct sg_table with binding information
Masahiro Yamadae1c05062015-07-07 10:14:59 +0900338 * @num_regions: Number of regions with device-address contiguous pages
Thomas Hellstromd92d9852013-10-24 01:49:26 -0700339 */
340struct vmw_sg_table {
341 enum vmw_dma_map_mode mode;
342 struct page **pages;
343 const dma_addr_t *addrs;
344 struct sg_table *sgt;
345 unsigned long num_regions;
346 unsigned long num_pages;
347};
348
349/**
350 * struct vmw_piter - Page iterator that iterates over a list of pages
351 * and DMA addresses that could be either a scatter-gather list or
352 * arrays
353 *
354 * @pages: Array of page pointers to the pages.
355 * @addrs: DMA addresses to the pages if coherent pages are used.
356 * @iter: Scatter-gather page iterator. Current position in SG list.
357 * @i: Current position in arrays.
358 * @num_pages: Number of pages total.
359 * @next: Function to advance the iterator. Returns false if past the list
360 * of pages, true otherwise.
361 * @dma_address: Function to return the DMA address of the current page.
362 */
363struct vmw_piter {
364 struct page **pages;
365 const dma_addr_t *addrs;
Thomas Hellstrom8dc39cf2019-05-15 17:45:23 +0200366 struct sg_dma_page_iter iter;
Thomas Hellstromd92d9852013-10-24 01:49:26 -0700367 unsigned long i;
368 unsigned long num_pages;
369 bool (*next)(struct vmw_piter *);
370 dma_addr_t (*dma_address)(struct vmw_piter *);
371 struct page *(*page)(struct vmw_piter *);
372};
373
Thomas Hellstromb5c3b1a62013-10-08 02:27:17 -0700374/*
Sinclair Yehc8261a92015-06-26 01:23:42 -0700375 * enum vmw_display_unit_type - Describes the display unit
Thomas Hellstromb5c3b1a62013-10-08 02:27:17 -0700376 */
Sinclair Yehc8261a92015-06-26 01:23:42 -0700377enum vmw_display_unit_type {
378 vmw_du_invalid = 0,
379 vmw_du_legacy,
Sinclair Yeh35c05122015-06-26 01:42:06 -0700380 vmw_du_screen_object,
381 vmw_du_screen_target
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 Hellstromc0951b72012-11-20 12:19:35 +0000419 struct drm_open_hash res_ht;
420 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;
Thomas Hellstrombe38ab62011-08-31 07:42:54 +0000423 uint32_t *cmd_bounce;
424 uint32_t cmd_bounce_size;
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +0200425 struct vmw_buffer_object *cur_query_bo;
Thomas Hellstromfc18afc2018-09-26 15:36:52 +0200426 struct list_head bo_relocations;
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000427 struct list_head res_relocations;
428 uint32_t *buf_start;
429 struct vmw_res_cache_entry res_cache[vmw_res_max];
430 struct vmw_resource *last_query_ctx;
431 bool needs_post_query_barrier;
Thomas Hellstromd80efd52015-08-10 10:39:35 -0700432 struct vmw_ctx_binding_state *staged_bindings;
433 bool staged_bindings_inuse;
Thomas Hellstrom18e4a462014-06-09 12:39:22 +0200434 struct list_head staged_cmd_res;
Thomas Hellstrom9c079b82018-09-26 15:28:55 +0200435 struct list_head ctx_list;
436 struct vmw_ctx_validation_info *dx_ctx_node;
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +0200437 struct vmw_buffer_object *dx_query_mob;
Thomas Hellstromd80efd52015-08-10 10:39:35 -0700438 struct vmw_resource *dx_query_ctx;
439 struct vmw_cmdbuf_res_manager *man;
Thomas Hellstrom9c079b82018-09-26 15:28:55 +0200440 struct vmw_validation_context *ctx;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000441};
442
443struct vmw_legacy_display;
444struct vmw_overlay;
445
Thomas Hellstrom7c4f7782010-06-01 11:38:17 +0200446struct vmw_vga_topology_state {
447 uint32_t width;
448 uint32_t height;
449 uint32_t primary;
450 uint32_t pos_x;
451 uint32_t pos_y;
452};
453
Thomas Hellstromd80efd52015-08-10 10:39:35 -0700454
455/*
456 * struct vmw_otable - Guest Memory OBject table metadata
457 *
458 * @size: Size of the table (page-aligned).
459 * @page_table: Pointer to a struct vmw_mob holding the page table.
460 */
461struct vmw_otable {
462 unsigned long size;
463 struct vmw_mob *page_table;
464 bool enabled;
465};
466
467struct vmw_otable_batch {
468 unsigned num_otables;
469 struct vmw_otable *otables;
470 struct vmw_resource *context;
471 struct ttm_buffer_object *otable_bo;
472};
473
Thomas Hellstromef369902017-08-24 08:06:28 +0200474enum {
475 VMW_IRQTHREAD_FENCE,
476 VMW_IRQTHREAD_CMDBUF,
477 VMW_IRQTHREAD_MAX
478};
479
Deepak Rawat878c6ec2018-12-13 11:44:42 -0800480/**
481 * enum vmw_sm_type - Graphics context capability supported by device.
482 * @VMW_SM_LEGACY: Pre DX context.
483 * @VMW_SM_4: Context support upto SM4.
484 * @VMW_SM_4_1: Context support upto SM4_1.
Deepak Rawat4dec2802018-12-13 11:48:09 -0800485 * @VMW_SM_5: Context support up to SM5.
Deepak Rawat878c6ec2018-12-13 11:44:42 -0800486 * @VMW_SM_MAX: Should be the last.
487 */
488enum vmw_sm_type {
489 VMW_SM_LEGACY = 0,
490 VMW_SM_4,
491 VMW_SM_4_1,
Deepak Rawat4dec2802018-12-13 11:48:09 -0800492 VMW_SM_5,
Deepak Rawat878c6ec2018-12-13 11:44:42 -0800493 VMW_SM_MAX
494};
495
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000496struct vmw_private {
497 struct ttm_bo_device bdev;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000498
499 struct vmw_fifo_state fifo;
500
501 struct drm_device *dev;
Gerd Hoffmann293f86b2019-09-05 09:05:08 +0200502 struct drm_vma_offset_manager vma_manager;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000503 unsigned long vmw_chipset;
504 unsigned int io_start;
505 uint32_t vram_start;
506 uint32_t vram_size;
Thomas Hellstrombc2d6502012-11-21 10:32:36 +0100507 uint32_t prim_bb_mem;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000508 uint32_t mmio_start;
509 uint32_t mmio_size;
510 uint32_t fb_max_width;
511 uint32_t fb_max_height;
Sinclair Yeh35c05122015-06-26 01:42:06 -0700512 uint32_t texture_max_width;
513 uint32_t texture_max_height;
514 uint32_t stdu_max_width;
515 uint32_t stdu_max_height;
Jakob Bornecrantzeb4f9232012-02-09 16:56:46 +0100516 uint32_t initial_width;
517 uint32_t initial_height;
Thomas Hellstromb76ff5e2015-10-28 10:44:04 +0100518 u32 *mmio_virt;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000519 uint32_t capabilities;
Neha Bhende3b4c2512018-06-18 16:44:48 -0700520 uint32_t capabilities2;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000521 uint32_t max_gmr_ids;
Thomas Hellstromfb17f182011-08-31 07:42:53 +0000522 uint32_t max_gmr_pages;
Thomas Hellstrom6da768a2012-11-21 11:06:22 +0100523 uint32_t max_mob_pages;
Charmaine Lee857aea12014-02-12 12:07:38 +0100524 uint32_t max_mob_size;
Thomas Hellstromfb17f182011-08-31 07:42:53 +0000525 uint32_t memory_size;
Thomas Hellstrom135cba02010-10-26 21:21:47 +0200526 bool has_gmr;
Thomas Hellstrom3530bdc2012-11-21 10:49:52 +0100527 bool has_mob;
Thomas Hellstrom496eb6f2015-01-14 02:33:39 -0800528 spinlock_t hw_lock;
529 spinlock_t cap_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;
Thomas Hellstrom93cd1682016-05-03 11:24:35 +0200544 struct mutex global_kms_state_mutex;
Sinclair Yeh36cc79b2017-03-23 11:28:11 -0700545 spinlock_t cursor_lock;
Thomas Hellstromc3b9b162018-03-22 10:26:37 +0100546 struct drm_atomic_state *suspend_state;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000547
548 /*
549 * Context and surface management.
550 */
551
Thomas Hellstrom13289242018-09-26 15:41:52 +0200552 spinlock_t resource_lock;
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000553 struct idr res_idr[vmw_res_max];
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000554
555 /*
556 * A resource manager for kernel-only surfaces and
557 * contexts.
558 */
559
560 struct ttm_object_device *tdev;
561
562 /*
563 * Fencing and IRQs.
564 */
565
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +0000566 atomic_t marker_seq;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000567 wait_queue_head_t fence_queue;
568 wait_queue_head_t fifo_queue;
Thomas Hellstrom496eb6f2015-01-14 02:33:39 -0800569 spinlock_t waiter_lock;
570 int fence_queue_waiters; /* Protected by waiter_lock */
571 int goal_queue_waiters; /* Protected by waiter_lock */
Thomas Hellstromd2e88512015-10-28 19:07:35 +0100572 int cmdbuf_waiters; /* Protected by waiter_lock */
573 int error_waiters; /* Protected by waiter_lock */
574 int fifo_queue_waiters; /* Protected by waiter_lock */
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +0000575 uint32_t last_read_seqno;
Thomas Hellstromae2a1042011-09-01 20:18:44 +0000576 struct vmw_fence_manager *fman;
Thomas Hellstromd2e88512015-10-28 19:07:35 +0100577 uint32_t irq_mask; /* Updates protected by waiter_lock */
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000578
579 /*
580 * Device state
581 */
582
583 uint32_t traces_state;
584 uint32_t enable_state;
585 uint32_t config_done_state;
586
587 /**
588 * Execbuf
589 */
590 /**
591 * Protected by the cmdbuf mutex.
592 */
593
594 struct vmw_sw_context ctx;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000595 struct mutex cmdbuf_mutex;
Thomas Hellstrom173fb7d2013-10-08 02:32:36 -0700596 struct mutex binding_mutex;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000597
598 /**
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000599 * Operating mode.
600 */
601
602 bool stealth;
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200603 bool enable_fb;
Thomas Hellstrom153b3d52015-06-25 10:47:43 -0700604 spinlock_t svga_lock;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000605
606 /**
Thomas Hellstrom9c84aeb2019-05-28 08:08:55 +0200607 * PM management.
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000608 */
Thomas Hellstromd9f36a02010-01-13 22:28:43 +0100609 struct notifier_block pm_nb;
Thomas Hellstrom153b3d52015-06-25 10:47:43 -0700610 bool refuse_hibernation;
Thomas Hellstromc3b9b162018-03-22 10:26:37 +0100611 bool suspend_locked;
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200612
613 struct mutex release_mutex;
Thomas Hellstrom153b3d52015-06-25 10:47:43 -0700614 atomic_t num_fifo_resources;
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +0200615
616 /*
Thomas Hellstrom294adf72014-02-27 12:34:51 +0100617 * Replace this with an rwsem as soon as we have down_xx_interruptible()
618 */
619 struct ttm_lock reservation_sem;
620
621 /*
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +0200622 * Query processing. These members
623 * are protected by the cmdbuf mutex.
624 */
625
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +0200626 struct vmw_buffer_object *dummy_query_bo;
627 struct vmw_buffer_object *pinned_bo;
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +0200628 uint32_t query_cid;
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000629 uint32_t query_cid_valid;
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +0200630 bool dummy_query_bo_pinned;
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +0200631
632 /*
633 * Surface swapping. The "surface_lru" list is protected by the
634 * resource lock in order to be able to destroy a surface and take
635 * it off the lru atomically. "used_memory_size" is currently
636 * protected by the cmdbuf mutex for simplicity.
637 */
638
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000639 struct list_head res_lru[vmw_res_max];
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +0200640 uint32_t used_memory_size;
Thomas Hellstromd92d9852013-10-24 01:49:26 -0700641
642 /*
643 * DMA mapping stuff.
644 */
645 enum vmw_dma_map_mode map_mode;
Thomas Hellstrom3530bdc2012-11-21 10:49:52 +0100646
647 /*
648 * Guest Backed stuff
649 */
Thomas Hellstromd80efd52015-08-10 10:39:35 -0700650 struct vmw_otable_batch otable_batch;
Thomas Hellstrom3eab3d92015-06-25 11:57:56 -0700651
652 struct vmw_cmdbuf_man *cman;
Thomas Hellstromef369902017-08-24 08:06:28 +0200653 DECLARE_BITMAP(irqthread_pending, VMW_IRQTHREAD_MAX);
Thomas Hellstromfd567462018-12-12 11:52:08 +0100654
655 /* Validation memory reservation */
656 struct vmw_validation_mem vvm;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000657};
658
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000659static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res)
660{
661 return container_of(res, struct vmw_surface, res);
662}
663
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000664static inline struct vmw_private *vmw_priv(struct drm_device *dev)
665{
666 return (struct vmw_private *)dev->dev_private;
667}
668
669static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
670{
671 return (struct vmw_fpriv *)file_priv->driver_priv;
672}
673
Thomas Hellstrom496eb6f2015-01-14 02:33:39 -0800674/*
675 * The locking here is fine-grained, so that it is performed once
676 * for every read- and write operation. This is of course costly, but we
677 * don't perform much register access in the timing critical paths anyway.
678 * Instead we have the extra benefit of being sure that we don't forget
679 * the hw lock around register accesses.
680 */
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000681static inline void vmw_write(struct vmw_private *dev_priv,
682 unsigned int offset, uint32_t value)
683{
Thomas Hellstromef369902017-08-24 08:06:28 +0200684 spin_lock(&dev_priv->hw_lock);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000685 outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
686 outl(value, dev_priv->io_start + VMWGFX_VALUE_PORT);
Thomas Hellstromef369902017-08-24 08:06:28 +0200687 spin_unlock(&dev_priv->hw_lock);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000688}
689
690static inline uint32_t vmw_read(struct vmw_private *dev_priv,
691 unsigned int offset)
692{
Thomas Hellstrom496eb6f2015-01-14 02:33:39 -0800693 u32 val;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000694
Thomas Hellstromef369902017-08-24 08:06:28 +0200695 spin_lock(&dev_priv->hw_lock);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000696 outl(offset, dev_priv->io_start + VMWGFX_INDEX_PORT);
697 val = inl(dev_priv->io_start + VMWGFX_VALUE_PORT);
Thomas Hellstromef369902017-08-24 08:06:28 +0200698 spin_unlock(&dev_priv->hw_lock);
Thomas Hellstrom496eb6f2015-01-14 02:33:39 -0800699
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000700 return val;
701}
702
Deepak Rawat878c6ec2018-12-13 11:44:42 -0800703/**
704 * has_sm4_context - Does the device support SM4 context.
705 * @dev_priv: Device private.
706 *
707 * Return: Bool value if device support SM4 context or not.
708 */
709static inline bool has_sm4_context(const struct vmw_private *dev_priv)
710{
711 return (dev_priv->sm_type >= VMW_SM_4);
712}
713
714/**
715 * has_sm4_1_context - Does the device support SM4_1 context.
716 * @dev_priv: Device private.
717 *
718 * Return: Bool value if device support SM4_1 context or not.
719 */
720static inline bool has_sm4_1_context(const struct vmw_private *dev_priv)
721{
722 return (dev_priv->sm_type >= VMW_SM_4_1);
723}
724
Deepak Rawat4dec2802018-12-13 11:48:09 -0800725/**
726 * has_sm5_context - Does the device support SM5 context.
727 * @dev_priv: Device private.
728 *
729 * Return: Bool value if device support SM5 context or not.
730 */
731static inline bool has_sm5_context(const struct vmw_private *dev_priv)
732{
733 return (dev_priv->sm_type >= VMW_SM_5);
734}
735
Thomas Hellstrom153b3d52015-06-25 10:47:43 -0700736extern void vmw_svga_enable(struct vmw_private *dev_priv);
737extern void vmw_svga_disable(struct vmw_private *dev_priv);
738
Thomas Hellstrom30c78bb2010-10-01 10:21:48 +0200739
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000740/**
741 * GMR utilities - vmwgfx_gmr.c
742 */
743
744extern int vmw_gmr_bind(struct vmw_private *dev_priv,
Thomas Hellstromd92d9852013-10-24 01:49:26 -0700745 const struct vmw_sg_table *vsgt,
Thomas Hellstrom135cba02010-10-26 21:21:47 +0200746 unsigned long num_pages,
747 int gmr_id);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000748extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
749
750/**
751 * Resource utilities - vmwgfx_resource.c
752 */
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000753struct vmw_user_resource_conv;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000754
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000755extern void vmw_resource_unreference(struct vmw_resource **p_res);
756extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
Thomas Hellstrom30f82d812014-02-05 08:13:56 +0100757extern struct vmw_resource *
758vmw_resource_reference_unless_doomed(struct vmw_resource *res);
Thomas Hellstromfb80edb2019-03-28 11:36:25 +0100759extern int vmw_resource_validate(struct vmw_resource *res, bool intr,
760 bool dirtying);
Thomas Hellstrom1a4b1722015-06-26 02:03:53 -0700761extern int vmw_resource_reserve(struct vmw_resource *res, bool interruptible,
762 bool no_backup);
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000763extern bool vmw_resource_needs_backup(const struct vmw_resource *res);
Jakob Bornecrantz551a6692011-11-28 13:19:11 +0100764extern int vmw_user_lookup_handle(struct vmw_private *dev_priv,
765 struct ttm_object_file *tfile,
766 uint32_t handle,
767 struct vmw_surface **out_surf,
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +0200768 struct vmw_buffer_object **out_buf);
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000769extern int vmw_user_resource_lookup_handle(
770 struct vmw_private *dev_priv,
771 struct ttm_object_file *tfile,
772 uint32_t handle,
773 const struct vmw_user_resource_conv *converter,
774 struct vmw_resource **p_res);
Thomas Hellstrome8c66ef2018-09-26 16:32:40 +0200775extern struct vmw_resource *
776vmw_user_resource_noref_lookup_handle(struct vmw_private *dev_priv,
777 struct ttm_object_file *tfile,
778 uint32_t handle,
779 const struct vmw_user_resource_conv *
780 converter);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000781extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
782 struct drm_file *file_priv);
783extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
784 struct drm_file *file_priv);
785extern int vmw_user_stream_lookup(struct vmw_private *dev_priv,
786 struct ttm_object_file *tfile,
787 uint32_t *inout_id,
788 struct vmw_resource **out);
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000789extern void vmw_resource_unreserve(struct vmw_resource *res,
Thomas Hellstroma9f58c42019-02-20 08:21:26 +0100790 bool dirty_set,
791 bool dirty,
Thomas Hellstromd80efd52015-08-10 10:39:35 -0700792 bool switch_backup,
Thomas Hellstrome9431ea2018-06-19 15:33:53 +0200793 struct vmw_buffer_object *new_backup,
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000794 unsigned long new_backup_offset);
Sinclair Yehfd11a3c2015-08-10 10:56:15 -0700795extern void vmw_query_move_notify(struct ttm_buffer_object *bo,
Dave Airlie29661412020-08-04 12:56:32 +1000796 struct ttm_resource *mem);
Thomas Hellstrome9431ea2018-06-19 15:33:53 +0200797extern int vmw_query_readback_all(struct vmw_buffer_object *dx_query_mob);
Thomas Hellstromc0951b72012-11-20 12:19:35 +0000798extern void vmw_resource_evict_all(struct vmw_private *dev_priv);
Thomas Hellstrome9431ea2018-06-19 15:33:53 +0200799extern void vmw_resource_unbind_list(struct vmw_buffer_object *vbo);
Thomas Hellstroma0a63942019-03-04 19:37:40 +0100800void vmw_resource_mob_attach(struct vmw_resource *res);
801void vmw_resource_mob_detach(struct vmw_resource *res);
Thomas Hellstromb7468b12019-03-27 10:56:08 +0100802void vmw_resource_dirty_update(struct vmw_resource *res, pgoff_t start,
803 pgoff_t end);
Thomas Hellstromfb80edb2019-03-28 11:36:25 +0100804int vmw_resources_clean(struct vmw_buffer_object *vbo, pgoff_t start,
805 pgoff_t end, pgoff_t *num_prefault);
Thomas Hellstroma0a63942019-03-04 19:37:40 +0100806
807/**
808 * vmw_resource_mob_attached - Whether a resource currently has a mob attached
809 * @res: The resource
810 *
811 * Return: true if the resource has a mob attached, false otherwise.
812 */
813static inline bool vmw_resource_mob_attached(const struct vmw_resource *res)
814{
Thomas Hellstrom61335d72019-03-05 08:24:35 +0100815 return !RB_EMPTY_NODE(&res->mob_node);
Thomas Hellstroma0a63942019-03-04 19:37:40 +0100816}
Thomas Hellstrom79273e12018-01-16 09:33:27 +0100817
Jakob Bornecrantzd991ef02011-10-04 20:13:21 +0200818/**
Thomas Hellstrome8c66ef2018-09-26 16:32:40 +0200819 * vmw_user_resource_noref_release - release a user resource pointer looked up
820 * without reference
821 */
822static inline void vmw_user_resource_noref_release(void)
823{
824 ttm_base_object_noref_release();
825}
826
827/**
Thomas Hellstrome9431ea2018-06-19 15:33:53 +0200828 * Buffer object helper functions - vmwgfx_bo.c
Jakob Bornecrantzd991ef02011-10-04 20:13:21 +0200829 */
Thomas Hellstrome9431ea2018-06-19 15:33:53 +0200830extern int vmw_bo_pin_in_placement(struct vmw_private *vmw_priv,
831 struct vmw_buffer_object *bo,
832 struct ttm_placement *placement,
833 bool interruptible);
834extern int vmw_bo_pin_in_vram(struct vmw_private *dev_priv,
835 struct vmw_buffer_object *buf,
836 bool interruptible);
837extern int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
838 struct vmw_buffer_object *buf,
839 bool interruptible);
840extern int vmw_bo_pin_in_start_of_vram(struct vmw_private *vmw_priv,
841 struct vmw_buffer_object *bo,
Thomas Hellstrom459d0fa2015-06-26 00:25:37 -0700842 bool interruptible);
Thomas Hellstrome9431ea2018-06-19 15:33:53 +0200843extern int vmw_bo_unpin(struct vmw_private *vmw_priv,
844 struct vmw_buffer_object *bo,
845 bool interruptible);
Thomas Hellstromb37a6b92011-10-04 20:13:28 +0200846extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf,
847 SVGAGuestPtr *ptr);
Thomas Hellstrome9431ea2018-06-19 15:33:53 +0200848extern void vmw_bo_pin_reserved(struct vmw_buffer_object *bo, bool pin);
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +0200849extern void vmw_bo_bo_free(struct ttm_buffer_object *bo);
850extern int vmw_bo_init(struct vmw_private *dev_priv,
851 struct vmw_buffer_object *vmw_bo,
852 size_t size, struct ttm_placement *placement,
Guixiong Weibde26a72020-04-25 00:14:39 +1400853 bool interruptible,
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +0200854 void (*bo_free)(struct ttm_buffer_object *bo));
855extern int vmw_user_bo_verify_access(struct ttm_buffer_object *bo,
856 struct ttm_object_file *tfile);
857extern int vmw_user_bo_alloc(struct vmw_private *dev_priv,
858 struct ttm_object_file *tfile,
859 uint32_t size,
860 bool shareable,
861 uint32_t *handle,
862 struct vmw_buffer_object **p_dma_buf,
863 struct ttm_base_object **p_base);
864extern int vmw_user_bo_reference(struct ttm_object_file *tfile,
865 struct vmw_buffer_object *dma_buf,
866 uint32_t *handle);
867extern int vmw_bo_alloc_ioctl(struct drm_device *dev, void *data,
868 struct drm_file *file_priv);
869extern int vmw_bo_unref_ioctl(struct drm_device *dev, void *data,
870 struct drm_file *file_priv);
871extern int vmw_user_bo_synccpu_ioctl(struct drm_device *dev, void *data,
872 struct drm_file *file_priv);
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +0200873extern int vmw_user_bo_lookup(struct ttm_object_file *tfile,
874 uint32_t id, struct vmw_buffer_object **out,
875 struct ttm_base_object **base);
Thomas Hellstrome9431ea2018-06-19 15:33:53 +0200876extern void vmw_bo_fence_single(struct ttm_buffer_object *bo,
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000877 struct vmw_fence_obj *fence);
Thomas Hellstrome9431ea2018-06-19 15:33:53 +0200878extern void *vmw_bo_map_and_cache(struct vmw_buffer_object *vbo);
879extern void vmw_bo_unmap(struct vmw_buffer_object *vbo);
880extern void vmw_bo_move_notify(struct ttm_buffer_object *bo,
Dave Airlie29661412020-08-04 12:56:32 +1000881 struct ttm_resource *mem);
Thomas Hellstrome9431ea2018-06-19 15:33:53 +0200882extern void vmw_bo_swap_notify(struct ttm_buffer_object *bo);
Thomas Hellstromb733bc22018-09-26 16:03:57 +0200883extern struct vmw_buffer_object *
884vmw_user_bo_noref_lookup(struct ttm_object_file *tfile, u32 handle);
885
886/**
887 * vmw_user_bo_noref_release - release a buffer object pointer looked up
888 * without reference
889 */
890static inline void vmw_user_bo_noref_release(void)
891{
892 ttm_base_object_noref_release();
893}
894
Thomas Hellstroma0a63942019-03-04 19:37:40 +0100895/**
896 * vmw_bo_adjust_prio - Adjust the buffer object eviction priority
897 * according to attached resources
898 * @vbo: The struct vmw_buffer_object
899 */
900static inline void vmw_bo_prio_adjust(struct vmw_buffer_object *vbo)
901{
902 int i = ARRAY_SIZE(vbo->res_prios);
903
904 while (i--) {
905 if (vbo->res_prios[i]) {
906 vbo->base.priority = i;
907 return;
908 }
909 }
910
911 vbo->base.priority = 3;
912}
913
914/**
915 * vmw_bo_prio_add - Notify a buffer object of a newly attached resource
916 * eviction priority
917 * @vbo: The struct vmw_buffer_object
918 * @prio: The resource priority
919 *
920 * After being notified, the code assigns the highest resource eviction priority
921 * to the backing buffer object (mob).
922 */
923static inline void vmw_bo_prio_add(struct vmw_buffer_object *vbo, int prio)
924{
925 if (vbo->res_prios[prio]++ == 0)
926 vmw_bo_prio_adjust(vbo);
927}
928
929/**
930 * vmw_bo_prio_del - Notify a buffer object of a resource with a certain
931 * priority being removed
932 * @vbo: The struct vmw_buffer_object
933 * @prio: The resource priority
934 *
935 * After being notified, the code assigns the highest resource eviction priority
936 * to the backing buffer object (mob).
937 */
938static inline void vmw_bo_prio_del(struct vmw_buffer_object *vbo, int prio)
939{
940 if (--vbo->res_prios[prio] == 0)
941 vmw_bo_prio_adjust(vbo);
942}
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000943
944/**
945 * Misc Ioctl functionality - vmwgfx_ioctl.c
946 */
947
948extern int vmw_getparam_ioctl(struct drm_device *dev, void *data,
949 struct drm_file *file_priv);
Thomas Hellstromf63f6a52011-09-01 20:18:41 +0000950extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
951 struct drm_file *file_priv);
Jakob Bornecrantz2fcd5a72011-10-04 20:13:26 +0200952extern int vmw_present_ioctl(struct drm_device *dev, void *data,
953 struct drm_file *file_priv);
954extern int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
955 struct drm_file *file_priv);
Al Viroafc9a422017-07-03 06:39:46 -0400956extern __poll_t vmw_fops_poll(struct file *filp,
Thomas Hellstrom5438ae82011-10-10 12:23:27 +0200957 struct poll_table_struct *wait);
958extern ssize_t vmw_fops_read(struct file *filp, char __user *buffer,
959 size_t count, loff_t *offset);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000960
961/**
962 * Fifo utilities - vmwgfx_fifo.c
963 */
964
965extern int vmw_fifo_init(struct vmw_private *dev_priv,
966 struct vmw_fifo_state *fifo);
967extern void vmw_fifo_release(struct vmw_private *dev_priv,
968 struct vmw_fifo_state *fifo);
Thomas Hellstromd80efd52015-08-10 10:39:35 -0700969extern void *
970vmw_fifo_reserve_dx(struct vmw_private *dev_priv, uint32_t bytes, int ctx_id);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000971extern void vmw_fifo_commit(struct vmw_private *dev_priv, uint32_t bytes);
Thomas Hellstromd80efd52015-08-10 10:39:35 -0700972extern void vmw_fifo_commit_flush(struct vmw_private *dev_priv, uint32_t bytes);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000973extern int vmw_fifo_send_fence(struct vmw_private *dev_priv,
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +0000974 uint32_t *seqno);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000975extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
Jakob Bornecrantz8e19a952010-01-30 03:38:06 +0000976extern bool vmw_fifo_have_3d(struct vmw_private *dev_priv);
Jakob Bornecrantzd7e19582010-05-28 11:21:59 +0200977extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv);
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +0200978extern int vmw_fifo_emit_dummy_query(struct vmw_private *dev_priv,
979 uint32_t cid);
Thomas Hellstrom3eab3d92015-06-25 11:57:56 -0700980extern int vmw_fifo_flush(struct vmw_private *dev_priv,
981 bool interruptible);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000982
Deepak Rawat11c45412019-02-14 16:15:39 -0800983#define VMW_FIFO_RESERVE_DX(__priv, __bytes, __ctx_id) \
984({ \
985 vmw_fifo_reserve_dx(__priv, __bytes, __ctx_id) ? : ({ \
986 DRM_ERROR("FIFO reserve failed at %s for %u bytes\n", \
987 __func__, (unsigned int) __bytes); \
988 NULL; \
989 }); \
990})
991
992#define VMW_FIFO_RESERVE(__priv, __bytes) \
993 VMW_FIFO_RESERVE_DX(__priv, __bytes, SVGA3D_INVALID_ID)
994
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000995/**
996 * TTM glue - vmwgfx_ttm_glue.c
997 */
998
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +0000999extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma);
1000
Thomas Hellstromfd567462018-12-12 11:52:08 +01001001extern void vmw_validation_mem_init_ttm(struct vmw_private *dev_priv,
1002 size_t gran);
Thomas Hellstrom (VMware)94310422020-03-24 18:50:35 +01001003
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001004/**
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +02001005 * TTM buffer object driver - vmwgfx_ttm_buffer.c
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001006 */
1007
Thomas Hellstrom308d17e2013-11-28 01:46:56 -08001008extern const size_t vmw_tt_size;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001009extern struct ttm_placement vmw_vram_placement;
1010extern struct ttm_placement vmw_vram_ne_placement;
Thomas Hellstrom8ba51522010-01-16 16:05:05 +01001011extern struct ttm_placement vmw_vram_sys_placement;
Thomas Hellstrom135cba02010-10-26 21:21:47 +02001012extern struct ttm_placement vmw_vram_gmr_placement;
Jakob Bornecrantzd991ef02011-10-04 20:13:21 +02001013extern struct ttm_placement vmw_vram_gmr_ne_placement;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001014extern struct ttm_placement vmw_sys_placement;
Thomas Hellstrom3530bdc2012-11-21 10:49:52 +01001015extern struct ttm_placement vmw_sys_ne_placement;
Jakob Bornecrantzd991ef02011-10-04 20:13:21 +02001016extern struct ttm_placement vmw_evictable_placement;
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +02001017extern struct ttm_placement vmw_srf_placement;
Thomas Hellstrom96c5f0d2012-11-21 11:19:53 +01001018extern struct ttm_placement vmw_mob_placement;
Thomas Hellstrom3eab3d92015-06-25 11:57:56 -07001019extern struct ttm_placement vmw_mob_ne_placement;
Thomas Hellstromef86cfe2018-01-16 11:07:30 +01001020extern struct ttm_placement vmw_nonfixed_placement;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001021extern struct ttm_bo_driver vmw_bo_driver;
Thomas Hellstrom0fd53cf2013-10-24 13:27:38 -07001022extern const struct vmw_sg_table *
1023vmw_bo_sg_table(struct ttm_buffer_object *bo);
Dave Airlie56dc01f2020-08-04 12:55:34 +10001024extern int vmw_bo_create_and_populate(struct vmw_private *dev_priv,
1025 unsigned long bo_size,
1026 struct ttm_buffer_object **bo_p);
1027
Thomas Hellstromd92d9852013-10-24 01:49:26 -07001028extern void vmw_piter_start(struct vmw_piter *viter,
1029 const struct vmw_sg_table *vsgt,
1030 unsigned long p_offs);
1031
1032/**
1033 * vmw_piter_next - Advance the iterator one page.
1034 *
1035 * @viter: Pointer to the iterator to advance.
1036 *
1037 * Returns false if past the list of pages, true otherwise.
1038 */
1039static inline bool vmw_piter_next(struct vmw_piter *viter)
1040{
1041 return viter->next(viter);
1042}
1043
1044/**
1045 * vmw_piter_dma_addr - Return the DMA address of the current page.
1046 *
1047 * @viter: Pointer to the iterator
1048 *
1049 * Returns the DMA address of the page pointed to by @viter.
1050 */
1051static inline dma_addr_t vmw_piter_dma_addr(struct vmw_piter *viter)
1052{
1053 return viter->dma_address(viter);
1054}
1055
1056/**
1057 * vmw_piter_page - Return a pointer to the current page.
1058 *
1059 * @viter: Pointer to the iterator
1060 *
1061 * Returns the DMA address of the page pointed to by @viter.
1062 */
1063static inline struct page *vmw_piter_page(struct vmw_piter *viter)
1064{
1065 return viter->page(viter);
1066}
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001067
1068/**
1069 * Command submission - vmwgfx_execbuf.c
1070 */
1071
Emil Velikovcbfbe472019-05-22 17:41:17 +01001072extern int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
1073 struct drm_file *file_priv);
Thomas Hellstrom922ade02011-10-04 20:13:17 +02001074extern int vmw_execbuf_process(struct drm_file *file_priv,
1075 struct vmw_private *dev_priv,
1076 void __user *user_commands,
1077 void *kernel_commands,
1078 uint32_t command_size,
1079 uint64_t throttle_us,
Thomas Hellstromd80efd52015-08-10 10:39:35 -07001080 uint32_t dx_context_handle,
Thomas Hellstrom922ade02011-10-04 20:13:17 +02001081 struct drm_vmw_fence_rep __user
Jakob Bornecrantzbb1bd2f2012-02-09 16:56:43 +01001082 *user_fence_rep,
Sinclair Yehc906965d2017-07-05 01:49:32 -07001083 struct vmw_fence_obj **out_fence,
1084 uint32_t flags);
Thomas Hellstromc0951b72012-11-20 12:19:35 +00001085extern void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv,
1086 struct vmw_fence_obj *fence);
1087extern void vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv);
Thomas Hellstrome2fa3a72011-10-04 20:13:30 +02001088
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +02001089extern int vmw_execbuf_fence_commands(struct drm_file *file_priv,
1090 struct vmw_private *dev_priv,
1091 struct vmw_fence_obj **p_fence,
1092 uint32_t *p_handle);
Thomas Hellstrom57c5ee72011-10-10 12:23:26 +02001093extern void vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
1094 struct vmw_fpriv *vmw_fp,
1095 int ret,
1096 struct drm_vmw_fence_rep __user
1097 *user_fence_rep,
1098 struct vmw_fence_obj *fence,
Sinclair Yehc906965d2017-07-05 01:49:32 -07001099 uint32_t fence_handle,
1100 int32_t out_fence_fd,
1101 struct sync_file *sync_file);
Thomas Hellstrom65b97a22017-08-24 08:06:29 +02001102bool vmw_cmd_describe(const void *buf, u32 *size, char const **cmd);
Thomas Hellstrom5bb39e82011-10-04 20:13:33 +02001103
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001104/**
1105 * IRQs and wating - vmwgfx_irq.c
1106 */
1107
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +00001108extern int vmw_wait_seqno(struct vmw_private *dev_priv, bool lazy,
Sinclair Yehc8261a92015-06-26 01:23:42 -07001109 uint32_t seqno, bool interruptible,
1110 unsigned long timeout);
Thomas Hellstrome3001732017-08-24 08:06:27 +02001111extern int vmw_irq_install(struct drm_device *dev, int irq);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001112extern void vmw_irq_uninstall(struct drm_device *dev);
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +00001113extern bool vmw_seqno_passed(struct vmw_private *dev_priv,
1114 uint32_t seqno);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001115extern int vmw_fallback_wait(struct vmw_private *dev_priv,
1116 bool lazy,
1117 bool fifo_idle,
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +00001118 uint32_t seqno,
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001119 bool interruptible,
1120 unsigned long timeout);
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +00001121extern void vmw_update_seqno(struct vmw_private *dev_priv,
Thomas Hellstrom1925d452010-05-28 11:21:57 +02001122 struct vmw_fifo_state *fifo_state);
Thomas Hellstromae2a1042011-09-01 20:18:44 +00001123extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
1124extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
Thomas Hellstrom57c5ee72011-10-10 12:23:26 +02001125extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
1126extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv);
Thomas Hellstrom3eab3d92015-06-25 11:57:56 -07001127extern void vmw_generic_waiter_add(struct vmw_private *dev_priv, u32 flag,
1128 int *waiter_count);
1129extern void vmw_generic_waiter_remove(struct vmw_private *dev_priv,
1130 u32 flag, int *waiter_count);
Thomas Hellstrom1925d452010-05-28 11:21:57 +02001131
1132/**
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +00001133 * Rudimentary fence-like objects currently used only for throttling -
1134 * vmwgfx_marker.c
Thomas Hellstrom1925d452010-05-28 11:21:57 +02001135 */
1136
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +00001137extern void vmw_marker_queue_init(struct vmw_marker_queue *queue);
1138extern void vmw_marker_queue_takedown(struct vmw_marker_queue *queue);
1139extern int vmw_marker_push(struct vmw_marker_queue *queue,
Sinclair Yehc8261a92015-06-26 01:23:42 -07001140 uint32_t seqno);
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +00001141extern int vmw_marker_pull(struct vmw_marker_queue *queue,
Sinclair Yehc8261a92015-06-26 01:23:42 -07001142 uint32_t signaled_seqno);
Thomas Hellstrom1925d452010-05-28 11:21:57 +02001143extern int vmw_wait_lag(struct vmw_private *dev_priv,
Thomas Hellstrom6bcd8d3c2011-09-01 20:18:42 +00001144 struct vmw_marker_queue *queue, uint32_t us);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001145
1146/**
1147 * Kernel framebuffer - vmwgfx_fb.c
1148 */
1149
1150int vmw_fb_init(struct vmw_private *vmw_priv);
1151int vmw_fb_close(struct vmw_private *dev_priv);
1152int vmw_fb_off(struct vmw_private *vmw_priv);
1153int vmw_fb_on(struct vmw_private *vmw_priv);
1154
1155/**
1156 * Kernel modesetting - vmwgfx_kms.c
1157 */
1158
1159int vmw_kms_init(struct vmw_private *dev_priv);
1160int vmw_kms_close(struct vmw_private *dev_priv);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001161int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
1162 struct drm_file *file_priv);
1163void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
1164void vmw_kms_cursor_snoop(struct vmw_surface *srf,
1165 struct ttm_object_file *tfile,
1166 struct ttm_buffer_object *bo,
1167 SVGA3dCmdHeader *header);
Michel Dänzer0bef23f2011-08-31 07:42:50 +00001168int vmw_kms_write_svga(struct vmw_private *vmw_priv,
1169 unsigned width, unsigned height, unsigned pitch,
1170 unsigned bpp, unsigned depth);
Thomas Hellstrome133e7372010-10-05 12:43:04 +02001171bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
1172 uint32_t pitch,
1173 uint32_t height);
Thomas Zimmermann4bebe912020-01-23 14:59:41 +01001174u32 vmw_get_vblank_counter(struct drm_crtc *crtc);
1175int vmw_enable_vblank(struct drm_crtc *crtc);
1176void vmw_disable_vblank(struct drm_crtc *crtc);
Jakob Bornecrantz2fcd5a72011-10-04 20:13:26 +02001177int vmw_kms_present(struct vmw_private *dev_priv,
1178 struct drm_file *file_priv,
1179 struct vmw_framebuffer *vfb,
1180 struct vmw_surface *surface,
1181 uint32_t sid, int32_t destX, int32_t destY,
1182 struct drm_vmw_rect *clips,
1183 uint32_t num_clips);
Thomas Hellstromcd2b89e2011-10-25 23:35:53 +02001184int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
1185 struct drm_file *file_priv);
Thomas Hellstrom8fbf9d92015-11-26 19:45:16 +01001186void vmw_kms_legacy_hotspot_clear(struct vmw_private *dev_priv);
Thomas Hellstromc3b9b162018-03-22 10:26:37 +01001187int vmw_kms_suspend(struct drm_device *dev);
1188int vmw_kms_resume(struct drm_device *dev);
Thomas Hellstrom140bcaa2018-03-08 10:07:37 +01001189void vmw_kms_lost_device(struct drm_device *dev);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001190
Dave Airlie5e1782d2012-08-28 01:53:54 +00001191int vmw_dumb_create(struct drm_file *file_priv,
1192 struct drm_device *dev,
1193 struct drm_mode_create_dumb *args);
1194
1195int vmw_dumb_map_offset(struct drm_file *file_priv,
1196 struct drm_device *dev, uint32_t handle,
1197 uint64_t *offset);
1198int vmw_dumb_destroy(struct drm_file *file_priv,
1199 struct drm_device *dev,
1200 uint32_t handle);
Thomas Hellstrom1a4b1722015-06-26 02:03:53 -07001201extern int vmw_resource_pin(struct vmw_resource *res, bool interruptible);
Thomas Hellstromed933942015-03-02 23:26:06 -08001202extern void vmw_resource_unpin(struct vmw_resource *res);
Thomas Hellstromd80efd52015-08-10 10:39:35 -07001203extern enum vmw_res_type vmw_res_type(const struct vmw_resource *res);
Thomas Hellstromed933942015-03-02 23:26:06 -08001204
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001205/**
1206 * Overlay control - vmwgfx_overlay.c
1207 */
1208
1209int vmw_overlay_init(struct vmw_private *dev_priv);
1210int vmw_overlay_close(struct vmw_private *dev_priv);
1211int vmw_overlay_ioctl(struct drm_device *dev, void *data,
1212 struct drm_file *file_priv);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001213int vmw_overlay_resume_all(struct vmw_private *dev_priv);
1214int vmw_overlay_pause_all(struct vmw_private *dev_priv);
1215int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
1216int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
1217int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
1218int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
1219
1220/**
Thomas Hellstrom135cba02010-10-26 21:21:47 +02001221 * GMR Id manager
1222 */
1223
Dave Airlie62161772020-08-04 12:55:54 +10001224int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type);
Dave Airlie6eee6672020-08-04 12:56:06 +10001225void vmw_gmrid_man_fini(struct vmw_private *dev_priv, int type);
Thomas Hellstrom135cba02010-10-26 21:21:47 +02001226
1227/**
Thomas Hellstrom69977ff2013-11-13 01:50:46 -08001228 * Prime - vmwgfx_prime.c
1229 */
1230
1231extern const struct dma_buf_ops vmw_prime_dmabuf_ops;
1232extern int vmw_prime_fd_to_handle(struct drm_device *dev,
1233 struct drm_file *file_priv,
1234 int fd, u32 *handle);
1235extern int vmw_prime_handle_to_fd(struct drm_device *dev,
1236 struct drm_file *file_priv,
1237 uint32_t handle, uint32_t flags,
1238 int *prime_fd);
1239
Thomas Hellstrom3530bdc2012-11-21 10:49:52 +01001240/*
1241 * MemoryOBject management - vmwgfx_mob.c
1242 */
1243struct vmw_mob;
1244extern int vmw_mob_bind(struct vmw_private *dev_priv, struct vmw_mob *mob,
Thomas Hellstrom0fd53cf2013-10-24 13:27:38 -07001245 const struct vmw_sg_table *vsgt,
1246 unsigned long num_data_pages, int32_t mob_id);
Thomas Hellstrom3530bdc2012-11-21 10:49:52 +01001247extern void vmw_mob_unbind(struct vmw_private *dev_priv,
1248 struct vmw_mob *mob);
1249extern void vmw_mob_destroy(struct vmw_mob *mob);
1250extern struct vmw_mob *vmw_mob_create(unsigned long data_pages);
1251extern int vmw_otables_setup(struct vmw_private *dev_priv);
1252extern void vmw_otables_takedown(struct vmw_private *dev_priv);
Thomas Hellstrom69977ff2013-11-13 01:50:46 -08001253
Thomas Hellstromc74c1622012-11-21 12:10:26 +01001254/*
Thomas Hellstrom7086d092012-11-21 12:20:53 +01001255 * Context management - vmwgfx_context.c
1256 */
1257
1258extern const struct vmw_user_resource_conv *user_context_converter;
1259
Thomas Hellstrom7086d092012-11-21 12:20:53 +01001260extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
1261 struct drm_file *file_priv);
Thomas Hellstromd80efd52015-08-10 10:39:35 -07001262extern int vmw_extended_context_define_ioctl(struct drm_device *dev, void *data,
1263 struct drm_file *file_priv);
Thomas Hellstrom7086d092012-11-21 12:20:53 +01001264extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
1265 struct drm_file *file_priv);
Thomas Hellstrom30f82d812014-02-05 08:13:56 +01001266extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
Thomas Hellstrom18e4a462014-06-09 12:39:22 +02001267extern struct vmw_cmdbuf_res_manager *
1268vmw_context_res_man(struct vmw_resource *ctx);
Thomas Hellstromd80efd52015-08-10 10:39:35 -07001269extern struct vmw_resource *vmw_context_cotable(struct vmw_resource *ctx,
1270 SVGACOTableType cotable_type);
1271extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
1272struct vmw_ctx_binding_state;
1273extern struct vmw_ctx_binding_state *
1274vmw_context_binding_state(struct vmw_resource *ctx);
1275extern void vmw_dx_context_scrub_cotables(struct vmw_resource *ctx,
1276 bool readback);
Sinclair Yehfd11a3c2015-08-10 10:56:15 -07001277extern int vmw_context_bind_dx_query(struct vmw_resource *ctx_res,
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +02001278 struct vmw_buffer_object *mob);
1279extern struct vmw_buffer_object *
Sinclair Yehfd11a3c2015-08-10 10:56:15 -07001280vmw_context_get_dx_query_mob(struct vmw_resource *ctx_res);
1281
Thomas Hellstromd80efd52015-08-10 10:39:35 -07001282
Thomas Hellstrom7086d092012-11-21 12:20:53 +01001283/*
1284 * Surface management - vmwgfx_surface.c
1285 */
1286
1287extern const struct vmw_user_resource_conv *user_surface_converter;
1288
Thomas Hellstrom7086d092012-11-21 12:20:53 +01001289extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data,
1290 struct drm_file *file_priv);
1291extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
1292 struct drm_file *file_priv);
1293extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,
1294 struct drm_file *file_priv);
1295extern int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data,
1296 struct drm_file *file_priv);
1297extern int vmw_gb_surface_reference_ioctl(struct drm_device *dev, void *data,
1298 struct drm_file *file_priv);
Sinclair Yeh233826a2015-03-05 01:06:13 -08001299int vmw_surface_gb_priv_define(struct drm_device *dev,
1300 uint32_t user_accounting_size,
Deepak Rawat397a1112018-06-20 14:25:07 -07001301 SVGA3dSurfaceAllFlags svga3d_flags,
Sinclair Yeh233826a2015-03-05 01:06:13 -08001302 SVGA3dSurfaceFormat format,
1303 bool for_scanout,
1304 uint32_t num_mip_levels,
1305 uint32_t multisample_count,
Thomas Hellstromd80efd52015-08-10 10:39:35 -07001306 uint32_t array_size,
Sinclair Yeh233826a2015-03-05 01:06:13 -08001307 struct drm_vmw_size size,
Deepak Rawat14b1c332018-06-20 14:48:35 -07001308 SVGA3dMSPattern multisample_pattern,
1309 SVGA3dMSQualityLevel quality_level,
Sinclair Yeh233826a2015-03-05 01:06:13 -08001310 struct vmw_surface **srf_out);
Deepak Rawat14b1c332018-06-20 14:48:35 -07001311extern int vmw_gb_surface_define_ext_ioctl(struct drm_device *dev,
1312 void *data,
1313 struct drm_file *file_priv);
1314extern int vmw_gb_surface_reference_ext_ioctl(struct drm_device *dev,
1315 void *data,
1316 struct drm_file *file_priv);
Thomas Hellstrom7086d092012-11-21 12:20:53 +01001317
Deepak Rawat504901d2019-04-29 14:55:44 -07001318int vmw_gb_surface_define(struct vmw_private *dev_priv,
1319 uint32_t user_accounting_size,
1320 const struct vmw_surface_metadata *req,
1321 struct vmw_surface **srf_out);
1322
Thomas Hellstrom7086d092012-11-21 12:20:53 +01001323/*
Thomas Hellstromc74c1622012-11-21 12:10:26 +01001324 * Shader management - vmwgfx_shader.c
1325 */
1326
Thomas Hellstrom7086d092012-11-21 12:20:53 +01001327extern const struct vmw_user_resource_conv *user_shader_converter;
1328
Thomas Hellstromc74c1622012-11-21 12:10:26 +01001329extern int vmw_shader_define_ioctl(struct drm_device *dev, void *data,
1330 struct drm_file *file_priv);
1331extern int vmw_shader_destroy_ioctl(struct drm_device *dev, void *data,
1332 struct drm_file *file_priv);
Thomas Hellstrom18e4a462014-06-09 12:39:22 +02001333extern int vmw_compat_shader_add(struct vmw_private *dev_priv,
1334 struct vmw_cmdbuf_res_manager *man,
Thomas Hellstromd5bde952014-01-31 10:12:10 +01001335 u32 user_key, const void *bytecode,
1336 SVGA3dShaderType shader_type,
1337 size_t size,
Thomas Hellstromd5bde952014-01-31 10:12:10 +01001338 struct list_head *list);
Thomas Hellstromd80efd52015-08-10 10:39:35 -07001339extern int vmw_shader_remove(struct vmw_cmdbuf_res_manager *man,
1340 u32 user_key, SVGA3dShaderType shader_type,
1341 struct list_head *list);
1342extern int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,
1343 struct vmw_resource *ctx,
1344 u32 user_key,
1345 SVGA3dShaderType shader_type,
1346 struct list_head *list);
1347extern void vmw_dx_shader_cotable_list_scrub(struct vmw_private *dev_priv,
1348 struct list_head *list,
1349 bool readback);
1350
Thomas Hellstrom18e4a462014-06-09 12:39:22 +02001351extern struct vmw_resource *
Thomas Hellstromd80efd52015-08-10 10:39:35 -07001352vmw_shader_lookup(struct vmw_cmdbuf_res_manager *man,
1353 u32 user_key, SVGA3dShaderType shader_type);
Thomas Hellstrom18e4a462014-06-09 12:39:22 +02001354
1355/*
Deepak Rawate8bead92018-12-13 14:04:31 -08001356 * Streamoutput management
1357 */
1358struct vmw_resource *
1359vmw_dx_streamoutput_lookup(struct vmw_cmdbuf_res_manager *man,
1360 u32 user_key);
1361int vmw_dx_streamoutput_add(struct vmw_cmdbuf_res_manager *man,
1362 struct vmw_resource *ctx,
1363 SVGA3dStreamOutputId user_key,
1364 struct list_head *list);
1365void vmw_dx_streamoutput_set_size(struct vmw_resource *res, u32 size);
1366int vmw_dx_streamoutput_remove(struct vmw_cmdbuf_res_manager *man,
1367 SVGA3dStreamOutputId user_key,
1368 struct list_head *list);
1369void vmw_dx_streamoutput_cotable_list_scrub(struct vmw_private *dev_priv,
1370 struct list_head *list,
1371 bool readback);
1372
1373/*
Thomas Hellstrom18e4a462014-06-09 12:39:22 +02001374 * Command buffer managed resources - vmwgfx_cmdbuf_res.c
1375 */
1376
1377extern struct vmw_cmdbuf_res_manager *
1378vmw_cmdbuf_res_man_create(struct vmw_private *dev_priv);
1379extern void vmw_cmdbuf_res_man_destroy(struct vmw_cmdbuf_res_manager *man);
1380extern size_t vmw_cmdbuf_res_man_size(void);
1381extern struct vmw_resource *
1382vmw_cmdbuf_res_lookup(struct vmw_cmdbuf_res_manager *man,
1383 enum vmw_cmdbuf_res_type res_type,
1384 u32 user_key);
1385extern void vmw_cmdbuf_res_revert(struct list_head *list);
1386extern void vmw_cmdbuf_res_commit(struct list_head *list);
1387extern int vmw_cmdbuf_res_add(struct vmw_cmdbuf_res_manager *man,
1388 enum vmw_cmdbuf_res_type res_type,
1389 u32 user_key,
1390 struct vmw_resource *res,
1391 struct list_head *list);
1392extern int vmw_cmdbuf_res_remove(struct vmw_cmdbuf_res_manager *man,
1393 enum vmw_cmdbuf_res_type res_type,
1394 u32 user_key,
Thomas Hellstromd80efd52015-08-10 10:39:35 -07001395 struct list_head *list,
1396 struct vmw_resource **res);
Thomas Hellstromd5bde952014-01-31 10:12:10 +01001397
Thomas Hellstromd80efd52015-08-10 10:39:35 -07001398/*
1399 * COTable management - vmwgfx_cotable.c
1400 */
1401extern const SVGACOTableType vmw_cotable_scrub_order[];
1402extern struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv,
1403 struct vmw_resource *ctx,
1404 u32 type);
1405extern int vmw_cotable_notify(struct vmw_resource *res, int id);
1406extern int vmw_cotable_scrub(struct vmw_resource *res, bool readback);
1407extern void vmw_cotable_add_resource(struct vmw_resource *ctx,
1408 struct list_head *head);
Thomas Hellstromc74c1622012-11-21 12:10:26 +01001409
Thomas Hellstrom3eab3d92015-06-25 11:57:56 -07001410/*
1411 * Command buffer managerment vmwgfx_cmdbuf.c
1412 */
1413struct vmw_cmdbuf_man;
1414struct vmw_cmdbuf_header;
1415
1416extern struct vmw_cmdbuf_man *
1417vmw_cmdbuf_man_create(struct vmw_private *dev_priv);
1418extern int vmw_cmdbuf_set_pool_size(struct vmw_cmdbuf_man *man,
1419 size_t size, size_t default_size);
1420extern void vmw_cmdbuf_remove_pool(struct vmw_cmdbuf_man *man);
1421extern void vmw_cmdbuf_man_destroy(struct vmw_cmdbuf_man *man);
1422extern int vmw_cmdbuf_idle(struct vmw_cmdbuf_man *man, bool interruptible,
1423 unsigned long timeout);
1424extern void *vmw_cmdbuf_reserve(struct vmw_cmdbuf_man *man, size_t size,
1425 int ctx_id, bool interruptible,
1426 struct vmw_cmdbuf_header *header);
1427extern void vmw_cmdbuf_commit(struct vmw_cmdbuf_man *man, size_t size,
1428 struct vmw_cmdbuf_header *header,
1429 bool flush);
Thomas Hellstrom3eab3d92015-06-25 11:57:56 -07001430extern void *vmw_cmdbuf_alloc(struct vmw_cmdbuf_man *man,
1431 size_t size, bool interruptible,
1432 struct vmw_cmdbuf_header **p_header);
1433extern void vmw_cmdbuf_header_free(struct vmw_cmdbuf_header *header);
1434extern int vmw_cmdbuf_cur_flush(struct vmw_cmdbuf_man *man,
1435 bool interruptible);
Thomas Hellstromef369902017-08-24 08:06:28 +02001436extern void vmw_cmdbuf_irqthread(struct vmw_cmdbuf_man *man);
Thomas Hellstrombf6f0362012-11-09 12:26:15 +00001437
Thomas Hellstrom79273e12018-01-16 09:33:27 +01001438/* CPU blit utilities - vmwgfx_blit.c */
1439
1440/**
1441 * struct vmw_diff_cpy - CPU blit information structure
1442 *
1443 * @rect: The output bounding box rectangle.
1444 * @line: The current line of the blit.
1445 * @line_offset: Offset of the current line segment.
1446 * @cpp: Bytes per pixel (granularity information).
1447 * @memcpy: Which memcpy function to use.
1448 */
1449struct vmw_diff_cpy {
1450 struct drm_rect rect;
1451 size_t line;
1452 size_t line_offset;
1453 int cpp;
1454 void (*do_cpy)(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src,
1455 size_t n);
1456};
1457
1458#define VMW_CPU_BLIT_INITIALIZER { \
1459 .do_cpy = vmw_memcpy, \
1460}
1461
1462#define VMW_CPU_BLIT_DIFF_INITIALIZER(_cpp) { \
1463 .line = 0, \
1464 .line_offset = 0, \
1465 .rect = { .x1 = INT_MAX/2, \
1466 .y1 = INT_MAX/2, \
1467 .x2 = INT_MIN/2, \
1468 .y2 = INT_MIN/2 \
1469 }, \
1470 .cpp = _cpp, \
1471 .do_cpy = vmw_diff_memcpy, \
1472}
1473
1474void vmw_diff_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src,
1475 size_t n);
1476
1477void vmw_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src, size_t n);
1478
1479int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
1480 u32 dst_offset, u32 dst_stride,
1481 struct ttm_buffer_object *src,
1482 u32 src_offset, u32 src_stride,
1483 u32 w, u32 h,
1484 struct vmw_diff_cpy *diff);
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001485
Thomas Hellstrom6ff67ae2018-06-21 09:39:21 +02001486/* Host messaging -vmwgfx_msg.c: */
1487int vmw_host_get_guestinfo(const char *guest_info_param,
1488 char *buffer, size_t *length);
1489int vmw_host_log(const char *log);
Roland Scheideggercb92a322019-11-21 17:44:56 +01001490int vmw_msg_ioctl(struct drm_device *dev, void *data,
1491 struct drm_file *file_priv);
Thomas Hellstrom6ff67ae2018-06-21 09:39:21 +02001492
Deepak Rawat5724f892019-02-11 11:46:27 -08001493/* VMW logging */
1494
1495/**
1496 * VMW_DEBUG_USER - Debug output for user-space debugging.
1497 *
1498 * @fmt: printf() like format string.
1499 *
1500 * This macro is for logging user-space error and debugging messages for e.g.
1501 * command buffer execution errors due to malformed commands, invalid context,
1502 * etc.
1503 */
1504#define VMW_DEBUG_USER(fmt, ...) \
1505 DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__)
1506
Thomas Hellstromb7468b12019-03-27 10:56:08 +01001507/* Resource dirtying - vmwgfx_page_dirty.c */
1508void vmw_bo_dirty_scan(struct vmw_buffer_object *vbo);
1509int vmw_bo_dirty_add(struct vmw_buffer_object *vbo);
1510void vmw_bo_dirty_transfer_to_res(struct vmw_resource *res);
1511void vmw_bo_dirty_clear_res(struct vmw_resource *res);
1512void vmw_bo_dirty_release(struct vmw_buffer_object *vbo);
Thomas Hellstromfb80edb2019-03-28 11:36:25 +01001513void vmw_bo_dirty_unmap(struct vmw_buffer_object *vbo,
1514 pgoff_t start, pgoff_t end);
Thomas Hellstromb7468b12019-03-27 10:56:08 +01001515vm_fault_t vmw_bo_vm_fault(struct vm_fault *vmf);
1516vm_fault_t vmw_bo_vm_mkwrite(struct vm_fault *vmf);
Thomas Hellstrom (VMware)75390282020-03-24 18:48:55 +01001517#ifdef CONFIG_TRANSPARENT_HUGEPAGE
1518vm_fault_t vmw_bo_vm_huge_fault(struct vm_fault *vmf,
1519 enum page_entry_size pe_size);
1520#endif
Thomas Hellstromb7468b12019-03-27 10:56:08 +01001521
Thomas Hellstrom (VMware)7546f7f2020-03-24 18:50:12 +01001522/* Transparent hugepage support - vmwgfx_thp.c */
1523#ifdef CONFIG_TRANSPARENT_HUGEPAGE
Dave Airlie252f8d72020-08-04 12:55:53 +10001524extern int vmw_thp_init(struct vmw_private *dev_priv);
Dave Airliee0830702020-08-04 12:56:01 +10001525void vmw_thp_fini(struct vmw_private *dev_priv);
Thomas Hellstrom (VMware)7546f7f2020-03-24 18:50:12 +01001526#endif
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001527
1528/**
1529 * VMW_DEBUG_KMS - Debug output for kernel mode-setting
1530 *
1531 * This macro is for debugging vmwgfx mode-setting code.
1532 */
1533#define VMW_DEBUG_KMS(fmt, ...) \
1534 DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__)
1535
1536/**
1537 * Inline helper functions
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +02001538 */
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001539
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +02001540static inline void vmw_surface_unreference(struct vmw_surface **srf)
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001541{
Thomas Hellstrombf6f0362012-11-09 12:26:15 +00001542 struct vmw_surface *tmp_srf = *srf;
1543 struct vmw_resource *res = &tmp_srf->res;
Thomas Zimmermann6034d9d2019-01-25 12:02:09 +01001544 *srf = NULL;
Thomas Hellstrombf6f0362012-11-09 12:26:15 +00001545
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001546 vmw_resource_unreference(&res);
1547}
Thomas Hellstromf1d34bf2018-06-19 15:02:16 +02001548
1549static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001550{
Thomas Zimmermann2d18cb92019-01-25 12:02:08 +01001551 (void) vmw_resource_reference(&srf->res);
1552 return srf;
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001553}
1554
Thomas Hellstromae2a1042011-09-01 20:18:44 +00001555static inline void vmw_bo_unreference(struct vmw_buffer_object **buf)
1556{
Christian König27eb1fa2018-10-19 13:49:05 +02001557 struct vmw_buffer_object *tmp_buf = *buf;
Thomas Hellstromae2a1042011-09-01 20:18:44 +00001558
Thomas Hellstrom153b3d52015-06-25 10:47:43 -07001559 *buf = NULL;
1560 if (tmp_buf != NULL) {
1561 ttm_bo_put(&tmp_buf->base);
1562 }
1563}
1564
1565static inline struct vmw_buffer_object *
1566vmw_bo_reference(struct vmw_buffer_object *buf)
1567{
1568 ttm_bo_get(&buf->base);
Thomas Hellstromb76ff5e2015-10-28 10:44:04 +01001569 return buf;
1570}
1571
1572static inline struct ttm_mem_global *vmw_mem_glob(struct vmw_private *dev_priv)
1573{
1574 return &ttm_mem_glob;
1575}
1576
1577static inline void vmw_fifo_resource_inc(struct vmw_private *dev_priv)
1578{
1579 atomic_inc(&dev_priv->num_fifo_resources);
1580}
1581
1582static inline void vmw_fifo_resource_dec(struct vmw_private *dev_priv)
1583{
1584 atomic_dec(&dev_priv->num_fifo_resources);
1585}
1586
1587/**
1588 * vmw_mmio_read - Perform a MMIO read from volatile memory
1589 *
1590 * @addr: The address to read from
1591 *
1592 * This function is intended to be equivalent to ioread32() on
1593 * memremap'd memory, but without byteswapping.
1594 */
Jakob Bornecrantzfb1d9732009-12-10 00:19:58 +00001595static inline u32 vmw_mmio_read(u32 *addr)
1596{
1597 return READ_ONCE(*addr);
1598}
1599
1600/**
1601 * vmw_mmio_write - Perform a MMIO write to volatile memory
1602 *
1603 * @addr: The address to write to
1604 *
1605 * This function is intended to be equivalent to iowrite32 on
1606 * memremap'd memory, but without byteswapping.
1607 */
1608static inline void vmw_mmio_write(u32 value, u32 *addr)
1609{
1610 WRITE_ONCE(*addr, value);
1611}
1612#endif