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