20#include <linux/dma-buf.h>
35#define XAIE_128BIT_ALIGN_MASK 0xFF
49 Fd = open(
"/dev/ion", O_RDONLY);
51 XAIE_ERROR(
"Failed to open ion.\n");
55 memset(&Query, 0,
sizeof(Query));
58 XAIE_ERROR(
"Failed to enquire ion heaps.\n");
64 XAIE_ERROR(
"Failed to allocate memory for heap details\n");
68 Query.
heaps = (uint64_t)Heaps;
71 XAIE_ERROR(
"Failed to enquire ion heap details.\n");
77 for (uint32_t i = 0; i < Query.
cnt; i++) {
78 XAIE_DBG(
"Heap id: %u, Heap name: %s, Heap type: %u\n", Heaps[i].
heap_id,
86 if (HeapNum == UINT_MAX) {
87 XAIE_ERROR(
"Failed to find contiguous heap\n");
92 memset(&AllocArgs, 0,
sizeof(AllocArgs));
102 XAIE_ERROR(
"Failed to allocate memory of %lu bytes\n");
106 VAddr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, AllocArgs.
fd, 0);
108 XAIE_ERROR(
"Failed to mmap\n");
112 handle.
fd = AllocArgs.
fd;
118 size, XAIE_MEM_NONCACHEABLE, handle.
fd) != XAIE_OK) {
119 XAIE_ERROR(
"dmabuf map failed\n");
197 struct dma_buf_sync Sync;
200 memset(&Sync, 0,
sizeof(Sync));
201 Sync.flags = DMA_BUF_SYNC_RW | DMA_BUF_SYNC_START;
202 Ret = ioctl(handle.
fd, DMA_BUF_IOCTL_SYNC, &Sync);
204 XAIE_ERROR(
"Failed to sync, %s.\n", strerror(errno));
213 struct dma_buf_sync Sync;
216 memset(&Sync, 0,
sizeof(Sync));
217 Sync.flags = DMA_BUF_SYNC_RW | DMA_BUF_SYNC_END;
218 Ret = ioctl(handle.
fd, DMA_BUF_IOCTL_SYNC, &Sync);
220 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
memory allocated via kmalloc
int * mlir_aie_mem_alloc(struct aie_libxaie_ctx_t *ctx, ext_mem_model_t &handle, int size)
Allocate a buffer in device memory.
void mlir_aie_sync_mem_dev(ext_mem_model_t &handle)
Synchronize the buffer from the host CPU to the device.
void mlir_aie_sync_mem_cpu(ext_mem_model_t &handle)
Synchronize the buffer from the device to the host CPU.
u64 mlir_aie_get_device_address(struct aie_libxaie_ctx_t *_xaie, void *VA)
Return a device address corresponding to the given host address.
XAie_DevInst * XAieDevInst
__u32 heap_id_mask
mask of heap ids to allocate from
__u32 fd
file descriptor for this allocation
__u64 len
size of the allocation
struct ion_heap_data - data about a heap
char name[MAX_HEAP_NAME]
first 32 characters of the heap name
__u32 heap_id
heap id for the heap
struct ion_heap_query - collection of data about all heaps
__u64 heaps
buffer to be populated
__u32 cnt
Total number of heaps to be copied.