Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License as published by |
| 6 | * the Free Software Foundation; version 2 of the License. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 12 | */ |
| 13 | |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 14 | #include <cpu/x86/post_code.h> |
| 15 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 16 | /* |
| 17 | * Replacement for cache_as_ram.inc when using the FSP binary. This code |
| 18 | * locates the FSP binary, initializes the cache as RAM and performs the |
| 19 | * first stage of initialization. Next this code switches the stack from |
| 20 | * the cache to RAM and then disables the cache as RAM. Finally this code |
| 21 | * performs the final stage of initialization. |
| 22 | */ |
| 23 | |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 24 | #define LHLT_DELAY 0x50000 /* I/O delay between post codes on failure */ |
| 25 | |
| 26 | .global bootblock_pre_c_entry |
| 27 | bootblock_pre_c_entry: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 28 | /* |
Kyösti Mälkki | ee2e936 | 2018-12-28 16:06:45 +0200 | [diff] [blame] | 29 | * Per FSP1.1 specs, following registers are preserved: |
| 30 | * EBX, EDI, ESI, EBP, MM0, MM1 |
| 31 | * |
| 32 | * Shift values to release MM2. |
Arthur Heymans | 59b6542 | 2019-05-23 15:24:30 +0200 | [diff] [blame] | 33 | * mm0 -> ebx: BIST value |
Kyösti Mälkki | ee2e936 | 2018-12-28 16:06:45 +0200 | [diff] [blame] | 34 | * mm1 -> mm0: low 32-bits of TSC value |
| 35 | * mm2 -> mm1: high 32-bits of TSC value |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 36 | */ |
Arthur Heymans | 59b6542 | 2019-05-23 15:24:30 +0200 | [diff] [blame] | 37 | movd %mm0, %ebx |
Kyösti Mälkki | ee2e936 | 2018-12-28 16:06:45 +0200 | [diff] [blame] | 38 | movd %mm1, %eax |
| 39 | movd %eax, %mm0 |
| 40 | movd %mm2, %eax |
| 41 | movd %eax, %mm1 |
| 42 | |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 43 | cache_as_ram: |
| 44 | post_code(0x20) |
| 45 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 46 | /* |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 47 | * Find the FSP binary in cbfs. |
| 48 | * Make a fake stack that has the return value back to this code. |
| 49 | */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 50 | lea fake_fsp_stack, %esp |
| 51 | jmp find_fsp |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 52 | find_fsp_ret: |
| 53 | /* Save the FSP location */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 54 | mov %eax, %ebp |
| 55 | |
| 56 | /* |
| 57 | * Only when a valid FSP binary is found at CONFIG_FSP_LOC is |
| 58 | * the returned FSP_INFO_HEADER structure address above the base |
| 59 | * address of FSP binary specified by the CONFIG_FSP_LOC value. |
| 60 | * All of the error values are in the 0x8xxxxxxx range which are |
| 61 | * below the CONFIG_FSP_LOC value. |
| 62 | */ |
| 63 | cmp $CONFIG_FSP_LOC, %eax |
| 64 | jbe halt1 |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 65 | |
Duncan Laurie | fb50983 | 2015-11-22 14:53:57 -0800 | [diff] [blame] | 66 | post_code(POST_FSP_TEMP_RAM_INIT) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 67 | |
| 68 | /* Calculate entry into FSP */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 69 | mov 0x30(%ebp), %eax /* Load TempRamInitEntry */ |
| 70 | add 0x1c(%ebp), %eax /* add in the offset for FSP */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 71 | |
| 72 | /* |
| 73 | * Pass early init variables on a fake stack (no memory yet) |
| 74 | * as well as the return location |
| 75 | */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 76 | lea CAR_init_stack, %esp |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 77 | |
| 78 | /* |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 79 | * BIST value is zero |
| 80 | * eax: TempRamInitApi address |
Arthur Heymans | 59b6542 | 2019-05-23 15:24:30 +0200 | [diff] [blame] | 81 | * ebx: BIST value |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 82 | * ebp: FSP_INFO_HEADER address |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 83 | * esi: Not used |
| 84 | * mm0: low 32-bits of TSC value |
| 85 | * mm1: high 32-bits of TSC value |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 86 | */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 87 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 88 | /* call FSP binary to setup temporary stack */ |
| 89 | jmp *%eax |
| 90 | |
| 91 | CAR_init_done: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 92 | |
| 93 | /* |
| 94 | * ebp: FSP_INFO_HEADER address |
Arthur Heymans | 59b6542 | 2019-05-23 15:24:30 +0200 | [diff] [blame] | 95 | * ebx: BIST value |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 96 | * ecx: Temp RAM base |
| 97 | * edx: Temp RAM top |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 98 | * mm0: low 32-bits of TSC value |
| 99 | * mm1: high 32-bits of TSC value |
| 100 | */ |
| 101 | |
| 102 | cmp $0, %eax |
| 103 | jne halt2 |
| 104 | |
| 105 | /* Setup bootloader stack */ |
| 106 | movl %edx, %esp |
| 107 | |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 108 | /* |
| 109 | * ebp: FSP_INFO_HEADER address |
Arthur Heymans | 59b6542 | 2019-05-23 15:24:30 +0200 | [diff] [blame] | 110 | * ebx: BIST value |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 111 | * ecx: Temp RAM base |
| 112 | * edx: Temp RAM top |
| 113 | * esp: Top of stack in temp RAM |
| 114 | * mm0: low 32-bits of TSC value |
| 115 | * mm1: high 32-bits of TSC value |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 116 | */ |
| 117 | |
Martin Roth | e18e642 | 2017-06-03 20:03:18 -0600 | [diff] [blame] | 118 | /* coreboot assumes stack/heap region will be zero */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 119 | cld |
| 120 | movl %ecx, %edi |
| 121 | neg %ecx |
Arthur Heymans | 59b6542 | 2019-05-23 15:24:30 +0200 | [diff] [blame] | 122 | /* Clear up to Temp Ram top. */ |
| 123 | add %edx, %ecx |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 124 | shrl $2, %ecx |
| 125 | xorl %eax, %eax |
| 126 | rep stosl |
| 127 | |
Arthur Heymans | 59b6542 | 2019-05-23 15:24:30 +0200 | [diff] [blame] | 128 | /* Need to align stack to 16 bytes at call instruction. Account for |
| 129 | the pushes below. */ |
| 130 | andl $0xfffffff0, %esp |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 131 | subl $8, %esp |
Arthur Heymans | 59b6542 | 2019-05-23 15:24:30 +0200 | [diff] [blame] | 132 | |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 133 | /* Push initial timestamp on the stack */ |
Arthur Heymans | 59b6542 | 2019-05-23 15:24:30 +0200 | [diff] [blame] | 134 | movd %mm1, %eax |
| 135 | pushl %eax /* tsc[63:32] */ |
| 136 | movd %mm0, %eax |
| 137 | pushl %eax /* tsc[31:0] */ |
| 138 | |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 139 | before_romstage: |
Subrata Banik | fbdc719 | 2016-01-19 19:19:15 +0530 | [diff] [blame] | 140 | post_code(0x2A) |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 141 | |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 142 | /* Call bootblock_c_entry(uint64_t base_timestamp) */ |
| 143 | call bootblock_c_entry |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 144 | |
Frans Hendriks | 4e0ec59 | 2019-06-06 10:07:17 +0200 | [diff] [blame] | 145 | /* Never reached */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 146 | |
| 147 | halt1: |
| 148 | /* |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 149 | * Failures for postcode 0xBA - failed in fsp_fih_early_find() |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 150 | * |
| 151 | * Values are: |
| 152 | * 0x01 - FV signature, "_FVH" not present |
| 153 | * 0x02 - FFS GUID not present |
| 154 | * 0x03 - FSP INFO Header not found |
Frans Hendriks | 683e77e | 2019-04-29 13:29:36 +0200 | [diff] [blame] | 155 | * 0x04 - ImageBase does not equal CONFIG_FSP_LOC - Is the FSP rebased |
| 156 | * to a different location, or does it need to be? |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 157 | * 0x05 - FSP INFO Header signature "FSPH" not found |
| 158 | * 0x06 - FSP Image ID is not the expected ID. |
| 159 | */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 160 | movb $0xBA, %ah |
| 161 | jmp .Lhlt |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 162 | |
| 163 | halt2: |
| 164 | /* |
| 165 | * Failures for postcode 0xBB - failed in the FSP: |
| 166 | * |
| 167 | * 0x00 - FSP_SUCCESS: Temp RAM was initialized successfully. |
| 168 | * 0x02 - FSP_INVALID_PARAMETER: Input parameters are invalid. |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 169 | * 0x03 - FSP_UNSUPPORTED: The FSP calling conditions were not met. |
| 170 | * 0x07 - FSP_DEVICE_ERROR: Temp RAM initialization failed |
Frans Hendriks | 683e77e | 2019-04-29 13:29:36 +0200 | [diff] [blame] | 171 | * 0x0E - FSP_NOT_FOUND: No valid microcode was found in the microcode |
| 172 | * region. |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 173 | * 0x14 - FSP_ALREADY_STARTED: Temp RAM initialization has been invoked |
| 174 | */ |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 175 | movb $0xBB, %ah |
| 176 | jmp .Lhlt |
| 177 | |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 178 | .Lhlt: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 179 | xchg %al, %ah |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 180 | #if CONFIG(POST_IO) |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 181 | outb %al, $CONFIG_POST_IO_PORT |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 182 | #else |
| 183 | post_code(POST_DEAD_CODE) |
| 184 | #endif |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 185 | movl $LHLT_DELAY, %ecx |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 186 | .Lhlt_Delay: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 187 | outb %al, $0xED |
| 188 | loop .Lhlt_Delay |
| 189 | jmp .Lhlt |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 190 | |
| 191 | /* |
| 192 | * esp is set to this location so that the call into and return from the FSP |
| 193 | * in find_fsp will work. |
| 194 | */ |
| 195 | .align 4 |
| 196 | fake_fsp_stack: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 197 | .long find_fsp_ret |
Lee Leahy | a887492 | 2015-08-26 14:58:29 -0700 | [diff] [blame] | 198 | .long CONFIG_FSP_LOC /* FSP base address */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 199 | |
| 200 | CAR_init_params: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 201 | .long CONFIG_CPU_MICROCODE_CBFS_LOC /* Microcode Location */ |
| 202 | .long CONFIG_CPU_MICROCODE_CBFS_LEN /* Microcode Length */ |
Aaron Durbin | 2524be4 | 2015-10-29 10:43:21 -0500 | [diff] [blame] | 203 | .long 0xFFFFFFFF - CONFIG_ROM_SIZE + 1 /* Firmware Location */ |
Frans Hendriks | 683e77e | 2019-04-29 13:29:36 +0200 | [diff] [blame] | 204 | .long CONFIG_ROM_SIZE /* Firmware Length */ |
Lee Leahy | 3dad489 | 2015-05-05 11:14:02 -0700 | [diff] [blame] | 205 | |
| 206 | CAR_init_stack: |
Lee Leahy | b5ad827 | 2015-04-20 15:29:16 -0700 | [diff] [blame] | 207 | .long CAR_init_done |
| 208 | .long CAR_init_params |