Angel Pons | 8a3453f | 2020-04-02 23:48:19 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 2 | |
Arthur Heymans | 8256ca0 | 2019-10-21 18:47:46 +0200 | [diff] [blame] | 3 | #include <cpu/x86/mtrr.h> |
| 4 | #include <cpu/x86/cache.h> |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 5 | #include <cpu/x86/post_code.h> |
| 6 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 7 | /* |
| 8 | * Replacement for cache_as_ram.inc when using the FSP binary. This code |
| 9 | * locates the FSP binary, initializes the cache as RAM and performs the |
| 10 | * first stage of initialization. Next this code switches the stack from |
| 11 | * the cache to RAM and then disables the cache as RAM. Finally this code |
| 12 | * performs the final stage of initialization. |
| 13 | */ |
| 14 | |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 15 | #define LHLT_DELAY 0x50000 /* I/O delay between post codes on failure */ |
| 16 | |
| 17 | .global bootblock_pre_c_entry |
| 18 | bootblock_pre_c_entry: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 19 | /* |
Kyösti Mälkki | ee2e936 | 2018-12-28 16:06:45 +0200 | [diff] [blame] | 20 | * Per FSP1.1 specs, following registers are preserved: |
| 21 | * EBX, EDI, ESI, EBP, MM0, MM1 |
| 22 | * |
| 23 | * Shift values to release MM2. |
Arthur Heymans | 59b6542 | 2019-05-23 15:24:30 +0200 | [diff] [blame] | 24 | * mm0 -> ebx: BIST value |
Kyösti Mälkki | ee2e936 | 2018-12-28 16:06:45 +0200 | [diff] [blame] | 25 | * mm1 -> mm0: low 32-bits of TSC value |
| 26 | * mm2 -> mm1: high 32-bits of TSC value |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 27 | */ |
Arthur Heymans | 59b6542 | 2019-05-23 15:24:30 +0200 | [diff] [blame] | 28 | movd %mm0, %ebx |
Kyösti Mälkki | ee2e936 | 2018-12-28 16:06:45 +0200 | [diff] [blame] | 29 | movd %mm1, %eax |
| 30 | movd %eax, %mm0 |
| 31 | movd %mm2, %eax |
| 32 | movd %eax, %mm1 |
| 33 | |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 34 | cache_as_ram: |
| 35 | post_code(0x20) |
| 36 | |
Arthur Heymans | 8256ca0 | 2019-10-21 18:47:46 +0200 | [diff] [blame] | 37 | /* Cache the rom and update the microcode */ |
| 38 | cache_rom: |
| 39 | /* Disable cache */ |
| 40 | movl %cr0, %eax |
| 41 | orl $CR0_CacheDisable, %eax |
| 42 | movl %eax, %cr0 |
| 43 | |
| 44 | movl $MTRR_PHYS_BASE(1), %ecx |
| 45 | xorl %edx, %edx |
| 46 | movl $(CACHE_ROM_BASE | MTRR_TYPE_WRPROT), %eax |
| 47 | wrmsr |
| 48 | |
| 49 | movl $MTRR_PHYS_MASK(1), %ecx |
| 50 | rdmsr |
| 51 | movl $(~(CACHE_ROM_SIZE - 1) | MTRR_PHYS_MASK_VALID), %eax |
| 52 | wrmsr |
| 53 | |
| 54 | /* Enable cache */ |
| 55 | movl %cr0, %eax |
| 56 | andl $(~(CR0_CacheDisable | CR0_NoWriteThrough)), %eax |
| 57 | invd |
| 58 | movl %eax, %cr0 |
| 59 | |
| 60 | /* Enable MTRR. */ |
| 61 | movl $MTRR_DEF_TYPE_MSR, %ecx |
| 62 | rdmsr |
| 63 | orl $MTRR_DEF_TYPE_EN, %eax |
| 64 | wrmsr |
| 65 | |
| 66 | /* The Google FSP release for Braswell has broken microcode update |
| 67 | code and FSP needs the installed microcode revision to be non zero. |
| 68 | It is better to have coreboot do it instead of relying on a fragile |
| 69 | blob. */ |
| 70 | update_microcode: |
| 71 | /* put the return address in %esp */ |
| 72 | movl $end_microcode_update, %esp |
| 73 | jmp update_bsp_microcode |
| 74 | end_microcode_update: |
| 75 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 76 | /* |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 77 | * Find the FSP binary in cbfs. |
| 78 | * Make a fake stack that has the return value back to this code. |
| 79 | */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 80 | lea fake_fsp_stack, %esp |
| 81 | jmp find_fsp |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 82 | find_fsp_ret: |
| 83 | /* Save the FSP location */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 84 | mov %eax, %ebp |
| 85 | |
| 86 | /* |
| 87 | * Only when a valid FSP binary is found at CONFIG_FSP_LOC is |
| 88 | * the returned FSP_INFO_HEADER structure address above the base |
| 89 | * address of FSP binary specified by the CONFIG_FSP_LOC value. |
| 90 | * All of the error values are in the 0x8xxxxxxx range which are |
| 91 | * below the CONFIG_FSP_LOC value. |
| 92 | */ |
| 93 | cmp $CONFIG_FSP_LOC, %eax |
| 94 | jbe halt1 |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 95 | |
Duncan Laurie | fb50983 | 2015-11-22 14:53:57 -0800 | [diff] [blame] | 96 | post_code(POST_FSP_TEMP_RAM_INIT) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 97 | |
| 98 | /* Calculate entry into FSP */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 99 | mov 0x30(%ebp), %eax /* Load TempRamInitEntry */ |
| 100 | add 0x1c(%ebp), %eax /* add in the offset for FSP */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 101 | |
| 102 | /* |
| 103 | * Pass early init variables on a fake stack (no memory yet) |
| 104 | * as well as the return location |
| 105 | */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 106 | lea CAR_init_stack, %esp |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 107 | |
| 108 | /* |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 109 | * BIST value is zero |
| 110 | * eax: TempRamInitApi address |
Arthur Heymans | 59b6542 | 2019-05-23 15:24:30 +0200 | [diff] [blame] | 111 | * ebx: BIST value |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 112 | * ebp: FSP_INFO_HEADER address |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 113 | * esi: Not used |
| 114 | * mm0: low 32-bits of TSC value |
| 115 | * mm1: high 32-bits of TSC value |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 116 | */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 117 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 118 | /* call FSP binary to setup temporary stack */ |
| 119 | jmp *%eax |
| 120 | |
| 121 | CAR_init_done: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 122 | |
| 123 | /* |
| 124 | * ebp: FSP_INFO_HEADER address |
Arthur Heymans | 59b6542 | 2019-05-23 15:24:30 +0200 | [diff] [blame] | 125 | * ebx: BIST value |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 126 | * ecx: Temp RAM base |
| 127 | * edx: Temp RAM top |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 128 | * mm0: low 32-bits of TSC value |
| 129 | * mm1: high 32-bits of TSC value |
| 130 | */ |
| 131 | |
| 132 | cmp $0, %eax |
| 133 | jne halt2 |
| 134 | |
| 135 | /* Setup bootloader stack */ |
Frans Hendriks | 7ba970a | 2020-11-19 08:10:47 +0100 | [diff] [blame] | 136 | movl $_ecar_stack, %esp |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 137 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 138 | /* |
| 139 | * ebp: FSP_INFO_HEADER address |
Arthur Heymans | 59b6542 | 2019-05-23 15:24:30 +0200 | [diff] [blame] | 140 | * ebx: BIST value |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 141 | * ecx: Temp RAM base |
| 142 | * edx: Temp RAM top |
| 143 | * esp: Top of stack in temp RAM |
| 144 | * mm0: low 32-bits of TSC value |
| 145 | * mm1: high 32-bits of TSC value |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 146 | */ |
| 147 | |
Frans Hendriks | 335eb12 | 2020-11-19 15:45:43 +0100 | [diff] [blame^] | 148 | /* clear .bss section */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 149 | cld |
Frans Hendriks | 335eb12 | 2020-11-19 15:45:43 +0100 | [diff] [blame^] | 150 | xor %eax, %eax |
| 151 | movl $(_ebss), %ecx |
| 152 | movl $(_bss), %edi |
| 153 | sub %edi, %ecx |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 154 | shrl $2, %ecx |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 155 | rep stosl |
| 156 | |
Arthur Heymans | 59b6542 | 2019-05-23 15:24:30 +0200 | [diff] [blame] | 157 | /* Need to align stack to 16 bytes at call instruction. Account for |
| 158 | the pushes below. */ |
| 159 | andl $0xfffffff0, %esp |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 160 | subl $8, %esp |
Arthur Heymans | 59b6542 | 2019-05-23 15:24:30 +0200 | [diff] [blame] | 161 | |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 162 | /* Push initial timestamp on the stack */ |
Arthur Heymans | 59b6542 | 2019-05-23 15:24:30 +0200 | [diff] [blame] | 163 | movd %mm1, %eax |
| 164 | pushl %eax /* tsc[63:32] */ |
| 165 | movd %mm0, %eax |
| 166 | pushl %eax /* tsc[31:0] */ |
| 167 | |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 168 | before_romstage: |
Subrata Banik | fbdc719 | 2016-01-19 19:19:15 +0530 | [diff] [blame] | 169 | post_code(0x2A) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 170 | |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 171 | /* Call bootblock_c_entry(uint64_t base_timestamp) */ |
| 172 | call bootblock_c_entry |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 173 | |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 174 | /* Never reached */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 175 | |
| 176 | halt1: |
| 177 | /* |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 178 | * Failures for postcode 0xBA - failed in fsp_fih_early_find() |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 179 | * |
| 180 | * Values are: |
| 181 | * 0x01 - FV signature, "_FVH" not present |
| 182 | * 0x02 - FFS GUID not present |
| 183 | * 0x03 - FSP INFO Header not found |
Frans Hendriks | 683e77e | 2019-04-29 13:29:36 +0200 | [diff] [blame] | 184 | * 0x04 - ImageBase does not equal CONFIG_FSP_LOC - Is the FSP rebased |
| 185 | * to a different location, or does it need to be? |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 186 | * 0x05 - FSP INFO Header signature "FSPH" not found |
| 187 | * 0x06 - FSP Image ID is not the expected ID. |
| 188 | */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 189 | movb $0xBA, %ah |
| 190 | jmp .Lhlt |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 191 | |
| 192 | halt2: |
| 193 | /* |
| 194 | * Failures for postcode 0xBB - failed in the FSP: |
| 195 | * |
| 196 | * 0x00 - FSP_SUCCESS: Temp RAM was initialized successfully. |
| 197 | * 0x02 - FSP_INVALID_PARAMETER: Input parameters are invalid. |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 198 | * 0x03 - FSP_UNSUPPORTED: The FSP calling conditions were not met. |
| 199 | * 0x07 - FSP_DEVICE_ERROR: Temp RAM initialization failed |
Frans Hendriks | 683e77e | 2019-04-29 13:29:36 +0200 | [diff] [blame] | 200 | * 0x0E - FSP_NOT_FOUND: No valid microcode was found in the microcode |
| 201 | * region. |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 202 | * 0x14 - FSP_ALREADY_STARTED: Temp RAM initialization has been invoked |
| 203 | */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 204 | movb $0xBB, %ah |
| 205 | jmp .Lhlt |
| 206 | |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 207 | .Lhlt: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 208 | xchg %al, %ah |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 209 | #if CONFIG(POST_IO) |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 210 | outb %al, $CONFIG_POST_IO_PORT |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 211 | #else |
| 212 | post_code(POST_DEAD_CODE) |
| 213 | #endif |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 214 | movl $LHLT_DELAY, %ecx |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 215 | .Lhlt_Delay: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 216 | outb %al, $0xED |
| 217 | loop .Lhlt_Delay |
| 218 | jmp .Lhlt |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 219 | |
| 220 | /* |
| 221 | * esp is set to this location so that the call into and return from the FSP |
| 222 | * in find_fsp will work. |
| 223 | */ |
| 224 | .align 4 |
| 225 | fake_fsp_stack: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 226 | .long find_fsp_ret |
Lee Leahy | a887492 | 2015-08-26 14:58:29 -0700 | [diff] [blame] | 227 | .long CONFIG_FSP_LOC /* FSP base address */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 228 | |
| 229 | CAR_init_params: |
Arthur Heymans | 12440ce | 2019-10-23 11:30:22 +0200 | [diff] [blame] | 230 | .long fake_microcode /* Microcode Location */ |
| 231 | .long fake_microcode_end - fake_microcode /* Microcode Length */ |
Aaron Durbin | 2524be4 | 2015-10-29 10:43:21 -0500 | [diff] [blame] | 232 | .long 0xFFFFFFFF - CONFIG_ROM_SIZE + 1 /* Firmware Location */ |
Frans Hendriks | 683e77e | 2019-04-29 13:29:36 +0200 | [diff] [blame] | 233 | .long CONFIG_ROM_SIZE /* Firmware Length */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 234 | |
| 235 | CAR_init_stack: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 236 | .long CAR_init_done |
| 237 | .long CAR_init_params |
Arthur Heymans | 12440ce | 2019-10-23 11:30:22 +0200 | [diff] [blame] | 238 | |
| 239 | /* coreboot updates microcode itself. FSP still needs a pointer |
| 240 | to something that looks like microcode, so provide it with fake |
| 241 | microcode. */ |
| 242 | fake_microcode: |
| 243 | fake_microcode_header_start: |
| 244 | .long 1 /* Header Version */ |
| 245 | .long 1 /* Microcode revision */ |
| 246 | .long 0x10232019 /* Date: Time of writing 23-10-2019 */ |
| 247 | .long 0x00010ff0 /* Sig: (non existing) Family: 0xf, Model: 0x1f, stepping: 0 */ |
| 248 | .long 0 /* Checksum: not checked by FSP, so won't care */ |
| 249 | .long 1 /* Loader Revision */ |
| 250 | .long 1 /* Processor Flags */ |
| 251 | .long fake_microcode_end - fake_microcode_header_end /* Data Size */ |
| 252 | .long fake_microcode_end - fake_microcode /* Total Size */ |
| 253 | .space 12 /* Reserved */ |
| 254 | fake_microcode_header_end: |
| 255 | .space 0x10 /* 16 bytes of empty data */ |
| 256 | fake_microcode_end: |