From patchwork Thu Mar 30 09:59:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oza Pawandeep X-Patchwork-Id: 9653495 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 5C2846034C for ; Thu, 30 Mar 2017 10:00:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 507E52858B for ; Thu, 30 Mar 2017 10:00:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 455E22858D; Thu, 30 Mar 2017 10:00:33 +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 DA6A52858B for ; Thu, 30 Mar 2017 10:00: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: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:In-Reply-To: References:List-Owner; bh=9WMZJTLEwjGIln52Rm6jWG4W+Uaj7rtWNRcaH0ouz00=; b=QVN oCHPlM/RdZWUg0fZrVNg0roKl9lupJ5H7h7A0KkAOa0yfW8WYjzjrzVicOPT7H/u7ufggNN0e3FyI MHRGvjxdR7nc8/5W4Ys37346YM6D//e68x7UF6BYj5BFuNAp6L9eKplhAHJ9wsRTnm1URbSB2FCgz 24lIHa+YQqpdI7ELc+gBGbo6G2JR7/W9UfL6uK8uDqsj6czkFhPPS1VpvX2lYj5RT5BQSIa49Vnq+ 2lI8xW+mQvQIptzsKL8oxIkG/sUTptZLIEGvRNmH88E7G2pAwp9xpH+kDfL8S19RnqmbfvA5Ig8/G HS/wGxYH4OGaYtVeJpCaNhsXq5Zo0ug==; 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 1ctWsZ-0006A0-1y; Thu, 30 Mar 2017 10:00:31 +0000 Received: from mail-wr0-x233.google.com ([2a00:1450:400c:c0c::233]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ctWsT-0005Ix-1r for linux-arm-kernel@lists.infradead.org; Thu, 30 Mar 2017 10:00:28 +0000 Received: by mail-wr0-x233.google.com with SMTP id k6so47127756wre.2 for ; Thu, 30 Mar 2017 03:00:04 -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=HZ0dVHp4vxxdnQL+DlNgSmNw6TgNYZqLBZq+fiFU4P0=; b=W/uwfJjiEEa3XtDGvL33ovXwc/A8MBIwi63lZF6YRALp7czNaDikTOb0+D+wLf0Fz4 /OY8JISbxsSecHbdub3tuL0/1eqLI+25yGYlx55QP9eIwls+BkMuKlNAitzH+c/Qqrnp gB5rysq3l/xxC6S7UQsMA/HvzuHz2sMPwVl4o= 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=HZ0dVHp4vxxdnQL+DlNgSmNw6TgNYZqLBZq+fiFU4P0=; b=eZbUHBKlh2j7YjOAUgOndrilHdgqD/jer8S9lTjA2cJ4xtldGlka5O8GRezCiSCurX 2QeKPRW4ZhxoKEXAXrwWFpxwD8et7UTEWlpwy920BtotanzzcNbS5gGBkiUWIQEcIUMm Y/OGvtbgPMmffZ+XZ3FwqbC+DFjlH17zLefMiMFG1bCEt35lUSq/z1iwYi3JFgUQ89Jm eBWbqmnshy9N4zIi96aQbgh99W2Pen+tjt2c0D/AZ4hnzXNtv0Iw8VTE5UO2+J5VWwho QC9AAbF6+YKXqAtrpGq2aRvKPgo4LlWF59aC48nN0sUuyOwxHXB7YB1Nu0n8ZNjBAH4J tZOA== X-Gm-Message-State: AFeK/H1gRN8yHWVlycPJnK//AnuufC5tVQzXTvk3Uvho0ICkMBdzWM1f9KFptIWgKOcREunX X-Received: by 10.28.113.73 with SMTP id m70mr2667930wmc.12.1490868002431; Thu, 30 Mar 2017 03:00:02 -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.02.59.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 30 Mar 2017 03:00:01 -0700 (PDT) From: Oza Pawandeep To: Joerg Roedel , Robin Murphy Subject: [RFC PATCH 1/2] of/pci: implement inbound dma-ranges for PCI Date: Thu, 30 Mar 2017 15:29:45 +0530 Message-Id: <1490867986-5675-1-git-send-email-oza.oza@broadcom.com> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170330_030025_299958_D5C734EB X-CRM114-Status: GOOD ( 15.89 ) 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 frmework and of framework integration assumes dma-ranges in a way where memory-mapped devices define their dma-ranges. dma-ranges: (child-bus-address, parent-bus-address, length). but iproc based SOCs and other SOCs(rcar) have PCI world dma-ranges. dma-ranges = <0x43000000 0x00 0x00 0x00 0x00 0x80 0x00>; of_dma_configure is specifically witten to take care of memory mapped devices. but no implementation exists for pci to take care of pcie based memory ranges. in fact pci world doesnt seem to define standard dma-ranges this exposes intrface not only to the pci host driver, but also it aims to provide an interface to callers such as of_dma_configure. so then the returned size get best possible (largest) dma_mask. for e.g. dma-ranges = <0x43000000 0x00 0x00 0x00 0x00 0x80 0x00>; we should get dev->coherent_dma_mask=0x7fffffffff. also this patch intends to handle multiple inbound windows and dma-ranges. it is left to the caller, how it wants to use them. Signed-off-by: Oza Pawandeep diff --git a/drivers/of/of_pci.c b/drivers/of/of_pci.c index 0ee42c3..5299438 100644 --- a/drivers/of/of_pci.c +++ b/drivers/of/of_pci.c @@ -283,6 +283,80 @@ 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 = -ENODEV; + 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..8509e3d 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,11 @@ 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)