18 #include <sys/ioctl.h> 19 #include <sys/types.h> 26 #include "meson_ion.h" 31 size_t bufferSize = 0;
32 ion_user_handle_t handle = 0;
35 unsigned long physicalAddress = 0;
43 size_t BufferSize()
const 48 ion_user_handle_t Handle()
const 53 int ExportHandle()
const 63 unsigned long PhysicalAddress()
const 65 return physicalAddress;
71 : bufferSize(bufferSize)
74 throw std::runtime_error(
"bufferSize < 1");
79 ion_fd = open(
"/dev/ion", O_RDWR);
82 throw std::runtime_error(
"open ion failed.");
91 allocation_data.len = bufferSize;
92 allocation_data.heap_id_mask = ION_HEAP_CARVEOUT_MASK;
94 #if defined(__aarch64__) 95 allocation_data.flags = ION_FLAG_CACHED_NEEDS_SYNC;
97 allocation_data.flags = 0;
100 io = ioctl(ion_fd, ION_IOC_ALLOC, &allocation_data);
103 throw std::runtime_error(
"ION_IOC_ALLOC failed.");
111 ionData.handle = allocation_data.handle;
113 io = ioctl(ion_fd, ION_IOC_SHARE, &ionData);
116 throw std::runtime_error(
"ION_IOC_SHARE failed.");
124 physData.handle = ionData.fd;
127 ionCustomData.cmd = ION_IOC_MESON_PHYS_ADDR;
128 ionCustomData.arg = (
long unsigned int)&physData;
130 io = ioctl(ion_fd, ION_IOC_CUSTOM, &ionCustomData);
133 throw std::runtime_error(
"ION_IOC_CUSTOM failed.");
137 handle = allocation_data.handle;
138 exportHandle = ionData.fd;
139 length = allocation_data.len;
140 physicalAddress = physData.phys_addr;
148 ionHandleData.handle = handle;
150 int io = ioctl(ion_fd, ION_IOC_FREE, &ionHandleData);
153 throw std::runtime_error(
"ION_IOC_FREE failed.");
161 #if defined(__aarch64__) 163 ionFdData.fd = ExportHandle();
165 int io = ioctl(ion_fd, ION_IOC_SYNC, &ionFdData);
168 throw std::runtime_error(
"ION_IOC_SYNC failed.");
176 void* result = mmap(NULL,
178 PROT_READ | PROT_WRITE,
179 MAP_FILE | MAP_SHARED,
182 if (result == MAP_FAILED)
184 throw std::runtime_error(
"mmap failed.");
struct ion_fd_data - metadata passed to/from userspace for a handle/fd pair : a handle : a file descr...
Definition: ion.h:104
struct ion_custom_data - metadata passed to/from userspace for a custom ioctl : the custom ioctl func...
Definition: ion.h:125
DOC: Ion Userspace API.
Definition: ion.h:86
Definition: IonBuffer.h:29
struct ion_handle_data - a handle passed to/from the kernel : a handle
Definition: ion.h:113
Definition: meson_ion.h:29