2 * vfio based device assignment support
4 * Copyright Red Hat, Inc. 2012
7 * Alex Williamson <alex.williamson@redhat.com>
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
13 #ifndef HW_VFIO_PCI_INT_H
14 #define HW_VFIO_PCI_INT_H
16 #include "qemu-common.h"
17 #include "qemu-queue.h"
19 #include "event_notifier.h"
21 typedef struct VFIOBAR
{
22 off_t fd_offset
; /* offset of BAR within device fd */
23 int fd
; /* device fd, allows us to pass VFIOBAR as opaque data */
24 MemoryRegion mem
; /* slow, read/write access */
25 MemoryRegion mmap_mem
; /* direct mapped access */
28 uint32_t flags
; /* VFIO region flags (rd/wr/mmap) */
29 uint8_t nr
; /* cache the BAR number for debug */
32 typedef struct VFIOINTx
{
33 bool pending
; /* interrupt pending */
34 bool kvm_accel
; /* set when QEMU bypass through KVM enabled */
35 uint8_t pin
; /* which pin to pull for qemu_set_irq */
36 EventNotifier interrupt
; /* eventfd triggered on interrupt */
37 EventNotifier unmask
; /* eventfd for unmask on QEMU bypass */
38 PCIINTxRoute route
; /* routing info for QEMU bypass */
45 typedef struct VFIOMSIVector
{
46 EventNotifier interrupt
; /* eventfd triggered on interrupt */
47 struct VFIODevice
*vdev
; /* back pointer to device */
48 int virq
; /* KVM irqchip route for QEMU bypass */
61 typedef struct VFIOContainer
{
62 int fd
; /* /dev/vfio/vfio, empowered by the attached groups */
64 /* enable abstraction to support various iommu backends */
66 MemoryListener listener
; /* Used by type1 iommu */
68 void (*release
)(struct VFIOContainer
*);
70 QLIST_HEAD(, VFIOGroup
) group_list
;
71 QLIST_ENTRY(VFIOContainer
) next
;
74 /* Cache of MSI-X setup plus extra mmap and memory region for split BAR map */
75 typedef struct VFIOMSIXInfo
{
79 uint32_t table_offset
;
81 MemoryRegion mmap_mem
;
85 typedef struct VFIODevice
{
89 unsigned int config_size
;
90 off_t config_offset
; /* Offset of config space region within device fd */
91 unsigned int rom_size
;
92 off_t rom_offset
; /* Offset of ROM region within device fd */
94 VFIOMSIVector
*msi_vectors
;
96 int nr_vectors
; /* Number of MSI/MSIX vectors currently in use */
97 int interrupt
; /* Current interrupt type */
98 VFIOBAR bars
[PCI_NUM_REGIONS
- 1]; /* No ROM */
99 PCIHostDeviceAddress host
;
100 QLIST_ENTRY(VFIODevice
) next
;
101 struct VFIOGroup
*group
;
105 typedef struct VFIOGroup
{
108 VFIOContainer
*container
;
109 QLIST_HEAD(, VFIODevice
) device_list
;
110 QLIST_ENTRY(VFIOGroup
) next
;
111 QLIST_ENTRY(VFIOGroup
) container_next
;
114 #endif /* HW_VFIO_PCI_INT_H */