cpu/intel (non-FSP): Use microcode from blobs repository
[coreboot.git] / src / cpu / intel / model_6ex / cache_as_ram.inc
blob09b8e93ce500b1864d9a245fbfe83cdd33475ea0
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  */
21 #include <cpu/x86/mtrr.h>
22 #include <cpu/x86/cache.h>
23 #include <cpu/x86/post_code.h>
25 #define CPU_PHYSMASK_HI  (1 << (CONFIG_CPU_ADDR_BITS - 32) - 1)
27 #define CACHE_AS_RAM_SIZE CONFIG_DCACHE_RAM_SIZE
28 #define CACHE_AS_RAM_BASE CONFIG_DCACHE_RAM_BASE
30         /* Save the BIST result. */
31         movl    %eax, %ebp
33 cache_as_ram:
34         post_code(0x20)
36         /* Send INIT IPI to all excluding ourself. */
37         movl    $0x000C4500, %eax
38         movl    $0xFEE00300, %esi
39         movl    %eax, (%esi)
41         /* Zero out all fixed range and variable range MTRRs. */
42         movl    $mtrr_table, %esi
43         movl    $((mtrr_table_end - mtrr_table) / 2), %edi
44         xorl    %eax, %eax
45         xorl    %edx, %edx
46 clear_mtrrs:
47         movw    (%esi), %bx
48         movzx   %bx, %ecx
49         wrmsr
50         add     $2, %esi
51         dec     %edi
52         jnz     clear_mtrrs
54         /* Configure the default memory type to uncacheable. */
55         movl    $MTRRdefType_MSR, %ecx
56         rdmsr
57         andl    $(~0x00000cff), %eax
58         wrmsr
60         /* Set Cache-as-RAM base address. */
61         movl    $(MTRRphysBase_MSR(0)), %ecx
62         movl    $(CACHE_AS_RAM_BASE | MTRR_TYPE_WRBACK), %eax
63         xorl    %edx, %edx
64         wrmsr
66         /* Set Cache-as-RAM mask. */
67         movl    $(MTRRphysMask_MSR(0)), %ecx
68         movl    $(~(CACHE_AS_RAM_SIZE - 1) | MTRRphysMaskValid), %eax
69         movl    $CPU_PHYSMASK_HI, %edx
70         wrmsr
72         /* Enable MTRR. */
73         movl    $MTRRdefType_MSR, %ecx
74         rdmsr
75         orl     $MTRRdefTypeEn, %eax
76         wrmsr
78         /* Enable L2 cache. */
79         movl    $0x11e, %ecx
80         rdmsr
81         orl     $(1 << 8), %eax
82         wrmsr
84         /* Enable cache (CR0.CD = 0, CR0.NW = 0). */
85         movl    %cr0, %eax
86         andl    $(~(CR0_CacheDisable | CR0_NoWriteThrough)), %eax
87         invd
88         movl    %eax, %cr0
90         /* Clear the cache memory reagion. */
91         movl    $CACHE_AS_RAM_BASE, %esi
92         movl    %esi, %edi
93         movl    $(CACHE_AS_RAM_SIZE / 4), %ecx
94         // movl $0x23322332, %eax
95         xorl    %eax, %eax
96         rep     stosl
98         /* Enable Cache-as-RAM mode by disabling cache. */
99         movl    %cr0, %eax
100         orl     $CR0_CacheDisable, %eax
101         movl    %eax, %cr0
103 #if CONFIG_XIP_ROM_SIZE
104         /* Enable cache for our code in Flash because we do XIP here */
105         movl    $MTRRphysBase_MSR(1), %ecx
106         xorl    %edx, %edx
107         /*
108          * IMPORTANT: The following calculation _must_ be done at runtime. See
109          * http://www.coreboot.org/pipermail/coreboot/2010-October/060855.html
110          */
111         movl    $copy_and_run, %eax
112         andl    $(~(CONFIG_XIP_ROM_SIZE - 1)), %eax
113         orl     $MTRR_TYPE_WRBACK, %eax
114         wrmsr
116         movl    $MTRRphysMask_MSR(1), %ecx
117         movl    $CPU_PHYSMASK_HI, %edx
118         movl    $(~(CONFIG_XIP_ROM_SIZE - 1) | MTRRphysMaskValid), %eax
119         wrmsr
120 #endif /* CONFIG_XIP_ROM_SIZE */
122         /* Enable cache. */
123         movl    %cr0, %eax
124         andl    $(~(CR0_CacheDisable | CR0_NoWriteThrough)), %eax
125         movl    %eax, %cr0
127         /* Set up the stack pointer. */
128         movl    $(CACHE_AS_RAM_BASE + CACHE_AS_RAM_SIZE - 4), %eax
129         movl    %eax, %esp
131         /* Restore the BIST result. */
132         movl    %ebp, %eax
133         movl    %esp, %ebp
134         pushl   %eax
136         post_code(0x23)
138         /* Call romstage.c main function. */
139         call    main
141         post_code(0x2f)
143         post_code(0x30)
145         /* Disable cache. */
146         movl    %cr0, %eax
147         orl     $CR0_CacheDisable, %eax
148         movl    %eax, %cr0
150         post_code(0x31)
152         /* Disable MTRR. */
153         movl    $MTRRdefType_MSR, %ecx
154         rdmsr
155         andl    $(~MTRRdefTypeEn), %eax
156         wrmsr
158         post_code(0x31)
160         invd
162         post_code(0x33)
164         /* Enable cache. */
165         movl    %cr0, %eax
166         andl    $~(CR0_CacheDisable | CR0_NoWriteThrough), %eax
167         movl    %eax, %cr0
169         post_code(0x36)
171         /* Disable cache. */
172         movl    %cr0, %eax
173         orl     $CR0_CacheDisable, %eax
174         movl    %eax, %cr0
176         post_code(0x38)
178         /* Enable Write Back and Speculative Reads for low RAM. */
179         movl    $MTRRphysBase_MSR(0), %ecx
180         movl    $(0x00000000 | MTRR_TYPE_WRBACK), %eax
181         xorl    %edx, %edx
182         wrmsr
183         movl    $MTRRphysMask_MSR(0), %ecx
184         movl    $(~(CONFIG_RAMTOP - 1) | MTRRphysMaskValid), %eax
185         movl    $CPU_PHYSMASK_HI, %edx
186         wrmsr
188 #if CACHE_ROM_SIZE
189         /* Enable caching and Speculative Reads for Flash ROM device. */
190         movl    $MTRRphysBase_MSR(1), %ecx
191         movl    $(CACHE_ROM_BASE | MTRR_TYPE_WRPROT), %eax
192         xorl    %edx, %edx
193         wrmsr
194         movl    $MTRRphysMask_MSR(1), %ecx
195         movl    $(~(CACHE_ROM_SIZE - 1) | MTRRphysMaskValid), %eax
196         movl    $CPU_PHYSMASK_HI, %edx
197         wrmsr
198 #endif
200         post_code(0x39)
202         /* And enable cache again after setting MTRRs. */
203         movl    %cr0, %eax
204         andl    $~(CR0_CacheDisable | CR0_NoWriteThrough), %eax
205         movl    %eax, %cr0
207         post_code(0x3a)
209         /* Enable MTRR. */
210         movl    $MTRRdefType_MSR, %ecx
211         rdmsr
212         orl     $MTRRdefTypeEn, %eax
213         wrmsr
215         post_code(0x3b)
217         /* Invalidate the cache again. */
218         invd
220         post_code(0x3c)
222 __main:
223         post_code(POST_PREPARE_RAMSTAGE)
224         cld                     /* Clear direction flag. */
226         movl    $CONFIG_RAMTOP, %esp
227         movl    %esp, %ebp
228         call    copy_and_run
230 .Lhlt:
231         post_code(POST_DEAD_CODE)
232         hlt
233         jmp     .Lhlt
235 mtrr_table:
236         /* Fixed MTRRs */
237         .word 0x250, 0x258, 0x259
238         .word 0x268, 0x269, 0x26A
239         .word 0x26B, 0x26C, 0x26D
240         .word 0x26E, 0x26F
241         /* Variable MTRRs */
242         .word 0x200, 0x201, 0x202, 0x203
243         .word 0x204, 0x205, 0x206, 0x207
244         .word 0x208, 0x209, 0x20A, 0x20B
245         .word 0x20C, 0x20D, 0x20E, 0x20F
246 mtrr_table_end: