[PATCH 11/11] drm/xe: Kill xe_device_mem_access_{get*,put}

2024-03-14 Thread Rodrigo Vivi
Let's simply convert all the current callers towards direct
xe_pm_runtime access and remove this extra layer of indirection.

v2: Convert all the current callers instead of a big refactor
at once.

Signed-off-by: Rodrigo Vivi 
Reviewed-by: Matthew Auld 
---
 drivers/gpu/drm/xe/display/xe_fb_pin.c |  7 ++---
 drivers/gpu/drm/xe/xe_bo.c |  8 +++---
 drivers/gpu/drm/xe/xe_device.c | 36 --
 drivers/gpu/drm/xe/xe_device.h |  3 ---
 drivers/gpu/drm/xe/xe_device_types.h   |  3 ---
 drivers/gpu/drm/xe/xe_exec_queue.c |  6 ++---
 drivers/gpu/drm/xe/xe_ggtt.c   |  9 ---
 drivers/gpu/drm/xe/xe_sched_job.c  |  5 ++--
 drivers/gpu/drm/xe/xe_vm.c |  6 ++---
 9 files changed, 22 insertions(+), 61 deletions(-)

diff --git a/drivers/gpu/drm/xe/display/xe_fb_pin.c 
b/drivers/gpu/drm/xe/display/xe_fb_pin.c
index 722c84a56607..403ed2d42f6b 100644
--- a/drivers/gpu/drm/xe/display/xe_fb_pin.c
+++ b/drivers/gpu/drm/xe/display/xe_fb_pin.c
@@ -10,6 +10,7 @@
 #include "intel_fb_pin.h"
 #include "xe_ggtt.h"
 #include "xe_gt.h"
+#include "xe_pm.h"
 
 #include 
 
@@ -190,7 +191,7 @@ static int __xe_pin_fb_vma_ggtt(struct intel_framebuffer 
*fb,
/* TODO: Consider sharing framebuffer mapping?
 * embed i915_vma inside intel_framebuffer
 */
-   xe_device_mem_access_get(tile_to_xe(ggtt->tile));
+   xe_pm_runtime_get_noresume(tile_to_xe(ggtt->tile));
ret = mutex_lock_interruptible(>lock);
if (ret)
goto out;
@@ -242,7 +243,7 @@ static int __xe_pin_fb_vma_ggtt(struct intel_framebuffer 
*fb,
 out_unlock:
mutex_unlock(>lock);
 out:
-   xe_device_mem_access_put(tile_to_xe(ggtt->tile));
+   xe_pm_runtime_put(tile_to_xe(ggtt->tile));
return ret;
 }
 
@@ -381,4 +382,4 @@ struct i915_address_space *intel_dpt_create(struct 
intel_framebuffer *fb)
 void intel_dpt_destroy(struct i915_address_space *vm)
 {
return;
-}
\ No newline at end of file
+}
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index 7ee4406da127..4c9a8ab4e840 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -716,7 +716,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, 
bool evict,
 
xe_assert(xe, migrate);
trace_xe_bo_move(bo, new_mem->mem_type, old_mem_type, 
move_lacks_source);
-   xe_device_mem_access_get(xe);
+   xe_pm_runtime_get_noresume(xe);
 
if (xe_bo_is_pinned(bo) && !xe_bo_is_user(bo)) {
/*
@@ -740,7 +740,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, 
bool evict,
 
if (XE_WARN_ON(new_mem->start == 
XE_BO_INVALID_OFFSET)) {
ret = -EINVAL;
-   xe_device_mem_access_put(xe);
+   xe_pm_runtime_put(xe);
goto out;
}
 
@@ -758,7 +758,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, 
bool evict,
new_mem, handle_system_ccs);
if (IS_ERR(fence)) {
ret = PTR_ERR(fence);
-   xe_device_mem_access_put(xe);
+   xe_pm_runtime_put(xe);
goto out;
}
if (!move_lacks_source) {
@@ -783,7 +783,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, 
bool evict,
dma_fence_put(fence);
}
 
-   xe_device_mem_access_put(xe);
+   xe_pm_runtime_put(xe);
 
 out:
return ret;
diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
index 6ab402153242..31182ebe0b89 100644
--- a/drivers/gpu/drm/xe/xe_device.c
+++ b/drivers/gpu/drm/xe/xe_device.c
@@ -655,42 +655,6 @@ void xe_device_assert_mem_access(struct xe_device *xe)
xe_assert(xe, !xe_pm_runtime_suspended(xe));
 }
 
-void xe_device_mem_access_get(struct xe_device *xe)
-{
-   int ref;
-
-   /*
-* This looks racy, but should be fine since the pm_callback_task only
-* transitions from NULL -> current (and back to NULL again), during the
-* runtime_resume() or runtime_suspend() callbacks, for which there can
-* only be a single one running for our device. We only need to prevent
-* recursively calling the runtime_get or runtime_put from those
-* callbacks, as well as preventing triggering any access_ongoing
-* asserts.
-*/
-   if (xe_pm_read_callback_task(xe) == current)
-   return;
-
-   xe_pm_runtime_get_noresume(xe);
-   ref = atomic_inc_return(>mem_access.ref);
-
-   xe_assert(xe, ref != S32_MAX);
-
-}
-
-void xe_device_mem_access_put(struct xe_device *xe)
-{
-   int ref;
-
-   if (xe_pm_read_callback_task(xe) == current)
-   return;
-
-   ref = 

[PATCH 11/11] drm/xe: Kill xe_device_mem_access_{get*,put}

2024-03-11 Thread Rodrigo Vivi
Let's simply convert all the current callers towards direct
xe_pm_runtime access and remove this extra layer of indirection.

v2: Convert all the current callers instead of a big refactor
at once.

Signed-off-by: Rodrigo Vivi 
Reviewed-by: Matthew Auld 
---
 drivers/gpu/drm/xe/display/xe_fb_pin.c |  7 ++---
 drivers/gpu/drm/xe/xe_bo.c |  8 +++---
 drivers/gpu/drm/xe/xe_device.c | 36 --
 drivers/gpu/drm/xe/xe_device.h |  3 ---
 drivers/gpu/drm/xe/xe_device_types.h   |  3 ---
 drivers/gpu/drm/xe/xe_exec_queue.c |  6 ++---
 drivers/gpu/drm/xe/xe_ggtt.c   |  9 ---
 drivers/gpu/drm/xe/xe_sched_job.c  |  5 ++--
 drivers/gpu/drm/xe/xe_vm.c |  6 ++---
 9 files changed, 22 insertions(+), 61 deletions(-)

diff --git a/drivers/gpu/drm/xe/display/xe_fb_pin.c 
b/drivers/gpu/drm/xe/display/xe_fb_pin.c
index 722c84a56607..403ed2d42f6b 100644
--- a/drivers/gpu/drm/xe/display/xe_fb_pin.c
+++ b/drivers/gpu/drm/xe/display/xe_fb_pin.c
@@ -10,6 +10,7 @@
 #include "intel_fb_pin.h"
 #include "xe_ggtt.h"
 #include "xe_gt.h"
+#include "xe_pm.h"
 
 #include 
 
@@ -190,7 +191,7 @@ static int __xe_pin_fb_vma_ggtt(struct intel_framebuffer 
*fb,
/* TODO: Consider sharing framebuffer mapping?
 * embed i915_vma inside intel_framebuffer
 */
-   xe_device_mem_access_get(tile_to_xe(ggtt->tile));
+   xe_pm_runtime_get_noresume(tile_to_xe(ggtt->tile));
ret = mutex_lock_interruptible(>lock);
if (ret)
goto out;
@@ -242,7 +243,7 @@ static int __xe_pin_fb_vma_ggtt(struct intel_framebuffer 
*fb,
 out_unlock:
mutex_unlock(>lock);
 out:
-   xe_device_mem_access_put(tile_to_xe(ggtt->tile));
+   xe_pm_runtime_put(tile_to_xe(ggtt->tile));
return ret;
 }
 
@@ -381,4 +382,4 @@ struct i915_address_space *intel_dpt_create(struct 
intel_framebuffer *fb)
 void intel_dpt_destroy(struct i915_address_space *vm)
 {
return;
-}
\ No newline at end of file
+}
diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index bc0cc5edc533..531c67083e2c 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -738,7 +738,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, 
bool evict,
 
xe_assert(xe, migrate);
trace_xe_bo_move(bo, new_mem->mem_type, old_mem_type, 
move_lacks_source);
-   xe_device_mem_access_get(xe);
+   xe_pm_runtime_get_noresume(xe);
 
if (xe_bo_is_pinned(bo) && !xe_bo_is_user(bo)) {
/*
@@ -762,7 +762,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, 
bool evict,
 
if (XE_WARN_ON(new_mem->start == 
XE_BO_INVALID_OFFSET)) {
ret = -EINVAL;
-   xe_device_mem_access_put(xe);
+   xe_pm_runtime_put(xe);
goto out;
}
 
@@ -780,7 +780,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, 
bool evict,
new_mem, handle_system_ccs);
if (IS_ERR(fence)) {
ret = PTR_ERR(fence);
-   xe_device_mem_access_put(xe);
+   xe_pm_runtime_put(xe);
goto out;
}
if (!move_lacks_source) {
@@ -805,7 +805,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, 
bool evict,
dma_fence_put(fence);
}
 
-   xe_device_mem_access_put(xe);
+   xe_pm_runtime_put(xe);
 
 out:
return ret;
diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
index 58815e9bf242..e2e6b6dc8534 100644
--- a/drivers/gpu/drm/xe/xe_device.c
+++ b/drivers/gpu/drm/xe/xe_device.c
@@ -655,42 +655,6 @@ void xe_device_assert_mem_access(struct xe_device *xe)
XE_WARN_ON(xe_pm_runtime_suspended(xe));
 }
 
-void xe_device_mem_access_get(struct xe_device *xe)
-{
-   int ref;
-
-   /*
-* This looks racy, but should be fine since the pm_callback_task only
-* transitions from NULL -> current (and back to NULL again), during the
-* runtime_resume() or runtime_suspend() callbacks, for which there can
-* only be a single one running for our device. We only need to prevent
-* recursively calling the runtime_get or runtime_put from those
-* callbacks, as well as preventing triggering any access_ongoing
-* asserts.
-*/
-   if (xe_pm_read_callback_task(xe) == current)
-   return;
-
-   xe_pm_runtime_get_noresume(xe);
-   ref = atomic_inc_return(>mem_access.ref);
-
-   xe_assert(xe, ref != S32_MAX);
-
-}
-
-void xe_device_mem_access_put(struct xe_device *xe)
-{
-   int ref;
-
-   if (xe_pm_read_callback_task(xe) == current)
-   return;
-
-   ref =