blob: ffafe9b4f349db624b512bbdd6e50fa0550f8871 [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
Frans Hendriks4e0ec592019-06-06 10:07:17 +020014#include <cpu/x86/post_code.h>
15
Lee Leahyb5ad8272015-04-20 15:29:16 -070016/*
17 * Replacement for cache_as_ram.inc when using the FSP binary. This code
18 * locates the FSP binary, initializes the cache as RAM and performs the
19 * first stage of initialization. Next this code switches the stack from
20 * the cache to RAM and then disables the cache as RAM. Finally this code
21 * performs the final stage of initialization.
22 */
23
Frans Hendriks4e0ec592019-06-06 10:07:17 +020024#define LHLT_DELAY 0x50000 /* I/O delay between post codes on failure */
25
26.global bootblock_pre_c_entry
27bootblock_pre_c_entry:
Lee Leahyb5ad8272015-04-20 15:29:16 -070028 /*
Kyösti Mälkkiee2e9362018-12-28 16:06:45 +020029 * Per FSP1.1 specs, following registers are preserved:
30 * EBX, EDI, ESI, EBP, MM0, MM1
31 *
32 * Shift values to release MM2.
Arthur Heymans59b65422019-05-23 15:24:30 +020033 * mm0 -> ebx: BIST value
Kyösti Mälkkiee2e9362018-12-28 16:06:45 +020034 * mm1 -> mm0: low 32-bits of TSC value
35 * mm2 -> mm1: high 32-bits of TSC value
Lee Leahyb5ad8272015-04-20 15:29:16 -070036 */
Arthur Heymans59b65422019-05-23 15:24:30 +020037 movd %mm0, %ebx
Kyösti Mälkkiee2e9362018-12-28 16:06:45 +020038 movd %mm1, %eax
39 movd %eax, %mm0
40 movd %mm2, %eax
41 movd %eax, %mm1
42
Lee Leahy3dad4892015-05-05 11:14:02 -070043cache_as_ram:
44 post_code(0x20)
45
Lee Leahyb5ad8272015-04-20 15:29:16 -070046 /*
Lee Leahy3dad4892015-05-05 11:14:02 -070047 * Find the FSP binary in cbfs.
48 * Make a fake stack that has the return value back to this code.
49 */
Lee Leahyb5ad8272015-04-20 15:29:16 -070050 lea fake_fsp_stack, %esp
51 jmp find_fsp
Lee Leahy3dad4892015-05-05 11:14:02 -070052find_fsp_ret:
53 /* Save the FSP location */
Lee Leahyb5ad8272015-04-20 15:29:16 -070054 mov %eax, %ebp
55
56 /*
57 * Only when a valid FSP binary is found at CONFIG_FSP_LOC is
58 * the returned FSP_INFO_HEADER structure address above the base
59 * address of FSP binary specified by the CONFIG_FSP_LOC value.
60 * All of the error values are in the 0x8xxxxxxx range which are
61 * below the CONFIG_FSP_LOC value.
62 */
63 cmp $CONFIG_FSP_LOC, %eax
64 jbe halt1
Lee Leahy3dad4892015-05-05 11:14:02 -070065
Duncan Lauriefb509832015-11-22 14:53:57 -080066 post_code(POST_FSP_TEMP_RAM_INIT)
Lee Leahy3dad4892015-05-05 11:14:02 -070067
68 /* Calculate entry into FSP */
Lee Leahyb5ad8272015-04-20 15:29:16 -070069 mov 0x30(%ebp), %eax /* Load TempRamInitEntry */
70 add 0x1c(%ebp), %eax /* add in the offset for FSP */
Lee Leahy3dad4892015-05-05 11:14:02 -070071
72 /*
73 * Pass early init variables on a fake stack (no memory yet)
74 * as well as the return location
75 */
Lee Leahyb5ad8272015-04-20 15:29:16 -070076 lea CAR_init_stack, %esp
Lee Leahy3dad4892015-05-05 11:14:02 -070077
78 /*
Lee Leahyb5ad8272015-04-20 15:29:16 -070079 * BIST value is zero
80 * eax: TempRamInitApi address
Arthur Heymans59b65422019-05-23 15:24:30 +020081 * ebx: BIST value
Lee Leahyb5ad8272015-04-20 15:29:16 -070082 * ebp: FSP_INFO_HEADER address
Lee Leahyb5ad8272015-04-20 15:29:16 -070083 * esi: Not used
84 * mm0: low 32-bits of TSC value
85 * mm1: high 32-bits of TSC value
Lee Leahy3dad4892015-05-05 11:14:02 -070086 */
Lee Leahy3dad4892015-05-05 11:14:02 -070087
Lee Leahyb5ad8272015-04-20 15:29:16 -070088 /* call FSP binary to setup temporary stack */
89 jmp *%eax
90
91CAR_init_done:
Lee Leahyb5ad8272015-04-20 15:29:16 -070092
93 /*
94 * ebp: FSP_INFO_HEADER address
Arthur Heymans59b65422019-05-23 15:24:30 +020095 * ebx: BIST value
Lee Leahyb5ad8272015-04-20 15:29:16 -070096 * ecx: Temp RAM base
97 * edx: Temp RAM top
Lee Leahyb5ad8272015-04-20 15:29:16 -070098 * mm0: low 32-bits of TSC value
99 * mm1: high 32-bits of TSC value
100 */
101
102 cmp $0, %eax
103 jne halt2
104
105 /* Setup bootloader stack */
106 movl %edx, %esp
107
Lee Leahyb5ad8272015-04-20 15:29:16 -0700108 /*
109 * ebp: FSP_INFO_HEADER address
Arthur Heymans59b65422019-05-23 15:24:30 +0200110 * ebx: BIST value
Lee Leahyb5ad8272015-04-20 15:29:16 -0700111 * ecx: Temp RAM base
112 * edx: Temp RAM top
113 * esp: Top of stack in temp RAM
114 * mm0: low 32-bits of TSC value
115 * mm1: high 32-bits of TSC value
Lee Leahyb5ad8272015-04-20 15:29:16 -0700116 */
117
Martin Rothe18e6422017-06-03 20:03:18 -0600118 /* coreboot assumes stack/heap region will be zero */
Lee Leahyb5ad8272015-04-20 15:29:16 -0700119 cld
120 movl %ecx, %edi
121 neg %ecx
Arthur Heymans59b65422019-05-23 15:24:30 +0200122 /* Clear up to Temp Ram top. */
123 add %edx, %ecx
Lee Leahyb5ad8272015-04-20 15:29:16 -0700124 shrl $2, %ecx
125 xorl %eax, %eax
126 rep stosl
127
Arthur Heymans59b65422019-05-23 15:24:30 +0200128 /* Need to align stack to 16 bytes at call instruction. Account for
129 the pushes below. */
130 andl $0xfffffff0, %esp
Frans Hendriks4e0ec592019-06-06 10:07:17 +0200131 subl $8, %esp
Arthur Heymans59b65422019-05-23 15:24:30 +0200132
Frans Hendriks4e0ec592019-06-06 10:07:17 +0200133 /* Push initial timestamp on the stack */
Arthur Heymans59b65422019-05-23 15:24:30 +0200134 movd %mm1, %eax
135 pushl %eax /* tsc[63:32] */
136 movd %mm0, %eax
137 pushl %eax /* tsc[31:0] */
138
Lee Leahy3dad4892015-05-05 11:14:02 -0700139before_romstage:
Subrata Banikfbdc7192016-01-19 19:19:15 +0530140 post_code(0x2A)
Lee Leahy3dad4892015-05-05 11:14:02 -0700141
Frans Hendriks4e0ec592019-06-06 10:07:17 +0200142 /* Call bootblock_c_entry(uint64_t base_timestamp) */
143 call bootblock_c_entry
Lee Leahy3dad4892015-05-05 11:14:02 -0700144
Frans Hendriks4e0ec592019-06-06 10:07:17 +0200145 /* Never reached */
Lee Leahy3dad4892015-05-05 11:14:02 -0700146
147halt1:
148 /*
Lee Leahyb5ad8272015-04-20 15:29:16 -0700149 * Failures for postcode 0xBA - failed in fsp_fih_early_find()
Lee Leahy3dad4892015-05-05 11:14:02 -0700150 *
151 * Values are:
152 * 0x01 - FV signature, "_FVH" not present
153 * 0x02 - FFS GUID not present
154 * 0x03 - FSP INFO Header not found
Frans Hendriks683e77e2019-04-29 13:29:36 +0200155 * 0x04 - ImageBase does not equal CONFIG_FSP_LOC - Is the FSP rebased
156 * to a different location, or does it need to be?
Lee Leahy3dad4892015-05-05 11:14:02 -0700157 * 0x05 - FSP INFO Header signature "FSPH" not found
158 * 0x06 - FSP Image ID is not the expected ID.
159 */
Lee Leahyb5ad8272015-04-20 15:29:16 -0700160 movb $0xBA, %ah
161 jmp .Lhlt
Lee Leahy3dad4892015-05-05 11:14:02 -0700162
163halt2:
164 /*
165 * Failures for postcode 0xBB - failed in the FSP:
166 *
167 * 0x00 - FSP_SUCCESS: Temp RAM was initialized successfully.
168 * 0x02 - FSP_INVALID_PARAMETER: Input parameters are invalid.
Lee Leahy3dad4892015-05-05 11:14:02 -0700169 * 0x03 - FSP_UNSUPPORTED: The FSP calling conditions were not met.
170 * 0x07 - FSP_DEVICE_ERROR: Temp RAM initialization failed
Frans Hendriks683e77e2019-04-29 13:29:36 +0200171 * 0x0E - FSP_NOT_FOUND: No valid microcode was found in the microcode
172 * region.
Lee Leahy3dad4892015-05-05 11:14:02 -0700173 * 0x14 - FSP_ALREADY_STARTED: Temp RAM initialization has been invoked
174 */
Lee Leahyb5ad8272015-04-20 15:29:16 -0700175 movb $0xBB, %ah
176 jmp .Lhlt
177
Lee Leahy3dad4892015-05-05 11:14:02 -0700178.Lhlt:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700179 xchg %al, %ah
Julius Wernercd49cce2019-03-05 16:53:33 -0800180#if CONFIG(POST_IO)
Lee Leahyb5ad8272015-04-20 15:29:16 -0700181 outb %al, $CONFIG_POST_IO_PORT
Lee Leahy3dad4892015-05-05 11:14:02 -0700182#else
183 post_code(POST_DEAD_CODE)
184#endif
Lee Leahyb5ad8272015-04-20 15:29:16 -0700185 movl $LHLT_DELAY, %ecx
Lee Leahy3dad4892015-05-05 11:14:02 -0700186.Lhlt_Delay:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700187 outb %al, $0xED
188 loop .Lhlt_Delay
189 jmp .Lhlt
Lee Leahy3dad4892015-05-05 11:14:02 -0700190
191/*
192 * esp is set to this location so that the call into and return from the FSP
193 * in find_fsp will work.
194 */
195 .align 4
196fake_fsp_stack:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700197 .long find_fsp_ret
Lee Leahya8874922015-08-26 14:58:29 -0700198 .long CONFIG_FSP_LOC /* FSP base address */
Lee Leahy3dad4892015-05-05 11:14:02 -0700199
200CAR_init_params:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700201 .long CONFIG_CPU_MICROCODE_CBFS_LOC /* Microcode Location */
202 .long CONFIG_CPU_MICROCODE_CBFS_LEN /* Microcode Length */
Aaron Durbin2524be42015-10-29 10:43:21 -0500203 .long 0xFFFFFFFF - CONFIG_ROM_SIZE + 1 /* Firmware Location */
Frans Hendriks683e77e2019-04-29 13:29:36 +0200204 .long CONFIG_ROM_SIZE /* Firmware Length */
Lee Leahy3dad4892015-05-05 11:14:02 -0700205
206CAR_init_stack:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700207 .long CAR_init_done
208 .long CAR_init_params