From: Tejun Heo <htejun@gmail.com>
To: jgarzik@pobox.com, gregkh@suse.de, alan@lxorguk.ukuu.org.uk,
linux-kernel@vger.kernel.org, linux-ide@vger.kernel.org,
htejun@gmail.com
Cc: Tejun Heo <htejun@gmail.com>
Subject: [PATCH 2/13] devres: implement managed IO region interface
Date: Wed, 10 Jan 2007 14:35:36 +0900 [thread overview]
Message-ID: <11684073361953-git-send-email-htejun@gmail.com> (raw)
In-Reply-To: <11684073353213-git-send-email-htejun@gmail.com>
Implement managed IO region interface - devm_request_region() and
devm_release_region(). Except for the first @dev argument and being
managed, these take the same arguments and have the same effect as
non-managed coutnerparts.
Signed-off-by: Tejun Heo <htejun@gmail.com>
---
include/linux/ioport.h | 20 +++++++++++++++
kernel/resource.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 82 insertions(+), 0 deletions(-)
diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index 15228d7..6859a3b 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -137,4 +137,24 @@ static inline int __deprecated check_region(resource_size_t s,
{
return __check_region(&ioport_resource, s, n);
}
+
+/* Wrappers for managed devices */
+struct device;
+#define devm_request_region(dev,start,n,name) \
+ __devm_request_region(dev, &ioport_resource, (start), (n), (name))
+#define devm_request_mem_region(dev,start,n,name) \
+ __devm_request_region(dev, &iomem_resource, (start), (n), (name))
+
+extern struct resource * __devm_request_region(struct device *dev,
+ struct resource *parent, resource_size_t start,
+ resource_size_t n, const char *name);
+
+#define devm_release_region(start,n) \
+ __devm_release_region(dev, &ioport_resource, (start), (n))
+#define devm_release_mem_region(start,n) \
+ __devm_release_region(dev, &iomem_resource, (start), (n))
+
+extern void __devm_release_region(struct device *dev, struct resource *parent,
+ resource_size_t start, resource_size_t n);
+
#endif /* _LINUX_IOPORT_H */
diff --git a/kernel/resource.c b/kernel/resource.c
index 7b9a497..2a3f886 100644
--- a/kernel/resource.c
+++ b/kernel/resource.c
@@ -17,6 +17,7 @@
#include <linux/fs.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
+#include <linux/device.h>
#include <asm/io.h>
@@ -618,6 +619,67 @@ void __release_region(struct resource *parent, resource_size_t start,
EXPORT_SYMBOL(__release_region);
/*
+ * Managed region resource
+ */
+struct region_devres {
+ struct resource *parent;
+ resource_size_t start;
+ resource_size_t n;
+};
+
+static void devm_region_release(struct device *dev, void *res)
+{
+ struct region_devres *this = res;
+
+ __release_region(this->parent, this->start, this->n);
+}
+
+static int devm_region_match(struct device *dev, void *res, void *match_data)
+{
+ struct region_devres *this = res, *match = match_data;
+
+ return this->parent == match->parent &&
+ this->start == match->start && this->n == match->n;
+}
+
+struct resource * __devm_request_region(struct device *dev,
+ struct resource *parent, resource_size_t start,
+ resource_size_t n, const char *name)
+{
+ struct region_devres *dr = NULL;
+ struct resource *res;
+
+ dr = devres_alloc(devm_region_release, sizeof(struct region_devres),
+ GFP_KERNEL);
+ if (!dr)
+ return NULL;
+
+ dr->parent = parent;
+ dr->start = start;
+ dr->n = n;
+
+ res = __request_region(parent, start, n, name);
+ if (res)
+ devres_add(dev, dr);
+ else
+ devres_free(dr);
+
+ return res;
+}
+EXPORT_SYMBOL(__devm_request_region);
+
+void __devm_release_region(struct device *dev, struct resource *parent,
+ resource_size_t start, resource_size_t n)
+{
+ struct region_devres match_data = { parent, start, n };
+
+ __release_region(parent, start, n);
+ WARN_ON(devres_destroy(dev, devm_region_release, devm_region_match,
+ &match_data));
+}
+EXPORT_SYMBOL(__devm_release_region);
+
+/*
* Called from init/main.c to reserve IO ports.
*/
#define MAXRESERVE 4
--
1.4.4.3
next prev parent reply other threads:[~2007-01-10 5:36 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-01-10 5:35 [PATCHSET] Managed device resources, take #2 Tejun Heo
2007-01-10 5:35 ` [PATCH 1/13] devres: device resource management core Tejun Heo
2007-01-10 5:35 ` [PATCH 3/13] devres: implement managed IRQ interface Tejun Heo
2007-01-10 5:35 ` [PATCH 4/13] devres: implement managed DMA interface Tejun Heo
2007-01-10 5:35 ` Tejun Heo [this message]
2007-01-10 5:35 ` [PATCH 9/13] libata: update libata core layer to use devres Tejun Heo
2007-01-10 5:35 ` [PATCH 7/13] devres: add Documentation/driver-model/devres.txt Tejun Heo
2007-01-10 5:35 ` [PATCH 6/13] devres: implement managed iomap interface Tejun Heo
2008-04-07 16:46 ` Sergei Shtylyov
2008-04-08 14:48 ` Tejun Heo
2008-04-08 14:55 ` Sergei Shtylyov
2008-04-08 15:03 ` Tejun Heo
2008-04-10 16:56 ` Sergei Shtylyov
2008-04-10 17:44 ` Kumar Gala
2008-04-10 18:24 ` Sergei Shtylyov
2008-04-10 19:40 ` Kumar Gala
2008-04-11 2:08 ` Tejun Heo
2007-01-10 5:35 ` [PATCH 8/13] libata: implement ata_host_detach() Tejun Heo
2007-01-10 5:35 ` [PATCH 5/13] devres: implement managed PCI interface Tejun Heo
2007-01-10 5:35 ` [PATCH 11/13] libata: remove unused functions Tejun Heo
2007-01-10 5:35 ` [PATCH 12/13] devres: implement pcim_iomap_regions() Tejun Heo
2007-01-20 0:31 ` [PATCHSET] Managed device resources, take #2 Jeff Garzik
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=11684073361953-git-send-email-htejun@gmail.com \
--to=htejun@gmail.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=gregkh@suse.de \
--cc=jgarzik@pobox.com \
--cc=linux-ide@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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