From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52668) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZU12I-0004NE-4U for qemu-devel@nongnu.org; Mon, 24 Aug 2015 19:20:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZU12F-0007bP-8r for qemu-devel@nongnu.org; Mon, 24 Aug 2015 19:20:18 -0400 Received: from mail-wi0-x235.google.com ([2a00:1450:400c:c05::235]:34977) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZU12F-0007bB-2r for qemu-devel@nongnu.org; Mon, 24 Aug 2015 19:20:15 -0400 Received: by wicne3 with SMTP id ne3so85467254wic.0 for ; Mon, 24 Aug 2015 16:20:14 -0700 (PDT) From: David Kiarie Date: Tue, 25 Aug 2015 02:19:29 +0300 Message-Id: <1440458369-7384-5-git-send-email-davidkiarie4@gmail.com> In-Reply-To: <1440458369-7384-1-git-send-email-davidkiarie4@gmail.com> References: <1440458369-7384-1-git-send-email-davidkiarie4@gmail.com> Subject: [Qemu-devel] [RFC 4/4] hw/pci-host: Add AMD IOMMU emulation to q35 and PIIX List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: valentine.sinitsyn@gmail.com, jan.kiszka@web.de, David , mst@redhat.com From: David Add AMD IOMMU emulation to q35 and PIIX chipsets. Signed-off-by: David Kiarie --- 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