20#include <linux/dma-buf.h>
35#define XAIE_128BIT_ALIGN_MASK 0xFF
56 Fd = open(
"/dev/ion", O_RDONLY);
58 XAIE_ERROR(
"Failed to open ion.\n");
62 memset(&Query, 0,
sizeof(Query));
65 XAIE_ERROR(
"Failed to enquire ion heaps.\n");
71 XAIE_ERROR(
"Failed to allocate memory for heap details\n");
75 Query.
heaps = (uint64_t)Heaps;
78 XAIE_ERROR(
"Failed to enquire ion heap details.\n");
84 for (uint32_t i = 0; i < Query.
cnt; i++) {
85 XAIE_DBG(
"Heap id: %u, Heap name: %s, Heap type: %u\n", Heaps[i].
heap_id,
93 if (HeapNum == UINT_MAX) {
94 XAIE_ERROR(
"Failed to find contiguous heap\n");
99 memset(&AllocArgs, 0,
sizeof(AllocArgs));
100 AllocArgs.
len = size;
109 XAIE_ERROR(
"Failed to allocate memory of %lu bytes\n");
113 VAddr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, AllocArgs.
fd, 0);
115 XAIE_ERROR(
"Failed to mmap\n");
119 handle.
fd = AllocArgs.
fd;
124 if (XAie_MemAttach(&(ctx->
DevInst), &(handle.
MemInst), DevAddr, (u64)VAddr,
125 size, XAIE_MEM_NONCACHEABLE, handle.
fd) != XAIE_OK) {
126 XAIE_ERROR(
"dmabuf map failed\n");
214 struct dma_buf_sync Sync;
217 memset(&Sync, 0,
sizeof(Sync));
218 Sync.flags = DMA_BUF_SYNC_RW | DMA_BUF_SYNC_START;
219 Ret = ioctl(handle.
fd, DMA_BUF_IOCTL_SYNC, &Sync);
221 XAIE_ERROR(
"Failed to sync, %s.\n", strerror(errno));
241 struct dma_buf_sync Sync;
244 memset(&Sync, 0,
sizeof(Sync));
245 Sync.flags = DMA_BUF_SYNC_RW | DMA_BUF_SYNC_END;
246 Ret = ioctl(handle.
fd, DMA_BUF_IOCTL_SYNC, &Sync);
248 XAIE_ERROR(
"Failed to sync, %s.\n", strerror(errno));
#define ION_IOC_ALLOC
DOC: ION_IOC_ALLOC - allocate memory.
#define ION_IOC_HEAP_QUERY
DOC: ION_IOC_HEAP_QUERY - information about available heaps.
@ ION_HEAP_TYPE_SYSTEM_CONTIG
int * mlir_aie_mem_alloc(struct aie_libxaie_ctx_t *ctx, ext_mem_model_t &handle, int size)
This is the memory function to allocate a memory.
void mlir_aie_sync_mem_dev(ext_mem_model_t &handle)
This is the memory function to sync the memory for Device.
void mlir_aie_sync_mem_cpu(ext_mem_model_t &handle)
This is function to attach the allocated memory descriptor to kernel driver.
u64 mlir_aie_get_device_address(struct aie_libxaie_ctx_t *_xaie, void *VA)
Return a device address corresponding to the given host address.
struct ion_heap_query - collection of data about all heaps @cnt - total number of heaps to be copied ...