From patchwork Wed May 3 04:46:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oza Pawandeep X-Patchwork-Id: 9708865 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 2504760351 for ; Wed, 3 May 2017 04:47:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E781285E9 for ; Wed, 3 May 2017 04:47:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 136F5285EE; Wed, 3 May 2017 04:47:29 +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 9A10E285E9 for ; Wed, 3 May 2017 04:47:28 +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=efcBZH4R1UVjdKRJrQqJgdWaCeKOCVLY+M3wNN2lHHI=; b=P9CqP+I9rJ1FCseJj2vHf5tWK9 xd0GuAtrty37SUblfIsX6x8nCtOdhqSLmBOLSA6EKqX31tWoWiPC0EG0Hq4pH9owh5ZLh/q/4NKw9 MN7VrzQXstvYFY/oi6OWM1KbjlGokaNID8ByRTjBMYDvBsoW/vZ+lOW2wOG+daWC6yhP6lYlPB6PV hph6Qk3Uovjh5wFkGg6zYVUJAu3tqPVe1e+12ZPuK/cCCkV9J/IXQalNCJWM0iGn3F3RmFgswjOGA kpV+FiWAokzomwR9pPVavUT+SNSCad5xKDGwMemaVSj+K3lUTMl+aIbYzybD7AQtU2SXsN650AIfM B9ZMaemg==; 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 1d5mCG-0002Oy-3D; Wed, 03 May 2017 04:47:28 +0000 Received: from mail-pg0-x229.google.com ([2607:f8b0:400e:c05::229]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1d5mC0-0001uY-MC for linux-arm-kernel@lists.infradead.org; Wed, 03 May 2017 04:47:15 +0000 Received: by mail-pg0-x229.google.com with SMTP id t7so71851668pgt.3 for ; Tue, 02 May 2017 21:46:52 -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=UsvXjn8XGLF/2yB22SsgiubmDsaibB4c+cCWEbD/4sk=; b=g9eEixAiMcH2jAH3hYjpI9cGpt4vWymb1TFbAxhMH+Uqldeafoy0MWudrjSYBxaPj/ LrL7X+Vt4BBmVlbQ0pphxxt+yxV0i8oWCiuir03uLy56BqYYZZM0R9gR2S5GiNuvWGJ6 MF20xes95iN2JkTqWNhj04ESgSQuaM+ojvS1U= 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=UsvXjn8XGLF/2yB22SsgiubmDsaibB4c+cCWEbD/4sk=; b=k/F4Cn/CFZ0TExk6kA/BQn/7/6iDqfRuKdNMCJ18TyTr0IDti1F4Gi1JyVCZ2UKC6C 5xJxrZPTshAE+Giipd+8er/0TKWsc0enaonFaObj6CaD7CSgBSXHH+g9p2/XlErRVb5F GNOB3ceFNk0rgCr8aep9yym+NWLITeJVvIt6yr9I3lPD4CE0PXFEkjdqxEwIqHbn4342 Kh3aaZNknKHixbliKs2JxsBhW0myPXbk9GUTfDFVs1UhjLZX1zGJoBkbhY3K7i91c91b t2zFsFm4aO8MA8WPcctqYav4KX2XMqNfHZ6owD1j0bEiHYObuSpiCG39ttl8CvBpCpBI iDtA== X-Gm-Message-State: AN3rC/6fSiCw4Msn4IJrWjrKOProluoyZtBOl8Ap0xek+Z3GpgG1SGr1 0RwozlwlyWHj3b6S X-Received: by 10.84.171.129 with SMTP id l1mr46862486plb.5.1493786811801; Tue, 02 May 2017 21:46:51 -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.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 May 2017 21:46:51 -0700 (PDT) From: Oza Pawandeep To: Joerg Roedel , Robin Murphy Subject: [PATCH 3/3] PCI/of fix of_dma_get_range; get PCI specific dma-ranges Date: Wed, 3 May 2017 10:16:35 +0530 Message-Id: <1493786795-28153-3-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_214712_921203_F2D5F00F X-CRM114-Status: GOOD ( 15.39 ) 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 current device framework and of framework integration assumes dma-ranges in a way where memory-mapped devices define their dma-ranges. (child-bus-address, parent-bus-address, length). of_dma_configure is specifically written to take care of memory mapped devices. but no implementation exists for pci to take care of pcie based memory ranges. for e.g. iproc based SOCs and other SOCs(suc as rcar) have PCI world dma-ranges. dma-ranges = <0x43000000 0x00 0x00 0x00 0x00 0x80 0x00>; this patch fixes this patch fixes the bug in of_dma_get_range, which with as is, parses the PCI memory ranges and return wrong size as 0. in order to get largest possible dma_mask. this patch also retuns the largest possible size based on dma-ranges, for e.g. dma-ranges = <0x43000000 0x00 0x00 0x00 0x00 0x80 0x00>; we should get dev->coherent_dma_mask=0x7fffffffff. based on which iova allocation space will honour PCI host bridge limitations. Bug: SOC-5216 Change-Id: I4c534bdd17e70c6b27327d39d1656e8ed0cf56d6 Signed-off-by: Oza Pawandeep Reviewed-on: http://gerrit-ccxsw.broadcom.net/40762 Reviewed-by: vpx_checkpatch status Reviewed-by: CCXSW Reviewed-by: Scott Branden Tested-by: vpx_autobuild status Tested-by: vpx_smoketest status diff --git a/drivers/of/address.c b/drivers/of/address.c index 02b2903..f7734fc 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -830,6 +831,54 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz int ret = 0; u64 dmaaddr; +#ifdef CONFIG_PCI + struct resource_entry *window; + LIST_HEAD(res); + + if (!node) + return -EINVAL; + + if (of_bus_pci_match(np)) { + *size = 0; + /* + * PCI dma-ranges is not mandatory property. + * many devices do no need to have it, since + * host bridge does not require inbound memory + * configuration or rather have design limitations. + * so we look for dma-ranges, if missing we + * just return the caller full size, and also + * no dma-ranges suggests that, host bridge allows + * whatever comes in, so we set dma_addr to 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); + + /* ignore the empty ranges. */ + if (*size == 0) { + pr_debug("empty/zero size dma-ranges found for node(%s)\n", + np->full_name); + *size = DMA_BIT_MASK(sizeof(dma_addr_t) * 8); + *dma_addr = *paddr = 0; + ret = 0; + } + + pr_err("dma_addr(%llx) cpu_addr(%llx) size(%llx)\n", + *dma_addr, *paddr, *size); + goto out; + } +#endif + if (!node) return -EINVAL;