2020-02-14 16:27:36 +03:00
|
|
|
/*
|
|
|
|
* virtio-iommu device
|
|
|
|
*
|
|
|
|
* Copyright (c) 2020 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2 or later, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QEMU_VIRTIO_IOMMU_H
|
|
|
|
#define QEMU_VIRTIO_IOMMU_H
|
|
|
|
|
|
|
|
#include "standard-headers/linux/virtio_iommu.h"
|
|
|
|
#include "hw/virtio/virtio.h"
|
|
|
|
#include "hw/pci/pci.h"
|
2020-09-03 23:43:22 +03:00
|
|
|
#include "qom/object.h"
|
2020-02-14 16:27:36 +03:00
|
|
|
|
|
|
|
#define TYPE_VIRTIO_IOMMU "virtio-iommu-device"
|
2021-10-13 22:17:55 +03:00
|
|
|
#define TYPE_VIRTIO_IOMMU_PCI "virtio-iommu-pci"
|
2020-09-16 21:25:19 +03:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(VirtIOIOMMU, VIRTIO_IOMMU)
|
2020-02-14 16:27:36 +03:00
|
|
|
|
2020-02-14 16:27:38 +03:00
|
|
|
#define TYPE_VIRTIO_IOMMU_MEMORY_REGION "virtio-iommu-memory-region"
|
|
|
|
|
2020-02-14 16:27:36 +03:00
|
|
|
typedef struct IOMMUDevice {
|
|
|
|
void *viommu;
|
|
|
|
PCIBus *bus;
|
|
|
|
int devfn;
|
|
|
|
IOMMUMemoryRegion iommu_mr;
|
|
|
|
AddressSpace as;
|
2022-06-13 09:10:08 +03:00
|
|
|
MemoryRegion root; /* The root container of the device */
|
|
|
|
MemoryRegion bypass_mr; /* The alias of shared memory MR */
|
2020-02-14 16:27:36 +03:00
|
|
|
} IOMMUDevice;
|
|
|
|
|
|
|
|
typedef struct IOMMUPciBus {
|
|
|
|
PCIBus *bus;
|
misc: Replace zero-length arrays with flexible array member (automatic)
Description copied from Linux kernel commit from Gustavo A. R. Silva
(see [3]):
--v-- description start --v--
The current codebase makes use of the zero-length array language
extension to the C90 standard, but the preferred mechanism to
declare variable-length types such as these ones is a flexible
array member [1], introduced in C99:
struct foo {
int stuff;
struct boo array[];
};
By making use of the mechanism above, we will get a compiler
warning in case the flexible array does not occur last in the
structure, which will help us prevent some kind of undefined
behavior bugs from being unadvertenly introduced [2] to the
Linux codebase from now on.
--^-- description end --^--
Do the similar housekeeping in the QEMU codebase (which uses
C99 since commit 7be41675f7cb).
All these instances of code were found with the help of the
following Coccinelle script:
@@
identifier s, m, a;
type t, T;
@@
struct s {
...
t m;
- T a[0];
+ T a[];
};
@@
identifier s, m, a;
type t, T;
@@
struct s {
...
t m;
- T a[0];
+ T a[];
} QEMU_PACKED;
[1] https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
[2] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=76497732932f
[3] https://git.kernel.org/pub/scm/linux/kernel/git/gustavoars/linux.git/commit/?id=17642a2fbd2c1
Inspired-by: Gustavo A. R. Silva <gustavo@embeddedor.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-03-04 18:38:15 +03:00
|
|
|
IOMMUDevice *pbdev[]; /* Parent array is sparse, so dynamically alloc */
|
2020-02-14 16:27:36 +03:00
|
|
|
} IOMMUPciBus;
|
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct VirtIOIOMMU {
|
2020-02-14 16:27:36 +03:00
|
|
|
VirtIODevice parent_obj;
|
|
|
|
VirtQueue *req_vq;
|
|
|
|
VirtQueue *event_vq;
|
|
|
|
struct virtio_iommu_config config;
|
|
|
|
uint64_t features;
|
|
|
|
GHashTable *as_by_busptr;
|
2020-02-14 16:27:38 +03:00
|
|
|
IOMMUPciBus *iommu_pcibus_by_bus_num[PCI_BUS_MAX];
|
2020-02-14 16:27:36 +03:00
|
|
|
PCIBus *primary_bus;
|
2020-07-03 18:59:42 +03:00
|
|
|
ReservedRegion *reserved_regions;
|
|
|
|
uint32_t nb_reserved_regions;
|
2020-02-14 16:27:36 +03:00
|
|
|
GTree *domains;
|
2022-06-13 09:10:09 +03:00
|
|
|
QemuRecMutex mutex;
|
2020-02-14 16:27:36 +03:00
|
|
|
GTree *endpoints;
|
2022-02-14 15:43:54 +03:00
|
|
|
bool boot_bypass;
|
2023-07-05 19:51:17 +03:00
|
|
|
Notifier machine_done;
|
|
|
|
bool granule_frozen;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2020-02-14 16:27:36 +03:00
|
|
|
|
|
|
|
#endif
|