Please bear with me - another rename checkin. This qualifies as trivial, no
[coreboot.git] / src / northbridge / amd / lx / raminit.c
index fd496d80f41693c78e1d61ee690a99679d9c980c..0c8fd801eec438d5a4f6087839ded6f5bf4b59aa 100644 (file)
@@ -1,21 +1,21 @@
 /*
-* This file is part of the LinuxBIOS project.
-*
-* Copyright (C) 2007 Advanced Micro Devices
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License version 2 as
-* published by the Free Software Foundation.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA     02110-1301 USA
-*/
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2007 Advanced Micro Devices, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.        See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+ */
 
 #include <cpu/amd/lxdef.h>
 #include <arch/io.h>
@@ -27,6 +27,23 @@ static const unsigned char NumColAddr[] = {
        0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 
 };
 
+void banner(char *s)
+{
+       print_debug("===========================");
+       print_debug(s);
+       print_debug("======================================\r\n");
+}
+void hcf(void)
+{
+       print_emerg("DIE\r\n");
+       /* this guarantees we flush the UART fifos (if any) and also 
+        * ensures that things, in general, keep going so no debug output 
+        * is lost
+        */
+       while (1)
+               print_emerg_char(0);
+}
+
 static void auto_size_dimm(unsigned int dimm)
 {
        uint32_t dimm_setting;
@@ -36,33 +53,37 @@ static void auto_size_dimm(unsigned int dimm)
 
        dimm_setting = 0;
 
+       banner("Check present");
        /* Check that we have a dimm */
        if (spd_read_byte(dimm, SPD_MEMORY_TYPE) == 0xFF) {
                return;
        }
 
+       banner("MODBANKS");
        /* Field: Module Banks per DIMM */
        /* EEPROM byte usage: (5) Number of DIMM Banks */
        spd_byte = spd_read_byte(dimm, SPD_NUM_DIMM_BANKS);
-       if ((MIN_MOD_BANKS > spd_byte) && (spd_byte > MAX_MOD_BANKS)) {
-               print_debug("Number of module banks not compatible\r\n");
+       if ((MIN_MOD_BANKS > spd_byte) || (spd_byte > MAX_MOD_BANKS)) {
+               print_emerg("Number of module banks not compatible\n");
                POST_CODE(ERROR_BANK_SET);
-               __asm__ __volatile__("hlt\n");
+               hcf();
        }
        dimm_setting |= (spd_byte >> 1) << CF07_UPPER_D0_MB_SHIFT;
+       banner("FIELDBANKS");
 
        /* Field: Banks per SDRAM device */
        /* EEPROM byte usage: (17) Number of Banks on SDRAM Device */
        spd_byte = spd_read_byte(dimm, SPD_NUM_BANKS_PER_SDRAM);
-       if ((MIN_DEV_BANKS > spd_byte) && (spd_byte > MAX_DEV_BANKS)) {
-               print_debug("Number of device banks not compatible\r\n");
+       if ((MIN_DEV_BANKS > spd_byte) || (spd_byte > MAX_DEV_BANKS)) {
+               print_emerg("Number of device banks not compatible\n");
                POST_CODE(ERROR_BANK_SET);
-               __asm__ __volatile__("hlt\n");
+               hcf();
        }
        dimm_setting |= (spd_byte >> 2) << CF07_UPPER_D0_CB_SHIFT;
+       banner("SPDNUMROWS");
 
        /*; Field: DIMM size
-        *; EEPROM byte usage: (3)  Number or Row Addresses
+        *; EEPROM byte usage: (3)  Number of Row Addresses
         *;                                       (4)  Number of Column Addresses
         *;                                       (5)  Number of DIMM Banks
         *;                                       (31) Module Bank Density
@@ -70,24 +91,29 @@ static void auto_size_dimm(unsigned int dimm)
         */
        if ((spd_read_byte(dimm, SPD_NUM_ROWS) & 0xF0)
            || (spd_read_byte(dimm, SPD_NUM_COLUMNS) & 0xF0)) {
-               print_debug("Assymetirc DIMM not compatible\r\n");
+               print_emerg("Assymetirc DIMM not compatible\n");
                POST_CODE(ERROR_UNSUPPORTED_DIMM);
-               __asm__ __volatile__("hlt\n");
+               hcf();
        }
+       banner("SPDBANKDENSITY");
 
        dimm_size = spd_read_byte(dimm, SPD_BANK_DENSITY);
+       banner("DIMMSIZE");
        dimm_size |= (dimm_size << 8);  /* align so 1GB(bit0) is bit 8, this is a little weird to get gcc to not optimize this out */
        dimm_size &= 0x01FC;    /* and off 2GB DIMM size : not supported and the 1GB size we just moved up to bit 8 as well as all the extra on top */
 
        /*       Module Density * Module Banks */
        dimm_size <<= (dimm_setting >> CF07_UPPER_D0_MB_SHIFT) & 1;     /* shift to multiply by # DIMM banks */
+       banner("BEFORT CTZ");
        dimm_size = __builtin_ctz(dimm_size);
+       banner("TEST DIMM SIZE>8");
        if (dimm_size > 8) {    /* 8 is 1GB only support 1GB per DIMM */
-               print_debug("Only support up to 1 GB per DIMM\r\n");
+               print_emerg("Only support up to 1 GB per DIMM\n");
                POST_CODE(ERROR_DENSITY_DIMM);
-               __asm__ __volatile__("hlt\n");
+               hcf();
        }
        dimm_setting |= dimm_size << CF07_UPPER_D0_SZ_SHIFT;
+       banner("PAGESIZE");
 
 /*; Field: PAGE size
 *; EEPROM byte usage: (4)  Number of Column Addresses
@@ -113,18 +139,22 @@ static void auto_size_dimm(unsigned int dimm)
 *;it adds 3 to get 10, then does 2^10=1K.  Get it?*/
 
        spd_byte = NumColAddr[spd_read_byte(dimm, SPD_NUM_COLUMNS) & 0xF];
+       banner("MAXCOLADDR");
        if (spd_byte > MAX_COL_ADDR) {
-               print_debug("DIMM page size not compatible\r\n");
+               print_emerg("DIMM page size not compatible\n");
                POST_CODE(ERROR_SET_PAGE);
-               __asm__ __volatile__("hlt\n");
+               hcf();
        }
+       banner(">12address test");
        spd_byte -= 7;
        if (spd_byte > 5) {     /* if the value is above 6 it means >12 address lines */
                spd_byte = 7;   /* which means >32k so set to disabled */
        }
        dimm_setting |= spd_byte << CF07_UPPER_D0_PSZ_SHIFT;    /* 0=1k,1=2k,2=4k,etc */
 
+       banner("RDMSR CF07");
        msr = rdmsr(MC_CF07_DATA);
+       banner("WRMSR CF07");
        if (dimm == DIMM0) {
                msr.hi &= 0xFFFF0000;
                msr.hi |= dimm_setting;
@@ -133,6 +163,7 @@ static void auto_size_dimm(unsigned int dimm)
                msr.hi |= dimm_setting << 16;
        }
        wrmsr(MC_CF07_DATA, msr);
+       banner("ALL DONE");
 }
 
 static void checkDDRMax(void)
@@ -151,10 +182,10 @@ static void checkDDRMax(void)
        }
 
        /* I don't think you need this check.
-          if (spd_byte0 < 0xA0 || spd_byte0 < 0xA0){
-          print_debug("DIMM overclocked. Check GeodeLink Speed\r\n");
+          if (spd_byte0 >= 0xA0 || spd_byte1 >= 0xA0){
+          print_emerg("DIMM overclocked. Check GeodeLink Speed\n");
           POST_CODE(POST_PLL_MEM_FAIL);
-          __asm__       __volatile__("hlt\n");
+          hcf();
           } */
 
        /* Use the slowest DIMM */
@@ -167,9 +198,9 @@ static void checkDDRMax(void)
 
        /* current speed > max speed? */
        if (GeodeLinkSpeed() > speed) {
-               print_debug("DIMM overclocked. Check GeodeLink Speed\r\n");
+               print_emerg("DIMM overclocked. Check GeodeLink Speed\r\n");
                POST_CODE(POST_PLL_MEM_FAIL);
-               __asm__ __volatile__("hlt\n");
+               hcf();
        }
 }
 
@@ -231,7 +262,7 @@ static void setCAS(void)
 ;*     Destroys: We really use everything !
 ;*****************************************************************************/
        uint16_t glspeed, dimm_speed;
-       uint8_t spd_byte, casmap0, casmap1;
+       uint8_t spd_byte, casmap0, casmap1, casmap_shift;
        msr_t msr;
 
        glspeed = GeodeLinkSpeed();
@@ -246,25 +277,24 @@ static void setCAS(void)
                        dimm_speed = 2 * (10000 / (((spd_byte >> 4) * 10) +
                                                (spd_byte & 0x0F)));
                        if (dimm_speed >= glspeed) {
+                               casmap_shift = 1; /* -.5 is a shift of 1 */
                                /* IF -1 timing is supported, check -1 timing > GeodeLink */
                                spd_byte = spd_read_byte(DIMM0, SPD_SDRAM_CYCLE_TIME_3RD);
                                if (spd_byte != 0) {
                                        /* Turn SPD ns time into MHZ. Check what the asm does to this math. */
                                        dimm_speed = 2 * (10000 / (((spd_byte >> 4) * 10) + (spd_byte & 0x0F)));
-                                       if (dimm_speed <= glspeed) {
-                                               /* set we can use -.5 timing but not -1 */
-                                               spd_byte = 31 - __builtin_clz((uint32_t) casmap0);
-                                               /* just want bits in the lower byte since we have to cast to a 32 */
-                                               casmap0 &= 0xFF << (--spd_byte);
+                                       if (dimm_speed >= glspeed) {
+                                               casmap_shift = 2; /* -1 is a shift of 2 */
                                        }
-                               }       /*MIN_CYCLE_10 !=0 */
+                               }       /* SPD_SDRAM_CYCLE_TIME_3RD (-1) !=0 */
                        } else {
-                               /* Timing_05 < GLspeed, can't use -.5 or -1 timing */
-                               spd_byte = 31 - __builtin_clz((uint32_t) casmap0);
-                               /* just want bits in the lower byte since we have to cast to a 32 */
-                               casmap0 &= 0xFF << (spd_byte);
+                               casmap_shift = 0;
                        }
-               }               /*MIN_CYCLE_05 !=0 */
+               }       /* SPD_SDRAM_CYCLE_TIME_2ND (-.5) !=0 */
+               /* set the casmap based on the shift to limit possible CAS settings */
+               spd_byte = 31 - __builtin_clz((uint32_t) casmap0);
+               /* just want bits in the lower byte since we have to cast to a 32 */
+               casmap0 &= 0xFF << (spd_byte - casmap_shift);
        } else {                /* No DIMM */
                casmap0 = 0;
        }
@@ -278,25 +308,25 @@ static void setCAS(void)
                        /* Turn SPD ns time into MHZ. Check what the asm does to this math. */
                        dimm_speed = 2 * (10000 / (((spd_byte >> 4) * 10) + (spd_byte & 0x0F)));
                        if (dimm_speed >= glspeed) {
+                               casmap_shift = 1; /* -.5 is a shift of 1 */
                                /* IF -1 timing is supported, check -1 timing > GeodeLink */
                                spd_byte = spd_read_byte(DIMM1, SPD_SDRAM_CYCLE_TIME_3RD);
                                if (spd_byte != 0) {
                                        /* Turn SPD ns time into MHZ. Check what the asm does to this math. */
                                        dimm_speed = 2 * (10000 / (((spd_byte >> 4) * 10) + (spd_byte & 0x0F)));
-                                       if (dimm_speed <= glspeed) {
-                                               /* set we can use -.5 timing but not -1 */
-                                               spd_byte = 31 - __builtin_clz((uint32_t) casmap1);
-                                               /* just want bits in the lower byte since we have to cast to a 32 */
-                                               casmap1 &= 0xFF << (--spd_byte);
+                                       if (dimm_speed >= glspeed) {
+                                               casmap_shift = 2; /* -1 is a shift of 2 */
                                        }
-                               }       /*MIN_CYCLE_10 !=0 */
+                                       /* note that the -1 result doesn't need to change the available CAS map */
+                               }       /* SPD_SDRAM_CYCLE_TIME_3RD (-1) !=0 */
                        } else {
-                               /* Timing_05 < GLspeed, can't use -.5 or -1 timing */
-                               spd_byte = 31 - __builtin_clz((uint32_t) casmap1);
-                               /* just want bits in the lower byte since we have to cast to a 32 */
-                               casmap1 &= 0xFF << (spd_byte);
+                               casmap_shift = 0;
                        }
-               }               /*MIN_CYCLE_05 !=0 */
+               }       /* SPD_SDRAM_CYCLE_TIME_2ND (-.5) !=0 */
+               /* set the casmap based on the shift to limit possible CAS settings */
+               spd_byte = 31 - __builtin_clz((uint32_t) casmap1);
+               /* just want bits in the lower byte since we have to cast to a 32 */
+               casmap1 &= 0xFF << (spd_byte - casmap_shift);
        } else {                /* No DIMM */
                casmap1 = 0;
        }
@@ -309,9 +339,9 @@ static void setCAS(void)
        } else if ((casmap0 &= casmap1)) {
                spd_byte = CASDDR[__builtin_ctz((uint32_t) casmap0)];
        } else {
-               print_debug("DIMM CAS Latencies not compatible\r\n");
+               print_emerg("DIMM CAS Latencies not compatible\r\n");
                POST_CODE(ERROR_DIFF_DIMMS);
-               __asm__ __volatile__("hlt\n");
+               hcf();
        }
 
        msr = rdmsr(MC_CF8F_DATA);
@@ -501,7 +531,7 @@ static void EnableMTest(void)
        msr.lo |= CFCLK_LOWER_TRISTATE_DIS_SET;
        wrmsr(MC_CFCLK_DBUG, msr);
 
-       print_debug("Enabled MTest for TLA debug\r\n");
+       print_info("Enabled MTest for TLA debug\r\n");
 }
 
 static void sdram_set_registers(const struct mem_controller *ctrl)
@@ -538,43 +568,53 @@ static void sdram_set_spd_registers(const struct mem_controller *ctrl)
 {
        uint8_t spd_byte;
 
+       banner("sdram_set_spd_register\n");
        POST_CODE(POST_MEM_SETUP);      // post_70h
 
        spd_byte = spd_read_byte(DIMM0, SPD_MODULE_ATTRIBUTES);
+       banner("Check DIMM 0");
        /* Check DIMM is not Register and not Buffered DIMMs. */
        if ((spd_byte != 0xFF) && (spd_byte & 3)) {
-               print_debug("DIMM0 NOT COMPATIBLE\r\n");
+               print_emerg("DIMM0 NOT COMPATIBLE\r\n");
                POST_CODE(ERROR_UNSUPPORTED_DIMM);
-               __asm__ __volatile__("hlt\n");
+               hcf();
        }
+       banner("Check DIMM 1");
        spd_byte = spd_read_byte(DIMM1, SPD_MODULE_ATTRIBUTES);
        if ((spd_byte != 0xFF) && (spd_byte & 3)) {
-               print_debug("DIMM1 NOT COMPATIBLE\r\n");
+               print_emerg("DIMM1 NOT COMPATIBLE\n");
                POST_CODE(ERROR_UNSUPPORTED_DIMM);
-               __asm__ __volatile__("hlt\n");
+               hcf();
        }
 
        POST_CODE(POST_MEM_SETUP2);     // post_72h
+       banner("Check DDR MAX");
 
        /* Check that the memory is not overclocked. */
        checkDDRMax();
 
        /* Size the DIMMS */
        POST_CODE(POST_MEM_SETUP3);     // post_73h
+       banner("AUTOSIZE DIMM 0");
        auto_size_dimm(DIMM0);
        POST_CODE(POST_MEM_SETUP4);     // post_74h
+       banner("AUTOSIZE DIMM 1");
        auto_size_dimm(DIMM1);
 
        /* Set CAS latency */
+       banner("set cas latency");
        POST_CODE(POST_MEM_SETUP5);     // post_75h
        setCAS();
 
        /* Set all the other latencies here (tRAS, tRP....) */
+       banner("set all latency");
        set_latencies();
 
        /* Set Extended Mode Registers */
+       banner("set emrs");
        set_extended_mode_registers();
 
+       banner("set ref rate");
        /* Set Memory Refresh Rate */
        set_refresh_rate();
 
@@ -608,9 +648,9 @@ static void sdram_enable(int controllers, const struct mem_controller *ctrl)
        msr = rdmsr(MC_CF07_DATA);
        if ((msr.hi & ((7 << CF07_UPPER_D1_PSZ_SHIFT) | (7 << CF07_UPPER_D0_PSZ_SHIFT))) == 
                        ((7 << CF07_UPPER_D1_PSZ_SHIFT) | (7 << CF07_UPPER_D0_PSZ_SHIFT))) {
-               print_debug("No memory in the system\r\n");
+               print_emerg("No memory in the system\r\n");
                POST_CODE(ERROR_NO_DIMMS);
-               __asm__ __volatile__("hlt\n");
+               hcf();
        }
 
        /*      Set CKEs */
@@ -718,7 +758,7 @@ static void sdram_enable(int controllers, const struct mem_controller *ctrl)
        msr.lo |= (209 << 8);   /* bits[15:8] = 209 */
        wrmsr(msrnum, msr);
 
-       print_debug("DRAM controller init done.\r\n");
+       print_emerg("DRAM controller init done.\n");
        POST_CODE(POST_MEM_SETUP_GOOD); //0x7E
 
        /* make sure there is nothing stale in the cache */
@@ -750,6 +790,6 @@ static void sdram_enable(int controllers, const struct mem_controller *ctrl)
                msr.lo |= 1;
                wrmsr(msrnum, msr);
        }
-       print_debug("RAM DLL lock\r\n");
+       print_info("RAM DLL lock\n");
 
 }