Dirk Hohndel (VMware) | dff9688 | 2018-05-07 01:16:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 OR MIT */ |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 2 | /************************************************************************** |
| 3 | * |
Martin Krastev | 7a7a933 | 2021-06-09 13:23:00 -0400 | [diff] [blame] | 4 | * Copyright 2009-2021 VMware, Inc., Palo Alto, CA., USA |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 5 | * |
| 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 Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 31 | #include <linux/suspend.h> |
Sam Ravnborg | d5c1f01 | 2019-06-23 12:23:33 +0200 | [diff] [blame] | 32 | #include <linux/sync_file.h> |
| 33 | |
| 34 | #include <drm/drm_auth.h> |
| 35 | #include <drm/drm_device.h> |
| 36 | #include <drm/drm_file.h> |
Sam Ravnborg | d5c1f01 | 2019-06-23 12:23:33 +0200 | [diff] [blame] | 37 | #include <drm/drm_rect.h> |
| 38 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 39 | #include <drm/ttm/ttm_bo_driver.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 40 | #include <drm/ttm/ttm_execbuf_util.h> |
Sam Ravnborg | d5c1f01 | 2019-06-23 12:23:33 +0200 | [diff] [blame] | 41 | |
Sam Ravnborg | d5c1f01 | 2019-06-23 12:23:33 +0200 | [diff] [blame] | 42 | #include "ttm_object.h" |
| 43 | |
| 44 | #include "vmwgfx_fence.h" |
Thomas Zimmermann | 2985c96 | 2021-11-29 10:48:40 +0100 | [diff] [blame] | 45 | #include "vmwgfx_hashtab.h" |
Sam Ravnborg | d5c1f01 | 2019-06-23 12:23:33 +0200 | [diff] [blame] | 46 | #include "vmwgfx_reg.h" |
| 47 | #include "vmwgfx_validation.h" |
| 48 | |
| 49 | /* |
| 50 | * FIXME: vmwgfx_drm.h needs to be last due to dependencies. |
| 51 | * uapi headers should not depend on header files outside uapi/. |
| 52 | */ |
| 53 | #include <drm/vmwgfx_drm.h> |
| 54 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 55 | |
Thomas Hellstrom | e300173 | 2017-08-24 08:06:27 +0200 | [diff] [blame] | 56 | #define VMWGFX_DRIVER_NAME "vmwgfx" |
Zack Rusin | 94eb7de | 2021-12-08 21:49:24 -0500 | [diff] [blame] | 57 | #define VMWGFX_DRIVER_DATE "20211206" |
Thomas Hellstrom | 2ae7b03 | 2011-09-01 20:18:45 +0000 | [diff] [blame] | 58 | #define VMWGFX_DRIVER_MAJOR 2 |
Zack Rusin | 94eb7de | 2021-12-08 21:49:24 -0500 | [diff] [blame] | 59 | #define VMWGFX_DRIVER_MINOR 20 |
Zack Rusin | c29758c | 2021-07-23 12:51:53 -0400 | [diff] [blame] | 60 | #define VMWGFX_DRIVER_PATCHLEVEL 0 |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 61 | #define VMWGFX_FIFO_STATIC_SIZE (1024*1024) |
Thomas Hellstrom | 7c4f778 | 2010-06-01 11:38:17 +0200 | [diff] [blame] | 62 | #define VMWGFX_MAX_DISPLAYS 16 |
Thomas Hellstrom | be38ab6 | 2011-08-31 07:42:54 +0000 | [diff] [blame] | 63 | #define VMWGFX_CMD_BOUNCE_INIT_SIZE 32768 |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 64 | |
Zack Rusin | 8772c0b | 2020-11-04 15:29:24 -0500 | [diff] [blame] | 65 | #define VMWGFX_PCI_ID_SVGA2 0x0405 |
Zack Rusin | 2cd80db | 2021-05-05 15:10:07 -0400 | [diff] [blame] | 66 | #define VMWGFX_PCI_ID_SVGA3 0x0406 |
Zack Rusin | 8772c0b | 2020-11-04 15:29:24 -0500 | [diff] [blame] | 67 | |
Thomas Hellstrom | 3530bdc | 2012-11-21 10:49:52 +0100 | [diff] [blame] | 68 | /* |
| 69 | * Perhaps we should have sysfs entries for these. |
| 70 | */ |
| 71 | #define VMWGFX_NUM_GB_CONTEXT 256 |
| 72 | #define VMWGFX_NUM_GB_SHADER 20000 |
| 73 | #define VMWGFX_NUM_GB_SURFACE 32768 |
Thomas Hellstrom | 7cba906 | 2014-01-09 11:03:18 +0100 | [diff] [blame] | 74 | #define VMWGFX_NUM_GB_SCREEN_TARGET VMWGFX_MAX_DISPLAYS |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 75 | #define VMWGFX_NUM_DXCONTEXT 256 |
| 76 | #define VMWGFX_NUM_DXQUERY 512 |
Thomas Hellstrom | 3530bdc | 2012-11-21 10:49:52 +0100 | [diff] [blame] | 77 | #define VMWGFX_NUM_MOB (VMWGFX_NUM_GB_CONTEXT +\ |
| 78 | VMWGFX_NUM_GB_SHADER +\ |
Thomas Hellstrom | 7cba906 | 2014-01-09 11:03:18 +0100 | [diff] [blame] | 79 | VMWGFX_NUM_GB_SURFACE +\ |
| 80 | VMWGFX_NUM_GB_SCREEN_TARGET) |
Thomas Hellstrom | 3530bdc | 2012-11-21 10:49:52 +0100 | [diff] [blame] | 81 | |
Zack Rusin | f6be232 | 2021-11-05 15:38:45 -0400 | [diff] [blame] | 82 | #define VMW_PL_GMR (TTM_PL_PRIV + 0) |
| 83 | #define VMW_PL_MOB (TTM_PL_PRIV + 1) |
| 84 | #define VMW_PL_SYSTEM (TTM_PL_PRIV + 2) |
Thomas Hellstrom | 135cba0 | 2010-10-26 21:21:47 +0200 | [diff] [blame] | 85 | |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 86 | #define VMW_RES_CONTEXT ttm_driver_type0 |
| 87 | #define VMW_RES_SURFACE ttm_driver_type1 |
| 88 | #define VMW_RES_STREAM ttm_driver_type2 |
| 89 | #define VMW_RES_FENCE ttm_driver_type3 |
Thomas Hellstrom | c74c162 | 2012-11-21 12:10:26 +0100 | [diff] [blame] | 90 | #define VMW_RES_SHADER ttm_driver_type4 |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 91 | |
Martin Krastev | 7a7a933 | 2021-06-09 13:23:00 -0400 | [diff] [blame] | 92 | #define MKSSTAT_CAPACITY_LOG2 5U |
| 93 | #define MKSSTAT_CAPACITY (1U << MKSSTAT_CAPACITY_LOG2) |
| 94 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 95 | struct vmw_fpriv { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 96 | struct ttm_object_file *tfile; |
Deepak Rawat | f9261b3 | 2018-06-20 15:24:05 -0700 | [diff] [blame] | 97 | bool gb_aware; /* user-space is guest-backed aware */ |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
Thomas Hellstrom | a0a6394 | 2019-03-04 19:37:40 +0100 | [diff] [blame] | 100 | /** |
| 101 | * struct vmw_buffer_object - TTM buffer object with vmwgfx additions |
| 102 | * @base: The TTM buffer object |
Thomas Hellstrom | 61335d7 | 2019-03-05 08:24:35 +0100 | [diff] [blame] | 103 | * @res_tree: RB tree of resources using this buffer object as a backing MOB |
Christian König | 7fb03cc | 2019-10-01 10:02:58 +0200 | [diff] [blame] | 104 | * @cpu_writers: Number of synccpu write grabs. Protected by reservation when |
| 105 | * increased. May be decreased without reservation. |
Thomas Hellstrom | a0a6394 | 2019-03-04 19:37:40 +0100 | [diff] [blame] | 106 | * @dx_query_ctx: DX context if this buffer object is used as a DX query MOB |
| 107 | * @map: Kmap object for semi-persistent mappings |
| 108 | * @res_prios: Eviction priority counts for attached resources |
Thomas Hellstrom | b7468b1 | 2019-03-27 10:56:08 +0100 | [diff] [blame] | 109 | * @dirty: structure for user-space dirty-tracking |
Thomas Hellstrom | a0a6394 | 2019-03-04 19:37:40 +0100 | [diff] [blame] | 110 | */ |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 111 | struct vmw_buffer_object { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 112 | struct ttm_buffer_object base; |
Thomas Hellstrom | 61335d7 | 2019-03-05 08:24:35 +0100 | [diff] [blame] | 113 | struct rb_root res_tree; |
Christian König | 7fb03cc | 2019-10-01 10:02:58 +0200 | [diff] [blame] | 114 | atomic_t cpu_writers; |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 115 | /* Not ref-counted. Protected by binding_mutex */ |
| 116 | struct vmw_resource *dx_query_ctx; |
Thomas Hellstrom | bf833fd | 2018-03-22 10:19:01 +0100 | [diff] [blame] | 117 | /* Protected by reservation */ |
| 118 | struct ttm_bo_kmap_obj map; |
Thomas Hellstrom | a0a6394 | 2019-03-04 19:37:40 +0100 | [diff] [blame] | 119 | u32 res_prios[TTM_MAX_BO_PRIORITY]; |
Thomas Hellstrom | b7468b1 | 2019-03-27 10:56:08 +0100 | [diff] [blame] | 120 | struct vmw_bo_dirty *dirty; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 123 | /** |
| 124 | * struct vmw_validate_buffer - Carries validation info about buffers. |
| 125 | * |
| 126 | * @base: Validation info for TTM. |
| 127 | * @hash: Hash entry for quick lookup of the TTM buffer object. |
| 128 | * |
| 129 | * This structure contains also driver private validation info |
| 130 | * on top of the info needed by TTM. |
| 131 | */ |
| 132 | struct vmw_validate_buffer { |
| 133 | struct ttm_validate_buffer base; |
Thomas Zimmermann | 2985c96 | 2021-11-29 10:48:40 +0100 | [diff] [blame] | 134 | struct vmwgfx_hash_item hash; |
Thomas Hellstrom | 96c5f0d | 2012-11-21 11:19:53 +0100 | [diff] [blame] | 135 | bool validate_as_mob; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | struct vmw_res_func; |
Thomas Hellstrom | 1328924 | 2018-09-26 15:41:52 +0200 | [diff] [blame] | 139 | |
| 140 | |
| 141 | /** |
| 142 | * struct vmw-resource - base class for hardware resources |
| 143 | * |
| 144 | * @kref: For refcounting. |
| 145 | * @dev_priv: Pointer to the device private for this resource. Immutable. |
| 146 | * @id: Device id. Protected by @dev_priv::resource_lock. |
| 147 | * @backup_size: Backup buffer size. Immutable. |
| 148 | * @res_dirty: Resource contains data not yet in the backup buffer. Protected |
| 149 | * by resource reserved. |
| 150 | * @backup_dirty: Backup buffer contains data not yet in the HW resource. |
Thomas Hellstrom | b7468b1 | 2019-03-27 10:56:08 +0100 | [diff] [blame] | 151 | * Protected by resource reserved. |
| 152 | * @coherent: Emulate coherency by tracking vm accesses. |
Thomas Hellstrom | 1328924 | 2018-09-26 15:41:52 +0200 | [diff] [blame] | 153 | * @backup: The backup buffer if any. Protected by resource reserved. |
| 154 | * @backup_offset: Offset into the backup buffer if any. Protected by resource |
| 155 | * reserved. Note that only a few resource types can have a @backup_offset |
| 156 | * different from zero. |
| 157 | * @pin_count: The pin count for this resource. A pinned resource has a |
| 158 | * pin-count greater than zero. It is not on the resource LRU lists and its |
| 159 | * backup buffer is pinned. Hence it can't be evicted. |
| 160 | * @func: Method vtable for this resource. Immutable. |
Thomas Hellstrom | 61335d7 | 2019-03-05 08:24:35 +0100 | [diff] [blame] | 161 | * @mob_node; Node for the MOB backup rbtree. Protected by @backup reserved. |
Thomas Hellstrom | 1328924 | 2018-09-26 15:41:52 +0200 | [diff] [blame] | 162 | * @lru_head: List head for the LRU list. Protected by @dev_priv::resource_lock. |
Thomas Hellstrom | 1328924 | 2018-09-26 15:41:52 +0200 | [diff] [blame] | 163 | * @binding_head: List head for the context binding list. Protected by |
| 164 | * the @dev_priv::binding_mutex |
| 165 | * @res_free: The resource destructor. |
| 166 | * @hw_destroy: Callback to destroy the resource on the device, as part of |
| 167 | * resource destruction. |
| 168 | */ |
Thomas Hellstrom | b7468b1 | 2019-03-27 10:56:08 +0100 | [diff] [blame] | 169 | struct vmw_resource_dirty; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 170 | struct vmw_resource { |
| 171 | struct kref kref; |
| 172 | struct vmw_private *dev_priv; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 173 | int id; |
Thomas Hellstrom | a0a6394 | 2019-03-04 19:37:40 +0100 | [diff] [blame] | 174 | u32 used_prio; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 175 | unsigned long backup_size; |
Thomas Hellstrom | b7468b1 | 2019-03-27 10:56:08 +0100 | [diff] [blame] | 176 | u32 res_dirty : 1; |
| 177 | u32 backup_dirty : 1; |
| 178 | u32 coherent : 1; |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 179 | struct vmw_buffer_object *backup; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 180 | unsigned long backup_offset; |
Thomas Hellstrom | 1328924 | 2018-09-26 15:41:52 +0200 | [diff] [blame] | 181 | unsigned long pin_count; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 182 | const struct vmw_res_func *func; |
Thomas Hellstrom | 61335d7 | 2019-03-05 08:24:35 +0100 | [diff] [blame] | 183 | struct rb_node mob_node; |
Thomas Hellstrom | 1328924 | 2018-09-26 15:41:52 +0200 | [diff] [blame] | 184 | struct list_head lru_head; |
Thomas Hellstrom | 1328924 | 2018-09-26 15:41:52 +0200 | [diff] [blame] | 185 | struct list_head binding_head; |
Thomas Hellstrom | b7468b1 | 2019-03-27 10:56:08 +0100 | [diff] [blame] | 186 | struct vmw_resource_dirty *dirty; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 187 | void (*res_free) (struct vmw_resource *res); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 188 | void (*hw_destroy) (struct vmw_resource *res); |
| 189 | }; |
| 190 | |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 191 | |
| 192 | /* |
| 193 | * Resources that are managed using ioctls. |
| 194 | */ |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 195 | enum vmw_res_type { |
| 196 | vmw_res_context, |
| 197 | vmw_res_surface, |
| 198 | vmw_res_stream, |
Thomas Hellstrom | c74c162 | 2012-11-21 12:10:26 +0100 | [diff] [blame] | 199 | vmw_res_shader, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 200 | vmw_res_dx_context, |
| 201 | vmw_res_cotable, |
| 202 | vmw_res_view, |
Deepak Rawat | e8bead9 | 2018-12-13 14:04:31 -0800 | [diff] [blame] | 203 | vmw_res_streamoutput, |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 204 | vmw_res_max |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 205 | }; |
| 206 | |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 207 | /* |
| 208 | * Resources that are managed using command streams. |
| 209 | */ |
| 210 | enum vmw_cmdbuf_res_type { |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 211 | vmw_cmdbuf_res_shader, |
Deepak Rawat | e8bead9 | 2018-12-13 14:04:31 -0800 | [diff] [blame] | 212 | vmw_cmdbuf_res_view, |
| 213 | vmw_cmdbuf_res_streamoutput |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 214 | }; |
| 215 | |
| 216 | struct vmw_cmdbuf_res_manager; |
| 217 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 218 | struct vmw_cursor_snooper { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 219 | size_t age; |
| 220 | uint32_t *image; |
| 221 | }; |
| 222 | |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 223 | struct vmw_framebuffer; |
Thomas Hellstrom | 5bb39e8 | 2011-10-04 20:13:33 +0200 | [diff] [blame] | 224 | struct vmw_surface_offset; |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 225 | |
Deepak Rawat | 26b8287 | 2019-04-29 11:42:45 -0700 | [diff] [blame] | 226 | /** |
| 227 | * struct vmw_surface_metadata - Metadata describing a surface. |
| 228 | * |
| 229 | * @flags: Device flags. |
| 230 | * @format: Surface SVGA3D_x format. |
| 231 | * @mip_levels: Mip level for each face. For GB first index is used only. |
| 232 | * @multisample_count: Sample count. |
| 233 | * @multisample_pattern: Sample patterns. |
| 234 | * @quality_level: Quality level. |
| 235 | * @autogen_filter: Filter for automatically generated mipmaps. |
| 236 | * @array_size: Number of array elements for a 1D/2D texture. For cubemap |
| 237 | texture number of faces * array_size. This should be 0 for pre |
| 238 | SM4 device. |
Deepak Rawat | 2a50f06 | 2019-04-30 13:04:55 -0700 | [diff] [blame] | 239 | * @buffer_byte_stride: Buffer byte stride. |
Deepak Rawat | 26b8287 | 2019-04-29 11:42:45 -0700 | [diff] [blame] | 240 | * @num_sizes: Size of @sizes. For GB surface this should always be 1. |
| 241 | * @base_size: Surface dimension. |
| 242 | * @sizes: Array representing mip sizes. Legacy only. |
| 243 | * @scanout: Whether this surface will be used for scanout. |
| 244 | * |
| 245 | * This tracks metadata for both legacy and guest backed surface. |
| 246 | */ |
| 247 | struct vmw_surface_metadata { |
| 248 | u64 flags; |
| 249 | u32 format; |
| 250 | u32 mip_levels[DRM_VMW_MAX_SURFACE_FACES]; |
| 251 | u32 multisample_count; |
| 252 | u32 multisample_pattern; |
| 253 | u32 quality_level; |
| 254 | u32 autogen_filter; |
| 255 | u32 array_size; |
| 256 | u32 num_sizes; |
Deepak Rawat | 2a50f06 | 2019-04-30 13:04:55 -0700 | [diff] [blame] | 257 | u32 buffer_byte_stride; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 258 | struct drm_vmw_size base_size; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 259 | struct drm_vmw_size *sizes; |
Jakob Bornecrantz | 5ffdb65 | 2010-01-30 03:38:08 +0000 | [diff] [blame] | 260 | bool scanout; |
Deepak Rawat | 26b8287 | 2019-04-29 11:42:45 -0700 | [diff] [blame] | 261 | }; |
| 262 | |
| 263 | /** |
| 264 | * struct vmw_surface: Resource structure for a surface. |
| 265 | * |
| 266 | * @res: The base resource for this surface. |
| 267 | * @metadata: Metadata for this surface resource. |
| 268 | * @snooper: Cursor data. Legacy surface only. |
| 269 | * @offsets: Legacy surface only. |
| 270 | * @view_list: List of views bound to this surface. |
| 271 | */ |
| 272 | struct vmw_surface { |
| 273 | struct vmw_resource res; |
| 274 | struct vmw_surface_metadata metadata; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 275 | struct vmw_cursor_snooper snooper; |
Thomas Hellstrom | 5bb39e8 | 2011-10-04 20:13:33 +0200 | [diff] [blame] | 276 | struct vmw_surface_offset *offsets; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 277 | struct list_head view_list; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 278 | }; |
| 279 | |
| 280 | struct vmw_fifo_state { |
| 281 | unsigned long reserved_size; |
Thomas Hellstrom | b9eb1a6 | 2015-04-02 02:39:45 -0700 | [diff] [blame] | 282 | u32 *dynamic_buffer; |
| 283 | u32 *static_buffer; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 284 | unsigned long static_buffer_size; |
| 285 | bool using_bounce_buffer; |
| 286 | uint32_t capabilities; |
Thomas Hellstrom | 85b9e48 | 2010-02-08 09:57:25 +0000 | [diff] [blame] | 287 | struct mutex fifo_mutex; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 288 | struct rw_semaphore rwsem; |
| 289 | }; |
| 290 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 291 | /** |
| 292 | * struct vmw_res_cache_entry - resource information cache entry |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 293 | * @handle: User-space handle of a resource. |
| 294 | * @res: Non-ref-counted pointer to the resource. |
| 295 | * @valid_handle: Whether the @handle member is valid. |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 296 | * @valid: Whether the entry is valid, which also implies that the execbuf |
| 297 | * code holds a reference to the resource, and it's placed on the |
| 298 | * validation list. |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 299 | * |
| 300 | * Used to avoid frequent repeated user-space handle lookups of the |
| 301 | * same resource. |
| 302 | */ |
| 303 | struct vmw_res_cache_entry { |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 304 | uint32_t handle; |
| 305 | struct vmw_resource *res; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 306 | void *private; |
| 307 | unsigned short valid_handle; |
| 308 | unsigned short valid; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 309 | }; |
| 310 | |
Thomas Hellstrom | d92d985 | 2013-10-24 01:49:26 -0700 | [diff] [blame] | 311 | /** |
| 312 | * enum vmw_dma_map_mode - indicate how to perform TTM page dma mappings. |
| 313 | */ |
| 314 | enum vmw_dma_map_mode { |
Thomas Hellstrom | d92d985 | 2013-10-24 01:49:26 -0700 | [diff] [blame] | 315 | vmw_dma_alloc_coherent, /* Use TTM coherent pages */ |
| 316 | vmw_dma_map_populate, /* Unmap from DMA just after unpopulate */ |
| 317 | vmw_dma_map_bind, /* Unmap from DMA just before unbind */ |
| 318 | vmw_dma_map_max |
| 319 | }; |
| 320 | |
| 321 | /** |
| 322 | * struct vmw_sg_table - Scatter/gather table for binding, with additional |
| 323 | * device-specific information. |
| 324 | * |
| 325 | * @sgt: Pointer to a struct sg_table with binding information |
Masahiro Yamada | e1c0506 | 2015-07-07 10:14:59 +0900 | [diff] [blame] | 326 | * @num_regions: Number of regions with device-address contiguous pages |
Thomas Hellstrom | d92d985 | 2013-10-24 01:49:26 -0700 | [diff] [blame] | 327 | */ |
| 328 | struct vmw_sg_table { |
| 329 | enum vmw_dma_map_mode mode; |
| 330 | struct page **pages; |
| 331 | const dma_addr_t *addrs; |
| 332 | struct sg_table *sgt; |
Thomas Hellstrom | d92d985 | 2013-10-24 01:49:26 -0700 | [diff] [blame] | 333 | unsigned long num_pages; |
| 334 | }; |
| 335 | |
| 336 | /** |
| 337 | * struct vmw_piter - Page iterator that iterates over a list of pages |
| 338 | * and DMA addresses that could be either a scatter-gather list or |
| 339 | * arrays |
| 340 | * |
| 341 | * @pages: Array of page pointers to the pages. |
| 342 | * @addrs: DMA addresses to the pages if coherent pages are used. |
| 343 | * @iter: Scatter-gather page iterator. Current position in SG list. |
| 344 | * @i: Current position in arrays. |
| 345 | * @num_pages: Number of pages total. |
| 346 | * @next: Function to advance the iterator. Returns false if past the list |
| 347 | * of pages, true otherwise. |
| 348 | * @dma_address: Function to return the DMA address of the current page. |
| 349 | */ |
| 350 | struct vmw_piter { |
| 351 | struct page **pages; |
| 352 | const dma_addr_t *addrs; |
Thomas Hellstrom | 8dc39cf | 2019-05-15 17:45:23 +0200 | [diff] [blame] | 353 | struct sg_dma_page_iter iter; |
Thomas Hellstrom | d92d985 | 2013-10-24 01:49:26 -0700 | [diff] [blame] | 354 | unsigned long i; |
| 355 | unsigned long num_pages; |
| 356 | bool (*next)(struct vmw_piter *); |
| 357 | dma_addr_t (*dma_address)(struct vmw_piter *); |
Thomas Hellstrom | d92d985 | 2013-10-24 01:49:26 -0700 | [diff] [blame] | 358 | }; |
| 359 | |
Zack Rusin | 8afa13a | 2021-12-06 12:26:12 -0500 | [diff] [blame] | 360 | |
| 361 | struct vmw_ttm_tt { |
| 362 | struct ttm_tt dma_ttm; |
| 363 | struct vmw_private *dev_priv; |
| 364 | int gmr_id; |
| 365 | struct vmw_mob *mob; |
| 366 | int mem_type; |
| 367 | struct sg_table sgt; |
| 368 | struct vmw_sg_table vsgt; |
| 369 | bool mapped; |
| 370 | bool bound; |
| 371 | }; |
| 372 | |
Thomas Hellstrom | b5c3b1a6 | 2013-10-08 02:27:17 -0700 | [diff] [blame] | 373 | /* |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 374 | * enum vmw_display_unit_type - Describes the display unit |
Thomas Hellstrom | b5c3b1a6 | 2013-10-08 02:27:17 -0700 | [diff] [blame] | 375 | */ |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 376 | enum vmw_display_unit_type { |
| 377 | vmw_du_invalid = 0, |
| 378 | vmw_du_legacy, |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 379 | vmw_du_screen_object, |
Zack Rusin | 2b27354 | 2021-07-23 12:51:51 -0400 | [diff] [blame] | 380 | vmw_du_screen_target, |
| 381 | vmw_du_max |
Thomas Hellstrom | b5c3b1a6 | 2013-10-08 02:27:17 -0700 | [diff] [blame] | 382 | }; |
| 383 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 384 | struct vmw_validation_context; |
| 385 | struct vmw_ctx_validation_info; |
Thomas Hellstrom | b5c3b1a6 | 2013-10-08 02:27:17 -0700 | [diff] [blame] | 386 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 387 | /** |
| 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 Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 394 | * @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 Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 398 | * @bo_relocations: List of buffer object relocations |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 399 | * @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 Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 406 | * @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 Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 418 | struct vmw_sw_context{ |
Thomas Zimmermann | 2985c96 | 2021-11-29 10:48:40 +0100 | [diff] [blame] | 419 | struct vmwgfx_open_hash res_ht; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 420 | bool res_ht_initialized; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 421 | bool kernel; |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 422 | struct vmw_fpriv *fp; |
Zack Rusin | 8afa13a | 2021-12-06 12:26:12 -0500 | [diff] [blame] | 423 | struct drm_file *filp; |
Thomas Hellstrom | be38ab6 | 2011-08-31 07:42:54 +0000 | [diff] [blame] | 424 | uint32_t *cmd_bounce; |
| 425 | uint32_t cmd_bounce_size; |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 426 | struct vmw_buffer_object *cur_query_bo; |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 427 | struct list_head bo_relocations; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 428 | struct list_head res_relocations; |
| 429 | uint32_t *buf_start; |
| 430 | struct vmw_res_cache_entry res_cache[vmw_res_max]; |
| 431 | struct vmw_resource *last_query_ctx; |
| 432 | bool needs_post_query_barrier; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 433 | struct vmw_ctx_binding_state *staged_bindings; |
| 434 | bool staged_bindings_inuse; |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 435 | struct list_head staged_cmd_res; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 436 | struct list_head ctx_list; |
| 437 | struct vmw_ctx_validation_info *dx_ctx_node; |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 438 | struct vmw_buffer_object *dx_query_mob; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 439 | struct vmw_resource *dx_query_ctx; |
| 440 | struct vmw_cmdbuf_res_manager *man; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 441 | struct vmw_validation_context *ctx; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 442 | }; |
| 443 | |
| 444 | struct vmw_legacy_display; |
| 445 | struct vmw_overlay; |
| 446 | |
Thomas Hellstrom | 7c4f778 | 2010-06-01 11:38:17 +0200 | [diff] [blame] | 447 | struct vmw_vga_topology_state { |
| 448 | uint32_t width; |
| 449 | uint32_t height; |
| 450 | uint32_t primary; |
| 451 | uint32_t pos_x; |
| 452 | uint32_t pos_y; |
| 453 | }; |
| 454 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 455 | |
| 456 | /* |
| 457 | * struct vmw_otable - Guest Memory OBject table metadata |
| 458 | * |
| 459 | * @size: Size of the table (page-aligned). |
| 460 | * @page_table: Pointer to a struct vmw_mob holding the page table. |
| 461 | */ |
| 462 | struct vmw_otable { |
| 463 | unsigned long size; |
| 464 | struct vmw_mob *page_table; |
| 465 | bool enabled; |
| 466 | }; |
| 467 | |
| 468 | struct vmw_otable_batch { |
| 469 | unsigned num_otables; |
| 470 | struct vmw_otable *otables; |
| 471 | struct vmw_resource *context; |
| 472 | struct ttm_buffer_object *otable_bo; |
| 473 | }; |
| 474 | |
Thomas Hellstrom | ef36990 | 2017-08-24 08:06:28 +0200 | [diff] [blame] | 475 | enum { |
| 476 | VMW_IRQTHREAD_FENCE, |
| 477 | VMW_IRQTHREAD_CMDBUF, |
| 478 | VMW_IRQTHREAD_MAX |
| 479 | }; |
| 480 | |
Deepak Rawat | 878c6ec | 2018-12-13 11:44:42 -0800 | [diff] [blame] | 481 | /** |
| 482 | * enum vmw_sm_type - Graphics context capability supported by device. |
| 483 | * @VMW_SM_LEGACY: Pre DX context. |
| 484 | * @VMW_SM_4: Context support upto SM4. |
| 485 | * @VMW_SM_4_1: Context support upto SM4_1. |
Deepak Rawat | 4dec280 | 2018-12-13 11:48:09 -0800 | [diff] [blame] | 486 | * @VMW_SM_5: Context support up to SM5. |
Zack Rusin | 4fb9326 | 2021-12-06 12:26:16 -0500 | [diff] [blame] | 487 | * @VMW_SM_5_1X: Adds support for sm5_1 and gl43 extensions. |
Deepak Rawat | 878c6ec | 2018-12-13 11:44:42 -0800 | [diff] [blame] | 488 | * @VMW_SM_MAX: Should be the last. |
| 489 | */ |
| 490 | enum vmw_sm_type { |
| 491 | VMW_SM_LEGACY = 0, |
| 492 | VMW_SM_4, |
| 493 | VMW_SM_4_1, |
Deepak Rawat | 4dec280 | 2018-12-13 11:48:09 -0800 | [diff] [blame] | 494 | VMW_SM_5, |
Zack Rusin | 4fb9326 | 2021-12-06 12:26:16 -0500 | [diff] [blame] | 495 | VMW_SM_5_1X, |
Deepak Rawat | 878c6ec | 2018-12-13 11:44:42 -0800 | [diff] [blame] | 496 | VMW_SM_MAX |
| 497 | }; |
| 498 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 499 | struct vmw_private { |
Zack Rusin | 9703bb3 | 2020-11-03 22:21:34 -0500 | [diff] [blame] | 500 | struct drm_device drm; |
Christian König | 8af8a10 | 2020-10-01 14:51:40 +0200 | [diff] [blame] | 501 | struct ttm_device bdev; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 502 | |
Gerd Hoffmann | 293f86b | 2019-09-05 09:05:08 +0200 | [diff] [blame] | 503 | struct drm_vma_offset_manager vma_manager; |
Zack Rusin | baee602 | 2021-06-09 13:23:06 -0400 | [diff] [blame] | 504 | u32 pci_id; |
Zack Rusin | be4f77a | 2020-11-04 13:46:09 -0500 | [diff] [blame] | 505 | resource_size_t io_start; |
| 506 | resource_size_t vram_start; |
| 507 | resource_size_t vram_size; |
Zack Rusin | ebc9ac7 | 2021-06-15 14:23:33 -0400 | [diff] [blame] | 508 | resource_size_t max_primary_mem; |
Zack Rusin | c2aaa37 | 2021-06-15 14:23:34 -0400 | [diff] [blame] | 509 | u32 __iomem *rmmio; |
Zack Rusin | be4f77a | 2020-11-04 13:46:09 -0500 | [diff] [blame] | 510 | u32 *fifo_mem; |
Zack Rusin | be4f77a | 2020-11-04 13:46:09 -0500 | [diff] [blame] | 511 | resource_size_t fifo_mem_size; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 512 | uint32_t fb_max_width; |
| 513 | uint32_t fb_max_height; |
Sinclair Yeh | 35c0512 | 2015-06-26 01:42:06 -0700 | [diff] [blame] | 514 | uint32_t texture_max_width; |
| 515 | uint32_t texture_max_height; |
| 516 | uint32_t stdu_max_width; |
| 517 | uint32_t stdu_max_height; |
Jakob Bornecrantz | eb4f923 | 2012-02-09 16:56:46 +0100 | [diff] [blame] | 518 | uint32_t initial_width; |
| 519 | uint32_t initial_height; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 520 | uint32_t capabilities; |
Neha Bhende | 3b4c251 | 2018-06-18 16:44:48 -0700 | [diff] [blame] | 521 | uint32_t capabilities2; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 522 | uint32_t max_gmr_ids; |
Thomas Hellstrom | fb17f18 | 2011-08-31 07:42:53 +0000 | [diff] [blame] | 523 | uint32_t max_gmr_pages; |
Thomas Hellstrom | 6da768a | 2012-11-21 11:06:22 +0100 | [diff] [blame] | 524 | uint32_t max_mob_pages; |
Charmaine Lee | 857aea1 | 2014-02-12 12:07:38 +0100 | [diff] [blame] | 525 | uint32_t max_mob_size; |
Thomas Hellstrom | fb17f18 | 2011-08-31 07:42:53 +0000 | [diff] [blame] | 526 | uint32_t memory_size; |
Thomas Hellstrom | 135cba0 | 2010-10-26 21:21:47 +0200 | [diff] [blame] | 527 | bool has_gmr; |
Thomas Hellstrom | 3530bdc | 2012-11-21 10:49:52 +0100 | [diff] [blame] | 528 | bool has_mob; |
Thomas Hellstrom | 496eb6f | 2015-01-14 02:33:39 -0800 | [diff] [blame] | 529 | spinlock_t hw_lock; |
Sinclair Yeh | 04319d8 | 2016-06-29 12:15:48 -0700 | [diff] [blame] | 530 | bool assume_16bpp; |
Deepak Rawat | 878c6ec | 2018-12-13 11:44:42 -0800 | [diff] [blame] | 531 | |
| 532 | enum vmw_sm_type sm_type; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 533 | |
| 534 | /* |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 535 | * Framebuffer info. |
| 536 | */ |
| 537 | |
| 538 | void *fb_info; |
Sinclair Yeh | c8261a9 | 2015-06-26 01:23:42 -0700 | [diff] [blame] | 539 | enum vmw_display_unit_type active_display_unit; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 540 | struct vmw_legacy_display *ldu_priv; |
| 541 | struct vmw_overlay *overlay_priv; |
Thomas Hellstrom | 578e609 | 2016-02-12 09:45:42 +0100 | [diff] [blame] | 542 | struct drm_property *hotplug_mode_update_property; |
Thomas Hellstrom | 76404ac | 2016-02-12 09:55:45 +0100 | [diff] [blame] | 543 | struct drm_property *implicit_placement_property; |
Sinclair Yeh | 36cc79b | 2017-03-23 11:28:11 -0700 | [diff] [blame] | 544 | spinlock_t cursor_lock; |
Thomas Hellstrom | c3b9b16 | 2018-03-22 10:26:37 +0100 | [diff] [blame] | 545 | struct drm_atomic_state *suspend_state; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 546 | |
| 547 | /* |
| 548 | * Context and surface management. |
| 549 | */ |
| 550 | |
Thomas Hellstrom | 1328924 | 2018-09-26 15:41:52 +0200 | [diff] [blame] | 551 | spinlock_t resource_lock; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 552 | struct idr res_idr[vmw_res_max]; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 553 | |
| 554 | /* |
| 555 | * A resource manager for kernel-only surfaces and |
| 556 | * contexts. |
| 557 | */ |
| 558 | |
| 559 | struct ttm_object_device *tdev; |
| 560 | |
| 561 | /* |
| 562 | * Fencing and IRQs. |
| 563 | */ |
| 564 | |
Thomas Hellstrom | 6bcd8d3c | 2011-09-01 20:18:42 +0000 | [diff] [blame] | 565 | atomic_t marker_seq; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 566 | wait_queue_head_t fence_queue; |
| 567 | wait_queue_head_t fifo_queue; |
Thomas Hellstrom | 496eb6f | 2015-01-14 02:33:39 -0800 | [diff] [blame] | 568 | spinlock_t waiter_lock; |
| 569 | int fence_queue_waiters; /* Protected by waiter_lock */ |
| 570 | int goal_queue_waiters; /* Protected by waiter_lock */ |
Thomas Hellstrom | d2e8851 | 2015-10-28 19:07:35 +0100 | [diff] [blame] | 571 | int cmdbuf_waiters; /* Protected by waiter_lock */ |
| 572 | int error_waiters; /* Protected by waiter_lock */ |
| 573 | int fifo_queue_waiters; /* Protected by waiter_lock */ |
Thomas Hellstrom | 6bcd8d3c | 2011-09-01 20:18:42 +0000 | [diff] [blame] | 574 | uint32_t last_read_seqno; |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 575 | struct vmw_fence_manager *fman; |
Thomas Hellstrom | d2e8851 | 2015-10-28 19:07:35 +0100 | [diff] [blame] | 576 | uint32_t irq_mask; /* Updates protected by waiter_lock */ |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 577 | |
| 578 | /* |
| 579 | * Device state |
| 580 | */ |
| 581 | |
| 582 | uint32_t traces_state; |
| 583 | uint32_t enable_state; |
| 584 | uint32_t config_done_state; |
| 585 | |
| 586 | /** |
| 587 | * Execbuf |
| 588 | */ |
| 589 | /** |
| 590 | * Protected by the cmdbuf mutex. |
| 591 | */ |
| 592 | |
| 593 | struct vmw_sw_context ctx; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 594 | struct mutex cmdbuf_mutex; |
Thomas Hellstrom | 173fb7d | 2013-10-08 02:32:36 -0700 | [diff] [blame] | 595 | struct mutex binding_mutex; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 596 | |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 597 | bool enable_fb; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 598 | |
| 599 | /** |
Thomas Hellstrom | 9c84aeb | 2019-05-28 08:08:55 +0200 | [diff] [blame] | 600 | * PM management. |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 601 | */ |
Thomas Hellstrom | d9f36a0 | 2010-01-13 22:28:43 +0100 | [diff] [blame] | 602 | struct notifier_block pm_nb; |
Thomas Hellstrom | 153b3d5 | 2015-06-25 10:47:43 -0700 | [diff] [blame] | 603 | bool refuse_hibernation; |
Thomas Hellstrom | c3b9b16 | 2018-03-22 10:26:37 +0100 | [diff] [blame] | 604 | bool suspend_locked; |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 605 | |
Thomas Hellstrom | 153b3d5 | 2015-06-25 10:47:43 -0700 | [diff] [blame] | 606 | atomic_t num_fifo_resources; |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 607 | |
| 608 | /* |
| 609 | * Query processing. These members |
| 610 | * are protected by the cmdbuf mutex. |
| 611 | */ |
| 612 | |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 613 | struct vmw_buffer_object *dummy_query_bo; |
| 614 | struct vmw_buffer_object *pinned_bo; |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 615 | uint32_t query_cid; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 616 | uint32_t query_cid_valid; |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 617 | bool dummy_query_bo_pinned; |
Thomas Hellstrom | 5bb39e8 | 2011-10-04 20:13:33 +0200 | [diff] [blame] | 618 | |
| 619 | /* |
| 620 | * Surface swapping. The "surface_lru" list is protected by the |
| 621 | * resource lock in order to be able to destroy a surface and take |
| 622 | * it off the lru atomically. "used_memory_size" is currently |
| 623 | * protected by the cmdbuf mutex for simplicity. |
| 624 | */ |
| 625 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 626 | struct list_head res_lru[vmw_res_max]; |
Thomas Hellstrom | 5bb39e8 | 2011-10-04 20:13:33 +0200 | [diff] [blame] | 627 | uint32_t used_memory_size; |
Thomas Hellstrom | d92d985 | 2013-10-24 01:49:26 -0700 | [diff] [blame] | 628 | |
| 629 | /* |
| 630 | * DMA mapping stuff. |
| 631 | */ |
| 632 | enum vmw_dma_map_mode map_mode; |
Thomas Hellstrom | 3530bdc | 2012-11-21 10:49:52 +0100 | [diff] [blame] | 633 | |
| 634 | /* |
| 635 | * Guest Backed stuff |
| 636 | */ |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 637 | struct vmw_otable_batch otable_batch; |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 638 | |
Zack Rusin | 2cd80db | 2021-05-05 15:10:07 -0400 | [diff] [blame] | 639 | struct vmw_fifo_state *fifo; |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 640 | struct vmw_cmdbuf_man *cman; |
Thomas Hellstrom | ef36990 | 2017-08-24 08:06:28 +0200 | [diff] [blame] | 641 | DECLARE_BITMAP(irqthread_pending, VMW_IRQTHREAD_MAX); |
Thomas Hellstrom | fd56746 | 2018-12-12 11:52:08 +0100 | [diff] [blame] | 642 | |
Zack Rusin | d92223e | 2021-06-09 13:22:59 -0400 | [diff] [blame] | 643 | uint32 *devcaps; |
Martin Krastev | 7a7a933 | 2021-06-09 13:23:00 -0400 | [diff] [blame] | 644 | |
| 645 | /* |
| 646 | * mksGuestStat instance-descriptor and pid arrays |
| 647 | */ |
| 648 | struct page *mksstat_user_pages[MKSSTAT_CAPACITY]; |
| 649 | atomic_t mksstat_user_pids[MKSSTAT_CAPACITY]; |
| 650 | |
| 651 | #if IS_ENABLED(CONFIG_DRM_VMWGFX_MKSSTATS) |
| 652 | struct page *mksstat_kern_pages[MKSSTAT_CAPACITY]; |
| 653 | u8 mksstat_kern_top_timer[MKSSTAT_CAPACITY]; |
| 654 | atomic_t mksstat_kern_pids[MKSSTAT_CAPACITY]; |
| 655 | #endif |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 656 | }; |
| 657 | |
Zack Rusin | 8afa13a | 2021-12-06 12:26:12 -0500 | [diff] [blame] | 658 | static inline struct vmw_buffer_object *gem_to_vmw_bo(struct drm_gem_object *gobj) |
| 659 | { |
| 660 | return container_of((gobj), struct vmw_buffer_object, base.base); |
| 661 | } |
| 662 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 663 | static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res) |
| 664 | { |
| 665 | return container_of(res, struct vmw_surface, res); |
| 666 | } |
| 667 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 668 | static inline struct vmw_private *vmw_priv(struct drm_device *dev) |
| 669 | { |
| 670 | return (struct vmw_private *)dev->dev_private; |
| 671 | } |
| 672 | |
| 673 | static inline struct vmw_fpriv *vmw_fpriv(struct drm_file *file_priv) |
| 674 | { |
| 675 | return (struct vmw_fpriv *)file_priv->driver_priv; |
| 676 | } |
| 677 | |
Thomas Hellstrom | 496eb6f | 2015-01-14 02:33:39 -0800 | [diff] [blame] | 678 | /* |
Zack Rusin | 2cd80db | 2021-05-05 15:10:07 -0400 | [diff] [blame] | 679 | * SVGA v3 has mmio register access and lacks fifo cmds |
| 680 | */ |
| 681 | static inline bool vmw_is_svga_v3(const struct vmw_private *dev) |
| 682 | { |
| 683 | return dev->pci_id == VMWGFX_PCI_ID_SVGA3; |
| 684 | } |
| 685 | |
| 686 | /* |
Thomas Hellstrom | 496eb6f | 2015-01-14 02:33:39 -0800 | [diff] [blame] | 687 | * The locking here is fine-grained, so that it is performed once |
| 688 | * for every read- and write operation. This is of course costly, but we |
| 689 | * don't perform much register access in the timing critical paths anyway. |
| 690 | * Instead we have the extra benefit of being sure that we don't forget |
| 691 | * the hw lock around register accesses. |
| 692 | */ |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 693 | static inline void vmw_write(struct vmw_private *dev_priv, |
| 694 | unsigned int offset, uint32_t value) |
| 695 | { |
Zack Rusin | 2cd80db | 2021-05-05 15:10:07 -0400 | [diff] [blame] | 696 | if (vmw_is_svga_v3(dev_priv)) { |
| 697 | iowrite32(value, dev_priv->rmmio + offset); |
| 698 | } else { |
| 699 | spin_lock(&dev_priv->hw_lock); |
| 700 | outl(offset, dev_priv->io_start + SVGA_INDEX_PORT); |
| 701 | outl(value, dev_priv->io_start + SVGA_VALUE_PORT); |
| 702 | spin_unlock(&dev_priv->hw_lock); |
| 703 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | static inline uint32_t vmw_read(struct vmw_private *dev_priv, |
| 707 | unsigned int offset) |
| 708 | { |
Thomas Hellstrom | 496eb6f | 2015-01-14 02:33:39 -0800 | [diff] [blame] | 709 | u32 val; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 710 | |
Zack Rusin | 2cd80db | 2021-05-05 15:10:07 -0400 | [diff] [blame] | 711 | if (vmw_is_svga_v3(dev_priv)) { |
| 712 | val = ioread32(dev_priv->rmmio + offset); |
| 713 | } else { |
| 714 | spin_lock(&dev_priv->hw_lock); |
| 715 | outl(offset, dev_priv->io_start + SVGA_INDEX_PORT); |
| 716 | val = inl(dev_priv->io_start + SVGA_VALUE_PORT); |
| 717 | spin_unlock(&dev_priv->hw_lock); |
| 718 | } |
Thomas Hellstrom | 496eb6f | 2015-01-14 02:33:39 -0800 | [diff] [blame] | 719 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 720 | return val; |
| 721 | } |
| 722 | |
Deepak Rawat | 878c6ec | 2018-12-13 11:44:42 -0800 | [diff] [blame] | 723 | /** |
| 724 | * has_sm4_context - Does the device support SM4 context. |
| 725 | * @dev_priv: Device private. |
| 726 | * |
| 727 | * Return: Bool value if device support SM4 context or not. |
| 728 | */ |
| 729 | static inline bool has_sm4_context(const struct vmw_private *dev_priv) |
| 730 | { |
| 731 | return (dev_priv->sm_type >= VMW_SM_4); |
| 732 | } |
| 733 | |
| 734 | /** |
| 735 | * has_sm4_1_context - Does the device support SM4_1 context. |
| 736 | * @dev_priv: Device private. |
| 737 | * |
| 738 | * Return: Bool value if device support SM4_1 context or not. |
| 739 | */ |
| 740 | static inline bool has_sm4_1_context(const struct vmw_private *dev_priv) |
| 741 | { |
| 742 | return (dev_priv->sm_type >= VMW_SM_4_1); |
| 743 | } |
| 744 | |
Deepak Rawat | 4dec280 | 2018-12-13 11:48:09 -0800 | [diff] [blame] | 745 | /** |
| 746 | * has_sm5_context - Does the device support SM5 context. |
| 747 | * @dev_priv: Device private. |
| 748 | * |
| 749 | * Return: Bool value if device support SM5 context or not. |
| 750 | */ |
| 751 | static inline bool has_sm5_context(const struct vmw_private *dev_priv) |
| 752 | { |
| 753 | return (dev_priv->sm_type >= VMW_SM_5); |
| 754 | } |
| 755 | |
Zack Rusin | 4fb9326 | 2021-12-06 12:26:16 -0500 | [diff] [blame] | 756 | /** |
| 757 | * has_gl43_context - Does the device support GL43 context. |
| 758 | * @dev_priv: Device private. |
| 759 | * |
| 760 | * Return: Bool value if device support SM5 context or not. |
| 761 | */ |
| 762 | static inline bool has_gl43_context(const struct vmw_private *dev_priv) |
| 763 | { |
| 764 | return (dev_priv->sm_type >= VMW_SM_5_1X); |
| 765 | } |
| 766 | |
| 767 | |
| 768 | static inline u32 vmw_max_num_uavs(struct vmw_private *dev_priv) |
| 769 | { |
| 770 | return (has_gl43_context(dev_priv) ? |
| 771 | SVGA3D_DX11_1_MAX_UAVIEWS : SVGA3D_MAX_UAVIEWS); |
| 772 | } |
| 773 | |
Thomas Hellstrom | 153b3d5 | 2015-06-25 10:47:43 -0700 | [diff] [blame] | 774 | extern void vmw_svga_enable(struct vmw_private *dev_priv); |
| 775 | extern void vmw_svga_disable(struct vmw_private *dev_priv); |
| 776 | |
Thomas Hellstrom | 30c78bb | 2010-10-01 10:21:48 +0200 | [diff] [blame] | 777 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 778 | /** |
| 779 | * GMR utilities - vmwgfx_gmr.c |
| 780 | */ |
| 781 | |
| 782 | extern int vmw_gmr_bind(struct vmw_private *dev_priv, |
Thomas Hellstrom | d92d985 | 2013-10-24 01:49:26 -0700 | [diff] [blame] | 783 | const struct vmw_sg_table *vsgt, |
Thomas Hellstrom | 135cba0 | 2010-10-26 21:21:47 +0200 | [diff] [blame] | 784 | unsigned long num_pages, |
| 785 | int gmr_id); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 786 | extern void vmw_gmr_unbind(struct vmw_private *dev_priv, int gmr_id); |
| 787 | |
| 788 | /** |
| 789 | * Resource utilities - vmwgfx_resource.c |
| 790 | */ |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 791 | struct vmw_user_resource_conv; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 792 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 793 | extern void vmw_resource_unreference(struct vmw_resource **p_res); |
| 794 | extern struct vmw_resource *vmw_resource_reference(struct vmw_resource *res); |
Thomas Hellstrom | 30f82d81 | 2014-02-05 08:13:56 +0100 | [diff] [blame] | 795 | extern struct vmw_resource * |
| 796 | vmw_resource_reference_unless_doomed(struct vmw_resource *res); |
Thomas Hellstrom | fb80edb | 2019-03-28 11:36:25 +0100 | [diff] [blame] | 797 | extern int vmw_resource_validate(struct vmw_resource *res, bool intr, |
| 798 | bool dirtying); |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 799 | extern int vmw_resource_reserve(struct vmw_resource *res, bool interruptible, |
| 800 | bool no_backup); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 801 | extern bool vmw_resource_needs_backup(const struct vmw_resource *res); |
Jakob Bornecrantz | 551a669 | 2011-11-28 13:19:11 +0100 | [diff] [blame] | 802 | extern int vmw_user_lookup_handle(struct vmw_private *dev_priv, |
Zack Rusin | 8afa13a | 2021-12-06 12:26:12 -0500 | [diff] [blame] | 803 | struct drm_file *filp, |
Jakob Bornecrantz | 551a669 | 2011-11-28 13:19:11 +0100 | [diff] [blame] | 804 | uint32_t handle, |
| 805 | struct vmw_surface **out_surf, |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 806 | struct vmw_buffer_object **out_buf); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 807 | extern int vmw_user_resource_lookup_handle( |
| 808 | struct vmw_private *dev_priv, |
| 809 | struct ttm_object_file *tfile, |
| 810 | uint32_t handle, |
| 811 | const struct vmw_user_resource_conv *converter, |
| 812 | struct vmw_resource **p_res); |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 813 | extern struct vmw_resource * |
| 814 | vmw_user_resource_noref_lookup_handle(struct vmw_private *dev_priv, |
| 815 | struct ttm_object_file *tfile, |
| 816 | uint32_t handle, |
| 817 | const struct vmw_user_resource_conv * |
| 818 | converter); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 819 | extern int vmw_stream_claim_ioctl(struct drm_device *dev, void *data, |
| 820 | struct drm_file *file_priv); |
| 821 | extern int vmw_stream_unref_ioctl(struct drm_device *dev, void *data, |
| 822 | struct drm_file *file_priv); |
| 823 | extern int vmw_user_stream_lookup(struct vmw_private *dev_priv, |
| 824 | struct ttm_object_file *tfile, |
| 825 | uint32_t *inout_id, |
| 826 | struct vmw_resource **out); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 827 | extern void vmw_resource_unreserve(struct vmw_resource *res, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 828 | bool dirty_set, |
| 829 | bool dirty, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 830 | bool switch_backup, |
Thomas Hellstrom | e9431ea | 2018-06-19 15:33:53 +0200 | [diff] [blame] | 831 | struct vmw_buffer_object *new_backup, |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 832 | unsigned long new_backup_offset); |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 833 | extern void vmw_query_move_notify(struct ttm_buffer_object *bo, |
Christian König | 6cf9dc2 | 2021-02-11 13:00:25 +0100 | [diff] [blame] | 834 | struct ttm_resource *old_mem, |
| 835 | struct ttm_resource *new_mem); |
Thomas Hellstrom | e9431ea | 2018-06-19 15:33:53 +0200 | [diff] [blame] | 836 | extern int vmw_query_readback_all(struct vmw_buffer_object *dx_query_mob); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 837 | extern void vmw_resource_evict_all(struct vmw_private *dev_priv); |
Thomas Hellstrom | e9431ea | 2018-06-19 15:33:53 +0200 | [diff] [blame] | 838 | extern void vmw_resource_unbind_list(struct vmw_buffer_object *vbo); |
Thomas Hellstrom | a0a6394 | 2019-03-04 19:37:40 +0100 | [diff] [blame] | 839 | void vmw_resource_mob_attach(struct vmw_resource *res); |
| 840 | void vmw_resource_mob_detach(struct vmw_resource *res); |
Thomas Hellstrom | b7468b1 | 2019-03-27 10:56:08 +0100 | [diff] [blame] | 841 | void vmw_resource_dirty_update(struct vmw_resource *res, pgoff_t start, |
| 842 | pgoff_t end); |
Thomas Hellstrom | fb80edb | 2019-03-28 11:36:25 +0100 | [diff] [blame] | 843 | int vmw_resources_clean(struct vmw_buffer_object *vbo, pgoff_t start, |
| 844 | pgoff_t end, pgoff_t *num_prefault); |
Thomas Hellstrom | a0a6394 | 2019-03-04 19:37:40 +0100 | [diff] [blame] | 845 | |
| 846 | /** |
| 847 | * vmw_resource_mob_attached - Whether a resource currently has a mob attached |
| 848 | * @res: The resource |
| 849 | * |
| 850 | * Return: true if the resource has a mob attached, false otherwise. |
| 851 | */ |
| 852 | static inline bool vmw_resource_mob_attached(const struct vmw_resource *res) |
| 853 | { |
Thomas Hellstrom | 61335d7 | 2019-03-05 08:24:35 +0100 | [diff] [blame] | 854 | return !RB_EMPTY_NODE(&res->mob_node); |
Thomas Hellstrom | a0a6394 | 2019-03-04 19:37:40 +0100 | [diff] [blame] | 855 | } |
Thomas Hellstrom | 79273e1 | 2018-01-16 09:33:27 +0100 | [diff] [blame] | 856 | |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 857 | /** |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 858 | * vmw_user_resource_noref_release - release a user resource pointer looked up |
| 859 | * without reference |
| 860 | */ |
| 861 | static inline void vmw_user_resource_noref_release(void) |
| 862 | { |
| 863 | ttm_base_object_noref_release(); |
| 864 | } |
| 865 | |
| 866 | /** |
Thomas Hellstrom | e9431ea | 2018-06-19 15:33:53 +0200 | [diff] [blame] | 867 | * Buffer object helper functions - vmwgfx_bo.c |
Jakob Bornecrantz | d991ef0 | 2011-10-04 20:13:21 +0200 | [diff] [blame] | 868 | */ |
Zack Rusin | 8afa13a | 2021-12-06 12:26:12 -0500 | [diff] [blame] | 869 | extern bool vmw_bo_is_vmw_bo(struct ttm_buffer_object *bo); |
Thomas Hellstrom | e9431ea | 2018-06-19 15:33:53 +0200 | [diff] [blame] | 870 | extern int vmw_bo_pin_in_placement(struct vmw_private *vmw_priv, |
| 871 | struct vmw_buffer_object *bo, |
| 872 | struct ttm_placement *placement, |
| 873 | bool interruptible); |
| 874 | extern int vmw_bo_pin_in_vram(struct vmw_private *dev_priv, |
| 875 | struct vmw_buffer_object *buf, |
| 876 | bool interruptible); |
| 877 | extern int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv, |
| 878 | struct vmw_buffer_object *buf, |
| 879 | bool interruptible); |
| 880 | extern int vmw_bo_pin_in_start_of_vram(struct vmw_private *vmw_priv, |
| 881 | struct vmw_buffer_object *bo, |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 882 | bool interruptible); |
Thomas Hellstrom | e9431ea | 2018-06-19 15:33:53 +0200 | [diff] [blame] | 883 | extern int vmw_bo_unpin(struct vmw_private *vmw_priv, |
| 884 | struct vmw_buffer_object *bo, |
| 885 | bool interruptible); |
Thomas Hellstrom | b37a6b9 | 2011-10-04 20:13:28 +0200 | [diff] [blame] | 886 | extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf, |
| 887 | SVGAGuestPtr *ptr); |
Thomas Hellstrom | e9431ea | 2018-06-19 15:33:53 +0200 | [diff] [blame] | 888 | extern void vmw_bo_pin_reserved(struct vmw_buffer_object *bo, bool pin); |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 889 | extern void vmw_bo_bo_free(struct ttm_buffer_object *bo); |
Christian König | b254557 | 2020-09-21 14:14:32 +0200 | [diff] [blame] | 890 | extern int vmw_bo_create_kernel(struct vmw_private *dev_priv, |
| 891 | unsigned long size, |
| 892 | struct ttm_placement *placement, |
| 893 | struct ttm_buffer_object **p_bo); |
Zack Rusin | 8afa13a | 2021-12-06 12:26:12 -0500 | [diff] [blame] | 894 | extern int vmw_bo_create(struct vmw_private *dev_priv, |
| 895 | size_t size, struct ttm_placement *placement, |
| 896 | bool interruptible, bool pin, |
| 897 | void (*bo_free)(struct ttm_buffer_object *bo), |
| 898 | struct vmw_buffer_object **p_bo); |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 899 | extern int vmw_bo_init(struct vmw_private *dev_priv, |
| 900 | struct vmw_buffer_object *vmw_bo, |
| 901 | size_t size, struct ttm_placement *placement, |
Christian König | fbe86ca5 | 2020-09-21 14:37:25 +0200 | [diff] [blame] | 902 | bool interruptible, bool pin, |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 903 | void (*bo_free)(struct ttm_buffer_object *bo)); |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 904 | extern int vmw_bo_unref_ioctl(struct drm_device *dev, void *data, |
| 905 | struct drm_file *file_priv); |
| 906 | extern int vmw_user_bo_synccpu_ioctl(struct drm_device *dev, void *data, |
| 907 | struct drm_file *file_priv); |
Zack Rusin | 8afa13a | 2021-12-06 12:26:12 -0500 | [diff] [blame] | 908 | extern int vmw_user_bo_lookup(struct drm_file *filp, |
| 909 | uint32_t handle, |
| 910 | struct vmw_buffer_object **out); |
Thomas Hellstrom | e9431ea | 2018-06-19 15:33:53 +0200 | [diff] [blame] | 911 | extern void vmw_bo_fence_single(struct ttm_buffer_object *bo, |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 912 | struct vmw_fence_obj *fence); |
Thomas Hellstrom | e9431ea | 2018-06-19 15:33:53 +0200 | [diff] [blame] | 913 | extern void *vmw_bo_map_and_cache(struct vmw_buffer_object *vbo); |
| 914 | extern void vmw_bo_unmap(struct vmw_buffer_object *vbo); |
| 915 | extern void vmw_bo_move_notify(struct ttm_buffer_object *bo, |
Dave Airlie | 2966141 | 2020-08-04 12:56:32 +1000 | [diff] [blame] | 916 | struct ttm_resource *mem); |
Thomas Hellstrom | e9431ea | 2018-06-19 15:33:53 +0200 | [diff] [blame] | 917 | extern void vmw_bo_swap_notify(struct ttm_buffer_object *bo); |
Thomas Hellstrom | b733bc2 | 2018-09-26 16:03:57 +0200 | [diff] [blame] | 918 | extern struct vmw_buffer_object * |
Zack Rusin | 8afa13a | 2021-12-06 12:26:12 -0500 | [diff] [blame] | 919 | vmw_user_bo_noref_lookup(struct drm_file *filp, u32 handle); |
Thomas Hellstrom | b733bc2 | 2018-09-26 16:03:57 +0200 | [diff] [blame] | 920 | |
Thomas Hellstrom | a0a6394 | 2019-03-04 19:37:40 +0100 | [diff] [blame] | 921 | /** |
| 922 | * vmw_bo_adjust_prio - Adjust the buffer object eviction priority |
| 923 | * according to attached resources |
| 924 | * @vbo: The struct vmw_buffer_object |
| 925 | */ |
| 926 | static inline void vmw_bo_prio_adjust(struct vmw_buffer_object *vbo) |
| 927 | { |
| 928 | int i = ARRAY_SIZE(vbo->res_prios); |
| 929 | |
| 930 | while (i--) { |
| 931 | if (vbo->res_prios[i]) { |
| 932 | vbo->base.priority = i; |
| 933 | return; |
| 934 | } |
| 935 | } |
| 936 | |
| 937 | vbo->base.priority = 3; |
| 938 | } |
| 939 | |
| 940 | /** |
| 941 | * vmw_bo_prio_add - Notify a buffer object of a newly attached resource |
| 942 | * eviction priority |
| 943 | * @vbo: The struct vmw_buffer_object |
| 944 | * @prio: The resource priority |
| 945 | * |
| 946 | * After being notified, the code assigns the highest resource eviction priority |
| 947 | * to the backing buffer object (mob). |
| 948 | */ |
| 949 | static inline void vmw_bo_prio_add(struct vmw_buffer_object *vbo, int prio) |
| 950 | { |
| 951 | if (vbo->res_prios[prio]++ == 0) |
| 952 | vmw_bo_prio_adjust(vbo); |
| 953 | } |
| 954 | |
| 955 | /** |
| 956 | * vmw_bo_prio_del - Notify a buffer object of a resource with a certain |
| 957 | * priority being removed |
| 958 | * @vbo: The struct vmw_buffer_object |
| 959 | * @prio: The resource priority |
| 960 | * |
| 961 | * After being notified, the code assigns the highest resource eviction priority |
| 962 | * to the backing buffer object (mob). |
| 963 | */ |
| 964 | static inline void vmw_bo_prio_del(struct vmw_buffer_object *vbo, int prio) |
| 965 | { |
| 966 | if (--vbo->res_prios[prio] == 0) |
| 967 | vmw_bo_prio_adjust(vbo); |
| 968 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 969 | |
| 970 | /** |
Zack Rusin | 8afa13a | 2021-12-06 12:26:12 -0500 | [diff] [blame] | 971 | * GEM related functionality - vmwgfx_gem.c |
| 972 | */ |
| 973 | extern int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv, |
| 974 | struct drm_file *filp, |
| 975 | uint32_t size, |
| 976 | uint32_t *handle, |
| 977 | struct vmw_buffer_object **p_vbo); |
| 978 | extern int vmw_gem_object_create_ioctl(struct drm_device *dev, void *data, |
| 979 | struct drm_file *filp); |
| 980 | extern void vmw_gem_destroy(struct ttm_buffer_object *bo); |
| 981 | extern void vmw_debugfs_gem_init(struct vmw_private *vdev); |
| 982 | |
| 983 | /** |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 984 | * Misc Ioctl functionality - vmwgfx_ioctl.c |
| 985 | */ |
| 986 | |
| 987 | extern int vmw_getparam_ioctl(struct drm_device *dev, void *data, |
| 988 | struct drm_file *file_priv); |
Thomas Hellstrom | f63f6a5 | 2011-09-01 20:18:41 +0000 | [diff] [blame] | 989 | extern int vmw_get_cap_3d_ioctl(struct drm_device *dev, void *data, |
| 990 | struct drm_file *file_priv); |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 991 | extern int vmw_present_ioctl(struct drm_device *dev, void *data, |
| 992 | struct drm_file *file_priv); |
| 993 | extern int vmw_present_readback_ioctl(struct drm_device *dev, void *data, |
| 994 | struct drm_file *file_priv); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 995 | |
| 996 | /** |
| 997 | * Fifo utilities - vmwgfx_fifo.c |
| 998 | */ |
| 999 | |
Zack Rusin | 2cd80db | 2021-05-05 15:10:07 -0400 | [diff] [blame] | 1000 | extern struct vmw_fifo_state *vmw_fifo_create(struct vmw_private *dev_priv); |
| 1001 | extern void vmw_fifo_destroy(struct vmw_private *dev_priv); |
| 1002 | extern bool vmw_cmd_supported(struct vmw_private *vmw); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1003 | extern void * |
Zack Rusin | 8426ed9 | 2020-11-18 12:54:19 -0500 | [diff] [blame] | 1004 | vmw_cmd_ctx_reserve(struct vmw_private *dev_priv, uint32_t bytes, int ctx_id); |
| 1005 | extern void vmw_cmd_commit(struct vmw_private *dev_priv, uint32_t bytes); |
| 1006 | extern void vmw_cmd_commit_flush(struct vmw_private *dev_priv, uint32_t bytes); |
| 1007 | extern int vmw_cmd_send_fence(struct vmw_private *dev_priv, uint32_t *seqno); |
| 1008 | extern bool vmw_supports_3d(struct vmw_private *dev_priv); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1009 | extern void vmw_fifo_ping_host(struct vmw_private *dev_priv, uint32_t reason); |
Jakob Bornecrantz | d7e1958 | 2010-05-28 11:21:59 +0200 | [diff] [blame] | 1010 | extern bool vmw_fifo_have_pitchlock(struct vmw_private *dev_priv); |
Zack Rusin | 8426ed9 | 2020-11-18 12:54:19 -0500 | [diff] [blame] | 1011 | extern int vmw_cmd_emit_dummy_query(struct vmw_private *dev_priv, |
| 1012 | uint32_t cid); |
| 1013 | extern int vmw_cmd_flush(struct vmw_private *dev_priv, |
| 1014 | bool interruptible); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1015 | |
Zack Rusin | 8426ed9 | 2020-11-18 12:54:19 -0500 | [diff] [blame] | 1016 | #define VMW_CMD_CTX_RESERVE(__priv, __bytes, __ctx_id) \ |
Deepak Rawat | 11c4541 | 2019-02-14 16:15:39 -0800 | [diff] [blame] | 1017 | ({ \ |
Zack Rusin | 8426ed9 | 2020-11-18 12:54:19 -0500 | [diff] [blame] | 1018 | vmw_cmd_ctx_reserve(__priv, __bytes, __ctx_id) ? : ({ \ |
Deepak Rawat | 11c4541 | 2019-02-14 16:15:39 -0800 | [diff] [blame] | 1019 | DRM_ERROR("FIFO reserve failed at %s for %u bytes\n", \ |
| 1020 | __func__, (unsigned int) __bytes); \ |
| 1021 | NULL; \ |
| 1022 | }); \ |
| 1023 | }) |
| 1024 | |
Zack Rusin | 8426ed9 | 2020-11-18 12:54:19 -0500 | [diff] [blame] | 1025 | #define VMW_CMD_RESERVE(__priv, __bytes) \ |
| 1026 | VMW_CMD_CTX_RESERVE(__priv, __bytes, SVGA3D_INVALID_ID) |
Deepak Rawat | 11c4541 | 2019-02-14 16:15:39 -0800 | [diff] [blame] | 1027 | |
Zack Rusin | 2cd80db | 2021-05-05 15:10:07 -0400 | [diff] [blame] | 1028 | |
| 1029 | /** |
| 1030 | * vmw_fifo_caps - Returns the capabilities of the FIFO command |
| 1031 | * queue or 0 if fifo memory isn't present. |
| 1032 | * @dev_priv: The device private context |
| 1033 | */ |
| 1034 | static inline uint32_t vmw_fifo_caps(const struct vmw_private *dev_priv) |
| 1035 | { |
| 1036 | if (!dev_priv->fifo_mem || !dev_priv->fifo) |
| 1037 | return 0; |
| 1038 | return dev_priv->fifo->capabilities; |
| 1039 | } |
| 1040 | |
| 1041 | |
| 1042 | /** |
| 1043 | * vmw_is_cursor_bypass3_enabled - Returns TRUE iff Cursor Bypass 3 |
| 1044 | * is enabled in the FIFO. |
| 1045 | * @dev_priv: The device private context |
| 1046 | */ |
| 1047 | static inline bool |
| 1048 | vmw_is_cursor_bypass3_enabled(const struct vmw_private *dev_priv) |
| 1049 | { |
| 1050 | return (vmw_fifo_caps(dev_priv) & SVGA_FIFO_CAP_CURSOR_BYPASS_3) != 0; |
| 1051 | } |
| 1052 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1053 | /** |
| 1054 | * TTM glue - vmwgfx_ttm_glue.c |
| 1055 | */ |
| 1056 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1057 | extern int vmw_mmap(struct file *filp, struct vm_area_struct *vma); |
| 1058 | |
| 1059 | /** |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1060 | * TTM buffer object driver - vmwgfx_ttm_buffer.c |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1061 | */ |
| 1062 | |
Thomas Hellstrom | 308d17e | 2013-11-28 01:46:56 -0800 | [diff] [blame] | 1063 | extern const size_t vmw_tt_size; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1064 | extern struct ttm_placement vmw_vram_placement; |
Thomas Hellstrom | 8ba5152 | 2010-01-16 16:05:05 +0100 | [diff] [blame] | 1065 | extern struct ttm_placement vmw_vram_sys_placement; |
Thomas Hellstrom | 135cba0 | 2010-10-26 21:21:47 +0200 | [diff] [blame] | 1066 | extern struct ttm_placement vmw_vram_gmr_placement; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1067 | extern struct ttm_placement vmw_sys_placement; |
Thomas Hellstrom | 5bb39e8 | 2011-10-04 20:13:33 +0200 | [diff] [blame] | 1068 | extern struct ttm_placement vmw_srf_placement; |
Thomas Hellstrom | 96c5f0d | 2012-11-21 11:19:53 +0100 | [diff] [blame] | 1069 | extern struct ttm_placement vmw_mob_placement; |
Thomas Hellstrom | ef86cfe | 2018-01-16 11:07:30 +0100 | [diff] [blame] | 1070 | extern struct ttm_placement vmw_nonfixed_placement; |
Christian König | 8af8a10 | 2020-10-01 14:51:40 +0200 | [diff] [blame] | 1071 | extern struct ttm_device_funcs vmw_bo_driver; |
Thomas Hellstrom | 0fd53cf | 2013-10-24 13:27:38 -0700 | [diff] [blame] | 1072 | extern const struct vmw_sg_table * |
| 1073 | vmw_bo_sg_table(struct ttm_buffer_object *bo); |
Dave Airlie | 56dc01f | 2020-08-04 12:55:34 +1000 | [diff] [blame] | 1074 | extern int vmw_bo_create_and_populate(struct vmw_private *dev_priv, |
| 1075 | unsigned long bo_size, |
| 1076 | struct ttm_buffer_object **bo_p); |
| 1077 | |
Thomas Hellstrom | d92d985 | 2013-10-24 01:49:26 -0700 | [diff] [blame] | 1078 | extern void vmw_piter_start(struct vmw_piter *viter, |
| 1079 | const struct vmw_sg_table *vsgt, |
| 1080 | unsigned long p_offs); |
| 1081 | |
| 1082 | /** |
| 1083 | * vmw_piter_next - Advance the iterator one page. |
| 1084 | * |
| 1085 | * @viter: Pointer to the iterator to advance. |
| 1086 | * |
| 1087 | * Returns false if past the list of pages, true otherwise. |
| 1088 | */ |
| 1089 | static inline bool vmw_piter_next(struct vmw_piter *viter) |
| 1090 | { |
| 1091 | return viter->next(viter); |
| 1092 | } |
| 1093 | |
| 1094 | /** |
| 1095 | * vmw_piter_dma_addr - Return the DMA address of the current page. |
| 1096 | * |
| 1097 | * @viter: Pointer to the iterator |
| 1098 | * |
| 1099 | * Returns the DMA address of the page pointed to by @viter. |
| 1100 | */ |
| 1101 | static inline dma_addr_t vmw_piter_dma_addr(struct vmw_piter *viter) |
| 1102 | { |
| 1103 | return viter->dma_address(viter); |
| 1104 | } |
| 1105 | |
| 1106 | /** |
| 1107 | * vmw_piter_page - Return a pointer to the current page. |
| 1108 | * |
| 1109 | * @viter: Pointer to the iterator |
| 1110 | * |
| 1111 | * Returns the DMA address of the page pointed to by @viter. |
| 1112 | */ |
| 1113 | static inline struct page *vmw_piter_page(struct vmw_piter *viter) |
| 1114 | { |
Zack Rusin | 8d9a8d9 | 2021-06-09 13:23:04 -0400 | [diff] [blame] | 1115 | return viter->pages[viter->i]; |
Thomas Hellstrom | d92d985 | 2013-10-24 01:49:26 -0700 | [diff] [blame] | 1116 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1117 | |
| 1118 | /** |
| 1119 | * Command submission - vmwgfx_execbuf.c |
| 1120 | */ |
| 1121 | |
Emil Velikov | cbfbe47 | 2019-05-22 17:41:17 +0100 | [diff] [blame] | 1122 | extern int vmw_execbuf_ioctl(struct drm_device *dev, void *data, |
| 1123 | struct drm_file *file_priv); |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 1124 | extern int vmw_execbuf_process(struct drm_file *file_priv, |
| 1125 | struct vmw_private *dev_priv, |
| 1126 | void __user *user_commands, |
| 1127 | void *kernel_commands, |
| 1128 | uint32_t command_size, |
| 1129 | uint64_t throttle_us, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1130 | uint32_t dx_context_handle, |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 1131 | struct drm_vmw_fence_rep __user |
Jakob Bornecrantz | bb1bd2f | 2012-02-09 16:56:43 +0100 | [diff] [blame] | 1132 | *user_fence_rep, |
Sinclair Yeh | c906965d | 2017-07-05 01:49:32 -0700 | [diff] [blame] | 1133 | struct vmw_fence_obj **out_fence, |
| 1134 | uint32_t flags); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1135 | extern void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv, |
| 1136 | struct vmw_fence_obj *fence); |
| 1137 | extern void vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv); |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1138 | |
Thomas Hellstrom | 5bb39e8 | 2011-10-04 20:13:33 +0200 | [diff] [blame] | 1139 | extern int vmw_execbuf_fence_commands(struct drm_file *file_priv, |
| 1140 | struct vmw_private *dev_priv, |
| 1141 | struct vmw_fence_obj **p_fence, |
| 1142 | uint32_t *p_handle); |
Thomas Hellstrom | 57c5ee7 | 2011-10-10 12:23:26 +0200 | [diff] [blame] | 1143 | extern void vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv, |
| 1144 | struct vmw_fpriv *vmw_fp, |
| 1145 | int ret, |
| 1146 | struct drm_vmw_fence_rep __user |
| 1147 | *user_fence_rep, |
| 1148 | struct vmw_fence_obj *fence, |
Sinclair Yeh | c906965d | 2017-07-05 01:49:32 -0700 | [diff] [blame] | 1149 | uint32_t fence_handle, |
| 1150 | int32_t out_fence_fd, |
| 1151 | struct sync_file *sync_file); |
Thomas Hellstrom | 65b97a2 | 2017-08-24 08:06:29 +0200 | [diff] [blame] | 1152 | bool vmw_cmd_describe(const void *buf, u32 *size, char const **cmd); |
Thomas Hellstrom | 5bb39e8 | 2011-10-04 20:13:33 +0200 | [diff] [blame] | 1153 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1154 | /** |
| 1155 | * IRQs and wating - vmwgfx_irq.c |
| 1156 | */ |
| 1157 | |
Thomas Hellstrom | e300173 | 2017-08-24 08:06:27 +0200 | [diff] [blame] | 1158 | extern int vmw_irq_install(struct drm_device *dev, int irq); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1159 | extern void vmw_irq_uninstall(struct drm_device *dev); |
Thomas Hellstrom | 6bcd8d3c | 2011-09-01 20:18:42 +0000 | [diff] [blame] | 1160 | extern bool vmw_seqno_passed(struct vmw_private *dev_priv, |
| 1161 | uint32_t seqno); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1162 | extern int vmw_fallback_wait(struct vmw_private *dev_priv, |
| 1163 | bool lazy, |
| 1164 | bool fifo_idle, |
Thomas Hellstrom | 6bcd8d3c | 2011-09-01 20:18:42 +0000 | [diff] [blame] | 1165 | uint32_t seqno, |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1166 | bool interruptible, |
| 1167 | unsigned long timeout); |
Zack Rusin | 2cd80db | 2021-05-05 15:10:07 -0400 | [diff] [blame] | 1168 | extern void vmw_update_seqno(struct vmw_private *dev_priv); |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 1169 | extern void vmw_seqno_waiter_add(struct vmw_private *dev_priv); |
| 1170 | extern void vmw_seqno_waiter_remove(struct vmw_private *dev_priv); |
Thomas Hellstrom | 57c5ee7 | 2011-10-10 12:23:26 +0200 | [diff] [blame] | 1171 | extern void vmw_goal_waiter_add(struct vmw_private *dev_priv); |
| 1172 | extern void vmw_goal_waiter_remove(struct vmw_private *dev_priv); |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 1173 | extern void vmw_generic_waiter_add(struct vmw_private *dev_priv, u32 flag, |
| 1174 | int *waiter_count); |
| 1175 | extern void vmw_generic_waiter_remove(struct vmw_private *dev_priv, |
| 1176 | u32 flag, int *waiter_count); |
Thomas Hellstrom | 1925d45 | 2010-05-28 11:21:57 +0200 | [diff] [blame] | 1177 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1178 | |
| 1179 | /** |
| 1180 | * Kernel framebuffer - vmwgfx_fb.c |
| 1181 | */ |
| 1182 | |
Thomas Zimmermann | 5dbf2fc | 2021-04-15 13:00:37 +0200 | [diff] [blame] | 1183 | #ifdef CONFIG_DRM_FBDEV_EMULATION |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1184 | int vmw_fb_init(struct vmw_private *vmw_priv); |
| 1185 | int vmw_fb_close(struct vmw_private *dev_priv); |
| 1186 | int vmw_fb_off(struct vmw_private *vmw_priv); |
| 1187 | int vmw_fb_on(struct vmw_private *vmw_priv); |
Thomas Zimmermann | 5dbf2fc | 2021-04-15 13:00:37 +0200 | [diff] [blame] | 1188 | #else |
| 1189 | static inline int vmw_fb_init(struct vmw_private *vmw_priv) |
| 1190 | { |
| 1191 | return 0; |
| 1192 | } |
| 1193 | static inline int vmw_fb_close(struct vmw_private *dev_priv) |
| 1194 | { |
| 1195 | return 0; |
| 1196 | } |
| 1197 | static inline int vmw_fb_off(struct vmw_private *vmw_priv) |
| 1198 | { |
| 1199 | return 0; |
| 1200 | } |
| 1201 | static inline int vmw_fb_on(struct vmw_private *vmw_priv) |
| 1202 | { |
| 1203 | return 0; |
| 1204 | } |
| 1205 | #endif |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1206 | |
| 1207 | /** |
| 1208 | * Kernel modesetting - vmwgfx_kms.c |
| 1209 | */ |
| 1210 | |
| 1211 | int vmw_kms_init(struct vmw_private *dev_priv); |
| 1212 | int vmw_kms_close(struct vmw_private *dev_priv); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1213 | int vmw_kms_cursor_bypass_ioctl(struct drm_device *dev, void *data, |
| 1214 | struct drm_file *file_priv); |
| 1215 | void vmw_kms_cursor_post_execbuf(struct vmw_private *dev_priv); |
| 1216 | void vmw_kms_cursor_snoop(struct vmw_surface *srf, |
| 1217 | struct ttm_object_file *tfile, |
| 1218 | struct ttm_buffer_object *bo, |
| 1219 | SVGA3dCmdHeader *header); |
Michel Dänzer | 0bef23f | 2011-08-31 07:42:50 +0000 | [diff] [blame] | 1220 | int vmw_kms_write_svga(struct vmw_private *vmw_priv, |
| 1221 | unsigned width, unsigned height, unsigned pitch, |
| 1222 | unsigned bpp, unsigned depth); |
Thomas Hellstrom | e133e737 | 2010-10-05 12:43:04 +0200 | [diff] [blame] | 1223 | bool vmw_kms_validate_mode_vram(struct vmw_private *dev_priv, |
| 1224 | uint32_t pitch, |
| 1225 | uint32_t height); |
Thomas Zimmermann | 4bebe91 | 2020-01-23 14:59:41 +0100 | [diff] [blame] | 1226 | u32 vmw_get_vblank_counter(struct drm_crtc *crtc); |
| 1227 | int vmw_enable_vblank(struct drm_crtc *crtc); |
| 1228 | void vmw_disable_vblank(struct drm_crtc *crtc); |
Jakob Bornecrantz | 2fcd5a7 | 2011-10-04 20:13:26 +0200 | [diff] [blame] | 1229 | int vmw_kms_present(struct vmw_private *dev_priv, |
| 1230 | struct drm_file *file_priv, |
| 1231 | struct vmw_framebuffer *vfb, |
| 1232 | struct vmw_surface *surface, |
| 1233 | uint32_t sid, int32_t destX, int32_t destY, |
| 1234 | struct drm_vmw_rect *clips, |
| 1235 | uint32_t num_clips); |
Thomas Hellstrom | cd2b89e | 2011-10-25 23:35:53 +0200 | [diff] [blame] | 1236 | int vmw_kms_update_layout_ioctl(struct drm_device *dev, void *data, |
| 1237 | struct drm_file *file_priv); |
Thomas Hellstrom | 8fbf9d9 | 2015-11-26 19:45:16 +0100 | [diff] [blame] | 1238 | void vmw_kms_legacy_hotspot_clear(struct vmw_private *dev_priv); |
Thomas Hellstrom | c3b9b16 | 2018-03-22 10:26:37 +0100 | [diff] [blame] | 1239 | int vmw_kms_suspend(struct drm_device *dev); |
| 1240 | int vmw_kms_resume(struct drm_device *dev); |
Thomas Hellstrom | 140bcaa | 2018-03-08 10:07:37 +0100 | [diff] [blame] | 1241 | void vmw_kms_lost_device(struct drm_device *dev); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1242 | |
Dave Airlie | 5e1782d | 2012-08-28 01:53:54 +0000 | [diff] [blame] | 1243 | int vmw_dumb_create(struct drm_file *file_priv, |
| 1244 | struct drm_device *dev, |
| 1245 | struct drm_mode_create_dumb *args); |
Thomas Hellstrom | 1a4b172 | 2015-06-26 02:03:53 -0700 | [diff] [blame] | 1246 | extern int vmw_resource_pin(struct vmw_resource *res, bool interruptible); |
Thomas Hellstrom | ed93394 | 2015-03-02 23:26:06 -0800 | [diff] [blame] | 1247 | extern void vmw_resource_unpin(struct vmw_resource *res); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1248 | extern enum vmw_res_type vmw_res_type(const struct vmw_resource *res); |
Thomas Hellstrom | ed93394 | 2015-03-02 23:26:06 -0800 | [diff] [blame] | 1249 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1250 | /** |
| 1251 | * Overlay control - vmwgfx_overlay.c |
| 1252 | */ |
| 1253 | |
| 1254 | int vmw_overlay_init(struct vmw_private *dev_priv); |
| 1255 | int vmw_overlay_close(struct vmw_private *dev_priv); |
| 1256 | int vmw_overlay_ioctl(struct drm_device *dev, void *data, |
| 1257 | struct drm_file *file_priv); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1258 | int vmw_overlay_resume_all(struct vmw_private *dev_priv); |
| 1259 | int vmw_overlay_pause_all(struct vmw_private *dev_priv); |
| 1260 | int vmw_overlay_claim(struct vmw_private *dev_priv, uint32_t *out); |
| 1261 | int vmw_overlay_unref(struct vmw_private *dev_priv, uint32_t stream_id); |
| 1262 | int vmw_overlay_num_overlays(struct vmw_private *dev_priv); |
| 1263 | int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv); |
| 1264 | |
| 1265 | /** |
Thomas Hellstrom | 135cba0 | 2010-10-26 21:21:47 +0200 | [diff] [blame] | 1266 | * GMR Id manager |
| 1267 | */ |
| 1268 | |
Dave Airlie | 6216177 | 2020-08-04 12:55:54 +1000 | [diff] [blame] | 1269 | int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type); |
Dave Airlie | 6eee667 | 2020-08-04 12:56:06 +1000 | [diff] [blame] | 1270 | void vmw_gmrid_man_fini(struct vmw_private *dev_priv, int type); |
Thomas Hellstrom | 135cba0 | 2010-10-26 21:21:47 +0200 | [diff] [blame] | 1271 | |
| 1272 | /** |
Zack Rusin | f6be232 | 2021-11-05 15:38:45 -0400 | [diff] [blame] | 1273 | * System memory manager |
| 1274 | */ |
| 1275 | int vmw_sys_man_init(struct vmw_private *dev_priv); |
| 1276 | void vmw_sys_man_fini(struct vmw_private *dev_priv); |
| 1277 | |
| 1278 | /** |
Thomas Hellstrom | 69977ff | 2013-11-13 01:50:46 -0800 | [diff] [blame] | 1279 | * Prime - vmwgfx_prime.c |
| 1280 | */ |
| 1281 | |
| 1282 | extern const struct dma_buf_ops vmw_prime_dmabuf_ops; |
| 1283 | extern int vmw_prime_fd_to_handle(struct drm_device *dev, |
| 1284 | struct drm_file *file_priv, |
| 1285 | int fd, u32 *handle); |
| 1286 | extern int vmw_prime_handle_to_fd(struct drm_device *dev, |
| 1287 | struct drm_file *file_priv, |
| 1288 | uint32_t handle, uint32_t flags, |
| 1289 | int *prime_fd); |
| 1290 | |
Thomas Hellstrom | 3530bdc | 2012-11-21 10:49:52 +0100 | [diff] [blame] | 1291 | /* |
| 1292 | * MemoryOBject management - vmwgfx_mob.c |
| 1293 | */ |
| 1294 | struct vmw_mob; |
| 1295 | extern int vmw_mob_bind(struct vmw_private *dev_priv, struct vmw_mob *mob, |
Thomas Hellstrom | 0fd53cf | 2013-10-24 13:27:38 -0700 | [diff] [blame] | 1296 | const struct vmw_sg_table *vsgt, |
| 1297 | unsigned long num_data_pages, int32_t mob_id); |
Thomas Hellstrom | 3530bdc | 2012-11-21 10:49:52 +0100 | [diff] [blame] | 1298 | extern void vmw_mob_unbind(struct vmw_private *dev_priv, |
| 1299 | struct vmw_mob *mob); |
| 1300 | extern void vmw_mob_destroy(struct vmw_mob *mob); |
| 1301 | extern struct vmw_mob *vmw_mob_create(unsigned long data_pages); |
| 1302 | extern int vmw_otables_setup(struct vmw_private *dev_priv); |
| 1303 | extern void vmw_otables_takedown(struct vmw_private *dev_priv); |
Thomas Hellstrom | 69977ff | 2013-11-13 01:50:46 -0800 | [diff] [blame] | 1304 | |
Thomas Hellstrom | c74c162 | 2012-11-21 12:10:26 +0100 | [diff] [blame] | 1305 | /* |
Thomas Hellstrom | 7086d09 | 2012-11-21 12:20:53 +0100 | [diff] [blame] | 1306 | * Context management - vmwgfx_context.c |
| 1307 | */ |
| 1308 | |
| 1309 | extern const struct vmw_user_resource_conv *user_context_converter; |
| 1310 | |
Thomas Hellstrom | 7086d09 | 2012-11-21 12:20:53 +0100 | [diff] [blame] | 1311 | extern int vmw_context_define_ioctl(struct drm_device *dev, void *data, |
| 1312 | struct drm_file *file_priv); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1313 | extern int vmw_extended_context_define_ioctl(struct drm_device *dev, void *data, |
| 1314 | struct drm_file *file_priv); |
Thomas Hellstrom | 7086d09 | 2012-11-21 12:20:53 +0100 | [diff] [blame] | 1315 | extern int vmw_context_destroy_ioctl(struct drm_device *dev, void *data, |
| 1316 | struct drm_file *file_priv); |
Thomas Hellstrom | 30f82d81 | 2014-02-05 08:13:56 +0100 | [diff] [blame] | 1317 | extern struct list_head *vmw_context_binding_list(struct vmw_resource *ctx); |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 1318 | extern struct vmw_cmdbuf_res_manager * |
| 1319 | vmw_context_res_man(struct vmw_resource *ctx); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1320 | extern struct vmw_resource *vmw_context_cotable(struct vmw_resource *ctx, |
| 1321 | SVGACOTableType cotable_type); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1322 | struct vmw_ctx_binding_state; |
| 1323 | extern struct vmw_ctx_binding_state * |
| 1324 | vmw_context_binding_state(struct vmw_resource *ctx); |
| 1325 | extern void vmw_dx_context_scrub_cotables(struct vmw_resource *ctx, |
| 1326 | bool readback); |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 1327 | extern int vmw_context_bind_dx_query(struct vmw_resource *ctx_res, |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1328 | struct vmw_buffer_object *mob); |
| 1329 | extern struct vmw_buffer_object * |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 1330 | vmw_context_get_dx_query_mob(struct vmw_resource *ctx_res); |
| 1331 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1332 | |
Thomas Hellstrom | 7086d09 | 2012-11-21 12:20:53 +0100 | [diff] [blame] | 1333 | /* |
| 1334 | * Surface management - vmwgfx_surface.c |
| 1335 | */ |
| 1336 | |
| 1337 | extern const struct vmw_user_resource_conv *user_surface_converter; |
| 1338 | |
Thomas Hellstrom | 7086d09 | 2012-11-21 12:20:53 +0100 | [diff] [blame] | 1339 | extern int vmw_surface_destroy_ioctl(struct drm_device *dev, void *data, |
| 1340 | struct drm_file *file_priv); |
| 1341 | extern int vmw_surface_define_ioctl(struct drm_device *dev, void *data, |
| 1342 | struct drm_file *file_priv); |
| 1343 | extern int vmw_surface_reference_ioctl(struct drm_device *dev, void *data, |
| 1344 | struct drm_file *file_priv); |
| 1345 | extern int vmw_gb_surface_define_ioctl(struct drm_device *dev, void *data, |
| 1346 | struct drm_file *file_priv); |
| 1347 | extern int vmw_gb_surface_reference_ioctl(struct drm_device *dev, void *data, |
| 1348 | struct drm_file *file_priv); |
Deepak Rawat | 14b1c33 | 2018-06-20 14:48:35 -0700 | [diff] [blame] | 1349 | extern int vmw_gb_surface_define_ext_ioctl(struct drm_device *dev, |
| 1350 | void *data, |
| 1351 | struct drm_file *file_priv); |
| 1352 | extern int vmw_gb_surface_reference_ext_ioctl(struct drm_device *dev, |
| 1353 | void *data, |
| 1354 | struct drm_file *file_priv); |
Thomas Hellstrom | 7086d09 | 2012-11-21 12:20:53 +0100 | [diff] [blame] | 1355 | |
Deepak Rawat | 504901d | 2019-04-29 14:55:44 -0700 | [diff] [blame] | 1356 | int vmw_gb_surface_define(struct vmw_private *dev_priv, |
Deepak Rawat | 504901d | 2019-04-29 14:55:44 -0700 | [diff] [blame] | 1357 | const struct vmw_surface_metadata *req, |
| 1358 | struct vmw_surface **srf_out); |
| 1359 | |
Thomas Hellstrom | 7086d09 | 2012-11-21 12:20:53 +0100 | [diff] [blame] | 1360 | /* |
Thomas Hellstrom | c74c162 | 2012-11-21 12:10:26 +0100 | [diff] [blame] | 1361 | * Shader management - vmwgfx_shader.c |
| 1362 | */ |
| 1363 | |
Thomas Hellstrom | 7086d09 | 2012-11-21 12:20:53 +0100 | [diff] [blame] | 1364 | extern const struct vmw_user_resource_conv *user_shader_converter; |
| 1365 | |
Thomas Hellstrom | c74c162 | 2012-11-21 12:10:26 +0100 | [diff] [blame] | 1366 | extern int vmw_shader_define_ioctl(struct drm_device *dev, void *data, |
| 1367 | struct drm_file *file_priv); |
| 1368 | extern int vmw_shader_destroy_ioctl(struct drm_device *dev, void *data, |
| 1369 | struct drm_file *file_priv); |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 1370 | extern int vmw_compat_shader_add(struct vmw_private *dev_priv, |
| 1371 | struct vmw_cmdbuf_res_manager *man, |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 1372 | u32 user_key, const void *bytecode, |
| 1373 | SVGA3dShaderType shader_type, |
| 1374 | size_t size, |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 1375 | struct list_head *list); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1376 | extern int vmw_shader_remove(struct vmw_cmdbuf_res_manager *man, |
| 1377 | u32 user_key, SVGA3dShaderType shader_type, |
| 1378 | struct list_head *list); |
| 1379 | extern int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man, |
| 1380 | struct vmw_resource *ctx, |
| 1381 | u32 user_key, |
| 1382 | SVGA3dShaderType shader_type, |
| 1383 | struct list_head *list); |
| 1384 | extern void vmw_dx_shader_cotable_list_scrub(struct vmw_private *dev_priv, |
| 1385 | struct list_head *list, |
| 1386 | bool readback); |
| 1387 | |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 1388 | extern struct vmw_resource * |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1389 | vmw_shader_lookup(struct vmw_cmdbuf_res_manager *man, |
| 1390 | u32 user_key, SVGA3dShaderType shader_type); |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 1391 | |
| 1392 | /* |
Deepak Rawat | e8bead9 | 2018-12-13 14:04:31 -0800 | [diff] [blame] | 1393 | * Streamoutput management |
| 1394 | */ |
| 1395 | struct vmw_resource * |
| 1396 | vmw_dx_streamoutput_lookup(struct vmw_cmdbuf_res_manager *man, |
| 1397 | u32 user_key); |
| 1398 | int vmw_dx_streamoutput_add(struct vmw_cmdbuf_res_manager *man, |
| 1399 | struct vmw_resource *ctx, |
| 1400 | SVGA3dStreamOutputId user_key, |
| 1401 | struct list_head *list); |
| 1402 | void vmw_dx_streamoutput_set_size(struct vmw_resource *res, u32 size); |
| 1403 | int vmw_dx_streamoutput_remove(struct vmw_cmdbuf_res_manager *man, |
| 1404 | SVGA3dStreamOutputId user_key, |
| 1405 | struct list_head *list); |
| 1406 | void vmw_dx_streamoutput_cotable_list_scrub(struct vmw_private *dev_priv, |
| 1407 | struct list_head *list, |
| 1408 | bool readback); |
| 1409 | |
| 1410 | /* |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 1411 | * Command buffer managed resources - vmwgfx_cmdbuf_res.c |
| 1412 | */ |
| 1413 | |
| 1414 | extern struct vmw_cmdbuf_res_manager * |
| 1415 | vmw_cmdbuf_res_man_create(struct vmw_private *dev_priv); |
| 1416 | extern void vmw_cmdbuf_res_man_destroy(struct vmw_cmdbuf_res_manager *man); |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 1417 | extern struct vmw_resource * |
| 1418 | vmw_cmdbuf_res_lookup(struct vmw_cmdbuf_res_manager *man, |
| 1419 | enum vmw_cmdbuf_res_type res_type, |
| 1420 | u32 user_key); |
| 1421 | extern void vmw_cmdbuf_res_revert(struct list_head *list); |
| 1422 | extern void vmw_cmdbuf_res_commit(struct list_head *list); |
| 1423 | extern int vmw_cmdbuf_res_add(struct vmw_cmdbuf_res_manager *man, |
| 1424 | enum vmw_cmdbuf_res_type res_type, |
| 1425 | u32 user_key, |
| 1426 | struct vmw_resource *res, |
| 1427 | struct list_head *list); |
| 1428 | extern int vmw_cmdbuf_res_remove(struct vmw_cmdbuf_res_manager *man, |
| 1429 | enum vmw_cmdbuf_res_type res_type, |
| 1430 | u32 user_key, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1431 | struct list_head *list, |
| 1432 | struct vmw_resource **res); |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 1433 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1434 | /* |
| 1435 | * COTable management - vmwgfx_cotable.c |
| 1436 | */ |
| 1437 | extern const SVGACOTableType vmw_cotable_scrub_order[]; |
| 1438 | extern struct vmw_resource *vmw_cotable_alloc(struct vmw_private *dev_priv, |
| 1439 | struct vmw_resource *ctx, |
| 1440 | u32 type); |
| 1441 | extern int vmw_cotable_notify(struct vmw_resource *res, int id); |
| 1442 | extern int vmw_cotable_scrub(struct vmw_resource *res, bool readback); |
| 1443 | extern void vmw_cotable_add_resource(struct vmw_resource *ctx, |
| 1444 | struct list_head *head); |
Thomas Hellstrom | c74c162 | 2012-11-21 12:10:26 +0100 | [diff] [blame] | 1445 | |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 1446 | /* |
| 1447 | * Command buffer managerment vmwgfx_cmdbuf.c |
| 1448 | */ |
| 1449 | struct vmw_cmdbuf_man; |
| 1450 | struct vmw_cmdbuf_header; |
| 1451 | |
| 1452 | extern struct vmw_cmdbuf_man * |
| 1453 | vmw_cmdbuf_man_create(struct vmw_private *dev_priv); |
Zack Rusin | 8426ed9 | 2020-11-18 12:54:19 -0500 | [diff] [blame] | 1454 | extern int vmw_cmdbuf_set_pool_size(struct vmw_cmdbuf_man *man, size_t size); |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 1455 | extern void vmw_cmdbuf_remove_pool(struct vmw_cmdbuf_man *man); |
| 1456 | extern void vmw_cmdbuf_man_destroy(struct vmw_cmdbuf_man *man); |
| 1457 | extern int vmw_cmdbuf_idle(struct vmw_cmdbuf_man *man, bool interruptible, |
| 1458 | unsigned long timeout); |
| 1459 | extern void *vmw_cmdbuf_reserve(struct vmw_cmdbuf_man *man, size_t size, |
| 1460 | int ctx_id, bool interruptible, |
| 1461 | struct vmw_cmdbuf_header *header); |
| 1462 | extern void vmw_cmdbuf_commit(struct vmw_cmdbuf_man *man, size_t size, |
| 1463 | struct vmw_cmdbuf_header *header, |
| 1464 | bool flush); |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 1465 | extern void *vmw_cmdbuf_alloc(struct vmw_cmdbuf_man *man, |
| 1466 | size_t size, bool interruptible, |
| 1467 | struct vmw_cmdbuf_header **p_header); |
| 1468 | extern void vmw_cmdbuf_header_free(struct vmw_cmdbuf_header *header); |
| 1469 | extern int vmw_cmdbuf_cur_flush(struct vmw_cmdbuf_man *man, |
| 1470 | bool interruptible); |
Thomas Hellstrom | ef36990 | 2017-08-24 08:06:28 +0200 | [diff] [blame] | 1471 | extern void vmw_cmdbuf_irqthread(struct vmw_cmdbuf_man *man); |
Thomas Hellstrom | bf6f036 | 2012-11-09 12:26:15 +0000 | [diff] [blame] | 1472 | |
Thomas Hellstrom | 79273e1 | 2018-01-16 09:33:27 +0100 | [diff] [blame] | 1473 | /* CPU blit utilities - vmwgfx_blit.c */ |
| 1474 | |
| 1475 | /** |
| 1476 | * struct vmw_diff_cpy - CPU blit information structure |
| 1477 | * |
| 1478 | * @rect: The output bounding box rectangle. |
| 1479 | * @line: The current line of the blit. |
| 1480 | * @line_offset: Offset of the current line segment. |
| 1481 | * @cpp: Bytes per pixel (granularity information). |
| 1482 | * @memcpy: Which memcpy function to use. |
| 1483 | */ |
| 1484 | struct vmw_diff_cpy { |
| 1485 | struct drm_rect rect; |
| 1486 | size_t line; |
| 1487 | size_t line_offset; |
| 1488 | int cpp; |
| 1489 | void (*do_cpy)(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src, |
| 1490 | size_t n); |
| 1491 | }; |
| 1492 | |
| 1493 | #define VMW_CPU_BLIT_INITIALIZER { \ |
| 1494 | .do_cpy = vmw_memcpy, \ |
| 1495 | } |
| 1496 | |
| 1497 | #define VMW_CPU_BLIT_DIFF_INITIALIZER(_cpp) { \ |
| 1498 | .line = 0, \ |
| 1499 | .line_offset = 0, \ |
| 1500 | .rect = { .x1 = INT_MAX/2, \ |
| 1501 | .y1 = INT_MAX/2, \ |
| 1502 | .x2 = INT_MIN/2, \ |
| 1503 | .y2 = INT_MIN/2 \ |
| 1504 | }, \ |
| 1505 | .cpp = _cpp, \ |
| 1506 | .do_cpy = vmw_diff_memcpy, \ |
| 1507 | } |
| 1508 | |
| 1509 | void vmw_diff_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src, |
| 1510 | size_t n); |
| 1511 | |
| 1512 | void vmw_memcpy(struct vmw_diff_cpy *diff, u8 *dest, const u8 *src, size_t n); |
| 1513 | |
| 1514 | int vmw_bo_cpu_blit(struct ttm_buffer_object *dst, |
| 1515 | u32 dst_offset, u32 dst_stride, |
| 1516 | struct ttm_buffer_object *src, |
| 1517 | u32 src_offset, u32 src_stride, |
| 1518 | u32 w, u32 h, |
| 1519 | struct vmw_diff_cpy *diff); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1520 | |
Thomas Hellstrom | 6ff67ae | 2018-06-21 09:39:21 +0200 | [diff] [blame] | 1521 | /* Host messaging -vmwgfx_msg.c: */ |
| 1522 | int vmw_host_get_guestinfo(const char *guest_info_param, |
| 1523 | char *buffer, size_t *length); |
Zack Rusin | 523375c | 2021-05-04 23:57:40 -0400 | [diff] [blame] | 1524 | __printf(1, 2) int vmw_host_printf(const char *fmt, ...); |
Roland Scheidegger | cb92a32 | 2019-11-21 17:44:56 +0100 | [diff] [blame] | 1525 | int vmw_msg_ioctl(struct drm_device *dev, void *data, |
| 1526 | struct drm_file *file_priv); |
Thomas Hellstrom | 6ff67ae | 2018-06-21 09:39:21 +0200 | [diff] [blame] | 1527 | |
Martin Krastev | 7a7a933 | 2021-06-09 13:23:00 -0400 | [diff] [blame] | 1528 | /* Host mksGuestStats -vmwgfx_msg.c: */ |
| 1529 | int vmw_mksstat_get_kern_slot(pid_t pid, struct vmw_private *dev_priv); |
| 1530 | |
| 1531 | int vmw_mksstat_reset_ioctl(struct drm_device *dev, void *data, |
| 1532 | struct drm_file *file_priv); |
| 1533 | int vmw_mksstat_add_ioctl(struct drm_device *dev, void *data, |
| 1534 | struct drm_file *file_priv); |
| 1535 | int vmw_mksstat_remove_ioctl(struct drm_device *dev, void *data, |
| 1536 | struct drm_file *file_priv); |
| 1537 | int vmw_mksstat_remove_all(struct vmw_private *dev_priv); |
| 1538 | |
Deepak Rawat | 5724f89 | 2019-02-11 11:46:27 -0800 | [diff] [blame] | 1539 | /* VMW logging */ |
| 1540 | |
| 1541 | /** |
| 1542 | * VMW_DEBUG_USER - Debug output for user-space debugging. |
| 1543 | * |
| 1544 | * @fmt: printf() like format string. |
| 1545 | * |
| 1546 | * This macro is for logging user-space error and debugging messages for e.g. |
| 1547 | * command buffer execution errors due to malformed commands, invalid context, |
| 1548 | * etc. |
| 1549 | */ |
| 1550 | #define VMW_DEBUG_USER(fmt, ...) \ |
| 1551 | DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__) |
| 1552 | |
Thomas Hellstrom | b7468b1 | 2019-03-27 10:56:08 +0100 | [diff] [blame] | 1553 | /* Resource dirtying - vmwgfx_page_dirty.c */ |
| 1554 | void vmw_bo_dirty_scan(struct vmw_buffer_object *vbo); |
| 1555 | int vmw_bo_dirty_add(struct vmw_buffer_object *vbo); |
| 1556 | void vmw_bo_dirty_transfer_to_res(struct vmw_resource *res); |
| 1557 | void vmw_bo_dirty_clear_res(struct vmw_resource *res); |
| 1558 | void vmw_bo_dirty_release(struct vmw_buffer_object *vbo); |
Thomas Hellstrom | fb80edb | 2019-03-28 11:36:25 +0100 | [diff] [blame] | 1559 | void vmw_bo_dirty_unmap(struct vmw_buffer_object *vbo, |
| 1560 | pgoff_t start, pgoff_t end); |
Thomas Hellstrom | b7468b1 | 2019-03-27 10:56:08 +0100 | [diff] [blame] | 1561 | vm_fault_t vmw_bo_vm_fault(struct vm_fault *vmf); |
| 1562 | vm_fault_t vmw_bo_vm_mkwrite(struct vm_fault *vmf); |
| 1563 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1564 | |
| 1565 | /** |
| 1566 | * VMW_DEBUG_KMS - Debug output for kernel mode-setting |
| 1567 | * |
| 1568 | * This macro is for debugging vmwgfx mode-setting code. |
| 1569 | */ |
| 1570 | #define VMW_DEBUG_KMS(fmt, ...) \ |
| 1571 | DRM_DEBUG_DRIVER(fmt, ##__VA_ARGS__) |
| 1572 | |
| 1573 | /** |
| 1574 | * Inline helper functions |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1575 | */ |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1576 | |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1577 | static inline void vmw_surface_unreference(struct vmw_surface **srf) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1578 | { |
Thomas Hellstrom | bf6f036 | 2012-11-09 12:26:15 +0000 | [diff] [blame] | 1579 | struct vmw_surface *tmp_srf = *srf; |
| 1580 | struct vmw_resource *res = &tmp_srf->res; |
Thomas Zimmermann | 6034d9d | 2019-01-25 12:02:09 +0100 | [diff] [blame] | 1581 | *srf = NULL; |
Thomas Hellstrom | bf6f036 | 2012-11-09 12:26:15 +0000 | [diff] [blame] | 1582 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1583 | vmw_resource_unreference(&res); |
| 1584 | } |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1585 | |
| 1586 | static inline struct vmw_surface *vmw_surface_reference(struct vmw_surface *srf) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1587 | { |
Thomas Zimmermann | 2d18cb9 | 2019-01-25 12:02:08 +0100 | [diff] [blame] | 1588 | (void) vmw_resource_reference(&srf->res); |
| 1589 | return srf; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1590 | } |
| 1591 | |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 1592 | static inline void vmw_bo_unreference(struct vmw_buffer_object **buf) |
| 1593 | { |
Christian König | 27eb1fa | 2018-10-19 13:49:05 +0200 | [diff] [blame] | 1594 | struct vmw_buffer_object *tmp_buf = *buf; |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 1595 | |
Thomas Hellstrom | 153b3d5 | 2015-06-25 10:47:43 -0700 | [diff] [blame] | 1596 | *buf = NULL; |
Zack Rusin | 2ef4fb9 | 2021-03-22 13:04:11 -0400 | [diff] [blame] | 1597 | if (tmp_buf != NULL) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1598 | ttm_bo_put(&tmp_buf->base); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | static inline struct vmw_buffer_object * |
| 1602 | vmw_bo_reference(struct vmw_buffer_object *buf) |
| 1603 | { |
| 1604 | ttm_bo_get(&buf->base); |
| 1605 | return buf; |
| 1606 | } |
| 1607 | |
Thomas Hellstrom | 153b3d5 | 2015-06-25 10:47:43 -0700 | [diff] [blame] | 1608 | static inline void vmw_fifo_resource_inc(struct vmw_private *dev_priv) |
| 1609 | { |
| 1610 | atomic_inc(&dev_priv->num_fifo_resources); |
| 1611 | } |
| 1612 | |
| 1613 | static inline void vmw_fifo_resource_dec(struct vmw_private *dev_priv) |
| 1614 | { |
| 1615 | atomic_dec(&dev_priv->num_fifo_resources); |
| 1616 | } |
Thomas Hellstrom | b76ff5e | 2015-10-28 10:44:04 +0100 | [diff] [blame] | 1617 | |
| 1618 | /** |
Zack Rusin | be4f77a | 2020-11-04 13:46:09 -0500 | [diff] [blame] | 1619 | * vmw_fifo_mem_read - Perform a MMIO read from the fifo memory |
Thomas Hellstrom | b76ff5e | 2015-10-28 10:44:04 +0100 | [diff] [blame] | 1620 | * |
Zack Rusin | be4f77a | 2020-11-04 13:46:09 -0500 | [diff] [blame] | 1621 | * @fifo_reg: The fifo register to read from |
Thomas Hellstrom | b76ff5e | 2015-10-28 10:44:04 +0100 | [diff] [blame] | 1622 | * |
| 1623 | * This function is intended to be equivalent to ioread32() on |
| 1624 | * memremap'd memory, but without byteswapping. |
| 1625 | */ |
Zack Rusin | be4f77a | 2020-11-04 13:46:09 -0500 | [diff] [blame] | 1626 | static inline u32 vmw_fifo_mem_read(struct vmw_private *vmw, uint32 fifo_reg) |
Thomas Hellstrom | b76ff5e | 2015-10-28 10:44:04 +0100 | [diff] [blame] | 1627 | { |
Zack Rusin | 2cd80db | 2021-05-05 15:10:07 -0400 | [diff] [blame] | 1628 | BUG_ON(vmw_is_svga_v3(vmw)); |
Zack Rusin | be4f77a | 2020-11-04 13:46:09 -0500 | [diff] [blame] | 1629 | return READ_ONCE(*(vmw->fifo_mem + fifo_reg)); |
Thomas Hellstrom | b76ff5e | 2015-10-28 10:44:04 +0100 | [diff] [blame] | 1630 | } |
| 1631 | |
| 1632 | /** |
Zack Rusin | be4f77a | 2020-11-04 13:46:09 -0500 | [diff] [blame] | 1633 | * vmw_fifo_mem_write - Perform a MMIO write to volatile memory |
Thomas Hellstrom | b76ff5e | 2015-10-28 10:44:04 +0100 | [diff] [blame] | 1634 | * |
Zack Rusin | be4f77a | 2020-11-04 13:46:09 -0500 | [diff] [blame] | 1635 | * @addr: The fifo register to write to |
Thomas Hellstrom | b76ff5e | 2015-10-28 10:44:04 +0100 | [diff] [blame] | 1636 | * |
| 1637 | * This function is intended to be equivalent to iowrite32 on |
| 1638 | * memremap'd memory, but without byteswapping. |
| 1639 | */ |
Zack Rusin | be4f77a | 2020-11-04 13:46:09 -0500 | [diff] [blame] | 1640 | static inline void vmw_fifo_mem_write(struct vmw_private *vmw, u32 fifo_reg, |
| 1641 | u32 value) |
Thomas Hellstrom | b76ff5e | 2015-10-28 10:44:04 +0100 | [diff] [blame] | 1642 | { |
Zack Rusin | 2cd80db | 2021-05-05 15:10:07 -0400 | [diff] [blame] | 1643 | BUG_ON(vmw_is_svga_v3(vmw)); |
Zack Rusin | be4f77a | 2020-11-04 13:46:09 -0500 | [diff] [blame] | 1644 | WRITE_ONCE(*(vmw->fifo_mem + fifo_reg), value); |
Thomas Hellstrom | b76ff5e | 2015-10-28 10:44:04 +0100 | [diff] [blame] | 1645 | } |
Zack Rusin | 2cd80db | 2021-05-05 15:10:07 -0400 | [diff] [blame] | 1646 | |
| 1647 | static inline u32 vmw_fence_read(struct vmw_private *dev_priv) |
| 1648 | { |
| 1649 | u32 fence; |
| 1650 | if (vmw_is_svga_v3(dev_priv)) |
| 1651 | fence = vmw_read(dev_priv, SVGA_REG_FENCE); |
| 1652 | else |
| 1653 | fence = vmw_fifo_mem_read(dev_priv, SVGA_FIFO_FENCE); |
| 1654 | return fence; |
| 1655 | } |
| 1656 | |
| 1657 | static inline void vmw_fence_write(struct vmw_private *dev_priv, |
| 1658 | u32 fence) |
| 1659 | { |
| 1660 | BUG_ON(vmw_is_svga_v3(dev_priv)); |
| 1661 | vmw_fifo_mem_write(dev_priv, SVGA_FIFO_FENCE, fence); |
| 1662 | } |
| 1663 | |
| 1664 | static inline u32 vmw_irq_status_read(struct vmw_private *vmw) |
| 1665 | { |
| 1666 | u32 status; |
| 1667 | if (vmw_is_svga_v3(vmw)) |
| 1668 | status = vmw_read(vmw, SVGA_REG_IRQ_STATUS); |
| 1669 | else |
| 1670 | status = inl(vmw->io_start + SVGA_IRQSTATUS_PORT); |
| 1671 | return status; |
| 1672 | } |
| 1673 | |
| 1674 | static inline void vmw_irq_status_write(struct vmw_private *vmw, |
| 1675 | uint32 status) |
| 1676 | { |
| 1677 | if (vmw_is_svga_v3(vmw)) |
| 1678 | vmw_write(vmw, SVGA_REG_IRQ_STATUS, status); |
| 1679 | else |
| 1680 | outl(status, vmw->io_start + SVGA_IRQSTATUS_PORT); |
| 1681 | } |
| 1682 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1683 | #endif |