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 | |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 27 | #include <rules.h> |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 28 | |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 29 | #define LHLT_DELAY 0x50000 /* I/O delay between post codes on failure */ |
| 30 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 31 | /* |
| 32 | * eax: BIST value |
| 33 | * mm0: low 32-bits of TSC value |
| 34 | * mm1: high 32-bits of TSC value |
| 35 | */ |
Subrata Banik | fbdc719 | 2016-01-19 19:19:15 +0530 | [diff] [blame] | 36 | movl %eax, %edi |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 37 | cache_as_ram: |
| 38 | post_code(0x20) |
| 39 | |
Subrata Banik | fbdc719 | 2016-01-19 19:19:15 +0530 | [diff] [blame] | 40 | #if IS_ENABLED(CONFIG_SKIP_FSP_CAR) |
| 41 | |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 42 | /* |
Subrata Banik | fbdc719 | 2016-01-19 19:19:15 +0530 | [diff] [blame] | 43 | * SOC specific setup |
| 44 | * NOTE: This has to preserve the registers |
| 45 | * mm0, mm1 and edi. |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 46 | */ |
Subrata Banik | fbdc719 | 2016-01-19 19:19:15 +0530 | [diff] [blame] | 47 | #include <soc/car_setup.S> |
| 48 | |
| 49 | post_code(0x28) |
| 50 | |
| 51 | #endif |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 52 | |
| 53 | /* |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 54 | * Find the FSP binary in cbfs. |
| 55 | * Make a fake stack that has the return value back to this code. |
| 56 | */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 57 | lea fake_fsp_stack, %esp |
| 58 | jmp find_fsp |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 59 | find_fsp_ret: |
| 60 | /* Save the FSP location */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 61 | 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 Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 72 | |
Duncan Laurie | fb50983 | 2015-11-22 14:53:57 -0800 | [diff] [blame] | 73 | post_code(POST_FSP_TEMP_RAM_INIT) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 74 | |
| 75 | /* Calculate entry into FSP */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 76 | mov 0x30(%ebp), %eax /* Load TempRamInitEntry */ |
| 77 | add 0x1c(%ebp), %eax /* add in the offset for FSP */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 78 | |
| 79 | /* |
| 80 | * Pass early init variables on a fake stack (no memory yet) |
| 81 | * as well as the return location |
| 82 | */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 83 | lea CAR_init_stack, %esp |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 84 | |
| 85 | /* |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 86 | * 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 Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 93 | */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 94 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 95 | /* call FSP binary to setup temporary stack */ |
| 96 | jmp *%eax |
| 97 | |
| 98 | CAR_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 Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 116 | /* |
| 117 | * ebp: FSP_INFO_HEADER address |
| 118 | * ecx: Temp RAM base |
| 119 | * edx: Temp RAM top |
Aaron Durbin | e1ecfc9 | 2015-09-16 15:18:04 -0500 | [diff] [blame] | 120 | * edi: BIST value |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 121 | * esp: Top of stack in temp RAM |
| 122 | * mm0: low 32-bits of TSC value |
| 123 | * mm1: high 32-bits of TSC value |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 124 | */ |
| 125 | |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 126 | /* Create cache_as_ram_params on stack */ |
Aaron Durbin | e1ecfc9 | 2015-09-16 15:18:04 -0500 | [diff] [blame] | 127 | pushl %edx /* bootloader CAR end */ |
| 128 | pushl %ecx /* bootloader CAR begin */ |
| 129 | pushl %ebp /* FSP_INFO_HEADER */ |
Aaron Durbin | e1ecfc9 | 2015-09-16 15:18:04 -0500 | [diff] [blame] | 130 | pushl %edi /* bist */ |
| 131 | movd %mm1, %eax |
| 132 | pushl %eax /* tsc[63:32] */ |
| 133 | movd %mm0, %eax |
| 134 | pushl %eax /* tsc[31:0] */ |
| 135 | pushl %esp /* pointer to cache_as_ram_params */ |
| 136 | |
| 137 | /* Save FSP_INFO_HEADER location in ebx */ |
| 138 | mov %ebp, %ebx |
| 139 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 140 | /* Coreboot assumes stack/heap region will be zero */ |
| 141 | cld |
| 142 | movl %ecx, %edi |
| 143 | neg %ecx |
Aaron Durbin | e1ecfc9 | 2015-09-16 15:18:04 -0500 | [diff] [blame] | 144 | /* Only clear up to current stack value. */ |
| 145 | add %esp, %ecx |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 146 | shrl $2, %ecx |
| 147 | xorl %eax, %eax |
| 148 | rep stosl |
| 149 | |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 150 | before_romstage: |
Subrata Banik | fbdc719 | 2016-01-19 19:19:15 +0530 | [diff] [blame] | 151 | post_code(0x2A) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 152 | |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 153 | /* Call cache_as_ram_main(struct cache_as_ram_params *) */ |
| 154 | call cache_as_ram_main |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 155 | |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 156 | /* 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^] | 157 | * no such thing as after RAM init. */ |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 158 | #if !ENV_VERSTAGE |
Aaron Durbin | e6af4be | 2015-09-24 12:26:31 -0500 | [diff] [blame] | 159 | #include "after_raminit.S" |
Aaron Durbin | 909c512 | 2015-09-29 17:41:30 -0500 | [diff] [blame] | 160 | #endif |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 161 | |
| 162 | movb $0x69, %ah |
| 163 | jmp .Lhlt |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 164 | |
| 165 | halt1: |
| 166 | /* |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 167 | * Failures for postcode 0xBA - failed in fsp_fih_early_find() |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 168 | * |
| 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 Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 178 | movb $0xBA, %ah |
| 179 | jmp .Lhlt |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 180 | |
| 181 | halt2: |
| 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 Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 187 | * 0x03 - FSP_UNSUPPORTED: The FSP calling conditions were not met. |
| 188 | * 0x07 - FSP_DEVICE_ERROR: Temp RAM initialization failed |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 189 | * 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] | 190 | * 0x14 - FSP_ALREADY_STARTED: Temp RAM initialization has been invoked |
| 191 | */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 192 | movb $0xBB, %ah |
| 193 | jmp .Lhlt |
| 194 | |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 195 | .Lhlt: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 196 | xchg %al, %ah |
| 197 | #if IS_ENABLED(CONFIG_POST_IO) |
| 198 | outb %al, $CONFIG_POST_IO_PORT |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 199 | #else |
| 200 | post_code(POST_DEAD_CODE) |
| 201 | #endif |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 202 | movl $LHLT_DELAY, %ecx |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 203 | .Lhlt_Delay: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 204 | outb %al, $0xED |
| 205 | loop .Lhlt_Delay |
| 206 | jmp .Lhlt |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 207 | |
| 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 |
| 213 | fake_fsp_stack: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 214 | .long find_fsp_ret |
Lee Leahy | a887492 | 2015-08-26 14:58:29 -0700 | [diff] [blame] | 215 | .long CONFIG_FSP_LOC /* FSP base address */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 216 | |
| 217 | CAR_init_params: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 218 | .long CONFIG_CPU_MICROCODE_CBFS_LOC /* Microcode Location */ |
| 219 | .long CONFIG_CPU_MICROCODE_CBFS_LEN /* Microcode Length */ |
Aaron Durbin | 2524be4 | 2015-10-29 10:43:21 -0500 | [diff] [blame] | 220 | .long 0xFFFFFFFF - CONFIG_ROM_SIZE + 1 /* Firmware Location */ |
| 221 | .long CONFIG_ROM_SIZE /* Total Firmware Length */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 222 | |
| 223 | CAR_init_stack: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 224 | .long CAR_init_done |
| 225 | .long CAR_init_params |