From patchwork Wed May 3 04:46:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oza Pawandeep X-Patchwork-Id: 757862 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3wHlyB6qgmz9s7k for ; Wed, 3 May 2017 14:47:30 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=broadcom.com header.i=@broadcom.com header.b="blHHQrOF"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751442AbdECEqv (ORCPT ); Wed, 3 May 2017 00:46:51 -0400 Received: from mail-pg0-f45.google.com ([74.125.83.45]:36241 "EHLO mail-pg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751598AbdECEqs (ORCPT ); Wed, 3 May 2017 00:46:48 -0400 Received: by mail-pg0-f45.google.com with SMTP id t7so71849908pgt.3 for ; Tue, 02 May 2017 21:46:48 -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; bh=2HuGi4wATZnctjlUoY8yWJKV/SHKOruvAKjehqIRy6A=; b=blHHQrOFnOdokdFz/HIRh5KIwqQCj7ohisnDdMmdvxSDQi9iDaJX4pcSFWT7Me15AJ fMIekszGXzJoHoNu9f1nBkDC0laryxUblX/TPMiT9J0mU5mS343OXUyl3OSvXVMaE+FQ QNAsXiLtXLV06xSbasNnyh2J+gG2QCmOIbpkI= 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; bh=2HuGi4wATZnctjlUoY8yWJKV/SHKOruvAKjehqIRy6A=; b=B5eCwHK2ZUcSAYdzSFKA6tB0x8O5TBsID0Vuc/I3e8h0QJsZVVqAeq9cwW9ssAiSct BJTkUJlNYD1NoLHSQXNjNqAuvDzQM4V3N4zxin5u1UZkYlI1g4b466AYO5dGiKU9nkla 1WOTCDamkVXJDim1dLYpl1BmMVM0uTmV0HeObAGV2uZecaiHWg/MMZLPhccPuFjmt/AV LJaW1ewU5oSGeeP0a/xLfhCWCyhlCzU8B6Vy9Jcw+bH45FbvFBCPF663piXp74sNuqa1 S0Ad8MaVOywE3tViewhP7OxC+/ujo2osmSa7yuNyU/mBFI7H/T9ZNWPQn4F+BPjd4lhf GfDQ== X-Gm-Message-State: AN3rC/5gg0oyaFvBpg6iYUU/d3Har93h9Dzul5V0Z7b+GXo0x2AqaaYF ajQbMFokLCxzBIwf X-Received: by 10.84.174.3 with SMTP id q3mr46826125plb.179.1493786802786; Tue, 02 May 2017 21:46:42 -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.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 02 May 2017 21:46:41 -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 1/3] of/pci/dma: fix DMA configuration for PCI masters Date: Wed, 3 May 2017 10:16:33 +0530 Message-Id: <1493786795-28153-1-git-send-email-oza.oza@broadcom.com> X-Mailer: git-send-email 1.9.1 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org 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 serves following: 1) exposes interface to the pci host driver for their inbound memory ranges 2) provide an interface to callers such as of_dma_get_ranges. so then the returned size get best possible (largest) dma_mask. because PCI RC drivers do not call APIs such as dma_set_coherent_mask() and hence rather it shows its addressing capabilities based on dma-ranges. for e.g. dma-ranges = <0x43000000 0x00 0x00 0x00 0x00 0x80 0x00>; we should get dev->coherent_dma_mask=0x7fffffffff. 3) this patch handles multiple inbound windows and dma-ranges. it is left to the caller, how it wants to use them. the new function returns the resources in a standard and unform way 4) this way the callers of for e.g. of_dma_get_ranges does not need to change. 5) leaves scope of adding PCI flag handling for inbound memory by the new function. Bug: SOC-5216 Change-Id: Ie045386df91e1e0587846bb147ae40d96f6d7d2e Signed-off-by: Oza Pawandeep Reviewed-on: http://gerrit-ccxsw.broadcom.net/40428 Reviewed-by: vpx_checkpatch status Reviewed-by: CCXSW Reviewed-by: Ray Jui Tested-by: vpx_autobuild status Tested-by: vpx_smoketest status Tested-by: CCXSW Reviewed-by: Scott Branden diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c index 0ee42c3..ed6e69a 100644 --- a/drivers/of/of_pci.c +++ b/drivers/of/of_pci.c @@ -283,6 +283,83 @@ int of_pci_get_host_bridge_resources(struct device_node *dev, return err; } EXPORT_SYMBOL_GPL(of_pci_get_host_bridge_resources); + +/** + * of_pci_get_dma_ranges - Parse PCI host bridge inbound resources from DT + * @np: device node of the host bridge having the dma-ranges property + * @resources: list where the range of resources will be added after DT parsing + * + * It is the caller's job to free the @resources list. + * + * This function will parse the "dma-ranges" property of a + * PCI host bridge device node and setup the resource mapping based + * on its content. + * + * It returns zero if the range parsing has been successful or a standard error + * value if it failed. + */ + +int of_pci_get_dma_ranges(struct device_node *np, struct list_head *resources) +{ + struct device_node *node = of_node_get(np); + int rlen; + int ret = 0; + const int na = 3, ns = 2; + struct resource *res; + struct of_pci_range_parser parser; + struct of_pci_range range; + + if (!node) + return -EINVAL; + + parser.node = node; + parser.pna = of_n_addr_cells(node); + parser.np = parser.pna + na + ns; + + parser.range = of_get_property(node, "dma-ranges", &rlen); + + if (!parser.range) { + pr_debug("pcie device has no dma-ranges defined for node(%s)\n", + np->full_name); + ret = -EINVAL; + goto out; + } + + parser.end = parser.range + rlen / sizeof(__be32); + + for_each_of_pci_range(&parser, &range) { + /* + * If we failed translation or got a zero-sized region + * then skip this range + */ + if (range.cpu_addr == OF_BAD_ADDR || range.size == 0) + continue; + + res = kzalloc(sizeof(struct resource), GFP_KERNEL); + if (!res) { + ret = -ENOMEM; + goto parse_failed; + } + + ret = of_pci_range_to_resource(&range, np, res); + if (ret) { + kfree(res); + continue; + } + + pci_add_resource_offset(resources, res, + res->start - range.pci_addr); + } + + return ret; + +parse_failed: + pci_free_resource_list(resources); +out: + of_node_put(node); + return ret; +} +EXPORT_SYMBOL_GPL(of_pci_get_dma_ranges); #endif /* CONFIG_OF_ADDRESS */ #ifdef CONFIG_PCI_MSI diff --git a/include/linux/of_pci.h b/include/linux/of_pci.h index 0e0974e..617b90d 100644 --- a/include/linux/of_pci.h +++ b/include/linux/of_pci.h @@ -76,6 +76,7 @@ static inline void of_pci_check_probe_only(void) { } int of_pci_get_host_bridge_resources(struct device_node *dev, unsigned char busno, unsigned char bus_max, struct list_head *resources, resource_size_t *io_base); +int of_pci_get_dma_ranges(struct device_node *np, struct list_head *resources); #else static inline int of_pci_get_host_bridge_resources(struct device_node *dev, unsigned char busno, unsigned char bus_max, @@ -83,6 +84,12 @@ static inline int of_pci_get_host_bridge_resources(struct device_node *dev, { return -EINVAL; } + +static inline int of_pci_get_dma_ranges(struct device_node *np, + struct list_head *resources) +{ + return -EINVAL; +} #endif #if defined(CONFIG_OF) && defined(CONFIG_PCI_MSI)