AMD IOMMU
v3 cover AMD IOMMU
David Kiarie (4):
hw/core: Add AMD IO MMU to machine properties
hw/i386: ACPI table for AMD IO MMU
hw/pci-host: Emulate AMD IO MMU
hw/core/machine.c | 17 +- hw/i386/Makefile.objs | 1 + hw/i386/acpi-build.c | 96 +++ hw/i386/amd_iommu.c | 1420 +++++++++++++++++++++++++++++++++++++++++++ hw/i386/amd_iommu.h | 399 ++++++++++++ hw/pci-host/piix.c | 11 + hw/pci-host/q35.c | 16 +- include/hw/acpi/acpi-defs.h | 55 ++ include/hw/boards.h | 3 +- include/hw/pci/pci.h | 2 + qemu-options.hx | 6 +- util/qemu-config.c | 4 +- 12 files changed, 2014 insertions(+), 16 deletions(-) create mode 100644 hw/i386/amd_iommu.c create mode 100644 hw/i386/amd_iommu.h
Hello,
This series introduces AMD IO MMU emulation to qemu. It's the third version.
Changes since v2.
-Coding style; fixed all errors reported by scripts/checkpatch.pl as suggested by Micheal -Implemented read/only and write 1/clear registers to IO MMU MMIO
-Cleaned up dead code
-Introduced a switch that controls IO MMU emulation and what type is emulated i.e
q35,iommu=amd|intel
as suggested by Marcel
-Tested with audio device passthrough (ac97 with sound driver alsa) -Reserved memory for IO MMU MMIO via ACPI (I need someone to check this)
I was supposed to implement interrupts related to w1/c registers but I decided to reserve everything to do with interrupts for later
Testing procedure outlined here
http://www.linux-kvm.org/page/How_to_assign_devices_with_VT-d_in_KVM
Signature · 1 line
2.1.4
PATCH v3 2/4 hw/core: Add AMD IO MMU to machine properties
Add IO MMU as a string to machine properties which is used to control whether and they type of IO MMU to emulate
--- hw/core/machine.c | 17 +++++++++-------- include/hw/boards.h | 3 ++- qemu-options.hx | 6 +++--- util/qemu-config.c | 4 ++-- 4 files changed, 16 insertions(+), 14 deletions(-)
hw/core/machine.c +9 -8
@@ -283,18 +283,19 @@ static void machine_set_firmware(Object *obj, const char *value, Error **errp) ms->firmware =g_strdup (value); } -static bool machine_get_iommu (Object *obj,Error **errp) +static char *machine_get_iommu (Object *obj,Error **errp) {MachineState *ms =MACHINE (obj); -return ms->iommu; +return g_strdup (ms->iommu); } -static void machine_set_iommu (Object *obj,bool value,Error **errp) +static void machine_set_iommu (Object *obj,const char *value,Error **errp) {MachineState *ms =MACHINE (obj); - ms->iommu = value; +g_free (ms->iommu); + ms->iommu =g_strdup (value); }static void machine_set_suppress_vmdesc (Object *obj,bool value,Error **errp)
@@ -454,11 +455,10 @@ static void machine_initfn(Object *obj)object_property_set_description (obj,"firmware" ,"Firmware image" ,NULL ); -object_property_add_bool (obj,"iommu" , - machine_get_iommu, - machine_set_iommu,NULL ); +object_property_add_str (obj,"iommu" , + machine_get_iommu, machine_set_iommu,NULL );object_property_set_description (obj,"iommu" , -"Set on/off to enable/disable Intel IOMMU (VT-d)" , +"IOMMU list" ,NULL ); object_property_add_bool(obj, "suppress-vmdesc", machine_get_suppress_vmdesc,
@@ -484,6 +484,7 @@ static void machine_finalize(Object *obj)g_free (ms->dumpdtb);g_free (ms->dt_compatible);g_free (ms->firmware); +g_free (ms->iommu); }bool machine_usb (MachineState *machine)
include/hw/boards.h +2 -1
@@ -36,6 +36,7 @@ bool machine_usb(MachineState *machine);bool machine_kernel_irqchip_allowed (MachineState *machine);bool machine_kernel_irqchip_required (MachineState *machine);bool machine_kernel_irqchip_split (MachineState *machine); +bool machine_amd_iommu (MachineState *machine);int machine_kvm_shadow_mem (MachineState *machine);int machine_phandle_start (MachineState *machine);bool machine_dump_guest_core (MachineState *machine);
@@ -126,7 +127,7 @@ struct MachineState {bool usb_disabled;bool igd_gfx_passthru;char *firmware; -bool iommu; +char *iommu;bool suppress_vmdesc;ram_addr_t ram_size;
qemu-options.hx +3 -3
@@ -38,7 +38,7 @@ 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=amd|intel enables and selects the emulated IO MMU (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"
@@ -72,8 +72,8 @@ Include guest memory in a core dump. The default is on. 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. +@item iommu=intel|amd +Enables and selects the emulated IO MMU. The default is off. @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 IO MMU and sets the emulated type", },{ .name = "suppress-vmdesc", .type = QEMU_OPT_BOOL,
Signature · 1 line
2.1.4
PATCH v3 1/4 hw/i386: Introduce AMD IO MMU
In reply to David KiarieFrom: David <[email protected]>
Add AMD IO MMU emulation to Qemu in addition to Intel IO MMU. The IO MMU does basic translation, error checking and has a minimal IOTLB implementation.
--- hw/i386/Makefile.objs | 1 + hw/i386/amd_iommu.c | 1420 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/i386/amd_iommu.h | 399 ++++++++++++++ include/hw/pci/pci.h | 2 + 4 files changed, 1822 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 +1420 -0
1,420 lines not on this page · raw message
hw/i386/amd_iommu.h new file +399 -0
399 lines not on this page · raw message
include/hw/pci/pci.h +2 -0
@@ -15,6 +15,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 v3 3/4 hw/i386: ACPI table for AMD IO MMU
In reply to David KiarieAdd IVRS table for AMD IO MMU. Also reverve MMIO
region for IO MMU via ACPI
--- hw/i386/acpi-build.c | 96 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/acpi/acpi-defs.h | 55 ++++++++++++++++++++++++++ 2 files changed, 151 insertions(+)
hw/i386/acpi-build.c +96 -0
@@ -52,6 +52,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"
@@ -2424,6 +2425,88 @@ build_dmar_q35(GArray *table_data, GArray *linker) }static void +amd_iommu_acpi_set_flag (uint8_t *value,uint64_t flag) +{ +uint64_t newvalue = *value | flag; + *(uint64_t *)value = newvalue; +} + +static void +amd_iommu_acpi_set_feature (uint64_t *value,uint64_t feature) +{ +uint64_t newvalue = *value | feature; + *value = newvalue; +} + +static void +build_amd_iommu (GArray *table_data,GArray *linker) +{ +int iommu_start = table_data->len; +bool iommu_ambig; +uint64_t host_width = (AMD_IOMMU_HOST_ADDRESS_WIDTH <<8 ); + +AcpiAMDIOMMUIVRS *ivrs; +AcpiAMDIOMMUHardwareUnit *iommu; + +/* IVRS definition */ + ivrs =acpi_data_push (table_data,sizeof (*ivrs)); + ivrs->revision =ACPI_IOMMU_IVRS_TYPE ; + ivrs->length = (sizeof (*ivrs) +sizeof (*iommu)); + ivrs->v_common_info = host_width; + +AMDIOMMUState *s = (AMDIOMMUState *)object_resolve_path_type ("" , +TYPE_AMD_IOMMU_DEVICE , &iommu_ambig); + +/* IVDB definition */ + iommu =acpi_data_push (table_data,sizeof (*iommu)); +if (!iommu_ambig) { + iommu->type =0x10 ; +/* IVHD flags */ +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_HT_TUNEN ); +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_PPRSUP ); +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_IOTLBSUP ); +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_ISOC ); +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_PREFSUP ); + + iommu->length =sizeof (*iommu); + iommu->device_id =PCI_DEVICE_ID_RD890_IOMMU ; + iommu->capability_offset = s->capab_offset; + iommu->mmio_base = s->mmio.addr; +fprintf (stderr,"MMIO addr acpi %lx" , s->mmio.addr); + + iommu->pci_segment =cpu_to_le16 (0 ); + iommu->interrupt_info =cpu_to_le16 (0 ); + +/* EFR features */ +amd_iommu_acpi_set_feature (&iommu->efr_register,IVHD_EFR_GTSUP ); +amd_iommu_acpi_set_feature (&iommu->efr_register,IVHD_EFR_HATS ); +amd_iommu_acpi_set_feature (&iommu->efr_register,IVHD_EFR_GATS ); + +/* device entries */ +memset (iommu->dev_entries,0 ,20 ); + +/* Add device flags here */ + 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 ); +} + +static bool acpi_has_amd_iommu (void ) +{ +bool ambiguous; +Object *amd_iommu; + + amd_iommu =object_resolve_path_type ("" ,TYPE_AMD_IOMMU_DEVICE , + &ambiguous); +return amd_iommu && !ambiguous; +} + +static void build_dsdt (GArray *table_data,GArray *linker,AcpiPmInfo *pm,AcpiMiscInfo *misc) {
@@ -2481,6 +2564,14 @@ build_dsdt(GArray *table_data, GArray *linker,build_q35_pci0_int (dsdt); } +/* AMD IOMMU */ +if (acpi_has_amd_iommu ()) { + sb_scope =aml_scope ("_SB" ); +aml_append (sb_scope, +aml_operation_region ("AMDV" ,AML_SYSTEM_MEMORY ,IOMMU_BASE_ADDR , +16 *1024 )); + } +build_cpu_hotplug_aml (dsdt);build_memory_hotplug_aml (dsdt, nr_mem, pm->mem_hp_io_base, pm->mem_hp_io_len);
@@ -2691,6 +2782,11 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)build_dmar_q35 (tables_blob, tables->linker); } +if (acpi_has_amd_iommu () && !acpi_has_iommu ()) { +acpi_add_table (table_offsets, tables_blob); +build_amd_iommu (tables_blob, tables->linker); + } +if (acpi_has_nvdimm ()) {nvdimm_build_acpi (table_offsets, tables_blob, tables->linker); }
include/hw/acpi/acpi-defs.h +55 -0
59 lines not on this page · raw message
Signature · 1 line
2.1.4
PATCH v3 4/4 hw/pci-host: Emulate AMD IO MMU
In reply to David KiarieSupport AMD IO MMU emulation in q35 and piix chipsets
--- hw/pci-host/piix.c | 11 +++++++++++ hw/pci-host/q35.c | 16 ++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-)
hw/pci-host/piix.c +11 -0
@@ -35,6 +35,7 @@#include "hw/i386/ioapic.h" #include "qapi/visitor.h" #include "qemu/error-report.h" +#include "hw/i386/amd_iommu.h" /* * I440FX chipset data sheet.
@@ -297,6 +298,16 @@ static void i440fx_pcihost_realize(DeviceState *dev, Error **errp)sysbus_add_io (sbd,0xcfc , &s->data_mem);sysbus_init_ioports (sbd,0xcfc ,4 ); + +/* AMD IOMMU (AMD-Vi) */ +if (g_strcmp0 (object_property_get_str (qdev_get_machine (),"iommu" ,NULL ), +"amd" ) ==0 ) { +AMDIOMMUState *iommu_state; +PCIDevice *iommu; + iommu =pci_create_simple (s->bus,0x20 ,TYPE_AMD_IOMMU_DEVICE ); + iommu_state =AMD_IOMMU_DEVICE (iommu); +pci_setup_iommu (s->bus, bridge_host_amd_iommu, iommu_state); + } }static void i440fx_realize (PCIDevice *dev,Error **errp)
hw/pci-host/q35.c +14 -2
@@ -30,6 +30,7 @@#include "hw/hw.h" #include "hw/pci-host/q35.h" #include "qapi/visitor.h" +#include "hw/i386/amd_iommu.h" /**************************************************************************** * Q35 host
@@ -505,10 +506,21 @@ 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 )) { + +char *iommu =object_property_get_str (qdev_get_machine (),"iommu" ,NULL ); + +if (g_strcmp0 (iommu,"intel" ) ==0 ) { +/* Intel IOMMU (VT-d) */ mch_init_dmar (mch); + }else if (g_strcmp0 (iommu,"amd" ) ==0 ) { +AMDIOMMUState *iommu_state; +PCIDevice *iommu; +PCIBus *bus =PCI_BUS (qdev_get_parent_bus (DEVICE (mch))); + 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); } +g_free (iommu); }uint64_t mch_mcfg_base (void )
Signature · 1 line
2.1.4
Re: [Qemu-devel] [V3 3/4] hw/i386: ACPI table for AMD IO MMU
In reply to David KiarieQuoted 63 lines · David Kiarie
Add IVRS table for AMD IO MMU. Also reverve MMIO
region for IO MMU via ACPISigned-off-by David Kiarie <[email protected]>--- hw/i386/acpi-build.c | 96 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/acpi/acpi-defs.h | 55 ++++++++++++++++++++++++++ 2 files changed, 151 insertions(+)hw/i386/acpi-build.c +39
-0@@ -52,6 +52,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" @@ -2424,6 +2425,88 @@ build_dmar_q35(GArray *table_data, GArray *linker) }static void +amd_iommu_acpi_set_flag (uint8_t *value,uint64_t flag) +{ +uint64_t newvalue = *value | flag; + *(uint64_t *)value = newvalue; +} + +static void +amd_iommu_acpi_set_feature (uint64_t *value,uint64_t feature) +{ +uint64_t newvalue = *value | feature; + *value = newvalue; +} + +static void +build_amd_iommu (GArray *table_data,GArray *linker) +{ +int iommu_start = table_data->len; +bool iommu_ambig; +uint64_t host_width = (AMD_IOMMU_HOST_ADDRESS_WIDTH <<8 ); + +AcpiAMDIOMMUIVRS *ivrs; +AcpiAMDIOMMUHardwareUnit *iommu; + +/* IVRS definition */ + ivrs =acpi_data_push (table_data,sizeof (*ivrs)); + ivrs->revision =ACPI_IOMMU_IVRS_TYPE ; + ivrs->length = (sizeof (*ivrs) +sizeof (*iommu)); + ivrs->v_common_info = host_width; + +AMDIOMMUState *s = (AMDIOMMUState *)object_resolve_path_type ("" , +TYPE_AMD_IOMMU_DEVICE , &iommu_ambig); + +/* IVDB definition */ + iommu =acpi_data_push (table_data,sizeof (*iommu)); +if (!iommu_ambig) { + iommu->type =0x10 ; +/* IVHD flags */ +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_HT_TUNEN );
hw/i386/acpi-build.c build_dmar_q35(GArray *table_data, GArray *linker) · line 2475
Quoted 10 lines
hw/i386/acpi-build.c +10
-0+amd_iommu_acpi_set_flag (&iommu->flags,IVHD_PPRSUP ); +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_IOTLBSUP ); +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_ISOC ); +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_PREFSUP ); + + iommu->length =sizeof (*iommu); + iommu->device_id =PCI_DEVICE_ID_RD890_IOMMU ; + iommu->capability_offset = s->capab_offset; + iommu->mmio_base = s->mmio.addr; +fprintf (stderr,"MMIO addr acpi %lx" , s->mmio.addr);
?
hw/i386/acpi-build.c build_dmar_q35(GArray *table_data, GArray *linker) · line 2478
Quoted 3 lines
hw/i386/acpi-build.c +3
-0+ + iommu->pci_segment =cpu_to_le16 (0 ); + iommu->interrupt_info =cpu_to_le16 (0 );
No need to byteswap 0.
And you *do* need to byteswap the rest of the fields.
Which is really an awkward API to use.
Igor, I think we want to give build_append_int_noprefix a saner name so people can write data tables more easily without bothering with structs, defines and cpu_to_le.
We already have acpi_data_push if you have a struct, so how about about acpi_data_field_push?
/* Append a field to a data table. */
void acpi_data_field_push(GArray *table, uint64_t value, int size)
{
int i;
for (i = 0; i < size; ++i) {
build_append_byte(table, value & 0xFF);
value = value >> 8;
}
assert(!value);
}Quoted 4 lines
hw/i386/acpi-build.c +4
-0+ +/* EFR features */ +amd_iommu_acpi_set_feature (&iommu->efr_register,IVHD_EFR_GTSUP ); +amd_iommu_acpi_set_feature (&iommu->efr_register,IVHD_EFR_HATS );
hw/i386/acpi-build.c build_dmar_q35(GArray *table_data, GArray *linker) · line 2492
Quoted 10 lines
hw/i386/acpi-build.c +10
-0+amd_iommu_acpi_set_feature (&iommu->efr_register,IVHD_EFR_GATS ); + +/* device entries */ +memset (iommu->dev_entries,0 ,20 ); + +/* Add device flags here */ + iommu->dev_entries[12 ] =3 ; + iommu->dev_entries[16 ] =4 ; + iommu->dev_entries[17 ] =0xff ; + iommu->dev_entries[18 ] =0xff ;
Add documentation please.
Quoted 113 lines
hw/i386/acpi-build.c +30
-0+ } + +build_header (linker, table_data, (void *)(table_data->data + iommu_start), +"IVRS" , table_data->len - iommu_start,1 ,NULL ); +} + +static bool acpi_has_amd_iommu (void ) +{ +bool ambiguous; +Object *amd_iommu; + + amd_iommu =object_resolve_path_type ("" ,TYPE_AMD_IOMMU_DEVICE , + &ambiguous); +return amd_iommu && !ambiguous; +} + +static void build_dsdt (GArray *table_data,GArray *linker,AcpiPmInfo *pm,AcpiMiscInfo *misc) {@@ -2481,6 +2564,14 @@ build_dsdt(GArray *table_data, GArray *linker,build_q35_pci0_int (dsdt); } +/* AMD IOMMU */ +if (acpi_has_amd_iommu ()) { + sb_scope =aml_scope ("_SB" ); +aml_append (sb_scope, +aml_operation_region ("AMDV" ,AML_SYSTEM_MEMORY ,IOMMU_BASE_ADDR , +16 *1024 )); + } +build_cpu_hotplug_aml (dsdt);build_memory_hotplug_aml (dsdt, nr_mem, pm->mem_hp_io_base, pm->mem_hp_io_len);@@ -2691,6 +2782,11 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)build_dmar_q35 (tables_blob, tables->linker); } +if (acpi_has_amd_iommu () && !acpi_has_iommu ()) { +acpi_add_table (table_offsets, tables_blob); +build_amd_iommu (tables_blob, tables->linker); + } +if (acpi_has_nvdimm ()) {nvdimm_build_acpi (table_offsets, 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 Signature · 1 line
2.1.4
Re: [Qemu-devel] [V3 3/4] hw/i386: ACPI table for AMD IO MMU
In reply to David KiarieQuoted 1 line · David Kiarie
Add IVRS table for AMD IO MMU. Also reverve MMIO
reserve?
Quoted 1 line
region for IO MMU via ACPI
It does not look like you reserve anything.
Pls add a link to hardware spec (in the device implementation) so we can check what does real hardware do.
If this is it:
http://developer.amd.com/wordpress/media/2012/10/488821.pdf
then the way that works seems to be by guest programming the MMIO base.
We should do the same: patch seabios and EFI to do this.
Quoted 25 lines
Signed-off-by David Kiarie <[email protected]>--- hw/i386/acpi-build.c | 96 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/acpi/acpi-defs.h | 55 ++++++++++++++++++++++++++ 2 files changed, 151 insertions(+)hw/i386/acpi-build.c +4
-0@@ -52,6 +52,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" @@ -2424,6 +2425,88 @@ build_dmar_q35(GArray *table_data, GArray *linker) }static void +amd_iommu_acpi_set_flag (uint8_t *value,uint64_t flag) +{ +uint64_t newvalue = *value | flag;
hw/i386/acpi-build.c build_dmar_q35(GArray *table_data, GArray *linker) · line 2440
Quoted 10 lines
hw/i386/acpi-build.c +10
-0+ *(uint64_t *)value = newvalue; +} + +static void +amd_iommu_acpi_set_feature (uint64_t *value,uint64_t feature) +{ +uint64_t newvalue = *value | feature; + *value = newvalue; +} +
These wrappers aren't very useful I think.
Quoted 74 lines
hw/i386/acpi-build.c +69
-0+static void +build_amd_iommu (GArray *table_data,GArray *linker) +{ +int iommu_start = table_data->len; +bool iommu_ambig; +uint64_t host_width = (AMD_IOMMU_HOST_ADDRESS_WIDTH <<8 ); + +AcpiAMDIOMMUIVRS *ivrs; +AcpiAMDIOMMUHardwareUnit *iommu; + +/* IVRS definition */ + ivrs =acpi_data_push (table_data,sizeof (*ivrs)); + ivrs->revision =ACPI_IOMMU_IVRS_TYPE ; + ivrs->length = (sizeof (*ivrs) +sizeof (*iommu)); + ivrs->v_common_info = host_width; + +AMDIOMMUState *s = (AMDIOMMUState *)object_resolve_path_type ("" , +TYPE_AMD_IOMMU_DEVICE , &iommu_ambig); + +/* IVDB definition */ + iommu =acpi_data_push (table_data,sizeof (*iommu)); +if (!iommu_ambig) { + iommu->type =0x10 ; +/* IVHD flags */ +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_HT_TUNEN ); +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_PPRSUP ); +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_IOTLBSUP ); +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_ISOC ); +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_PREFSUP ); + + iommu->length =sizeof (*iommu); + iommu->device_id =PCI_DEVICE_ID_RD890_IOMMU ; + iommu->capability_offset = s->capab_offset; + iommu->mmio_base = s->mmio.addr; +fprintf (stderr,"MMIO addr acpi %lx" , s->mmio.addr); + + iommu->pci_segment =cpu_to_le16 (0 ); + iommu->interrupt_info =cpu_to_le16 (0 ); + +/* EFR features */ +amd_iommu_acpi_set_feature (&iommu->efr_register,IVHD_EFR_GTSUP ); +amd_iommu_acpi_set_feature (&iommu->efr_register,IVHD_EFR_HATS ); +amd_iommu_acpi_set_feature (&iommu->efr_register,IVHD_EFR_GATS ); + +/* device entries */ +memset (iommu->dev_entries,0 ,20 ); + +/* Add device flags here */ + 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 ); +} + +static bool acpi_has_amd_iommu (void ) +{ +bool ambiguous; +Object *amd_iommu; + + amd_iommu =object_resolve_path_type ("" ,TYPE_AMD_IOMMU_DEVICE , + &ambiguous); +return amd_iommu && !ambiguous; +} + +static void build_dsdt (GArray *table_data,GArray *linker,AcpiPmInfo *pm,AcpiMiscInfo *misc) {@@ -2481,6 +2564,14 @@ build_dsdt(GArray *table_data, GArray *linker,build_q35_pci0_int (dsdt);
hw/i386/acpi-build.c build_dsdt(GArray *table_data, GArray *linker, · line 2574
Quoted 10 lines
hw/i386/acpi-build.c +8
-0} +/* AMD IOMMU */ +if (acpi_has_amd_iommu ()) { + sb_scope =aml_scope ("_SB" ); +aml_append (sb_scope, +aml_operation_region ("AMDV" ,AML_SYSTEM_MEMORY ,IOMMU_BASE_ADDR , +16 *1024 )); + } +
Where does AMDV string come from?
Quoted 81 lines
hw/i386/acpi-build.c +5
-0build_cpu_hotplug_aml (dsdt);build_memory_hotplug_aml (dsdt, nr_mem, pm->mem_hp_io_base, pm->mem_hp_io_len);@@ -2691,6 +2782,11 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)build_dmar_q35 (tables_blob, tables->linker); } +if (acpi_has_amd_iommu () && !acpi_has_iommu ()) { +acpi_add_table (table_offsets, tables_blob); +build_amd_iommu (tables_blob, tables->linker); + } +if (acpi_has_nvdimm ()) {nvdimm_build_acpi (table_offsets, 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 Signature · 1 line
2.1.4
Re: [Qemu-devel] [V3 3/4] hw/i386: ACPI table for AMD IO MMU
Quoted 4 lines · Michael S. Tsirkin
Quoted 1 line · David Kiarie
Add IVRS table for AMD IO MMU. Also reverve MMIO
reserve?
Yeah, typo.
Quoted 10 lines
Quoted 2 lines
region for IO MMU via ACPI
It does not look like you reserve anything.
Pls add a link to hardware spec (in the device implementation) so we can check what does real hardware do.
Quoted 6 lines
If this is it:
http://developer.amd.com/wordpress/media/2012/10/488821.pdfthen the way that works seems to be by guest programming the MMIO base.
We should do the same: patch seabios and EFI to do this.
Yes, that's the spec.
We thought this could be possible via ACPI (without patching BIOS ), no ?
Quoted 207 lines
Quoted 26 lines
Signed-off-by David Kiarie <[email protected]>--- hw/i386/acpi-build.c | 96 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/acpi/acpi-defs.h | 55 ++++++++++++++++++++++++++ 2 files changed, 151 insertions(+)hw/i386/acpi-build.c +4
-0@@ -52,6 +52,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" @@ -2424,6 +2425,88 @@ build_dmar_q35(GArray *table_data, GArray *linker) }static void +amd_iommu_acpi_set_flag (uint8_t *value,uint64_t flag) +{ +uint64_t newvalue = *value | flag;hw/i386/acpi-build.c build_dmar_q35(GArray *table_data, GArray *linker) · line 2440
Quoted 10 lines
hw/i386/acpi-build.c +10
-0+ *(uint64_t *)value = newvalue; +} + +static void +amd_iommu_acpi_set_feature (uint64_t *value,uint64_t feature) +{ +uint64_t newvalue = *value | feature; + *value = newvalue; +} +These wrappers aren't very useful I think.
Quoted 74 lines
hw/i386/acpi-build.c +69
-0+static void +build_amd_iommu (GArray *table_data,GArray *linker) +{ +int iommu_start = table_data->len; +bool iommu_ambig; +uint64_t host_width = (AMD_IOMMU_HOST_ADDRESS_WIDTH <<8 ); + +AcpiAMDIOMMUIVRS *ivrs; +AcpiAMDIOMMUHardwareUnit *iommu; + +/* IVRS definition */ + ivrs =acpi_data_push (table_data,sizeof (*ivrs)); + ivrs->revision =ACPI_IOMMU_IVRS_TYPE ; + ivrs->length = (sizeof (*ivrs) +sizeof (*iommu)); + ivrs->v_common_info = host_width; + +AMDIOMMUState *s = (AMDIOMMUState *)object_resolve_path_type ("" , +TYPE_AMD_IOMMU_DEVICE , &iommu_ambig); + +/* IVDB definition */ + iommu =acpi_data_push (table_data,sizeof (*iommu)); +if (!iommu_ambig) { + iommu->type =0x10 ; +/* IVHD flags */ +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_HT_TUNEN ); +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_PPRSUP ); +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_IOTLBSUP ); +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_ISOC ); +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_PREFSUP ); + + iommu->length =sizeof (*iommu); + iommu->device_id =PCI_DEVICE_ID_RD890_IOMMU ; + iommu->capability_offset = s->capab_offset; + iommu->mmio_base = s->mmio.addr; +fprintf (stderr,"MMIO addr acpi %lx" , s->mmio.addr); + + iommu->pci_segment =cpu_to_le16 (0 ); + iommu->interrupt_info =cpu_to_le16 (0 ); + +/* EFR features */ +amd_iommu_acpi_set_feature (&iommu->efr_register,IVHD_EFR_GTSUP ); +amd_iommu_acpi_set_feature (&iommu->efr_register,IVHD_EFR_HATS ); +amd_iommu_acpi_set_feature (&iommu->efr_register,IVHD_EFR_GATS ); + +/* device entries */ +memset (iommu->dev_entries,0 ,20 ); + +/* Add device flags here */ + 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 ); +} + +static bool acpi_has_amd_iommu (void ) +{ +bool ambiguous; +Object *amd_iommu; + + amd_iommu =object_resolve_path_type ("" ,TYPE_AMD_IOMMU_DEVICE , + &ambiguous); +return amd_iommu && !ambiguous; +} + +static void build_dsdt (GArray *table_data,GArray *linker,AcpiPmInfo *pm,AcpiMiscInfo *misc) {@@ -2481,6 +2564,14 @@ build_dsdt(GArray *table_data, GArray *linker,build_q35_pci0_int (dsdt);hw/i386/acpi-build.c build_dsdt(GArray *table_data, GArray *linker, · line 2574
Quoted 10 lines
hw/i386/acpi-build.c +8
-0} +/* AMD IOMMU */ +if (acpi_has_amd_iommu ()) { + sb_scope =aml_scope ("_SB" ); +aml_append (sb_scope, +aml_operation_region ("AMDV" ,AML_SYSTEM_MEMORY ,IOMMU_BASE_ADDR , +16 *1024 )); + } +Where does AMDV string come from?
Quoted 81 lines
hw/i386/acpi-build.c +5
-0build_cpu_hotplug_aml (dsdt);build_memory_hotplug_aml (dsdt, nr_mem, pm->mem_hp_io_base, pm->mem_hp_io_len);@@ -2691,6 +2782,11 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)build_dmar_q35 (tables_blob, tables->linker); } +if (acpi_has_amd_iommu () && !acpi_has_iommu ()) { +acpi_add_table (table_offsets, tables_blob); +build_amd_iommu (tables_blob, tables->linker); + } +if (acpi_has_nvdimm ()) {nvdimm_build_acpi (table_offsets, tables_blob, tables->linker); }include/hw/acpi/acpi-defs.h +55
-1@@ -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 --2.1.4
Re: [Qemu-devel] [V3 3/4] hw/i386: ACPI table for AMD IO MMU
In reply to Michael S. TsirkinQuoted 135 lines · Michael S. Tsirkin
Quoted 1 line · David Kiarie
Add IVRS table for AMD IO MMU. Also reverve MMIO
reserve?
Quoted 1 line
region for IO MMU via ACPI
It does not look like you reserve anything.
Pls add a link to hardware spec (in the device implementation) so we can check what does real hardware do.
If this is it:
http://developer.amd.com/wordpress/media/2012/10/488821.pdfthen the way that works seems to be by guest programming the MMIO base.
We should do the same: patch seabios and EFI to do this.Quoted 25 lines
Signed-off-by David Kiarie <[email protected]>--- hw/i386/acpi-build.c | 96 +++++++++++++++++++++++++++++++++++++++++++++ include/hw/acpi/acpi-defs.h | 55 ++++++++++++++++++++++++++ 2 files changed, 151 insertions(+)hw/i386/acpi-build.c +4
-0@@ -52,6 +52,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" @@ -2424,6 +2425,88 @@ build_dmar_q35(GArray *table_data, GArray *linker) }static void +amd_iommu_acpi_set_flag (uint8_t *value,uint64_t flag) +{ +uint64_t newvalue = *value | flag;hw/i386/acpi-build.c build_dmar_q35(GArray *table_data, GArray *linker) · line 2440
Quoted 10 lines
hw/i386/acpi-build.c +10
-0+ *(uint64_t *)value = newvalue; +} + +static void +amd_iommu_acpi_set_feature (uint64_t *value,uint64_t feature) +{ +uint64_t newvalue = *value | feature; + *value = newvalue; +} +These wrappers aren't very useful I think.
Quoted 76 lines
hw/i386/acpi-build.c +69
-0+static void +build_amd_iommu (GArray *table_data,GArray *linker) +{ +int iommu_start = table_data->len; +bool iommu_ambig; +uint64_t host_width = (AMD_IOMMU_HOST_ADDRESS_WIDTH <<8 ); + +AcpiAMDIOMMUIVRS *ivrs; +AcpiAMDIOMMUHardwareUnit *iommu; + +/* IVRS definition */ + ivrs =acpi_data_push (table_data,sizeof (*ivrs)); + ivrs->revision =ACPI_IOMMU_IVRS_TYPE ; + ivrs->length = (sizeof (*ivrs) +sizeof (*iommu)); + ivrs->v_common_info = host_width; + +AMDIOMMUState *s = (AMDIOMMUState *)object_resolve_path_type ("" , +TYPE_AMD_IOMMU_DEVICE , &iommu_ambig); + +/* IVDB definition */ + iommu =acpi_data_push (table_data,sizeof (*iommu)); +if (!iommu_ambig) { + iommu->type =0x10 ; +/* IVHD flags */ +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_HT_TUNEN ); +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_PPRSUP ); +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_IOTLBSUP ); +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_ISOC ); +amd_iommu_acpi_set_flag (&iommu->flags,IVHD_PREFSUP ); + + iommu->length =sizeof (*iommu); + iommu->device_id =PCI_DEVICE_ID_RD890_IOMMU ; + iommu->capability_offset = s->capab_offset; + iommu->mmio_base = s->mmio.addr; +fprintf (stderr,"MMIO addr acpi %lx" , s->mmio.addr); + + iommu->pci_segment =cpu_to_le16 (0 ); + iommu->interrupt_info =cpu_to_le16 (0 ); + +/* EFR features */ +amd_iommu_acpi_set_feature (&iommu->efr_register,IVHD_EFR_GTSUP ); +amd_iommu_acpi_set_feature (&iommu->efr_register,IVHD_EFR_HATS ); +amd_iommu_acpi_set_feature (&iommu->efr_register,IVHD_EFR_GATS ); + +/* device entries */ +memset (iommu->dev_entries,0 ,20 ); + +/* Add device flags here */ + 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 ); +} + +static bool acpi_has_amd_iommu (void ) +{ +bool ambiguous; +Object *amd_iommu; + + amd_iommu =object_resolve_path_type ("" ,TYPE_AMD_IOMMU_DEVICE , + &ambiguous); +return amd_iommu && !ambiguous; +} + +static void build_dsdt (GArray *table_data,GArray *linker,AcpiPmInfo *pm,AcpiMiscInfo *misc) {@@ -2481,6 +2564,14 @@ build_dsdt(GArray *table_data, GArray *linker,build_q35_pci0_int (dsdt); }
Quoted 10 lines
hw/i386/acpi-build.c build_dsdt(GArray *table_data, GArray *linker, · line 2574
Quoted 8 lines
hw/i386/acpi-build.c +8
-0+/* AMD IOMMU */ +if (acpi_has_amd_iommu ()) { + sb_scope =aml_scope ("_SB" ); +aml_append (sb_scope, +aml_operation_region ("AMDV" ,AML_SYSTEM_MEMORY ,IOMMU_BASE_ADDR , +16 *1024 )); + } +Where does AMDV string come from?
I made it up. I thought region names could be anything.
Quoted 82 lines
Quoted 82 lines
hw/i386/acpi-build.c +5
-0build_cpu_hotplug_aml (dsdt);build_memory_hotplug_aml (dsdt, nr_mem, pm->mem_hp_io_base, pm->mem_hp_io_len);@@ -2691,6 +2782,11 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)build_dmar_q35 (tables_blob, tables->linker); } +if (acpi_has_amd_iommu () && !acpi_has_iommu ()) { +acpi_add_table (table_offsets, tables_blob); +build_amd_iommu (tables_blob, tables->linker); + } +if (acpi_has_nvdimm ()) {nvdimm_build_acpi (table_offsets, tables_blob, tables->linker); }include/hw/acpi/acpi-defs.h +55
-1@@ -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 --2.1.4
Re: [Qemu-devel] [V3 3/4] hw/i386: ACPI table for AMD IO MMU
In reply to David kiarieQuoted 21 lines · David kiarie
Quoted 4 lines · Michael S. Tsirkin
Quoted 1 line · David Kiarie
Add IVRS table for AMD IO MMU. Also reverve MMIO
reserve?
Yeah, typo.
Quoted 13 lines
Quoted 2 lines
region for IO MMU via ACPI
It does not look like you reserve anything.
Pls add a link to hardware spec (in the device implementation) so we can check what does real hardware do.
If this is it:
http://developer.amd.com/wordpress/media/2012/10/488821.pdf
Quoted 7 lines
Quoted 3 lines
then the way that works seems to be by guest programming the MMIO base.
We should do the same: patch seabios and EFI to do this.Yes, that's the spec.
We thought this could be possible via ACPI (without patching BIOS ), no ?
I don't see how. We should do it the way it happens on real hardware.
Signature · 1 line
MST
Re: [Qemu-devel] [V3 3/4] hw/i386: ACPI table for AMD IO MMU
Quoted 26 lines · Michael S. Tsirkin
Quoted 25 lines · David kiarie
Quoted 4 lines · Michael S. Tsirkin
Quoted 1 line · David Kiarie
Add IVRS table for AMD IO MMU. Also reverve MMIO
reserve?
Yeah, typo.
Quoted 16 lines
Quoted 2 lines
region for IO MMU via ACPI
It does not look like you reserve anything.
Pls add a link to hardware spec (in the device implementation) so we can check what does real hardware do.
If this is it:
http://developer.amd.com/wordpress/media/2012/10/488821.pdfthen the way that works seems to be by guest programming the MMIO base.
We should do the same: patch seabios and EFI to do this.
Quoted 6 lines
Quoted 3 lines
Yes, that's the spec.
We thought this could be possible via ACPI (without patching BIOS ), no ?
I don't see how. We should do it the way it happens on real hardware.
Doesn't Seabios retrieve certain ACPI fragments from QEMU via a pv-interface by now?
Anyway, the question remains where this address comes from: The BIOS, which then writes it into some hw config register and reports it in addition via ACPI or the hardware (hard-wired).
Jan
Re: [Qemu-devel] [V3 3/4] hw/i386: ACPI table for AMD IO MMU
Quoted 34 lines · Jan Kiszka
Quoted 26 lines · Michael S. Tsirkin
Quoted 25 lines · David kiarie
Quoted 4 lines · Michael S. Tsirkin
Quoted 1 line · David Kiarie
Add IVRS table for AMD IO MMU. Also reverve MMIO
reserve?
Yeah, typo.
Quoted 16 lines
Quoted 2 lines
region for IO MMU via ACPI
It does not look like you reserve anything.
Pls add a link to hardware spec (in the device implementation) so we can check what does real hardware do.
If this is it:
http://developer.amd.com/wordpress/media/2012/10/488821.pdfthen the way that works seems to be by guest programming the MMIO base.
We should do the same: patch seabios and EFI to do this.Quoted 6 lines
Quoted 3 lines
Yes, that's the spec.
We thought this could be possible via ACPI (without patching BIOS ), no ?
I don't see how. We should do it the way it happens on real hardware.
Quoted 6 lines
Doesn't Seabios retrieve certain ACPI fragments from QEMU via a pv-interface by now?
Anyway, the question remains where this address comes from: The BIOS, which then writes it into some hw config register and reports it in addition via ACPI or the hardware (hard-wired).
Will look at patching BIOS.
Quoted 4 lines
Jan
Re: [Qemu-devel] [V3 3/4] hw/i386: ACPI table for AMD IO MMU
Quoted 35 lines · David kiarie
Quoted 34 lines · Jan Kiszka
Quoted 32 lines · Michael S. Tsirkin
Quoted 21 lines · David kiarie
Quoted 4 lines · Michael S. Tsirkin
Quoted 1 line · David Kiarie
Add IVRS table for AMD IO MMU. Also reverve MMIO
reserve?
Yeah, typo.
Quoted 13 lines
Quoted 2 lines
region for IO MMU via ACPI
It does not look like you reserve anything.
Pls add a link to hardware spec (in the device implementation) so we can check what does real hardware do.
If this is it:
http://developer.amd.com/wordpress/media/2012/10/488821.pdfQuoted 7 lines
Quoted 3 lines
then the way that works seems to be by guest programming the MMIO base.
We should do the same: patch seabios and EFI to do this.Yes, that's the spec.
We thought this could be possible via ACPI (without patching BIOS ), no ?
I don't see how. We should do it the way it happens on real hardware.
Quoted 8 lines
Quoted 6 lines
Doesn't Seabios retrieve certain ACPI fragments from QEMU via a pv-interface by now?
Anyway, the question remains where this address comes from: The BIOS, which then writes it into some hw config register and reports it in addition via ACPI or the hardware (hard-wired).
Will look at patching BIOS.
Scanning through the spec again: As the address is not hard-wired but configured via registers in the extended capabilities of the corresponding PCI functions of an IOMMU (and also enabled that way!), it's up to the BIOS to allocate an appropriate address for a system.
Jan
Re: [Qemu-devel] [V3 3/4] hw/i386: ACPI table for AMD IO MMU
Quoted 43 lines · Jan Kiszka
Quoted 42 lines · David kiarie
Quoted 40 lines · Jan Kiszka
Quoted 26 lines · Michael S. Tsirkin
Quoted 25 lines · David kiarie
Quoted 4 lines · Michael S. Tsirkin
Quoted 1 line · David Kiarie
Add IVRS table for AMD IO MMU. Also reverve MMIO
reserve?
Yeah, typo.
Quoted 16 lines
Quoted 2 lines
region for IO MMU via ACPI
It does not look like you reserve anything.
Pls add a link to hardware spec (in the device implementation) so we can check what does real hardware do.
If this is it:
http://developer.amd.com/wordpress/media/2012/10/488821.pdfthen the way that works seems to be by guest programming the MMIO base.
We should do the same: patch seabios and EFI to do this.Quoted 6 lines
Quoted 3 lines
Yes, that's the spec.
We thought this could be possible via ACPI (without patching BIOS ), no ?
I don't see how. We should do it the way it happens on real hardware.
Doesn't Seabios retrieve certain ACPI fragments from QEMU via a pv-interface by now?
Anyway, the question remains where this address comes from: The BIOS, which then writes it into some hw config register and reports it in addition via ACPI or the hardware (hard-wired).
Quoted 6 lines
Quoted 1 line
Will look at patching BIOS.
Scanning through the spec again: As the address is not hard-wired but configured via registers in the extended capabilities of the corresponding PCI functions of an IOMMU (and also enabled that way!), it's up to the BIOS to allocate an appropriate address for a system.
Is there a way to modify IVRS/ACPI table from seabios because the same address is supposed to be the IVRS table otherwise I'd have to hard-code it :/
Anyway, will check.
Quoted 4 lines
Jan
Re: [Qemu-devel] [V3 3/4] hw/i386: ACPI table for AMD IO MMU
In reply to Michael S. TsirkinQuoted 14 lines · Michael S. Tsirkin
Quoted 1 line · David Kiarie
Add IVRS table for AMD IO MMU. Also reverve MMIO
reserve?
Quoted 1 line
region for IO MMU via ACPI
It does not look like you reserve anything.
Pls add a link to hardware spec (in the device implementation) so we can check what does real hardware do.
Quoted 6 lines
If this is it:
http://developer.amd.com/wordpress/media/2012/10/488821.pdfthen the way that works seems to be by guest programming the MMIO base.
We should do the same: patch seabios and EFI to do this.
A similar question - how does a typical factory BIOS select which address to set as the MMIO base? Is it generally hard-coded or is it allocated from a range in some way?
-Kevin
Re: [Qemu-devel] [V3 3/4] hw/i386: ACPI table for AMD IO MMU
In reply to David kiarieQuoted 26 lines · David kiarie
Quoted 25 lines · Jan Kiszka
Quoted 23 lines · David kiarie
Quoted 14 lines · Jan Kiszka
Quoted 6 lines · Michael S. Tsirkin
Quoted 5 lines · David kiarie
Quoted 3 lines · Michael S. Tsirkin
then the way that works seems to be by guest programming the MMIO base.
We should do the same: patch seabios and EFI to do this.Quoted 6 lines
Quoted 3 lines
Yes, that's the spec.
We thought this could be possible via ACPI (without patching BIOS ), no ?
I don't see how. We should do it the way it happens on real hardware.
Quoted 6 lines
Doesn't Seabios retrieve certain ACPI fragments from QEMU via a pv-interface by now?
Anyway, the question remains where this address comes from: The BIOS, which then writes it into some hw config register and reports it in addition via ACPI or the hardware (hard-wired).
Will look at patching BIOS.
Quoted 8 lines
Quoted 4 lines
Scanning through the spec again: As the address is not hard-wired but configured via registers in the extended capabilities of the corresponding PCI functions of an IOMMU (and also enabled that way!), it's up to the BIOS to allocate an appropriate address for a system.
Is there a way to modify IVRS/ACPI table from seabios because the same address is supposed to be the IVRS table otherwise I'd have to hard-code it :/
There are generally two ways to do this - have QEMU set the addresses (in ACPI and/or fwcfg) and then SeaBIOS honors those addresses when programming the hardware - or SeaBIOS programs the addresses before reading the ACPI tables from fwcfg and then QEMU builds the tables with the addresses that were programmed into hardware when the tables are read from fwcfg.
As with my previous email, how does a typical factory BIOS determine what to program to these registers? Is it hardcoded or allocated from a range in some way?
-Kevin
Re: [Qemu-devel] [V3 3/4] hw/i386: ACPI table for AMD IO MMU
In reply to Kevin O'ConnorHi all,
I recall I saw IVRS filling code in the coreboot for one of the boards supported. David, you may want to have a look there.
Valentine
(from the phone)
Quoted 28 lines · Kevin O'Connor
Quoted 14 lines · Michael S. Tsirkin
Quoted 1 line · David Kiarie
Add IVRS table for AMD IO MMU. Also reverve MMIO
reserve?
Quoted 1 line
region for IO MMU via ACPI
It does not look like you reserve anything.
Pls add a link to hardware spec (in the device implementation) so we can check what does real hardware do.
Quoted 6 lines
If this is it:
http://developer.amd.com/wordpress/media/2012/10/488821.pdfthen the way that works seems to be by guest programming the MMIO base.
We should do the same: patch seabios and EFI to do this.A similar question - how does a typical factory BIOS select which address to set as the MMIO base? Is it generally hard-coded or is it allocated from a range in some way?
-Kevin
Re: [Qemu-devel] [V3 3/4] hw/i386: ACPI table for AMD IO MMU
Hi all,
I think, from coreboot code, the MMIO reservation is done through an MCFG table. I can't see one in Qemu but I don't have a clue how to extend it. There's literally nothing about MCFG online neither do I have an org that's a member of pcisig.
Could someone have the docs describing MCFG ?
Quoted 37 lines · Valentine Sinitsyn
Hi all,
I recall I saw IVRS filling code in the coreboot for one of the boards supported. David, you may want to have a look there.
Valentine
(from the phone)Quoted 28 lines · Kevin O'Connor
Quoted 14 lines · Michael S. Tsirkin
Quoted 1 line · David Kiarie
Add IVRS table for AMD IO MMU. Also reverve MMIO
reserve?
Quoted 1 line
region for IO MMU via ACPI
It does not look like you reserve anything.
Pls add a link to hardware spec (in the device implementation) so we can check what does real hardware do.
Quoted 6 lines
If this is it:
http://developer.amd.com/wordpress/media/2012/10/488821.pdfthen the way that works seems to be by guest programming the MMIO base.
We should do the same: patch seabios and EFI to do this.A similar question - how does a typical factory BIOS select which address to set as the MMIO base? Is it generally hard-coded or is it allocated from a range in some way?
-Kevin
Re: [Qemu-devel] [V3 2/4] hw/core: Add AMD IO MMU to machine properties
In reply to David KiarieQuoted 27 lines · David Kiarie
Add IO MMU as a string to machine properties which is used to control whether and they type of IO MMU to emulate
Signed-off-by David Kiarie <[email protected]>--- hw/core/machine.c | 17 +++++++++-------- include/hw/boards.h | 3 ++- qemu-options.hx | 6 +++--- util/qemu-config.c | 4 ++-- 4 files changed, 16 insertions(+), 14 deletions(-)hw/core/machine.c +2
-2@@ -283,18 +283,19 @@ static void machine_set_firmware(Object *obj, const char *value, Error **errp) ms->firmware =g_strdup (value); } -static bool machine_get_iommu (Object *obj,Error **errp) +static char *machine_get_iommu (Object *obj,Error **errp) {MachineState *ms =MACHINE (obj); -return ms->iommu; +return g_strdup (ms->iommu);
hw/core/machine.c static void machine_set_firmware(Object *obj, const char *value, Error **errp) · line 298
Quoted 10 lines
hw/core/machine.c +3
-2} -static void machine_set_iommu (Object *obj,bool value,Error **errp) +static void machine_set_iommu (Object *obj,const char *value,Error **errp) {MachineState *ms =MACHINE (obj); - ms->iommu = value; +g_free (ms->iommu); + ms->iommu =g_strdup (value);
Hi,
The patch is looking good, the only thing I am missing is dealing with incorrect input. We should accept only "intel" or "amd".
Thanks,
Marcel
Quoted 87 lines
hw/core/machine.c +4
-4}static void machine_set_suppress_vmdesc (Object *obj,bool value,Error **errp)@@ -454,11 +455,10 @@ static void machine_initfn(Object *obj)object_property_set_description (obj,"firmware" ,"Firmware image" ,NULL ); -object_property_add_bool (obj,"iommu" , - machine_get_iommu, - machine_set_iommu,NULL ); +object_property_add_str (obj,"iommu" , + machine_get_iommu, machine_set_iommu,NULL );object_property_set_description (obj,"iommu" , -"Set on/off to enable/disable Intel IOMMU (VT-d)" , +"IOMMU list" ,NULL ); object_property_add_bool(obj, "suppress-vmdesc", machine_get_suppress_vmdesc,@@ -484,6 +484,7 @@ static void machine_finalize(Object *obj)g_free (ms->dumpdtb);g_free (ms->dt_compatible);g_free (ms->firmware); +g_free (ms->iommu); }bool machine_usb (MachineState *machine)include/hw/boards.h +2
-1@@ -36,6 +36,7 @@ bool machine_usb(MachineState *machine);bool machine_kernel_irqchip_allowed (MachineState *machine);bool machine_kernel_irqchip_required (MachineState *machine);bool machine_kernel_irqchip_split (MachineState *machine); +bool machine_amd_iommu (MachineState *machine);int machine_kvm_shadow_mem (MachineState *machine);int machine_phandle_start (MachineState *machine);bool machine_dump_guest_core (MachineState *machine);@@ -126,7 +127,7 @@ struct MachineState {bool usb_disabled;bool igd_gfx_passthru;char *firmware; -bool iommu; +char *iommu;bool suppress_vmdesc;ram_addr_t ram_size;qemu-options.hx +3
-3@@ -38,7 +38,7 @@ 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=amd|intel enables and selects the emulated IO MMU (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"@@ -72,8 +72,8 @@ Include guest memory in a core dump. The default is on. 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. +@item iommu=intel|amd +Enables and selects the emulated IO MMU. The default is off. @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 IO MMU and sets the emulated type", },{ .name = "suppress-vmdesc", .type = QEMU_OPT_BOOL,
Re: [Qemu-devel] [V3 4/4] hw/pci-host: Emulate AMD IO MMU
In reply to David KiarieQuoted 21 lines · David Kiarie
Support AMD IO MMU emulation in q35 and piix chipsets
Signed-off-by David Kiarie <[email protected]>--- hw/pci-host/piix.c | 11 +++++++++++ hw/pci-host/q35.c | 16 ++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-)hw/pci-host/piix.c +1
-0@@ -35,6 +35,7 @@#include "hw/i386/ioapic.h" #include "qapi/visitor.h" #include "qemu/error-report.h" +#include "hw/i386/amd_iommu.h" /* * I440FX chipset data sheet.
hw/pci-host/piix.c static void i440fx_pcihost_realize(DeviceState *dev, Error **errp) · line 304
Quoted 7 lines
hw/pci-host/piix.c +4
-0@@ -297,6 +298,16 @@ static void i440fx_pcihost_realize(DeviceState *dev, Error **errp)sysbus_add_io (sbd,0xcfc , &s->data_mem);sysbus_init_ioports (sbd,0xcfc ,4 ); + +/* AMD IOMMU (AMD-Vi) */ +if (g_strcmp0 (object_property_get_str (qdev_get_machine (),"iommu" ,NULL ), +"amd" ) ==0 ) {
You can use the Machine wrapper and it will look slightly better (at least you get rid of the literal):
MACHINE(qdev_get_machine())->iommu <=> object_property_get_str(qdev_get_machine(), "iommu", NULL)
By the way, does i440fx host work with AMD iommu?
Quoted 24 lines
hw/pci-host/piix.c +6
-0+AMDIOMMUState *iommu_state; +PCIDevice *iommu; + iommu =pci_create_simple (s->bus,0x20 ,TYPE_AMD_IOMMU_DEVICE ); + iommu_state =AMD_IOMMU_DEVICE (iommu); +pci_setup_iommu (s->bus, bridge_host_amd_iommu, iommu_state); + } }static void i440fx_realize (PCIDevice *dev,Error **errp)hw/pci-host/q35.c +1
-0@@ -30,6 +30,7 @@#include "hw/hw.h" #include "hw/pci-host/q35.h" #include "qapi/visitor.h" +#include "hw/i386/amd_iommu.h" /**************************************************************************** * Q35 host @@ -505,10 +506,21 @@ 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);
hw/pci-host/q35.c static void mch_realize(PCIDevice *d, Error **errp) · line 515
Quoted 10 lines
hw/pci-host/q35.c +6
-2} -/* Intel IOMMU (VT-d) */ -if (object_property_get_bool (qdev_get_machine (),"iommu" ,NULL )) { + +char *iommu =object_property_get_str (qdev_get_machine (),"iommu" ,NULL ); + +if (g_strcmp0 (iommu,"intel" ) ==0 ) { +/* Intel IOMMU (VT-d) */ mch_init_dmar (mch); + }else if (g_strcmp0 (iommu,"amd" ) ==0 ) {
Last thing, maybe you can define "intel" and "amd" literals in one please, then use it them as you see fit.
Thanks,
Marcel
Quoted 12 lines
hw/pci-host/q35.c +7
-0+AMDIOMMUState *iommu_state; +PCIDevice *iommu; +PCIBus *bus =PCI_BUS (qdev_get_parent_bus (DEVICE (mch))); + 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); } +g_free (iommu); }uint64_t mch_mcfg_base (void )
Re: [Qemu-devel] [V3 4/4] hw/pci-host: Emulate AMD IO MMU
Quoted 36 lines · Marcel Apfelbaum
Quoted 21 lines · David Kiarie
Support AMD IO MMU emulation in q35 and piix chipsets
Signed-off-by David Kiarie <[email protected]>--- hw/pci-host/piix.c | 11 +++++++++++ hw/pci-host/q35.c | 16 ++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-)hw/pci-host/piix.c +1
-0@@ -35,6 +35,7 @@#include "hw/i386/ioapic.h" #include "qapi/visitor.h" #include "qemu/error-report.h" +#include "hw/i386/amd_iommu.h" /* * I440FX chipset data sheet. hw/pci-host/piix.c static void i440fx_pcihost_realize(DeviceState · line 306
Quoted 9 lines
hw/pci-host/piix.c +4
-0@@ -297,6 +298,16 @@ static void i440fx_pcihost_realize(DeviceState *dev, Error **errp)sysbus_add_io (sbd,0xcfc , &s->data_mem);sysbus_init_ioports (sbd,0xcfc ,4 ); + +/* AMD IOMMU (AMD-Vi) */ +if (g_strcmp0 (object_property_get_str (qdev_get_machine (),"iommu" ,NULL ), +"amd" ) ==0 ) {You can use the Machine wrapper and it will look slightly better (at least you get rid of the literal):
MACHINE(qdev_get_machine())->iommu <=>object_property_get_str(qdev_get_machine(), "iommu", NULL)
Quoted 3 lines
By the way, does i440fx host work with AMD iommu?
Forgot,...
Yeah, I checked this to confirm it works though looking at it, it seems like i440fx doesn't support PCIE(MSI) so interrupt related things might not work here but we're not yet there.
Quoted 59 lines
Quoted 27 lines
hw/pci-host/piix.c +6
-0+AMDIOMMUState *iommu_state; +PCIDevice *iommu; + iommu =pci_create_simple (s->bus,0x20 ,TYPE_AMD_IOMMU_DEVICE ); + iommu_state =AMD_IOMMU_DEVICE (iommu); +pci_setup_iommu (s->bus, bridge_host_amd_iommu, iommu_state); + } }static void
i440fx_realize(PCIDevice *dev, Error **errp)hw/pci-host/q35.c +1
-0@@ -30,6 +30,7 @@#include "hw/hw.h" #include "hw/pci-host/q35.h" #include "qapi/visitor.h" +#include "hw/i386/amd_iommu.h" /**************************************************************************** * Q35 host @@ -505,10 +506,21 @@ 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); }hw/pci-host/q35.c static void mch_realize(PCIDevice *d, Error · line 517
Quoted 10 lines
hw/pci-host/q35.c +6
-2-/* Intel IOMMU (VT-d) */ -if (object_property_get_bool (qdev_get_machine (),"iommu" ,NULL )) { + +char *iommu =object_property_get_str (qdev_get_machine (),"iommu" ,NULL ); + +if (g_strcmp0 (iommu,"intel" ) ==0 ) { +/* Intel IOMMU (VT-d) */ mch_init_dmar (mch); + }else if (g_strcmp0 (iommu,"amd" ) ==0 ) {Last thing, maybe you can define "intel" and "amd" literals in one please, then use it them as you see fit.
Thanks,
MarcelQuoted 12 lines
hw/pci-host/q35.c +7
-0+AMDIOMMUState *iommu_state; +PCIDevice *iommu; +PCIBus *bus =PCI_BUS (qdev_get_parent_bus (DEVICE (mch))); + 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); } +g_free (iommu); }
uint64_tmch_mcfg_base(void)