From patchwork Thu Jun 5 17:26:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Brugger X-Patchwork-Id: 4307841 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 BAB309F163 for ; Thu, 5 Jun 2014 17:29:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DF62D2034F for ; Thu, 5 Jun 2014 17:29: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 D0EDA2035D for ; Thu, 5 Jun 2014 17:29:32 +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 1WsbRf-0004Ke-Fd; Thu, 05 Jun 2014 17:27:19 +0000 Received: from mail-wi0-x231.google.com ([2a00:1450:400c:c05::231]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WsbRP-0004CA-2v for linux-arm-kernel@lists.infradead.org; Thu, 05 Jun 2014 17:27:03 +0000 Received: by mail-wi0-f177.google.com with SMTP id f8so3902558wiw.16 for ; Thu, 05 Jun 2014 10:26:37 -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=HqtSUcSQJOxSsvkbQGnHBLusCwwb9WufLvxOCoE4i7U=; b=s4NKAKa2YOnY0lcqFdtb9pUBB+VBtQUI0EH+QdQActv8jJWLUjyuYDT8x70om02edQ Rkt8t8OsKo1JFOoNhbukUqloFinuzdsQ20jYYO10+SkQvx32CzcBB3Ev+ZKBvpbOLBBU Cpz4y8dXATHB5RexWmsZMIfCnRykA4OXdeaLQ3b55dxDX2jL3AjlkPn9uQ2002shASXR +3KFGq+nI89xGxJBZWjlinQYo9h1vUQmYhgFvEqYszXeEuFdRxcrTvXSchE8Yj4fz93r 9F8tFJ2/rrb47e5DswcB2mBvH+ZwFk3i8KmICJibd2oKB21ajb8pBWb6tZ8PKgoD5ZRw 5aWw== X-Received: by 10.180.20.210 with SMTP id p18mr15186695wie.8.1401989194566; Thu, 05 Jun 2014 10:26:34 -0700 (PDT) Received: from startic-SATELLITE-L850-1RZ.lan (23.Red-213-98-62.staticIP.rima-tde.net. [213.98.62.23]) by mx.google.com with ESMTPSA id c2sm8855345wja.18.2014.06.05.10.26.32 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 05 Jun 2014 10:26:33 -0700 (PDT) From: Matthias Brugger To: linux-kernel@vger.kernel.org Subject: [PATCH v7 1/7] of: Provide function to request and map memory Date: Thu, 5 Jun 2014 19:26:15 +0200 Message-Id: <1401989181-4712-2-git-send-email-matthias.bgg@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1401989181-4712-1-git-send-email-matthias.bgg@gmail.com> References: <1401989181-4712-1-git-send-email-matthias.bgg@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140605_102703_280781_961376E9 X-CRM114-Status: GOOD ( 14.27 ) X-Spam-Score: -0.1 (/) Cc: mark.rutland@arm.com, andrew@lunn.ch, linux-doc@vger.kernel.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, linux-arm-kernel@lists.infradead.org, florian.vaussard@epfl.ch, sebastian.hesselbarth@gmail.com, devicetree@vger.kernel.org, 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, 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.15 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 Acked-by: Grant Likely --- drivers/of/address.c | 28 ++++++++++++++++++++++++++++ include/linux/of_address.h | 8 ++++++++ 2 files changed, 36 insertions(+) diff --git a/drivers/of/address.c b/drivers/of/address.c index cb4242a..c55b107 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -721,3 +721,31 @@ 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)