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 | * |
Dirk Hohndel (VMware) | dff9688 | 2018-05-07 01:16:26 +0200 | [diff] [blame] | 4 | * Copyright 2009 - 2015 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 | **************************************************************************/ |
Sinclair Yeh | 58585116 | 2017-07-05 01:45:40 -0700 | [diff] [blame] | 27 | #include <linux/sync_file.h> |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 28 | |
| 29 | #include "vmwgfx_drv.h" |
| 30 | #include "vmwgfx_reg.h" |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 31 | #include <drm/ttm/ttm_bo_api.h> |
| 32 | #include <drm/ttm/ttm_placement.h> |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 33 | #include "vmwgfx_so.h" |
| 34 | #include "vmwgfx_binding.h" |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 35 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 36 | #define VMW_RES_HT_ORDER 12 |
| 37 | |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 38 | /* |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 39 | * Helper macro to get dx_ctx_node if available otherwise print an error |
| 40 | * message. This is for use in command verifier function where if dx_ctx_node |
| 41 | * is not set then command is invalid. |
| 42 | */ |
| 43 | #define VMW_GET_CTX_NODE(__sw_context) \ |
| 44 | ({ \ |
| 45 | __sw_context->dx_ctx_node ? __sw_context->dx_ctx_node : ({ \ |
| 46 | DRM_ERROR("SM context is not set at %s\n", __func__); \ |
| 47 | __sw_context->dx_ctx_node; \ |
| 48 | }); \ |
| 49 | }) |
| 50 | |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 51 | #define VMW_DECLARE_CMD_VAR(__var, __type) \ |
| 52 | struct { \ |
| 53 | SVGA3dCmdHeader header; \ |
| 54 | __type body; \ |
| 55 | } __var |
| 56 | |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 57 | /* |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 58 | * struct vmw_relocation - Buffer object relocation |
| 59 | * |
| 60 | * @head: List head for the command submission context's relocation list |
Thomas Hellstrom | cc1e3b7 | 2018-09-26 15:38:13 +0200 | [diff] [blame] | 61 | * @vbo: Non ref-counted pointer to buffer object |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 62 | * @mob_loc: Pointer to location for mob id to be modified |
| 63 | * @location: Pointer to location for guest pointer to be modified |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 64 | */ |
| 65 | struct vmw_relocation { |
| 66 | struct list_head head; |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 67 | struct vmw_buffer_object *vbo; |
Thomas Hellstrom | cc1e3b7 | 2018-09-26 15:38:13 +0200 | [diff] [blame] | 68 | union { |
| 69 | SVGAMobId *mob_loc; |
| 70 | SVGAGuestPtr *location; |
| 71 | }; |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 72 | }; |
| 73 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 74 | /** |
Thomas Hellstrom | a194403 | 2016-10-10 11:06:45 -0700 | [diff] [blame] | 75 | * enum vmw_resource_relocation_type - Relocation type for resources |
| 76 | * |
| 77 | * @vmw_res_rel_normal: Traditional relocation. The resource id in the |
| 78 | * command stream is replaced with the actual id after validation. |
| 79 | * @vmw_res_rel_nop: NOP relocation. The command is unconditionally replaced |
| 80 | * with a NOP. |
| 81 | * @vmw_res_rel_cond_nop: Conditional NOP relocation. If the resource id |
| 82 | * after validation is -1, the command is replaced with a NOP. Otherwise no |
| 83 | * action. |
| 84 | */ |
| 85 | enum vmw_resource_relocation_type { |
| 86 | vmw_res_rel_normal, |
| 87 | vmw_res_rel_nop, |
| 88 | vmw_res_rel_cond_nop, |
| 89 | vmw_res_rel_max |
| 90 | }; |
| 91 | |
| 92 | /** |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 93 | * struct vmw_resource_relocation - Relocation info for resources |
| 94 | * |
| 95 | * @head: List head for the software context's relocation list. |
| 96 | * @res: Non-ref-counted pointer to the resource. |
Thomas Hellstrom | e7a4528 | 2016-10-10 10:44:00 -0700 | [diff] [blame] | 97 | * @offset: Offset of single byte entries into the command buffer where the |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 98 | * id that needs fixup is located. |
Thomas Hellstrom | a194403 | 2016-10-10 11:06:45 -0700 | [diff] [blame] | 99 | * @rel_type: Type of relocation. |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 100 | */ |
| 101 | struct vmw_resource_relocation { |
| 102 | struct list_head head; |
| 103 | const struct vmw_resource *res; |
Thomas Hellstrom | a194403 | 2016-10-10 11:06:45 -0700 | [diff] [blame] | 104 | u32 offset:29; |
| 105 | enum vmw_resource_relocation_type rel_type:3; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 106 | }; |
| 107 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 108 | /* |
| 109 | * struct vmw_ctx_validation_info - Extra validation metadata for contexts |
| 110 | * @head: List head of context list |
| 111 | * @ctx: The context resource |
| 112 | * @cur: The context's persistent binding state |
| 113 | * @staged: The binding state changes of this command buffer |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 114 | */ |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 115 | struct vmw_ctx_validation_info { |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 116 | struct list_head head; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 117 | struct vmw_resource *ctx; |
| 118 | struct vmw_ctx_binding_state *cur; |
| 119 | struct vmw_ctx_binding_state *staged; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 120 | }; |
| 121 | |
| 122 | /** |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 123 | * struct vmw_cmd_entry - Describe a command for the verifier |
| 124 | * |
| 125 | * @user_allow: Whether allowed from the execbuf ioctl. |
| 126 | * @gb_disable: Whether disabled if guest-backed objects are available. |
| 127 | * @gb_enable: Whether enabled iff guest-backed objects are available. |
| 128 | */ |
| 129 | struct vmw_cmd_entry { |
| 130 | int (*func) (struct vmw_private *, struct vmw_sw_context *, |
| 131 | SVGA3dCmdHeader *); |
| 132 | bool user_allow; |
| 133 | bool gb_disable; |
| 134 | bool gb_enable; |
Thomas Hellstrom | 65b97a2 | 2017-08-24 08:06:29 +0200 | [diff] [blame] | 135 | const char *cmd_name; |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | #define VMW_CMD_DEF(_cmd, _func, _user_allow, _gb_disable, _gb_enable) \ |
| 139 | [(_cmd) - SVGA_3D_CMD_BASE] = {(_func), (_user_allow),\ |
Thomas Hellstrom | 65b97a2 | 2017-08-24 08:06:29 +0200 | [diff] [blame] | 140 | (_gb_disable), (_gb_enable), #_cmd} |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 141 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 142 | static int vmw_resource_context_res_add(struct vmw_private *dev_priv, |
| 143 | struct vmw_sw_context *sw_context, |
| 144 | struct vmw_resource *ctx); |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 145 | static int vmw_translate_mob_ptr(struct vmw_private *dev_priv, |
| 146 | struct vmw_sw_context *sw_context, |
| 147 | SVGAMobId *id, |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 148 | struct vmw_buffer_object **vmw_bo_p); |
Thomas Hellstrom | e7a4528 | 2016-10-10 10:44:00 -0700 | [diff] [blame] | 149 | /** |
| 150 | * vmw_ptr_diff - Compute the offset from a to b in bytes |
| 151 | * |
| 152 | * @a: A starting pointer. |
| 153 | * @b: A pointer offset in the same address space. |
| 154 | * |
| 155 | * Returns: The offset in bytes between the two pointers. |
| 156 | */ |
| 157 | static size_t vmw_ptr_diff(void *a, void *b) |
| 158 | { |
| 159 | return (unsigned long) b - (unsigned long) a; |
| 160 | } |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 161 | |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 162 | /** |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 163 | * vmw_execbuf_bindings_commit - Commit modified binding state |
| 164 | * @sw_context: The command submission context |
| 165 | * @backoff: Whether this is part of the error path and binding state |
| 166 | * changes should be ignored |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 167 | */ |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 168 | static void vmw_execbuf_bindings_commit(struct vmw_sw_context *sw_context, |
| 169 | bool backoff) |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 170 | { |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 171 | struct vmw_ctx_validation_info *entry; |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 172 | |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 173 | list_for_each_entry(entry, &sw_context->ctx_list, head) { |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 174 | if (!backoff) |
| 175 | vmw_binding_state_commit(entry->cur, entry->staged); |
| 176 | if (entry->staged != sw_context->staged_bindings) |
| 177 | vmw_binding_state_free(entry->staged); |
| 178 | else |
| 179 | sw_context->staged_bindings_inuse = false; |
| 180 | } |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 181 | |
| 182 | /* List entries are freed with the validation context */ |
| 183 | INIT_LIST_HEAD(&sw_context->ctx_list); |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | /** |
| 187 | * vmw_bind_dx_query_mob - Bind the DX query MOB if referenced |
| 188 | * @sw_context: The command submission context |
| 189 | */ |
| 190 | static void vmw_bind_dx_query_mob(struct vmw_sw_context *sw_context) |
| 191 | { |
| 192 | if (sw_context->dx_query_mob) |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 193 | vmw_context_bind_dx_query(sw_context->dx_query_ctx, |
| 194 | sw_context->dx_query_mob); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 195 | } |
| 196 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 197 | /** |
| 198 | * vmw_cmd_ctx_first_setup - Perform the setup needed when a context is |
| 199 | * added to the validate list. |
| 200 | * |
| 201 | * @dev_priv: Pointer to the device private: |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 202 | * @sw_context: The command submission context |
| 203 | * @node: The validation node holding the context resource metadata |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 204 | */ |
| 205 | static int vmw_cmd_ctx_first_setup(struct vmw_private *dev_priv, |
| 206 | struct vmw_sw_context *sw_context, |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 207 | struct vmw_resource *res, |
| 208 | struct vmw_ctx_validation_info *node) |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 209 | { |
| 210 | int ret; |
| 211 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 212 | ret = vmw_resource_context_res_add(dev_priv, sw_context, res); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 213 | if (unlikely(ret != 0)) |
| 214 | goto out_err; |
| 215 | |
| 216 | if (!sw_context->staged_bindings) { |
| 217 | sw_context->staged_bindings = |
| 218 | vmw_binding_state_alloc(dev_priv); |
| 219 | if (IS_ERR(sw_context->staged_bindings)) { |
| 220 | DRM_ERROR("Failed to allocate context binding " |
| 221 | "information.\n"); |
| 222 | ret = PTR_ERR(sw_context->staged_bindings); |
| 223 | sw_context->staged_bindings = NULL; |
| 224 | goto out_err; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | if (sw_context->staged_bindings_inuse) { |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 229 | node->staged = vmw_binding_state_alloc(dev_priv); |
| 230 | if (IS_ERR(node->staged)) { |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 231 | DRM_ERROR("Failed to allocate context binding " |
| 232 | "information.\n"); |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 233 | ret = PTR_ERR(node->staged); |
| 234 | node->staged = NULL; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 235 | goto out_err; |
| 236 | } |
| 237 | } else { |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 238 | node->staged = sw_context->staged_bindings; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 239 | sw_context->staged_bindings_inuse = true; |
| 240 | } |
| 241 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 242 | node->ctx = res; |
| 243 | node->cur = vmw_context_binding_state(res); |
| 244 | list_add_tail(&node->head, &sw_context->ctx_list); |
| 245 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 246 | return 0; |
| 247 | out_err: |
| 248 | return ret; |
| 249 | } |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 250 | |
| 251 | /** |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 252 | * vmw_execbuf_res_size - calculate extra size fore the resource validation |
| 253 | * node |
| 254 | * @dev_priv: Pointer to the device private struct. |
| 255 | * @res_type: The resource type. |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 256 | * |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 257 | * Guest-backed contexts and DX contexts require extra size to store |
| 258 | * execbuf private information in the validation node. Typically the |
| 259 | * binding manager associated data structures. |
| 260 | * |
| 261 | * Returns: The extra size requirement based on resource type. |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 262 | */ |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 263 | static unsigned int vmw_execbuf_res_size(struct vmw_private *dev_priv, |
| 264 | enum vmw_res_type res_type) |
| 265 | { |
| 266 | return (res_type == vmw_res_dx_context || |
| 267 | (res_type == vmw_res_context && dev_priv->has_mob)) ? |
| 268 | sizeof(struct vmw_ctx_validation_info) : 0; |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * vmw_execbuf_rcache_update - Update a resource-node cache entry |
| 273 | * |
| 274 | * @rcache: Pointer to the entry to update. |
| 275 | * @res: Pointer to the resource. |
| 276 | * @private: Pointer to the execbuf-private space in the resource |
| 277 | * validation node. |
| 278 | */ |
| 279 | static void vmw_execbuf_rcache_update(struct vmw_res_cache_entry *rcache, |
| 280 | struct vmw_resource *res, |
| 281 | void *private) |
| 282 | { |
| 283 | rcache->res = res; |
| 284 | rcache->private = private; |
| 285 | rcache->valid = 1; |
| 286 | rcache->valid_handle = 0; |
| 287 | } |
| 288 | |
| 289 | /** |
| 290 | * vmw_execbuf_res_noref_val_add - Add a resource described by an |
| 291 | * unreferenced rcu-protected pointer to the validation list. |
| 292 | * @sw_context: Pointer to the software context. |
| 293 | * @res: Unreferenced rcu-protected pointer to the resource. |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 294 | * @dirty: Whether to change dirty status. |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 295 | * |
| 296 | * Returns: 0 on success. Negative error code on failure. Typical error |
| 297 | * codes are %-EINVAL on inconsistency and %-ESRCH if the resource was |
| 298 | * doomed. |
| 299 | */ |
| 300 | static int vmw_execbuf_res_noref_val_add(struct vmw_sw_context *sw_context, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 301 | struct vmw_resource *res, |
| 302 | u32 dirty) |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 303 | { |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 304 | struct vmw_private *dev_priv = res->dev_priv; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 305 | int ret; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 306 | enum vmw_res_type res_type = vmw_res_type(res); |
| 307 | struct vmw_res_cache_entry *rcache; |
| 308 | struct vmw_ctx_validation_info *ctx_info; |
| 309 | bool first_usage; |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 310 | unsigned int priv_size; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 311 | |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 312 | rcache = &sw_context->res_cache[res_type]; |
| 313 | if (likely(rcache->valid && rcache->res == res)) { |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 314 | if (dirty) |
| 315 | vmw_validation_res_set_dirty(sw_context->ctx, |
| 316 | rcache->private, dirty); |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 317 | vmw_user_resource_noref_release(); |
| 318 | return 0; |
| 319 | } |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 320 | |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 321 | priv_size = vmw_execbuf_res_size(dev_priv, res_type); |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 322 | ret = vmw_validation_add_resource(sw_context->ctx, res, priv_size, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 323 | dirty, (void **)&ctx_info, |
| 324 | &first_usage); |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 325 | vmw_user_resource_noref_release(); |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 326 | if (ret) |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 327 | return ret; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 328 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 329 | if (priv_size && first_usage) { |
| 330 | ret = vmw_cmd_ctx_first_setup(dev_priv, sw_context, res, |
| 331 | ctx_info); |
| 332 | if (ret) |
| 333 | return ret; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 336 | vmw_execbuf_rcache_update(rcache, res, ctx_info); |
| 337 | return 0; |
| 338 | } |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 339 | |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 340 | /** |
| 341 | * vmw_execbuf_res_noctx_val_add - Add a non-context resource to the resource |
| 342 | * validation list if it's not already on it |
| 343 | * @sw_context: Pointer to the software context. |
| 344 | * @res: Pointer to the resource. |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 345 | * @dirty: Whether to change dirty status. |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 346 | * |
| 347 | * Returns: Zero on success. Negative error code on failure. |
| 348 | */ |
| 349 | static int vmw_execbuf_res_noctx_val_add(struct vmw_sw_context *sw_context, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 350 | struct vmw_resource *res, |
| 351 | u32 dirty) |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 352 | { |
| 353 | struct vmw_res_cache_entry *rcache; |
| 354 | enum vmw_res_type res_type = vmw_res_type(res); |
| 355 | void *ptr; |
| 356 | int ret; |
| 357 | |
| 358 | rcache = &sw_context->res_cache[res_type]; |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 359 | if (likely(rcache->valid && rcache->res == res)) { |
| 360 | if (dirty) |
| 361 | vmw_validation_res_set_dirty(sw_context->ctx, |
| 362 | rcache->private, dirty); |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 363 | return 0; |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 364 | } |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 365 | |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 366 | ret = vmw_validation_add_resource(sw_context->ctx, res, 0, dirty, |
| 367 | &ptr, NULL); |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 368 | if (ret) |
| 369 | return ret; |
| 370 | |
| 371 | vmw_execbuf_rcache_update(rcache, res, ptr); |
| 372 | |
| 373 | return 0; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | /** |
| 377 | * vmw_view_res_val_add - Add a view and the surface it's pointing to |
| 378 | * to the validation list |
| 379 | * |
| 380 | * @sw_context: The software context holding the validation list. |
| 381 | * @view: Pointer to the view resource. |
| 382 | * |
| 383 | * Returns 0 if success, negative error code otherwise. |
| 384 | */ |
| 385 | static int vmw_view_res_val_add(struct vmw_sw_context *sw_context, |
| 386 | struct vmw_resource *view) |
| 387 | { |
| 388 | int ret; |
| 389 | |
| 390 | /* |
| 391 | * First add the resource the view is pointing to, otherwise |
| 392 | * it may be swapped out when the view is validated. |
| 393 | */ |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 394 | ret = vmw_execbuf_res_noctx_val_add(sw_context, vmw_view_srf(view), |
| 395 | vmw_view_dirtying(view)); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 396 | if (ret) |
| 397 | return ret; |
| 398 | |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 399 | return vmw_execbuf_res_noctx_val_add(sw_context, view, |
| 400 | VMW_RES_DIRTY_NONE); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | /** |
| 404 | * vmw_view_id_val_add - Look up a view and add it and the surface it's |
| 405 | * pointing to to the validation list. |
| 406 | * |
| 407 | * @sw_context: The software context holding the validation list. |
| 408 | * @view_type: The view type to look up. |
| 409 | * @id: view id of the view. |
| 410 | * |
| 411 | * The view is represented by a view id and the DX context it's created on, |
| 412 | * or scheduled for creation on. If there is no DX context set, the function |
Thomas Hellstrom | 508108e | 2018-09-26 16:28:45 +0200 | [diff] [blame] | 413 | * will return an -EINVAL error pointer. |
| 414 | * |
| 415 | * Returns: Unreferenced pointer to the resource on success, negative error |
| 416 | * pointer on failure. |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 417 | */ |
Thomas Hellstrom | 508108e | 2018-09-26 16:28:45 +0200 | [diff] [blame] | 418 | static struct vmw_resource * |
| 419 | vmw_view_id_val_add(struct vmw_sw_context *sw_context, |
| 420 | enum vmw_view_type view_type, u32 id) |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 421 | { |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 422 | struct vmw_ctx_validation_info *ctx_node = sw_context->dx_ctx_node; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 423 | struct vmw_resource *view; |
| 424 | int ret; |
| 425 | |
| 426 | if (!ctx_node) { |
| 427 | DRM_ERROR("DX Context not set.\n"); |
Thomas Hellstrom | 508108e | 2018-09-26 16:28:45 +0200 | [diff] [blame] | 428 | return ERR_PTR(-EINVAL); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | view = vmw_view_lookup(sw_context->man, view_type, id); |
| 432 | if (IS_ERR(view)) |
Thomas Hellstrom | 508108e | 2018-09-26 16:28:45 +0200 | [diff] [blame] | 433 | return view; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 434 | |
| 435 | ret = vmw_view_res_val_add(sw_context, view); |
Thomas Hellstrom | 508108e | 2018-09-26 16:28:45 +0200 | [diff] [blame] | 436 | if (ret) |
| 437 | return ERR_PTR(ret); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 438 | |
Thomas Hellstrom | 508108e | 2018-09-26 16:28:45 +0200 | [diff] [blame] | 439 | return view; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | /** |
Thomas Hellstrom | 30f82d81 | 2014-02-05 08:13:56 +0100 | [diff] [blame] | 443 | * vmw_resource_context_res_add - Put resources previously bound to a context on |
| 444 | * the validation list |
| 445 | * |
| 446 | * @dev_priv: Pointer to a device private structure |
| 447 | * @sw_context: Pointer to a software context used for this command submission |
| 448 | * @ctx: Pointer to the context resource |
| 449 | * |
| 450 | * This function puts all resources that were previously bound to @ctx on |
| 451 | * the resource validation list. This is part of the context state reemission |
| 452 | */ |
| 453 | static int vmw_resource_context_res_add(struct vmw_private *dev_priv, |
| 454 | struct vmw_sw_context *sw_context, |
| 455 | struct vmw_resource *ctx) |
| 456 | { |
| 457 | struct list_head *binding_list; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 458 | struct vmw_ctx_bindinfo *entry; |
Thomas Hellstrom | 30f82d81 | 2014-02-05 08:13:56 +0100 | [diff] [blame] | 459 | int ret = 0; |
| 460 | struct vmw_resource *res; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 461 | u32 i; |
Thomas Hellstrom | 30f82d81 | 2014-02-05 08:13:56 +0100 | [diff] [blame] | 462 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 463 | /* Add all cotables to the validation list. */ |
| 464 | if (dev_priv->has_dx && vmw_res_type(ctx) == vmw_res_dx_context) { |
| 465 | for (i = 0; i < SVGA_COTABLE_DX10_MAX; ++i) { |
| 466 | res = vmw_context_cotable(ctx, i); |
| 467 | if (IS_ERR(res)) |
| 468 | continue; |
| 469 | |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 470 | ret = vmw_execbuf_res_noctx_val_add(sw_context, res, |
| 471 | VMW_RES_DIRTY_SET); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 472 | if (unlikely(ret != 0)) |
| 473 | return ret; |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | |
| 478 | /* Add all resources bound to the context to the validation list */ |
Thomas Hellstrom | 30f82d81 | 2014-02-05 08:13:56 +0100 | [diff] [blame] | 479 | mutex_lock(&dev_priv->binding_mutex); |
| 480 | binding_list = vmw_context_binding_list(ctx); |
| 481 | |
| 482 | list_for_each_entry(entry, binding_list, ctx_list) { |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 483 | if (vmw_res_type(entry->res) == vmw_res_view) |
| 484 | ret = vmw_view_res_val_add(sw_context, entry->res); |
| 485 | else |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 486 | ret = vmw_execbuf_res_noctx_val_add |
| 487 | (sw_context, entry->res, |
| 488 | vmw_binding_dirtying(entry->bt)); |
Thomas Hellstrom | 30f82d81 | 2014-02-05 08:13:56 +0100 | [diff] [blame] | 489 | if (unlikely(ret != 0)) |
| 490 | break; |
| 491 | } |
| 492 | |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 493 | if (dev_priv->has_dx && vmw_res_type(ctx) == vmw_res_dx_context) { |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 494 | struct vmw_buffer_object *dx_query_mob; |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 495 | |
| 496 | dx_query_mob = vmw_context_get_dx_query_mob(ctx); |
| 497 | if (dx_query_mob) |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 498 | ret = vmw_validation_add_bo(sw_context->ctx, |
| 499 | dx_query_mob, true, false); |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 500 | } |
| 501 | |
Thomas Hellstrom | 30f82d81 | 2014-02-05 08:13:56 +0100 | [diff] [blame] | 502 | mutex_unlock(&dev_priv->binding_mutex); |
| 503 | return ret; |
| 504 | } |
| 505 | |
| 506 | /** |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 507 | * vmw_resource_relocation_add - Add a relocation to the relocation list |
| 508 | * |
| 509 | * @list: Pointer to head of relocation list. |
| 510 | * @res: The resource. |
| 511 | * @offset: Offset into the command buffer currently being parsed where the |
Thomas Hellstrom | e7a4528 | 2016-10-10 10:44:00 -0700 | [diff] [blame] | 512 | * id that needs fixup is located. Granularity is one byte. |
Thomas Hellstrom | a194403 | 2016-10-10 11:06:45 -0700 | [diff] [blame] | 513 | * @rel_type: Relocation type. |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 514 | */ |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 515 | static int vmw_resource_relocation_add(struct vmw_sw_context *sw_context, |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 516 | const struct vmw_resource *res, |
Thomas Hellstrom | a194403 | 2016-10-10 11:06:45 -0700 | [diff] [blame] | 517 | unsigned long offset, |
| 518 | enum vmw_resource_relocation_type |
| 519 | rel_type) |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 520 | { |
| 521 | struct vmw_resource_relocation *rel; |
| 522 | |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 523 | rel = vmw_validation_mem_alloc(sw_context->ctx, sizeof(*rel)); |
Ravikant B Sharma | 1a4adb0 | 2016-11-08 17:30:31 +0530 | [diff] [blame] | 524 | if (unlikely(!rel)) { |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 525 | DRM_ERROR("Failed to allocate a resource relocation.\n"); |
| 526 | return -ENOMEM; |
| 527 | } |
| 528 | |
| 529 | rel->res = res; |
| 530 | rel->offset = offset; |
Thomas Hellstrom | a194403 | 2016-10-10 11:06:45 -0700 | [diff] [blame] | 531 | rel->rel_type = rel_type; |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 532 | list_add_tail(&rel->head, &sw_context->res_relocations); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 533 | |
| 534 | return 0; |
| 535 | } |
| 536 | |
| 537 | /** |
| 538 | * vmw_resource_relocations_free - Free all relocations on a list |
| 539 | * |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 540 | * @list: Pointer to the head of the relocation list |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 541 | */ |
| 542 | static void vmw_resource_relocations_free(struct list_head *list) |
| 543 | { |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 544 | /* Memory is validation context memory, so no need to free it */ |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 545 | |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 546 | INIT_LIST_HEAD(list); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | /** |
| 550 | * vmw_resource_relocations_apply - Apply all relocations on a list |
| 551 | * |
| 552 | * @cb: Pointer to the start of the command buffer bein patch. This need |
| 553 | * not be the same buffer as the one being parsed when the relocation |
| 554 | * list was built, but the contents must be the same modulo the |
| 555 | * resource ids. |
| 556 | * @list: Pointer to the head of the relocation list. |
| 557 | */ |
| 558 | static void vmw_resource_relocations_apply(uint32_t *cb, |
| 559 | struct list_head *list) |
| 560 | { |
| 561 | struct vmw_resource_relocation *rel; |
| 562 | |
Thomas Hellstrom | a194403 | 2016-10-10 11:06:45 -0700 | [diff] [blame] | 563 | /* Validate the struct vmw_resource_relocation member size */ |
| 564 | BUILD_BUG_ON(SVGA_CB_MAX_SIZE >= (1 << 29)); |
| 565 | BUILD_BUG_ON(vmw_res_rel_max >= (1 << 3)); |
| 566 | |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 567 | list_for_each_entry(rel, list, head) { |
Thomas Hellstrom | e7a4528 | 2016-10-10 10:44:00 -0700 | [diff] [blame] | 568 | u32 *addr = (u32 *)((unsigned long) cb + rel->offset); |
Thomas Hellstrom | a194403 | 2016-10-10 11:06:45 -0700 | [diff] [blame] | 569 | switch (rel->rel_type) { |
| 570 | case vmw_res_rel_normal: |
Thomas Hellstrom | e7a4528 | 2016-10-10 10:44:00 -0700 | [diff] [blame] | 571 | *addr = rel->res->id; |
Thomas Hellstrom | a194403 | 2016-10-10 11:06:45 -0700 | [diff] [blame] | 572 | break; |
| 573 | case vmw_res_rel_nop: |
Thomas Hellstrom | e7a4528 | 2016-10-10 10:44:00 -0700 | [diff] [blame] | 574 | *addr = SVGA_3D_CMD_NOP; |
Thomas Hellstrom | a194403 | 2016-10-10 11:06:45 -0700 | [diff] [blame] | 575 | break; |
| 576 | default: |
| 577 | if (rel->res->id == -1) |
| 578 | *addr = SVGA_3D_CMD_NOP; |
| 579 | break; |
| 580 | } |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 581 | } |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 582 | } |
| 583 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 584 | static int vmw_cmd_invalid(struct vmw_private *dev_priv, |
| 585 | struct vmw_sw_context *sw_context, |
| 586 | SVGA3dCmdHeader *header) |
| 587 | { |
Sinclair Yeh | fcfffdd | 2017-07-17 23:28:36 -0700 | [diff] [blame] | 588 | return -EINVAL; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | static int vmw_cmd_ok(struct vmw_private *dev_priv, |
| 592 | struct vmw_sw_context *sw_context, |
| 593 | SVGA3dCmdHeader *header) |
| 594 | { |
| 595 | return 0; |
| 596 | } |
| 597 | |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 598 | /** |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 599 | * vmw_resources_reserve - Reserve all resources on the sw_context's |
| 600 | * resource list. |
| 601 | * |
| 602 | * @sw_context: Pointer to the software context. |
| 603 | * |
| 604 | * Note that since vmware's command submission currently is protected by |
| 605 | * the cmdbuf mutex, no fancy deadlock avoidance is required for resources, |
| 606 | * since only a single thread at once will attempt this. |
| 607 | */ |
| 608 | static int vmw_resources_reserve(struct vmw_sw_context *sw_context) |
| 609 | { |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 610 | int ret; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 611 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 612 | ret = vmw_validation_res_reserve(sw_context->ctx, true); |
| 613 | if (ret) |
| 614 | return ret; |
Charmaine Lee | 2f633e5 | 2015-08-10 10:45:11 -0700 | [diff] [blame] | 615 | |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 616 | if (sw_context->dx_query_mob) { |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 617 | struct vmw_buffer_object *expected_dx_query_mob; |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 618 | |
| 619 | expected_dx_query_mob = |
| 620 | vmw_context_get_dx_query_mob(sw_context->dx_query_ctx); |
| 621 | if (expected_dx_query_mob && |
| 622 | expected_dx_query_mob != sw_context->dx_query_mob) { |
| 623 | ret = -EINVAL; |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | return ret; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | /** |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 631 | * vmw_cmd_res_check - Check that a resource is present and if so, put it |
| 632 | * on the resource validate list unless it's already there. |
| 633 | * |
| 634 | * @dev_priv: Pointer to a device private structure. |
| 635 | * @sw_context: Pointer to the software context. |
| 636 | * @res_type: Resource type. |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 637 | * @dirty: Whether to change dirty status. |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 638 | * @converter: User-space visisble type specific information. |
| 639 | * @id_loc: Pointer to the location in the command buffer currently being |
| 640 | * parsed from where the user-space resource id handle is located. |
| 641 | * @p_val: Pointer to pointer to resource validalidation node. Populated |
| 642 | * on exit. |
| 643 | */ |
| 644 | static int |
| 645 | vmw_cmd_res_check(struct vmw_private *dev_priv, |
| 646 | struct vmw_sw_context *sw_context, |
| 647 | enum vmw_res_type res_type, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 648 | u32 dirty, |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 649 | const struct vmw_user_resource_conv *converter, |
| 650 | uint32_t *id_loc, |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 651 | struct vmw_resource **p_res) |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 652 | { |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 653 | struct vmw_res_cache_entry *rcache = &sw_context->res_cache[res_type]; |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 654 | struct vmw_resource *res; |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 655 | int ret; |
| 656 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 657 | if (p_res) |
| 658 | *p_res = NULL; |
| 659 | |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 660 | if (*id_loc == SVGA3D_INVALID_ID) { |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 661 | if (res_type == vmw_res_context) { |
| 662 | DRM_ERROR("Illegal context invalid id.\n"); |
| 663 | return -EINVAL; |
| 664 | } |
| 665 | return 0; |
| 666 | } |
| 667 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 668 | if (likely(rcache->valid_handle && *id_loc == rcache->handle)) { |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 669 | res = rcache->res; |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 670 | if (dirty) |
| 671 | vmw_validation_res_set_dirty(sw_context->ctx, |
| 672 | rcache->private, dirty); |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 673 | } else { |
| 674 | unsigned int size = vmw_execbuf_res_size(dev_priv, res_type); |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 675 | |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 676 | ret = vmw_validation_preload_res(sw_context->ctx, size); |
| 677 | if (ret) |
| 678 | return ret; |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 679 | |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 680 | res = vmw_user_resource_noref_lookup_handle |
| 681 | (dev_priv, sw_context->fp->tfile, *id_loc, converter); |
Chengguang Xu | 4efa666 | 2019-03-01 10:14:06 -0800 | [diff] [blame] | 682 | if (IS_ERR(res)) { |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 683 | DRM_ERROR("Could not find or use resource 0x%08x.\n", |
| 684 | (unsigned int) *id_loc); |
| 685 | return PTR_ERR(res); |
| 686 | } |
| 687 | |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 688 | ret = vmw_execbuf_res_noref_val_add(sw_context, res, dirty); |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 689 | if (unlikely(ret != 0)) |
| 690 | return ret; |
| 691 | |
| 692 | if (rcache->valid && rcache->res == res) { |
| 693 | rcache->valid_handle = true; |
| 694 | rcache->handle = *id_loc; |
| 695 | } |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 696 | } |
| 697 | |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 698 | ret = vmw_resource_relocation_add(sw_context, res, |
| 699 | vmw_ptr_diff(sw_context->buf_start, |
| 700 | id_loc), |
| 701 | vmw_res_rel_normal); |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 702 | if (p_res) |
| 703 | *p_res = res; |
| 704 | |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 705 | return 0; |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | /** |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 709 | * vmw_rebind_dx_query - Rebind DX query associated with the context |
| 710 | * |
| 711 | * @ctx_res: context the query belongs to |
| 712 | * |
| 713 | * This function assumes binding_mutex is held. |
| 714 | */ |
| 715 | static int vmw_rebind_all_dx_query(struct vmw_resource *ctx_res) |
| 716 | { |
| 717 | struct vmw_private *dev_priv = ctx_res->dev_priv; |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 718 | struct vmw_buffer_object *dx_query_mob; |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 719 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXBindAllQuery); |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 720 | |
| 721 | dx_query_mob = vmw_context_get_dx_query_mob(ctx_res); |
| 722 | |
| 723 | if (!dx_query_mob || dx_query_mob->dx_query_ctx) |
| 724 | return 0; |
| 725 | |
| 726 | cmd = vmw_fifo_reserve_dx(dev_priv, sizeof(*cmd), ctx_res->id); |
| 727 | |
| 728 | if (cmd == NULL) { |
| 729 | DRM_ERROR("Failed to rebind queries.\n"); |
| 730 | return -ENOMEM; |
| 731 | } |
| 732 | |
| 733 | cmd->header.id = SVGA_3D_CMD_DX_BIND_ALL_QUERY; |
| 734 | cmd->header.size = sizeof(cmd->body); |
| 735 | cmd->body.cid = ctx_res->id; |
| 736 | cmd->body.mobid = dx_query_mob->base.mem.start; |
| 737 | vmw_fifo_commit(dev_priv, sizeof(*cmd)); |
| 738 | |
| 739 | vmw_context_bind_dx_query(ctx_res, dx_query_mob); |
| 740 | |
| 741 | return 0; |
| 742 | } |
| 743 | |
| 744 | /** |
Thomas Hellstrom | 30f82d81 | 2014-02-05 08:13:56 +0100 | [diff] [blame] | 745 | * vmw_rebind_contexts - Rebind all resources previously bound to |
| 746 | * referenced contexts. |
| 747 | * |
| 748 | * @sw_context: Pointer to the software context. |
| 749 | * |
| 750 | * Rebind context binding points that have been scrubbed because of eviction. |
| 751 | */ |
| 752 | static int vmw_rebind_contexts(struct vmw_sw_context *sw_context) |
| 753 | { |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 754 | struct vmw_ctx_validation_info *val; |
Thomas Hellstrom | 30f82d81 | 2014-02-05 08:13:56 +0100 | [diff] [blame] | 755 | int ret; |
| 756 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 757 | list_for_each_entry(val, &sw_context->ctx_list, head) { |
| 758 | ret = vmw_binding_rebind_all(val->cur); |
Thomas Hellstrom | 30f82d81 | 2014-02-05 08:13:56 +0100 | [diff] [blame] | 759 | if (unlikely(ret != 0)) { |
| 760 | if (ret != -ERESTARTSYS) |
| 761 | DRM_ERROR("Failed to rebind context.\n"); |
| 762 | return ret; |
| 763 | } |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 764 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 765 | ret = vmw_rebind_all_dx_query(val->ctx); |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 766 | if (ret != 0) |
| 767 | return ret; |
Thomas Hellstrom | 30f82d81 | 2014-02-05 08:13:56 +0100 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | return 0; |
| 771 | } |
| 772 | |
| 773 | /** |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 774 | * vmw_view_bindings_add - Add an array of view bindings to a context |
| 775 | * binding state tracker. |
| 776 | * |
| 777 | * @sw_context: The execbuf state used for this command. |
| 778 | * @view_type: View type for the bindings. |
| 779 | * @binding_type: Binding type for the bindings. |
| 780 | * @shader_slot: The shader slot to user for the bindings. |
| 781 | * @view_ids: Array of view ids to be bound. |
| 782 | * @num_views: Number of view ids in @view_ids. |
| 783 | * @first_slot: The binding slot to be used for the first view id in @view_ids. |
| 784 | */ |
| 785 | static int vmw_view_bindings_add(struct vmw_sw_context *sw_context, |
| 786 | enum vmw_view_type view_type, |
| 787 | enum vmw_ctx_binding_type binding_type, |
| 788 | uint32 shader_slot, |
| 789 | uint32 view_ids[], u32 num_views, |
| 790 | u32 first_slot) |
| 791 | { |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 792 | struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 793 | u32 i; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 794 | |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 795 | if (!ctx_node) |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 796 | return -EINVAL; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 797 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 798 | for (i = 0; i < num_views; ++i) { |
| 799 | struct vmw_ctx_bindinfo_view binding; |
| 800 | struct vmw_resource *view = NULL; |
| 801 | |
| 802 | if (view_ids[i] != SVGA3D_INVALID_ID) { |
Thomas Hellstrom | 508108e | 2018-09-26 16:28:45 +0200 | [diff] [blame] | 803 | view = vmw_view_id_val_add(sw_context, view_type, |
| 804 | view_ids[i]); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 805 | if (IS_ERR(view)) { |
| 806 | DRM_ERROR("View not found.\n"); |
| 807 | return PTR_ERR(view); |
| 808 | } |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 809 | } |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 810 | binding.bi.ctx = ctx_node->ctx; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 811 | binding.bi.res = view; |
| 812 | binding.bi.bt = binding_type; |
| 813 | binding.shader_slot = shader_slot; |
| 814 | binding.slot = first_slot + i; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 815 | vmw_binding_add(ctx_node->staged, &binding.bi, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 816 | shader_slot, binding.slot); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 817 | } |
| 818 | |
| 819 | return 0; |
| 820 | } |
| 821 | |
| 822 | /** |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 823 | * vmw_cmd_cid_check - Check a command header for valid context information. |
| 824 | * |
| 825 | * @dev_priv: Pointer to a device private structure. |
| 826 | * @sw_context: Pointer to the software context. |
| 827 | * @header: A command header with an embedded user-space context handle. |
| 828 | * |
| 829 | * Convenience function: Call vmw_cmd_res_check with the user-space context |
| 830 | * handle embedded in @header. |
| 831 | */ |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 832 | static int vmw_cmd_cid_check(struct vmw_private *dev_priv, |
| 833 | struct vmw_sw_context *sw_context, |
| 834 | SVGA3dCmdHeader *header) |
| 835 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 836 | VMW_DECLARE_CMD_VAR(*cmd, uint32_t) = |
| 837 | container_of(header, typeof(*cmd), header); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 838 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 839 | return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 840 | VMW_RES_DIRTY_SET, user_context_converter, |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 841 | &cmd->body, NULL); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 842 | } |
| 843 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 844 | /** |
| 845 | * vmw_execbuf_info_from_res - Get the private validation metadata for a |
| 846 | * recently validated resource |
| 847 | * @sw_context: Pointer to the command submission context |
| 848 | * @res: The resource |
| 849 | * |
| 850 | * The resource pointed to by @res needs to be present in the command submission |
| 851 | * context's resource cache and hence the last resource of that type to be |
| 852 | * processed by the validation code. |
| 853 | * |
| 854 | * Return: a pointer to the private metadata of the resource, or NULL |
| 855 | * if it wasn't found |
| 856 | */ |
| 857 | static struct vmw_ctx_validation_info * |
| 858 | vmw_execbuf_info_from_res(struct vmw_sw_context *sw_context, |
| 859 | struct vmw_resource *res) |
| 860 | { |
| 861 | struct vmw_res_cache_entry *rcache = |
| 862 | &sw_context->res_cache[vmw_res_type(res)]; |
| 863 | |
| 864 | if (rcache->valid && rcache->res == res) |
| 865 | return rcache->private; |
| 866 | |
| 867 | WARN_ON_ONCE(true); |
| 868 | return NULL; |
| 869 | } |
| 870 | |
| 871 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 872 | static int vmw_cmd_set_render_target_check(struct vmw_private *dev_priv, |
| 873 | struct vmw_sw_context *sw_context, |
| 874 | SVGA3dCmdHeader *header) |
| 875 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 876 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdSetRenderTarget); |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 877 | struct vmw_resource *ctx; |
| 878 | struct vmw_resource *res; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 879 | int ret; |
| 880 | |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 881 | cmd = container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | b5c3b1a6 | 2013-10-08 02:27:17 -0700 | [diff] [blame] | 882 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 883 | if (cmd->body.type >= SVGA3D_RT_MAX) { |
| 884 | DRM_ERROR("Illegal render target type %u.\n", |
| 885 | (unsigned) cmd->body.type); |
| 886 | return -EINVAL; |
| 887 | } |
| 888 | |
Thomas Hellstrom | b5c3b1a6 | 2013-10-08 02:27:17 -0700 | [diff] [blame] | 889 | ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 890 | VMW_RES_DIRTY_SET, user_context_converter, |
| 891 | &cmd->body.cid, &ctx); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 892 | if (unlikely(ret != 0)) |
| 893 | return ret; |
| 894 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 895 | ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 896 | VMW_RES_DIRTY_SET, user_surface_converter, |
| 897 | &cmd->body.target.sid, &res); |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 898 | if (unlikely(ret)) |
Thomas Hellstrom | b5c3b1a6 | 2013-10-08 02:27:17 -0700 | [diff] [blame] | 899 | return ret; |
| 900 | |
| 901 | if (dev_priv->has_mob) { |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 902 | struct vmw_ctx_bindinfo_view binding; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 903 | struct vmw_ctx_validation_info *node; |
Thomas Hellstrom | b5c3b1a6 | 2013-10-08 02:27:17 -0700 | [diff] [blame] | 904 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 905 | node = vmw_execbuf_info_from_res(sw_context, ctx); |
| 906 | if (!node) |
| 907 | return -EINVAL; |
| 908 | |
| 909 | binding.bi.ctx = ctx; |
| 910 | binding.bi.res = res; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 911 | binding.bi.bt = vmw_ctx_binding_rt; |
| 912 | binding.slot = cmd->body.type; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 913 | vmw_binding_add(node->staged, &binding.bi, 0, binding.slot); |
Thomas Hellstrom | b5c3b1a6 | 2013-10-08 02:27:17 -0700 | [diff] [blame] | 914 | } |
| 915 | |
| 916 | return 0; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | static int vmw_cmd_surface_copy_check(struct vmw_private *dev_priv, |
| 920 | struct vmw_sw_context *sw_context, |
| 921 | SVGA3dCmdHeader *header) |
| 922 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 923 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdSurfaceCopy); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 924 | int ret; |
| 925 | |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 926 | cmd = container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | c9146cd | 2015-03-02 23:45:04 -0800 | [diff] [blame] | 927 | |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 928 | ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 929 | VMW_RES_DIRTY_NONE, user_surface_converter, |
| 930 | &cmd->body.src.sid, NULL); |
Thomas Hellstrom | 6bf6bf0 | 2015-06-26 02:22:40 -0700 | [diff] [blame] | 931 | if (ret) |
| 932 | return ret; |
Thomas Hellstrom | c9146cd | 2015-03-02 23:45:04 -0800 | [diff] [blame] | 933 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 934 | return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 935 | VMW_RES_DIRTY_SET, user_surface_converter, |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 936 | &cmd->body.dest.sid, NULL); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 937 | } |
| 938 | |
Neha Bhende | 0fca749e | 2015-08-10 10:51:07 -0700 | [diff] [blame] | 939 | static int vmw_cmd_buffer_copy_check(struct vmw_private *dev_priv, |
| 940 | struct vmw_sw_context *sw_context, |
| 941 | SVGA3dCmdHeader *header) |
| 942 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 943 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXBufferCopy); |
Neha Bhende | 0fca749e | 2015-08-10 10:51:07 -0700 | [diff] [blame] | 944 | int ret; |
| 945 | |
| 946 | cmd = container_of(header, typeof(*cmd), header); |
| 947 | ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 948 | VMW_RES_DIRTY_NONE, user_surface_converter, |
Neha Bhende | 0fca749e | 2015-08-10 10:51:07 -0700 | [diff] [blame] | 949 | &cmd->body.src, NULL); |
| 950 | if (ret != 0) |
| 951 | return ret; |
| 952 | |
| 953 | return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 954 | VMW_RES_DIRTY_SET, user_surface_converter, |
Neha Bhende | 0fca749e | 2015-08-10 10:51:07 -0700 | [diff] [blame] | 955 | &cmd->body.dest, NULL); |
| 956 | } |
| 957 | |
| 958 | static int vmw_cmd_pred_copy_check(struct vmw_private *dev_priv, |
| 959 | struct vmw_sw_context *sw_context, |
| 960 | SVGA3dCmdHeader *header) |
| 961 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 962 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXPredCopyRegion); |
Neha Bhende | 0fca749e | 2015-08-10 10:51:07 -0700 | [diff] [blame] | 963 | int ret; |
| 964 | |
| 965 | cmd = container_of(header, typeof(*cmd), header); |
| 966 | ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 967 | VMW_RES_DIRTY_NONE, user_surface_converter, |
Neha Bhende | 0fca749e | 2015-08-10 10:51:07 -0700 | [diff] [blame] | 968 | &cmd->body.srcSid, NULL); |
| 969 | if (ret != 0) |
| 970 | return ret; |
| 971 | |
| 972 | return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 973 | VMW_RES_DIRTY_SET, user_surface_converter, |
Neha Bhende | 0fca749e | 2015-08-10 10:51:07 -0700 | [diff] [blame] | 974 | &cmd->body.dstSid, NULL); |
| 975 | } |
| 976 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 977 | static int vmw_cmd_stretch_blt_check(struct vmw_private *dev_priv, |
| 978 | struct vmw_sw_context *sw_context, |
| 979 | SVGA3dCmdHeader *header) |
| 980 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 981 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdSurfaceStretchBlt); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 982 | int ret; |
| 983 | |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 984 | cmd = container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 985 | ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 986 | VMW_RES_DIRTY_NONE, user_surface_converter, |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 987 | &cmd->body.src.sid, NULL); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 988 | if (unlikely(ret != 0)) |
| 989 | return ret; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 990 | return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 991 | VMW_RES_DIRTY_SET, user_surface_converter, |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 992 | &cmd->body.dest.sid, NULL); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 993 | } |
| 994 | |
| 995 | static int vmw_cmd_blt_surf_screen_check(struct vmw_private *dev_priv, |
| 996 | struct vmw_sw_context *sw_context, |
| 997 | SVGA3dCmdHeader *header) |
| 998 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 999 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdBlitSurfaceToScreen) = |
| 1000 | container_of(header, typeof(*cmd), header); |
Jakob Bornecrantz | 0cff60c | 2011-10-04 20:13:27 +0200 | [diff] [blame] | 1001 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1002 | return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 1003 | VMW_RES_DIRTY_NONE, user_surface_converter, |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1004 | &cmd->body.srcImage.sid, NULL); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | static int vmw_cmd_present_check(struct vmw_private *dev_priv, |
| 1008 | struct vmw_sw_context *sw_context, |
| 1009 | SVGA3dCmdHeader *header) |
| 1010 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1011 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdPresent) = |
| 1012 | container_of(header, typeof(*cmd), header); |
Jakob Bornecrantz | 0cff60c | 2011-10-04 20:13:27 +0200 | [diff] [blame] | 1013 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1014 | return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 1015 | VMW_RES_DIRTY_NONE, user_surface_converter, |
| 1016 | &cmd->body.sid, NULL); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1019 | /** |
| 1020 | * vmw_query_bo_switch_prepare - Prepare to switch pinned buffer for queries. |
| 1021 | * |
| 1022 | * @dev_priv: The device private structure. |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1023 | * @new_query_bo: The new buffer holding query results. |
| 1024 | * @sw_context: The software context used for this command submission. |
| 1025 | * |
| 1026 | * This function checks whether @new_query_bo is suitable for holding |
| 1027 | * query results, and if another buffer currently is pinned for query |
| 1028 | * results. If so, the function prepares the state of @sw_context for |
| 1029 | * switching pinned buffers after successful submission of the current |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1030 | * command batch. |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1031 | */ |
| 1032 | static int vmw_query_bo_switch_prepare(struct vmw_private *dev_priv, |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1033 | struct vmw_buffer_object *new_query_bo, |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1034 | struct vmw_sw_context *sw_context) |
| 1035 | { |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1036 | struct vmw_res_cache_entry *ctx_entry = |
| 1037 | &sw_context->res_cache[vmw_res_context]; |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1038 | int ret; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1039 | |
| 1040 | BUG_ON(!ctx_entry->valid); |
| 1041 | sw_context->last_query_ctx = ctx_entry->res; |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1042 | |
| 1043 | if (unlikely(new_query_bo != sw_context->cur_query_bo)) { |
| 1044 | |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 1045 | if (unlikely(new_query_bo->base.num_pages > 4)) { |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1046 | DRM_ERROR("Query buffer too large.\n"); |
| 1047 | return -EINVAL; |
| 1048 | } |
| 1049 | |
| 1050 | if (unlikely(sw_context->cur_query_bo != NULL)) { |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1051 | sw_context->needs_post_query_barrier = true; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 1052 | ret = vmw_validation_add_bo(sw_context->ctx, |
| 1053 | sw_context->cur_query_bo, |
| 1054 | dev_priv->has_mob, false); |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1055 | if (unlikely(ret != 0)) |
| 1056 | return ret; |
| 1057 | } |
| 1058 | sw_context->cur_query_bo = new_query_bo; |
| 1059 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 1060 | ret = vmw_validation_add_bo(sw_context->ctx, |
| 1061 | dev_priv->dummy_query_bo, |
| 1062 | dev_priv->has_mob, false); |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1063 | if (unlikely(ret != 0)) |
| 1064 | return ret; |
| 1065 | |
| 1066 | } |
| 1067 | |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1068 | return 0; |
| 1069 | } |
| 1070 | |
| 1071 | |
| 1072 | /** |
| 1073 | * vmw_query_bo_switch_commit - Finalize switching pinned query buffer |
| 1074 | * |
| 1075 | * @dev_priv: The device private structure. |
| 1076 | * @sw_context: The software context used for this command submission batch. |
| 1077 | * |
| 1078 | * This function will check if we're switching query buffers, and will then, |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1079 | * issue a dummy occlusion query wait used as a query barrier. When the fence |
| 1080 | * object following that query wait has signaled, we are sure that all |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1081 | * preceding queries have finished, and the old query buffer can be unpinned. |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1082 | * However, since both the new query buffer and the old one are fenced with |
| 1083 | * that fence, we can do an asynchronus unpin now, and be sure that the |
| 1084 | * old query buffer won't be moved until the fence has signaled. |
| 1085 | * |
| 1086 | * As mentioned above, both the new - and old query buffers need to be fenced |
| 1087 | * using a sequence emitted *after* calling this function. |
| 1088 | */ |
| 1089 | static void vmw_query_bo_switch_commit(struct vmw_private *dev_priv, |
| 1090 | struct vmw_sw_context *sw_context) |
| 1091 | { |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1092 | /* |
| 1093 | * The validate list should still hold references to all |
| 1094 | * contexts here. |
| 1095 | */ |
| 1096 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1097 | if (sw_context->needs_post_query_barrier) { |
| 1098 | struct vmw_res_cache_entry *ctx_entry = |
| 1099 | &sw_context->res_cache[vmw_res_context]; |
| 1100 | struct vmw_resource *ctx; |
| 1101 | int ret; |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1102 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1103 | BUG_ON(!ctx_entry->valid); |
| 1104 | ctx = ctx_entry->res; |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1105 | |
| 1106 | ret = vmw_fifo_emit_dummy_query(dev_priv, ctx->id); |
| 1107 | |
| 1108 | if (unlikely(ret != 0)) |
| 1109 | DRM_ERROR("Out of fifo space for dummy query.\n"); |
| 1110 | } |
| 1111 | |
| 1112 | if (dev_priv->pinned_bo != sw_context->cur_query_bo) { |
| 1113 | if (dev_priv->pinned_bo) { |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 1114 | vmw_bo_pin_reserved(dev_priv->pinned_bo, false); |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1115 | vmw_bo_unreference(&dev_priv->pinned_bo); |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1116 | } |
| 1117 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1118 | if (!sw_context->needs_post_query_barrier) { |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 1119 | vmw_bo_pin_reserved(sw_context->cur_query_bo, true); |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1120 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1121 | /* |
| 1122 | * We pin also the dummy_query_bo buffer so that we |
| 1123 | * don't need to validate it when emitting |
| 1124 | * dummy queries in context destroy paths. |
| 1125 | */ |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1126 | |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 1127 | if (!dev_priv->dummy_query_bo_pinned) { |
| 1128 | vmw_bo_pin_reserved(dev_priv->dummy_query_bo, |
| 1129 | true); |
| 1130 | dev_priv->dummy_query_bo_pinned = true; |
| 1131 | } |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1132 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1133 | BUG_ON(sw_context->last_query_ctx == NULL); |
| 1134 | dev_priv->query_cid = sw_context->last_query_ctx->id; |
| 1135 | dev_priv->query_cid_valid = true; |
| 1136 | dev_priv->pinned_bo = |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1137 | vmw_bo_reference(sw_context->cur_query_bo); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1138 | } |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | /** |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1143 | * vmw_translate_mob_pointer - Prepare to translate a user-space buffer |
| 1144 | * handle to a MOB id. |
| 1145 | * |
| 1146 | * @dev_priv: Pointer to a device private structure. |
| 1147 | * @sw_context: The software context used for this command batch validation. |
| 1148 | * @id: Pointer to the user-space handle to be translated. |
| 1149 | * @vmw_bo_p: Points to a location that, on successful return will carry |
Thomas Hellstrom | b139d43 | 2018-09-26 16:27:54 +0200 | [diff] [blame] | 1150 | * a non-reference-counted pointer to the buffer object identified by the |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1151 | * user-space handle in @id. |
| 1152 | * |
| 1153 | * This function saves information needed to translate a user-space buffer |
| 1154 | * handle to a MOB id. The translation does not take place immediately, but |
| 1155 | * during a call to vmw_apply_relocations(). This function builds a relocation |
| 1156 | * list and a list of buffers to validate. The former needs to be freed using |
| 1157 | * either vmw_apply_relocations() or vmw_free_relocations(). The latter |
| 1158 | * needs to be freed using vmw_clear_validations. |
| 1159 | */ |
| 1160 | static int vmw_translate_mob_ptr(struct vmw_private *dev_priv, |
| 1161 | struct vmw_sw_context *sw_context, |
| 1162 | SVGAMobId *id, |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1163 | struct vmw_buffer_object **vmw_bo_p) |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1164 | { |
Thomas Hellstrom | b139d43 | 2018-09-26 16:27:54 +0200 | [diff] [blame] | 1165 | struct vmw_buffer_object *vmw_bo; |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1166 | uint32_t handle = *id; |
| 1167 | struct vmw_relocation *reloc; |
| 1168 | int ret; |
| 1169 | |
Thomas Hellstrom | b139d43 | 2018-09-26 16:27:54 +0200 | [diff] [blame] | 1170 | vmw_validation_preload_bo(sw_context->ctx); |
| 1171 | vmw_bo = vmw_user_bo_noref_lookup(sw_context->fp->tfile, handle); |
| 1172 | if (IS_ERR(vmw_bo)) { |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1173 | DRM_ERROR("Could not find or use MOB buffer.\n"); |
Thomas Hellstrom | b139d43 | 2018-09-26 16:27:54 +0200 | [diff] [blame] | 1174 | return PTR_ERR(vmw_bo); |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1175 | } |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1176 | |
Thomas Hellstrom | b139d43 | 2018-09-26 16:27:54 +0200 | [diff] [blame] | 1177 | ret = vmw_validation_add_bo(sw_context->ctx, vmw_bo, true, false); |
| 1178 | vmw_user_bo_noref_release(); |
| 1179 | if (unlikely(ret != 0)) |
| 1180 | return ret; |
| 1181 | |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 1182 | reloc = vmw_validation_mem_alloc(sw_context->ctx, sizeof(*reloc)); |
| 1183 | if (!reloc) |
Thomas Hellstrom | b139d43 | 2018-09-26 16:27:54 +0200 | [diff] [blame] | 1184 | return -ENOMEM; |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1185 | |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1186 | reloc->mob_loc = id; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 1187 | reloc->vbo = vmw_bo; |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1188 | |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1189 | *vmw_bo_p = vmw_bo; |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 1190 | list_add_tail(&reloc->head, &sw_context->bo_relocations); |
| 1191 | |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1192 | return 0; |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | /** |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1196 | * vmw_translate_guest_pointer - Prepare to translate a user-space buffer |
| 1197 | * handle to a valid SVGAGuestPtr |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1198 | * |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1199 | * @dev_priv: Pointer to a device private structure. |
| 1200 | * @sw_context: The software context used for this command batch validation. |
| 1201 | * @ptr: Pointer to the user-space handle to be translated. |
| 1202 | * @vmw_bo_p: Points to a location that, on successful return will carry |
Thomas Hellstrom | b139d43 | 2018-09-26 16:27:54 +0200 | [diff] [blame] | 1203 | * a non-reference-counted pointer to the DMA buffer identified by the |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1204 | * user-space handle in @id. |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1205 | * |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1206 | * This function saves information needed to translate a user-space buffer |
| 1207 | * handle to a valid SVGAGuestPtr. The translation does not take place |
| 1208 | * immediately, but during a call to vmw_apply_relocations(). |
| 1209 | * This function builds a relocation list and a list of buffers to validate. |
| 1210 | * The former needs to be freed using either vmw_apply_relocations() or |
| 1211 | * vmw_free_relocations(). The latter needs to be freed using |
| 1212 | * vmw_clear_validations. |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1213 | */ |
Thomas Hellstrom | 4e4ddd4 | 2010-02-21 14:54:55 +0000 | [diff] [blame] | 1214 | static int vmw_translate_guest_ptr(struct vmw_private *dev_priv, |
| 1215 | struct vmw_sw_context *sw_context, |
| 1216 | SVGAGuestPtr *ptr, |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1217 | struct vmw_buffer_object **vmw_bo_p) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1218 | { |
Thomas Hellstrom | b139d43 | 2018-09-26 16:27:54 +0200 | [diff] [blame] | 1219 | struct vmw_buffer_object *vmw_bo; |
Thomas Hellstrom | 4e4ddd4 | 2010-02-21 14:54:55 +0000 | [diff] [blame] | 1220 | uint32_t handle = ptr->gmrId; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1221 | struct vmw_relocation *reloc; |
Thomas Hellstrom | 4e4ddd4 | 2010-02-21 14:54:55 +0000 | [diff] [blame] | 1222 | int ret; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1223 | |
Thomas Hellstrom | b139d43 | 2018-09-26 16:27:54 +0200 | [diff] [blame] | 1224 | vmw_validation_preload_bo(sw_context->ctx); |
| 1225 | vmw_bo = vmw_user_bo_noref_lookup(sw_context->fp->tfile, handle); |
| 1226 | if (IS_ERR(vmw_bo)) { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1227 | DRM_ERROR("Could not find or use GMR region.\n"); |
Thomas Hellstrom | b139d43 | 2018-09-26 16:27:54 +0200 | [diff] [blame] | 1228 | return PTR_ERR(vmw_bo); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1229 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1230 | |
Thomas Hellstrom | b139d43 | 2018-09-26 16:27:54 +0200 | [diff] [blame] | 1231 | ret = vmw_validation_add_bo(sw_context->ctx, vmw_bo, false, false); |
| 1232 | vmw_user_bo_noref_release(); |
| 1233 | if (unlikely(ret != 0)) |
| 1234 | return ret; |
| 1235 | |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 1236 | reloc = vmw_validation_mem_alloc(sw_context->ctx, sizeof(*reloc)); |
| 1237 | if (!reloc) |
Thomas Hellstrom | b139d43 | 2018-09-26 16:27:54 +0200 | [diff] [blame] | 1238 | return -ENOMEM; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1239 | |
Thomas Hellstrom | 4e4ddd4 | 2010-02-21 14:54:55 +0000 | [diff] [blame] | 1240 | reloc->location = ptr; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 1241 | reloc->vbo = vmw_bo; |
Thomas Hellstrom | 4e4ddd4 | 2010-02-21 14:54:55 +0000 | [diff] [blame] | 1242 | *vmw_bo_p = vmw_bo; |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 1243 | list_add_tail(&reloc->head, &sw_context->bo_relocations); |
| 1244 | |
Thomas Hellstrom | 4e4ddd4 | 2010-02-21 14:54:55 +0000 | [diff] [blame] | 1245 | return 0; |
Thomas Hellstrom | 4e4ddd4 | 2010-02-21 14:54:55 +0000 | [diff] [blame] | 1246 | } |
| 1247 | |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 1248 | |
| 1249 | |
| 1250 | /** |
| 1251 | * vmw_cmd_dx_define_query - validate a SVGA_3D_CMD_DX_DEFINE_QUERY command. |
| 1252 | * |
| 1253 | * @dev_priv: Pointer to a device private struct. |
| 1254 | * @sw_context: The software context used for this command submission. |
| 1255 | * @header: Pointer to the command header in the command stream. |
| 1256 | * |
| 1257 | * This function adds the new query into the query COTABLE |
| 1258 | */ |
| 1259 | static int vmw_cmd_dx_define_query(struct vmw_private *dev_priv, |
| 1260 | struct vmw_sw_context *sw_context, |
| 1261 | SVGA3dCmdHeader *header) |
| 1262 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1263 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXDefineQuery); |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 1264 | struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context); |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 1265 | struct vmw_resource *cotable_res; |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1266 | int ret; |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 1267 | |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 1268 | if (!ctx_node) |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 1269 | return -EINVAL; |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 1270 | |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1271 | cmd = container_of(header, typeof(*cmd), header); |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 1272 | |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1273 | if (cmd->body.type < SVGA3D_QUERYTYPE_MIN || |
| 1274 | cmd->body.type >= SVGA3D_QUERYTYPE_MAX) |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 1275 | return -EINVAL; |
| 1276 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 1277 | cotable_res = vmw_context_cotable(ctx_node->ctx, SVGA_COTABLE_DXQUERY); |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1278 | ret = vmw_cotable_notify(cotable_res, cmd->body.queryId); |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 1279 | |
| 1280 | return ret; |
| 1281 | } |
| 1282 | |
| 1283 | |
| 1284 | |
| 1285 | /** |
| 1286 | * vmw_cmd_dx_bind_query - validate a SVGA_3D_CMD_DX_BIND_QUERY command. |
| 1287 | * |
| 1288 | * @dev_priv: Pointer to a device private struct. |
| 1289 | * @sw_context: The software context used for this command submission. |
| 1290 | * @header: Pointer to the command header in the command stream. |
| 1291 | * |
| 1292 | * The query bind operation will eventually associate the query ID |
| 1293 | * with its backing MOB. In this function, we take the user mode |
| 1294 | * MOB ID and use vmw_translate_mob_ptr() to translate it to its |
| 1295 | * kernel mode equivalent. |
| 1296 | */ |
| 1297 | static int vmw_cmd_dx_bind_query(struct vmw_private *dev_priv, |
| 1298 | struct vmw_sw_context *sw_context, |
| 1299 | SVGA3dCmdHeader *header) |
| 1300 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1301 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXBindQuery); |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1302 | struct vmw_buffer_object *vmw_bo; |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1303 | int ret; |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 1304 | |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1305 | cmd = container_of(header, typeof(*cmd), header); |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 1306 | |
| 1307 | /* |
| 1308 | * Look up the buffer pointed to by q.mobid, put it on the relocation |
| 1309 | * list so its kernel mode MOB ID can be filled in later |
| 1310 | */ |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1311 | ret = vmw_translate_mob_ptr(dev_priv, sw_context, &cmd->body.mobid, |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 1312 | &vmw_bo); |
| 1313 | |
| 1314 | if (ret != 0) |
| 1315 | return ret; |
| 1316 | |
| 1317 | sw_context->dx_query_mob = vmw_bo; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 1318 | sw_context->dx_query_ctx = sw_context->dx_ctx_node->ctx; |
Thomas Hellstrom | b139d43 | 2018-09-26 16:27:54 +0200 | [diff] [blame] | 1319 | return 0; |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 1320 | } |
| 1321 | |
| 1322 | |
| 1323 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1324 | /** |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1325 | * vmw_cmd_begin_gb_query - validate a SVGA_3D_CMD_BEGIN_GB_QUERY command. |
| 1326 | * |
| 1327 | * @dev_priv: Pointer to a device private struct. |
| 1328 | * @sw_context: The software context used for this command submission. |
| 1329 | * @header: Pointer to the command header in the command stream. |
| 1330 | */ |
| 1331 | static int vmw_cmd_begin_gb_query(struct vmw_private *dev_priv, |
| 1332 | struct vmw_sw_context *sw_context, |
| 1333 | SVGA3dCmdHeader *header) |
| 1334 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1335 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdBeginGBQuery) = |
| 1336 | container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1337 | |
| 1338 | return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 1339 | VMW_RES_DIRTY_SET, user_context_converter, |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1340 | &cmd->body.cid, NULL); |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1341 | } |
| 1342 | |
| 1343 | /** |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1344 | * vmw_cmd_begin_query - validate a SVGA_3D_CMD_BEGIN_QUERY command. |
| 1345 | * |
| 1346 | * @dev_priv: Pointer to a device private struct. |
| 1347 | * @sw_context: The software context used for this command submission. |
| 1348 | * @header: Pointer to the command header in the command stream. |
| 1349 | */ |
| 1350 | static int vmw_cmd_begin_query(struct vmw_private *dev_priv, |
| 1351 | struct vmw_sw_context *sw_context, |
| 1352 | SVGA3dCmdHeader *header) |
| 1353 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1354 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdBeginQuery) = |
| 1355 | container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1356 | |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1357 | if (unlikely(dev_priv->has_mob)) { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1358 | VMW_DECLARE_CMD_VAR(gb_cmd, SVGA3dCmdBeginGBQuery); |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1359 | |
| 1360 | BUG_ON(sizeof(gb_cmd) != sizeof(*cmd)); |
| 1361 | |
| 1362 | gb_cmd.header.id = SVGA_3D_CMD_BEGIN_GB_QUERY; |
| 1363 | gb_cmd.header.size = cmd->header.size; |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1364 | gb_cmd.body.cid = cmd->body.cid; |
| 1365 | gb_cmd.body.type = cmd->body.type; |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1366 | |
| 1367 | memcpy(cmd, &gb_cmd, sizeof(*cmd)); |
| 1368 | return vmw_cmd_begin_gb_query(dev_priv, sw_context, header); |
| 1369 | } |
| 1370 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1371 | return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 1372 | VMW_RES_DIRTY_SET, user_context_converter, |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1373 | &cmd->body.cid, NULL); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1374 | } |
| 1375 | |
| 1376 | /** |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1377 | * vmw_cmd_end_gb_query - validate a SVGA_3D_CMD_END_GB_QUERY command. |
| 1378 | * |
| 1379 | * @dev_priv: Pointer to a device private struct. |
| 1380 | * @sw_context: The software context used for this command submission. |
| 1381 | * @header: Pointer to the command header in the command stream. |
| 1382 | */ |
| 1383 | static int vmw_cmd_end_gb_query(struct vmw_private *dev_priv, |
| 1384 | struct vmw_sw_context *sw_context, |
| 1385 | SVGA3dCmdHeader *header) |
| 1386 | { |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1387 | struct vmw_buffer_object *vmw_bo; |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1388 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdEndGBQuery); |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1389 | int ret; |
| 1390 | |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1391 | cmd = container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1392 | ret = vmw_cmd_cid_check(dev_priv, sw_context, header); |
| 1393 | if (unlikely(ret != 0)) |
| 1394 | return ret; |
| 1395 | |
| 1396 | ret = vmw_translate_mob_ptr(dev_priv, sw_context, |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1397 | &cmd->body.mobid, |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1398 | &vmw_bo); |
| 1399 | if (unlikely(ret != 0)) |
| 1400 | return ret; |
| 1401 | |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 1402 | ret = vmw_query_bo_switch_prepare(dev_priv, vmw_bo, sw_context); |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1403 | |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1404 | return ret; |
| 1405 | } |
| 1406 | |
| 1407 | /** |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1408 | * vmw_cmd_end_query - validate a SVGA_3D_CMD_END_QUERY command. |
| 1409 | * |
| 1410 | * @dev_priv: Pointer to a device private struct. |
| 1411 | * @sw_context: The software context used for this command submission. |
| 1412 | * @header: Pointer to the command header in the command stream. |
| 1413 | */ |
Thomas Hellstrom | 4e4ddd4 | 2010-02-21 14:54:55 +0000 | [diff] [blame] | 1414 | static int vmw_cmd_end_query(struct vmw_private *dev_priv, |
| 1415 | struct vmw_sw_context *sw_context, |
| 1416 | SVGA3dCmdHeader *header) |
| 1417 | { |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1418 | struct vmw_buffer_object *vmw_bo; |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1419 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdEndQuery); |
Thomas Hellstrom | 4e4ddd4 | 2010-02-21 14:54:55 +0000 | [diff] [blame] | 1420 | int ret; |
| 1421 | |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1422 | cmd = container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1423 | if (dev_priv->has_mob) { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1424 | VMW_DECLARE_CMD_VAR(gb_cmd, SVGA3dCmdEndGBQuery); |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1425 | |
| 1426 | BUG_ON(sizeof(gb_cmd) != sizeof(*cmd)); |
| 1427 | |
| 1428 | gb_cmd.header.id = SVGA_3D_CMD_END_GB_QUERY; |
| 1429 | gb_cmd.header.size = cmd->header.size; |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1430 | gb_cmd.body.cid = cmd->body.cid; |
| 1431 | gb_cmd.body.type = cmd->body.type; |
| 1432 | gb_cmd.body.mobid = cmd->body.guestResult.gmrId; |
| 1433 | gb_cmd.body.offset = cmd->body.guestResult.offset; |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1434 | |
| 1435 | memcpy(cmd, &gb_cmd, sizeof(*cmd)); |
| 1436 | return vmw_cmd_end_gb_query(dev_priv, sw_context, header); |
| 1437 | } |
| 1438 | |
Thomas Hellstrom | 4e4ddd4 | 2010-02-21 14:54:55 +0000 | [diff] [blame] | 1439 | ret = vmw_cmd_cid_check(dev_priv, sw_context, header); |
| 1440 | if (unlikely(ret != 0)) |
| 1441 | return ret; |
| 1442 | |
| 1443 | ret = vmw_translate_guest_ptr(dev_priv, sw_context, |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1444 | &cmd->body.guestResult, |
Thomas Hellstrom | 4e4ddd4 | 2010-02-21 14:54:55 +0000 | [diff] [blame] | 1445 | &vmw_bo); |
| 1446 | if (unlikely(ret != 0)) |
| 1447 | return ret; |
| 1448 | |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 1449 | ret = vmw_query_bo_switch_prepare(dev_priv, vmw_bo, sw_context); |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1450 | |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 1451 | return ret; |
Thomas Hellstrom | 4e4ddd4 | 2010-02-21 14:54:55 +0000 | [diff] [blame] | 1452 | } |
| 1453 | |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1454 | /** |
| 1455 | * vmw_cmd_wait_gb_query - validate a SVGA_3D_CMD_WAIT_GB_QUERY command. |
| 1456 | * |
| 1457 | * @dev_priv: Pointer to a device private struct. |
| 1458 | * @sw_context: The software context used for this command submission. |
| 1459 | * @header: Pointer to the command header in the command stream. |
| 1460 | */ |
| 1461 | static int vmw_cmd_wait_gb_query(struct vmw_private *dev_priv, |
| 1462 | struct vmw_sw_context *sw_context, |
| 1463 | SVGA3dCmdHeader *header) |
| 1464 | { |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1465 | struct vmw_buffer_object *vmw_bo; |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1466 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdWaitForGBQuery); |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1467 | int ret; |
| 1468 | |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1469 | cmd = container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1470 | ret = vmw_cmd_cid_check(dev_priv, sw_context, header); |
| 1471 | if (unlikely(ret != 0)) |
| 1472 | return ret; |
| 1473 | |
| 1474 | ret = vmw_translate_mob_ptr(dev_priv, sw_context, |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1475 | &cmd->body.mobid, |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1476 | &vmw_bo); |
| 1477 | if (unlikely(ret != 0)) |
| 1478 | return ret; |
| 1479 | |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1480 | return 0; |
| 1481 | } |
| 1482 | |
| 1483 | /** |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1484 | * vmw_cmd_wait_query - validate a SVGA_3D_CMD_WAIT_QUERY command. |
| 1485 | * |
| 1486 | * @dev_priv: Pointer to a device private struct. |
| 1487 | * @sw_context: The software context used for this command submission. |
| 1488 | * @header: Pointer to the command header in the command stream. |
| 1489 | */ |
Thomas Hellstrom | 4e4ddd4 | 2010-02-21 14:54:55 +0000 | [diff] [blame] | 1490 | static int vmw_cmd_wait_query(struct vmw_private *dev_priv, |
| 1491 | struct vmw_sw_context *sw_context, |
| 1492 | SVGA3dCmdHeader *header) |
| 1493 | { |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1494 | struct vmw_buffer_object *vmw_bo; |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1495 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdWaitForQuery); |
Thomas Hellstrom | 4e4ddd4 | 2010-02-21 14:54:55 +0000 | [diff] [blame] | 1496 | int ret; |
| 1497 | |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1498 | cmd = container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1499 | if (dev_priv->has_mob) { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1500 | VMW_DECLARE_CMD_VAR(gb_cmd, SVGA3dCmdWaitForGBQuery); |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1501 | |
| 1502 | BUG_ON(sizeof(gb_cmd) != sizeof(*cmd)); |
| 1503 | |
| 1504 | gb_cmd.header.id = SVGA_3D_CMD_WAIT_FOR_GB_QUERY; |
| 1505 | gb_cmd.header.size = cmd->header.size; |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1506 | gb_cmd.body.cid = cmd->body.cid; |
| 1507 | gb_cmd.body.type = cmd->body.type; |
| 1508 | gb_cmd.body.mobid = cmd->body.guestResult.gmrId; |
| 1509 | gb_cmd.body.offset = cmd->body.guestResult.offset; |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 1510 | |
| 1511 | memcpy(cmd, &gb_cmd, sizeof(*cmd)); |
| 1512 | return vmw_cmd_wait_gb_query(dev_priv, sw_context, header); |
| 1513 | } |
| 1514 | |
Thomas Hellstrom | 4e4ddd4 | 2010-02-21 14:54:55 +0000 | [diff] [blame] | 1515 | ret = vmw_cmd_cid_check(dev_priv, sw_context, header); |
| 1516 | if (unlikely(ret != 0)) |
| 1517 | return ret; |
| 1518 | |
| 1519 | ret = vmw_translate_guest_ptr(dev_priv, sw_context, |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1520 | &cmd->body.guestResult, |
Thomas Hellstrom | 4e4ddd4 | 2010-02-21 14:54:55 +0000 | [diff] [blame] | 1521 | &vmw_bo); |
| 1522 | if (unlikely(ret != 0)) |
| 1523 | return ret; |
| 1524 | |
Thomas Hellstrom | 4e4ddd4 | 2010-02-21 14:54:55 +0000 | [diff] [blame] | 1525 | return 0; |
| 1526 | } |
| 1527 | |
Thomas Hellstrom | 4e4ddd4 | 2010-02-21 14:54:55 +0000 | [diff] [blame] | 1528 | static int vmw_cmd_dma(struct vmw_private *dev_priv, |
| 1529 | struct vmw_sw_context *sw_context, |
| 1530 | SVGA3dCmdHeader *header) |
| 1531 | { |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1532 | struct vmw_buffer_object *vmw_bo = NULL; |
Thomas Hellstrom | 4e4ddd4 | 2010-02-21 14:54:55 +0000 | [diff] [blame] | 1533 | struct vmw_surface *srf = NULL; |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1534 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdSurfaceDMA); |
Thomas Hellstrom | 4e4ddd4 | 2010-02-21 14:54:55 +0000 | [diff] [blame] | 1535 | int ret; |
Thomas Hellstrom | cbd75e9 | 2014-04-15 18:25:48 +0200 | [diff] [blame] | 1536 | SVGA3dCmdSurfaceDMASuffix *suffix; |
| 1537 | uint32_t bo_size; |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 1538 | bool dirty; |
Thomas Hellstrom | 4e4ddd4 | 2010-02-21 14:54:55 +0000 | [diff] [blame] | 1539 | |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1540 | cmd = container_of(header, typeof(*cmd), header); |
| 1541 | suffix = (SVGA3dCmdSurfaceDMASuffix *)((unsigned long) &cmd->body + |
Thomas Hellstrom | cbd75e9 | 2014-04-15 18:25:48 +0200 | [diff] [blame] | 1542 | header->size - sizeof(*suffix)); |
| 1543 | |
| 1544 | /* Make sure device and verifier stays in sync. */ |
| 1545 | if (unlikely(suffix->suffixSize != sizeof(*suffix))) { |
| 1546 | DRM_ERROR("Invalid DMA suffix size.\n"); |
| 1547 | return -EINVAL; |
| 1548 | } |
| 1549 | |
Thomas Hellstrom | 4e4ddd4 | 2010-02-21 14:54:55 +0000 | [diff] [blame] | 1550 | ret = vmw_translate_guest_ptr(dev_priv, sw_context, |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1551 | &cmd->body.guest.ptr, |
Thomas Hellstrom | 4e4ddd4 | 2010-02-21 14:54:55 +0000 | [diff] [blame] | 1552 | &vmw_bo); |
| 1553 | if (unlikely(ret != 0)) |
| 1554 | return ret; |
| 1555 | |
Thomas Hellstrom | cbd75e9 | 2014-04-15 18:25:48 +0200 | [diff] [blame] | 1556 | /* Make sure DMA doesn't cross BO boundaries. */ |
| 1557 | bo_size = vmw_bo->base.num_pages * PAGE_SIZE; |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1558 | if (unlikely(cmd->body.guest.ptr.offset > bo_size)) { |
Thomas Hellstrom | cbd75e9 | 2014-04-15 18:25:48 +0200 | [diff] [blame] | 1559 | DRM_ERROR("Invalid DMA offset.\n"); |
| 1560 | return -EINVAL; |
| 1561 | } |
| 1562 | |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1563 | bo_size -= cmd->body.guest.ptr.offset; |
Thomas Hellstrom | cbd75e9 | 2014-04-15 18:25:48 +0200 | [diff] [blame] | 1564 | if (unlikely(suffix->maximumOffset > bo_size)) |
| 1565 | suffix->maximumOffset = bo_size; |
| 1566 | |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1567 | dirty = (cmd->body.transfer == SVGA3D_WRITE_HOST_VRAM) ? |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 1568 | VMW_RES_DIRTY_SET : 0; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1569 | ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 1570 | dirty, user_surface_converter, |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1571 | &cmd->body.host.sid, NULL); |
Thomas Hellstrom | 5bb39e8 | 2011-10-04 20:13:33 +0200 | [diff] [blame] | 1572 | if (unlikely(ret != 0)) { |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1573 | if (unlikely(ret != -ERESTARTSYS)) |
| 1574 | DRM_ERROR("could not find surface for DMA.\n"); |
Thomas Hellstrom | b139d43 | 2018-09-26 16:27:54 +0200 | [diff] [blame] | 1575 | return ret; |
Thomas Hellstrom | 5bb39e8 | 2011-10-04 20:13:33 +0200 | [diff] [blame] | 1576 | } |
| 1577 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1578 | srf = vmw_res_to_srf(sw_context->res_cache[vmw_res_surface].res); |
Thomas Hellstrom | be38ab6 | 2011-08-31 07:42:54 +0000 | [diff] [blame] | 1579 | |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 1580 | vmw_kms_cursor_snoop(srf, sw_context->fp->tfile, &vmw_bo->base, |
| 1581 | header); |
Thomas Hellstrom | be38ab6 | 2011-08-31 07:42:54 +0000 | [diff] [blame] | 1582 | |
Thomas Hellstrom | b139d43 | 2018-09-26 16:27:54 +0200 | [diff] [blame] | 1583 | return 0; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 1584 | } |
| 1585 | |
Thomas Hellstrom | 7a73ba7 | 2009-12-22 16:53:41 +0100 | [diff] [blame] | 1586 | static int vmw_cmd_draw(struct vmw_private *dev_priv, |
| 1587 | struct vmw_sw_context *sw_context, |
| 1588 | SVGA3dCmdHeader *header) |
| 1589 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1590 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDrawPrimitives); |
Thomas Hellstrom | 7a73ba7 | 2009-12-22 16:53:41 +0100 | [diff] [blame] | 1591 | SVGA3dVertexDecl *decl = (SVGA3dVertexDecl *)( |
| 1592 | (unsigned long)header + sizeof(*cmd)); |
| 1593 | SVGA3dPrimitiveRange *range; |
| 1594 | uint32_t i; |
| 1595 | uint32_t maxnum; |
| 1596 | int ret; |
| 1597 | |
| 1598 | ret = vmw_cmd_cid_check(dev_priv, sw_context, header); |
| 1599 | if (unlikely(ret != 0)) |
| 1600 | return ret; |
| 1601 | |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1602 | cmd = container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | 7a73ba7 | 2009-12-22 16:53:41 +0100 | [diff] [blame] | 1603 | maxnum = (header->size - sizeof(cmd->body)) / sizeof(*decl); |
| 1604 | |
| 1605 | if (unlikely(cmd->body.numVertexDecls > maxnum)) { |
| 1606 | DRM_ERROR("Illegal number of vertex declarations.\n"); |
| 1607 | return -EINVAL; |
| 1608 | } |
| 1609 | |
| 1610 | for (i = 0; i < cmd->body.numVertexDecls; ++i, ++decl) { |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1611 | ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 1612 | VMW_RES_DIRTY_NONE, |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1613 | user_surface_converter, |
| 1614 | &decl->array.surfaceId, NULL); |
Thomas Hellstrom | 7a73ba7 | 2009-12-22 16:53:41 +0100 | [diff] [blame] | 1615 | if (unlikely(ret != 0)) |
| 1616 | return ret; |
| 1617 | } |
| 1618 | |
| 1619 | maxnum = (header->size - sizeof(cmd->body) - |
| 1620 | cmd->body.numVertexDecls * sizeof(*decl)) / sizeof(*range); |
| 1621 | if (unlikely(cmd->body.numRanges > maxnum)) { |
| 1622 | DRM_ERROR("Illegal number of index ranges.\n"); |
| 1623 | return -EINVAL; |
| 1624 | } |
| 1625 | |
| 1626 | range = (SVGA3dPrimitiveRange *) decl; |
| 1627 | for (i = 0; i < cmd->body.numRanges; ++i, ++range) { |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1628 | ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 1629 | VMW_RES_DIRTY_NONE, |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1630 | user_surface_converter, |
| 1631 | &range->indexArray.surfaceId, NULL); |
Thomas Hellstrom | 7a73ba7 | 2009-12-22 16:53:41 +0100 | [diff] [blame] | 1632 | if (unlikely(ret != 0)) |
| 1633 | return ret; |
| 1634 | } |
| 1635 | return 0; |
| 1636 | } |
| 1637 | |
| 1638 | |
| 1639 | static int vmw_cmd_tex_state(struct vmw_private *dev_priv, |
| 1640 | struct vmw_sw_context *sw_context, |
| 1641 | SVGA3dCmdHeader *header) |
| 1642 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1643 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdSetTextureState); |
Thomas Hellstrom | 7a73ba7 | 2009-12-22 16:53:41 +0100 | [diff] [blame] | 1644 | SVGA3dTextureState *last_state = (SVGA3dTextureState *) |
| 1645 | ((unsigned long) header + header->size + sizeof(header)); |
| 1646 | SVGA3dTextureState *cur_state = (SVGA3dTextureState *) |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1647 | ((unsigned long) header + sizeof(*cmd)); |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 1648 | struct vmw_resource *ctx; |
| 1649 | struct vmw_resource *res; |
Thomas Hellstrom | 7a73ba7 | 2009-12-22 16:53:41 +0100 | [diff] [blame] | 1650 | int ret; |
| 1651 | |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1652 | cmd = container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | b5c3b1a6 | 2013-10-08 02:27:17 -0700 | [diff] [blame] | 1653 | |
| 1654 | ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 1655 | VMW_RES_DIRTY_SET, user_context_converter, |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1656 | &cmd->body.cid, &ctx); |
Thomas Hellstrom | 7a73ba7 | 2009-12-22 16:53:41 +0100 | [diff] [blame] | 1657 | if (unlikely(ret != 0)) |
| 1658 | return ret; |
| 1659 | |
| 1660 | for (; cur_state < last_state; ++cur_state) { |
| 1661 | if (likely(cur_state->name != SVGA3D_TS_BIND_TEXTURE)) |
| 1662 | continue; |
| 1663 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1664 | if (cur_state->stage >= SVGA3D_NUM_TEXTURE_UNITS) { |
| 1665 | DRM_ERROR("Illegal texture/sampler unit %u.\n", |
| 1666 | (unsigned) cur_state->stage); |
| 1667 | return -EINVAL; |
| 1668 | } |
| 1669 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1670 | ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 1671 | VMW_RES_DIRTY_NONE, |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1672 | user_surface_converter, |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 1673 | &cur_state->value, &res); |
Thomas Hellstrom | 7a73ba7 | 2009-12-22 16:53:41 +0100 | [diff] [blame] | 1674 | if (unlikely(ret != 0)) |
| 1675 | return ret; |
Thomas Hellstrom | b5c3b1a6 | 2013-10-08 02:27:17 -0700 | [diff] [blame] | 1676 | |
| 1677 | if (dev_priv->has_mob) { |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1678 | struct vmw_ctx_bindinfo_tex binding; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 1679 | struct vmw_ctx_validation_info *node; |
Thomas Hellstrom | b5c3b1a6 | 2013-10-08 02:27:17 -0700 | [diff] [blame] | 1680 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 1681 | node = vmw_execbuf_info_from_res(sw_context, ctx); |
| 1682 | if (!node) |
| 1683 | return -EINVAL; |
| 1684 | |
| 1685 | binding.bi.ctx = ctx; |
| 1686 | binding.bi.res = res; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1687 | binding.bi.bt = vmw_ctx_binding_tex; |
| 1688 | binding.texture_stage = cur_state->stage; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 1689 | vmw_binding_add(node->staged, &binding.bi, 0, |
| 1690 | binding.texture_stage); |
Thomas Hellstrom | b5c3b1a6 | 2013-10-08 02:27:17 -0700 | [diff] [blame] | 1691 | } |
Thomas Hellstrom | 7a73ba7 | 2009-12-22 16:53:41 +0100 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | return 0; |
| 1695 | } |
| 1696 | |
Jakob Bornecrantz | 4084fb8 | 2011-10-04 20:13:19 +0200 | [diff] [blame] | 1697 | static int vmw_cmd_check_define_gmrfb(struct vmw_private *dev_priv, |
| 1698 | struct vmw_sw_context *sw_context, |
| 1699 | void *buf) |
| 1700 | { |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 1701 | struct vmw_buffer_object *vmw_bo; |
Jakob Bornecrantz | 4084fb8 | 2011-10-04 20:13:19 +0200 | [diff] [blame] | 1702 | |
| 1703 | struct { |
| 1704 | uint32_t header; |
| 1705 | SVGAFifoCmdDefineGMRFB body; |
| 1706 | } *cmd = buf; |
| 1707 | |
Thomas Hellstrom | b139d43 | 2018-09-26 16:27:54 +0200 | [diff] [blame] | 1708 | return vmw_translate_guest_ptr(dev_priv, sw_context, |
| 1709 | &cmd->body.ptr, |
| 1710 | &vmw_bo); |
Jakob Bornecrantz | 4084fb8 | 2011-10-04 20:13:19 +0200 | [diff] [blame] | 1711 | } |
| 1712 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1713 | |
| 1714 | /** |
| 1715 | * vmw_cmd_res_switch_backup - Utility function to handle backup buffer |
| 1716 | * switching |
| 1717 | * |
| 1718 | * @dev_priv: Pointer to a device private struct. |
| 1719 | * @sw_context: The software context being used for this batch. |
| 1720 | * @val_node: The validation node representing the resource. |
| 1721 | * @buf_id: Pointer to the user-space backup buffer handle in the command |
| 1722 | * stream. |
| 1723 | * @backup_offset: Offset of backup into MOB. |
| 1724 | * |
| 1725 | * This function prepares for registering a switch of backup buffers |
| 1726 | * in the resource metadata just prior to unreserving. It's basically a wrapper |
| 1727 | * around vmw_cmd_res_switch_backup with a different interface. |
| 1728 | */ |
| 1729 | static int vmw_cmd_res_switch_backup(struct vmw_private *dev_priv, |
| 1730 | struct vmw_sw_context *sw_context, |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 1731 | struct vmw_resource *res, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1732 | uint32_t *buf_id, |
| 1733 | unsigned long backup_offset) |
| 1734 | { |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 1735 | struct vmw_buffer_object *vbo; |
| 1736 | void *info; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1737 | int ret; |
| 1738 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 1739 | info = vmw_execbuf_info_from_res(sw_context, res); |
| 1740 | if (!info) |
| 1741 | return -EINVAL; |
| 1742 | |
| 1743 | ret = vmw_translate_mob_ptr(dev_priv, sw_context, buf_id, &vbo); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1744 | if (ret) |
| 1745 | return ret; |
| 1746 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 1747 | vmw_validation_res_switch_backup(sw_context->ctx, info, vbo, |
| 1748 | backup_offset); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1749 | return 0; |
| 1750 | } |
| 1751 | |
| 1752 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 1753 | /** |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 1754 | * vmw_cmd_switch_backup - Utility function to handle backup buffer switching |
| 1755 | * |
| 1756 | * @dev_priv: Pointer to a device private struct. |
| 1757 | * @sw_context: The software context being used for this batch. |
| 1758 | * @res_type: The resource type. |
| 1759 | * @converter: Information about user-space binding for this resource type. |
| 1760 | * @res_id: Pointer to the user-space resource handle in the command stream. |
| 1761 | * @buf_id: Pointer to the user-space backup buffer handle in the command |
| 1762 | * stream. |
| 1763 | * @backup_offset: Offset of backup into MOB. |
| 1764 | * |
| 1765 | * This function prepares for registering a switch of backup buffers |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1766 | * in the resource metadata just prior to unreserving. It's basically a wrapper |
| 1767 | * around vmw_cmd_res_switch_backup with a different interface. |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 1768 | */ |
| 1769 | static int vmw_cmd_switch_backup(struct vmw_private *dev_priv, |
| 1770 | struct vmw_sw_context *sw_context, |
| 1771 | enum vmw_res_type res_type, |
| 1772 | const struct vmw_user_resource_conv |
| 1773 | *converter, |
| 1774 | uint32_t *res_id, |
| 1775 | uint32_t *buf_id, |
| 1776 | unsigned long backup_offset) |
| 1777 | { |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 1778 | struct vmw_resource *res; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1779 | int ret; |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 1780 | |
| 1781 | ret = vmw_cmd_res_check(dev_priv, sw_context, res_type, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 1782 | VMW_RES_DIRTY_NONE, converter, res_id, &res); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1783 | if (ret) |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 1784 | return ret; |
| 1785 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 1786 | return vmw_cmd_res_switch_backup(dev_priv, sw_context, res, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 1787 | buf_id, backup_offset); |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 1788 | } |
| 1789 | |
| 1790 | /** |
| 1791 | * vmw_cmd_bind_gb_surface - Validate an SVGA_3D_CMD_BIND_GB_SURFACE |
| 1792 | * command |
| 1793 | * |
| 1794 | * @dev_priv: Pointer to a device private struct. |
| 1795 | * @sw_context: The software context being used for this batch. |
| 1796 | * @header: Pointer to the command header in the command stream. |
| 1797 | */ |
| 1798 | static int vmw_cmd_bind_gb_surface(struct vmw_private *dev_priv, |
| 1799 | struct vmw_sw_context *sw_context, |
| 1800 | SVGA3dCmdHeader *header) |
| 1801 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1802 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdBindGBSurface) = |
| 1803 | container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 1804 | |
| 1805 | return vmw_cmd_switch_backup(dev_priv, sw_context, vmw_res_surface, |
| 1806 | user_surface_converter, |
| 1807 | &cmd->body.sid, &cmd->body.mobid, |
| 1808 | 0); |
| 1809 | } |
| 1810 | |
| 1811 | /** |
| 1812 | * vmw_cmd_update_gb_image - Validate an SVGA_3D_CMD_UPDATE_GB_IMAGE |
| 1813 | * command |
| 1814 | * |
| 1815 | * @dev_priv: Pointer to a device private struct. |
| 1816 | * @sw_context: The software context being used for this batch. |
| 1817 | * @header: Pointer to the command header in the command stream. |
| 1818 | */ |
| 1819 | static int vmw_cmd_update_gb_image(struct vmw_private *dev_priv, |
| 1820 | struct vmw_sw_context *sw_context, |
| 1821 | SVGA3dCmdHeader *header) |
| 1822 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1823 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdUpdateGBImage) = |
| 1824 | container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 1825 | |
| 1826 | return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 1827 | VMW_RES_DIRTY_NONE, user_surface_converter, |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 1828 | &cmd->body.image.sid, NULL); |
| 1829 | } |
| 1830 | |
| 1831 | /** |
| 1832 | * vmw_cmd_update_gb_surface - Validate an SVGA_3D_CMD_UPDATE_GB_SURFACE |
| 1833 | * command |
| 1834 | * |
| 1835 | * @dev_priv: Pointer to a device private struct. |
| 1836 | * @sw_context: The software context being used for this batch. |
| 1837 | * @header: Pointer to the command header in the command stream. |
| 1838 | */ |
| 1839 | static int vmw_cmd_update_gb_surface(struct vmw_private *dev_priv, |
| 1840 | struct vmw_sw_context *sw_context, |
| 1841 | SVGA3dCmdHeader *header) |
| 1842 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1843 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdUpdateGBSurface) = |
| 1844 | container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 1845 | |
| 1846 | return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 1847 | VMW_RES_DIRTY_CLEAR, user_surface_converter, |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 1848 | &cmd->body.sid, NULL); |
| 1849 | } |
| 1850 | |
| 1851 | /** |
| 1852 | * vmw_cmd_readback_gb_image - Validate an SVGA_3D_CMD_READBACK_GB_IMAGE |
| 1853 | * command |
| 1854 | * |
| 1855 | * @dev_priv: Pointer to a device private struct. |
| 1856 | * @sw_context: The software context being used for this batch. |
| 1857 | * @header: Pointer to the command header in the command stream. |
| 1858 | */ |
| 1859 | static int vmw_cmd_readback_gb_image(struct vmw_private *dev_priv, |
| 1860 | struct vmw_sw_context *sw_context, |
| 1861 | SVGA3dCmdHeader *header) |
| 1862 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1863 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdReadbackGBImage) = |
| 1864 | container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 1865 | |
| 1866 | return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 1867 | VMW_RES_DIRTY_NONE, user_surface_converter, |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 1868 | &cmd->body.image.sid, NULL); |
| 1869 | } |
| 1870 | |
| 1871 | /** |
| 1872 | * vmw_cmd_readback_gb_surface - Validate an SVGA_3D_CMD_READBACK_GB_SURFACE |
| 1873 | * command |
| 1874 | * |
| 1875 | * @dev_priv: Pointer to a device private struct. |
| 1876 | * @sw_context: The software context being used for this batch. |
| 1877 | * @header: Pointer to the command header in the command stream. |
| 1878 | */ |
| 1879 | static int vmw_cmd_readback_gb_surface(struct vmw_private *dev_priv, |
| 1880 | struct vmw_sw_context *sw_context, |
| 1881 | SVGA3dCmdHeader *header) |
| 1882 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1883 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdReadbackGBSurface) = |
| 1884 | container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 1885 | |
| 1886 | return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 1887 | VMW_RES_DIRTY_CLEAR, user_surface_converter, |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 1888 | &cmd->body.sid, NULL); |
| 1889 | } |
| 1890 | |
| 1891 | /** |
| 1892 | * vmw_cmd_invalidate_gb_image - Validate an SVGA_3D_CMD_INVALIDATE_GB_IMAGE |
| 1893 | * command |
| 1894 | * |
| 1895 | * @dev_priv: Pointer to a device private struct. |
| 1896 | * @sw_context: The software context being used for this batch. |
| 1897 | * @header: Pointer to the command header in the command stream. |
| 1898 | */ |
| 1899 | static int vmw_cmd_invalidate_gb_image(struct vmw_private *dev_priv, |
| 1900 | struct vmw_sw_context *sw_context, |
| 1901 | SVGA3dCmdHeader *header) |
| 1902 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1903 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdInvalidateGBImage) = |
| 1904 | container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 1905 | |
| 1906 | return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 1907 | VMW_RES_DIRTY_NONE, user_surface_converter, |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 1908 | &cmd->body.image.sid, NULL); |
| 1909 | } |
| 1910 | |
| 1911 | /** |
| 1912 | * vmw_cmd_invalidate_gb_surface - Validate an |
| 1913 | * SVGA_3D_CMD_INVALIDATE_GB_SURFACE command |
| 1914 | * |
| 1915 | * @dev_priv: Pointer to a device private struct. |
| 1916 | * @sw_context: The software context being used for this batch. |
| 1917 | * @header: Pointer to the command header in the command stream. |
| 1918 | */ |
| 1919 | static int vmw_cmd_invalidate_gb_surface(struct vmw_private *dev_priv, |
| 1920 | struct vmw_sw_context *sw_context, |
| 1921 | SVGA3dCmdHeader *header) |
| 1922 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1923 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdInvalidateGBSurface) = |
| 1924 | container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 1925 | |
| 1926 | return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 1927 | VMW_RES_DIRTY_CLEAR, user_surface_converter, |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 1928 | &cmd->body.sid, NULL); |
| 1929 | } |
| 1930 | |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 1931 | |
| 1932 | /** |
| 1933 | * vmw_cmd_shader_define - Validate an SVGA_3D_CMD_SHADER_DEFINE |
| 1934 | * command |
| 1935 | * |
| 1936 | * @dev_priv: Pointer to a device private struct. |
| 1937 | * @sw_context: The software context being used for this batch. |
| 1938 | * @header: Pointer to the command header in the command stream. |
| 1939 | */ |
| 1940 | static int vmw_cmd_shader_define(struct vmw_private *dev_priv, |
| 1941 | struct vmw_sw_context *sw_context, |
| 1942 | SVGA3dCmdHeader *header) |
| 1943 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1944 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDefineShader); |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 1945 | int ret; |
| 1946 | size_t size; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 1947 | struct vmw_resource *ctx; |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 1948 | |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1949 | cmd = container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 1950 | |
| 1951 | ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 1952 | VMW_RES_DIRTY_SET, user_context_converter, |
| 1953 | &cmd->body.cid, &ctx); |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 1954 | if (unlikely(ret != 0)) |
| 1955 | return ret; |
| 1956 | |
| 1957 | if (unlikely(!dev_priv->has_mob)) |
| 1958 | return 0; |
| 1959 | |
| 1960 | size = cmd->header.size - sizeof(cmd->body); |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 1961 | ret = vmw_compat_shader_add(dev_priv, |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 1962 | vmw_context_res_man(ctx), |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 1963 | cmd->body.shid, cmd + 1, |
| 1964 | cmd->body.type, size, |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 1965 | &sw_context->staged_cmd_res); |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 1966 | if (unlikely(ret != 0)) |
| 1967 | return ret; |
| 1968 | |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 1969 | return vmw_resource_relocation_add(sw_context, |
Thomas Hellstrom | e7a4528 | 2016-10-10 10:44:00 -0700 | [diff] [blame] | 1970 | NULL, |
| 1971 | vmw_ptr_diff(sw_context->buf_start, |
Thomas Hellstrom | a194403 | 2016-10-10 11:06:45 -0700 | [diff] [blame] | 1972 | &cmd->header.id), |
| 1973 | vmw_res_rel_nop); |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 1974 | } |
| 1975 | |
| 1976 | /** |
| 1977 | * vmw_cmd_shader_destroy - Validate an SVGA_3D_CMD_SHADER_DESTROY |
| 1978 | * command |
| 1979 | * |
| 1980 | * @dev_priv: Pointer to a device private struct. |
| 1981 | * @sw_context: The software context being used for this batch. |
| 1982 | * @header: Pointer to the command header in the command stream. |
| 1983 | */ |
| 1984 | static int vmw_cmd_shader_destroy(struct vmw_private *dev_priv, |
| 1985 | struct vmw_sw_context *sw_context, |
| 1986 | SVGA3dCmdHeader *header) |
| 1987 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1988 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDestroyShader); |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 1989 | int ret; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 1990 | struct vmw_resource *ctx; |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 1991 | |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 1992 | cmd = container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 1993 | |
| 1994 | ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 1995 | VMW_RES_DIRTY_SET, user_context_converter, |
| 1996 | &cmd->body.cid, &ctx); |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 1997 | if (unlikely(ret != 0)) |
| 1998 | return ret; |
| 1999 | |
| 2000 | if (unlikely(!dev_priv->has_mob)) |
| 2001 | return 0; |
| 2002 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2003 | ret = vmw_shader_remove(vmw_context_res_man(ctx), |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2004 | cmd->body.shid, |
| 2005 | cmd->body.type, |
| 2006 | &sw_context->staged_cmd_res); |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 2007 | if (unlikely(ret != 0)) |
| 2008 | return ret; |
| 2009 | |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 2010 | return vmw_resource_relocation_add(sw_context, |
Thomas Hellstrom | e7a4528 | 2016-10-10 10:44:00 -0700 | [diff] [blame] | 2011 | NULL, |
| 2012 | vmw_ptr_diff(sw_context->buf_start, |
Thomas Hellstrom | a194403 | 2016-10-10 11:06:45 -0700 | [diff] [blame] | 2013 | &cmd->header.id), |
| 2014 | vmw_res_rel_nop); |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 2015 | } |
| 2016 | |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 2017 | /** |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 2018 | * vmw_cmd_set_shader - Validate an SVGA_3D_CMD_SET_SHADER |
| 2019 | * command |
| 2020 | * |
| 2021 | * @dev_priv: Pointer to a device private struct. |
| 2022 | * @sw_context: The software context being used for this batch. |
| 2023 | * @header: Pointer to the command header in the command stream. |
| 2024 | */ |
| 2025 | static int vmw_cmd_set_shader(struct vmw_private *dev_priv, |
| 2026 | struct vmw_sw_context *sw_context, |
| 2027 | SVGA3dCmdHeader *header) |
| 2028 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 2029 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdSetShader); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2030 | struct vmw_ctx_bindinfo_shader binding; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2031 | struct vmw_resource *ctx, *res = NULL; |
| 2032 | struct vmw_ctx_validation_info *ctx_info; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 2033 | int ret; |
| 2034 | |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 2035 | cmd = container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 2036 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2037 | if (cmd->body.type >= SVGA3D_SHADERTYPE_PREDX_MAX) { |
| 2038 | DRM_ERROR("Illegal shader type %u.\n", |
| 2039 | (unsigned) cmd->body.type); |
| 2040 | return -EINVAL; |
| 2041 | } |
| 2042 | |
Thomas Hellstrom | b5c3b1a6 | 2013-10-08 02:27:17 -0700 | [diff] [blame] | 2043 | ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 2044 | VMW_RES_DIRTY_SET, user_context_converter, |
| 2045 | &cmd->body.cid, &ctx); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 2046 | if (unlikely(ret != 0)) |
| 2047 | return ret; |
| 2048 | |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 2049 | if (!dev_priv->has_mob) |
| 2050 | return 0; |
Thomas Hellstrom | c74c162 | 2012-11-21 12:10:26 +0100 | [diff] [blame] | 2051 | |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 2052 | if (cmd->body.shid != SVGA3D_INVALID_ID) { |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2053 | res = vmw_shader_lookup(vmw_context_res_man(ctx), |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2054 | cmd->body.shid, |
| 2055 | cmd->body.type); |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 2056 | |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 2057 | if (!IS_ERR(res)) { |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 2058 | ret = vmw_execbuf_res_noctx_val_add(sw_context, res, |
| 2059 | VMW_RES_DIRTY_NONE); |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 2060 | if (unlikely(ret != 0)) |
| 2061 | return ret; |
| 2062 | } |
Thomas Hellstrom | b5c3b1a6 | 2013-10-08 02:27:17 -0700 | [diff] [blame] | 2063 | } |
Thomas Hellstrom | c74c162 | 2012-11-21 12:10:26 +0100 | [diff] [blame] | 2064 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2065 | if (IS_ERR_OR_NULL(res)) { |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 2066 | ret = vmw_cmd_res_check(dev_priv, sw_context, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 2067 | vmw_res_shader, VMW_RES_DIRTY_NONE, |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 2068 | user_shader_converter, |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2069 | &cmd->body.shid, &res); |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 2070 | if (unlikely(ret != 0)) |
| 2071 | return ret; |
| 2072 | } |
| 2073 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2074 | ctx_info = vmw_execbuf_info_from_res(sw_context, ctx); |
| 2075 | if (!ctx_info) |
| 2076 | return -EINVAL; |
| 2077 | |
| 2078 | binding.bi.ctx = ctx; |
| 2079 | binding.bi.res = res; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2080 | binding.bi.bt = vmw_ctx_binding_shader; |
| 2081 | binding.shader_slot = cmd->body.type - SVGA3D_SHADERTYPE_MIN; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2082 | vmw_binding_add(ctx_info->staged, &binding.bi, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2083 | binding.shader_slot, 0); |
| 2084 | return 0; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 2085 | } |
| 2086 | |
Thomas Hellstrom | c74c162 | 2012-11-21 12:10:26 +0100 | [diff] [blame] | 2087 | /** |
Thomas Hellstrom | 0ccbbae | 2014-01-30 11:13:43 +0100 | [diff] [blame] | 2088 | * vmw_cmd_set_shader_const - Validate an SVGA_3D_CMD_SET_SHADER_CONST |
| 2089 | * command |
| 2090 | * |
| 2091 | * @dev_priv: Pointer to a device private struct. |
| 2092 | * @sw_context: The software context being used for this batch. |
| 2093 | * @header: Pointer to the command header in the command stream. |
| 2094 | */ |
| 2095 | static int vmw_cmd_set_shader_const(struct vmw_private *dev_priv, |
| 2096 | struct vmw_sw_context *sw_context, |
| 2097 | SVGA3dCmdHeader *header) |
| 2098 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 2099 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdSetShaderConst); |
Thomas Hellstrom | 0ccbbae | 2014-01-30 11:13:43 +0100 | [diff] [blame] | 2100 | int ret; |
| 2101 | |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 2102 | cmd = container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | 0ccbbae | 2014-01-30 11:13:43 +0100 | [diff] [blame] | 2103 | |
| 2104 | ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 2105 | VMW_RES_DIRTY_SET, user_context_converter, |
| 2106 | &cmd->body.cid, NULL); |
Thomas Hellstrom | 0ccbbae | 2014-01-30 11:13:43 +0100 | [diff] [blame] | 2107 | if (unlikely(ret != 0)) |
| 2108 | return ret; |
| 2109 | |
| 2110 | if (dev_priv->has_mob) |
| 2111 | header->id = SVGA_3D_CMD_SET_GB_SHADERCONSTS_INLINE; |
| 2112 | |
| 2113 | return 0; |
| 2114 | } |
| 2115 | |
| 2116 | /** |
Thomas Hellstrom | c74c162 | 2012-11-21 12:10:26 +0100 | [diff] [blame] | 2117 | * vmw_cmd_bind_gb_shader - Validate an SVGA_3D_CMD_BIND_GB_SHADER |
| 2118 | * command |
| 2119 | * |
| 2120 | * @dev_priv: Pointer to a device private struct. |
| 2121 | * @sw_context: The software context being used for this batch. |
| 2122 | * @header: Pointer to the command header in the command stream. |
| 2123 | */ |
| 2124 | static int vmw_cmd_bind_gb_shader(struct vmw_private *dev_priv, |
| 2125 | struct vmw_sw_context *sw_context, |
| 2126 | SVGA3dCmdHeader *header) |
| 2127 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 2128 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdBindGBShader) = |
| 2129 | container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | c74c162 | 2012-11-21 12:10:26 +0100 | [diff] [blame] | 2130 | |
| 2131 | return vmw_cmd_switch_backup(dev_priv, sw_context, vmw_res_shader, |
| 2132 | user_shader_converter, |
| 2133 | &cmd->body.shid, &cmd->body.mobid, |
| 2134 | cmd->body.offsetInBytes); |
| 2135 | } |
| 2136 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2137 | /** |
| 2138 | * vmw_cmd_dx_set_single_constant_buffer - Validate an |
| 2139 | * SVGA_3D_CMD_DX_SET_SINGLE_CONSTANT_BUFFER command. |
| 2140 | * |
| 2141 | * @dev_priv: Pointer to a device private struct. |
| 2142 | * @sw_context: The software context being used for this batch. |
| 2143 | * @header: Pointer to the command header in the command stream. |
| 2144 | */ |
| 2145 | static int |
| 2146 | vmw_cmd_dx_set_single_constant_buffer(struct vmw_private *dev_priv, |
| 2147 | struct vmw_sw_context *sw_context, |
| 2148 | SVGA3dCmdHeader *header) |
| 2149 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 2150 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXSetSingleConstantBuffer); |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2151 | struct vmw_resource *res = NULL; |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2152 | struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2153 | struct vmw_ctx_bindinfo_cb binding; |
| 2154 | int ret; |
| 2155 | |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2156 | if (!ctx_node) |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2157 | return -EINVAL; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2158 | |
| 2159 | cmd = container_of(header, typeof(*cmd), header); |
| 2160 | ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 2161 | VMW_RES_DIRTY_NONE, user_surface_converter, |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2162 | &cmd->body.sid, &res); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2163 | if (unlikely(ret != 0)) |
| 2164 | return ret; |
| 2165 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2166 | binding.bi.ctx = ctx_node->ctx; |
| 2167 | binding.bi.res = res; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2168 | binding.bi.bt = vmw_ctx_binding_cb; |
| 2169 | binding.shader_slot = cmd->body.type - SVGA3D_SHADERTYPE_MIN; |
| 2170 | binding.offset = cmd->body.offsetInBytes; |
| 2171 | binding.size = cmd->body.sizeInBytes; |
| 2172 | binding.slot = cmd->body.slot; |
| 2173 | |
| 2174 | if (binding.shader_slot >= SVGA3D_NUM_SHADERTYPE_DX10 || |
| 2175 | binding.slot >= SVGA3D_DX_MAX_CONSTBUFFERS) { |
| 2176 | DRM_ERROR("Illegal const buffer shader %u slot %u.\n", |
| 2177 | (unsigned) cmd->body.type, |
| 2178 | (unsigned) binding.slot); |
| 2179 | return -EINVAL; |
| 2180 | } |
| 2181 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2182 | vmw_binding_add(ctx_node->staged, &binding.bi, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2183 | binding.shader_slot, binding.slot); |
| 2184 | |
| 2185 | return 0; |
| 2186 | } |
| 2187 | |
| 2188 | /** |
| 2189 | * vmw_cmd_dx_set_shader_res - Validate an |
| 2190 | * SVGA_3D_CMD_DX_SET_SHADER_RESOURCES command |
| 2191 | * |
| 2192 | * @dev_priv: Pointer to a device private struct. |
| 2193 | * @sw_context: The software context being used for this batch. |
| 2194 | * @header: Pointer to the command header in the command stream. |
| 2195 | */ |
| 2196 | static int vmw_cmd_dx_set_shader_res(struct vmw_private *dev_priv, |
| 2197 | struct vmw_sw_context *sw_context, |
| 2198 | SVGA3dCmdHeader *header) |
| 2199 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 2200 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXSetShaderResources) = |
| 2201 | container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2202 | u32 num_sr_view = (cmd->header.size - sizeof(cmd->body)) / |
| 2203 | sizeof(SVGA3dShaderResourceViewId); |
| 2204 | |
| 2205 | if ((u64) cmd->body.startView + (u64) num_sr_view > |
| 2206 | (u64) SVGA3D_DX_MAX_SRVIEWS || |
| 2207 | cmd->body.type >= SVGA3D_SHADERTYPE_DX10_MAX) { |
| 2208 | DRM_ERROR("Invalid shader binding.\n"); |
| 2209 | return -EINVAL; |
| 2210 | } |
| 2211 | |
| 2212 | return vmw_view_bindings_add(sw_context, vmw_view_sr, |
| 2213 | vmw_ctx_binding_sr, |
| 2214 | cmd->body.type - SVGA3D_SHADERTYPE_MIN, |
| 2215 | (void *) &cmd[1], num_sr_view, |
| 2216 | cmd->body.startView); |
| 2217 | } |
| 2218 | |
| 2219 | /** |
| 2220 | * vmw_cmd_dx_set_shader - Validate an SVGA_3D_CMD_DX_SET_SHADER |
| 2221 | * command |
| 2222 | * |
| 2223 | * @dev_priv: Pointer to a device private struct. |
| 2224 | * @sw_context: The software context being used for this batch. |
| 2225 | * @header: Pointer to the command header in the command stream. |
| 2226 | */ |
| 2227 | static int vmw_cmd_dx_set_shader(struct vmw_private *dev_priv, |
| 2228 | struct vmw_sw_context *sw_context, |
| 2229 | SVGA3dCmdHeader *header) |
| 2230 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 2231 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXSetShader); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2232 | struct vmw_resource *res = NULL; |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2233 | struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2234 | struct vmw_ctx_bindinfo_shader binding; |
| 2235 | int ret = 0; |
| 2236 | |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2237 | if (!ctx_node) |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2238 | return -EINVAL; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2239 | |
| 2240 | cmd = container_of(header, typeof(*cmd), header); |
| 2241 | |
| 2242 | if (cmd->body.type >= SVGA3D_SHADERTYPE_DX10_MAX) { |
| 2243 | DRM_ERROR("Illegal shader type %u.\n", |
| 2244 | (unsigned) cmd->body.type); |
| 2245 | return -EINVAL; |
| 2246 | } |
| 2247 | |
| 2248 | if (cmd->body.shaderId != SVGA3D_INVALID_ID) { |
| 2249 | res = vmw_shader_lookup(sw_context->man, cmd->body.shaderId, 0); |
| 2250 | if (IS_ERR(res)) { |
| 2251 | DRM_ERROR("Could not find shader for binding.\n"); |
| 2252 | return PTR_ERR(res); |
| 2253 | } |
| 2254 | |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 2255 | ret = vmw_execbuf_res_noctx_val_add(sw_context, res, |
| 2256 | VMW_RES_DIRTY_NONE); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2257 | if (ret) |
Thomas Hellstrom | 508108e | 2018-09-26 16:28:45 +0200 | [diff] [blame] | 2258 | return ret; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2259 | } |
| 2260 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2261 | binding.bi.ctx = ctx_node->ctx; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2262 | binding.bi.res = res; |
| 2263 | binding.bi.bt = vmw_ctx_binding_dx_shader; |
| 2264 | binding.shader_slot = cmd->body.type - SVGA3D_SHADERTYPE_MIN; |
| 2265 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2266 | vmw_binding_add(ctx_node->staged, &binding.bi, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2267 | binding.shader_slot, 0); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2268 | |
Thomas Hellstrom | 508108e | 2018-09-26 16:28:45 +0200 | [diff] [blame] | 2269 | return 0; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2270 | } |
| 2271 | |
| 2272 | /** |
| 2273 | * vmw_cmd_dx_set_vertex_buffers - Validates an |
| 2274 | * SVGA_3D_CMD_DX_SET_VERTEX_BUFFERS command |
| 2275 | * |
| 2276 | * @dev_priv: Pointer to a device private struct. |
| 2277 | * @sw_context: The software context being used for this batch. |
| 2278 | * @header: Pointer to the command header in the command stream. |
| 2279 | */ |
| 2280 | static int vmw_cmd_dx_set_vertex_buffers(struct vmw_private *dev_priv, |
| 2281 | struct vmw_sw_context *sw_context, |
| 2282 | SVGA3dCmdHeader *header) |
| 2283 | { |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2284 | struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2285 | struct vmw_ctx_bindinfo_vb binding; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2286 | struct vmw_resource *res; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2287 | struct { |
| 2288 | SVGA3dCmdHeader header; |
| 2289 | SVGA3dCmdDXSetVertexBuffers body; |
| 2290 | SVGA3dVertexBuffer buf[]; |
| 2291 | } *cmd; |
| 2292 | int i, ret, num; |
| 2293 | |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2294 | if (!ctx_node) |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2295 | return -EINVAL; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2296 | |
| 2297 | cmd = container_of(header, typeof(*cmd), header); |
| 2298 | num = (cmd->header.size - sizeof(cmd->body)) / |
| 2299 | sizeof(SVGA3dVertexBuffer); |
| 2300 | if ((u64)num + (u64)cmd->body.startBuffer > |
| 2301 | (u64)SVGA3D_DX_MAX_VERTEXBUFFERS) { |
| 2302 | DRM_ERROR("Invalid number of vertex buffers.\n"); |
| 2303 | return -EINVAL; |
| 2304 | } |
| 2305 | |
| 2306 | for (i = 0; i < num; i++) { |
| 2307 | ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 2308 | VMW_RES_DIRTY_NONE, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2309 | user_surface_converter, |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2310 | &cmd->buf[i].sid, &res); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2311 | if (unlikely(ret != 0)) |
| 2312 | return ret; |
| 2313 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2314 | binding.bi.ctx = ctx_node->ctx; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2315 | binding.bi.bt = vmw_ctx_binding_vb; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2316 | binding.bi.res = res; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2317 | binding.offset = cmd->buf[i].offset; |
| 2318 | binding.stride = cmd->buf[i].stride; |
| 2319 | binding.slot = i + cmd->body.startBuffer; |
| 2320 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2321 | vmw_binding_add(ctx_node->staged, &binding.bi, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2322 | 0, binding.slot); |
| 2323 | } |
| 2324 | |
| 2325 | return 0; |
| 2326 | } |
| 2327 | |
| 2328 | /** |
| 2329 | * vmw_cmd_dx_ia_set_vertex_buffers - Validate an |
Brian Paul | 8bd6287 | 2017-07-17 07:36:10 -0700 | [diff] [blame] | 2330 | * SVGA_3D_CMD_DX_IA_SET_INDEX_BUFFER command. |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2331 | * |
| 2332 | * @dev_priv: Pointer to a device private struct. |
| 2333 | * @sw_context: The software context being used for this batch. |
| 2334 | * @header: Pointer to the command header in the command stream. |
| 2335 | */ |
| 2336 | static int vmw_cmd_dx_set_index_buffer(struct vmw_private *dev_priv, |
| 2337 | struct vmw_sw_context *sw_context, |
| 2338 | SVGA3dCmdHeader *header) |
| 2339 | { |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2340 | struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2341 | struct vmw_ctx_bindinfo_ib binding; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2342 | struct vmw_resource *res; |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 2343 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXSetIndexBuffer); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2344 | int ret; |
| 2345 | |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2346 | if (!ctx_node) |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2347 | return -EINVAL; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2348 | |
| 2349 | cmd = container_of(header, typeof(*cmd), header); |
| 2350 | ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 2351 | VMW_RES_DIRTY_NONE, user_surface_converter, |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2352 | &cmd->body.sid, &res); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2353 | if (unlikely(ret != 0)) |
| 2354 | return ret; |
| 2355 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2356 | binding.bi.ctx = ctx_node->ctx; |
| 2357 | binding.bi.res = res; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2358 | binding.bi.bt = vmw_ctx_binding_ib; |
| 2359 | binding.offset = cmd->body.offset; |
| 2360 | binding.format = cmd->body.format; |
| 2361 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2362 | vmw_binding_add(ctx_node->staged, &binding.bi, 0, 0); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2363 | |
| 2364 | return 0; |
| 2365 | } |
| 2366 | |
| 2367 | /** |
| 2368 | * vmw_cmd_dx_set_rendertarget - Validate an |
| 2369 | * SVGA_3D_CMD_DX_SET_RENDERTARGETS command |
| 2370 | * |
| 2371 | * @dev_priv: Pointer to a device private struct. |
| 2372 | * @sw_context: The software context being used for this batch. |
| 2373 | * @header: Pointer to the command header in the command stream. |
| 2374 | */ |
| 2375 | static int vmw_cmd_dx_set_rendertargets(struct vmw_private *dev_priv, |
| 2376 | struct vmw_sw_context *sw_context, |
| 2377 | SVGA3dCmdHeader *header) |
| 2378 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 2379 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXSetRenderTargets) = |
| 2380 | container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2381 | u32 num_rt_view = (cmd->header.size - sizeof(cmd->body)) / |
| 2382 | sizeof(SVGA3dRenderTargetViewId); |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 2383 | int ret; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2384 | |
| 2385 | if (num_rt_view > SVGA3D_MAX_SIMULTANEOUS_RENDER_TARGETS) { |
| 2386 | DRM_ERROR("Invalid DX Rendertarget binding.\n"); |
| 2387 | return -EINVAL; |
| 2388 | } |
| 2389 | |
| 2390 | ret = vmw_view_bindings_add(sw_context, vmw_view_ds, |
| 2391 | vmw_ctx_binding_ds, 0, |
| 2392 | &cmd->body.depthStencilViewId, 1, 0); |
| 2393 | if (ret) |
| 2394 | return ret; |
| 2395 | |
| 2396 | return vmw_view_bindings_add(sw_context, vmw_view_rt, |
| 2397 | vmw_ctx_binding_dx_rt, 0, |
| 2398 | (void *)&cmd[1], num_rt_view, 0); |
| 2399 | } |
| 2400 | |
| 2401 | /** |
| 2402 | * vmw_cmd_dx_clear_rendertarget_view - Validate an |
| 2403 | * SVGA_3D_CMD_DX_CLEAR_RENDERTARGET_VIEW command |
| 2404 | * |
| 2405 | * @dev_priv: Pointer to a device private struct. |
| 2406 | * @sw_context: The software context being used for this batch. |
| 2407 | * @header: Pointer to the command header in the command stream. |
| 2408 | */ |
| 2409 | static int vmw_cmd_dx_clear_rendertarget_view(struct vmw_private *dev_priv, |
| 2410 | struct vmw_sw_context *sw_context, |
| 2411 | SVGA3dCmdHeader *header) |
| 2412 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 2413 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXClearRenderTargetView) = |
| 2414 | container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2415 | |
Thomas Hellstrom | 508108e | 2018-09-26 16:28:45 +0200 | [diff] [blame] | 2416 | return PTR_RET(vmw_view_id_val_add(sw_context, vmw_view_rt, |
| 2417 | cmd->body.renderTargetViewId)); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2418 | } |
| 2419 | |
| 2420 | /** |
| 2421 | * vmw_cmd_dx_clear_rendertarget_view - Validate an |
| 2422 | * SVGA_3D_CMD_DX_CLEAR_DEPTHSTENCIL_VIEW command |
| 2423 | * |
| 2424 | * @dev_priv: Pointer to a device private struct. |
| 2425 | * @sw_context: The software context being used for this batch. |
| 2426 | * @header: Pointer to the command header in the command stream. |
| 2427 | */ |
| 2428 | static int vmw_cmd_dx_clear_depthstencil_view(struct vmw_private *dev_priv, |
| 2429 | struct vmw_sw_context *sw_context, |
| 2430 | SVGA3dCmdHeader *header) |
| 2431 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 2432 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXClearDepthStencilView) = |
| 2433 | container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2434 | |
Thomas Hellstrom | 508108e | 2018-09-26 16:28:45 +0200 | [diff] [blame] | 2435 | return PTR_RET(vmw_view_id_val_add(sw_context, vmw_view_ds, |
| 2436 | cmd->body.depthStencilViewId)); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2437 | } |
| 2438 | |
| 2439 | static int vmw_cmd_dx_view_define(struct vmw_private *dev_priv, |
| 2440 | struct vmw_sw_context *sw_context, |
| 2441 | SVGA3dCmdHeader *header) |
| 2442 | { |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2443 | struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context); |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2444 | struct vmw_resource *srf; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2445 | struct vmw_resource *res; |
| 2446 | enum vmw_view_type view_type; |
| 2447 | int ret; |
| 2448 | /* |
| 2449 | * This is based on the fact that all affected define commands have |
| 2450 | * the same initial command body layout. |
| 2451 | */ |
| 2452 | struct { |
| 2453 | SVGA3dCmdHeader header; |
| 2454 | uint32 defined_id; |
| 2455 | uint32 sid; |
| 2456 | } *cmd; |
| 2457 | |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2458 | if (!ctx_node) |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2459 | return -EINVAL; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2460 | |
| 2461 | view_type = vmw_view_cmd_to_type(header->id); |
Dan Carpenter | 0d9cac0 | 2018-01-10 12:40:04 +0300 | [diff] [blame] | 2462 | if (view_type == vmw_view_max) |
| 2463 | return -EINVAL; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2464 | cmd = container_of(header, typeof(*cmd), header); |
| 2465 | ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 2466 | VMW_RES_DIRTY_NONE, user_surface_converter, |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2467 | &cmd->sid, &srf); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2468 | if (unlikely(ret != 0)) |
| 2469 | return ret; |
| 2470 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2471 | res = vmw_context_cotable(ctx_node->ctx, vmw_view_cotables[view_type]); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2472 | ret = vmw_cotable_notify(res, cmd->defined_id); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2473 | if (unlikely(ret != 0)) |
| 2474 | return ret; |
| 2475 | |
| 2476 | return vmw_view_add(sw_context->man, |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2477 | ctx_node->ctx, |
| 2478 | srf, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2479 | view_type, |
| 2480 | cmd->defined_id, |
| 2481 | header, |
| 2482 | header->size + sizeof(*header), |
| 2483 | &sw_context->staged_cmd_res); |
| 2484 | } |
| 2485 | |
Charmaine Lee | 2f633e5 | 2015-08-10 10:45:11 -0700 | [diff] [blame] | 2486 | /** |
| 2487 | * vmw_cmd_dx_set_so_targets - Validate an |
| 2488 | * SVGA_3D_CMD_DX_SET_SOTARGETS command. |
| 2489 | * |
| 2490 | * @dev_priv: Pointer to a device private struct. |
| 2491 | * @sw_context: The software context being used for this batch. |
| 2492 | * @header: Pointer to the command header in the command stream. |
| 2493 | */ |
| 2494 | static int vmw_cmd_dx_set_so_targets(struct vmw_private *dev_priv, |
| 2495 | struct vmw_sw_context *sw_context, |
| 2496 | SVGA3dCmdHeader *header) |
| 2497 | { |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2498 | struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context); |
Charmaine Lee | 2f633e5 | 2015-08-10 10:45:11 -0700 | [diff] [blame] | 2499 | struct vmw_ctx_bindinfo_so binding; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2500 | struct vmw_resource *res; |
Charmaine Lee | 2f633e5 | 2015-08-10 10:45:11 -0700 | [diff] [blame] | 2501 | struct { |
| 2502 | SVGA3dCmdHeader header; |
| 2503 | SVGA3dCmdDXSetSOTargets body; |
| 2504 | SVGA3dSoTarget targets[]; |
| 2505 | } *cmd; |
| 2506 | int i, ret, num; |
| 2507 | |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2508 | if (!ctx_node) |
Charmaine Lee | 2f633e5 | 2015-08-10 10:45:11 -0700 | [diff] [blame] | 2509 | return -EINVAL; |
Charmaine Lee | 2f633e5 | 2015-08-10 10:45:11 -0700 | [diff] [blame] | 2510 | |
| 2511 | cmd = container_of(header, typeof(*cmd), header); |
| 2512 | num = (cmd->header.size - sizeof(cmd->body)) / |
| 2513 | sizeof(SVGA3dSoTarget); |
| 2514 | |
| 2515 | if (num > SVGA3D_DX_MAX_SOTARGETS) { |
| 2516 | DRM_ERROR("Invalid DX SO binding.\n"); |
| 2517 | return -EINVAL; |
| 2518 | } |
| 2519 | |
| 2520 | for (i = 0; i < num; i++) { |
| 2521 | ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 2522 | VMW_RES_DIRTY_SET, |
Charmaine Lee | 2f633e5 | 2015-08-10 10:45:11 -0700 | [diff] [blame] | 2523 | user_surface_converter, |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2524 | &cmd->targets[i].sid, &res); |
Charmaine Lee | 2f633e5 | 2015-08-10 10:45:11 -0700 | [diff] [blame] | 2525 | if (unlikely(ret != 0)) |
| 2526 | return ret; |
| 2527 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2528 | binding.bi.ctx = ctx_node->ctx; |
| 2529 | binding.bi.res = res; |
Charmaine Lee | 2f633e5 | 2015-08-10 10:45:11 -0700 | [diff] [blame] | 2530 | binding.bi.bt = vmw_ctx_binding_so, |
| 2531 | binding.offset = cmd->targets[i].offset; |
| 2532 | binding.size = cmd->targets[i].sizeInBytes; |
| 2533 | binding.slot = i; |
| 2534 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2535 | vmw_binding_add(ctx_node->staged, &binding.bi, |
Charmaine Lee | 2f633e5 | 2015-08-10 10:45:11 -0700 | [diff] [blame] | 2536 | 0, binding.slot); |
| 2537 | } |
| 2538 | |
| 2539 | return 0; |
| 2540 | } |
| 2541 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2542 | static int vmw_cmd_dx_so_define(struct vmw_private *dev_priv, |
| 2543 | struct vmw_sw_context *sw_context, |
| 2544 | SVGA3dCmdHeader *header) |
| 2545 | { |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2546 | struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2547 | struct vmw_resource *res; |
| 2548 | /* |
| 2549 | * This is based on the fact that all affected define commands have |
| 2550 | * the same initial command body layout. |
| 2551 | */ |
| 2552 | struct { |
| 2553 | SVGA3dCmdHeader header; |
| 2554 | uint32 defined_id; |
| 2555 | } *cmd; |
| 2556 | enum vmw_so_type so_type; |
| 2557 | int ret; |
| 2558 | |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2559 | if (!ctx_node) |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2560 | return -EINVAL; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2561 | |
| 2562 | so_type = vmw_so_cmd_to_type(header->id); |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2563 | res = vmw_context_cotable(ctx_node->ctx, vmw_so_cotables[so_type]); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2564 | cmd = container_of(header, typeof(*cmd), header); |
| 2565 | ret = vmw_cotable_notify(res, cmd->defined_id); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2566 | |
| 2567 | return ret; |
| 2568 | } |
| 2569 | |
| 2570 | /** |
| 2571 | * vmw_cmd_dx_check_subresource - Validate an |
| 2572 | * SVGA_3D_CMD_DX_[X]_SUBRESOURCE command |
| 2573 | * |
| 2574 | * @dev_priv: Pointer to a device private struct. |
| 2575 | * @sw_context: The software context being used for this batch. |
| 2576 | * @header: Pointer to the command header in the command stream. |
| 2577 | */ |
| 2578 | static int vmw_cmd_dx_check_subresource(struct vmw_private *dev_priv, |
| 2579 | struct vmw_sw_context *sw_context, |
| 2580 | SVGA3dCmdHeader *header) |
| 2581 | { |
| 2582 | struct { |
| 2583 | SVGA3dCmdHeader header; |
| 2584 | union { |
| 2585 | SVGA3dCmdDXReadbackSubResource r_body; |
| 2586 | SVGA3dCmdDXInvalidateSubResource i_body; |
| 2587 | SVGA3dCmdDXUpdateSubResource u_body; |
| 2588 | SVGA3dSurfaceId sid; |
| 2589 | }; |
| 2590 | } *cmd; |
| 2591 | |
| 2592 | BUILD_BUG_ON(offsetof(typeof(*cmd), r_body.sid) != |
| 2593 | offsetof(typeof(*cmd), sid)); |
| 2594 | BUILD_BUG_ON(offsetof(typeof(*cmd), i_body.sid) != |
| 2595 | offsetof(typeof(*cmd), sid)); |
| 2596 | BUILD_BUG_ON(offsetof(typeof(*cmd), u_body.sid) != |
| 2597 | offsetof(typeof(*cmd), sid)); |
| 2598 | |
| 2599 | cmd = container_of(header, typeof(*cmd), header); |
| 2600 | |
| 2601 | return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 2602 | VMW_RES_DIRTY_NONE, user_surface_converter, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2603 | &cmd->sid, NULL); |
| 2604 | } |
| 2605 | |
| 2606 | static int vmw_cmd_dx_cid_check(struct vmw_private *dev_priv, |
| 2607 | struct vmw_sw_context *sw_context, |
| 2608 | SVGA3dCmdHeader *header) |
| 2609 | { |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2610 | struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2611 | |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2612 | if (!ctx_node) |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2613 | return -EINVAL; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2614 | |
| 2615 | return 0; |
| 2616 | } |
| 2617 | |
| 2618 | /** |
| 2619 | * vmw_cmd_dx_view_remove - validate a view remove command and |
| 2620 | * schedule the view resource for removal. |
| 2621 | * |
| 2622 | * @dev_priv: Pointer to a device private struct. |
| 2623 | * @sw_context: The software context being used for this batch. |
| 2624 | * @header: Pointer to the command header in the command stream. |
| 2625 | * |
| 2626 | * Check that the view exists, and if it was not created using this |
Thomas Hellstrom | a194403 | 2016-10-10 11:06:45 -0700 | [diff] [blame] | 2627 | * command batch, conditionally make this command a NOP. |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2628 | */ |
| 2629 | static int vmw_cmd_dx_view_remove(struct vmw_private *dev_priv, |
| 2630 | struct vmw_sw_context *sw_context, |
| 2631 | SVGA3dCmdHeader *header) |
| 2632 | { |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2633 | struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2634 | struct { |
| 2635 | SVGA3dCmdHeader header; |
| 2636 | union vmw_view_destroy body; |
| 2637 | } *cmd = container_of(header, typeof(*cmd), header); |
| 2638 | enum vmw_view_type view_type = vmw_view_cmd_to_type(header->id); |
| 2639 | struct vmw_resource *view; |
| 2640 | int ret; |
| 2641 | |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2642 | if (!ctx_node) |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2643 | return -EINVAL; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2644 | |
| 2645 | ret = vmw_view_remove(sw_context->man, |
| 2646 | cmd->body.view_id, view_type, |
| 2647 | &sw_context->staged_cmd_res, |
| 2648 | &view); |
| 2649 | if (ret || !view) |
| 2650 | return ret; |
| 2651 | |
| 2652 | /* |
Thomas Hellstrom | a194403 | 2016-10-10 11:06:45 -0700 | [diff] [blame] | 2653 | * If the view wasn't created during this command batch, it might |
| 2654 | * have been removed due to a context swapout, so add a |
| 2655 | * relocation to conditionally make this command a NOP to avoid |
| 2656 | * device errors. |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2657 | */ |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 2658 | return vmw_resource_relocation_add(sw_context, |
Thomas Hellstrom | a194403 | 2016-10-10 11:06:45 -0700 | [diff] [blame] | 2659 | view, |
| 2660 | vmw_ptr_diff(sw_context->buf_start, |
| 2661 | &cmd->header.id), |
| 2662 | vmw_res_rel_cond_nop); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2663 | } |
| 2664 | |
| 2665 | /** |
| 2666 | * vmw_cmd_dx_define_shader - Validate an SVGA_3D_CMD_DX_DEFINE_SHADER |
| 2667 | * command |
| 2668 | * |
| 2669 | * @dev_priv: Pointer to a device private struct. |
| 2670 | * @sw_context: The software context being used for this batch. |
| 2671 | * @header: Pointer to the command header in the command stream. |
| 2672 | */ |
| 2673 | static int vmw_cmd_dx_define_shader(struct vmw_private *dev_priv, |
| 2674 | struct vmw_sw_context *sw_context, |
| 2675 | SVGA3dCmdHeader *header) |
| 2676 | { |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2677 | struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2678 | struct vmw_resource *res; |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 2679 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXDefineShader) = |
| 2680 | container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2681 | int ret; |
| 2682 | |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2683 | if (!ctx_node) |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2684 | return -EINVAL; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2685 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2686 | res = vmw_context_cotable(ctx_node->ctx, SVGA_COTABLE_DXSHADER); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2687 | ret = vmw_cotable_notify(res, cmd->body.shaderId); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2688 | if (ret) |
| 2689 | return ret; |
| 2690 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2691 | return vmw_dx_shader_add(sw_context->man, ctx_node->ctx, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2692 | cmd->body.shaderId, cmd->body.type, |
| 2693 | &sw_context->staged_cmd_res); |
| 2694 | } |
| 2695 | |
| 2696 | /** |
| 2697 | * vmw_cmd_dx_destroy_shader - Validate an SVGA_3D_CMD_DX_DESTROY_SHADER |
| 2698 | * command |
| 2699 | * |
| 2700 | * @dev_priv: Pointer to a device private struct. |
| 2701 | * @sw_context: The software context being used for this batch. |
| 2702 | * @header: Pointer to the command header in the command stream. |
| 2703 | */ |
| 2704 | static int vmw_cmd_dx_destroy_shader(struct vmw_private *dev_priv, |
| 2705 | struct vmw_sw_context *sw_context, |
| 2706 | SVGA3dCmdHeader *header) |
| 2707 | { |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2708 | struct vmw_ctx_validation_info *ctx_node = VMW_GET_CTX_NODE(sw_context); |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 2709 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXDestroyShader) = |
| 2710 | container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2711 | int ret; |
| 2712 | |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2713 | if (!ctx_node) |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2714 | return -EINVAL; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2715 | |
| 2716 | ret = vmw_shader_remove(sw_context->man, cmd->body.shaderId, 0, |
| 2717 | &sw_context->staged_cmd_res); |
| 2718 | if (ret) |
| 2719 | DRM_ERROR("Could not find shader to remove.\n"); |
| 2720 | |
| 2721 | return ret; |
| 2722 | } |
| 2723 | |
| 2724 | /** |
| 2725 | * vmw_cmd_dx_bind_shader - Validate an SVGA_3D_CMD_DX_BIND_SHADER |
| 2726 | * command |
| 2727 | * |
| 2728 | * @dev_priv: Pointer to a device private struct. |
| 2729 | * @sw_context: The software context being used for this batch. |
| 2730 | * @header: Pointer to the command header in the command stream. |
| 2731 | */ |
| 2732 | static int vmw_cmd_dx_bind_shader(struct vmw_private *dev_priv, |
| 2733 | struct vmw_sw_context *sw_context, |
| 2734 | SVGA3dCmdHeader *header) |
| 2735 | { |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2736 | struct vmw_resource *ctx; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2737 | struct vmw_resource *res; |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 2738 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXBindShader) = |
| 2739 | container_of(header, typeof(*cmd), header); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2740 | int ret; |
| 2741 | |
| 2742 | if (cmd->body.cid != SVGA3D_INVALID_ID) { |
| 2743 | ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_context, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 2744 | VMW_RES_DIRTY_SET, |
| 2745 | user_context_converter, &cmd->body.cid, |
| 2746 | &ctx); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2747 | if (ret) |
| 2748 | return ret; |
| 2749 | } else { |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2750 | struct vmw_ctx_validation_info *ctx_node = |
| 2751 | VMW_GET_CTX_NODE(sw_context); |
| 2752 | |
| 2753 | if (!ctx_node) |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2754 | return -EINVAL; |
Deepak Rawat | 6f74fd9 | 2019-02-08 12:53:57 -0800 | [diff] [blame] | 2755 | |
| 2756 | ctx = ctx_node->ctx; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2757 | } |
| 2758 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 2759 | res = vmw_shader_lookup(vmw_context_res_man(ctx), |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2760 | cmd->body.shid, 0); |
| 2761 | if (IS_ERR(res)) { |
| 2762 | DRM_ERROR("Could not find shader to bind.\n"); |
| 2763 | return PTR_ERR(res); |
| 2764 | } |
| 2765 | |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 2766 | ret = vmw_execbuf_res_noctx_val_add(sw_context, res, |
| 2767 | VMW_RES_DIRTY_NONE); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2768 | if (ret) { |
| 2769 | DRM_ERROR("Error creating resource validation node.\n"); |
Thomas Hellstrom | 508108e | 2018-09-26 16:28:45 +0200 | [diff] [blame] | 2770 | return ret; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2771 | } |
| 2772 | |
Thomas Hellstrom | 508108e | 2018-09-26 16:28:45 +0200 | [diff] [blame] | 2773 | return vmw_cmd_res_switch_backup(dev_priv, sw_context, res, |
| 2774 | &cmd->body.mobid, |
| 2775 | cmd->body.offsetInBytes); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 2776 | } |
| 2777 | |
Charmaine Lee | f3b33550 | 2016-02-12 08:11:56 +0100 | [diff] [blame] | 2778 | /** |
| 2779 | * vmw_cmd_dx_genmips - Validate an SVGA_3D_CMD_DX_GENMIPS command |
| 2780 | * |
| 2781 | * @dev_priv: Pointer to a device private struct. |
| 2782 | * @sw_context: The software context being used for this batch. |
| 2783 | * @header: Pointer to the command header in the command stream. |
| 2784 | */ |
| 2785 | static int vmw_cmd_dx_genmips(struct vmw_private *dev_priv, |
| 2786 | struct vmw_sw_context *sw_context, |
| 2787 | SVGA3dCmdHeader *header) |
| 2788 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 2789 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXGenMips) = |
| 2790 | container_of(header, typeof(*cmd), header); |
Charmaine Lee | f3b33550 | 2016-02-12 08:11:56 +0100 | [diff] [blame] | 2791 | |
Thomas Hellstrom | 508108e | 2018-09-26 16:28:45 +0200 | [diff] [blame] | 2792 | return PTR_RET(vmw_view_id_val_add(sw_context, vmw_view_sr, |
| 2793 | cmd->body.shaderResourceViewId)); |
Charmaine Lee | f3b33550 | 2016-02-12 08:11:56 +0100 | [diff] [blame] | 2794 | } |
| 2795 | |
Charmaine Lee | 1f982e4 | 2016-10-10 10:37:03 -0700 | [diff] [blame] | 2796 | /** |
| 2797 | * vmw_cmd_dx_transfer_from_buffer - |
| 2798 | * Validate an SVGA_3D_CMD_DX_TRANSFER_FROM_BUFFER command |
| 2799 | * |
| 2800 | * @dev_priv: Pointer to a device private struct. |
| 2801 | * @sw_context: The software context being used for this batch. |
| 2802 | * @header: Pointer to the command header in the command stream. |
| 2803 | */ |
| 2804 | static int vmw_cmd_dx_transfer_from_buffer(struct vmw_private *dev_priv, |
| 2805 | struct vmw_sw_context *sw_context, |
| 2806 | SVGA3dCmdHeader *header) |
| 2807 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 2808 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdDXTransferFromBuffer) = |
| 2809 | container_of(header, typeof(*cmd), header); |
Charmaine Lee | 1f982e4 | 2016-10-10 10:37:03 -0700 | [diff] [blame] | 2810 | int ret; |
| 2811 | |
| 2812 | ret = vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 2813 | VMW_RES_DIRTY_NONE, user_surface_converter, |
Charmaine Lee | 1f982e4 | 2016-10-10 10:37:03 -0700 | [diff] [blame] | 2814 | &cmd->body.srcSid, NULL); |
| 2815 | if (ret != 0) |
| 2816 | return ret; |
| 2817 | |
| 2818 | return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 2819 | VMW_RES_DIRTY_SET, user_surface_converter, |
Charmaine Lee | 1f982e4 | 2016-10-10 10:37:03 -0700 | [diff] [blame] | 2820 | &cmd->body.destSid, NULL); |
| 2821 | } |
| 2822 | |
Neha Bhende | 0d81d34 | 2018-06-18 17:14:56 -0700 | [diff] [blame] | 2823 | /** |
| 2824 | * vmw_cmd_intra_surface_copy - |
| 2825 | * Validate an SVGA_3D_CMD_INTRA_SURFACE_COPY command |
| 2826 | * |
| 2827 | * @dev_priv: Pointer to a device private struct. |
| 2828 | * @sw_context: The software context being used for this batch. |
| 2829 | * @header: Pointer to the command header in the command stream. |
| 2830 | */ |
| 2831 | static int vmw_cmd_intra_surface_copy(struct vmw_private *dev_priv, |
| 2832 | struct vmw_sw_context *sw_context, |
| 2833 | SVGA3dCmdHeader *header) |
| 2834 | { |
Deepak Rawat | d01316d | 2019-02-08 15:50:40 -0800 | [diff] [blame^] | 2835 | VMW_DECLARE_CMD_VAR(*cmd, SVGA3dCmdIntraSurfaceCopy) = |
| 2836 | container_of(header, typeof(*cmd), header); |
Neha Bhende | 0d81d34 | 2018-06-18 17:14:56 -0700 | [diff] [blame] | 2837 | |
| 2838 | if (!(dev_priv->capabilities2 & SVGA_CAP2_INTRA_SURFACE_COPY)) |
| 2839 | return -EINVAL; |
| 2840 | |
| 2841 | return vmw_cmd_res_check(dev_priv, sw_context, vmw_res_surface, |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 2842 | VMW_RES_DIRTY_SET, user_surface_converter, |
| 2843 | &cmd->body.surface.sid, NULL); |
Neha Bhende | 0d81d34 | 2018-06-18 17:14:56 -0700 | [diff] [blame] | 2844 | } |
| 2845 | |
| 2846 | |
Jakob Bornecrantz | 4084fb8 | 2011-10-04 20:13:19 +0200 | [diff] [blame] | 2847 | static int vmw_cmd_check_not_3d(struct vmw_private *dev_priv, |
| 2848 | struct vmw_sw_context *sw_context, |
| 2849 | void *buf, uint32_t *size) |
| 2850 | { |
| 2851 | uint32_t size_remaining = *size; |
Jakob Bornecrantz | 4084fb8 | 2011-10-04 20:13:19 +0200 | [diff] [blame] | 2852 | uint32_t cmd_id; |
| 2853 | |
Thomas Hellstrom | b9eb1a6 | 2015-04-02 02:39:45 -0700 | [diff] [blame] | 2854 | cmd_id = ((uint32_t *)buf)[0]; |
Jakob Bornecrantz | 4084fb8 | 2011-10-04 20:13:19 +0200 | [diff] [blame] | 2855 | switch (cmd_id) { |
| 2856 | case SVGA_CMD_UPDATE: |
| 2857 | *size = sizeof(uint32_t) + sizeof(SVGAFifoCmdUpdate); |
Jakob Bornecrantz | 4084fb8 | 2011-10-04 20:13:19 +0200 | [diff] [blame] | 2858 | break; |
| 2859 | case SVGA_CMD_DEFINE_GMRFB: |
| 2860 | *size = sizeof(uint32_t) + sizeof(SVGAFifoCmdDefineGMRFB); |
| 2861 | break; |
| 2862 | case SVGA_CMD_BLIT_GMRFB_TO_SCREEN: |
| 2863 | *size = sizeof(uint32_t) + sizeof(SVGAFifoCmdBlitGMRFBToScreen); |
| 2864 | break; |
| 2865 | case SVGA_CMD_BLIT_SCREEN_TO_GMRFB: |
| 2866 | *size = sizeof(uint32_t) + sizeof(SVGAFifoCmdBlitGMRFBToScreen); |
| 2867 | break; |
| 2868 | default: |
| 2869 | DRM_ERROR("Unsupported SVGA command: %u.\n", cmd_id); |
| 2870 | return -EINVAL; |
| 2871 | } |
| 2872 | |
| 2873 | if (*size > size_remaining) { |
| 2874 | DRM_ERROR("Invalid SVGA command (size mismatch):" |
| 2875 | " %u.\n", cmd_id); |
| 2876 | return -EINVAL; |
| 2877 | } |
| 2878 | |
Jakob Bornecrantz | 0cff60c | 2011-10-04 20:13:27 +0200 | [diff] [blame] | 2879 | if (unlikely(!sw_context->kernel)) { |
Jakob Bornecrantz | 4084fb8 | 2011-10-04 20:13:19 +0200 | [diff] [blame] | 2880 | DRM_ERROR("Kernel only SVGA command: %u.\n", cmd_id); |
| 2881 | return -EPERM; |
| 2882 | } |
| 2883 | |
| 2884 | if (cmd_id == SVGA_CMD_DEFINE_GMRFB) |
| 2885 | return vmw_cmd_check_define_gmrfb(dev_priv, sw_context, buf); |
| 2886 | |
| 2887 | return 0; |
| 2888 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 2889 | |
Thomas Hellstrom | 4fbd9d2 | 2014-02-12 12:37:01 +0100 | [diff] [blame] | 2890 | static const struct vmw_cmd_entry vmw_cmd_entries[SVGA_3D_CMD_MAX] = { |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 2891 | VMW_CMD_DEF(SVGA_3D_CMD_SURFACE_DEFINE, &vmw_cmd_invalid, |
| 2892 | false, false, false), |
| 2893 | VMW_CMD_DEF(SVGA_3D_CMD_SURFACE_DESTROY, &vmw_cmd_invalid, |
| 2894 | false, false, false), |
| 2895 | VMW_CMD_DEF(SVGA_3D_CMD_SURFACE_COPY, &vmw_cmd_surface_copy_check, |
| 2896 | true, false, false), |
| 2897 | VMW_CMD_DEF(SVGA_3D_CMD_SURFACE_STRETCHBLT, &vmw_cmd_stretch_blt_check, |
| 2898 | true, false, false), |
| 2899 | VMW_CMD_DEF(SVGA_3D_CMD_SURFACE_DMA, &vmw_cmd_dma, |
| 2900 | true, false, false), |
| 2901 | VMW_CMD_DEF(SVGA_3D_CMD_CONTEXT_DEFINE, &vmw_cmd_invalid, |
| 2902 | false, false, false), |
| 2903 | VMW_CMD_DEF(SVGA_3D_CMD_CONTEXT_DESTROY, &vmw_cmd_invalid, |
| 2904 | false, false, false), |
| 2905 | VMW_CMD_DEF(SVGA_3D_CMD_SETTRANSFORM, &vmw_cmd_cid_check, |
| 2906 | true, false, false), |
| 2907 | VMW_CMD_DEF(SVGA_3D_CMD_SETZRANGE, &vmw_cmd_cid_check, |
| 2908 | true, false, false), |
| 2909 | VMW_CMD_DEF(SVGA_3D_CMD_SETRENDERSTATE, &vmw_cmd_cid_check, |
| 2910 | true, false, false), |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 2911 | VMW_CMD_DEF(SVGA_3D_CMD_SETRENDERTARGET, |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 2912 | &vmw_cmd_set_render_target_check, true, false, false), |
| 2913 | VMW_CMD_DEF(SVGA_3D_CMD_SETTEXTURESTATE, &vmw_cmd_tex_state, |
| 2914 | true, false, false), |
| 2915 | VMW_CMD_DEF(SVGA_3D_CMD_SETMATERIAL, &vmw_cmd_cid_check, |
| 2916 | true, false, false), |
| 2917 | VMW_CMD_DEF(SVGA_3D_CMD_SETLIGHTDATA, &vmw_cmd_cid_check, |
| 2918 | true, false, false), |
| 2919 | VMW_CMD_DEF(SVGA_3D_CMD_SETLIGHTENABLED, &vmw_cmd_cid_check, |
| 2920 | true, false, false), |
| 2921 | VMW_CMD_DEF(SVGA_3D_CMD_SETVIEWPORT, &vmw_cmd_cid_check, |
| 2922 | true, false, false), |
| 2923 | VMW_CMD_DEF(SVGA_3D_CMD_SETCLIPPLANE, &vmw_cmd_cid_check, |
| 2924 | true, false, false), |
| 2925 | VMW_CMD_DEF(SVGA_3D_CMD_CLEAR, &vmw_cmd_cid_check, |
| 2926 | true, false, false), |
| 2927 | VMW_CMD_DEF(SVGA_3D_CMD_PRESENT, &vmw_cmd_present_check, |
| 2928 | false, false, false), |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 2929 | VMW_CMD_DEF(SVGA_3D_CMD_SHADER_DEFINE, &vmw_cmd_shader_define, |
| 2930 | true, false, false), |
| 2931 | VMW_CMD_DEF(SVGA_3D_CMD_SHADER_DESTROY, &vmw_cmd_shader_destroy, |
| 2932 | true, false, false), |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 2933 | VMW_CMD_DEF(SVGA_3D_CMD_SET_SHADER, &vmw_cmd_set_shader, |
| 2934 | true, false, false), |
Thomas Hellstrom | 0ccbbae | 2014-01-30 11:13:43 +0100 | [diff] [blame] | 2935 | VMW_CMD_DEF(SVGA_3D_CMD_SET_SHADER_CONST, &vmw_cmd_set_shader_const, |
| 2936 | true, false, false), |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 2937 | VMW_CMD_DEF(SVGA_3D_CMD_DRAW_PRIMITIVES, &vmw_cmd_draw, |
| 2938 | true, false, false), |
| 2939 | VMW_CMD_DEF(SVGA_3D_CMD_SETSCISSORRECT, &vmw_cmd_cid_check, |
| 2940 | true, false, false), |
| 2941 | VMW_CMD_DEF(SVGA_3D_CMD_BEGIN_QUERY, &vmw_cmd_begin_query, |
| 2942 | true, false, false), |
| 2943 | VMW_CMD_DEF(SVGA_3D_CMD_END_QUERY, &vmw_cmd_end_query, |
| 2944 | true, false, false), |
| 2945 | VMW_CMD_DEF(SVGA_3D_CMD_WAIT_FOR_QUERY, &vmw_cmd_wait_query, |
| 2946 | true, false, false), |
| 2947 | VMW_CMD_DEF(SVGA_3D_CMD_PRESENT_READBACK, &vmw_cmd_ok, |
| 2948 | true, false, false), |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 2949 | VMW_CMD_DEF(SVGA_3D_CMD_BLIT_SURFACE_TO_SCREEN, |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 2950 | &vmw_cmd_blt_surf_screen_check, false, false, false), |
| 2951 | VMW_CMD_DEF(SVGA_3D_CMD_SURFACE_DEFINE_V2, &vmw_cmd_invalid, |
| 2952 | false, false, false), |
| 2953 | VMW_CMD_DEF(SVGA_3D_CMD_GENERATE_MIPMAPS, &vmw_cmd_invalid, |
| 2954 | false, false, false), |
| 2955 | VMW_CMD_DEF(SVGA_3D_CMD_ACTIVATE_SURFACE, &vmw_cmd_invalid, |
| 2956 | false, false, false), |
| 2957 | VMW_CMD_DEF(SVGA_3D_CMD_DEACTIVATE_SURFACE, &vmw_cmd_invalid, |
| 2958 | false, false, false), |
| 2959 | VMW_CMD_DEF(SVGA_3D_CMD_SCREEN_DMA, &vmw_cmd_invalid, |
| 2960 | false, false, false), |
Deepak Rawat | dc75e73 | 2018-06-13 13:53:28 -0700 | [diff] [blame] | 2961 | VMW_CMD_DEF(SVGA_3D_CMD_DEAD1, &vmw_cmd_invalid, |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 2962 | false, false, false), |
Deepak Rawat | dc75e73 | 2018-06-13 13:53:28 -0700 | [diff] [blame] | 2963 | VMW_CMD_DEF(SVGA_3D_CMD_DEAD2, &vmw_cmd_invalid, |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 2964 | false, false, false), |
| 2965 | VMW_CMD_DEF(SVGA_3D_CMD_LOGICOPS_BITBLT, &vmw_cmd_invalid, |
| 2966 | false, false, false), |
| 2967 | VMW_CMD_DEF(SVGA_3D_CMD_LOGICOPS_TRANSBLT, &vmw_cmd_invalid, |
| 2968 | false, false, false), |
| 2969 | VMW_CMD_DEF(SVGA_3D_CMD_LOGICOPS_STRETCHBLT, &vmw_cmd_invalid, |
| 2970 | false, false, false), |
| 2971 | VMW_CMD_DEF(SVGA_3D_CMD_LOGICOPS_COLORFILL, &vmw_cmd_invalid, |
| 2972 | false, false, false), |
| 2973 | VMW_CMD_DEF(SVGA_3D_CMD_LOGICOPS_ALPHABLEND, &vmw_cmd_invalid, |
| 2974 | false, false, false), |
| 2975 | VMW_CMD_DEF(SVGA_3D_CMD_LOGICOPS_CLEARTYPEBLEND, &vmw_cmd_invalid, |
| 2976 | false, false, false), |
| 2977 | VMW_CMD_DEF(SVGA_3D_CMD_SET_OTABLE_BASE, &vmw_cmd_invalid, |
| 2978 | false, false, true), |
| 2979 | VMW_CMD_DEF(SVGA_3D_CMD_READBACK_OTABLE, &vmw_cmd_invalid, |
| 2980 | false, false, true), |
| 2981 | VMW_CMD_DEF(SVGA_3D_CMD_DEFINE_GB_MOB, &vmw_cmd_invalid, |
| 2982 | false, false, true), |
| 2983 | VMW_CMD_DEF(SVGA_3D_CMD_DESTROY_GB_MOB, &vmw_cmd_invalid, |
| 2984 | false, false, true), |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 2985 | VMW_CMD_DEF(SVGA_3D_CMD_REDEFINE_GB_MOB64, &vmw_cmd_invalid, |
| 2986 | false, false, true), |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 2987 | VMW_CMD_DEF(SVGA_3D_CMD_UPDATE_GB_MOB_MAPPING, &vmw_cmd_invalid, |
| 2988 | false, false, true), |
| 2989 | VMW_CMD_DEF(SVGA_3D_CMD_DEFINE_GB_SURFACE, &vmw_cmd_invalid, |
| 2990 | false, false, true), |
| 2991 | VMW_CMD_DEF(SVGA_3D_CMD_DESTROY_GB_SURFACE, &vmw_cmd_invalid, |
| 2992 | false, false, true), |
| 2993 | VMW_CMD_DEF(SVGA_3D_CMD_BIND_GB_SURFACE, &vmw_cmd_bind_gb_surface, |
| 2994 | true, false, true), |
| 2995 | VMW_CMD_DEF(SVGA_3D_CMD_COND_BIND_GB_SURFACE, &vmw_cmd_invalid, |
| 2996 | false, false, true), |
| 2997 | VMW_CMD_DEF(SVGA_3D_CMD_UPDATE_GB_IMAGE, &vmw_cmd_update_gb_image, |
| 2998 | true, false, true), |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 2999 | VMW_CMD_DEF(SVGA_3D_CMD_UPDATE_GB_SURFACE, |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 3000 | &vmw_cmd_update_gb_surface, true, false, true), |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 3001 | VMW_CMD_DEF(SVGA_3D_CMD_READBACK_GB_IMAGE, |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 3002 | &vmw_cmd_readback_gb_image, true, false, true), |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 3003 | VMW_CMD_DEF(SVGA_3D_CMD_READBACK_GB_SURFACE, |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 3004 | &vmw_cmd_readback_gb_surface, true, false, true), |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 3005 | VMW_CMD_DEF(SVGA_3D_CMD_INVALIDATE_GB_IMAGE, |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 3006 | &vmw_cmd_invalidate_gb_image, true, false, true), |
Thomas Hellstrom | a97e219 | 2012-11-21 11:45:13 +0100 | [diff] [blame] | 3007 | VMW_CMD_DEF(SVGA_3D_CMD_INVALIDATE_GB_SURFACE, |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 3008 | &vmw_cmd_invalidate_gb_surface, true, false, true), |
| 3009 | VMW_CMD_DEF(SVGA_3D_CMD_DEFINE_GB_CONTEXT, &vmw_cmd_invalid, |
| 3010 | false, false, true), |
| 3011 | VMW_CMD_DEF(SVGA_3D_CMD_DESTROY_GB_CONTEXT, &vmw_cmd_invalid, |
| 3012 | false, false, true), |
| 3013 | VMW_CMD_DEF(SVGA_3D_CMD_BIND_GB_CONTEXT, &vmw_cmd_invalid, |
| 3014 | false, false, true), |
| 3015 | VMW_CMD_DEF(SVGA_3D_CMD_READBACK_GB_CONTEXT, &vmw_cmd_invalid, |
| 3016 | false, false, true), |
| 3017 | VMW_CMD_DEF(SVGA_3D_CMD_INVALIDATE_GB_CONTEXT, &vmw_cmd_invalid, |
| 3018 | false, false, true), |
| 3019 | VMW_CMD_DEF(SVGA_3D_CMD_DEFINE_GB_SHADER, &vmw_cmd_invalid, |
| 3020 | false, false, true), |
| 3021 | VMW_CMD_DEF(SVGA_3D_CMD_BIND_GB_SHADER, &vmw_cmd_bind_gb_shader, |
| 3022 | true, false, true), |
| 3023 | VMW_CMD_DEF(SVGA_3D_CMD_DESTROY_GB_SHADER, &vmw_cmd_invalid, |
| 3024 | false, false, true), |
Thomas Hellstrom | f2a0dcb | 2014-01-15 10:04:07 +0100 | [diff] [blame] | 3025 | VMW_CMD_DEF(SVGA_3D_CMD_SET_OTABLE_BASE64, &vmw_cmd_invalid, |
Thomas Hellstrom | 8ba0731 | 2013-10-08 02:25:35 -0700 | [diff] [blame] | 3026 | false, false, false), |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 3027 | VMW_CMD_DEF(SVGA_3D_CMD_BEGIN_GB_QUERY, &vmw_cmd_begin_gb_query, |
| 3028 | true, false, true), |
| 3029 | VMW_CMD_DEF(SVGA_3D_CMD_END_GB_QUERY, &vmw_cmd_end_gb_query, |
| 3030 | true, false, true), |
| 3031 | VMW_CMD_DEF(SVGA_3D_CMD_WAIT_FOR_GB_QUERY, &vmw_cmd_wait_gb_query, |
| 3032 | true, false, true), |
| 3033 | VMW_CMD_DEF(SVGA_3D_CMD_NOP, &vmw_cmd_ok, |
| 3034 | true, false, true), |
Thomas Hellstrom | 5f55be5f | 2017-08-24 08:06:30 +0200 | [diff] [blame] | 3035 | VMW_CMD_DEF(SVGA_3D_CMD_NOP_ERROR, &vmw_cmd_ok, |
| 3036 | true, false, true), |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 3037 | VMW_CMD_DEF(SVGA_3D_CMD_ENABLE_GART, &vmw_cmd_invalid, |
| 3038 | false, false, true), |
| 3039 | VMW_CMD_DEF(SVGA_3D_CMD_DISABLE_GART, &vmw_cmd_invalid, |
| 3040 | false, false, true), |
| 3041 | VMW_CMD_DEF(SVGA_3D_CMD_MAP_MOB_INTO_GART, &vmw_cmd_invalid, |
| 3042 | false, false, true), |
| 3043 | VMW_CMD_DEF(SVGA_3D_CMD_UNMAP_GART_RANGE, &vmw_cmd_invalid, |
| 3044 | false, false, true), |
| 3045 | VMW_CMD_DEF(SVGA_3D_CMD_DEFINE_GB_SCREENTARGET, &vmw_cmd_invalid, |
| 3046 | false, false, true), |
| 3047 | VMW_CMD_DEF(SVGA_3D_CMD_DESTROY_GB_SCREENTARGET, &vmw_cmd_invalid, |
| 3048 | false, false, true), |
| 3049 | VMW_CMD_DEF(SVGA_3D_CMD_BIND_GB_SCREENTARGET, &vmw_cmd_invalid, |
| 3050 | false, false, true), |
| 3051 | VMW_CMD_DEF(SVGA_3D_CMD_UPDATE_GB_SCREENTARGET, &vmw_cmd_invalid, |
| 3052 | false, false, true), |
| 3053 | VMW_CMD_DEF(SVGA_3D_CMD_READBACK_GB_IMAGE_PARTIAL, &vmw_cmd_invalid, |
| 3054 | false, false, true), |
| 3055 | VMW_CMD_DEF(SVGA_3D_CMD_INVALIDATE_GB_IMAGE_PARTIAL, &vmw_cmd_invalid, |
| 3056 | false, false, true), |
| 3057 | VMW_CMD_DEF(SVGA_3D_CMD_SET_GB_SHADERCONSTS_INLINE, &vmw_cmd_cid_check, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3058 | true, false, true), |
| 3059 | VMW_CMD_DEF(SVGA_3D_CMD_GB_SCREEN_DMA, &vmw_cmd_invalid, |
| 3060 | false, false, true), |
| 3061 | VMW_CMD_DEF(SVGA_3D_CMD_BIND_GB_SURFACE_WITH_PITCH, &vmw_cmd_invalid, |
| 3062 | false, false, true), |
| 3063 | VMW_CMD_DEF(SVGA_3D_CMD_GB_MOB_FENCE, &vmw_cmd_invalid, |
| 3064 | false, false, true), |
| 3065 | VMW_CMD_DEF(SVGA_3D_CMD_DEFINE_GB_SURFACE_V2, &vmw_cmd_invalid, |
| 3066 | false, false, true), |
| 3067 | |
| 3068 | /* |
| 3069 | * DX commands |
| 3070 | */ |
| 3071 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_CONTEXT, &vmw_cmd_invalid, |
| 3072 | false, false, true), |
| 3073 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_CONTEXT, &vmw_cmd_invalid, |
| 3074 | false, false, true), |
| 3075 | VMW_CMD_DEF(SVGA_3D_CMD_DX_BIND_CONTEXT, &vmw_cmd_invalid, |
| 3076 | false, false, true), |
| 3077 | VMW_CMD_DEF(SVGA_3D_CMD_DX_READBACK_CONTEXT, &vmw_cmd_invalid, |
| 3078 | false, false, true), |
| 3079 | VMW_CMD_DEF(SVGA_3D_CMD_DX_INVALIDATE_CONTEXT, &vmw_cmd_invalid, |
| 3080 | false, false, true), |
| 3081 | VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_SINGLE_CONSTANT_BUFFER, |
| 3082 | &vmw_cmd_dx_set_single_constant_buffer, true, false, true), |
| 3083 | VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_SHADER_RESOURCES, |
| 3084 | &vmw_cmd_dx_set_shader_res, true, false, true), |
| 3085 | VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_SHADER, &vmw_cmd_dx_set_shader, |
| 3086 | true, false, true), |
Charmaine Lee | 2f633e5 | 2015-08-10 10:45:11 -0700 | [diff] [blame] | 3087 | VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_SAMPLERS, &vmw_cmd_dx_cid_check, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3088 | true, false, true), |
Charmaine Lee | 2f633e5 | 2015-08-10 10:45:11 -0700 | [diff] [blame] | 3089 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DRAW, &vmw_cmd_dx_cid_check, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3090 | true, false, true), |
Charmaine Lee | 2f633e5 | 2015-08-10 10:45:11 -0700 | [diff] [blame] | 3091 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DRAW_INDEXED, &vmw_cmd_dx_cid_check, |
| 3092 | true, false, true), |
| 3093 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DRAW_INSTANCED, &vmw_cmd_dx_cid_check, |
| 3094 | true, false, true), |
| 3095 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DRAW_INDEXED_INSTANCED, |
| 3096 | &vmw_cmd_dx_cid_check, true, false, true), |
| 3097 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DRAW_AUTO, &vmw_cmd_dx_cid_check, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3098 | true, false, true), |
| 3099 | VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_VERTEX_BUFFERS, |
| 3100 | &vmw_cmd_dx_set_vertex_buffers, true, false, true), |
| 3101 | VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_INDEX_BUFFER, |
| 3102 | &vmw_cmd_dx_set_index_buffer, true, false, true), |
| 3103 | VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_RENDERTARGETS, |
| 3104 | &vmw_cmd_dx_set_rendertargets, true, false, true), |
| 3105 | VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_BLEND_STATE, &vmw_cmd_dx_cid_check, |
| 3106 | true, false, true), |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3107 | VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_DEPTHSTENCIL_STATE, |
Charmaine Lee | 2f633e5 | 2015-08-10 10:45:11 -0700 | [diff] [blame] | 3108 | &vmw_cmd_dx_cid_check, true, false, true), |
| 3109 | VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_RASTERIZER_STATE, |
| 3110 | &vmw_cmd_dx_cid_check, true, false, true), |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 3111 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_QUERY, &vmw_cmd_dx_define_query, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3112 | true, false, true), |
Charmaine Lee | e02e588 | 2016-04-12 08:19:08 -0700 | [diff] [blame] | 3113 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_QUERY, &vmw_cmd_dx_cid_check, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3114 | true, false, true), |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 3115 | VMW_CMD_DEF(SVGA_3D_CMD_DX_BIND_QUERY, &vmw_cmd_dx_bind_query, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3116 | true, false, true), |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 3117 | VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_QUERY_OFFSET, |
Charmaine Lee | e02e588 | 2016-04-12 08:19:08 -0700 | [diff] [blame] | 3118 | &vmw_cmd_dx_cid_check, true, false, true), |
| 3119 | VMW_CMD_DEF(SVGA_3D_CMD_DX_BEGIN_QUERY, &vmw_cmd_dx_cid_check, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3120 | true, false, true), |
Charmaine Lee | e02e588 | 2016-04-12 08:19:08 -0700 | [diff] [blame] | 3121 | VMW_CMD_DEF(SVGA_3D_CMD_DX_END_QUERY, &vmw_cmd_dx_cid_check, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3122 | true, false, true), |
| 3123 | VMW_CMD_DEF(SVGA_3D_CMD_DX_READBACK_QUERY, &vmw_cmd_invalid, |
| 3124 | true, false, true), |
Charmaine Lee | 1883598 | 2016-04-12 08:14:23 -0700 | [diff] [blame] | 3125 | VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_PREDICATION, &vmw_cmd_dx_cid_check, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3126 | true, false, true), |
| 3127 | VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_VIEWPORTS, &vmw_cmd_dx_cid_check, |
| 3128 | true, false, true), |
| 3129 | VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_SCISSORRECTS, &vmw_cmd_dx_cid_check, |
| 3130 | true, false, true), |
| 3131 | VMW_CMD_DEF(SVGA_3D_CMD_DX_CLEAR_RENDERTARGET_VIEW, |
| 3132 | &vmw_cmd_dx_clear_rendertarget_view, true, false, true), |
| 3133 | VMW_CMD_DEF(SVGA_3D_CMD_DX_CLEAR_DEPTHSTENCIL_VIEW, |
| 3134 | &vmw_cmd_dx_clear_depthstencil_view, true, false, true), |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3135 | VMW_CMD_DEF(SVGA_3D_CMD_DX_PRED_COPY, &vmw_cmd_invalid, |
| 3136 | true, false, true), |
Charmaine Lee | f3b33550 | 2016-02-12 08:11:56 +0100 | [diff] [blame] | 3137 | VMW_CMD_DEF(SVGA_3D_CMD_DX_GENMIPS, &vmw_cmd_dx_genmips, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3138 | true, false, true), |
| 3139 | VMW_CMD_DEF(SVGA_3D_CMD_DX_UPDATE_SUBRESOURCE, |
| 3140 | &vmw_cmd_dx_check_subresource, true, false, true), |
| 3141 | VMW_CMD_DEF(SVGA_3D_CMD_DX_READBACK_SUBRESOURCE, |
| 3142 | &vmw_cmd_dx_check_subresource, true, false, true), |
| 3143 | VMW_CMD_DEF(SVGA_3D_CMD_DX_INVALIDATE_SUBRESOURCE, |
| 3144 | &vmw_cmd_dx_check_subresource, true, false, true), |
| 3145 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_SHADERRESOURCE_VIEW, |
| 3146 | &vmw_cmd_dx_view_define, true, false, true), |
| 3147 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_SHADERRESOURCE_VIEW, |
| 3148 | &vmw_cmd_dx_view_remove, true, false, true), |
| 3149 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_RENDERTARGET_VIEW, |
| 3150 | &vmw_cmd_dx_view_define, true, false, true), |
| 3151 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_RENDERTARGET_VIEW, |
| 3152 | &vmw_cmd_dx_view_remove, true, false, true), |
| 3153 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_VIEW, |
| 3154 | &vmw_cmd_dx_view_define, true, false, true), |
| 3155 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_DEPTHSTENCIL_VIEW, |
| 3156 | &vmw_cmd_dx_view_remove, true, false, true), |
| 3157 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_ELEMENTLAYOUT, |
| 3158 | &vmw_cmd_dx_so_define, true, false, true), |
| 3159 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_ELEMENTLAYOUT, |
| 3160 | &vmw_cmd_dx_cid_check, true, false, true), |
| 3161 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_BLEND_STATE, |
| 3162 | &vmw_cmd_dx_so_define, true, false, true), |
| 3163 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_BLEND_STATE, |
| 3164 | &vmw_cmd_dx_cid_check, true, false, true), |
| 3165 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_DEPTHSTENCIL_STATE, |
| 3166 | &vmw_cmd_dx_so_define, true, false, true), |
| 3167 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_DEPTHSTENCIL_STATE, |
| 3168 | &vmw_cmd_dx_cid_check, true, false, true), |
| 3169 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_RASTERIZER_STATE, |
| 3170 | &vmw_cmd_dx_so_define, true, false, true), |
| 3171 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_RASTERIZER_STATE, |
| 3172 | &vmw_cmd_dx_cid_check, true, false, true), |
| 3173 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_SAMPLER_STATE, |
| 3174 | &vmw_cmd_dx_so_define, true, false, true), |
| 3175 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_SAMPLER_STATE, |
| 3176 | &vmw_cmd_dx_cid_check, true, false, true), |
| 3177 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_SHADER, |
| 3178 | &vmw_cmd_dx_define_shader, true, false, true), |
| 3179 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_SHADER, |
| 3180 | &vmw_cmd_dx_destroy_shader, true, false, true), |
| 3181 | VMW_CMD_DEF(SVGA_3D_CMD_DX_BIND_SHADER, |
| 3182 | &vmw_cmd_dx_bind_shader, true, false, true), |
| 3183 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DEFINE_STREAMOUTPUT, |
| 3184 | &vmw_cmd_dx_so_define, true, false, true), |
| 3185 | VMW_CMD_DEF(SVGA_3D_CMD_DX_DESTROY_STREAMOUTPUT, |
| 3186 | &vmw_cmd_dx_cid_check, true, false, true), |
Charmaine Lee | 2f633e5 | 2015-08-10 10:45:11 -0700 | [diff] [blame] | 3187 | VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_STREAMOUTPUT, &vmw_cmd_dx_cid_check, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3188 | true, false, true), |
Charmaine Lee | 2f633e5 | 2015-08-10 10:45:11 -0700 | [diff] [blame] | 3189 | VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_SOTARGETS, |
| 3190 | &vmw_cmd_dx_set_so_targets, true, false, true), |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3191 | VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_INPUT_LAYOUT, |
| 3192 | &vmw_cmd_dx_cid_check, true, false, true), |
| 3193 | VMW_CMD_DEF(SVGA_3D_CMD_DX_SET_TOPOLOGY, |
| 3194 | &vmw_cmd_dx_cid_check, true, false, true), |
Neha Bhende | 0fca749e | 2015-08-10 10:51:07 -0700 | [diff] [blame] | 3195 | VMW_CMD_DEF(SVGA_3D_CMD_DX_BUFFER_COPY, |
| 3196 | &vmw_cmd_buffer_copy_check, true, false, true), |
| 3197 | VMW_CMD_DEF(SVGA_3D_CMD_DX_PRED_COPY_REGION, |
| 3198 | &vmw_cmd_pred_copy_check, true, false, true), |
Charmaine Lee | 1f982e4 | 2016-10-10 10:37:03 -0700 | [diff] [blame] | 3199 | VMW_CMD_DEF(SVGA_3D_CMD_DX_TRANSFER_FROM_BUFFER, |
| 3200 | &vmw_cmd_dx_transfer_from_buffer, |
| 3201 | true, false, true), |
Neha Bhende | 0d81d34 | 2018-06-18 17:14:56 -0700 | [diff] [blame] | 3202 | VMW_CMD_DEF(SVGA_3D_CMD_INTRA_SURFACE_COPY, &vmw_cmd_intra_surface_copy, |
| 3203 | true, false, true), |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3204 | }; |
| 3205 | |
Thomas Hellstrom | 65b97a2 | 2017-08-24 08:06:29 +0200 | [diff] [blame] | 3206 | bool vmw_cmd_describe(const void *buf, u32 *size, char const **cmd) |
| 3207 | { |
| 3208 | u32 cmd_id = ((u32 *) buf)[0]; |
| 3209 | |
| 3210 | if (cmd_id >= SVGA_CMD_MAX) { |
| 3211 | SVGA3dCmdHeader *header = (SVGA3dCmdHeader *) buf; |
| 3212 | const struct vmw_cmd_entry *entry; |
| 3213 | |
| 3214 | *size = header->size + sizeof(SVGA3dCmdHeader); |
| 3215 | cmd_id = header->id; |
| 3216 | if (cmd_id >= SVGA_3D_CMD_MAX) |
| 3217 | return false; |
| 3218 | |
| 3219 | cmd_id -= SVGA_3D_CMD_BASE; |
| 3220 | entry = &vmw_cmd_entries[cmd_id]; |
| 3221 | *cmd = entry->cmd_name; |
| 3222 | return true; |
| 3223 | } |
| 3224 | |
| 3225 | switch (cmd_id) { |
| 3226 | case SVGA_CMD_UPDATE: |
| 3227 | *cmd = "SVGA_CMD_UPDATE"; |
| 3228 | *size = sizeof(u32) + sizeof(SVGAFifoCmdUpdate); |
| 3229 | break; |
| 3230 | case SVGA_CMD_DEFINE_GMRFB: |
| 3231 | *cmd = "SVGA_CMD_DEFINE_GMRFB"; |
| 3232 | *size = sizeof(u32) + sizeof(SVGAFifoCmdDefineGMRFB); |
| 3233 | break; |
| 3234 | case SVGA_CMD_BLIT_GMRFB_TO_SCREEN: |
| 3235 | *cmd = "SVGA_CMD_BLIT_GMRFB_TO_SCREEN"; |
| 3236 | *size = sizeof(u32) + sizeof(SVGAFifoCmdBlitGMRFBToScreen); |
| 3237 | break; |
| 3238 | case SVGA_CMD_BLIT_SCREEN_TO_GMRFB: |
| 3239 | *cmd = "SVGA_CMD_BLIT_SCREEN_TO_GMRFB"; |
| 3240 | *size = sizeof(u32) + sizeof(SVGAFifoCmdBlitGMRFBToScreen); |
| 3241 | break; |
| 3242 | default: |
| 3243 | *cmd = "UNKNOWN"; |
| 3244 | *size = 0; |
| 3245 | return false; |
| 3246 | } |
| 3247 | |
| 3248 | return true; |
| 3249 | } |
| 3250 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3251 | static int vmw_cmd_check(struct vmw_private *dev_priv, |
| 3252 | struct vmw_sw_context *sw_context, |
| 3253 | void *buf, uint32_t *size) |
| 3254 | { |
| 3255 | uint32_t cmd_id; |
Thomas Hellstrom | 7a73ba7 | 2009-12-22 16:53:41 +0100 | [diff] [blame] | 3256 | uint32_t size_remaining = *size; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3257 | SVGA3dCmdHeader *header = (SVGA3dCmdHeader *) buf; |
| 3258 | int ret; |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 3259 | const struct vmw_cmd_entry *entry; |
| 3260 | bool gb = dev_priv->capabilities & SVGA_CAP_GBOBJECTS; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3261 | |
Thomas Hellstrom | b9eb1a6 | 2015-04-02 02:39:45 -0700 | [diff] [blame] | 3262 | cmd_id = ((uint32_t *)buf)[0]; |
Jakob Bornecrantz | 4084fb8 | 2011-10-04 20:13:19 +0200 | [diff] [blame] | 3263 | /* Handle any none 3D commands */ |
| 3264 | if (unlikely(cmd_id < SVGA_CMD_MAX)) |
| 3265 | return vmw_cmd_check_not_3d(dev_priv, sw_context, buf, size); |
| 3266 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3267 | |
Thomas Hellstrom | b9eb1a6 | 2015-04-02 02:39:45 -0700 | [diff] [blame] | 3268 | cmd_id = header->id; |
| 3269 | *size = header->size + sizeof(SVGA3dCmdHeader); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3270 | |
| 3271 | cmd_id -= SVGA_3D_CMD_BASE; |
Thomas Hellstrom | 7a73ba7 | 2009-12-22 16:53:41 +0100 | [diff] [blame] | 3272 | if (unlikely(*size > size_remaining)) |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 3273 | goto out_invalid; |
Thomas Hellstrom | 7a73ba7 | 2009-12-22 16:53:41 +0100 | [diff] [blame] | 3274 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3275 | if (unlikely(cmd_id >= SVGA_3D_CMD_MAX - SVGA_3D_CMD_BASE)) |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 3276 | goto out_invalid; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3277 | |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 3278 | entry = &vmw_cmd_entries[cmd_id]; |
Thomas Hellstrom | 36e952c | 2014-02-12 13:19:36 +0100 | [diff] [blame] | 3279 | if (unlikely(!entry->func)) |
| 3280 | goto out_invalid; |
| 3281 | |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 3282 | if (unlikely(!entry->user_allow && !sw_context->kernel)) |
| 3283 | goto out_privileged; |
| 3284 | |
| 3285 | if (unlikely(entry->gb_disable && gb)) |
| 3286 | goto out_old; |
| 3287 | |
| 3288 | if (unlikely(entry->gb_enable && !gb)) |
| 3289 | goto out_new; |
| 3290 | |
| 3291 | ret = entry->func(dev_priv, sw_context, header); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3292 | if (unlikely(ret != 0)) |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 3293 | goto out_invalid; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3294 | |
| 3295 | return 0; |
Thomas Hellstrom | c373d4e | 2012-11-21 12:22:35 +0100 | [diff] [blame] | 3296 | out_invalid: |
| 3297 | DRM_ERROR("Invalid SVGA3D command: %d\n", |
| 3298 | cmd_id + SVGA_3D_CMD_BASE); |
| 3299 | return -EINVAL; |
| 3300 | out_privileged: |
| 3301 | DRM_ERROR("Privileged SVGA3D command: %d\n", |
| 3302 | cmd_id + SVGA_3D_CMD_BASE); |
| 3303 | return -EPERM; |
| 3304 | out_old: |
| 3305 | DRM_ERROR("Deprecated (disallowed) SVGA3D command: %d\n", |
| 3306 | cmd_id + SVGA_3D_CMD_BASE); |
| 3307 | return -EINVAL; |
| 3308 | out_new: |
| 3309 | DRM_ERROR("SVGA3D command: %d not supported by virtual hardware.\n", |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3310 | cmd_id + SVGA_3D_CMD_BASE); |
| 3311 | return -EINVAL; |
| 3312 | } |
| 3313 | |
| 3314 | static int vmw_cmd_check_all(struct vmw_private *dev_priv, |
| 3315 | struct vmw_sw_context *sw_context, |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 3316 | void *buf, |
Thomas Hellstrom | be38ab6 | 2011-08-31 07:42:54 +0000 | [diff] [blame] | 3317 | uint32_t size) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3318 | { |
| 3319 | int32_t cur_size = size; |
| 3320 | int ret; |
| 3321 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3322 | sw_context->buf_start = buf; |
| 3323 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3324 | while (cur_size > 0) { |
Thomas Hellstrom | 7a73ba7 | 2009-12-22 16:53:41 +0100 | [diff] [blame] | 3325 | size = cur_size; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3326 | ret = vmw_cmd_check(dev_priv, sw_context, buf, &size); |
| 3327 | if (unlikely(ret != 0)) |
| 3328 | return ret; |
| 3329 | buf = (void *)((unsigned long) buf + size); |
| 3330 | cur_size -= size; |
| 3331 | } |
| 3332 | |
| 3333 | if (unlikely(cur_size != 0)) { |
| 3334 | DRM_ERROR("Command verifier out of sync.\n"); |
| 3335 | return -EINVAL; |
| 3336 | } |
| 3337 | |
| 3338 | return 0; |
| 3339 | } |
| 3340 | |
| 3341 | static void vmw_free_relocations(struct vmw_sw_context *sw_context) |
| 3342 | { |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 3343 | /* Memory is validation context memory, so no need to free it */ |
| 3344 | |
| 3345 | INIT_LIST_HEAD(&sw_context->bo_relocations); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3346 | } |
| 3347 | |
| 3348 | static void vmw_apply_relocations(struct vmw_sw_context *sw_context) |
| 3349 | { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3350 | struct vmw_relocation *reloc; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3351 | struct ttm_buffer_object *bo; |
| 3352 | |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 3353 | list_for_each_entry(reloc, &sw_context->bo_relocations, head) { |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 3354 | bo = &reloc->vbo->base; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3355 | switch (bo->mem.mem_type) { |
| 3356 | case TTM_PL_VRAM: |
Thomas Hellstrom | 135cba0 | 2010-10-26 21:21:47 +0200 | [diff] [blame] | 3357 | reloc->location->offset += bo->offset; |
| 3358 | reloc->location->gmrId = SVGA_GMR_FRAMEBUFFER; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3359 | break; |
| 3360 | case VMW_PL_GMR: |
Thomas Hellstrom | 135cba0 | 2010-10-26 21:21:47 +0200 | [diff] [blame] | 3361 | reloc->location->gmrId = bo->mem.start; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3362 | break; |
Thomas Hellstrom | ddcda24 | 2012-11-21 11:26:55 +0100 | [diff] [blame] | 3363 | case VMW_PL_MOB: |
| 3364 | *reloc->mob_loc = bo->mem.start; |
| 3365 | break; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3366 | default: |
| 3367 | BUG(); |
| 3368 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3369 | } |
| 3370 | vmw_free_relocations(sw_context); |
| 3371 | } |
| 3372 | |
Thomas Hellstrom | be38ab6 | 2011-08-31 07:42:54 +0000 | [diff] [blame] | 3373 | static int vmw_resize_cmd_bounce(struct vmw_sw_context *sw_context, |
| 3374 | uint32_t size) |
| 3375 | { |
| 3376 | if (likely(sw_context->cmd_bounce_size >= size)) |
| 3377 | return 0; |
| 3378 | |
| 3379 | if (sw_context->cmd_bounce_size == 0) |
| 3380 | sw_context->cmd_bounce_size = VMWGFX_CMD_BOUNCE_INIT_SIZE; |
| 3381 | |
| 3382 | while (sw_context->cmd_bounce_size < size) { |
| 3383 | sw_context->cmd_bounce_size = |
| 3384 | PAGE_ALIGN(sw_context->cmd_bounce_size + |
| 3385 | (sw_context->cmd_bounce_size >> 1)); |
| 3386 | } |
| 3387 | |
Markus Elfring | 0bc3299 | 2016-07-22 13:31:00 +0200 | [diff] [blame] | 3388 | vfree(sw_context->cmd_bounce); |
Thomas Hellstrom | be38ab6 | 2011-08-31 07:42:54 +0000 | [diff] [blame] | 3389 | sw_context->cmd_bounce = vmalloc(sw_context->cmd_bounce_size); |
| 3390 | |
| 3391 | if (sw_context->cmd_bounce == NULL) { |
| 3392 | DRM_ERROR("Failed to allocate command bounce buffer.\n"); |
| 3393 | sw_context->cmd_bounce_size = 0; |
| 3394 | return -ENOMEM; |
| 3395 | } |
| 3396 | |
| 3397 | return 0; |
| 3398 | } |
| 3399 | |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 3400 | /** |
| 3401 | * vmw_execbuf_fence_commands - create and submit a command stream fence |
| 3402 | * |
| 3403 | * Creates a fence object and submits a command stream marker. |
| 3404 | * If this fails for some reason, We sync the fifo and return NULL. |
| 3405 | * It is then safe to fence buffers with a NULL pointer. |
Jakob Bornecrantz | 6070e9f | 2011-10-04 20:13:16 +0200 | [diff] [blame] | 3406 | * |
| 3407 | * If @p_handle is not NULL @file_priv must also not be NULL. Creates |
| 3408 | * a userspace handle if @p_handle is not NULL, otherwise not. |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 3409 | */ |
| 3410 | |
| 3411 | int vmw_execbuf_fence_commands(struct drm_file *file_priv, |
| 3412 | struct vmw_private *dev_priv, |
| 3413 | struct vmw_fence_obj **p_fence, |
| 3414 | uint32_t *p_handle) |
| 3415 | { |
| 3416 | uint32_t sequence; |
| 3417 | int ret; |
| 3418 | bool synced = false; |
| 3419 | |
Jakob Bornecrantz | 6070e9f | 2011-10-04 20:13:16 +0200 | [diff] [blame] | 3420 | /* p_handle implies file_priv. */ |
| 3421 | BUG_ON(p_handle != NULL && file_priv == NULL); |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 3422 | |
| 3423 | ret = vmw_fifo_send_fence(dev_priv, &sequence); |
| 3424 | if (unlikely(ret != 0)) { |
| 3425 | DRM_ERROR("Fence submission error. Syncing.\n"); |
| 3426 | synced = true; |
| 3427 | } |
| 3428 | |
| 3429 | if (p_handle != NULL) |
| 3430 | ret = vmw_user_fence_create(file_priv, dev_priv->fman, |
Maarten Lankhorst | c060a4e | 2014-03-26 13:06:24 +0100 | [diff] [blame] | 3431 | sequence, p_fence, p_handle); |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 3432 | else |
Maarten Lankhorst | c060a4e | 2014-03-26 13:06:24 +0100 | [diff] [blame] | 3433 | ret = vmw_fence_create(dev_priv->fman, sequence, p_fence); |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 3434 | |
| 3435 | if (unlikely(ret != 0 && !synced)) { |
| 3436 | (void) vmw_fallback_wait(dev_priv, false, false, |
| 3437 | sequence, false, |
| 3438 | VMW_FENCE_WAIT_TIMEOUT); |
| 3439 | *p_fence = NULL; |
| 3440 | } |
| 3441 | |
Thomas Hellstrom | 728354c | 2019-01-31 10:55:37 +0100 | [diff] [blame] | 3442 | return ret; |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 3443 | } |
| 3444 | |
Thomas Hellstrom | 8bf445c | 2011-10-10 12:23:25 +0200 | [diff] [blame] | 3445 | /** |
| 3446 | * vmw_execbuf_copy_fence_user - copy fence object information to |
| 3447 | * user-space. |
| 3448 | * |
| 3449 | * @dev_priv: Pointer to a vmw_private struct. |
| 3450 | * @vmw_fp: Pointer to the struct vmw_fpriv representing the calling file. |
| 3451 | * @ret: Return value from fence object creation. |
| 3452 | * @user_fence_rep: User space address of a struct drm_vmw_fence_rep to |
| 3453 | * which the information should be copied. |
| 3454 | * @fence: Pointer to the fenc object. |
| 3455 | * @fence_handle: User-space fence handle. |
Sinclair Yeh | c906965d | 2017-07-05 01:49:32 -0700 | [diff] [blame] | 3456 | * @out_fence_fd: exported file descriptor for the fence. -1 if not used |
| 3457 | * @sync_file: Only used to clean up in case of an error in this function. |
Thomas Hellstrom | 8bf445c | 2011-10-10 12:23:25 +0200 | [diff] [blame] | 3458 | * |
| 3459 | * This function copies fence information to user-space. If copying fails, |
| 3460 | * The user-space struct drm_vmw_fence_rep::error member is hopefully |
| 3461 | * left untouched, and if it's preloaded with an -EFAULT by user-space, |
| 3462 | * the error will hopefully be detected. |
| 3463 | * Also if copying fails, user-space will be unable to signal the fence |
| 3464 | * object so we wait for it immediately, and then unreference the |
| 3465 | * user-space reference. |
| 3466 | */ |
Thomas Hellstrom | 57c5ee7 | 2011-10-10 12:23:26 +0200 | [diff] [blame] | 3467 | void |
Thomas Hellstrom | 8bf445c | 2011-10-10 12:23:25 +0200 | [diff] [blame] | 3468 | vmw_execbuf_copy_fence_user(struct vmw_private *dev_priv, |
| 3469 | struct vmw_fpriv *vmw_fp, |
| 3470 | int ret, |
| 3471 | struct drm_vmw_fence_rep __user *user_fence_rep, |
| 3472 | struct vmw_fence_obj *fence, |
Sinclair Yeh | c906965d | 2017-07-05 01:49:32 -0700 | [diff] [blame] | 3473 | uint32_t fence_handle, |
| 3474 | int32_t out_fence_fd, |
| 3475 | struct sync_file *sync_file) |
Thomas Hellstrom | 8bf445c | 2011-10-10 12:23:25 +0200 | [diff] [blame] | 3476 | { |
| 3477 | struct drm_vmw_fence_rep fence_rep; |
| 3478 | |
| 3479 | if (user_fence_rep == NULL) |
| 3480 | return; |
| 3481 | |
Dan Carpenter | 80d9b24 | 2011-10-18 09:10:12 +0300 | [diff] [blame] | 3482 | memset(&fence_rep, 0, sizeof(fence_rep)); |
| 3483 | |
Thomas Hellstrom | 8bf445c | 2011-10-10 12:23:25 +0200 | [diff] [blame] | 3484 | fence_rep.error = ret; |
Sinclair Yeh | c906965d | 2017-07-05 01:49:32 -0700 | [diff] [blame] | 3485 | fence_rep.fd = out_fence_fd; |
Thomas Hellstrom | 8bf445c | 2011-10-10 12:23:25 +0200 | [diff] [blame] | 3486 | if (ret == 0) { |
| 3487 | BUG_ON(fence == NULL); |
| 3488 | |
| 3489 | fence_rep.handle = fence_handle; |
Maarten Lankhorst | 2298e80 | 2014-03-26 14:07:44 +0100 | [diff] [blame] | 3490 | fence_rep.seqno = fence->base.seqno; |
Thomas Hellstrom | 8bf445c | 2011-10-10 12:23:25 +0200 | [diff] [blame] | 3491 | vmw_update_seqno(dev_priv, &dev_priv->fifo); |
| 3492 | fence_rep.passed_seqno = dev_priv->last_read_seqno; |
| 3493 | } |
| 3494 | |
| 3495 | /* |
| 3496 | * copy_to_user errors will be detected by user space not |
| 3497 | * seeing fence_rep::error filled in. Typically |
| 3498 | * user-space would have pre-set that member to -EFAULT. |
| 3499 | */ |
| 3500 | ret = copy_to_user(user_fence_rep, &fence_rep, |
| 3501 | sizeof(fence_rep)); |
| 3502 | |
| 3503 | /* |
| 3504 | * User-space lost the fence object. We need to sync |
| 3505 | * and unreference the handle. |
| 3506 | */ |
| 3507 | if (unlikely(ret != 0) && (fence_rep.error == 0)) { |
Sinclair Yeh | c906965d | 2017-07-05 01:49:32 -0700 | [diff] [blame] | 3508 | if (sync_file) |
| 3509 | fput(sync_file->file); |
| 3510 | |
| 3511 | if (fence_rep.fd != -1) { |
| 3512 | put_unused_fd(fence_rep.fd); |
| 3513 | fence_rep.fd = -1; |
| 3514 | } |
| 3515 | |
Thomas Hellstrom | 8bf445c | 2011-10-10 12:23:25 +0200 | [diff] [blame] | 3516 | ttm_ref_object_base_unref(vmw_fp->tfile, |
| 3517 | fence_handle, TTM_REF_USAGE); |
| 3518 | DRM_ERROR("Fence copy error. Syncing.\n"); |
Maarten Lankhorst | c060a4e | 2014-03-26 13:06:24 +0100 | [diff] [blame] | 3519 | (void) vmw_fence_obj_wait(fence, false, false, |
Thomas Hellstrom | 8bf445c | 2011-10-10 12:23:25 +0200 | [diff] [blame] | 3520 | VMW_FENCE_WAIT_TIMEOUT); |
| 3521 | } |
| 3522 | } |
| 3523 | |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 3524 | /** |
| 3525 | * vmw_execbuf_submit_fifo - Patch a command batch and submit it using |
| 3526 | * the fifo. |
| 3527 | * |
| 3528 | * @dev_priv: Pointer to a device private structure. |
| 3529 | * @kernel_commands: Pointer to the unpatched command batch. |
| 3530 | * @command_size: Size of the unpatched command batch. |
| 3531 | * @sw_context: Structure holding the relocation lists. |
| 3532 | * |
| 3533 | * Side effects: If this function returns 0, then the command batch |
| 3534 | * pointed to by @kernel_commands will have been modified. |
| 3535 | */ |
| 3536 | static int vmw_execbuf_submit_fifo(struct vmw_private *dev_priv, |
| 3537 | void *kernel_commands, |
| 3538 | u32 command_size, |
| 3539 | struct vmw_sw_context *sw_context) |
| 3540 | { |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3541 | void *cmd; |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 3542 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3543 | if (sw_context->dx_ctx_node) |
| 3544 | cmd = vmw_fifo_reserve_dx(dev_priv, command_size, |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 3545 | sw_context->dx_ctx_node->ctx->id); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3546 | else |
| 3547 | cmd = vmw_fifo_reserve(dev_priv, command_size); |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 3548 | if (!cmd) { |
| 3549 | DRM_ERROR("Failed reserving fifo space for commands.\n"); |
| 3550 | return -ENOMEM; |
| 3551 | } |
| 3552 | |
| 3553 | vmw_apply_relocations(sw_context); |
| 3554 | memcpy(cmd, kernel_commands, command_size); |
| 3555 | vmw_resource_relocations_apply(cmd, &sw_context->res_relocations); |
| 3556 | vmw_resource_relocations_free(&sw_context->res_relocations); |
| 3557 | vmw_fifo_commit(dev_priv, command_size); |
| 3558 | |
| 3559 | return 0; |
| 3560 | } |
| 3561 | |
| 3562 | /** |
| 3563 | * vmw_execbuf_submit_cmdbuf - Patch a command batch and submit it using |
| 3564 | * the command buffer manager. |
| 3565 | * |
| 3566 | * @dev_priv: Pointer to a device private structure. |
| 3567 | * @header: Opaque handle to the command buffer allocation. |
| 3568 | * @command_size: Size of the unpatched command batch. |
| 3569 | * @sw_context: Structure holding the relocation lists. |
| 3570 | * |
| 3571 | * Side effects: If this function returns 0, then the command buffer |
| 3572 | * represented by @header will have been modified. |
| 3573 | */ |
| 3574 | static int vmw_execbuf_submit_cmdbuf(struct vmw_private *dev_priv, |
| 3575 | struct vmw_cmdbuf_header *header, |
| 3576 | u32 command_size, |
| 3577 | struct vmw_sw_context *sw_context) |
| 3578 | { |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 3579 | u32 id = ((sw_context->dx_ctx_node) ? sw_context->dx_ctx_node->ctx->id : |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3580 | SVGA3D_INVALID_ID); |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 3581 | void *cmd = vmw_cmdbuf_reserve(dev_priv->cman, command_size, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3582 | id, false, header); |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 3583 | |
| 3584 | vmw_apply_relocations(sw_context); |
| 3585 | vmw_resource_relocations_apply(cmd, &sw_context->res_relocations); |
| 3586 | vmw_resource_relocations_free(&sw_context->res_relocations); |
| 3587 | vmw_cmdbuf_commit(dev_priv->cman, command_size, header, false); |
| 3588 | |
| 3589 | return 0; |
| 3590 | } |
| 3591 | |
| 3592 | /** |
| 3593 | * vmw_execbuf_cmdbuf - Prepare, if possible, a user-space command batch for |
| 3594 | * submission using a command buffer. |
| 3595 | * |
| 3596 | * @dev_priv: Pointer to a device private structure. |
| 3597 | * @user_commands: User-space pointer to the commands to be submitted. |
| 3598 | * @command_size: Size of the unpatched command batch. |
| 3599 | * @header: Out parameter returning the opaque pointer to the command buffer. |
| 3600 | * |
| 3601 | * This function checks whether we can use the command buffer manager for |
| 3602 | * submission and if so, creates a command buffer of suitable size and |
| 3603 | * copies the user data into that buffer. |
| 3604 | * |
| 3605 | * On successful return, the function returns a pointer to the data in the |
| 3606 | * command buffer and *@header is set to non-NULL. |
| 3607 | * If command buffers could not be used, the function will return the value |
| 3608 | * of @kernel_commands on function call. That value may be NULL. In that case, |
| 3609 | * the value of *@header will be set to NULL. |
| 3610 | * If an error is encountered, the function will return a pointer error value. |
| 3611 | * If the function is interrupted by a signal while sleeping, it will return |
| 3612 | * -ERESTARTSYS casted to a pointer error value. |
| 3613 | */ |
Thomas Hellstrom | b9eb1a6 | 2015-04-02 02:39:45 -0700 | [diff] [blame] | 3614 | static void *vmw_execbuf_cmdbuf(struct vmw_private *dev_priv, |
| 3615 | void __user *user_commands, |
| 3616 | void *kernel_commands, |
| 3617 | u32 command_size, |
| 3618 | struct vmw_cmdbuf_header **header) |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 3619 | { |
| 3620 | size_t cmdbuf_size; |
| 3621 | int ret; |
| 3622 | |
| 3623 | *header = NULL; |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 3624 | if (command_size > SVGA_CB_MAX_SIZE) { |
| 3625 | DRM_ERROR("Command buffer is too large.\n"); |
| 3626 | return ERR_PTR(-EINVAL); |
| 3627 | } |
| 3628 | |
Thomas Hellstrom | 51ab70b | 2016-10-10 10:51:24 -0700 | [diff] [blame] | 3629 | if (!dev_priv->cman || kernel_commands) |
| 3630 | return kernel_commands; |
| 3631 | |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 3632 | /* If possible, add a little space for fencing. */ |
| 3633 | cmdbuf_size = command_size + 512; |
| 3634 | cmdbuf_size = min_t(size_t, cmdbuf_size, SVGA_CB_MAX_SIZE); |
| 3635 | kernel_commands = vmw_cmdbuf_alloc(dev_priv->cman, cmdbuf_size, |
| 3636 | true, header); |
| 3637 | if (IS_ERR(kernel_commands)) |
| 3638 | return kernel_commands; |
| 3639 | |
| 3640 | ret = copy_from_user(kernel_commands, user_commands, |
| 3641 | command_size); |
| 3642 | if (ret) { |
| 3643 | DRM_ERROR("Failed copying commands.\n"); |
| 3644 | vmw_cmdbuf_header_free(*header); |
| 3645 | *header = NULL; |
| 3646 | return ERR_PTR(-EFAULT); |
| 3647 | } |
| 3648 | |
| 3649 | return kernel_commands; |
| 3650 | } |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 3651 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3652 | static int vmw_execbuf_tie_context(struct vmw_private *dev_priv, |
| 3653 | struct vmw_sw_context *sw_context, |
| 3654 | uint32_t handle) |
| 3655 | { |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3656 | struct vmw_resource *res; |
| 3657 | int ret; |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 3658 | unsigned int size; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3659 | |
| 3660 | if (handle == SVGA3D_INVALID_ID) |
| 3661 | return 0; |
| 3662 | |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 3663 | size = vmw_execbuf_res_size(dev_priv, vmw_res_dx_context); |
| 3664 | ret = vmw_validation_preload_res(sw_context->ctx, size); |
| 3665 | if (ret) |
| 3666 | return ret; |
| 3667 | |
| 3668 | res = vmw_user_resource_noref_lookup_handle |
| 3669 | (dev_priv, sw_context->fp->tfile, handle, |
| 3670 | user_context_converter); |
Chengguang Xu | 4efa666 | 2019-03-01 10:14:06 -0800 | [diff] [blame] | 3671 | if (IS_ERR(res)) { |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3672 | DRM_ERROR("Could not find or user DX context 0x%08x.\n", |
| 3673 | (unsigned) handle); |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 3674 | return PTR_ERR(res); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3675 | } |
| 3676 | |
Thomas Hellstrom | a9f58c4 | 2019-02-20 08:21:26 +0100 | [diff] [blame] | 3677 | ret = vmw_execbuf_res_noref_val_add(sw_context, res, VMW_RES_DIRTY_SET); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3678 | if (unlikely(ret != 0)) |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 3679 | return ret; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3680 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 3681 | sw_context->dx_ctx_node = vmw_execbuf_info_from_res(sw_context, res); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3682 | sw_context->man = vmw_context_res_man(res); |
Thomas Hellstrom | e8c66ef | 2018-09-26 16:32:40 +0200 | [diff] [blame] | 3683 | |
| 3684 | return 0; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3685 | } |
| 3686 | |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 3687 | int vmw_execbuf_process(struct drm_file *file_priv, |
| 3688 | struct vmw_private *dev_priv, |
| 3689 | void __user *user_commands, |
| 3690 | void *kernel_commands, |
| 3691 | uint32_t command_size, |
| 3692 | uint64_t throttle_us, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3693 | uint32_t dx_context_handle, |
Jakob Bornecrantz | bb1bd2f | 2012-02-09 16:56:43 +0100 | [diff] [blame] | 3694 | struct drm_vmw_fence_rep __user *user_fence_rep, |
Sinclair Yeh | c906965d | 2017-07-05 01:49:32 -0700 | [diff] [blame] | 3695 | struct vmw_fence_obj **out_fence, |
| 3696 | uint32_t flags) |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3697 | { |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3698 | struct vmw_sw_context *sw_context = &dev_priv->ctx; |
Jakob Bornecrantz | bb1bd2f | 2012-02-09 16:56:43 +0100 | [diff] [blame] | 3699 | struct vmw_fence_obj *fence = NULL; |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 3700 | struct vmw_cmdbuf_header *header; |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 3701 | uint32_t handle; |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 3702 | int ret; |
Sinclair Yeh | c906965d | 2017-07-05 01:49:32 -0700 | [diff] [blame] | 3703 | int32_t out_fence_fd = -1; |
| 3704 | struct sync_file *sync_file = NULL; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 3705 | DECLARE_VAL_CONTEXT(val_ctx, &sw_context->res_ht, 1); |
Sinclair Yeh | c906965d | 2017-07-05 01:49:32 -0700 | [diff] [blame] | 3706 | |
Thomas Hellstrom | fd56746 | 2018-12-12 11:52:08 +0100 | [diff] [blame] | 3707 | vmw_validation_set_val_mem(&val_ctx, &dev_priv->vvm); |
| 3708 | |
Sinclair Yeh | c906965d | 2017-07-05 01:49:32 -0700 | [diff] [blame] | 3709 | if (flags & DRM_VMW_EXECBUF_FLAG_EXPORT_FENCE_FD) { |
| 3710 | out_fence_fd = get_unused_fd_flags(O_CLOEXEC); |
| 3711 | if (out_fence_fd < 0) { |
| 3712 | DRM_ERROR("Failed to get a fence file descriptor.\n"); |
| 3713 | return out_fence_fd; |
| 3714 | } |
| 3715 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3716 | |
Charmaine Lee | 2f633e5 | 2015-08-10 10:45:11 -0700 | [diff] [blame] | 3717 | if (throttle_us) { |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 3718 | ret = vmw_wait_lag(dev_priv, &dev_priv->fifo.marker_queue, |
| 3719 | throttle_us); |
Charmaine Lee | 2f633e5 | 2015-08-10 10:45:11 -0700 | [diff] [blame] | 3720 | |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 3721 | if (ret) |
Sinclair Yeh | c906965d | 2017-07-05 01:49:32 -0700 | [diff] [blame] | 3722 | goto out_free_fence_fd; |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 3723 | } |
Charmaine Lee | 2f633e5 | 2015-08-10 10:45:11 -0700 | [diff] [blame] | 3724 | |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 3725 | kernel_commands = vmw_execbuf_cmdbuf(dev_priv, user_commands, |
| 3726 | kernel_commands, command_size, |
| 3727 | &header); |
Sinclair Yeh | c906965d | 2017-07-05 01:49:32 -0700 | [diff] [blame] | 3728 | if (IS_ERR(kernel_commands)) { |
| 3729 | ret = PTR_ERR(kernel_commands); |
| 3730 | goto out_free_fence_fd; |
| 3731 | } |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 3732 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3733 | ret = mutex_lock_interruptible(&dev_priv->cmdbuf_mutex); |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 3734 | if (ret) { |
| 3735 | ret = -ERESTARTSYS; |
| 3736 | goto out_free_header; |
| 3737 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3738 | |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 3739 | sw_context->kernel = false; |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 3740 | if (kernel_commands == NULL) { |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 3741 | ret = vmw_resize_cmd_bounce(sw_context, command_size); |
| 3742 | if (unlikely(ret != 0)) |
| 3743 | goto out_unlock; |
| 3744 | |
| 3745 | |
| 3746 | ret = copy_from_user(sw_context->cmd_bounce, |
| 3747 | user_commands, command_size); |
| 3748 | |
| 3749 | if (unlikely(ret != 0)) { |
| 3750 | ret = -EFAULT; |
| 3751 | DRM_ERROR("Failed copying commands.\n"); |
| 3752 | goto out_unlock; |
| 3753 | } |
| 3754 | kernel_commands = sw_context->cmd_bounce; |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 3755 | } else if (!header) |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 3756 | sw_context->kernel = true; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3757 | |
Thomas Hellstrom | d5bde95 | 2014-01-31 10:12:10 +0100 | [diff] [blame] | 3758 | sw_context->fp = vmw_fpriv(file_priv); |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 3759 | INIT_LIST_HEAD(&sw_context->ctx_list); |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 3760 | sw_context->cur_query_bo = dev_priv->pinned_bo; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3761 | sw_context->last_query_ctx = NULL; |
| 3762 | sw_context->needs_post_query_barrier = false; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3763 | sw_context->dx_ctx_node = NULL; |
Sinclair Yeh | fd11a3c | 2015-08-10 10:56:15 -0700 | [diff] [blame] | 3764 | sw_context->dx_query_mob = NULL; |
| 3765 | sw_context->dx_query_ctx = NULL; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3766 | memset(sw_context->res_cache, 0, sizeof(sw_context->res_cache)); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3767 | INIT_LIST_HEAD(&sw_context->res_relocations); |
Thomas Hellstrom | fc18afc | 2018-09-26 15:36:52 +0200 | [diff] [blame] | 3768 | INIT_LIST_HEAD(&sw_context->bo_relocations); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3769 | if (sw_context->staged_bindings) |
| 3770 | vmw_binding_state_reset(sw_context->staged_bindings); |
| 3771 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3772 | if (!sw_context->res_ht_initialized) { |
| 3773 | ret = drm_ht_create(&sw_context->res_ht, VMW_RES_HT_ORDER); |
| 3774 | if (unlikely(ret != 0)) |
| 3775 | goto out_unlock; |
| 3776 | sw_context->res_ht_initialized = true; |
| 3777 | } |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 3778 | INIT_LIST_HEAD(&sw_context->staged_cmd_res); |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 3779 | sw_context->ctx = &val_ctx; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3780 | ret = vmw_execbuf_tie_context(dev_priv, sw_context, dx_context_handle); |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 3781 | if (unlikely(ret != 0)) |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3782 | goto out_err_nores; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3783 | |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 3784 | ret = vmw_cmd_check_all(dev_priv, sw_context, kernel_commands, |
| 3785 | command_size); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3786 | if (unlikely(ret != 0)) |
Thomas Hellstrom | cf5e341 | 2014-01-30 10:58:19 +0100 | [diff] [blame] | 3787 | goto out_err_nores; |
Thomas Hellstrom | be38ab6 | 2011-08-31 07:42:54 +0000 | [diff] [blame] | 3788 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3789 | ret = vmw_resources_reserve(sw_context); |
| 3790 | if (unlikely(ret != 0)) |
Thomas Hellstrom | cf5e341 | 2014-01-30 10:58:19 +0100 | [diff] [blame] | 3791 | goto out_err_nores; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3792 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 3793 | ret = vmw_validation_bo_reserve(&val_ctx, true); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3794 | if (unlikely(ret != 0)) |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3795 | goto out_err_nores; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3796 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 3797 | ret = vmw_validation_bo_validate(&val_ctx, true); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3798 | if (unlikely(ret != 0)) |
| 3799 | goto out_err; |
| 3800 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 3801 | ret = vmw_validation_res_validate(&val_ctx, true); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3802 | if (unlikely(ret != 0)) |
| 3803 | goto out_err; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 3804 | vmw_validation_drop_ht(&val_ctx); |
Thomas Hellstrom | 1925d45 | 2010-05-28 11:21:57 +0200 | [diff] [blame] | 3805 | |
Thomas Hellstrom | 173fb7d | 2013-10-08 02:32:36 -0700 | [diff] [blame] | 3806 | ret = mutex_lock_interruptible(&dev_priv->binding_mutex); |
| 3807 | if (unlikely(ret != 0)) { |
| 3808 | ret = -ERESTARTSYS; |
| 3809 | goto out_err; |
| 3810 | } |
| 3811 | |
Thomas Hellstrom | 30f82d81 | 2014-02-05 08:13:56 +0100 | [diff] [blame] | 3812 | if (dev_priv->has_mob) { |
| 3813 | ret = vmw_rebind_contexts(sw_context); |
| 3814 | if (unlikely(ret != 0)) |
Dan Carpenter | b2ad988 | 2014-02-11 19:03:47 +0300 | [diff] [blame] | 3815 | goto out_unlock_binding; |
Thomas Hellstrom | 30f82d81 | 2014-02-05 08:13:56 +0100 | [diff] [blame] | 3816 | } |
| 3817 | |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 3818 | if (!header) { |
| 3819 | ret = vmw_execbuf_submit_fifo(dev_priv, kernel_commands, |
| 3820 | command_size, sw_context); |
| 3821 | } else { |
| 3822 | ret = vmw_execbuf_submit_cmdbuf(dev_priv, header, command_size, |
| 3823 | sw_context); |
| 3824 | header = NULL; |
Thomas Hellstrom | be38ab6 | 2011-08-31 07:42:54 +0000 | [diff] [blame] | 3825 | } |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3826 | mutex_unlock(&dev_priv->binding_mutex); |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 3827 | if (ret) |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 3828 | goto out_err; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3829 | |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 3830 | vmw_query_bo_switch_commit(dev_priv, sw_context); |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 3831 | ret = vmw_execbuf_fence_commands(file_priv, dev_priv, |
| 3832 | &fence, |
| 3833 | (user_fence_rep) ? &handle : NULL); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3834 | /* |
| 3835 | * This error is harmless, because if fence submission fails, |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 3836 | * vmw_fifo_send_fence will sync. The error will be propagated to |
| 3837 | * user-space in @fence_rep |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3838 | */ |
| 3839 | |
| 3840 | if (ret != 0) |
| 3841 | DRM_ERROR("Fence submission error. Syncing.\n"); |
| 3842 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 3843 | vmw_execbuf_bindings_commit(sw_context, false); |
| 3844 | vmw_bind_dx_query_mob(sw_context); |
| 3845 | vmw_validation_res_unreserve(&val_ctx, false); |
Thomas Hellstrom | 173fb7d | 2013-10-08 02:32:36 -0700 | [diff] [blame] | 3846 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 3847 | vmw_validation_bo_fence(sw_context->ctx, fence); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3848 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3849 | if (unlikely(dev_priv->pinned_bo != NULL && |
| 3850 | !dev_priv->query_cid_valid)) |
| 3851 | __vmw_execbuf_release_pinned_bo(dev_priv, fence); |
| 3852 | |
Sinclair Yeh | c906965d | 2017-07-05 01:49:32 -0700 | [diff] [blame] | 3853 | /* |
| 3854 | * If anything fails here, give up trying to export the fence |
| 3855 | * and do a sync since the user mode will not be able to sync |
| 3856 | * the fence itself. This ensures we are still functionally |
| 3857 | * correct. |
| 3858 | */ |
| 3859 | if (flags & DRM_VMW_EXECBUF_FLAG_EXPORT_FENCE_FD) { |
| 3860 | |
| 3861 | sync_file = sync_file_create(&fence->base); |
| 3862 | if (!sync_file) { |
| 3863 | DRM_ERROR("Unable to create sync file for fence\n"); |
| 3864 | put_unused_fd(out_fence_fd); |
| 3865 | out_fence_fd = -1; |
| 3866 | |
| 3867 | (void) vmw_fence_obj_wait(fence, false, false, |
| 3868 | VMW_FENCE_WAIT_TIMEOUT); |
| 3869 | } else { |
| 3870 | /* Link the fence with the FD created earlier */ |
| 3871 | fd_install(out_fence_fd, sync_file->file); |
| 3872 | } |
| 3873 | } |
| 3874 | |
Thomas Hellstrom | 8bf445c | 2011-10-10 12:23:25 +0200 | [diff] [blame] | 3875 | vmw_execbuf_copy_fence_user(dev_priv, vmw_fpriv(file_priv), ret, |
Sinclair Yeh | c906965d | 2017-07-05 01:49:32 -0700 | [diff] [blame] | 3876 | user_fence_rep, fence, handle, |
| 3877 | out_fence_fd, sync_file); |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 3878 | |
Jakob Bornecrantz | bb1bd2f | 2012-02-09 16:56:43 +0100 | [diff] [blame] | 3879 | /* Don't unreference when handing fence out */ |
| 3880 | if (unlikely(out_fence != NULL)) { |
| 3881 | *out_fence = fence; |
| 3882 | fence = NULL; |
| 3883 | } else if (likely(fence != NULL)) { |
Thomas Hellstrom | ae2a104 | 2011-09-01 20:18:44 +0000 | [diff] [blame] | 3884 | vmw_fence_obj_unreference(&fence); |
Jakob Bornecrantz | bb1bd2f | 2012-02-09 16:56:43 +0100 | [diff] [blame] | 3885 | } |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3886 | |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 3887 | vmw_cmdbuf_res_commit(&sw_context->staged_cmd_res); |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 3888 | mutex_unlock(&dev_priv->cmdbuf_mutex); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3889 | |
| 3890 | /* |
| 3891 | * Unreference resources outside of the cmdbuf_mutex to |
| 3892 | * avoid deadlocks in resource destruction paths. |
| 3893 | */ |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 3894 | vmw_validation_unref_lists(&val_ctx); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3895 | |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3896 | return 0; |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 3897 | |
Thomas Hellstrom | 173fb7d | 2013-10-08 02:32:36 -0700 | [diff] [blame] | 3898 | out_unlock_binding: |
| 3899 | mutex_unlock(&dev_priv->binding_mutex); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3900 | out_err: |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 3901 | vmw_validation_bo_backoff(&val_ctx); |
Thomas Hellstrom | cf5e341 | 2014-01-30 10:58:19 +0100 | [diff] [blame] | 3902 | out_err_nores: |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 3903 | vmw_execbuf_bindings_commit(sw_context, true); |
| 3904 | vmw_validation_res_unreserve(&val_ctx, true); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3905 | vmw_resource_relocations_free(&sw_context->res_relocations); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3906 | vmw_free_relocations(sw_context); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3907 | if (unlikely(dev_priv->pinned_bo != NULL && |
| 3908 | !dev_priv->query_cid_valid)) |
| 3909 | __vmw_execbuf_release_pinned_bo(dev_priv, NULL); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3910 | out_unlock: |
Thomas Hellstrom | 18e4a46 | 2014-06-09 12:39:22 +0200 | [diff] [blame] | 3911 | vmw_cmdbuf_res_revert(&sw_context->staged_cmd_res); |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 3912 | vmw_validation_drop_ht(&val_ctx); |
| 3913 | WARN_ON(!list_empty(&sw_context->ctx_list)); |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 3914 | mutex_unlock(&dev_priv->cmdbuf_mutex); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3915 | |
| 3916 | /* |
| 3917 | * Unreference resources outside of the cmdbuf_mutex to |
| 3918 | * avoid deadlocks in resource destruction paths. |
| 3919 | */ |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 3920 | vmw_validation_unref_lists(&val_ctx); |
Thomas Hellstrom | 3eab3d9 | 2015-06-25 11:57:56 -0700 | [diff] [blame] | 3921 | out_free_header: |
| 3922 | if (header) |
| 3923 | vmw_cmdbuf_header_free(header); |
Sinclair Yeh | c906965d | 2017-07-05 01:49:32 -0700 | [diff] [blame] | 3924 | out_free_fence_fd: |
| 3925 | if (out_fence_fd >= 0) |
| 3926 | put_unused_fd(out_fence_fd); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3927 | |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 3928 | return ret; |
| 3929 | } |
| 3930 | |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 3931 | /** |
| 3932 | * vmw_execbuf_unpin_panic - Idle the fifo and unpin the query buffer. |
| 3933 | * |
| 3934 | * @dev_priv: The device private structure. |
| 3935 | * |
| 3936 | * This function is called to idle the fifo and unpin the query buffer |
| 3937 | * if the normal way to do this hits an error, which should typically be |
| 3938 | * extremely rare. |
| 3939 | */ |
| 3940 | static void vmw_execbuf_unpin_panic(struct vmw_private *dev_priv) |
| 3941 | { |
| 3942 | DRM_ERROR("Can't unpin query buffer. Trying to recover.\n"); |
| 3943 | |
| 3944 | (void) vmw_fallback_wait(dev_priv, false, true, 0, false, 10*HZ); |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 3945 | vmw_bo_pin_reserved(dev_priv->pinned_bo, false); |
| 3946 | if (dev_priv->dummy_query_bo_pinned) { |
| 3947 | vmw_bo_pin_reserved(dev_priv->dummy_query_bo, false); |
| 3948 | dev_priv->dummy_query_bo_pinned = false; |
| 3949 | } |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 3950 | } |
| 3951 | |
| 3952 | |
| 3953 | /** |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3954 | * __vmw_execbuf_release_pinned_bo - Flush queries and unpin the pinned |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 3955 | * query bo. |
| 3956 | * |
| 3957 | * @dev_priv: The device private structure. |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3958 | * @fence: If non-NULL should point to a struct vmw_fence_obj issued |
| 3959 | * _after_ a query barrier that flushes all queries touching the current |
| 3960 | * buffer pointed to by @dev_priv->pinned_bo |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 3961 | * |
| 3962 | * This function should be used to unpin the pinned query bo, or |
| 3963 | * as a query barrier when we need to make sure that all queries have |
| 3964 | * finished before the next fifo command. (For example on hardware |
| 3965 | * context destructions where the hardware may otherwise leak unfinished |
| 3966 | * queries). |
| 3967 | * |
| 3968 | * This function does not return any failure codes, but make attempts |
| 3969 | * to do safe unpinning in case of errors. |
| 3970 | * |
| 3971 | * The function will synchronize on the previous query barrier, and will |
| 3972 | * thus not finish until that barrier has executed. |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3973 | * |
| 3974 | * the @dev_priv->cmdbuf_mutex needs to be held by the current thread |
| 3975 | * before calling this function. |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 3976 | */ |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3977 | void __vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv, |
| 3978 | struct vmw_fence_obj *fence) |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 3979 | { |
| 3980 | int ret = 0; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 3981 | struct vmw_fence_obj *lfence = NULL; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 3982 | DECLARE_VAL_CONTEXT(val_ctx, NULL, 0); |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 3983 | |
| 3984 | if (dev_priv->pinned_bo == NULL) |
| 3985 | goto out_unlock; |
| 3986 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 3987 | ret = vmw_validation_add_bo(&val_ctx, dev_priv->pinned_bo, false, |
| 3988 | false); |
| 3989 | if (ret) |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 3990 | goto out_no_reserve; |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 3991 | |
| 3992 | ret = vmw_validation_add_bo(&val_ctx, dev_priv->dummy_query_bo, false, |
| 3993 | false); |
| 3994 | if (ret) |
| 3995 | goto out_no_reserve; |
| 3996 | |
| 3997 | ret = vmw_validation_bo_reserve(&val_ctx, false); |
| 3998 | if (ret) |
| 3999 | goto out_no_reserve; |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 4000 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 4001 | if (dev_priv->query_cid_valid) { |
| 4002 | BUG_ON(fence != NULL); |
| 4003 | ret = vmw_fifo_emit_dummy_query(dev_priv, dev_priv->query_cid); |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 4004 | if (ret) |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 4005 | goto out_no_emit; |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 4006 | dev_priv->query_cid_valid = false; |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 4007 | } |
| 4008 | |
Thomas Hellstrom | 459d0fa | 2015-06-26 00:25:37 -0700 | [diff] [blame] | 4009 | vmw_bo_pin_reserved(dev_priv->pinned_bo, false); |
| 4010 | if (dev_priv->dummy_query_bo_pinned) { |
| 4011 | vmw_bo_pin_reserved(dev_priv->dummy_query_bo, false); |
| 4012 | dev_priv->dummy_query_bo_pinned = false; |
| 4013 | } |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 4014 | if (fence == NULL) { |
| 4015 | (void) vmw_execbuf_fence_commands(NULL, dev_priv, &lfence, |
| 4016 | NULL); |
| 4017 | fence = lfence; |
| 4018 | } |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 4019 | vmw_validation_bo_fence(&val_ctx, fence); |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 4020 | if (lfence != NULL) |
| 4021 | vmw_fence_obj_unreference(&lfence); |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 4022 | |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 4023 | vmw_validation_unref_lists(&val_ctx); |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 4024 | vmw_bo_unreference(&dev_priv->pinned_bo); |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 4025 | out_unlock: |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 4026 | return; |
| 4027 | |
| 4028 | out_no_emit: |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 4029 | vmw_validation_bo_backoff(&val_ctx); |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 4030 | out_no_reserve: |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 4031 | vmw_validation_unref_lists(&val_ctx); |
| 4032 | vmw_execbuf_unpin_panic(dev_priv); |
Thomas Hellstrom | f1d34bf | 2018-06-19 15:02:16 +0200 | [diff] [blame] | 4033 | vmw_bo_unreference(&dev_priv->pinned_bo); |
Thomas Hellstrom | 9c079b8 | 2018-09-26 15:28:55 +0200 | [diff] [blame] | 4034 | |
Thomas Hellstrom | c0951b7 | 2012-11-20 12:19:35 +0000 | [diff] [blame] | 4035 | } |
| 4036 | |
| 4037 | /** |
| 4038 | * vmw_execbuf_release_pinned_bo - Flush queries and unpin the pinned |
| 4039 | * query bo. |
| 4040 | * |
| 4041 | * @dev_priv: The device private structure. |
| 4042 | * |
| 4043 | * This function should be used to unpin the pinned query bo, or |
| 4044 | * as a query barrier when we need to make sure that all queries have |
| 4045 | * finished before the next fifo command. (For example on hardware |
| 4046 | * context destructions where the hardware may otherwise leak unfinished |
| 4047 | * queries). |
| 4048 | * |
| 4049 | * This function does not return any failure codes, but make attempts |
| 4050 | * to do safe unpinning in case of errors. |
| 4051 | * |
| 4052 | * The function will synchronize on the previous query barrier, and will |
| 4053 | * thus not finish until that barrier has executed. |
| 4054 | */ |
| 4055 | void vmw_execbuf_release_pinned_bo(struct vmw_private *dev_priv) |
| 4056 | { |
| 4057 | mutex_lock(&dev_priv->cmdbuf_mutex); |
| 4058 | if (dev_priv->query_cid_valid) |
| 4059 | __vmw_execbuf_release_pinned_bo(dev_priv, NULL); |
Thomas Hellstrom | e2fa3a7 | 2011-10-04 20:13:30 +0200 | [diff] [blame] | 4060 | mutex_unlock(&dev_priv->cmdbuf_mutex); |
| 4061 | } |
| 4062 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 4063 | int vmw_execbuf_ioctl(struct drm_device *dev, unsigned long data, |
| 4064 | struct drm_file *file_priv, size_t size) |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 4065 | { |
| 4066 | struct vmw_private *dev_priv = vmw_priv(dev); |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 4067 | struct drm_vmw_execbuf_arg arg; |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 4068 | int ret; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 4069 | static const size_t copy_offset[] = { |
| 4070 | offsetof(struct drm_vmw_execbuf_arg, context_handle), |
| 4071 | sizeof(struct drm_vmw_execbuf_arg)}; |
Sinclair Yeh | 58585116 | 2017-07-05 01:45:40 -0700 | [diff] [blame] | 4072 | struct dma_fence *in_fence = NULL; |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 4073 | |
| 4074 | if (unlikely(size < copy_offset[0])) { |
| 4075 | DRM_ERROR("Invalid command size, ioctl %d\n", |
| 4076 | DRM_VMW_EXECBUF); |
| 4077 | return -EINVAL; |
| 4078 | } |
| 4079 | |
| 4080 | if (copy_from_user(&arg, (void __user *) data, copy_offset[0]) != 0) |
| 4081 | return -EFAULT; |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 4082 | |
| 4083 | /* |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 4084 | * Extend the ioctl argument while |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 4085 | * maintaining backwards compatibility: |
| 4086 | * We take different code paths depending on the value of |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 4087 | * arg.version. |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 4088 | */ |
| 4089 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 4090 | if (unlikely(arg.version > DRM_VMW_EXECBUF_VERSION || |
| 4091 | arg.version == 0)) { |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 4092 | DRM_ERROR("Incorrect execbuf version.\n"); |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 4093 | return -EINVAL; |
| 4094 | } |
| 4095 | |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 4096 | if (arg.version > 1 && |
| 4097 | copy_from_user(&arg.context_handle, |
| 4098 | (void __user *) (data + copy_offset[0]), |
| 4099 | copy_offset[arg.version - 1] - |
| 4100 | copy_offset[0]) != 0) |
| 4101 | return -EFAULT; |
| 4102 | |
| 4103 | switch (arg.version) { |
| 4104 | case 1: |
| 4105 | arg.context_handle = (uint32_t) -1; |
| 4106 | break; |
| 4107 | case 2: |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 4108 | default: |
| 4109 | break; |
| 4110 | } |
| 4111 | |
Sinclair Yeh | 58585116 | 2017-07-05 01:45:40 -0700 | [diff] [blame] | 4112 | |
| 4113 | /* If imported a fence FD from elsewhere, then wait on it */ |
| 4114 | if (arg.flags & DRM_VMW_EXECBUF_FLAG_IMPORT_FENCE_FD) { |
| 4115 | in_fence = sync_file_get_fence(arg.imported_fence_fd); |
| 4116 | |
| 4117 | if (!in_fence) { |
| 4118 | DRM_ERROR("Cannot get imported fence\n"); |
| 4119 | return -EINVAL; |
| 4120 | } |
| 4121 | |
| 4122 | ret = vmw_wait_dma_fence(dev_priv->fman, in_fence); |
| 4123 | if (ret) |
| 4124 | goto out; |
| 4125 | } |
| 4126 | |
Thomas Hellstrom | 294adf7 | 2014-02-27 12:34:51 +0100 | [diff] [blame] | 4127 | ret = ttm_read_lock(&dev_priv->reservation_sem, true); |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 4128 | if (unlikely(ret != 0)) |
| 4129 | return ret; |
| 4130 | |
| 4131 | ret = vmw_execbuf_process(file_priv, dev_priv, |
Thomas Hellstrom | d80efd5 | 2015-08-10 10:39:35 -0700 | [diff] [blame] | 4132 | (void __user *)(unsigned long)arg.commands, |
| 4133 | NULL, arg.command_size, arg.throttle_us, |
| 4134 | arg.context_handle, |
| 4135 | (void __user *)(unsigned long)arg.fence_rep, |
Sinclair Yeh | c906965d | 2017-07-05 01:49:32 -0700 | [diff] [blame] | 4136 | NULL, |
| 4137 | arg.flags); |
Thomas Hellstrom | 5151adb | 2015-03-09 01:56:21 -0700 | [diff] [blame] | 4138 | ttm_read_unlock(&dev_priv->reservation_sem); |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 4139 | if (unlikely(ret != 0)) |
Sinclair Yeh | 58585116 | 2017-07-05 01:45:40 -0700 | [diff] [blame] | 4140 | goto out; |
Thomas Hellstrom | 922ade0 | 2011-10-04 20:13:17 +0200 | [diff] [blame] | 4141 | |
| 4142 | vmw_kms_cursor_post_execbuf(dev_priv); |
| 4143 | |
Sinclair Yeh | 58585116 | 2017-07-05 01:45:40 -0700 | [diff] [blame] | 4144 | out: |
| 4145 | if (in_fence) |
| 4146 | dma_fence_put(in_fence); |
| 4147 | return ret; |
Jakob Bornecrantz | fb1d973 | 2009-12-10 00:19:58 +0000 | [diff] [blame] | 4148 | } |