Re: [PATCH 1/4] drm/amdgpu/ttm: move vram/gtt mgr allocations to mman.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 07.08.20 um 01:34 schrieb Dave Airlie:
From: Dave Airlie <airlied@xxxxxxxxxx>

Christian suggested this and it makes sense.

Signed-off-by: Dave Airlie <airlied@xxxxxxxxxx>

Reviewed-by: Christian König <christian.koenig@xxxxxxx>

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c  | 21 ++++-------------
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h      | 19 ++++++++++++++++
  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++----------------
  3 files changed, 27 insertions(+), 37 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
index c847a5fe94c9..010518148ef8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
@@ -24,13 +24,6 @@
#include "amdgpu.h" -struct amdgpu_gtt_mgr {
-	struct ttm_resource_manager manager;
-	struct drm_mm mm;
-	spinlock_t lock;
-	atomic64_t available;
-};
-
  static inline struct amdgpu_gtt_mgr *to_gtt_mgr(struct ttm_resource_manager *man)
  {
  	return container_of(man, struct amdgpu_gtt_mgr, manager);
@@ -93,16 +86,11 @@ static const struct ttm_resource_manager_func amdgpu_gtt_mgr_func;
   */
  int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
  {
-	struct ttm_resource_manager *man;
-	struct amdgpu_gtt_mgr *mgr;
+	struct amdgpu_gtt_mgr *mgr = &adev->mman.gtt_mgr;
+	struct ttm_resource_manager *man = &mgr->manager;
  	uint64_t start, size;
  	int ret;
- mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
-	if (!mgr)
-		return -ENOMEM;
-
-	man = &mgr->manager;
  	man->use_tt = true;
  	man->func = &amdgpu_gtt_mgr_func;
  	man->available_caching = TTM_PL_MASK_CACHING;
@@ -142,8 +130,8 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
   */
  void amdgpu_gtt_mgr_fini(struct amdgpu_device *adev)
  {
-	struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT);
-	struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
+	struct amdgpu_gtt_mgr *mgr = &adev->mman.gtt_mgr;
+	struct ttm_resource_manager *man = &mgr->manager;
  	int ret;
ttm_resource_manager_set_used(man, false);
@@ -161,7 +149,6 @@ void amdgpu_gtt_mgr_fini(struct amdgpu_device *adev)
ttm_resource_manager_cleanup(man);
  	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_TT, NULL);
-	kfree(mgr);
  }
/**
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
index 36b024fd077e..168294be276d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
@@ -41,6 +41,22 @@
#define AMDGPU_POISON 0xd0bed0be +struct amdgpu_vram_mgr {
+	struct ttm_resource_manager manager;
+	struct drm_mm mm;
+	spinlock_t lock;
+	atomic64_t usage;
+	atomic64_t vis_usage;
+	struct amdgpu_device *adev;
+};
+
+struct amdgpu_gtt_mgr {
+	struct ttm_resource_manager manager;
+	struct drm_mm mm;
+	spinlock_t lock;
+	atomic64_t available;
+};
+
  struct amdgpu_mman {
  	struct ttm_bo_device		bdev;
  	bool				mem_global_referenced;
@@ -59,6 +75,9 @@ struct amdgpu_mman {
  	struct mutex				gtt_window_lock;
  	/* Scheduler entity for buffer moves */
  	struct drm_sched_entity			entity;
+
+	struct amdgpu_vram_mgr vram_mgr;
+	struct amdgpu_gtt_mgr gtt_mgr;
  };
struct amdgpu_copy_mem {
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index 895634cbf999..a41a8abc9927 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -28,15 +28,6 @@
  #include "amdgpu_atomfirmware.h"
  #include "atom.h"
-struct amdgpu_vram_mgr {
-	struct ttm_resource_manager manager;
-	struct drm_mm mm;
-	spinlock_t lock;
-	atomic64_t usage;
-	atomic64_t vis_usage;
-	struct amdgpu_device *adev;
-};
-
  static inline struct amdgpu_vram_mgr *to_vram_mgr(struct ttm_resource_manager *man)
  {
  	return container_of(man, struct amdgpu_vram_mgr, manager);
@@ -177,16 +168,10 @@ static const struct ttm_resource_manager_func amdgpu_vram_mgr_func;
   */
  int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
  {
-	struct ttm_resource_manager *man;
-	struct amdgpu_vram_mgr *mgr;
+	struct amdgpu_vram_mgr *mgr = &adev->mman.vram_mgr;
+	struct ttm_resource_manager *man = &mgr->manager;
  	int ret;
- mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
-	if (!mgr)
-		return -ENOMEM;
-
-	man = &mgr->manager;
-
  	man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
  	man->default_caching = TTM_PL_FLAG_WC;
@@ -219,8 +204,8 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
   */
  void amdgpu_vram_mgr_fini(struct amdgpu_device *adev)
  {
-	struct ttm_resource_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM);
-	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
+	struct amdgpu_vram_mgr *mgr = &adev->mman.vram_mgr;
+	struct ttm_resource_manager *man = &mgr->manager;
  	int ret;
ttm_resource_manager_set_used(man, false);
@@ -237,7 +222,6 @@ void amdgpu_vram_mgr_fini(struct amdgpu_device *adev)
ttm_resource_manager_cleanup(man);
  	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_VRAM, NULL);
-	kfree(mgr);
  }
/**

_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel




[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux