From patchwork Fri May 5 13:47:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oza Pawandeep X-Patchwork-Id: 9713635 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 BD9076034B for ; Fri, 5 May 2017 14:11:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB60E28691 for ; Fri, 5 May 2017 14:11:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AF560286BB; Fri, 5 May 2017 14:11:26 +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 A418628691 for ; Fri, 5 May 2017 14:11:25 +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=MpQfRyLFXkCMjfcOHRPzcQOGNyqB2OoG1I20AKdHcvk=; b=mqYJgLuhCB5SNVhrNGSqIfMl78 3cN0NZXiEowogVFJWGXkj0cntOC5CDTEV+4o+KxlkiLTlKKT82H3DeZZ7erH2VBG9CEF9JKLMfsZ1 4vI4TgTvSSLRDu2U+37rdsSv+0S9gyj5RZwfjbm0mlfXkXUleQEnzsf+dumdNpV77CP4GewKp231q re3ppp+B5mm4RIDsLbP6XhFOfklX6Hw5XIwDs2Ke4+g9X7OXvtYObkFGDwimm4k64bnKKMcswkeUp hGztRMGY2/xmJIVNybL38A8MsVyZ0DquGUNi6m4dUNw4VE/82UZiSLtoDlRJSMh/kcFms54DT2cbs pR0R5jQg==; 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 1d6dwv-0007VQ-GR; Fri, 05 May 2017 14:11:13 +0000 Received: from mail-wm0-x22a.google.com ([2a00:1450:400c:c09::22a]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d6daX-0002jH-QG for linux-arm-kernel@lists.infradead.org; Fri, 05 May 2017 13:48:09 +0000 Received: by mail-wm0-x22a.google.com with SMTP id m123so6901923wma.0 for ; Fri, 05 May 2017 06:47:45 -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=1RCSD1k10sHTXjN2JnPBku868qtEqKI+6iwQ82iuCuY=; b=SLvAcGvgz7HmsRIhemT7n/SZnB035wzWHHPgbfkp8XMsiI4fcMb4vaC/5P1CiVafol xPFvpUYVLtAhukf3n5T2Au4cV8fa1mvc+rxmDSpdlGiijx8VpO7yMi+ilIAELA8LGRQ5 GIOaQeK6+dImOJU4NAsPvWp4ulb62kVOyrwcs= 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=1RCSD1k10sHTXjN2JnPBku868qtEqKI+6iwQ82iuCuY=; b=c4BNVRf94niHx0X6IuIaNallgPCkgpG/yUvtTTtE02sBd9MTV8aCDv1gYoWRpPcEfL s+C8r7f9UVuaaEaGsqe/PYc41/39GWwhxrzMPWjFB1kOmsKR75NQeJoPpAkKF+BCcNo4 PUkOk/AkM8hyz1POE7p9DJ5miPUgp7zzdt9Cf7Om7egVhQ8HqYhxvzUuHi4I2tfPD0We MJEoy6ihvlHOsIUUsgROY6MjjLN6URL1OG87bgYa7NMiyHyomr2qVCCg+ZOMi4aVaVQq SG9YjtXlYvrX1w0oh5+V6r58nT1i7Qm6E9RK3XMt8LONqBVRXjkipVfLLNY15hYhXd++ lXKg== X-Gm-Message-State: AODbwcCpVFuq1WSyYJ8m3vRaRgE33A4OuVjDR4vekw38lngllX6HY1lt o17asiL024PuG/5X X-Received: by 10.28.186.196 with SMTP id k187mr2007570wmf.80.1493992063880; Fri, 05 May 2017 06:47:43 -0700 (PDT) Received: from anjanavk-OptiPlex-7010.dhcp.avagotech.net ([192.19.237.250]) by smtp.gmail.com with ESMTPSA id f64sm2153673wmg.2.2017.05.05.06.47.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 05 May 2017 06:47:43 -0700 (PDT) From: Oza Pawandeep To: Joerg Roedel , Robin Murphy Subject: [PATCH v4 2/3] iommu/pci: reserve IOVA for PCI masters Date: Fri, 5 May 2017 19:17:19 +0530 Message-Id: <1493992040-31222-3-git-send-email-oza.oza@broadcom.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493992040-31222-1-git-send-email-oza.oza@broadcom.com> References: <1493992040-31222-1-git-send-email-oza.oza@broadcom.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170505_064806_215991_323302BF X-CRM114-Status: GOOD ( 13.18 ) 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 IOVA which are reserved. which inturn does not allocate IOVA if it falls into hole. Signed-off-by: Oza Pawandeep 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); + } + } } /**