Kyösti Mälkki (kyosti.malkki@gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/8891
-gerrit
commit dbc7f8d9b528e74eb37955c5d72de8940fe0f70a Author: Kyösti Mälkki kyosti.malkki@gmail.com Date: Thu Mar 26 20:04:38 2015 +0200
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 --- src/device/device.c | 63 +++++++++++++++++++++++-------------------- 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 c0efa1f..72f2373 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? */ @@ -1027,12 +1032,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; } } @@ -1054,12 +1059,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 c01540a..768c86d 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