From patchwork Fri Jun 20 11:48:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Brugger X-Patchwork-Id: 4388531 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8A3CABEECB for ; Fri, 20 Jun 2014 11:52:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9FB48203DF for ; Fri, 20 Jun 2014 11:52:03 +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 BDB0C203DA for ; Fri, 20 Jun 2014 11:52:02 +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 1WxxKJ-0002RN-9Y; Fri, 20 Jun 2014 11:49:51 +0000 Received: from mail-wi0-x233.google.com ([2a00:1450:400c:c05::233]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WxxK9-0002Ho-Aq for linux-arm-kernel@lists.infradead.org; Fri, 20 Jun 2014 11:49:42 +0000 Received: by mail-wi0-f179.google.com with SMTP id cc10so651004wib.12 for ; Fri, 20 Jun 2014 04:49:19 -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=HlQrhF8w9yySDgON5d/osMX3Wo3jKRuaKsH6oNc3aRg=; b=CRBhbxgCKPVhEZnfNi/ykDv000h9k8+W65uIGtMiq4AIrsSaKqXCudCMFusaTJsaes YzdjO7kChl/I0pQJRS81Rhhq3DpekFeXWWuISIbf9uM86lzQED5V6HYbfHIObyhP3k8b PCO89eQ5EkubKZg8L6Ki+r2mue0BZqMtW9vK5qBSIoPRHwbSOvq84qqeJUS91a1pCWp9 QQr2BZwcuCEIEDSinBhodL5XsFoWRfv7xd9VTBJUlQBMlmWU3f482BFT27tjdxCSu1c3 WmI8RWs03oPyo68An7eWHtabjDov9ClSaGXX0ig2nyJOUU4lqq8It9BHO+VSOt6v+km6 qoMQ== X-Received: by 10.180.82.7 with SMTP id e7mr3610248wiy.6.1403264959405; Fri, 20 Jun 2014 04:49:19 -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 cd1sm15124794wjc.19.2014.06.20.04.49.16 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 20 Jun 2014 04:49:18 -0700 (PDT) From: Matthias Brugger To: linux-kernel@vger.kernel.org Subject: [PATCH v9 1/3] of: Provide function to request and map memory Date: Fri, 20 Jun 2014 13:48:47 +0200 Message-Id: <1403264929-21325-2-git-send-email-matthias.bgg@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1403264929-21325-1-git-send-email-matthias.bgg@gmail.com> References: <1403264929-21325-1-git-send-email-matthias.bgg@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140620_044941_529937_C38A6B44 X-CRM114-Status: GOOD ( 14.80 ) 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, Matthias Brugger , 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 From: Matthias Brugger 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 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)