libocxl
Functions
OpenCAPI MMIO Functions

The MMIO functions map the global and per-PASID MMIO spaces of the AFU into the address space of the process, as well as moderating access to them. More...

Functions

ocxl_err global_mmio_open (ocxl_afu *afu)
 Open the global MMIO descriptor on an AFU. More...
 
ocxl_err ocxl_mmio_map_advanced (ocxl_afu_h afu, ocxl_mmio_type type, size_t size, int prot, uint64_t flags, off_t offset, ocxl_mmio_h *region)
 Map an MMIO area of an AFU. More...
 
ocxl_err ocxl_mmio_map (ocxl_afu_h afu, ocxl_mmio_type type, ocxl_mmio_h *region)
 Map an MMIO area of an AFU. More...
 
void ocxl_mmio_unmap (ocxl_mmio_h region)
 Unmap an MMIO region from an AFU. More...
 
int ocxl_mmio_get_fd (ocxl_afu_h afu, ocxl_mmio_type type)
 Get a file descriptor for an MMIO area of an AFU. More...
 
size_t ocxl_mmio_size (ocxl_afu_h afu, ocxl_mmio_type type)
 Get the size of an MMIO region for an AFU. More...
 
ocxl_err ocxl_mmio_get_info (ocxl_mmio_h region, void **address, size_t *size)
 Get the address & size of a mapped MMIO region. More...
 
ocxl_err ocxl_mmio_read32 (ocxl_mmio_h mmio, off_t offset, ocxl_endian endian, uint32_t *out)
 Read a 32-bit value from an AFU's MMIO region & convert endianess. More...
 
ocxl_err ocxl_mmio_read64 (ocxl_mmio_h mmio, off_t offset, ocxl_endian endian, uint64_t *out)
 Read a 64-bit value from an AFU's MMIO region & convert endianess. More...
 
ocxl_err ocxl_mmio_write32 (ocxl_mmio_h mmio, off_t offset, ocxl_endian endian, uint32_t value)
 Convert endianess and write a 32-bit value to an AFU's MMIO region. More...
 
ocxl_err ocxl_mmio_write64 (ocxl_mmio_h mmio, off_t offset, ocxl_endian endian, uint64_t value)
 Convert endianess and write a 64-bit value to an AFU's MMIO region. More...
 

Detailed Description

The MMIO functions map the global and per-PASID MMIO spaces of the AFU into the address space of the process, as well as moderating access to them.

Only 32bit & 64bit accesses are supported.

Function Documentation

◆ global_mmio_open()

ocxl_err global_mmio_open ( ocxl_afu *  afu)

Open the global MMIO descriptor on an AFU.

Parameters
afuthe AFU
Return values
OCXL_NO_DEVif the MMIO descriptor could not be opened

Definition at line 93 of file mmio.c.

◆ ocxl_mmio_get_fd()

int ocxl_mmio_get_fd ( ocxl_afu_h  afu,
ocxl_mmio_type  type 
)

Get a file descriptor for an MMIO area of an AFU.

Once obtained, the descriptor may be used to manually MMAP a section of the MMIO area.

See also
ocxl_mmio_size() to get the size of the MMIO areas
Precondition
the AFU has been opened
Parameters
afuthe AFU to operate on
typethe type of MMIO area to map
Returns
the requested descriptor, or -1 if it is not available

Definition at line 329 of file mmio.c.

◆ ocxl_mmio_get_info()

ocxl_err ocxl_mmio_get_info ( ocxl_mmio_h  region,
void **  address,
size_t *  size 
)

Get the address & size of a mapped MMIO region.

Precondition
the AFU has been opened, and the MMIO area mapped
Parameters
regionthe MMIO region to get the details for
address[out] The address of the MMIO region
size[out] the size of the MMIO region in bytes
Return values
OCXL_OKif the details were retrieved
OCXL_INVALID_ARGSif the region is invalid

Definition at line 386 of file mmio.c.

◆ ocxl_mmio_map()

ocxl_err ocxl_mmio_map ( ocxl_afu_h  afu,
ocxl_mmio_type  type,
ocxl_mmio_h region 
)

Map an MMIO area of an AFU.

Maps the entire global/per-PASID region of MMIO memory on the AFU with read/write access granted.

Precondition
the AFU has been opened
Parameters
afuthe AFU to operate on
typethe type of MMIO area to map
region[out] the MMIO region handle
Return values
OCXL_OKon success
OCXL_NO_MEMif the map failed
OCXL_NO_CONTEXTif the AFU has not been opened
OCXL_INVALID_ARGSif the flags are not valid

Definition at line 291 of file mmio.c.

◆ ocxl_mmio_map_advanced()

ocxl_err ocxl_mmio_map_advanced ( ocxl_afu_h  afu,
ocxl_mmio_type  type,
size_t  size,
int  prot,
uint64_t  flags,
off_t  offset,
ocxl_mmio_h region 
)

Map an MMIO area of an AFU.

Provides finer grain control of MMIO region mapping. Allows for protection parameters to be specified, as well as allowing partial mappings (with PAGE_SIZE granularity).

Precondition
the AFU has been opened
Parameters
afuthe AFU to operate on
typethe type of MMIO area to map
sizethe size of the MMIO region to map (or 0 to map the full region)
protthe protection parameters as per mmap/mprotect
flagsAdditional flags to modify the map behavior (currently unused, must be 0)
offsetthe offset of the MMIO region to map (or 0 to map the full region), should be a multiple of PAGE_SIZE
[out]regionthe MMIO region handle
Return values
OCXL_OKon success
OCXL_NO_MEMif the map failed
OCXL_NO_CONTEXTif the AFU has not been opened
OCXL_INVALID_ARGSif the flags are not valid

Definition at line 254 of file mmio.c.

◆ ocxl_mmio_read32()

ocxl_err ocxl_mmio_read32 ( ocxl_mmio_h  mmio,
off_t  offset,
ocxl_endian  endian,
uint32_t *  out 
)

Read a 32-bit value from an AFU's MMIO region & convert endianess.

Read the 32-bit value at offset from the address of the mapped MMIO space, and convert endianess as specified by the endian parameter. Memory barriers are inserted before and after the MMIO operation.

Precondition
the AFU has been opened, and the MMIO area mapped
Parameters
mmiothe MMIO area to operate on
offsetA byte address that is aligned on a word (4 byte) boundary. It must be lower than the MMIO size (-4 bytes) reported by ocxl_mmio_size()
endianthe endianess of the stored data (will be converted to native)
[out]outthe value that was read
Return values
OCXL_OKif the value was read
OCXL_NO_CONTEXTif the MMIO area is not mapped
OCXL_OUT_OF_BOUNDSif the offset exceeds the available area

Definition at line 617 of file mmio.c.

◆ ocxl_mmio_read64()

ocxl_err ocxl_mmio_read64 ( ocxl_mmio_h  mmio,
off_t  offset,
ocxl_endian  endian,
uint64_t *  out 
)

Read a 64-bit value from an AFU's MMIO region & convert endianess.

Read the 64-bit value at offset from the address of the mapped MMIO space, and convert endianess as specified by the endian parameter. Memory barriers are inserted before and after the MMIO operation.

Precondition
the AFU has been opened, and the MMIO area mapped
Parameters
mmiothe MMIO area to operate on
offsetA byte address that is aligned on an 8 byte boundary. It must be lower than the MMIO size (-8 bytes) reported by ocxl_afu_get_mmio_size()
endianthe endianess of the stored data (will be converted to native)
[out]outthe value that was read
Return values
OCXL_OKif the value was read
OCXL_NO_CONTEXTif the MMIO area is not mapped
OCXL_OUT_OF_BOUNDSif the offset exceeds the available area

Definition at line 657 of file mmio.c.

◆ ocxl_mmio_size()

size_t ocxl_mmio_size ( ocxl_afu_h  afu,
ocxl_mmio_type  type 
)

Get the size of an MMIO region for an AFU.

Parameters
afuthe AFU to get the MMIO size of
typethe type of the MMIO region
Returns
the size of the MMIO region in bytes

Definition at line 356 of file mmio.c.

◆ ocxl_mmio_unmap()

void ocxl_mmio_unmap ( ocxl_mmio_h  region)

Unmap an MMIO region from an AFU.

Precondition
the AFU has been opened, and the MMIO area mapped
Parameters
regionthe MMIO region to unmap

Definition at line 303 of file mmio.c.

◆ ocxl_mmio_write32()

ocxl_err ocxl_mmio_write32 ( ocxl_mmio_h  mmio,
off_t  offset,
ocxl_endian  endian,
uint32_t  value 
)

Convert endianess and write a 32-bit value to an AFU's MMIO region.

Convert endianess and write the 32-bit word at offset from the address of the mapped MMIO space. Memory barriers are inserted before and after the MMIO operation.

Precondition
the AFU has been opened, and the MMIO area mapped
Parameters
mmiothe MMIO area to operate on
offsetA byte address that is aligned on a 4 byte boundary. It must be lower than the MMIO size (-4 bytes) reported by ocxl_mmio_size()
endianthe endianess of the stored data (value will be converted to this before storing it)
valuethe value to write
Return values
OCXL_OKif the value was written
OCXL_NO_CONTEXTif the MMIO area is not mapped
OCXL_OUT_OF_BOUNDSif the offset exceeds the available area

Definition at line 697 of file mmio.c.

◆ ocxl_mmio_write64()

ocxl_err ocxl_mmio_write64 ( ocxl_mmio_h  mmio,
off_t  offset,
ocxl_endian  endian,
uint64_t  value 
)

Convert endianess and write a 64-bit value to an AFU's MMIO region.

Convert endianess and write the 32-bit word at offset from the address of the mapped MMIO space. Memory barriers are inserted before and after the MMIO operation.

Precondition
the AFU has been opened, and the MMIO area mapped
Parameters
mmiothe MMIO area to operate on
offsetA byte address that is aligned on an 8 byte boundary. It must be lower than the MMIO size (-8 bytes) reported by ocxl_mmio_size()
endianthe endianess of the stored data (value will be converted to this before storing it)
valuethe value to write
Return values
OCXL_OKif the value was written
OCXL_NO_CONTEXTif the MMIO area is not mapped
OCXL_OUT_OF_BOUNDSif the offset exceeds the available area

Definition at line 732 of file mmio.c.