blob: 4ac6d292320ceac9a89b06c3601e2a89b0642e5f [file] [log] [blame]
Arthur Heymansdd4d8952018-06-03 12:04:26 +02001/*
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
Arthur Heymansc2ccc972018-06-03 12:09:52 +02006 * Copyright (C) 2012 Kyösti Mälkki <kyosti.malkki@gmail.com>
Arthur Heymansdd4d8952018-06-03 12:04:26 +02007 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#include <cpu/x86/mtrr.h>
19#include <cpu/x86/cache.h>
20#include <cpu/x86/post_code.h>
21
22#define CACHE_AS_RAM_SIZE (CONFIG_DCACHE_RAM_SIZE \
23 + CONFIG_DCACHE_RAM_MRC_VAR_SIZE)
24#define CACHE_AS_RAM_BASE CONFIG_DCACHE_RAM_BASE
25
Arthur Heymansdd4d8952018-06-03 12:04:26 +020026#define NoEvictMod_MSR 0x2e0
27
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +020028.global bootblock_pre_c_entry
29
Arthur Heymansdd4d8952018-06-03 12:04:26 +020030.code32
31_cache_as_ram_setup:
32
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +020033bootblock_pre_c_entry:
Arthur Heymansdd4d8952018-06-03 12:04:26 +020034
35cache_as_ram:
36 post_code(0x20)
37
38 /* Send INIT IPI to all excluding ourself. */
39 movl $0x000C4500, %eax
40 movl $0xFEE00300, %esi
41 movl %eax, (%esi)
42
43 /* All CPUs need to be in Wait for SIPI state */
44wait_for_sipi:
45 movl (%esi), %eax
46 bt $12, %eax
47 jc wait_for_sipi
48
49 post_code(0x21)
50 /* Clean-up MTRR_DEF_TYPE_MSR. */
51 movl $MTRR_DEF_TYPE_MSR, %ecx
52 xorl %eax, %eax
53 xorl %edx, %edx
54 wrmsr
55
56 post_code(0x22)
Arthur Heymansc2ccc972018-06-03 12:09:52 +020057 /* Clear/disable fixed MTRRs */
58 mov $fixed_mtrr_list_size, %ebx
59 xor %eax, %eax
60 xor %edx, %edx
61
62clear_fixed_mtrr:
63 add $-2, %ebx
64 movzwl fixed_mtrr_list(%ebx), %ecx
Arthur Heymansdd4d8952018-06-03 12:04:26 +020065 wrmsr
Arthur Heymansc2ccc972018-06-03 12:09:52 +020066 jnz clear_fixed_mtrr
Arthur Heymansdd4d8952018-06-03 12:04:26 +020067
68 /* Zero out all variable range MTRRs. */
69 movl $MTRR_CAP_MSR, %ecx
70 rdmsr
71 andl $0xff, %eax
72 shl $1, %eax
73 movl %eax, %edi
74 movl $0x200, %ecx
75 xorl %eax, %eax
76 xorl %edx, %edx
77clear_var_mtrrs:
78 wrmsr
79 add $1, %ecx
80 dec %edi
81 jnz clear_var_mtrrs
82
Arthur Heymansc2ccc972018-06-03 12:09:52 +020083 /* Determine CPU_ADDR_BITS and load PHYSMASK high word to %edx. */
84 movl $0x80000008, %eax
85 cpuid
86 movb %al, %cl
87 sub $32, %cl
88 movl $1, %edx
89 shl %cl, %edx
90 subl $1, %edx
91
92 /* Preload high word of address mask (in %edx) for Variable
93 * MTRRs 0 and 1.
94 */
95addrsize_set_high:
96 xorl %eax, %eax
97 movl $MTRR_PHYS_MASK(0), %ecx
98 wrmsr
99 movl $MTRR_PHYS_MASK(1), %ecx
100 wrmsr
101
102
Arthur Heymansdd4d8952018-06-03 12:04:26 +0200103 post_code(0x23)
104 /* Set Cache-as-RAM base address. */
105 movl $(MTRR_PHYS_BASE(0)), %ecx
106 movl $(CACHE_AS_RAM_BASE | MTRR_TYPE_WRBACK), %eax
107 xorl %edx, %edx
108 wrmsr
109
110 post_code(0x24)
111 /* Set Cache-as-RAM mask. */
112 movl $(MTRR_PHYS_MASK(0)), %ecx
Arthur Heymansc2ccc972018-06-03 12:09:52 +0200113 rdmsr
Arthur Heymansdd4d8952018-06-03 12:04:26 +0200114 movl $(~(CACHE_AS_RAM_SIZE - 1) | MTRR_PHYS_MASK_VALID), %eax
Arthur Heymansdd4d8952018-06-03 12:04:26 +0200115 wrmsr
116
117 post_code(0x25)
118
119 /* Enable MTRR. */
120 movl $MTRR_DEF_TYPE_MSR, %ecx
121 rdmsr
122 orl $MTRR_DEF_TYPE_EN, %eax
123 wrmsr
124
125 /* Enable cache (CR0.CD = 0, CR0.NW = 0). */
126 movl %cr0, %eax
127 andl $(~(CR0_CacheDisable | CR0_NoWriteThrough)), %eax
128 invd
129 movl %eax, %cr0
130
131 /* enable the 'no eviction' mode */
Arthur Heymansa28befd2018-12-20 13:59:34 +0100132 movl $NoEvictMod_MSR, %ecx
Arthur Heymansdd4d8952018-06-03 12:04:26 +0200133 rdmsr
Arthur Heymansa28befd2018-12-20 13:59:34 +0100134 orl $1, %eax
135 andl $~2, %eax
Arthur Heymansdd4d8952018-06-03 12:04:26 +0200136 wrmsr
137
138 /* Clear the cache memory region. This will also fill up the cache. */
139 movl $CACHE_AS_RAM_BASE, %esi
140 movl %esi, %edi
141 movl $(CACHE_AS_RAM_SIZE >> 2), %ecx
Arthur Heymansdd4d8952018-06-03 12:04:26 +0200142 xorl %eax, %eax
143 rep stosl
144
145 /* enable the 'no eviction run' state */
Arthur Heymansa28befd2018-12-20 13:59:34 +0100146 movl $NoEvictMod_MSR, %ecx
Arthur Heymansdd4d8952018-06-03 12:04:26 +0200147 rdmsr
Arthur Heymansa28befd2018-12-20 13:59:34 +0100148 orl $3, %eax
Arthur Heymansdd4d8952018-06-03 12:04:26 +0200149 wrmsr
150
151 post_code(0x26)
152 /* Enable Cache-as-RAM mode by disabling cache. */
153 movl %cr0, %eax
154 orl $CR0_CacheDisable, %eax
155 movl %eax, %cr0
156
157 /* Enable cache for our code in Flash because we do XIP here */
158 movl $MTRR_PHYS_BASE(1), %ecx
159 xorl %edx, %edx
Arthur Heymansc2ccc972018-06-03 12:09:52 +0200160 movl $CACHE_ROM_BASE | MTRR_TYPE_WRPROT, %eax
Arthur Heymansdd4d8952018-06-03 12:04:26 +0200161 wrmsr
162
163 movl $MTRR_PHYS_MASK(1), %ecx
Arthur Heymansc2ccc972018-06-03 12:09:52 +0200164 rdmsr
165 movl $(~(CACHE_ROM_SIZE - 1) | MTRR_PHYS_MASK_VALID), %eax
Arthur Heymansdd4d8952018-06-03 12:04:26 +0200166 wrmsr
167
168 post_code(0x28)
169 /* Enable cache. */
170 movl %cr0, %eax
171 andl $(~(CR0_CacheDisable | CR0_NoWriteThrough)), %eax
172 movl %eax, %cr0
173
174 /* Setup the stack. */
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +0200175 mov $_car_stack_end, %esp
Arthur Heymansdd4d8952018-06-03 12:04:26 +0200176
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +0200177 /* Need to align stack to 16 bytes at call instruction. Account for
178 the pushes below. */
Arthur Heymans348b79f2018-06-03 17:14:19 +0200179 andl $0xfffffff0, %esp
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +0200180 subl $4, %esp
Arthur Heymans348b79f2018-06-03 17:14:19 +0200181
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +0200182 /* push TSC and BIST to stack */
183 movd %mm0, %eax
184 pushl %eax /* BIST */
185 movd %mm2, %eax
186 pushl %eax /* tsc[63:32] */
187 movd %mm1, %eax
188 pushl %eax /* tsc[31:0] */
Arthur Heymansdd4d8952018-06-03 12:04:26 +0200189
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +0200190before_c_entry:
Arthur Heymansdd4d8952018-06-03 12:04:26 +0200191 post_code(0x29)
Kyösti Mälkkic641f7e2018-12-28 16:54:54 +0200192 call bootblock_c_entry_bist
Arthur Heymansdd4d8952018-06-03 12:04:26 +0200193
194 /* Should never see this postcode */
195 post_code(POST_DEAD_CODE)
196
197
198.Lhlt:
199 hlt
200 jmp .Lhlt
201
Arthur Heymansc2ccc972018-06-03 12:09:52 +0200202fixed_mtrr_list:
203 .word MTRR_FIX_64K_00000
204 .word MTRR_FIX_16K_80000
205 .word MTRR_FIX_16K_A0000
206 .word MTRR_FIX_4K_C0000
207 .word MTRR_FIX_4K_C8000
208 .word MTRR_FIX_4K_D0000
209 .word MTRR_FIX_4K_D8000
210 .word MTRR_FIX_4K_E0000
211 .word MTRR_FIX_4K_E8000
212 .word MTRR_FIX_4K_F0000
213 .word MTRR_FIX_4K_F8000
214fixed_mtrr_list_size = . - fixed_mtrr_list
Arthur Heymansdd4d8952018-06-03 12:04:26 +0200215
216_cache_as_ram_setup_end: