From patchwork Wed May 3 04:46:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oza Pawandeep X-Patchwork-Id: 9708861 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E36BF60351 for ; Wed, 3 May 2017 04:47:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DBEAF285E9 for ; Wed, 3 May 2017 04:47:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D091A285EE; Wed, 3 May 2017 04:47:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7B4CA285E9 for ; Wed, 3 May 2017 04:47:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Roh2M4AtRuWZMhXpJAaqAgb58zx3LfMQJYo7ldtaT80=; b=dH1H8U02mcfDbPmoKg1/unvp6G msxYUfQJgf3ovnXEkxmS7bExSwoGrmBq39s8supBfwmywJNADeGpwxaQsOjeBHOZaF2+RCmf8llpS RLDjojnuLkr1qoVMnNjlzclHxSMi1XBzWUxMSyfoE8DcfXwATzYeIgexMFOjn5o7mDKKA0IF0MTkE EEn3oXzvgeneNWlID7r329sOaambC1RSLYDfLSV1zsuz7JGwQJ56h4FLPjJan2lY9qIQnZs4BRG8h qWTblptqS8AM1rM5GVBRtJfLBg9G6jsueS0pIIqpaswYVkK5K51MHTH/KUqCTecq45H9kTLfcDM7V hLB5HclQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1d5mC3-00026d-OX; Wed, 03 May 2017 04:47:15 +0000 Received: from mail-pf0-x233.google.com ([2607:f8b0:400e:c00::233]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d5mBx-0001uM-8i for linux-arm-kernel@lists.infradead.org; Wed, 03 May 2017 04:47:12 +0000 Received: by mail-pf0-x233.google.com with SMTP id q66so6978073pfi.3 for ; Tue, 02 May 2017 21:46:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Ic1WyvhKO908Duh68nquV+ykhEzmaaTA14e0vxdZr0M=; b=NDqlK/sgARqTAUhsL61bRjFs+bQFPimhAGx7OhM7igNpLQgY5vrXJaPKpYWDndsRH9 PZNFYv0mSrMlTtrjcYs+sQ2G4A3LEszfsJ3uYZhyU9X0vWN5Gb5ybY8KAie/jzHIEosg 4sT5pYkwzU/Ftl4hEwDNeT1HNrce4o23rluPI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Ic1WyvhKO908Duh68nquV+ykhEzmaaTA14e0vxdZr0M=; b=sh95pAvpjpZUK5SsP/tyJmLqYwzGolBPHsLCmaTqX2Y3aB9yeapKdiDgOO9DDsJRpq 8OkPdwJN2lbpzg7axhT3unsdd4qWA7bQBg6KdfZ/PGMQQzO+rebzqU5nWXlqyMsx7LoU rogoAGellGtPM3w3GPSIw06Nh5aV3dPLoMLCTf0hoWfm0P3oX9cljp70ZaaI2YdI+jxL 5nL0sal+LXzYK57IxK6nTVy5pESk4Gi8O15L6vM7TzjUeEZv4WcRuSyyVR8KJH2XSpj0 JaWC/rFiZIu3tYP2CDRGXcbWVub7SWvi+jyBDT9ca0c1MBI+SJEOIUESUy56Ot4J4r6a WlDA== X-Gm-Message-State: AN3rC/4wkf/H6EwsBYnbIIEeo+4a0gWnWxBf6dhEJL0KAdZo0fcrMp0t H2F2lALlzzriMyuJ X-Received: by 10.99.171.15 with SMTP id p15mr37135148pgf.121.1493786808457; Tue, 02 May 2017 21:46:48 -0700 (PDT) Received: from anjanavk-OptiPlex-7010.dhcp.avagotech.net ([192.19.237.250]) by smtp.gmail.com with ESMTPSA id 83sm1614963pfu.106.2017.05.02.21.46.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 May 2017 21:46:47 -0700 (PDT) From: Oza Pawandeep To: Joerg Roedel , Robin Murphy Subject: [PATCH 2/3] iommu/pci: reserve iova for PCI masters Date: Wed, 3 May 2017 10:16:34 +0530 Message-Id: <1493786795-28153-2-git-send-email-oza.oza@broadcom.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493786795-28153-1-git-send-email-oza.oza@broadcom.com> References: <1493786795-28153-1-git-send-email-oza.oza@broadcom.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170502_214709_500939_71CF6259 X-CRM114-Status: GOOD ( 13.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Oza Pawandeep , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, bcm-kernel-feedback-list@broadcom.com, Oza Pawandeep , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP this patch reserves the iova for PCI masters. ARM64 based SOCs may have scattered memory banks. such as iproc based SOC has <0x00000000 0x80000000 0x0 0x80000000>, /* 2G @ 2G */ <0x00000008 0x80000000 0x3 0x80000000>, /* 14G @ 34G */ <0x00000090 0x00000000 0x4 0x00000000>, /* 16G @ 576G */ <0x000000a0 0x00000000 0x4 0x00000000>; /* 16G @ 640G */ but incoming PCI transcation addressing capability is limited by host bridge, for example if max incoming window capability is 512 GB, then 0x00000090 and 0x000000a0 will fall beyond it. to address this problem, iommu has to avoid allocating iovas which are reserved. which inturn does not allocate iova if it falls into hole. Bug: SOC-5216 Change-Id: Icbfc99a045d730be143fef427098c937b9d46353 Signed-off-by: Oza Pawandeep Reviewed-on: http://gerrit-ccxsw.broadcom.net/40760 Reviewed-by: vpx_checkpatch status Reviewed-by: CCXSW Tested-by: vpx_autobuild status Tested-by: vpx_smoketest status Tested-by: CCXSW Reviewed-by: Scott Branden diff --git a/drivers/iommu/dma-iommu.c b/drivers/iommu/dma-iommu.c index 48d36ce..08764b0 100644 --- a/drivers/iommu/dma-iommu.c +++ b/drivers/iommu/dma-iommu.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -171,8 +172,12 @@ static void iova_reserve_pci_windows(struct pci_dev *dev, struct iova_domain *iovad) { struct pci_host_bridge *bridge = pci_find_host_bridge(dev->bus); + struct device_node *np = bridge->dev.parent->of_node; struct resource_entry *window; unsigned long lo, hi; + int ret; + dma_addr_t tmp_dma_addr = 0, dma_addr; + LIST_HEAD(res); resource_list_for_each_entry(window, &bridge->windows) { if (resource_type(window->res) != IORESOURCE_MEM && @@ -183,6 +188,36 @@ static void iova_reserve_pci_windows(struct pci_dev *dev, hi = iova_pfn(iovad, window->res->end - window->offset); reserve_iova(iovad, lo, hi); } + + /* PCI inbound memory reservation. */ + ret = of_pci_get_dma_ranges(np, &res); + if (!ret) { + resource_list_for_each_entry(window, &res) { + struct resource *res_dma = window->res; + + dma_addr = res_dma->start - window->offset; + if (tmp_dma_addr > dma_addr) { + pr_warn("PCI: failed to reserve iovas; ranges should be sorted\n"); + return; + } + if (tmp_dma_addr != dma_addr) { + lo = iova_pfn(iovad, tmp_dma_addr); + hi = iova_pfn(iovad, dma_addr - 1); + reserve_iova(iovad, lo, hi); + } + tmp_dma_addr = window->res->end - window->offset; + } + /* + * the last dma-range should honour based on the + * 32/64-bit dma addresses. + */ + if (tmp_dma_addr < DMA_BIT_MASK(sizeof(dma_addr_t) * 8)) { + lo = iova_pfn(iovad, tmp_dma_addr); + hi = iova_pfn(iovad, + DMA_BIT_MASK(sizeof(dma_addr_t) * 8) - 1); + reserve_iova(iovad, lo, hi); + } + } } /**