AMD Rev F support
[coreboot.git] / src / cpu / amd / car / post_cache_as_ram.c
1 /* 2005.6 by yhlu 
2  * 2006.3 yhlu add copy data from CAR to ram
3  */
4 #include "cpu/amd/car/disable_cache_as_ram.c"
5
6 #include "cpu/amd/car/clear_init_ram.c"
7
8 static inline void print_debug_pcar(const char *strval, uint32_t val)
9 {
10 #if CONFIG_USE_INIT
11         printk_debug("%s%08x\r\n", strval, val);
12 #else
13         print_debug(strval); print_debug_hex32(val); print_debug("\r\n");
14 #endif
15 }
16
17 static void inline __attribute__((always_inline))  memcopy(void *dest, const void *src, unsigned long bytes)
18 {
19         __asm__ volatile(
20                 "cld\n\t"
21                 "rep; movsl\n\t"
22                 : /* No outputs */
23                 : "S" (src), "D" (dest), "c" ((bytes)>>2)
24                 );
25 }
26
27
28 static void post_cache_as_ram(void)
29 {
30
31 #if 1
32         {
33         /* Check value of esp to verify if we have enough rom for stack in Cache as RAM */
34         unsigned v_esp;
35         __asm__ volatile (
36                 "movl   %%esp, %0\n\t"
37                 : "=a" (v_esp)
38         );
39         print_debug_pcar("v_esp=", v_esp);
40         }
41 #endif
42
43         unsigned testx = 0x5a5a5a5a;
44         print_debug_pcar("testx = ", testx);
45
46         /* copy data from cache as ram to 
47                 ram need to set CONFIG_LB_MEM_TOPK to 2048 and use var mtrr instead.
48          */
49 #if CONFIG_LB_MEM_TOPK <= 1024
50         #error "You need to set CONFIG_LB_MEM_TOPK greater than 1024"
51 #endif
52         
53         set_init_ram_access(); /* So we can access RAM from [1M, CONFIG_LB_MEM_TOPK) */
54
55 //      dump_mem(DCACHE_RAM_BASE+DCACHE_RAM_SIZE-0x8000, DCACHE_RAM_BASE+DCACHE_RAM_SIZE-0x7c00);
56         print_debug("Copying data from cache to ram -- switching to use ram as stack... ");
57
58         /* from here don't store more data in CAR */
59 #if 0
60         __asm__ volatile (
61                 "pushl  %eax\n\t"
62         );
63 #endif
64
65         memcopy((void *)((CONFIG_LB_MEM_TOPK<<10)-DCACHE_RAM_SIZE), (void *)DCACHE_RAM_BASE, DCACHE_RAM_SIZE); //inline
66 //        dump_mem((CONFIG_LB_MEM_TOPK<<10) - 0x8000, (CONFIG_LB_MEM_TOPK<<10) - 0x7c00);
67
68         __asm__ volatile (
69                 /* set new esp */ /* before _RAMBASE */
70                 "subl   %0, %%ebp\n\t"
71                 "subl   %0, %%esp\n\t"
72                 ::"a"( (DCACHE_RAM_BASE + DCACHE_RAM_SIZE)- (CONFIG_LB_MEM_TOPK<<10) )
73         ); // We need to push %eax to the stack (CAR) before copy stack and pop it later after copy stack and change esp
74 #if 0
75         __asm__ volatile (
76                 "popl   %eax\n\t"
77         );
78 #endif
79
80
81         /* We can put data to stack again */
82
83         /* only global variable sysinfo in cache need to be offset */
84         print_debug("Done\r\n");
85         print_debug_pcar("testx = ", testx);
86
87         print_debug("Disabling cache as ram now \r\n");
88         disable_cache_as_ram_bsp();  
89
90         print_debug("Clearing initial memory region: ");
91         clear_init_ram(); //except the range from [(CONFIG_LB_MEM_TOPK<<10) - DCACHE_RAM_SIZE, (CONFIG_LB_MEM_TOPK<<10))
92         print_debug("Done\r\n");
93
94 //      dump_mem((CONFIG_LB_MEM_TOPK<<10) - 0x8000, (CONFIG_LB_MEM_TOPK<<10) - 0x7c00);
95
96 #ifndef MEM_TRAIN_SEQ
97 #define MEM_TRAIN_SEQ 0
98 #endif
99         set_sysinfo_in_ram(1); // So other core0 could start to train mem
100
101 #if MEM_TRAIN_SEQ == 1
102 //      struct sys_info *sysinfox = ((CONFIG_LB_MEM_TOPK<<10) - DCACHE_RAM_GLOBAL_VAR_SIZE);
103
104         // wait for ap memory to trained
105 //        wait_all_core0_mem_trained(sysinfox); // moved to lapic_init_cpus.c
106 #endif
107         /*copy and execute linuxbios_ram */
108         copy_and_run();
109         /* We will not return */
110
111         print_debug("should not be here -\r\n");
112
113 }
114