L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
L4Re::Dma_space Class Reference

Managed DMA Address Space. More...

#include <dma_space>

Collaboration diagram for L4Re::Dma_space:

Public Types

enum  Direction { Bidirectional , To_device , From_device , None }
 Direction of the DMA transfers. More...
enum  Attribute : unsigned { Search_addr = 1U << 0 , Partial_map = 1U << 1 , Reserve = 1U << 2 , Replace = 1U << 3 }
 Attributes used for the memory region. More...
enum  Unmap_flag : unsigned { Cancel_reservation = 1U << 0 }
 Flags used by Dma_space::unmap(). More...
typedef l4_uint64_t Dma_addr
 Data type for DMA addresses.
using Attributes = L4::Types::Flags_t<Attribute, unsigned>
 Attributes for DMA mappings.
using Unmap_flags = L4::Types::Flags_t<Unmap_flag, unsigned>
 Flags for Dma_space::unmap().

Public Member Functions

l4_ret_t map (L4::Ipc::Cap< L4Re::Dataspace > src, L4Re::Dataspace::Offset offset, l4_size_t *size, Attributes attrs, Direction dir, Dma_addr *dma_addr)
 Map the given part of this data space into the DMA address space.
l4_ret_t map (L4::Ipc::Cap< L4Re::Dataspace > src, L4Re::Dataspace::Offset offset, Dma_size *size, Dma_addr *dma_addr, Dma_addr dma_max=-1, Attributes attrs=Search_addr, unsigned char align=L4_SUPERPAGESHIFT)
 Map the given part of this data space into the DMA address space.
l4_ret_t unmap (Dma_addr dma_addr, Dma_size size, Attributes attrs, Direction dir)
 Unmap the given part of this data space from the DMA address space.
l4_ret_t unmap (Dma_addr dma_addr, Dma_size size, Unmap_flags flags=Unmap_flags())
 Unmap the given part of this data space from the DMA address space.

Detailed Description

Managed DMA Address Space.

A managed Dma_space represents the L4Re abstraction of an DMA address space of one or several devices. Devices are assigned to a managed Dma_space by binding the Dma_space to the respective DMA domain (see L4vbus::Vbus::assign_dma_domain()), which might link the Dma_space with a kernel DMA space. Note that several DMA domains can be bound to the same Dma_space. Whenever a device needs direct access to parts of an L4Re::Dataspace, that part of the data space must be mapped to the managed Dma_space that is assigned to that device. Binding to DMA domains must happen before mapping. After the DMA accesses to the memory are finished the memory must be unmapped from the device's DMA address space.

Mapping to a managed DMA address space, using map(), makes the given parts of the data space visible to the associated device at the returned DMA address. As long as the memory is mapped into a DMA space it is 'pinned' and cannot be subject to dynamic memory management such as swapping.

unmap() is the reverse operation to map() and unmaps the given data-space part for the DMA address space.

Definition at line 50 of file dma_space.

Member Typedef Documentation

◆ Attributes

Attributes for DMA mappings.

See also
Attribute

Definition at line 144 of file dma_space.

◆ Unmap_flags

Flags for Dma_space::unmap().

See also
Unmap_flag

Definition at line 303 of file dma_space.

Member Enumeration Documentation

◆ Attribute

enum L4Re::Dma_space::Attribute : unsigned

Attributes used for the memory region.

See also
Attributes
Enumerator
Search_addr 

Search for suitable address.

A spot for the whole mapping is searched, starting from the passed start address. Without this flag, the start address is taken literally. Can be combined with Attribute::Partial_map.

If no address remapping is possible (i.e., the Dma_space was associated by Dma_space_mgr::associate_phys()), the flag has no effect. The Dma_space::map() call will always return the physical address.

Partial_map 

Truncate mapping if it does not fit.

If there is not enough room after the chosen start address, truncate the mapping instead of failing.

Reserve 

Reserve a region instead of mapping pages.

If set, the dataspace argument of Dma_space::map() is ignored. Use the Attribute::Replace flag to place dataspace mappings in a reserved region later. The reservation is released with Dma_space::unmap() carrying Unmap_flag::Cancel_reservation.

If no address remapping is possible (i.e., the Dma_space was associated by Dma_space_mgr::associate_phys()), Dma_space::map() will always fail with -L4_EPERM if this flag is present.

Replace 

Replace mappings.

The pages in the map region are replaced with mappings from the dataspace. Without this flag, existing mappings cause Dma_space::map() to fail. Areas previously claimed by Dma_space_mgr::block_area() are never replaced and still cause Dma_space::map() to fail.

If combined with Attribute::Reserve, no dataspace mapping is established. Instead, the reservation reference count is increased. Only after the matching number of Dma_space::unmap(Cancel_reservation) calls, the reservation is released.

If no address remapping is possible (i.e., the Dma_space was associated by Dma_space_mgr::associate_phys()), the flag has no effect. The Dma_space::map() call will always return the physical address.

Cannot be combined with Attribute::Search_addr or Attribute::Partial_map.

Definition at line 78 of file dma_space.

◆ Direction

Direction of the DMA transfers.

Deprecated
Ignored by the API. Use function overloads without the direction parameter instead.
Enumerator
Bidirectional 

device reads and writes to the memory

To_device 

device reads the memory

From_device 

device writes to the memory

None 

device is coherently connected to the memory

Definition at line 66 of file dma_space.

◆ Unmap_flag

enum L4Re::Dma_space::Unmap_flag : unsigned

Flags used by Dma_space::unmap().

See also
Unmap_flags
Enumerator
Cancel_reservation 

Cancel a prior Attribute::Reserve claim instead of unmapping a dataspace mapping.

Without this flag, unmap() releases one dataspace mapping that was previously established by map() (with or without Attribute::Replace). With this flag, unmap() releases one previous Attribute::Reserve claim and does not touch any active dataspace mappings in the range.

Definition at line 282 of file dma_space.

Member Function Documentation

◆ map() [1/2]

l4_ret_t L4Re::Dma_space::map ( L4::Ipc::Cap< L4Re::Dataspace > src,
L4Re::Dataspace::Offset offset,
Dma_size * size,
Dma_addr * dma_addr,
Dma_addr dma_max = -1,
Attributes attrs = Search_addr,
unsigned char align = L4_SUPERPAGESHIFT )
inline

Map the given part of this data space into the DMA address space.

Parameters
[in]srcSource data space (that describes the memory).
[in]offsetThe offset (bytes) within src. Must be zero in case Attribute::Reserve is passed in attrs.
[in,out]sizeThe size (bytes) of the region to be mapped for DMA, after successful mapping the size returned is the size mapped for DMA as a single block. This size might be smaller than the original input size, in this case the caller might call map() again with a new offset and the remaining size.
[in,out]dma_addrThe DMA address to use for DMA with the associated device. Either taken literally (in which case it must be page aligned) or used as starting address if Attribute::Search_addr is passed.
[in]dma_maxHighest allowed DMA address of the mapping (inclusive).
[in]attrsThe attributes used for this DMA mapping (a combination of Dma_space::Attribute values).
[in]alignAlignment of mapping (log2 based). Only used if Attribute::Search_addr is passed.
Return values
L4_EOKOperation successful.
-L4_EADDRNOTAVAILThe specified region overlaps an existing mapping/blocking or no space left in search area.
-L4_EPERMInsufficient permissions; see precondition.
-L4_EINVALThe capability src is invalid or does not refer to a valid dataspace.
-L4_ENOMEMNot enough memory to allocate internal datastructures.
-L4_ERANGEoffset is larger than the size of the dataspace.

The DMA mapping is created writable if capability src has the permission L4_CAP_FPAGE_W. Otherwise, a read-only DMA mapping is established.

If no address remapping is possible (i.e., the Dma_space was associated by Dma_space_mgr::associate_phys()), Dma_space::map() will always return the physical address. The caller should therefore be prepared that a desired DMA address is ignored.

Note
Dma_space_mgr::associate() or Dma_space_mgr::associate_phys() must be called prior to mapping memory. Usually this is done implicitly when binding the managed Dma_space to a DMA domain (see L4vbus::Vbus::assign_dma_domain()).

Definition at line 260 of file dma_space.

References L4::Kobject_t< Derived, L4::Kobject, L4::PROTO_ANY, Type_info::Demand_t<> >::c(), L4_SUPERPAGESHIFT, and Search_addr.

Here is the call graph for this function:

◆ map() [2/2]

l4_ret_t L4Re::Dma_space::map ( L4::Ipc::Cap< L4Re::Dataspace > src,
L4Re::Dataspace::Offset offset,
l4_size_t * size,
Attributes attrs,
Direction dir,
Dma_addr * dma_addr )
inline

Map the given part of this data space into the DMA address space.

A suitable address in the DMA task will be chosen automatically.

Parameters
[in]srcSource data space (that describes the memory).
[in]offsetThe offset (bytes) within src.
[in,out]sizeThe size (bytes) of the region to be mapped for DMA, after successful mapping the size returned is the size mapped for DMA as a single block. This size might be smaller than the original input size, in this case the caller might call map() again with a new offset and the remaining size.
[in]attrsThe attributes used for this DMA mapping (a combination of Dma_space::Attribute values). The Search_addr attribute is forced by this overload!
[in]dirThe direction of the DMA transfer issued with this mapping. The same value must later be passed to unmap(). (ignored)
[out]dma_addrThe DMA address to use for DMA with the associated device.
Return values
L4_EOKOperation successful.
-L4_EADDRNOTAVAILThe specified region overlaps an existing mapping.
-L4_EINVALThe capability src is invalid or does not refer to a valid dataspace.
-L4_ENOMEMNot enough memory to allocate internal datastructures.
-L4_ERANGEoffset is larger than the size of the dataspace.

The DMA mapping is created writable if capability src has the permission L4_CAP_FPAGE_W. Otherwise, a read-only DMA mapping is established.

Note
Dma_space_mgr::associate() or Dma_space_mgr::associate_phys() must be called prior to mapping memory. Usually this is done implicitly when binding the managed Dma_space to a DMA domain (see L4vbus::Vbus::assign_dma_domain()).
Deprecated
Use the other overload without dir parameter.

Definition at line 190 of file dma_space.

References map(), and Search_addr.

Referenced by map().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unmap() [1/2]

l4_ret_t L4Re::Dma_space::unmap ( Dma_addr dma_addr,
Dma_size size,
Attributes attrs,
Direction dir )
inline

Unmap the given part of this data space from the DMA address space.

The calls to map() and unmap() must be balanced. That is, each page of a mapping that was established by map() previously must be unmapped exactly once.

Sub-ranges that do not currently hold a mapping are silently skipped. That is, unmapping the same region too often, is not treated as an error.

Parameters
dma_addrThe DMA address (returned by Dma_space::map()).
sizeThe size (bytes) of the memory region to unmap.
attrsThe attributes for the unmap (currently none, ignored).
dirThe direction of the finished DMA operation (ignored).
Return values
L4_EOKOperation successful.
-L4_ENOMEMNot enough memory to allocate internal datastructures.
Deprecated
Use the overload without attrs and dir because they are ignored.

Definition at line 326 of file dma_space.

References unmap().

Referenced by unmap().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unmap() [2/2]

l4_ret_t L4Re::Dma_space::unmap ( Dma_addr dma_addr,
Dma_size size,
Unmap_flags flags = Unmap_flags() )
inline

Unmap the given part of this data space from the DMA address space.

The calls to map() and unmap() must be balanced. That is, each page of a mapping that was established by map() previously must be unmapped exactly once. Likewise, every Attribute::Reserve claim must be released by exactly one unmap() call carrying Unmap_flag::Cancel_reservation.

Sub-ranges that do not currently hold a claim of the requested kind are silently skipped. That is, unmapping the same region too often, is not treated as an error. This behaviour applies both to actual mappings, as well as reservations.

Parameters
dma_addrThe DMA address (returned by Dma_space::map()).
sizeThe size (bytes) of the memory region to unmap.
flagsA combination of Dma_space::Unmap_flag values.
Return values
L4_EOKOperation successful.
-L4_EPERMThe range overlaps with a privileged Dma_space_mgr::block_area() claim.
-L4_EINVALInvalid arguments. Can be caused by unknown flags, size of 0 or an address overflow.
-L4_ENOMEMNot enough memory to allocate internal datastructures.

Definition at line 358 of file dma_space.

References L4::Kobject_t< Derived, L4::Kobject, L4::PROTO_ANY, Type_info::Demand_t<> >::c().

Here is the call graph for this function:

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