Commit 6b2e8aa4 authored by Zack Rusin's avatar Zack Rusin

drm/vmwgfx: Remove the duplicate bo_free function

Remove the explicit bo_free parameter which was switching between
vmw_bo_bo_free and vmw_gem_destroy which had exactly the same
implementation.

It makes no sense to keep parameter which is always the same, remove it
and all code referencing it. Instead use the vmw_bo_bo_free directly.
Signed-off-by: default avatarZack Rusin <zackr@vmware.com>
Reviewed-by: default avatarMartin Krastev <krastevm@vmware.com>
Reviewed-by: default avatarMaaz Mombasawala <mombasawalam@vmware.com>
Acked-by: default avatarThomas Zimmermann <tzimmermann@suse.de>
Link: https://patchwork.freedesktop.org/patch/msgid/20230131033542.953249-3-zack@kde.org
parent 9da2957f
...@@ -46,6 +46,22 @@ vmw_buffer_object(struct ttm_buffer_object *bo) ...@@ -46,6 +46,22 @@ vmw_buffer_object(struct ttm_buffer_object *bo)
return container_of(bo, struct vmw_buffer_object, base); return container_of(bo, struct vmw_buffer_object, base);
} }
/**
* vmw_bo_bo_free - vmw buffer object destructor
*
* @bo: Pointer to the embedded struct ttm_buffer_object
*/
static void vmw_bo_bo_free(struct ttm_buffer_object *bo)
{
struct vmw_buffer_object *vmw_bo = vmw_buffer_object(bo);
WARN_ON(vmw_bo->dirty);
WARN_ON(!RB_EMPTY_ROOT(&vmw_bo->res_tree));
vmw_bo_unmap(vmw_bo);
drm_gem_object_release(&bo->base);
kfree(vmw_bo);
}
/** /**
* bo_is_vmw - check if the buffer object is a &vmw_buffer_object * bo_is_vmw - check if the buffer object is a &vmw_buffer_object
* @bo: ttm buffer object to be checked * @bo: ttm buffer object to be checked
...@@ -58,8 +74,7 @@ vmw_buffer_object(struct ttm_buffer_object *bo) ...@@ -58,8 +74,7 @@ vmw_buffer_object(struct ttm_buffer_object *bo)
*/ */
static bool bo_is_vmw(struct ttm_buffer_object *bo) static bool bo_is_vmw(struct ttm_buffer_object *bo)
{ {
return bo->destroy == &vmw_bo_bo_free || return bo->destroy == &vmw_bo_bo_free;
bo->destroy == &vmw_gem_destroy;
} }
/** /**
...@@ -361,23 +376,6 @@ void vmw_bo_unmap(struct vmw_buffer_object *vbo) ...@@ -361,23 +376,6 @@ void vmw_bo_unmap(struct vmw_buffer_object *vbo)
ttm_bo_kunmap(&vbo->map); ttm_bo_kunmap(&vbo->map);
} }
/**
* vmw_bo_bo_free - vmw buffer object destructor
*
* @bo: Pointer to the embedded struct ttm_buffer_object
*/
void vmw_bo_bo_free(struct ttm_buffer_object *bo)
{
struct vmw_buffer_object *vmw_bo = vmw_buffer_object(bo);
WARN_ON(vmw_bo->dirty);
WARN_ON(!RB_EMPTY_ROOT(&vmw_bo->res_tree));
vmw_bo_unmap(vmw_bo);
drm_gem_object_release(&bo->base);
kfree(vmw_bo);
}
/* default destructor */ /* default destructor */
static void vmw_bo_default_destroy(struct ttm_buffer_object *bo) static void vmw_bo_default_destroy(struct ttm_buffer_object *bo)
{ {
...@@ -434,13 +432,10 @@ int vmw_bo_create_kernel(struct vmw_private *dev_priv, unsigned long size, ...@@ -434,13 +432,10 @@ int vmw_bo_create_kernel(struct vmw_private *dev_priv, unsigned long size,
int vmw_bo_create(struct vmw_private *vmw, int vmw_bo_create(struct vmw_private *vmw,
size_t size, struct ttm_placement *placement, size_t size, struct ttm_placement *placement,
bool interruptible, bool pin, bool interruptible, bool pin,
void (*bo_free)(struct ttm_buffer_object *bo),
struct vmw_buffer_object **p_bo) struct vmw_buffer_object **p_bo)
{ {
int ret; int ret;
BUG_ON(!bo_free);
*p_bo = kmalloc(sizeof(**p_bo), GFP_KERNEL); *p_bo = kmalloc(sizeof(**p_bo), GFP_KERNEL);
if (unlikely(!*p_bo)) { if (unlikely(!*p_bo)) {
DRM_ERROR("Failed to allocate a buffer.\n"); DRM_ERROR("Failed to allocate a buffer.\n");
...@@ -448,8 +443,7 @@ int vmw_bo_create(struct vmw_private *vmw, ...@@ -448,8 +443,7 @@ int vmw_bo_create(struct vmw_private *vmw,
} }
ret = vmw_bo_init(vmw, *p_bo, size, ret = vmw_bo_init(vmw, *p_bo, size,
placement, interruptible, pin, placement, interruptible, pin);
bo_free);
if (unlikely(ret != 0)) if (unlikely(ret != 0))
goto out_error; goto out_error;
...@@ -469,7 +463,6 @@ int vmw_bo_create(struct vmw_private *vmw, ...@@ -469,7 +463,6 @@ int vmw_bo_create(struct vmw_private *vmw,
* @placement: Initial placement. * @placement: Initial placement.
* @interruptible: Whether waits should be performed interruptible. * @interruptible: Whether waits should be performed interruptible.
* @pin: If the BO should be created pinned at a fixed location. * @pin: If the BO should be created pinned at a fixed location.
* @bo_free: The buffer object destructor.
* Returns: Zero on success, negative error code on error. * Returns: Zero on success, negative error code on error.
* *
* Note that on error, the code will free the buffer object. * Note that on error, the code will free the buffer object.
...@@ -477,8 +470,7 @@ int vmw_bo_create(struct vmw_private *vmw, ...@@ -477,8 +470,7 @@ int vmw_bo_create(struct vmw_private *vmw,
int vmw_bo_init(struct vmw_private *dev_priv, int vmw_bo_init(struct vmw_private *dev_priv,
struct vmw_buffer_object *vmw_bo, struct vmw_buffer_object *vmw_bo,
size_t size, struct ttm_placement *placement, size_t size, struct ttm_placement *placement,
bool interruptible, bool pin, bool interruptible, bool pin)
void (*bo_free)(struct ttm_buffer_object *bo))
{ {
struct ttm_operation_ctx ctx = { struct ttm_operation_ctx ctx = {
.interruptible = interruptible, .interruptible = interruptible,
...@@ -488,7 +480,6 @@ int vmw_bo_init(struct vmw_private *dev_priv, ...@@ -488,7 +480,6 @@ int vmw_bo_init(struct vmw_private *dev_priv,
struct drm_device *vdev = &dev_priv->drm; struct drm_device *vdev = &dev_priv->drm;
int ret; int ret;
WARN_ON_ONCE(!bo_free);
memset(vmw_bo, 0, sizeof(*vmw_bo)); memset(vmw_bo, 0, sizeof(*vmw_bo));
BUILD_BUG_ON(TTM_MAX_BO_PRIORITY <= 3); BUILD_BUG_ON(TTM_MAX_BO_PRIORITY <= 3);
vmw_bo->base.priority = 3; vmw_bo->base.priority = 3;
...@@ -498,7 +489,7 @@ int vmw_bo_init(struct vmw_private *dev_priv, ...@@ -498,7 +489,7 @@ int vmw_bo_init(struct vmw_private *dev_priv,
drm_gem_private_object_init(vdev, &vmw_bo->base.base, size); drm_gem_private_object_init(vdev, &vmw_bo->base.base, size);
ret = ttm_bo_init_reserved(bdev, &vmw_bo->base, ttm_bo_type_device, ret = ttm_bo_init_reserved(bdev, &vmw_bo->base, ttm_bo_type_device,
placement, 0, &ctx, NULL, NULL, bo_free); placement, 0, &ctx, NULL, NULL, vmw_bo_bo_free);
if (unlikely(ret)) { if (unlikely(ret)) {
return ret; return ret;
} }
......
...@@ -424,7 +424,7 @@ static int vmw_cotable_resize(struct vmw_resource *res, size_t new_size) ...@@ -424,7 +424,7 @@ static int vmw_cotable_resize(struct vmw_resource *res, size_t new_size)
* we can use tryreserve without failure. * we can use tryreserve without failure.
*/ */
ret = vmw_bo_create(dev_priv, new_size, &vmw_mob_placement, ret = vmw_bo_create(dev_priv, new_size, &vmw_mob_placement,
true, true, vmw_bo_bo_free, &buf); true, true, &buf);
if (ret) { if (ret) {
DRM_ERROR("Failed initializing new cotable MOB.\n"); DRM_ERROR("Failed initializing new cotable MOB.\n");
goto out_done; goto out_done;
......
...@@ -397,8 +397,7 @@ static int vmw_dummy_query_bo_create(struct vmw_private *dev_priv) ...@@ -397,8 +397,7 @@ static int vmw_dummy_query_bo_create(struct vmw_private *dev_priv)
* user of the bo currently. * user of the bo currently.
*/ */
ret = vmw_bo_create(dev_priv, PAGE_SIZE, ret = vmw_bo_create(dev_priv, PAGE_SIZE,
&vmw_sys_placement, false, true, &vmw_sys_placement, false, true, &vbo);
&vmw_bo_bo_free, &vbo);
if (unlikely(ret != 0)) if (unlikely(ret != 0))
return ret; return ret;
......
...@@ -893,7 +893,6 @@ extern int vmw_bo_unpin(struct vmw_private *vmw_priv, ...@@ -893,7 +893,6 @@ extern int vmw_bo_unpin(struct vmw_private *vmw_priv,
extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf, extern void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf,
SVGAGuestPtr *ptr); SVGAGuestPtr *ptr);
extern void vmw_bo_pin_reserved(struct vmw_buffer_object *bo, bool pin); extern void vmw_bo_pin_reserved(struct vmw_buffer_object *bo, bool pin);
extern void vmw_bo_bo_free(struct ttm_buffer_object *bo);
extern int vmw_bo_create_kernel(struct vmw_private *dev_priv, extern int vmw_bo_create_kernel(struct vmw_private *dev_priv,
unsigned long size, unsigned long size,
struct ttm_placement *placement, struct ttm_placement *placement,
...@@ -901,13 +900,11 @@ extern int vmw_bo_create_kernel(struct vmw_private *dev_priv, ...@@ -901,13 +900,11 @@ extern int vmw_bo_create_kernel(struct vmw_private *dev_priv,
extern int vmw_bo_create(struct vmw_private *dev_priv, extern int vmw_bo_create(struct vmw_private *dev_priv,
size_t size, struct ttm_placement *placement, size_t size, struct ttm_placement *placement,
bool interruptible, bool pin, bool interruptible, bool pin,
void (*bo_free)(struct ttm_buffer_object *bo),
struct vmw_buffer_object **p_bo); struct vmw_buffer_object **p_bo);
extern int vmw_bo_init(struct vmw_private *dev_priv, extern int vmw_bo_init(struct vmw_private *dev_priv,
struct vmw_buffer_object *vmw_bo, struct vmw_buffer_object *vmw_bo,
size_t size, struct ttm_placement *placement, size_t size, struct ttm_placement *placement,
bool interruptible, bool pin, bool interruptible, bool pin);
void (*bo_free)(struct ttm_buffer_object *bo));
extern int vmw_bo_unref_ioctl(struct drm_device *dev, void *data, extern int vmw_bo_unref_ioctl(struct drm_device *dev, void *data,
struct drm_file *file_priv); struct drm_file *file_priv);
extern int vmw_user_bo_synccpu_ioctl(struct drm_device *dev, void *data, extern int vmw_user_bo_synccpu_ioctl(struct drm_device *dev, void *data,
...@@ -982,7 +979,6 @@ extern int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv, ...@@ -982,7 +979,6 @@ extern int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv,
struct vmw_buffer_object **p_vbo); struct vmw_buffer_object **p_vbo);
extern int vmw_gem_object_create_ioctl(struct drm_device *dev, void *data, extern int vmw_gem_object_create_ioctl(struct drm_device *dev, void *data,
struct drm_file *filp); struct drm_file *filp);
extern void vmw_gem_destroy(struct ttm_buffer_object *bo);
extern void vmw_debugfs_gem_init(struct vmw_private *vdev); extern void vmw_debugfs_gem_init(struct vmw_private *vdev);
/** /**
......
...@@ -125,22 +125,6 @@ static const struct drm_gem_object_funcs vmw_gem_object_funcs = { ...@@ -125,22 +125,6 @@ static const struct drm_gem_object_funcs vmw_gem_object_funcs = {
.vm_ops = &vmw_vm_ops, .vm_ops = &vmw_vm_ops,
}; };
/**
* vmw_gem_destroy - vmw buffer object destructor
*
* @bo: Pointer to the embedded struct ttm_buffer_object
*/
void vmw_gem_destroy(struct ttm_buffer_object *bo)
{
struct vmw_buffer_object *vbo = vmw_buffer_object(bo);
WARN_ON(vbo->dirty);
WARN_ON(!RB_EMPTY_ROOT(&vbo->res_tree));
vmw_bo_unmap(vbo);
drm_gem_object_release(&vbo->base.base);
kfree(vbo);
}
int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv, int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv,
struct drm_file *filp, struct drm_file *filp,
uint32_t size, uint32_t size,
...@@ -153,7 +137,7 @@ int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv, ...@@ -153,7 +137,7 @@ int vmw_gem_object_create_with_handle(struct vmw_private *dev_priv,
(dev_priv->has_mob) ? (dev_priv->has_mob) ?
&vmw_sys_placement : &vmw_sys_placement :
&vmw_vram_sys_placement, &vmw_vram_sys_placement,
true, false, &vmw_gem_destroy, p_vbo); true, false, p_vbo);
(*p_vbo)->base.base.funcs = &vmw_gem_object_funcs; (*p_vbo)->base.base.funcs = &vmw_gem_object_funcs;
if (ret != 0) if (ret != 0)
......
...@@ -332,8 +332,7 @@ static int vmw_resource_buf_alloc(struct vmw_resource *res, ...@@ -332,8 +332,7 @@ static int vmw_resource_buf_alloc(struct vmw_resource *res,
ret = vmw_bo_create(res->dev_priv, res->backup_size, ret = vmw_bo_create(res->dev_priv, res->backup_size,
res->func->backup_placement, res->func->backup_placement,
interruptible, false, interruptible, false, &backup);
&vmw_bo_bo_free, &backup);
if (unlikely(ret != 0)) if (unlikely(ret != 0))
goto out_no_bo; goto out_no_bo;
......
...@@ -445,7 +445,7 @@ vmw_sou_primary_plane_prepare_fb(struct drm_plane *plane, ...@@ -445,7 +445,7 @@ vmw_sou_primary_plane_prepare_fb(struct drm_plane *plane,
vmw_overlay_pause_all(dev_priv); vmw_overlay_pause_all(dev_priv);
ret = vmw_bo_create(dev_priv, size, ret = vmw_bo_create(dev_priv, size,
&vmw_vram_placement, &vmw_vram_placement,
false, true, &vmw_bo_bo_free, &vps->bo); false, true, &vps->bo);
vmw_overlay_resume_all(dev_priv); vmw_overlay_resume_all(dev_priv);
if (ret) { if (ret) {
vps->bo = NULL; /* vmw_bo_init frees on error */ vps->bo = NULL; /* vmw_bo_init frees on error */
......
...@@ -893,7 +893,7 @@ int vmw_compat_shader_add(struct vmw_private *dev_priv, ...@@ -893,7 +893,7 @@ int vmw_compat_shader_add(struct vmw_private *dev_priv,
return -EINVAL; return -EINVAL;
ret = vmw_bo_create(dev_priv, size, &vmw_sys_placement, ret = vmw_bo_create(dev_priv, size, &vmw_sys_placement,
true, true, vmw_bo_bo_free, &buf); true, true, &buf);
if (unlikely(ret != 0)) if (unlikely(ret != 0))
goto out; goto out;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment