xref: /openbmc/qemu/include/hw/virtio/virtio-iommu.h (revision b439595a08d79120325de4684698bb7b6516aa8a)
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 #include "qom/object.h"
27 
28 #define TYPE_VIRTIO_IOMMU "virtio-iommu-device"
29 #define TYPE_VIRTIO_IOMMU_PCI "virtio-iommu-pci"
30 OBJECT_DECLARE_SIMPLE_TYPE(VirtIOIOMMU, VIRTIO_IOMMU)
31 
32 #define TYPE_VIRTIO_IOMMU_MEMORY_REGION "virtio-iommu-memory-region"
33 
34 typedef struct IOMMUDevice {
35     void         *viommu;
36     PCIBus       *bus;
37     int           devfn;
38     IOMMUMemoryRegion  iommu_mr;
39     AddressSpace  as;
40     MemoryRegion root;          /* The root container of the device */
41     MemoryRegion bypass_mr;     /* The alias of shared memory MR */
42     GList *resv_regions;
43 } IOMMUDevice;
44 
45 typedef struct IOMMUPciBus {
46     PCIBus       *bus;
47     IOMMUDevice  *pbdev[]; /* Parent array is sparse, so dynamically alloc */
48 } IOMMUPciBus;
49 
50 struct VirtIOIOMMU {
51     VirtIODevice parent_obj;
52     VirtQueue *req_vq;
53     VirtQueue *event_vq;
54     struct virtio_iommu_config config;
55     uint64_t features;
56     GHashTable *as_by_busptr;
57     IOMMUPciBus *iommu_pcibus_by_bus_num[PCI_BUS_MAX];
58     PCIBus *primary_bus;
59     ReservedRegion *prop_resv_regions;
60     uint32_t nr_prop_resv_regions;
61     GTree *domains;
62     QemuRecMutex mutex;
63     GTree *endpoints;
64     bool boot_bypass;
65     Notifier machine_done;
66     bool granule_frozen;
67 };
68 
69 #endif
70