Skip to content

Commit 1d251d9

Browse files
YongZhao12alexdeucher
authored andcommitted
drm/amdkfd: Consolidate duplicated bo alloc flags
ALLOC_MEM_FLAGS_* used are the same as the KFD_IOC_ALLOC_MEM_FLAGS_*, but they are interweavedly used in kernel driver, resulting in bad readability. For example, KFD_IOC_ALLOC_MEM_FLAGS_COHERENT is not referenced in kernel, and it functions implicitly in kernel through ALLOC_MEM_FLAGS_COHERENT, causing unnecessary confusion. Replace all occurrences of ALLOC_MEM_FLAGS_* with KFD_IOC_ALLOC_MEM_FLAGS_* to solve the problem. Signed-off-by: Yong Zhao <[email protected]> Reviewed-by: Felix Kuehling <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 8f2e0c0 commit 1d251d9

File tree

4 files changed

+27
-42
lines changed

4 files changed

+27
-42
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/module.h>
3030
#include <linux/dma-buf.h>
3131
#include "amdgpu_xgmi.h"
32+
#include <uapi/linux/kfd_ioctl.h>
3233

3334
static const unsigned int compute_vmid_bitmap = 0xFF00;
3435

@@ -501,10 +502,11 @@ int amdgpu_amdkfd_get_dmabuf_info(struct kgd_dev *kgd, int dma_buf_fd,
501502
metadata_size, &metadata_flags);
502503
if (flags) {
503504
*flags = (bo->preferred_domains & AMDGPU_GEM_DOMAIN_VRAM) ?
504-
ALLOC_MEM_FLAGS_VRAM : ALLOC_MEM_FLAGS_GTT;
505+
KFD_IOC_ALLOC_MEM_FLAGS_VRAM
506+
: KFD_IOC_ALLOC_MEM_FLAGS_GTT;
505507

506508
if (bo->flags & AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED)
507-
*flags |= ALLOC_MEM_FLAGS_PUBLIC;
509+
*flags |= KFD_IOC_ALLOC_MEM_FLAGS_PUBLIC;
508510
}
509511

510512
out_put:

drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "amdgpu_vm.h"
3030
#include "amdgpu_amdkfd.h"
3131
#include "amdgpu_dma_buf.h"
32+
#include <uapi/linux/kfd_ioctl.h>
3233

3334
/* BO flag to indicate a KFD userptr BO */
3435
#define AMDGPU_AMDKFD_USERPTR_BO (1ULL << 63)
@@ -400,18 +401,18 @@ static int vm_update_pds(struct amdgpu_vm *vm, struct amdgpu_sync *sync)
400401
static uint64_t get_pte_flags(struct amdgpu_device *adev, struct kgd_mem *mem)
401402
{
402403
struct amdgpu_device *bo_adev = amdgpu_ttm_adev(mem->bo->tbo.bdev);
403-
bool coherent = mem->alloc_flags & ALLOC_MEM_FLAGS_COHERENT;
404+
bool coherent = mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_COHERENT;
404405
uint32_t mapping_flags;
405406

406407
mapping_flags = AMDGPU_VM_PAGE_READABLE;
407-
if (mem->alloc_flags & ALLOC_MEM_FLAGS_WRITABLE)
408+
if (mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE)
408409
mapping_flags |= AMDGPU_VM_PAGE_WRITEABLE;
409-
if (mem->alloc_flags & ALLOC_MEM_FLAGS_EXECUTABLE)
410+
if (mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_EXECUTABLE)
410411
mapping_flags |= AMDGPU_VM_PAGE_EXECUTABLE;
411412

412413
switch (adev->asic_type) {
413414
case CHIP_ARCTURUS:
414-
if (mem->alloc_flags & ALLOC_MEM_FLAGS_VRAM) {
415+
if (mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM) {
415416
if (bo_adev == adev)
416417
mapping_flags |= coherent ?
417418
AMDGPU_VM_MTYPE_CC : AMDGPU_VM_MTYPE_RW;
@@ -1160,24 +1161,24 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
11601161
/*
11611162
* Check on which domain to allocate BO
11621163
*/
1163-
if (flags & ALLOC_MEM_FLAGS_VRAM) {
1164+
if (flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM) {
11641165
domain = alloc_domain = AMDGPU_GEM_DOMAIN_VRAM;
11651166
alloc_flags = AMDGPU_GEM_CREATE_VRAM_WIPE_ON_RELEASE;
1166-
alloc_flags |= (flags & ALLOC_MEM_FLAGS_PUBLIC) ?
1167+
alloc_flags |= (flags & KFD_IOC_ALLOC_MEM_FLAGS_PUBLIC) ?
11671168
AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED :
11681169
AMDGPU_GEM_CREATE_NO_CPU_ACCESS;
1169-
} else if (flags & ALLOC_MEM_FLAGS_GTT) {
1170+
} else if (flags & KFD_IOC_ALLOC_MEM_FLAGS_GTT) {
11701171
domain = alloc_domain = AMDGPU_GEM_DOMAIN_GTT;
11711172
alloc_flags = 0;
1172-
} else if (flags & ALLOC_MEM_FLAGS_USERPTR) {
1173+
} else if (flags & KFD_IOC_ALLOC_MEM_FLAGS_USERPTR) {
11731174
domain = AMDGPU_GEM_DOMAIN_GTT;
11741175
alloc_domain = AMDGPU_GEM_DOMAIN_CPU;
11751176
alloc_flags = 0;
11761177
if (!offset || !*offset)
11771178
return -EINVAL;
11781179
user_addr = untagged_addr(*offset);
1179-
} else if (flags & (ALLOC_MEM_FLAGS_DOORBELL |
1180-
ALLOC_MEM_FLAGS_MMIO_REMAP)) {
1180+
} else if (flags & (KFD_IOC_ALLOC_MEM_FLAGS_DOORBELL |
1181+
KFD_IOC_ALLOC_MEM_FLAGS_MMIO_REMAP)) {
11811182
domain = AMDGPU_GEM_DOMAIN_GTT;
11821183
alloc_domain = AMDGPU_GEM_DOMAIN_CPU;
11831184
bo_type = ttm_bo_type_sg;
@@ -1198,7 +1199,7 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
11981199
}
11991200
INIT_LIST_HEAD(&(*mem)->bo_va_list);
12001201
mutex_init(&(*mem)->lock);
1201-
(*mem)->aql_queue = !!(flags & ALLOC_MEM_FLAGS_AQL_QUEUE_MEM);
1202+
(*mem)->aql_queue = !!(flags & KFD_IOC_ALLOC_MEM_FLAGS_AQL_QUEUE_MEM);
12021203

12031204
/* Workaround for AQL queue wraparound bug. Map the same
12041205
* memory twice. That means we only actually allocate half
@@ -1680,10 +1681,12 @@ int amdgpu_amdkfd_gpuvm_import_dmabuf(struct kgd_dev *kgd,
16801681

16811682
INIT_LIST_HEAD(&(*mem)->bo_va_list);
16821683
mutex_init(&(*mem)->lock);
1684+
16831685
(*mem)->alloc_flags =
16841686
((bo->preferred_domains & AMDGPU_GEM_DOMAIN_VRAM) ?
1685-
ALLOC_MEM_FLAGS_VRAM : ALLOC_MEM_FLAGS_GTT) |
1686-
ALLOC_MEM_FLAGS_WRITABLE | ALLOC_MEM_FLAGS_EXECUTABLE;
1687+
KFD_IOC_ALLOC_MEM_FLAGS_VRAM : KFD_IOC_ALLOC_MEM_FLAGS_GTT)
1688+
| KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE
1689+
| KFD_IOC_ALLOC_MEM_FLAGS_EXECUTABLE;
16871690

16881691
(*mem)->bo = amdgpu_bo_ref(bo);
16891692
(*mem)->va = va;

drivers/gpu/drm/amd/amdkfd/kfd_process.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -327,10 +327,10 @@ static int kfd_process_alloc_gpuvm(struct kfd_process_device *pdd,
327327
static int kfd_process_device_reserve_ib_mem(struct kfd_process_device *pdd)
328328
{
329329
struct qcm_process_device *qpd = &pdd->qpd;
330-
uint32_t flags = ALLOC_MEM_FLAGS_GTT |
331-
ALLOC_MEM_FLAGS_NO_SUBSTITUTE |
332-
ALLOC_MEM_FLAGS_WRITABLE |
333-
ALLOC_MEM_FLAGS_EXECUTABLE;
330+
uint32_t flags = KFD_IOC_ALLOC_MEM_FLAGS_GTT |
331+
KFD_IOC_ALLOC_MEM_FLAGS_NO_SUBSTITUTE |
332+
KFD_IOC_ALLOC_MEM_FLAGS_WRITABLE |
333+
KFD_IOC_ALLOC_MEM_FLAGS_EXECUTABLE;
334334
void *kaddr;
335335
int ret;
336336

@@ -697,8 +697,9 @@ static int kfd_process_device_init_cwsr_dgpu(struct kfd_process_device *pdd)
697697
{
698698
struct kfd_dev *dev = pdd->dev;
699699
struct qcm_process_device *qpd = &pdd->qpd;
700-
uint32_t flags = ALLOC_MEM_FLAGS_GTT |
701-
ALLOC_MEM_FLAGS_NO_SUBSTITUTE | ALLOC_MEM_FLAGS_EXECUTABLE;
700+
uint32_t flags = KFD_IOC_ALLOC_MEM_FLAGS_GTT
701+
| KFD_IOC_ALLOC_MEM_FLAGS_NO_SUBSTITUTE
702+
| KFD_IOC_ALLOC_MEM_FLAGS_EXECUTABLE;
702703
void *kaddr;
703704
int ret;
704705

drivers/gpu/drm/amd/include/kgd_kfd_interface.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -167,27 +167,6 @@ struct tile_config {
167167

168168
#define KFD_MAX_NUM_OF_QUEUES_PER_DEVICE_DEFAULT 4096
169169

170-
/*
171-
* Allocation flag domains
172-
* NOTE: This must match the corresponding definitions in kfd_ioctl.h.
173-
*/
174-
#define ALLOC_MEM_FLAGS_VRAM (1 << 0)
175-
#define ALLOC_MEM_FLAGS_GTT (1 << 1)
176-
#define ALLOC_MEM_FLAGS_USERPTR (1 << 2)
177-
#define ALLOC_MEM_FLAGS_DOORBELL (1 << 3)
178-
#define ALLOC_MEM_FLAGS_MMIO_REMAP (1 << 4)
179-
180-
/*
181-
* Allocation flags attributes/access options.
182-
* NOTE: This must match the corresponding definitions in kfd_ioctl.h.
183-
*/
184-
#define ALLOC_MEM_FLAGS_WRITABLE (1 << 31)
185-
#define ALLOC_MEM_FLAGS_EXECUTABLE (1 << 30)
186-
#define ALLOC_MEM_FLAGS_PUBLIC (1 << 29)
187-
#define ALLOC_MEM_FLAGS_NO_SUBSTITUTE (1 << 28) /* TODO */
188-
#define ALLOC_MEM_FLAGS_AQL_QUEUE_MEM (1 << 27)
189-
#define ALLOC_MEM_FLAGS_COHERENT (1 << 26) /* For GFXv9 or later */
190-
191170
/**
192171
* struct kfd2kgd_calls
193172
*

0 commit comments

Comments
 (0)