Commit c9f66169 authored by Magnus Damm's avatar Magnus Damm Committed by Linus Torvalds

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: default avatarMagnus 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: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent c26ec88e
...@@ -42,10 +42,8 @@ struct resource *platform_get_resource(struct platform_device *dev, ...@@ -42,10 +42,8 @@ struct resource *platform_get_resource(struct platform_device *dev,
for (i = 0; i < dev->num_resources; i++) { for (i = 0; i < dev->num_resources; i++) {
struct resource *r = &dev->resource[i]; struct resource *r = &dev->resource[i];
if ((r->flags & (IORESOURCE_IO|IORESOURCE_MEM| if (type == resource_type(r) && num-- == 0)
IORESOURCE_IRQ|IORESOURCE_DMA)) == type) return r;
if (num-- == 0)
return r;
} }
return NULL; return NULL;
} }
...@@ -78,10 +76,8 @@ struct resource *platform_get_resource_byname(struct platform_device *dev, ...@@ -78,10 +76,8 @@ struct resource *platform_get_resource_byname(struct platform_device *dev,
for (i = 0; i < dev->num_resources; i++) { for (i = 0; i < dev->num_resources; i++) {
struct resource *r = &dev->resource[i]; struct resource *r = &dev->resource[i];
if ((r->flags & (IORESOURCE_IO|IORESOURCE_MEM| if (type == resource_type(r) && !strcmp(r->name, name))
IORESOURCE_IRQ|IORESOURCE_DMA)) == type) return r;
if (!strcmp(r->name, name))
return r;
} }
return NULL; return NULL;
} }
...@@ -259,9 +255,9 @@ int platform_device_add(struct platform_device *pdev) ...@@ -259,9 +255,9 @@ int platform_device_add(struct platform_device *pdev)
p = r->parent; p = r->parent;
if (!p) { if (!p) {
if (r->flags & IORESOURCE_MEM) if (resource_type(r) == IORESOURCE_MEM)
p = &iomem_resource; p = &iomem_resource;
else if (r->flags & IORESOURCE_IO) else if (resource_type(r) == IORESOURCE_IO)
p = &ioport_resource; p = &ioport_resource;
} }
...@@ -282,9 +278,14 @@ int platform_device_add(struct platform_device *pdev) ...@@ -282,9 +278,14 @@ int platform_device_add(struct platform_device *pdev)
return ret; return ret;
failed: failed:
while (--i >= 0) while (--i >= 0) {
if (pdev->resource[i].flags & (IORESOURCE_MEM|IORESOURCE_IO)) struct resource *r = &pdev->resource[i];
release_resource(&pdev->resource[i]); unsigned long type = resource_type(r);
if (type == IORESOURCE_MEM || type == IORESOURCE_IO)
release_resource(r);
}
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(platform_device_add); EXPORT_SYMBOL_GPL(platform_device_add);
...@@ -306,7 +307,9 @@ void platform_device_del(struct platform_device *pdev) ...@@ -306,7 +307,9 @@ void platform_device_del(struct platform_device *pdev)
for (i = 0; i < pdev->num_resources; i++) { for (i = 0; i < pdev->num_resources; i++) {
struct resource *r = &pdev->resource[i]; struct resource *r = &pdev->resource[i];
if (r->flags & (IORESOURCE_MEM|IORESOURCE_IO)) unsigned long type = resource_type(r);
if (type == IORESOURCE_MEM || type == IORESOURCE_IO)
release_resource(r); release_resource(r);
} }
} }
......
...@@ -34,7 +34,8 @@ struct resource_list { ...@@ -34,7 +34,8 @@ struct resource_list {
*/ */
#define IORESOURCE_BITS 0x000000ff /* Bus-specific bits */ #define IORESOURCE_BITS 0x000000ff /* Bus-specific bits */
#define IORESOURCE_IO 0x00000100 /* Resource type */ #define IORESOURCE_TYPE_BITS 0x00000f00 /* Resource type */
#define IORESOURCE_IO 0x00000100
#define IORESOURCE_MEM 0x00000200 #define IORESOURCE_MEM 0x00000200
#define IORESOURCE_IRQ 0x00000400 #define IORESOURCE_IRQ 0x00000400
#define IORESOURCE_DMA 0x00000800 #define IORESOURCE_DMA 0x00000800
...@@ -126,6 +127,10 @@ static inline resource_size_t resource_size(struct resource *res) ...@@ -126,6 +127,10 @@ static inline resource_size_t resource_size(struct resource *res)
{ {
return res->end - res->start + 1; return res->end - res->start + 1;
} }
static inline unsigned long resource_type(struct resource *res)
{
return res->flags & IORESOURCE_TYPE_BITS;
}
/* Convenience shorthand with allocation */ /* Convenience shorthand with allocation */
#define request_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name)) #define request_region(start,n,name) __request_region(&ioport_resource, (start), (n), (name))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment