Remove some DOS line endings accidentially introduced in r3014.
[coreboot.git] / src / cpu / amd / car / cache_as_ram.inc
1 /*
2  * This file is part of the LinuxBIOS project.
3  *
4  * Copyright (C) 2005-2007 Advanced Micro Devices, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
18  */
19
20 #define CacheSize DCACHE_RAM_SIZE
21 #define CacheBase (0xd0000 - CacheSize)
22
23 /* leave some space for global variable to pass to RAM stage */
24 #define GlobalVarSize DCACHE_RAM_GLOBAL_VAR_SIZE
25
26 #if CAR_FAM10 == 1
27 #define CacheSizeAPStack 0x400 /* 1K */
28 #endif
29
30 #include <cpu/x86/mtrr.h>
31 #include <cpu/amd/mtrr.h>
32
33         /* Save the BIST result */
34         movl    %eax, %ebp
35
36         /*for normal part %ebx already contain cpu_init_detected from fallback call */
37
38 cache_as_ram_setup:
39
40         movb    $0xA0, %al
41         outb    %al, $0x80
42
43         /* hope we can skip the double set for normal part */
44 #if ((HAVE_FAILOVER_BOOT == 1) && (USE_FAILOVER_IMAGE == 1)) || ((HAVE_FAILOVER_BOOT == 0) && (USE_FALLBACK_IMAGE == 1))
45
46         /* check if cpu_init_detected */
47         movl    $MTRRdefType_MSR, %ecx
48         rdmsr
49         andl    $(1 << 11), %eax
50         movl    %eax, %ebx      /* We store the status */
51
52 #if CAR_FAM10 == 1
53         /* for GH, CAR need to set DRAM Base/Limit Registers to direct that to node0 */
54
55         /* Only BSP needed, for other nodes set during HT/memory init. */
56         /* So we need to check if it is BSP */
57         movl    $0x1b, %ecx
58         rdmsr
59         bt      $8, %eax /*BSC */
60         jnc     CAR_FAM10_out
61
62         /* Enable RT tables on BSP */
63         movl    $0x8000c06c, %eax
64         movw    $0xcf8, %dx
65         outl    %eax, %dx
66         addw    $4, %dx
67         inl     %dx, %eax
68         btr     $0, %eax
69         outl    %eax, %dx
70
71         /* Setup temporary DRAM map: [0,16M) bit 0-23 */
72         movl    $0x8000c144, %eax
73         movw    $0xcf8, %dx
74         outl    %eax, %dx
75         addw    $4, %dx
76         movl    $0, %eax
77         outl    %eax, %dx
78
79         movl    $0x8000c140, %eax
80         movw    $0xcf8, %dx
81         outl    %eax, %dx
82         addw    $4, %dx
83         movl    $3, %eax
84         outl    %eax, %dx
85
86 CAR_FAM10_out:
87
88 #endif
89
90 #if CAR_FAM10 == 1
91         /* Errata 193: Disable clean copybacks to L3 cache to allow cached ROM.
92            Re-enable it in after RAM is initialized and before CAR is disabled */
93         movl    $0xc001102a, %ecx
94         rdmsr
95         bts     $15, %eax
96         wrmsr
97 #endif
98
99         /* Set MtrrFixDramModEn for clear fixed mtrr */
100 enable_fixed_mtrr_dram_modify:
101         movl    $SYSCFG_MSR, %ecx
102         rdmsr
103         andl    $(~(SYSCFG_MSR_MtrrFixDramEn | SYSCFG_MSR_MtrrVarDramEn)), %eax
104         orl     $SYSCFG_MSR_MtrrFixDramModEn, %eax
105         wrmsr
106
107         /* Clear all MTRRs */
108         xorl    %edx, %edx
109         movl    $fixed_mtrr_msr, %esi
110
111 clear_fixed_var_mtrr:
112         lodsl   (%esi), %eax
113         testl   %eax, %eax
114         jz              clear_fixed_var_mtrr_out
115
116         movl    %eax, %ecx
117         xorl    %eax, %eax
118         wrmsr
119
120         jmp             clear_fixed_var_mtrr
121 clear_fixed_var_mtrr_out:
122
123 #if CacheSize == 0x10000
124         /* enable caching for 64K using fixed mtrr */
125         movl    $0x268, %ecx  /* fix4k_c0000*/
126  #if CAR_FAM10 == 1
127         movl    $0x1e1e1e1e, %edx /* WB MEM type */
128  #else
129         movl    $0x06060606, %edx /* WB IO type */
130  #endif
131
132         movl    %edx, %eax
133         wrmsr
134         movl    $0x269, %ecx
135         wrmsr
136 #endif
137
138 #if CacheSize == 0xc000
139         /* enable caching for 16K using fixed mtrr */
140         movl    $0x268, %ecx  /* fix4k_c4000*/
141  #if CAR_FAM10 == 1
142         movl    $0x1e1e1e1e, %edx /* WB MEM type */
143  #else
144         movl    $0x06060606, %edx /* WB IO type */
145  #endif
146         xorl    %eax, %eax
147         wrmsr
148         /* enable caching for 32K using fixed mtrr */
149         movl    $0x269, %ecx  /* fix4k_c8000*/
150  #if CAR_FAM10 == 1
151         movl    $0x1e1e1e1e, %edx /* WB MEM type */
152  #else
153         movl    $0x06060606, %edx /* WB IO type */
154  #endif
155         movl    %edx, %eax
156         wrmsr
157 #endif
158
159
160 #if CacheSize == 0x8000
161         /* enable caching for 32K using fixed mtrr */
162         movl    $0x269, %ecx  /* fix4k_c8000*/
163  #if CAR_FAM10 == 1
164         movl    $0x1e1e1e1e, %edx /* WB MEM type */
165  #else
166         movl    $0x06060606, %edx /* WB IO type */
167  #endif
168         movl    %edx, %eax
169         wrmsr
170 #endif
171
172 #if CacheSize < 0x8000
173         /* enable caching for 16K/8K/4K using fixed mtrr */
174         movl    $0x269, %ecx  /* fix4k_cc000*/
175  #if CacheSize == 0x4000
176   #if CAR_FAM10 == 1
177         movl    $0x1e1e1e1e, %edx /* WB MEM type */
178   #else
179         movl    $0x06060606, %edx /* WB IO type */
180   #endif
181  #endif
182  #if CacheSize == 0x2000
183   #if CAR_FAM10 == 1
184         movl    $0x1e1e0000, %edx /* WB MEM type */
185   #else
186         movl    $0x06060000, %edx /* WB IO type */
187   #endif
188  #endif
189  #if CacheSize == 0x1000
190   #if CAR_FAM10 == 1
191         movl    $0x1e000000, %edx /* WB MEM type */
192   #else
193         movl    $0x06000000, %edx /* WB IO type */
194   #endif
195  #endif
196         xorl    %eax, %eax
197         wrmsr
198 #endif
199
200         /* enable memory access for first MBs using top_mem */
201         movl    $TOP_MEM, %ecx
202         xorl    %edx, %edx
203         movl    $(((CONFIG_LB_MEM_TOPK << 10) + TOP_MEM_MASK) & ~TOP_MEM_MASK) , %eax
204         wrmsr
205 #endif /*  USE_FAILOVER_IMAGE == 1*/
206
207
208 #if ((HAVE_FAILOVER_BOOT == 1) && (USE_FAILOVER_IMAGE == 0)) || ((HAVE_FAILOVER_BOOT == 0) && (USE_FALLBACK_IMAGE == 0))
209         /* disable cache */
210         movl    %cr0, %eax
211         orl             $(1 << 30),%eax
212         movl    %eax, %cr0
213
214 #endif
215
216 #if defined(XIP_ROM_SIZE) && defined(XIP_ROM_BASE)
217         /* enable write base caching so we can do execute in place
218          * on the flash rom.
219          */
220         movl    $0x202, %ecx
221         xorl    %edx, %edx
222         movl    $(XIP_ROM_BASE | MTRR_TYPE_WRBACK), %eax
223         wrmsr
224
225         movl    $0x203, %ecx
226         movl    $((1 << (CPU_ADDR_BITS - 32)) - 1), %edx  /* AMD 40 bit for K8, 48 bit for GH */
227         movl    $(~(XIP_ROM_SIZE - 1) | 0x800), %eax
228         wrmsr
229 #endif /* XIP_ROM_SIZE && XIP_ROM_BASE */
230
231 #if ((HAVE_FAILOVER_BOOT == 1) && (USE_FAILOVER_IMAGE == 1)) || ((HAVE_FAILOVER_BOOT == 0) && (USE_FALLBACK_IMAGE == 1))
232         /* Set the default memory type and enable fixed and variable MTRRs */
233         movl    $MTRRdefType_MSR, %ecx
234         xorl    %edx, %edx
235         /* Enable Variable and Fixed MTRRs */
236         movl    $0x00000c00, %eax
237         wrmsr
238
239         /* Enable the MTRRs and IORRs in SYSCFG */
240         movl    $SYSCFG_MSR, %ecx
241         rdmsr
242         orl             $(SYSCFG_MSR_MtrrVarDramEn | SYSCFG_MSR_MtrrFixDramEn), %eax
243         wrmsr
244 #endif
245
246         movb    $0xA1, %al
247         outb    %al, $0x80
248
249         /* enable cache */
250         movl    %cr0, %eax
251         andl    $0x9fffffff, %eax
252         movl    %eax, %cr0
253
254
255 #if CAR_FAM10 == 1
256         /* So we need to check if it is BSP */
257         movl    $0x1b, %ecx
258         rdmsr
259         bt      $8, %eax /*BSC */
260         jnc     CAR_FAM10_ap
261 #endif
262
263         movb    $0xA2, %al
264         outb    %al, $0x80
265
266 #if ((HAVE_FAILOVER_BOOT == 1) && (USE_FAILOVER_IMAGE == 1)) || ((HAVE_FAILOVER_BOOT == 0) && (USE_FALLBACK_IMAGE == 1))
267                 /* Read the range with lodsl*/
268         cld
269         movl    $CacheBase, %esi
270         movl    $(CacheSize >> 2), %ecx
271         rep             lodsl
272         /* Clear the range */
273         movl    $CacheBase, %edi
274         movl    $(CacheSize >> 2), %ecx
275         xorl    %eax, %eax
276         rep             stosl
277
278 #endif /*USE_FAILOVER_IMAGE == 1*/
279
280         /* set up the stack pointer */
281         movl    $(CacheBase + CacheSize - GlobalVarSize), %eax
282         movl    %eax, %esp
283
284         movb    $0xA3, %al
285         outb    %al, $0x80
286
287 #if CAR_FAM10 == 1
288
289         jmp     CAR_FAM10_ap_out
290 CAR_FAM10_ap:
291         /* need to set stack pointer for AP */
292         /* it will be from CacheBase + (CacheSize - GlobalVarSize)/2 - (NodeID<<CoreIDbits + CoreID) * CacheSizeAPStack*/
293         /* So need to get the NodeID and CoreID at first */
294         /* If NB_CFG bit 54 is set just use initial apicid, otherwise need to reverse it */
295
296         /* store our init detected */
297         movl    %ebx, %esi
298
299         /* get the coreid bits at first */
300         movl    $0x80000008, %eax
301         cpuid
302         shrl    $12, %ecx
303         andl    $0x0f, %ecx
304         movl    %ecx, %edi
305
306         /* get the initial apic id */
307         movl    $1, %eax
308         cpuid
309         shrl    $24, %ebx
310
311         /* get the nb cfg bit 54 */
312         movl    $0xc001001f, %ecx /* NB_CFG_MSR */
313         rdmsr
314         movl    %edi, %ecx      /* CoreID bits */
315         bt      $(54-32), %edx
316         jc      roll_cfg
317         rolb    %cl, %bl
318 roll_cfg:
319
320         /* calculate stack pointer */
321         movl    $CacheSizeAPStack, %eax
322         mull    %ebx
323         movl    $(CacheBase + (CacheSize - GlobalVarSize)/2), %esp
324         subl    %eax, %esp
325
326         /* retrive init detected */
327         movl    %esi, %ebx
328
329         movb    $0xA4, %al
330         outb    %al, $0x80
331
332 CAR_FAM10_ap_out:
333 #endif
334
335         movb    $0xA5, %al
336         outb    %al, $0x80
337
338         /* Restore the BIST result */
339         movl    %ebp, %eax
340
341         /* We need to set ebp ? No need */
342         movl    %esp, %ebp
343         pushl   %ebx  /* init detected */
344         pushl   %eax  /* bist */
345         call    cache_as_ram_main
346         /* We will not go back */
347
348         movb    $0xAF, %al              /* Should never see this postcode */
349         outb    %al, $0x80
350
351 fixed_mtrr_msr:
352         .long   0x250, 0x258, 0x259
353         .long   0x268, 0x269, 0x26A
354         .long   0x26B, 0x26C, 0x26D
355         .long   0x26E, 0x26F
356 var_mtrr_msr:
357         .long   0x200, 0x201, 0x202, 0x203
358         .long   0x204, 0x205, 0x206, 0x207
359         .long   0x208, 0x209, 0x20A, 0x20B
360         .long   0x20C, 0x20D, 0x20E, 0x20F
361 var_iorr_msr:
362         .long   0xC0010016, 0xC0010017, 0xC0010018, 0xC0010019
363 mem_top:
364         .long   0xC001001A, 0xC001001D
365         .long   0x000 /* NULL, end of table */
366
367 cache_as_ram_setup_out: