3bd4046649929ef1280550c237db92e618212681
[coreboot.git] / src / cpu / via / car / 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) 2005 Eswar Nallusamy, LANL
6  * Copyright (C) 2005 Tyan
7  * (Written by Yinghai Lu <yhlu@tyan.com> for Tyan)
8  * Copyright (C) 2007 coresystems GmbH
9  * (Written by Stefan Reinauer <stepan@coresystems.de> for coresystems GmbH)
10  * Copyright (C) 2007,2008 Carl-Daniel Hailfinger
11  * Copyright (C) 2008 VIA Technologies, Inc.
12  * (Written by Jason Zhao <jasonzhao@viatech.com.cn> for VIA)
13  * 
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; version 2 of the License.
17  * 
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  * 
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
26  */
27
28 #define CacheSize DCACHE_RAM_SIZE
29 #define CacheBase DCACHE_RAM_BASE
30
31
32 #include        <cpu/x86/mtrr.h>
33
34         /* Save the BIST result */
35         movl    %eax, %ebp
36
37 CacheAsRam:
38
39         /* disable cache */
40         movl    %cr0, %eax
41         orl    $(0x1<<30),%eax
42         movl    %eax,%cr0
43         invd
44
45         /* Set the default memory type and enable fixed and variable MTRRs */
46         movl    $MTRRdefType_MSR, %ecx
47         xorl    %edx, %edx
48         /* Enable Variable and Fixed MTRRs */
49         movl    $0x00000c00, %eax
50         wrmsr
51
52         /* Clear all MTRRs */
53         xorl    %edx, %edx
54         movl    $fixed_mtrr_msr, %esi
55 clear_fixed_var_mtrr:
56         lodsl   (%esi), %eax
57         testl   %eax, %eax
58         jz      clear_fixed_var_mtrr_out
59
60         movl    %eax, %ecx
61         xorl    %eax, %eax
62         wrmsr
63
64         jmp     clear_fixed_var_mtrr
65 clear_fixed_var_mtrr_out:
66         /* MTRRPhysBase */
67         movl    $0x200, %ecx
68         xorl    %edx, %edx
69         movl    $(CacheBase|MTRR_TYPE_WRBACK),%eax
70         wrmsr
71
72         /* MTRRPhysMask */
73         movl    $0x201, %ecx
74         /* This assumes we never access addresses above 2^36 in CAR. */
75         movl    $0x0000000f,%edx
76         movl    $(~(CacheSize-1)|0x800),%eax
77         wrmsr
78
79         /* enable write base caching so we can do execute in place
80          * on the flash rom.
81          */
82         /* MTRRPhysBase */
83         movl    $0x202, %ecx
84         xorl    %edx, %edx
85         movl    $(XIP_ROM_BASE|MTRR_TYPE_WRBACK),%eax
86         wrmsr
87
88         /* MTRRPhysMask */
89         movl    $0x203, %ecx
90         movl    $0x0000000f,%edx
91         movl    $(~(XIP_ROM_SIZE - 1) | 0x800), %eax
92         wrmsr
93
94
95         movl    $MTRRdefType_MSR, %ecx
96         xorl    %edx, %edx
97         /* Enable Variable and Fixed MTRRs */
98         movl    $0x00000800, %eax
99         wrmsr
100
101         movl    %cr0, %eax
102         andl    $0x9fffffff,%eax
103         movl    %eax, %cr0
104
105         /* Read the range with lodsl*/
106         cld
107         movl    $CacheBase, %esi
108         movl    %esi, %edi
109         movl    $(CacheSize>>2), %ecx
110         rep     lodsl
111
112         movl    $CacheBase, %esi
113         movl    %esi, %edi
114         movl    $(CacheSize>>2), %ecx
115
116         /* 0x5c5c5c5c is a memory test pattern.
117          * TODO: Check if everything works with the zero pattern as well. */
118         /*xorl    %eax, %eax*/
119         xorl    $0x5c5c5c5c,%eax
120         rep     stosl
121
122         movl    XIP_ROM_BASE, %esi
123         movl    %esi, %edi
124         movl    $(XIP_ROM_SIZE>>2), %ecx
125         rep     lodsl
126
127         /* The key point of this CAR code is C7 cache does not turn into
128          * "no fill" mode, which is not compatible with general CAR code.
129          */
130
131         movl    $(CacheBase+CacheSize-4), %eax
132         movl    %eax, %esp
133
134 #ifdef CONFIG_CARTEST
135 testok: movb $0x40,%al
136         outb %al, $0x80
137         xorl  %edx, %edx
138         xorl  %eax, %eax
139         movl  $0x5c5c,%edx
140         pushl %edx
141         pushl %edx
142         pushl %edx
143         pushl %edx
144         pushl %edx
145         popl  %esi
146         popl  %esi
147         popl  %eax
148         popl  %eax
149         popl  %eax
150         cmpl %edx,%eax
151         jne stackerr
152 #endif
153
154         /* Restore the BIST result */
155         movl    %ebp, %eax
156         /* We need to set ebp ? No need */
157         movl    %esp, %ebp
158         pushl   %eax  /* bist */
159         call    amd64_main
160         /* We will not go back */
161
162 fixed_mtrr_msr:
163         .long   0x250, 0x258, 0x259
164         .long   0x268, 0x269, 0x26A
165         .long   0x26B, 0x26C, 0x26D
166         .long   0x26E, 0x26F
167 var_mtrr_msr:
168         .long   0x200, 0x201, 0x202, 0x203
169         .long   0x204, 0x205, 0x206, 0x207
170         .long   0x208, 0x209, 0x20A, 0x20B
171         .long   0x20C, 0x20D, 0x20E, 0x20F
172         .long   0x000 /* NULL, end of table */