Commit c7b9aa7a authored by Nirmoy Das's avatar Nirmoy Das Committed by Alex Deucher

drm/amdgpu: do not allocate entries separately

Allocate PD/PT entries while allocating VM BOs and use that
instead of allocating those entries separately.

v2: create a new var for num entries.
Signed-off-by: default avatarNirmoy Das <nirmoy.das@amd.com>
Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent 9c3fec68
...@@ -876,6 +876,7 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev, ...@@ -876,6 +876,7 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev,
struct amdgpu_bo_param bp; struct amdgpu_bo_param bp;
struct amdgpu_bo *bo; struct amdgpu_bo *bo;
struct dma_resv *resv; struct dma_resv *resv;
unsigned int num_entries;
int r; int r;
memset(&bp, 0, sizeof(bp)); memset(&bp, 0, sizeof(bp));
...@@ -886,7 +887,14 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev, ...@@ -886,7 +887,14 @@ static int amdgpu_vm_pt_create(struct amdgpu_device *adev,
bp.domain = amdgpu_bo_get_preferred_pin_domain(adev, bp.domain); bp.domain = amdgpu_bo_get_preferred_pin_domain(adev, bp.domain);
bp.flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS | bp.flags = AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS |
AMDGPU_GEM_CREATE_CPU_GTT_USWC; AMDGPU_GEM_CREATE_CPU_GTT_USWC;
bp.bo_ptr_size = sizeof(struct amdgpu_bo_vm);
if (level < AMDGPU_VM_PTB)
num_entries = amdgpu_vm_num_entries(adev, level);
else
num_entries = 0;
bp.bo_ptr_size = struct_size((*vmbo), entries, num_entries);
if (vm->use_cpu_for_update) if (vm->use_cpu_for_update)
bp.flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED; bp.flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
...@@ -957,19 +965,14 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev, ...@@ -957,19 +965,14 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
struct amdgpu_bo_vm *pt; struct amdgpu_bo_vm *pt;
int r; int r;
if (cursor->level < AMDGPU_VM_PTB && !entry->entries) { if (entry->base.bo) {
unsigned num_entries; if (cursor->level < AMDGPU_VM_PTB)
entry->entries =
num_entries = amdgpu_vm_num_entries(adev, cursor->level); to_amdgpu_bo_vm(entry->base.bo)->entries;
entry->entries = kvmalloc_array(num_entries, else
sizeof(*entry->entries), entry->entries = NULL;
GFP_KERNEL | __GFP_ZERO);
if (!entry->entries)
return -ENOMEM;
}
if (entry->base.bo)
return 0; return 0;
}
r = amdgpu_vm_pt_create(adev, vm, cursor->level, immediate, &pt); r = amdgpu_vm_pt_create(adev, vm, cursor->level, immediate, &pt);
if (r) if (r)
...@@ -981,6 +984,10 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev, ...@@ -981,6 +984,10 @@ static int amdgpu_vm_alloc_pts(struct amdgpu_device *adev,
pt_bo = &pt->bo; pt_bo = &pt->bo;
pt_bo->parent = amdgpu_bo_ref(cursor->parent->base.bo); pt_bo->parent = amdgpu_bo_ref(cursor->parent->base.bo);
amdgpu_vm_bo_base_init(&entry->base, vm, pt_bo); amdgpu_vm_bo_base_init(&entry->base, vm, pt_bo);
if (cursor->level < AMDGPU_VM_PTB)
entry->entries = pt->entries;
else
entry->entries = NULL;
r = amdgpu_vm_clear_bo(adev, vm, pt, immediate); r = amdgpu_vm_clear_bo(adev, vm, pt, immediate);
if (r) if (r)
...@@ -1010,7 +1017,6 @@ static void amdgpu_vm_free_table(struct amdgpu_vm_pt *entry) ...@@ -1010,7 +1017,6 @@ static void amdgpu_vm_free_table(struct amdgpu_vm_pt *entry)
amdgpu_bo_unref(&shadow); amdgpu_bo_unref(&shadow);
amdgpu_bo_unref(&entry->base.bo); amdgpu_bo_unref(&entry->base.bo);
} }
kvfree(entry->entries);
entry->entries = NULL; entry->entries = NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment