// SPDX-License-Identifier: GPL-2.0 OR MIT /************************************************************************** * * Copyright 2009-2023 VMware, Inc., Palo Alto, CA., USA * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sub license, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice (including the * next paragraph) shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE * USE OR OTHER DEALINGS IN THE SOFTWARE. *
**************************************************************************/
/** * vmw_dx_shader_commit_notify - Notify that a shader operation has been * committed to hardware from a user-supplied command stream. * * @res: Pointer to the shader resource. * @state: Indicating whether a creation or removal has been committed. *
*/ staticvoid vmw_dx_shader_commit_notify(struct vmw_resource *res, enum vmw_cmdbuf_res_state state)
{ struct vmw_dx_shader *shader = vmw_res_to_dx_shader(res); struct vmw_private *dev_priv = res->dev_priv;
/** * vmw_dx_shader_create - The DX shader create callback * * @res: The DX shader resource * * The create callback is called as part of resource validation and * makes sure that we unscrub the shader if it's previously been scrubbed.
*/ staticint vmw_dx_shader_create(struct vmw_resource *res)
{ struct vmw_private *dev_priv = res->dev_priv; struct vmw_dx_shader *shader = vmw_res_to_dx_shader(res); int ret = 0;
WARN_ON_ONCE(!shader->committed);
if (vmw_resource_mob_attached(res)) {
mutex_lock(&dev_priv->binding_mutex);
ret = vmw_dx_shader_unscrub(res);
mutex_unlock(&dev_priv->binding_mutex);
}
/** * vmw_dx_shader_scrub - Have the device unbind a MOB from a DX shader. * * @res: The shader resource * * This function unbinds a MOB from the DX shader without requiring the * MOB dma_buffer to be reserved. The driver still considers the MOB bound. * However, once the driver eventually decides to unbind the MOB, it doesn't * need to access the context.
*/ staticint vmw_dx_shader_scrub(struct vmw_resource *res)
{ struct vmw_dx_shader *shader = vmw_res_to_dx_shader(res); struct vmw_private *dev_priv = res->dev_priv; struct {
SVGA3dCmdHeader header;
SVGA3dCmdDXBindShader body;
} *cmd;
if (likely(fence != NULL))
vmw_fence_obj_unreference(&fence);
return 0;
}
/** * vmw_dx_shader_cotable_list_scrub - The cotable unbind_func callback for * DX shaders. * * @dev_priv: Pointer to device private structure. * @list: The list of cotable resources. * @readback: Whether the call was part of a readback unbind. * * Scrubs all shader MOBs so that any subsequent shader unbind or shader * destroy operation won't need to swap in the context.
*/ void vmw_dx_shader_cotable_list_scrub(struct vmw_private *dev_priv, struct list_head *list, bool readback)
{ struct vmw_dx_shader *entry, *next;
/** * vmw_dx_shader_add - Add a shader resource as a command buffer managed * resource. * * @man: The command buffer resource manager. * @ctx: Pointer to the context resource. * @user_key: The id used for this shader. * @shader_type: The shader type. * @list: The list of staged command buffer managed resources.
*/ int vmw_dx_shader_add(struct vmw_cmdbuf_res_manager *man, struct vmw_resource *ctx,
u32 user_key,
SVGA3dShaderType shader_type, struct list_head *list)
{ struct vmw_dx_shader *shader; struct vmw_resource *res; struct vmw_private *dev_priv = ctx->dev_priv; int ret;
if (!vmw_shader_id_ok(user_key, shader_type)) return -EINVAL;
shader = kmalloc(sizeof(*shader), GFP_KERNEL); if (!shader) { return -ENOMEM;
}
res = &shader->res;
shader->ctx = ctx;
shader->cotable = vmw_resource_reference
(vmw_context_cotable(ctx, SVGA_COTABLE_DXSHADER));
shader->id = user_key;
shader->committed = false;
INIT_LIST_HEAD(&shader->cotable_head);
ret = vmw_resource_init(dev_priv, res, true,
vmw_dx_shader_res_free, &vmw_dx_shader_func); if (ret) goto out_resource_init;
/* * The user_key name-space is not per shader type for DX shaders, * so when hashing, use a single zero shader type.
*/
ret = vmw_cmdbuf_res_add(man, vmw_cmdbuf_res_shader,
vmw_shader_key(user_key, 0),
res, list); if (ret) goto out_resource_init;
/* * This function is called when user space has no more references on the * base object. It releases the base-object's reference on the resource object.
*/
shader = kzalloc(sizeof(*shader), GFP_KERNEL); if (unlikely(!shader)) {
ret = -ENOMEM; goto out_err;
}
res = &shader->res;
/* * From here on, the destructor takes over resource freeing.
*/
ret = vmw_gb_shader_init(dev_priv, res, shader_size,
offset, shader_type, 0, 0, buffer,
vmw_shader_free);
/** * vmw_shader_id_ok - Check whether a compat shader user key and * shader type are within valid bounds. * * @user_key: User space id of the shader. * @shader_type: Shader type. * * Returns true if valid false if not.
*/ staticbool vmw_shader_id_ok(u32 user_key, SVGA3dShaderType shader_type)
{ return user_key <= ((1 << 20) - 1) && (unsigned) shader_type < 16;
}
/** * vmw_shader_key - Compute a hash key suitable for a compat shader. * * @user_key: User space id of the shader. * @shader_type: Shader type. * * Returns a hash key suitable for a command buffer managed resource * manager hash table.
*/ static u32 vmw_shader_key(u32 user_key, SVGA3dShaderType shader_type)
{ return user_key | (shader_type << 20);
}
/** * vmw_shader_remove - Stage a compat shader for removal. * * @man: Pointer to the compat shader manager identifying the shader namespace. * @user_key: The key that is used to identify the shader. The key is * unique to the shader type. * @shader_type: Shader type. * @list: Caller's list of staged command buffer resource actions.
*/ int vmw_shader_remove(struct vmw_cmdbuf_res_manager *man,
u32 user_key, SVGA3dShaderType shader_type, struct list_head *list)
{ struct vmw_resource *dummy;
if (!vmw_shader_id_ok(user_key, shader_type)) return -EINVAL;
/** * vmw_shader_lookup - Look up a compat shader * * @man: Pointer to the command buffer managed resource manager identifying * the shader namespace. * @user_key: The user space id of the shader. * @shader_type: The shader type. * * Returns a refcounted pointer to a struct vmw_resource if the shader was * found. An error pointer otherwise.
*/ struct vmw_resource *
vmw_shader_lookup(struct vmw_cmdbuf_res_manager *man,
u32 user_key,
SVGA3dShaderType shader_type)
{ if (!vmw_shader_id_ok(user_key, shader_type)) return ERR_PTR(-EINVAL);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.