No warnings day, next round.
[coreboot.git] / src / northbridge / amd / lx / raminit.c
index 9981f58cae0802c0f0dd1336519241059c862d41..bf7a817c801bb8e78fae68a27d5f6aae08b760be 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.
  *
@@ -27,6 +27,25 @@ static const unsigned char NumColAddr[] = {
        0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F 
 };
 
+static void banner(const char *s)
+{
+       /* This is so ugly. */
+       print_debug("===========================");
+       print_debug(s);
+       print_debug("======================================\n");
+}
+
+static void hcf(void)
+{
+       print_emerg("DIE\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 +55,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\n");
-               POST_CODE(ERROR_BANK_SET);
-               __asm__ __volatile__("hlt\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);
+               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\n");
-               POST_CODE(ERROR_BANK_SET);
-               __asm__ __volatile__("hlt\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);
+               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 +93,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\n");
-               POST_CODE(ERROR_UNSUPPORTED_DIMM);
-               __asm__ __volatile__("hlt\n");
+               print_emerg("Assymetirc DIMM not compatible\n");
+               post_code(ERROR_UNSUPPORTED_DIMM);
+               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\n");
-               POST_CODE(ERROR_DENSITY_DIMM);
-               __asm__ __volatile__("hlt\n");
+               print_emerg("Only support up to 1 GB per DIMM\n");
+               post_code(ERROR_DENSITY_DIMM);
+               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 +141,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\n");
-               POST_CODE(ERROR_SET_PAGE);
-               __asm__ __volatile__("hlt\n");
+               print_emerg("DIMM page size not compatible\n");
+               post_code(ERROR_SET_PAGE);
+               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 +165,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)
@@ -152,9 +185,9 @@ static void checkDDRMax(void)
 
        /* I don't think you need this check.
           if (spd_byte0 >= 0xA0 || spd_byte1 >= 0xA0){
-          print_debug("DIMM overclocked. Check GeodeLink Speed\n");
-          POST_CODE(POST_PLL_MEM_FAIL);
-          __asm__       __volatile__("hlt\n");
+          print_emerg("DIMM overclocked. Check GeodeLink Speed\n");
+          post_code(POST_PLL_MEM_FAIL);
+          hcf();
           } */
 
        /* Use the slowest DIMM */
@@ -163,13 +196,13 @@ static void checkDDRMax(void)
        }
 
        /* Turn SPD ns time into MHZ. Check what the asm does to this math. */
-       speed = 2 * ((10000 / (((spd_byte0 >> 4) * 10) + (spd_byte0 & 0x0F))));
+       speed = 20000 / (((spd_byte0 >> 4) * 10) + (spd_byte0 & 0x0F));
 
        /* current speed > max speed? */
        if (GeodeLinkSpeed() > speed) {
-               print_debug("DIMM overclocked. Check GeodeLink Speed\r\n");
-               POST_CODE(POST_PLL_MEM_FAIL);
-               __asm__ __volatile__("hlt\n");
+               print_emerg("DIMM overclocked. Check GeodeLink Speed\n");
+               post_code(POST_PLL_MEM_FAIL);
+               hcf();
        }
 }
 
@@ -243,15 +276,14 @@ static void setCAS(void)
                spd_byte = spd_read_byte(DIMM0, SPD_SDRAM_CYCLE_TIME_2ND);
                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)));
+                       dimm_speed = 20000 / (((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)));
+                                       dimm_speed = 20000 / (((spd_byte >> 4) * 10) + (spd_byte & 0x0F));
                                        if (dimm_speed >= glspeed) {
                                                casmap_shift = 2; /* -1 is a shift of 2 */
                                        }
@@ -275,14 +307,14 @@ static void setCAS(void)
                spd_byte = spd_read_byte(DIMM1, SPD_SDRAM_CYCLE_TIME_2ND);
                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)));
+                       dimm_speed = 20000 / (((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)));
+                                       dimm_speed = 20000 / (((spd_byte >> 4) * 10) + (spd_byte & 0x0F));
                                        if (dimm_speed >= glspeed) {
                                                casmap_shift = 2; /* -1 is a shift of 2 */
                                        }
@@ -308,9 +340,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");
-               POST_CODE(ERROR_DIFF_DIMMS);
-               __asm__ __volatile__("hlt\n");
+               print_emerg("DIMM CAS Latencies not compatible\n");
+               post_code(ERROR_DIFF_DIMMS);
+               hcf();
        }
 
        msr = rdmsr(MC_CF8F_DATA);
@@ -482,6 +514,8 @@ static void set_extended_mode_registers(void)
        wrmsr(MC_CF07_DATA, msr);
 }
 
+#undef TLA_MEMORY_DEBUG
+#ifdef TLA_MEMORY_DEBUG
 static void EnableMTest(void)
 {
        msr_t msr;
@@ -500,8 +534,9 @@ 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\n");
 }
+#endif
 
 static void sdram_set_registers(const struct mem_controller *ctrl)
 {
@@ -537,43 +572,53 @@ static void sdram_set_spd_registers(const struct mem_controller *ctrl)
 {
        uint8_t spd_byte;
 
-       POST_CODE(POST_MEM_SETUP);      // post_70h
+       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");
-               POST_CODE(ERROR_UNSUPPORTED_DIMM);
-               __asm__ __volatile__("hlt\n");
+               print_emerg("DIMM0 NOT COMPATIBLE\n");
+               post_code(ERROR_UNSUPPORTED_DIMM);
+               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\n");
-               POST_CODE(ERROR_UNSUPPORTED_DIMM);
-               __asm__ __volatile__("hlt\n");
+               print_emerg("DIMM1 NOT COMPATIBLE\n");
+               post_code(ERROR_UNSUPPORTED_DIMM);
+               hcf();
        }
 
-       POST_CODE(POST_MEM_SETUP2);     // post_72h
+       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
+       post_code(POST_MEM_SETUP3);     // post_73h
+       banner("AUTOSIZE DIMM 0");
        auto_size_dimm(DIMM0);
-       POST_CODE(POST_MEM_SETUP4);     // post_74h
+       post_code(POST_MEM_SETUP4);     // post_74h
+       banner("AUTOSIZE DIMM 1");
        auto_size_dimm(DIMM1);
 
        /* Set CAS latency */
-       POST_CODE(POST_MEM_SETUP5);     // post_75h
+       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();
 
@@ -598,18 +643,20 @@ static void sdram_enable(int controllers, const struct mem_controller *ctrl)
 ;* 9) MRS w/ memory config & reset DLL clear
 ;* 8) DDR SDRAM ready for normal operation
 ;********************************************************************/
-       POST_CODE(POST_MEM_ENABLE);     // post_76h
+       post_code(POST_MEM_ENABLE);     // post_76h
 
+#ifdef TLA_MEMORY_DEBUG
        /* Only enable MTest for TLA memory debug */
-       /*EnableMTest(); */
+       EnableMTest();
+#endif
 
        /* If both Page Size = "Not Installed" we have a problems and should halt. */
        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");
-               POST_CODE(ERROR_NO_DIMMS);
-               __asm__ __volatile__("hlt\n");
+               print_emerg("No memory in the system\n");
+               post_code(ERROR_NO_DIMMS);
+               hcf();
        }
 
        /*      Set CKEs */
@@ -717,8 +764,8 @@ 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.\n");
-       POST_CODE(POST_MEM_SETUP_GOOD); //0x7E
+       print_emerg("DRAM controller init done.\n");
+       post_code(POST_MEM_SETUP_GOOD); //0x7E
 
        /* make sure there is nothing stale in the cache */
        /* CAR stack is in the cache __asm__ __volatile__("wbinvd\n"); */
@@ -749,6 +796,6 @@ static void sdram_enable(int controllers, const struct mem_controller *ctrl)
                msr.lo |= 1;
                wrmsr(msrnum, msr);
        }
-       print_debug("RAM DLL lock\n");
+       print_info("RAM DLL lock\n");
 
 }