a216aa3295fcd0c10bab19af99335238beb22d22
[coreboot.git] / src / cpu / intel / model_106cx / cache_as_ram.inc
1 /* 
2  * This file is part of the coreboot project.
3  * 
4  * Copyright (C) 2000,2007 Ronald G. Minnich <rminnich@gmail.com>
5  * Copyright (C) 2007-2008 coresystems GmbH
6  * 
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; version 2 of the License.
10  * 
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
19  */
20
21 #define CACHE_AS_RAM_SIZE CONFIG_DCACHE_RAM_SIZE
22 #define CACHE_AS_RAM_BASE CONFIG_DCACHE_RAM_BASE
23 #define post_code(x) intel_chip_post_macro(x)
24
25 #include <cpu/x86/mtrr.h>
26 #include <cpu/amd/mtrr.h>
27
28         /* Save the BIST result */
29         movl    %eax, %ebp
30
31 cache_as_ram:
32 #if CONFIG_USE_FALLBACK_IMAGE == 1
33
34         post_code(0x20)
35
36         /* Send INIT IPI to all excluding ourself */
37         movl    $0x000C4500, %eax
38         movl    $0xFEE00300, %esi
39         movl    %eax, (%esi)
40
41         post_code(0x21)
42
43         /* Zero out all Fixed Range and Variable Range MTRRs */
44         movl    $mtrr_table, %esi
45         movl    $( (mtrr_table_end - mtrr_table) / 2), %edi
46         xorl    %eax, %eax
47         xorl    %edx, %edx
48 clear_mtrrs:
49         movw    (%esi), %bx
50         movzx   %bx, %ecx
51         wrmsr
52         add     $2, %esi
53         dec     %edi
54         jnz     clear_mtrrs
55         post_code(0x22)
56
57         /* Configure the default memory type to uncacheable */
58         movl    $MTRRdefType_MSR, %ecx
59         rdmsr
60         andl    $(~0x00000cff), %eax
61         wrmsr
62
63         post_code(0x23)
64         /* Set cache as ram base address */
65         movl    $(MTRRphysBase_MSR(0)), %ecx
66         movl    $(CACHE_AS_RAM_BASE | MTRR_TYPE_WRBACK), %eax
67         xorl    %edx, %edx
68         wrmsr
69
70         post_code(0x24)
71         /* Set cache as ram mask */
72         movl    $(MTRRphysMask_MSR(0)), %ecx
73         movl    $(~((CACHE_AS_RAM_SIZE-1)) | (1 << 11)), %eax
74         movl    $0x00000000, %edx
75         wrmsr
76
77         post_code(0x25)
78         /* Enable MTRR */
79         movl    $MTRRdefType_MSR, %ecx
80         rdmsr
81         orl     $(1 << 11), %eax
82         wrmsr
83
84         post_code(0x26)
85         /* Enable L2 Cache */
86         movl    $0x11e, %ecx
87         rdmsr
88         orl     $(1 << 8), %eax
89         wrmsr
90
91         post_code(0x27)
92         /* CR0.CD = 0, CR0.NW = 0 */
93         movl    %cr0, %eax
94         andl    $( ~( (1 << 30) | (1 << 29) ) ), %eax
95         invd
96         movl    %eax, %cr0
97
98         post_code(0x28)
99         /* Clear the cache memory reagion */
100         movl    $CACHE_AS_RAM_BASE, %esi
101         movl    %esi, %edi
102         movl    $(CACHE_AS_RAM_SIZE / 4), %ecx
103         //movl  $0x23322332, %eax
104         xorl    %eax, %eax
105         rep     stosl
106
107         post_code(0x29)
108         /* Enable Cache As RAM mode by disabling cache */
109         movl    %cr0, %eax
110         orl     $(1 << 30), %eax
111         movl    %eax, %cr0
112
113 #if defined(CONFIG_XIP_ROM_SIZE) && defined(CONFIG_XIP_ROM_BASE)
114         /* Enable cache for our code in Flash because we do XIP here */
115         movl    $MTRRphysBase_MSR(1), %ecx
116         xorl    %edx, %edx
117         movl    $(CONFIG_XIP_ROM_BASE | MTRR_TYPE_WRBACK), %eax
118         wrmsr
119
120         movl    $MTRRphysMask_MSR(1), %ecx
121         movl    $0x00000000, %edx
122         movl    $(~(CONFIG_XIP_ROM_SIZE - 1) | 0x800), %eax
123         wrmsr
124 #endif /* CONFIG_XIP_ROM_SIZE && CONFIG_XIP_ROM_BASE */
125
126         post_code(0x2a)
127         /* enable cache */
128         movl    %cr0, %eax
129         andl    $( ~( (1 << 30) | (1 << 29) ) ), %eax
130         movl    %eax, %cr0
131 #endif
132
133         /* Set up stack pointer */
134 #if defined(CONFIG_USBDEBUG_DIRECT) && (CONFIG_USBDEBUG_DIRECT == 1)
135         /* leave some space for the struct ehci_debug_info */
136         movl    $(CACHE_AS_RAM_BASE + CACHE_AS_RAM_SIZE - 4 - 128), %eax
137 #else
138         movl    $(CACHE_AS_RAM_BASE + CACHE_AS_RAM_SIZE - 4), %eax
139 #endif
140         movl    %eax, %esp
141
142         /* Restore the BIST result */
143         movl    %ebp, %eax
144         movl    %esp, %ebp
145         pushl   %eax
146
147         post_code(0x23)
148
149         call    stage1_main
150
151         post_code(0x2f)
152 error:
153         hlt
154         jmp     error
155
156 mtrr_table:
157         /* Fixed MTRRs */
158         .word 0x250, 0x258, 0x259
159         .word 0x268, 0x269, 0x26A
160         .word 0x26B, 0x26C, 0x26D
161         .word 0x26E, 0x26F
162         /* Variable MTRRs */
163         .word 0x200, 0x201, 0x202, 0x203
164         .word 0x204, 0x205, 0x206, 0x207
165         .word 0x208, 0x209, 0x20A, 0x20B
166         .word 0x20C, 0x20D, 0x20E, 0x20F
167 mtrr_table_end:
168