[coreboot] [PATCH] Factor out a few commonly duplicated functions from northbridge.c

Uwe Hermann uwe at hermann-uwe.de
Sun Oct 24 15:27:33 CEST 2010


On Mon, Oct 11, 2010 at 09:24:07PM +0200, Peter Stuge wrote:
> Uwe Hermann wrote:
> > 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,
> 
> How do they differ?

This is the common implementation now factored out:

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;
}


The diff to that in the K8 version is this (in tolm_test()):

-        if (!best || (best->base > new->base))
+        /* Skip VGA. */
+        if (!best || (best->base > new->base && new->base > 0xa0000)) {

Small fix which could also be moved into the global tolm_test(). Depending on
whether or not we want _all_ northbridges to skip that VGA range, we
could add a parameter to the funtion, or just always skip it.


The version on Fam10h is this, not sure if this is worth the hassle:

static u32 my_find_pci_tolm(struct bus *bus, u32 tolm)
{
        struct resource *min;
        min = 0;
        search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test, &min);
        if (min && tolm > min->base) {
                tolm = min->base;
        }
        return tolm;
}

And then later:

        pci_tolm = 0xffffffffUL;
        for(link = dev->link_list; link; link = link->next) {
                pci_tolm = my_find_pci_tolm(link, pci_tolm);
        }


Uwe.
-- 
http://hermann-uwe.de     | http://sigrok.org
http://randomprojects.org | http://unmaintained-free-software.org




More information about the coreboot mailing list