qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Kiarie <davidkiarie4@gmail.com>
To: qemu-devel@nongnu.org
Cc: mst@redhat.com, crosthwaitepeter@gmail.com,
	valentine.sinitsyn@gmail.com, jan.kiszka@web.de,
	marcel@redhat.com, David Kiarie <davidkiarie4@gmail.com>
Subject: [Qemu-devel] [V3 4/4] hw/pci-host: Emulate AMD IO MMU
Date: Thu, 14 Jan 2016 11:04:28 +0300	[thread overview]
Message-ID: <1452758668-19284-5-git-send-email-davidkiarie4@gmail.com> (raw)
In-Reply-To: <1452758668-19284-1-git-send-email-davidkiarie4@gmail.com>

Support AMD IO MMU emulation in q35 and piix chipsets

Signed-off-by: David Kiarie <davidkiarie4@gmail.com>
---
 hw/pci-host/piix.c | 11 +++++++++++
 hw/pci-host/q35.c  | 16 ++++++++++++++--
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
index 924f0fa..19e2930 100644
--- a/hw/pci-host/piix.c
+++ b/hw/pci-host/piix.c
@@ -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)
diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c
index 1fb4707..dd4c822 100644
--- a/hw/pci-host/q35.c
+++ b/hw/pci-host/q35.c
@@ -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)
-- 
2.1.4

  parent reply	other threads:[~2016-01-14  8:05 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-14  8:04 [Qemu-devel] [V3 0/4] AMD IOMMU David Kiarie
2016-01-14  8:04 ` [Qemu-devel] [V3 1/4] hw/i386: Introduce AMD IO MMU David Kiarie
2016-01-14  8:04 ` [Qemu-devel] [V3 2/4] hw/core: Add AMD IO MMU to machine properties David Kiarie
2016-01-17 13:45   ` Marcel Apfelbaum
2016-01-14  8:04 ` [Qemu-devel] [V3 3/4] hw/i386: ACPI table for AMD IO MMU David Kiarie
2016-01-14  9:56   ` Michael S. Tsirkin
2016-01-14 10:09   ` Michael S. Tsirkin
2016-01-14 12:15     ` David kiarie
2016-01-14 15:39       ` Michael S. Tsirkin
2016-01-14 15:42         ` Jan Kiszka
2016-01-14 16:09           ` David kiarie
2016-01-14 16:19             ` Jan Kiszka
2016-01-14 16:29               ` David kiarie
2016-01-14 16:52                 ` Kevin O'Connor
2016-01-14 12:34     ` David kiarie
2016-01-14 16:29     ` Kevin O'Connor
2016-01-14 16:54       ` Valentine Sinitsyn
2016-01-15 13:52         ` David kiarie
2016-01-14  8:04 ` David Kiarie [this message]
2016-01-17 13:57   ` [Qemu-devel] [V3 4/4] hw/pci-host: Emulate " Marcel Apfelbaum
2016-01-18 16:36     ` David Kiarie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1452758668-19284-5-git-send-email-davidkiarie4@gmail.com \
    --to=davidkiarie4@gmail.com \
    --cc=crosthwaitepeter@gmail.com \
    --cc=jan.kiszka@web.de \
    --cc=marcel@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=valentine.sinitsyn@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).