summaryrefslogtreecommitdiff
path: root/src/devices
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices')
-rw-r--r--src/devices/device.c36
-rw-r--r--src/devices/device_util.c52
-rw-r--r--src/devices/root_device.c6
3 files changed, 60 insertions, 34 deletions
diff --git a/src/devices/device.c b/src/devices/device.c
index 96559c5833..033f41d2ca 100644
--- a/src/devices/device.c
+++ b/src/devices/device.c
@@ -169,9 +169,10 @@ struct pick_largest_state {
int seen_last;
};
-static void pick_largest_resource(struct pick_largest_state *state,
+static void pick_largest_resource(void *gp,
struct device *dev, struct resource *resource)
{
+ struct pick_largest_state *state = gp;
struct resource *last;
last = state->last;
/* Be certain to pick the successor to last */
@@ -197,33 +198,6 @@ static void pick_largest_resource(struct pick_largest_state *state,
}
}
-static void find_largest_resource(struct pick_largest_state *state,
- struct bus *bus, unsigned long type_mask, unsigned long type)
-{
- struct device *curdev;
- for(curdev = bus->children; curdev; curdev = curdev->sibling) {
- int i;
- /* Ignore disabled devices */
- if (!curdev->have_resources) continue;
- for(i = 0; i < curdev->resources; i++) {
- struct resource *resource = &curdev->resource[i];
- /* If it isn't the right kind of resource ignore it */
- if ((resource->flags & type_mask) != type) {
- continue;
- }
- /* If it is a subtractive resource recurse */
- if (resource->flags & IORESOURCE_SUBTRACTIVE) {
- struct bus *subbus;
- subbus = &curdev->link[resource->index];
- find_largest_resource(state, subbus, type_mask, type);
- continue;
- }
- /* See if this is the largest resource */
- pick_largest_resource(state, curdev, resource);
- }
- }
-}
-
static struct device *largest_resource(struct bus *bus, struct resource **result_res,
unsigned long type_mask, unsigned long type)
{
@@ -234,7 +208,7 @@ static struct device *largest_resource(struct bus *bus, struct resource **result
state.result = 0;
state.seen_last = 0;
- find_largest_resource(&state, bus, type_mask, type);
+ search_bus_resources(bus, type_mask, type, pick_largest_resource, &state);
*result_res = state.result;
return state.result_dev;
@@ -282,7 +256,7 @@ void compute_allocate_resource(
min_align = 0;
base = bridge->base;
- printk_spew("%s compute_allocate_%s: base: %08lx size: %08lx align: %d gran: %d\n",
+ printk_spew("%s compute_allocate_%s: base: %08Lx size: %08Lx align: %d gran: %d\n",
dev_path(bus->dev),
(bridge->flags & IORESOURCE_IO)? "io":
(bridge->flags & IORESOURCE_PREFETCH)? "prefmem" : "mem",
@@ -383,7 +357,7 @@ void compute_allocate_resource(
*/
bridge->size = round(base, bridge->gran) - bridge->base;
- printk_spew("%s compute_allocate_%s: base: %08lx size: %08lx align: %d gran: %d done\n",
+ printk_spew("%s compute_allocate_%s: base: %08Lx size: %08Lx align: %d gran: %d done\n",
dev_path(bus->dev),
(bridge->flags & IORESOURCE_IO)? "io":
(bridge->flags & IORESOURCE_PREFETCH)? "prefmem" : "mem",
diff --git a/src/devices/device_util.c b/src/devices/device_util.c
index 56a96015b8..fd8fdcf9b8 100644
--- a/src/devices/device_util.c
+++ b/src/devices/device_util.c
@@ -2,6 +2,7 @@
#include <device/device.h>
#include <device/path.h>
#include <device/pci.h>
+#include <device/resource.h>
#include <string.h>
/**
@@ -388,3 +389,54 @@ void report_resource_stored(device_t dev, struct resource *resource, const char
comment);
}
}
+
+void search_bus_resources(struct bus *bus,
+ unsigned long type_mask, unsigned long type,
+ resource_search_t search, void *gp)
+{
+ struct device *curdev;
+ for(curdev = bus->children; curdev; curdev = curdev->sibling) {
+ int i;
+ /* Ignore disabled devices */
+ if (!curdev->have_resources) continue;
+ for(i = 0; i < curdev->resources; i++) {
+ struct resource *resource = &curdev->resource[i];
+ /* If it isn't the right kind of resource ignore it */
+ if ((resource->flags & type_mask) != type) {
+ continue;
+ }
+ /* If it is a subtractive resource recurse */
+ if (resource->flags & IORESOURCE_SUBTRACTIVE) {
+ struct bus * subbus;
+ subbus = &curdev->link[IOINDEX_SUBTRACTIVE_LINK(resource->index)];
+ search_bus_resources(subbus, type_mask, type, search, gp);
+ continue;
+ }
+ search(gp, curdev, resource);
+ }
+ }
+}
+
+void search_global_resources(
+ unsigned long type_mask, unsigned long type,
+ resource_search_t search, void *gp)
+{
+ struct device *curdev;
+ for(curdev = all_devices; curdev; curdev = curdev->next) {
+ int i;
+ /* Ignore disabled devices */
+ if (!curdev->have_resources) continue;
+ for(i = 0; i < curdev->resources; i++) {
+ struct resource *resource = &curdev->resource[i];
+ /* If it isn't the right kind of resource ignore it */
+ if ((resource->flags & type_mask) != type) {
+ continue;
+ }
+ /* If it is a subtractive resource ignore it */
+ if (resource->flags & IORESOURCE_SUBTRACTIVE) {
+ continue;
+ }
+ search(gp, curdev, resource);
+ }
+ }
+}
diff --git a/src/devices/root_device.c b/src/devices/root_device.c
index 95189e0241..897a5a3bbf 100644
--- a/src/devices/root_device.c
+++ b/src/devices/root_device.c
@@ -72,7 +72,7 @@ unsigned int scan_static_bus(device_t bus, unsigned int max)
device_t child;
unsigned link;
- printk_debug("%s for %s\n", __func__, dev_path(bus));
+ printk_spew("%s for %s\n", __func__, dev_path(bus));
for(link = 0; link < bus->links; link++) {
for(child = bus->link[link].children; child; child = child->sibling) {
@@ -91,12 +91,12 @@ unsigned int scan_static_bus(device_t bus, unsigned int max)
for(child = bus->link[link].children; child; child = child->sibling) {
if (!child->ops || !child->ops->scan_bus)
continue;
- printk_debug("%s scanning...\n", dev_path(child));
+ printk_spew("%s scanning...\n", dev_path(child));
max = child->ops->scan_bus(child, max);
}
}
- printk_debug("%s done\n", __func__);
+ printk_spew("%s done\n", __func__);
return max;
}