fix timer choice in Kconfig. HAVE_INIT_TIMER is selected correctly, no need to
[coreboot.git] / src / cpu / intel / model_6ex / 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
24 #include <cpu/x86/mtrr.h>
25 #include <cpu/amd/mtrr.h>
26
27         /* Save the BIST result */
28         movl    %eax, %ebp
29
30 cache_as_ram:
31         post_code(0x20)
32
33         /* Send INIT IPI to all excluding ourself */
34         movl    $0x000C4500, %eax
35         movl    $0xFEE00300, %esi
36         movl    %eax, (%esi)
37
38         /* Zero out all Fixed Range and Variable Range MTRRs */
39         movl    $mtrr_table, %esi
40         movl    $( (mtrr_table_end - mtrr_table) / 2), %edi
41         xorl    %eax, %eax
42         xorl    %edx, %edx
43 clear_mtrrs:
44         movw    (%esi), %bx
45         movzx   %bx, %ecx
46         wrmsr
47         add     $2, %esi
48         dec     %edi
49         jnz     clear_mtrrs
50
51         /* Configure the default memory type to uncacheable */
52         movl    $MTRRdefType_MSR, %ecx
53         rdmsr
54         andl    $(~0x00000cff), %eax
55         wrmsr
56
57         /* Set cache as ram base address */
58         movl    $(MTRRphysBase_MSR(0)), %ecx
59         movl    $(CACHE_AS_RAM_BASE | MTRR_TYPE_WRBACK), %eax
60         xorl    %edx, %edx
61         wrmsr
62
63         /* Set cache as ram mask */
64         movl    $(MTRRphysMask_MSR(0)), %ecx
65         movl    $(~((CACHE_AS_RAM_SIZE-1)) | (1 << 11)), %eax
66         movl    $0x0000000f, %edx
67         wrmsr
68
69         /* Enable MTRR */
70         movl    $MTRRdefType_MSR, %ecx
71         rdmsr
72         orl     $(1 << 11), %eax
73         wrmsr
74
75         /* Enable L2 Cache */
76         movl    $0x11e, %ecx
77         rdmsr
78         orl     $(1 << 8), %eax
79         wrmsr
80
81         /* CR0.CD = 0, CR0.NW = 0 */
82         movl    %cr0, %eax
83         andl    $( ~( (1 << 30) | (1 << 29) ) ), %eax
84         invd
85         movl    %eax, %cr0
86
87         /* Clear the cache memory reagion */
88         movl    $CACHE_AS_RAM_BASE, %esi
89         movl    %esi, %edi
90         movl    $(CACHE_AS_RAM_SIZE / 4), %ecx
91         //movl  $0x23322332, %eax
92         xorl    %eax, %eax
93         rep     stosl
94
95         /* Enable Cache As RAM mode by disabling cache */
96         movl    %cr0, %eax
97         orl     $(1 << 30), %eax
98         movl    %eax, %cr0
99
100 #if defined(CONFIG_XIP_ROM_SIZE) && defined(CONFIG_XIP_ROM_BASE)
101         /* Enable cache for our code in Flash because we do XIP here */
102         movl    $MTRRphysBase_MSR(1), %ecx
103         xorl    %edx, %edx
104 #if defined(CONFIG_TINY_BOOTBLOCK) && CONFIG_TINY_BOOTBLOCK
105 #define REAL_XIP_ROM_BASE AUTO_XIP_ROM_BASE
106 #else
107 #define REAL_XIP_ROM_BASE CONFIG_XIP_ROM_BASE
108 #endif
109         movl    $REAL_XIP_ROM_BASE, %eax
110         orl     $MTRR_TYPE_WRBACK, %eax
111         wrmsr
112
113         movl    $MTRRphysMask_MSR(1), %ecx
114         movl    $0x0000000f, %edx
115         movl    $(~(CONFIG_XIP_ROM_SIZE - 1) | 0x800), %eax
116         wrmsr
117 #endif /* CONFIG_XIP_ROM_SIZE && CONFIG_XIP_ROM_BASE */
118
119         /* enable cache */
120         movl    %cr0, %eax
121         andl    $( ~( (1 << 30) | (1 << 29) ) ), %eax
122         movl    %eax, %cr0
123
124         /* Set up stack pointer */
125 #if defined(CONFIG_USBDEBUG_DIRECT) && (CONFIG_USBDEBUG_DIRECT == 1)
126         /* leave some space for the struct ehci_debug_info */
127         movl    $(CACHE_AS_RAM_BASE + CACHE_AS_RAM_SIZE - 4 - 128), %eax
128 #else
129         movl    $(CACHE_AS_RAM_BASE + CACHE_AS_RAM_SIZE - 4), %eax
130 #endif
131         movl    %eax, %esp
132
133         /* Restore the BIST result */
134         movl    %ebp, %eax
135         movl    %esp, %ebp
136         pushl   %eax
137
138         post_code(0x23)
139
140         /* Call romstage.c main function */
141         call    main
142
143         post_code(0x2f)
144
145         post_code(0x30)
146
147         /* Disable Cache */
148         movl    %cr0, %eax
149         orl    $(1 << 30), %eax
150         movl    %eax, %cr0
151
152         post_code(0x31)
153
154         /* Disable MTRR */
155         movl    $MTRRdefType_MSR, %ecx
156         rdmsr
157         andl    $(~(1 << 11)), %eax
158         wrmsr
159
160         post_code(0x31)
161
162         invd
163 #if 0
164         xorl    %eax, %eax
165         xorl    %edx, %edx
166         movl    $MTRRphysBase_MSR(0), %ecx
167         wrmsr
168         movl    $MTRRphysMask_MSR(0), %ecx
169         wrmsr
170         movl    $MTRRphysBase_MSR(1), %ecx
171         wrmsr
172         movl    $MTRRphysMask_MSR(1), %ecx
173         wrmsr
174 #endif
175
176         post_code(0x33)
177
178 #undef CLEAR_FIRST_1M_RAM
179 #ifdef CLEAR_FIRST_1M_RAM
180         post_code(0x34)
181         /* Enable Write Combining and Speculative Reads for the first 1MB */
182         movl    $MTRRphysBase_MSR(0), %ecx
183         movl    $(0x00000000 | MTRR_TYPE_WRCOMB), %eax
184         xorl    %edx, %edx
185         wrmsr
186         movl    $MTRRphysMask_MSR(0), %ecx
187         movl    $(~(1024*1024 -1) | (1 << 11)), %eax
188         movl    $0x0000000f, %edx       // 36bit address space
189         wrmsr
190         post_code(0x35)
191 #endif
192
193         /* Enable Cache */
194         movl    %cr0, %eax
195         andl    $~( (1 << 30) | (1 << 29) ), %eax
196         movl    %eax, %cr0
197
198
199         post_code(0x36)
200 #ifdef CLEAR_FIRST_1M_RAM
201
202         /* Clear first 1MB of RAM */
203         movl    $0x00000000, %edi
204         cld
205         xorl    %eax, %eax
206         movl    $((1024*1024) / 4), %ecx
207         rep stosl
208         
209         post_code(0x37)
210 #endif
211
212         /* Disable Cache */
213         movl    %cr0, %eax
214         orl    $(1 << 30), %eax
215         movl    %eax, %cr0
216
217         post_code(0x38)
218
219         /* Enable Write Back and Speculative Reads for the first 1MB */
220         movl    $MTRRphysBase_MSR(0), %ecx
221         movl    $(0x00000000 | MTRR_TYPE_WRBACK), %eax
222         xorl    %edx, %edx
223         wrmsr
224         movl    $MTRRphysMask_MSR(0), %ecx
225         movl    $(~(1024*1024 -1) | (1 << 11)), %eax
226         movl    $0x0000000f, %edx       // 36bit address space
227         wrmsr
228
229         post_code(0x39)
230
231         /* And Enable Cache again after setting MTRRs */
232         movl    %cr0, %eax
233         andl    $~( (1 << 30) | (1 << 29) ), %eax
234         movl    %eax, %cr0
235
236         post_code(0x3a)
237
238         /* Enable MTRR */
239         movl    $MTRRdefType_MSR, %ecx
240         rdmsr
241         orl     $(1 << 11), %eax
242         wrmsr
243
244         post_code(0x3b)
245
246         /* Invalidate the cache again */
247         invd
248
249         post_code(0x3c)
250
251         /* clear boot_complete flag */
252         xorl    %ebp, %ebp
253 __main:
254         post_code(0x11)
255         cld                     /* clear direction flag */
256         
257         movl    %ebp, %esi
258
259         /* For now: use CONFIG_RAMBASE + 1MB - 64K (counting downwards) as stack. This
260          * makes sure that we stay completely within the 1M-64K of memory that we
261          * preserve for suspend/resume.
262          */
263
264 #ifndef HIGH_MEMORY_SAVE
265 #warning Need a central place for HIGH_MEMORY_SAVE
266 #define HIGH_MEMORY_SAVE ( (1024 - 64) * 1024 )
267 #endif
268         movl $(CONFIG_RAMBASE + HIGH_MEMORY_SAVE), %esp
269         movl    %esp, %ebp
270         pushl %esi
271         call copy_and_run
272
273 .Lhlt:  
274         post_code(0xee)
275         hlt
276         jmp     .Lhlt
277
278 mtrr_table:
279         /* Fixed MTRRs */
280         .word 0x250, 0x258, 0x259
281         .word 0x268, 0x269, 0x26A
282         .word 0x26B, 0x26C, 0x26D
283         .word 0x26E, 0x26F
284         /* Variable MTRRs */
285         .word 0x200, 0x201, 0x202, 0x203
286         .word 0x204, 0x205, 0x206, 0x207
287         .word 0x208, 0x209, 0x20A, 0x20B
288         .word 0x20C, 0x20D, 0x20E, 0x20F
289 mtrr_table_end:
290