2 * common header for 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.
12 * Based on qemu-kvm device-assignment:
13 * Adapted for KVM by Qumranet.
14 * Copyright (c) 2007, Neocleus, Alex Novik (alex@neocleus.com)
15 * Copyright (c) 2007, Neocleus, Guy Zana (guy@neocleus.com)
16 * Copyright (C) 2008, Qumranet, Amit Shah (amit.shah@qumranet.com)
17 * Copyright (C) 2008, Red Hat, Amit Shah (amit.shah@redhat.com)
18 * Copyright (C) 2008, IBM, Muli Ben-Yehuda (muli@il.ibm.com)
20 #ifndef HW_VFIO_VFIO_COMMON_H
21 #define HW_VFIO_VFIO_COMMON_H
23 #include "qemu-common.h"
24 #include "exec/address-spaces.h"
25 #include "exec/memory.h"
26 #include "qemu/queue.h"
27 #include "qemu/notify.h"
29 #include <linux/vfio.h>
32 /*#define DEBUG_VFIO*/
34 #define DPRINTF(fmt, ...) \
35 do { fprintf(stderr, "vfio: " fmt, ## __VA_ARGS__); } while (0)
37 #define DPRINTF(fmt, ...) \
42 VFIO_DEVICE_TYPE_PCI
= 0,
43 VFIO_DEVICE_TYPE_PLATFORM
= 1,
46 typedef struct VFIOMmap
{
53 typedef struct VFIORegion
{
54 struct VFIODevice
*vbasedev
;
55 off_t fd_offset
; /* offset of region within device fd */
56 MemoryRegion
*mem
; /* slow, read/write access */
58 uint32_t flags
; /* VFIO region flags (rd/wr/mmap) */
61 uint8_t nr
; /* cache the region number for debug */
64 typedef struct VFIOAddressSpace
{
66 QLIST_HEAD(, VFIOContainer
) containers
;
67 QLIST_ENTRY(VFIOAddressSpace
) list
;
72 typedef struct VFIOContainer
{
73 VFIOAddressSpace
*space
;
74 int fd
; /* /dev/vfio/vfio, empowered by the attached groups */
75 MemoryListener listener
;
79 * This assumes the host IOMMU can support only a single
80 * contiguous IOVA window. We may need to generalize that in
83 hwaddr min_iova
, max_iova
;
84 uint64_t iova_pgsizes
;
85 QLIST_HEAD(, VFIOGuestIOMMU
) giommu_list
;
86 QLIST_HEAD(, VFIOGroup
) group_list
;
87 QLIST_ENTRY(VFIOContainer
) next
;
90 typedef struct VFIOGuestIOMMU
{
91 VFIOContainer
*container
;
94 QLIST_ENTRY(VFIOGuestIOMMU
) giommu_next
;
97 typedef struct VFIODeviceOps VFIODeviceOps
;
99 typedef struct VFIODevice
{
100 QLIST_ENTRY(VFIODevice
) next
;
101 struct VFIOGroup
*group
;
110 unsigned int num_irqs
;
111 unsigned int num_regions
;
115 struct VFIODeviceOps
{
116 void (*vfio_compute_needs_reset
)(VFIODevice
*vdev
);
117 int (*vfio_hot_reset_multi
)(VFIODevice
*vdev
);
118 void (*vfio_eoi
)(VFIODevice
*vdev
);
121 typedef struct VFIOGroup
{
124 VFIOContainer
*container
;
125 QLIST_HEAD(, VFIODevice
) device_list
;
126 QLIST_ENTRY(VFIOGroup
) next
;
127 QLIST_ENTRY(VFIOGroup
) container_next
;
130 void vfio_put_base_device(VFIODevice
*vbasedev
);
131 void vfio_disable_irqindex(VFIODevice
*vbasedev
, int index
);
132 void vfio_unmask_single_irqindex(VFIODevice
*vbasedev
, int index
);
133 void vfio_mask_single_irqindex(VFIODevice
*vbasedev
, int index
);
134 void vfio_region_write(void *opaque
, hwaddr addr
,
135 uint64_t data
, unsigned size
);
136 uint64_t vfio_region_read(void *opaque
,
137 hwaddr addr
, unsigned size
);
138 int vfio_region_setup(Object
*obj
, VFIODevice
*vbasedev
, VFIORegion
*region
,
139 int index
, const char *name
);
140 int vfio_region_mmap(VFIORegion
*region
);
141 void vfio_region_mmaps_set_enabled(VFIORegion
*region
, bool enabled
);
142 void vfio_region_exit(VFIORegion
*region
);
143 void vfio_region_finalize(VFIORegion
*region
);
144 void vfio_reset_handler(void *opaque
);
145 VFIOGroup
*vfio_get_group(int groupid
, AddressSpace
*as
);
146 void vfio_put_group(VFIOGroup
*group
);
147 int vfio_get_device(VFIOGroup
*group
, const char *name
,
148 VFIODevice
*vbasedev
);
150 extern const MemoryRegionOps vfio_region_ops
;
151 extern QLIST_HEAD(vfio_group_head
, VFIOGroup
) vfio_group_list
;
152 extern QLIST_HEAD(vfio_as_head
, VFIOAddressSpace
) vfio_address_spaces
;
155 int vfio_get_region_info(VFIODevice
*vbasedev
, int index
,
156 struct vfio_region_info
**info
);
157 int vfio_get_dev_region_info(VFIODevice
*vbasedev
, uint32_t type
,
158 uint32_t subtype
, struct vfio_region_info
**info
);
160 #endif /* !HW_VFIO_VFIO_COMMON_H */