iPXE
dma.h File Reference

DMA mappings. More...

#include <stdint.h>
#include <ipxe/api.h>
#include <ipxe/io.h>
#include <ipxe/malloc.h>
#include <ipxe/umalloc.h>
#include <config/ioapi.h>
#include <bits/dma.h>

Go to the source code of this file.

Data Structures

struct  dma_mapping
 A DMA mapping. More...
struct  dma_device
 A DMA-capable device. More...
struct  dma_operations
 DMA operations. More...

Macros

#define DMAAPI_PREFIX_op   __op_
#define DMAAPI_PREFIX_flat   __flat_
#define DMA_TX   0x01
 Device will read data from host memory.
#define DMA_RX   0x02
 Device will write data to host memory.
#define DMA_BI   ( DMA_TX | DMA_RX )
 Device will both read data from and write data to host memory.
#define DMAAPI_INLINE(_subsys, _api_func)
 Calculate static inline DMA I/O API function name.
#define PROVIDE_DMAAPI(_subsys, _api_func, _func)
 Provide a DMA I/O API implementation.
#define PROVIDE_DMAAPI_INLINE(_subsys, _api_func)
 Provide a static inline DMA I/O API implementation.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
static __always_inline int DMAAPI_INLINE (flat, dma_map)(struct dma_device *dma
 Map buffer for DMA.
static __always_inline void DMAAPI_INLINE (flat, dma_unmap)(struct dma_mapping *map
 Unmap buffer.
void dma_unmap (struct dma_mapping *map, size_t len)
 Unmap buffer.
void * dma_alloc (struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
 Allocate and map DMA-coherent buffer.
void dma_free (struct dma_mapping *map, void *addr, size_t len)
 Unmap and free DMA-coherent buffer.
void * dma_umalloc (struct dma_device *dma, struct dma_mapping *map, size_t len, size_t align)
 Allocate and map DMA-coherent buffer from external (user) memory.
void dma_ufree (struct dma_mapping *map, void *addr, size_t len)
 Unmap and free DMA-coherent buffer from external (user) memory.
void dma_set_mask (struct dma_device *dma, physaddr_t mask)
 Set addressable space mask.
physaddr_t dma (struct dma_mapping *map, void *addr)
 Get DMA address from virtual address.
static __always_inline int dma_mapped (struct dma_mapping *map)
 Check if DMA unmapping is required.
static __always_inline void dma_init (struct dma_device *dma, struct dma_operations *op)
 Initialise DMA device.
static __always_inline void dma_set_mask_64bit (struct dma_device *dma)
 Set 64-bit addressable space mask.

Variables

static __always_inline int struct dma_mappingmap
static __always_inline int struct dma_mapping void *addr __unused

Detailed Description

DMA mappings.

Definition in file dma.h.

Macro Definition Documentation

◆ DMAAPI_PREFIX_op

#define DMAAPI_PREFIX_op   __op_

Definition at line 23 of file dma.h.

◆ DMAAPI_PREFIX_flat

#define DMAAPI_PREFIX_flat   __flat_

Definition at line 29 of file dma.h.

◆ DMA_TX

#define DMA_TX   0x01

Device will read data from host memory.

Definition at line 135 of file dma.h.

Referenced by efipci_dma_map(), iob_map_tx(), xhci_endpoint_message(), and xhci_endpoint_stream().

◆ DMA_RX

#define DMA_RX   0x02

Device will write data to host memory.

Definition at line 138 of file dma.h.

Referenced by efipci_dma_map(), iob_map_rx(), xhci_endpoint_message(), and xhci_endpoint_stream().

◆ DMA_BI

#define DMA_BI   ( DMA_TX | DMA_RX )

Device will both read data from and write data to host memory.

Definition at line 141 of file dma.h.

Referenced by efipci_dma_alloc().

◆ DMAAPI_INLINE

#define DMAAPI_INLINE ( _subsys,
_api_func )
Value:
SINGLE_API_INLINE ( DMAAPI_PREFIX_ ## _subsys, _api_func )
#define SINGLE_API_INLINE(_prefix, _api_func)
Calculate static inline function name.
Definition api.h:45

Calculate static inline DMA I/O API function name.

Parameters
_prefixSubsystem prefix
_api_funcAPI function
Return values
_subsys_funcSubsystem API function

Definition at line 150 of file dma.h.

150#define DMAAPI_INLINE( _subsys, _api_func ) \
151 SINGLE_API_INLINE ( DMAAPI_PREFIX_ ## _subsys, _api_func )

◆ PROVIDE_DMAAPI

#define PROVIDE_DMAAPI ( _subsys,
_api_func,
_func )
Value:
PROVIDE_SINGLE_API ( DMAAPI_PREFIX_ ## _subsys, _api_func, _func )
#define PROVIDE_SINGLE_API(_prefix, _api_func, _func)
Provide an API implementation.
Definition api.h:55

Provide a DMA I/O API implementation.

Parameters
_prefixSubsystem prefix
_api_funcAPI function
_funcImplementing function

Definition at line 160 of file dma.h.

160#define PROVIDE_DMAAPI( _subsys, _api_func, _func ) \
161 PROVIDE_SINGLE_API ( DMAAPI_PREFIX_ ## _subsys, _api_func, _func )

◆ PROVIDE_DMAAPI_INLINE

#define PROVIDE_DMAAPI_INLINE ( _subsys,
_api_func )
Value:
PROVIDE_SINGLE_API_INLINE ( DMAAPI_PREFIX_ ## _subsys, _api_func )
#define PROVIDE_SINGLE_API_INLINE(_prefix, _api_func)
Provide a static inline API implementation.
Definition api.h:74

Provide a static inline DMA I/O API implementation.

Parameters
_prefixSubsystem prefix
_api_funcAPI function

Definition at line 169 of file dma.h.

169#define PROVIDE_DMAAPI_INLINE( _subsys, _api_func ) \
170 PROVIDE_SINGLE_API_INLINE ( DMAAPI_PREFIX_ ## _subsys, _api_func )

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ DMAAPI_INLINE() [1/2]

__always_inline int DMAAPI_INLINE ( flat ,
dma_map  )
inlinestatic

Map buffer for DMA.

Parameters
dmaDMA device
mapDMA mapping to fill in
addrBuffer address
lenLength of buffer
flagsMapping flags
Return values
rcReturn status code

References dma().

◆ DMAAPI_INLINE() [2/2]

__always_inline void DMAAPI_INLINE ( flat ,
dma_unmap  )
inlinestatic

Unmap buffer.

Parameters
mapDMA mapping
lenUsed length

References __unused, assert, DBG_LOG, dma_unmap(), len, map, and NULL.

◆ dma_unmap()

void dma_unmap ( struct dma_mapping * map,
size_t len )

Unmap buffer.

Parameters
mapDMA mapping
lenUsed length

References len, and map.

Referenced by DMAAPI_INLINE(), iob_unmap(), PROVIDE_DMAAPI(), and PROVIDE_DMAAPI_INLINE().

◆ dma_alloc()

void * dma_alloc ( struct dma_device * dma,
struct dma_mapping * map,
size_t len,
size_t align )

◆ dma_free()

◆ dma_umalloc()

void * dma_umalloc ( struct dma_device * dma,
struct dma_mapping * map,
size_t len,
size_t align )

Allocate and map DMA-coherent buffer from external (user) memory.

Parameters
dmaDMA device
mapDMA mapping to fill in
lenLength of buffer
alignPhysical alignment
Return values
addrBuffer address, or NULL on error

References dma(), len, and map.

Referenced by gve_alloc_qpl(), gve_alloc_queue(), PROVIDE_DMAAPI(), PROVIDE_DMAAPI_INLINE(), and xhci_scratchpad_alloc().

◆ dma_ufree()

void dma_ufree ( struct dma_mapping * map,
void * addr,
size_t len )

Unmap and free DMA-coherent buffer from external (user) memory.

Parameters
mapDMA mapping
addrBuffer address
lenLength of buffer

References addr, len, and map.

Referenced by gve_alloc_queue(), gve_free_qpl(), gve_free_queue(), PROVIDE_DMAAPI(), PROVIDE_DMAAPI_INLINE(), xhci_scratchpad_alloc(), and xhci_scratchpad_free().

◆ dma_set_mask()

void dma_set_mask ( struct dma_device * dma,
physaddr_t mask )

Set addressable space mask.

Parameters
dmaDMA device
maskAddressable space mask

References dma().

Referenced by dma_set_mask_64bit(), PROVIDE_DMAAPI(), and PROVIDE_DMAAPI_INLINE().

◆ dma()

physaddr_t dma ( struct dma_mapping * map,
void * addr )

◆ dma_mapped()

__always_inline int dma_mapped ( struct dma_mapping * map)
inlinestatic

Check if DMA unmapping is required.

Parameters
mapDMA mapping
unmapUnmapping is required

Definition at line 442 of file dma.h.

442 {
443
444 /* Unmapping is required if a DMA device was recorded */
445 return ( map->dma != NULL );
446}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
static __always_inline int struct dma_mapping * map
Definition dma.h:184

References __always_inline, map, and NULL.

Referenced by free_iob(), net_discard(), netdev_rx(), netdev_rx_err(), netdev_tx(), and netdev_tx_err().

◆ dma_init()

__always_inline void dma_init ( struct dma_device * dma,
struct dma_operations * op )
inlinestatic

Initialise DMA device.

Parameters
dmaDMA device
opDMA operations

Definition at line 454 of file dma.h.

455 {
456
457 /* Set operations table */
458 dma->op = op;
459}
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
static uint16_t struct vmbus_xfer_pages_operations * op
Definition netvsc.h:327

References __always_inline, dma(), and op.

Referenced by efipci_info().

◆ dma_set_mask_64bit()

__always_inline void dma_set_mask_64bit ( struct dma_device * dma)
inlinestatic

Set 64-bit addressable space mask.

Parameters
dmaDMA device

Definition at line 467 of file dma.h.

467 {
468
469 /* Set mask to maximum physical address */
470 dma_set_mask ( dma, ~( ( physaddr_t ) 0 ) );
471}
unsigned long physaddr_t
Definition stdint.h:20
void dma_set_mask(struct dma_device *dma, physaddr_t mask)
Set addressable space mask.

References dma(), and dma_set_mask().

Referenced by gve_probe(), ice_probe(), intel_probe(), intelx_probe(), intelxl_probe(), intelxlvf_probe(), intelxvf_probe(), realtek_detect(), virtnet_probe_legacy(), virtnet_probe_modern(), and xhci_init().

Variable Documentation

◆ map

◆ __unused

__always_inline void size_t len __unused
Initial value:
{
if ( DBG_LOG ) {
map->dma = dma;
dma->mapped++;
}
return 0
#define DBG_LOG
Definition compiler.h:317

Definition at line 184 of file dma.h.