remove trailing whitespace
[coreboot.git] / src / northbridge / amd / amdk8 / raminit_f.c
index 3c96477cb35540175274dd3eff281ad4e6aa50e3..319293b7ed61e9f138efeb6e261d57040e8ab19e 100644 (file)
  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 */
 
-#include <cpu/x86/mem.h>
 #include <cpu/x86/cache.h>
 #include <cpu/x86/mtrr.h>
 #include <cpu/x86/tsc.h>
 
 #include <stdlib.h>
 #include "raminit.h"
-#include "amdk8_f.h"
+#include "f.h"
 #include <spd_ddr2.h>
-
-#ifndef QRANK_DIMM_SUPPORT
-#define QRANK_DIMM_SUPPORT 0
-#endif
-
-#if CONFIG_USE_PRINTK_IN_CAR
-#else
-#error This file needs CONFIG_USE_PRINTK_IN_CAR
+#if CONFIG_HAVE_OPTION_TABLE
+#include "option_table.h"
 #endif
 
-#define RAM_TIMING_DEBUG 0
-
-#if RAM_TIMING_DEBUG == 1
-#define printk_raminit printk_debug
+#if CONFIG_DEBUG_RAM_SETUP
+#define printk_raminit(args...) printk(BIOS_DEBUG, args)
 #else
-#define printk_raminit(fmt, arg...)
+#define printk_raminit(args...)
 #endif
 
 
-#if (CONFIG_LB_MEM_TOPK & (CONFIG_LB_MEM_TOPK -1)) != 0
-# error "CONFIG_LB_MEM_TOPK must be a power of 2"
+#if (CONFIG_RAMTOP & (CONFIG_RAMTOP -1)) != 0
+# error "CONFIG_RAMTOP must be a power of 2"
 #endif
 
-#include "amdk8_f_pci.c"
+#include "f_pci.c"
 
 
        /* for PCI_ADDR(0, 0x18, 2, 0x98) index,
@@ -82,7 +73,7 @@
        */
 
 
-static void setup_resource_map(const unsigned int *register_values, int max)
+void setup_resource_map(const unsigned int *register_values, int max)
 {
        int i;
        for (i = 0; i < max; i += 3) {
@@ -401,7 +392,7 @@ static void sdram_set_registers(const struct mem_controller *ctrl, struct sys_in
         *         110 = 8 bus clocks
         *         111 = 9 bus clocks
         * [ 7: 7] Reserved
-        * [ 9: 8] Twtr (Internal DRAM Write-to-Read Command Delay, 
+        * [ 9: 8] Twtr (Internal DRAM Write-to-Read Command Delay,
         * minium write-to-read delay when both access the same chip select)
         *         00 = Reserved
         *         01 = 1 bus clocks
@@ -533,7 +524,7 @@ static void sdram_set_registers(const struct mem_controller *ctrl, struct sys_in
         *             registered DIMM is present
         * [19:19] Reserved
         * [20:20] SlowAccessMode (Slow Access Mode (2T Mode))
-        *         0 = DRAM address and control signals are driven for one 
+        *         0 = DRAM address and control signals are driven for one
         *             MEMCLK cycle
         *         1 = One additional MEMCLK of setup time is provided on all
         *             DRAM address and control signals except CS, CKE, and ODT;
@@ -699,7 +690,7 @@ static void sdram_set_registers(const struct mem_controller *ctrl, struct sys_in
        }
        sysinfo->ctrl_present[ctrl->node_id] = 1;
 
-       printk_spew("setting up CPU %02x northbridge registers\n", ctrl->node_id);
+       printk(BIOS_SPEW, "setting up CPU %02x northbridge registers\n", ctrl->node_id);
        max = ARRAY_SIZE(register_values);
        for (i = 0; i < max; i += 3) {
                device_t dev;
@@ -712,29 +703,34 @@ static void sdram_set_registers(const struct mem_controller *ctrl, struct sys_in
                reg |= register_values[i+2];
                pci_write_config32(dev, where, reg);
        }
-       printk_spew("done.\n");
+       printk(BIOS_SPEW, "done.\n");
 }
 
+#if 0
 static int is_dual_channel(const struct mem_controller *ctrl)
 {
        uint32_t dcl;
        dcl = pci_read_config32(ctrl->f2, DRAM_CONFIG_LOW);
        return dcl & DCL_Width128;
 }
+#endif
 
 static int is_opteron(const struct mem_controller *ctrl)
 {
-       /* Test to see if I am an Opteron.
-        * FIXME Testing dual channel capability is correct for now
-        * but a better test is probably required.
-        * m2 and s1g1 support dual channel too. but only support unbuffered dimm
+       /* Test to see if I am an Opteron. M2 and S1G1 support dual
+        * channel, too, but only support unbuffered DIMMs so we need a
+        * better test for Opterons.
+        * However, all code uses is_opteron() to find out whether to
+        * use dual channel, so if we really check for opteron here, we
+        * need to fix up all code using this function, too.
         */
-#warning "FIXME implement a better test for opterons"
+
        uint32_t nbcap;
        nbcap = pci_read_config32(ctrl->f3, NORTHBRIDGE_CAP);
        return !!(nbcap & NBCAP_128Bit);
 }
 
+#if 0
 static int is_registered(const struct mem_controller *ctrl)
 {
        /* Test to see if we are dealing with registered SDRAM.
@@ -745,7 +741,7 @@ static int is_registered(const struct mem_controller *ctrl)
        dcl = pci_read_config32(ctrl->f2, DRAM_CONFIG_LOW);
        return !(dcl & DCL_UnBuffDimm);
 }
-
+#endif
 
 static void spd_get_dimm_size(unsigned device, struct dimm_size *sz)
 {
@@ -809,7 +805,7 @@ static void spd_get_dimm_size(unsigned device, struct dimm_size *sz)
        if (value <=4 ) value += 8; // add back to 1G to high
        value += (27-5); // make 128MB to the real lines
        if ( value != (sz->per_rank)) {
-               printk_err("Bad RANK Size --\n");
+               printk(BIOS_ERR, "Bad RANK Size --\n");
                goto val_err;
        }
 
@@ -870,7 +866,7 @@ static void set_dimm_size(const struct mem_controller *ctrl,
                /* Set the appropriate DIMM base address register */
                pci_write_config32(ctrl->f2, DRAM_CSBASE + (((index << 1) + 0) << 2), base0);
                pci_write_config32(ctrl->f2, DRAM_CSBASE + (((index << 1) + 1) << 2), base1);
-#if QRANK_DIMM_SUPPORT == 1
+#if CONFIG_QRANK_DIMM_SUPPORT
                if (sz->rank == 4) {
                        pci_write_config32(ctrl->f2, DRAM_CSBASE + (((index << 1) + 4) << 2), base0);
                        pci_write_config32(ctrl->f2, DRAM_CSBASE + (((index << 1) + 5) << 2), base1);
@@ -898,7 +894,7 @@ static void set_dimm_size(const struct mem_controller *ctrl,
                } else {
                        dword = pci_read_config32(ctrl->f2, DRAM_TIMING_LOW); //Channel A
                        dword &= ~(ClkDis0 >> index);
-#if QRANK_DIMM_SUPPORT == 1
+#if CONFIG_QRANK_DIMM_SUPPORT
                        if (sz->rank == 4) {
                                dword &= ~(ClkDis0 >> (index+2));
                        }
@@ -908,7 +904,7 @@ static void set_dimm_size(const struct mem_controller *ctrl,
                        if (meminfo->is_Width128) { // ChannelA+B
                                dword = pci_read_config32(ctrl->f2, DRAM_CTRL_MISC);
                                dword &= ~(ClkDis0 >> index);
-#if QRANK_DIMM_SUPPORT == 1
+#if CONFIG_QRANK_DIMM_SUPPORT
                                if (sz->rank == 4) {
                                        dword &= ~(ClkDis0 >> (index+2));
                                }
@@ -961,7 +957,7 @@ static void set_dimm_cs_map(const struct mem_controller *ctrl,
        }
        map = pci_read_config32(ctrl->f2, DRAM_BANK_ADDR_MAP);
        map &= ~(0xf << (index * 4));
-#if QRANK_DIMM_SUPPORT == 1
+#if CONFIG_QRANK_DIMM_SUPPORT
        if (sz->rank == 4) {
                map &= ~(0xf << ( (index + 2) * 4));
        }
@@ -972,7 +968,7 @@ static void set_dimm_cs_map(const struct mem_controller *ctrl,
                unsigned temp_map;
                temp_map = cs_map_aaa[(sz->bank-2)*3*4 + (sz->rows - 13)*3 + (sz->col - 9) ];
                map |= temp_map << (index*4);
-#if QRANK_DIMM_SUPPORT == 1
+#if CONFIG_QRANK_DIMM_SUPPORT
                if (sz->rank == 4) {
                        map |=  temp_map << ( (index + 2) * 4);
                }
@@ -1049,7 +1045,7 @@ static void set_top_mem(unsigned tom_k, unsigned hole_startk)
        }
 
        /* Report the amount of memory. */
-       printk_debug("RAM end at 0x%08x kB\n", tom_k);
+       printk(BIOS_DEBUG, "RAM end at 0x%08x kB\n", tom_k);
 
        /* Now set top of memory */
        msr_t msr;
@@ -1111,6 +1107,15 @@ static unsigned long interleave_chip_selects(const struct mem_controller *ctrl,
        /* See if all of the memory chip selects are the same size
         * and if so count them.
         */
+#if defined(CMOS_VSTART_interleave_chip_selects)
+       if (read_option(interleave_chip_selects, 1) == 0)
+               return 0;
+#else
+#if !defined(CONFIG_INTERLEAVE_CHIP_SELECTS) || !CONFIG_INTERLEAVE_CHIP_SELECTS
+       return 0;
+#endif
+#endif
+
        chip_selects = 0;
        common_size = 0;
        common_cs_mode = 0xff;
@@ -1183,7 +1188,7 @@ static unsigned long interleave_chip_selects(const struct mem_controller *ctrl,
                csbase += csbase_inc;
        }
 
-       printk_debug("Interleaved\n");
+       printk(BIOS_DEBUG, "Interleaved\n");
 
        /* Return the memory size in K */
        return common_size << ((27-10) + bits);
@@ -1224,7 +1229,7 @@ static unsigned long order_chip_selects(const struct mem_controller *ctrl)
                        csbase = value;
                        canidate = index;
                }
-               
+
                /* See if I have found a new canidate */
                if (csbase == 0) {
                        break;
@@ -1258,7 +1263,7 @@ static unsigned long order_chip_selects(const struct mem_controller *ctrl)
        return (tom & ~0xff000000) << (27-10);
 }
 
-unsigned long memory_end_k(const struct mem_controller *ctrl, int max_node_id)
+static unsigned long memory_end_k(const struct mem_controller *ctrl, int max_node_id)
 {
        unsigned node_id;
        unsigned end_k;
@@ -1283,15 +1288,10 @@ static void order_dimms(const struct mem_controller *ctrl,
 {
        unsigned long tom_k, base_k;
 
-       if (read_option(CMOS_VSTART_interleave_chip_selects,
-           CMOS_VLEN_interleave_chip_selects, 1) != 0) {
-               tom_k = interleave_chip_selects(ctrl, meminfo->is_Width128);
-       } else {
-               printk_debug("Interleaving disabled\n");
-               tom_k = 0;
-       }
+       tom_k = interleave_chip_selects(ctrl, meminfo->is_Width128);
 
        if (!tom_k) {
+               printk(BIOS_DEBUG, "Interleaving disabled\n");
                tom_k = order_chip_selects(ctrl);
        }
 
@@ -1305,14 +1305,14 @@ static void order_dimms(const struct mem_controller *ctrl,
 static long disable_dimm(const struct mem_controller *ctrl, unsigned index,
                          struct mem_info *meminfo)
 {
-       printk_debug("disabling dimm %02x\n", index);
+       printk(BIOS_DEBUG, "disabling dimm %02x\n", index);
        if (!(meminfo->dimm_mask & 0x0F) && (meminfo->dimm_mask & 0xF0)) { /* channelB only? */
                pci_write_config32(ctrl->f2, DRAM_CSBASE + (((index << 1) + 4) << 2), 0);
                pci_write_config32(ctrl->f2, DRAM_CSBASE + (((index << 1) + 5) << 2), 0);
        } else {
                pci_write_config32(ctrl->f2, DRAM_CSBASE + (((index << 1) + 0) << 2), 0);
                pci_write_config32(ctrl->f2, DRAM_CSBASE + (((index << 1) + 1) << 2), 0);
-#if QRANK_DIMM_SUPPORT == 1
+#if CONFIG_QRANK_DIMM_SUPPORT
                if (meminfo->sz[index].rank == 4) {
                        pci_write_config32(ctrl->f2, DRAM_CSBASE + (((index << 1) + 4) << 2), 0);
                        pci_write_config32(ctrl->f2, DRAM_CSBASE + (((index << 1) + 5) << 2), 0);
@@ -1378,9 +1378,9 @@ static long spd_handle_unbuffered_dimms(const struct mem_controller *ctrl,
        pci_write_config32(ctrl->f2, DRAM_CONFIG_LOW, dcl);
 
        if (meminfo->is_registered) {
-               printk_spew("Registered\n");
+               printk(BIOS_SPEW, "Registered\n");
        } else {
-               printk_spew("Unbuffered\n");
+               printk(BIOS_SPEW, "Unbuffered\n");
        }
        return meminfo->dimm_mask;
 }
@@ -1481,7 +1481,7 @@ static long spd_enable_2channels(const struct mem_controller *ctrl, struct mem_i
                /* Abort if the chips don't support a common CAS latency. */
                common_cl = spd_read_byte(device0, 18) & spd_read_byte(device1, 18);
                if (!common_cl) {
-                       printk_debug("No common CAS latency supported\n");
+                       printk(BIOS_DEBUG, "No common CAS latency supported\n");
                        goto single_channel;
                } else {
                        printk_raminit("Common CAS latency bitfield: 0x%02x\n", common_cl);
@@ -1503,7 +1503,7 @@ static long spd_enable_2channels(const struct mem_controller *ctrl, struct mem_i
                        }
                }
        }
-       printk_spew("Enabling dual channel memory\n");
+       printk(BIOS_SPEW, "Enabling dual channel memory\n");
        dcl = pci_read_config32(ctrl->f2, DRAM_CONFIG_LOW);
        dcl &= ~DCL_BurstLength32;  /*  32byte mode may be preferred in platforms that include graphics controllers that generate a lot of 32-bytes system memory accesses
                                        32byte mode is not supported when the DRAM interface is 128 bits wides, even 32byte mode is set, system still use 64 byte mode  */
@@ -1522,7 +1522,7 @@ static long spd_enable_2channels(const struct mem_controller *ctrl, struct mem_i
                if (((meminfo->dimm_mask >> DIMM_SOCKETS) & ((1 << DIMM_SOCKETS) - 1))) {
                        /* mux capable and single dimm in channelB */
                        if (mux_cap) {
-                               printk_spew("Enable 64MuxMode & BurstLength32\n");
+                               printk(BIOS_SPEW, "Enable 64MuxMode & BurstLength32\n");
                                dcm = pci_read_config32(ctrl->f2, DRAM_CTRL_MISC);
                                dcm |= DCM_Mode64BitMux;
                                pci_write_config32(ctrl->f2, DRAM_CTRL_MISC, dcm);
@@ -1537,7 +1537,7 @@ static long spd_enable_2channels(const struct mem_controller *ctrl, struct mem_i
        } else { /* unmatched dual dimms ? */
                /* unmatched dual dimms not supported by meminit code. Use single channelA dimm. */
                meminfo->dimm_mask &= ~((1 << (DIMM_SOCKETS * 2)) - (1 << DIMM_SOCKETS));
-               printk_spew("Unmatched dual dimms. Use single channelA dimm.\n");
+               printk(BIOS_SPEW, "Unmatched dual dimms. Use single channelA dimm.\n");
        }
        return meminfo->dimm_mask;
 }
@@ -1618,7 +1618,7 @@ static const struct mem_param *get_mem_param(unsigned min_cycle_time)
        if (!param->cycle_time) {
                die("min_cycle_time to low");
        }
-       printk_spew("%s\n", param->name);
+       printk(BIOS_SPEW, "%s\n", param->name);
        return param;
 }
 
@@ -1643,7 +1643,7 @@ static uint8_t get_exact_divisor(int i, uint8_t divisor)
          /*15*/   200, 160, 120, 100,
        };
 
-       
+
        int index;
        msr_t msr;
 
@@ -1662,7 +1662,7 @@ static uint8_t get_exact_divisor(int i, uint8_t divisor)
                unsigned fid_start;
                msr = rdmsr(0xc0010015);
                fid_start = (msr.lo & (0x3f << 24));
-               
+
                index = fid_start>>25;
        }
 
@@ -1698,7 +1698,7 @@ static unsigned convert_to_linear(unsigned value)
 
 static const uint8_t latency_indicies[] = { 25, 23, 9 };
 
-int find_optimum_spd_latency(u32 spd_device, unsigned *min_latency, unsigned *min_cycle_time)
+static int find_optimum_spd_latency(u32 spd_device, unsigned *min_latency, unsigned *min_cycle_time)
 {
        int new_cycle_time, new_latency;
        int index;
@@ -1805,7 +1805,17 @@ static struct spd_set_memclk_result spd_set_memclk(const struct mem_controller *
        value = pci_read_config32(ctrl->f3, NORTHBRIDGE_CAP);
        min_cycle_time = min_cycle_times[(value >> NBCAP_MEMCLK_SHIFT) & NBCAP_MEMCLK_MASK];
        bios_cycle_time = min_cycle_times[
-               read_option(CMOS_VSTART_max_mem_clock, CMOS_VLEN_max_mem_clock, 0)];
+#ifdef CMOS_VSTART_max_mem_clock
+               read_option(max_mem_clock, 0)
+#else
+#if defined(CONFIG_MAX_MEM_CLOCK)
+               CONFIG_MAX_MEM_CLOCK
+#else
+               0 // use DDR400 as default
+#endif
+#endif
+       ];
+
        if (bios_cycle_time > min_cycle_time) {
                min_cycle_time = bios_cycle_time;
        }
@@ -1846,7 +1856,7 @@ static struct spd_set_memclk_result spd_set_memclk(const struct mem_controller *
                                continue;
                        }
                }
-               
+
        }
        /* Make a second pass through the dimms and disable
         * any that cannot support the selected memclk and cas latency.
@@ -1920,7 +1930,7 @@ static struct spd_set_memclk_result spd_set_memclk(const struct mem_controller *
        value |= result.param->dch_memclk << DCH_MemClkFreq_SHIFT;
        pci_write_config32(ctrl->f2, DRAM_CONFIG_HIGH, value);
 
-       printk_debug("%s\n", result.param->name);
+       printk(BIOS_DEBUG, "%s\n", result.param->name);
 
        /* Update DRAM Timing Low with our selected cas latency */
        value = pci_read_config32(ctrl->f2, DRAM_TIMING_LOW);
@@ -1946,7 +1956,7 @@ static unsigned convert_to_1_4(unsigned value)
        return valuex;
 }
 
-int get_dimm_Trc_clocks(u32 spd_device, const struct mem_param *param)
+static int get_dimm_Trc_clocks(u32 spd_device, const struct mem_param *param)
 {
        int value;
        int value2;
@@ -1967,9 +1977,9 @@ int get_dimm_Trc_clocks(u32 spd_device, const struct mem_param *param)
        printk_raminit("update_dimm_Trc: clocks = %i\n", clocks);
 
        if (clocks < DTL_TRC_MIN) {
-#warning We should die here or at least disable this bank.
-               printk_notice("update_dimm_Trc: can't refresh fast enough, "
-                       "want %i clocks, can %i clocks\n", clocks, DTL_TRC_MIN);
+               // We might want to die here instead or (at least|better) disable this bank.
+               printk(BIOS_NOTICE, "update_dimm_Trc: Can't refresh fast enough, "
+                       "want %i clocks, minimum is %i clocks.\n", clocks, DTL_TRC_MIN);
                clocks = DTL_TRC_MIN;
        }
        return clocks;
@@ -2063,9 +2073,9 @@ static int update_dimm_TT_1_4(const struct mem_controller *ctrl, const struct me
        if (clocks < TT_MIN) {
                clocks = TT_MIN;
        }
-       
+
        if (clocks > TT_MAX) {
-               printk_info("warning spd byte : %x = %x > TT_MAX: %x, setting TT_MAX", SPD_TT, value, TT_MAX);
+               printk(BIOS_INFO, "warning spd byte : %x = %x > TT_MAX: %x, setting TT_MAX", SPD_TT, value, TT_MAX);
                clocks = TT_MAX;
        }
 
@@ -2194,7 +2204,7 @@ static int update_dimm_Tref(const struct mem_controller *ctrl,
 static void set_4RankRDimm(const struct mem_controller *ctrl,
                        const struct mem_param *param, struct mem_info *meminfo)
 {
-#if QRANK_DIMM_SUPPORT == 1
+#if CONFIG_QRANK_DIMM_SUPPORT
        int value;
        int i;
        long dimm_mask = meminfo->dimm_mask;
@@ -2234,7 +2244,7 @@ static uint32_t get_extra_dimm_mask(const struct mem_controller *ctrl,
        uint32_t mask_single_rank;
        uint32_t mask_page_1k;
        int value;
-#if QRANK_DIMM_SUPPORT == 1
+#if CONFIG_QRANK_DIMM_SUPPORT
        int rank;
 #endif
 
@@ -2267,20 +2277,20 @@ static uint32_t get_extra_dimm_mask(const struct mem_controller *ctrl,
 
                value = spd_read_byte(spd_device, SPD_PRI_WIDTH);
 
-               #if QRANK_DIMM_SUPPORT == 1
+               #if CONFIG_QRANK_DIMM_SUPPORT
                        rank = meminfo->sz[i].rank;
                #endif
 
                if (value==4) {
                        mask_x4 |= (1<<i);
-                       #if QRANK_DIMM_SUPPORT == 1
+                       #if CONFIG_QRANK_DIMM_SUPPORT
                        if (rank==4) {
                                mask_x4 |= 1<<(i+2);
                        }
                        #endif
                } else if (value==16) {
                        mask_x16 |= (1<<i);
-                       #if QRANK_DIMM_SUPPORT == 1
+                       #if CONFIG_QRANK_DIMM_SUPPORT
                         if (rank==4) {
                                 mask_x16 |= 1<<(i+2);
                         }
@@ -2364,14 +2374,21 @@ static void set_ecc(const struct mem_controller *ctrl,
        if (nbcap & NBCAP_ECC) {
                dcl |= DCL_DimmEccEn;
        }
-       if (read_option(CMOS_VSTART_ECC_memory, CMOS_VLEN_ECC_memory, 1) == 0) {
+#ifdef CMOS_VSTART_ECC_memory
+       if (read_option(ECC_memory, 1) == 0) {
                dcl &= ~DCL_DimmEccEn;
        }
+#else // CMOS_VSTART_ECC_memory not defined
+#if !CONFIG_ECC_MEMORY
+       dcl &= ~DCL_DimmEccEn;
+#endif
+#endif
        pci_write_config32(ctrl->f2, DRAM_CONFIG_LOW, dcl);
 
        meminfo->is_ecc = 1;
        if (!(dcl & DCL_DimmEccEn)) {
                meminfo->is_ecc = 0;
+               printk(BIOS_DEBUG, "set_ecc: ECC disabled\n");
                return; // already disabled the ECC, so don't need to read SPD any more
        }
 
@@ -2380,7 +2397,7 @@ static void set_ecc(const struct mem_controller *ctrl,
                if (!(meminfo->dimm_mask & (1 << i))) {
                        if (meminfo->dimm_mask & (1 << (DIMM_SOCKETS + i))) { /* channelB only? */
                                spd_device = ctrl->channel1[i];
-                               printk_debug("set_ecc spd_device: 0x%x\n", spd_device);
+                               printk(BIOS_DEBUG, "set_ecc spd_device: 0x%x\n", spd_device);
                        } else {
                                continue;
                        }
@@ -2413,7 +2430,7 @@ static void set_TT(const struct mem_controller *ctrl,
        uint32_t reg;
 
        if ((val < TT_MIN) || (val > TT_MAX)) {
-               printk_err(str);
+               printk(BIOS_ERR, "%s", str);
                die(" Unknown\n");
        }
 
@@ -2489,6 +2506,7 @@ static void set_max_async_latency(const struct mem_controller *ctrl, const struc
        pci_write_config32(ctrl->f2, DRAM_CONFIG_HIGH, dch);
 }
 
+#if (CONFIG_DIMM_SUPPORT & 0x0100)==0x0000 /* 2T mode only used for unbuffered DIMM */
 static void set_SlowAccessMode(const struct mem_controller *ctrl)
 {
        uint32_t dch;
@@ -2499,6 +2517,7 @@ static void set_SlowAccessMode(const struct mem_controller *ctrl)
 
        pci_write_config32(ctrl->f2, DRAM_CONFIG_HIGH, dch);
 }
+#endif
 
 /*
        DRAM_OUTPUT_DRV_COMP_CTRL 0, 0x20
@@ -2512,9 +2531,8 @@ static void set_misc_timing(const struct mem_controller *ctrl, struct mem_info *
        unsigned SlowAccessMode = 0;
 #endif
 
-       long dimm_mask = meminfo->dimm_mask & 0x0f;
-
 #if CONFIG_DIMM_SUPPORT==0x0104   /* DDR2 and REG */
+       long dimm_mask = meminfo->dimm_mask & 0x0f;
        /* for REG DIMM */
        dword = 0x00111222;
        dwordx = 0x002f0000;
@@ -2579,6 +2597,7 @@ static void set_misc_timing(const struct mem_controller *ctrl, struct mem_info *
 #endif
 
 #if CONFIG_DIMM_SUPPORT==0x0004  /* DDR2 and unbuffered */
+       long dimm_mask = meminfo->dimm_mask & 0x0f;
        /* for UNBUF DIMM */
        dword = 0x00111222;
        dwordx = 0x002f2f00;
@@ -2773,7 +2792,7 @@ static long spd_set_dram_timing(const struct mem_controller *ctrl,
 
                continue;
        dimm_err:
-               printk_debug("spd_set_dram_timing dimm_err!\n");
+               printk(BIOS_DEBUG, "spd_set_dram_timing dimm_err!\n");
                if (rc < 0) {
                        return -1;
                }
@@ -2823,7 +2842,7 @@ static void sdram_set_spd_registers(const struct mem_controller *ctrl,
 #endif
        meminfo = &sysinfo->meminfo[ctrl->node_id];
 
-       printk_debug("sdram_set_spd_registers: paramx :%p\n", &paramx);
+       printk(BIOS_DEBUG, "sdram_set_spd_registers: paramx :%p\n", &paramx);
 
        activate_spd_rom(ctrl);
        meminfo->dimm_mask = spd_detect_dimms(ctrl);
@@ -2832,7 +2851,7 @@ static void sdram_set_spd_registers(const struct mem_controller *ctrl,
 
        if (!(meminfo->dimm_mask & ((1 << 2*DIMM_SOCKETS) - 1)))
        {
-               printk_debug("No memory for this cpu\n");
+               printk(BIOS_DEBUG, "No memory for this cpu\n");
                return;
        }
        meminfo->dimm_mask = spd_enable_2channels(ctrl, meminfo);
@@ -2990,25 +3009,26 @@ static void set_hw_mem_hole(int controllers, const struct mem_controller *ctrl)
 
 }
 #endif
-
+#if CONFIG_HAVE_ACPI_RESUME == 1
 #include "exit_from_self.c"
+#endif
 
 static void sdram_enable(int controllers, const struct mem_controller *ctrl,
                          struct sys_info *sysinfo)
 {
        int i;
-#ifdef ACPI_IS_WAKEUP_EARLY
+#if CONFIG_HAVE_ACPI_RESUME == 1
        int suspend = acpi_is_wakeup_early();
 #else
        int suspend = 0;
 #endif
+
 #if K8_REV_F_SUPPORT_F0_F1_WORKAROUND == 1
         unsigned cpu_f0_f1[8];
        /* FIXME: How about 32 node machine later? */
        tsc_t tsc, tsc0[8];
 
-       printk_debug("sdram_enable: tsc0[8]: %p", &tsc0[0]);
+       printk(BIOS_DEBUG, "sdram_enable: tsc0[8]: %p", &tsc0[0]);
        uint32_t dword;
 #endif
 
@@ -3042,9 +3062,9 @@ static void sdram_enable(int controllers, const struct mem_controller *ctrl,
 
        /* lets override the rest of the routine */
        if (suspend) {
-               printk_debug("Wakeup!\n");
+               printk(BIOS_DEBUG, "Wakeup!\n");
                exit_from_self(controllers, ctrl, sysinfo);
-               printk_debug("Mem running !\n");
+               printk(BIOS_DEBUG, "Mem running !\n");
                return;
        }
 
@@ -3062,7 +3082,7 @@ static void sdram_enable(int controllers, const struct mem_controller *ctrl,
                dcl = pci_read_config32(ctrl[i].f2, DRAM_CONFIG_LOW);
                if (dcl & DCL_DimmEccEn) {
                        uint32_t mnc;
-                       printk_spew("ECC enabled\n");
+                       printk(BIOS_SPEW, "ECC enabled\n");
                        mnc = pci_read_config32(ctrl[i].f3, MCA_NB_CONFIG);
                        mnc |= MNC_ECC_EN;
                        if (dcl & DCL_Width128) {
@@ -3097,17 +3117,17 @@ static void sdram_enable(int controllers, const struct mem_controller *ctrl,
                /* Skip everything if I don't have any memory on this controller */
                if (sysinfo->meminfo[i].dimm_mask==0x00) continue;
 
-               printk_debug("Initializing memory: ");
+               printk(BIOS_DEBUG, "Initializing memory: ");
                int loops = 0;
                do {
                        dcl = pci_read_config32(ctrl[i].f2, DRAM_CONFIG_LOW);
                        loops++;
                        if ((loops & 1023) == 0) {
-                               printk_debug(".");
+                               printk(BIOS_DEBUG, ".");
                        }
                } while(((dcl & DCL_InitDram) != 0) && (loops < TIMEOUT_LOOPS));
                if (loops >= TIMEOUT_LOOPS) {
-                       printk_debug(" failed\n");
+                       printk(BIOS_DEBUG, " failed\n");
                        continue;
                }
 
@@ -3135,7 +3155,7 @@ static void sdram_enable(int controllers, const struct mem_controller *ctrl,
                        print_debug_dqs_tsc("     dtsc0", i, tsc0[i].hi, tsc0[i].lo, 2);
                }
 #endif
-               printk_debug(" done\n");
+               printk(BIOS_DEBUG, " done\n");
        }
 
 #if CONFIG_HW_MEM_HOLE_SIZEK != 0
@@ -3207,7 +3227,7 @@ static void sdram_enable(int controllers, const struct mem_controller *ctrl,
 
 }
 
-static void fill_mem_ctrl(int controllers, struct mem_controller *ctrl_a,
+void fill_mem_ctrl(int controllers, struct mem_controller *ctrl_a,
                          const uint16_t *spd_addr)
 {
        int i;