From: Ladislav Michl <ladis@linux-mips.org>
To: Bjorn Helgaas <bhelgaas@google.com>,
Wei Yongjun <weiyongjun1@huawei.com>
Cc: linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
Dmitry Torokhov <dmitry.torokhov@gmail.com>
Subject: [PATCH 4/5] devres: Add devm_ioremap_shared_resource()
Date: Sun, 21 Jan 2018 22:16:29 +0100 [thread overview]
Message-ID: <20180121211629.GE15151@lenoch> (raw)
In-Reply-To: <20180121211432.GA15151@lenoch>
Implement managed ioremap function for shared resources.
Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
---
include/linux/device.h | 9 ++++++++-
lib/devres.c | 22 ++++++++++++++--------
2 files changed, 22 insertions(+), 9 deletions(-)
diff --git a/include/linux/device.h b/include/linux/device.h
index e99d41a6190b..a35247a5f578 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -731,7 +731,14 @@ void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset,
resource_size_t size);
void __iomem *devm_ioremap_wc(struct device *dev, resource_size_t offset,
resource_size_t size);
-void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res);
+
+#define devm_ioremap_resource(dev, res) \
+ __devm_ioremap_resource(dev, res, false)
+#define devm_ioremap_shared_resource(dev, res) \
+ __devm_ioremap_resource(dev, res, true)
+
+void __iomem *__devm_ioremap_resource(struct device *dev, struct resource *res,
+ bool shared);
void devm_iounmap(struct device *dev, void __iomem *addr);
diff --git a/lib/devres.c b/lib/devres.c
index e9aad136f667..9fa15816cb83 100644
--- a/lib/devres.c
+++ b/lib/devres.c
@@ -22,6 +22,9 @@ static int devm_ioremap_match(struct device *dev, void *res, void *match_data)
* @size: Size of map
*
* Managed ioremap(). Map is automatically unmapped on driver detach.
+ *
+ * When possible, use devm_ioremap_resource() or
+ * devm_ioremap_shared_resource() instead.
*/
void __iomem *devm_ioremap(struct device *dev, resource_size_t offset,
resource_size_t size)
@@ -116,13 +119,14 @@ void devm_iounmap(struct device *dev, void __iomem *addr)
EXPORT_SYMBOL(devm_iounmap);
/**
- * devm_ioremap_resource() - check, request region, and ioremap resource
+ * __devm_ioremap_resource() - check, request region, and ioremap resource
* @dev: generic device to handle the resource for
* @res: resource to be handled
+ * @shared: region is not requested when true
*
- * Checks that a resource is a valid memory region, requests the memory
- * region and ioremaps it. All operations are managed and will be undone
- * on driver detach.
+ * Checks that a resource is a valid memory region, eventually requests the
+ * memory region and ioremaps it. All operations are managed and will be
+ * undone on driver detach.
*
* Returns a pointer to the remapped memory or an ERR_PTR() encoded error code
* on failure. Usage example:
@@ -132,7 +136,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 shared)
{
resource_size_t size;
const char *name;
@@ -148,7 +153,7 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res)
size = resource_size(res);
name = res->name ?: dev_name(dev);
- if (!devm_request_mem_region(dev, res->start, size, name)) {
+ if (!shared && !devm_request_mem_region(dev, res->start, size, name)) {
dev_err(dev, "can't request region for resource %pR\n", res);
return IOMEM_ERR_PTR(-EBUSY);
}
@@ -156,13 +161,14 @@ void __iomem *devm_ioremap_resource(struct device *dev, struct resource *res)
dest_ptr = devm_ioremap(dev, res->start, size);
if (!dest_ptr) {
dev_err(dev, "ioremap failed for resource %pR\n", res);
- devm_release_mem_region(dev, res->start, size);
+ if (!shared)
+ devm_release_mem_region(dev, res->start, size);
dest_ptr = IOMEM_ERR_PTR(-ENOMEM);
}
return dest_ptr;
}
-EXPORT_SYMBOL(devm_ioremap_resource);
+EXPORT_SYMBOL(__devm_ioremap_resource);
#ifdef CONFIG_HAS_IOPORT_MAP
/*
--
2.15.1
next prev parent reply other threads:[~2018-01-21 21:16 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-21 21:14 [RFC 0/5] Add managed ioremap function for shared resources Ladislav Michl
2018-01-21 21:15 ` [PATCH 1/5] devres: Move managed io function declarations into device.h Ladislav Michl
2018-01-22 9:30 ` kbuild test robot
2018-01-22 11:50 ` Ladislav Michl
2018-01-22 12:32 ` Linus Walleij
2018-01-22 10:08 ` kbuild test robot
2018-01-22 12:58 ` Ladislav Michl
2018-01-22 17:49 ` Dmitry Torokhov
2018-01-22 21:50 ` Ladislav Michl
2018-01-22 23:21 ` Dmitry Torokhov
2018-01-21 21:15 ` [PATCH 2/5] PCI: Move managed resource alloc to devres Ladislav Michl
2018-01-22 23:33 ` Dmitry Torokhov
2018-01-23 6:58 ` Ladislav Michl
2018-01-21 21:16 ` [PATCH 3/5] devres: Make devm_ioremap_release() static Ladislav Michl
2018-01-21 21:16 ` Ladislav Michl [this message]
2018-01-21 21:17 ` [PATCH 5/5] mtd: nand: davinci: Use devm_ioremap_shared_resource() Ladislav Michl
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=20180121211629.GE15151@lenoch \
--to=ladis@linux-mips.org \
--cc=bhelgaas@google.com \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=weiyongjun1@huawei.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.