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: 9708855 X-Patchwork-Delegate: bhelgaas@google.com 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 F3D5A60387 for ; Wed, 3 May 2017 04:47:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDF79285E9 for ; Wed, 3 May 2017 04:47:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E2547285EE; Wed, 3 May 2017 04:47:01 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B328285EB for ; Wed, 3 May 2017 04:47:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751889AbdECEqz (ORCPT ); Wed, 3 May 2017 00:46:55 -0400 Received: from mail-pg0-f42.google.com ([74.125.83.42]:34829 "EHLO mail-pg0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751860AbdECEqw (ORCPT ); Wed, 3 May 2017 00:46:52 -0400 Received: by mail-pg0-f42.google.com with SMTP id o3so66705220pgn.2 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=PfKB1pBK4n9KUVbWyP52fb9JNv2WTAwgsSiGAW6yNY27g8yEMMw00dYpAjkeS3/j8I 7U2/6pfeEoP0XE1pDlruna9i8eX/p7+nqgdz53fRPDZEpxMhVjhT/wFczpWhuhZAGwpS /uKOfrX47o+galHF0vty7X19pdpGxficD1xw6Hx6R9XbncUnoBE/LADltZ+SfIM/j8OX VcWKNacGLiePb5K9MG0Tm0F/ILKBoNlwhkET/3N+AHn++QeCU8A4YU4bWLlIHNkbOxnx lb1KGqLmRWAOLuDagDXWdqfI+OVPUsy2pqxwTiQrOHFK/mwOVjXYsLnBG8gE2ShZ0/mu GBCA== X-Gm-Message-State: AN3rC/6bBt9vFF0xeHMjEw3x4ugdxaYYZswhQbW8m4sTHBq3+Rmm0olo A8hhFihLYLhrMwDm 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 Cc: iommu@lists.linux-foundation.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, Oza Pawandeep , Oza Pawandeep 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> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.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;