From patchwork Tue Mar 31 05:28:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 456509 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 374DF140187 for ; Tue, 31 Mar 2015 16:36:53 +1100 (AEDT) Received: from localhost ([::1]:37029 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ycor5-0006hg-Cv for incoming@patchwork.ozlabs.org; Tue, 31 Mar 2015 01:36:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43866) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ycokv-0004Nw-5D for qemu-devel@nongnu.org; Tue, 31 Mar 2015 01:30:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ycokn-0007oo-4U for qemu-devel@nongnu.org; Tue, 31 Mar 2015 01:30:29 -0400 Received: from e23smtp01.au.ibm.com ([202.81.31.143]:58363) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ycokl-0007ld-Jp for qemu-devel@nongnu.org; Tue, 31 Mar 2015 01:30:21 -0400 Received: from /spool/local by e23smtp01.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 31 Mar 2015 15:30:17 +1000 Received: from d23dlp03.au.ibm.com (202.81.31.214) by e23smtp01.au.ibm.com (202.81.31.207) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 31 Mar 2015 15:30:14 +1000 Received: from d23relay10.au.ibm.com (d23relay10.au.ibm.com [9.190.26.77]) by d23dlp03.au.ibm.com (Postfix) with ESMTP id 971683578053; Tue, 31 Mar 2015 16:30:13 +1100 (EST) Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay10.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id t2V5U5UR49414368; Tue, 31 Mar 2015 16:30:13 +1100 Received: from d23av04.au.ibm.com (localhost [127.0.0.1]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id t2V5TdhO026335; Tue, 31 Mar 2015 16:29:40 +1100 Received: from ozlabs.au.ibm.com (ozlabs.au.ibm.com [9.192.253.14]) by d23av04.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id t2V5TdV8025788; Tue, 31 Mar 2015 16:29:39 +1100 Received: from bran.ozlabs.ibm.com (haven.au.ibm.com [9.192.253.15]) by ozlabs.au.ibm.com (Postfix) with ESMTP id 24CB2A03DD; Tue, 31 Mar 2015 16:28:57 +1100 (AEDT) Received: from ka1.ozlabs.ibm.com (ka1.ozlabs.ibm.com [10.61.145.11]) by bran.ozlabs.ibm.com (Postfix) with ESMTP id 6E9AE16A9E5; Tue, 31 Mar 2015 16:28:56 +1100 (AEDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Tue, 31 Mar 2015 16:28:44 +1100 Message-Id: <1427779727-13353-10-git-send-email-aik@ozlabs.ru> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1427779727-13353-1-git-send-email-aik@ozlabs.ru> References: <1427779727-13353-1-git-send-email-aik@ozlabs.ru> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 15033105-1618-0000-0000-000001D6E7D3 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 202.81.31.143 Cc: Alexey Kardashevskiy , Alex Williamson , qemu-ppc@nongnu.org, Alexander Graf , David Gibson Subject: [Qemu-devel] [PATCH qemu v5 09/12] spapr_iommu: Add root memory region 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org We are going to have multiple DMA windows at different offsets on a PCI bus. For the sake of migration, we will have as many TCE table objects pre-created as many windows supported. So we need a way to map windows dynamically onto a PCI bus when migration of a table is completed but at this stage a TCE table object does not have access to a PHB to ask it to map a DMA window backed by just migrated TCE table. This adds a "root" memory region (UINT64_MAX long) to the TCE object. This new region is mapped on a PCI bus with enabled overlapping as there will be one root MR per TCE table, each of them mapped at 0. The actual IOMMU memory region is a subregion of the root region and a TCE table enables/disables this subregion and maps it at the specific offset inside the root MR which is 1:1 mapping of a PCI address space. Signed-off-by: Alexey Kardashevskiy --- hw/ppc/spapr_iommu.c | 9 ++++++++- include/hw/ppc/spapr.h | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c index a015357..d880818 100644 --- a/hw/ppc/spapr_iommu.c +++ b/hw/ppc/spapr_iommu.c @@ -150,6 +150,8 @@ sPAPRTCETable *spapr_tce_new_table(DeviceState *owner, uint32_t liobn) tcet->liobn = liobn; snprintf(tmp, sizeof(tmp), "tce-table-%x", liobn); + memory_region_init(&tcet->root, OBJECT(tcet), tmp, UINT64_MAX); + object_property_add_child(OBJECT(owner), tmp, OBJECT(tcet), NULL); object_property_set_bool(OBJECT(tcet), true, "realized", NULL); @@ -200,6 +202,8 @@ void spapr_tce_table_enable(sPAPRTCETable *tcet) "iommu-spapr", (uint64_t)tcet->nb_table << tcet->page_shift); + memory_region_add_subregion(&tcet->root, tcet->bus_offset, &tcet->iommu); + tcet->enabled = true; } @@ -209,6 +213,8 @@ void spapr_tce_table_disable(sPAPRTCETable *tcet) return; } + memory_region_del_subregion(&tcet->root, &tcet->iommu); + if (!kvm_enabled() || (kvmppc_remove_spapr_tce(tcet->table, tcet->fd, tcet->nb_table) != 0)) { @@ -216,6 +222,7 @@ void spapr_tce_table_disable(sPAPRTCETable *tcet) g_free(tcet->table); } tcet->table = NULL; + object_unref(OBJECT(&tcet->iommu)); tcet->enabled = false; spapr_tce_set_props(tcet, 0, 0, 0, false); } @@ -231,7 +238,7 @@ static void spapr_tce_table_unrealize(DeviceState *dev, Error **errp) MemoryRegion *spapr_tce_get_iommu(sPAPRTCETable *tcet) { - return &tcet->iommu; + return &tcet->root; } static void spapr_tce_reset(DeviceState *dev) diff --git a/include/hw/ppc/spapr.h b/include/hw/ppc/spapr.h index 6e33b9b..5a45c3f 100644 --- a/include/hw/ppc/spapr.h +++ b/include/hw/ppc/spapr.h @@ -507,7 +507,7 @@ struct sPAPRTCETable { bool bypass; bool vfio_accel; int fd; - MemoryRegion iommu; + MemoryRegion root, iommu; struct VIOsPAPRDevice *vdev; /* for @bypass migration compatibility only */ QLIST_ENTRY(sPAPRTCETable) list; };