xref: /qemu/include/hw/virtio/virtio-iommu.h (revision 22c37a10f3e1de1b19aa8281bc368d8cea960f4c)
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 
27 #define TYPE_VIRTIO_IOMMU "virtio-iommu-device"
28 #define VIRTIO_IOMMU(obj) \
29         OBJECT_CHECK(VirtIOIOMMU, (obj), TYPE_VIRTIO_IOMMU)
30 
31 typedef struct IOMMUDevice {
32     void         *viommu;
33     PCIBus       *bus;
34     int           devfn;
35     IOMMUMemoryRegion  iommu_mr;
36     AddressSpace  as;
37 } IOMMUDevice;
38 
39 typedef struct IOMMUPciBus {
40     PCIBus       *bus;
41     IOMMUDevice  *pbdev[0]; /* Parent array is sparse, so dynamically alloc */
42 } IOMMUPciBus;
43 
44 typedef struct VirtIOIOMMU {
45     VirtIODevice parent_obj;
46     VirtQueue *req_vq;
47     VirtQueue *event_vq;
48     struct virtio_iommu_config config;
49     uint64_t features;
50     GHashTable *as_by_busptr;
51     PCIBus *primary_bus;
52     GTree *domains;
53     QemuMutex mutex;
54     GTree *endpoints;
55 } VirtIOIOMMU;
56 
57 #endif
58