blob: c4d7977c41ff6635965ecd00fea527887e4d2854 [file] [log] [blame]
Patrick Georgiac959032020-05-05 22:49:26 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Andrey Petrovb4831462016-02-25 17:42:25 -08002
Kyösti Mälkkia963acd2019-08-16 20:34:25 +03003#include <arch/romstage.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02004#include <device/pci_ops.h>
Andrey Petrovb4831462016-02-25 17:42:25 -08005#include <arch/symbols.h>
Ravi Sarawadi2da008a2016-04-27 15:20:14 -07006#include <assert.h>
Patrick Rudolphf677d172018-10-01 19:17:11 +02007#include <cf9_reset.h>
Andrey Petrovb4831462016-02-25 17:42:25 -08008#include <console/console.h>
Felix Singer6c3a89c2020-07-26 09:26:52 +02009#include <device/device.h>
Aaron Durbin5c9df702018-04-18 01:05:25 -060010#include <cpu/x86/pae.h>
John Su85376bf2018-11-06 10:51:43 +080011#include <delay.h>
Andrey Petrovb4831462016-02-25 17:42:25 -080012#include <device/pci_def.h>
Ravi Sarawadi2da008a2016-04-27 15:20:14 -070013#include <device/resource.h>
Andrey Petrovb4831462016-02-25 17:42:25 -080014#include <fsp/api.h>
15#include <fsp/util.h>
Barnali Sarkar66fe0c42017-05-23 18:17:14 +053016#include <intelblocks/cpulib.h>
John Su85376bf2018-11-06 10:51:43 +080017#include <intelblocks/lpc_lib.h>
18#include <intelblocks/msr.h>
19#include <intelblocks/pmclib.h>
Subrata Banik208587e2017-05-19 18:38:24 +053020#include <intelblocks/systemagent.h>
Aaron Durbindecd0622017-12-15 12:26:40 -070021#include <mrc_cache.h>
Shaunak Sahaa0122542016-10-10 12:34:28 -070022#include <soc/cpu.h>
Ravi Sarawadi2da008a2016-04-27 15:20:14 -070023#include <soc/iomap.h>
Aaron Durbin5c9df702018-04-18 01:05:25 -060024#include <soc/meminit.h>
Ravi Sarawadi2da008a2016-04-27 15:20:14 -070025#include <soc/pci_devs.h>
26#include <soc/pm.h>
Andrey Petrovb4831462016-02-25 17:42:25 -080027#include <soc/romstage.h>
John Su85376bf2018-11-06 10:51:43 +080028#include <soc/systemagent.h>
Furquan Shaikhd6c55592016-11-21 12:41:20 -080029#include <spi_flash.h>
Shaunak Sahaa0122542016-10-10 12:34:28 -070030#include <timer.h>
Shaunak Sahaa0122542016-10-10 12:34:28 -070031#include "chip.h"
Andrey Petrovb4831462016-02-25 17:42:25 -080032
Andrey Petrov96e9ff12016-11-04 16:18:30 -070033static const uint8_t hob_variable_guid[16] = {
34 0x7d, 0x14, 0x34, 0xa0, 0x0c, 0x69, 0x54, 0x41,
35 0x8d, 0xe6, 0xc0, 0x44, 0x64, 0x1d, 0xe9, 0x42,
36};
37
Arthur Heymans6d6945b2018-12-29 14:00:46 +010038static uint32_t fsp_version;
Andrey Petrov96e9ff12016-11-04 16:18:30 -070039
Furquan Shaikhc6814092016-05-04 16:03:36 -070040/* High Performance Event Timer Configuration */
41#define P2SB_HPTC 0x60
42#define P2SB_HPTC_ADDRESS_ENABLE (1 << 7)
43/*
44 * ADDRESS_SELECT ENCODING_RANGE
45 * 0 0xFED0 0000 - 0xFED0 03FF
46 * 1 0xFED0 1000 - 0xFED0 13FF
47 * 2 0xFED0 2000 - 0xFED0 23FF
48 * 3 0xFED0 3000 - 0xFED0 33FF
49 */
50#define P2SB_HPTC_ADDRESS_SELECT_0 (0 << 0)
51#define P2SB_HPTC_ADDRESS_SELECT_1 (1 << 0)
52#define P2SB_HPTC_ADDRESS_SELECT_2 (2 << 0)
53#define P2SB_HPTC_ADDRESS_SELECT_3 (3 << 0)
54
Andrey Petrovb4831462016-02-25 17:42:25 -080055/*
56 * Enables several BARs and devices which are needed for memory init
57 * - MCH_BASE_ADDR is needed in order to talk to the memory controller
Andrey Petrovb4831462016-02-25 17:42:25 -080058 * - HPET is enabled because FSP wants to store a pointer to global data in the
59 * HPET comparator register
60 */
61static void soc_early_romstage_init(void)
62{
Subrata Banik208587e2017-05-19 18:38:24 +053063 static const struct sa_mmio_descriptor soc_fixed_pci_resources[] = {
64 { MCHBAR, MCH_BASE_ADDRESS, MCH_BASE_SIZE, "MCHBAR" },
65 };
66
Jonathan Neuschäfer5268b762018-02-12 12:24:25 +010067 /* Set Fixed MMIO address into PCI configuration space */
Subrata Banik208587e2017-05-19 18:38:24 +053068 sa_set_pci_bar(soc_fixed_pci_resources,
69 ARRAY_SIZE(soc_fixed_pci_resources));
Andrey Petrovb4831462016-02-25 17:42:25 -080070
Andrey Petrovb4831462016-02-25 17:42:25 -080071 /* Enable decoding for HPET. Needed for FSP global pointer storage */
Subrata Banik2ee54db2017-03-05 12:37:00 +053072 pci_write_config8(PCH_DEV_P2SB, P2SB_HPTC, P2SB_HPTC_ADDRESS_SELECT_0 |
Furquan Shaikhc6814092016-05-04 16:03:36 -070073 P2SB_HPTC_ADDRESS_ENABLE);
Andrey Petrovb4831462016-02-25 17:42:25 -080074}
75
Shaunak Sahaa0122542016-10-10 12:34:28 -070076/*
77 * Punit Initialization code. This all isn't documented, but
78 * this is the recipe.
79 */
80static bool punit_init(void)
81{
82 uint32_t reg;
83 uint32_t data;
84 struct stopwatch sw;
85
John Su85376bf2018-11-06 10:51:43 +080086 /* Thermal throttle activation offset */
Sumeet R Pawnikar360684b2020-06-18 15:56:11 +053087 configure_tcc_thermal_target();
John Su85376bf2018-11-06 10:51:43 +080088
Shaunak Sahaa0122542016-10-10 12:34:28 -070089 /*
90 * Software Core Disable Mask (P_CR_CORE_DISABLE_MASK_0_0_0_MCHBAR).
91 * Enable all cores here.
92 */
Subrata Banik208587e2017-05-19 18:38:24 +053093 MCHBAR32(CORE_DISABLE_MASK) = 0x0;
Subrata Banikd18b53f2017-05-19 13:44:14 +053094
Shaunak Sahaa0122542016-10-10 12:34:28 -070095 /* P-Unit bring up */
Subrata Banik208587e2017-05-19 18:38:24 +053096 reg = MCHBAR32(BIOS_RESET_CPL);
Shaunak Sahaa0122542016-10-10 12:34:28 -070097 if (reg == 0xffffffff) {
98 /* P-unit not found */
Lee Leahya4447532017-03-09 10:45:02 -080099 printk(BIOS_DEBUG, "Punit MMIO not available\n");
Shaunak Sahaa0122542016-10-10 12:34:28 -0700100 return false;
Lee Leahya4447532017-03-09 10:45:02 -0800101 }
102 /* Set Punit interrupt pin IPIN offset 3D */
Subrata Banik2ee54db2017-03-05 12:37:00 +0530103 pci_write_config8(SA_DEV_PUNIT, PCI_INTERRUPT_PIN, 0x2);
Shaunak Sahaa0122542016-10-10 12:34:28 -0700104
Lee Leahya4447532017-03-09 10:45:02 -0800105 /* Set PUINT IRQ to 24 and INTPIN LOCK */
Subrata Banik208587e2017-05-19 18:38:24 +0530106 MCHBAR32(PUNIT_THERMAL_DEVICE_IRQ) =
107 PUINT_THERMAL_DEVICE_IRQ_VEC_NUMBER |
108 PUINT_THERMAL_DEVICE_IRQ_LOCK;
Shaunak Sahaa0122542016-10-10 12:34:28 -0700109
Angel Ponsb36100f2020-09-07 13:18:10 +0200110 if (!CONFIG(SOC_INTEL_GEMINILAKE)) {
Hannah Williams3ff14a02017-05-05 16:30:22 -0700111 data = MCHBAR32(0x7818);
112 data &= 0xFFFFE01F;
113 data |= 0x20 | 0x200;
114 MCHBAR32(0x7818) = data;
115 }
Shaunak Sahaa0122542016-10-10 12:34:28 -0700116
Lee Leahya4447532017-03-09 10:45:02 -0800117 /* Stage0 BIOS Reset Complete (RST_CPL) */
Subrata Banik208587e2017-05-19 18:38:24 +0530118 enable_bios_reset_cpl();
Shaunak Sahaa0122542016-10-10 12:34:28 -0700119
Lee Leahya4447532017-03-09 10:45:02 -0800120 /*
Subrata Banik208587e2017-05-19 18:38:24 +0530121 * Poll for bit 8 to check if PCODE has completed its action
Martin Roth26f97f92021-10-01 14:53:22 -0600122 * in response to BIOS Reset complete.
Lee Leahya4447532017-03-09 10:45:02 -0800123 * We wait here till 1 ms for the bit to get set.
124 */
125 stopwatch_init_msecs_expire(&sw, 1);
Subrata Banik208587e2017-05-19 18:38:24 +0530126 while (!(MCHBAR32(BIOS_RESET_CPL) & PCODE_INIT_DONE)) {
Lee Leahya4447532017-03-09 10:45:02 -0800127 if (stopwatch_expired(&sw)) {
Subrata Banik208587e2017-05-19 18:38:24 +0530128 printk(BIOS_DEBUG, "PCODE Init Done Failure\n");
Lee Leahya4447532017-03-09 10:45:02 -0800129 return false;
Shaunak Sahaa0122542016-10-10 12:34:28 -0700130 }
Lee Leahya4447532017-03-09 10:45:02 -0800131 udelay(100);
Shaunak Sahaa0122542016-10-10 12:34:28 -0700132 }
Subrata Banik208587e2017-05-19 18:38:24 +0530133
Shaunak Sahaa0122542016-10-10 12:34:28 -0700134 return true;
135}
136
Barnali Sarkar66fe0c42017-05-23 18:17:14 +0530137void set_max_freq(void)
138{
139 if (cpu_get_burst_mode_state() == BURST_MODE_UNAVAILABLE) {
140 /* Burst Mode has been factory configured as disabled
141 * and is not available in this physical processor
142 * package.
143 */
144 printk(BIOS_DEBUG, "Burst Mode is factory disabled\n");
145 return;
146 }
147
148 /* Enable burst mode */
Subrata Banik6d569162019-04-10 12:19:27 +0530149 cpu_burst_mode(true);
Barnali Sarkar66fe0c42017-05-23 18:17:14 +0530150
151 /* Enable speed step. */
Subrata Banik6d569162019-04-10 12:19:27 +0530152 cpu_set_eist(true);
Barnali Sarkar66fe0c42017-05-23 18:17:14 +0530153
154 /* Set P-State ratio */
155 cpu_set_p_state_to_turbo_ratio();
156}
157
Kyösti Mälkkicd7a70f2019-08-17 20:51:08 +0300158void mainboard_romstage_entry(void)
Andrey Petrovb4831462016-02-25 17:42:25 -0800159{
Aaron Durbinb4302502016-07-17 17:04:37 -0500160 bool s3wake;
Kyösti Mälkkicd7a70f2019-08-17 20:51:08 +0300161 size_t var_size;
Patrick Georgic6202e82017-10-25 18:47:27 -0400162 struct chipset_power_state *ps = pmc_get_power_state();
Andrey Petrov96e9ff12016-11-04 16:18:30 -0700163 const void *new_var_data;
Andrey Petrovb4831462016-02-25 17:42:25 -0800164
Kyösti Mälkkib7908d22019-08-18 06:01:41 +0300165 soc_early_romstage_init();
Usha Paaf28d22020-02-17 15:14:18 +0530166 report_platform_info();
Kyösti Mälkkib7908d22019-08-18 06:01:41 +0300167
Shaunak Saha93cdc8b2017-04-18 15:42:09 -0700168 s3wake = pmc_fill_power_state(ps) == ACPI_S3;
Lee Leahy9671faa2016-07-24 18:18:52 -0700169 fsp_memory_init(s3wake);
Shaunak Sahaa0122542016-10-10 12:34:28 -0700170
171 if (punit_init())
172 set_max_freq();
173 else
174 printk(BIOS_DEBUG, "Punit failed to initialize properly\n");
175
Andrey Petrov96e9ff12016-11-04 16:18:30 -0700176 /* Stash variable MRC data and let cache system update it later */
177 new_var_data = fsp_find_extension_hob_by_guid(hob_variable_guid,
178 &var_size);
179 if (new_var_data)
Aaron Durbin31be2c92016-12-03 22:08:20 -0600180 mrc_cache_stash_data(MRC_VARIABLE_DATA,
Arthur Heymans6d6945b2018-12-29 14:00:46 +0100181 fsp_version, new_var_data,
Aaron Durbin31be2c92016-12-03 22:08:20 -0600182 var_size);
Andrey Petrov96e9ff12016-11-04 16:18:30 -0700183 else
184 printk(BIOS_ERR, "Failed to determine variable data\n");
185
Ravi Sarawadi15f6f3a2016-08-18 13:31:29 -0700186 mainboard_save_dimm_info();
Kyösti Mälkkicd7a70f2019-08-17 20:51:08 +0300187}
188
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700189static void fill_console_params(FSPM_UPD *mupd)
Andrey Petrovb4831462016-02-25 17:42:25 -0800190{
Julius Wernercd49cce2019-03-05 16:53:33 -0800191 if (CONFIG(CONSOLE_SERIAL)) {
192 if (CONFIG(INTEL_LPSS_UART_FOR_CONSOLE)) {
Mario Scheithauer9e9cf272017-05-15 17:24:56 +0200193 mupd->FspmConfig.SerialDebugPortDevice =
194 CONFIG_UART_FOR_CONSOLE;
195 /* use MMIO port type */
196 mupd->FspmConfig.SerialDebugPortType = 2;
197 /* use 4 byte register stride */
198 mupd->FspmConfig.SerialDebugPortStrideSize = 2;
199 /* used only for port type set to external */
200 mupd->FspmConfig.SerialDebugPortAddress = 0;
Julius Wernercd49cce2019-03-05 16:53:33 -0800201 } else if (CONFIG(DRIVERS_UART_8250IO)) {
Mario Scheithauer9e9cf272017-05-15 17:24:56 +0200202 /* use external UART for debug */
203 mupd->FspmConfig.SerialDebugPortDevice = 3;
204 /* use I/O port type */
205 mupd->FspmConfig.SerialDebugPortType = 1;
206 /* use 1 byte register stride */
207 mupd->FspmConfig.SerialDebugPortStrideSize = 0;
208 /* used only for port type set to external */
209 mupd->FspmConfig.SerialDebugPortAddress =
210 CONFIG_TTYS0_BASE;
211 }
Andrey Petrovb4831462016-02-25 17:42:25 -0800212 } else {
213 mupd->FspmConfig.SerialDebugPortType = 0;
214 }
215}
216
Aaron Durbin9c86aafe2017-04-26 15:02:51 -0500217static void check_full_retrain(const FSPM_UPD *mupd)
218{
219 struct chipset_power_state *ps;
220
221 if (mupd->FspmArchUpd.BootMode != FSP_BOOT_WITH_FULL_CONFIGURATION)
222 return;
223
Patrick Georgic6202e82017-10-25 18:47:27 -0400224 ps = pmc_get_power_state();
Aaron Durbin9c86aafe2017-04-26 15:02:51 -0500225
226 if (ps->gen_pmcon1 & WARM_RESET_STS) {
227 printk(BIOS_INFO, "Full retrain unsupported on warm reboot.\n");
Patrick Rudolphf677d172018-10-01 19:17:11 +0200228 full_reset();
Aaron Durbin9c86aafe2017-04-26 15:02:51 -0500229 }
230}
231
Maxim Polyakov1a4496e2020-06-20 17:26:21 +0300232static void soc_gpu_init_params(FSPM_UPD *mupd)
233{
234 enum {
235 GPU_PRIMARY_IGD = 2,
236 GPU_PRIMARY_PCI = 3,
237 };
238 /* Select primary GPU device */
239 if (CONFIG(ONBOARD_VGA_IS_PRIMARY) && is_devfn_enabled(SA_DEVFN_IGD))
240 mupd->FspmConfig.PrimaryVideoAdaptor = GPU_PRIMARY_IGD;
241 else
242 mupd->FspmConfig.PrimaryVideoAdaptor = GPU_PRIMARY_PCI;
243}
244
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700245static void soc_memory_init_params(FSPM_UPD *mupd)
246{
Angel Ponsb36100f2020-09-07 13:18:10 +0200247#if CONFIG(SOC_INTEL_GEMINILAKE)
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700248 /* Only for GLK */
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700249 FSP_M_CONFIG *m_cfg = &mupd->FspmConfig;
250
Michael Niewöhner490546f2020-09-15 12:20:08 +0200251 m_cfg->PrmrrSize = get_valid_prmrr_size();
Shamile Khan3d9462a2018-03-21 14:43:42 -0700252
Srinidhi N Kaushik5af546c2018-05-14 23:33:55 -0700253 /*
254 * CpuMemoryTest in FSP tests 0 to 1M of the RAM after MRC init.
255 * With PAGING_IN_CACHE_AS_RAM enabled for GLK, there was no page
256 * table entry for this range which caused a page fault. Since this
257 * test is anyway not exhaustive, skipping the memory test in FSP.
Shamile Khan3d9462a2018-03-21 14:43:42 -0700258 */
Srinidhi N Kaushik5af546c2018-05-14 23:33:55 -0700259 m_cfg->SkipMemoryTestUpd = 1;
260
261 /*
262 * PCIe power sequence can be done from within FSP when provided
263 * with the GPIOs used for PERST to FSP. Since this is done in
264 * coreboot, skipping the PCIe power sequence done by FSP.
265 */
266 m_cfg->SkipPciePowerSequence = 1;
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700267#endif
268}
269
Shaunak Saha6681cf02018-03-22 06:29:57 -0700270static void parse_devicetree_setting(FSPM_UPD *m_upd)
271{
Angel Ponsb36100f2020-09-07 13:18:10 +0200272#if CONFIG(SOC_INTEL_GEMINILAKE)
Subrata Banik54a34172021-06-09 03:54:58 +0530273 m_upd->FspmConfig.TraceHubEn = is_devfn_enabled(PCH_DEVFN_NPK);
Maxim Polyakov7b98e3e2020-02-16 11:51:57 +0300274#else
Subrata Banik54a34172021-06-09 03:54:58 +0530275 m_upd->FspmConfig.NpkEn = is_devfn_enabled(PCH_DEVFN_NPK);
Shaunak Saha6681cf02018-03-22 06:29:57 -0700276#endif
277}
278
Andrey Petrovf796c6e2016-11-18 14:57:51 -0800279void platform_fsp_memory_init_params_cb(FSPM_UPD *mupd, uint32_t version)
Andrey Petrovb4831462016-02-25 17:42:25 -0800280{
Aaron Durbin9c86aafe2017-04-26 15:02:51 -0500281 check_full_retrain(mupd);
282
Andrey Petrovb4831462016-02-25 17:42:25 -0800283 fill_console_params(mupd);
Maxim Polyakov1a4496e2020-06-20 17:26:21 +0300284 soc_gpu_init_params(mupd);
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700285
Angel Ponsb36100f2020-09-07 13:18:10 +0200286 if (CONFIG(SOC_INTEL_GEMINILAKE))
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700287 soc_memory_init_params(mupd);
288
Andrey Petrovb4831462016-02-25 17:42:25 -0800289 mainboard_memory_init_params(mupd);
290
Shaunak Saha6681cf02018-03-22 06:29:57 -0700291 parse_devicetree_setting(mupd);
292
Andrey Petrovb4831462016-02-25 17:42:25 -0800293 /* Do NOT let FSP do any GPIO pad configuration */
Bora Guvendikde4b09f2016-05-09 17:18:26 -0700294 mupd->FspmConfig.PreMemGpioTablePtr = (uintptr_t) NULL;
Andrey Petrov24a594f2016-06-28 17:37:09 -0700295
296 /*
297 * Tell CSE we do not need to use Ring Buffer Protocol (RBP) to fetch
298 * firmware for us if we are using memory-mapped SPI. This lets CSE
299 * state machine transition to next boot state, so that it can function
300 * as designed.
301 */
Aaron Durbin16c173f2016-08-11 14:04:10 -0500302 mupd->FspmConfig.SkipCseRbp =
Julius Wernercd49cce2019-03-05 16:53:33 -0800303 CONFIG(BOOT_DEVICE_MEMORY_MAPPED);
Andrey Petrov0910f4e2016-10-03 16:05:20 -0700304
305 /*
306 * Converged Security Engine (CSE) has secure storage functionality.
307 * HECI2 device can be used to access that functionality. However, part
308 * of S3 resume flow involves resetting HECI2 which takes 136ms. Since
309 * coreboot does not use secure storage functionality, instruct FSP to
310 * skip HECI2 reset.
311 */
312 mupd->FspmConfig.EnableS3Heci2 = 0;
Andrey Petrov96e9ff12016-11-04 16:18:30 -0700313
314 /*
315 * Apollolake splits MRC cache into two parts: constant and variable.
316 * The constant part is not expected to change often and variable is.
317 * Currently variable part consists of parameters that change on cold
318 * boots such as scrambler seed and some memory controller registers.
319 * Scrambler seed is vital for S3 resume case because attempt to use
320 * wrong/missing key renders DRAM contents useless.
321 */
322
Shelley Chenad9cd682020-07-23 16:10:52 -0700323 mupd->FspmConfig.VariableNvsBufferPtr =
324 mrc_cache_current_mmap_leak(MRC_VARIABLE_DATA, version,
325 NULL);
326
327 assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED));
Andrey Petrov96e9ff12016-11-04 16:18:30 -0700328
Arthur Heymans6d6945b2018-12-29 14:00:46 +0100329 fsp_version = version;
Aaron Durbin5c9df702018-04-18 01:05:25 -0600330
Andrey Petrovb4831462016-02-25 17:42:25 -0800331}
332
Aaron Durbin64031672018-04-21 14:45:32 -0600333__weak
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700334void mainboard_memory_init_params(FSPM_UPD *mupd)
Andrey Petrovb4831462016-02-25 17:42:25 -0800335{
336 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
337}
Furquan Shaikhbae63832016-06-17 15:50:24 -0700338
Aaron Durbin64031672018-04-21 14:45:32 -0600339__weak
Ravi Sarawadi15f6f3a2016-08-18 13:31:29 -0700340void mainboard_save_dimm_info(void)
341{
342 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
343}