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