Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 1 | /* |
| 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 Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 7 | * Copyright (C) 2015 Intel Corp. |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 8 | * |
| 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 Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 17 | */ |
| 18 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 19 | /* |
| 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 | |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 27 | |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 28 | #define LHLT_DELAY 0x50000 /* I/O delay between post codes on failure */ |
| 29 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 30 | /* |
Kyösti Mälkki | ee2e936 | 2018-12-28 16:06:45 +0200 | [diff] [blame] | 31 | * Per FSP1.1 specs, following registers are preserved: |
| 32 | * EBX, EDI, ESI, EBP, MM0, MM1 |
| 33 | * |
| 34 | * Shift values to release MM2. |
| 35 | * mm0 -> edi: BIST value |
| 36 | * mm1 -> mm0: low 32-bits of TSC value |
| 37 | * mm2 -> mm1: high 32-bits of TSC value |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 38 | */ |
Kyösti Mälkki | ee2e936 | 2018-12-28 16:06:45 +0200 | [diff] [blame] | 39 | movd %mm0, %edi |
| 40 | movd %mm1, %eax |
| 41 | movd %eax, %mm0 |
| 42 | movd %mm2, %eax |
| 43 | movd %eax, %mm1 |
| 44 | |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 45 | cache_as_ram: |
| 46 | post_code(0x20) |
| 47 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 48 | /* |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 49 | * Find the FSP binary in cbfs. |
| 50 | * Make a fake stack that has the return value back to this code. |
| 51 | */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 52 | lea fake_fsp_stack, %esp |
| 53 | jmp find_fsp |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 54 | find_fsp_ret: |
| 55 | /* Save the FSP location */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 56 | 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 Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 67 | |
Duncan Laurie | fb50983 | 2015-11-22 14:53:57 -0800 | [diff] [blame] | 68 | post_code(POST_FSP_TEMP_RAM_INIT) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 69 | |
| 70 | /* Calculate entry into FSP */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 71 | mov 0x30(%ebp), %eax /* Load TempRamInitEntry */ |
| 72 | add 0x1c(%ebp), %eax /* add in the offset for FSP */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * Pass early init variables on a fake stack (no memory yet) |
| 76 | * as well as the return location |
| 77 | */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 78 | lea CAR_init_stack, %esp |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 79 | |
| 80 | /* |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 81 | * 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 Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 88 | */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 89 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 90 | /* call FSP binary to setup temporary stack */ |
| 91 | jmp *%eax |
| 92 | |
| 93 | CAR_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 Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 111 | /* |
| 112 | * ebp: FSP_INFO_HEADER address |
| 113 | * ecx: Temp RAM base |
| 114 | * edx: Temp RAM top |
Aaron Durbin | e1ecfc9 | 2015-09-16 15:18:04 -0500 | [diff] [blame] | 115 | * edi: BIST value |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 116 | * esp: Top of stack in temp RAM |
| 117 | * mm0: low 32-bits of TSC value |
| 118 | * mm1: high 32-bits of TSC value |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 119 | */ |
| 120 | |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 121 | /* Create cache_as_ram_params on stack */ |
Aaron Durbin | e1ecfc9 | 2015-09-16 15:18:04 -0500 | [diff] [blame] | 122 | pushl %edx /* bootloader CAR end */ |
| 123 | pushl %ecx /* bootloader CAR begin */ |
| 124 | pushl %ebp /* FSP_INFO_HEADER */ |
Aaron Durbin | e1ecfc9 | 2015-09-16 15:18:04 -0500 | [diff] [blame] | 125 | pushl %edi /* bist */ |
| 126 | movd %mm1, %eax |
| 127 | pushl %eax /* tsc[63:32] */ |
| 128 | movd %mm0, %eax |
Elyes HAOUAS | 0d8f1da | 2018-05-28 15:48:04 +0200 | [diff] [blame] | 129 | pushl %eax /* tsc[31:0] */ |
Aaron Durbin | e1ecfc9 | 2015-09-16 15:18:04 -0500 | [diff] [blame] | 130 | pushl %esp /* pointer to cache_as_ram_params */ |
| 131 | |
| 132 | /* Save FSP_INFO_HEADER location in ebx */ |
| 133 | mov %ebp, %ebx |
| 134 | |
Martin Roth | e18e642 | 2017-06-03 20:03:18 -0600 | [diff] [blame] | 135 | /* coreboot assumes stack/heap region will be zero */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 136 | cld |
| 137 | movl %ecx, %edi |
| 138 | neg %ecx |
Aaron Durbin | e1ecfc9 | 2015-09-16 15:18:04 -0500 | [diff] [blame] | 139 | /* Only clear up to current stack value. */ |
| 140 | add %esp, %ecx |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 141 | shrl $2, %ecx |
| 142 | xorl %eax, %eax |
| 143 | rep stosl |
| 144 | |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 145 | before_romstage: |
Subrata Banik | fbdc719 | 2016-01-19 19:19:15 +0530 | [diff] [blame] | 146 | post_code(0x2A) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 147 | |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 148 | /* Call cache_as_ram_main(struct cache_as_ram_params *) */ |
| 149 | call cache_as_ram_main |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 150 | |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 151 | /* One will never return from cache_as_ram_main() in verstage so there's |
Elyes HAOUAS | 7753731 | 2016-07-30 15:37:26 +0200 | [diff] [blame] | 152 | * no such thing as after RAM init. */ |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 153 | #if !ENV_VERSTAGE |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 154 | #include "after_raminit.S" |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 155 | #endif |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 156 | |
| 157 | movb $0x69, %ah |
| 158 | jmp .Lhlt |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 159 | |
| 160 | halt1: |
| 161 | /* |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 162 | * Failures for postcode 0xBA - failed in fsp_fih_early_find() |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 163 | * |
| 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 Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 173 | movb $0xBA, %ah |
| 174 | jmp .Lhlt |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 175 | |
| 176 | halt2: |
| 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 Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 182 | * 0x03 - FSP_UNSUPPORTED: The FSP calling conditions were not met. |
| 183 | * 0x07 - FSP_DEVICE_ERROR: Temp RAM initialization failed |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 184 | * 0x0E - FSP_NOT_FOUND: No valid microcode was found in the microcode region. |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 185 | * 0x14 - FSP_ALREADY_STARTED: Temp RAM initialization has been invoked |
| 186 | */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 187 | movb $0xBB, %ah |
| 188 | jmp .Lhlt |
| 189 | |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 190 | .Lhlt: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 191 | xchg %al, %ah |
| 192 | #if IS_ENABLED(CONFIG_POST_IO) |
| 193 | outb %al, $CONFIG_POST_IO_PORT |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 194 | #else |
| 195 | post_code(POST_DEAD_CODE) |
| 196 | #endif |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 197 | movl $LHLT_DELAY, %ecx |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 198 | .Lhlt_Delay: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 199 | outb %al, $0xED |
| 200 | loop .Lhlt_Delay |
| 201 | jmp .Lhlt |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 202 | |
| 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 |
| 208 | fake_fsp_stack: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 209 | .long find_fsp_ret |
Lee Leahy | a887492 | 2015-08-26 14:58:29 -0700 | [diff] [blame] | 210 | .long CONFIG_FSP_LOC /* FSP base address */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 211 | |
| 212 | CAR_init_params: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 213 | .long CONFIG_CPU_MICROCODE_CBFS_LOC /* Microcode Location */ |
| 214 | .long CONFIG_CPU_MICROCODE_CBFS_LEN /* Microcode Length */ |
Aaron Durbin | 2524be4 | 2015-10-29 10:43:21 -0500 | [diff] [blame] | 215 | .long 0xFFFFFFFF - CONFIG_ROM_SIZE + 1 /* Firmware Location */ |
| 216 | .long CONFIG_ROM_SIZE /* Total Firmware Length */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 217 | |
| 218 | CAR_init_stack: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 219 | .long CAR_init_done |
| 220 | .long CAR_init_params |