printk_foo -> printk(BIOS_FOO, ...)
[coreboot.git] / src / cpu / amd / car / post_cache_as_ram.c
index 5b3737123a5c008f2104d2fb84f1e69af7e723a8..939990997cea7953acc25490fbbf481a32d00183 100644 (file)
@@ -1,23 +1,27 @@
-/* 2005.6 by yhlu 
+/* 2005.6 by yhlu
  * 2006.3 yhlu add copy data from CAR to ram
  */
 #include "cpu/amd/car/disable_cache_as_ram.c"
 
-#include "cpu/amd/car/clear_init_ram.c"
-
 static inline void print_debug_pcar(const char *strval, uint32_t val)
 {
-        printk_debug("%s%08x\r\n", strval, val);
+       printk(BIOS_DEBUG, "%s%08x\r\n", strval, val);
 }
 
+/* from linux kernel 2.6.32 asm/string_32.h */
+
 static void inline __attribute__((always_inline))  memcopy(void *dest, const void *src, unsigned long bytes)
 {
-        __asm__ volatile(
-                "cld\n\t"
-                "rep; movsl\n\t"
-                : /* No outputs */
-                : "S" (src), "D" (dest), "c" ((bytes)>>2)
-                );
+       int d0, d1, d2;
+       asm volatile("cld ; rep ; movsl\n\t"
+                       "movl %4,%%ecx\n\t"
+                       "andl $3,%%ecx\n\t"
+                       "jz 1f\n\t"
+                       "rep ; movsb\n\t"
+                       "1:"
+                       : "=&c" (d0), "=&D" (d1), "=&S" (d2)
+                       : "0" (bytes / 4), "g" (bytes), "1" ((long)dest), "2" ((long)src)
+                       : "memory", "cc");
 }
 /* Disable Erratum 343 Workaround, see RevGuide for Fam10h, Pub#41322 Rev 3.33 */
 
@@ -37,28 +41,29 @@ static void post_cache_as_ram(void)
 {
 
 #if 1
-        {
-        /* Check value of esp to verify if we have enough rom for stack in Cache as RAM */
-        unsigned v_esp;
-        __asm__ volatile (
-                "movl   %%esp, %0\n\t"
-                : "=a" (v_esp)
-        );
-        print_debug_pcar("v_esp=", v_esp);
-        }
+       {
+       /* Check value of esp to verify if we have enough rom for stack in Cache as RAM */
+       unsigned v_esp;
+       __asm__ volatile (
+               "movl   %%esp, %0\n\t"
+               : "=a" (v_esp)
+       );
+       print_debug_pcar("v_esp=", v_esp);
+       }
 #endif
 
        unsigned testx = 0x5a5a5a5a;
        print_debug_pcar("testx = ", testx);
 
-       /* copy data from cache as ram to 
+       /* copy data from cache as ram to
                ram need to set CONFIG_RAMTOP to 2M and use var mtrr instead.
         */
 #if CONFIG_RAMTOP <= 0x100000
-        #error "You need to set CONFIG_RAMTOP greater than 1M"
+       #error "You need to set CONFIG_RAMTOP greater than 1M"
 #endif
-       
-       set_init_ram_access(); /* So we can access RAM from [1M, CONFIG_RAMTOP) */
+
+       /* So we can access RAM from [1M, CONFIG_RAMTOP) */
+       set_var_mtrr(0, 0x00000000, CONFIG_RAMTOP, MTRR_TYPE_WRBACK);
 
 //     dump_mem(CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE-0x8000, CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE-0x7c00);
        print_debug("Copying data from cache to RAM -- switching to use RAM as stack... ");
@@ -66,56 +71,49 @@ static void post_cache_as_ram(void)
        /* from here don't store more data in CAR */
        vErrata343();
 
-#if 0
-        __asm__ volatile (
-               "pushl  %eax\n\t"
-        );
-#endif
-
-        memcopy((void *)((CONFIG_RAMTOP)-CONFIG_DCACHE_RAM_SIZE), (void *)CONFIG_DCACHE_RAM_BASE, CONFIG_DCACHE_RAM_SIZE); //inline
-//        dump_mem((CONFIG_RAMTOP) - 0x8000, (CONFIG_RAMTOP) - 0x7c00);
-
-        __asm__ volatile (
-                /* set new esp */ /* before CONFIG_RAMBASE */
-                "subl   %0, %%ebp\n\t"
-                "subl   %0, %%esp\n\t"
-                ::"a"( (CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE)- (CONFIG_RAMTOP) )
-        ); // We need to push %eax to the stack (CAR) before copy stack and pop it later after copy stack and change esp
-#if 0
-        __asm__ volatile (
-               "popl   %eax\n\t"
-        );
-#endif
+       memcopy((void *)((CONFIG_RAMTOP)-CONFIG_DCACHE_RAM_SIZE), (void *)CONFIG_DCACHE_RAM_BASE, CONFIG_DCACHE_RAM_SIZE); //inline
+//     dump_mem((CONFIG_RAMTOP) - 0x8000, (CONFIG_RAMTOP) - 0x7c00);
 
+       __asm__ volatile (
+               /* set new esp */ /* before CONFIG_RAMBASE */
+               "subl   %0, %%esp\n\t"
+               ::"a"( (CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE)- (CONFIG_RAMTOP) )
+               /* discard all registers (eax is used for %0), so gcc redo everything
+                  after the stack is moved */
+               : "cc", "memory", "%ebx", "%ecx", "%edx", "%esi", "%edi", "%ebp"
+       );
 
        /* We can put data to stack again */
 
-        /* only global variable sysinfo in cache need to be offset */
-        print_debug("Done\r\n");
-        print_debug_pcar("testx = ", testx);
+       /* only global variable sysinfo in cache need to be offset */
+       print_debug("Done\r\n");
+       print_debug_pcar("testx = ", testx);
 
        print_debug("Disabling cache as ram now \r\n");
-       disable_cache_as_ram_bsp();  
-
-        print_debug("Clearing initial memory region: ");
-        clear_init_ram(); //except the range from [(CONFIG_RAMTOP) - CONFIG_DCACHE_RAM_SIZE, (CONFIG_RAMTOP))
-        print_debug("Done\r\n");
+       disable_cache_as_ram_bsp();
+
+       print_debug("Clearing initial memory region: ");
+#if CONFIG_HAVE_ACPI_RESUME == 1
+       /* clear only coreboot used region of memory. Note: this may break ECC enabled boards */
+       memset((void*) CONFIG_RAMBASE, 0, (CONFIG_RAMTOP) - CONFIG_RAMBASE - CONFIG_DCACHE_RAM_SIZE);
+#else
+       memset((void*)0, 0, ((CONFIG_RAMTOP) - CONFIG_DCACHE_RAM_SIZE));
+#endif
+       print_debug("Done\r\n");
 
 //     dump_mem((CONFIG_RAMTOP) - 0x8000, (CONFIG_RAMTOP) - 0x7c00);
 
-        set_sysinfo_in_ram(1); // So other core0 could start to train mem
+       set_sysinfo_in_ram(1); // So other core0 could start to train mem
 
 #if CONFIG_MEM_TRAIN_SEQ == 1
 //     struct sys_info *sysinfox = ((CONFIG_RAMTOP) - CONFIG_DCACHE_RAM_GLOBAL_VAR_SIZE);
 
-        // wait for ap memory to trained
-//        wait_all_core0_mem_trained(sysinfox); // moved to lapic_init_cpus.c
+       // wait for ap memory to trained
+//     wait_all_core0_mem_trained(sysinfox); // moved to lapic_init_cpus.c
 #endif
-        /*copy and execute coreboot_ram */
-        copy_and_run();
-        /* We will not return */
-
-        print_debug("should not be here -\r\n");
+       /*copy and execute coreboot_ram */
+       copy_and_run();
+       /* We will not return */
 
+       print_debug("should not be here -\r\n");
 }
-