iPXE
Data Structures | Macros | Functions | Variables
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. More...
 
#define DMA_RX   0x02
 Device will write data to host memory. More...
 
#define DMA_BI   ( DMA_TX | DMA_RX )
 Device will both read data from and write data to host memory. More...
 
#define DMAAPI_INLINE(_subsys, _api_func)   SINGLE_API_INLINE ( DMAAPI_PREFIX_ ## _subsys, _api_func )
 Calculate static inline DMA I/O API function name. More...
 
#define PROVIDE_DMAAPI(_subsys, _api_func, _func)   PROVIDE_SINGLE_API ( DMAAPI_PREFIX_ ## _subsys, _api_func, _func )
 Provide a DMA I/O API implementation. More...
 
#define PROVIDE_DMAAPI_INLINE(_subsys, _api_func)   PROVIDE_SINGLE_API_INLINE ( DMAAPI_PREFIX_ ## _subsys, _api_func )
 Provide a static inline DMA I/O API implementation. More...
 

Functions

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

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 22 of file dma.h.

◆ DMAAPI_PREFIX_flat

#define DMAAPI_PREFIX_flat   __flat_

Definition at line 28 of file dma.h.

◆ DMA_TX

#define DMA_TX   0x01

Device will read data from host memory.

Definition at line 134 of file dma.h.

◆ DMA_RX

#define DMA_RX   0x02

Device will write data to host memory.

Definition at line 137 of file dma.h.

◆ DMA_BI

#define DMA_BI   ( DMA_TX | DMA_RX )

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

Definition at line 140 of file dma.h.

◆ DMAAPI_INLINE

#define DMAAPI_INLINE (   _subsys,
  _api_func 
)    SINGLE_API_INLINE ( DMAAPI_PREFIX_ ## _subsys, _api_func )

Calculate static inline DMA I/O API function name.

Parameters
_prefixSubsystem prefix
_api_funcAPI function
Return values
_subsys_funcSubsystem API function

Definition at line 149 of file dma.h.

◆ PROVIDE_DMAAPI

#define PROVIDE_DMAAPI (   _subsys,
  _api_func,
  _func 
)    PROVIDE_SINGLE_API ( DMAAPI_PREFIX_ ## _subsys, _api_func, _func )

Provide a DMA I/O API implementation.

Parameters
_prefixSubsystem prefix
_api_funcAPI function
_funcImplementing function

Definition at line 159 of file dma.h.

◆ PROVIDE_DMAAPI_INLINE

#define PROVIDE_DMAAPI_INLINE (   _subsys,
  _api_func 
)    PROVIDE_SINGLE_API_INLINE ( DMAAPI_PREFIX_ ## _subsys, _api_func )

Provide a static inline DMA I/O API implementation.

Parameters
_prefixSubsystem prefix
_api_funcAPI function

Definition at line 168 of file dma.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ DMAAPI_INLINE() [1/2]

static __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

◆ DMAAPI_INLINE() [2/2]

static __always_inline void DMAAPI_INLINE ( flat  ,
dma_unmap   
)
inlinestatic

Unmap buffer.

Parameters
mapDMA mapping
lenUsed length

◆ dma_unmap()

void dma_unmap ( struct dma_mapping map,
size_t  len 
)

Unmap buffer.

Parameters
mapDMA mapping
lenUsed length

Referenced by iob_unmap().

◆ dma_alloc()

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

◆ dma_free()

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

◆ 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

Referenced by gve_alloc_qpl(), gve_alloc_queue(), 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

Referenced by gve_alloc_queue(), gve_free_qpl(), gve_free_queue(), 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

Referenced by dma_set_mask_64bit().

◆ dma()

physaddr_t dma ( struct dma_mapping map,
void *  addr 
)

◆ dma_mapped()

static __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 441 of file dma.h.

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

References dma_mapping::dma, map, and NULL.

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

◆ dma_init()

static __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 453 of file dma.h.

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

References dma(), and op.

Referenced by efipci_info().

◆ dma_set_mask_64bit()

static __always_inline void dma_set_mask_64bit ( struct dma_device dma)
inlinestatic

Set 64-bit addressable space mask.

Parameters
dmaDMA device

Definition at line 466 of file dma.h.

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

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

__always_inline int struct dma_mapping* map

◆ __unused

__always_inline void size_t len __unused
Initial value:
{
if ( DBG_LOG ) {
map->dma = dma;
dma->mapped++;
}
return 0
struct dma_device * dma
DMA device (if unmapping is required)
Definition: dma.h:41
static __always_inline int struct dma_mapping * map
Definition: dma.h:183
#define DBG_LOG
Definition: compiler.h:317
physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.

Definition at line 183 of file dma.h.