xref: /qemu/include/hw/virtio/virtio-iommu.h (revision cfb42188b24d5904f82cd609185847a1168226e3)
1 /*
2  * virtio-iommu device
3  *
4  * Copyright (c) 2020 Red Hat, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2 or later, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along with
16  * this program.  If not, see <http://www.gnu.org/licenses/>.
17  *
18  */
19 
20 #ifndef QEMU_VIRTIO_IOMMU_H
21 #define QEMU_VIRTIO_IOMMU_H
22 
23 #include "standard-headers/linux/virtio_iommu.h"
24 #include "hw/virtio/virtio.h"
25 #include "hw/pci/pci.h"
26 
27 #define TYPE_VIRTIO_IOMMU "virtio-iommu-device"
28 #define VIRTIO_IOMMU(obj) \
29         OBJECT_CHECK(VirtIOIOMMU, (obj), TYPE_VIRTIO_IOMMU)
30 
31 #define TYPE_VIRTIO_IOMMU_MEMORY_REGION "virtio-iommu-memory-region"
32 
33 typedef struct IOMMUDevice {
34     void         *viommu;
35     PCIBus       *bus;
36     int           devfn;
37     IOMMUMemoryRegion  iommu_mr;
38     AddressSpace  as;
39 } IOMMUDevice;
40 
41 typedef struct IOMMUPciBus {
42     PCIBus       *bus;
43     IOMMUDevice  *pbdev[0]; /* Parent array is sparse, so dynamically alloc */
44 } IOMMUPciBus;
45 
46 typedef struct VirtIOIOMMU {
47     VirtIODevice parent_obj;
48     VirtQueue *req_vq;
49     VirtQueue *event_vq;
50     struct virtio_iommu_config config;
51     uint64_t features;
52     GHashTable *as_by_busptr;
53     IOMMUPciBus *iommu_pcibus_by_bus_num[PCI_BUS_MAX];
54     PCIBus *primary_bus;
55     GTree *domains;
56     QemuMutex mutex;
57     GTree *endpoints;
58 } VirtIOIOMMU;
59 
60 #endif
61