1dff96888SDirk Hohndel (VMware) /* SPDX-License-Identifier: GPL-2.0 OR MIT */
2fb1d9738SJakob Bornecrantz /**************************************************************************
3fb1d9738SJakob Bornecrantz  *
409881d29SZack Rusin  * Copyright 2009-2023 VMware, Inc., Palo Alto, CA., USA
5fb1d9738SJakob Bornecrantz  *
6fb1d9738SJakob Bornecrantz  * Permission is hereby granted, free of charge, to any person obtaining a
7fb1d9738SJakob Bornecrantz  * copy of this software and associated documentation files (the
8fb1d9738SJakob Bornecrantz  * "Software"), to deal in the Software without restriction, including
9fb1d9738SJakob Bornecrantz  * without limitation the rights to use, copy, modify, merge, publish,
10fb1d9738SJakob Bornecrantz  * distribute, sub license, and/or sell copies of the Software, and to
11fb1d9738SJakob Bornecrantz  * permit persons to whom the Software is furnished to do so, subject to
12fb1d9738SJakob Bornecrantz  * the following conditions:
13fb1d9738SJakob Bornecrantz  *
14fb1d9738SJakob Bornecrantz  * The above copyright notice and this permission notice (including the
15fb1d9738SJakob Bornecrantz  * next paragraph) shall be included in all copies or substantial portions
16fb1d9738SJakob Bornecrantz  * of the Software.
17fb1d9738SJakob Bornecrantz  *
18fb1d9738SJakob Bornecrantz  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19fb1d9738SJakob Bornecrantz  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20fb1d9738SJakob Bornecrantz  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21fb1d9738SJakob Bornecrantz  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22fb1d9738SJakob Bornecrantz  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23fb1d9738SJakob Bornecrantz  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24fb1d9738SJakob Bornecrantz  * USE OR OTHER DEALINGS IN THE SOFTWARE.
25fb1d9738SJakob Bornecrantz  *
26fb1d9738SJakob Bornecrantz  **************************************************************************/
27fb1d9738SJakob Bornecrantz 
28fb1d9738SJakob Bornecrantz #ifndef _VMWGFX_DRV_H_
29fb1d9738SJakob Bornecrantz #define _VMWGFX_DRV_H_
30fb1d9738SJakob Bornecrantz 
31760285e7SDavid Howells #include <linux/suspend.h>
32d5c1f011SSam Ravnborg #include <linux/sync_file.h>
339e931f2eSMaaz Mombasawala #include <linux/hashtable.h>
34d5c1f011SSam Ravnborg 
35d5c1f011SSam Ravnborg #include <drm/drm_auth.h>
36d5c1f011SSam Ravnborg #include <drm/drm_device.h>
37d5c1f011SSam Ravnborg #include <drm/drm_file.h>
38d5c1f011SSam Ravnborg #include <drm/drm_rect.h>
39d5c1f011SSam Ravnborg 
40760285e7SDavid Howells #include <drm/ttm/ttm_execbuf_util.h>
41a3185f91SChristian König #include <drm/ttm/ttm_tt.h>
42a3185f91SChristian König #include <drm/ttm/ttm_placement.h>
43a3185f91SChristian König #include <drm/ttm/ttm_bo.h>
44d5c1f011SSam Ravnborg 
45d5c1f011SSam Ravnborg #include "ttm_object.h"
46d5c1f011SSam Ravnborg 
47d5c1f011SSam Ravnborg #include "vmwgfx_fence.h"
48d5c1f011SSam Ravnborg #include "vmwgfx_reg.h"
49d5c1f011SSam Ravnborg #include "vmwgfx_validation.h"
50d5c1f011SSam Ravnborg 
51d5c1f011SSam Ravnborg /*
52d5c1f011SSam Ravnborg  * FIXME: vmwgfx_drm.h needs to be last due to dependencies.
53d5c1f011SSam Ravnborg  * uapi headers should not depend on header files outside uapi/.
54d5c1f011SSam Ravnborg  */
55d5c1f011SSam Ravnborg #include <drm/vmwgfx_drm.h>
56d5c1f011SSam Ravnborg 
57fb1d9738SJakob Bornecrantz 
58e300173fSThomas Hellstrom #define VMWGFX_DRIVER_NAME "vmwgfx"
5994eb7de6SZack Rusin #define VMWGFX_DRIVER_DATE "20211206"
602ae7b03cSThomas Hellstrom #define VMWGFX_DRIVER_MAJOR 2
6194eb7de6SZack Rusin #define VMWGFX_DRIVER_MINOR 20
62c29758cdSZack Rusin #define VMWGFX_DRIVER_PATCHLEVEL 0
63fb1d9738SJakob Bornecrantz #define VMWGFX_FIFO_STATIC_SIZE (1024*1024)
647c4f7780SThomas Hellstrom #define VMWGFX_MAX_DISPLAYS 16
65be38ab6eSThomas Hellstrom #define VMWGFX_CMD_BOUNCE_INIT_SIZE 32768
66fb1d9738SJakob Bornecrantz 
67df42523cSZack Rusin #define VMWGFX_MIN_INITIAL_WIDTH 1280
68df42523cSZack Rusin #define VMWGFX_MIN_INITIAL_HEIGHT 800
69df42523cSZack Rusin 
708772c0bbSZack Rusin #define VMWGFX_PCI_ID_SVGA2              0x0405
712cd80dbdSZack Rusin #define VMWGFX_PCI_ID_SVGA3              0x0406
728772c0bbSZack Rusin 
733530bdc3SThomas Hellstrom /*
7432160e6aSZack Rusin  * This has to match get_count_order(SVGA_IRQFLAG_MAX)
7532160e6aSZack Rusin  */
7632160e6aSZack Rusin #define VMWGFX_MAX_NUM_IRQS 6
7732160e6aSZack Rusin 
7832160e6aSZack Rusin /*
793530bdc3SThomas Hellstrom  * Perhaps we should have sysfs entries for these.
803530bdc3SThomas Hellstrom  */
813530bdc3SThomas Hellstrom #define VMWGFX_NUM_GB_CONTEXT 256
823530bdc3SThomas Hellstrom #define VMWGFX_NUM_GB_SHADER 20000
833530bdc3SThomas Hellstrom #define VMWGFX_NUM_GB_SURFACE 32768
847cba9062SThomas Hellstrom #define VMWGFX_NUM_GB_SCREEN_TARGET VMWGFX_MAX_DISPLAYS
85d80efd5cSThomas Hellstrom #define VMWGFX_NUM_DXCONTEXT 256
86d80efd5cSThomas Hellstrom #define VMWGFX_NUM_DXQUERY 512
873530bdc3SThomas Hellstrom #define VMWGFX_NUM_MOB (VMWGFX_NUM_GB_CONTEXT +\
883530bdc3SThomas Hellstrom 			VMWGFX_NUM_GB_SHADER +\
897cba9062SThomas Hellstrom 			VMWGFX_NUM_GB_SURFACE +\
907cba9062SThomas Hellstrom 			VMWGFX_NUM_GB_SCREEN_TARGET)
913530bdc3SThomas Hellstrom 
92283cde69SChristian König #define VMW_PL_GMR      (TTM_PL_PRIV + 0)
93283cde69SChristian König #define VMW_PL_MOB      (TTM_PL_PRIV + 1)
94f6be2326SZack Rusin #define VMW_PL_SYSTEM   (TTM_PL_PRIV + 2)
95135cba0dSThomas Hellstrom 
96ae2a1040SThomas Hellstrom #define VMW_RES_CONTEXT ttm_driver_type0
97ae2a1040SThomas Hellstrom #define VMW_RES_SURFACE ttm_driver_type1
98ae2a1040SThomas Hellstrom #define VMW_RES_STREAM ttm_driver_type2
99ae2a1040SThomas Hellstrom #define VMW_RES_FENCE ttm_driver_type3
100c74c162fSThomas Hellstrom #define VMW_RES_SHADER ttm_driver_type4
1019e931f2eSMaaz Mombasawala #define VMW_RES_HT_ORDER 12
102ae2a1040SThomas Hellstrom 
103da7ffb96SZack Rusin #define VMW_CURSOR_SNOOP_FORMAT SVGA3D_A8R8G8B8
104da7ffb96SZack Rusin #define VMW_CURSOR_SNOOP_WIDTH 64
105da7ffb96SZack Rusin #define VMW_CURSOR_SNOOP_HEIGHT 64
106da7ffb96SZack Rusin 
1077a7a933eSMartin Krastev #define MKSSTAT_CAPACITY_LOG2 5U
1087a7a933eSMartin Krastev #define MKSSTAT_CAPACITY (1U << MKSSTAT_CAPACITY_LOG2)
1097a7a933eSMartin Krastev 
110fb1d9738SJakob Bornecrantz struct vmw_fpriv {
111fb1d9738SJakob Bornecrantz 	struct ttm_object_file *tfile;
112f9261b30SDeepak Rawat 	bool gb_aware; /* user-space is guest-backed aware */
113fb1d9738SJakob Bornecrantz };
114fb1d9738SJakob Bornecrantz 
1159da30cddSMaaz Mombasawala struct vmwgfx_hash_item {
1169da30cddSMaaz Mombasawala 	struct hlist_node head;
1179da30cddSMaaz Mombasawala 	unsigned long key;
1189da30cddSMaaz Mombasawala };
1199da30cddSMaaz Mombasawala 
120fb1d9738SJakob Bornecrantz 
121c0951b79SThomas Hellstrom /**
122c0951b79SThomas Hellstrom  * struct vmw_validate_buffer - Carries validation info about buffers.
123c0951b79SThomas Hellstrom  *
124c0951b79SThomas Hellstrom  * @base: Validation info for TTM.
125c0951b79SThomas Hellstrom  * @hash: Hash entry for quick lookup of the TTM buffer object.
126c0951b79SThomas Hellstrom  *
127c0951b79SThomas Hellstrom  * This structure contains also driver private validation info
128c0951b79SThomas Hellstrom  * on top of the info needed by TTM.
129c0951b79SThomas Hellstrom  */
130c0951b79SThomas Hellstrom struct vmw_validate_buffer {
131c0951b79SThomas Hellstrom 	struct ttm_validate_buffer base;
1322985c964SThomas Zimmermann 	struct vmwgfx_hash_item hash;
13396c5f0dfSThomas Hellstrom 	bool validate_as_mob;
134c0951b79SThomas Hellstrom };
135c0951b79SThomas Hellstrom 
136c0951b79SThomas Hellstrom struct vmw_res_func;
13713289241SThomas Hellstrom 
13813289241SThomas Hellstrom 
13913289241SThomas Hellstrom /**
14013289241SThomas Hellstrom  * struct vmw-resource - base class for hardware resources
14113289241SThomas Hellstrom  *
14213289241SThomas Hellstrom  * @kref: For refcounting.
14313289241SThomas Hellstrom  * @dev_priv: Pointer to the device private for this resource. Immutable.
14413289241SThomas Hellstrom  * @id: Device id. Protected by @dev_priv::resource_lock.
145668b2066SZack Rusin  * @guest_memory_size: Guest memory buffer size. Immutable.
146668b2066SZack Rusin  * @res_dirty: Resource contains data not yet in the guest memory buffer.
147b7468b15SThomas Hellstrom  * Protected by resource reserved.
148668b2066SZack Rusin  * @guest_memory_dirty: Guest memory buffer contains data not yet in the HW
149668b2066SZack Rusin  * resource. Protected by resource reserved.
150b7468b15SThomas Hellstrom  * @coherent: Emulate coherency by tracking vm accesses.
151668b2066SZack Rusin  * @guest_memory_bo: The guest memory buffer if any. Protected by resource
152668b2066SZack Rusin  * reserved.
153668b2066SZack Rusin  * @guest_memory_offset: Offset into the guest memory buffer if any. Protected
154668b2066SZack Rusin  * by resource reserved. Note that only a few resource types can have a
155668b2066SZack Rusin  * @guest_memory_offset different from zero.
15613289241SThomas Hellstrom  * @pin_count: The pin count for this resource. A pinned resource has a
15713289241SThomas Hellstrom  * pin-count greater than zero. It is not on the resource LRU lists and its
158668b2066SZack Rusin  * guest memory buffer is pinned. Hence it can't be evicted.
15913289241SThomas Hellstrom  * @func: Method vtable for this resource. Immutable.
160668b2066SZack Rusin  * @mob_node; Node for the MOB guest memory rbtree. Protected by
161668b2066SZack Rusin  * @guest_memory_bo reserved.
16213289241SThomas Hellstrom  * @lru_head: List head for the LRU list. Protected by @dev_priv::resource_lock.
16313289241SThomas Hellstrom  * @binding_head: List head for the context binding list. Protected by
16413289241SThomas Hellstrom  * the @dev_priv::binding_mutex
16513289241SThomas Hellstrom  * @res_free: The resource destructor.
16613289241SThomas Hellstrom  * @hw_destroy: Callback to destroy the resource on the device, as part of
16713289241SThomas Hellstrom  * resource destruction.
16813289241SThomas Hellstrom  */
16909881d29SZack Rusin struct vmw_bo;
170668b2066SZack Rusin struct vmw_bo;
171b7468b15SThomas Hellstrom struct vmw_resource_dirty;
172fb1d9738SJakob Bornecrantz struct vmw_resource {
173fb1d9738SJakob Bornecrantz 	struct kref kref;
174fb1d9738SJakob Bornecrantz 	struct vmw_private *dev_priv;
175fb1d9738SJakob Bornecrantz 	int id;
176a0a63940SThomas Hellstrom 	u32 used_prio;
177668b2066SZack Rusin 	unsigned long guest_memory_size;
178b7468b15SThomas Hellstrom 	u32 res_dirty : 1;
179668b2066SZack Rusin 	u32 guest_memory_dirty : 1;
180b7468b15SThomas Hellstrom 	u32 coherent : 1;
181668b2066SZack Rusin 	struct vmw_bo *guest_memory_bo;
182668b2066SZack Rusin 	unsigned long guest_memory_offset;
18313289241SThomas Hellstrom 	unsigned long pin_count;
184c0951b79SThomas Hellstrom 	const struct vmw_res_func *func;
18561335d7aSThomas Hellstrom 	struct rb_node mob_node;
18613289241SThomas Hellstrom 	struct list_head lru_head;
18713289241SThomas Hellstrom 	struct list_head binding_head;
188b7468b15SThomas Hellstrom 	struct vmw_resource_dirty *dirty;
189fb1d9738SJakob Bornecrantz 	void (*res_free) (struct vmw_resource *res);
190c0951b79SThomas Hellstrom 	void (*hw_destroy) (struct vmw_resource *res);
191c0951b79SThomas Hellstrom };
192c0951b79SThomas Hellstrom 
19318e4a466SThomas Hellstrom 
19418e4a466SThomas Hellstrom /*
19518e4a466SThomas Hellstrom  * Resources that are managed using ioctls.
19618e4a466SThomas Hellstrom  */
197c0951b79SThomas Hellstrom enum vmw_res_type {
198c0951b79SThomas Hellstrom 	vmw_res_context,
199c0951b79SThomas Hellstrom 	vmw_res_surface,
200c0951b79SThomas Hellstrom 	vmw_res_stream,
201c74c162fSThomas Hellstrom 	vmw_res_shader,
202d80efd5cSThomas Hellstrom 	vmw_res_dx_context,
203d80efd5cSThomas Hellstrom 	vmw_res_cotable,
204d80efd5cSThomas Hellstrom 	vmw_res_view,
205e8bead9cSDeepak Rawat 	vmw_res_streamoutput,
206c0951b79SThomas Hellstrom 	vmw_res_max
207fb1d9738SJakob Bornecrantz };
208fb1d9738SJakob Bornecrantz 
20918e4a466SThomas Hellstrom /*
21018e4a466SThomas Hellstrom  * Resources that are managed using command streams.
21118e4a466SThomas Hellstrom  */
21218e4a466SThomas Hellstrom enum vmw_cmdbuf_res_type {
213d80efd5cSThomas Hellstrom 	vmw_cmdbuf_res_shader,
214e8bead9cSDeepak Rawat 	vmw_cmdbuf_res_view,
215e8bead9cSDeepak Rawat 	vmw_cmdbuf_res_streamoutput
21618e4a466SThomas Hellstrom };
21718e4a466SThomas Hellstrom 
21818e4a466SThomas Hellstrom struct vmw_cmdbuf_res_manager;
21918e4a466SThomas Hellstrom 
220fb1d9738SJakob Bornecrantz struct vmw_cursor_snooper {
221fb1d9738SJakob Bornecrantz 	size_t age;
222fb1d9738SJakob Bornecrantz 	uint32_t *image;
223fb1d9738SJakob Bornecrantz };
224fb1d9738SJakob Bornecrantz 
2252fcd5a73SJakob Bornecrantz struct vmw_framebuffer;
2265bb39e81SThomas Hellstrom struct vmw_surface_offset;
2272fcd5a73SJakob Bornecrantz 
22826b82873SDeepak Rawat /**
22926b82873SDeepak Rawat  * struct vmw_surface_metadata - Metadata describing a surface.
23026b82873SDeepak Rawat  *
23126b82873SDeepak Rawat  * @flags: Device flags.
23226b82873SDeepak Rawat  * @format: Surface SVGA3D_x format.
23326b82873SDeepak Rawat  * @mip_levels: Mip level for each face. For GB first index is used only.
23426b82873SDeepak Rawat  * @multisample_count: Sample count.
23526b82873SDeepak Rawat  * @multisample_pattern: Sample patterns.
23626b82873SDeepak Rawat  * @quality_level: Quality level.
23726b82873SDeepak Rawat  * @autogen_filter: Filter for automatically generated mipmaps.
23826b82873SDeepak Rawat  * @array_size: Number of array elements for a 1D/2D texture. For cubemap
23926b82873SDeepak Rawat                 texture number of faces * array_size. This should be 0 for pre
24026b82873SDeepak Rawat 		SM4 device.
2412a50f06dSDeepak Rawat  * @buffer_byte_stride: Buffer byte stride.
24226b82873SDeepak Rawat  * @num_sizes: Size of @sizes. For GB surface this should always be 1.
24326b82873SDeepak Rawat  * @base_size: Surface dimension.
24426b82873SDeepak Rawat  * @sizes: Array representing mip sizes. Legacy only.
24526b82873SDeepak Rawat  * @scanout: Whether this surface will be used for scanout.
24626b82873SDeepak Rawat  *
24726b82873SDeepak Rawat  * This tracks metadata for both legacy and guest backed surface.
24826b82873SDeepak Rawat  */
24926b82873SDeepak Rawat struct vmw_surface_metadata {
25026b82873SDeepak Rawat 	u64 flags;
25126b82873SDeepak Rawat 	u32 format;
25226b82873SDeepak Rawat 	u32 mip_levels[DRM_VMW_MAX_SURFACE_FACES];
25326b82873SDeepak Rawat 	u32 multisample_count;
25426b82873SDeepak Rawat 	u32 multisample_pattern;
25526b82873SDeepak Rawat 	u32 quality_level;
25626b82873SDeepak Rawat 	u32 autogen_filter;
25726b82873SDeepak Rawat 	u32 array_size;
25826b82873SDeepak Rawat 	u32 num_sizes;
2592a50f06dSDeepak Rawat 	u32 buffer_byte_stride;
260c0951b79SThomas Hellstrom 	struct drm_vmw_size base_size;
261fb1d9738SJakob Bornecrantz 	struct drm_vmw_size *sizes;
2625ffdb658SJakob Bornecrantz 	bool scanout;
26326b82873SDeepak Rawat };
26426b82873SDeepak Rawat 
26526b82873SDeepak Rawat /**
26626b82873SDeepak Rawat  * struct vmw_surface: Resource structure for a surface.
26726b82873SDeepak Rawat  *
26826b82873SDeepak Rawat  * @res: The base resource for this surface.
26926b82873SDeepak Rawat  * @metadata: Metadata for this surface resource.
27026b82873SDeepak Rawat  * @snooper: Cursor data. Legacy surface only.
27126b82873SDeepak Rawat  * @offsets: Legacy surface only.
27226b82873SDeepak Rawat  * @view_list: List of views bound to this surface.
27326b82873SDeepak Rawat  */
27426b82873SDeepak Rawat struct vmw_surface {
27526b82873SDeepak Rawat 	struct vmw_resource res;
27626b82873SDeepak Rawat 	struct vmw_surface_metadata metadata;
277fb1d9738SJakob Bornecrantz 	struct vmw_cursor_snooper snooper;
2785bb39e81SThomas Hellstrom 	struct vmw_surface_offset *offsets;
279d80efd5cSThomas Hellstrom 	struct list_head view_list;
280fb1d9738SJakob Bornecrantz };
281fb1d9738SJakob Bornecrantz 
282fb1d9738SJakob Bornecrantz struct vmw_fifo_state {
283fb1d9738SJakob Bornecrantz 	unsigned long reserved_size;
284b9eb1a61SThomas Hellstrom 	u32 *dynamic_buffer;
285b9eb1a61SThomas Hellstrom 	u32 *static_buffer;
286fb1d9738SJakob Bornecrantz 	unsigned long static_buffer_size;
287fb1d9738SJakob Bornecrantz 	bool using_bounce_buffer;
288fb1d9738SJakob Bornecrantz 	uint32_t capabilities;
28985b9e487SThomas Hellstrom 	struct mutex fifo_mutex;
290fb1d9738SJakob Bornecrantz 	struct rw_semaphore rwsem;
291fb1d9738SJakob Bornecrantz };
292fb1d9738SJakob Bornecrantz 
293c0951b79SThomas Hellstrom /**
294c0951b79SThomas Hellstrom  * struct vmw_res_cache_entry - resource information cache entry
2959c079b8cSThomas Hellstrom  * @handle: User-space handle of a resource.
2969c079b8cSThomas Hellstrom  * @res: Non-ref-counted pointer to the resource.
2979c079b8cSThomas Hellstrom  * @valid_handle: Whether the @handle member is valid.
298c0951b79SThomas Hellstrom  * @valid: Whether the entry is valid, which also implies that the execbuf
299c0951b79SThomas Hellstrom  * code holds a reference to the resource, and it's placed on the
300c0951b79SThomas Hellstrom  * validation list.
301c0951b79SThomas Hellstrom  *
302c0951b79SThomas Hellstrom  * Used to avoid frequent repeated user-space handle lookups of the
303c0951b79SThomas Hellstrom  * same resource.
304c0951b79SThomas Hellstrom  */
305c0951b79SThomas Hellstrom struct vmw_res_cache_entry {
306c0951b79SThomas Hellstrom 	uint32_t handle;
307c0951b79SThomas Hellstrom 	struct vmw_resource *res;
3089c079b8cSThomas Hellstrom 	void *private;
3099c079b8cSThomas Hellstrom 	unsigned short valid_handle;
3109c079b8cSThomas Hellstrom 	unsigned short valid;
311c0951b79SThomas Hellstrom };
312c0951b79SThomas Hellstrom 
313d92d9851SThomas Hellstrom /**
314d92d9851SThomas Hellstrom  * enum vmw_dma_map_mode - indicate how to perform TTM page dma mappings.
315d92d9851SThomas Hellstrom  */
316d92d9851SThomas Hellstrom enum vmw_dma_map_mode {
317d92d9851SThomas Hellstrom 	vmw_dma_alloc_coherent, /* Use TTM coherent pages */
318d92d9851SThomas Hellstrom 	vmw_dma_map_populate,   /* Unmap from DMA just after unpopulate */
319d92d9851SThomas Hellstrom 	vmw_dma_map_bind,       /* Unmap from DMA just before unbind */
320d92d9851SThomas Hellstrom 	vmw_dma_map_max
321d92d9851SThomas Hellstrom };
322d92d9851SThomas Hellstrom 
323d92d9851SThomas Hellstrom /**
324d92d9851SThomas Hellstrom  * struct vmw_sg_table - Scatter/gather table for binding, with additional
325d92d9851SThomas Hellstrom  * device-specific information.
326d92d9851SThomas Hellstrom  *
327d92d9851SThomas Hellstrom  * @sgt: Pointer to a struct sg_table with binding information
328e1c05067SMasahiro Yamada  * @num_regions: Number of regions with device-address contiguous pages
329d92d9851SThomas Hellstrom  */
330d92d9851SThomas Hellstrom struct vmw_sg_table {
331d92d9851SThomas Hellstrom 	enum vmw_dma_map_mode mode;
332d92d9851SThomas Hellstrom 	struct page **pages;
333d92d9851SThomas Hellstrom 	const dma_addr_t *addrs;
334d92d9851SThomas Hellstrom 	struct sg_table *sgt;
335d92d9851SThomas Hellstrom 	unsigned long num_pages;
336d92d9851SThomas Hellstrom };
337d92d9851SThomas Hellstrom 
338d92d9851SThomas Hellstrom /**
339d92d9851SThomas Hellstrom  * struct vmw_piter - Page iterator that iterates over a list of pages
340d92d9851SThomas Hellstrom  * and DMA addresses that could be either a scatter-gather list or
341d92d9851SThomas Hellstrom  * arrays
342d92d9851SThomas Hellstrom  *
343d92d9851SThomas Hellstrom  * @pages: Array of page pointers to the pages.
344d92d9851SThomas Hellstrom  * @addrs: DMA addresses to the pages if coherent pages are used.
345d92d9851SThomas Hellstrom  * @iter: Scatter-gather page iterator. Current position in SG list.
346d92d9851SThomas Hellstrom  * @i: Current position in arrays.
347d92d9851SThomas Hellstrom  * @num_pages: Number of pages total.
348d92d9851SThomas Hellstrom  * @next: Function to advance the iterator. Returns false if past the list
349d92d9851SThomas Hellstrom  * of pages, true otherwise.
350d92d9851SThomas Hellstrom  * @dma_address: Function to return the DMA address of the current page.
351d92d9851SThomas Hellstrom  */
352d92d9851SThomas Hellstrom struct vmw_piter {
353d92d9851SThomas Hellstrom 	struct page **pages;
354d92d9851SThomas Hellstrom 	const dma_addr_t *addrs;
3558dc39cfcSThomas Hellstrom 	struct sg_dma_page_iter iter;
356d92d9851SThomas Hellstrom 	unsigned long i;
357d92d9851SThomas Hellstrom 	unsigned long num_pages;
358d92d9851SThomas Hellstrom 	bool (*next)(struct vmw_piter *);
359d92d9851SThomas Hellstrom 	dma_addr_t (*dma_address)(struct vmw_piter *);
360d92d9851SThomas Hellstrom };
361d92d9851SThomas Hellstrom 
3628afa13a0SZack Rusin 
3638afa13a0SZack Rusin struct vmw_ttm_tt {
3648afa13a0SZack Rusin 	struct ttm_tt dma_ttm;
3658afa13a0SZack Rusin 	struct vmw_private *dev_priv;
3668afa13a0SZack Rusin 	int gmr_id;
3678afa13a0SZack Rusin 	struct vmw_mob *mob;
3688afa13a0SZack Rusin 	int mem_type;
3698afa13a0SZack Rusin 	struct sg_table sgt;
3708afa13a0SZack Rusin 	struct vmw_sg_table vsgt;
3718afa13a0SZack Rusin 	bool mapped;
3728afa13a0SZack Rusin 	bool bound;
3738afa13a0SZack Rusin };
3748afa13a0SZack Rusin 
375b5c3b1a6SThomas Hellstrom /*
376c8261a96SSinclair Yeh  * enum vmw_display_unit_type - Describes the display unit
377b5c3b1a6SThomas Hellstrom  */
378c8261a96SSinclair Yeh enum vmw_display_unit_type {
379c8261a96SSinclair Yeh 	vmw_du_invalid = 0,
380c8261a96SSinclair Yeh 	vmw_du_legacy,
38135c05125SSinclair Yeh 	vmw_du_screen_object,
3822b273544SZack Rusin 	vmw_du_screen_target,
3832b273544SZack Rusin 	vmw_du_max
384b5c3b1a6SThomas Hellstrom };
385b5c3b1a6SThomas Hellstrom 
3869c079b8cSThomas Hellstrom struct vmw_validation_context;
3879c079b8cSThomas Hellstrom struct vmw_ctx_validation_info;
388b5c3b1a6SThomas Hellstrom 
3899c079b8cSThomas Hellstrom /**
3909c079b8cSThomas Hellstrom  * struct vmw_sw_context - Command submission context
3919c079b8cSThomas Hellstrom  * @res_ht: Pointer hash table used to find validation duplicates
3929c079b8cSThomas Hellstrom  * @kernel: Whether the command buffer originates from kernel code rather
3939c079b8cSThomas Hellstrom  * than from user-space
3949c079b8cSThomas Hellstrom  * @fp: If @kernel is false, points to the file of the client. Otherwise
3959c079b8cSThomas Hellstrom  * NULL
3969c079b8cSThomas Hellstrom  * @cmd_bounce: Command bounce buffer used for command validation before
3979c079b8cSThomas Hellstrom  * copying to fifo space
3989c079b8cSThomas Hellstrom  * @cmd_bounce_size: Current command bounce buffer size
3999c079b8cSThomas Hellstrom  * @cur_query_bo: Current buffer object used as query result buffer
400fc18afcfSThomas Hellstrom  * @bo_relocations: List of buffer object relocations
4019c079b8cSThomas Hellstrom  * @res_relocations: List of resource relocations
4029c079b8cSThomas Hellstrom  * @buf_start: Pointer to start of memory where command validation takes
4039c079b8cSThomas Hellstrom  * place
4049c079b8cSThomas Hellstrom  * @res_cache: Cache of recently looked up resources
4059c079b8cSThomas Hellstrom  * @last_query_ctx: Last context that submitted a query
4069c079b8cSThomas Hellstrom  * @needs_post_query_barrier: Whether a query barrier is needed after
4079c079b8cSThomas Hellstrom  * command submission
4089c079b8cSThomas Hellstrom  * @staged_bindings: Cached per-context binding tracker
4099c079b8cSThomas Hellstrom  * @staged_bindings_inuse: Whether the cached per-context binding tracker
4109c079b8cSThomas Hellstrom  * is in use
4119c079b8cSThomas Hellstrom  * @staged_cmd_res: List of staged command buffer managed resources in this
4129c079b8cSThomas Hellstrom  * command buffer
4139c079b8cSThomas Hellstrom  * @ctx_list: List of context resources referenced in this command buffer
4149c079b8cSThomas Hellstrom  * @dx_ctx_node: Validation metadata of the current DX context
4159c079b8cSThomas Hellstrom  * @dx_query_mob: The MOB used for DX queries
4169c079b8cSThomas Hellstrom  * @dx_query_ctx: The DX context used for the last DX query
4179c079b8cSThomas Hellstrom  * @man: Pointer to the command buffer managed resource manager
4189c079b8cSThomas Hellstrom  * @ctx: The validation context
4199c079b8cSThomas Hellstrom  */
420fb1d9738SJakob Bornecrantz struct vmw_sw_context{
4219e931f2eSMaaz Mombasawala 	DECLARE_HASHTABLE(res_ht, VMW_RES_HT_ORDER);
4229c079b8cSThomas Hellstrom 	bool kernel;
423d5bde956SThomas Hellstrom 	struct vmw_fpriv *fp;
4248afa13a0SZack Rusin 	struct drm_file *filp;
425be38ab6eSThomas Hellstrom 	uint32_t *cmd_bounce;
426be38ab6eSThomas Hellstrom 	uint32_t cmd_bounce_size;
42709881d29SZack Rusin 	struct vmw_bo *cur_query_bo;
428fc18afcfSThomas Hellstrom 	struct list_head bo_relocations;
429c0951b79SThomas Hellstrom 	struct list_head res_relocations;
430c0951b79SThomas Hellstrom 	uint32_t *buf_start;
431c0951b79SThomas Hellstrom 	struct vmw_res_cache_entry res_cache[vmw_res_max];
432c0951b79SThomas Hellstrom 	struct vmw_resource *last_query_ctx;
433c0951b79SThomas Hellstrom 	bool needs_post_query_barrier;
434d80efd5cSThomas Hellstrom 	struct vmw_ctx_binding_state *staged_bindings;
435d80efd5cSThomas Hellstrom 	bool staged_bindings_inuse;
43618e4a466SThomas Hellstrom 	struct list_head staged_cmd_res;
4379c079b8cSThomas Hellstrom 	struct list_head ctx_list;
4389c079b8cSThomas Hellstrom 	struct vmw_ctx_validation_info *dx_ctx_node;
43909881d29SZack Rusin 	struct vmw_bo *dx_query_mob;
440d80efd5cSThomas Hellstrom 	struct vmw_resource *dx_query_ctx;
441d80efd5cSThomas Hellstrom 	struct vmw_cmdbuf_res_manager *man;
4429c079b8cSThomas Hellstrom 	struct vmw_validation_context *ctx;
443fb1d9738SJakob Bornecrantz };
444fb1d9738SJakob Bornecrantz 
445fb1d9738SJakob Bornecrantz struct vmw_legacy_display;
446fb1d9738SJakob Bornecrantz struct vmw_overlay;
447fb1d9738SJakob Bornecrantz 
4487c4f7780SThomas Hellstrom struct vmw_vga_topology_state {
4497c4f7780SThomas Hellstrom 	uint32_t width;
4507c4f7780SThomas Hellstrom 	uint32_t height;
4517c4f7780SThomas Hellstrom 	uint32_t primary;
4527c4f7780SThomas Hellstrom 	uint32_t pos_x;
4537c4f7780SThomas Hellstrom 	uint32_t pos_y;
4547c4f7780SThomas Hellstrom };
4557c4f7780SThomas Hellstrom 
456d80efd5cSThomas Hellstrom 
457d80efd5cSThomas Hellstrom /*
458d80efd5cSThomas Hellstrom  * struct vmw_otable - Guest Memory OBject table metadata
459d80efd5cSThomas Hellstrom  *
460d80efd5cSThomas Hellstrom  * @size:           Size of the table (page-aligned).
461d80efd5cSThomas Hellstrom  * @page_table:     Pointer to a struct vmw_mob holding the page table.
462d80efd5cSThomas Hellstrom  */
463d80efd5cSThomas Hellstrom struct vmw_otable {
464d80efd5cSThomas Hellstrom 	unsigned long size;
465d80efd5cSThomas Hellstrom 	struct vmw_mob *page_table;
466d80efd5cSThomas Hellstrom 	bool enabled;
467d80efd5cSThomas Hellstrom };
468d80efd5cSThomas Hellstrom 
469d80efd5cSThomas Hellstrom struct vmw_otable_batch {
470d80efd5cSThomas Hellstrom 	unsigned num_otables;
471d80efd5cSThomas Hellstrom 	struct vmw_otable *otables;
472d80efd5cSThomas Hellstrom 	struct vmw_resource *context;
473668b2066SZack Rusin 	struct vmw_bo *otable_bo;
474d80efd5cSThomas Hellstrom };
475d80efd5cSThomas Hellstrom 
476ef369904SThomas Hellstrom enum {
477ef369904SThomas Hellstrom 	VMW_IRQTHREAD_FENCE,
478ef369904SThomas Hellstrom 	VMW_IRQTHREAD_CMDBUF,
479ef369904SThomas Hellstrom 	VMW_IRQTHREAD_MAX
480ef369904SThomas Hellstrom };
481ef369904SThomas Hellstrom 
482878c6ecdSDeepak Rawat /**
483878c6ecdSDeepak Rawat  * enum vmw_sm_type - Graphics context capability supported by device.
484878c6ecdSDeepak Rawat  * @VMW_SM_LEGACY: Pre DX context.
485878c6ecdSDeepak Rawat  * @VMW_SM_4: Context support upto SM4.
486878c6ecdSDeepak Rawat  * @VMW_SM_4_1: Context support upto SM4_1.
4874dec2805SDeepak Rawat  * @VMW_SM_5: Context support up to SM5.
4884fb9326bSZack Rusin  * @VMW_SM_5_1X: Adds support for sm5_1 and gl43 extensions.
489878c6ecdSDeepak Rawat  * @VMW_SM_MAX: Should be the last.
490878c6ecdSDeepak Rawat  */
491878c6ecdSDeepak Rawat enum vmw_sm_type {
492878c6ecdSDeepak Rawat 	VMW_SM_LEGACY = 0,
493878c6ecdSDeepak Rawat 	VMW_SM_4,
494878c6ecdSDeepak Rawat 	VMW_SM_4_1,
4954dec2805SDeepak Rawat 	VMW_SM_5,
4964fb9326bSZack Rusin 	VMW_SM_5_1X,
497878c6ecdSDeepak Rawat 	VMW_SM_MAX
498878c6ecdSDeepak Rawat };
499878c6ecdSDeepak Rawat 
500fb1d9738SJakob Bornecrantz struct vmw_private {
5019703bb32SZack Rusin 	struct drm_device drm;
5028af8a109SChristian König 	struct ttm_device bdev;
503fb1d9738SJakob Bornecrantz 
504293f86b3SGerd Hoffmann 	struct drm_vma_offset_manager vma_manager;
505baee602eSZack Rusin 	u32 pci_id;
506be4f77acSZack Rusin 	resource_size_t io_start;
507be4f77acSZack Rusin 	resource_size_t vram_start;
508be4f77acSZack Rusin 	resource_size_t vram_size;
509ebc9ac7cSZack Rusin 	resource_size_t max_primary_mem;
510c2aaa37dSZack Rusin 	u32 __iomem *rmmio;
511be4f77acSZack Rusin 	u32 *fifo_mem;
512be4f77acSZack Rusin 	resource_size_t fifo_mem_size;
513fb1d9738SJakob Bornecrantz 	uint32_t fb_max_width;
514fb1d9738SJakob Bornecrantz 	uint32_t fb_max_height;
51535c05125SSinclair Yeh 	uint32_t texture_max_width;
51635c05125SSinclair Yeh 	uint32_t texture_max_height;
51735c05125SSinclair Yeh 	uint32_t stdu_max_width;
51835c05125SSinclair Yeh 	uint32_t stdu_max_height;
519eb4f923bSJakob Bornecrantz 	uint32_t initial_width;
520eb4f923bSJakob Bornecrantz 	uint32_t initial_height;
521fb1d9738SJakob Bornecrantz 	uint32_t capabilities;
5223b4c2511SNeha Bhende 	uint32_t capabilities2;
523fb1d9738SJakob Bornecrantz 	uint32_t max_gmr_ids;
524fb17f189SThomas Hellstrom 	uint32_t max_gmr_pages;
5256da768aaSThomas Hellstrom 	uint32_t max_mob_pages;
526857aea1cSCharmaine Lee 	uint32_t max_mob_size;
527fb17f189SThomas Hellstrom 	uint32_t memory_size;
528135cba0dSThomas Hellstrom 	bool has_gmr;
5293530bdc3SThomas Hellstrom 	bool has_mob;
530496eb6fdSThomas Hellstrom 	spinlock_t hw_lock;
53104319d89SSinclair Yeh 	bool assume_16bpp;
53232160e6aSZack Rusin 	u32 irqs[VMWGFX_MAX_NUM_IRQS];
53332160e6aSZack Rusin 	u32 num_irq_vectors;
534878c6ecdSDeepak Rawat 
535878c6ecdSDeepak Rawat 	enum vmw_sm_type sm_type;
536fb1d9738SJakob Bornecrantz 
537fb1d9738SJakob Bornecrantz 	/*
538fb1d9738SJakob Bornecrantz 	 * Framebuffer info.
539fb1d9738SJakob Bornecrantz 	 */
540fb1d9738SJakob Bornecrantz 
541c8261a96SSinclair Yeh 	enum vmw_display_unit_type active_display_unit;
542fb1d9738SJakob Bornecrantz 	struct vmw_legacy_display *ldu_priv;
543fb1d9738SJakob Bornecrantz 	struct vmw_overlay *overlay_priv;
544578e609aSThomas Hellstrom 	struct drm_property *hotplug_mode_update_property;
54576404ac0SThomas Hellstrom 	struct drm_property *implicit_placement_property;
54636cc79bcSSinclair Yeh 	spinlock_t cursor_lock;
547c3b9b165SThomas Hellstrom 	struct drm_atomic_state *suspend_state;
548fb1d9738SJakob Bornecrantz 
549fb1d9738SJakob Bornecrantz 	/*
550fb1d9738SJakob Bornecrantz 	 * Context and surface management.
551fb1d9738SJakob Bornecrantz 	 */
552fb1d9738SJakob Bornecrantz 
55313289241SThomas Hellstrom 	spinlock_t resource_lock;
554c0951b79SThomas Hellstrom 	struct idr res_idr[vmw_res_max];
555fb1d9738SJakob Bornecrantz 
556fb1d9738SJakob Bornecrantz 	/*
557fb1d9738SJakob Bornecrantz 	 * A resource manager for kernel-only surfaces and
558fb1d9738SJakob Bornecrantz 	 * contexts.
559fb1d9738SJakob Bornecrantz 	 */
560fb1d9738SJakob Bornecrantz 
561fb1d9738SJakob Bornecrantz 	struct ttm_object_device *tdev;
562fb1d9738SJakob Bornecrantz 
563fb1d9738SJakob Bornecrantz 	/*
564fb1d9738SJakob Bornecrantz 	 * Fencing and IRQs.
565fb1d9738SJakob Bornecrantz 	 */
566fb1d9738SJakob Bornecrantz 
5676bcd8d3cSThomas Hellstrom 	atomic_t marker_seq;
568fb1d9738SJakob Bornecrantz 	wait_queue_head_t fence_queue;
569fb1d9738SJakob Bornecrantz 	wait_queue_head_t fifo_queue;
570496eb6fdSThomas Hellstrom 	spinlock_t waiter_lock;
571496eb6fdSThomas Hellstrom 	int fence_queue_waiters; /* Protected by waiter_lock */
572496eb6fdSThomas Hellstrom 	int goal_queue_waiters; /* Protected by waiter_lock */
573d2e8851aSThomas Hellstrom 	int cmdbuf_waiters; /* Protected by waiter_lock */
574d2e8851aSThomas Hellstrom 	int error_waiters; /* Protected by waiter_lock */
575d2e8851aSThomas Hellstrom 	int fifo_queue_waiters; /* Protected by waiter_lock */
5766bcd8d3cSThomas Hellstrom 	uint32_t last_read_seqno;
577ae2a1040SThomas Hellstrom 	struct vmw_fence_manager *fman;
578d2e8851aSThomas Hellstrom 	uint32_t irq_mask; /* Updates protected by waiter_lock */
579fb1d9738SJakob Bornecrantz 
580fb1d9738SJakob Bornecrantz 	/*
581fb1d9738SJakob Bornecrantz 	 * Device state
582fb1d9738SJakob Bornecrantz 	 */
583fb1d9738SJakob Bornecrantz 
584fb1d9738SJakob Bornecrantz 	uint32_t traces_state;
585fb1d9738SJakob Bornecrantz 	uint32_t enable_state;
586fb1d9738SJakob Bornecrantz 	uint32_t config_done_state;
587fb1d9738SJakob Bornecrantz 
588fb1d9738SJakob Bornecrantz 	/**
589fb1d9738SJakob Bornecrantz 	 * Execbuf
590fb1d9738SJakob Bornecrantz 	 */
591fb1d9738SJakob Bornecrantz 	/**
592fb1d9738SJakob Bornecrantz 	 * Protected by the cmdbuf mutex.
593fb1d9738SJakob Bornecrantz 	 */
594fb1d9738SJakob Bornecrantz 
595fb1d9738SJakob Bornecrantz 	struct vmw_sw_context ctx;
596fb1d9738SJakob Bornecrantz 	struct mutex cmdbuf_mutex;
597173fb7d4SThomas Hellstrom 	struct mutex binding_mutex;
598fb1d9738SJakob Bornecrantz 
599fb1d9738SJakob Bornecrantz 	/**
6009c84aebaSThomas Hellstrom 	 * PM management.
601fb1d9738SJakob Bornecrantz 	 */
602d9f36a00SThomas Hellstrom 	struct notifier_block pm_nb;
603153b3d5bSThomas Hellstrom 	bool refuse_hibernation;
604c3b9b165SThomas Hellstrom 	bool suspend_locked;
60530c78bb8SThomas Hellstrom 
606153b3d5bSThomas Hellstrom 	atomic_t num_fifo_resources;
607e2fa3a76SThomas Hellstrom 
608e2fa3a76SThomas Hellstrom 	/*
609e2fa3a76SThomas Hellstrom 	 * Query processing. These members
610e2fa3a76SThomas Hellstrom 	 * are protected by the cmdbuf mutex.
611e2fa3a76SThomas Hellstrom 	 */
612e2fa3a76SThomas Hellstrom 
61309881d29SZack Rusin 	struct vmw_bo *dummy_query_bo;
61409881d29SZack Rusin 	struct vmw_bo *pinned_bo;
615e2fa3a76SThomas Hellstrom 	uint32_t query_cid;
616c0951b79SThomas Hellstrom 	uint32_t query_cid_valid;
617e2fa3a76SThomas Hellstrom 	bool dummy_query_bo_pinned;
6185bb39e81SThomas Hellstrom 
6195bb39e81SThomas Hellstrom 	/*
6205bb39e81SThomas Hellstrom 	 * Surface swapping. The "surface_lru" list is protected by the
6215bb39e81SThomas Hellstrom 	 * resource lock in order to be able to destroy a surface and take
6225bb39e81SThomas Hellstrom 	 * it off the lru atomically. "used_memory_size" is currently
6235bb39e81SThomas Hellstrom 	 * protected by the cmdbuf mutex for simplicity.
6245bb39e81SThomas Hellstrom 	 */
6255bb39e81SThomas Hellstrom 
626c0951b79SThomas Hellstrom 	struct list_head res_lru[vmw_res_max];
6275bb39e81SThomas Hellstrom 	uint32_t used_memory_size;
628d92d9851SThomas Hellstrom 
629d92d9851SThomas Hellstrom 	/*
630d92d9851SThomas Hellstrom 	 * DMA mapping stuff.
631d92d9851SThomas Hellstrom 	 */
632d92d9851SThomas Hellstrom 	enum vmw_dma_map_mode map_mode;
6333530bdc3SThomas Hellstrom 
6343530bdc3SThomas Hellstrom 	/*
6353530bdc3SThomas Hellstrom 	 * Guest Backed stuff
6363530bdc3SThomas Hellstrom 	 */
637d80efd5cSThomas Hellstrom 	struct vmw_otable_batch otable_batch;
6383eab3d9eSThomas Hellstrom 
6392cd80dbdSZack Rusin 	struct vmw_fifo_state *fifo;
6403eab3d9eSThomas Hellstrom 	struct vmw_cmdbuf_man *cman;
641ef369904SThomas Hellstrom 	DECLARE_BITMAP(irqthread_pending, VMW_IRQTHREAD_MAX);
642fd567467SThomas Hellstrom 
643d92223eaSZack Rusin 	uint32 *devcaps;
6447a7a933eSMartin Krastev 
6457a7a933eSMartin Krastev 	/*
6467a7a933eSMartin Krastev 	 * mksGuestStat instance-descriptor and pid arrays
6477a7a933eSMartin Krastev 	 */
6487a7a933eSMartin Krastev 	struct page *mksstat_user_pages[MKSSTAT_CAPACITY];
6497a7a933eSMartin Krastev 	atomic_t mksstat_user_pids[MKSSTAT_CAPACITY];
6507a7a933eSMartin Krastev 
6517a7a933eSMartin Krastev #if IS_ENABLED(CONFIG_DRM_VMWGFX_MKSSTATS)
6527a7a933eSMartin Krastev 	struct page *mksstat_kern_pages[MKSSTAT_CAPACITY];
6537a7a933eSMartin Krastev 	u8 mksstat_kern_top_timer[MKSSTAT_CAPACITY];
6547a7a933eSMartin Krastev 	atomic_t mksstat_kern_pids[MKSSTAT_CAPACITY];
6557a7a933eSMartin Krastev #endif
656fb1d9738SJakob Bornecrantz };
657fb1d9738SJakob Bornecrantz 
vmw_res_to_srf(struct vmw_resource * res)658c0951b79SThomas Hellstrom static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res)
659c0951b79SThomas Hellstrom {
660c0951b79SThomas Hellstrom 	return container_of(res, struct vmw_surface, res);
661c0951b79SThomas Hellstrom }
662c0951b79SThomas Hellstrom 
vmw_priv(struct drm_device * dev)663fb1d9738SJakob Bornecrantz static inline struct vmw_private *vmw_priv(struct drm_device *dev)
664fb1d9738SJakob Bornecrantz {
665fb1d9738SJakob Bornecrantz 	return (struct vmw_private *)dev->dev_private;
666fb1d9738SJakob Bornecrantz }
667fb1d9738SJakob Bornecrantz 
vmw_priv_from_ttm(struct ttm_device * bdev)668668b2066SZack Rusin static inline struct vmw_private *vmw_priv_from_ttm(struct ttm_device *bdev)
669668b2066SZack Rusin {
670668b2066SZack Rusin 	return container_of(bdev, struct vmw_private, bdev);
671668b2066SZack Rusin }
672668b2066SZack Rusin 
vmw_fpriv(struct drm_file * file_priv)673fb1d9738SJakob Bornecrantz static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv)
674fb1d9738SJakob Bornecrantz {
675fb1d9738SJakob Bornecrantz 	return (struct vmw_fpriv *)file_priv->driver_priv;
676fb1d9738SJakob Bornecrantz }
677fb1d9738SJakob Bornecrantz 
678496eb6fdSThomas Hellstrom /*
6792cd80dbdSZack Rusin  * SVGA v3 has mmio register access and lacks fifo cmds
6802cd80dbdSZack Rusin  */
vmw_is_svga_v3(const struct vmw_private * dev)6812cd80dbdSZack Rusin static inline bool vmw_is_svga_v3(const struct vmw_private *dev)
6822cd80dbdSZack Rusin {
6832cd80dbdSZack Rusin 	return dev->pci_id == VMWGFX_PCI_ID_SVGA3;
6842cd80dbdSZack Rusin }
6852cd80dbdSZack Rusin 
6862cd80dbdSZack Rusin /*
687496eb6fdSThomas Hellstrom  * The locking here is fine-grained, so that it is performed once
688496eb6fdSThomas Hellstrom  * for every read- and write operation. This is of course costly, but we
689496eb6fdSThomas Hellstrom  * don't perform much register access in the timing critical paths anyway.
690496eb6fdSThomas Hellstrom  * Instead we have the extra benefit of being sure that we don't forget
691496eb6fdSThomas Hellstrom  * the hw lock around register accesses.
692496eb6fdSThomas Hellstrom  */
vmw_write(struct vmw_private * dev_priv,unsigned int offset,uint32_t value)693fb1d9738SJakob Bornecrantz static inline void vmw_write(struct vmw_private *dev_priv,
694fb1d9738SJakob Bornecrantz 			     unsigned int offset, uint32_t value)
695fb1d9738SJakob Bornecrantz {
6962cd80dbdSZack Rusin 	if (vmw_is_svga_v3(dev_priv)) {
6972cd80dbdSZack Rusin 		iowrite32(value, dev_priv->rmmio + offset);
6982cd80dbdSZack Rusin 	} else {
699ef369904SThomas Hellstrom 		spin_lock(&dev_priv->hw_lock);
7002cd80dbdSZack Rusin 		outl(offset, dev_priv->io_start + SVGA_INDEX_PORT);
7012cd80dbdSZack Rusin 		outl(value, dev_priv->io_start + SVGA_VALUE_PORT);
702ef369904SThomas Hellstrom 		spin_unlock(&dev_priv->hw_lock);
703fb1d9738SJakob Bornecrantz 	}
7042cd80dbdSZack Rusin }
705fb1d9738SJakob Bornecrantz 
vmw_read(struct vmw_private * dev_priv,unsigned int offset)706fb1d9738SJakob Bornecrantz static inline uint32_t vmw_read(struct vmw_private *dev_priv,
707fb1d9738SJakob Bornecrantz 				unsigned int offset)
708fb1d9738SJakob Bornecrantz {
709496eb6fdSThomas Hellstrom 	u32 val;
710fb1d9738SJakob Bornecrantz 
7112cd80dbdSZack Rusin 	if (vmw_is_svga_v3(dev_priv)) {
7122cd80dbdSZack Rusin 		val = ioread32(dev_priv->rmmio + offset);
7132cd80dbdSZack Rusin 	} else {
714ef369904SThomas Hellstrom 		spin_lock(&dev_priv->hw_lock);
7152cd80dbdSZack Rusin 		outl(offset, dev_priv->io_start + SVGA_INDEX_PORT);
7162cd80dbdSZack Rusin 		val = inl(dev_priv->io_start + SVGA_VALUE_PORT);
717ef369904SThomas Hellstrom 		spin_unlock(&dev_priv->hw_lock);
7182cd80dbdSZack Rusin 	}
719496eb6fdSThomas Hellstrom 
720fb1d9738SJakob Bornecrantz 	return val;
721fb1d9738SJakob Bornecrantz }
722fb1d9738SJakob Bornecrantz 
723878c6ecdSDeepak Rawat /**
724878c6ecdSDeepak Rawat  * has_sm4_context - Does the device support SM4 context.
725878c6ecdSDeepak Rawat  * @dev_priv: Device private.
726878c6ecdSDeepak Rawat  *
727878c6ecdSDeepak Rawat  * Return: Bool value if device support SM4 context or not.
728878c6ecdSDeepak Rawat  */
has_sm4_context(const struct vmw_private * dev_priv)729878c6ecdSDeepak Rawat static inline bool has_sm4_context(const struct vmw_private *dev_priv)
730878c6ecdSDeepak Rawat {
731878c6ecdSDeepak Rawat 	return (dev_priv->sm_type >= VMW_SM_4);
732878c6ecdSDeepak Rawat }
733878c6ecdSDeepak Rawat 
734878c6ecdSDeepak Rawat /**
735878c6ecdSDeepak Rawat  * has_sm4_1_context - Does the device support SM4_1 context.
736878c6ecdSDeepak Rawat  * @dev_priv: Device private.
737878c6ecdSDeepak Rawat  *
738878c6ecdSDeepak Rawat  * Return: Bool value if device support SM4_1 context or not.
739878c6ecdSDeepak Rawat  */
has_sm4_1_context(const struct vmw_private * dev_priv)740878c6ecdSDeepak Rawat static inline bool has_sm4_1_context(const struct vmw_private *dev_priv)
741878c6ecdSDeepak Rawat {
742878c6ecdSDeepak Rawat 	return (dev_priv->sm_type >= VMW_SM_4_1);
743878c6ecdSDeepak Rawat }
744878c6ecdSDeepak Rawat 
7454dec2805SDeepak Rawat /**
7464dec2805SDeepak Rawat  * has_sm5_context - Does the device support SM5 context.
7474dec2805SDeepak Rawat  * @dev_priv: Device private.
7484dec2805SDeepak Rawat  *
7494dec2805SDeepak Rawat  * Return: Bool value if device support SM5 context or not.
7504dec2805SDeepak Rawat  */
has_sm5_context(const struct vmw_private * dev_priv)7514dec2805SDeepak Rawat static inline bool has_sm5_context(const struct vmw_private *dev_priv)
7524dec2805SDeepak Rawat {
7534dec2805SDeepak Rawat 	return (dev_priv->sm_type >= VMW_SM_5);
7544dec2805SDeepak Rawat }
7554dec2805SDeepak Rawat 
7564fb9326bSZack Rusin /**
7574fb9326bSZack Rusin  * has_gl43_context - Does the device support GL43 context.
7584fb9326bSZack Rusin  * @dev_priv: Device private.
7594fb9326bSZack Rusin  *
7604fb9326bSZack Rusin  * Return: Bool value if device support SM5 context or not.
7614fb9326bSZack Rusin  */
has_gl43_context(const struct vmw_private * dev_priv)7624fb9326bSZack Rusin static inline bool has_gl43_context(const struct vmw_private *dev_priv)
7634fb9326bSZack Rusin {
7644fb9326bSZack Rusin 	return (dev_priv->sm_type >= VMW_SM_5_1X);
7654fb9326bSZack Rusin }
7664fb9326bSZack Rusin 
7674fb9326bSZack Rusin 
vmw_max_num_uavs(struct vmw_private * dev_priv)7684fb9326bSZack Rusin static inline u32 vmw_max_num_uavs(struct vmw_private *dev_priv)
7694fb9326bSZack Rusin {
7704fb9326bSZack Rusin 	return (has_gl43_context(dev_priv) ?
7714fb9326bSZack Rusin 			SVGA3D_DX11_1_MAX_UAVIEWS : SVGA3D_MAX_UAVIEWS);
7724fb9326bSZack Rusin }
7734fb9326bSZack Rusin 
774153b3d5bSThomas Hellstrom extern void vmw_svga_enable(struct vmw_private *dev_priv);
775153b3d5bSThomas Hellstrom extern void vmw_svga_disable(struct vmw_private *dev_priv);
77635d86fb6SZack Rusin bool vmwgfx_supported(struct vmw_private *vmw);
777153b3d5bSThomas Hellstrom 
77830c78bb8SThomas Hellstrom 
779fb1d9738SJakob Bornecrantz /**
780fb1d9738SJakob Bornecrantz  * GMR utilities - vmwgfx_gmr.c
781fb1d9738SJakob Bornecrantz  */
782fb1d9738SJakob Bornecrantz 
783fb1d9738SJakob Bornecrantz extern int vmw_gmr_bind(struct vmw_private *dev_priv,
784d92d9851SThomas Hellstrom 			const struct vmw_sg_table *vsgt,
785135cba0dSThomas Hellstrom 			unsigned long num_pages,
786135cba0dSThomas Hellstrom 			int gmr_id);
787fb1d9738SJakob Bornecrantz extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id);
788fb1d9738SJakob Bornecrantz 
789fb1d9738SJakob Bornecrantz /**
790fb1d9738SJakob Bornecrantz  * Resource utilities - vmwgfx_resource.c
791fb1d9738SJakob Bornecrantz  */
792c0951b79SThomas Hellstrom struct vmw_user_resource_conv;
793fb1d9738SJakob Bornecrantz 
794fb1d9738SJakob Bornecrantz extern void vmw_resource_unreference(struct vmw_resource **p_res);
795fb1d9738SJakob Bornecrantz extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res);
79630f82d81SThomas Hellstrom extern struct vmw_resource *
79730f82d81SThomas Hellstrom vmw_resource_reference_unless_doomed(struct vmw_resource *res);
798fb80edb0SThomas Hellstrom extern int vmw_resource_validate(struct vmw_resource *res, bool intr,
799fb80edb0SThomas Hellstrom 				 bool dirtying);
8001a4b172aSThomas Hellstrom extern int vmw_resource_reserve(struct vmw_resource *res, bool interruptible,
8011a4b172aSThomas Hellstrom 				bool no_backup);
802c0951b79SThomas Hellstrom extern bool vmw_resource_needs_backup(const struct vmw_resource *res);
803551a6697SJakob Bornecrantz extern int vmw_user_lookup_handle(struct vmw_private *dev_priv,
8048afa13a0SZack Rusin 				  struct drm_file *filp,
805551a6697SJakob Bornecrantz 				  uint32_t handle,
806551a6697SJakob Bornecrantz 				  struct vmw_surface **out_surf,
80709881d29SZack Rusin 				  struct vmw_bo **out_buf);
808c0951b79SThomas Hellstrom extern int vmw_user_resource_lookup_handle(
809c0951b79SThomas Hellstrom 	struct vmw_private *dev_priv,
810fb1d9738SJakob Bornecrantz 	struct ttm_object_file *tfile,
8117a73ba74SThomas Hellstrom 	uint32_t handle,
812c0951b79SThomas Hellstrom 	const struct vmw_user_resource_conv *converter,
813c0951b79SThomas Hellstrom 	struct vmw_resource **p_res);
814a309c719SZack Rusin 
815fb1d9738SJakob Bornecrantz extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data,
816fb1d9738SJakob Bornecrantz 				  struct drm_file *file_priv);
817fb1d9738SJakob Bornecrantz extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data,
818fb1d9738SJakob Bornecrantz 				  struct drm_file *file_priv);
819fb1d9738SJakob Bornecrantz extern int vmw_user_stream_lookup(struct vmw_private *dev_priv,
820fb1d9738SJakob Bornecrantz 				  struct ttm_object_file *tfile,
821fb1d9738SJakob Bornecrantz 				  uint32_t *inout_id,
822fb1d9738SJakob Bornecrantz 				  struct vmw_resource **out);
823c0951b79SThomas Hellstrom extern void vmw_resource_unreserve(struct vmw_resource *res,
824a9f58c45SThomas Hellstrom 				   bool dirty_set,
825a9f58c45SThomas Hellstrom 				   bool dirty,
826668b2066SZack Rusin 				   bool switch_guest_memory,
827668b2066SZack Rusin 				   struct vmw_bo *new_guest_memory,
828668b2066SZack Rusin 				   unsigned long new_guest_memory_offset);
829fd11a3c0SSinclair Yeh extern void vmw_query_move_notify(struct ttm_buffer_object *bo,
8306cf9dc23SChristian König 				  struct ttm_resource *old_mem,
8316cf9dc23SChristian König 				  struct ttm_resource *new_mem);
83209881d29SZack Rusin int vmw_query_readback_all(struct vmw_bo *dx_query_mob);
83309881d29SZack Rusin void vmw_resource_evict_all(struct vmw_private *dev_priv);
83409881d29SZack Rusin void vmw_resource_unbind_list(struct vmw_bo *vbo);
835a0a63940SThomas Hellstrom void vmw_resource_mob_attach(struct vmw_resource *res);
836a0a63940SThomas Hellstrom void vmw_resource_mob_detach(struct vmw_resource *res);
837b7468b15SThomas Hellstrom void vmw_resource_dirty_update(struct vmw_resource *res, pgoff_t start,
838b7468b15SThomas Hellstrom 			       pgoff_t end);
83909881d29SZack Rusin int vmw_resources_clean(struct vmw_bo *vbo, pgoff_t start,
840fb80edb0SThomas Hellstrom 			pgoff_t end, pgoff_t *num_prefault);
841a0a63940SThomas Hellstrom 
842a0a63940SThomas Hellstrom /**
843a0a63940SThomas Hellstrom  * vmw_resource_mob_attached - Whether a resource currently has a mob attached
844a0a63940SThomas Hellstrom  * @res: The resource
845a0a63940SThomas Hellstrom  *
846a0a63940SThomas Hellstrom  * Return: true if the resource has a mob attached, false otherwise.
847a0a63940SThomas Hellstrom  */
vmw_resource_mob_attached(const struct vmw_resource * res)848a0a63940SThomas Hellstrom static inline bool vmw_resource_mob_attached(const struct vmw_resource *res)
849a0a63940SThomas Hellstrom {
85061335d7aSThomas Hellstrom 	return !RB_EMPTY_NODE(&res->mob_node);
851a0a63940SThomas Hellstrom }
85279273e1bSThomas Hellstrom 
853d991ef03SJakob Bornecrantz /**
8548afa13a0SZack Rusin  * GEM related functionality - vmwgfx_gem.c
8558afa13a0SZack Rusin  */
85691398b41SZack Rusin struct vmw_bo_params;
85791398b41SZack Rusin int vmw_gem_object_create(struct vmw_private *vmw,
85891398b41SZack Rusin 			  struct vmw_bo_params *params,
85991398b41SZack Rusin 			  struct vmw_bo **p_vbo);
8608afa13a0SZack Rusin extern int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv,
8618afa13a0SZack Rusin 					     struct drm_file *filp,
8628afa13a0SZack Rusin 					     uint32_t size,
8638afa13a0SZack Rusin 					     uint32_t *handle,
86409881d29SZack Rusin 					     struct vmw_bo **p_vbo);
8658afa13a0SZack Rusin extern int vmw_gem_object_create_ioctl(struct drm_device *dev, void *data,
8668afa13a0SZack Rusin 				       struct drm_file *filp);
8678afa13a0SZack Rusin extern void vmw_debugfs_gem_init(struct vmw_private *vdev);
8688afa13a0SZack Rusin 
8698afa13a0SZack Rusin /**
870fb1d9738SJakob Bornecrantz  * Misc Ioctl functionality - vmwgfx_ioctl.c
871fb1d9738SJakob Bornecrantz  */
872fb1d9738SJakob Bornecrantz 
873fb1d9738SJakob Bornecrantz extern int vmw_getparam_ioctl(struct drm_device *dev, void *data,
874fb1d9738SJakob Bornecrantz 			      struct drm_file *file_priv);
875f63f6a59SThomas Hellstrom extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data,
876f63f6a59SThomas Hellstrom 				struct drm_file *file_priv);
8772fcd5a73SJakob Bornecrantz extern int vmw_present_ioctl(struct drm_device *dev, void *data,
8782fcd5a73SJakob Bornecrantz 			     struct drm_file *file_priv);
8792fcd5a73SJakob Bornecrantz extern int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
8802fcd5a73SJakob Bornecrantz 				      struct drm_file *file_priv);
881fb1d9738SJakob Bornecrantz 
882fb1d9738SJakob Bornecrantz /**
883fb1d9738SJakob Bornecrantz  * Fifo utilities - vmwgfx_fifo.c
884fb1d9738SJakob Bornecrantz  */
885fb1d9738SJakob Bornecrantz 
8862cd80dbdSZack Rusin extern struct vmw_fifo_state *vmw_fifo_create(struct vmw_private *dev_priv);
8872cd80dbdSZack Rusin extern void vmw_fifo_destroy(struct vmw_private *dev_priv);
8882cd80dbdSZack Rusin extern bool vmw_cmd_supported(struct vmw_private *vmw);
889d80efd5cSThomas Hellstrom extern void *
8908426ed9cSZack Rusin vmw_cmd_ctx_reserve(struct vmw_private *dev_priv, uint32_t bytes, int ctx_id);
8918426ed9cSZack Rusin extern void vmw_cmd_commit(struct vmw_private *dev_priv, uint32_t bytes);
8928426ed9cSZack Rusin extern void vmw_cmd_commit_flush(struct vmw_private *dev_priv, uint32_t bytes);
8938426ed9cSZack Rusin extern int vmw_cmd_send_fence(struct vmw_private *dev_priv, uint32_t *seqno);
8948426ed9cSZack Rusin extern bool vmw_supports_3d(struct vmw_private *dev_priv);
895fb1d9738SJakob Bornecrantz extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason);
896d7e1958dSJakob Bornecrantz extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv);
8978426ed9cSZack Rusin extern int vmw_cmd_emit_dummy_query(struct vmw_private *dev_priv,
898e2fa3a76SThomas Hellstrom 				    uint32_t cid);
8998426ed9cSZack Rusin extern int vmw_cmd_flush(struct vmw_private *dev_priv,
9003eab3d9eSThomas Hellstrom 			 bool interruptible);
901fb1d9738SJakob Bornecrantz 
9028426ed9cSZack Rusin #define VMW_CMD_CTX_RESERVE(__priv, __bytes, __ctx_id)                        \
90311c45419SDeepak Rawat ({                                                                            \
9048426ed9cSZack Rusin 	vmw_cmd_ctx_reserve(__priv, __bytes, __ctx_id) ? : ({                 \
90511c45419SDeepak Rawat 		DRM_ERROR("FIFO reserve failed at %s for %u bytes\n",         \
90611c45419SDeepak Rawat 			  __func__, (unsigned int) __bytes);                  \
90711c45419SDeepak Rawat 		NULL;                                                         \
90811c45419SDeepak Rawat 	});                                                                   \
90911c45419SDeepak Rawat })
91011c45419SDeepak Rawat 
9118426ed9cSZack Rusin #define VMW_CMD_RESERVE(__priv, __bytes)                                     \
9128426ed9cSZack Rusin 	VMW_CMD_CTX_RESERVE(__priv, __bytes, SVGA3D_INVALID_ID)
91311c45419SDeepak Rawat 
9142cd80dbdSZack Rusin 
9152cd80dbdSZack Rusin /**
9162cd80dbdSZack Rusin  * vmw_fifo_caps - Returns the capabilities of the FIFO command
9172cd80dbdSZack Rusin  * queue or 0 if fifo memory isn't present.
9182cd80dbdSZack Rusin  * @dev_priv: The device private context
9192cd80dbdSZack Rusin  */
vmw_fifo_caps(const struct vmw_private * dev_priv)9202cd80dbdSZack Rusin static inline uint32_t vmw_fifo_caps(const struct vmw_private *dev_priv)
9212cd80dbdSZack Rusin {
9222cd80dbdSZack Rusin 	if (!dev_priv->fifo_mem || !dev_priv->fifo)
9232cd80dbdSZack Rusin 		return 0;
9242cd80dbdSZack Rusin 	return dev_priv->fifo->capabilities;
9252cd80dbdSZack Rusin }
9262cd80dbdSZack Rusin 
9272cd80dbdSZack Rusin 
9282cd80dbdSZack Rusin /**
9292cd80dbdSZack Rusin  * vmw_is_cursor_bypass3_enabled - Returns TRUE iff Cursor Bypass 3
9302cd80dbdSZack Rusin  * is enabled in the FIFO.
9312cd80dbdSZack Rusin  * @dev_priv: The device private context
9322cd80dbdSZack Rusin  */
9332cd80dbdSZack Rusin static inline bool
vmw_is_cursor_bypass3_enabled(const struct vmw_private * dev_priv)9342cd80dbdSZack Rusin vmw_is_cursor_bypass3_enabled(const struct vmw_private *dev_priv)
9352cd80dbdSZack Rusin {
9362cd80dbdSZack Rusin 	return (vmw_fifo_caps(dev_priv) & SVGA_FIFO_CAP_CURSOR_BYPASS_3) != 0;
9372cd80dbdSZack Rusin }
9382cd80dbdSZack Rusin 
939fb1d9738SJakob Bornecrantz /**
940f1d34bfdSThomas Hellstrom  * TTM buffer object driver - vmwgfx_ttm_buffer.c
941fb1d9738SJakob Bornecrantz  */
942fb1d9738SJakob Bornecrantz 
943308d17efSThomas Hellstrom extern const size_t vmw_tt_size;
944fb1d9738SJakob Bornecrantz extern struct ttm_placement vmw_vram_placement;
945135cba0dSThomas Hellstrom extern struct ttm_placement vmw_vram_gmr_placement;
946fb1d9738SJakob Bornecrantz extern struct ttm_placement vmw_sys_placement;
9478af8a109SChristian König extern struct ttm_device_funcs vmw_bo_driver;
9480fd53cfbSThomas Hellstrom extern const struct vmw_sg_table *
9490fd53cfbSThomas Hellstrom vmw_bo_sg_table(struct ttm_buffer_object *bo);
950668b2066SZack Rusin int vmw_bo_create_and_populate(struct vmw_private *dev_priv,
951668b2066SZack Rusin 			       size_t bo_size,
952668b2066SZack Rusin 			       u32 domain,
953668b2066SZack Rusin 			       struct vmw_bo **bo_p);
95456dc01f1SDave Airlie 
955d92d9851SThomas Hellstrom extern void vmw_piter_start(struct vmw_piter *viter,
956d92d9851SThomas Hellstrom 			    const struct vmw_sg_table *vsgt,
957d92d9851SThomas Hellstrom 			    unsigned long p_offs);
958d92d9851SThomas Hellstrom 
959d92d9851SThomas Hellstrom /**
960d92d9851SThomas Hellstrom  * vmw_piter_next - Advance the iterator one page.
961d92d9851SThomas Hellstrom  *
962d92d9851SThomas Hellstrom  * @viter: Pointer to the iterator to advance.
963d92d9851SThomas Hellstrom  *
964d92d9851SThomas Hellstrom  * Returns false if past the list of pages, true otherwise.
965d92d9851SThomas Hellstrom  */
vmw_piter_next(struct vmw_piter * viter)966d92d9851SThomas Hellstrom static inline bool vmw_piter_next(struct vmw_piter *viter)
967d92d9851SThomas Hellstrom {
968d92d9851SThomas Hellstrom 	return viter->next(viter);
969d92d9851SThomas Hellstrom }
970d92d9851SThomas Hellstrom 
971d92d9851SThomas Hellstrom /**
972d92d9851SThomas Hellstrom  * vmw_piter_dma_addr - Return the DMA address of the current page.
973d92d9851SThomas Hellstrom  *
974d92d9851SThomas Hellstrom  * @viter: Pointer to the iterator
975d92d9851SThomas Hellstrom  *
976d92d9851SThomas Hellstrom  * Returns the DMA address of the page pointed to by @viter.
977d92d9851SThomas Hellstrom  */
vmw_piter_dma_addr(struct vmw_piter * viter)978d92d9851SThomas Hellstrom static inline dma_addr_t vmw_piter_dma_addr(struct vmw_piter *viter)
979d92d9851SThomas Hellstrom {
980d92d9851SThomas Hellstrom 	return viter->dma_address(viter);
981d92d9851SThomas Hellstrom }
982d92d9851SThomas Hellstrom 
983d92d9851SThomas Hellstrom /**
984d92d9851SThomas Hellstrom  * vmw_piter_page - Return a pointer to the current page.
985d92d9851SThomas Hellstrom  *
986d92d9851SThomas Hellstrom  * @viter: Pointer to the iterator
987d92d9851SThomas Hellstrom  *
988d92d9851SThomas Hellstrom  * Returns the DMA address of the page pointed to by @viter.
989d92d9851SThomas Hellstrom  */
vmw_piter_page(struct vmw_piter * viter)990d92d9851SThomas Hellstrom static inline struct page *vmw_piter_page(struct vmw_piter *viter)
991d92d9851SThomas Hellstrom {
9928d9a8d9bSZack Rusin 	return viter->pages[viter->i];
993d92d9851SThomas Hellstrom }
994fb1d9738SJakob Bornecrantz 
995fb1d9738SJakob Bornecrantz /**
996fb1d9738SJakob Bornecrantz  * Command submission - vmwgfx_execbuf.c
997fb1d9738SJakob Bornecrantz  */
998fb1d9738SJakob Bornecrantz 
999cbfbe47fSEmil Velikov extern int vmw_execbuf_ioctl(struct drm_device *dev, void *data,
1000cbfbe47fSEmil Velikov 			     struct drm_file *file_priv);
1001922ade0dSThomas Hellstrom extern int vmw_execbuf_process(struct drm_file *file_priv,
1002922ade0dSThomas Hellstrom 			       struct vmw_private *dev_priv,
1003922ade0dSThomas Hellstrom 			       void __user *user_commands,
1004922ade0dSThomas Hellstrom 			       void *kernel_commands,
1005922ade0dSThomas Hellstrom 			       uint32_t command_size,
1006922ade0dSThomas Hellstrom 			       uint64_t throttle_us,
1007d80efd5cSThomas Hellstrom 			       uint32_t dx_context_handle,
1008922ade0dSThomas Hellstrom 			       struct drm_vmw_fence_rep __user
1009bb1bd2f4SJakob Bornecrantz 			       *user_fence_rep,
1010c906965dSSinclair Yeh 			       struct vmw_fence_obj **out_fence,
1011c906965dSSinclair Yeh 			       uint32_t flags);
1012c0951b79SThomas Hellstrom extern void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv,
1013c0951b79SThomas Hellstrom 					    struct vmw_fence_obj *fence);
1014c0951b79SThomas Hellstrom extern void vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv);
1015e2fa3a76SThomas Hellstrom 
10165bb39e81SThomas Hellstrom extern int vmw_execbuf_fence_commands(struct drm_file *file_priv,
10175bb39e81SThomas Hellstrom 				      struct vmw_private *dev_priv,
10185bb39e81SThomas Hellstrom 				      struct vmw_fence_obj **p_fence,
10195bb39e81SThomas Hellstrom 				      uint32_t *p_handle);
1020a0f90c88SMathias Krause extern int vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv,
102157c5ee79SThomas Hellstrom 					struct vmw_fpriv *vmw_fp,
102257c5ee79SThomas Hellstrom 					int ret,
102357c5ee79SThomas Hellstrom 					struct drm_vmw_fence_rep __user
102457c5ee79SThomas Hellstrom 					*user_fence_rep,
102557c5ee79SThomas Hellstrom 					struct vmw_fence_obj *fence,
1026c906965dSSinclair Yeh 					uint32_t fence_handle,
1027a0f90c88SMathias Krause 					int32_t out_fence_fd);
102865b97a2bSThomas Hellstrom bool vmw_cmd_describe(const void *buf, u32 *size, char const **cmd);
10295bb39e81SThomas Hellstrom 
1030fb1d9738SJakob Bornecrantz /**
1031fb1d9738SJakob Bornecrantz  * IRQs and wating - vmwgfx_irq.c
1032fb1d9738SJakob Bornecrantz  */
1033fb1d9738SJakob Bornecrantz 
103432160e6aSZack Rusin extern int vmw_irq_install(struct vmw_private *dev_priv);
1035fb1d9738SJakob Bornecrantz extern void vmw_irq_uninstall(struct drm_device *dev);
10366bcd8d3cSThomas Hellstrom extern bool vmw_seqno_passed(struct vmw_private *dev_priv,
10376bcd8d3cSThomas Hellstrom 				uint32_t seqno);
1038fb1d9738SJakob Bornecrantz extern int vmw_fallback_wait(struct vmw_private *dev_priv,
1039fb1d9738SJakob Bornecrantz 			     bool lazy,
1040fb1d9738SJakob Bornecrantz 			     bool fifo_idle,
10416bcd8d3cSThomas Hellstrom 			     uint32_t seqno,
1042fb1d9738SJakob Bornecrantz 			     bool interruptible,
1043fb1d9738SJakob Bornecrantz 			     unsigned long timeout);
10442cd80dbdSZack Rusin extern void vmw_update_seqno(struct vmw_private *dev_priv);
1045ae2a1040SThomas Hellstrom extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv);
1046ae2a1040SThomas Hellstrom extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv);
104757c5ee79SThomas Hellstrom extern void vmw_goal_waiter_add(struct vmw_private *dev_priv);
104857c5ee79SThomas Hellstrom extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv);
10493eab3d9eSThomas Hellstrom extern void vmw_generic_waiter_add(struct vmw_private *dev_priv, u32 flag,
10503eab3d9eSThomas Hellstrom 				   int *waiter_count);
10513eab3d9eSThomas Hellstrom extern void vmw_generic_waiter_remove(struct vmw_private *dev_priv,
10523eab3d9eSThomas Hellstrom 				      u32 flag, int *waiter_count);
10531925d456SThomas Hellstrom 
1054fb1d9738SJakob Bornecrantz /**
1055fb1d9738SJakob Bornecrantz  * Kernel modesetting - vmwgfx_kms.c
1056fb1d9738SJakob Bornecrantz  */
1057fb1d9738SJakob Bornecrantz 
1058fb1d9738SJakob Bornecrantz int vmw_kms_init(struct vmw_private *dev_priv);
1059fb1d9738SJakob Bornecrantz int vmw_kms_close(struct vmw_private *dev_priv);
1060fb1d9738SJakob Bornecrantz int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data,
1061fb1d9738SJakob Bornecrantz 				struct drm_file *file_priv);
1062fb1d9738SJakob Bornecrantz void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv);
1063fb1d9738SJakob Bornecrantz void vmw_kms_cursor_snoop(struct vmw_surface *srf,
1064fb1d9738SJakob Bornecrantz 			  struct ttm_object_file *tfile,
1065fb1d9738SJakob Bornecrantz 			  struct ttm_buffer_object *bo,
1066fb1d9738SJakob Bornecrantz 			  SVGA3dCmdHeader *header);
10670bef23f9SMichel Dänzer int vmw_kms_write_svga(struct vmw_private *vmw_priv,
1068d7e1958dSJakob Bornecrantz 		       unsigned width, unsigned height, unsigned pitch,
10696558429bSMichel Dänzer 		       unsigned bpp, unsigned depth);
1070e133e737SThomas Hellstrom bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv,
1071e133e737SThomas Hellstrom 				uint32_t pitch,
1072e133e737SThomas Hellstrom 				uint32_t height);
10732fcd5a73SJakob Bornecrantz int vmw_kms_present(struct vmw_private *dev_priv,
10742fcd5a73SJakob Bornecrantz 		    struct drm_file *file_priv,
10752fcd5a73SJakob Bornecrantz 		    struct vmw_framebuffer *vfb,
10762fcd5a73SJakob Bornecrantz 		    struct vmw_surface *surface,
10772fcd5a73SJakob Bornecrantz 		    uint32_t sid, int32_t destX, int32_t destY,
10782fcd5a73SJakob Bornecrantz 		    struct drm_vmw_rect *clips,
10792fcd5a73SJakob Bornecrantz 		    uint32_t num_clips);
1080cd2b89e7SThomas Hellstrom int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data,
1081cd2b89e7SThomas Hellstrom 				struct drm_file *file_priv);
10828fbf9d92SThomas Hellstrom void vmw_kms_legacy_hotspot_clear(struct vmw_private *dev_priv);
1083c3b9b165SThomas Hellstrom int vmw_kms_suspend(struct drm_device *dev);
1084c3b9b165SThomas Hellstrom int vmw_kms_resume(struct drm_device *dev);
1085140bcaa2SThomas Hellstrom void vmw_kms_lost_device(struct drm_device *dev);
1086fb1d9738SJakob Bornecrantz 
10875e1782d2SDave Airlie int vmw_dumb_create(struct drm_file *file_priv,
10885e1782d2SDave Airlie 		    struct drm_device *dev,
10895e1782d2SDave Airlie 		    struct drm_mode_create_dumb *args);
10901a4b172aSThomas Hellstrom extern int vmw_resource_pin(struct vmw_resource *res, bool interruptible);
1091ed93394cSThomas Hellstrom extern void vmw_resource_unpin(struct vmw_resource *res);
1092d80efd5cSThomas Hellstrom extern enum vmw_res_type vmw_res_type(const struct vmw_resource *res);
1093ed93394cSThomas Hellstrom 
1094fb1d9738SJakob Bornecrantz /**
1095fb1d9738SJakob Bornecrantz  * Overlay control - vmwgfx_overlay.c
1096fb1d9738SJakob Bornecrantz  */
1097fb1d9738SJakob Bornecrantz 
1098fb1d9738SJakob Bornecrantz int vmw_overlay_init(struct vmw_private *dev_priv);
1099fb1d9738SJakob Bornecrantz int vmw_overlay_close(struct vmw_private *dev_priv);
1100fb1d9738SJakob Bornecrantz int vmw_overlay_ioctl(struct drm_device *dev, void *data,
1101fb1d9738SJakob Bornecrantz 		      struct drm_file *file_priv);
1102fb1d9738SJakob Bornecrantz int vmw_overlay_resume_all(struct vmw_private *dev_priv);
1103fb1d9738SJakob Bornecrantz int vmw_overlay_pause_all(struct vmw_private *dev_priv);
1104fb1d9738SJakob Bornecrantz int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out);
1105fb1d9738SJakob Bornecrantz int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id);
1106fb1d9738SJakob Bornecrantz int vmw_overlay_num_overlays(struct vmw_private *dev_priv);
1107fb1d9738SJakob Bornecrantz int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
1108fb1d9738SJakob Bornecrantz 
1109fb1d9738SJakob Bornecrantz /**
1110135cba0dSThomas Hellstrom  * GMR Id manager
1111135cba0dSThomas Hellstrom  */
1112135cba0dSThomas Hellstrom 
111362161778SDave Airlie int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type);
11146eee6675SDave Airlie void vmw_gmrid_man_fini(struct vmw_private *dev_priv, int type);
1115135cba0dSThomas Hellstrom 
1116135cba0dSThomas Hellstrom /**
1117f6be2326SZack Rusin  * System memory manager
1118f6be2326SZack Rusin  */
1119f6be2326SZack Rusin int vmw_sys_man_init(struct vmw_private *dev_priv);
1120f6be2326SZack Rusin void vmw_sys_man_fini(struct vmw_private *dev_priv);
1121f6be2326SZack Rusin 
1122f6be2326SZack Rusin /**
112369977ff5SThomas Hellstrom  * Prime - vmwgfx_prime.c
112469977ff5SThomas Hellstrom  */
112569977ff5SThomas Hellstrom 
112669977ff5SThomas Hellstrom extern const struct dma_buf_ops vmw_prime_dmabuf_ops;
112769977ff5SThomas Hellstrom extern int vmw_prime_fd_to_handle(struct drm_device *dev,
112869977ff5SThomas Hellstrom 				  struct drm_file *file_priv,
112969977ff5SThomas Hellstrom 				  int fd, u32 *handle);
113069977ff5SThomas Hellstrom extern int vmw_prime_handle_to_fd(struct drm_device *dev,
113169977ff5SThomas Hellstrom 				  struct drm_file *file_priv,
113269977ff5SThomas Hellstrom 				  uint32_t handle, uint32_t flags,
113369977ff5SThomas Hellstrom 				  int *prime_fd);
113465674218SZack Rusin struct drm_gem_object *vmw_prime_import_sg_table(struct drm_device *dev,
113565674218SZack Rusin 						 struct dma_buf_attachment *attach,
113665674218SZack Rusin 						 struct sg_table *table);
113769977ff5SThomas Hellstrom 
11383530bdc3SThomas Hellstrom /*
11393530bdc3SThomas Hellstrom  * MemoryOBject management -  vmwgfx_mob.c
11403530bdc3SThomas Hellstrom  */
11413530bdc3SThomas Hellstrom struct vmw_mob;
11423530bdc3SThomas Hellstrom extern int vmw_mob_bind(struct vmw_private *dev_priv, struct vmw_mob *mob,
11430fd53cfbSThomas Hellstrom 			const struct vmw_sg_table *vsgt,
11440fd53cfbSThomas Hellstrom 			unsigned long num_data_pages, int32_t mob_id);
11453530bdc3SThomas Hellstrom extern void vmw_mob_unbind(struct vmw_private *dev_priv,
11463530bdc3SThomas Hellstrom 			   struct vmw_mob *mob);
11473530bdc3SThomas Hellstrom extern void vmw_mob_destroy(struct vmw_mob *mob);
11483530bdc3SThomas Hellstrom extern struct vmw_mob *vmw_mob_create(unsigned long data_pages);
11493530bdc3SThomas Hellstrom extern int vmw_otables_setup(struct vmw_private *dev_priv);
11503530bdc3SThomas Hellstrom extern void vmw_otables_takedown(struct vmw_private *dev_priv);
115169977ff5SThomas Hellstrom 
1152c74c162fSThomas Hellstrom /*
11537086d099SThomas Hellstrom  * Context management - vmwgfx_context.c
11547086d099SThomas Hellstrom  */
11557086d099SThomas Hellstrom 
11567086d099SThomas Hellstrom extern const struct vmw_user_resource_conv *user_context_converter;
11577086d099SThomas Hellstrom 
11587086d099SThomas Hellstrom extern int vmw_context_define_ioctl(struct drm_device *dev, void *data,
11597086d099SThomas Hellstrom 				    struct drm_file *file_priv);
1160d80efd5cSThomas Hellstrom extern int vmw_extended_context_define_ioctl(struct drm_device *dev, void *data,
1161d80efd5cSThomas Hellstrom 					     struct drm_file *file_priv);
11627086d099SThomas Hellstrom extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data,
11637086d099SThomas Hellstrom 				     struct drm_file *file_priv);
116430f82d81SThomas Hellstrom extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx);
116518e4a466SThomas Hellstrom extern struct vmw_cmdbuf_res_manager *
116618e4a466SThomas Hellstrom vmw_context_res_man(struct vmw_resource *ctx);
1167d80efd5cSThomas Hellstrom extern struct vmw_resource *vmw_context_cotable(struct vmw_resource *ctx,
1168d80efd5cSThomas Hellstrom 						SVGACOTableType cotable_type);
1169d80efd5cSThomas Hellstrom struct vmw_ctx_binding_state;
1170d80efd5cSThomas Hellstrom extern struct vmw_ctx_binding_state *
1171d80efd5cSThomas Hellstrom vmw_context_binding_state(struct vmw_resource *ctx);
1172d80efd5cSThomas Hellstrom extern void vmw_dx_context_scrub_cotables(struct vmw_resource *ctx,
1173d80efd5cSThomas Hellstrom 					  bool readback);
1174fd11a3c0SSinclair Yeh extern int vmw_context_bind_dx_query(struct vmw_resource *ctx_res,
117509881d29SZack Rusin 				     struct vmw_bo *mob);
117609881d29SZack Rusin extern struct vmw_bo *
1177fd11a3c0SSinclair Yeh vmw_context_get_dx_query_mob(struct vmw_resource *ctx_res);
1178fd11a3c0SSinclair Yeh 
1179d80efd5cSThomas Hellstrom 
11807086d099SThomas Hellstrom /*
11817086d099SThomas Hellstrom  * Surface management - vmwgfx_surface.c
11827086d099SThomas Hellstrom  */
11837086d099SThomas Hellstrom 
11847086d099SThomas Hellstrom extern const struct vmw_user_resource_conv *user_surface_converter;
11857086d099SThomas Hellstrom 
11867086d099SThomas Hellstrom extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data,
11877086d099SThomas Hellstrom 				     struct drm_file *file_priv);
11887086d099SThomas Hellstrom extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data,
11897086d099SThomas Hellstrom 				    struct drm_file *file_priv);
11907086d099SThomas Hellstrom extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data,
11917086d099SThomas Hellstrom 				       struct drm_file *file_priv);
11927086d099SThomas Hellstrom extern int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data,
11937086d099SThomas Hellstrom 				       struct drm_file *file_priv);
11947086d099SThomas Hellstrom extern int vmw_gb_surface_reference_ioctl(struct drm_device *dev, void *data,
11957086d099SThomas Hellstrom 					  struct drm_file *file_priv);
119614b1c33eSDeepak Rawat extern int vmw_gb_surface_define_ext_ioctl(struct drm_device *dev,
119714b1c33eSDeepak Rawat 					   void *data,
119814b1c33eSDeepak Rawat 					   struct drm_file *file_priv);
119914b1c33eSDeepak Rawat extern int vmw_gb_surface_reference_ext_ioctl(struct drm_device *dev,
120014b1c33eSDeepak Rawat 					      void *data,
120114b1c33eSDeepak Rawat 					      struct drm_file *file_priv);
12027086d099SThomas Hellstrom 
1203504901dbSDeepak Rawat int vmw_gb_surface_define(struct vmw_private *dev_priv,
1204504901dbSDeepak Rawat 			  const struct vmw_surface_metadata *req,
1205504901dbSDeepak Rawat 			  struct vmw_surface **srf_out);
1206504901dbSDeepak Rawat 
12077086d099SThomas Hellstrom /*
1208c74c162fSThomas Hellstrom  * Shader management - vmwgfx_shader.c
1209c74c162fSThomas Hellstrom  */
1210c74c162fSThomas Hellstrom 
12117086d099SThomas Hellstrom extern const struct vmw_user_resource_conv *user_shader_converter;
12127086d099SThomas Hellstrom 
1213c74c162fSThomas Hellstrom extern int vmw_shader_define_ioctl(struct drm_device *dev, void *data,
1214c74c162fSThomas Hellstrom 				   struct drm_file *file_priv);
1215c74c162fSThomas Hellstrom extern int vmw_shader_destroy_ioctl(struct drm_device *dev, void *data,
1216c74c162fSThomas Hellstrom 				    struct drm_file *file_priv);
121718e4a466SThomas Hellstrom extern int vmw_compat_shader_add(struct vmw_private *dev_priv,
121818e4a466SThomas Hellstrom 				 struct vmw_cmdbuf_res_manager *man,
1219d5bde956SThomas Hellstrom 				 u32 user_key, const void *bytecode,
1220d5bde956SThomas Hellstrom 				 SVGA3dShaderType shader_type,
1221d5bde956SThomas Hellstrom 				 size_t size,
1222d5bde956SThomas Hellstrom 				 struct list_head *list);
1223d80efd5cSThomas Hellstrom extern int vmw_shader_remove(struct vmw_cmdbuf_res_manager *man,
122418e4a466SThomas Hellstrom 			     u32 user_key, SVGA3dShaderType shader_type,
122518e4a466SThomas Hellstrom 			     struct list_head *list);
1226d80efd5cSThomas Hellstrom extern int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man,
1227d80efd5cSThomas Hellstrom 			     struct vmw_resource *ctx,
1228d80efd5cSThomas Hellstrom 			     u32 user_key,
1229d80efd5cSThomas Hellstrom 			     SVGA3dShaderType shader_type,
1230d80efd5cSThomas Hellstrom 			     struct list_head *list);
1231d80efd5cSThomas Hellstrom extern void vmw_dx_shader_cotable_list_scrub(struct vmw_private *dev_priv,
1232d80efd5cSThomas Hellstrom 					     struct list_head *list,
1233d80efd5cSThomas Hellstrom 					     bool readback);
1234d80efd5cSThomas Hellstrom 
123518e4a466SThomas Hellstrom extern struct vmw_resource *
1236d80efd5cSThomas Hellstrom vmw_shader_lookup(struct vmw_cmdbuf_res_manager *man,
123718e4a466SThomas Hellstrom 		  u32 user_key, SVGA3dShaderType shader_type);
123818e4a466SThomas Hellstrom 
123918e4a466SThomas Hellstrom /*
1240e8bead9cSDeepak Rawat  * Streamoutput management
1241e8bead9cSDeepak Rawat  */
1242e8bead9cSDeepak Rawat struct vmw_resource *
1243e8bead9cSDeepak Rawat vmw_dx_streamoutput_lookup(struct vmw_cmdbuf_res_manager *man,
1244e8bead9cSDeepak Rawat 			   u32 user_key);
1245e8bead9cSDeepak Rawat int vmw_dx_streamoutput_add(struct vmw_cmdbuf_res_manager *man,
1246e8bead9cSDeepak Rawat 			    struct vmw_resource *ctx,
1247e8bead9cSDeepak Rawat 			    SVGA3dStreamOutputId user_key,
1248e8bead9cSDeepak Rawat 			    struct list_head *list);
1249e8bead9cSDeepak Rawat void vmw_dx_streamoutput_set_size(struct vmw_resource *res, u32 size);
1250e8bead9cSDeepak Rawat int vmw_dx_streamoutput_remove(struct vmw_cmdbuf_res_manager *man,
1251e8bead9cSDeepak Rawat 			       SVGA3dStreamOutputId user_key,
1252e8bead9cSDeepak Rawat 			       struct list_head *list);
1253e8bead9cSDeepak Rawat void vmw_dx_streamoutput_cotable_list_scrub(struct vmw_private *dev_priv,
1254e8bead9cSDeepak Rawat 					    struct list_head *list,
1255e8bead9cSDeepak Rawat 					    bool readback);
1256e8bead9cSDeepak Rawat 
1257e8bead9cSDeepak Rawat /*
125818e4a466SThomas Hellstrom  * Command buffer managed resources - vmwgfx_cmdbuf_res.c
125918e4a466SThomas Hellstrom  */
126018e4a466SThomas Hellstrom 
126118e4a466SThomas Hellstrom extern struct vmw_cmdbuf_res_manager *
126218e4a466SThomas Hellstrom vmw_cmdbuf_res_man_create(struct vmw_private *dev_priv);
126318e4a466SThomas Hellstrom extern void vmw_cmdbuf_res_man_destroy(struct vmw_cmdbuf_res_manager *man);
126418e4a466SThomas Hellstrom extern struct vmw_resource *
126518e4a466SThomas Hellstrom vmw_cmdbuf_res_lookup(struct vmw_cmdbuf_res_manager *man,
126618e4a466SThomas Hellstrom 		      enum vmw_cmdbuf_res_type res_type,
126718e4a466SThomas Hellstrom 		      u32 user_key);
126818e4a466SThomas Hellstrom extern void vmw_cmdbuf_res_revert(struct list_head *list);
126918e4a466SThomas Hellstrom extern void vmw_cmdbuf_res_commit(struct list_head *list);
127018e4a466SThomas Hellstrom extern int vmw_cmdbuf_res_add(struct vmw_cmdbuf_res_manager *man,
127118e4a466SThomas Hellstrom 			      enum vmw_cmdbuf_res_type res_type,
127218e4a466SThomas Hellstrom 			      u32 user_key,
127318e4a466SThomas Hellstrom 			      struct vmw_resource *res,
127418e4a466SThomas Hellstrom 			      struct list_head *list);
127518e4a466SThomas Hellstrom extern int vmw_cmdbuf_res_remove(struct vmw_cmdbuf_res_manager *man,
127618e4a466SThomas Hellstrom 				 enum vmw_cmdbuf_res_type res_type,
127718e4a466SThomas Hellstrom 				 u32 user_key,
1278d80efd5cSThomas Hellstrom 				 struct list_head *list,
1279d80efd5cSThomas Hellstrom 				 struct vmw_resource **res);
1280d5bde956SThomas Hellstrom 
1281d80efd5cSThomas Hellstrom /*
1282d80efd5cSThomas Hellstrom  * COTable management - vmwgfx_cotable.c
1283d80efd5cSThomas Hellstrom  */
1284d80efd5cSThomas Hellstrom extern const SVGACOTableType vmw_cotable_scrub_order[];
1285d80efd5cSThomas Hellstrom extern struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv,
1286d80efd5cSThomas Hellstrom 					      struct vmw_resource *ctx,
1287d80efd5cSThomas Hellstrom 					      u32 type);
1288d80efd5cSThomas Hellstrom extern int vmw_cotable_notify(struct vmw_resource *res, int id);
1289d80efd5cSThomas Hellstrom extern int vmw_cotable_scrub(struct vmw_resource *res, bool readback);
1290d80efd5cSThomas Hellstrom extern void vmw_cotable_add_resource(struct vmw_resource *ctx,
1291d80efd5cSThomas Hellstrom 				     struct list_head *head);
1292c74c162fSThomas Hellstrom 
12933eab3d9eSThomas Hellstrom /*
12943eab3d9eSThomas Hellstrom  * Command buffer managerment vmwgfx_cmdbuf.c
12953eab3d9eSThomas Hellstrom  */
12963eab3d9eSThomas Hellstrom struct vmw_cmdbuf_man;
12973eab3d9eSThomas Hellstrom struct vmw_cmdbuf_header;
12983eab3d9eSThomas Hellstrom 
12993eab3d9eSThomas Hellstrom extern struct vmw_cmdbuf_man *
13003eab3d9eSThomas Hellstrom vmw_cmdbuf_man_create(struct vmw_private *dev_priv);
13018426ed9cSZack Rusin extern int vmw_cmdbuf_set_pool_size(struct vmw_cmdbuf_man *man, size_t size);
13023eab3d9eSThomas Hellstrom extern void vmw_cmdbuf_remove_pool(struct vmw_cmdbuf_man *man);
13033eab3d9eSThomas Hellstrom extern void vmw_cmdbuf_man_destroy(struct vmw_cmdbuf_man *man);
13043eab3d9eSThomas Hellstrom extern int vmw_cmdbuf_idle(struct vmw_cmdbuf_man *man, bool interruptible,
13053eab3d9eSThomas Hellstrom 			   unsigned long timeout);
13063eab3d9eSThomas Hellstrom extern void *vmw_cmdbuf_reserve(struct vmw_cmdbuf_man *man, size_t size,
13073eab3d9eSThomas Hellstrom 				int ctx_id, bool interruptible,
13083eab3d9eSThomas Hellstrom 				struct vmw_cmdbuf_header *header);
13093eab3d9eSThomas Hellstrom extern void vmw_cmdbuf_commit(struct vmw_cmdbuf_man *man, size_t size,
13103eab3d9eSThomas Hellstrom 			      struct vmw_cmdbuf_header *header,
13113eab3d9eSThomas Hellstrom 			      bool flush);
13123eab3d9eSThomas Hellstrom extern void *vmw_cmdbuf_alloc(struct vmw_cmdbuf_man *man,
13133eab3d9eSThomas Hellstrom 			      size_t size, bool interruptible,
13143eab3d9eSThomas Hellstrom 			      struct vmw_cmdbuf_header **p_header);
13153eab3d9eSThomas Hellstrom extern void vmw_cmdbuf_header_free(struct vmw_cmdbuf_header *header);
13163eab3d9eSThomas Hellstrom extern int vmw_cmdbuf_cur_flush(struct vmw_cmdbuf_man *man,
13173eab3d9eSThomas Hellstrom 				bool interruptible);
1318ef369904SThomas Hellstrom extern void vmw_cmdbuf_irqthread(struct vmw_cmdbuf_man *man);
1319bf6f0368SThomas Hellstrom 
132079273e1bSThomas Hellstrom /* CPU blit utilities - vmwgfx_blit.c */
132179273e1bSThomas Hellstrom 
132279273e1bSThomas Hellstrom /**
132379273e1bSThomas Hellstrom  * struct vmw_diff_cpy - CPU blit information structure
132479273e1bSThomas Hellstrom  *
132579273e1bSThomas Hellstrom  * @rect: The output bounding box rectangle.
132679273e1bSThomas Hellstrom  * @line: The current line of the blit.
132779273e1bSThomas Hellstrom  * @line_offset: Offset of the current line segment.
132879273e1bSThomas Hellstrom  * @cpp: Bytes per pixel (granularity information).
132979273e1bSThomas Hellstrom  * @memcpy: Which memcpy function to use.
133079273e1bSThomas Hellstrom  */
133179273e1bSThomas Hellstrom struct vmw_diff_cpy {
133279273e1bSThomas Hellstrom 	struct drm_rect rect;
133379273e1bSThomas Hellstrom 	size_t line;
133479273e1bSThomas Hellstrom 	size_t line_offset;
133579273e1bSThomas Hellstrom 	int cpp;
133679273e1bSThomas Hellstrom 	void (*do_cpy)(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src,
133779273e1bSThomas Hellstrom 		       size_t n);
133879273e1bSThomas Hellstrom };
133979273e1bSThomas Hellstrom 
134079273e1bSThomas Hellstrom #define VMW_CPU_BLIT_INITIALIZER {	\
134179273e1bSThomas Hellstrom 	.do_cpy = vmw_memcpy,		\
134279273e1bSThomas Hellstrom }
134379273e1bSThomas Hellstrom 
134479273e1bSThomas Hellstrom #define VMW_CPU_BLIT_DIFF_INITIALIZER(_cpp) {	  \
134579273e1bSThomas Hellstrom 	.line = 0,				  \
134679273e1bSThomas Hellstrom 	.line_offset = 0,			  \
134779273e1bSThomas Hellstrom 	.rect = { .x1 = INT_MAX/2,		  \
134879273e1bSThomas Hellstrom 		  .y1 = INT_MAX/2,		  \
134979273e1bSThomas Hellstrom 		  .x2 = INT_MIN/2,		  \
135079273e1bSThomas Hellstrom 		  .y2 = INT_MIN/2		  \
135179273e1bSThomas Hellstrom 	},					  \
135279273e1bSThomas Hellstrom 	.cpp = _cpp,				  \
135379273e1bSThomas Hellstrom 	.do_cpy = vmw_diff_memcpy,		  \
135479273e1bSThomas Hellstrom }
135579273e1bSThomas Hellstrom 
135679273e1bSThomas Hellstrom void vmw_diff_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src,
135779273e1bSThomas Hellstrom 		     size_t n);
135879273e1bSThomas Hellstrom 
135979273e1bSThomas Hellstrom void vmw_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src, size_t n);
136079273e1bSThomas Hellstrom 
136179273e1bSThomas Hellstrom int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
136279273e1bSThomas Hellstrom 		    u32 dst_offset, u32 dst_stride,
136379273e1bSThomas Hellstrom 		    struct ttm_buffer_object *src,
136479273e1bSThomas Hellstrom 		    u32 src_offset, u32 src_stride,
136579273e1bSThomas Hellstrom 		    u32 w, u32 h,
136679273e1bSThomas Hellstrom 		    struct vmw_diff_cpy *diff);
1367fb1d9738SJakob Bornecrantz 
13686ff67ae7SThomas Hellstrom /* Host messaging -vmwgfx_msg.c: */
136935d86fb6SZack Rusin void vmw_disable_backdoor(void);
13706ff67ae7SThomas Hellstrom int vmw_host_get_guestinfo(const char *guest_info_param,
13716ff67ae7SThomas Hellstrom 			   char *buffer, size_t *length);
1372523375c9SZack Rusin __printf(1, 2) int vmw_host_printf(const char *fmt, ...);
1373cb92a323SRoland Scheidegger int vmw_msg_ioctl(struct drm_device *dev, void *data,
1374cb92a323SRoland Scheidegger 		  struct drm_file *file_priv);
13756ff67ae7SThomas Hellstrom 
13767a7a933eSMartin Krastev /* Host mksGuestStats -vmwgfx_msg.c: */
13777a7a933eSMartin Krastev int vmw_mksstat_get_kern_slot(pid_t pid, struct vmw_private *dev_priv);
13787a7a933eSMartin Krastev 
13797a7a933eSMartin Krastev int vmw_mksstat_reset_ioctl(struct drm_device *dev, void *data,
13807a7a933eSMartin Krastev 		      struct drm_file *file_priv);
13817a7a933eSMartin Krastev int vmw_mksstat_add_ioctl(struct drm_device *dev, void *data,
13827a7a933eSMartin Krastev 		      struct drm_file *file_priv);
13837a7a933eSMartin Krastev int vmw_mksstat_remove_ioctl(struct drm_device *dev, void *data,
13847a7a933eSMartin Krastev 		      struct drm_file *file_priv);
13857a7a933eSMartin Krastev int vmw_mksstat_remove_all(struct vmw_private *dev_priv);
13867a7a933eSMartin Krastev 
13875724f899SDeepak Rawat /* VMW logging */
13885724f899SDeepak Rawat 
13895724f899SDeepak Rawat /**
13905724f899SDeepak Rawat  * VMW_DEBUG_USER - Debug output for user-space debugging.
13915724f899SDeepak Rawat  *
13925724f899SDeepak Rawat  * @fmt: printf() like format string.
13935724f899SDeepak Rawat  *
13945724f899SDeepak Rawat  * This macro is for logging user-space error and debugging messages for e.g.
13955724f899SDeepak Rawat  * command buffer execution errors due to malformed commands, invalid context,
13965724f899SDeepak Rawat  * etc.
13975724f899SDeepak Rawat  */
13985724f899SDeepak Rawat #define VMW_DEBUG_USER(fmt, ...)                                              \
13995724f899SDeepak Rawat 	DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__)
14005724f899SDeepak Rawat 
1401b7468b15SThomas Hellstrom /* Resource dirtying - vmwgfx_page_dirty.c */
140209881d29SZack Rusin void vmw_bo_dirty_scan(struct vmw_bo *vbo);
140309881d29SZack Rusin int vmw_bo_dirty_add(struct vmw_bo *vbo);
1404b7468b15SThomas Hellstrom void vmw_bo_dirty_transfer_to_res(struct vmw_resource *res);
1405b7468b15SThomas Hellstrom void vmw_bo_dirty_clear_res(struct vmw_resource *res);
140609881d29SZack Rusin void vmw_bo_dirty_release(struct vmw_bo *vbo);
140709881d29SZack Rusin void vmw_bo_dirty_unmap(struct vmw_bo *vbo,
1408fb80edb0SThomas Hellstrom 			pgoff_t start, pgoff_t end);
1409b7468b15SThomas Hellstrom vm_fault_t vmw_bo_vm_fault(struct vm_fault *vmf);
1410b7468b15SThomas Hellstrom vm_fault_t vmw_bo_vm_mkwrite(struct vm_fault *vmf);
1411b7468b15SThomas Hellstrom 
1412fb1d9738SJakob Bornecrantz 
1413fb1d9738SJakob Bornecrantz /**
1414fb1d9738SJakob Bornecrantz  * VMW_DEBUG_KMS - Debug output for kernel mode-setting
1415fb1d9738SJakob Bornecrantz  *
1416fb1d9738SJakob Bornecrantz  * This macro is for debugging vmwgfx mode-setting code.
1417fb1d9738SJakob Bornecrantz  */
1418fb1d9738SJakob Bornecrantz #define VMW_DEBUG_KMS(fmt, ...)                                               \
1419fb1d9738SJakob Bornecrantz 	DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__)
1420fb1d9738SJakob Bornecrantz 
1421fb1d9738SJakob Bornecrantz /**
1422fb1d9738SJakob Bornecrantz  * Inline helper functions
1423f1d34bfdSThomas Hellstrom  */
1424fb1d9738SJakob Bornecrantz 
vmw_surface_unreference(struct vmw_surface ** srf)1425f1d34bfdSThomas Hellstrom static inline void vmw_surface_unreference(struct vmw_surface **srf)
1426fb1d9738SJakob Bornecrantz {
1427fb1d9738SJakob Bornecrantz 	struct vmw_surface *tmp_srf = *srf;
1428fb1d9738SJakob Bornecrantz 	struct vmw_resource *res = &tmp_srf->res;
14296034d9d4SThomas Zimmermann 	*srf = NULL;
1430fb1d9738SJakob Bornecrantz 
1431bf6f0368SThomas Hellstrom 	vmw_resource_unreference(&res);
1432fb1d9738SJakob Bornecrantz }
1433f1d34bfdSThomas Hellstrom 
vmw_surface_reference(struct vmw_surface * srf)1434f1d34bfdSThomas Hellstrom static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf)
1435fb1d9738SJakob Bornecrantz {
14362d18cb98SThomas Zimmermann 	(void) vmw_resource_reference(&srf->res);
1437fb1d9738SJakob Bornecrantz 	return srf;
1438fb1d9738SJakob Bornecrantz }
1439fb1d9738SJakob Bornecrantz 
vmw_fifo_resource_inc(struct vmw_private * dev_priv)1440153b3d5bSThomas Hellstrom static inline void vmw_fifo_resource_inc(struct vmw_private *dev_priv)
1441153b3d5bSThomas Hellstrom {
1442153b3d5bSThomas Hellstrom 	atomic_inc(&dev_priv->num_fifo_resources);
1443153b3d5bSThomas Hellstrom }
1444153b3d5bSThomas Hellstrom 
vmw_fifo_resource_dec(struct vmw_private * dev_priv)1445153b3d5bSThomas Hellstrom static inline void vmw_fifo_resource_dec(struct vmw_private *dev_priv)
1446153b3d5bSThomas Hellstrom {
1447153b3d5bSThomas Hellstrom 	atomic_dec(&dev_priv->num_fifo_resources);
1448153b3d5bSThomas Hellstrom }
1449b76ff5eaSThomas Hellstrom 
1450b76ff5eaSThomas Hellstrom /**
1451be4f77acSZack Rusin  * vmw_fifo_mem_read - Perform a MMIO read from the fifo memory
1452b76ff5eaSThomas Hellstrom  *
1453be4f77acSZack Rusin  * @fifo_reg: The fifo register to read from
1454b76ff5eaSThomas Hellstrom  *
1455b76ff5eaSThomas Hellstrom  * This function is intended to be equivalent to ioread32() on
1456b76ff5eaSThomas Hellstrom  * memremap'd memory, but without byteswapping.
1457b76ff5eaSThomas Hellstrom  */
vmw_fifo_mem_read(struct vmw_private * vmw,uint32 fifo_reg)1458be4f77acSZack Rusin static inline u32 vmw_fifo_mem_read(struct vmw_private *vmw, uint32 fifo_reg)
1459b76ff5eaSThomas Hellstrom {
14602cd80dbdSZack Rusin 	BUG_ON(vmw_is_svga_v3(vmw));
1461be4f77acSZack Rusin 	return READ_ONCE(*(vmw->fifo_mem + fifo_reg));
1462b76ff5eaSThomas Hellstrom }
1463b76ff5eaSThomas Hellstrom 
1464b76ff5eaSThomas Hellstrom /**
1465be4f77acSZack Rusin  * vmw_fifo_mem_write - Perform a MMIO write to volatile memory
1466b76ff5eaSThomas Hellstrom  *
1467be4f77acSZack Rusin  * @addr: The fifo register to write to
1468b76ff5eaSThomas Hellstrom  *
1469b76ff5eaSThomas Hellstrom  * This function is intended to be equivalent to iowrite32 on
1470b76ff5eaSThomas Hellstrom  * memremap'd memory, but without byteswapping.
1471b76ff5eaSThomas Hellstrom  */
vmw_fifo_mem_write(struct vmw_private * vmw,u32 fifo_reg,u32 value)1472be4f77acSZack Rusin static inline void vmw_fifo_mem_write(struct vmw_private *vmw, u32 fifo_reg,
1473be4f77acSZack Rusin 				      u32 value)
1474b76ff5eaSThomas Hellstrom {
14752cd80dbdSZack Rusin 	BUG_ON(vmw_is_svga_v3(vmw));
1476be4f77acSZack Rusin 	WRITE_ONCE(*(vmw->fifo_mem + fifo_reg), value);
1477b76ff5eaSThomas Hellstrom }
14782cd80dbdSZack Rusin 
vmw_fence_read(struct vmw_private * dev_priv)14792cd80dbdSZack Rusin static inline u32 vmw_fence_read(struct vmw_private *dev_priv)
14802cd80dbdSZack Rusin {
14812cd80dbdSZack Rusin 	u32 fence;
14822cd80dbdSZack Rusin 	if (vmw_is_svga_v3(dev_priv))
14832cd80dbdSZack Rusin 		fence = vmw_read(dev_priv, SVGA_REG_FENCE);
14842cd80dbdSZack Rusin 	else
14852cd80dbdSZack Rusin 		fence = vmw_fifo_mem_read(dev_priv, SVGA_FIFO_FENCE);
14862cd80dbdSZack Rusin 	return fence;
14872cd80dbdSZack Rusin }
14882cd80dbdSZack Rusin 
vmw_fence_write(struct vmw_private * dev_priv,u32 fence)14892cd80dbdSZack Rusin static inline void vmw_fence_write(struct vmw_private *dev_priv,
14902cd80dbdSZack Rusin 				  u32 fence)
14912cd80dbdSZack Rusin {
14922cd80dbdSZack Rusin 	BUG_ON(vmw_is_svga_v3(dev_priv));
14932cd80dbdSZack Rusin 	vmw_fifo_mem_write(dev_priv, SVGA_FIFO_FENCE, fence);
14942cd80dbdSZack Rusin }
14952cd80dbdSZack Rusin 
vmw_irq_status_read(struct vmw_private * vmw)14962cd80dbdSZack Rusin static inline u32 vmw_irq_status_read(struct vmw_private *vmw)
14972cd80dbdSZack Rusin {
14982cd80dbdSZack Rusin 	u32 status;
14992cd80dbdSZack Rusin 	if (vmw_is_svga_v3(vmw))
15002cd80dbdSZack Rusin 		status = vmw_read(vmw, SVGA_REG_IRQ_STATUS);
15012cd80dbdSZack Rusin 	else
15022cd80dbdSZack Rusin 		status = inl(vmw->io_start + SVGA_IRQSTATUS_PORT);
15032cd80dbdSZack Rusin 	return status;
15042cd80dbdSZack Rusin }
15052cd80dbdSZack Rusin 
vmw_irq_status_write(struct vmw_private * vmw,uint32 status)15062cd80dbdSZack Rusin static inline void vmw_irq_status_write(struct vmw_private *vmw,
15072cd80dbdSZack Rusin 					uint32 status)
15082cd80dbdSZack Rusin {
15092cd80dbdSZack Rusin 	if (vmw_is_svga_v3(vmw))
15102cd80dbdSZack Rusin 		vmw_write(vmw, SVGA_REG_IRQ_STATUS, status);
15112cd80dbdSZack Rusin 	else
15122cd80dbdSZack Rusin 		outl(status, vmw->io_start + SVGA_IRQSTATUS_PORT);
15132cd80dbdSZack Rusin }
15142cd80dbdSZack Rusin 
vmw_has_fences(struct vmw_private * vmw)1515c593197bSZack Rusin static inline bool vmw_has_fences(struct vmw_private *vmw)
1516c593197bSZack Rusin {
1517c593197bSZack Rusin 	if ((vmw->capabilities & (SVGA_CAP_COMMAND_BUFFERS |
1518c593197bSZack Rusin 				  SVGA_CAP_CMD_BUFFERS_2)) != 0)
1519c593197bSZack Rusin 		return true;
1520c593197bSZack Rusin 	return (vmw_fifo_caps(vmw) & SVGA_FIFO_CAP_FENCE) != 0;
1521c593197bSZack Rusin }
1522c593197bSZack Rusin 
vmw_shadertype_is_valid(enum vmw_sm_type shader_model,u32 shader_type)152314abdfaeSZack Rusin static inline bool vmw_shadertype_is_valid(enum vmw_sm_type shader_model,
152414abdfaeSZack Rusin 					   u32 shader_type)
152514abdfaeSZack Rusin {
152614abdfaeSZack Rusin 	SVGA3dShaderType max_allowed = SVGA3D_SHADERTYPE_PREDX_MAX;
152714abdfaeSZack Rusin 
152814abdfaeSZack Rusin 	if (shader_model >= VMW_SM_5)
152914abdfaeSZack Rusin 		max_allowed = SVGA3D_SHADERTYPE_MAX;
153014abdfaeSZack Rusin 	else if (shader_model >= VMW_SM_4)
153114abdfaeSZack Rusin 		max_allowed = SVGA3D_SHADERTYPE_DX10_MAX;
153214abdfaeSZack Rusin 	return shader_type >= SVGA3D_SHADERTYPE_MIN && shader_type < max_allowed;
153314abdfaeSZack Rusin }
153414abdfaeSZack Rusin 
1535fb1d9738SJakob Bornecrantz #endif
1536