Factor out a few commonly duplicated functions from northbridge.c.
[coreboot.git] / src / northbridge / intel / e7525 / northbridge.c
index 65404d6bf3235f39f9759639f201b1f86e175dbf..6ffe3b1b041b2dfd32d53cf64192178a46a11899 100644 (file)
 
 static unsigned int max_bus;
 
-static void ram_resource(device_t dev, unsigned long index, 
-       unsigned long basek, unsigned long sizek)
-{
-       struct resource *resource;
-
-       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;
-}
-
-
-static void pci_domain_read_resources(device_t dev)
-{
-       struct resource *resource;
-
-       /* Initialize the system wide io space constraints */
-       resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0,0));
-       resource->base  = 0;
-       resource->size  = 0;
-       resource->align = 0;
-       resource->gran  = 0;
-       resource->limit = 0xffffUL;
-       resource->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
-
-       /* Initialize the system wide memory resources constraints */
-       resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1,0));
-       resource->base  = 0;
-       resource->size  = 0;
-       resource->align = 0;
-       resource->gran  = 0;
-       resource->limit = 0xffffffffUL;
-       resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
-}
-
-static 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;
-}
-
-static uint32_t find_pci_tolm(struct bus *bus)
-{
-       struct resource *min;
-       uint32_t tolm;
-       min = 0;
-       search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test, &min);
-       tolm = 0xffffffffUL;
-       if (min && tolm > min->base) {
-               tolm = min->base;
-       }
-       return tolm;
-}
-
-#if CONFIG_HAVE_HIGH_TABLES==1
+#if CONFIG_WRITE_HIGH_TABLES==1
 #define HIGH_TABLES_SIZE 64    // maximum size of high tables in KB
 extern uint64_t high_tables_base, high_tables_size;
 #endif
@@ -86,17 +26,17 @@ static void pci_domain_set_resources(device_t dev)
        device_t mc_dev;
        uint32_t pci_tolm;
 
-        pci_tolm = find_pci_tolm(&dev->link[0]);
+        pci_tolm = find_pci_tolm(dev->link_list);
 
 #if 1
-       printk_debug("PCI mem marker = %x\n", pci_tolm);
-#endif 
+       printk(BIOS_DEBUG, "PCI mem marker = %x\n", pci_tolm);
+#endif
        /* FIXME Me temporary hack */
        if(pci_tolm > 0xe0000000)
                pci_tolm = 0xe0000000;
        /* Ensure pci_tolm is 128M aligned */
        pci_tolm &= 0xf8000000;
-       mc_dev = dev->link[0].children;
+       mc_dev = dev->link_list->children;
        if (mc_dev) {
                /* Figure out which areas are/should be occupied by RAM.
                 * This is all computed in kilobytes and converted to/from
@@ -122,7 +62,7 @@ static void pci_domain_set_resources(device_t dev)
                        remapbasek   = 0x3ff << 16;
                        remaplimitk  = 0 << 16;
                        remapoffsetk = 0 << 16;
-               } 
+               }
                else {
                        /* The PCI memory hole overlaps memory
                         * setup the remap window.
@@ -160,39 +100,36 @@ static void pci_domain_set_resources(device_t dev)
 
                /* Report the memory regions */
                ram_resource(dev, 3,   0, 640);
-               ram_resource(dev, 4, 768, tolmk - 768);
+               ram_resource(dev, 4, 768, (tolmk - 768));
                if (tomk > 4*1024*1024) {
                        ram_resource(dev, 5, 4096*1024, tomk - 4*1024*1024);
                }
                if (remaplimitk >= remapbasek) {
-                       ram_resource(dev, 6, remapbasek, 
+                       ram_resource(dev, 6, remapbasek,
                                (remaplimitk + 64*1024) - remapbasek);
                }
 
-#if CONFIG_HAVE_HIGH_TABLES==1
+#if CONFIG_WRITE_HIGH_TABLES==1
                /* Leave some space for ACPI, PIRQ and MP tables */
                high_tables_base = (tolmk - HIGH_TABLES_SIZE) * 1024;
                high_tables_size = HIGH_TABLES_SIZE * 1024;
 #endif
        }
-       assign_resources(&dev->link[0]);
+       assign_resources(dev->link_list);
 }
 
-static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max)
+static u32 e7525_domain_scan_bus(device_t dev, u32 max)
 {
-       max = pci_scan_bus(&dev->link[0], 0, 0xff, max);
-       if (max > max_bus) {
-               max_bus = max;
-       }
-       return max;
+       max_bus = pci_domain_scan_bus(dev, max);
+       return max_bus;
 }
 
 static struct device_operations pci_domain_ops = {
        .read_resources   = pci_domain_read_resources,
        .set_resources    = pci_domain_set_resources,
-       .enable_resources = enable_childrens_resources,
-       .init             = 0,
-       .scan_bus         = pci_domain_scan_bus,
+       .enable_resources = NULL,
+       .init             = NULL,
+       .scan_bus         = e7525_domain_scan_bus,
        .ops_pci_bus      = &pci_cf8_conf1, /* Do we want to use the memory mapped space here? */
 };
 
@@ -210,9 +147,8 @@ static void mc_read_resources(device_t dev)
 
 static void mc_set_resources(device_t dev)
 {
-       struct resource *resource, *last;
+       struct resource *resource;
 
-       last = &dev->resource[dev->resources];
        resource = find_resource(dev, 0xcf);
        if (resource) {
                report_resource_stored(dev, resource, "<mmconfig>");
@@ -222,7 +158,7 @@ static void mc_set_resources(device_t dev)
 
 static void intel_set_subsystem(device_t dev, unsigned vendor, unsigned device)
 {
-       pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, 
+       pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
                ((device & 0xffff) << 16) | (vendor & 0xffff));
 }
 
@@ -247,7 +183,7 @@ static const struct pci_driver mc_driver __pci_driver = {
 
 static void cpu_bus_init(device_t dev)
 {
-        initialize_cpus(&dev->link[0]);
+        initialize_cpus(dev->link_list);
 }
 
 static void cpu_bus_noop(device_t dev)