PCI Device

struct vfio_pci_device

vfio pci device state

Definition:

struct vfio_pci_device {
    struct vfio_device dev;
    unsigned long long classcode;
    const char *bdf;
    struct vfio_region_info config_region_info;
    struct vfio_region_info bar_region_info[PCI_STD_NUM_BARS];
};

Members

dev

struct vfio_device

classcode

pci class code

bdf

pci device identifier (“bus:device:function”)

config_region_info

pci configuration space region information

bar_region_info

pci BAR region information

int vfio_pci_open(struct vfio_pci_device *pci, const char *bdf)

open and initialize pci device

Parameters

struct vfio_pci_device *pci

struct vfio_pci_device to initialize

const char *bdf

pci device identifier (“bus:device:function”) to open

Description

Open the pci device identified by bdf and initialize pci.

Return

On success, returns 0. On error, returns -1 and sets errno.

void *vfio_pci_map_bar(struct vfio_pci_device *pci, int idx, size_t len, uint64_t offset, int prot)

map a vfio device region into virtual memory

Parameters

struct vfio_pci_device *pci

struct vfio_pci_device

int idx

the vfio region index to map

size_t len

number of bytes to map

uint64_t offset

offset at which to start mapping

int prot

what accesses to permit to the mapped area (see man mmap).

Description

Map the vfio device memory region identified by idx into virtual memory.

Return

On success, returns the virtual memory address mapped. On error, returns NULL and sets errno.

void vfio_pci_unmap_bar(struct vfio_pci_device *pci, int idx, void *mem, size_t len, uint64_t offset)

unmap a vfio device region in virtual memory

Parameters

struct vfio_pci_device *pci

struct vfio_pci_device

int idx

the vfio region index to unmap

void *mem

virtual memory address to unmap

size_t len

number of bytes to unmap

uint64_t offset

offset at which to start unmapping

Description

Unmap the virtual memory address, previously mapped to the vfio device memory region identified by idx.

ssize_t vfio_pci_read_config(struct vfio_pci_device *pci, void *buf, size_t len, off_t offset)

Read from the PCI configuration space

Parameters

struct vfio_pci_device *pci

struct vfio_pci_device

void *buf

buffer to store the bytes read

size_t len

number of bytes to read

off_t offset

offset at which to read

Description

Read a number of bytes at a specified offset in the PCI configuration space.

Return

On success, returns the number of bytes read. On error, return -1 and set errno.

ssize_t vfio_pci_write_config(struct vfio_pci_device *pci, void *buf, size_t len, off_t offset)

Write into the PCI configuration space

Parameters

struct vfio_pci_device *pci

struct vfio_pci_device

void *buf

buffer to write

size_t len

number of bytes to write

off_t offset

offset at which to write

Description

Write a number of bytes at a specified offset in the PCI configuration space.

Return

On success, returns the number of bytes written. On error, return -1 and set errno.