diff options
25 files changed, 419 insertions, 385 deletions
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c index 0859c72b52ea..a307f34d9189 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 OR MIT /************************************************************************** * - * Copyright © 2011-2018 VMware, Inc., Palo Alto, CA., USA + * Copyright © 2011-2023 VMware, Inc., Palo Alto, CA., USA * All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a @@ -26,55 +26,41 @@ * **************************************************************************/ -#include <drm/ttm/ttm_placement.h> - +#include "vmwgfx_bo.h" #include "vmwgfx_drv.h" -#include "ttm_object.h" -/** - * vmw_buffer_object - Convert a struct ttm_buffer_object to a struct - * vmw_buffer_object. - * - * @bo: Pointer to the TTM buffer object. - * Return: Pointer to the struct vmw_buffer_object embedding the - * TTM buffer object. - */ -static struct vmw_buffer_object * -vmw_buffer_object(struct ttm_buffer_object *bo) -{ - return container_of(bo, struct vmw_buffer_object, base); -} +#include <drm/ttm/ttm_placement.h> /** - * vmw_bo_bo_free - vmw buffer object destructor + * vmw_bo_free - vmw_bo destructor * * @bo: Pointer to the embedded struct ttm_buffer_object */ -static void vmw_bo_bo_free(struct ttm_buffer_object *bo) +static void vmw_bo_free(struct ttm_buffer_object *bo) { - struct vmw_buffer_object *vmw_bo = vmw_buffer_object(bo); + struct vmw_bo *vbo = to_vmw_bo(&bo->base); - WARN_ON(vmw_bo->dirty); - WARN_ON(!RB_EMPTY_ROOT(&vmw_bo->res_tree)); - vmw_bo_unmap(vmw_bo); + WARN_ON(vbo->dirty); + WARN_ON(!RB_EMPTY_ROOT(&vbo->res_tree)); + vmw_bo_unmap(vbo); drm_gem_object_release(&bo->base); - kfree(vmw_bo); + kfree(vbo); } /** - * bo_is_vmw - check if the buffer object is a &vmw_buffer_object + * bo_is_vmw - check if the buffer object is a &vmw_bo * @bo: ttm buffer object to be checked * * Uses destroy function associated with the object to determine if this is - * a &vmw_buffer_object. + * a &vmw_bo. * * Returns: - * true if the object is of &vmw_buffer_object type, false if not. + * true if the object is of &vmw_bo type, false if not. */ static bool bo_is_vmw(struct ttm_buffer_object *bo) { - return bo->destroy == &vmw_bo_bo_free; + return bo->destroy == &vmw_bo_free; } /** @@ -88,7 +74,7 @@ static bool bo_is_vmw(struct ttm_buffer_object *bo) * -ERESTARTSYS if interrupted by a signal */ int vmw_bo_pin_in_placement(struct vmw_private *dev_priv, - struct vmw_buffer_object *buf, + struct vmw_bo *buf, struct ttm_placement *placement, bool interruptible) { @@ -125,7 +111,7 @@ err: * -ERESTARTSYS if interrupted by a signal */ int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv, - struct vmw_buffer_object *buf, + struct vmw_bo *buf, bool interruptible) { struct ttm_operation_ctx ctx = {interruptible, false }; @@ -167,7 +153,7 @@ err: * -ERESTARTSYS if interrupted by a signal */ int vmw_bo_pin_in_vram(struct vmw_private *dev_priv, - struct vmw_buffer_object *buf, + struct vmw_bo *buf, bool interruptible) { return vmw_bo_pin_in_placement(dev_priv, buf, &vmw_vram_placement, @@ -188,7 +174,7 @@ int vmw_bo_pin_in_vram(struct vmw_private *dev_priv, * -ERESTARTSYS if interrupted by a signal */ int vmw_bo_pin_in_start_of_vram(struct vmw_private *dev_priv, - struct vmw_buffer_object *buf, + struct vmw_bo *buf, bool interruptible) { struct ttm_operation_ctx ctx = {interruptible, false }; @@ -248,7 +234,7 @@ err_unlock: * -ERESTARTSYS if interrupted by a signal */ int vmw_bo_unpin(struct vmw_private *dev_priv, - struct vmw_buffer_object *buf, + struct vmw_bo *buf, bool interruptible) { struct ttm_buffer_object *bo = &buf->base; @@ -293,7 +279,7 @@ void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *bo, * @pin: Whether to pin or unpin. * */ -void vmw_bo_pin_reserved(struct vmw_buffer_object *vbo, bool pin) +void vmw_bo_pin_reserved(struct vmw_bo *vbo, bool pin) { struct ttm_operation_ctx ctx = { false, true }; struct ttm_place pl; @@ -341,7 +327,7 @@ void vmw_bo_pin_reserved(struct vmw_buffer_object *vbo, bool pin) * 3) Buffer object destruction * */ -void *vmw_bo_map_and_cache(struct vmw_buffer_object *vbo) +void *vmw_bo_map_and_cache(struct vmw_bo *vbo) { struct ttm_buffer_object *bo = &vbo->base; bool not_used; @@ -366,9 +352,9 @@ void *vmw_bo_map_and_cache(struct vmw_buffer_object *vbo) * @vbo: The buffer object whose map we are tearing down. * * This function tears down a cached map set up using - * vmw_buffer_object_map_and_cache(). + * vmw_bo_map_and_cache(). */ -void vmw_bo_unmap(struct vmw_buffer_object *vbo) +void vmw_bo_unmap(struct vmw_bo *vbo) { if (vbo->map.bo == NULL) return; @@ -432,7 +418,7 @@ error_free: int vmw_bo_create(struct vmw_private *vmw, size_t size, struct ttm_placement *placement, bool interruptible, bool pin, - struct vmw_buffer_object **p_bo) + struct vmw_bo **p_bo) { int ret; @@ -458,7 +444,7 @@ out_error: * vmw_bo_init - Initialize a vmw buffer object * * @dev_priv: Pointer to the device private struct - * @vmw_bo: Pointer to the struct vmw_buffer_object to initialize. + * @vmw_bo: Pointer to the struct vmw_bo to initialize. * @size: Buffer object size in bytes. * @placement: Initial placement. * @interruptible: Whether waits should be performed interruptible. @@ -468,7 +454,7 @@ out_error: * Note that on error, the code will free the buffer object. */ int vmw_bo_init(struct vmw_private *dev_priv, - struct vmw_buffer_object *vmw_bo, + struct vmw_bo *vmw_bo, size_t size, struct ttm_placement *placement, bool interruptible, bool pin) { @@ -489,7 +475,7 @@ int vmw_bo_init(struct vmw_private *dev_priv, drm_gem_private_object_init(vdev, &vmw_bo->base.base, size); ret = ttm_bo_init_reserved(bdev, &vmw_bo->base, ttm_bo_type_device, - placement, 0, &ctx, NULL, NULL, vmw_bo_bo_free); + placement, 0, &ctx, NULL, NULL, vmw_bo_free); if (unlikely(ret)) { return ret; } @@ -502,7 +488,7 @@ int vmw_bo_init(struct vmw_private *dev_priv, } /** - * vmw_user_bo_synccpu_grab - Grab a struct vmw_buffer_object for cpu + * vmw_user_bo_synccpu_grab - Grab a struct vmw_bo for cpu * access, idling previous GPU operations on the buffer and optionally * blocking it for further command submissions. * @@ -515,7 +501,7 @@ int vmw_bo_init(struct vmw_private *dev_priv, * * A blocking grab will be automatically released when @tfile is closed. */ -static int vmw_user_bo_synccpu_grab(struct vmw_buffer_object *vmw_bo, +static int vmw_user_bo_synccpu_grab(struct vmw_bo *vmw_bo, uint32_t flags) { bool nonblock = !!(flags & drm_vmw_synccpu_dontblock); @@ -562,7 +548,7 @@ static int vmw_user_bo_synccpu_release(struct drm_file *filp, uint32_t handle, uint32_t flags) { - struct vmw_buffer_object *vmw_bo; + struct vmw_bo *vmw_bo; int ret = vmw_user_bo_lookup(filp, handle, &vmw_bo); if (!ret) { @@ -593,7 +579,7 @@ int vmw_user_bo_synccpu_ioctl(struct drm_device *dev, void *data, { struct drm_vmw_synccpu_arg *arg = (struct drm_vmw_synccpu_arg *) data; - struct vmw_buffer_object *vbo; + struct vmw_bo *vbo; int ret; if ((arg->flags & (drm_vmw_synccpu_read | drm_vmw_synccpu_write)) == 0 @@ -666,14 +652,14 @@ int vmw_bo_unref_ioctl(struct drm_device *dev, void *data, * @filp: The file the handle is registered with. * @handle: The user buffer object handle * @out: Pointer to a where a pointer to the embedded - * struct vmw_buffer_object should be placed. + * struct vmw_bo should be placed. * Return: Zero on success, Negative error code on error. * * The vmw buffer object pointer will be refcounted. */ int vmw_user_bo_lookup(struct drm_file *filp, uint32_t handle, - struct vmw_buffer_object **out) + struct vmw_bo **out) { struct drm_gem_object *gobj; @@ -684,7 +670,7 @@ int vmw_user_bo_lookup(struct drm_file *filp, return -ESRCH; } - *out = gem_to_vmw_bo(gobj); + *out = to_vmw_bo(gobj); ttm_bo_get(&(*out)->base); drm_gem_object_put(gobj); @@ -744,7 +730,7 @@ int vmw_dumb_create(struct drm_file *file_priv, struct drm_mode_create_dumb *args) { struct vmw_private *dev_priv = vmw_priv(dev); - struct vmw_buffer_object *vbo; + struct vmw_bo *vbo; int cpp = DIV_ROUND_UP(args->bpp, 8); int ret; @@ -778,12 +764,12 @@ int vmw_dumb_create(struct drm_file *file_priv, */ void vmw_bo_swap_notify(struct ttm_buffer_object *bo) { - /* Is @bo embedded in a struct vmw_buffer_object? */ + /* Is @bo embedded in a struct vmw_bo? */ if (!bo_is_vmw(bo)) return; /* Kill any cached kernel maps before swapout */ - vmw_bo_unmap(vmw_buffer_object(bo)); + vmw_bo_unmap(to_vmw_bo(&bo->base)); } @@ -800,13 +786,13 @@ void vmw_bo_swap_notify(struct ttm_buffer_object *bo) void vmw_bo_move_notify(struct ttm_buffer_object *bo, struct ttm_resource *mem) { - struct vmw_buffer_object *vbo; + struct vmw_bo *vbo; - /* Make sure @bo is embedded in a struct vmw_buffer_object? */ + /* Make sure @bo is embedded in a struct vmw_bo? */ if (!bo_is_vmw(bo)) return; - vbo = container_of(bo, struct vmw_buffer_object, base); + vbo = container_of(bo, struct vmw_bo, base); /* * Kill any cached kernel maps before move to or from VRAM. diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.h b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.h new file mode 100644 index 000000000000..498767d937c7 --- /dev/null +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.h @@ -0,0 +1,189 @@ +/* SPDX-License-Identifier: GPL-2.0 OR MIT */ +/************************************************************************** + * + * Copyright 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. + * + **************************************************************************/ + +#ifndef VMWGFX_BO_H +#define VMWGFX_BO_H + +#include "device_include/svga_reg.h" + +#include <drm/ttm/ttm_bo.h> + +#include <linux/rbtree_types.h> +#include <linux/types.h> + +struct vmw_bo_dirty; +struct vmw_fence_obj; +struct vmw_private; +struct vmw_resource; + +/** + * struct vmw_bo - TTM buffer object with vmwgfx additions + * @base: The TTM buffer object + * @res_tree: RB tree of resources using this buffer object as a backing MOB + * @base_mapped_count: ttm BO mapping count; used by KMS atomic helpers. + * @cpu_writers: Number of synccpu write grabs. Protected by reservation when + * increased. May be decreased without reservation. + * @dx_query_ctx: DX context if this buffer object is used as a DX query MOB + * @map: Kmap object for semi-persistent mappings + * @res_prios: Eviction priority counts for attached resources + * @dirty: structure for user-space dirty-tracking + */ +struct vmw_bo { + struct ttm_buffer_object base; + struct rb_root res_tree; + /* For KMS atomic helpers: ttm bo mapping count */ + atomic_t base_mapped_count; + + atomic_t cpu_writers; + /* Not ref-counted. Protected by binding_mutex */ + struct vmw_resource *dx_query_ctx; + /* Protected by reservation */ + struct ttm_bo_kmap_obj map; + u32 res_prios[TTM_MAX_BO_PRIORITY]; + struct vmw_bo_dirty *dirty; +}; + +int vmw_bo_create_kernel(struct vmw_private *dev_priv, + unsigned long size, + struct ttm_placement *placement, + struct ttm_buffer_object **p_bo); +int vmw_bo_create(struct vmw_private *dev_priv, + size_t size, struct ttm_placement *placement, + bool interruptible, bool pin, + struct vmw_bo **p_bo); +int vmw_bo_init(struct vmw_private *dev_priv, + struct vmw_bo *vmw_bo, + size_t size, struct ttm_placement *placement, + bool interruptible, bool pin); +int vmw_bo_unref_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv); + +int vmw_bo_pin_in_placement(struct vmw_private *vmw_priv, + struct vmw_bo *bo, + struct ttm_placement *placement, + bool interruptible); +int vmw_bo_pin_in_vram(struct vmw_private *dev_priv, + struct vmw_bo *buf, + bool interruptible); +int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv, + struct vmw_bo *buf, + bool interruptible); +int vmw_bo_pin_in_start_of_vram(struct vmw_private *vmw_priv, + struct vmw_bo *bo, + bool interruptible); +void vmw_bo_pin_reserved(struct vmw_bo *bo, bool pin); +int vmw_bo_unpin(struct vmw_private *vmw_priv, + struct vmw_bo *bo, + bool interruptible); + +void vmw_bo_get_guest_ptr(const struct ttm_buffer_object *buf, + SVGAGuestPtr *ptr); +int vmw_user_bo_synccpu_ioctl(struct drm_device *dev, void *data, + struct drm_file *file_priv); +int vmw_user_bo_lookup(struct drm_file *filp, + uint32_t handle, + struct vmw_bo **out); +void vmw_bo_fence_single(struct ttm_buffer_object *bo, + struct vmw_fence_obj *fence); + +void *vmw_bo_map_and_cache(struct vmw_bo *vbo); +void vmw_bo_unmap(struct vmw_bo *vbo); + +void vmw_bo_move_notify(struct ttm_buffer_object *bo, + struct ttm_resource *mem); +void vmw_bo_swap_notify(struct ttm_buffer_object *bo); + +/** + * vmw_bo_adjust_prio - Adjust the buffer object eviction priority + * according to attached resources + * @vbo: The struct vmw_bo + */ +static inline void vmw_bo_prio_adjust(struct vmw_bo *vbo) +{ + int i = ARRAY_SIZE(vbo->res_prios); + + while (i--) { + if (vbo->res_prios[i]) { + vbo->base.priority = i; + return; + } + } + + vbo->base.priority = 3; +} + +/** + * vmw_bo_prio_add - Notify a buffer object of a newly attached resource + * eviction priority + * @vbo: The struct vmw_bo + * @prio: The resource priority + * + * After being notified, the code assigns the highest resource eviction priority + * to the backing buffer object (mob). + */ +static inline void vmw_bo_prio_add(struct vmw_bo *vbo, int prio) +{ + if (vbo->res_prios[prio]++ == 0) + vmw_bo_prio_adjust(vbo); +} + +/** + * vmw_bo_prio_del - Notify a buffer object of a resource with a certain + * priority being removed + * @vbo: The struct vmw_bo + * @prio: The resource priority + * + * After being notified, the code assigns the highest resource eviction priority + * to the backing buffer object (mob). + */ +static inline void vmw_bo_prio_del(struct vmw_bo *vbo, int prio) +{ + if (--vbo->res_prios[prio] == 0) + vmw_bo_prio_adjust(vbo); +} + +static inline void vmw_bo_unreference(struct vmw_bo **buf) +{ + struct vmw_bo *tmp_buf = *buf; + + *buf = NULL; + if (tmp_buf) + ttm_bo_put(&tmp_buf->base); +} + +static inline struct vmw_bo *vmw_bo_reference(struct vmw_bo *buf) +{ + ttm_bo_get(&buf->base); + return buf; +} + +static inline struct vmw_bo *to_vmw_bo(struct drm_gem_object *gobj) +{ + return container_of((gobj), struct vmw_bo, base.base); +} + +#endif // VMWGFX_BO_H diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c b/drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c index 162dfeb1cc5a..b1e7810032d3 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 OR MIT /************************************************************************** * - * Copyright 2009-2020 VMware, Inc., Palo Alto, CA., USA + * 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 @@ -24,13 +24,13 @@ * USE OR OTHER DEALINGS IN THE SOFTWARE. * **************************************************************************/ - -#include <linux/sched/signal.h> +#include "vmwgfx_bo.h" +#include "vmwgfx_drv.h" +#include "vmwgfx_devcaps.h" #include <drm/ttm/ttm_placement.h> -#include "vmwgfx_drv.h" -#include "vmwgfx_devcaps.h" +#include <linux/sched/signal.h> bool vmw_supports_3d(struct vmw_private *dev_priv) { diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c b/drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c index 2b843ff4b437..11ff367692ce 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 OR MIT /************************************************************************** * - * Copyright 2015 VMware, Inc., Palo Alto, CA., USA + * Copyright 2015-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 @@ -25,12 +25,13 @@ * **************************************************************************/ -#include <linux/dmapool.h> -#include <linux/pci.h> +#include "vmwgfx_bo.h" +#include "vmwgfx_drv.h" #include <drm/ttm/ttm_bo.h> -#include "vmwgfx_drv.h" +#include <linux/dmapool.h> +#include <linux/pci.h> /* * Size of inline command buffers. Try to make sure that a page size is a diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_context.c b/drivers/gpu/drm/vmwgfx/vmwgfx_context.c index e0f48cd9529b..cc02be6a9884 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_context.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_context.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 OR MIT /************************************************************************** * - * Copyright 2009-2015 VMware, Inc., Palo Alto, CA., USA + * 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 @@ -27,9 +27,10 @@ #include <drm/ttm/ttm_placement.h> +#include "vmwgfx_binding.h" +#include "vmwgfx_bo.h" #include "vmwgfx_drv.h" #include "vmwgfx_resource_priv.h" -#include "vmwgfx_binding.h" struct vmw_user_context { struct ttm_base_object base; @@ -38,7 +39,7 @@ struct vmw_user_context { struct vmw_cmdbuf_res_manager *man; struct vmw_resource *cotables[SVGA_COTABLE_MAX]; spinlock_t cotable_lock; - struct vmw_buffer_object *dx_query_mob; + struct vmw_bo *dx_query_mob; }; static void vmw_user_context_free(struct vmw_resource *res); @@ -853,7 +854,7 @@ vmw_context_binding_state(struct vmw_resource *ctx) * specified in the parameter. 0 otherwise. */ int vmw_context_bind_dx_query(struct vmw_resource *ctx_res, - struct vmw_buffer_object *mob) + struct vmw_bo *mob) { struct vmw_user_context *uctx = container_of(ctx_res, struct vmw_user_context, res); @@ -885,7 +886,7 @@ int vmw_context_bind_dx_query(struct vmw_resource *ctx_res, * * @ctx_res: The context resource */ -struct vmw_buffer_object * +struct vmw_bo * vmw_context_get_dx_query_mob(struct vmw_resource *ctx_res) { struct vmw_user_context *uctx = diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c b/drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c index 87455446a6f9..9193faae8dab 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 OR MIT /************************************************************************** * - * Copyright 2014-2015 VMware, Inc., Palo Alto, CA., USA + * Copyright 2014-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 @@ -30,13 +30,14 @@ * whenever the backing MOB is evicted. */ -#include <drm/ttm/ttm_placement.h> - +#include "vmwgfx_bo.h" #include "vmwgfx_drv.h" #include "vmwgfx_mksstat.h" #include "vmwgfx_resource_priv.h" #include "vmwgfx_so.h" +#include <drm/ttm/ttm_placement.h> + /** * struct vmw_cotable - Context Object Table resource * @@ -399,7 +400,7 @@ static int vmw_cotable_resize(struct vmw_resource *res, size_t new_size) struct ttm_operation_ctx ctx = { false, false }; struct vmw_private *dev_priv = res->dev_priv; struct vmw_cotable *vcotbl = vmw_cotable(res); - struct vmw_buffer_object *buf, *old_buf = res->backup; + struct vmw_bo *buf, *old_buf = res->backup; struct ttm_buffer_object *bo, *old_bo = &res->backup->base; size_t old_size = res->backup_size; size_t old_size_read_back = vcotbl->size_read_back; diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c index d1734d9422a7..d6d90fbfea59 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 OR MIT /************************************************************************** * - * Copyright 2009-2022 VMware, Inc., Palo Alto, CA., USA + * 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 @@ -28,9 +28,10 @@ #include "vmwgfx_drv.h" +#include "vmwgfx_bo.h" +#include "vmwgfx_binding.h" #include "vmwgfx_devcaps.h" #include "vmwgfx_mksstat.h" -#include "vmwgfx_binding.h" #include "ttm_object.h" #include <drm/drm_aperture.h> @@ -386,7 +387,7 @@ static void vmw_print_sm_type(struct vmw_private *dev_priv) static int vmw_dummy_query_bo_create(struct vmw_private *dev_priv) { int ret; - struct vmw_buffer_object *vbo; + struct vmw_bo *vbo; struct ttm_bo_kmap_obj map; volatile SVGA3dQueryResult *result; bool dummy; diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h index e19f630c0851..7eb3787a9063 100644 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h @@ -1,7 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0 OR MIT */ /************************************************************************** * - * Copyright 2009-2022 VMware, Inc., Palo Alto, CA., USA + * 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 @@ -117,32 +117,6 @@ struct vmwgfx_hash_item { unsigned long key; }; -/** - * struct vmw_buffer_object - TTM buffer object with vmwgfx additions - * @base: The TTM buffer object - * @res_tree: RB tree of resources using this buffer object as a backing MOB - * @base_mapped_count: ttm BO mapping count; used by KMS atomic helpers. - * @cpu_writers: Number of synccpu write grabs. Protected by reservation when - * increased. May be decreased without reservation. - * @dx_query_ctx: DX context if this buffer object is used as a DX query MOB - * @map: Kmap object for semi-persistent mappings - * @res_prios: Eviction priority counts for attached resources - * @dirty: structure for user-space dirty-tracking - */ -struct vmw_buffer_object { - struct ttm_buffer_object base; - struct rb_root res_tree; - /* For KMS atomic helpers: ttm bo mapping count */ - atomic_t base_mapped_count; - - atomic_t cpu_writers; - /* Not ref-counted. Protected by binding_mutex */ - struct vmw_resource *dx_query_ctx; - /* Protected by reservation */ - struct ttm_bo_kmap_obj map; - u32 res_prios[TTM_MAX_BO_PRIORITY]; - struct vmw_bo_dirty *dirty; -}; /** * struct vmw_validate_buffer - Carries validation info about buffers. @@ -190,6 +164,7 @@ struct vmw_res_func; * @hw_destroy: Callback to destroy the resource on the device, as part of * resource destruction. */ +struct vmw_bo; struct vmw_resource_dirty; struct vmw_resource { struct kref kref; @@ -200,7 +175,7 @@ struct vmw_resource { u32 res_dirty : 1; u32 backup_dirty : 1; u32 coherent : 1; - struct vmw_buffer_object *backup; + struct vmw_bo *backup; unsigned long backup_offset; unsigned long pin_count; const struct vmw_res_func *func; @@ -446,7 +421,7 @@ struct vmw_sw_context{ struct drm_file *filp; uint32_t *cmd_bounce; uint32_t cmd_bounce_size; - struct vmw_buffer_object *cur_query_bo; + struct vmw_bo *cur_query_bo; struct list_head bo_relocations; struct list_head res_relocations; uint32_t *buf_start; @@ -458,7 +433,7 @@ struct vmw_sw_context{ struct list_head staged_cmd_res; struct list_head ctx_list; struct vmw_ctx_validation_info *dx_ctx_node; - struct vmw_buffer_object *dx_query_mob; + struct vmw_bo *dx_query_mob; struct vmw_resource *dx_query_ctx; struct vmw_cmdbuf_res_manager *man; struct vmw_validation_context *ctx; @@ -632,8 +607,8 @@ struct vmw_private { * are protected by the cmdbuf mutex. */ - struct vmw_buffer_object *dummy_query_bo; - struct vmw_buffer_object *pinned_bo; + struct vmw_bo *dummy_query_bo; + struct vmw_bo *pinned_bo; uint32_t query_cid; uint32_t query_cid_valid; bool dummy_query_bo_pinned; @@ -677,11 +652,6 @@ struct vmw_private { #endif }; -static inline struct vmw_buffer_object *gem_to_vmw_bo(struct drm_gem_object *gobj) -{ - return container_of((gobj), struct vmw_buffer_object, base.base); -} - static inline struct vmw_surface *vmw_res_to_srf(struct vmw_resource *res) { return container_of(res, struct vmw_surface, res); @@ -825,7 +795,7 @@ extern int vmw_user_lookup_handle(struct vmw_private *dev_priv, struct drm_file *filp, uint32_t handle, struct vmw_surface **out_surf, - struct vmw_buffer_object **out_buf); + struct vmw_bo **out_buf); extern int vmw_user_resource_lookup_handle( struct vmw_private *dev_priv, struct ttm_object_file *tfile, @@ -845,19 +815,19 @@ extern void vmw_resource_unreserve(struct vmw_resource *res, bool dirty_set, bool dirty, bool switch_backup, - struct vmw_buffer_object *new_backup, + struct vmw_bo *new_backup, unsigned long new_backup_offset); extern void vmw_query_move_notify(struct ttm_buffer_object *bo, struct ttm_resource *old_mem, struct ttm_resource *new_mem); -extern int vmw_query_readback_all(struct vmw_buffer_object *dx_query_mob); -extern void vmw_resource_evict_all(struct vmw_private *dev_priv); -extern void vmw_resource_unbind_list(struct vmw_buffer_object *vbo); +int vmw_query_readback_all(struct vmw_bo *dx_query_mob); +void vmw_resource_evict_all(struct vmw_private *dev_priv); +void vmw_resource_unbind_list(struct vmw_bo *vbo); void vmw_resource_mob_attach(struct vmw_resource *res); void vmw_resource_mob_detach(struct vmw_resource *res); void vmw_resource_dirty_update(struct vmw_resource *res, pgoff_t start, pgoff_t end); -int vmw_resources_clean(struct vmw_buffer_object *vbo, pgoff_t start, +int vmw_resources_clean(struct vmw_bo *vbo, pgoff_t start, pgoff_t end, pgoff_t *num_prefault); /** @@ -872,111 +842,13 @@ static inline bool vmw_resource_mob_attached(const struct vmw_resource *res) } /** - * Buffer object helper functions - vmwgfx_bo.c - */ -extern int vmw_bo_pin_in_placement(struct vmw_private *vmw_priv, - struct vmw_buffer_object *bo, - struct ttm_placement *placement, - bool interruptible); -extern int vmw_bo_pin_in_vram(struct vmw_private *dev |