libcamera  v0.3.1+12-19bbca3c
Supporting cameras in Linux since 2019
dma_buf_allocator.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 /*
3  * Copyright (C) 2020, Raspberry Pi Ltd
4  *
5  * Helper class for dma-buf allocations.
6  */
7 
8 #pragma once
9 
10 #include <stddef.h>
11 
12 #include <libcamera/base/flags.h>
14 
15 namespace libcamera {
16 
18 {
19 public:
20  enum class DmaBufAllocatorFlag {
21  CmaHeap = 1 << 0,
22  SystemHeap = 1 << 1,
23  UDmaBuf = 1 << 2,
24  };
25 
27 
30  bool isValid() const { return providerHandle_.isValid(); }
31  UniqueFD alloc(const char *name, std::size_t size);
32 
33 private:
34  UniqueFD allocFromHeap(const char *name, std::size_t size);
35  UniqueFD allocFromUDmaBuf(const char *name, std::size_t size);
36  UniqueFD providerHandle_;
37  DmaBufAllocatorFlag type_;
38 };
39 
41 
42 } /* namespace libcamera */
Allocate using a memfd + /dev/udmabuf.
Helper class for dma-buf allocations.
Definition: dma_buf_allocator.h:17
File descriptor wrapper that owns a file descriptor.
DmaBufAllocator(DmaBufAllocatorFlags flags=DmaBufAllocatorFlag::CmaHeap)
Construct a DmaBufAllocator of a given type.
Definition: dma_buf_allocator.cpp:94
Top-level libcamera namespace.
Definition: backtrace.h:17
unique_ptr-like wrapper for a file descriptor
Definition: unique_fd.h:17
~DmaBufAllocator()
Destroy the DmaBufAllocator instance.
#define LIBCAMERA_FLAGS_ENABLE_OPERATORS(_enum)
Enable bitwise operations on the enum enumeration.
Allocate from the system dma-heap, using the page allocator.
Enum-based bit fields.
Allocate from a CMA dma-heap, providing physically-contiguous memory.
Type-safe container for enum-based bitfields.
Definition: flags.h:15
UniqueFD alloc(const char *name, std::size_t size)
Allocate a dma-buf from the DmaBufAllocator.
Definition: dma_buf_allocator.cpp:197
bool isValid() const
Check if the DmaBufAllocator instance is valid.
Definition: dma_buf_allocator.h:30
DmaBufAllocatorFlag
Type of the dma-buf provider.
Definition: dma_buf_allocator.h:20