mirror of
https://github.com/fail0verflow/switch-coreboot.git
synced 2025-05-04 01:39:18 -04:00
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>
This commit is contained in:
parent
fcbebb61c5
commit
fdc0a902d4
2 changed files with 36 additions and 29 deletions
|
@ -611,16 +611,28 @@ static void allocate_resources(struct bus *bus, struct resource *bridge,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define MEM_MASK (IORESOURCE_MEM)
|
static int resource_is(struct resource *res, u32 type)
|
||||||
#define IO_MASK (IORESOURCE_IO)
|
{
|
||||||
#define PREF_TYPE (IORESOURCE_PREFETCH | IORESOURCE_MEM)
|
return (res->flags & IORESOURCE_TYPE_MASK) == type;
|
||||||
#define MEM_TYPE (IORESOURCE_MEM)
|
}
|
||||||
#define IO_TYPE (IORESOURCE_IO)
|
|
||||||
|
|
||||||
struct constraints {
|
struct constraints {
|
||||||
struct resource io, mem;
|
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)
|
static void constrain_resources(struct device *dev, struct constraints* limits)
|
||||||
{
|
{
|
||||||
struct device *child;
|
struct device *child;
|
||||||
|
@ -639,12 +651,8 @@ static void constrain_resources(struct device *dev, struct constraints* limits)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* MEM, or I/O - skip any others. */
|
lim = resource_limit(limits, res);
|
||||||
if ((res->flags & MEM_MASK) == MEM_TYPE)
|
if (!lim)
|
||||||
lim = &limits->mem;
|
|
||||||
else if ((res->flags & IO_MASK) == IO_TYPE)
|
|
||||||
lim = &limits->io;
|
|
||||||
else
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -685,6 +693,7 @@ static void avoid_fixed_resources(struct device *dev)
|
||||||
{
|
{
|
||||||
struct constraints limits;
|
struct constraints limits;
|
||||||
struct resource *res;
|
struct resource *res;
|
||||||
|
struct resource *lim;
|
||||||
|
|
||||||
printk(BIOS_SPEW, "%s: %s\n", __func__, dev_path(dev));
|
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__,
|
printk(BIOS_SPEW, "%s:@%s %02lx limit %08llx\n", __func__,
|
||||||
dev_path(dev), res->index, res->limit);
|
dev_path(dev), res->index, res->limit);
|
||||||
|
|
||||||
if ((res->flags & MEM_MASK) == MEM_TYPE &&
|
lim = resource_limit(&limits, res);
|
||||||
(res->limit < limits.mem.limit))
|
if (!lim)
|
||||||
limits.mem.limit = res->limit;
|
continue;
|
||||||
if ((res->flags & IO_MASK) == IO_TYPE &&
|
|
||||||
(res->limit < limits.io.limit))
|
if (res->base > lim->base)
|
||||||
limits.io.limit = res->limit;
|
lim->base = res->base;
|
||||||
|
if (res->limit < lim->limit)
|
||||||
|
lim->limit = res->limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Look through the tree for fixed resources and update the limits. */
|
/* 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. */
|
/* Update dev's resources with new limits. */
|
||||||
for (res = dev->resource_list; res; res = res->next) {
|
for (res = dev->resource_list; res; res = res->next) {
|
||||||
struct resource *lim;
|
|
||||||
|
|
||||||
if ((res->flags & IORESOURCE_FIXED))
|
if ((res->flags & IORESOURCE_FIXED))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* MEM, or I/O - skip any others. */
|
lim = resource_limit(&limits, res);
|
||||||
if ((res->flags & MEM_MASK) == MEM_TYPE)
|
if (!lim)
|
||||||
lim = &limits.mem;
|
|
||||||
else if ((res->flags & IO_MASK) == IO_TYPE)
|
|
||||||
lim = &limits.io;
|
|
||||||
else
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Is the resource outside the limits? */
|
/* Is the resource outside the limits? */
|
||||||
|
@ -1034,12 +1039,12 @@ void dev_configure(void)
|
||||||
continue;
|
continue;
|
||||||
if (res->flags & IORESOURCE_MEM) {
|
if (res->flags & IORESOURCE_MEM) {
|
||||||
compute_resources(child->link_list,
|
compute_resources(child->link_list,
|
||||||
res, MEM_MASK, MEM_TYPE);
|
res, IORESOURCE_TYPE_MASK, IORESOURCE_MEM);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (res->flags & IORESOURCE_IO) {
|
if (res->flags & IORESOURCE_IO) {
|
||||||
compute_resources(child->link_list,
|
compute_resources(child->link_list,
|
||||||
res, IO_MASK, IO_TYPE);
|
res, IORESOURCE_TYPE_MASK, IORESOURCE_IO);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1061,12 +1066,12 @@ void dev_configure(void)
|
||||||
continue;
|
continue;
|
||||||
if (res->flags & IORESOURCE_MEM) {
|
if (res->flags & IORESOURCE_MEM) {
|
||||||
allocate_resources(child->link_list,
|
allocate_resources(child->link_list,
|
||||||
res, MEM_MASK, MEM_TYPE);
|
res, IORESOURCE_TYPE_MASK, IORESOURCE_MEM);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (res->flags & IORESOURCE_IO) {
|
if (res->flags & IORESOURCE_IO) {
|
||||||
allocate_resources(child->link_list,
|
allocate_resources(child->link_list,
|
||||||
res, IO_MASK, IO_TYPE);
|
res, IORESOURCE_TYPE_MASK, IORESOURCE_IO);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,8 @@
|
||||||
#define IORESOURCE_IRQ 0x00000400
|
#define IORESOURCE_IRQ 0x00000400
|
||||||
#define IORESOURCE_DRQ 0x00000800
|
#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_PREFETCH 0x00001000 /* No side effects */
|
||||||
#define IORESOURCE_READONLY 0x00002000
|
#define IORESOURCE_READONLY 0x00002000
|
||||||
#define IORESOURCE_CACHEABLE 0x00004000
|
#define IORESOURCE_CACHEABLE 0x00004000
|
||||||
|
|
Loading…
Add table
Reference in a new issue