blob: 11eee04e88acbb8193715897f9cd86c63df149cb [file] [log] [blame]
Angel Pons8a3453f2020-04-02 23:48:19 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Lee Leahy0946ec32015-04-20 15:24:54 -07003
Duncan Laurie59be6242016-03-07 13:21:56 -08004#include <bootmode.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07005#include <acpi/acpi.h>
Lee Leahy0946ec32015-04-20 15:24:54 -07006#include <console/console.h>
Kyösti Mälkkib2a5f0b2019-08-04 19:54:32 +03007#include <cpu/x86/smm.h>
Lee Leahy94b856e2015-10-15 12:07:03 -07008#include <fsp/ramstage.h>
Aaron Durbin789f2b62015-09-09 17:05:06 -05009#include <fsp/util.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070010#include <lib.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070011#include <stage_cache.h>
Aaron Durbin39bdb0b2015-08-04 23:59:43 -050012#include <string.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070013#include <timestamp.h>
Frans Hendriks50b999f2019-11-08 13:55:45 +010014#include <cbmem.h>
Lee Leahy0946ec32015-04-20 15:24:54 -070015
16/* SOC initialization after FSP silicon init */
Aaron Durbin64031672018-04-21 14:45:32 -060017__weak void soc_after_silicon_init(void)
Lee Leahy0946ec32015-04-20 15:24:54 -070018{
Lee Leahy0946ec32015-04-20 15:24:54 -070019}
20
Alexandru Gagniuc41c003c2015-08-28 19:07:35 -040021static void display_hob_info(FSP_INFO_HEADER *fsp_info_header)
22{
23 const EFI_GUID graphics_info_guid = EFI_PEI_GRAPHICS_INFO_HOB_GUID;
Alexandru Gagniuc41c003c2015-08-28 19:07:35 -040024 void *hob_list_ptr = get_hob_list();
25
Alexandru Gagniuc41c003c2015-08-28 19:07:35 -040026 /* Verify the HOBs */
27 if (hob_list_ptr == NULL) {
Frans Hendriks509f4692019-06-28 14:11:41 +020028 printk(BIOS_ERR, "ERROR - HOB pointer is NULL!\n");
Alexandru Gagniuc41c003c2015-08-28 19:07:35 -040029 return;
30 }
31
Frans Hendriks509f4692019-06-28 14:11:41 +020032 if (CONFIG(DISPLAY_HOBS))
33 print_hob_type_structure(0, hob_list_ptr);
Alexandru Gagniuc41c003c2015-08-28 19:07:35 -040034
35 /*
36 * Verify that FSP is generating the required HOBs:
37 * 7.1: FSP_BOOTLOADER_TEMP_MEMORY_HOB only produced for FSP 1.0
38 * 7.2: FSP_RESERVED_MEMORY_RESOURCE_HOB verified by raminit
39 * 7.3: FSP_NON_VOLATILE_STORAGE_HOB verified by raminit
40 * 7.4: FSP_BOOTLOADER_TOLUM_HOB verified by raminit
41 * 7.5: EFI_PEI_GRAPHICS_INFO_HOB verified below,
42 * if the ImageAttribute bit is set
43 * FSP_SMBIOS_MEMORY_INFO HOB verified by raminit
44 */
45 if ((fsp_info_header->ImageAttribute & GRAPHICS_SUPPORT_BIT) &&
Frans Hendriks509f4692019-06-28 14:11:41 +020046 !get_next_guid_hob(&graphics_info_guid, hob_list_ptr) &&
47 CONFIG(DISPLAY_HOBS)) {
48 printk(BIOS_ERR, "7.5: EFI_PEI_GRAPHICS_INFO_HOB missing!\n");
49 printk(BIOS_ERR,
Alexandru Gagniuc41c003c2015-08-28 19:07:35 -040050 "ERROR - Missing one or more required FSP HOBs!\n");
Frans Hendriks509f4692019-06-28 14:11:41 +020051 }
Alexandru Gagniuc41c003c2015-08-28 19:07:35 -040052}
53
Lee Leahycff5f092016-02-08 08:37:53 -080054void fsp_run_silicon_init(FSP_INFO_HEADER *fsp_info_header, int is_s3_wakeup)
Lee Leahy0946ec32015-04-20 15:24:54 -070055{
Lee Leahy0946ec32015-04-20 15:24:54 -070056 FSP_SILICON_INIT fsp_silicon_init;
57 SILICON_INIT_UPD *original_params;
58 SILICON_INIT_UPD silicon_init_params;
59 EFI_STATUS status;
60 UPD_DATA_REGION *upd_ptr;
61 VPD_DATA_REGION *vpd_ptr;
Wim Vervoorn67117c32019-12-16 14:21:09 +010062 const struct cbmem_entry *logo_entry = NULL;
Lee Leahy0946ec32015-04-20 15:24:54 -070063
Lee Leahycff5f092016-02-08 08:37:53 -080064 /* Display the FSP header */
Lee Leahy0946ec32015-04-20 15:24:54 -070065 if (fsp_info_header == NULL) {
66 printk(BIOS_ERR, "FSP_INFO_HEADER not set!\n");
67 return;
68 }
69 print_fsp_info(fsp_info_header);
70
71 /* Initialize the UPD values */
72 vpd_ptr = (VPD_DATA_REGION *)(fsp_info_header->CfgRegionOffset +
73 fsp_info_header->ImageBase);
Julius Werner540a9802019-12-09 13:03:29 -080074 printk(BIOS_DEBUG, "%p: VPD Data\n", vpd_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -070075 upd_ptr = (UPD_DATA_REGION *)(vpd_ptr->PcdUpdRegionOffset +
76 fsp_info_header->ImageBase);
Julius Werner540a9802019-12-09 13:03:29 -080077 printk(BIOS_DEBUG, "%p: UPD Data\n", upd_ptr);
Lee Leahy0946ec32015-04-20 15:24:54 -070078 original_params = (void *)((u8 *)upd_ptr +
79 upd_ptr->SiliconInitUpdOffset);
80 memcpy(&silicon_init_params, original_params,
81 sizeof(silicon_init_params));
82 soc_silicon_init_params(&silicon_init_params);
83
84 /* Locate VBT and pass to FSP GOP */
Julius Wernercd49cce2019-03-05 16:53:33 -080085 if (CONFIG(RUN_FSP_GOP))
Aaron Durbin39bdb0b2015-08-04 23:59:43 -050086 load_vbt(is_s3_wakeup, &silicon_init_params);
Lee Leahy0946ec32015-04-20 15:24:54 -070087 mainboard_silicon_init_params(&silicon_init_params);
88
Wim Vervoorn67117c32019-12-16 14:21:09 +010089 if (CONFIG(FSP1_1_DISPLAY_LOGO) && !is_s3_wakeup)
90 logo_entry = soc_load_logo(&silicon_init_params);
Frans Hendriks50b999f2019-11-08 13:55:45 +010091
Lee Leahy0946ec32015-04-20 15:24:54 -070092 /* Display the UPD data */
Julius Wernercd49cce2019-03-05 16:53:33 -080093 if (CONFIG(DISPLAY_UPD_DATA))
Lee Leahy0946ec32015-04-20 15:24:54 -070094 soc_display_silicon_init_params(original_params,
95 &silicon_init_params);
96
97 /* Perform silicon initialization after RAM is configured */
98 printk(BIOS_DEBUG, "Calling FspSiliconInit\n");
99 fsp_silicon_init = (FSP_SILICON_INIT)(fsp_info_header->ImageBase
100 + fsp_info_header->FspSiliconInitEntryOffset);
101 timestamp_add_now(TS_FSP_SILICON_INIT_START);
Julius Werner540a9802019-12-09 13:03:29 -0800102 printk(BIOS_DEBUG, "Calling FspSiliconInit(%p) at %p\n",
Lee Leahy0946ec32015-04-20 15:24:54 -0700103 &silicon_init_params, fsp_silicon_init);
Duncan Lauriefb509832015-11-22 14:53:57 -0800104 post_code(POST_FSP_SILICON_INIT);
Lee Leahy0946ec32015-04-20 15:24:54 -0700105 status = fsp_silicon_init(&silicon_init_params);
106 timestamp_add_now(TS_FSP_SILICON_INIT_END);
107 printk(BIOS_DEBUG, "FspSiliconInit returned 0x%08x\n", status);
108
Frans Hendriks50b999f2019-11-08 13:55:45 +0100109 /* The logo_entry can be freed up now as it is not required any longer */
Wim Vervoorn67117c32019-12-16 14:21:09 +0100110 if (logo_entry && !is_s3_wakeup)
Frans Hendriks50b999f2019-11-08 13:55:45 +0100111 cbmem_entry_remove(logo_entry);
112
Duncan Laurie59be6242016-03-07 13:21:56 -0800113 /* Mark graphics init done after SiliconInit if VBT was provided */
Julius Wernercd49cce2019-03-05 16:53:33 -0800114#if CONFIG(RUN_FSP_GOP)
Duncan Laurie59be6242016-03-07 13:21:56 -0800115 /* GraphicsConfigPtr doesn't exist in Quark X1000's FSP, so this needs
Elyes HAOUAS2e4d8062016-08-25 20:50:50 +0200116 * to be #if'd out instead of using if (). */
Duncan Laurie59be6242016-03-07 13:21:56 -0800117 if (silicon_init_params.GraphicsConfigPtr)
118 gfx_set_init_done(1);
119#endif
120
Alexandru Gagniuc41c003c2015-08-28 19:07:35 -0400121 display_hob_info(fsp_info_header);
Lee Leahy0946ec32015-04-20 15:24:54 -0700122 soc_after_silicon_init();
123}
124
Aaron Durbinabf87a22015-08-05 12:26:56 -0500125static void fsp_cache_save(struct prog *fsp)
Lee Leahy0946ec32015-04-20 15:24:54 -0700126{
Julius Wernercd49cce2019-03-05 16:53:33 -0800127 if (CONFIG(NO_STAGE_CACHE))
Furquan Shaikh1e162bf2016-05-06 09:20:35 -0700128 return;
129
130 printk(BIOS_DEBUG, "FSP: Saving binary in cache\n");
131
Aaron Durbinabf87a22015-08-05 12:26:56 -0500132 if (prog_entry(fsp) == NULL) {
133 printk(BIOS_ERR, "ERROR: No FSP to save in cache.\n");
Lee Leahy0946ec32015-04-20 15:24:54 -0700134 return;
135 }
136
Aaron Durbinabf87a22015-08-05 12:26:56 -0500137 stage_cache_add(STAGE_REFCODE, fsp);
Lee Leahy0946ec32015-04-20 15:24:54 -0700138}
139
Aaron Durbinabf87a22015-08-05 12:26:56 -0500140static int fsp_find_and_relocate(struct prog *fsp)
Lee Leahy0946ec32015-04-20 15:24:54 -0700141{
Aaron Durbin5d6f0f92015-10-08 15:06:28 -0500142 if (prog_locate(fsp)) {
143 printk(BIOS_ERR, "ERROR: Couldn't find %s\n", prog_name(fsp));
Lee Leahy0946ec32015-04-20 15:24:54 -0700144 return -1;
145 }
146
Aaron Durbin5d6f0f92015-10-08 15:06:28 -0500147 if (fsp_relocate(fsp, prog_rdev(fsp))) {
Aaron Durbin22ea0072015-08-05 10:17:33 -0500148 printk(BIOS_ERR, "ERROR: FSP relocation failed.\n");
149 return -1;
150 }
Lee Leahy0946ec32015-04-20 15:24:54 -0700151
Lee Leahy0946ec32015-04-20 15:24:54 -0700152 return 0;
153}
154
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800155void fsp_load(void)
Lee Leahy0946ec32015-04-20 15:24:54 -0700156{
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800157 static int load_done;
Aaron Durbin7e7a4df2015-12-08 14:34:35 -0600158 struct prog fsp = PROG_INIT(PROG_REFCODE, "fsp.bin");
Aaron Durbin39bdb0b2015-08-04 23:59:43 -0500159 int is_s3_wakeup = acpi_is_wakeup_s3();
Lee Leahy0946ec32015-04-20 15:24:54 -0700160
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800161 if (load_done)
162 return;
163
Julius Wernercd49cce2019-03-05 16:53:33 -0800164 if (is_s3_wakeup && !CONFIG(NO_STAGE_CACHE)) {
Lee Leahy0946ec32015-04-20 15:24:54 -0700165 printk(BIOS_DEBUG, "FSP: Loading binary from cache\n");
Aaron Durbinabf87a22015-08-05 12:26:56 -0500166 stage_cache_load_stage(STAGE_REFCODE, &fsp);
Lee Leahy0946ec32015-04-20 15:24:54 -0700167 } else {
Aaron Durbinabf87a22015-08-05 12:26:56 -0500168 fsp_find_and_relocate(&fsp);
Aaron Durbinabf87a22015-08-05 12:26:56 -0500169 fsp_cache_save(&fsp);
Lee Leahy0946ec32015-04-20 15:24:54 -0700170 }
171
Aaron Durbinabf87a22015-08-05 12:26:56 -0500172 /* FSP_INFO_HEADER is set as the program entry. */
173 fsp_update_fih(prog_entry(&fsp));
174
Furquan Shaikhf4b20af2017-02-20 13:33:32 -0800175 load_done = 1;
176}
177
178void intel_silicon_init(void)
179{
180 fsp_load();
181 fsp_run_silicon_init(fsp_get_fih(), acpi_is_wakeup_s3());
Lee Leahy0946ec32015-04-20 15:24:54 -0700182}
183
184/* Initialize the UPD parameters for SiliconInit */
Aaron Durbin64031672018-04-21 14:45:32 -0600185__weak void mainboard_silicon_init_params(
Lee Leahy0946ec32015-04-20 15:24:54 -0700186 SILICON_INIT_UPD *params)
187{
Lee Leahy0946ec32015-04-20 15:24:54 -0700188};
189
190/* Display the UPD parameters for SiliconInit */
Aaron Durbin64031672018-04-21 14:45:32 -0600191__weak void soc_display_silicon_init_params(
Lee Leahy0946ec32015-04-20 15:24:54 -0700192 const SILICON_INIT_UPD *old, SILICON_INIT_UPD *new)
193{
194 printk(BIOS_SPEW, "UPD values for SiliconInit:\n");
195 hexdump32(BIOS_SPEW, new, sizeof(*new));
196}
197
198/* Initialize the UPD parameters for SiliconInit */
Aaron Durbin64031672018-04-21 14:45:32 -0600199__weak void soc_silicon_init_params(SILICON_INIT_UPD *params)
Lee Leahy0946ec32015-04-20 15:24:54 -0700200{
Lee Leahy0946ec32015-04-20 15:24:54 -0700201}