blob: fea7acb2e270d097dd89e618423d51f3cf578706 [file] [log] [blame]
Lee Leahy3dad4892015-05-05 11:14:02 -07001/*
2 * This file is part of the coreboot project.
3 *
Lee Leahy3dad4892015-05-05 11:14:02 -07004 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
Lee Leahy3dad4892015-05-05 11:14:02 -070012 */
13
Arthur Heymans8256ca02019-10-21 18:47:46 +020014#include <cpu/x86/mtrr.h>
15#include <cpu/x86/cache.h>
Frans Hendriks4e0ec592019-06-06 10:07:17 +020016#include <cpu/x86/post_code.h>
17
Lee Leahyb5ad8272015-04-20 15:29:16 -070018/*
19 * Replacement for cache_as_ram.inc when using the FSP binary. This code
20 * locates the FSP binary, initializes the cache as RAM and performs the
21 * first stage of initialization. Next this code switches the stack from
22 * the cache to RAM and then disables the cache as RAM. Finally this code
23 * performs the final stage of initialization.
24 */
25
Frans Hendriks4e0ec592019-06-06 10:07:17 +020026#define LHLT_DELAY 0x50000 /* I/O delay between post codes on failure */
27
28.global bootblock_pre_c_entry
29bootblock_pre_c_entry:
Lee Leahyb5ad8272015-04-20 15:29:16 -070030 /*
Kyösti Mälkkiee2e9362018-12-28 16:06:45 +020031 * Per FSP1.1 specs, following registers are preserved:
32 * EBX, EDI, ESI, EBP, MM0, MM1
33 *
34 * Shift values to release MM2.
Arthur Heymans59b65422019-05-23 15:24:30 +020035 * mm0 -> ebx: BIST value
Kyösti Mälkkiee2e9362018-12-28 16:06:45 +020036 * mm1 -> mm0: low 32-bits of TSC value
37 * mm2 -> mm1: high 32-bits of TSC value
Lee Leahyb5ad8272015-04-20 15:29:16 -070038 */
Arthur Heymans59b65422019-05-23 15:24:30 +020039 movd %mm0, %ebx
Kyösti Mälkkiee2e9362018-12-28 16:06:45 +020040 movd %mm1, %eax
41 movd %eax, %mm0
42 movd %mm2, %eax
43 movd %eax, %mm1
44
Lee Leahy3dad4892015-05-05 11:14:02 -070045cache_as_ram:
46 post_code(0x20)
47
Arthur Heymans8256ca02019-10-21 18:47:46 +020048 /* Cache the rom and update the microcode */
49cache_rom:
50 /* Disable cache */
51 movl %cr0, %eax
52 orl $CR0_CacheDisable, %eax
53 movl %eax, %cr0
54
55 movl $MTRR_PHYS_BASE(1), %ecx
56 xorl %edx, %edx
57 movl $(CACHE_ROM_BASE | MTRR_TYPE_WRPROT), %eax
58 wrmsr
59
60 movl $MTRR_PHYS_MASK(1), %ecx
61 rdmsr
62 movl $(~(CACHE_ROM_SIZE - 1) | MTRR_PHYS_MASK_VALID), %eax
63 wrmsr
64
65 /* Enable cache */
66 movl %cr0, %eax
67 andl $(~(CR0_CacheDisable | CR0_NoWriteThrough)), %eax
68 invd
69 movl %eax, %cr0
70
71 /* Enable MTRR. */
72 movl $MTRR_DEF_TYPE_MSR, %ecx
73 rdmsr
74 orl $MTRR_DEF_TYPE_EN, %eax
75 wrmsr
76
77 /* The Google FSP release for Braswell has broken microcode update
78 code and FSP needs the installed microcode revision to be non zero.
79 It is better to have coreboot do it instead of relying on a fragile
80 blob. */
81update_microcode:
82 /* put the return address in %esp */
83 movl $end_microcode_update, %esp
84 jmp update_bsp_microcode
85end_microcode_update:
86
Lee Leahyb5ad8272015-04-20 15:29:16 -070087 /*
Lee Leahy3dad4892015-05-05 11:14:02 -070088 * Find the FSP binary in cbfs.
89 * Make a fake stack that has the return value back to this code.
90 */
Lee Leahyb5ad8272015-04-20 15:29:16 -070091 lea fake_fsp_stack, %esp
92 jmp find_fsp
Lee Leahy3dad4892015-05-05 11:14:02 -070093find_fsp_ret:
94 /* Save the FSP location */
Lee Leahyb5ad8272015-04-20 15:29:16 -070095 mov %eax, %ebp
96
97 /*
98 * Only when a valid FSP binary is found at CONFIG_FSP_LOC is
99 * the returned FSP_INFO_HEADER structure address above the base
100 * address of FSP binary specified by the CONFIG_FSP_LOC value.
101 * All of the error values are in the 0x8xxxxxxx range which are
102 * below the CONFIG_FSP_LOC value.
103 */
104 cmp $CONFIG_FSP_LOC, %eax
105 jbe halt1
Lee Leahy3dad4892015-05-05 11:14:02 -0700106
Duncan Lauriefb509832015-11-22 14:53:57 -0800107 post_code(POST_FSP_TEMP_RAM_INIT)
Lee Leahy3dad4892015-05-05 11:14:02 -0700108
109 /* Calculate entry into FSP */
Lee Leahyb5ad8272015-04-20 15:29:16 -0700110 mov 0x30(%ebp), %eax /* Load TempRamInitEntry */
111 add 0x1c(%ebp), %eax /* add in the offset for FSP */
Lee Leahy3dad4892015-05-05 11:14:02 -0700112
113 /*
114 * Pass early init variables on a fake stack (no memory yet)
115 * as well as the return location
116 */
Lee Leahyb5ad8272015-04-20 15:29:16 -0700117 lea CAR_init_stack, %esp
Lee Leahy3dad4892015-05-05 11:14:02 -0700118
119 /*
Lee Leahyb5ad8272015-04-20 15:29:16 -0700120 * BIST value is zero
121 * eax: TempRamInitApi address
Arthur Heymans59b65422019-05-23 15:24:30 +0200122 * ebx: BIST value
Lee Leahyb5ad8272015-04-20 15:29:16 -0700123 * ebp: FSP_INFO_HEADER address
Lee Leahyb5ad8272015-04-20 15:29:16 -0700124 * esi: Not used
125 * mm0: low 32-bits of TSC value
126 * mm1: high 32-bits of TSC value
Lee Leahy3dad4892015-05-05 11:14:02 -0700127 */
Lee Leahy3dad4892015-05-05 11:14:02 -0700128
Lee Leahyb5ad8272015-04-20 15:29:16 -0700129 /* call FSP binary to setup temporary stack */
130 jmp *%eax
131
132CAR_init_done:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700133
134 /*
135 * ebp: FSP_INFO_HEADER address
Arthur Heymans59b65422019-05-23 15:24:30 +0200136 * ebx: BIST value
Lee Leahyb5ad8272015-04-20 15:29:16 -0700137 * ecx: Temp RAM base
138 * edx: Temp RAM top
Lee Leahyb5ad8272015-04-20 15:29:16 -0700139 * mm0: low 32-bits of TSC value
140 * mm1: high 32-bits of TSC value
141 */
142
143 cmp $0, %eax
144 jne halt2
145
146 /* Setup bootloader stack */
147 movl %edx, %esp
148
Lee Leahyb5ad8272015-04-20 15:29:16 -0700149 /*
150 * ebp: FSP_INFO_HEADER address
Arthur Heymans59b65422019-05-23 15:24:30 +0200151 * ebx: BIST value
Lee Leahyb5ad8272015-04-20 15:29:16 -0700152 * ecx: Temp RAM base
153 * edx: Temp RAM top
154 * esp: Top of stack in temp RAM
155 * mm0: low 32-bits of TSC value
156 * mm1: high 32-bits of TSC value
Lee Leahyb5ad8272015-04-20 15:29:16 -0700157 */
158
Martin Rothe18e6422017-06-03 20:03:18 -0600159 /* coreboot assumes stack/heap region will be zero */
Lee Leahyb5ad8272015-04-20 15:29:16 -0700160 cld
161 movl %ecx, %edi
162 neg %ecx
Arthur Heymans59b65422019-05-23 15:24:30 +0200163 /* Clear up to Temp Ram top. */
164 add %edx, %ecx
Lee Leahyb5ad8272015-04-20 15:29:16 -0700165 shrl $2, %ecx
166 xorl %eax, %eax
167 rep stosl
168
Arthur Heymans59b65422019-05-23 15:24:30 +0200169 /* Need to align stack to 16 bytes at call instruction. Account for
170 the pushes below. */
171 andl $0xfffffff0, %esp
Frans Hendriks4e0ec592019-06-06 10:07:17 +0200172 subl $8, %esp
Arthur Heymans59b65422019-05-23 15:24:30 +0200173
Frans Hendriks4e0ec592019-06-06 10:07:17 +0200174 /* Push initial timestamp on the stack */
Arthur Heymans59b65422019-05-23 15:24:30 +0200175 movd %mm1, %eax
176 pushl %eax /* tsc[63:32] */
177 movd %mm0, %eax
178 pushl %eax /* tsc[31:0] */
179
Lee Leahy3dad4892015-05-05 11:14:02 -0700180before_romstage:
Subrata Banikfbdc7192016-01-19 19:19:15 +0530181 post_code(0x2A)
Lee Leahy3dad4892015-05-05 11:14:02 -0700182
Frans Hendriks4e0ec592019-06-06 10:07:17 +0200183 /* Call bootblock_c_entry(uint64_t base_timestamp) */
184 call bootblock_c_entry
Lee Leahy3dad4892015-05-05 11:14:02 -0700185
Frans Hendriks4e0ec592019-06-06 10:07:17 +0200186 /* Never reached */
Lee Leahy3dad4892015-05-05 11:14:02 -0700187
188halt1:
189 /*
Lee Leahyb5ad8272015-04-20 15:29:16 -0700190 * Failures for postcode 0xBA - failed in fsp_fih_early_find()
Lee Leahy3dad4892015-05-05 11:14:02 -0700191 *
192 * Values are:
193 * 0x01 - FV signature, "_FVH" not present
194 * 0x02 - FFS GUID not present
195 * 0x03 - FSP INFO Header not found
Frans Hendriks683e77e2019-04-29 13:29:36 +0200196 * 0x04 - ImageBase does not equal CONFIG_FSP_LOC - Is the FSP rebased
197 * to a different location, or does it need to be?
Lee Leahy3dad4892015-05-05 11:14:02 -0700198 * 0x05 - FSP INFO Header signature "FSPH" not found
199 * 0x06 - FSP Image ID is not the expected ID.
200 */
Lee Leahyb5ad8272015-04-20 15:29:16 -0700201 movb $0xBA, %ah
202 jmp .Lhlt
Lee Leahy3dad4892015-05-05 11:14:02 -0700203
204halt2:
205 /*
206 * Failures for postcode 0xBB - failed in the FSP:
207 *
208 * 0x00 - FSP_SUCCESS: Temp RAM was initialized successfully.
209 * 0x02 - FSP_INVALID_PARAMETER: Input parameters are invalid.
Lee Leahy3dad4892015-05-05 11:14:02 -0700210 * 0x03 - FSP_UNSUPPORTED: The FSP calling conditions were not met.
211 * 0x07 - FSP_DEVICE_ERROR: Temp RAM initialization failed
Frans Hendriks683e77e2019-04-29 13:29:36 +0200212 * 0x0E - FSP_NOT_FOUND: No valid microcode was found in the microcode
213 * region.
Lee Leahy3dad4892015-05-05 11:14:02 -0700214 * 0x14 - FSP_ALREADY_STARTED: Temp RAM initialization has been invoked
215 */
Lee Leahyb5ad8272015-04-20 15:29:16 -0700216 movb $0xBB, %ah
217 jmp .Lhlt
218
Lee Leahy3dad4892015-05-05 11:14:02 -0700219.Lhlt:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700220 xchg %al, %ah
Julius Wernercd49cce2019-03-05 16:53:33 -0800221#if CONFIG(POST_IO)
Lee Leahyb5ad8272015-04-20 15:29:16 -0700222 outb %al, $CONFIG_POST_IO_PORT
Lee Leahy3dad4892015-05-05 11:14:02 -0700223#else
224 post_code(POST_DEAD_CODE)
225#endif
Lee Leahyb5ad8272015-04-20 15:29:16 -0700226 movl $LHLT_DELAY, %ecx
Lee Leahy3dad4892015-05-05 11:14:02 -0700227.Lhlt_Delay:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700228 outb %al, $0xED
229 loop .Lhlt_Delay
230 jmp .Lhlt
Lee Leahy3dad4892015-05-05 11:14:02 -0700231
232/*
233 * esp is set to this location so that the call into and return from the FSP
234 * in find_fsp will work.
235 */
236 .align 4
237fake_fsp_stack:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700238 .long find_fsp_ret
Lee Leahya8874922015-08-26 14:58:29 -0700239 .long CONFIG_FSP_LOC /* FSP base address */
Lee Leahy3dad4892015-05-05 11:14:02 -0700240
241CAR_init_params:
Arthur Heymans12440ce2019-10-23 11:30:22 +0200242 .long fake_microcode /* Microcode Location */
243 .long fake_microcode_end - fake_microcode /* Microcode Length */
Aaron Durbin2524be42015-10-29 10:43:21 -0500244 .long 0xFFFFFFFF - CONFIG_ROM_SIZE + 1 /* Firmware Location */
Frans Hendriks683e77e2019-04-29 13:29:36 +0200245 .long CONFIG_ROM_SIZE /* Firmware Length */
Lee Leahy3dad4892015-05-05 11:14:02 -0700246
247CAR_init_stack:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700248 .long CAR_init_done
249 .long CAR_init_params
Arthur Heymans12440ce2019-10-23 11:30:22 +0200250
251 /* coreboot updates microcode itself. FSP still needs a pointer
252 to something that looks like microcode, so provide it with fake
253 microcode. */
254fake_microcode:
255fake_microcode_header_start:
256 .long 1 /* Header Version */
257 .long 1 /* Microcode revision */
258 .long 0x10232019 /* Date: Time of writing 23-10-2019 */
259 .long 0x00010ff0 /* Sig: (non existing) Family: 0xf, Model: 0x1f, stepping: 0 */
260 .long 0 /* Checksum: not checked by FSP, so won't care */
261 .long 1 /* Loader Revision */
262 .long 1 /* Processor Flags */
263 .long fake_microcode_end - fake_microcode_header_end /* Data Size */
264 .long fake_microcode_end - fake_microcode /* Total Size */
265 .space 12 /* Reserved */
266fake_microcode_header_end:
267 .space 0x10 /* 16 bytes of empty data */
268fake_microcode_end: