blob: 5fff60ac1aa931027ec8580bb29f126ec5431b4a [file] [log] [blame]
Angel Pons8a3453f2020-04-02 23:48:19 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Lee Leahy0946ec32015-04-20 15:24:54 -07002
Duncan Laurie59be6242016-03-07 13:21:56 -08003#include <bootmode.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07004#include <acpi/acpi.h>
Lee Leahy0946ec32015-04-20 15:24:54 -07005#include <console/console.h>
Lee Leahy94b856e2015-10-15 12:07:03 -07006#include <fsp/ramstage.h>
Aaron Durbin789f2b62015-09-09 17:05:06 -05007#include <fsp/util.h>
Patrick Rudolph92106b12020-02-19 12:54:06 +01008#include <framebuffer_info.h>
Lee Leahy0946ec32015-04-20 15:24:54 -07009#include <lib.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070010#include <stage_cache.h>
Aaron Durbin39bdb0b2015-08-04 23:59:43 -050011#include <string.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070012#include <timestamp.h>
Frans Hendriks50b999f2019-11-08 13:55:45 +010013#include <cbmem.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070014
15/* SOC initialization after FSP silicon init */
Aaron Durbin64031672018-04-21 14:45:32 -060016__weak void soc_after_silicon_init(void)
Lee Leahy0946ec32015-04-20 15:24:54 -070017{
Lee Leahy0946ec32015-04-20 15:24:54 -070018}
19
Alexandru Gagniuc41c003c2015-08-28 19:07:35 -040020static void display_hob_info(FSP_INFO_HEADER *fsp_info_header)
21{
22 const EFI_GUID graphics_info_guid = EFI_PEI_GRAPHICS_INFO_HOB_GUID;
Alexandru Gagniuc41c003c2015-08-28 19:07:35 -040023 void *hob_list_ptr = get_hob_list();
24
Alexandru Gagniuc41c003c2015-08-28 19:07:35 -040025 /* Verify the HOBs */
26 if (hob_list_ptr == NULL) {
Frans Hendriks509f4692019-06-28 14:11:41 +020027 printk(BIOS_ERR, "ERROR - HOB pointer is NULL!\n");
Alexandru Gagniuc41c003c2015-08-28 19:07:35 -040028 return;
29 }
30
Frans Hendriks509f4692019-06-28 14:11:41 +020031 if (CONFIG(DISPLAY_HOBS))
32 print_hob_type_structure(0, hob_list_ptr);
Alexandru Gagniuc41c003c2015-08-28 19:07:35 -040033
34 /*
35 * Verify that FSP is generating the required HOBs:
36 * 7.1: FSP_BOOTLOADER_TEMP_MEMORY_HOB only produced for FSP 1.0
37 * 7.2: FSP_RESERVED_MEMORY_RESOURCE_HOB verified by raminit
38 * 7.3: FSP_NON_VOLATILE_STORAGE_HOB verified by raminit
39 * 7.4: FSP_BOOTLOADER_TOLUM_HOB verified by raminit
40 * 7.5: EFI_PEI_GRAPHICS_INFO_HOB verified below,
41 * if the ImageAttribute bit is set
42 * FSP_SMBIOS_MEMORY_INFO HOB verified by raminit
43 */
44 if ((fsp_info_header->ImageAttribute & GRAPHICS_SUPPORT_BIT) &&
Frans Hendriks509f4692019-06-28 14:11:41 +020045 !get_next_guid_hob(&graphics_info_guid, hob_list_ptr) &&
46 CONFIG(DISPLAY_HOBS)) {
47 printk(BIOS_ERR, "7.5: EFI_PEI_GRAPHICS_INFO_HOB missing!\n");
48 printk(BIOS_ERR,
Alexandru Gagniuc41c003c2015-08-28 19:07:35 -040049 "ERROR - Missing one or more required FSP HOBs!\n");
Frans Hendriks509f4692019-06-28 14:11:41 +020050 }
Alexandru Gagniuc41c003c2015-08-28 19:07:35 -040051}
52
Lee Leahycff5f092016-02-08 08:37:53 -080053void fsp_run_silicon_init(FSP_INFO_HEADER *fsp_info_header, int is_s3_wakeup)
Lee Leahy0946ec32015-04-20 15:24:54 -070054{
Lee Leahy0946ec32015-04-20 15:24:54 -070055 FSP_SILICON_INIT fsp_silicon_init;
56 SILICON_INIT_UPD *original_params;
57 SILICON_INIT_UPD silicon_init_params;
58 EFI_STATUS status;
59 UPD_DATA_REGION *upd_ptr;
60 VPD_DATA_REGION *vpd_ptr;
Wim Vervoorn67117c32019-12-16 14:21:09 +010061 const struct cbmem_entry *logo_entry = NULL;
Lee Leahy0946ec32015-04-20 15:24:54 -070062
Lee Leahycff5f092016-02-08 08:37:53 -080063 /* Display the FSP header */
Lee Leahy0946ec32015-04-20 15:24:54 -070064 if (fsp_info_header == NULL) {
65 printk(BIOS_ERR, "FSP_INFO_HEADER not set!\n");
66 return;
67 }
68 print_fsp_info(fsp_info_header);
69
70 /* Initialize the UPD values */
71 vpd_ptr = (VPD_DATA_REGION *)(fsp_info_header->CfgRegionOffset +
72 fsp_info_header->ImageBase);
Julius Werner540a9802019-12-09 13:03:29 -080073 printk(BIOS_DEBUG, "%p: VPD Data\n", vpd_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -070074 upd_ptr = (UPD_DATA_REGION *)(vpd_ptr->PcdUpdRegionOffset +
75 fsp_info_header->ImageBase);
Julius Werner540a9802019-12-09 13:03:29 -080076 printk(BIOS_DEBUG, "%p: UPD Data\n", upd_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -070077 original_params = (void *)((u8 *)upd_ptr +
78 upd_ptr->SiliconInitUpdOffset);
79 memcpy(&silicon_init_params, original_params,
80 sizeof(silicon_init_params));
81 soc_silicon_init_params(&silicon_init_params);
82
83 /* Locate VBT and pass to FSP GOP */
Julius Wernercd49cce2019-03-05 16:53:33 -080084 if (CONFIG(RUN_FSP_GOP))
Aaron Durbin39bdb0b2015-08-04 23:59:43 -050085 load_vbt(is_s3_wakeup, &silicon_init_params);
Lee Leahy0946ec32015-04-20 15:24:54 -070086 mainboard_silicon_init_params(&silicon_init_params);
87
Wim Vervoorn67117c32019-12-16 14:21:09 +010088 if (CONFIG(FSP1_1_DISPLAY_LOGO) && !is_s3_wakeup)
89 logo_entry = soc_load_logo(&silicon_init_params);
Frans Hendriks50b999f2019-11-08 13:55:45 +010090
Lee Leahy0946ec32015-04-20 15:24:54 -070091 /* Display the UPD data */
Julius Wernercd49cce2019-03-05 16:53:33 -080092 if (CONFIG(DISPLAY_UPD_DATA))
Lee Leahy0946ec32015-04-20 15:24:54 -070093 soc_display_silicon_init_params(original_params,
94 &silicon_init_params);
95
96 /* Perform silicon initialization after RAM is configured */
97 printk(BIOS_DEBUG, "Calling FspSiliconInit\n");
98 fsp_silicon_init = (FSP_SILICON_INIT)(fsp_info_header->ImageBase
99 + fsp_info_header->FspSiliconInitEntryOffset);
100 timestamp_add_now(TS_FSP_SILICON_INIT_START);
Julius Werner540a9802019-12-09 13:03:29 -0800101 printk(BIOS_DEBUG, "Calling FspSiliconInit(%p) at %p\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700102 &silicon_init_params, fsp_silicon_init);
Duncan Lauriefb509832015-11-22 14:53:57 -0800103 post_code(POST_FSP_SILICON_INIT);
Lee Leahy0946ec32015-04-20 15:24:54 -0700104 status = fsp_silicon_init(&silicon_init_params);
105 timestamp_add_now(TS_FSP_SILICON_INIT_END);
106 printk(BIOS_DEBUG, "FspSiliconInit returned 0x%08x\n", status);
107
Frans Hendriks50b999f2019-11-08 13:55:45 +0100108 /* The logo_entry can be freed up now as it is not required any longer */
Wim Vervoorn67117c32019-12-16 14:21:09 +0100109 if (logo_entry && !is_s3_wakeup)
Frans Hendriks50b999f2019-11-08 13:55:45 +0100110 cbmem_entry_remove(logo_entry);
111
Duncan Laurie59be6242016-03-07 13:21:56 -0800112 /* Mark graphics init done after SiliconInit if VBT was provided */
Julius Wernercd49cce2019-03-05 16:53:33 -0800113#if CONFIG(RUN_FSP_GOP)
Duncan Laurie59be6242016-03-07 13:21:56 -0800114 /* GraphicsConfigPtr doesn't exist in Quark X1000's FSP, so this needs
Elyes HAOUAS2e4d8062016-08-25 20:50:50 +0200115 * to be #if'd out instead of using if (). */
Duncan Laurie59be6242016-03-07 13:21:56 -0800116 if (silicon_init_params.GraphicsConfigPtr)
117 gfx_set_init_done(1);
118#endif
119
Patrick Rudolph92106b12020-02-19 12:54:06 +0100120 if (CONFIG(RUN_FSP_GOP)) {
121 const EFI_GUID vbt_guid = EFI_PEI_GRAPHICS_INFO_HOB_GUID;
122 u32 *vbt_hob;
123
124 void *hob_list_ptr = get_hob_list();
125 vbt_hob = get_next_guid_hob(&vbt_guid, hob_list_ptr);
126 if (vbt_hob == NULL) {
127 printk(BIOS_ERR, "FSP_ERR: Graphics Data HOB is not present\n");
128 } else {
129 EFI_PEI_GRAPHICS_INFO_HOB *gop;
130
131 printk(BIOS_DEBUG, "FSP_DEBUG: Graphics Data HOB present\n");
132 gop = GET_GUID_HOB_DATA(vbt_hob);
133
134 fb_add_framebuffer_info(gop->FrameBufferBase,
135 gop->GraphicsMode.HorizontalResolution,
136 gop->GraphicsMode.VerticalResolution,
137 gop->GraphicsMode.PixelsPerScanLine * 4,
138 32);
139 }
140 }
141
Alexandru Gagniuc41c003c2015-08-28 19:07:35 -0400142 display_hob_info(fsp_info_header);
Lee Leahy0946ec32015-04-20 15:24:54 -0700143 soc_after_silicon_init();
144}
145
Aaron Durbinabf87a22015-08-05 12:26:56 -0500146static void fsp_cache_save(struct prog *fsp)
Lee Leahy0946ec32015-04-20 15:24:54 -0700147{
Julius Wernercd49cce2019-03-05 16:53:33 -0800148 if (CONFIG(NO_STAGE_CACHE))
Furquan Shaikh1e162bf2016-05-06 09:20:35 -0700149 return;
150
151 printk(BIOS_DEBUG, "FSP: Saving binary in cache\n");
152
Aaron Durbinabf87a22015-08-05 12:26:56 -0500153 if (prog_entry(fsp) == NULL) {
154 printk(BIOS_ERR, "ERROR: No FSP to save in cache.\n");
Lee Leahy0946ec32015-04-20 15:24:54 -0700155 return;
156 }
157
Aaron Durbinabf87a22015-08-05 12:26:56 -0500158 stage_cache_add(STAGE_REFCODE, fsp);
Lee Leahy0946ec32015-04-20 15:24:54 -0700159}
160
Aaron Durbinabf87a22015-08-05 12:26:56 -0500161static int fsp_find_and_relocate(struct prog *fsp)
Lee Leahy0946ec32015-04-20 15:24:54 -0700162{
Aaron Durbin5d6f0f92015-10-08 15:06:28 -0500163 if (prog_locate(fsp)) {
164 printk(BIOS_ERR, "ERROR: Couldn't find %s\n", prog_name(fsp));
Lee Leahy0946ec32015-04-20 15:24:54 -0700165 return -1;
166 }
167
Aaron Durbin5d6f0f92015-10-08 15:06:28 -0500168 if (fsp_relocate(fsp, prog_rdev(fsp))) {
Aaron Durbin22ea0072015-08-05 10:17:33 -0500169 printk(BIOS_ERR, "ERROR: FSP relocation failed.\n");
170 return -1;
171 }
Lee Leahy0946ec32015-04-20 15:24:54 -0700172
Lee Leahy0946ec32015-04-20 15:24:54 -0700173 return 0;
174}
175
Kyösti Mälkkid0bc92d2021-01-10 00:23:58 +0200176static void fsp_load(void)
Lee Leahy0946ec32015-04-20 15:24:54 -0700177{
Aaron Durbin7e7a4df2015-12-08 14:34:35 -0600178 struct prog fsp = PROG_INIT(PROG_REFCODE, "fsp.bin");
Aaron Durbin39bdb0b2015-08-04 23:59:43 -0500179 int is_s3_wakeup = acpi_is_wakeup_s3();
Lee Leahy0946ec32015-04-20 15:24:54 -0700180
Julius Wernercd49cce2019-03-05 16:53:33 -0800181 if (is_s3_wakeup && !CONFIG(NO_STAGE_CACHE)) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700182 printk(BIOS_DEBUG, "FSP: Loading binary from cache\n");
Aaron Durbinabf87a22015-08-05 12:26:56 -0500183 stage_cache_load_stage(STAGE_REFCODE, &fsp);
Lee Leahy0946ec32015-04-20 15:24:54 -0700184 } else {
Aaron Durbinabf87a22015-08-05 12:26:56 -0500185 fsp_find_and_relocate(&fsp);
Aaron Durbinabf87a22015-08-05 12:26:56 -0500186 fsp_cache_save(&fsp);
Lee Leahy0946ec32015-04-20 15:24:54 -0700187 }
188
Aaron Durbinabf87a22015-08-05 12:26:56 -0500189 /* FSP_INFO_HEADER is set as the program entry. */
190 fsp_update_fih(prog_entry(&fsp));
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800191}
192
193void intel_silicon_init(void)
194{
195 fsp_load();
196 fsp_run_silicon_init(fsp_get_fih(), acpi_is_wakeup_s3());
Lee Leahy0946ec32015-04-20 15:24:54 -0700197}
198
199/* Initialize the UPD parameters for SiliconInit */
Aaron Durbin64031672018-04-21 14:45:32 -0600200__weak void mainboard_silicon_init_params(
Lee Leahy0946ec32015-04-20 15:24:54 -0700201 SILICON_INIT_UPD *params)
202{
Lee Leahy0946ec32015-04-20 15:24:54 -0700203};
204
205/* Display the UPD parameters for SiliconInit */
Aaron Durbin64031672018-04-21 14:45:32 -0600206__weak void soc_display_silicon_init_params(
Lee Leahy0946ec32015-04-20 15:24:54 -0700207 const SILICON_INIT_UPD *old, SILICON_INIT_UPD *new)
208{
209 printk(BIOS_SPEW, "UPD values for SiliconInit:\n");
210 hexdump32(BIOS_SPEW, new, sizeof(*new));
211}
212
213/* Initialize the UPD parameters for SiliconInit */
Aaron Durbin64031672018-04-21 14:45:32 -0600214__weak void soc_silicon_init_params(SILICON_INIT_UPD *params)
Lee Leahy0946ec32015-04-20 15:24:54 -0700215{
Lee Leahy0946ec32015-04-20 15:24:54 -0700216}