From patchwork Mon May 22 16:39:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oza Pawandeep X-Patchwork-Id: 9741039 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 E44CB60388 for ; Mon, 22 May 2017 16:40:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D629728449 for ; Mon, 22 May 2017 16:40:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB25D2871C; Mon, 22 May 2017 16:40:36 +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 57B6F28449 for ; Mon, 22 May 2017 16:40:36 +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=QmTYx4recMkpz6B6LuYxaOHWWUF8g+MPJ41tLicJP38=; b=LFKOOoWFcYzbgdXRIfCCI3URNo xhpeswTVq0tARN2Fje58BOl0P2jbHfr8pSaleqJqCqzwLcs5KOBcRLw0ZSLEpi6J1QMZKvTc8cON2 W2gWbYIjqNNCGTW7h6kTHGOzYDaKLONhJndR/MpvsBQqH/6e/61VL4PdwceLmc0FGZ51q2tNLAGOp GJTsULnSOgMSL0a7Kra0tWJah0PFrJZIFca/2+eTg6jAIXv70+e4Zw354oGb/BRSD/KUv46aFhVKX dSRNcwrMCSKdAs27AY2IXqUl382hAr0G5LSm28tlLTS/NTWkGMOiPPQEnRDmFM+5ZWi4Bh3wLJBuh OSj/IUlA==; 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 1dCqNn-0002S7-Gn; Mon, 22 May 2017 16:40:35 +0000 Received: from mail-pf0-x22c.google.com ([2607:f8b0:400e:c00::22c]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dCqNX-0000wg-2K for linux-arm-kernel@lists.infradead.org; Mon, 22 May 2017 16:40:21 +0000 Received: by mail-pf0-x22c.google.com with SMTP id m17so87441318pfg.3 for ; Mon, 22 May 2017 09:39:58 -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=snTiGbuGAzqfk9+I+Hf1R6/W8lL7DAbbYGOiXhWAofE=; b=Kd6lpBBUK0c4DxZBa7PP2qOKCZqe2xZ5ttxiUKEfvWt1SpP5NMMnjXB8JVXqEd1gFO /RgboOU/yhVb0xZ+y/prlXoWnDM89Up/aolsD0J6YppQBP+RSffdIWKzuy2bZFLs4xEW ZWRTDcjzRV8GV7GtOLOGYE3fpmaF+2AB/6iz8= 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=snTiGbuGAzqfk9+I+Hf1R6/W8lL7DAbbYGOiXhWAofE=; b=cP7Y7D3AjqeuJF5txAtbQYua5VY3SVJMq6pQsj4NyYpQUx3Pv6CmtYb1/FDT5SU32a 17tl4X61pl+99fHk7//sjwhbT8RvYYVyWzDedG8IWTDSycCdWnD8GYkb5b9xk36Rrgaa 2+46g7RPtRJiH1JGhXJzydmkRte81wh9QeVa0Nxs2+cTnfow+c+IgUoyN8kwWHFVHQ7Y HaT34cl6BOA+GQMov2mrtCzFTPtY+yv3X+BuAyMoxa0nKROwti5LPhtL8KZheBKlJVk0 Z0q8xL5pFDx3juBoubmktYI9l8T/iGfcZtiJw6H6/iFKMZeW0uU9KHVBDtaGEhwCfxRo 4yYw== X-Gm-Message-State: AODbwcDZu28MEfOZcYGb1iRRD6laqBosgI1ftfc+sbe9/g8SXQFc6gVX 3VQ7gIUfjuvyegxX X-Received: by 10.84.232.76 with SMTP id f12mr30437486pln.101.1495471198251; Mon, 22 May 2017 09:39:58 -0700 (PDT) Received: from anjanavk-OptiPlex-7010.dhcp.avagotech.net ([192.19.237.250]) by smtp.gmail.com with ESMTPSA id x198sm26538853pgx.28.2017.05.22.09.39.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 May 2017 09:39:57 -0700 (PDT) From: Oza Pawandeep To: Joerg Roedel , Robin Murphy Subject: [PATCH v7 1/3] OF/PCI: Export inbound memory interface to PCI RC drivers. Date: Mon, 22 May 2017 22:09:40 +0530 Message-Id: <1495471182-12490-2-git-send-email-oza.oza@broadcom.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1495471182-12490-1-git-send-email-oza.oza@broadcom.com> References: <1495471182-12490-1-git-send-email-oza.oza@broadcom.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170522_094019_189115_D6B9863D X-CRM114-Status: GOOD ( 15.12 ) 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 The patch exports interface to PCIe RC drivers so that, Drivers can get their inbound memory configuration. It provides basis for IOVA reservations for inbound memory holes, if RC is not capable of addressing all the host memory, Specifically when IOMMU is enabled and on ARMv8 where 64bit IOVA could be allocated. It handles multiple inbound windows, and returns resources, and 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 c9d4d3a..20cf527 100644 --- a/drivers/of/of_pci.c +++ b/drivers/of/of_pci.c @@ -283,6 +283,102 @@ 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 *dn, struct list_head *resources) +{ + struct device_node *node = of_node_get(dn); + int rlen; + int pna = of_n_addr_cells(node); + const int na = 3, ns = 2; + int np = pna + na + ns; + int ret = 0; + struct resource *res; + const u32 *dma_ranges; + struct of_pci_range range; + + if (!node) + return -EINVAL; + + while (1) { + dma_ranges = of_get_property(node, "dma-ranges", &rlen); + + /* Ignore empty ranges, they imply no translation required. */ + if (dma_ranges && rlen > 0) + break; + + /* no dma-ranges, they imply no translation required. */ + if (!dma_ranges) + break; + + node = of_get_next_parent(node); + + if (!node) + break; + } + + if (!dma_ranges) { + pr_debug("pcie device has no dma-ranges defined for node(%s)\n", + dn->full_name); + ret = -EINVAL; + goto out; + } + + while ((rlen -= np * 4) >= 0) { + range.pci_space = be32_to_cpup((const __be32 *) &dma_ranges[0]); + range.pci_addr = of_read_number(dma_ranges + 1, ns); + range.cpu_addr = of_translate_dma_address(node, + dma_ranges + na); + range.size = of_read_number(dma_ranges + pna + na, ns); + range.flags = IORESOURCE_MEM; + + dma_ranges += np; + + /* + * 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, dn, 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 */ /** diff --git a/include/linux/of_pci.h b/include/linux/of_pci.h index 518c8d2..0eafe86 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 #endif