trivial: add note that VSA blob belongs into CBFS.
[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_PRINTK_IN_CAR
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 /* Disable Erratum 343 Workaround, see RevGuide for Fam10h, Pub#41322 Rev 3.33 */
27
28 static void vErrata343(void)
29 {
30 #ifdef BU_CFG2_MSR
31     msr_t msr;
32     unsigned int uiMask = 0xFFFFFFF7;
33
34     msr = rdmsr(BU_CFG2_MSR);
35     msr.hi &= uiMask; // set bit 35 to 0
36     wrmsr(BU_CFG2_MSR, msr);
37 #endif
38 }
39
40 static void post_cache_as_ram(void)
41 {
42
43 #if 1
44         {
45         /* Check value of esp to verify if we have enough rom for stack in Cache as RAM */
46         unsigned v_esp;
47         __asm__ volatile (
48                 "movl   %%esp, %0\n\t"
49                 : "=a" (v_esp)
50         );
51         print_debug_pcar("v_esp=", v_esp);
52         }
53 #endif
54
55         unsigned testx = 0x5a5a5a5a;
56         print_debug_pcar("testx = ", testx);
57
58         /* copy data from cache as ram to 
59                 ram need to set CONFIG_RAMTOP to 2M and use var mtrr instead.
60          */
61 #if CONFIG_RAMTOP <= 0x100000
62         #error "You need to set CONFIG_RAMTOP greater than 1M"
63 #endif
64         
65         set_init_ram_access(); /* So we can access RAM from [1M, CONFIG_RAMTOP) */
66
67 //      dump_mem(CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE-0x8000, CONFIG_DCACHE_RAM_BASE+CONFIG_DCACHE_RAM_SIZE-0x7c00);
68         print_debug("Copying data from cache to RAM -- switching to use RAM as stack... ");
69
70         /* from here don't store more data in CAR */
71         vErrata343();
72
73 #if 0
74         __asm__ volatile (
75                 "pushl  %eax\n\t"
76         );
77 #endif
78
79         memcopy((void *)((CONFIG_RAMTOP)-CONFIG_DCACHE_RAM_SIZE), (void *)CONFIG_DCACHE_RAM_BASE, CONFIG_DCACHE_RAM_SIZE); //inline
80 //        dump_mem((CONFIG_RAMTOP) - 0x8000, (CONFIG_RAMTOP) - 0x7c00);
81
82         __asm__ volatile (
83                 /* set new esp */ /* before CONFIG_RAMBASE */
84                 "subl   %0, %%ebp\n\t"
85                 "subl   %0, %%esp\n\t"
86                 ::"a"( (CONFIG_DCACHE_RAM_BASE + CONFIG_DCACHE_RAM_SIZE)- (CONFIG_RAMTOP) )
87         ); // We need to push %eax to the stack (CAR) before copy stack and pop it later after copy stack and change esp
88 #if 0
89         __asm__ volatile (
90                 "popl   %eax\n\t"
91         );
92 #endif
93
94
95         /* We can put data to stack again */
96
97         /* only global variable sysinfo in cache need to be offset */
98         print_debug("Done\r\n");
99         print_debug_pcar("testx = ", testx);
100
101         print_debug("Disabling cache as ram now \r\n");
102         disable_cache_as_ram_bsp();  
103
104         print_debug("Clearing initial memory region: ");
105         clear_init_ram(); //except the range from [(CONFIG_RAMTOP) - CONFIG_DCACHE_RAM_SIZE, (CONFIG_RAMTOP))
106         print_debug("Done\r\n");
107
108 //      dump_mem((CONFIG_RAMTOP) - 0x8000, (CONFIG_RAMTOP) - 0x7c00);
109
110 #ifndef CONFIG_MEM_TRAIN_SEQ
111 #define CONFIG_MEM_TRAIN_SEQ 0
112 #endif
113         set_sysinfo_in_ram(1); // So other core0 could start to train mem
114
115 #if CONFIG_MEM_TRAIN_SEQ == 1
116 //      struct sys_info *sysinfox = ((CONFIG_RAMTOP) - CONFIG_DCACHE_RAM_GLOBAL_VAR_SIZE);
117
118         // wait for ap memory to trained
119 //        wait_all_core0_mem_trained(sysinfox); // moved to lapic_init_cpus.c
120 #endif
121         /*copy and execute coreboot_ram */
122         copy_and_run();
123         /* We will not return */
124
125         print_debug("should not be here -\r\n");
126
127 }
128