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 */ 4222c37a10SEric Auger } IOMMUDevice; 4322c37a10SEric Auger 4422c37a10SEric Auger typedef struct IOMMUPciBus { 4522c37a10SEric Auger PCIBus *bus; 46f7795e40SPhilippe Mathieu-Daudé IOMMUDevice *pbdev[]; /* Parent array is sparse, so dynamically alloc */ 4722c37a10SEric Auger } IOMMUPciBus; 4822c37a10SEric Auger 49db1015e9SEduardo Habkost struct VirtIOIOMMU { 5022c37a10SEric Auger VirtIODevice parent_obj; 5122c37a10SEric Auger VirtQueue *req_vq; 5222c37a10SEric Auger VirtQueue *event_vq; 5322c37a10SEric Auger struct virtio_iommu_config config; 5422c37a10SEric Auger uint64_t features; 5522c37a10SEric Auger GHashTable *as_by_busptr; 56cfb42188SEric Auger IOMMUPciBus *iommu_pcibus_by_bus_num[PCI_BUS_MAX]; 5722c37a10SEric Auger PCIBus *primary_bus; 581733eebbSEric Auger ReservedRegion *reserved_regions; 591733eebbSEric Auger uint32_t nb_reserved_regions; 6022c37a10SEric Auger GTree *domains; 6108f2030aSZhenzhong Duan QemuRecMutex mutex; 6222c37a10SEric Auger GTree *endpoints; 63448179e3SJean-Philippe Brucker bool boot_bypass; 64*94df5b21SEric Auger Notifier machine_done; 65*94df5b21SEric Auger bool granule_frozen; 66db1015e9SEduardo Habkost }; 6722c37a10SEric Auger 6822c37a10SEric Auger #endif 69