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" 27294ac5feSEric Auger #include "qapi/qapi-types-virtio.h" 28*32cad1ffSPhilippe Mathieu-Daudé #include "system/host_iommu_device.h" 2922c37a10SEric Auger 3022c37a10SEric Auger #define TYPE_VIRTIO_IOMMU "virtio-iommu-device" 3119d20e91SEric Auger #define TYPE_VIRTIO_IOMMU_PCI "virtio-iommu-pci" 328063396bSEduardo Habkost OBJECT_DECLARE_SIMPLE_TYPE(VirtIOIOMMU, VIRTIO_IOMMU) 3322c37a10SEric Auger 34cfb42188SEric Auger #define TYPE_VIRTIO_IOMMU_MEMORY_REGION "virtio-iommu-memory-region" 35cfb42188SEric Auger 3622c37a10SEric Auger typedef struct IOMMUDevice { 3722c37a10SEric Auger void *viommu; 3822c37a10SEric Auger PCIBus *bus; 3922c37a10SEric Auger int devfn; 4022c37a10SEric Auger IOMMUMemoryRegion iommu_mr; 4122c37a10SEric Auger AddressSpace as; 4290519b90SZhenzhong Duan MemoryRegion root; /* The root container of the device */ 4390519b90SZhenzhong Duan MemoryRegion bypass_mr; /* The alias of shared memory MR */ 44908cae0dSEric Auger GList *resv_regions; 4530d40e39SEric Auger GList *host_resv_ranges; 4622c37a10SEric Auger } IOMMUDevice; 4722c37a10SEric Auger 4822c37a10SEric Auger typedef struct IOMMUPciBus { 4922c37a10SEric Auger PCIBus *bus; 50f7795e40SPhilippe Mathieu-Daudé IOMMUDevice *pbdev[]; /* Parent array is sparse, so dynamically alloc */ 5122c37a10SEric Auger } IOMMUPciBus; 5222c37a10SEric Auger 53db1015e9SEduardo Habkost struct VirtIOIOMMU { 5422c37a10SEric Auger VirtIODevice parent_obj; 5522c37a10SEric Auger VirtQueue *req_vq; 5622c37a10SEric Auger VirtQueue *event_vq; 5722c37a10SEric Auger struct virtio_iommu_config config; 5822c37a10SEric Auger uint64_t features; 5922c37a10SEric Auger GHashTable *as_by_busptr; 60817ef10dSEric Auger GHashTable *host_iommu_devices; 61cfb42188SEric Auger IOMMUPciBus *iommu_pcibus_by_bus_num[PCI_BUS_MAX]; 6222c37a10SEric Auger PCIBus *primary_bus; 6341cc70cdSEric Auger ReservedRegion *prop_resv_regions; 6441cc70cdSEric Auger uint32_t nr_prop_resv_regions; 6522c37a10SEric Auger GTree *domains; 6608f2030aSZhenzhong Duan QemuRecMutex mutex; 6722c37a10SEric Auger GTree *endpoints; 68448179e3SJean-Philippe Brucker bool boot_bypass; 6994df5b21SEric Auger Notifier machine_done; 7094df5b21SEric Auger bool granule_frozen; 71294ac5feSEric Auger GranuleMode granule_mode; 7201e7e492SEric Auger uint8_t aw_bits; 73db1015e9SEduardo Habkost }; 7422c37a10SEric Auger 7522c37a10SEric Auger #endif 76