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