diff options
author | Kyösti Mälkki <kyosti.malkki@gmail.com> | 2015-03-26 20:04:38 +0200 |
---|---|---|
committer | Kyösti Mälkki <kyosti.malkki@gmail.com> | 2015-06-10 05:51:51 +0200 |
commit | fdc0a902d4231fee86d70dfd9bc7207e41642ea3 (patch) | |
tree | 4f0a3aa47693f8e71f22a0bce9845e5d40c76961 | |
parent | fcbebb61c59e2af7aacc03a6215650a0369d4c69 (diff) | |
download | coreboot-fdc0a902d4231fee86d70dfd9bc7207e41642ea3.tar.xz |
resource: Refactor IORESOURCE flags use
The type of a resource is really an enumeration but our implementation
is as a bitmask. Compare all relevant bits and remove the shadowed
declarations of IORESOURCE bits.
Change-Id: I7f605d72ea702eb4fa6019ca1297f98d240c4f1a
Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-on: http://review.coreboot.org/8891
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
-rw-r--r-- | src/device/device.c | 63 | ||||
-rw-r--r-- | src/include/device/resource.h | 2 |
2 files changed, 36 insertions, 29 deletions
diff --git a/src/device/device.c b/src/device/device.c index c9ccfcc9bc..cf418eb4d1 100644 --- a/src/device/device.c +++ b/src/device/device.c @@ -611,16 +611,28 @@ static void allocate_resources(struct bus *bus, struct resource *bridge, } } -#define MEM_MASK (IORESOURCE_MEM) -#define IO_MASK (IORESOURCE_IO) -#define PREF_TYPE (IORESOURCE_PREFETCH | IORESOURCE_MEM) -#define MEM_TYPE (IORESOURCE_MEM) -#define IO_TYPE (IORESOURCE_IO) +static int resource_is(struct resource *res, u32 type) +{ + return (res->flags & IORESOURCE_TYPE_MASK) == type; +} struct constraints { struct resource io, mem; }; +static struct resource * resource_limit(struct constraints *limits, struct resource *res) +{ + struct resource *lim = NULL; + + /* MEM, or I/O - skip any others. */ + if (resource_is(res, IORESOURCE_MEM)) + lim = &limits->mem; + else if (resource_is(res, IORESOURCE_IO)) + lim = &limits->io; + + return lim; +} + static void constrain_resources(struct device *dev, struct constraints* limits) { struct device *child; @@ -639,12 +651,8 @@ static void constrain_resources(struct device *dev, struct constraints* limits) continue; } - /* MEM, or I/O - skip any others. */ - if ((res->flags & MEM_MASK) == MEM_TYPE) - lim = &limits->mem; - else if ((res->flags & IO_MASK) == IO_TYPE) - lim = &limits->io; - else + lim = resource_limit(limits, res); + if (!lim) continue; /* @@ -685,6 +693,7 @@ static void avoid_fixed_resources(struct device *dev) { struct constraints limits; struct resource *res; + struct resource *lim; printk(BIOS_SPEW, "%s: %s\n", __func__, dev_path(dev)); @@ -701,12 +710,14 @@ static void avoid_fixed_resources(struct device *dev) printk(BIOS_SPEW, "%s:@%s %02lx limit %08llx\n", __func__, dev_path(dev), res->index, res->limit); - if ((res->flags & MEM_MASK) == MEM_TYPE && - (res->limit < limits.mem.limit)) - limits.mem.limit = res->limit; - if ((res->flags & IO_MASK) == IO_TYPE && - (res->limit < limits.io.limit)) - limits.io.limit = res->limit; + lim = resource_limit(&limits, res); + if (!lim) + continue; + + if (res->base > lim->base) + lim->base = res->base; + if (res->limit < lim->limit) + lim->limit = res->limit; } /* Look through the tree for fixed resources and update the limits. */ @@ -714,17 +725,11 @@ static void avoid_fixed_resources(struct device *dev) /* Update dev's resources with new limits. */ for (res = dev->resource_list; res; res = res->next) { - struct resource *lim; - if ((res->flags & IORESOURCE_FIXED)) continue; - /* MEM, or I/O - skip any others. */ - if ((res->flags & MEM_MASK) == MEM_TYPE) - lim = &limits.mem; - else if ((res->flags & IO_MASK) == IO_TYPE) - lim = &limits.io; - else + lim = resource_limit(&limits, res); + if (!lim) continue; /* Is the resource outside the limits? */ @@ -1034,12 +1039,12 @@ void dev_configure(void) continue; if (res->flags & IORESOURCE_MEM) { compute_resources(child->link_list, - res, MEM_MASK, MEM_TYPE); + res, IORESOURCE_TYPE_MASK, IORESOURCE_MEM); continue; } if (res->flags & IORESOURCE_IO) { compute_resources(child->link_list, - res, IO_MASK, IO_TYPE); + res, IORESOURCE_TYPE_MASK, IORESOURCE_IO); continue; } } @@ -1061,12 +1066,12 @@ void dev_configure(void) continue; if (res->flags & IORESOURCE_MEM) { allocate_resources(child->link_list, - res, MEM_MASK, MEM_TYPE); + res, IORESOURCE_TYPE_MASK, IORESOURCE_MEM); continue; } if (res->flags & IORESOURCE_IO) { allocate_resources(child->link_list, - res, IO_MASK, IO_TYPE); + res, IORESOURCE_TYPE_MASK, IORESOURCE_IO); continue; } } diff --git a/src/include/device/resource.h b/src/include/device/resource.h index c01540ae3a..768c86d46a 100644 --- a/src/include/device/resource.h +++ b/src/include/device/resource.h @@ -11,6 +11,8 @@ #define IORESOURCE_IRQ 0x00000400 #define IORESOURCE_DRQ 0x00000800 +#define IORESOURCE_TYPE_MASK (IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_IRQ | IORESOURCE_DRQ) + #define IORESOURCE_PREFETCH 0x00001000 /* No side effects */ #define IORESOURCE_READONLY 0x00002000 #define IORESOURCE_CACHEABLE 0x00004000 |