xref: /qemu/include/hw/virtio/virtio-iommu.h (revision 30d40e39bdcb50e67f7cca7bee8bf59234c4ec12)
122c37a10SEric Auger /*
222c37a10SEric Auger  * virtio-iommu device
322c37a10SEric Auger  *
422c37a10SEric Auger  * Copyright (c) 2020 Red Hat, Inc.
522c37a10SEric Auger  *
622c37a10SEric Auger  * This program is free software; you can redistribute it and/or modify it
722c37a10SEric Auger  * under the terms and conditions of the GNU General Public License,
822c37a10SEric Auger  * version 2 or later, as published by the Free Software Foundation.
922c37a10SEric Auger  *
1022c37a10SEric Auger  * This program is distributed in the hope it will be useful, but WITHOUT
1122c37a10SEric Auger  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1222c37a10SEric Auger  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
1322c37a10SEric Auger  * more details.
1422c37a10SEric Auger  *
1522c37a10SEric Auger  * You should have received a copy of the GNU General Public License along with
1622c37a10SEric Auger  * this program.  If not, see <http://www.gnu.org/licenses/>.
1722c37a10SEric Auger  *
1822c37a10SEric Auger  */
1922c37a10SEric Auger 
2022c37a10SEric Auger #ifndef QEMU_VIRTIO_IOMMU_H
2122c37a10SEric Auger #define QEMU_VIRTIO_IOMMU_H
2222c37a10SEric Auger 
2322c37a10SEric Auger #include "standard-headers/linux/virtio_iommu.h"
2422c37a10SEric Auger #include "hw/virtio/virtio.h"
2522c37a10SEric Auger #include "hw/pci/pci.h"
26db1015e9SEduardo Habkost #include "qom/object.h"
2722c37a10SEric Auger 
2822c37a10SEric Auger #define TYPE_VIRTIO_IOMMU "virtio-iommu-device"
2919d20e91SEric Auger #define TYPE_VIRTIO_IOMMU_PCI "virtio-iommu-pci"
308063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(VirtIOIOMMU, VIRTIO_IOMMU)
3122c37a10SEric Auger 
32cfb42188SEric Auger #define TYPE_VIRTIO_IOMMU_MEMORY_REGION "virtio-iommu-memory-region"
33cfb42188SEric Auger 
3422c37a10SEric Auger typedef struct IOMMUDevice {
3522c37a10SEric Auger     void         *viommu;
3622c37a10SEric Auger     PCIBus       *bus;
3722c37a10SEric Auger     int           devfn;
3822c37a10SEric Auger     IOMMUMemoryRegion  iommu_mr;
3922c37a10SEric Auger     AddressSpace  as;
4090519b90SZhenzhong Duan     MemoryRegion root;          /* The root container of the device */
4190519b90SZhenzhong Duan     MemoryRegion bypass_mr;     /* The alias of shared memory MR */
42908cae0dSEric Auger     GList *resv_regions;
43*30d40e39SEric Auger     GList *host_resv_ranges;
4409b4c3d6SEric Auger     bool probe_done;
4522c37a10SEric Auger } IOMMUDevice;
4622c37a10SEric Auger 
4722c37a10SEric Auger typedef struct IOMMUPciBus {
4822c37a10SEric Auger     PCIBus       *bus;
49f7795e40SPhilippe Mathieu-Daudé     IOMMUDevice  *pbdev[]; /* Parent array is sparse, so dynamically alloc */
5022c37a10SEric Auger } IOMMUPciBus;
5122c37a10SEric Auger 
52db1015e9SEduardo Habkost struct VirtIOIOMMU {
5322c37a10SEric Auger     VirtIODevice parent_obj;
5422c37a10SEric Auger     VirtQueue *req_vq;
5522c37a10SEric Auger     VirtQueue *event_vq;
5622c37a10SEric Auger     struct virtio_iommu_config config;
5722c37a10SEric Auger     uint64_t features;
5822c37a10SEric Auger     GHashTable *as_by_busptr;
59cfb42188SEric Auger     IOMMUPciBus *iommu_pcibus_by_bus_num[PCI_BUS_MAX];
6022c37a10SEric Auger     PCIBus *primary_bus;
6141cc70cdSEric Auger     ReservedRegion *prop_resv_regions;
6241cc70cdSEric Auger     uint32_t nr_prop_resv_regions;
6322c37a10SEric Auger     GTree *domains;
6408f2030aSZhenzhong Duan     QemuRecMutex mutex;
6522c37a10SEric Auger     GTree *endpoints;
66448179e3SJean-Philippe Brucker     bool boot_bypass;
6794df5b21SEric Auger     Notifier machine_done;
6894df5b21SEric Auger     bool granule_frozen;
69db1015e9SEduardo Habkost };
7022c37a10SEric Auger 
7122c37a10SEric Auger #endif
72