Module memory

Source
Expand description

Abstracts the different kinds of backing memory (MMAP, USERPTR, DMABUF) supported by V4L2.

V4L2 allows to use either memory that is provided by the device itself (MMAP) or memory imported via user allocation (USERPTR) or the dma-buf subsystem (DMABUF). This results in 2 very different behaviors and 3 memory types that we need to model.

The Memory trait represents these memory types and is thus implemented by exacly 3 types: MMAP, UserPtr, and DMABuf. These types do very little apart from providing a constant with the corresponding V4L2 memory type they model, and implement the SelfBacked (for MMAP) or Imported (for UserPtr and DMABuf) traits to indicate where their memory comes from.

The PlaneHandle trait is used by types which can bind to one of these memory types, i.e. a type that can represent a single memory plane of a buffer. For MMAP memory this is a void type (since MMAP provides its own memory). UserPtr, a Vec<u8> can adequately be used as backing memory, and for DMABuf we will use a file descriptor. For handles that can be mapped into the user address-space (and indeed for MMAP this is the only way to access the memory), the Mappable trait can be implemented.

The set of handles that make all the planes for a given buffer is represented by the BufferHandles trait. This trait is more abstract since we may want to decide at runtime the kind of memory we want to use ; therefore this trait does not have any particular kind of memory attached to it. PrimitiveBufferHandles is used to represent plane handles which memory type is known at compilation time, and thus includes a reference to a PlaneHandle type and by transition its Memory type.

Structs§

DmaBuf
DmaBufHandle
Handle for a DMABUF plane. Any type that can provide a file descriptor is valid.
Mmap
MmapHandle
Dummy handle for a MMAP plane, to use with APIs that require handles. MMAP buffers are backed by the device, and thus we don’t need to attach any extra information to them.
UserPtr
UserPtrHandle
Handle for a USERPTR plane. These buffers are backed by userspace-allocated memory, which translates well into Rust’s slice of u8s. Since slices also carry size information, we know that we are not passing unallocated areas of the address-space to the kernel.

Enums§

MemoryType
All the supported V4L2 memory types.

Traits§

BufferHandles
Trait for structures providing all the handles of a single buffer.
DmaBufSource
Imported
Trait for memory types to which external memory must be attached to, i.e. UserPtr and DMABuf.
Mappable
Memory
Trait describing a memory type that can be used to back V4L2 buffers.
PlaneHandle
Trait for a handle that represents actual data for a single place. A buffer will have as many of these as it has planes.
PrimitiveBufferHandles
Trait for plane handles for which the final memory type is known at compile time.
SelfBacked
Trait for memory types that provide their own memory, i.e. MMAP.

Type Aliases§

DmaBufferHandles