blob: 8604c3b0b0363584151c6c11e9cdf81947c3dfc3 [file] [log] [blame]
Martin Rotha6427162014-04-25 14:12:13 -06001/*
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.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
Martin Rotha6427162014-04-25 14:12:13 -060022#include <cpu/x86/mtrr.h>
23#include <cpu/x86/cache.h>
24#include <cpu/x86/post_code.h>
Martin Rothe10108a2014-12-04 18:06:36 -070025#include <microcode_size.h>
Martin Rotha6427162014-04-25 14:12:13 -060026#include <cbmem.h>
27
28#ifndef CONFIG_FSP_LOC
29# error "CONFIG_FSP_LOC must be set."
30#endif
31
32#ifndef CONFIG_POST_IO
33# error "CONFIG_POST_IO must be set."
34#endif
35
36#if CONFIG_POST_IO
37# ifndef CONFIG_POST_IO_PORT
38# error "CONFIG_POST_IO_PORT must be set."
39# endif
40#endif
41
42#ifndef CONFIG_CPU_MICROCODE_CBFS_LOC
43# error "CONFIG_CPU_MICROCODE_CBFS_LOC must be set."
44#endif
45
46#define LHLT_DELAY 0x50000 /* I/O delay between post codes on failure */
47
48 cmp $0, %eax
49 jne bisthalt
50
51cache_as_ram:
52 post_code(0x20)
53
54 /*
55 * Find the FSP binary in cbfs.
56 * Make a fake stack that has the return value back to this code.
57 */
58 lea fake_fsp_stack, %esp
59 jmp find_fsp
60find_fsp_ret:
61 /* Save the FSP location */
62 mov %eax, %ebp
63 cmp $CONFIG_FSP_LOC, %eax
64 jb halt1
65
66 post_code(0x22)
67
68 /* Calculate entry into FSP */
69 mov 0x30(%ebp), %eax /* Load TempRamInitEntry */
70 add 0x1c(%ebp), %eax /* add in the offset for the FSP base address */
71
72 /*
73 * Pass early init variables on a fake stack (no memory yet)
74 * as well as the return location
75 */
76 lea CAR_init_stack, %esp
77
78 /* call FSP binary to setup temporary stack */
79 jmp *%eax
80
81CAR_init_done:
82 addl $4, %esp
83 cmp $0, %eax
84 jne halt2
85
86 /* Save FSP_INFO_HEADER location in ebx */
87 mov %ebp, %ebx
88
89 /*
90 * set up bootloader stack
91 * ecx: stack base
92 * edx: stack top
93 */
Martin Roth9cd15532015-01-11 14:58:47 -070094 mov %edx, %esp
Martin Rotha6427162014-04-25 14:12:13 -060095 movl %esp, %ebp
Martin Roth9cd15532015-01-11 14:58:47 -070096
97 /* Clear the cbmem CAR memory region. */
98 movl %ecx, %edi
99 movl %edx, %ecx
100 sub %edi, %ecx
101 shr $2, %ecx
102 xorl %eax, %eax
103 rep stosl
Martin Rotha6427162014-04-25 14:12:13 -0600104
105before_romstage:
106 post_code(0x23)
107
108 /* Call romstage.c main function. */
Martin Roth9cd15532015-01-11 14:58:47 -0700109 pushl %ebx /* main takes FSP_INFO_HEADER as its argument */
Martin Rotha6427162014-04-25 14:12:13 -0600110 call main /* does not return */
111 movb $0xB8, %ah
112 jmp .Lhlt
113
114bisthalt:
115 movb $0xB9, %ah
116 jmp .Lhlt
117
118halt1:
119 /*
120 * Failures for postcode 0xBA - failed in find_fsp()
121 *
122 * Values are:
123 * 0x01 - FV signature, "_FVH" not present
124 * 0x02 - FFS GUID not present
125 * 0x03 - FSP INFO Header not found
126 * 0x04 - ImageBase does not equal CONFIG_FSP_LOC - Is the FSP rebased to
127 * a different location, or does it need to be?
128 * 0x05 - FSP INFO Header signature "FSPH" not found
129 * 0x06 - FSP Image ID is not the expected ID.
130 */
131 movb $0xBA, %ah
132 jmp .Lhlt
133
134halt2:
135 /*
136 * Failures for postcode 0xBB - failed in the FSP:
137 *
138 * 0x00 - FSP_SUCCESS: Temp RAM was initialized successfully.
139 * 0x02 - FSP_INVALID_PARAMETER: Input parameters are invalid.
140 * 0x0E - FSP_NOT_FOUND: No valid microcode was found in the microcode region.
141 * 0x03 - FSP_UNSUPPORTED: The FSP calling conditions were not met.
142 * 0x07 - FSP_DEVICE_ERROR: Temp RAM initialization failed
143 * 0x14 - FSP_ALREADY_STARTED: Temp RAM initialization has been invoked
144 */
145 movb $0xBB, %ah
146
147.Lhlt:
148 xchg %al, %ah
149#if CONFIG_POST_IO
150 outb %al, $CONFIG_POST_IO_PORT
151#else
152 post_code(POST_DEAD_CODE)
153#endif
154 movl $LHLT_DELAY, %ecx
155.Lhlt_Delay:
156 outb %al, $0xED
157 loop .Lhlt_Delay
158 jmp .Lhlt
159
160/*
161 * esp is set to this location so that the call into and return from the FSP
162 * in find_fsp will work.
163 */
164 .align 4
165fake_fsp_stack:
166 .long find_fsp_ret
167
168CAR_init_params:
169 .long CONFIG_CPU_MICROCODE_CBFS_LOC
Martin Rothe10108a2014-12-04 18:06:36 -0700170 .long MICROCODE_REGION_LENGTH
Martin Rotha6427162014-04-25 14:12:13 -0600171 .long 0xFFFFFFFF - CACHE_ROM_SIZE + 1 /* Firmware Location */
172 .long CACHE_ROM_SIZE /* Total Firmware Length */
173
174CAR_init_stack:
175 .long CAR_init_done
176 .long CAR_init_params
177