2020-02-14 14:27:36 +01: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 22:43:22 +02:00
|
|
|
#include "qom/object.h"
|
2020-02-14 14:27:36 +01:00
|
|
|
|
|
|
|
#define TYPE_VIRTIO_IOMMU "virtio-iommu-device"
|
2020-02-14 14:27:43 +01:00
|
|
|
#define TYPE_VIRTIO_IOMMU_PCI "virtio-iommu-device-base"
|
2020-09-16 20:25:19 +02:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(VirtIOIOMMU, VIRTIO_IOMMU)
|
2020-02-14 14:27:36 +01:00
|
|
|
|
2020-02-14 14:27:38 +01:00
|
|
|
#define TYPE_VIRTIO_IOMMU_MEMORY_REGION "virtio-iommu-memory-region"
|
|
|
|
|
2020-02-14 14:27:36 +01:00
|
|
|
typedef struct IOMMUDevice {
|
|
|
|
void *viommu;
|
|
|
|
PCIBus *bus;
|
|
|
|
int devfn;
|
|
|
|
IOMMUMemoryRegion iommu_mr;
|
|
|
|
AddressSpace as;
|
|
|
|
} 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 16:38:15 +01:00
|
|
|
IOMMUDevice *pbdev[]; /* Parent array is sparse, so dynamically alloc */
|
2020-02-14 14:27:36 +01:00
|
|
|
} IOMMUPciBus;
|
|
|
|
|
2020-09-03 22:43:22 +02:00
|
|
|
struct VirtIOIOMMU {
|
2020-02-14 14:27:36 +01: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 14:27:38 +01:00
|
|
|
IOMMUPciBus *iommu_pcibus_by_bus_num[PCI_BUS_MAX];
|
2020-02-14 14:27:36 +01:00
|
|
|
PCIBus *primary_bus;
|
2020-07-03 17:59:42 +02:00
|
|
|
ReservedRegion *reserved_regions;
|
|
|
|
uint32_t nb_reserved_regions;
|
2020-02-14 14:27:36 +01:00
|
|
|
GTree *domains;
|
|
|
|
QemuMutex mutex;
|
|
|
|
GTree *endpoints;
|
2020-09-03 22:43:22 +02:00
|
|
|
};
|
2020-02-14 14:27:36 +01:00
|
|
|
|
|
|
|
#endif
|