41 struct ion_allocation_data AllocArgs;
42 struct ion_heap_query Query;
43 struct ion_heap_data *Heaps;
46 Fd = open(
"/dev/ion", O_RDONLY);
48 XAIE_ERROR(
"Failed to open ion.\n");
52 memset(&Query, 0,
sizeof(Query));
53 Ret = ioctl(Fd, ION_IOC_HEAP_QUERY, &Query);
55 XAIE_ERROR(
"Failed to enquire ion heaps.\n");
59 Heaps = (
struct ion_heap_data *)calloc(Query.cnt,
sizeof(*Heaps));
61 XAIE_ERROR(
"Failed to allocate memory for heap details\n");
65 Query.heaps = (uint64_t)Heaps;
66 Ret = ioctl(Fd, ION_IOC_HEAP_QUERY, &Query);
68 XAIE_ERROR(
"Failed to enquire ion heap details.\n");
74 for (uint32_t i = 0; i < Query.cnt; i++) {
75 XAIE_DBG(
"Heap id: %u, Heap name: %s, Heap type: %u\n", Heaps[i].heap_id,
76 Heaps[i].name, Heaps[i].type);
77 if (Heaps[i].type == ION_HEAP_TYPE_SYSTEM_CONTIG) {
83 if (HeapNum == UINT_MAX) {
84 XAIE_ERROR(
"Failed to find contiguous heap\n");
89 memset(&AllocArgs, 0,
sizeof(AllocArgs));
91 AllocArgs.heap_id_mask = 1 << Heaps[HeapNum].heap_id;
97 Ret = ioctl(Fd, ION_IOC_ALLOC, &AllocArgs);
99 XAIE_ERROR(
"Failed to allocate memory of %d bytes\n", size);
103 VAddr = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, AllocArgs.fd, 0);
105 XAIE_ERROR(
"Failed to mmap\n");
109 handle.
fd = AllocArgs.fd;
115 size, XAIE_MEM_NONCACHEABLE, handle.
fd) != XAIE_OK) {
116 XAIE_ERROR(
"dmabuf map failed\n");