From patchwork Fri Jun 20 12:28:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Brugger X-Patchwork-Id: 4389211 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3C62E9F314 for ; Fri, 20 Jun 2014 12:33:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AD2BC20351 for ; Fri, 20 Jun 2014 12:33:33 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 156DA2037F for ; Fri, 20 Jun 2014 12:33:29 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WxxyL-0004Wc-PA; Fri, 20 Jun 2014 12:31:13 +0000 Received: from mail-wg0-x22e.google.com ([2a00:1450:400c:c00::22e]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wxxwm-0001th-0W for linux-arm-kernel@lists.infradead.org; Fri, 20 Jun 2014 12:29:40 +0000 Received: by mail-wg0-f46.google.com with SMTP id y10so3656382wgg.5 for ; Fri, 20 Jun 2014 05:29:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mnK7t6YOdSIbn+mg66zOM2U7wGIJKZq6zBXTqoD7cVw=; b=GIvriOmHFmF2lTYXAZgKEb+pkdniqCj002ECdOxlEwGhHpMnj+n5sdzWQuPzkWe8/P b/WwU5SpHnRCAuvL9b6zv6k2g7+Lt9yNYU3HQVqlsEepiB9GS1qE5/pPcUh2mE8r04J9 IShMf8xnz6v4QLYPxlUPYTJ1x6sxj7jiig0hAS3rThRFBIW8hl7498tq7L72XSW+gEC3 Ey3us5qjalE/jyOxuMMxvuS6kEKyK44g2Fit89byZWIxaVpEjZpPSeBkDMTZ7vDyTVac vWThXCQTeh8yPlksUdmZRueWo9gmCqn5eOqWKdF+Lmtaa60955S8aY1I9qzCbeR9Q+hq pR7w== X-Received: by 10.194.243.70 with SMTP id ww6mr4003983wjc.76.1403267351879; Fri, 20 Jun 2014 05:29:11 -0700 (PDT) Received: from localhost.localdomain (232.Red-2-136-47.dynamicIP.rima-tde.net. [2.136.47.232]) by mx.google.com with ESMTPSA id ho2sm4348828wib.15.2014.06.20.05.29.09 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 20 Jun 2014 05:29:11 -0700 (PDT) From: Matthias Brugger To: linux-kernel@vger.kernel.org Subject: [PATCH v9.1] of: Provide function to request and map memory Date: Fri, 20 Jun 2014 14:28:48 +0200 Message-Id: <1403267328-23085-1-git-send-email-matthias.bgg@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1403264929-21325-2-git-send-email-matthias.bgg@gmail.com> References: <1403264929-21325-2-git-send-email-matthias.bgg@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140620_052936_323286_C4E37391 X-CRM114-Status: GOOD ( 14.67 ) X-Spam-Score: -0.8 (/) Cc: mark.rutland@arm.com, andrew@lunn.ch, linux-doc@vger.kernel.org, devicetree@vger.kernel.org, linus.walleij@linaro.org, gregory.clement@free-electrons.com, thierry.reding@gmail.com, heiko.stuebner@bq.com, linux@arm.linux.org.uk, arnd@arndb.de, daniel.lezcano@linaro.org, shawn.guo@freescale.com, grant.likely@linaro.org, florian.vaussard@epfl.ch, sebastian.hesselbarth@gmail.com, anders.berg@lsi.com, jason@lakedaemon.net, pawel.moll@arm.com, ijc+devicetree@hellion.org.uk, marc.zyngier@arm.com, robh+dt@kernel.org, matthias.bgg@gmail.com, tglx@linutronix.de, soren.brinkmann@xilinx.com, linux-arm-kernel@lists.infradead.org, rdunlap@infradead.org, sboyd@codeaurora.org, silvio.fricke@gmail.com, galak@codeaurora.org, olof@lixom.net, maxime.ripard@free-electrons.com, jic23@kernel.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A call to of_iomap does not request the memory region. This patch adds the function of_io_request_and_map which requests the memory region before mapping it. Signed-off-by: Matthias Brugger Suggested-by: Thomas Gleixner Suggested-by: Rob Herring Acked-by: Grant Likely --- Changes for v9.1: - fixed the Author email address drivers/of/address.c | 29 +++++++++++++++++++++++++++++ include/linux/of_address.h | 8 ++++++++ 2 files changed, 37 insertions(+) diff --git a/drivers/of/address.c b/drivers/of/address.c index cb4242a..09074ba 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -721,3 +721,32 @@ void __iomem *of_iomap(struct device_node *np, int index) return ioremap(res.start, resource_size(&res)); } EXPORT_SYMBOL(of_iomap); + +/* + * of_io_request_and_map - Requests a resource and maps the memory mapped IO + * for a given device_node + * @device: the device whose io range will be mapped + * @index: index of the io range + * @name: name of the resource + * + * Returns a pointer to the requested and mapped memory + */ +void __iomem *of_io_request_and_map(struct device_node *np, int index, + char *name) +{ + struct resource res; + void __iomem *mem; + + if (of_address_to_resource(np, index, &res)) + return NULL; + + if (!request_mem_region(res.start, resource_size(&res), name)) + return NULL; + + mem = ioremap(res.start, resource_size(&res)); + if (!mem) + release_mem_region(res.start, resource_size(&res)); + + return mem; +} +EXPORT_SYMBOL(of_io_request_and_map); diff --git a/include/linux/of_address.h b/include/linux/of_address.h index 5f6ed6b..725b875 100644 --- a/include/linux/of_address.h +++ b/include/linux/of_address.h @@ -96,6 +96,8 @@ static inline struct of_pci_range *of_pci_range_parser_one( extern int of_address_to_resource(struct device_node *dev, int index, struct resource *r); void __iomem *of_iomap(struct device_node *node, int index); +void __iomem *of_io_request_and_map(struct device_node *device, + int index, char *name); #else static inline int of_address_to_resource(struct device_node *dev, int index, struct resource *r) @@ -107,6 +109,12 @@ static inline void __iomem *of_iomap(struct device_node *device, int index) { return NULL; } + +static inline void __iomem *of_io_request_and_map(struct device_node *device, + int index, char *name) +{ + return NULL; +} #endif #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_PCI)