libhsakmt: support allocating a fixed address at mmap_aperture.

When HsaMemFlags.ui32.FixedAddress=1 allocate fixed address at mmap_aperture.

Signed-off-by: Xiaogang Chen<Xiaogang.Chen@amd.com>
Change-Id: I1f3b532ec3c1a4fb0962126a0bd56441abaf6a9c
This commit is contained in:
Xiaogang Chen
2023-05-25 13:38:39 -05:00
کامیت شده توسط Xiaogang Chen
والد 11ac57d293
کامیت d2a37894bb
+27 -3
مشاهده پرونده
@@ -785,14 +785,38 @@ static void *mmap_aperture_allocate_aligned(manageable_aperture_t *aper,
uint64_t alignment_size = PAGE_SIZE << svm.alignment_order;
uint64_t guard_size;
if (address)
return NULL;
if (!aper->is_cpu_accessible) {
pr_err("MMap Aperture must be CPU accessible\n");
return NULL;
}
if (address) {
void *addr;
#ifdef MAP_FIXED_NOREPLACE
addr = mmap(address, size, PROT_NONE,
MAP_ANONYMOUS | MAP_NORESERVE | MAP_PRIVATE | MAP_FIXED_NOREPLACE,
-1, 0);
#else
addr = mmap(address, size, PROT_NONE,
MAP_ANONYMOUS | MAP_NORESERVE | MAP_PRIVATE,
-1, 0);
#endif
if (addr == MAP_FAILED) {
pr_err("mmap failed: %s\n", strerror(errno));
return NULL;
}
#ifndef MAP_FIXED_NOREPLACE
if (address != addr) {
pr_err("mmap failed to return addr asked\n");
munmap(addr, size);
return NULL;
}
#endif
return addr;
}
/* Align big buffers to the next power-of-2. By default, the max alignment
* size is set to 2MB. This can be modified by the env variable
* HSA_MAX_VA_ALIGN. This variable sets the order of the alignment size as