AMD IOMMU
v7 cover AMD IOMMU
Hello there,
This series adds AMD IOMMU emulation support to Qemu.
The only main change since V6 is:
-Fixed a cache bug that caused the issue reported by Jan
I have assummed that we are running one IOMMU and users don't have the freedom to run many IOMMUs. For instance, I've decided to stick with 'pci_create_simple' since if I change this and manually create the the device inorder to set the addr, I'll be repeating exactly what 'pci_create_simple' does while there is no immediate benefit. Being able to run multiple IOMMUs is a plus but at the moment I experience a few problems with the code while there is no immediate benefit.
Other than these patches there's also an planned GSoC project to add features to feature-limited AMD IO MMU listed here[1]. It could also look at the the possibility of running multiple IOMMUs. GSoC is a program that offers students stipends to work on open source projects. You can read more about GSoC here[2]. Am a student and am willing to take up this IO MMU related project but I've not got a full mentor. Yeah, you're right, there are mentors listed on the project's details but they would only want to co-mentor as they may not have much time. They were listed there mainly for purposes of listing the project. I'd like to know if anyone is willing to mentor this project mainly the people involved in the review process or anyone else!
David Kiarie (4):
hw/i386: Introduce AMD IOMMU
hw/i386: ACPI table for AMD IOMMU
hw/core: Add AMD IOMMU to machine properties
hw/pci-host: Emulate AMD IOMMU
hw/core/machine.c | 27 +- hw/i386/Makefile.objs | 1 + hw/i386/acpi-build.c | 98 ++- hw/i386/amd_iommu.c | 1431 +++++++++++++++++++++++++++++++++++++++++ hw/i386/amd_iommu.h | 398 ++++++++++++ hw/pci-host/q35.c | 21 +- include/hw/acpi/acpi-defs.h | 55 ++ include/hw/boards.h | 1 + include/hw/i386/intel_iommu.h | 2 + include/hw/pci/pci.h | 2 + qemu-options.hx | 7 +- util/qemu-config.c | 4 +- 12 files changed, 2027 insertions(+), 20 deletions(-) create mode 100644 hw/i386/amd_iommu.c create mode 100644 hw/i386/amd_iommu.h
[1]http://qemu-project.org/Google_Summer_of_Code_2016#Qemu_AMD_IO_MMU_emulation [2]https://summerofcode.withgoogle.com/
Signature · 1 line
2.1.4
PATCH v7 2/4 hw/i386: ACPI table for AMD IOMMU
Add IVRS table for AMD IOMMU. Generate IVRS or DMAR depending on emulated IOMMU
--- hw/i386/acpi-build.c | 98 ++++++++++++++++++++++++++++++++++++++----- include/hw/acpi/acpi-defs.h | 55 ++++++++++++++++++++++++ include/hw/i386/intel_iommu.h | 1 + 3 files changed, 143 insertions(+), 11 deletions(-)
hw/i386/acpi-build.c +87 -11
@@ -51,6 +51,7 @@#include "hw/pci/pci_bus.h" #include "hw/pci-host/q35.h" #include "hw/i386/intel_iommu.h" +#include "hw/i386/amd_iommu.h" #include "hw/timer/hpet.h" #include "hw/acpi/aml-build.h"
@@ -121,6 +122,12 @@ typedef struct AcpiBuildPciBusHotplugState {bool pcihp_bridge_en; } AcpiBuildPciBusHotplugState; +typedef enum iommu_type { +TYPE_AMD , +TYPE_INTEL , +TYPE_NONE +}iommu_type ; +static int acpi_add_cpu_info (Object *o,void *opaque) {
@@ -2542,6 +2549,78 @@ build_dmar_q35(GArray *table_data, GArray *linker) "DMAR", table_data->len - dmar_start, 1, NULL, NULL); } +static void +build_amd_iommu (GArray *table_data,GArray *linker) +{ +int iommu_start = table_data->len; +bool iommu_ambig; + +AcpiAMDIOMMUIVRS *ivrs; +AcpiAMDIOMMUHardwareUnit *iommu; + +/* IVRS definition */ + ivrs =acpi_data_push (table_data,sizeof (*ivrs)); + ivrs->revision =cpu_to_le16 (ACPI_IOMMU_IVRS_TYPE ); + ivrs->length =cpu_to_le16 ((sizeof (*ivrs) +sizeof (*iommu))); + ivrs->v_common_info =cpu_to_le64 (AMD_IOMMU_HOST_ADDRESS_WIDTH <<8 ); + +AMDIOMMUState *s = (AMDIOMMUState *)object_resolve_path_type ("" , +TYPE_AMD_IOMMU_DEVICE , &iommu_ambig); + +/* IVDB definition - type 10h */ + iommu =acpi_data_push (table_data,sizeof (*iommu)); +if (!iommu_ambig) { + iommu->type =cpu_to_le16 (0x10 ); +/* IVHD flags */ + iommu->flags =cpu_to_le16 (iommu->flags); + iommu->flags =cpu_to_le16 (IVHD_HT_TUNEN |IVHD_PPRSUP |IVHD_IOTLBSUP + |IVHD_PREFSUP ); + iommu->length =cpu_to_le16 (sizeof (*iommu)); + iommu->device_id =cpu_to_le16 (PCI_DEVICE_ID_RD890_IOMMU ); + iommu->capability_offset =cpu_to_le16 (s->capab_offset); + iommu->mmio_base =cpu_to_le64 (s->mmio.addr); + iommu->pci_segment =0 ; + iommu->interrupt_info =0 ; +/* EFR features */ + iommu->efr_register =cpu_to_le64 (IVHD_EFR_GTSUP |IVHD_EFR_HATS + |IVHD_EFR_GATS ); + iommu->efr_register =cpu_to_le64 (iommu->efr_register); +/* device entries */ +memset (iommu->dev_entries,0 ,20 ); +/* Add device flags here +* This is are 4-byte device entries currently reporting the range of +* devices 00h - ffffh; all devices +* +* Device setting affecting all devices should be made here +* +* Refer to +* (http://developer.amd.com/wordpress/media/2012/10/488821.pdf) +* 5.2.2.1 +*/ + iommu->dev_entries[12 ] =3 ; + iommu->dev_entries[16 ] =4 ; + iommu->dev_entries[17 ] =0xff ; + iommu->dev_entries[18 ] =0xff ; + } + +build_header (linker, table_data, (void *)(table_data->data + iommu_start), +"IVRS" , table_data->len - iommu_start,1 ,NULL ,NULL ); +} + +static iommu_type has_iommu (void ) +{ +bool ambiguous; + +if (object_resolve_path_type ("" ,TYPE_AMD_IOMMU_DEVICE , &ambiguous) + && !ambiguous) +return TYPE_AMD ; +else if (object_resolve_path_type ("" ,TYPE_INTEL_IOMMU_DEVICE , &ambiguous) + && !ambiguous) +return TYPE_INTEL ; +else +return TYPE_NONE ; +} +static GArray *build_rsdp (GArray *rsdp_table,GArray *linker,unsigned rsdt) {
@@ -2600,16 +2679,6 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)return true; } -static bool acpi_has_iommu (void ) -{ -bool ambiguous; -Object *intel_iommu; - - intel_iommu =object_resolve_path_type ("" ,TYPE_INTEL_IOMMU_DEVICE , - &ambiguous); -return intel_iommu && !ambiguous; -} -static bool acpi_has_nvdimm (void ) {PCMachineState *pcms =PC_MACHINE (qdev_get_machine ());
@@ -2630,6 +2699,7 @@ void acpi_build(AcpiBuildTables *tables)AcpiMcfgInfo mcfg;PcPciInfo pci;uint8_t *u; +iommu_type type =has_iommu ();size_t aml_len =0 ;GArray *tables_blob = tables->table_data;AcpiSlicOem slic_oem = { .id =NULL , .table_id =NULL };
@@ -2696,7 +2766,13 @@ void acpi_build(AcpiBuildTables *tables)acpi_add_table (table_offsets, tables_blob);build_mcfg_q35 (tables_blob, tables->linker, &mcfg); } -if (acpi_has_iommu ()) { + +if (type ==TYPE_AMD ) { +acpi_add_table (table_offsets, tables_blob); +build_amd_iommu (tables_blob, tables->linker); + } + +if (type ==TYPE_INTEL ) {acpi_add_table (table_offsets, tables_blob);build_dmar_q35 (tables_blob, tables->linker); }
include/hw/acpi/acpi-defs.h +55 -0
59 lines not on this page · raw message
include/hw/i386/intel_iommu.h +1 -0
@@ -24,6 +24,7 @@#include "hw/qdev.h" #include "sysemu/dma.h" +#define INTEL_IOMMU_STR "intel"#define TYPE_INTEL_IOMMU_DEVICE "intel-iommu"#define INTEL_IOMMU_DEVICE (obj) \ OBJECT_CHECK(IntelIOMMUState, (obj), TYPE_INTEL_IOMMU_DEVICE)
Signature · 1 line
2.1.4
PATCH v7 3/4 hw/core: Add AMD IOMMU to machine properties
In reply to David KiarieAdd IOMMU as a string to machine properties which is used to control whether and the type of IOMMU to emulate
--- hw/core/machine.c | 27 ++++++++++++++++++++++++--- include/hw/boards.h | 1 + qemu-options.hx | 7 +++++-- util/qemu-config.c | 4 ++-- 4 files changed, 32 insertions(+), 7 deletions(-)
hw/core/machine.c +24 -3
@@ -14,6 +14,8 @@#include "hw/boards.h" #include "qapi-visit.h" #include "qapi/visitor.h" +#include "hw/i386/amd_iommu.h" +#include "hw/i386/intel_iommu.h" #include "hw/sysbus.h" #include "sysemu/sysemu.h" #include "qemu/error-report.h"
@@ -298,6 +300,20 @@ static void machine_set_iommu(Object *obj, bool value, Error **errp) ms->iommu = value; } +static bool machine_get_amd_iommu_override (Object *obj,Error **errp) +{ +MachineState *ms =MACHINE (obj); + +return ms->amd_iommu_type; +} + +static void machine_set_amd_iommu_override (Object *obj,bool value,Error **errp) +{ +MachineState *ms =MACHINE (obj); + + ms->amd_iommu_type = value; +} +static void machine_set_suppress_vmdesc (Object *obj,bool value,Error **errp) {MachineState *ms =MACHINE (obj);
@@ -471,10 +487,15 @@ static void machine_initfn(Object *obj)"Firmware image" , NULL);object_property_add_bool (obj,"iommu" , - machine_get_iommu, - machine_set_iommu,NULL ); + machine_get_iommu, machine_set_iommu,NULL );object_property_set_description (obj,"iommu" , -"Set on/off to enable/disable Intel IOMMU (VT-d)" , +"Set on to enable IOMMU emulation" , +NULL ); +object_property_add_bool (obj,"amd-iommu" , + machine_get_amd_iommu_override, + machine_set_amd_iommu_override,NULL ); +object_property_set_description (obj,"amd-iommu" , +"Set on to override emulated IOMMU to AMD IOMMU" ,NULL ); object_property_add_bool(obj, "suppress-vmdesc", machine_get_suppress_vmdesc,
include/hw/boards.h +1 -0
@@ -126,6 +126,7 @@ struct MachineState {bool igd_gfx_passthru;char *firmware;bool iommu; +bool amd_iommu_type;bool suppress_vmdesc;bool enforce_config_section;
qemu-options.hx +5 -2
@@ -38,7 +38,8 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " kvm_shadow_mem=size of KVM shadow MMU\n" " dump-guest-core=on|off include guest memory in a core dump (default=on)\n" " mem-merge=on|off controls memory merge support (default: on)\n" - " iommu=on|off controls emulated Intel IOMMU (VT-d) support (default=off)\n" + " iommu=on|off controls emulated IOMMU support(default: off)\n" + " amd-iommu=on|off overrides emulated IOMMU to AMD IOMMU (default: off)\n" " igd-passthru=on|off controls IGD GFX passthrough support (default=off)\n" " aes-key-wrap=on|off controls support for AES key wrapping (default=on)\n" " dea-key-wrap=on|off controls support for DEA key wrapping (default=on)\n"
@@ -74,7 +75,9 @@ Enables or disables memory merge support. This feature, when supported by the host, de-duplicates identical memory pages among VMs instances (enabled by default). @item iommu=on|off -Enables or disables emulated Intel IOMMU (VT-d) support. The default is off. +Enables and disables IOMMU emulation. The default is off. +@item amd-iommu=on|off +Overrides emulated IOMMU from AMD IOMMU. By default Intel IOMMU is emulated. @item aes-key-wrap=on|off Enables or disables AES key wrapping support on s390-ccw hosts. This feature controls whether AES wrapping keys will be created to allow
util/qemu-config.c +2 -2
@@ -213,8 +213,8 @@ static QemuOptsList machine_opts = { .help = "firmware image", },{ .name = "iommu", - .type = QEMU_OPT_BOOL, - .help = "Set on/off to enable/disable Intel IOMMU (VT-d)", + .type = QEMU_OPT_STRING, + .help = "Enables IOMMU and sets the emulated type", },{ .name = "suppress-vmdesc", .type = QEMU_OPT_BOOL,
Signature · 1 line
2.1.4
PATCH v7 1/4 hw/i386: Introduce AMD IOMMU
In reply to David KiarieAdd AMD IOMMU emulaton to Qemu in addition to Intel IOMMU The IOMMU does basic translation, error checking and has a mininal IOTLB implementation
--- hw/i386/Makefile.objs | 1 + hw/i386/amd_iommu.c | 1431 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/amd_iommu.h | 398 ++++++++++++++ include/hw/pci/pci.h | 2 + 4 files changed, 1832 insertions(+) create mode 100644 hw/i386/amd_iommu.c create mode 100644 hw/i386/amd_iommu.h
hw/i386/Makefile.objs +1 -0
@@ -3,6 +3,7 @@ obj-y += multiboot.o obj-y += pc.o pc_piix.o pc_q35.o obj-y += pc_sysfw.o obj-y += intel_iommu.o +obj-y += amd_iommu.o obj-$(CONFIG_XEN) += ../xenpv/ xen/ obj-y += kvmvapic.o
hw/i386/amd_iommu.c new file +1431 -0
1,431 lines not on this page · raw message
hw/i386/amd_iommu.h new file +398 -0
398 lines not on this page · raw message
include/hw/pci/pci.h +2 -0
@@ -14,6 +14,8 @@/* PCI bus */ +#define PCI_BUS_NUM (x) (((x) >> 8) & 0xff) +#define PCI_DEVID (bus, devfn) ((((uint16_t)(bus)) << 8) | (devfn))#define PCI_DEVFN (slot, func) ((((slot) & 0x1f) << 3) | ((func) & 0x07))#define PCI_SLOT (devfn) (((devfn) >> 3) & 0x1f)#define PCI_FUNC (devfn) ((devfn) & 0x07)
Signature · 1 line
2.1.4
PATCH v7 4/4 hw/pci-host: Emulate AMD IOMMU
In reply to David KiarieAdd AMD IOMMU emulation support to q35 chipset
--- hw/pci-host/q35.c | 21 +++++++++++++++++++-- include/hw/i386/intel_iommu.h | 1 + 2 files changed, 20 insertions(+), 2 deletions(-)
hw/pci-host/q35.c +19 -2
@@ -31,6 +31,7 @@#include "hw/hw.h" #include "hw/pci-host/q35.h" #include "qapi/visitor.h" +#include "hw/i386/amd_iommu.h" /**************************************************************************** * Q35 host
@@ -447,6 +448,19 @@ static void mch_init_dmar(MCHPCIState *mch)pci_setup_iommu (pci_bus, q35_host_dma_iommu, mch->iommu); } +static void mch_init_amdvi (MCHPCIState *mch) +{ +AMDIOMMUState *iommu_state; +PCIBus *bus =PCI_BUS (qdev_get_parent_bus (DEVICE (mch))); +PCIDevice *iommu; + + iommu =pci_create_simple (bus,0x20 ,TYPE_AMD_IOMMU_DEVICE ); + + iommu_state =AMD_IOMMU_DEVICE (iommu); + +pci_setup_iommu (bus, bridge_host_amd_iommu, iommu_state); +} +static void mch_realize (PCIDevice *d,Error **errp) {int i;
@@ -505,8 +519,11 @@ static void mch_realize(PCIDevice *d, Error **errp) mch->pci_address_space, &mch->pam_regions[i+1 ], PAM_EXPAN_BASE + i * PAM_EXPAN_SIZE, PAM_EXPAN_SIZE); } -/* Intel IOMMU (VT-d) */ -if (object_property_get_bool (qdev_get_machine (),"iommu" ,NULL )) { + +if (object_property_get_bool (qdev_get_machine (),"iommu" ,NULL ) && +object_property_get_bool (qdev_get_machine (),"amd-iommu" ,NULL )) { +mch_init_amdvi (mch); + }else if (object_property_get_bool (qdev_get_machine (),"iommu" ,NULL )) {mch_init_dmar (mch); } }
include/hw/i386/intel_iommu.h +1 -0
@@ -28,6 +28,7 @@#define TYPE_INTEL_IOMMU_DEVICE "intel-iommu"#define INTEL_IOMMU_DEVICE (obj) \ OBJECT_CHECK(IntelIOMMUState, (obj), TYPE_INTEL_IOMMU_DEVICE) +#define INTEL_IOMMU_STR "intel"/* DMAR Hardware Unit Definition address (IOMMU unit) */ #define Q35_HOST_BRIDGE_IOMMU_ADDR 0xfed90000ULL
Signature · 1 line
2.1.4
Re: [Qemu-devel] [V7 3/4] hw/core: Add AMD IOMMU to machine properties
In reply to David KiarieQuoted 81 lines · David Kiarie
Add IOMMU as a string to machine properties which is used to control whether and the type of IOMMU to emulate
Signed-off-by David Kiarie <[email protected]>--- hw/core/machine.c | 27 ++++++++++++++++++++++++--- include/hw/boards.h | 1 + qemu-options.hx | 7 +++++-- util/qemu-config.c | 4 ++-- 4 files changed, 32 insertions(+), 7 deletions(-)hw/core/machine.c +24
-3@@ -14,6 +14,8 @@#include "hw/boards.h" #include "qapi-visit.h" #include "qapi/visitor.h" +#include "hw/i386/amd_iommu.h" +#include "hw/i386/intel_iommu.h" #include "hw/sysbus.h" #include "sysemu/sysemu.h" #include "qemu/error-report.h" @@ -298,6 +300,20 @@ static void machine_set_iommu(Object *obj, bool value, Error **errp) ms->iommu = value; } +static bool machine_get_amd_iommu_override (Object *obj,Error **errp) +{ +MachineState *ms =MACHINE (obj); + +return ms->amd_iommu_type; +} + +static void machine_set_amd_iommu_override (Object *obj,bool value,Error **errp) +{ +MachineState *ms =MACHINE (obj); + + ms->amd_iommu_type = value; +} +static void machine_set_suppress_vmdesc (Object *obj,bool value,Error **errp) {MachineState *ms =MACHINE (obj);@@ -471,10 +487,15 @@ static void machine_initfn(Object *obj)"Firmware image" , NULL);object_property_add_bool (obj,"iommu" , - machine_get_iommu, - machine_set_iommu,NULL ); + machine_get_iommu, machine_set_iommu,NULL );object_property_set_description (obj,"iommu" , -"Set on/off to enable/disable Intel IOMMU (VT-d)" , +"Set on to enable IOMMU emulation" , +NULL ); +object_property_add_bool (obj,"amd-iommu" , + machine_get_amd_iommu_override, + machine_set_amd_iommu_override,NULL ); +object_property_set_description (obj,"amd-iommu" , +"Set on to override emulated IOMMU to AMD IOMMU" ,NULL ); object_property_add_bool(obj, "suppress-vmdesc", machine_get_suppress_vmdesc,include/hw/boards.h +1
-0@@ -126,6 +126,7 @@ struct MachineState {bool igd_gfx_passthru;char *firmware;bool iommu; +bool amd_iommu_type;bool suppress_vmdesc;bool enforce_config_section;qemu-options.hx +0
-0
qemu-options.hx DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ · line 42
Quoted 6 lines
qemu-options.hx +2
-1@@ -38,7 +38,8 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " kvm_shadow_mem=size of KVM shadow MMU\n" " dump-guest-core=on|off include guest memory in a core dump (default=on)\n" " mem-merge=on|off controls memory merge support (default: on)\n" - " iommu=on|off controls emulated Intel IOMMU (VT-d) support (default=off)\n" + " iommu=on|off controls emulated IOMMU support(default: off)\n" + " amd-iommu=on|off overrides emulated IOMMU to AMD IOMMU (default: off)\n"
Hi David,
I think this is a step backward from the last series (in my opinion). Summarizing what Jan and Michael said, it should be:
iommu=on|off controls emulated IOMMU support(default: off) x-iommu-type=intel|amd controls the IOMMU emulation type(default: intel)
In this way:
-machine iommu=on => it works like before
-machine iommu=on,x-iommu-type=intel => ask for intel emulation -machine iommu=off,x-iommu-type=amd => ask for amd emulation
The "x-" prefix I suppose is for "tech preview" property, right Michael?
Of course -device iommu,type="intel|amd" would be preferred, but I understand is not in the scope of this series.
Thanks,
Marcel
Quoted 30 lines
qemu-options.hx +3
-1" igd-passthru=on|off controls IGD GFX passthrough support (default=off)\n" " aes-key-wrap=on|off controls support for AES key wrapping (default=on)\n" " dea-key-wrap=on|off controls support for DEA key wrapping (default=on)\n"@@ -74,7 +75,9 @@ Enables or disables memory merge support. This feature, when supported by the host, de-duplicates identical memory pages among VMs instances (enabled by default). @item iommu=on|off -Enables or disables emulated Intel IOMMU (VT-d) support. The default is off. +Enables and disables IOMMU emulation. The default is off. +@item amd-iommu=on|off +Overrides emulated IOMMU from AMD IOMMU. By default Intel IOMMU is emulated. @item aes-key-wrap=on|off Enables or disables AES key wrapping support on s390-ccw hosts. This feature controls whether AES wrapping keys will be created to allowutil/qemu-config.c +2
-2@@ -213,8 +213,8 @@ static QemuOptsList machine_opts = { .help = "firmware image", },{ .name = "iommu", - .type = QEMU_OPT_BOOL, - .help = "Set on/off to enable/disable Intel IOMMU (VT-d)", + .type = QEMU_OPT_STRING, + .help = "Enables IOMMU and sets the emulated type", },{ .name = "suppress-vmdesc", .type = QEMU_OPT_BOOL,
Re: [Qemu-devel] [V7 2/4] hw/i386: ACPI table for AMD IOMMU
In reply to David KiarieQuoted 7 lines · David Kiarie
Add IVRS table for AMD IOMMU. Generate IVRS or DMAR depending on emulated IOMMU
Signed-off-by David Kiarie <[email protected]>--- hw/i386/acpi-build.c | 98 ++++++++++++++++++++++++++++++++++++++----- include/hw/acpi/acpi-defs.h | 55 ++++++++++++++++++++++++
Added Igor to CC, maybe he can have a look to the ACPI code.
Thanks,
Marcel
Quoted 224 lines
include/hw/i386/intel_iommu.h | 1 + 3 files changed, 143 insertions(+), 11 deletions(-)hw/i386/acpi-build.c +87
-11@@ -51,6 +51,7 @@#include "hw/pci/pci_bus.h" #include "hw/pci-host/q35.h" #include "hw/i386/intel_iommu.h" +#include "hw/i386/amd_iommu.h" #include "hw/timer/hpet.h" #include "hw/acpi/aml-build.h" @@ -121,6 +122,12 @@ typedef struct AcpiBuildPciBusHotplugState {bool pcihp_bridge_en; } AcpiBuildPciBusHotplugState; +typedef enum iommu_type { +TYPE_AMD , +TYPE_INTEL , +TYPE_NONE +}iommu_type ; +static int acpi_add_cpu_info (Object *o,void *opaque) {@@ -2542,6 +2549,78 @@ build_dmar_q35(GArray *table_data, GArray *linker) "DMAR", table_data->len - dmar_start, 1, NULL, NULL); } +static void +build_amd_iommu (GArray *table_data,GArray *linker) +{ +int iommu_start = table_data->len; +bool iommu_ambig; + +AcpiAMDIOMMUIVRS *ivrs; +AcpiAMDIOMMUHardwareUnit *iommu; + +/* IVRS definition */ + ivrs =acpi_data_push (table_data,sizeof (*ivrs)); + ivrs->revision =cpu_to_le16 (ACPI_IOMMU_IVRS_TYPE ); + ivrs->length =cpu_to_le16 ((sizeof (*ivrs) +sizeof (*iommu))); + ivrs->v_common_info =cpu_to_le64 (AMD_IOMMU_HOST_ADDRESS_WIDTH <<8 ); + +AMDIOMMUState *s = (AMDIOMMUState *)object_resolve_path_type ("" , +TYPE_AMD_IOMMU_DEVICE , &iommu_ambig); + +/* IVDB definition - type 10h */ + iommu =acpi_data_push (table_data,sizeof (*iommu)); +if (!iommu_ambig) { + iommu->type =cpu_to_le16 (0x10 ); +/* IVHD flags */ + iommu->flags =cpu_to_le16 (iommu->flags); + iommu->flags =cpu_to_le16 (IVHD_HT_TUNEN |IVHD_PPRSUP |IVHD_IOTLBSUP + |IVHD_PREFSUP ); + iommu->length =cpu_to_le16 (sizeof (*iommu)); + iommu->device_id =cpu_to_le16 (PCI_DEVICE_ID_RD890_IOMMU ); + iommu->capability_offset =cpu_to_le16 (s->capab_offset); + iommu->mmio_base =cpu_to_le64 (s->mmio.addr); + iommu->pci_segment =0 ; + iommu->interrupt_info =0 ; +/* EFR features */ + iommu->efr_register =cpu_to_le64 (IVHD_EFR_GTSUP |IVHD_EFR_HATS + |IVHD_EFR_GATS ); + iommu->efr_register =cpu_to_le64 (iommu->efr_register); +/* device entries */ +memset (iommu->dev_entries,0 ,20 ); +/* Add device flags here +* This is are 4-byte device entries currently reporting the range of +* devices 00h - ffffh; all devices +* +* Device setting affecting all devices should be made here +* +* Refer to +* (http://developer.amd.com/wordpress/media/2012/10/488821.pdf) +* 5.2.2.1 +*/ + iommu->dev_entries[12 ] =3 ; + iommu->dev_entries[16 ] =4 ; + iommu->dev_entries[17 ] =0xff ; + iommu->dev_entries[18 ] =0xff ; + } + +build_header (linker, table_data, (void *)(table_data->data + iommu_start), +"IVRS" , table_data->len - iommu_start,1 ,NULL ,NULL ); +} + +static iommu_type has_iommu (void ) +{ +bool ambiguous; + +if (object_resolve_path_type ("" ,TYPE_AMD_IOMMU_DEVICE , &ambiguous) + && !ambiguous) +return TYPE_AMD ; +else if (object_resolve_path_type ("" ,TYPE_INTEL_IOMMU_DEVICE , &ambiguous) + && !ambiguous) +return TYPE_INTEL ; +else +return TYPE_NONE ; +} +static GArray *build_rsdp (GArray *rsdp_table,GArray *linker,unsigned rsdt) {@@ -2600,16 +2679,6 @@ static bool acpi_get_mcfg(AcpiMcfgInfo *mcfg)return true; } -static bool acpi_has_iommu (void ) -{ -bool ambiguous; -Object *intel_iommu; - - intel_iommu =object_resolve_path_type ("" ,TYPE_INTEL_IOMMU_DEVICE , - &ambiguous); -return intel_iommu && !ambiguous; -} -static bool acpi_has_nvdimm (void ) {PCMachineState *pcms =PC_MACHINE (qdev_get_machine ());@@ -2630,6 +2699,7 @@ void acpi_build(AcpiBuildTables *tables)AcpiMcfgInfo mcfg;PcPciInfo pci;uint8_t *u; +iommu_type type =has_iommu ();size_t aml_len =0 ;GArray *tables_blob = tables->table_data;AcpiSlicOem slic_oem = { .id =NULL , .table_id =NULL };@@ -2696,7 +2766,13 @@ void acpi_build(AcpiBuildTables *tables)acpi_add_table (table_offsets, tables_blob);build_mcfg_q35 (tables_blob, tables->linker, &mcfg); } -if (acpi_has_iommu ()) { + +if (type ==TYPE_AMD ) { +acpi_add_table (table_offsets, tables_blob); +build_amd_iommu (tables_blob, tables->linker); + } + +if (type ==TYPE_INTEL ) {acpi_add_table (table_offsets, tables_blob);build_dmar_q35 (tables_blob, tables->linker); }include/hw/acpi/acpi-defs.h +55
-0@@ -570,4 +570,59 @@ typedef struct AcpiDmarHardwareUnit AcpiDmarHardwareUnit;/* Masks for Flags field above */ #define ACPI_DMAR_INCLUDE_PCI_ALL 1 +/* IVRS constants */ +#define ACPI_IOMMU_HARDWAREUNIT_TYPE 0x10 +#define ACPI_IOMMU_IVRS_TYPE 0x1 +#define AMD_IOMMU_HOST_ADDRESS_WIDTH 39UL + +/* AMD IOMMU IVRS table */ +struct AcpiAMDIOMMUIVRS { +ACPI_TABLE_HEADER_DEF + uint32_t v_common_info; /* common virtualization information */ +uint64_t reserved;/* reserved */ +}QEMU_PACKED ; +typedef struct AcpiAMDIOMMUIVRS AcpiAMDIOMMUIVRS ; + +/* flags in the IVHD headers */ +#define IVHD_HT_TUNEN (1UL << 0) +#define IVHD_PASS_PW (1UL << 1) +#define IVHD_RESPASS_PW (1UL << 2) +#define IVHD_ISOC (1UL << 3) +#define IVHD_IOTLBSUP (1UL << 4) +#define IVHD_COHERENT (1UL << 5) +#define IVHD_PREFSUP (1UL << 6) +#define IVHD_PPRSUP (1UL << 7) + +/* features in the IVHD headers */ +#define IVHD_EFR_HATS 48 +#define IVHD_EFR_GATS 48 +#define IVHD_EFR_MSI_NUM +#define IVHD_EFR_PNBANKS +#define IVHD_EFR_PNCOUNTERS +#define IVHD_EFR_PASMAX +#define IVHD_EFR_HESUP (1UL << 7) +#define IVHD_EFR_GASUP (1UL << 6) +#define IVHD_EFR_IASUP (1UL << 5) +#define IVHD_EFR_GLXSUP (3UL << 3) +#define IVHD_EFR_GTSUP (1UL << 2) +#define IVHD_EFR_NXSUP (1UL << 1) +#define IVHD_EFR_XTSUP (1UL << 0) + +/* IVDB type 10h */ +struct AcpiAMDIOMMUHardwareUnit { +uint8_t type; +uint8_t flags; +uint16_t length; +uint16_t device_id; +uint16_t capability_offset; +uint64_t mmio_base; +uint16_t pci_segment; +uint16_t interrupt_info; +uint32_t features; +uint64_t efr_register; +uint64_t reserved; +uint8_t dev_entries[20 ]; +}QEMU_PACKED ; +typedef struct AcpiAMDIOMMUHardwareUnit AcpiAMDIOMMUHardwareUnit ; +#endif include/hw/i386/intel_iommu.h +1
-0@@ -24,6 +24,7 @@#include "hw/qdev.h" #include "sysemu/dma.h" +#define INTEL_IOMMU_STR "intel"#define TYPE_INTEL_IOMMU_DEVICE "intel-iommu"#define INTEL_IOMMU_DEVICE (obj) \ OBJECT_CHECK(IntelIOMMUState, (obj), TYPE_INTEL_IOMMU_DEVICE)
Re: [Qemu-devel] [V7 3/4] hw/core: Add AMD IOMMU to machine properties
In reply to Marcel ApfelbaumQuoted 113 lines · Marcel Apfelbaum
Quoted 90 lines · David Kiarie
Add IOMMU as a string to machine properties which is used to control whether and the type of IOMMU to emulate
Signed-off-by David Kiarie <[email protected]>--- hw/core/machine.c | 27 ++++++++++++++++++++++++--- include/hw/boards.h | 1 + qemu-options.hx | 7 +++++-- util/qemu-config.c | 4 ++-- 4 files changed, 32 insertions(+), 7 deletions(-)hw/core/machine.c +16
-0@@ -14,6 +14,8 @@#include "hw/boards.h" #include "qapi-visit.h" #include "qapi/visitor.h" +#include "hw/i386/amd_iommu.h" +#include "hw/i386/intel_iommu.h" #include "hw/sysbus.h" #include "sysemu/sysemu.h" #include "qemu/error-report.h" @@ -298,6 +300,20 @@ static void machine_set_iommu(Object *obj, bool value, Error **errp) ms->iommu = value; } +static bool machine_get_amd_iommu_override (Object *obj,Error **errp) +{ +MachineState *ms =MACHINE (obj); + +return ms->amd_iommu_type; +} + +static void machine_set_amd_iommu_override (Object *obj,bool value,Error **errp) +{ +MachineState *ms =MACHINE (obj); + + ms->amd_iommu_type = value; +} + static void machine_set_suppress_vmdesc(Object *obj, bool value, Error**errp)
{ MachineState *ms = MACHINE(obj);hw/core/machine.c +8
-3@@ -471,10 +487,15 @@ static void machine_initfn(Object *obj)"Firmware image" , NULL);object_property_add_bool (obj,"iommu" , - machine_get_iommu, - machine_set_iommu,NULL ); + machine_get_iommu, machine_set_iommu,NULL );object_property_set_description (obj,"iommu" , - "Set on/off to enable/disable Intel IOMMU (VT-d)", +"Set on to enable IOMMU emulation" , +NULL ); +object_property_add_bool (obj,"amd-iommu" , + machine_get_amd_iommu_override, + machine_set_amd_iommu_override,NULL ); +object_property_set_description (obj,"amd-iommu" , + "Set on to override emulated IOMMU to AMD IOMMU",NULL );object_property_add_bool(obj, "suppress-vmdesc",
machine_get_suppress_vmdesc,include/hw/boards.h +1
-0@@ -126,6 +126,7 @@ struct MachineState {bool igd_gfx_passthru;char *firmware;bool iommu; +bool amd_iommu_type;bool suppress_vmdesc;bool enforce_config_section;qemu-options.hx +0
-0@@ -38,7 +38,8 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " kvm_shadow_mem=size of KVM shadow MMU\n" " dump-guest-core=on|off include guest memory in acore dump (default=on)\n"
Quoted 8 lines
" mem-merge=on|off controls memory merge support
(default: on)\n"
- " iommu=on|off controls emulated Intel IOMMU (VT-d)
support (default=off)\n"
+ " iommu=on|off controls emulated IOMMU
support(default: off)\n"
+ " amd-iommu=on|off overrides emulated IOMMU to AMD
IOMMU (default: off)\n"Hi David,
I think this is a step backward from the last series (in my opinion). Summarizing what Jan and Michael said, it should be:
iommu=on|off controls emulated IOMMU support(default: off) x-iommu-type=intel|amd controls the IOMMU emulation type(default: intel)In this way:
-machine iommu=on => it works like before
-machine iommu=on,x-iommu-type=intel => ask for intel emulation -machine iommu=off,x-iommu-type=amd => ask for amd emulation
Quoted 4 lines
The "x-" prefix I suppose is for "tech preview" property, right Michael?
Of course -device iommu,type="intel|amd" would be preferred, but I understand
I thought the idea was to get rid of the "ugly" option parsing which will remain if I have it as above...
Quoted 48 lines
is not in the scope of this series.
Thanks,
MarcelQuoted 37 lines
" igd-passthru=on|off controls IGD GFX passthrough
support (default=off)\n"
" aes-key-wrap=on|off controls support for AES key
wrapping (default=on)\n"
" dea-key-wrap=on|off controls support for DEA key
wrapping (default=on)\n"qemu-options.hx +0
-0@@ -74,7 +75,9 @@ Enables or disables memory merge support. This feature,when supported by
the host, de-duplicates identical memory pages among VMs instances (enabled by default).
@item iommu=on|off
-Enables or disables emulated Intel IOMMU (VT-d) support. The default is off.qemu-options.hx +3
-0+Enables and disables IOMMU emulation. The default is off. +@item amd-iommu=on|off +Overrides emulated IOMMU from AMD IOMMU. By default Intel IOMMU isemulated.
@item aes-key-wrap=on|off
Enables or disables AES key wrapping support on s390-ccw hosts. This
feature
controls whether AES wrapping keys will be created to allowutil/qemu-config.c +2
-2@@ -213,8 +213,8 @@ static QemuOptsList machine_opts = { .help = "firmware image", },{ .name = "iommu", - .type = QEMU_OPT_BOOL, - .help = "Set on/off to enable/disable Intel IOMMU (VT-d)", + .type = QEMU_OPT_STRING, + .help = "Enables IOMMU and sets the emulated type", },{ .name = "suppress-vmdesc", .type = QEMU_OPT_BOOL,
Re: [Qemu-devel] [V7 3/4] hw/core: Add AMD IOMMU to machine properties
Quoted 114 lines · David Kiarie
Quoted 113 lines · Marcel Apfelbaum
Quoted 90 lines · David Kiarie
Add IOMMU as a string to machine properties which is used to control whether and the type of IOMMU to emulate
Signed-off-by David Kiarie <[email protected]>--- hw/core/machine.c | 27 ++++++++++++++++++++++++--- include/hw/boards.h | 1 + qemu-options.hx | 7 +++++-- util/qemu-config.c | 4 ++-- 4 files changed, 32 insertions(+), 7 deletions(-)hw/core/machine.c +16
-0@@ -14,6 +14,8 @@#include "hw/boards.h" #include "qapi-visit.h" #include "qapi/visitor.h" +#include "hw/i386/amd_iommu.h" +#include "hw/i386/intel_iommu.h" #include "hw/sysbus.h" #include "sysemu/sysemu.h" #include "qemu/error-report.h" @@ -298,6 +300,20 @@ static void machine_set_iommu(Object *obj, bool value, Error **errp) ms->iommu = value; } +static bool machine_get_amd_iommu_override (Object *obj,Error **errp) +{ +MachineState *ms =MACHINE (obj); + +return ms->amd_iommu_type; +} + +static void machine_set_amd_iommu_override (Object *obj,bool value,Error **errp) +{ +MachineState *ms =MACHINE (obj); + + ms->amd_iommu_type = value; +} + static void machine_set_suppress_vmdesc(Object *obj, bool value, Error**errp)
{ MachineState *ms = MACHINE(obj);hw/core/machine.c +8
-3@@ -471,10 +487,15 @@ static void machine_initfn(Object *obj)"Firmware image" , NULL);object_property_add_bool (obj,"iommu" , - machine_get_iommu, - machine_set_iommu,NULL ); + machine_get_iommu, machine_set_iommu,NULL );object_property_set_description (obj,"iommu" , - "Set on/off to enable/disable Intel IOMMU (VT-d)", +"Set on to enable IOMMU emulation" , +NULL ); +object_property_add_bool (obj,"amd-iommu" , + machine_get_amd_iommu_override, + machine_set_amd_iommu_override,NULL ); +object_property_set_description (obj,"amd-iommu" , + "Set on to override emulated IOMMU to AMD IOMMU",NULL );object_property_add_bool(obj, "suppress-vmdesc",
machine_get_suppress_vmdesc,include/hw/boards.h +1
-0@@ -126,6 +126,7 @@ struct MachineState {bool igd_gfx_passthru;char *firmware;bool iommu; +bool amd_iommu_type;bool suppress_vmdesc;bool enforce_config_section;qemu-options.hx +0
-0@@ -38,7 +38,8 @@ DEF("machine", HAS_ARG, QEMU_OPTION_machine, \ " kvm_shadow_mem=size of KVM shadow MMU\n" " dump-guest-core=on|off include guest memory in acore dump (default=on)\n"
Quoted 8 lines
" mem-merge=on|off controls memory merge support
(default: on)\n"
- " iommu=on|off controls emulated Intel IOMMU (VT-d)
support (default=off)\n"
+ " iommu=on|off controls emulated IOMMU
support(default: off)\n"
+ " amd-iommu=on|off overrides emulated IOMMU to AMD
IOMMU (default: off)\n"Hi David,
I think this is a step backward from the last series (in my opinion). Summarizing what Jan and Michael said, it should be:
iommu=on|off controls emulated IOMMU support(default: off) x-iommu-type=intel|amd controls the IOMMU emulation type(default: intel)In this way:
-machine iommu=on => it works like before
-machine iommu=on,x-iommu-type=intel => ask for intel emulation -machine iommu=off,x-iommu-type=amd => ask for amd emulation
Quoted 8 lines
Quoted 4 lines
The "x-" prefix I suppose is for "tech preview" property, right Michael?
Of course -device iommu,type="intel|amd" would be preferred, but I understand
I thought the idea was to get rid of the "ugly" option parsing which will remain if I have it as above...
Hi,
Well, we can limit the parsing to one place, when the option is set in machine.
Let's say the machine has a string property "x-iommu-type" (with only "set" property implemented, no "get")
object_property_add_str(obj, "x-iommu-type",
NULL, machine_set_iommu_type, NULL);You can parse and validate the type *only inside* machine_set_iommu_type and use an enum as a machine field. The "intel"/"amd" strings and parsing would be isolated to machine.c file which is reasonable.
You defined already the enum in patch 2/4: "iommu_type". Maybe you can rename it to MachineIommuType or something and add it to include/hw/boards.h.
From this point forward you can use only the enum value in code.
Thanks,
Marcel
Quoted 48 lines
Quoted 48 lines
is not in the scope of this series.
Thanks,
MarcelQuoted 37 lines
" igd-passthru=on|off controls IGD GFX passthrough
support (default=off)\n"
" aes-key-wrap=on|off controls support for AES key
wrapping (default=on)\n"
" dea-key-wrap=on|off controls support for DEA key
wrapping (default=on)\n"qemu-options.hx +0
-0@@ -74,7 +75,9 @@ Enables or disables memory merge support. This feature,when supported by
the host, de-duplicates identical memory pages among VMs instances (enabled by default).
@item iommu=on|off
-Enables or disables emulated Intel IOMMU (VT-d) support. The default is off.qemu-options.hx +3
-0+Enables and disables IOMMU emulation. The default is off. +@item amd-iommu=on|off +Overrides emulated IOMMU from AMD IOMMU. By default Intel IOMMU isemulated.
@item aes-key-wrap=on|off
Enables or disables AES key wrapping support on s390-ccw hosts. This
feature
controls whether AES wrapping keys will be created to allowutil/qemu-config.c +2
-2@@ -213,8 +213,8 @@ static QemuOptsList machine_opts = { .help = "firmware image", },{ .name = "iommu", - .type = QEMU_OPT_BOOL, - .help = "Set on/off to enable/disable Intel IOMMU (VT-d)", + .type = QEMU_OPT_STRING, + .help = "Enables IOMMU and sets the emulated type", },{ .name = "suppress-vmdesc", .type = QEMU_OPT_BOOL,