blob: af6f3a91e1329dcfc1df421f83b9138e2e28b6b8 [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 */
Subrata Banikfbdc7192016-01-19 19:19:15 +053036 movl %eax, %edi
Lee Leahy3dad4892015-05-05 11:14:02 -070037cache_as_ram:
38 post_code(0x20)
39
Subrata Banikfbdc7192016-01-19 19:19:15 +053040#if IS_ENABLED(CONFIG_SKIP_FSP_CAR)
41
Lee Leahy3dad4892015-05-05 11:14:02 -070042 /*
Subrata Banikfbdc7192016-01-19 19:19:15 +053043 * SOC specific setup
44 * NOTE: This has to preserve the registers
45 * mm0, mm1 and edi.
Lee Leahyb5ad8272015-04-20 15:29:16 -070046 */
Subrata Banikfbdc7192016-01-19 19:19:15 +053047 #include <soc/car_setup.S>
48
49 post_code(0x28)
50
51#endif
Lee Leahyb5ad8272015-04-20 15:29:16 -070052
53 /*
Lee Leahy3dad4892015-05-05 11:14:02 -070054 * Find the FSP binary in cbfs.
55 * Make a fake stack that has the return value back to this code.
56 */
Lee Leahyb5ad8272015-04-20 15:29:16 -070057 lea fake_fsp_stack, %esp
58 jmp find_fsp
Lee Leahy3dad4892015-05-05 11:14:02 -070059find_fsp_ret:
60 /* Save the FSP location */
Lee Leahyb5ad8272015-04-20 15:29:16 -070061 mov %eax, %ebp
62
63 /*
64 * Only when a valid FSP binary is found at CONFIG_FSP_LOC is
65 * the returned FSP_INFO_HEADER structure address above the base
66 * address of FSP binary specified by the CONFIG_FSP_LOC value.
67 * All of the error values are in the 0x8xxxxxxx range which are
68 * below the CONFIG_FSP_LOC value.
69 */
70 cmp $CONFIG_FSP_LOC, %eax
71 jbe halt1
Lee Leahy3dad4892015-05-05 11:14:02 -070072
Duncan Lauriefb509832015-11-22 14:53:57 -080073 post_code(POST_FSP_TEMP_RAM_INIT)
Lee Leahy3dad4892015-05-05 11:14:02 -070074
75 /* Calculate entry into FSP */
Lee Leahyb5ad8272015-04-20 15:29:16 -070076 mov 0x30(%ebp), %eax /* Load TempRamInitEntry */
77 add 0x1c(%ebp), %eax /* add in the offset for FSP */
Lee Leahy3dad4892015-05-05 11:14:02 -070078
79 /*
80 * Pass early init variables on a fake stack (no memory yet)
81 * as well as the return location
82 */
Lee Leahyb5ad8272015-04-20 15:29:16 -070083 lea CAR_init_stack, %esp
Lee Leahy3dad4892015-05-05 11:14:02 -070084
85 /*
Lee Leahyb5ad8272015-04-20 15:29:16 -070086 * BIST value is zero
87 * eax: TempRamInitApi address
88 * ebp: FSP_INFO_HEADER address
89 * edi: BIST value
90 * esi: Not used
91 * mm0: low 32-bits of TSC value
92 * mm1: high 32-bits of TSC value
Lee Leahy3dad4892015-05-05 11:14:02 -070093 */
Lee Leahy3dad4892015-05-05 11:14:02 -070094
Lee Leahyb5ad8272015-04-20 15:29:16 -070095 /* call FSP binary to setup temporary stack */
96 jmp *%eax
97
98CAR_init_done:
99 addl $4, %esp
100
101 /*
102 * ebp: FSP_INFO_HEADER address
103 * ecx: Temp RAM base
104 * edx: Temp RAM top
105 * edi: BIST value
106 * mm0: low 32-bits of TSC value
107 * mm1: high 32-bits of TSC value
108 */
109
110 cmp $0, %eax
111 jne halt2
112
113 /* Setup bootloader stack */
114 movl %edx, %esp
115
Lee Leahyb5ad8272015-04-20 15:29:16 -0700116 /*
117 * ebp: FSP_INFO_HEADER address
118 * ecx: Temp RAM base
119 * edx: Temp RAM top
Aaron Durbine1ecfc92015-09-16 15:18:04 -0500120 * edi: BIST value
Lee Leahyb5ad8272015-04-20 15:29:16 -0700121 * esp: Top of stack in temp RAM
122 * mm0: low 32-bits of TSC value
123 * mm1: high 32-bits of TSC value
Lee Leahyb5ad8272015-04-20 15:29:16 -0700124 */
125
Aaron Durbine6af4be2015-09-24 12:26:31 -0500126 /* Create cache_as_ram_params on stack */
Aaron Durbine1ecfc92015-09-16 15:18:04 -0500127 pushl %edx /* bootloader CAR end */
128 pushl %ecx /* bootloader CAR begin */
129 pushl %ebp /* FSP_INFO_HEADER */
Aaron Durbine1ecfc92015-09-16 15:18:04 -0500130 pushl %edi /* bist */
131 movd %mm1, %eax
132 pushl %eax /* tsc[63:32] */
133 movd %mm0, %eax
Elyes HAOUAS0d8f1da2018-05-28 15:48:04 +0200134 pushl %eax /* tsc[31:0] */
Aaron Durbine1ecfc92015-09-16 15:18:04 -0500135 pushl %esp /* pointer to cache_as_ram_params */
136
137 /* Save FSP_INFO_HEADER location in ebx */
138 mov %ebp, %ebx
139
Martin Rothe18e6422017-06-03 20:03:18 -0600140 /* coreboot assumes stack/heap region will be zero */
Lee Leahyb5ad8272015-04-20 15:29:16 -0700141 cld
142 movl %ecx, %edi
143 neg %ecx
Aaron Durbine1ecfc92015-09-16 15:18:04 -0500144 /* Only clear up to current stack value. */
145 add %esp, %ecx
Lee Leahyb5ad8272015-04-20 15:29:16 -0700146 shrl $2, %ecx
147 xorl %eax, %eax
148 rep stosl
149
Lee Leahy3dad4892015-05-05 11:14:02 -0700150before_romstage:
Subrata Banikfbdc7192016-01-19 19:19:15 +0530151 post_code(0x2A)
Lee Leahy3dad4892015-05-05 11:14:02 -0700152
Aaron Durbine6af4be2015-09-24 12:26:31 -0500153 /* Call cache_as_ram_main(struct cache_as_ram_params *) */
154 call cache_as_ram_main
Lee Leahy3dad4892015-05-05 11:14:02 -0700155
Aaron Durbin909c5122015-09-29 17:41:30 -0500156/* One will never return from cache_as_ram_main() in verstage so there's
Elyes HAOUAS77537312016-07-30 15:37:26 +0200157 * no such thing as after RAM init. */
Aaron Durbin909c5122015-09-29 17:41:30 -0500158#if !ENV_VERSTAGE
Aaron Durbine6af4be2015-09-24 12:26:31 -0500159#include "after_raminit.S"
Aaron Durbin909c5122015-09-29 17:41:30 -0500160#endif
Lee Leahyb5ad8272015-04-20 15:29:16 -0700161
162 movb $0x69, %ah
163 jmp .Lhlt
Lee Leahy3dad4892015-05-05 11:14:02 -0700164
165halt1:
166 /*
Lee Leahyb5ad8272015-04-20 15:29:16 -0700167 * Failures for postcode 0xBA - failed in fsp_fih_early_find()
Lee Leahy3dad4892015-05-05 11:14:02 -0700168 *
169 * Values are:
170 * 0x01 - FV signature, "_FVH" not present
171 * 0x02 - FFS GUID not present
172 * 0x03 - FSP INFO Header not found
173 * 0x04 - ImageBase does not equal CONFIG_FSP_LOC - Is the FSP rebased to
174 * a different location, or does it need to be?
175 * 0x05 - FSP INFO Header signature "FSPH" not found
176 * 0x06 - FSP Image ID is not the expected ID.
177 */
Lee Leahyb5ad8272015-04-20 15:29:16 -0700178 movb $0xBA, %ah
179 jmp .Lhlt
Lee Leahy3dad4892015-05-05 11:14:02 -0700180
181halt2:
182 /*
183 * Failures for postcode 0xBB - failed in the FSP:
184 *
185 * 0x00 - FSP_SUCCESS: Temp RAM was initialized successfully.
186 * 0x02 - FSP_INVALID_PARAMETER: Input parameters are invalid.
Lee Leahy3dad4892015-05-05 11:14:02 -0700187 * 0x03 - FSP_UNSUPPORTED: The FSP calling conditions were not met.
188 * 0x07 - FSP_DEVICE_ERROR: Temp RAM initialization failed
Lee Leahyb5ad8272015-04-20 15:29:16 -0700189 * 0x0E - FSP_NOT_FOUND: No valid microcode was found in the microcode region.
Lee Leahy3dad4892015-05-05 11:14:02 -0700190 * 0x14 - FSP_ALREADY_STARTED: Temp RAM initialization has been invoked
191 */
Lee Leahyb5ad8272015-04-20 15:29:16 -0700192 movb $0xBB, %ah
193 jmp .Lhlt
194
Lee Leahy3dad4892015-05-05 11:14:02 -0700195.Lhlt:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700196 xchg %al, %ah
197#if IS_ENABLED(CONFIG_POST_IO)
198 outb %al, $CONFIG_POST_IO_PORT
Lee Leahy3dad4892015-05-05 11:14:02 -0700199#else
200 post_code(POST_DEAD_CODE)
201#endif
Lee Leahyb5ad8272015-04-20 15:29:16 -0700202 movl $LHLT_DELAY, %ecx
Lee Leahy3dad4892015-05-05 11:14:02 -0700203.Lhlt_Delay:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700204 outb %al, $0xED
205 loop .Lhlt_Delay
206 jmp .Lhlt
Lee Leahy3dad4892015-05-05 11:14:02 -0700207
208/*
209 * esp is set to this location so that the call into and return from the FSP
210 * in find_fsp will work.
211 */
212 .align 4
213fake_fsp_stack:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700214 .long find_fsp_ret
Lee Leahya8874922015-08-26 14:58:29 -0700215 .long CONFIG_FSP_LOC /* FSP base address */
Lee Leahy3dad4892015-05-05 11:14:02 -0700216
217CAR_init_params:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700218 .long CONFIG_CPU_MICROCODE_CBFS_LOC /* Microcode Location */
219 .long CONFIG_CPU_MICROCODE_CBFS_LEN /* Microcode Length */
Aaron Durbin2524be42015-10-29 10:43:21 -0500220 .long 0xFFFFFFFF - CONFIG_ROM_SIZE + 1 /* Firmware Location */
221 .long CONFIG_ROM_SIZE /* Total Firmware Length */
Lee Leahy3dad4892015-05-05 11:14:02 -0700222
223CAR_init_stack:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700224 .long CAR_init_done
225 .long CAR_init_params