blob: 493dbc8d04cba9a95b36851ba7dc681013296cd4 [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
Frans Hendriks683e77e2019-04-29 13:29:36 +020027/* I/O delay between post codes on failure */
28#define LHLT_DELAY 0x50000
Lee Leahyb5ad8272015-04-20 15:29:16 -070029 /*
Kyösti Mälkkiee2e9362018-12-28 16:06:45 +020030 * Per FSP1.1 specs, following registers are preserved:
31 * EBX, EDI, ESI, EBP, MM0, MM1
32 *
33 * Shift values to release MM2.
Arthur Heymans59b65422019-05-23 15:24:30 +020034 * mm0 -> ebx: BIST value
Kyösti Mälkkiee2e9362018-12-28 16:06:45 +020035 * mm1 -> mm0: low 32-bits of TSC value
36 * mm2 -> mm1: high 32-bits of TSC value
Lee Leahyb5ad8272015-04-20 15:29:16 -070037 */
Arthur Heymans59b65422019-05-23 15:24:30 +020038 movd %mm0, %ebx
Kyösti Mälkkiee2e9362018-12-28 16:06:45 +020039 movd %mm1, %eax
40 movd %eax, %mm0
41 movd %mm2, %eax
42 movd %eax, %mm1
43
Lee Leahy3dad4892015-05-05 11:14:02 -070044cache_as_ram:
45 post_code(0x20)
46
Lee Leahyb5ad8272015-04-20 15:29:16 -070047 /*
Lee Leahy3dad4892015-05-05 11:14:02 -070048 * Find the FSP binary in cbfs.
49 * Make a fake stack that has the return value back to this code.
50 */
Lee Leahyb5ad8272015-04-20 15:29:16 -070051 lea fake_fsp_stack, %esp
52 jmp find_fsp
Lee Leahy3dad4892015-05-05 11:14:02 -070053find_fsp_ret:
54 /* Save the FSP location */
Lee Leahyb5ad8272015-04-20 15:29:16 -070055 mov %eax, %ebp
56
57 /*
58 * Only when a valid FSP binary is found at CONFIG_FSP_LOC is
59 * the returned FSP_INFO_HEADER structure address above the base
60 * address of FSP binary specified by the CONFIG_FSP_LOC value.
61 * All of the error values are in the 0x8xxxxxxx range which are
62 * below the CONFIG_FSP_LOC value.
63 */
64 cmp $CONFIG_FSP_LOC, %eax
65 jbe halt1
Lee Leahy3dad4892015-05-05 11:14:02 -070066
Duncan Lauriefb509832015-11-22 14:53:57 -080067 post_code(POST_FSP_TEMP_RAM_INIT)
Lee Leahy3dad4892015-05-05 11:14:02 -070068
69 /* Calculate entry into FSP */
Lee Leahyb5ad8272015-04-20 15:29:16 -070070 mov 0x30(%ebp), %eax /* Load TempRamInitEntry */
71 add 0x1c(%ebp), %eax /* add in the offset for FSP */
Lee Leahy3dad4892015-05-05 11:14:02 -070072
73 /*
74 * Pass early init variables on a fake stack (no memory yet)
75 * as well as the return location
76 */
Lee Leahyb5ad8272015-04-20 15:29:16 -070077 lea CAR_init_stack, %esp
Lee Leahy3dad4892015-05-05 11:14:02 -070078
79 /*
Lee Leahyb5ad8272015-04-20 15:29:16 -070080 * BIST value is zero
81 * eax: TempRamInitApi address
Arthur Heymans59b65422019-05-23 15:24:30 +020082 * ebx: BIST value
Lee Leahyb5ad8272015-04-20 15:29:16 -070083 * ebp: FSP_INFO_HEADER address
Lee Leahyb5ad8272015-04-20 15:29:16 -070084 * esi: Not used
85 * mm0: low 32-bits of TSC value
86 * mm1: high 32-bits of TSC value
Lee Leahy3dad4892015-05-05 11:14:02 -070087 */
Lee Leahy3dad4892015-05-05 11:14:02 -070088
Lee Leahyb5ad8272015-04-20 15:29:16 -070089 /* call FSP binary to setup temporary stack */
90 jmp *%eax
91
92CAR_init_done:
Lee Leahyb5ad8272015-04-20 15:29:16 -070093
94 /*
95 * ebp: FSP_INFO_HEADER address
Arthur Heymans59b65422019-05-23 15:24:30 +020096 * ebx: BIST value
Lee Leahyb5ad8272015-04-20 15:29:16 -070097 * ecx: Temp RAM base
98 * edx: Temp RAM top
Lee Leahyb5ad8272015-04-20 15:29:16 -070099 * mm0: low 32-bits of TSC value
100 * mm1: high 32-bits of TSC value
101 */
102
103 cmp $0, %eax
104 jne halt2
105
106 /* Setup bootloader stack */
107 movl %edx, %esp
108
Lee Leahyb5ad8272015-04-20 15:29:16 -0700109 /*
110 * ebp: FSP_INFO_HEADER address
Arthur Heymans59b65422019-05-23 15:24:30 +0200111 * ebx: BIST value
Lee Leahyb5ad8272015-04-20 15:29:16 -0700112 * ecx: Temp RAM base
113 * edx: Temp RAM top
114 * esp: Top of stack in temp RAM
115 * mm0: low 32-bits of TSC value
116 * mm1: high 32-bits of TSC value
Lee Leahyb5ad8272015-04-20 15:29:16 -0700117 */
118
Martin Rothe18e6422017-06-03 20:03:18 -0600119 /* coreboot assumes stack/heap region will be zero */
Lee Leahyb5ad8272015-04-20 15:29:16 -0700120 cld
121 movl %ecx, %edi
122 neg %ecx
Arthur Heymans59b65422019-05-23 15:24:30 +0200123 /* Clear up to Temp Ram top. */
124 add %edx, %ecx
Lee Leahyb5ad8272015-04-20 15:29:16 -0700125 shrl $2, %ecx
126 xorl %eax, %eax
127 rep stosl
128
Arthur Heymans59b65422019-05-23 15:24:30 +0200129 /* Need to align stack to 16 bytes at call instruction. Account for
130 the pushes below. */
131 andl $0xfffffff0, %esp
132 subl $4, %esp
133
134 /* Push BIST and initial timestamp on the stack */
135 pushl %ebx /* bist */
136 movd %mm1, %eax
137 pushl %eax /* tsc[63:32] */
138 movd %mm0, %eax
139 pushl %eax /* tsc[31:0] */
140
Lee Leahy3dad4892015-05-05 11:14:02 -0700141before_romstage:
Subrata Banikfbdc7192016-01-19 19:19:15 +0530142 post_code(0x2A)
Lee Leahy3dad4892015-05-05 11:14:02 -0700143
Arthur Heymans59b65422019-05-23 15:24:30 +0200144 /* Call bootblock_c_entry_bist(uint64_t base_timestamp, uint32_t bist)
145 in cpu/intel/car/romstage.c */
146 call bootblock_c_entry_bist
Lee Leahy3dad4892015-05-05 11:14:02 -0700147
Lee Leahyb5ad8272015-04-20 15:29:16 -0700148 movb $0x69, %ah
149 jmp .Lhlt
Lee Leahy3dad4892015-05-05 11:14:02 -0700150
151halt1:
152 /*
Lee Leahyb5ad8272015-04-20 15:29:16 -0700153 * Failures for postcode 0xBA - failed in fsp_fih_early_find()
Lee Leahy3dad4892015-05-05 11:14:02 -0700154 *
155 * Values are:
156 * 0x01 - FV signature, "_FVH" not present
157 * 0x02 - FFS GUID not present
158 * 0x03 - FSP INFO Header not found
Frans Hendriks683e77e2019-04-29 13:29:36 +0200159 * 0x04 - ImageBase does not equal CONFIG_FSP_LOC - Is the FSP rebased
160 * to a different location, or does it need to be?
Lee Leahy3dad4892015-05-05 11:14:02 -0700161 * 0x05 - FSP INFO Header signature "FSPH" not found
162 * 0x06 - FSP Image ID is not the expected ID.
163 */
Lee Leahyb5ad8272015-04-20 15:29:16 -0700164 movb $0xBA, %ah
165 jmp .Lhlt
Lee Leahy3dad4892015-05-05 11:14:02 -0700166
167halt2:
168 /*
169 * Failures for postcode 0xBB - failed in the FSP:
170 *
171 * 0x00 - FSP_SUCCESS: Temp RAM was initialized successfully.
172 * 0x02 - FSP_INVALID_PARAMETER: Input parameters are invalid.
Lee Leahy3dad4892015-05-05 11:14:02 -0700173 * 0x03 - FSP_UNSUPPORTED: The FSP calling conditions were not met.
174 * 0x07 - FSP_DEVICE_ERROR: Temp RAM initialization failed
Frans Hendriks683e77e2019-04-29 13:29:36 +0200175 * 0x0E - FSP_NOT_FOUND: No valid microcode was found in the microcode
176 * region.
Lee Leahy3dad4892015-05-05 11:14:02 -0700177 * 0x14 - FSP_ALREADY_STARTED: Temp RAM initialization has been invoked
178 */
Lee Leahyb5ad8272015-04-20 15:29:16 -0700179 movb $0xBB, %ah
180 jmp .Lhlt
181
Lee Leahy3dad4892015-05-05 11:14:02 -0700182.Lhlt:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700183 xchg %al, %ah
Julius Wernercd49cce2019-03-05 16:53:33 -0800184#if CONFIG(POST_IO)
Lee Leahyb5ad8272015-04-20 15:29:16 -0700185 outb %al, $CONFIG_POST_IO_PORT
Lee Leahy3dad4892015-05-05 11:14:02 -0700186#else
187 post_code(POST_DEAD_CODE)
188#endif
Lee Leahyb5ad8272015-04-20 15:29:16 -0700189 movl $LHLT_DELAY, %ecx
Lee Leahy3dad4892015-05-05 11:14:02 -0700190.Lhlt_Delay:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700191 outb %al, $0xED
192 loop .Lhlt_Delay
193 jmp .Lhlt
Lee Leahy3dad4892015-05-05 11:14:02 -0700194
195/*
196 * esp is set to this location so that the call into and return from the FSP
197 * in find_fsp will work.
198 */
199 .align 4
200fake_fsp_stack:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700201 .long find_fsp_ret
Lee Leahya8874922015-08-26 14:58:29 -0700202 .long CONFIG_FSP_LOC /* FSP base address */
Lee Leahy3dad4892015-05-05 11:14:02 -0700203
204CAR_init_params:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700205 .long CONFIG_CPU_MICROCODE_CBFS_LOC /* Microcode Location */
206 .long CONFIG_CPU_MICROCODE_CBFS_LEN /* Microcode Length */
Aaron Durbin2524be42015-10-29 10:43:21 -0500207 .long 0xFFFFFFFF - CONFIG_ROM_SIZE + 1 /* Firmware Location */
Frans Hendriks683e77e2019-04-29 13:29:36 +0200208 .long CONFIG_ROM_SIZE /* Firmware Length */
Lee Leahy3dad4892015-05-05 11:14:02 -0700209
210CAR_init_stack:
Lee Leahyb5ad8272015-04-20 15:29:16 -0700211 .long CAR_init_done
212 .long CAR_init_params