]> git.proxmox.com Git - mirror_qemu.git/blame - include/hw/vfio/vfio-common.h
vfio: Remove unneeded union from VFIOContainer
[mirror_qemu.git] / include / hw / vfio / vfio-common.h
CommitLineData
e2c7d025
EA
1/*
2 * common header for vfio based device assignment support
3 *
4 * Copyright Red Hat, Inc. 2012
5 *
6 * Authors:
7 * Alex Williamson <alex.williamson@redhat.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
11 *
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)
19 */
20#ifndef HW_VFIO_VFIO_COMMON_H
21#define HW_VFIO_VFIO_COMMON_H
22
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"
28
29/*#define DEBUG_VFIO*/
30#ifdef DEBUG_VFIO
31#define DPRINTF(fmt, ...) \
32 do { fprintf(stderr, "vfio: " fmt, ## __VA_ARGS__); } while (0)
33#else
34#define DPRINTF(fmt, ...) \
35 do { } while (0)
36#endif
37
e2c7d025
EA
38enum {
39 VFIO_DEVICE_TYPE_PCI = 0,
0ea2730b 40 VFIO_DEVICE_TYPE_PLATFORM = 1,
e2c7d025
EA
41};
42
43typedef struct VFIORegion {
44 struct VFIODevice *vbasedev;
45 off_t fd_offset; /* offset of region within device fd */
46 MemoryRegion mem; /* slow, read/write access */
47 MemoryRegion mmap_mem; /* direct mapped access */
48 void *mmap;
49 size_t size;
50 uint32_t flags; /* VFIO region flags (rd/wr/mmap) */
51 uint8_t nr; /* cache the region number for debug */
52} VFIORegion;
53
54typedef struct VFIOAddressSpace {
55 AddressSpace *as;
56 QLIST_HEAD(, VFIOContainer) containers;
57 QLIST_ENTRY(VFIOAddressSpace) list;
58} VFIOAddressSpace;
59
60struct VFIOGroup;
61
e2c7d025
EA
62typedef struct VFIOContainer {
63 VFIOAddressSpace *space;
64 int fd; /* /dev/vfio/vfio, empowered by the attached groups */
ee0bf0e5
DG
65 MemoryListener listener;
66 int error;
67 bool initialized;
e2c7d025
EA
68 QLIST_HEAD(, VFIOGuestIOMMU) giommu_list;
69 QLIST_HEAD(, VFIOGroup) group_list;
70 QLIST_ENTRY(VFIOContainer) next;
71} VFIOContainer;
72
73typedef struct VFIOGuestIOMMU {
74 VFIOContainer *container;
75 MemoryRegion *iommu;
76 Notifier n;
77 QLIST_ENTRY(VFIOGuestIOMMU) giommu_next;
78} VFIOGuestIOMMU;
79
80typedef struct VFIODeviceOps VFIODeviceOps;
81
82typedef struct VFIODevice {
83 QLIST_ENTRY(VFIODevice) next;
84 struct VFIOGroup *group;
85 char *name;
86 int fd;
87 int type;
88 bool reset_works;
89 bool needs_reset;
5e15d79b 90 bool no_mmap;
e2c7d025
EA
91 VFIODeviceOps *ops;
92 unsigned int num_irqs;
93 unsigned int num_regions;
94 unsigned int flags;
95} VFIODevice;
96
97struct VFIODeviceOps {
98 void (*vfio_compute_needs_reset)(VFIODevice *vdev);
99 int (*vfio_hot_reset_multi)(VFIODevice *vdev);
100 void (*vfio_eoi)(VFIODevice *vdev);
e2c7d025
EA
101};
102
103typedef struct VFIOGroup {
104 int fd;
105 int groupid;
106 VFIOContainer *container;
107 QLIST_HEAD(, VFIODevice) device_list;
108 QLIST_ENTRY(VFIOGroup) next;
109 QLIST_ENTRY(VFIOGroup) container_next;
110} VFIOGroup;
111
112void vfio_put_base_device(VFIODevice *vbasedev);
113void vfio_disable_irqindex(VFIODevice *vbasedev, int index);
114void vfio_unmask_single_irqindex(VFIODevice *vbasedev, int index);
115void vfio_mask_single_irqindex(VFIODevice *vbasedev, int index);
116void vfio_region_write(void *opaque, hwaddr addr,
117 uint64_t data, unsigned size);
118uint64_t vfio_region_read(void *opaque,
119 hwaddr addr, unsigned size);
e2c7d025
EA
120int vfio_mmap_region(Object *vdev, VFIORegion *region,
121 MemoryRegion *mem, MemoryRegion *submem,
122 void **map, size_t size, off_t offset,
123 const char *name);
124void vfio_reset_handler(void *opaque);
125VFIOGroup *vfio_get_group(int groupid, AddressSpace *as);
126void vfio_put_group(VFIOGroup *group);
127int vfio_get_device(VFIOGroup *group, const char *name,
128 VFIODevice *vbasedev);
129
130extern const MemoryRegionOps vfio_region_ops;
e2c7d025
EA
131extern QLIST_HEAD(vfio_group_head, VFIOGroup) vfio_group_list;
132extern QLIST_HEAD(vfio_as_head, VFIOAddressSpace) vfio_address_spaces;
133
134#endif /* !HW_VFIO_VFIO_COMMON_H */