From patchwork Tue Jun 21 07:47:31 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 638538 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3rYg3G1KCCz9sxb for ; Tue, 21 Jun 2016 17:54:02 +1000 (AEST) Received: from localhost ([::1]:49484 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFGVU-0000vw-20 for incoming@patchwork.ozlabs.org; Tue, 21 Jun 2016 03:54:00 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60673) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFGQ3-0003BD-Nz for qemu-devel@nongnu.org; Tue, 21 Jun 2016 03:48:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bFGQ0-0003HP-Kz for qemu-devel@nongnu.org; Tue, 21 Jun 2016 03:48:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46881) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bFGQ0-0003Eo-CE for qemu-devel@nongnu.org; Tue, 21 Jun 2016 03:48:20 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A854080082; Tue, 21 Jun 2016 07:48:17 +0000 (UTC) Received: from pxdev.xzpeter.org (vpn1-6-130.pek2.redhat.com [10.72.6.130]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u5L7luxB018693; Tue, 21 Jun 2016 03:48:12 -0400 From: Peter Xu To: qemu-devel@nongnu.org Date: Tue, 21 Jun 2016 15:47:31 +0800 Message-Id: <1466495274-5011-4-git-send-email-peterx@redhat.com> In-Reply-To: <1466495274-5011-1-git-send-email-peterx@redhat.com> References: <1466495274-5011-1-git-send-email-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 21 Jun 2016 07:48:17 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v10 03/26] x86-iommu: q35: generalize find_add_as() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ehabkost@redhat.com, mst@redhat.com, jasowang@redhat.com, rkrcmar@redhat.com, peterx@redhat.com, alex.williamson@redhat.com, jan.kiszka@web.de, wexu@redhat.com, pbonzini@redhat.com, marcel@redhat.com, imammedo@redhat.com, davidkiarie4@gmail.com, rth@twiddle.net Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Remove VT-d calls in common q35 codes. Instead, we provide a general find_add_as() for x86-iommu type. Signed-off-by: Peter Xu --- hw/i386/intel_iommu.c | 17 +++++++++-------- include/hw/i386/intel_iommu.h | 5 ----- include/hw/i386/x86-iommu.h | 3 +++ 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c index 1936c41..b487224 100644 --- a/hw/i386/intel_iommu.c +++ b/hw/i386/intel_iommu.c @@ -1900,8 +1900,10 @@ static Property vtd_properties[] = { }; -VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s, PCIBus *bus, int devfn) +static AddressSpace *vtd_find_add_as(X86IOMMUState *x86_iommu, PCIBus *bus, + int devfn) { + IntelIOMMUState *s = (IntelIOMMUState *)x86_iommu; uintptr_t key = (uintptr_t)bus; VTDBus *vtd_bus = g_hash_table_lookup(s->vtd_as_by_busptr, &key); VTDAddressSpace *vtd_dev_as; @@ -1929,7 +1931,7 @@ VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s, PCIBus *bus, int devfn) address_space_init(&vtd_dev_as->as, &vtd_dev_as->iommu, "intel_iommu"); } - return vtd_dev_as; + return &vtd_dev_as->as; } /* Do the initialization. It will also be called when reset, so pay @@ -2021,13 +2023,11 @@ static void vtd_reset(DeviceState *dev) static AddressSpace *vtd_host_dma_iommu(PCIBus *bus, void *opaque, int devfn) { - IntelIOMMUState *s = opaque; - VTDAddressSpace *vtd_as; - - assert(0 <= devfn && devfn <= VTD_PCI_DEVFN_MAX); + X86IOMMUState *x86_iommu = opaque; + X86IOMMUClass *x86_class = X86_IOMMU_GET_CLASS(x86_iommu); - vtd_as = vtd_find_add_as(s, bus, devfn); - return &vtd_as->as; + assert(0 <= devfn && devfn <= X86_IOMMU_PCI_DEVFN_MAX); + return x86_class->find_add_as(x86_iommu, bus, devfn); } static void vtd_realize(DeviceState *dev, Error **errp) @@ -2060,6 +2060,7 @@ static void vtd_class_init(ObjectClass *klass, void *data) dc->vmsd = &vtd_vmstate; dc->props = vtd_properties; x86_class->realize = vtd_realize; + x86_class->find_add_as = vtd_find_add_as; } static const TypeInfo vtd_info = { diff --git a/include/hw/i386/intel_iommu.h b/include/hw/i386/intel_iommu.h index 0794309..e36b896 100644 --- a/include/hw/i386/intel_iommu.h +++ b/include/hw/i386/intel_iommu.h @@ -125,9 +125,4 @@ struct IntelIOMMUState { VTDBus *vtd_as_by_bus_num[VTD_PCI_BUS_MAX]; /* VTDBus objects indexed by bus number */ }; -/* Find the VTD Address space associated with the given bus pointer, - * create a new one if none exists - */ -VTDAddressSpace *vtd_find_add_as(IntelIOMMUState *s, PCIBus *bus, int devfn); - #endif diff --git a/include/hw/i386/x86-iommu.h b/include/hw/i386/x86-iommu.h index d6991cb..2070cd1 100644 --- a/include/hw/i386/x86-iommu.h +++ b/include/hw/i386/x86-iommu.h @@ -21,6 +21,7 @@ #define IOMMU_COMMON_H #include "hw/sysbus.h" +#include "exec/memory.h" #define TYPE_X86_IOMMU_DEVICE ("x86-iommu") #define X86_IOMMU_DEVICE(obj) \ @@ -40,6 +41,8 @@ struct X86IOMMUClass { SysBusDeviceClass parent; /* Intel/AMD specific realize() hook */ DeviceRealize realize; + /* Find/Add IOMMU address space for specific PCI device */ + AddressSpace *(*find_add_as)(X86IOMMUState *s, PCIBus *bus, int devfn); }; struct X86IOMMUState {