[coreboot-gerrit] New patch to review for coreboot: 16f2649 resource: Declare IORESOURCE_TYPE and resource_match()
Kyösti Mälkki (kyosti.malkki@gmail.com)
gerrit at coreboot.org
Tue Mar 24 05:29:59 CET 2015
Kyösti Mälkki (kyosti.malkki at gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/8894
-gerrit
commit 16f264999ee98011efba3e9c78b4915bec6e14fd
Author: Kyösti Mälkki <kyosti.malkki at gmail.com>
Date: Mon Mar 23 22:56:43 2015 +0200
resource: Declare IORESOURCE_TYPE and resource_match()
Change-Id: I0ccfa07479f5c5998c1191dbc4eed77aca78799b
Signed-off-by: Kyösti Mälkki <kyosti.malkki at gmail.com>
---
src/device/device.c | 49 +++++++++++++++++++------------------------
src/include/device/resource.h | 2 ++
2 files changed, 24 insertions(+), 27 deletions(-)
diff --git a/src/device/device.c b/src/device/device.c
index 3aa4875..0e7344f 100644
--- a/src/device/device.c
+++ b/src/device/device.c
@@ -278,10 +278,11 @@ static void pick_largest_resource(void *gp, struct device *dev,
static struct device *largest_resource(struct bus *bus,
struct resource **result_res,
- unsigned long type_mask,
- unsigned long type)
+ struct resource *bridge)
{
struct pick_largest_state state;
+ u32 type_mask = (IORESOURCE_TYPE | IORESOURCE_PREFETCH);
+ u32 type = bridge->flags & type_mask;
state.last = *result_res;
state.result_dev = NULL;
@@ -295,12 +296,17 @@ static struct device *largest_resource(struct bus *bus,
return state.result_dev;
}
-#define IORESOURCE_TYPE (IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_PREFETCH)
-
static int resource_match(struct resource *res, struct resource *lim)
{
- u32 mask = (IORESOURCE_TYPE & ~IORESOURCE_PREFETCH);
- return (res->flags & mask) == (lim->flags & mask);
+ return (res->flags & IORESOURCE_TYPE) == (lim->flags & IORESOURCE_TYPE);
+}
+
+static int resource_match_bridge(struct resource *res, struct resource *win)
+{
+ u32 type_mask = (IORESOURCE_TYPE | IORESOURCE_PREFETCH);
+ if (!(res->flags & IORESOURCE_BRIDGE))
+ return 0;
+ return (res->flags & type_mask) == (win->flags & type_mask);
}
/**
@@ -332,12 +338,8 @@ static int resource_match(struct resource *res, struct resource *lim)
*
* @param bus The bus we are traversing.
* @param bridge The bridge resource which must contain the bus' resources.
- * @param type_mask This value gets ANDed with the resource type.
- * @param type This value must match the result of the AND.
- * @return TODO
*/
-static void compute_resources(struct bus *bus, struct resource *bridge,
- unsigned long type_mask, unsigned long type)
+static void compute_resources(struct bus *bus, struct resource *bridge)
{
struct device *dev;
struct resource *resource;
@@ -361,8 +363,7 @@ static void compute_resources(struct bus *bus, struct resource *bridge,
child_bridge = child_bridge->next) {
struct bus* link;
- if (!(child_bridge->flags & IORESOURCE_BRIDGE)
- || (child_bridge->flags & type_mask) != type)
+ if (!resource_match_bridge(child_bridge, bridge))
continue;
link = dev->link_list;
@@ -376,7 +377,7 @@ static void compute_resources(struct bus *bus, struct resource *bridge,
dev_path(dev));
}
- compute_resources(link, child_bridge, type_mask, type);
+ compute_resources(link, child_bridge);
}
}
@@ -388,7 +389,7 @@ static void compute_resources(struct bus *bus, struct resource *bridge,
* amount of address space taken by them. Take granularity and
* alignment into account.
*/
- while ((dev = largest_resource(bus, &resource, type_mask, type))) {
+ while ((dev = largest_resource(bus, &resource, bridge))) {
/* Size 0 resources can be skipped. */
if (!resource->size)
@@ -465,13 +466,10 @@ static void compute_resources(struct bus *bus, struct resource *bridge,
*
* @param bus The bus we are traversing.
* @param bridge The bridge resource which must contain the bus' resources.
- * @param type_mask This value gets ANDed with the resource type.
- * @param type This value must match the result of the AND.
*
* @see compute_resources
*/
-static void allocate_resources(struct bus *bus, struct resource *bridge,
- unsigned long type_mask, unsigned long type)
+static void allocate_resources(struct bus *bus, struct resource *bridge)
{
struct device *dev;
struct resource *resource;
@@ -490,7 +488,7 @@ static void allocate_resources(struct bus *bus, struct resource *bridge,
* Walk through all the resources on the current bus and allocate them
* address space.
*/
- while ((dev = largest_resource(bus, &resource, type_mask, type))) {
+ while ((dev = largest_resource(bus, &resource, bridge))) {
/* Propagate the bridge limit to the resource register. */
if (resource->limit > bridge->limit)
@@ -581,8 +579,7 @@ static void allocate_resources(struct bus *bus, struct resource *bridge,
child_bridge = child_bridge->next) {
struct bus* link;
- if (!(child_bridge->flags & IORESOURCE_BRIDGE) ||
- (child_bridge->flags & type_mask) != type)
+ if (!resource_match_bridge(child_bridge, bridge))
continue;
link = dev->link_list;
@@ -594,7 +591,7 @@ static void allocate_resources(struct bus *bus, struct resource *bridge,
IOINDEX_LINK(child_bridge->index),
dev_path(dev));
- allocate_resources(link, child_bridge, type_mask, type);
+ allocate_resources(link, child_bridge);
}
}
}
@@ -972,8 +969,7 @@ void dev_configure(void)
if (res->flags & IORESOURCE_FIXED)
continue;
- compute_resources(child->link_list, res,
- IORESOURCE_TYPE, res->flags & IORESOURCE_TYPE);
+ compute_resources(child->link_list, res);
}
}
@@ -992,8 +988,7 @@ void dev_configure(void)
if (res->flags & IORESOURCE_FIXED)
continue;
- allocate_resources(child->link_list, res,
- IORESOURCE_TYPE, res->flags & IORESOURCE_TYPE);
+ allocate_resources(child->link_list, res);
}
}
assign_resources(root->link_list);
diff --git a/src/include/device/resource.h b/src/include/device/resource.h
index c01540a..b7f2d67 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 (IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_IRQ | IORESOURCE_DRQ)
+
#define IORESOURCE_PREFETCH 0x00001000 /* No side effects */
#define IORESOURCE_READONLY 0x00002000
#define IORESOURCE_CACHEABLE 0x00004000
More information about the coreboot-gerrit
mailing list