blob: 195b7c5f6f29c21d1451689bd4e8694865cda09e [file] [log] [blame]
Uwe Hermann203bffe2007-07-07 21:18:47 +00001/*
Stefan Reinauer6220b632008-01-27 18:54:57 +00002 * This file is part of the coreboot project.
Uwe Hermann203bffe2007-07-07 21:18:47 +00003 *
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 Advanced Micro Devices, Inc.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; version 2 of the License.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
Stefan Reinauer5dfd4412007-05-19 08:44:14 +000025
Uwe Hermann203bffe2007-07-07 21:18:47 +000026/* Init code - Switch CPU to protected mode and enable Cache-as-Ram (CAR). */
Stefan Reinauer5dfd4412007-05-19 08:44:14 +000027
Ronald G. Minnich24d5ad52008-08-04 00:39:28 +000028#include <macros.h>
Stefan Reinauer5dfd4412007-05-19 08:44:14 +000029#include <amd_geodelx.h>
30
Stefan Reinauer5dfd4412007-05-19 08:44:14 +000031
Uwe Hermann203bffe2007-07-07 21:18:47 +000032 /* When we come here we are in protected mode. We expand the stack
Uwe Hermannbd53a462007-05-19 21:31:23 +000033 * and copy the data segment from ROM to the memory.
34 *
35 * After that, we call the chipset bootstrap routine that
36 * does what is left of the chipset initialization.
37 *
Carl-Daniel Hailfingeref06e832008-10-07 21:59:21 +000038 * NOTE: Aligned to 4 so that we are sure that the prefetch
Uwe Hermannbd53a462007-05-19 21:31:23 +000039 * cache will be reloaded.
40 */
Stefan Reinauer5dfd4412007-05-19 08:44:14 +000041
42 .align 4
43 .globl protected_stage0
44protected_stage0:
Uwe Hermann203bffe2007-07-07 21:18:47 +000045 /* This code was used by v2. TODO. */
Uwe Hermannbd53a462007-05-19 21:31:23 +000046 lgdt %cs:gdtptr
47 ljmp $ROM_CODE_SEG, $__protected_stage0
Stefan Reinauer5dfd4412007-05-19 08:44:14 +000048
49.globl __protected_stage0
50__protected_stage0:
Carl-Daniel Hailfinger7b5c1642008-10-06 23:26:29 +000051 /* Save the BIST result. */
Uwe Hermannbd53a462007-05-19 21:31:23 +000052 movl %eax, %ebp
Stefan Reinauer5dfd4412007-05-19 08:44:14 +000053
Uwe Hermannbd53a462007-05-19 21:31:23 +000054 port80_post(0x01)
Stefan Reinauer5dfd4412007-05-19 08:44:14 +000055
Uwe Hermannbd53a462007-05-19 21:31:23 +000056 movw $ROM_DATA_SEG, %ax
57 movw %ax, %ds
58 movw %ax, %es
59 movw %ax, %ss
60 movw %ax, %fs
61 movw %ax, %gs
Stefan Reinauer5dfd4412007-05-19 08:44:14 +000062
Uwe Hermannbd53a462007-05-19 21:31:23 +000063 /* Restore the BIST value to %eax. */
64 movl %ebp, %eax
Stefan Reinauer5dfd4412007-05-19 08:44:14 +000065
Uwe Hermann203bffe2007-07-07 21:18:47 +000066 .align 4
Uwe Hermannbd53a462007-05-19 21:31:23 +000067 /* Here begins CAR support. */
Stefan Reinauer6220b632008-01-27 18:54:57 +000068 /* This particular code is straight from coreboot v2. */
Uwe Hermannbd53a462007-05-19 21:31:23 +000069
70 /* DCacheSetup: Setup data cache for use as RAM for a stack. */
Stefan Reinauer5dfd4412007-05-19 08:44:14 +000071DCacheSetup:
Stefan Reinauer5dfd4412007-05-19 08:44:14 +000072 invd
Uwe Hermann203bffe2007-07-07 21:18:47 +000073
Uwe Hermannbd53a462007-05-19 21:31:23 +000074 /* Set cache properties. */
Stefan Reinauer5dfd4412007-05-19 08:44:14 +000075 movl $CPU_RCONF_DEFAULT, %ecx
76 rdmsr
Uwe Hermann203bffe2007-07-07 21:18:47 +000077
Uwe Hermannbd53a462007-05-19 21:31:23 +000078 /* 1MB system memory in write back 1|00100|00. */
79 movl $0x010010000, %eax
Stefan Reinauer5dfd4412007-05-19 08:44:14 +000080 wrmsr
81
Uwe Hermannbd53a462007-05-19 21:31:23 +000082 /* In LX DCDIS is set after POR which disables the cache..., clear
83 * this bit.
84 */
Marc Jones064cd702007-07-19 15:15:57 +000085 movl $CPU_DM_CONFIG0,%ecx
Stefan Reinauer5dfd4412007-05-19 08:44:14 +000086 rdmsr
Uwe Hermann203bffe2007-07-07 21:18:47 +000087
Uwe Hermannbd53a462007-05-19 21:31:23 +000088 /* TODO: Make consistent with i$ init, either whole reg = 0, or just
89 * this bit...
90 */
91 andl $(~(DM_CONFIG0_LOWER_DCDIS_SET)), %eax
Stefan Reinauer5dfd4412007-05-19 08:44:14 +000092 wrmsr
93
Uwe Hermannbd53a462007-05-19 21:31:23 +000094 /* Get cache timing params from BIOS config data locations and apply. */
95 /* Fix delay controls for DM and IM arrays. */
Stefan Reinauer5dfd4412007-05-19 08:44:14 +000096 movl $CPU_BC_MSS_ARRAY_CTL0, %ecx
97 xorl %edx, %edx
98 movl $0x2814D352, %eax
99 wrmsr
100
101 movl $CPU_BC_MSS_ARRAY_CTL1, %ecx
102 xorl %edx, %edx
103 movl $0x1068334D, %eax
104 wrmsr
105
106 movl $CPU_BC_MSS_ARRAY_CTL2, %ecx
107 movl $0x00000106, %edx
108 movl $0x83104104, %eax
109 wrmsr
110
111 movl $GLCP_FIFOCTL, %ecx
112 rdmsr
113 movl $0x00000005, %edx
114 wrmsr
115
Uwe Hermannbd53a462007-05-19 21:31:23 +0000116 /* Enable setting. */
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000117 movl $CPU_BC_MSS_ARRAY_CTL_ENA, %ecx
118 xorl %edx, %edx
119 movl $0x01, %eax
120 wrmsr
121
122 /* Get cleaned up. */
123 xorl %edi, %edi
124 xorl %esi, %esi
125 xorl %ebp, %ebp
126
Uwe Hermannbd53a462007-05-19 21:31:23 +0000127 /* DCache Ways0 through Ways7 will be tagged for
128 * LX_STACK_BASE + DCACHE_RAM_SIZE for holding stack.
129 */
130 /* Remember, there is NO stack yet... */
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000131
Uwe Hermannbd53a462007-05-19 21:31:23 +0000132 /* Tell cache we want to fill Way 0 starting at the top. */
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000133 xorl %edx, %edx
134 xorl %eax, %eax
135 movl $CPU_DC_INDEX, %ecx
136 wrmsr
137
Uwe Hermann203bffe2007-07-07 21:18:47 +0000138 /* Start address for tag of Way0: ebp will hold the incrementing
139 * address. Don't destroy!
Uwe Hermannbd53a462007-05-19 21:31:23 +0000140 */
141 movl $LX_STACK_BASE, %ebp /* Init to start address. */
Uwe Hermann203bffe2007-07-07 21:18:47 +0000142
143 /* Set valid bit and tag for this Way (B[31:12]: Cache tag value for
Uwe Hermannbd53a462007-05-19 21:31:23 +0000144 * line/way curr. selected by CPU_DC_INDEX.
145 */
146 orl $1, %ebp
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000147
Uwe Hermannbd53a462007-05-19 21:31:23 +0000148 /* Start tag Ways 0 with 128 lines with 32 bytes each: edi will hold
Uwe Hermann203bffe2007-07-07 21:18:47 +0000149 * the line counter. Don't destroy!
Uwe Hermannbd53a462007-05-19 21:31:23 +0000150 */
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000151 movl $LX_NUM_CACHELINES, %edi
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000152
Uwe Hermannbd53a462007-05-19 21:31:23 +0000153DCacheSetupFillWay:
154 /* Fill with dummy data: zero it so we can tell it from PCI memory
155 * space (returns FFs).
156 */
157 /* We will now store a line (32 bytes = 4 x 8 bytes = 4 quad-words). */
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000158 movw $0x04, %si
159 xorl %edx, %edx
160 xorl %eax, %eax
161 movl $CPU_DC_DATA, %ecx
Uwe Hermannbd53a462007-05-19 21:31:23 +0000162
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000163DCacheSetup_quadWordLoop:
164 wrmsr
165 decw %si
166 jnz DCacheSetup_quadWordLoop
167
Uwe Hermannbd53a462007-05-19 21:31:23 +0000168 /* Set the tag for this line, need to do this for every new cache
169 * line to validate it!
170 */
171 /* Accessing CPU_DC_TAG_I makes the LINE field in CPU_DC_INDEX
172 * increment and thus continue in the next cache line...
173 */
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000174 xorl %edx, %edx
175 movl %ebp, %eax
176 movl $CPU_DC_TAG, %ecx
177 wrmsr
178
Uwe Hermann203bffe2007-07-07 21:18:47 +0000179 /* Switch to next line. Lines are in bits 10:4. */
Uwe Hermannbd53a462007-05-19 21:31:23 +0000180 /* When index is crossing 0x7F -> 0x80 writing a RSVD bit as 0x80 is
181 * not a valid CL anymore!
182 */
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000183 movl $CPU_DC_INDEX, %ecx
184 rdmsr
Uwe Hermann203bffe2007-07-07 21:18:47 +0000185
Uwe Hermannbd53a462007-05-19 21:31:23 +0000186 /* TODO: Probably would be more elegant to calculate this from
187 * counter var edi...
188 */
189 addl $0x010, %eax
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000190 wrmsr
191
192 decl %edi
193 jnz DCacheSetupFillWay
194
Uwe Hermannbd53a462007-05-19 21:31:23 +0000195 /* 1 Way has been filled, forward start address for next Way,
196 * terminate if we have reached end of desired address range.
197 */
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000198 addl $LX_CACHEWAY_SIZE, %ebp
199 cmpl $LX_STACK_END, %ebp
200 jge leave_DCacheSetup
201 movl $LX_NUM_CACHELINES, %edi
202
Uwe Hermannbd53a462007-05-19 21:31:23 +0000203 /* Switch to next way. */
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000204 movl $CPU_DC_INDEX, %ecx
205 rdmsr
206 addl $0x01, %eax
Uwe Hermann203bffe2007-07-07 21:18:47 +0000207
208 /* Let's be sure: reset line index bits 10:4. */
Uwe Hermannbd53a462007-05-19 21:31:23 +0000209 andl $0xFFFFF80F, %eax
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000210 wrmsr
211
212 jmp DCacheSetupFillWay
213
214leave_DCacheSetup:
215 xorl %edi, %edi
216 xorl %esi, %esi
217 xorl %ebp, %ebp
218
Uwe Hermannbd53a462007-05-19 21:31:23 +0000219 /* Disable the cache, but... DO NOT INVALIDATE the tags. */
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000220 /* Memory reads and writes will all hit in the cache. */
Uwe Hermannbd53a462007-05-19 21:31:23 +0000221 /* Cache updates and memory write-backs will not occur! */
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000222 movl %cr0, %eax
Uwe Hermannbd53a462007-05-19 21:31:23 +0000223 orl $(CR0_CD + CR0_NW), %eax /* Set the CD and NW bits. */
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000224 movl %eax, %cr0
225
226 /* Now point sp to the cached stack. */
Uwe Hermannbd53a462007-05-19 21:31:23 +0000227 /* The stack will be fully functional at this location. No system
228 * memory is required at all!
229 */
230 /* Set up the stack pointer. */
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000231 movl $LX_STACK_END, %eax
232 movl %eax, %esp
233
Uwe Hermannbd53a462007-05-19 21:31:23 +0000234 /* Test the stack. */
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000235 movl $0x0F0F05A5A, %edx
236 pushl %edx
237 popl %ecx
238 cmpl %ecx, %edx
239 je DCacheSetupGood
240 movb $0xC5, %al
241 outb %al, $0x80
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000242
Uwe Hermannbd53a462007-05-19 21:31:23 +0000243DCacheSetupBad:
244 hlt /* Issues */
245 jmp DCacheSetupBad
246
247DCacheSetupGood:
Uwe Hermannbd53a462007-05-19 21:31:23 +0000248 /* At this point, CAR should be working. */
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000249 movl $(LX_STACK_END), %eax
Uwe Hermannbd53a462007-05-19 21:31:23 +0000250 movl %eax, %esp
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000251
Uwe Hermannbd53a462007-05-19 21:31:23 +0000252 /* Load a different set of data segments. */
253 movw $CACHE_RAM_DATA_SEG, %ax
254 movw %ax, %ds
255 movw %ax, %es
256 movw %ax, %ss
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000257
258lout:
Carl-Daniel Hailfinger1b5c3992008-08-18 16:54:12 +0000259 /* Store zero for the pointer to the global variables. */
260 movl $0, %eax
261 pushl %eax
262
Uwe Hermannbd53a462007-05-19 21:31:23 +0000263 /* Restore the BIST result. */
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000264 movl %ebp, %eax
Uwe Hermann203bffe2007-07-07 21:18:47 +0000265
Uwe Hermannbd53a462007-05-19 21:31:23 +0000266 /* We need to set ebp? No need. */
Stefan Reinauer5dfd4412007-05-19 08:44:14 +0000267 movl %esp, %ebp
Carl-Daniel Hailfinger96fcf122008-10-07 23:53:02 +0000268
Marc Jonesf2872762009-02-10 22:41:35 +0000269 /* Third parameter: cpu #: 0 == BSP all other are APs.
270 * Always 0 for Geode.
271 */
272 pushl $0
Carl-Daniel Hailfinger96fcf122008-10-07 23:53:02 +0000273 /* Second parameter: init_detected */
274 /* Store zero for the unused init_detected parameter. */
275 pushl $0
276 /* First parameter: bist */
277 pushl %eax
Carl-Daniel Hailfinger33de3b22008-10-16 03:00:28 +0000278 call stage1_phase1
Uwe Hermannbd53a462007-05-19 21:31:23 +0000279 /* We will not go back. */
280
Carl-Daniel Hailfinger73d43832008-10-08 16:07:29 +0000281#include "../stage0_common.S"