printk_foo -> printk(BIOS_FOO, ...)
[coreboot.git] / src / northbridge / amd / amdfam10 / northbridge.c
index 79e52b82b814fdbefbb9ffacf1d21ccd4665e709..543d74cbfd65e363eaa1c7fd4f1c2ff9c9c9626f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * This file is part of the LinuxBIOS project.
+ * This file is part of the coreboot project.
  *
  * Copyright (C) 2007 Advanced Micro Devices, Inc.
  *
@@ -42,7 +42,7 @@
 
 #include "amdfam10.h"
 
-#if HW_MEM_HOLE_SIZEK != 0
+#if CONFIG_HW_MEM_HOLE_SIZEK != 0
 #include <cpu/amd/model_10xxx_rev.h>
 #endif
 
@@ -60,13 +60,13 @@ device_t get_node_pci(u32 nodeid, u32 fn)
 {
 #if NODE_NUMS == 64
        if(nodeid<32) {
-               return dev_find_slot(CBB, PCI_DEVFN(CDB + nodeid, fn));
+               return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn));
        } else {
-               return dev_find_slot(CBB-1, PCI_DEVFN(CDB + nodeid - 32, fn));
+               return dev_find_slot(CONFIG_CBB-1, PCI_DEVFN(CONFIG_CDB + nodeid - 32, fn));
        }
 
 #else
-       return dev_find_slot(CBB, PCI_DEVFN(CDB + nodeid, fn));
+       return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn));
 #endif
 
 }
@@ -83,7 +83,7 @@ static void get_fx_devs(void)
                __f4_dev[i] = get_node_pci(i, 4);
        }
        if (!__f1_dev[0]) {
-               printk_err("Cannot find %02x:%02x.1", CBB, CDB);
+               printk(BIOS_ERR, "Cannot find %02x:%02x.1", CONFIG_CBB, CONFIG_CDB);
                die("Cannot go on\n");
        }
 }
@@ -113,14 +113,14 @@ static u32 amdfam10_nodeid(device_t dev)
 #if NODE_NUMS == 64
        unsigned busn;
        busn = dev->bus->secondary;
-       if(busn != CBB) {
-               return (dev->path.u.pci.devfn >> 3) - CDB + 32;
+       if(busn != CONFIG_CBB) {
+               return (dev->path.pci.devfn >> 3) - CONFIG_CDB + 32;
        } else {
-               return (dev->path.u.pci.devfn >> 3) - CDB;
+               return (dev->path.pci.devfn >> 3) - CONFIG_CDB;
        }
 
 #else
-       return (dev->path.u.pci.devfn >> 3) - CDB;
+       return (dev->path.pci.devfn >> 3) - CONFIG_CDB;
 #endif
 }
 
@@ -156,7 +156,7 @@ static u32 amdfam10_scan_chain(device_t dev, u32 nodeid, u32 link, u32 sblink,
                u32 busn = max&0xff;
                u32 max_devfn;
 
-#if HT3_SUPPORT==1
+#if CONFIG_HT3_SUPPORT==1
                if(is_sublink1) {
                        u32 regpos;
                        u32 reg;
@@ -187,7 +187,7 @@ static u32 amdfam10_scan_chain(device_t dev, u32 nodeid, u32 link, u32 sblink,
                 */
                ht_c_index = get_ht_c_index(nodeid, link, &sysconf);
 
-#if EXT_CONF_SUPPORT == 0
+#if CONFIG_EXT_CONF_SUPPORT == 0
                if(ht_c_index>=4) return max;
 #endif
 
@@ -196,12 +196,12 @@ static u32 amdfam10_scan_chain(device_t dev, u32 nodeid, u32 link, u32 sblink,
                 * so we set the subordinate bus number to 0xff for the moment.
                 */
 
-#if SB_HT_CHAIN_ON_BUS0 > 0
+#if CONFIG_SB_HT_CHAIN_ON_BUS0 > 0
                // first chain will on bus 0
                if((nodeid == 0) && (sblink==link)) { // actually max is 0 here
                         min_bus = max;
                }
-       #if SB_HT_CHAIN_ON_BUS0 > 1
+       #if CONFIG_SB_HT_CHAIN_ON_BUS0 > 1
                // second chain will be on 0x40, third 0x80, forth 0xc0
                // i would refined that to  2, 3, 4 ==> 0, 0x, 40, 0x80, 0xc0
                //                          >4 will use  more segments, We can have 16 segmment and every segment have 256 bus, For that case need the kernel support mmio pci config.
@@ -295,9 +295,9 @@ static u32 amdfam10_scan_chains(device_t dev, u32 max)
 
 
 // Put sb chain in bus 0
-#if SB_HT_CHAIN_ON_BUS0 > 0
+#if CONFIG_SB_HT_CHAIN_ON_BUS0 > 0
        if(nodeid==0) {
-       #if ((HT_CHAIN_UNITID_BASE != 1) || (HT_CHAIN_END_UNITID_BASE != 0x20))
+       #if ((CONFIG_HT_CHAIN_UNITID_BASE != 1) || (CONFIG_HT_CHAIN_END_UNITID_BASE != 0x20))
                offset_unitid = 1;
        #endif
                max = amdfam10_scan_chain(dev, nodeid, sblink, sblink, max, offset_unitid ); // do sb ht chain at first, in case s2885 put sb chain (8131/8111) on link2, but put 8151 on link0
@@ -305,18 +305,18 @@ static u32 amdfam10_scan_chains(device_t dev, u32 max)
 #endif
 
 
-#if PCI_BUS_SEGN_BITS
+#if CONFIG_PCI_BUS_SEGN_BITS
        max = check_segn(dev, max, sysconf.nodes, &sysconf);
 #endif
 
 
        for(link = 0; link < dev->links; link++) {
-#if SB_HT_CHAIN_ON_BUS0 > 0
+#if CONFIG_SB_HT_CHAIN_ON_BUS0 > 0
                if( (nodeid == 0) && (sblink == link) ) continue; //already done
 #endif
                offset_unitid = 0;
-               #if ((HT_CHAIN_UNITID_BASE != 1) || (HT_CHAIN_END_UNITID_BASE != 0x20))
-                       #if SB_HT_CHAIN_UNITID_OFFSET_ONLY == 1
+               #if ((CONFIG_HT_CHAIN_UNITID_BASE != 1) || (CONFIG_HT_CHAIN_END_UNITID_BASE != 0x20))
+                       #if CONFIG_SB_HT_CHAIN_UNITID_OFFSET_ONLY == 1
                        if((nodeid == 0) && (sblink == link))
                        #endif
                                offset_unitid = 1;
@@ -338,8 +338,10 @@ static int reg_useable(u32 reg,device_t goal_dev, u32 goal_nodeid,
        for(nodeid = 0; !res && (nodeid < NODE_NUMS); nodeid++) {
                device_t dev;
                dev = __f0_dev[nodeid];
+               if (!dev)
+                       continue;
                for(link = 0; !res && (link < 8); link++) {
-                       res = probe_resource(dev, 0x1000 + reg + (link<<16)); // 8 links, 0x1000 man f1,
+                       res = probe_resource(dev, IOINDEX(0x1000 + reg, link));
                }
        }
        result = 2;
@@ -383,7 +385,7 @@ static struct resource *amdfam10_find_iopair(device_t dev, u32 nodeid, u32 link)
                reg = 0x110+ (index<<24) + (4<<20); // index could be 0, 255
        }
 
-       resource = new_resource(dev, 0x1000 + reg + (link<<16));
+               resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
 
        return resource;
 }
@@ -419,7 +421,7 @@ static struct resource *amdfam10_find_mempair(device_t dev, u32 nodeid, u32 link
                reg = 0x110+ (index<<24) + (6<<20); // index could be 0, 63
 
        }
-       resource = new_resource(dev, 0x1000 + reg + (link<<16));
+       resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
        return resource;
 }
 
@@ -432,7 +434,7 @@ static void amdfam10_link_read_bases(device_t dev, u32 nodeid, u32 link)
        resource =  amdfam10_find_iopair(dev, nodeid, link);
        if (resource) {
                u32 align;
-#if EXT_CONF_SUPPORT == 1
+#if CONFIG_EXT_CONF_SUPPORT == 1
                if((resource->index & 0x1fff) == 0x1110) { // ext
                        align = 8;
                }
@@ -444,9 +446,7 @@ static void amdfam10_link_read_bases(device_t dev, u32 nodeid, u32 link)
                resource->align = align;
                resource->gran  = align;
                resource->limit = 0xffffUL;
-               resource->flags = IORESOURCE_IO;
-               compute_allocate_resource(&dev->link[link], resource,
-                                       IORESOURCE_IO, IORESOURCE_IO);
+               resource->flags = IORESOURCE_IO | IORESOURCE_BRIDGE;
        }
 
        /* Initialize the prefetchable memory constraints on the current bus */
@@ -457,12 +457,9 @@ static void amdfam10_link_read_bases(device_t dev, u32 nodeid, u32 link)
                resource->align = log2(HT_MEM_HOST_ALIGN);
                resource->gran  = log2(HT_MEM_HOST_ALIGN);
                resource->limit = 0xffffffffffULL;
-               resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
-               compute_allocate_resource(&dev->link[link], resource,
-                       IORESOURCE_MEM | IORESOURCE_PREFETCH,
-                       IORESOURCE_MEM | IORESOURCE_PREFETCH);
+               resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH | IORESOURCE_BRIDGE;
 
-#if EXT_CONF_SUPPORT == 1
+#if CONFIG_EXT_CONF_SUPPORT == 1
                if((resource->index & 0x1fff) == 0x1110) { // ext
                        normalize_resource(resource);
                }
@@ -478,12 +475,9 @@ static void amdfam10_link_read_bases(device_t dev, u32 nodeid, u32 link)
                resource->align = log2(HT_MEM_HOST_ALIGN);
                resource->gran  = log2(HT_MEM_HOST_ALIGN);
                resource->limit = 0xffffffffffULL;
-               resource->flags = IORESOURCE_MEM;
-               compute_allocate_resource(&dev->link[link], resource,
-                       IORESOURCE_MEM | IORESOURCE_PREFETCH,
-                       IORESOURCE_MEM);
+               resource->flags = IORESOURCE_MEM | IORESOURCE_BRIDGE;
 
-#if EXT_CONF_SUPPORT == 1
+#if CONFIG_EXT_CONF_SUPPORT == 1
                if((resource->index & 0x1fff) == 0x1110) { // ext
                        normalize_resource(resource);
                }
@@ -539,19 +533,14 @@ static void amdfam10_set_resource(device_t dev, struct resource *resource,
 
        /* Get the register and link */
        reg  = resource->index & 0xfff; // 4k
-       link = ( resource->index>> 16)& 0x7; // 8 links
+       link = IOINDEX_LINK(resource->index);
 
        if (resource->flags & IORESOURCE_IO) {
-               compute_allocate_resource(&dev->link[link], resource,
-                       IORESOURCE_IO, IORESOURCE_IO);
 
                set_io_addr_reg(dev, nodeid, link, reg, rbase>>8, rend>>8);
                store_conf_io_addr(nodeid, link, reg, (resource->index >> 24), rbase>>8, rend>>8);
        }
        else if (resource->flags & IORESOURCE_MEM) {
-               compute_allocate_resource(&dev->link[link], resource,
-                       IORESOURCE_MEM | IORESOURCE_PREFETCH,
-                       resource->flags & (IORESOURCE_MEM | IORESOURCE_PREFETCH));
                set_mmio_addr_reg(nodeid, link, reg, (resource->index >>24), rbase>>8, rend>>8, sysconf.nodes) ;// [39:8]
                store_conf_mmio_addr(nodeid, link, reg, (resource->index >>24), rbase>>8, rend>>8);
        }
@@ -579,7 +568,7 @@ static void amdfam10_create_vga_resource(device_t dev, unsigned nodeid)
        for (link = 0; link < dev->links; link++) {
                if (dev->link[link].bridge_ctrl & PCI_BRIDGE_CTL_VGA) {
 #if CONFIG_CONSOLE_VGA_MULTI == 1
-                       printk_debug("VGA: vga_pri bus num = %d dev->link[link] bus range [%d,%d]\n", vga_pri->bus->secondary,
+                       printk(BIOS_DEBUG, "VGA: vga_pri bus num = %d dev->link[link] bus range [%d,%d]\n", vga_pri->bus->secondary,
                                dev->link[link].secondary,dev->link[link].subordinate);
                        /* We need to make sure the vga_pri is under the link */
                        if((vga_pri->bus->secondary >= dev->link[link].secondary ) &&
@@ -594,7 +583,7 @@ static void amdfam10_create_vga_resource(device_t dev, unsigned nodeid)
        if (link == dev->links)
                return;
 
-       printk_debug("VGA: %s (aka node %d) link %d has VGA device\n", dev_path(dev), nodeid, link);
+       printk(BIOS_DEBUG, "VGA: %s (aka node %d) link %d has VGA device\n", dev_path(dev), nodeid, link);
        set_vga_enable_reg(nodeid, link);
 }
 
@@ -644,22 +633,18 @@ static struct device_operations northbridge_operations = {
 };
 
 
-static struct pci_driver mcf0_driver __pci_driver = {
+static const struct pci_driver mcf0_driver __pci_driver = {
        .ops    = &northbridge_operations,
        .vendor = PCI_VENDOR_ID_AMD,
        .device = 0x1200,
 };
 
-#if CONFIG_CHIP_NAME == 1
-
 struct chip_operations northbridge_amd_amdfam10_ops = {
        CHIP_NAME("AMD FAM10 Northbridge")
        .enable_dev = 0,
 };
 
-#endif
-
-static void pci_domain_read_resources(device_t dev)
+static void amdfam10_domain_read_resources(device_t dev)
 {
        struct resource *resource;
        unsigned reg;
@@ -674,20 +659,20 @@ static void pci_domain_read_resources(device_t dev)
                /* Is this register allocated? */
                if ((base & 3) != 0) {
                        unsigned nodeid, link;
-                       device_t dev;
+                       device_t reg_dev;
                        if(reg<0xc0) { // mmio
                                nodeid = (limit & 0xf) + (base&0x30);
                        } else { // io
                                nodeid =  (limit & 0xf) + ((base>>4)&0x30);
                        }
                        link   = (limit >> 4) & 7;
-                       dev = __f0_dev[nodeid];
-                       if (dev) {
-                               /* Reserve the resource  */
-                               struct resource *resource;
-                               resource = new_resource(dev, 0x1000 + reg + (link<<16));
-                               if (resource) {
-                                       resource->flags = 1;
+                       reg_dev = __f0_dev[nodeid];
+                       if (reg_dev) {
+                               /* Reserve the resource  */
+                               struct resource *reg_resource;
+                               reg_resource = new_resource(reg_dev, IOINDEX(0x1000 + reg, link));
+                               if (reg_resource) {
+                                       reg_resource->flags = 1;
                                }
                        }
                }
@@ -696,16 +681,7 @@ static void pci_domain_read_resources(device_t dev)
           I don't believe that much preset value */
 
 #if CONFIG_PCI_64BIT_PREF_MEM == 0
-       /* Initialize the system wide io space constraints */
-       resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
-       resource->base  = 0x400;
-       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->limit = 0xfcffffffffULL;
-       resource->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
+       pci_domain_read_resources(dev);
 #else
        for(link=0; link<dev->links; link++) {
                /* Initialize the system wide io space constraints */
@@ -713,24 +689,16 @@ static void pci_domain_read_resources(device_t dev)
                resource->base  = 0x400;
                resource->limit = 0xffffUL;
                resource->flags = IORESOURCE_IO;
-               compute_allocate_resource(&dev->link[link], resource,
-                       IORESOURCE_IO, IORESOURCE_IO);
 
                /* Initialize the system wide prefetchable memory resources constraints */
                resource = new_resource(dev, 1|(link<<2));
                resource->limit = 0xfcffffffffULL;
                resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
-               compute_allocate_resource(&dev->link[link], resource,
-                       IORESOURCE_MEM | IORESOURCE_PREFETCH,
-                       IORESOURCE_MEM | IORESOURCE_PREFETCH);
 
                /* Initialize the system wide memory resources constraints */
                resource = new_resource(dev, 2|(link<<2));
                resource->limit = 0xfcffffffffULL;
                resource->flags = IORESOURCE_MEM;
-               compute_allocate_resource(&dev->link[link], resource,
-                       IORESOURCE_MEM | IORESOURCE_PREFETCH,
-                       IORESOURCE_MEM);
        }
 #endif
 }
@@ -772,11 +740,7 @@ static u32 find_pci_tolm(struct bus *bus, u32 tolm)
        return tolm;
 }
 
-#if CONFIG_PCI_64BIT_PREF_MEM == 1
-#define BRIDGE_IO_MASK (IORESOURCE_IO | IORESOURCE_MEM | IORESOURCE_PREFETCH)
-#endif
-
-#if HW_MEM_HOLE_SIZEK != 0
+#if CONFIG_HW_MEM_HOLE_SIZEK != 0
 
 struct hw_mem_hole_info {
        unsigned hole_startk;
@@ -788,7 +752,7 @@ static struct hw_mem_hole_info get_hw_mem_hole_info(void)
                struct hw_mem_hole_info mem_hole;
                int i;
 
-               mem_hole.hole_startk = HW_MEM_HOLE_SIZEK;
+               mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK;
                mem_hole.node_id = -1;
 
                for (i = 0; i < sysconf.nodes; i++) {
@@ -842,7 +806,7 @@ static void disable_hoist_memory(unsigned long hole_startk, int i)
        u32 hole_sizek;
 
        u32 one_DCT;
-       struct sys_info *sysinfox = (struct sys_info *)((CONFIG_LB_MEM_TOPK<<10) - DCACHE_RAM_GLOBAL_VAR_SIZE); // in RAM
+       struct sys_info *sysinfox = (struct sys_info *)((CONFIG_RAMTOP) - CONFIG_DCACHE_RAM_GLOBAL_VAR_SIZE); // in RAM
        struct mem_info *meminfo;
        meminfo = &sysinfox->meminfo[i];
 
@@ -913,6 +877,11 @@ static void disable_hoist_memory(unsigned long hole_startk, int i)
 
 #endif
 
+#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
+
 static void pci_domain_set_resources(device_t dev)
 {
 #if CONFIG_PCI_64BIT_PREF_MEM == 1
@@ -923,7 +892,7 @@ static void pci_domain_set_resources(device_t dev)
        u32 pci_tolm;
        int i, idx;
        u32 link;
-#if HW_MEM_HOLE_SIZEK != 0
+#if CONFIG_HW_MEM_HOLE_SIZEK != 0
        struct hw_mem_hole_info mem_hole;
        u32 reset_memhole = 1;
 #endif
@@ -937,9 +906,9 @@ static void pci_domain_set_resources(device_t dev)
                mem1 = find_resource(dev, 1|(link<<2));
                mem2 = find_resource(dev, 2|(link<<2));
 
-               printk_debug("base1: 0x%08Lx limit1: 0x%08Lx size: 0x%08Lx align: %d\n",
+               printk(BIOS_DEBUG, "base1: 0x%08Lx limit1: 0x%08Lx size: 0x%08Lx align: %d\n",
                        mem1->base, mem1->limit, mem1->size, mem1->align);
-               printk_debug("base2: 0x%08Lx limit2: 0x%08Lx size: 0x%08Lx align: %d\n",
+               printk(BIOS_DEBUG, "base2: 0x%08Lx limit2: 0x%08Lx size: 0x%08Lx align: %d\n",
                        mem2->base, mem2->limit, mem2->size, mem2->align);
 
                /* See if both resources have roughly the same limits */
@@ -965,9 +934,9 @@ static void pci_domain_set_resources(device_t dev)
                        mem1->base = resource_max(mem1);
                }
 
-               printk_debug("base1: 0x%08Lx limit1: 0x%08Lx size: 0x%08Lx align: %d\n",
+               printk(BIOS_DEBUG, "base1: 0x%08Lx limit1: 0x%08Lx size: 0x%08Lx align: %d\n",
                        mem1->base, mem1->limit, mem1->size, mem1->align);
-               printk_debug("base2: 0x%08Lx limit2: 0x%08Lx size: 0x%08Lx align: %d\n",
+               printk(BIOS_DEBUG, "base2: 0x%08Lx limit2: 0x%08Lx size: 0x%08Lx align: %d\n",
                        mem2->base, mem2->limit, mem2->size, mem2->align);
        }
 
@@ -977,9 +946,6 @@ static void pci_domain_set_resources(device_t dev)
                resource->flags |= IORESOURCE_ASSIGNED;
                resource->flags &= ~IORESOURCE_STORED;
                link = (resource>>2) & 3;
-               compute_allocate_resource(&dev->link[link], resource,
-                       BRIDGE_IO_MASK, resource->flags & BRIDGE_IO_MASK);
-
                resource->flags |= IORESOURCE_STORED;
                report_resource_stored(dev, resource, "");
 
@@ -1000,7 +966,7 @@ static void pci_domain_set_resources(device_t dev)
        /* Round the mmio hold to 64M */
        mmio_basek &= ~((64*1024) - 1);
 
-#if HW_MEM_HOLE_SIZEK != 0
+#if CONFIG_HW_MEM_HOLE_SIZEK != 0
 /* if the hw mem hole is already set in raminit stage, here we will compare
  * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will
  * use hole_basek as mmio_basek and we don't need to reset hole.
@@ -1020,7 +986,7 @@ static void pci_domain_set_resources(device_t dev)
 
        if(reset_memhole) {
                if(mem_hole.node_id!=-1) {
-               /* We need to select HW_MEM_HOLE_SIZEK for raminit, it can not
+               /* We need to select CONFIG_HW_MEM_HOLE_SIZEK for raminit, it can not
                    make hole_startk to some basek too!
                   We need to reset our Mem Hole, because We want more big HOLE
                    than we already set
@@ -1030,7 +996,7 @@ static void pci_domain_set_resources(device_t dev)
                        disable_hoist_memory(mem_hole.hole_startk, mem_hole.node_id);
                }
 
-       #if HW_MEM_HOLE_SIZE_AUTO_INC == 1
+       #if CONFIG_HW_MEM_HOLE_SIZE_AUTO_INC == 1
                // We need to double check if the mmio_basek is valid for hole
                // setting, if it is equal to basek, we need to decrease it some
                resource_t basek_pri;
@@ -1075,7 +1041,7 @@ static void pci_domain_set_resources(device_t dev)
 
                }
 
-//             printk_debug("node %d : mmio_basek=%08x, basek=%08x, limitk=%08x\n", i, mmio_basek, basek, limitk);
+//             printk(BIOS_DEBUG, "node %d : mmio_basek=%08x, basek=%08x, limitk=%08x\n", i, mmio_basek, basek, limitk);
 
                /* split the region to accomodate pci memory space */
                if ( (basek < 4*1024*1024 ) && (limitk > mmio_basek) ) {
@@ -1086,11 +1052,20 @@ static void pci_domain_set_resources(device_t dev)
                                        ram_resource(dev, (idx | i), basek, pre_sizek);
                                        idx += 0x10;
                                        sizek -= pre_sizek;
+#if CONFIG_WRITE_HIGH_TABLES==1
+                                       if (i==0 && high_tables_base==0) {
+                                       /* Leave some space for ACPI, PIRQ and MP tables */
+                                               high_tables_base = (mmio_basek - HIGH_TABLES_SIZE) * 1024;
+                                               high_tables_size = HIGH_TABLES_SIZE * 1024;
+                                               printk(BIOS_DEBUG, "(split)%xK table at =%08llx\n", HIGH_TABLES_SIZE,
+                                                            high_tables_base);
+                                       }
+#endif
                                }
                                #if CONFIG_AMDMCT == 0
-                               #if HW_MEM_HOLE_SIZEK != 0
+                               #if CONFIG_HW_MEM_HOLE_SIZEK != 0
                                if(reset_memhole) {
-                                       struct sys_info *sysinfox = (struct sys_info *)((CONFIG_LB_MEM_TOPK<<10) - DCACHE_RAM_GLOBAL_VAR_SIZE); // in RAM
+                                       struct sys_info *sysinfox = (struct sys_info *)((CONFIG_RAMTOP) - CONFIG_DCACHE_RAM_GLOBAL_VAR_SIZE); // in RAM
                                        struct mem_info *meminfo;
                                        meminfo = &sysinfox->meminfo[i];
                                        sizek += hoist_memory(mmio_basek,i, get_one_DCT(meminfo), sysconf.nodes);
@@ -1110,6 +1085,15 @@ static void pci_domain_set_resources(device_t dev)
                }
                ram_resource(dev, (idx | i), basek, sizek);
                idx += 0x10;
+#if CONFIG_WRITE_HIGH_TABLES==1
+               printk(BIOS_DEBUG, "%d: mmio_basek=%08lx, basek=%08x, limitk=%08x\n",
+                            i, mmio_basek, basek, limitk);
+               if (i==0 && high_tables_base==0) {
+               /* Leave some space for ACPI, PIRQ and MP tables */
+                       high_tables_base = (limitk - HIGH_TABLES_SIZE) * 1024;
+                       high_tables_size = HIGH_TABLES_SIZE * 1024;
+               }
+#endif
        }
 
        for(link = 0; link < dev->links; link++) {
@@ -1121,7 +1105,7 @@ static void pci_domain_set_resources(device_t dev)
        }
 }
 
-static u32 pci_domain_scan_bus(device_t dev, u32 max)
+static u32 amdfam10_domain_scan_bus(device_t dev, u32 max)
 {
        u32 reg;
        int i;
@@ -1129,7 +1113,7 @@ static u32 pci_domain_scan_bus(device_t dev, u32 max)
        for(reg = 0xe0; reg <= 0xec; reg += 4) {
                f1_write_config32(reg, 0);
        }
-#if EXT_CONF_SUPPORT == 1
+#if CONFIG_EXT_CONF_SUPPORT == 1
        // all nodes
        for(i = 0; i< sysconf.nodes; i++) {
                int index;
@@ -1143,7 +1127,7 @@ static u32 pci_domain_scan_bus(device_t dev, u32 max)
 
 
        for(i=0;i<dev->links;i++) {
-               max = pci_scan_bus(&dev->link[i], PCI_DEVFN(CDB, 0), 0xff, max);
+               max = pci_scan_bus(&dev->link[i], PCI_DEVFN(CONFIG_CDB, 0), 0xff, max);
        }
 
        /* Tune the hypertransport transaction for best performance.
@@ -1160,7 +1144,7 @@ static u32 pci_domain_scan_bus(device_t dev, u32 max)
                        if (!dev->link[0].disable_relaxed_ordering) {
                                httc |= HTTC_RSP_PASS_PW;
                        }
-                       printk_spew("%s passpw: %s\n",
+                       printk(BIOS_SPEW, "%s passpw: %s\n",
                                dev_path(dev),
                                (!dev->link[0].disable_relaxed_ordering)?
                                "enabled":"disabled");
@@ -1171,12 +1155,12 @@ static u32 pci_domain_scan_bus(device_t dev, u32 max)
 }
 
 static struct device_operations pci_domain_ops = {
-       .read_resources   = pci_domain_read_resources,
+       .read_resources   = amdfam10_domain_read_resources,
        .set_resources    = pci_domain_set_resources,
        .enable_resources = enable_childrens_resources,
        .init             = 0,
-       .scan_bus         = pci_domain_scan_bus,
-#if MMCONF_SUPPORT
+       .scan_bus         = amdfam10_domain_scan_bus,
+#if CONFIG_MMCONF_SUPPORT_DEFAULT
        .ops_pci_bus      = &pci_ops_mmconf,
 #else
        .ops_pci_bus      = &pci_cf8_conf1,
@@ -1207,16 +1191,16 @@ static void sysconf_init(device_t dev) // first node
        sysconf.bsp_apicid = lapicid();
        sysconf.apicid_offset = sysconf.bsp_apicid;
 
-#if (ENABLE_APIC_EXT_ID == 1)
+#if (CONFIG_ENABLE_APIC_EXT_ID == 1)
        if (pci_read_config32(dev, 0x68) & (HTTC_APIC_EXT_ID|HTTC_APIC_EXT_BRD_CST))
        {
                sysconf.enabled_apic_ext_id = 1;
        }
-       #if (APIC_ID_OFFSET>0)
+       #if (CONFIG_APIC_ID_OFFSET>0)
        if(sysconf.enabled_apic_ext_id) {
                if(sysconf.bsp_apicid == 0) {
                        /* bsp apic id is not changed */
-                       sysconf.apicid_offset = APIC_ID_OFFSET;
+                       sysconf.apicid_offset = CONFIG_APIC_ID_OFFSET;
                } else {
                        sysconf.lift_bsp_apicid = 1;
                }
@@ -1260,37 +1244,37 @@ static u32 cpu_bus_scan(device_t dev, u32 max)
 
        nb_cfg_54 = read_nb_cfg_54();
 
-#if CBB
-       dev_mc = dev_find_slot(0, PCI_DEVFN(CDB, 0)); //0x00
+#if CONFIG_CBB
+       dev_mc = dev_find_slot(0, PCI_DEVFN(CONFIG_CDB, 0)); //0x00
        if(dev_mc && dev_mc->bus) {
-               printk_debug("%s found", dev_path(dev_mc));
+               printk(BIOS_DEBUG, "%s found", dev_path(dev_mc));
                pci_domain = dev_mc->bus->dev;
                if(pci_domain && (pci_domain->path.type == DEVICE_PATH_PCI_DOMAIN)) {
-                       printk_debug("\n%s move to ",dev_path(dev_mc));
-                       dev_mc->bus->secondary = CBB; // move to 0xff
-                       printk_debug("%s",dev_path(dev_mc));
+                       printk(BIOS_DEBUG, "\n%s move to ",dev_path(dev_mc));
+                       dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
+                       printk(BIOS_DEBUG, "%s",dev_path(dev_mc));
 
                } else {
-                       printk_debug(" but it is not under pci_domain directly ");
+                       printk(BIOS_DEBUG, " but it is not under pci_domain directly ");
                }
-               printk_debug("\n");
+               printk(BIOS_DEBUG, "\n");
 
        }
-       dev_mc = dev_find_slot(CBB, PCI_DEVFN(CDB, 0));
+       dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
        if(!dev_mc) {
                dev_mc = dev_find_slot(0, PCI_DEVFN(0x18, 0));
                if (dev_mc && dev_mc->bus) {
-                       printk_debug("%s found\n", dev_path(dev_mc));
+                       printk(BIOS_DEBUG, "%s found\n", dev_path(dev_mc));
                        pci_domain = dev_mc->bus->dev;
                        if(pci_domain && (pci_domain->path.type == DEVICE_PATH_PCI_DOMAIN)) {
                                if((pci_domain->links==1) && (pci_domain->link[0].children == dev_mc)) {
-                                       printk_debug("%s move to ",dev_path(dev_mc));
-                                       dev_mc->bus->secondary = CBB; // move to 0xff
-                                       printk_debug("%s\n",dev_path(dev_mc));
+                                       printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
+                                       dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
+                                       printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
                                        while(dev_mc){
-                                               printk_debug("%s move to ",dev_path(dev_mc));
-                                               dev_mc->path.u.pci.devfn -= PCI_DEVFN(0x18,0);
-                                               printk_debug("%s\n",dev_path(dev_mc));
+                                               printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
+                                               dev_mc->path.pci.devfn -= PCI_DEVFN(0x18,0);
+                                               printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
                                                dev_mc = dev_mc->sibling;
                                        }
                                }
@@ -1300,9 +1284,9 @@ static u32 cpu_bus_scan(device_t dev, u32 max)
 
 #endif
 
-       dev_mc = dev_find_slot(CBB, PCI_DEVFN(CDB, 0));
+       dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
        if (!dev_mc) {
-               printk_err("%02x:%02x.0 not found", CBB, CDB);
+               printk(BIOS_ERR, "%02x:%02x.0 not found", CONFIG_CBB, CONFIG_CDB);
                die("");
        }
 
@@ -1310,16 +1294,16 @@ static u32 cpu_bus_scan(device_t dev, u32 max)
 
        nodes = sysconf.nodes;
 
-#if CBB && (NODE_NUMS > 32)
+#if CONFIG_CBB && (NODE_NUMS > 32)
        if(nodes>32) { // need to put node 32 to node 63 to bus 0xfe
                if(pci_domain->links==1) {
                        pci_domain->links++; // from 1 to 2
                        pci_domain->link[1].link = 1;
                        pci_domain->link[1].dev = pci_domain;
                        pci_domain->link[1].children = 0;
-                       printk_debug("%s links increase to %d\n", dev_path(pci_domain), pci_domain->links);
+                       printk(BIOS_DEBUG, "%s links increase to %d\n", dev_path(pci_domain), pci_domain->links);
                }
-               pci_domain->link[1].secondary = CBB - 1;
+               pci_domain->link[1].secondary = CONFIG_CBB - 1;
        }
 #endif
        /* Find which cpus are present */
@@ -1330,10 +1314,10 @@ static u32 cpu_bus_scan(device_t dev, u32 max)
                unsigned busn, devn;
                struct bus *pbus;
 
-               busn = CBB;
-               devn = CDB+i;
+               busn = CONFIG_CBB;
+               devn = CONFIG_CDB+i;
                pbus = dev_mc->bus;
-#if CBB && (NODE_NUMS > 32)
+#if CONFIG_CBB && (NODE_NUMS > 32)
                if(i>=32) {
                        busn--;
                        devn-=32;
@@ -1360,7 +1344,7 @@ static u32 cpu_bus_scan(device_t dev, u32 max)
                         */
                        int j;
                        int linknum;
-#if HT3_SUPPORT==1
+#if CONFIG_HT3_SUPPORT==1
                        linknum = 8;
 #else
                        linknum = 4;
@@ -1371,7 +1355,7 @@ static u32 cpu_bus_scan(device_t dev, u32 max)
                                         dev->link[j].dev = dev;
                                }
                                dev->links = linknum;
-                               printk_debug("%s links increase to %d\n", dev_path(dev), dev->links);
+                               printk(BIOS_DEBUG, "%s links increase to %d\n", dev_path(dev), dev->links);
                        }
                }
 
@@ -1380,7 +1364,9 @@ static u32 cpu_bus_scan(device_t dev, u32 max)
                if (dev && dev->enabled) {
                        j = pci_read_config32(dev, 0xe8);
                        cores_found = (j >> 12) & 3; // dev is func 3
-                       printk_debug("  %s siblings=%d\n", dev_path(dev), cores_found);
+                       if (siblings > 3)
+                               cores_found |= (j >> 13) & 4;
+                       printk(BIOS_DEBUG, "  %s siblings=%d\n", dev_path(dev), cores_found);
                }
 
                u32 jj;
@@ -1395,7 +1381,7 @@ static u32 cpu_bus_scan(device_t dev, u32 max)
 
                        /* Build the cpu device path */
                        cpu_path.type = DEVICE_PATH_APIC;
-                       cpu_path.u.apic.apic_id = i * (nb_cfg_54?(siblings+1):1) + j * (nb_cfg_54?1:64); // ?
+                       cpu_path.apic.apic_id = i * (nb_cfg_54?(siblings+1):1) + j * (nb_cfg_54?1:64); // ?
 
                        /* See if I can find the cpu */
                        cpu = find_dev_path(cpu_bus, &cpu_path);
@@ -1417,20 +1403,20 @@ static u32 cpu_bus_scan(device_t dev, u32 max)
 
                        /* Report what I have done */
                        if (cpu) {
-                               cpu->path.u.apic.node_id = i;
-                               cpu->path.u.apic.core_id = j;
-       #if (ENABLE_APIC_EXT_ID == 1) && (APIC_ID_OFFSET>0)
+                               cpu->path.apic.node_id = i;
+                               cpu->path.apic.core_id = j;
+       #if (CONFIG_ENABLE_APIC_EXT_ID == 1) && (CONFIG_APIC_ID_OFFSET>0)
                                 if(sysconf.enabled_apic_ext_id) {
                                        if(sysconf.lift_bsp_apicid) {
-                                               cpu->path.u.apic.apic_id += sysconf.apicid_offset;
+                                               cpu->path.apic.apic_id += sysconf.apicid_offset;
                                        } else
                                        {
-                                               if (cpu->path.u.apic.apic_id != 0)
-                                                       cpu->path.u.apic.apic_id += sysconf.apicid_offset;
+                                               if (cpu->path.apic.apic_id != 0)
+                                                       cpu->path.apic.apic_id += sysconf.apicid_offset;
                                         }
                                }
        #endif
-                               printk_debug("CPU: %s %s\n",
+                               printk(BIOS_DEBUG, "CPU: %s %s\n",
                                        dev_path(cpu), cpu->enabled?"enabled":"disabled");
                        }