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
devstruct vfio_deviceclasscodepci class code
bdfpci device identifier (“bus:device:function”)
config_region_infopci configuration space region information
bar_region_infopci 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 *pcistruct vfio_pci_deviceto initializeconst char *bdfpci 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 *pciint idxthe vfio region index to map
size_t lennumber of bytes to map
uint64_t offsetoffset at which to start mapping
int protwhat 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 *pciint idxthe vfio region index to unmap
void *memvirtual memory address to unmap
size_t lennumber of bytes to unmap
uint64_t offsetoffset 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 *pcivoid *bufbuffer to store the bytes read
size_t lennumber of bytes to read
off_t offsetoffset 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 *pcivoid *bufbuffer to write
size_t lennumber of bytes to write
off_t offsetoffset 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.