From: Russ Dill <Russ.Dill@ti.com>
To: linux-kernel@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org
Cc: linux-kbuild@vger.kernel.org,
Ard Biesheuvel <ard.biesheuvel@linaro.org>,
mans@mansr.com, Shawn Guo <shawn.guo@linaro.org>,
Dave Martin <Dave.Martin@arm.com>,
Russell King - ARM Linux <linux@arm.linux.org.uk>
Subject: [RFC PATCH 02/11] lib: devres: Add exec versions of devm_ioremap_resource and friends
Date: Tue, 17 Sep 2013 05:43:28 -0700 [thread overview]
Message-ID: <1379421817-15759-3-git-send-email-Russ.Dill@ti.com> (raw)
In-Reply-To: <1379421817-15759-1-git-send-email-Russ.Dill@ti.com>
Now that there is an _exec version of ioremap, add devm support for it.
Signed-off-by: Russ Dill <Russ.Dill@ti.com>
---
include/linux/device.h | 17 ++++++++-
include/linux/io.h | 4 +++
lib/devres.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 114 insertions(+), 4 deletions(-)
diff --git a/include/linux/device.h b/include/linux/device.h
index 22b546a..204180a 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -596,10 +596,25 @@ extern int devres_release_group(struct device *dev, void *id);
extern void *devm_kzalloc(struct device *dev, size_t size, gfp_t gfp);
extern void devm_kfree(struct device *dev, void *p);
-void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res);
+void __iomem *__devm_ioremap_resource(struct device *dev, struct resource *res,
+ bool exec);
+static inline void __iomem *devm_ioremap_resource(struct device *dev,
+ struct resource *res)
+{
+ return __devm_ioremap_resource(dev, res, false);
+}
void __iomem *devm_request_and_ioremap(struct device *dev,
struct resource *res);
+static inline void __iomem *devm_ioremap_exec_resource(struct device *dev,
+ struct resource *res)
+{
+ return __devm_ioremap_resource(dev, res, true);
+}
+
+void __iomem *devm_request_and_ioremap_exec(struct device *dev,
+ struct resource *res);
+
/* allows to add/remove a custom action to devres stack */
int devm_add_action(struct device *dev, void (*action)(void *), void *data);
void devm_remove_action(struct device *dev, void (*action)(void *), void *data);
diff --git a/include/linux/io.h b/include/linux/io.h
index f4f42fa..582b207 100644
--- a/include/linux/io.h
+++ b/include/linux/io.h
@@ -62,6 +62,10 @@ void __iomem *devm_ioremap(struct device *dev, resource_size_t offset,
unsigned long size);
void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset,
unsigned long size);
+void __iomem *devm_ioremap_exec(struct device *dev, resource_size_t offset,
+ unsigned long size);
+void __iomem *devm_ioremap_exec_nocache(struct device *dev, resource_size_t offset,
+ unsigned long size);
void devm_iounmap(struct device *dev, void __iomem *addr);
int check_signature(const volatile void __iomem *io_addr,
const unsigned char *signature, int length);
diff --git a/lib/devres.c b/lib/devres.c
index 8235331..06cafe5 100644
--- a/lib/devres.c
+++ b/lib/devres.c
@@ -72,6 +72,64 @@ void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset,
EXPORT_SYMBOL(devm_ioremap_nocache);
/**
+ * devm_ioremap_exec - Managed ioremap_exec()
+ * @dev: Generic device to remap IO address for
+ * @offset: BUS offset to map
+ * @size: Size of map
+ *
+ * Managed ioremap_exec(). Map is automatically unmapped on driver detach.
+ */
+void __iomem *devm_ioremap_exec(struct device *dev, resource_size_t offset,
+ unsigned long size)
+{
+ void __iomem **ptr, *addr;
+
+ ptr = devres_alloc(devm_ioremap_release, sizeof(*ptr), GFP_KERNEL);
+ if (!ptr)
+ return NULL;
+
+ addr = ioremap_exec(offset, size);
+ if (addr) {
+ *ptr = addr;
+ devres_add(dev, ptr);
+ } else
+ devres_free(ptr);
+
+ return addr;
+}
+EXPORT_SYMBOL(devm_ioremap_exec);
+
+/**
+ * devm_ioremap_exec_nocache - Managed ioremap_exec_nocache()
+ * @dev: Generic device to remap IO address for
+ * @offset: BUS offset to map
+ * @size: Size of map
+ *
+ * Managed ioremap_exec_nocache(). Map is automatically unmapped on driver
+ * detach.
+ */
+void __iomem *devm_ioremap_exec_nocache(struct device *dev,
+ resource_size_t offset,
+ unsigned long size)
+{
+ void __iomem **ptr, *addr;
+
+ ptr = devres_alloc(devm_ioremap_release, sizeof(*ptr), GFP_KERNEL);
+ if (!ptr)
+ return NULL;
+
+ addr = ioremap_exec_nocache(offset, size);
+ if (addr) {
+ *ptr = addr;
+ devres_add(dev, ptr);
+ } else
+ devres_free(ptr);
+
+ return addr;
+}
+EXPORT_SYMBOL(devm_ioremap_exec_nocache);
+
+/**
* devm_iounmap - Managed iounmap()
* @dev: Generic device to unmap for
* @addr: Address to unmap
@@ -104,7 +162,8 @@ EXPORT_SYMBOL(devm_iounmap);
* if (IS_ERR(base))
* return PTR_ERR(base);
*/
-void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res)
+void __iomem *__devm_ioremap_resource(struct device *dev, struct resource *res,
+ bool exec)
{
resource_size_t size;
const char *name;
@@ -125,7 +184,11 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res)
return ERR_PTR(-EBUSY);
}
- if (res->flags & IORESOURCE_CACHEABLE)
+ if (exec && res->flags & IORESOURCE_CACHEABLE)
+ dest_ptr = devm_ioremap_exec(dev, res->start, size);
+ else if (exec)
+ dest_ptr = devm_ioremap_exec_nocache(dev, res->start, size);
+ else if (res->flags & IORESOURCE_CACHEABLE)
dest_ptr = devm_ioremap(dev, res->start, size);
else
dest_ptr = devm_ioremap_nocache(dev, res->start, size);
@@ -138,7 +201,7 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res)
return dest_ptr;
}
-EXPORT_SYMBOL(devm_ioremap_resource);
+EXPORT_SYMBOL(__devm_ioremap_resource);
/**
* devm_request_and_ioremap() - Check, request region, and ioremap resource
@@ -168,6 +231,34 @@ void __iomem *devm_request_and_ioremap(struct device *device,
}
EXPORT_SYMBOL(devm_request_and_ioremap);
+/**
+ * devm_request_and_ioremap_exec() - Check, request region, and ioremap resource
+ * @dev: Generic device to handle the resource for
+ * @res: resource to be handled
+ *
+ * Takes all necessary steps to ioremap a mem resource. Uses managed device, so
+ * everything is undone on driver detach. Checks arguments, so you can feed
+ * it the result from e.g. platform_get_resource() directly. Returns the
+ * remapped pointer or NULL on error. Usage example:
+ *
+ * res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ * base = devm_request_and_ioremap_exec(&pdev->dev, res);
+ * if (!base)
+ * return -EADDRNOTAVAIL;
+ */
+void __iomem *devm_request_and_ioremap_exec(struct device *device,
+ struct resource *res)
+{
+ void __iomem *dest_ptr;
+
+ dest_ptr = devm_ioremap_exec_resource(device, res);
+ if (IS_ERR(dest_ptr))
+ return NULL;
+
+ return dest_ptr;
+}
+EXPORT_SYMBOL(devm_request_and_ioremap_exec);
+
#ifdef CONFIG_HAS_IOPORT
/*
* Generic iomap devres
--
1.8.3.2
next prev parent reply other threads:[~2013-09-17 12:43 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-09-17 12:43 [RFC PATCH 00/11] Embeddable Position Independent Executable Russ Dill
2013-09-17 12:43 ` [RFC PATCH 01/11] asm-generic: io: Add exec versions of ioremap Russ Dill
2013-09-17 12:43 ` Russ Dill [this message]
2013-09-17 12:43 ` [RFC PATCH 03/11] misc: SRAM: Add option to map SRAM to allow code execution Russ Dill
2013-09-17 12:43 ` [RFC PATCH 04/11] asm-generic: fncpy: Add function copying macros Russ Dill
2013-09-17 14:23 ` Geert Uytterhoeven
2013-09-17 12:43 ` [RFC PATCH 05/11] PIE: Support embedding position independent executables Russ Dill
2013-09-17 12:43 ` [RFC PATCH 06/11] ARM: PIE: Add position independent executable embedding to ARM Russ Dill
2013-09-17 12:43 ` [RFC PATCH 07/11] ARM: PIE: Add support for updating PIE relocations Russ Dill
2013-09-17 12:43 ` [RFC PATCH 08/11] ARM: PIE: Add macro for generating PIE resume trampoline Russ Dill
2013-09-17 12:43 ` [RFC PATCH 09/11] ARM: dts: AM33XX: Associate SRAM with MPU and mark it exec Russ Dill
2013-09-17 12:43 ` [RFC PATCH 10/11] ARM: OMAP2+: AM33XX: Add PIE support for AM33XX Russ Dill
2013-09-17 12:43 ` [RFC PATCH 11/11] ARM: OMAP2+: AM33XX: Basic suspend resume support Russ Dill
2013-10-23 14:11 ` [RFC PATCH 00/11] Embeddable Position Independent Executable Linus Walleij
2013-10-24 8:09 ` Heiko Stübner
2014-04-22 8:15 ` Heiko Stübner
2014-06-04 13:36 ` Pascal Hürst
2013-11-07 23:29 ` Kevin Hilman
2013-11-08 18:09 ` Dave Martin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1379421817-15759-3-git-send-email-Russ.Dill@ti.com \
--to=russ.dill@ti.com \
--cc=Dave.Martin@arm.com \
--cc=ard.biesheuvel@linaro.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux@arm.linux.org.uk \
--cc=mans@mansr.com \
--cc=shawn.guo@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox