From patchwork Mon Mar 21 07:46:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 8630001 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 31B9F9F36E for ; Mon, 21 Mar 2016 07:49:06 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8888320270 for ; Mon, 21 Mar 2016 07:49:05 +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 C29F32021B for ; Mon, 21 Mar 2016 07:49:04 +0000 (UTC) Received: from localhost ([::1]:56038 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahuaG-0004dm-8O for patchwork-qemu-devel@patchwork.kernel.org; Mon, 21 Mar 2016 03:49:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34929) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahuZn-0004H6-Jt for qemu-devel@nongnu.org; Mon, 21 Mar 2016 03:48:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ahuZl-0001tF-51 for qemu-devel@nongnu.org; Mon, 21 Mar 2016 03:48:35 -0400 Received: from e23smtp09.au.ibm.com ([202.81.31.142]:53672) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ahuZk-0001sK-J2 for qemu-devel@nongnu.org; Mon, 21 Mar 2016 03:48:33 -0400 Received: from localhost by e23smtp09.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 21 Mar 2016 17:48:29 +1000 Received: from d23dlp02.au.ibm.com (202.81.31.213) by e23smtp09.au.ibm.com (202.81.31.206) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 21 Mar 2016 17:48:26 +1000 X-IBM-Helo: d23dlp02.au.ibm.com X-IBM-MailFrom: aik@ozlabs.ru X-IBM-RcptTo: qemu-devel@nongnu.org;qemu-ppc@nongnu.org Received: from d23relay09.au.ibm.com (d23relay09.au.ibm.com [9.185.63.181]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 940772BB005B; Mon, 21 Mar 2016 18:48:21 +1100 (EST) Received: from d23av04.au.ibm.com (d23av04.au.ibm.com [9.190.235.139]) by d23relay09.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u2L7m0bO57344246; Mon, 21 Mar 2016 18:48:21 +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 u2L7laFD029078; Mon, 21 Mar 2016 18:47:36 +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 u2L7latb028149; Mon, 21 Mar 2016 18:47:36 +1100 Received: from bran.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114]) by ozlabs.au.ibm.com (Postfix) with ESMTP id 0A0E3A01D5; Mon, 21 Mar 2016 18:47:09 +1100 (AEDT) Received: from vpl2.ozlabs.ibm.com (vpl2.ozlabs.ibm.com [10.61.141.27]) by bran.ozlabs.ibm.com (Postfix) with ESMTP id 075D8E39B3; Mon, 21 Mar 2016 18:47:09 +1100 (AEDT) From: Alexey Kardashevskiy To: qemu-devel@nongnu.org Date: Mon, 21 Mar 2016 18:46:51 +1100 Message-Id: <1458546426-26222-4-git-send-email-aik@ozlabs.ru> X-Mailer: git-send-email 2.5.0.rc3 In-Reply-To: <1458546426-26222-1-git-send-email-aik@ozlabs.ru> References: <1458546426-26222-1-git-send-email-aik@ozlabs.ru> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16032107-0033-0000-0000-0000055001C2 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 202.81.31.142 Cc: Alexey Kardashevskiy , Alex Williamson , qemu-ppc@nongnu.org, David Gibson Subject: [Qemu-devel] [PATCH qemu v14 03/18] spapr_pci: Move DMA window enablement to a helper 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.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable 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 We are going to have multiple DMA windows soon so let's start preparing. This adds a new helper to create a DMA window and makes use of it in sPAPRPHBState::realize(). Signed-off-by: Alexey Kardashevskiy Reviewed-by: David Gibson --- Changes: v14: * replaced "int" return to Error* in spapr_phb_dma_window_enable() --- hw/ppc/spapr_pci.c | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 79baa7b..18332bf 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -803,6 +803,33 @@ static char *spapr_phb_get_loc_code(sPAPRPHBState *sphb, PCIDevice *pdev) return buf; } +static void spapr_phb_dma_window_enable(sPAPRPHBState *sphb, + uint32_t liobn, + uint32_t page_shift, + uint64_t window_addr, + uint64_t window_size, + Error **errp) +{ + sPAPRTCETable *tcet; + uint32_t nb_table = window_size >> page_shift; + + if (!nb_table) { + error_setg(errp, "Zero size table"); + return; + } + + tcet = spapr_tce_new_table(DEVICE(sphb), liobn, window_addr, + page_shift, nb_table, false); + if (!tcet) { + error_setg(errp, "Unable to create TCE table liobn %x for %s", + liobn, sphb->dtbusname); + return; + } + + memory_region_add_subregion(&sphb->iommu_root, tcet->bus_offset, + spapr_tce_get_iommu(tcet)); +} + /* Macros to operate with address in OF binding to PCI */ #define b_x(x, p, l) (((x) & ((1<<(l))-1)) << (p)) #define b_n(x) b_x((x), 31, 1) /* 0 if relocatable */ @@ -1307,8 +1334,7 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp) int i; PCIBus *bus; uint64_t msi_window_size = 4096; - sPAPRTCETable *tcet; - uint32_t nb_table; + Error *local_err = NULL; if (sphb->index != (uint32_t)-1) { hwaddr windows_base; @@ -1460,18 +1486,13 @@ static void spapr_phb_realize(DeviceState *dev, Error **errp) } } - nb_table = sphb->dma_win_size >> SPAPR_TCE_PAGE_SHIFT; - tcet = spapr_tce_new_table(DEVICE(sphb), sphb->dma_liobn, - 0, SPAPR_TCE_PAGE_SHIFT, nb_table, false); - if (!tcet) { - error_setg(errp, "Unable to create TCE table for %s", - sphb->dtbusname); - return; - } - /* Register default 32bit DMA window */ - memory_region_add_subregion(&sphb->iommu_root, sphb->dma_win_addr, - spapr_tce_get_iommu(tcet)); + spapr_phb_dma_window_enable(sphb, sphb->dma_liobn, SPAPR_TCE_PAGE_SHIFT, + sphb->dma_win_addr, sphb->dma_win_size, + &local_err); + if (local_err) { + error_propagate(errp, local_err); + } sphb->msi = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, g_free); }