From patchwork Wed Jun 11 12:34:09 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Brugger X-Patchwork-Id: 4336141 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 E66359F314 for ; Wed, 11 Jun 2014 12:37:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0F175201B4 for ; Wed, 11 Jun 2014 12:37:40 +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 2DDA920179 for ; Wed, 11 Jun 2014 12:37:39 +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 1Wuhk5-0003Jw-QH; Wed, 11 Jun 2014 12:35:01 +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 1Wuhjw-0003ED-2v for linux-arm-kernel@lists.infradead.org; Wed, 11 Jun 2014 12:34:54 +0000 Received: by mail-wg0-f46.google.com with SMTP id y10so4910449wgg.17 for ; Wed, 11 Jun 2014 05:34:30 -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=QAoMiQy/507ESSCSqyeOhwG7RvRHh96vjAWDKDMkNQc=; b=DC3IAqAJBY9E7HvKe+I+c0PPdf4gxVHa6UMuw0sznszGiTHWXDa948YtaAfEcsXHcH bmtMhN6XnSS1hpLbGuVMb2uRdg4WFVM6xg6GBaQl4KnuTe8UmjXg0Nplqfs1gVt1ycMK 3WjxNNA0lPJtE9lrH+D+82DylLUSiEel9yLQ25sqK6lUCljKFyyn98BCExoO026NyHvN sBcqbAr5MhPOvv294qVUBGvbezjyeNC4c8sgiq1X8lZr1xdr7xcaDEA0somAgKcZsQdD UzFTSq5PMtd7p7eah/sk2JQYvOG9sY/k9zMH92qYU3JwfWO+xRQDT7juumtadERWN9in IYcQ== X-Received: by 10.180.100.41 with SMTP id ev9mr47758481wib.22.1402490068560; Wed, 11 Jun 2014 05:34:28 -0700 (PDT) Received: from localhost.localdomain (87.Red-83-39-6.dynamicIP.rima-tde.net. [83.39.6.87]) by mx.google.com with ESMTPSA id k2sm34050615wjq.20.2014.06.11.05.34.26 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Jun 2014 05:34:27 -0700 (PDT) From: Matthias Brugger To: linux-kernel@vger.kernel.org Subject: [PATCH v8 1/7] of: Provide function to request and map memory Date: Wed, 11 Jun 2014 14:34:09 +0200 Message-Id: <1402490055-15197-2-git-send-email-matthias.bgg@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1402490055-15197-1-git-send-email-matthias.bgg@gmail.com> References: <1402490055-15197-1-git-send-email-matthias.bgg@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140611_053452_317127_17062254 X-CRM114-Status: GOOD ( 14.85 ) 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=-2.4 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable 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 --- 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 5edfcb0..d6b2900 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -702,6 +702,35 @@ void __iomem *of_iomap(struct device_node *np, int index) } 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); + /** * of_dma_get_range - Get DMA range info * @np: device node to get DMA range info diff --git a/include/linux/of_address.h b/include/linux/of_address.h index c13b878..0a13482 100644 --- a/include/linux/of_address.h +++ b/include/linux/of_address.h @@ -109,6 +109,8 @@ static inline bool of_dma_is_coherent(struct device_node *np) 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) @@ -120,6 +122,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)