[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC 14/20] hw/vfio/common: Introduce vfio_alloc_guest_iomm
From: |
Eric Auger |
Subject: |
[Qemu-devel] [RFC 14/20] hw/vfio/common: Introduce vfio_alloc_guest_iommu helper |
Date: |
Sat, 1 Sep 2018 16:23:06 +0200 |
Soon this code will be called several times. So let's introduce
an helper.
Signed-off-by: Eric Auger <address@hidden>
---
hw/vfio/common.c | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index 7bd3cc250d..2342bccf38 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -24,6 +24,7 @@
#include <linux/kvm.h>
#endif
#include <linux/vfio.h>
+#include <linux/iommu.h>
#include "hw/vfio/vfio-common.h"
#include "hw/vfio/vfio.h"
@@ -401,6 +402,19 @@ out:
rcu_read_unlock();
}
+static VFIOGuestIOMMU *vfio_alloc_guest_iommu(VFIOContainer *container,
+ IOMMUMemoryRegion *iommu,
+ hwaddr offset)
+{
+ VFIOGuestIOMMU *giommu = g_new0(VFIOGuestIOMMU, 1);
+
+ giommu->container = container;
+ giommu->iommu = iommu;
+ giommu->iommu_offset = offset;
+ /* notifier will be registered separately */
+ return giommu;
+}
+
static void vfio_listener_region_add(MemoryListener *listener,
MemoryRegionSection *section)
{
@@ -508,6 +522,7 @@ static void vfio_listener_region_add(MemoryListener
*listener,
if (memory_region_is_iommu(section->mr)) {
VFIOGuestIOMMU *giommu;
IOMMUMemoryRegion *iommu_mr = IOMMU_MEMORY_REGION(section->mr);
+ hwaddr offset;
int iommu_idx;
trace_vfio_listener_region_add_iommu(iova, end);
@@ -517,11 +532,11 @@ static void vfio_listener_region_add(MemoryListener
*listener,
* would be the right place to wire that up (tell the KVM
* device emulation the VFIO iommu handles to use).
*/
- giommu = g_malloc0(sizeof(*giommu));
- giommu->iommu = iommu_mr;
- giommu->iommu_offset = section->offset_within_address_space -
- section->offset_within_region;
- giommu->container = container;
+
+ offset = section->offset_within_address_space -
+ section->offset_within_region;
+ giommu = vfio_alloc_guest_iommu(container, iommu_mr, offset);
+
llend = int128_add(int128_make64(section->offset_within_region),
section->size);
llend = int128_sub(llend, int128_one());
--
2.17.1
- [Qemu-devel] [RFC 00/20] vSMMUv3/pSMMUv3 2 stage VFIO integration, Eric Auger, 2018/09/01
- [Qemu-devel] [RFC 20/20] hw/arm/smmuv3: Remove warning about unsupported MAP notifiers, Eric Auger, 2018/09/01
- [Qemu-devel] [RFC 19/20] vfio/pci: Always set up MSI route before enabling vectors, Eric Auger, 2018/09/01
- [Qemu-devel] [RFC 16/20] hw/vfio/common: Register specific nested mode notifiers and memory_listener, Eric Auger, 2018/09/01
- [Qemu-devel] [RFC 18/20] target/arm/kvm: Notifies IOMMU on MSI stage 1 binding, Eric Auger, 2018/09/01
- [Qemu-devel] [RFC 15/20] hw/vfio/common: Introduce vfio_dma_(un)map_ram_section helpers, Eric Auger, 2018/09/01
- [Qemu-devel] [RFC 17/20] hw/vfio/common: Register MAP notifier for MSI binding, Eric Auger, 2018/09/01
- [Qemu-devel] [RFC 14/20] hw/vfio/common: Introduce vfio_alloc_guest_iommu helper,
Eric Auger <=
- [Qemu-devel] [RFC 13/20] hw/arm/smmuv3: Notify on config changes, Eric Auger, 2018/09/01
- [Qemu-devel] [RFC 12/20] hw/arm/smmuv3: Implement dummy replay, Eric Auger, 2018/09/01
- [Qemu-devel] [RFC 10/20] memory: Add IOMMUConfigNotifier, Eric Auger, 2018/09/01
- [Qemu-devel] [RFC 11/20] hw/arm/smmuv3: Store s1ctrptr in translation config data, Eric Auger, 2018/09/01
- [Qemu-devel] [RFC 06/20] hw/vfio/common: Refactor container initialization, Eric Auger, 2018/09/01
- [Qemu-devel] [RFC 09/20] memory: rename memory_region notify_iommu, notify_one, Eric Auger, 2018/09/01
- [Qemu-devel] [RFC 08/20] memory: Introduce IOMMUIOLTBNotifier, Eric Auger, 2018/09/01
- [Qemu-devel] [RFC 07/20] hw/vfio/common: Force nested if iommu requires it, Eric Auger, 2018/09/01
- [Qemu-devel] [RFC 04/20] memory: add IOMMU_ATTR_VFIO_NESTED IOMMU memory region attribute, Eric Auger, 2018/09/01
- [Qemu-devel] [RFC 05/20] hw/arm/smmuv3: Implement get_attr API to report IOMMU_ATTR_VFIO_NESTED, Eric Auger, 2018/09/01