qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Kiarie <davidkiarie4@gmail.com>
To: qemu-devel@nongnu.org
Cc: valentine.sinitsyn@gmail.com, jan.kiszka@web.de,
	David <davidkiarie4@gmail.com>,
	mst@redhat.com
Subject: [Qemu-devel] [RFC 4/4] hw/pci-host: Add AMD IOMMU emulation to q35 and PIIX
Date: Tue, 25 Aug 2015 02:19:29 +0300	[thread overview]
Message-ID: <1440458369-7384-5-git-send-email-davidkiarie4@gmail.com> (raw)
In-Reply-To: <1440458369-7384-1-git-send-email-davidkiarie4@gmail.com>

From: David <davidkiarie4@gmail.com>

Add AMD IOMMU emulation to q35 and PIIX chipsets.

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

diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c
index 1cb25f3..348cff0 100644
--- a/hw/pci-host/piix.c
+++ b/hw/pci-host/piix.c
@@ -31,6 +31,7 @@
 #include "qemu/range.h"
 #include "hw/xen/xen.h"
 #include "hw/pci-host/pam.h"
+#include "hw/i386/amd_iommu.h"
 #include "sysemu/sysemu.h"
 #include "hw/i386/ioapic.h"
 #include "qapi/visitor.h"
@@ -292,12 +293,21 @@ static void i440fx_pcihost_realize(DeviceState *dev, Error **errp)
 {
     PCIHostState *s = PCI_HOST_BRIDGE(dev);
     SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
+    AMDIOMMUState *iommu_state;
+    PCIDevice *iommu;
 
     sysbus_add_io(sbd, 0xcf8, &s->conf_mem);
     sysbus_init_ioports(sbd, 0xcf8, 4);
 
     sysbus_add_io(sbd, 0xcfc, &s->data_mem);
     sysbus_init_ioports(sbd, 0xcfc, 4);
+
+    /* AMD IOMMU (AMD-Vi) */
+    if(machine_amd_iommu(current_machine)){
+        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)
@@ -333,6 +343,7 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state,
     object_property_add_child(qdev_get_machine(), "i440fx", OBJECT(dev), NULL);
     qdev_init_nofail(dev);
 
+
     d = pci_create_simple(b, 0, TYPE_I440FX_PCI_DEVICE);
     *pi440fx_state = I440FX_PCI_DEVICE(d);
     f = *pi440fx_state;
diff --git a/hw/pci-host/q35.c b/hw/pci-host/q35.c
index bd74094..4bb7e3f 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
@@ -470,6 +471,8 @@ static void mch_realize(PCIDevice *d, Error **errp)
 {
     int i;
     MCHPCIState *mch = MCH_PCI_DEVICE(d);
+    AMDIOMMUState *iommu_state;
+    PCIDevice *iommu;
 
     /* setup pci memory mapping */
     pc_pci_as_mapping_init(OBJECT(mch), mch->system_memory,
@@ -528,6 +531,14 @@ static void mch_realize(PCIDevice *d, Error **errp)
     if (machine_iommu(current_machine)) {
         mch_init_dmar(mch);
     }
+
+    /* AMD IOMMU (AMD-Vi) */
+    if (machine_amd_iommu(current_machine)){
+        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);
+    }
 }
 
 uint64_t mch_mcfg_base(void)
-- 
2.1.4

      parent reply	other threads:[~2015-08-24 23:20 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-24 23:19 [Qemu-devel] [RFC 0/4] AMD IOMMU David Kiarie
2015-08-24 23:19 ` [Qemu-devel] [RFC 1/4] hw/core: Prepare for introducing " David Kiarie
2015-08-24 23:19 ` [Qemu-devel] [RFC 2/4] hw/i386: Introduce " David Kiarie
2015-08-25  6:39   ` Valentine Sinitsyn
2015-08-25  7:25     ` David kiarie
2015-08-25  7:31       ` Valentine Sinitsyn
2015-08-25  7:41         ` David kiarie
2015-08-25  7:43           ` Valentine Sinitsyn
2015-08-25  7:44           ` David kiarie
2015-09-07 12:46   ` Valentine Sinitsyn
2015-09-09  7:30     ` David kiarie
2015-09-09  7:45       ` Valentine Sinitsyn
2015-09-09  7:59         ` David kiarie
2015-09-09  8:07           ` Valentine Sinitsyn
2015-09-09  8:12             ` David kiarie
2015-09-09  8:14               ` Valentine Sinitsyn
2015-09-09  8:31                 ` David kiarie
2015-09-09  7:59         ` Michael S. Tsirkin
2015-09-09  8:04           ` Valentine Sinitsyn
2015-09-12 10:55     ` Valentine Sinitsyn
2015-08-24 23:19 ` [Qemu-devel] [RFC 3/4] hw/i386: Introduce IVRS for " David Kiarie
2015-08-24 23:19 ` David Kiarie [this message]

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=1440458369-7384-5-git-send-email-davidkiarie4@gmail.com \
    --to=davidkiarie4@gmail.com \
    --cc=jan.kiszka@web.de \
    --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).