summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Galo <carlosgalo@google.com>2023-11-11 01:39:34 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-11-11 01:39:34 +0000
commita43fbc363213dbe0373a1df26f0ffa46a1a00130 (patch)
tree27cb135b776aa065dd684ec65bdb41738c8dc4ec
parent24ec783563436c7f96c6eb8b90d8c55d21362b1b (diff)
parentd4ff3d3037614ee2e2e496dcc9976150e0dd3fc6 (diff)
downloadlibdmabufheap-a43fbc363213dbe0373a1df26f0ffa46a1a00130.tar.gz
libdmabufheap: Do not fallback to ion when dma-buf exists am: d7fd440294 am: 0f1d4f9e68 am: d4ff3d3037
Original change: https://android-review.googlesource.com/c/platform/system/memory/libdmabufheap/+/2819907 Change-Id: I0c03ba9138c4d784de7f46db6d9448ec0e45b97e Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.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;