aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMagnus Damm <damm@igel.co.jp>2008-10-16 01:05:15 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-10-16 14:21:51 -0400
commitc9f66169f1c696f9489503d7de92daff135c1efd (patch)
treeb96efd22193122874196c4809b94069f8e46cb34
parentc26ec88ea86ad5122a6ea5ad635e6a1f6c395d74 (diff)
resource: add resource_type() and IORESOURCE_TYPE_BITS
Add resource_type() and IORESOURCE_TYPE_BITS. They make it easier to add more resource types without having to rewrite tons of code. Signed-off-by: Magnus Damm <damm@igel.co.jp> Cc: Ben Dooks <ben-linux@fluff.org> Cc: Jean Delvare <khali@linux-fr.org> Cc: Paul Mundt <lethal@linux-sh.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/base/platform.c31
-rw-r--r--include/linux/ioport.h7
2 files changed, 23 insertions, 15 deletions
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 3f940393d6c7..66b710c28812 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -42,10 +42,8 @@ struct resource *platform_get_resource(struct platform_device *dev,
42 for (i = 0; i < dev->num_resources; i++) { 42 for (i = 0; i < dev->num_resources; i++) {
43 struct resource *r = &dev->resource[i]; 43 struct resource *r = &dev->resource[i];
44 44
45 if ((r->flags & (IORESOURCE_IO|IORESOURCE_MEM| 45 if (type == resource_type(r) && num-- == 0)
46 IORESOURCE_IRQ|IORESOURCE_DMA)) == type) 46 return r;
47 if (num-- == 0)
48 return r;
49 } 47 }
50 return NULL; 48 return NULL;
51} 49}
@@ -78,10 +76,8 @@ struct resource *platform_get_resource_byname(struct platform_device *dev,
78 for (i = 0; i < dev->num_resources; i++) { 76 for (i = 0; i < dev->num_resources; i++) {
79 struct resource *r = &dev->resource[i]; 77 struct resource *r = &dev->resource[i];
80 78
81 if ((r->flags & (IORESOURCE_IO|IORESOURCE_MEM| 79 if (type == resource_type(r) && !strcmp(r->name, name))
82 IORESOURCE_IRQ|IORESOURCE_DMA)) == type) 80 return r;
83 if (!strcmp(r->name, name))
84 return r;
85 } 81 }
86 return NULL; 82 return NULL;
87} 83}
@@ -259,9 +255,9 @@ int platform_device_add(struct platform_device *pdev)
259 255
260 p = r->parent; 256 p = r->parent;
261 if (!p) { 257 if (!p) {
262 if (r->flags & IORESOURCE_MEM) 258 if (resource_type(r) == IORESOURCE_MEM)
263 p = &iomem_resource; 259 p = &iomem_resource;
264 else if (r->flags & IORESOURCE_IO) 260 else if (resource_type(r) == IORESOURCE_IO)
265 p = &ioport_resource; 261 p = &ioport_resource;
266 } 262 }
267 263
@@ -282,9 +278,14 @@ int platform_device_add(struct platform_device *pdev)
282 return ret; 278 return ret;
283 279
284 failed: 280 failed:
285 while (--i >= 0) 281 while (--i >= 0) {
286 if (pdev->resource[i].flags & (IORESOURCE_MEM|IORESOURCE_IO)) 282 struct resource *r = &pdev->resource[i];
287 release_resource(&pdev->resource[i]); 283 unsigned long type = resource_type(r);
284
285 if (type == IORESOURCE_MEM || type == IORESOURCE_IO)
286 release_resource(r);
287 }
288
288 return ret; 289 return ret;
289} 290}
290EXPORT_SYMBOL_GPL(platform_device_add); 291EXPORT_SYMBOL_GPL(platform_device_add);
@@ -306,7 +307,9 @@ void platform_device_del(struct platform_device *pdev)
306 307
307 for (i = 0; i < pdev->num_resources; i++) { 308 for (i = 0; i < pdev->num_resources; i++) {
308 struct resource *r = &pdev->resource[i]; 309 struct resource *r = &pdev->resource[i];
309 if (r->flags & (IORESOURCE_MEM|IORESOURCE_IO)) 310 unsigned long type = resource_type(r);
311
312 if (type == IORESOURCE_MEM || type == IORESOURCE_IO)
310 release_resource(r); 313 release_resource(r);
311 } 314 }
312 } 315 }
diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index ee9bcc6f32b6..0dde77272d7a 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -34,7 +34,8 @@ struct resource_list {
34 */ 34 */
35#define IORESOURCE_BITS 0x000000ff /* Bus-specific bits */ 35#define IORESOURCE_BITS 0x000000ff /* Bus-specific bits */
36 36
37#define IORESOURCE_IO 0x00000100 /* Resource type */ 37#define IORESOURCE_TYPE_BITS 0x00000f00 /* Resource type */
38#define IORESOURCE_IO 0x00000100
38#define IORESOURCE_MEM 0x00000200 39#define IORESOURCE_MEM 0x00000200
39#define IORESOURCE_IRQ 0x00000400 40#define IORESOURCE_IRQ 0x00000400
40#define IORESOURCE_DMA 0x00000800 41#define IORESOURCE_DMA 0x00000800
@@ -126,6 +127,10 @@ static inline resource_size_t resource_size(struct resource *res)
126{ 127{
127 return res->end - res->start + 1; 128 return res->end - res->start + 1;
128} 129}
130static inline unsigned long resource_type(struct resource *res)
131{
132 return res->flags & IORESOURCE_TYPE_BITS;
133}
129 134
130/* Convenience shorthand with allocation */ 135/* Convenience shorthand with allocation */
131#define request_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name)) 136#define request_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name))