Move C labels to start-of-line
[coreboot.git] / src / northbridge / intel / i945 / raminit.c
index 8ae147081094352899190f03e00ce7a2350580de..a4512d7ba80743c5d5561fb4d5cffe955399b513 100644 (file)
@@ -28,7 +28,8 @@
 #include "i945.h"
 #include <cbmem.h>
 
-struct cbmem_entry *get_cbmem_toc(void) {
+struct cbmem_entry *get_cbmem_toc(void)
+{
        return (struct cbmem_entry *)(get_top_of_ram() - HIGH_MEMORY_SIZE);
 }
 
@@ -53,6 +54,15 @@ struct cbmem_entry *get_cbmem_toc(void) {
 #define RAM_EMRS_2                     (0x1 << 21)
 #define RAM_EMRS_3                     (0x2 << 21)
 
+static int get_dimm_spd_address(struct sys_info *sysinfo, int device)
+{
+       if (sysinfo->spd_addresses)
+               return sysinfo->spd_addresses[device];
+       else
+               return DIMM0 + device;
+
+}
+
 static inline int spd_read_byte(unsigned device, unsigned address)
 {
        return smbus_read_byte(device, address);
@@ -87,7 +97,7 @@ static void ram_read32(u32 offset)
 }
 
 #if CONFIG_DEBUG_RAM_SETUP
-static void sdram_dump_mchbar_registers(void)
+void sdram_dump_mchbar_registers(void)
 {
        int i;
        printk(BIOS_DEBUG, "Dumping MCHBAR Registers\n");
@@ -103,7 +113,7 @@ static void sdram_dump_mchbar_registers(void)
 static int memclk(void)
 {
        int offset = 0;
-#if defined(CONFIG_NORTHBRIDGE_INTEL_I945GM)
+#if CONFIG_NORTHBRIDGE_INTEL_I945GM
        offset++;
 #endif
        switch (((MCHBAR32(CLKCFG) >> 4) & 7) - offset) {
@@ -115,7 +125,7 @@ static int memclk(void)
        return -1;
 }
 
-#if defined(CONFIG_NORTHBRIDGE_INTEL_I945GM)
+#if CONFIG_NORTHBRIDGE_INTEL_I945GM
 static u16 fsbclk(void)
 {
        switch (MCHBAR32(CLKCFG) & 7) {
@@ -126,7 +136,7 @@ static u16 fsbclk(void)
        }
        return 0xffff;
 }
-#elif defined(CONFIG_NORTHBRIDGE_INTEL_I945GC)
+#elif CONFIG_NORTHBRIDGE_INTEL_I945GC
 static u16 fsbclk(void)
 {
        switch (MCHBAR32(CLKCFG) & 7) {
@@ -284,8 +294,8 @@ static void sdram_detect_errors(struct sys_info *sysinfo)
        reg8 |= (1<<7);
        pci_write_config8(PCI_DEV(0, 0x1f, 0), 0xa2, reg8);
 
-       /* clear self refresh if not wake-up from suspend */
-       if (sysinfo->boot_path != 2) {
+       /* clear self refresh status if check is disabled or not a resume */
+       if (!CONFIG_CHECK_SLFRCS_ON_RESUME || sysinfo->boot_path != 2) {
                MCHBAR8(0xf14) |= 3;
        } else {
                /* Validate self refresh config */
@@ -366,7 +376,8 @@ static void sdram_get_dram_configuration(struct sys_info *sysinfo)
         */
 
        for (i=0; i<(2 * DIMM_SOCKETS); i++) {
-               u8 reg8, device = DIMM0 + i;
+               int device = get_dimm_spd_address(sysinfo, i);
+               u8 reg8;
 
                /* Initialize the socket information with a sane value */
                sysinfo->dimm[i] = SYSINFO_DIMM_NOT_POPULATED;
@@ -457,7 +468,7 @@ static void sdram_verify_package_type(struct sys_info * sysinfo)
                        continue;
 
                /* Is the current DIMM a stacked DIMM? */
-               if (spd_read_byte(DIMM0 + i, SPD_NUM_DIMM_BANKS) & (1 << 4))
+               if (spd_read_byte(get_dimm_spd_address(sysinfo, i), SPD_NUM_DIMM_BANKS) & (1 << 4))
                        sysinfo->package = 1;
        }
 }
@@ -474,7 +485,8 @@ static u8 sdram_possible_cas_latencies(struct sys_info * sysinfo)
 
        for (i=0; i<2*DIMM_SOCKETS; i++) {
                if (sysinfo->dimm[i] != SYSINFO_DIMM_NOT_POPULATED)
-                       cas_mask &= spd_read_byte(DIMM0 + i, SPD_ACCEPTABLE_CAS_LATENCIES);
+                       cas_mask &= spd_read_byte(get_dimm_spd_address(sysinfo, i),
+                                                 SPD_ACCEPTABLE_CAS_LATENCIES);
        }
 
        if(!cas_mask) {
@@ -528,6 +540,7 @@ static void sdram_detect_cas_latency_and_ram_speed(struct sys_info * sysinfo, u8
 
                PRINTK_DEBUG("Probing Speed %d\n", j);
                for (i=0; i<2*DIMM_SOCKETS; i++) {
+                       int device = get_dimm_spd_address(sysinfo, i);
                        int current_cas_mask;
 
                        PRINTK_DEBUG("  DIMM: %d\n", i);
@@ -535,7 +548,7 @@ static void sdram_detect_cas_latency_and_ram_speed(struct sys_info * sysinfo, u8
                                continue;
                        }
 
-                       current_cas_mask = spd_read_byte(DIMM0 + i, SPD_ACCEPTABLE_CAS_LATENCIES);
+                       current_cas_mask = spd_read_byte(device, SPD_ACCEPTABLE_CAS_LATENCIES);
 
                        while (current_cas_mask) {
                                int highest_supported_cas = 0, current_cas = 0;
@@ -561,11 +574,11 @@ static void sdram_detect_cas_latency_and_ram_speed(struct sys_info * sysinfo, u8
 
                                idx = highest_supported_cas - current_cas;
                                PRINTK_DEBUG("idx=%d, ", idx);
-                               PRINTK_DEBUG("tCLK=%x, ", spd_read_byte(DIMM0 + i, spd_lookup_table[2*idx]));
-                               PRINTK_DEBUG("tAC=%x", spd_read_byte(DIMM0 + i, spd_lookup_table[(2*idx)+1]));
+                               PRINTK_DEBUG("tCLK=%x, ", spd_read_byte(device, spd_lookup_table[2*idx]));
+                               PRINTK_DEBUG("tAC=%x", spd_read_byte(device, spd_lookup_table[(2*idx)+1]));
 
-                               if (spd_read_byte(DIMM0 + i, spd_lookup_table[2*idx]) <= ddr2_speeds_table[2*j] &&
-                                               spd_read_byte(DIMM0 + i, spd_lookup_table[(2*idx)+1]) <= ddr2_speeds_table[(2*j)+1]) {
+                               if (spd_read_byte(device, spd_lookup_table[2*idx]) <= ddr2_speeds_table[2*j] &&
+                                               spd_read_byte(device, spd_lookup_table[(2*idx)+1]) <= ddr2_speeds_table[(2*j)+1]) {
                                        PRINTK_DEBUG(":    OK\n");
                                        break;
                                }
@@ -629,7 +642,7 @@ static void sdram_detect_smallest_tRAS(struct sys_info * sysinfo)
                if (sysinfo->dimm[i] == SYSINFO_DIMM_NOT_POPULATED)
                        continue;
 
-               reg8 = spd_read_byte(DIMM0 + i, SPD_MIN_ACTIVE_TO_PRECHARGE_DELAY);
+               reg8 = spd_read_byte(get_dimm_spd_address(sysinfo, i), SPD_MIN_ACTIVE_TO_PRECHARGE_DELAY);
                if (!reg8) {
                        die("Invalid tRAS value.\n");
                }
@@ -669,7 +682,7 @@ static void sdram_detect_smallest_tRP(struct sys_info * sysinfo)
                if (sysinfo->dimm[i] == SYSINFO_DIMM_NOT_POPULATED)
                        continue;
 
-               reg8 = spd_read_byte(DIMM0 + i, SPD_MIN_ROW_PRECHARGE_TIME);
+               reg8 = spd_read_byte(get_dimm_spd_address(sysinfo, i), SPD_MIN_ROW_PRECHARGE_TIME);
                if (!reg8) {
                        die("Invalid tRP value.\n");
                }
@@ -710,7 +723,7 @@ static void sdram_detect_smallest_tRCD(struct sys_info * sysinfo)
                if (sysinfo->dimm[i] == SYSINFO_DIMM_NOT_POPULATED)
                        continue;
 
-               reg8 = spd_read_byte(DIMM0 + i, SPD_MIN_RAS_TO_CAS_DELAY);
+               reg8 = spd_read_byte(get_dimm_spd_address(sysinfo, i), SPD_MIN_RAS_TO_CAS_DELAY);
                if (!reg8) {
                        die("Invalid tRCD value.\n");
                }
@@ -750,7 +763,7 @@ static void sdram_detect_smallest_tWR(struct sys_info * sysinfo)
                if (sysinfo->dimm[i] == SYSINFO_DIMM_NOT_POPULATED)
                        continue;
 
-               reg8 = spd_read_byte(DIMM0 + i, SPD_WRITE_RECOVERY_TIME);
+               reg8 = spd_read_byte(get_dimm_spd_address(sysinfo, i), SPD_WRITE_RECOVERY_TIME);
                if (!reg8) {
                        die("Invalid tWR value.\n");
                }
@@ -831,7 +844,8 @@ static void sdram_detect_smallest_refresh(struct sys_info * sysinfo)
                if (sysinfo->dimm[i] == SYSINFO_DIMM_NOT_POPULATED)
                        continue;
 
-               refresh = spd_read_byte(DIMM0 + i, SPD_REFRESH) & ~(1 << 7);
+               refresh = spd_read_byte(get_dimm_spd_address(sysinfo, i),
+                                       SPD_REFRESH) & ~(1 << 7);
 
                /* 15.6us */
                if (!refresh)
@@ -859,7 +873,8 @@ static void sdram_verify_burst_length(struct sys_info * sysinfo)
                if (sysinfo->dimm[i] == SYSINFO_DIMM_NOT_POPULATED)
                        continue;
 
-               if (!(spd_read_byte(DIMM0 + i, SPD_SUPPORTED_BURST_LENGTHS) & SPD_BURST_LENGTH_8))
+               if (!(spd_read_byte(get_dimm_spd_address(sysinfo, i),
+                                   SPD_SUPPORTED_BURST_LENGTHS) & SPD_BURST_LENGTH_8))
                        die("Only DDR-II RAM with burst length 8 is supported by this chipset.\n");
        }
 }
@@ -1060,7 +1075,7 @@ static const u32 *slew_group_lookup(int dual_channel, int index)
        return nc;
 }
 
-#if defined(CONFIG_NORTHBRIDGE_INTEL_I945GM)
+#if CONFIG_NORTHBRIDGE_INTEL_I945GM
 /* Strength multiplier tables */
 static const u8 dual_channel_strength_multiplier[] = {
        0x44, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x11,
@@ -1115,7 +1130,7 @@ static const u8 single_channel_strength_multiplier[] = {
        0x33, 0x00, 0x00, 0x11, 0x00, 0x44, 0x33, 0x11,
        0x33, 0x00, 0x11, 0x00, 0x44, 0x44, 0x33, 0x11
 };
-#elif defined(CONFIG_NORTHBRIDGE_INTEL_I945GC)
+#elif CONFIG_NORTHBRIDGE_INTEL_I945GC
 static const u8 dual_channel_strength_multiplier[] = {
        0x44, 0x22, 0x00, 0x00, 0x44, 0x44, 0x44, 0x22,
        0x44, 0x22, 0x00, 0x00, 0x44, 0x44, 0x44, 0x22,
@@ -1391,12 +1406,13 @@ struct dimm_size {
        unsigned long side2;
 };
 
-static struct dimm_size sdram_get_dimm_size(u16 device)
+static struct dimm_size sdram_get_dimm_size(struct sys_info *sysinfo, u16 dimmno)
 {
        /* Calculate the log base 2 size of a DIMM in bits */
        struct dimm_size sz;
-       int value, low, rows, columns;
+       int value, low, rows, columns, device;
 
+       device = get_dimm_spd_address(sysinfo, dimmno);
        sz.side1 = 0;
        sz.side2 = 0;
 
@@ -1462,7 +1478,7 @@ static struct dimm_size sdram_get_dimm_size(u16 device)
         */
        sz.side1 = 0;
        sz.side2 = 0;
- out:
+out:
        return sz;
 }
 
@@ -1479,9 +1495,10 @@ static void sdram_detect_dimm_size(struct sys_info * sysinfo)
                if (sysinfo->dimm[i] == SYSINFO_DIMM_NOT_POPULATED)
                        continue;
 
-               sz = sdram_get_dimm_size(DIMM0 + i);
+               sz = sdram_get_dimm_size(sysinfo, i);
 
-               sysinfo->banks[i] = spd_read_byte(DIMM0 + i, SPD_NUM_BANKS_PER_SDRAM);  /* banks */
+               sysinfo->banks[i] = spd_read_byte(get_dimm_spd_address(sysinfo, i),
+                                                 SPD_NUM_BANKS_PER_SDRAM);     /* banks */
 
                if (sz.side1 < 30)
                        die("DDR-II rank size smaller than 128MB is not supported.\n");
@@ -1573,7 +1590,7 @@ static int sdram_set_row_attributes(struct sys_info *sysinfo)
                        continue;
                }
 
-               device = DIMM0 + i;
+               device = get_dimm_spd_address(sysinfo, i);
 
                value = spd_read_byte(device, SPD_NUM_ROWS);    /* rows */
                columnsrows = (value & 0x0f);
@@ -2169,7 +2186,7 @@ static void sdram_program_clock_crossing(void)
        /**
         * We add the indices according to our clocks from CLKCFG.
         */
-#if defined(CONFIG_NORTHBRIDGE_INTEL_I945GM)
+#if CONFIG_NORTHBRIDGE_INTEL_I945GM
        static const u32 data_clock_crossing[] = {
                0x00100401, 0x00000000, /* DDR400 FSB400 */
                0xffffffff, 0xffffffff, /*  nonexistant  */
@@ -2214,7 +2231,7 @@ static void sdram_program_clock_crossing(void)
                0xffffffff, 0xffffffff, /*  nonexistant  */
        };
 
-#elif defined(CONFIG_NORTHBRIDGE_INTEL_I945GC)
+#elif CONFIG_NORTHBRIDGE_INTEL_I945GC
        /* i945 G/P */
        static const u32 data_clock_crossing[] = {
                0xffffffff, 0xffffffff, /*  nonexistant  */
@@ -2805,9 +2822,9 @@ static void sdram_enable_memory_clocks(struct sys_info *sysinfo)
 {
        u8 clocks[2] = { 0, 0 };
 
-#if defined(CONFIG_NORTHBRIDGE_INTEL_I945GM)
+#if CONFIG_NORTHBRIDGE_INTEL_I945GM
 #define CLOCKS_WIDTH 2
-#elif defined(CONFIG_NORTHBRIDGE_INTEL_I945GC)
+#elif CONFIG_NORTHBRIDGE_INTEL_I945GC
 #define CLOCKS_WIDTH 3
 #endif
        if (sysinfo->dimm[0] != SYSINFO_DIMM_NOT_POPULATED)
@@ -3038,7 +3055,7 @@ static void sdram_setup_processor_side(void)
 /**
  * @param boot_path: 0 = normal, 1 = reset, 2 = resume from s3
  */
-void sdram_initialize(int boot_path)
+void sdram_initialize(int boot_path, const u8 *spd_addresses)
 {
        struct sys_info sysinfo;
        u8 reg8, cas_mask;
@@ -3048,6 +3065,7 @@ void sdram_initialize(int boot_path)
        memset(&sysinfo, 0, sizeof(sysinfo));
 
        sysinfo.boot_path = boot_path;
+       sysinfo.spd_addresses = spd_addresses;
 
        /* Look at the type of DIMMs and verify all DIMMs are x8 or x16 width */
        sdram_get_dram_configuration(&sysinfo);
@@ -3174,9 +3192,33 @@ void sdram_initialize(int boot_path)
 
 unsigned long get_top_of_ram(void)
 {
-       /* This will not work if TSEG is in place! */
-       u32 tom = pci_read_config32(PCI_DEV(0,2,0), 0x5c);
+       u32 tom;
 
+       if (pci_read_config8(PCI_DEV(0, 0x0, 0), DEVEN) & ((1 << 4) | (1 << 3))) {
+               /* IGD enabled, get top of Memory from BSM register */
+               tom = pci_read_config32(PCI_DEV(0,2,0), 0x5c);
+       } else {
+               tom = (pci_read_config8(PCI_DEV(0,0,0), TOLUD) & 0xf7) << 24;
+       }
+
+       /* if TSEG enabled subtract size */
+       switch(pci_read_config8(PCI_DEV(0, 0, 0), ESMRAM)) {
+       case 0x01:
+               /* 1MB TSEG */
+               tom -= 0x10000;
+               break;
+       case 0x03:
+               /* 2MB TSEG */
+               tom -= 0x20000;
+               break;
+       case 0x05:
+               /* 8MB TSEG */
+               tom -= 0x80000;
+               break;
+       default:
+               /* TSEG either disabled or invalid */
+               break;
+       }
        return (unsigned long) tom;
 }