From patchwork Fri May 5 14:00:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oza Pawandeep X-Patchwork-Id: 9713627 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 B3F1960362 for ; Fri, 5 May 2017 14:01:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD4CE286A0 for ; Fri, 5 May 2017 14:01:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A1F37286BB; Fri, 5 May 2017 14:01:32 +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 3527B286A0 for ; Fri, 5 May 2017 14:01:32 +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=cpzunqFecynaNj8RB3NsaKoWmi NlAR5dUOuA2MoK9by6m5JwWCrnHATmV0XpWZRjBheaNsoj7imEf+j2o6o+yBQR6klaoAuxJ8uZ1g1 asCoMIzDTef2GS5LK0T3+0YlVLcCVIp8UbL/3fHCMeJLyYY7ZDAVHRXdZa7a5NUhkPxq11V6Ck2nb beD6tMxkcUSOzwwQIfvpI6gtMtlId9kO84qvglXo5W33uYf6fKtW56cPx9zHpGFelf8sH4i44wuv9 C58xC0uzcjgKF3mtlQG6CU61uMqepOnx6Nlc79hI4WN1yNC7iOVvnczXDImOs86MnFfctdefUrNvG Yzb6aODA==; 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 1d6dnX-0002Ju-AD; Fri, 05 May 2017 14:01:31 +0000 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d6dnH-0001ms-8l for linux-arm-kernel@lists.infradead.org; Fri, 05 May 2017 14:01:19 +0000 Received: by mail-wm0-x236.google.com with SMTP id w64so24794251wma.0 for ; Fri, 05 May 2017 07:00:54 -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=V1QWID8nibhQI3VQpkoNx82MnOm44fwjDpIt8xlHGwBERllguoomasFJW2IO/nz+3f Ti27Fp1wy7MjVfIgFOHHPjSl1kfS1bp1fFKAf/AAYoa+VcmQ6qZDwPb1sZt5nGcfe9Og yMKNR9/tRyu6TEkXJWuz1grXjEri/ZrNYwmOc= 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=uQ7ISmW/45SEbAbE94t0IXVXZelmFeYTw5fPhSSeqcnNjnxJqpObw4j4nMenXwkFiA iqiQT4jw7G8pg8eG/kMwV6DIN3DFsH/CrEk7RlHhO6Wq2RzVEDD7Gpd0tARS9FdpqjDM PMixOnFGroPVIS7MkRqtn9/bpesQze54DK5LyX3vCrrRJuuUOwC+web5/r5oBODt0THN rBc3PScac3LpuDpO6+b6634CEhrmIuhyZSCIOgN/CtSSWXIAsABZkbWUkVTCfAm8Ab5A 4n5/0CTZmSwc74cl7tU4LXR6jfON9y/SBmLVruOp1hfbZF9JszVqCUhsKA7CZz6DWg53 qAig== X-Gm-Message-State: AODbwcDxdtujYEQuWUgwjztEHjG4upHwS3l4vnUzyJWFy8R3olQ0o7cP V4D2KubZAnJEe/iy X-Received: by 10.28.158.212 with SMTP id h203mr5770813wme.139.1493992853381; Fri, 05 May 2017 07:00:53 -0700 (PDT) Received: from anjanavk-OptiPlex-7010.dhcp.avagotech.net ([192.19.237.250]) by smtp.gmail.com with ESMTPSA id 188sm2264174wmf.29.2017.05.05.07.00.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 05 May 2017 07:00:52 -0700 (PDT) From: Oza Pawandeep To: Joerg Roedel , Robin Murphy Subject: [PATCH v5 2/3] iommu/pci: reserve IOVA for PCI masters Date: Fri, 5 May 2017 19:30:26 +0530 Message-Id: <1493992827-1553-3-git-send-email-oza.oza@broadcom.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493992827-1553-1-git-send-email-oza.oza@broadcom.com> References: <1493992827-1553-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_070115_583556_634C825C 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); + } + } } /**