Commit 09881d29 authored by Zack Rusin's avatar Zack Rusin
Browse files

drm/vmwgfx: Rename vmw_buffer_object to vmw_bo



The rest of the drivers which are using ttm have mostly standardized on
driver_prefix_bo as the name for subclasses of the TTM buffer object.
Make vmwgfx match the rest of the drivers and follow the same naming
semantics.

This is especially clear given that the name of the file in which the
object was defined is vmw_bo.c.

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-4-zack@kde.org
parent 6b2e8aa4
Loading
Loading
Loading
Loading
+40 −54
Original line number Diff line number Diff line
// 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 @@ int vmw_bo_pin_in_placement(struct vmw_private *dev_priv,
 * -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 @@ int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
 * -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 @@ int vmw_bo_pin_in_start_of_vram(struct vmw_private *dev_priv,
 * -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 @@ int vmw_bo_create_kernel(struct vmw_private *dev_priv, unsigned long size,
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 @@ int vmw_bo_create(struct vmw_private *vmw,
 * 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 @@ int vmw_bo_create(struct vmw_private *vmw,
 * 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.
+189 −0
Original line number Diff line number Diff line
/* 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
+5 −5
Original line number Diff line number Diff line
// 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)
{
+5 −4
Original line number Diff line number Diff line
// 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
+6 −5
Original line number Diff line number Diff line
// 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 =
Loading