libcamera  v0.2.0+150-2031e2f2
Supporting cameras in Linux since 2019
Public Types | Public Member Functions | List of all members
libcamera::DmaHeap Class Reference

Helper class for dma-heap allocations. More...

Public Types

enum  DmaHeapFlag { DmaHeapFlag::Cma = 1 << 0, DmaHeapFlag::System = 1 << 1 }
 Type of the dma-heap. More...
 
using DmaHeapFlags = Flags< DmaHeapFlag >
 A bitwise combination of DmaHeap::DmaHeapFlag values.
 

Public Member Functions

 DmaHeap (DmaHeapFlags flags=DmaHeapFlag::Cma)
 Construct a DmaHeap of a given type. More...
 
 ~DmaHeap ()
 Destroy the DmaHeap instance.
 
bool isValid () const
 Check if the DmaHeap instance is valid. More...
 
UniqueFD alloc (const char *name, std::size_t size)
 Allocate a dma-buf from the DmaHeap. More...
 

Detailed Description

Helper class for dma-heap allocations.

DMA heaps are kernel devices that provide an API to allocate memory from different pools called "heaps", wrap each allocated piece of memory in a dmabuf object, and return the dmabuf file descriptor to userspace. Multiple heaps can be provided by the system, with different properties for the underlying memory.

This class wraps a DMA heap selected at construction time, and exposes functions to manage memory allocation.

Member Enumeration Documentation

◆ DmaHeapFlag

Type of the dma-heap.

Enumerator
Cma 

Allocate from a CMA dma-heap, providing physically-contiguous memory.

System 

Allocate from the system dma-heap, using the page allocator.

Constructor & Destructor Documentation

◆ DmaHeap()

libcamera::DmaHeap::DmaHeap ( DmaHeapFlags  type = DmaHeapFlag::Cma)

Construct a DmaHeap of a given type.

Parameters
[in]typeThe type(s) of the dma-heap(s) to allocate from

The DMA heap type is selected with the type parameter, which defaults to the CMA heap. If no heap of the given type can be accessed, the constructed DmaHeap instance is invalid as indicated by the isValid() function.

Multiple types can be selected by combining type flags, in which case the constructed DmaHeap will match one of the types. If the system provides multiple heaps that match the requested types, which heap is used is undefined.

Member Function Documentation

◆ alloc()

UniqueFD libcamera::DmaHeap::alloc ( const char *  name,
std::size_t  size 
)

Allocate a dma-buf from the DmaHeap.

Parameters
[in]nameThe name to set for the allocated buffer
[in]sizeThe size of the buffer to allocate

Allocates a dma-buf with read/write access.

If the allocation fails, return an invalid UniqueFD.

Returns
The UniqueFD of the allocated buffer

◆ isValid()

libcamera::DmaHeap::isValid ( ) const
inline

Check if the DmaHeap instance is valid.

Returns
True if the DmaHeap is valid, false otherwise

The documentation for this class was generated from the following files: