From 4b42a62966527f18f3894af953b0757080424b00 Mon Sep 17 00:00:00 2001 From: Uwe Hermann Date: Mon, 11 Oct 2010 19:36:13 +0000 Subject: Factor out a few commonly duplicated functions from northbridge.c. The following functions are moved to devices/device_util.c: - ram_resource() - tolm_test() - find_pci_tolm() There are only two tolm_test() / find_pci_tolm() which differ from the defaults, one of them can easily be eliminated in a follow-up patch, maybe even both, but for now keep it simple and only eliminate the majority. Signed-off-by: Uwe Hermann Acked-by: Peter Stuge git-svn-id: svn://svn.coreboot.org/coreboot/trunk@5937 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1 --- src/devices/device_util.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'src/devices') diff --git a/src/devices/device_util.c b/src/devices/device_util.c index c845ecd35d..2c46884d9e 100644 --- a/src/devices/device_util.c +++ b/src/devices/device_util.c @@ -730,3 +730,47 @@ void show_all_devs_resources(int debug_level, const char* msg) show_one_resource(debug_level, dev, res, ""); } } + +void ram_resource(device_t dev, unsigned long index, + unsigned long basek, unsigned long sizek) +{ + struct resource *resource; + + if (!sizek) + return; + + resource = new_resource(dev, index); + resource->base = ((resource_t)basek) << 10; + resource->size = ((resource_t)sizek) << 10; + resource->flags = IORESOURCE_MEM | IORESOURCE_CACHEABLE | \ + IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED; +} + +void tolm_test(void *gp, struct device *dev, struct resource *new) +{ + struct resource **best_p = gp; + struct resource *best; + + best = *best_p; + + if (!best || (best->base > new->base)) + best = new; + + *best_p = best; +} + +u32 find_pci_tolm(struct bus *bus) +{ + struct resource *min = NULL; + u32 tolm; + + search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, + tolm_test, &min); + + tolm = 0xffffffffUL; + + if (min && tolm > min->base) + tolm = min->base; + + return tolm; +} -- cgit v1.2.3