summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Galo <carlosgalo@google.com>2023-11-08 01:43:29 +0000
committerCarlos Galo <carlosgalo@google.com>2023-11-09 21:54:51 +0000
commitd7fd440294f32ee623419e1c725059795fba8063 (patch)
tree27cb135b776aa065dd684ec65bdb41738c8dc4ec
parent988c3be5c4dc221bb0f51e225fe2d1581a988d4f (diff)
downloadlibdmabufheap-d7fd440294f32ee623419e1c725059795fba8063.tar.gz
libdmabufheap: Do not fallback to ion when dma-buf exists
Test: m Bug: 295390628 Change-Id: Ic4b5bf8ba1c43854432a1c78ca1a3d474f4031ad Signed-off-by: Carlos Galo <carlosgalo@google.com>
-rw-r--r--BufferAllocator.cpp23
-rw-r--r--include/BufferAllocator/BufferAllocator.h2
2 files changed, 15 insertions, 10 deletions
diff --git a/BufferAllocator.cpp b/BufferAllocator.cpp
index a360cfd..0c625f6 100644
--- a/BufferAllocator.cpp
+++ b/BufferAllocator.cpp
@@ -210,8 +210,7 @@ int BufferAllocator::GetIonConfig(const std::string& heap_name, IonHeapConfig& h
return ret;
}
-int BufferAllocator::DmabufAlloc(const std::string& heap_name, size_t len) {
- int fd = OpenDmabufHeap(heap_name);
+int BufferAllocator::DmabufAlloc(const std::string& heap_name, size_t len, int fd) {
if (fd < 0) return fd;
struct dma_heap_allocation_data heap_data{
@@ -263,12 +262,14 @@ int BufferAllocator::IonAlloc(const std::string& heap_name, size_t len,
int BufferAllocator::Alloc(const std::string& heap_name, size_t len,
unsigned int heap_flags, size_t legacy_align) {
- int fd = DmabufAlloc(heap_name, len);
+ int dma_buf_heap_fd = OpenDmabufHeap(heap_name);
+ if (dma_buf_heap_fd >= 0) return DmabufAlloc(heap_name, len, dma_buf_heap_fd);
- if (fd < 0)
- fd = IonAlloc(heap_name, len, heap_flags, legacy_align);
-
- return fd;
+ /*
+ * Swap back to ion only if we failed to allocate for a dma-buffer heap
+ * that doesn't exist.
+ */
+ return IonAlloc(heap_name, len, heap_flags, legacy_align);
}
int BufferAllocator::AllocSystem(bool cpu_access_needed, size_t len, unsigned int heap_flags,
@@ -283,8 +284,12 @@ int BufferAllocator::AllocSystem(bool cpu_access_needed, size_t len, unsigned in
return (dmabuf_heap_list.find(kDmabufSystemUncachedHeapName) != dmabuf_heap_list.end());
}();
- if (uncached_dmabuf_system_heap_support)
- return DmabufAlloc(kDmabufSystemUncachedHeapName, len);
+ if (uncached_dmabuf_system_heap_support) {
+ int dma_buf_heap_fd = OpenDmabufHeap(kDmabufSystemUncachedHeapName);
+ return (dma_buf_heap_fd < 0)
+ ? dma_buf_heap_fd
+ : DmabufAlloc(kDmabufSystemUncachedHeapName, len, dma_buf_heap_fd);
+ }
static bool uncached_ion_system_heap_support = [this]() -> bool {
IonHeapConfig heap_config;
diff --git a/include/BufferAllocator/BufferAllocator.h b/include/BufferAllocator/BufferAllocator.h
index 95ffdf5..bcc63a0 100644
--- a/include/BufferAllocator/BufferAllocator.h
+++ b/include/BufferAllocator/BufferAllocator.h
@@ -195,7 +195,7 @@ class BufferAllocator {
unsigned int ion_heap_flags = 0);
void LogInterface(const std::string& interface);
int IonAlloc(const std::string& heap_name, size_t len, unsigned int heap_flags = 0, size_t legacy_align = 0);
- int DmabufAlloc(const std::string& heap_name, size_t len);
+ int DmabufAlloc(const std::string& heap_name, size_t len, int fd);
struct IonHeapConfig {
unsigned int mask;