#include <sys/mman.h>
#include "aub_mem.h"
-
-#ifndef HAVE_MEMFD_CREATE
-#include <sys/syscall.h>
-
-static inline int
-memfd_create(const char *name, unsigned int flags)
-{
- return syscall(SYS_memfd_create, name, flags);
-}
-#endif
+#include "util/anon_file.h"
struct bo_map {
struct list_head link;
struct gen_batch_decode_bo bo;
bool unmap_after_use;
+ bool ppgtt;
};
struct ggtt_entry {
uint64_t fd_offset;
uint64_t phys_addr;
uint8_t *data;
+ const uint8_t *aub_data;
};
static void
-add_gtt_bo_map(struct aub_mem *mem, struct gen_batch_decode_bo bo, bool unmap_after_use)
+add_gtt_bo_map(struct aub_mem *mem, struct gen_batch_decode_bo bo, bool ppgtt, bool unmap_after_use)
{
struct bo_map *m = calloc(1, sizeof(*m));
+ m->ppgtt = ppgtt;
m->bo = bo;
m->unmap_after_use = unmap_after_use;
list_add(&m->link, &mem->maps);
new_mem->phys_addr = phys_addr;
new_mem->fd_offset = mem->mem_fd_len;
- MAYBE_UNUSED int ftruncate_res = ftruncate(mem->mem_fd, mem->mem_fd_len += 4096);
+ ASSERTED int ftruncate_res = ftruncate(mem->mem_fd, mem->mem_fd_len += 4096);
assert(ftruncate_res == 0);
new_mem->data = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED,
.addr = address,
.size = size,
};
- add_gtt_bo_map(mem, bo, false);
+ add_gtt_bo_map(mem, bo, false, false);
}
void
uint32_t size_this_page = MIN2(to_write, 4096 - offset);
to_write -= size_this_page;
memcpy(pmem->data + offset, data, size_this_page);
+ pmem->aub_data = data - offset;
data = (const uint8_t *)data + size_this_page;
}
}
struct gen_batch_decode_bo bo = {0};
list_for_each_entry(struct bo_map, i, &mem->maps, link)
- if (i->bo.addr <= address && i->bo.addr + i->bo.size > address)
+ if (!i->ppgtt && i->bo.addr <= address && i->bo.addr + i->bo.size > address)
return i->bo;
address &= ~0xfff;
continue;
uint32_t map_offset = i->virt_addr - address;
- void *res = mmap((uint8_t *)bo.map + map_offset, 4096, PROT_READ,
- MAP_SHARED | MAP_FIXED, mem->mem_fd, phys_mem->fd_offset);
+ ASSERTED void *res =
+ mmap((uint8_t *)bo.map + map_offset, 4096, PROT_READ,
+ MAP_SHARED | MAP_FIXED, mem->mem_fd, phys_mem->fd_offset);
assert(res != MAP_FAILED);
}
- add_gtt_bo_map(mem, bo, true);
+ add_gtt_bo_map(mem, bo, false, true);
return bo;
}
struct aub_mem *mem = _mem;
struct gen_batch_decode_bo bo = {0};
+ list_for_each_entry(struct bo_map, i, &mem->maps, link)
+ if (i->ppgtt && i->bo.addr <= address && i->bo.addr + i->bo.size > address)
+ return i->bo;
+
address &= ~0xfff;
if (!ppgtt_mapped(mem, mem->pml4, address))
for (uint64_t page = address; page < end; page += 4096) {
struct phys_mem *phys_mem = ppgtt_walk(mem, mem->pml4, page);
- void *res = mmap((uint8_t *)bo.map + (page - bo.addr), 4096, PROT_READ,
- MAP_SHARED | MAP_FIXED, mem->mem_fd, phys_mem->fd_offset);
+ ASSERTED void *res =
+ mmap((uint8_t *)bo.map + (page - bo.addr), 4096, PROT_READ,
+ MAP_SHARED | MAP_FIXED, mem->mem_fd, phys_mem->fd_offset);
assert(res != MAP_FAILED);
}
- add_gtt_bo_map(mem, bo, true);
+ add_gtt_bo_map(mem, bo, true, true);
return bo;
}
list_inithead(&mem->maps);
- mem->mem_fd = memfd_create("phys memory", 0);
+ mem->mem_fd = os_create_anonymous_file(0, "phys memory");
return mem->mem_fd != -1;
}
close(mem->mem_fd);
mem->mem_fd = -1;
}
+
+struct gen_batch_decode_bo
+aub_mem_get_phys_addr_data(struct aub_mem *mem, uint64_t phys_addr)
+{
+ struct phys_mem *page = search_phys_mem(mem, phys_addr);
+ return page ?
+ (struct gen_batch_decode_bo) { .map = page->data, .addr = page->phys_addr, .size = 4096 } :
+ (struct gen_batch_decode_bo) {};
+}
+
+struct gen_batch_decode_bo
+aub_mem_get_ppgtt_addr_data(struct aub_mem *mem, uint64_t virt_addr)
+{
+ struct phys_mem *page = ppgtt_walk(mem, mem->pml4, virt_addr);
+ return page ?
+ (struct gen_batch_decode_bo) { .map = page->data, .addr = virt_addr & ~((1ULL << 12) - 1), .size = 4096 } :
+ (struct gen_batch_decode_bo) {};
+}
+
+struct gen_batch_decode_bo
+aub_mem_get_ppgtt_addr_aub_data(struct aub_mem *mem, uint64_t virt_addr)
+{
+ struct phys_mem *page = ppgtt_walk(mem, mem->pml4, virt_addr);
+ return page ?
+ (struct gen_batch_decode_bo) { .map = page->aub_data, .addr = virt_addr & ~((1ULL << 12) - 1), .size = 4096 } :
+ (struct gen_batch_decode_bo) {};
+}