summaryrefslogtreecommitdiff
path: root/include/libcamera/internal/dma_buf_allocator.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/libcamera/internal/dma_buf_allocator.h')
-rw-r--r--include/libcamera/internal/dma_buf_allocator.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/include/libcamera/internal/dma_buf_allocator.h b/include/libcamera/internal/dma_buf_allocator.h
new file mode 100644
index 00000000..36ec1696
--- /dev/null
+++ b/include/libcamera/internal/dma_buf_allocator.h
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: LGPL-2.1-or-later */
+/*
+ * Copyright (C) 2020, Raspberry Pi Ltd
+ *
+ * Helper class for dma-buf allocations.
+ */
+
+#pragma once
+
+#include <stddef.h>
+
+#include <libcamera/base/flags.h>
+#include <libcamera/base/unique_fd.h>
+
+namespace libcamera {
+
+class DmaBufAllocator
+{
+public:
+ enum class DmaBufAllocatorFlag {
+ CmaHeap = 1 << 0,
+ SystemHeap = 1 << 1,
+ UDmaBuf = 1 << 2,
+ };
+
+ using DmaBufAllocatorFlags = Flags<DmaBufAllocatorFlag>;
+
+ DmaBufAllocator(DmaBufAllocatorFlags flags = DmaBufAllocatorFlag::CmaHeap);
+ ~DmaBufAllocator();
+ bool isValid() const { return providerHandle_.isValid(); }
+ UniqueFD alloc(const char *name, std::size_t size);
+
+private:
+ UniqueFD allocFromHeap(const char *name, std::size_t size);
+ UniqueFD allocFromUDmaBuf(const char *name, std::size_t size);
+ UniqueFD providerHandle_;
+ DmaBufAllocatorFlag type_;
+};
+
+LIBCAMERA_FLAGS_ENABLE_OPERATORS(DmaBufAllocator::DmaBufAllocatorFlag)
+
+} /* namespace libcamera */