amdgpu_allocate_static_csa() stored the kernel CPU mapping of the newly
created CSA directly into adev->virt.csa_cpu_addr. That hard-codes the
single device-global CSA and prevents the function from being reused to
allocate additional CSA buffers.

Return the CPU mapping through an out parameter instead and let the
caller decide where to store it.

Signed-off-by: Xiang Liu <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c    | 4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_csa.h    | 2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 3 ++-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c
index 814cb9e903586..083a2cf20324b 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.c
@@ -40,7 +40,7 @@ uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev)
 }
 
 int amdgpu_allocate_static_csa(struct amdgpu_device *adev, struct amdgpu_bo 
**bo,
-                               u32 domain, uint32_t size)
+                               u32 domain, uint32_t size, void **cpu_ptr)
 {
        void *ptr;
 
@@ -51,7 +51,7 @@ int amdgpu_allocate_static_csa(struct amdgpu_device *adev, 
struct amdgpu_bo **bo
                return -ENOMEM;
 
        memset(ptr, 0, size);
-       adev->virt.csa_cpu_addr = ptr;
+       *cpu_ptr = ptr;
        return 0;
 }
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.h
index 7dfc1f2012ebf..34b85cda1cc56 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_csa.h
@@ -30,7 +30,7 @@
 uint32_t amdgpu_get_total_csa_size(struct amdgpu_device *adev);
 uint64_t amdgpu_csa_vaddr(struct amdgpu_device *adev);
 int amdgpu_allocate_static_csa(struct amdgpu_device *adev, struct amdgpu_bo 
**bo,
-                               u32 domain, uint32_t size);
+                               u32 domain, uint32_t size, void **cpu_ptr);
 int amdgpu_map_static_csa(struct amdgpu_device *adev, struct amdgpu_vm *vm,
                          struct amdgpu_bo *bo, struct amdgpu_bo_va **bo_va,
                          uint64_t csa_addr, uint32_t size);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index 1253df9b1a9d2..a8e76fae11282 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -2422,7 +2422,8 @@ static int amdgpu_device_ip_init(struct amdgpu_device 
*adev)
                                r = amdgpu_allocate_static_csa(adev, 
&adev->virt.csa_obj,
                                                               
AMDGPU_GEM_DOMAIN_VRAM |
                                                               
AMDGPU_GEM_DOMAIN_GTT,
-                                                              AMDGPU_CSA_SIZE);
+                                                              AMDGPU_CSA_SIZE,
+                                                              
&adev->virt.csa_cpu_addr);
                                if (r) {
                                        dev_err(adev->dev,
                                                "allocate CSA failed %d\n", r);
-- 
2.34.1

Reply via email to