#include "dma_util.h" #include #include #include #include #include #include int dma_heap_alloc(const char *heap_name, size_t size, int *fd) { /* Try the requested heap first, then fall back to cma then to * system-uncached so existing callers (decoder "cma", detector * "reserved") keep working. Callers that must have a <4G buffer (output * fds and the composer mirror) pass "system-uncached-dma32", whose pages * are guaranteed below 4G. The plain system-uncached heap can hand out * pages above 4G, which the RGA driver refuses to import. */ const char *tries[3]; int n = 0; if (heap_name && heap_name[0]) tries[n++] = heap_name; if (n == 0 || strcmp(tries[0], "cma") != 0) tries[n++] = "cma"; if (n == 0 || strcmp(tries[0], "system-uncached") != 0) tries[n++] = "system-uncached"; for (int t = 0; t < n; t++) { char path[64]; snprintf(path, sizeof(path), "/dev/dma_heap/%s", tries[t]); int heap_fd = open(path, O_RDWR | O_CLOEXEC); if (heap_fd < 0) continue; struct dma_heap_allocation_data data = { .len = size, .fd_flags = O_RDWR | O_CLOEXEC, }; int ret = ioctl(heap_fd, DMA_HEAP_IOCTL_ALLOC, &data); close(heap_fd); if (ret < 0) continue; *fd = (int)data.fd; return 0; } return -1; }