From patchwork Mon Jan 18 15:25:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Kiarie X-Patchwork-Id: 8055491 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id CFC1B9F440 for ; Mon, 18 Jan 2016 15:29:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2874920489 for ; Mon, 18 Jan 2016 15:29:37 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 789C3203E3 for ; Mon, 18 Jan 2016 15:29:36 +0000 (UTC) Received: from localhost ([::1]:60348 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLBkN-00067g-T1 for patchwork-qemu-devel@patchwork.kernel.org; Mon, 18 Jan 2016 10:29:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50859) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLBhs-0002ct-0C for qemu-devel@nongnu.org; Mon, 18 Jan 2016 10:27:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aLBhr-0004G9-5H for qemu-devel@nongnu.org; Mon, 18 Jan 2016 10:26:59 -0500 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:35570) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aLBhq-0004Fr-U9 for qemu-devel@nongnu.org; Mon, 18 Jan 2016 10:26:59 -0500 Received: by mail-wm0-x242.google.com with SMTP id 123so10026515wmz.2 for ; Mon, 18 Jan 2016 07:26:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=EYuJSeTnovb+GD0Waze5zZeE/0h1yVHj4OvtWEiE2d0=; b=hAczfocGaPJIz4Z4LGvLjelixv8bRJVm4JIMyhPcu0yVILTChdAly0yXDZeyLBR0ez sR0UOhkNdzSSI/RbZFkG7ZtDjVOakm2i1l9eDv3A0tC8TOrrIDexQtWKyjjxLI3okj1q 7q0X4DO9TqaEJWw5kzr7xb22A8jpB/my1fzmUAldChpLok7T1VBnwHuprjhTp10246H6 Iov2ZLdDtTaBo3q1Oe8pUDDT0nSZS8+XhH26Bu740/+a/6xC1TIM5kjDLtzQkjYqTm5T xM+Kys/BgghUXU4M6LQuqBkw3w0F+ZXt3MXetNAkSVMr0FNp1A33x1yo4+i8jHI9Vrb9 KLfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=EYuJSeTnovb+GD0Waze5zZeE/0h1yVHj4OvtWEiE2d0=; b=iuCVBKBE5UDQ7LhrOOcAVBwdFeOrxnjsjPIdP1u+A/P0EZIjnBrxJtJ+dzYRpq/Gvw DLimEHa1blVoumAiB/KPy9ctiyVZ2L0hjFQ/8I1Q4Vh6KJYjhhGEW3j5ZBBg4kiHzjTl GqxK4kMjr2rgsT7/DMT7Nzb6Wp3KNV2K2SchrV7ByqnE5xfIq9JFwa+aj0IEXQkZW3m0 vAkiNAa+nzu1dnt91RxY/ze9FD2DrXS94DnnE5N7Ztmhx48Oa9xd2dpkkRZFHVNDZ784 N24FNns72pkuqXl0aXHRPkpJ7De0cMRAXOSDh3yph2qhAdMaPMXfYs+rTLiQaH1cnZ7v aULA== X-Gm-Message-State: ALoCoQnzQUyoac0xkzpV29md8Y8ai6eACzbug0K2hGi/okyggVpH4Ji7oONZ5g0qE8bSKuluu8LXilma4US4L0kBaWey+3figg== X-Received: by 10.194.109.2 with SMTP id ho2mr29396288wjb.66.1453130818343; Mon, 18 Jan 2016 07:26:58 -0800 (PST) Received: from debian.flybox.orange ([154.122.88.181]) by smtp.googlemail.com with ESMTPSA id t3sm24381762wjz.11.2016.01.18.07.26.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Jan 2016 07:26:57 -0800 (PST) From: David Kiarie To: qemu-devel@nongnu.org Date: Mon, 18 Jan 2016 18:25:45 +0300 Message-Id: <1453130745-25793-5-git-send-email-davidkiarie4@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1453130745-25793-1-git-send-email-davidkiarie4@gmail.com> References: <1453130745-25793-1-git-send-email-davidkiarie4@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::242 Cc: mst@redhat.com, crosthwaitepeter@gmail.com, valentine.sinitsyn@gmail.com, jan.kiszka@web.de, marcel@redhat.com, David Kiarie Subject: [Qemu-devel] [V4 4/4] hw/pci-host: Emulate AMD IO MMU X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Support AMD IO MMU emulation in q35 and piix chipsets Signed-off-by: David Kiarie --- hw/pci-host/piix.c | 11 +++++++++++ hw/pci-host/q35.c | 14 ++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/hw/pci-host/piix.c b/hw/pci-host/piix.c index b0d7e31..3ba245d 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..0c60e3c 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,9 +506,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); } }