blob: 7d68f3210f225cda79747ba42562ee61e36c188a [file] [log] [blame]
Lee Leahy3dad4892015-05-05 11:14:02 -07001/*
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
6 * Copyright (C) 2013-2014 Sage Electronic Engineering, LLC.
Lee Leahyb5ad8272015-04-20 15:29:16 -07007 * Copyright (C) 2015 Intel Corp.
Lee Leahy3dad4892015-05-05 11:14:02 -07008 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
Lee Leahy3dad4892015-05-05 11:14:02 -070017 */
18
Lee Leahyb5ad8272015-04-20 15:29:16 -070019/*
20 * Replacement for cache_as_ram.inc when using the FSP binary. This code
21 * locates the FSP binary, initializes the cache as RAM and performs the
22 * first stage of initialization. Next this code switches the stack from
23 * the cache to RAM and then disables the cache as RAM. Finally this code
24 * performs the final stage of initialization.
25 */
26
Aaron Durbin909c5122015-09-29 17:41:30 -050027#include <rules.h>
Lee Leahy3dad4892015-05-05 11:14:02 -070028
Lee Leahy3dad4892015-05-05 11:14:02 -070029#define LHLT_DELAY 0x50000 /* I/O delay between post codes on failure */
30
Lee Leahyb5ad8272015-04-20 15:29:16 -070031 /*
32 * eax: BIST value
33 * mm0: low 32-bits of TSC value
34 * mm1: high 32-bits of TSC value
35 */
36
37 mov %eax, %edi
Lee Leahy3dad4892015-05-05 11:14:02 -070038
39cache_as_ram:
40 post_code(0x20)
41
42 /*
Lee Leahyb5ad8272015-04-20 15:29:16 -070043 * edi: BIST value
44 * mm0: low 32-bits of TSC value
45 * mm1: high 32-bits of TSC value
46 */
47
48 /*
Lee Leahy3dad4892015-05-05 11:14:02 -070049 * Find the FSP binary in cbfs.
50 * Make a fake stack that has the return value back to this code.
51 */
Lee Leahyb5ad8272015-04-20 15:29:16 -070052 lea fake_fsp_stack, %esp
53 jmp find_fsp
Lee Leahy3dad4892015-05-05 11:14:02 -070054find_fsp_ret:
55 /* Save the FSP location */
Lee Leahyb5ad8272015-04-20 15:29:16 -070056 mov %eax, %ebp
57
58 /*
59 * Only when a valid FSP binary is found at CONFIG_FSP_LOC is
60 * the returned FSP_INFO_HEADER structure address above the base
61 * address of FSP binary specified by the CONFIG_FSP_LOC value.
62 * All of the error values are in the 0x8xxxxxxx range which are
63 * below the CONFIG_FSP_LOC value.
64 */
65 cmp $CONFIG_FSP_LOC, %eax
66 jbe halt1
Lee Leahy3dad4892015-05-05 11:14:02 -070067
68 post_code(0x22)
69
70 /* Calculate entry into FSP */
Lee Leahyb5ad8272015-04-20 15:29:16 -070071 mov 0x30(%ebp), %eax /* Load TempRamInitEntry */
72 add 0x1c(%ebp), %eax /* add in the offset for FSP */
Lee Leahy3dad4892015-05-05 11:14:02 -070073
74 /*
75 * Pass early init variables on a fake stack (no memory yet)
76 * as well as the return location
77 */
Lee Leahyb5ad8272015-04-20 15:29:16 -070078 lea CAR_init_stack, %esp
Lee Leahy3dad4892015-05-05 11:14:02 -070079
80 /*
Lee Leahyb5ad8272015-04-20 15:29:16 -070081 * BIST value is zero
82 * eax: TempRamInitApi address
83 * ebp: FSP_INFO_HEADER address
84 * edi: BIST value
85 * esi: Not used
86 * mm0: low 32-bits of TSC value
87 * mm1: high 32-bits of TSC value
Lee Leahy3dad4892015-05-05 11:14:02 -070088 */
Lee Leahy3dad4892015-05-05 11:14:02 -070089
Lee Leahyb5ad8272015-04-20 15:29:16 -070090 /* call FSP binary to setup temporary stack */
91 jmp *%eax
92
93CAR_init_done:
94 addl $4, %esp
95
96 /*
97 * ebp: FSP_INFO_HEADER address
98 * ecx: Temp RAM base
99 * edx: Temp RAM top
100 * edi: BIST value
101 * mm0: low 32-bits of TSC value
102 * mm1: high 32-bits of TSC value
103 */
104
105 cmp $0, %eax
106 jne halt2
107
108 /* Setup bootloader stack */
109 movl %edx, %esp
110
Lee Leahyb5ad8272015-04-20 15:29:16 -0700111 /*
112 * ebp: FSP_INFO_HEADER address
113 * ecx: Temp RAM base
114 * edx: Temp RAM top
Aaron Durbine1ecfc92015-09-16 15:18:04 -0500115 * edi: BIST value
Lee Leahyb5ad8272015-04-20 15:29:16 -0700116 * esp: Top of stack in temp RAM
117 * mm0: low 32-bits of TSC value
118 * mm1: high 32-bits of TSC value
Lee Leahyb5ad8272015-04-20 15:29:16 -0700119 */
120
Aaron Durbine6af4be2015-09-24 12:26:31 -0500121 /* Create cache_as_ram_params on stack */
Aaron Durbine1ecfc92015-09-16 15:18:04 -0500122 pushl %edx /* bootloader CAR end */
123 pushl %ecx /* bootloader CAR begin */
124 pushl %ebp /* FSP_INFO_HEADER */
Aaron Durbine1ecfc92015-09-16 15:18:04 -0500125 pushl %edi /* bist */
126 movd %mm1, %eax
127 pushl %eax /* tsc[63:32] */
128 movd %mm0, %eax
129 pushl %eax /* tsc[31:0] */
130 pushl %esp /* pointer to cache_as_ram_params */
131
132 /* Save FSP_INFO_HEADER location in ebx */
133 mov %ebp, %ebx
134
Lee Leahyb5ad8272015-04-20 15:29:16 -0700135 /* Coreboot assumes stack/heap region will be zero */
136 cld
137 movl %ecx, %edi
138 neg %ecx
Aaron Durbine1ecfc92015-09-16 15:18:04 -0500139 /* Only clear up to current stack value. */
140 add %esp, %ecx
Lee Leahyb5ad8272015-04-20 15:29:16 -0700141 shrl $2, %ecx
142 xorl %eax, %eax
143 rep stosl
144
Lee Leahy3dad4892015-05-05 11:14:02 -0700145before_romstage:
146 post_code(0x23)
147
Aaron Durbine6af4be2015-09-24 12:26:31 -0500148 /* Call cache_as_ram_main(struct cache_as_ram_params *) */
149 call cache_as_ram_main
Lee Leahy3dad4892015-05-05 11:14:02 -0700150
Aaron Durbin909c5122015-09-29 17:41:30 -0500151/* One will never return from cache_as_ram_main() in verstage so there's
152 * no such thing as after ram init. */
153#if !ENV_VERSTAGE
Aaron Durbine6af4be2015-09-24 12:26:31 -0500154#include "after_raminit.S"
Aaron Durbin909c5122015-09-29 17:41:30 -0500155#endif
Lee Leahyb5ad8272015-04-20 15:29:16 -0700156
157 movb $0x69, %ah
158 jmp .Lhlt
Lee Leahy3dad4892015-05-05 11:14:02 -0700159
160halt1:
161 /*
Lee Leahyb5ad8272015-04-20 15:29:16 -0700162 * Failures for postcode 0xBA - failed in fsp_fih_early_find()
Lee Leahy3dad4892015-05-05 11:14:02 -0700163 *
164 * Values are:
165 * 0x01 - FV signature, "_FVH" not present
166 * 0x02 - FFS GUID not present
167 * 0x03 - FSP INFO Header not found
168 * 0x04 - ImageBase does not equal CONFIG_FSP_LOC - Is the FSP rebased to
169 * a different location, or does it need to be?
170 * 0x05 - FSP INFO Header signature "FSPH" not found
171 * 0x06 - FSP Image ID is not the expected ID.
172 */
Lee Leahyb5ad8272015-04-20 15:29:16 -0700173 movb $0xBA, %ah
174 jmp .Lhlt
Lee Leahy3dad4892015-05-05 11:14:02 -0700175
176halt2:
177 /*
178 * Failures for postcode 0xBB - failed in the FSP:
179 *
180 * 0x00 - FSP_SUCCESS: Temp RAM was initialized successfully.
181 * 0x02 - FSP_INVALID_PARAMETER: Input parameters are invalid.
Lee Leahy3dad4892015-05-05 11:14:02 -0700182 * 0x03 - FSP_UNSUPPORTED: The FSP calling conditions were not met.
183 * 0x07 - FSP_DEVICE_ERROR: Temp RAM initialization failed
Lee Leahyb5ad8272015-04-20 15:29:16 -0700184 * 0x0E - FSP_NOT_FOUND: No valid microcode was found in the microcode region.
Lee Leahy3dad4892015-05-05 11:14:02 -0700185 * 0x14 - FSP_ALREADY_STARTED: Temp RAM initialization has been invoked
186 */
Lee Leahyb5ad8272015-04-20 15:29:16 -0700187 movb $0xBB, %ah
188 jmp .Lhlt
189
Lee Leahy3dad4892015-05-05 11:14:02 -0700190.Lhlt:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700191 xchg %al, %ah
192#if IS_ENABLED(CONFIG_POST_IO)
193 outb %al, $CONFIG_POST_IO_PORT
Lee Leahy3dad4892015-05-05 11:14:02 -0700194#else
195 post_code(POST_DEAD_CODE)
196#endif
Lee Leahyb5ad8272015-04-20 15:29:16 -0700197 movl $LHLT_DELAY, %ecx
Lee Leahy3dad4892015-05-05 11:14:02 -0700198.Lhlt_Delay:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700199 outb %al, $0xED
200 loop .Lhlt_Delay
201 jmp .Lhlt
Lee Leahy3dad4892015-05-05 11:14:02 -0700202
203/*
204 * esp is set to this location so that the call into and return from the FSP
205 * in find_fsp will work.
206 */
207 .align 4
208fake_fsp_stack:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700209 .long find_fsp_ret
Lee Leahya8874922015-08-26 14:58:29 -0700210 .long CONFIG_FSP_LOC /* FSP base address */
Lee Leahy3dad4892015-05-05 11:14:02 -0700211
212CAR_init_params:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700213 .long CONFIG_CPU_MICROCODE_CBFS_LOC /* Microcode Location */
214 .long CONFIG_CPU_MICROCODE_CBFS_LEN /* Microcode Length */
Aaron Durbin2524be42015-10-29 10:43:21 -0500215 .long 0xFFFFFFFF - CONFIG_ROM_SIZE + 1 /* Firmware Location */
216 .long CONFIG_ROM_SIZE /* Total Firmware Length */
Lee Leahy3dad4892015-05-05 11:14:02 -0700217
218CAR_init_stack:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700219 .long CAR_init_done
220 .long CAR_init_params