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. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 20 | * Foundation, Inc. |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 21 | */ |
| 22 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 23 | /* |
| 24 | * Replacement for cache_as_ram.inc when using the FSP binary. This code |
| 25 | * locates the FSP binary, initializes the cache as RAM and performs the |
| 26 | * first stage of initialization. Next this code switches the stack from |
| 27 | * the cache to RAM and then disables the cache as RAM. Finally this code |
| 28 | * performs the final stage of initialization. |
| 29 | */ |
| 30 | |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 31 | |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 32 | #define LHLT_DELAY 0x50000 /* I/O delay between post codes on failure */ |
| 33 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 34 | /* |
| 35 | * eax: BIST value |
| 36 | * mm0: low 32-bits of TSC value |
| 37 | * mm1: high 32-bits of TSC value |
| 38 | */ |
| 39 | |
| 40 | mov %eax, %edi |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 41 | |
| 42 | cache_as_ram: |
| 43 | post_code(0x20) |
| 44 | |
| 45 | /* |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 46 | * edi: BIST value |
| 47 | * mm0: low 32-bits of TSC value |
| 48 | * mm1: high 32-bits of TSC value |
| 49 | */ |
| 50 | |
| 51 | /* |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 52 | * Find the FSP binary in cbfs. |
| 53 | * Make a fake stack that has the return value back to this code. |
| 54 | */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 55 | lea fake_fsp_stack, %esp |
| 56 | jmp find_fsp |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 57 | find_fsp_ret: |
| 58 | /* Save the FSP location */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 59 | mov %eax, %ebp |
| 60 | |
| 61 | /* |
| 62 | * Only when a valid FSP binary is found at CONFIG_FSP_LOC is |
| 63 | * the returned FSP_INFO_HEADER structure address above the base |
| 64 | * address of FSP binary specified by the CONFIG_FSP_LOC value. |
| 65 | * All of the error values are in the 0x8xxxxxxx range which are |
| 66 | * below the CONFIG_FSP_LOC value. |
| 67 | */ |
| 68 | cmp $CONFIG_FSP_LOC, %eax |
| 69 | jbe halt1 |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 70 | |
| 71 | post_code(0x22) |
| 72 | |
| 73 | /* Calculate entry into FSP */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 74 | mov 0x30(%ebp), %eax /* Load TempRamInitEntry */ |
| 75 | add 0x1c(%ebp), %eax /* add in the offset for FSP */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 76 | |
| 77 | /* |
| 78 | * Pass early init variables on a fake stack (no memory yet) |
| 79 | * as well as the return location |
| 80 | */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 81 | lea CAR_init_stack, %esp |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 82 | |
| 83 | /* |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 84 | * BIST value is zero |
| 85 | * eax: TempRamInitApi address |
| 86 | * ebp: FSP_INFO_HEADER address |
| 87 | * edi: BIST value |
| 88 | * esi: Not used |
| 89 | * mm0: low 32-bits of TSC value |
| 90 | * mm1: high 32-bits of TSC value |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 91 | */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 92 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 93 | /* call FSP binary to setup temporary stack */ |
| 94 | jmp *%eax |
| 95 | |
| 96 | CAR_init_done: |
| 97 | addl $4, %esp |
| 98 | |
| 99 | /* |
| 100 | * ebp: FSP_INFO_HEADER address |
| 101 | * ecx: Temp RAM base |
| 102 | * edx: Temp RAM top |
| 103 | * edi: BIST value |
| 104 | * mm0: low 32-bits of TSC value |
| 105 | * mm1: high 32-bits of TSC value |
| 106 | */ |
| 107 | |
| 108 | cmp $0, %eax |
| 109 | jne halt2 |
| 110 | |
| 111 | /* Setup bootloader stack */ |
| 112 | movl %edx, %esp |
| 113 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 114 | /* |
| 115 | * ebp: FSP_INFO_HEADER address |
| 116 | * ecx: Temp RAM base |
| 117 | * edx: Temp RAM top |
Aaron Durbin | e1ecfc9 | 2015-09-16 15:18:04 -0500 | [diff] [blame] | 118 | * edi: BIST value |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 119 | * esp: Top of stack in temp RAM |
| 120 | * mm0: low 32-bits of TSC value |
| 121 | * mm1: high 32-bits of TSC value |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 122 | */ |
| 123 | |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame^] | 124 | /* Create cache_as_ram_params on stack */ |
Aaron Durbin | e1ecfc9 | 2015-09-16 15:18:04 -0500 | [diff] [blame] | 125 | pushl %edx /* bootloader CAR end */ |
| 126 | pushl %ecx /* bootloader CAR begin */ |
| 127 | pushl %ebp /* FSP_INFO_HEADER */ |
Aaron Durbin | e1ecfc9 | 2015-09-16 15:18:04 -0500 | [diff] [blame] | 128 | pushl %edi /* bist */ |
| 129 | movd %mm1, %eax |
| 130 | pushl %eax /* tsc[63:32] */ |
| 131 | movd %mm0, %eax |
| 132 | pushl %eax /* tsc[31:0] */ |
| 133 | pushl %esp /* pointer to cache_as_ram_params */ |
| 134 | |
| 135 | /* Save FSP_INFO_HEADER location in ebx */ |
| 136 | mov %ebp, %ebx |
| 137 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 138 | /* Coreboot assumes stack/heap region will be zero */ |
| 139 | cld |
| 140 | movl %ecx, %edi |
| 141 | neg %ecx |
Aaron Durbin | e1ecfc9 | 2015-09-16 15:18:04 -0500 | [diff] [blame] | 142 | /* Only clear up to current stack value. */ |
| 143 | add %esp, %ecx |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 144 | shrl $2, %ecx |
| 145 | xorl %eax, %eax |
| 146 | rep stosl |
| 147 | |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 148 | before_romstage: |
| 149 | post_code(0x23) |
| 150 | |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame^] | 151 | /* Call cache_as_ram_main(struct cache_as_ram_params *) */ |
| 152 | call cache_as_ram_main |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 153 | |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame^] | 154 | #include "after_raminit.S" |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 155 | |
| 156 | movb $0x69, %ah |
| 157 | jmp .Lhlt |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 158 | |
| 159 | halt1: |
| 160 | /* |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 161 | * Failures for postcode 0xBA - failed in fsp_fih_early_find() |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 162 | * |
| 163 | * Values are: |
| 164 | * 0x01 - FV signature, "_FVH" not present |
| 165 | * 0x02 - FFS GUID not present |
| 166 | * 0x03 - FSP INFO Header not found |
| 167 | * 0x04 - ImageBase does not equal CONFIG_FSP_LOC - Is the FSP rebased to |
| 168 | * a different location, or does it need to be? |
| 169 | * 0x05 - FSP INFO Header signature "FSPH" not found |
| 170 | * 0x06 - FSP Image ID is not the expected ID. |
| 171 | */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 172 | movb $0xBA, %ah |
| 173 | jmp .Lhlt |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 174 | |
| 175 | halt2: |
| 176 | /* |
| 177 | * Failures for postcode 0xBB - failed in the FSP: |
| 178 | * |
| 179 | * 0x00 - FSP_SUCCESS: Temp RAM was initialized successfully. |
| 180 | * 0x02 - FSP_INVALID_PARAMETER: Input parameters are invalid. |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 181 | * 0x03 - FSP_UNSUPPORTED: The FSP calling conditions were not met. |
| 182 | * 0x07 - FSP_DEVICE_ERROR: Temp RAM initialization failed |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 183 | * 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] | 184 | * 0x14 - FSP_ALREADY_STARTED: Temp RAM initialization has been invoked |
| 185 | */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 186 | movb $0xBB, %ah |
| 187 | jmp .Lhlt |
| 188 | |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 189 | .Lhlt: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 190 | xchg %al, %ah |
| 191 | #if IS_ENABLED(CONFIG_POST_IO) |
| 192 | outb %al, $CONFIG_POST_IO_PORT |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 193 | #else |
| 194 | post_code(POST_DEAD_CODE) |
| 195 | #endif |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 196 | movl $LHLT_DELAY, %ecx |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 197 | .Lhlt_Delay: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 198 | outb %al, $0xED |
| 199 | loop .Lhlt_Delay |
| 200 | jmp .Lhlt |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 201 | |
| 202 | /* |
| 203 | * esp is set to this location so that the call into and return from the FSP |
| 204 | * in find_fsp will work. |
| 205 | */ |
| 206 | .align 4 |
| 207 | fake_fsp_stack: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 208 | .long find_fsp_ret |
Lee Leahy | a887492 | 2015-08-26 14:58:29 -0700 | [diff] [blame] | 209 | .long CONFIG_FSP_LOC /* FSP base address */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 210 | |
| 211 | CAR_init_params: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 212 | .long CONFIG_CPU_MICROCODE_CBFS_LOC /* Microcode Location */ |
| 213 | .long CONFIG_CPU_MICROCODE_CBFS_LEN /* Microcode Length */ |
| 214 | .long 0xFFFFFFFF - CONFIG_CBFS_SIZE + 1 /* Firmware Location */ |
| 215 | .long CONFIG_CBFS_SIZE /* Total Firmware Length */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 216 | |
| 217 | CAR_init_stack: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 218 | .long CAR_init_done |
| 219 | .long CAR_init_params |