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>

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...
 
static __always_inline void * DMAAPI_INLINE (flat, dma_alloc)(struct dma_device *dma
 Allocate and map DMA-coherent buffer. More...
 
 if (DBG_LOG &&addr)
 
static __always_inline void DMAAPI_INLINE (flat, dma_free)(struct dma_mapping *map
 Unmap and free DMA-coherent buffer. More...
 
 if (DBG_LOG)
 
static __always_inline userptr_t DMAAPI_INLINE (flat, dma_umalloc)(struct dma_device *dma
 Allocate and map DMA-coherent buffer from external (user) memory. More...
 
static __always_inline void DMAAPI_INLINE (flat, dma_ufree)(struct dma_mapping *map
 Unmap and free DMA-coherent buffer from external (user) memory. More...
 
static __always_inline void DMAAPI_INLINE (flat, dma_set_mask)(struct dma_device *dma __unused
 Set addressable space mask. More...
 
void dma_unmap (struct dma_mapping *map)
 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...
 
userptr_t 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, userptr_t 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_phys (struct dma_mapping *map, physaddr_t addr)
 Get DMA address from physical address. More...
 
static __always_inline 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 physaddr_t addr __unused
 
static __always_inline void struct dma_mapping size_t len
 
static __always_inline void struct dma_mapping size_t size_t align
 
 addr = malloc_phys ( len, align )
 

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

◆ DMA_RX

#define DMA_RX   0x02

Device will write data to host memory.

Definition at line 135 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 138 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 147 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 157 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 166 of file dma.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ DMAAPI_INLINE() [1/7]

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/7]

static __always_inline void DMAAPI_INLINE ( flat  ,
dma_unmap   
)
inlinestatic

Unmap buffer.

Parameters
mapDMA mapping

Definition at line 200 of file dma.h.

200  {
201 
202  /* Decrement mapping count (for debugging) */
203  if ( DBG_LOG ) {
204  assert ( map->dma != NULL );
205  map->dma->mapped--;
206  map->dma = NULL;
207  }
208 }
struct dma_device * dma
DMA device (if unmapping is required)
Definition: dma.h:41
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static __always_inline int struct dma_mapping * map
Definition: dma.h:181
unsigned int mapped
Total number of mappings (for debugging)
Definition: dma.h:53
#define DBG_LOG
Definition: compiler.h:317
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References assert(), DBG_LOG, dma_mapping::dma, map, dma_device::mapped, and NULL.

◆ DMAAPI_INLINE() [3/7]

static __always_inline void* DMAAPI_INLINE ( flat  ,
dma_alloc   
)
inlinestatic

Allocate and map DMA-coherent buffer.

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

◆ if() [1/2]

if ( DBG_LOG &&  addr)

Definition at line 229 of file dma.h.

229  {
230  map->dma = dma;
231  dma->mapped++;
232  }
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:181
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436

References dma_mapping::dma, dma(), and map.

◆ DMAAPI_INLINE() [4/7]

static __always_inline void DMAAPI_INLINE ( flat  ,
dma_free   
)
inlinestatic

Unmap and free DMA-coherent buffer.

Parameters
mapDMA mapping
addrBuffer address
lenLength of buffer

◆ if() [2/2]

if ( DBG_LOG  )

Definition at line 252 of file dma.h.

252  {
253  assert ( map->dma != NULL );
254  map->dma->mapped--;
255  map->dma = NULL;
256  }
struct dma_device * dma
DMA device (if unmapping is required)
Definition: dma.h:41
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static __always_inline int struct dma_mapping * map
Definition: dma.h:181
unsigned int mapped
Total number of mappings (for debugging)
Definition: dma.h:53
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

References assert(), dma_mapping::dma, map, dma_device::mapped, and NULL.

◆ DMAAPI_INLINE() [5/7]

static __always_inline userptr_t DMAAPI_INLINE ( flat  ,
dma_umalloc   
)
inlinestatic

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

◆ DMAAPI_INLINE() [6/7]

static __always_inline void DMAAPI_INLINE ( flat  ,
dma_ufree   
)
inlinestatic

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

Parameters
mapDMA mapping
addrBuffer address
lenLength of buffer

◆ DMAAPI_INLINE() [7/7]

static __always_inline void DMAAPI_INLINE ( flat  ,
dma_set_mask   
)
inlinestatic

Set addressable space mask.

Parameters
dmaDMA device
maskAddressable space mask

◆ dma_unmap()

void dma_unmap ( struct dma_mapping map)

Unmap buffer.

Parameters
mapDMA mapping

Referenced by intelxl_msix_disable(), intelxl_msix_enable(), and iob_unmap().

◆ dma_alloc()

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

Allocate and map DMA-coherent buffer.

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

Referenced by intel_create_ring(), intelxl_alloc_admin(), intelxl_alloc_ring(), rdc_create_ring(), realtek_create_buffer(), realtek_create_ring(), vp_alloc_vq(), xhci_context(), xhci_dcbaa_alloc(), xhci_device_open(), xhci_event_alloc(), xhci_ring_alloc(), and xhci_scratchpad_alloc().

◆ dma_free()

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

◆ dma_umalloc()

userptr_t 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 xhci_scratchpad_alloc().

◆ dma_ufree()

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

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

Parameters
mapDMA mapping
addrBuffer address
lenLength of buffer

Referenced by 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_phys()

physaddr_t dma_phys ( struct dma_mapping map,
physaddr_t  addr 
)

Get DMA address from physical address.

Parameters
mapDMA mapping
addrPhysical address within the mapped region
Return values
addrDevice-side DMA address

Referenced by dma(), and xhci_scratchpad_alloc().

◆ dma()

static __always_inline physaddr_t dma ( struct dma_mapping map,
void *  addr 
)
inlinestatic

Get DMA address from virtual address.

Parameters
mapDMA mapping
addrVirtual address within the mapped region
Return values
addrDevice-side DMA address

Definition at line 436 of file dma.h.

437  {
438 
439  /* Get DMA address from corresponding physical address */
440  return dma_phys ( map, virt_to_phys ( addr ) );
441 }
physaddr_t dma_phys(struct dma_mapping *map, physaddr_t addr)
Get DMA address from physical address.
static __always_inline unsigned long virt_to_phys(volatile const void *addr)
Convert virtual address to a physical address.
Definition: uaccess.h:287
addr
Definition: dma.h:226
static __always_inline int struct dma_mapping * map
Definition: dma.h:181

References addr, dma_phys(), map, and virt_to_phys().

Referenced by alloc_rx_iob(), dma_init(), dma_op_alloc(), dma_op_free(), dma_op_map(), dma_op_set_mask(), dma_op_ufree(), dma_op_umalloc(), dma_op_unmap(), dma_set_mask_64bit(), efipci_dma_alloc(), efipci_dma_free(), efipci_dma_map(), efipci_dma_set_mask(), efipci_dma_ufree(), efipci_dma_umalloc(), efipci_dma_unmap(), ice_admin_add_txq(), if(), intel_create_ring(), intelxl_admin_command(), intelxl_admin_event_init(), intelxl_create_ring(), intelxl_enable_admin(), intelxl_msix_enable(), intelxlvf_admin_configure(), iob_dma(), iob_map(), iob_map_rx(), iob_map_tx(), myri10ge_net_poll(), rdc_create_ring(), realtek_create_buffer(), realtek_create_ring(), virtnet_enqueue_iob(), vp_find_vq(), vpm_find_vqs(), xhci_abort(), xhci_address_device_input(), xhci_command_alloc(), xhci_configure_endpoint_input(), xhci_context(), xhci_dcbaa_alloc(), xhci_device_open(), xhci_event_alloc(), xhci_event_poll(), xhci_ring_alloc(), xhci_scratchpad_alloc(), and xhci_set_tr_dequeue_pointer().

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

449  {
450 
451  /* Unmapping is required if a DMA device was recorded */
452  return ( map->dma != NULL );
453 }
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:181
#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 461 of file dma.h.

462  {
463 
464  /* Set operations table */
465  dma->op = op;
466 }
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436

References dma(), and op.

Referenced by efipci_open().

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

474  {
475 
476  /* Set mask to maximum physical address */
477  dma_set_mask ( dma, ~( ( physaddr_t ) 0 ) );
478 }
void dma_set_mask(struct dma_device *dma, physaddr_t mask)
Set addressable space mask.
unsigned long physaddr_t
Definition: stdint.h:20
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436

References dma(), and dma_set_mask().

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

Variable Documentation

◆ map

static __always_inline userptr_t struct dma_mapping * map

◆ __unused

__always_inline void physaddr_t mask __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:181
static __always_inline physaddr_t dma(struct dma_mapping *map, void *addr)
Get DMA address from virtual address.
Definition: dma.h:436
#define DBG_LOG
Definition: compiler.h:317

Definition at line 181 of file dma.h.

◆ len

Initial value:
{
static __always_inline void struct dma_mapping size_t len
Definition: dma.h:221
addr
Definition: dma.h:226
static void free_phys(void *ptr, size_t size)
Free memory allocated with malloc_phys()
Definition: malloc.h:77

Definition at line 221 of file dma.h.

◆ align

◆ addr

Definition at line 226 of file dma.h.

Referenced by dma().