Skip to contentSkip to conversation

AMD IOMMU

PATCH Superseded David Kiarie 2 participants 10 messages Feb 17, 2016 – Feb 21, 2016

v4 of 19 Superseded Latest is v19 →

lore
Share & tools
lore
#0 lore raw

v4 cover AMD IOMMU

Hello there,

This is v5 of AMD IOMMU patches that fixes the issues mentioned in v4 except I fail to see the endian-ness issues Michael mentioned.

I also stripped PIIX AMD IOMMU support since I added an MSI interrupt. One of the patches has a conflict with current master but it this is mergable I could quickly send a clean patch.

Thanks!

David Kiarie (4):
hw/i386: Introduce AMD IO MMU
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             |   28 +-
 hw/i386/Makefile.objs         |    1 +
 hw/i386/acpi-build.c          |   98 ++-
 hw/i386/amd_iommu.c           | 1430 +++++++++++++++++++++++++++++++++++++++++
 hw/i386/amd_iommu.h           |  395 ++++++++++++
 hw/pci-host/piix.c            |    1 +
 hw/pci-host/q35.c             |   14 +-
 include/hw/acpi/acpi-defs.h   |   55 ++
 include/hw/boards.h           |    3 +-
 include/hw/i386/intel_iommu.h |    1 +
 include/hw/pci/pci.h          |    2 +
 qemu-options.hx               |    6 +-
 util/qemu-config.c            |    4 +-
 13 files changed, 2011 insertions(+), 27 deletions(-)
 create mode 100644 hw/i386/amd_iommu.c
 create mode 100644 hw/i386/amd_iommu.h
Signature · 1 line
2.1.4
#4 lore raw

PATCH v4 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   | 28 ++++++++++++++++++++--------
 include/hw/boards.h |  3 ++-
 qemu-options.hx     |  6 +++---
 util/qemu-config.c  |  4 ++--
 4 files changed, 27 insertions(+), 14 deletions(-)
hw/core/machine.c +20 -8
index 1261368..6379f24 100644
@@ -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"
@@ -284,18 +286,28 @@ 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);
+    Error *err = NULL;
+
+    g_free(ms->iommu);
+
+    if (g_strcmp0(value, AMD_IOMMU_STR) &&
+            g_strcmp0(value, INTEL_IOMMU_STR)) {
+        error_setg(errp, "Invalid IO MMU type %s", value);
+        error_propagate(errp, err);
+        return;
+    }
 
-    ms->iommu = value;
+    ms->iommu = g_strdup(value);
 }
 
 static void machine_set_suppress_vmdesc(Object *obj, bool value, Error **errp)
@@ -455,11 +467,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,
@@ -485,6 +496,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
index 0f30959..b119245 100644
@@ -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
index 733a194..9ac92c1 100644
@@ -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
index fb97307..5ffb5c3 100644
@@ -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
#6 lore raw

PATCH v4 3/4 hw/i386: ACPI table for AMD IO MMU

In reply to David Kiarie

Add IVRS table for AMD IO MMU. Also reverve MMIO
region for IO MMU via ACPI

---
 hw/i386/acpi-build.c        | 98 ++++++++++++++++++++++++++++++++++++++++-----
 include/hw/acpi/acpi-defs.h | 55 +++++++++++++++++++++++++
 2 files changed, 142 insertions(+), 11 deletions(-)
hw/i386/acpi-build.c +87 -11
index 739cfa3..b8cd091 100644
@@ -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)
 {
@@ -2423,6 +2430,78 @@ build_dmar_q35(GArray *table_data, GArray *linker)
 }
 
 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);
+}
+
+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 void
 build_dsdt(GArray *table_data, GArray *linker,
            AcpiPmInfo *pm, AcpiMiscInfo *misc)
 {
@@ -2590,16 +2669,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());
@@ -2618,6 +2687,7 @@ void acpi_build(PcGuestInfo *guest_info, 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;
 
@@ -2685,7 +2755,13 @@ void acpi_build(PcGuestInfo *guest_info, 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

Signature · 1 line
2.1.4
#1 lore raw

PATCH v4 1/4 hw/i386: Introduce AMD IO MMU

In reply to David Kiarie

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   | 1430 +++++++++++++++++++++++++++++++++++++++++++++++++
 hw/i386/amd_iommu.h   |  395 ++++++++++++++
 include/hw/pci/pci.h  |    2 +
 4 files changed, 1828 insertions(+)
 create mode 100644 hw/i386/amd_iommu.c
 create mode 100644 hw/i386/amd_iommu.h
hw/i386/Makefile.objs +1 -0
index b52d5b8..2f1a265 100644
@@ -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 +1430 -0

1,430 lines not on this page · raw message

hw/i386/amd_iommu.h new file +395 -0

395 lines not on this page · raw message

include/hw/pci/pci.h +2 -0
index dedf277..61deace 100644
@@ -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
#8 lore raw

PATCH v4 4/4 hw/pci-host: Emulate AMD IO MMU

In reply to David Kiarie

Add AMD IO MMU emulation support to q35 chipset

---
 hw/pci-host/piix.c            |  1 +
 hw/pci-host/q35.c             | 14 ++++++++++++--
 include/hw/i386/intel_iommu.h |  1 +
 3 files changed, 14 insertions(+), 2 deletions(-)
hw/pci-host/piix.c +1 -0
index 3832ed6..6aad34c 100644
@@ -36,6 +36,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/q35.c +12 -2
index 42b421e..7284bdd 100644
@@ -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
@@ -506,9 +507,18 @@ 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 (g_strcmp0(MACHINE(qdev_get_machine())->iommu, INTEL_IOMMU_STR) == 0) {
+        /* Intel IOMMU (VT-d) */
         mch_init_dmar(mch);
+    } else if (g_strcmp0(MACHINE(qdev_get_machine())->iommu, AMD_IOMMU_STR)
+               == 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);
     }
 }
 
include/hw/i386/intel_iommu.h +1 -0
index 5dbadb7..0b32bd6 100644
@@ -27,6 +27,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
#2 lore raw

Re: [Qemu-devel] [V4 1/4] hw/i386: Introduce AMD IO MMU

In reply to David Kiarie
Quoted 5 lines · David Kiarie
hw/i386/amd_iommu.h new file +0 -0
new file mode 100644
index 0000000..4264c19

...

hw/i386/amd_iommu.h line 247

Quoted 11 lines
hw/i386/amd_iommu.h new file +11 -0
+/* extended feature support */
+#define IOMMU_EXT_FEATURES(IOMMU_FEATURE_PREFETCH | IOMMU_FEATURE_PPR | \
+        IOMMU_FEATURE_NX | IOMMU_FEATURE_IA | IOMMU_FEATURE_GT | \
+        IOMMU_FEATURE_GA | IOMMU_FEATURE_HE | IOMMU_GATS_MODE | \
+        IOMMU_HATS_MODE)
+
+/* capabilities header */
+#define IOMMU_CAPAB_FEATURES(IOMMU_CAPAB_FLAT_EXT | \
+        IOMMU_CAPAB_FLAG_NPCACHE | \ IOMMU_CAPAB_FLAG_IOTLBSUP \
+        | IOMMU_CAPAB_ID_SEC | IOMMU_CAPAB_INIT_TYPE | \
+        IOMMU_CAPAB_FLAG_HTTUNNEL |  IOMMU_CAPAB_EFR_SUP)

These two do not compile because you misformatted the macros. Must be

#define X (Y | Z | ...)

Jan

#3 lore raw

Re: [Qemu-devel] [V4 1/4] hw/i386: Introduce AMD IO MMU

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 7 lines · Jan Kiszka
Quoted 3 lines · David Kiarie
hw/i386/amd_iommu.h new file renamed from hw/i386/amd_iommu.h +0 -0

mode 100644 index 0000000..4264c19 --- /dev/null +++ b/hw/i386/amd_iommu.h

...

Quoted 8 lines
Quoted 8 lines

+/* extended feature support */ +#define IOMMU_EXT_FEATURES(IOMMU_FEATURE_PREFETCH | IOMMU_FEATURE_PPR |
\ + IOMMU_FEATURE_NX | IOMMU_FEATURE_IA | IOMMU_FEATURE_GT

| \ +        IOMMU_FEATURE_GA | IOMMU_FEATURE_HE |
IOMMU_GATS_MODE | \ +        IOMMU_HATS_MODE) + +/* capabilities
header */ +#define IOMMU_CAPAB_FEATURES(IOMMU_CAPAB_FLAT_EXT | \ 
+        IOMMU_CAPAB_FLAG_NPCACHE | \ IOMMU_CAPAB_FLAG_IOTLBSUP

\

Oh, and there is a stray '\' here.

Quoted 11 lines
Quoted 2 lines

+ | IOMMU_CAPAB_ID_SEC | IOMMU_CAPAB_INIT_TYPE | \ +
IOMMU_CAPAB_FLAG_HTTUNNEL | IOMMU_CAPAB_EFR_SUP)

These two do not compile because you misformatted the macros. Must be

#define X (Y | Z | ...)

Jan

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iEYEARECAAYFAlbJcswACgkQitSsb3rl5xRgIACfdNU0T9q5sNfnAqfXSAUSsuuE sMIAoL1duOzpcBkY6OXKxwEpb7uijplA
=6zSV
-----END PGP SIGNATURE-----

#7 lore raw

Re: [Qemu-devel] [V4 3/4] hw/i386: ACPI table for AMD IO MMU

In reply to David Kiarie
Quoted 83 lines · David Kiarie

Add IVRS table for AMD IO MMU. Also reverve MMIO
region for IO MMU via ACPI

---
 hw/i386/acpi-build.c        | 98 ++++++++++++++++++++++++++++++++++++++++-----
 include/hw/acpi/acpi-defs.h | 55 +++++++++++++++++++++++++
 2 files changed, 142 insertions(+), 11 deletions(-)
hw/i386/acpi-build.c +52 -0
index 739cfa3..b8cd091 100644
@@ -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)
 {
@@ -2423,6 +2430,78 @@ build_dmar_q35(GArray *table_data, GArray *linker)
 }
 
 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)

hw/i386/acpi-build.c build_dmar_q35(GArray *table_data, GArray *linker) · line 2487

Quoted 10 lines
hw/i386/acpi-build.c +10 -0
+         *  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);

Requires rebasing over master (to append another NULL here).

Jan

#5 lore raw

Re: [Qemu-devel] [V4 2/4] hw/core: Add AMD IO MMU to machine properties

In reply to David Kiarie
Quoted 3 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

Let's call it consistently "IOMMU", instead of "IO MMU", also in the outputs.

Jan

#9 lore raw
In reply to David Kiarie
Quoted 5 lines · David Kiarie

Hello there,

This is v5 of AMD IOMMU patches that fixes the issues mentioned in v4 except I fail to see the endian-ness issues Michael mentioned.

I also stripped PIIX AMD IOMMU support since I added an MSI interrupt. One of the patches has a conflict with current master but it this is mergable I could quickly send a clean patch.

I've just made it compile over master, but something is broken, at least in the PCI capability layout:

# lspci -vv -s 00:04.0
00:04.0 Generic system peripheral [0806]: Advanced Micro Devices [AMD] Device 0020
        Subsystem: Red Hat, Inc Device 1100
        Control: I/O+ Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR+ FastB2B- DisINTx-
        Status: Cap+ 66MHz- UDF- FastB2B- ParErr- DEVSEL=fast >TAbort- <TAbort- <MAbort- >SERR- <PERR- INTx-
        Capabilities: [64] HyperTransport: Slave or Primary Interface
                Command: BaseUnitID=0 UnitCnt=0 MastHost- DefDir-
                Link Control 0: CFlE- CST- CFE- <LkFail- Init- EOC- TXO- <CRCErr=0
                Link Config 0: MLWI=8bit MLWO=8bit LWI=8bit LWO=8bit
                Link Control 1: CFlE- CST- CFE- <LkFail- Init- EOC- TXO- <CRCErr=0
                Link Config 1: MLWI=8bit MLWO=8bit LWI=8bit LWO=8bit
                Revision ID: 0.00
        Capabilities: [60] MSI: Enable- Count=1/1 Maskable- 64bit-
                Address: 00006008  Data: 0000
        Capabilities: [5c] HyperTransport: Slave or Primary Interface
                Command: BaseUnitID=0 UnitCnt=0 MastHost- DefDir-
                Link Control 0: CFlE- CST+ CFE- <LkFail- Init- EOC- TXO- <CRCErr=c
                Link Config 0: MLWI=8bit MLWO=8bit LWI=8bit LWO=8bit
                Link Control 1: CFlE- CST- CFE+ <LkFail- Init- EOC- TXO- <CRCErr=0
                Link Config 1: MLWI=8bit MLWO=8bit LWI=8bit LWO=8bit
                Revision ID: 0.00
        Capabilities: [58] MSI: Enable- Count=1/1 Maskable- 64bit-
                Address: 00005808  Data: 5c05
        Capabilities: [40] <chain broken>

Two times MSI, and a broken chain. At least unusual is also the reverted ordering. Please examine and fix.

Thanks,
Jan