Re: [PATCH v2 8/8] drm/vmwgfx: Stop using raw ttm_buffer_object's

2023-01-31 Thread "Maaz Mombasawala (VMware)
On 1/30/23 19:35, Zack Rusin wrote:
> From: Zack Rusin 
> 
> Various bits of the driver used raw ttm_buffer_object instead of the
> driver specific vmw_bo object. All those places used to duplicate
> the mapped bo caching policy of vmw_bo.
> 
> Instead of duplicating all of that code and special casing various
> functions to work both with vmw_bo and raw ttm_buffer_object's unify
> the buffer object handling code.
> 
> As part of that work fix the naming of bo's, e.g. insted of generic
> backup use 'guest_memory' because that's what it really is.
> 
> All of it makes the driver easier to maintain and the code easier to
> read. Saves 100+ loc as well.
> 
> Signed-off-by: Zack Rusin 
> ---
>  drivers/gpu/drm/vmwgfx/vmwgfx_bo.c| 204 +---
>  drivers/gpu/drm/vmwgfx/vmwgfx_bo.h|  60 ++---
>  drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c   |   4 +-
>  drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c|  44 ++--
>  drivers/gpu/drm/vmwgfx/vmwgfx_context.c   |  16 +-
>  drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c   |  51 ++--
>  drivers/gpu/drm/vmwgfx/vmwgfx_drv.c   |  17 +-
>  drivers/gpu/drm/vmwgfx/vmwgfx_drv.h   |  53 +++--
>  drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c   |  14 +-
>  drivers/gpu/drm/vmwgfx/vmwgfx_gem.c   |  37 +--
>  drivers/gpu/drm/vmwgfx/vmwgfx_kms.c   | 105 -
>  drivers/gpu/drm/vmwgfx/vmwgfx_kms.h   |   6 +-
>  drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c   |   4 +-
>  drivers/gpu/drm/vmwgfx/vmwgfx_mob.c   |  38 +--
>  drivers/gpu/drm/vmwgfx/vmwgfx_overlay.c   |   2 +-
>  drivers/gpu/drm/vmwgfx/vmwgfx_page_dirty.c|  51 ++--
>  drivers/gpu/drm/vmwgfx/vmwgfx_resource.c  | 220 +-
>  drivers/gpu/drm/vmwgfx/vmwgfx_resource_priv.h |   7 +-
>  drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c  |  29 ++-
>  drivers/gpu/drm/vmwgfx/vmwgfx_shader.c|  49 ++--
>  drivers/gpu/drm/vmwgfx/vmwgfx_so.c|   2 +-
>  drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c  |   8 +-
>  drivers/gpu/drm/vmwgfx/vmwgfx_streamoutput.c  |   8 +-
>  drivers/gpu/drm/vmwgfx/vmwgfx_surface.c   |  98 
>  drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c|  66 ++
>  drivers/gpu/drm/vmwgfx/vmwgfx_va.c|   2 +-
>  drivers/gpu/drm/vmwgfx/vmwgfx_validation.c|  62 +++--
>  27 files changed, 566 insertions(+), 691 deletions(-)
> 
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c 
> b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
> index d8f6ccecf4bf..63486802c8fd 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
> @@ -32,6 +32,12 @@
>  
>  #include 
>  
> +static void vmw_bo_release(struct vmw_bo *vbo)
> +{
> + vmw_bo_unmap(vbo);
> + drm_gem_object_release(>tbo.base);
> +}
> +
>  /**
>   * vmw_bo_free - vmw_bo destructor
>   *
> @@ -43,26 +49,10 @@ static void vmw_bo_free(struct ttm_buffer_object *bo)
>  
>   WARN_ON(vbo->dirty);
>   WARN_ON(!RB_EMPTY_ROOT(>res_tree));
> - vmw_bo_unmap(vbo);
> - drm_gem_object_release(>base);
> + vmw_bo_release(vbo);
>   kfree(vbo);
>  }
>  
> -/**
> - * bo_is_vmw - check if the buffer object is a _bo
> - * @bo: ttm buffer object to be checked
> - *
> - * Uses destroy function associated with the object to determine if this is
> - * a _bo.
> - *
> - * Returns:
> - * true if the object is of _bo type, false if not.
> - */
> -static bool bo_is_vmw(struct ttm_buffer_object *bo)
> -{
> - return bo->destroy == _bo_free;
> -}
> -
>  /**
>   * vmw_bo_pin_in_placement - Validate a buffer to placement.
>   *
> @@ -79,7 +69,7 @@ static int vmw_bo_pin_in_placement(struct vmw_private 
> *dev_priv,
>  bool interruptible)
>  {
>   struct ttm_operation_ctx ctx = {interruptible, false };
> - struct ttm_buffer_object *bo = >base;
> + struct ttm_buffer_object *bo = >tbo;
>   int ret;
>  
>   vmw_execbuf_release_pinned_bo(dev_priv);
> @@ -88,7 +78,7 @@ static int vmw_bo_pin_in_placement(struct vmw_private 
> *dev_priv,
>   if (unlikely(ret != 0))
>   goto err;
>  
> - if (buf->base.pin_count > 0)
> + if (buf->tbo.pin_count > 0)
>   ret = ttm_resource_compat(bo->resource, placement)
>   ? 0 : -EINVAL;
>   else
> @@ -120,7 +110,7 @@ int vmw_bo_pin_in_vram_or_gmr(struct vmw_private 
> *dev_priv,
> bool interruptible)
>  {
>   struct ttm_operation_ctx ctx = {interruptible, false };
> - struct ttm_buffer_object *bo = >base;
> + struct ttm_buffer_object *bo = >tbo;
>   int ret;
>  
>   vmw_execbuf_release_pinned_bo(dev_priv);
> @@ -129,7 +119,7 @@ int vmw_bo_pin_in_vram_or_gmr(struct vmw_private 
> *dev_priv,
>   if (unlikely(ret != 0))
>   goto err;
>  
> - if (buf->base.pin_count > 0) {
> + if (buf->tbo.pin_count > 0) {
>   ret = ttm_resource_compat(bo->resource, _vram_gmr_placement)
>   ? 0 : 

Re: [PATCH v2 8/8] drm/vmwgfx: Stop using raw ttm_buffer_object's

2023-01-31 Thread Martin Krastev (VMware)

From: Martin Krastev 


LGTM!
Reviewed-by: Martin Krastev 


Regards,
Martin


On 31.01.23 г. 5:35 ч., Zack Rusin wrote:

From: Zack Rusin 

Various bits of the driver used raw ttm_buffer_object instead of the
driver specific vmw_bo object. All those places used to duplicate
the mapped bo caching policy of vmw_bo.

Instead of duplicating all of that code and special casing various
functions to work both with vmw_bo and raw ttm_buffer_object's unify
the buffer object handling code.

As part of that work fix the naming of bo's, e.g. insted of generic
backup use 'guest_memory' because that's what it really is.

All of it makes the driver easier to maintain and the code easier to
read. Saves 100+ loc as well.

Signed-off-by: Zack Rusin 
---
  drivers/gpu/drm/vmwgfx/vmwgfx_bo.c| 204 +---
  drivers/gpu/drm/vmwgfx/vmwgfx_bo.h|  60 ++---
  drivers/gpu/drm/vmwgfx/vmwgfx_cmd.c   |   4 +-
  drivers/gpu/drm/vmwgfx/vmwgfx_cmdbuf.c|  44 ++--
  drivers/gpu/drm/vmwgfx/vmwgfx_context.c   |  16 +-
  drivers/gpu/drm/vmwgfx/vmwgfx_cotable.c   |  51 ++--
  drivers/gpu/drm/vmwgfx/vmwgfx_drv.c   |  17 +-
  drivers/gpu/drm/vmwgfx/vmwgfx_drv.h   |  53 +++--
  drivers/gpu/drm/vmwgfx/vmwgfx_execbuf.c   |  14 +-
  drivers/gpu/drm/vmwgfx/vmwgfx_gem.c   |  37 +--
  drivers/gpu/drm/vmwgfx/vmwgfx_kms.c   | 105 -
  drivers/gpu/drm/vmwgfx/vmwgfx_kms.h   |   6 +-
  drivers/gpu/drm/vmwgfx/vmwgfx_ldu.c   |   4 +-
  drivers/gpu/drm/vmwgfx/vmwgfx_mob.c   |  38 +--
  drivers/gpu/drm/vmwgfx/vmwgfx_overlay.c   |   2 +-
  drivers/gpu/drm/vmwgfx/vmwgfx_page_dirty.c|  51 ++--
  drivers/gpu/drm/vmwgfx/vmwgfx_resource.c  | 220 +-
  drivers/gpu/drm/vmwgfx/vmwgfx_resource_priv.h |   7 +-
  drivers/gpu/drm/vmwgfx/vmwgfx_scrn.c  |  29 ++-
  drivers/gpu/drm/vmwgfx/vmwgfx_shader.c|  49 ++--
  drivers/gpu/drm/vmwgfx/vmwgfx_so.c|   2 +-
  drivers/gpu/drm/vmwgfx/vmwgfx_stdu.c  |   8 +-
  drivers/gpu/drm/vmwgfx/vmwgfx_streamoutput.c  |   8 +-
  drivers/gpu/drm/vmwgfx/vmwgfx_surface.c   |  98 
  drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c|  66 ++
  drivers/gpu/drm/vmwgfx/vmwgfx_va.c|   2 +-
  drivers/gpu/drm/vmwgfx/vmwgfx_validation.c|  62 +++--
  27 files changed, 566 insertions(+), 691 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
index d8f6ccecf4bf..63486802c8fd 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_bo.c
@@ -32,6 +32,12 @@
  
  #include 
  
+static void vmw_bo_release(struct vmw_bo *vbo)

+{
+   vmw_bo_unmap(vbo);
+   drm_gem_object_release(>tbo.base);
+}
+
  /**
   * vmw_bo_free - vmw_bo destructor
   *
@@ -43,26 +49,10 @@ static void vmw_bo_free(struct ttm_buffer_object *bo)
  
  	WARN_ON(vbo->dirty);

WARN_ON(!RB_EMPTY_ROOT(>res_tree));
-   vmw_bo_unmap(vbo);
-   drm_gem_object_release(>base);
+   vmw_bo_release(vbo);
kfree(vbo);
  }
  
-/**

- * bo_is_vmw - check if the buffer object is a _bo
- * @bo: ttm buffer object to be checked
- *
- * Uses destroy function associated with the object to determine if this is
- * a _bo.
- *
- * Returns:
- * true if the object is of _bo type, false if not.
- */
-static bool bo_is_vmw(struct ttm_buffer_object *bo)
-{
-   return bo->destroy == _bo_free;
-}
-
  /**
   * vmw_bo_pin_in_placement - Validate a buffer to placement.
   *
@@ -79,7 +69,7 @@ static int vmw_bo_pin_in_placement(struct vmw_private 
*dev_priv,
   bool interruptible)
  {
struct ttm_operation_ctx ctx = {interruptible, false };
-   struct ttm_buffer_object *bo = >base;
+   struct ttm_buffer_object *bo = >tbo;
int ret;
  
  	vmw_execbuf_release_pinned_bo(dev_priv);

@@ -88,7 +78,7 @@ static int vmw_bo_pin_in_placement(struct vmw_private 
*dev_priv,
if (unlikely(ret != 0))
goto err;
  
-	if (buf->base.pin_count > 0)

+   if (buf->tbo.pin_count > 0)
ret = ttm_resource_compat(bo->resource, placement)
? 0 : -EINVAL;
else
@@ -120,7 +110,7 @@ int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
  bool interruptible)
  {
struct ttm_operation_ctx ctx = {interruptible, false };
-   struct ttm_buffer_object *bo = >base;
+   struct ttm_buffer_object *bo = >tbo;
int ret;
  
  	vmw_execbuf_release_pinned_bo(dev_priv);

@@ -129,7 +119,7 @@ int vmw_bo_pin_in_vram_or_gmr(struct vmw_private *dev_priv,
if (unlikely(ret != 0))
goto err;
  
-	if (buf->base.pin_count > 0) {

+   if (buf->tbo.pin_count > 0) {
ret = ttm_resource_compat(bo->resource, _vram_gmr_placement)
? 0 : -EINVAL;
goto out_unreserve;
@@ -195,7 +185,7 @@ int