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" 2622c37a10SEric Auger 2722c37a10SEric Auger #define TYPE_VIRTIO_IOMMU "virtio-iommu-device" 288b4eb09eSEric Auger #define TYPE_VIRTIO_IOMMU_PCI "virtio-iommu-device-base" 2922c37a10SEric Auger #define VIRTIO_IOMMU(obj) \ 3022c37a10SEric Auger OBJECT_CHECK(VirtIOIOMMU, (obj), TYPE_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; 4022c37a10SEric Auger } IOMMUDevice; 4122c37a10SEric Auger 4222c37a10SEric Auger typedef struct IOMMUPciBus { 4322c37a10SEric Auger PCIBus *bus; 44f7795e40SPhilippe Mathieu-Daudé IOMMUDevice *pbdev[]; /* Parent array is sparse, so dynamically alloc */ 4522c37a10SEric Auger } IOMMUPciBus; 4622c37a10SEric Auger 4722c37a10SEric Auger typedef struct VirtIOIOMMU { 4822c37a10SEric Auger VirtIODevice parent_obj; 4922c37a10SEric Auger VirtQueue *req_vq; 5022c37a10SEric Auger VirtQueue *event_vq; 5122c37a10SEric Auger struct virtio_iommu_config config; 5222c37a10SEric Auger uint64_t features; 5322c37a10SEric Auger GHashTable *as_by_busptr; 54cfb42188SEric Auger IOMMUPciBus *iommu_pcibus_by_bus_num[PCI_BUS_MAX]; 5522c37a10SEric Auger PCIBus *primary_bus; 56*1733eebbSEric Auger ReservedRegion *reserved_regions; 57*1733eebbSEric Auger uint32_t nb_reserved_regions; 5822c37a10SEric Auger GTree *domains; 5922c37a10SEric Auger QemuMutex mutex; 6022c37a10SEric Auger GTree *endpoints; 6122c37a10SEric Auger } VirtIOIOMMU; 6222c37a10SEric Auger 6322c37a10SEric Auger #endif 64