Implement get_viommu_cap() callback and expose stage-1 capability for now. VFIO uses it to create nested parent domain which is further used to create nested domain in vIOMMU. All these will be implemented in following patches.
Suggested-by: Yi Liu <yi.l....@intel.com> Signed-off-by: Zhenzhong Duan <zhenzhong.d...@intel.com> --- MAINTAINERS | 1 + include/hw/iommu.h | 14 ++++++++++++++ hw/i386/intel_iommu.c | 12 ++++++++++++ 3 files changed, 27 insertions(+) create mode 100644 include/hw/iommu.h diff --git a/MAINTAINERS b/MAINTAINERS index 94c4076127..27817974a6 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2277,6 +2277,7 @@ F: include/system/iommufd.h F: backends/host_iommu_device.c F: include/system/host_iommu_device.h F: include/qemu/chardev_open.h +F: include/hw/iommu.h F: util/chardev_open.c F: docs/devel/vfio-iommufd.rst diff --git a/include/hw/iommu.h b/include/hw/iommu.h new file mode 100644 index 0000000000..3c1c08f05d --- /dev/null +++ b/include/hw/iommu.h @@ -0,0 +1,14 @@ +/* + * General vIOMMU capabilities, flags, etc + * + * Copyright (C) 2025 Intel Corporation. + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef HW_IOMMU_H +#define HW_IOMMU_H + +#define VIOMMU_CAP_STAGE1 BIT_ULL(0) + +#endif /* HW_IOMMU_H */ diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index f0b1f90eff..702973da5c 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -24,6 +24,7 @@ #include "qemu/main-loop.h" #include "qapi/error.h" #include "hw/sysbus.h" +#include "hw/iommu.h" #include "intel_iommu_internal.h" #include "hw/pci/pci.h" #include "hw/pci/pci_bus.h" @@ -4412,6 +4413,16 @@ static void vtd_dev_unset_iommu_device(PCIBus *bus, void *opaque, int devfn) vtd_iommu_unlock(s); } +static uint64_t vtd_get_viommu_cap(void *opaque) +{ + IntelIOMMUState *s = opaque; + uint64_t caps; + + caps = s->flts ? VIOMMU_CAP_STAGE1 : 0; + + return caps; +} + /* Unmap the whole range in the notifier's scope. */ static void vtd_address_space_unmap(VTDAddressSpace *as, IOMMUNotifier *n) { @@ -4734,6 +4745,7 @@ static PCIIOMMUOps vtd_iommu_ops = { .get_address_space = vtd_host_dma_iommu, .set_iommu_device = vtd_dev_set_iommu_device, .unset_iommu_device = vtd_dev_unset_iommu_device, + .get_viommu_cap = vtd_get_viommu_cap, }; static bool vtd_decide_config(IntelIOMMUState *s, Error **errp) -- 2.34.1