Lines Matching +full:resource +full:- +full:id

1 // SPDX-License-Identifier: GPL-2.0 OR MIT
4 * Copyright 2009-2023 VMware, Inc., Palo Alto, CA., USA
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
52 u32 id; member
116 * The destroy callback is only called with a committed resource on
137 * vmw_res_to_dx_shader - typecast a struct vmw_resource to a
150 if (likely(res->func->destroy)) in vmw_hw_shader_destroy()
151 (void) res->func->destroy(res); in vmw_hw_shader_destroy()
153 res->id = -1; in vmw_hw_shader_destroy()
181 res->guest_memory_size = size; in vmw_gb_shader_init()
183 res->guest_memory_bo = vmw_user_bo_ref(byte_code); in vmw_gb_shader_init()
184 res->guest_memory_offset = offset; in vmw_gb_shader_init()
186 shader->size = size; in vmw_gb_shader_init()
187 shader->type = type; in vmw_gb_shader_init()
188 shader->num_input_sig = num_input_sig; in vmw_gb_shader_init()
189 shader->num_output_sig = num_output_sig; in vmw_gb_shader_init()
191 res->hw_destroy = vmw_hw_shader_destroy; in vmw_gb_shader_init()
201 struct vmw_private *dev_priv = res->dev_priv; in vmw_gb_shader_create()
209 if (likely(res->id != -1)) in vmw_gb_shader_create()
214 DRM_ERROR("Failed to allocate a shader id.\n"); in vmw_gb_shader_create()
218 if (unlikely(res->id >= VMWGFX_NUM_GB_SHADER)) { in vmw_gb_shader_create()
219 ret = -EBUSY; in vmw_gb_shader_create()
225 ret = -ENOMEM; in vmw_gb_shader_create()
229 cmd->header.id = SVGA_3D_CMD_DEFINE_GB_SHADER; in vmw_gb_shader_create()
230 cmd->header.size = sizeof(cmd->body); in vmw_gb_shader_create()
231 cmd->body.shid = res->id; in vmw_gb_shader_create()
232 cmd->body.type = shader->type; in vmw_gb_shader_create()
233 cmd->body.sizeInBytes = shader->size; in vmw_gb_shader_create()
248 struct vmw_private *dev_priv = res->dev_priv; in vmw_gb_shader_bind()
253 struct ttm_buffer_object *bo = val_buf->bo; in vmw_gb_shader_bind()
255 BUG_ON(bo->resource->mem_type != VMW_PL_MOB); in vmw_gb_shader_bind()
259 return -ENOMEM; in vmw_gb_shader_bind()
261 cmd->header.id = SVGA_3D_CMD_BIND_GB_SHADER; in vmw_gb_shader_bind()
262 cmd->header.size = sizeof(cmd->body); in vmw_gb_shader_bind()
263 cmd->body.shid = res->id; in vmw_gb_shader_bind()
264 cmd->body.mobid = bo->resource->start; in vmw_gb_shader_bind()
265 cmd->body.offsetInBytes = res->guest_memory_offset; in vmw_gb_shader_bind()
266 res->guest_memory_dirty = false; in vmw_gb_shader_bind()
276 struct vmw_private *dev_priv = res->dev_priv; in vmw_gb_shader_unbind()
283 BUG_ON(res->guest_memory_bo->tbo.resource->mem_type != VMW_PL_MOB); in vmw_gb_shader_unbind()
287 return -ENOMEM; in vmw_gb_shader_unbind()
289 cmd->header.id = SVGA_3D_CMD_BIND_GB_SHADER; in vmw_gb_shader_unbind()
290 cmd->header.size = sizeof(cmd->body); in vmw_gb_shader_unbind()
291 cmd->body.shid = res->id; in vmw_gb_shader_unbind()
292 cmd->body.mobid = SVGA3D_INVALID_ID; in vmw_gb_shader_unbind()
293 cmd->body.offsetInBytes = 0; in vmw_gb_shader_unbind()
303 vmw_bo_fence_single(val_buf->bo, fence); in vmw_gb_shader_unbind()
313 struct vmw_private *dev_priv = res->dev_priv; in vmw_gb_shader_destroy()
319 if (likely(res->id == -1)) in vmw_gb_shader_destroy()
322 mutex_lock(&dev_priv->binding_mutex); in vmw_gb_shader_destroy()
323 vmw_binding_res_list_scrub(&res->binding_head); in vmw_gb_shader_destroy()
327 mutex_unlock(&dev_priv->binding_mutex); in vmw_gb_shader_destroy()
328 return -ENOMEM; in vmw_gb_shader_destroy()
331 cmd->header.id = SVGA_3D_CMD_DESTROY_GB_SHADER; in vmw_gb_shader_destroy()
332 cmd->header.size = sizeof(cmd->body); in vmw_gb_shader_destroy()
333 cmd->body.shid = res->id; in vmw_gb_shader_destroy()
335 mutex_unlock(&dev_priv->binding_mutex); in vmw_gb_shader_destroy()
347 * vmw_dx_shader_commit_notify - Notify that a shader operation has been
348 * committed to hardware from a user-supplied command stream.
350 * @res: Pointer to the shader resource.
358 struct vmw_private *dev_priv = res->dev_priv; in vmw_dx_shader_commit_notify()
361 mutex_lock(&dev_priv->binding_mutex); in vmw_dx_shader_commit_notify()
362 vmw_cotable_add_resource(shader->cotable, in vmw_dx_shader_commit_notify()
363 &shader->cotable_head); in vmw_dx_shader_commit_notify()
364 shader->committed = true; in vmw_dx_shader_commit_notify()
365 res->id = shader->id; in vmw_dx_shader_commit_notify()
366 mutex_unlock(&dev_priv->binding_mutex); in vmw_dx_shader_commit_notify()
368 mutex_lock(&dev_priv->binding_mutex); in vmw_dx_shader_commit_notify()
369 list_del_init(&shader->cotable_head); in vmw_dx_shader_commit_notify()
370 shader->committed = false; in vmw_dx_shader_commit_notify()
371 res->id = -1; in vmw_dx_shader_commit_notify()
372 mutex_unlock(&dev_priv->binding_mutex); in vmw_dx_shader_commit_notify()
377 * vmw_dx_shader_unscrub - Have the device reattach a MOB to a DX shader.
379 * @res: The shader resource
386 struct vmw_private *dev_priv = res->dev_priv; in vmw_dx_shader_unscrub()
392 if (!list_empty(&shader->cotable_head) || !shader->committed) in vmw_dx_shader_unscrub()
395 cmd = VMW_CMD_CTX_RESERVE(dev_priv, sizeof(*cmd), shader->ctx->id); in vmw_dx_shader_unscrub()
397 return -ENOMEM; in vmw_dx_shader_unscrub()
399 cmd->header.id = SVGA_3D_CMD_DX_BIND_SHADER; in vmw_dx_shader_unscrub()
400 cmd->header.size = sizeof(cmd->body); in vmw_dx_shader_unscrub()
401 cmd->body.cid = shader->ctx->id; in vmw_dx_shader_unscrub()
402 cmd->body.shid = shader->id; in vmw_dx_shader_unscrub()
403 cmd->body.mobid = res->guest_memory_bo->tbo.resource->start; in vmw_dx_shader_unscrub()
404 cmd->body.offsetInBytes = res->guest_memory_offset; in vmw_dx_shader_unscrub()
407 vmw_cotable_add_resource(shader->cotable, &shader->cotable_head); in vmw_dx_shader_unscrub()
413 * vmw_dx_shader_create - The DX shader create callback
415 * @res: The DX shader resource
417 * The create callback is called as part of resource validation and
422 struct vmw_private *dev_priv = res->dev_priv; in vmw_dx_shader_create()
426 WARN_ON_ONCE(!shader->committed); in vmw_dx_shader_create()
429 mutex_lock(&dev_priv->binding_mutex); in vmw_dx_shader_create()
431 mutex_unlock(&dev_priv->binding_mutex); in vmw_dx_shader_create()
434 res->id = shader->id; in vmw_dx_shader_create()
439 * vmw_dx_shader_bind - The DX shader bind callback
441 * @res: The DX shader resource
448 struct vmw_private *dev_priv = res->dev_priv; in vmw_dx_shader_bind()
449 struct ttm_buffer_object *bo = val_buf->bo; in vmw_dx_shader_bind()
451 BUG_ON(bo->resource->mem_type != VMW_PL_MOB); in vmw_dx_shader_bind()
452 mutex_lock(&dev_priv->binding_mutex); in vmw_dx_shader_bind()
454 mutex_unlock(&dev_priv->binding_mutex); in vmw_dx_shader_bind()
460 * vmw_dx_shader_scrub - Have the device unbind a MOB from a DX shader.
462 * @res: The shader resource
472 struct vmw_private *dev_priv = res->dev_priv; in vmw_dx_shader_scrub()
478 if (list_empty(&shader->cotable_head)) in vmw_dx_shader_scrub()
481 WARN_ON_ONCE(!shader->committed); in vmw_dx_shader_scrub()
484 return -ENOMEM; in vmw_dx_shader_scrub()
486 cmd->header.id = SVGA_3D_CMD_DX_BIND_SHADER; in vmw_dx_shader_scrub()
487 cmd->header.size = sizeof(cmd->body); in vmw_dx_shader_scrub()
488 cmd->body.cid = shader->ctx->id; in vmw_dx_shader_scrub()
489 cmd->body.shid = res->id; in vmw_dx_shader_scrub()
490 cmd->body.mobid = SVGA3D_INVALID_ID; in vmw_dx_shader_scrub()
491 cmd->body.offsetInBytes = 0; in vmw_dx_shader_scrub()
493 res->id = -1; in vmw_dx_shader_scrub()
494 list_del_init(&shader->cotable_head); in vmw_dx_shader_scrub()
500 * vmw_dx_shader_unbind - The dx shader unbind callback.
502 * @res: The shader resource
510 struct vmw_private *dev_priv = res->dev_priv; in vmw_dx_shader_unbind()
514 BUG_ON(res->guest_memory_bo->tbo.resource->mem_type != VMW_PL_MOB); in vmw_dx_shader_unbind()
516 mutex_lock(&dev_priv->binding_mutex); in vmw_dx_shader_unbind()
518 mutex_unlock(&dev_priv->binding_mutex); in vmw_dx_shader_unbind()
525 vmw_bo_fence_single(val_buf->bo, fence); in vmw_dx_shader_unbind()
534 * vmw_dx_shader_cotable_list_scrub - The cotable unbind_func callback for
550 lockdep_assert_held_once(&dev_priv->binding_mutex); in vmw_dx_shader_cotable_list_scrub()
553 WARN_ON(vmw_dx_shader_scrub(&entry->res)); in vmw_dx_shader_cotable_list_scrub()
555 entry->committed = false; in vmw_dx_shader_cotable_list_scrub()
560 * vmw_dx_shader_res_free - The DX shader free callback
562 * @res: The shader resource
564 * Frees the DX shader resource.
570 vmw_resource_unreference(&shader->cotable); in vmw_dx_shader_res_free()
575 * vmw_dx_shader_add - Add a shader resource as a command buffer managed
576 * resource.
578 * @man: The command buffer resource manager.
579 * @ctx: Pointer to the context resource.
580 * @user_key: The id used for this shader.
592 struct vmw_private *dev_priv = ctx->dev_priv; in vmw_dx_shader_add()
596 return -EINVAL; in vmw_dx_shader_add()
600 return -ENOMEM; in vmw_dx_shader_add()
603 res = &shader->res; in vmw_dx_shader_add()
604 shader->ctx = ctx; in vmw_dx_shader_add()
605 shader->cotable = vmw_resource_reference in vmw_dx_shader_add()
607 shader->id = user_key; in vmw_dx_shader_add()
608 shader->committed = false; in vmw_dx_shader_add()
609 INIT_LIST_HEAD(&shader->cotable_head); in vmw_dx_shader_add()
616 * The user_key name-space is not per shader type for DX shaders, in vmw_dx_shader_add()
625 res->id = shader->id; in vmw_dx_shader_add()
626 res->hw_destroy = vmw_hw_shader_destroy; in vmw_dx_shader_add()
637 * User-space shader management:
643 return &(container_of(base, struct vmw_user_shader, base)-> in vmw_user_shader_base_to_res()
664 * base object. It releases the base-object's reference on the resource object.
680 struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; in vmw_shader_destroy_ioctl()
682 return ttm_ref_object_base_unref(tfile, arg->handle); in vmw_shader_destroy_ioctl()
701 ret = -ENOMEM; in vmw_user_shader_alloc()
705 res = &ushader->shader.res; in vmw_user_shader_alloc()
706 ushader->base.shareable = false; in vmw_user_shader_alloc()
707 ushader->base.tfile = NULL; in vmw_user_shader_alloc()
710 * From here on, the destructor takes over resource freeing. in vmw_user_shader_alloc()
721 ret = ttm_base_object_init(tfile, &ushader->base, false, in vmw_user_shader_alloc()
731 *handle = ushader->base.handle; in vmw_user_shader_alloc()
751 ret = -ENOMEM; in vmw_shader_alloc()
755 res = &shader->res; in vmw_shader_alloc()
758 * From here on, the destructor takes over resource freeing. in vmw_shader_alloc()
776 struct ttm_object_file *tfile = vmw_fpriv(file_priv)->tfile; in vmw_shader_define()
788 if ((u64)buffer->tbo.base.size < (u64)size + (u64)offset) { in vmw_shader_define()
789 VMW_DEBUG_USER("Illegal buffer- or shader size.\n"); in vmw_shader_define()
790 ret = -EINVAL; in vmw_shader_define()
804 ret = -EINVAL; in vmw_shader_define()
817 * vmw_shader_id_ok - Check whether a compat shader user key and
820 * @user_key: User space id of the shader.
827 return user_key <= ((1 << 20) - 1) && (unsigned) shader_type < 16; in vmw_shader_id_ok()
831 * vmw_shader_key - Compute a hash key suitable for a compat shader.
833 * @user_key: User space id of the shader.
836 * Returns a hash key suitable for a command buffer managed resource
845 * vmw_shader_remove - Stage a compat shader for removal.
851 * @list: Caller's list of staged command buffer resource actions.
860 return -EINVAL; in vmw_shader_remove()
868 * vmw_compat_shader_add - Create a compat shader and stage it for addition
869 * as a command buffer managed resource.
878 * @list: Caller's list of staged command buffer resource actions.
903 return -EINVAL; in vmw_compat_shader_add()
909 ret = ttm_bo_reserve(&buf->tbo, false, true, NULL); in vmw_compat_shader_add()
914 ret = ttm_bo_kmap(&buf->tbo, 0, PFN_UP(size), &map); in vmw_compat_shader_add()
916 ttm_bo_unreserve(&buf->tbo); in vmw_compat_shader_add()
924 ret = ttm_bo_validate(&buf->tbo, &buf->placement, &ctx); in vmw_compat_shader_add()
926 ttm_bo_unreserve(&buf->tbo); in vmw_compat_shader_add()
943 * vmw_shader_lookup - Look up a compat shader
945 * @man: Pointer to the command buffer managed resource manager identifying
947 * @user_key: The user space id of the shader.
959 return ERR_PTR(-EINVAL); in vmw_shader_lookup()
971 return vmw_shader_define(dev, file_priv, arg->shader_type, in vmw_shader_define_ioctl()
972 arg->buffer_handle, in vmw_shader_define_ioctl()
973 arg->size, arg->offset, in vmw_shader_define_ioctl()
975 &arg->shader_handle); in vmw_shader_define_ioctl()