From patchwork Thu Mar 30 09:59:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oza Pawandeep X-Patchwork-Id: 9653497 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 DAC916034C for ; Thu, 30 Mar 2017 10:00:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CEFDB28585 for ; Thu, 30 Mar 2017 10:00:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2F682858A; Thu, 30 Mar 2017 10:00:54 +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=ham 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 53E7A28585 for ; Thu, 30 Mar 2017 10:00:54 +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=BfngNprgBuK27H1xWyM/pY2F8u6yTvJ/Sut2//+q1Zg=; b=pQh9AGHfry/4CiulKXzpTzr7Gq ItWlVC3qqn+g4+sSr2K/LzP6O+QueYYJe058k+8e0tm94AzNCbxV4/8r9FYQxc/kVQ9cZ9VlZCj+i our+XvxW/Gb9hqHBysrM6KRGaZM8cWTxZAifF5YP2Zrs/XaNAP8rnHH+l6JU0FB4Nkt1vZjbd8aWg F38CtYDI9AHH4ICrDGXlJo0RFThcyX3QVZGooohUPL62ayjJAF4ezXfnA9dvN2QTbI6jw7D/tySwn 7yJ0S1icIEie+1BmU1olrI2Ug9G7aWdvUIl500SIx7VIktL/wjiSS/Uevg4Q8uoJ1g7SzwmJQT+/t 5q4fBHMQ==; 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 1ctWst-0006T1-Bz; Thu, 30 Mar 2017 10:00:51 +0000 Received: from mail-wr0-x231.google.com ([2a00:1450:400c:c0c::231]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ctWsc-00068L-Ro for linux-arm-kernel@lists.infradead.org; Thu, 30 Mar 2017 10:00:42 +0000 Received: by mail-wr0-x231.google.com with SMTP id w43so52993016wrb.0 for ; Thu, 30 Mar 2017 03:00:14 -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=2QwocwBDUZm6NlkRo1c/u97L7qBDqUm4XRWS6sxoWRU=; b=F+aXExOO7AXFA+waiDew65cXZtr8XEkIeWRsnQA1PTNFDUmfYFvD1hBKl3H/T6BhIc fzE7XrlqdegXnuEFgyyZxyXYfOyAEgGcFiYKHIHSDFvMPk054ttePEYKICwkcVCoMcIT uJr9lhxk+aSKGwJHi+in9614T7f7gb4/CV420= 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=2QwocwBDUZm6NlkRo1c/u97L7qBDqUm4XRWS6sxoWRU=; b=J0dxE6t99eaaPMU+8A4lOdS7K1d9RBOwnLYqqaPRxHlkMLBevTlEAM3fimPClPgDjv u2XDfAykWWIhzuNFXMPphhSZwdu8fBZjbjR6hkIU+S3K/EIcOwA2rbRx8/wmC9bvZOAZ ibAOPQCEZgFhuPIj5DhgOCYRXSrVej2jpAG1aAQngKXQX6RQbUbwSpBkmbCJIR4pyE2N kt/d+B9dybmuZraWWnKfrVMu88sq1YSIylPtqLHemJSEm0FSLmyhGLBUIVH3F5h+2+Ap CpKBK36y6kvMlHDdWNKoK75CFl2OUK+7jlcUryW7g3A0lLVH9a0T1J6Y22aQFdkbYiH1 14jA== X-Gm-Message-State: AFeK/H17DhTrRZPYds224UeHh/ewdu+/MAHkzRslVgS5bjPY1wiWWYhfFDeLLfuEL5wn45XA X-Received: by 10.28.107.13 with SMTP id g13mr2611792wmc.117.1490868011908; Thu, 30 Mar 2017 03:00:11 -0700 (PDT) Received: from anjanavk-OptiPlex-7010.dhcp.avagotech.net ([192.19.237.250]) by smtp.gmail.com with ESMTPSA id k43sm2123802wrk.42.2017.03.30.03.00.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 30 Mar 2017 03:00:11 -0700 (PDT) From: Oza Pawandeep To: Joerg Roedel , Robin Murphy Subject: [RFC PATCH 2/2] of/pci: call pci specific dma-ranges instead of memory-mapped. Date: Thu, 30 Mar 2017 15:29:46 +0530 Message-Id: <1490867986-5675-2-git-send-email-oza.oza@broadcom.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1490867986-5675-1-git-send-email-oza.oza@broadcom.com> References: <1490867986-5675-1-git-send-email-oza.oza@broadcom.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170330_030035_496492_746BF47F X-CRM114-Status: GOOD ( 12.07 ) 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 it is possible that PCI device supports 64-bit DMA addressing, and thus it's driver sets device's dma_mask to DMA_BIT_MASK(64), however PCI host bridge may have limitations on the inbound transaction addressing. As an example, consider NVME SSD device connected to iproc-PCIe controller. Currently, the IOMMU DMA ops only considers PCI device dma_mask when allocating an IOVA. This is particularly problematic on ARM/ARM64 SOCs where the IOMMU (i.e. SMMU) translates IOVA to PA for in-bound transactions only after PCI Host has forwarded these transactions on SOC IO bus. This means on such ARM/ARM64 SOCs the IOVA of in-bound transactions has to honor the addressing restrictions of the PCI Host. this patch calls pci specific of_pci_dma_get_ranges, instead of calling memory-mapped one, which returns wrong size and also not meant for PCI world. with this, it gets accurate resources back, and largest possible inbound window size. with that largest possible dma_mask can be generated. Signed-off-by: Oza Pawandeep diff --git a/drivers/of/device.c b/drivers/of/device.c index b1e6beb..d6a8dde 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include "of_private.h" @@ -89,6 +90,8 @@ void of_dma_configure(struct device *dev, struct device_node *np) bool coherent; unsigned long offset; const struct iommu_ops *iommu; + struct resource_entry *window; + LIST_HEAD(res); /* * Set default coherent_dma_mask to 32 bit. Drivers are expected to @@ -104,7 +107,24 @@ void of_dma_configure(struct device *dev, struct device_node *np) if (!dev->dma_mask) dev->dma_mask = &dev->coherent_dma_mask; - ret = of_dma_get_range(np, &dma_addr, &paddr, &size); + if (dev_is_pci(dev)) { + size = 0; + ret = of_pci_get_dma_ranges(np, &res); + if (!ret) { + resource_list_for_each_entry(window, &res) { + struct resource *res_dma = window->res; + if (size < resource_size(res_dma)) { + dma_addr = res_dma->start - window->offset; + paddr = res_dma->start; + size = resource_size(res_dma); + } + } + } + pci_free_resource_list(&res); + } + else + ret = of_dma_get_range(np, &dma_addr, &paddr, &size); + if (ret < 0) { dma_addr = offset = 0; size = dev->coherent_dma_mask + 1;