blob: f71088311b8e5c9d5386f90778d5fa6600b06b7d [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>
John Su85376bf2018-11-06 10:51:43 +080010#include <delay.h>
Andrey Petrovb4831462016-02-25 17:42:25 -080011#include <device/pci_def.h>
12#include <fsp/api.h>
13#include <fsp/util.h>
Barnali Sarkar66fe0c42017-05-23 18:17:14 +053014#include <intelblocks/cpulib.h>
Sean Rhodesbe8cd6b2022-06-01 11:32:05 +010015#include <intelblocks/cse.h>
John Su85376bf2018-11-06 10:51:43 +080016#include <intelblocks/lpc_lib.h>
17#include <intelblocks/msr.h>
18#include <intelblocks/pmclib.h>
Subrata Banik208587e2017-05-19 18:38:24 +053019#include <intelblocks/systemagent.h>
Aaron Durbindecd0622017-12-15 12:26:40 -070020#include <mrc_cache.h>
Shaunak Sahaa0122542016-10-10 12:34:28 -070021#include <soc/cpu.h>
Ravi Sarawadi2da008a2016-04-27 15:20:14 -070022#include <soc/iomap.h>
Aaron Durbin5c9df702018-04-18 01:05:25 -060023#include <soc/meminit.h>
Ravi Sarawadi2da008a2016-04-27 15:20:14 -070024#include <soc/pci_devs.h>
25#include <soc/pm.h>
Andrey Petrovb4831462016-02-25 17:42:25 -080026#include <soc/romstage.h>
John Su85376bf2018-11-06 10:51:43 +080027#include <soc/systemagent.h>
Furquan Shaikhd6c55592016-11-21 12:41:20 -080028#include <spi_flash.h>
Shaunak Sahaa0122542016-10-10 12:34:28 -070029#include <timer.h>
Shaunak Sahaa0122542016-10-10 12:34:28 -070030#include "chip.h"
Andrey Petrovb4831462016-02-25 17:42:25 -080031
Andrey Petrov96e9ff12016-11-04 16:18:30 -070032static const uint8_t hob_variable_guid[16] = {
33 0x7d, 0x14, 0x34, 0xa0, 0x0c, 0x69, 0x54, 0x41,
34 0x8d, 0xe6, 0xc0, 0x44, 0x64, 0x1d, 0xe9, 0x42,
35};
36
Arthur Heymans6d6945b2018-12-29 14:00:46 +010037static uint32_t fsp_version;
Andrey Petrov96e9ff12016-11-04 16:18:30 -070038
Furquan Shaikhc6814092016-05-04 16:03:36 -070039/* High Performance Event Timer Configuration */
40#define P2SB_HPTC 0x60
41#define P2SB_HPTC_ADDRESS_ENABLE (1 << 7)
42/*
43 * ADDRESS_SELECT ENCODING_RANGE
44 * 0 0xFED0 0000 - 0xFED0 03FF
45 * 1 0xFED0 1000 - 0xFED0 13FF
46 * 2 0xFED0 2000 - 0xFED0 23FF
47 * 3 0xFED0 3000 - 0xFED0 33FF
48 */
49#define P2SB_HPTC_ADDRESS_SELECT_0 (0 << 0)
50#define P2SB_HPTC_ADDRESS_SELECT_1 (1 << 0)
51#define P2SB_HPTC_ADDRESS_SELECT_2 (2 << 0)
52#define P2SB_HPTC_ADDRESS_SELECT_3 (3 << 0)
53
Andrey Petrovb4831462016-02-25 17:42:25 -080054/*
55 * Enables several BARs and devices which are needed for memory init
56 * - MCH_BASE_ADDR is needed in order to talk to the memory controller
Andrey Petrovb4831462016-02-25 17:42:25 -080057 * - HPET is enabled because FSP wants to store a pointer to global data in the
58 * HPET comparator register
59 */
60static void soc_early_romstage_init(void)
61{
Subrata Banik208587e2017-05-19 18:38:24 +053062 static const struct sa_mmio_descriptor soc_fixed_pci_resources[] = {
63 { MCHBAR, MCH_BASE_ADDRESS, MCH_BASE_SIZE, "MCHBAR" },
64 };
65
Jonathan Neuschäfer5268b762018-02-12 12:24:25 +010066 /* Set Fixed MMIO address into PCI configuration space */
Subrata Banik208587e2017-05-19 18:38:24 +053067 sa_set_pci_bar(soc_fixed_pci_resources,
68 ARRAY_SIZE(soc_fixed_pci_resources));
Andrey Petrovb4831462016-02-25 17:42:25 -080069
Andrey Petrovb4831462016-02-25 17:42:25 -080070 /* Enable decoding for HPET. Needed for FSP global pointer storage */
Subrata Banik2ee54db2017-03-05 12:37:00 +053071 pci_write_config8(PCH_DEV_P2SB, P2SB_HPTC, P2SB_HPTC_ADDRESS_SELECT_0 |
Furquan Shaikhc6814092016-05-04 16:03:36 -070072 P2SB_HPTC_ADDRESS_ENABLE);
Andrey Petrovb4831462016-02-25 17:42:25 -080073}
74
Shaunak Sahaa0122542016-10-10 12:34:28 -070075/*
76 * Punit Initialization code. This all isn't documented, but
77 * this is the recipe.
78 */
79static bool punit_init(void)
80{
81 uint32_t reg;
82 uint32_t data;
83 struct stopwatch sw;
84
John Su85376bf2018-11-06 10:51:43 +080085 /* Thermal throttle activation offset */
Sumeet R Pawnikar360684b2020-06-18 15:56:11 +053086 configure_tcc_thermal_target();
John Su85376bf2018-11-06 10:51:43 +080087
Shaunak Sahaa0122542016-10-10 12:34:28 -070088 /*
89 * Software Core Disable Mask (P_CR_CORE_DISABLE_MASK_0_0_0_MCHBAR).
90 * Enable all cores here.
91 */
Subrata Banik208587e2017-05-19 18:38:24 +053092 MCHBAR32(CORE_DISABLE_MASK) = 0x0;
Subrata Banikd18b53f2017-05-19 13:44:14 +053093
Shaunak Sahaa0122542016-10-10 12:34:28 -070094 /* P-Unit bring up */
Subrata Banik208587e2017-05-19 18:38:24 +053095 reg = MCHBAR32(BIOS_RESET_CPL);
Shaunak Sahaa0122542016-10-10 12:34:28 -070096 if (reg == 0xffffffff) {
97 /* P-unit not found */
Lee Leahya4447532017-03-09 10:45:02 -080098 printk(BIOS_DEBUG, "Punit MMIO not available\n");
Shaunak Sahaa0122542016-10-10 12:34:28 -070099 return false;
Lee Leahya4447532017-03-09 10:45:02 -0800100 }
101 /* Set Punit interrupt pin IPIN offset 3D */
Subrata Banik2ee54db2017-03-05 12:37:00 +0530102 pci_write_config8(SA_DEV_PUNIT, PCI_INTERRUPT_PIN, 0x2);
Shaunak Sahaa0122542016-10-10 12:34:28 -0700103
Lee Leahya4447532017-03-09 10:45:02 -0800104 /* Set PUINT IRQ to 24 and INTPIN LOCK */
Subrata Banik208587e2017-05-19 18:38:24 +0530105 MCHBAR32(PUNIT_THERMAL_DEVICE_IRQ) =
106 PUINT_THERMAL_DEVICE_IRQ_VEC_NUMBER |
107 PUINT_THERMAL_DEVICE_IRQ_LOCK;
Shaunak Sahaa0122542016-10-10 12:34:28 -0700108
Angel Ponsb36100f2020-09-07 13:18:10 +0200109 if (!CONFIG(SOC_INTEL_GEMINILAKE)) {
Hannah Williams3ff14a02017-05-05 16:30:22 -0700110 data = MCHBAR32(0x7818);
111 data &= 0xFFFFE01F;
112 data |= 0x20 | 0x200;
113 MCHBAR32(0x7818) = data;
114 }
Shaunak Sahaa0122542016-10-10 12:34:28 -0700115
Lee Leahya4447532017-03-09 10:45:02 -0800116 /* Stage0 BIOS Reset Complete (RST_CPL) */
Subrata Banik208587e2017-05-19 18:38:24 +0530117 enable_bios_reset_cpl();
Shaunak Sahaa0122542016-10-10 12:34:28 -0700118
Lee Leahya4447532017-03-09 10:45:02 -0800119 /*
Subrata Banik208587e2017-05-19 18:38:24 +0530120 * Poll for bit 8 to check if PCODE has completed its action
Martin Roth26f97f92021-10-01 14:53:22 -0600121 * in response to BIOS Reset complete.
Lee Leahya4447532017-03-09 10:45:02 -0800122 * We wait here till 1 ms for the bit to get set.
123 */
124 stopwatch_init_msecs_expire(&sw, 1);
Subrata Banik208587e2017-05-19 18:38:24 +0530125 while (!(MCHBAR32(BIOS_RESET_CPL) & PCODE_INIT_DONE)) {
Lee Leahya4447532017-03-09 10:45:02 -0800126 if (stopwatch_expired(&sw)) {
Subrata Banik208587e2017-05-19 18:38:24 +0530127 printk(BIOS_DEBUG, "PCODE Init Done Failure\n");
Lee Leahya4447532017-03-09 10:45:02 -0800128 return false;
Shaunak Sahaa0122542016-10-10 12:34:28 -0700129 }
Lee Leahya4447532017-03-09 10:45:02 -0800130 udelay(100);
Shaunak Sahaa0122542016-10-10 12:34:28 -0700131 }
Subrata Banik208587e2017-05-19 18:38:24 +0530132
Shaunak Sahaa0122542016-10-10 12:34:28 -0700133 return true;
134}
135
Barnali Sarkar66fe0c42017-05-23 18:17:14 +0530136void set_max_freq(void)
137{
138 if (cpu_get_burst_mode_state() == BURST_MODE_UNAVAILABLE) {
139 /* Burst Mode has been factory configured as disabled
140 * and is not available in this physical processor
141 * package.
142 */
143 printk(BIOS_DEBUG, "Burst Mode is factory disabled\n");
144 return;
145 }
146
147 /* Enable burst mode */
Subrata Banik6d569162019-04-10 12:19:27 +0530148 cpu_burst_mode(true);
Barnali Sarkar66fe0c42017-05-23 18:17:14 +0530149
150 /* Enable speed step. */
Subrata Banik6d569162019-04-10 12:19:27 +0530151 cpu_set_eist(true);
Barnali Sarkar66fe0c42017-05-23 18:17:14 +0530152
153 /* Set P-State ratio */
154 cpu_set_p_state_to_turbo_ratio();
155}
156
Kyösti Mälkkicd7a70f2019-08-17 20:51:08 +0300157void mainboard_romstage_entry(void)
Andrey Petrovb4831462016-02-25 17:42:25 -0800158{
Aaron Durbinb4302502016-07-17 17:04:37 -0500159 bool s3wake;
Kyösti Mälkkicd7a70f2019-08-17 20:51:08 +0300160 size_t var_size;
Patrick Georgic6202e82017-10-25 18:47:27 -0400161 struct chipset_power_state *ps = pmc_get_power_state();
Andrey Petrov96e9ff12016-11-04 16:18:30 -0700162 const void *new_var_data;
Andrey Petrovb4831462016-02-25 17:42:25 -0800163
Kyösti Mälkkib7908d22019-08-18 06:01:41 +0300164 soc_early_romstage_init();
Usha Paaf28d22020-02-17 15:14:18 +0530165 report_platform_info();
Kyösti Mälkkib7908d22019-08-18 06:01:41 +0300166
Sean Rhodesbe8cd6b2022-06-01 11:32:05 +0100167 /* Initialize Heci interfaces */
168 heci_init();
169
Shaunak Saha93cdc8b2017-04-18 15:42:09 -0700170 s3wake = pmc_fill_power_state(ps) == ACPI_S3;
Lee Leahy9671faa2016-07-24 18:18:52 -0700171 fsp_memory_init(s3wake);
Shaunak Sahaa0122542016-10-10 12:34:28 -0700172
173 if (punit_init())
174 set_max_freq();
175 else
176 printk(BIOS_DEBUG, "Punit failed to initialize properly\n");
177
Andrey Petrov96e9ff12016-11-04 16:18:30 -0700178 /* Stash variable MRC data and let cache system update it later */
179 new_var_data = fsp_find_extension_hob_by_guid(hob_variable_guid,
180 &var_size);
181 if (new_var_data)
Aaron Durbin31be2c92016-12-03 22:08:20 -0600182 mrc_cache_stash_data(MRC_VARIABLE_DATA,
Arthur Heymans6d6945b2018-12-29 14:00:46 +0100183 fsp_version, new_var_data,
Aaron Durbin31be2c92016-12-03 22:08:20 -0600184 var_size);
Andrey Petrov96e9ff12016-11-04 16:18:30 -0700185 else
186 printk(BIOS_ERR, "Failed to determine variable data\n");
187
Ravi Sarawadi15f6f3a2016-08-18 13:31:29 -0700188 mainboard_save_dimm_info();
Kyösti Mälkkicd7a70f2019-08-17 20:51:08 +0300189}
190
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700191static void fill_console_params(FSPM_UPD *mupd)
Andrey Petrovb4831462016-02-25 17:42:25 -0800192{
Julius Wernercd49cce2019-03-05 16:53:33 -0800193 if (CONFIG(CONSOLE_SERIAL)) {
194 if (CONFIG(INTEL_LPSS_UART_FOR_CONSOLE)) {
Mario Scheithauer9e9cf272017-05-15 17:24:56 +0200195 mupd->FspmConfig.SerialDebugPortDevice =
196 CONFIG_UART_FOR_CONSOLE;
197 /* use MMIO port type */
198 mupd->FspmConfig.SerialDebugPortType = 2;
199 /* use 4 byte register stride */
200 mupd->FspmConfig.SerialDebugPortStrideSize = 2;
201 /* used only for port type set to external */
202 mupd->FspmConfig.SerialDebugPortAddress = 0;
Julius Wernercd49cce2019-03-05 16:53:33 -0800203 } else if (CONFIG(DRIVERS_UART_8250IO)) {
Mario Scheithauer9e9cf272017-05-15 17:24:56 +0200204 /* use external UART for debug */
205 mupd->FspmConfig.SerialDebugPortDevice = 3;
206 /* use I/O port type */
207 mupd->FspmConfig.SerialDebugPortType = 1;
208 /* use 1 byte register stride */
209 mupd->FspmConfig.SerialDebugPortStrideSize = 0;
210 /* used only for port type set to external */
211 mupd->FspmConfig.SerialDebugPortAddress =
212 CONFIG_TTYS0_BASE;
213 }
Andrey Petrovb4831462016-02-25 17:42:25 -0800214 } else {
215 mupd->FspmConfig.SerialDebugPortType = 0;
216 }
217}
218
Aaron Durbin9c86aafe2017-04-26 15:02:51 -0500219static void check_full_retrain(const FSPM_UPD *mupd)
220{
221 struct chipset_power_state *ps;
222
223 if (mupd->FspmArchUpd.BootMode != FSP_BOOT_WITH_FULL_CONFIGURATION)
224 return;
225
Patrick Georgic6202e82017-10-25 18:47:27 -0400226 ps = pmc_get_power_state();
Aaron Durbin9c86aafe2017-04-26 15:02:51 -0500227
228 if (ps->gen_pmcon1 & WARM_RESET_STS) {
229 printk(BIOS_INFO, "Full retrain unsupported on warm reboot.\n");
Patrick Rudolphf677d172018-10-01 19:17:11 +0200230 full_reset();
Aaron Durbin9c86aafe2017-04-26 15:02:51 -0500231 }
232}
233
Maxim Polyakov1a4496e2020-06-20 17:26:21 +0300234static void soc_gpu_init_params(FSPM_UPD *mupd)
235{
236 enum {
Werner Zehf2234422022-03-17 08:37:34 +0100237 GPU_PRIMARY_IGD = 0,
238 GPU_PRIMARY_PCI = 1,
Maxim Polyakov1a4496e2020-06-20 17:26:21 +0300239 };
240 /* Select primary GPU device */
241 if (CONFIG(ONBOARD_VGA_IS_PRIMARY) && is_devfn_enabled(SA_DEVFN_IGD))
242 mupd->FspmConfig.PrimaryVideoAdaptor = GPU_PRIMARY_IGD;
243 else
244 mupd->FspmConfig.PrimaryVideoAdaptor = GPU_PRIMARY_PCI;
245}
246
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700247static void soc_memory_init_params(FSPM_UPD *mupd)
248{
Angel Ponsb36100f2020-09-07 13:18:10 +0200249#if CONFIG(SOC_INTEL_GEMINILAKE)
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700250 /* Only for GLK */
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700251 FSP_M_CONFIG *m_cfg = &mupd->FspmConfig;
252
Michael Niewöhner490546f2020-09-15 12:20:08 +0200253 m_cfg->PrmrrSize = get_valid_prmrr_size();
Shamile Khan3d9462a2018-03-21 14:43:42 -0700254
Srinidhi N Kaushik5af546c2018-05-14 23:33:55 -0700255 /*
256 * CpuMemoryTest in FSP tests 0 to 1M of the RAM after MRC init.
257 * With PAGING_IN_CACHE_AS_RAM enabled for GLK, there was no page
258 * table entry for this range which caused a page fault. Since this
259 * test is anyway not exhaustive, skipping the memory test in FSP.
Shamile Khan3d9462a2018-03-21 14:43:42 -0700260 */
Srinidhi N Kaushik5af546c2018-05-14 23:33:55 -0700261 m_cfg->SkipMemoryTestUpd = 1;
262
263 /*
264 * PCIe power sequence can be done from within FSP when provided
265 * with the GPIOs used for PERST to FSP. Since this is done in
266 * coreboot, skipping the PCIe power sequence done by FSP.
267 */
268 m_cfg->SkipPciePowerSequence = 1;
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700269#endif
270}
271
Shaunak Saha6681cf02018-03-22 06:29:57 -0700272static void parse_devicetree_setting(FSPM_UPD *m_upd)
273{
Angel Ponsb36100f2020-09-07 13:18:10 +0200274#if CONFIG(SOC_INTEL_GEMINILAKE)
Subrata Banik54a34172021-06-09 03:54:58 +0530275 m_upd->FspmConfig.TraceHubEn = is_devfn_enabled(PCH_DEVFN_NPK);
Maxim Polyakov7b98e3e2020-02-16 11:51:57 +0300276#else
Subrata Banik54a34172021-06-09 03:54:58 +0530277 m_upd->FspmConfig.NpkEn = is_devfn_enabled(PCH_DEVFN_NPK);
Shaunak Saha6681cf02018-03-22 06:29:57 -0700278#endif
279}
280
Andrey Petrovf796c6e2016-11-18 14:57:51 -0800281void platform_fsp_memory_init_params_cb(FSPM_UPD *mupd, uint32_t version)
Andrey Petrovb4831462016-02-25 17:42:25 -0800282{
Aaron Durbin9c86aafe2017-04-26 15:02:51 -0500283 check_full_retrain(mupd);
284
Andrey Petrovb4831462016-02-25 17:42:25 -0800285 fill_console_params(mupd);
Maxim Polyakov1a4496e2020-06-20 17:26:21 +0300286 soc_gpu_init_params(mupd);
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700287
Angel Ponsb36100f2020-09-07 13:18:10 +0200288 if (CONFIG(SOC_INTEL_GEMINILAKE))
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700289 soc_memory_init_params(mupd);
290
Andrey Petrovb4831462016-02-25 17:42:25 -0800291 mainboard_memory_init_params(mupd);
292
Shaunak Saha6681cf02018-03-22 06:29:57 -0700293 parse_devicetree_setting(mupd);
294
Andrey Petrovb4831462016-02-25 17:42:25 -0800295 /* Do NOT let FSP do any GPIO pad configuration */
Elyes Haouas9018dee2022-11-18 15:07:33 +0100296 mupd->FspmConfig.PreMemGpioTablePtr = (uintptr_t)NULL;
Andrey Petrov24a594f2016-06-28 17:37:09 -0700297
Sean Rhodesfafcb742022-01-20 21:28:31 +0000298 mupd->FspmConfig.SkipCseRbp = CONFIG(SKIP_CSE_RBP);
Andrey Petrov0910f4e2016-10-03 16:05:20 -0700299
300 /*
301 * Converged Security Engine (CSE) has secure storage functionality.
302 * HECI2 device can be used to access that functionality. However, part
303 * of S3 resume flow involves resetting HECI2 which takes 136ms. Since
304 * coreboot does not use secure storage functionality, instruct FSP to
305 * skip HECI2 reset.
306 */
307 mupd->FspmConfig.EnableS3Heci2 = 0;
Andrey Petrov96e9ff12016-11-04 16:18:30 -0700308
309 /*
310 * Apollolake splits MRC cache into two parts: constant and variable.
311 * The constant part is not expected to change often and variable is.
312 * Currently variable part consists of parameters that change on cold
313 * boots such as scrambler seed and some memory controller registers.
314 * Scrambler seed is vital for S3 resume case because attempt to use
315 * wrong/missing key renders DRAM contents useless.
316 */
317
Shelley Chenad9cd682020-07-23 16:10:52 -0700318 mupd->FspmConfig.VariableNvsBufferPtr =
319 mrc_cache_current_mmap_leak(MRC_VARIABLE_DATA, version,
320 NULL);
321
322 assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED));
Andrey Petrov96e9ff12016-11-04 16:18:30 -0700323
Arthur Heymans6d6945b2018-12-29 14:00:46 +0100324 fsp_version = version;
Andrey Petrovb4831462016-02-25 17:42:25 -0800325}
326
Aaron Durbin64031672018-04-21 14:45:32 -0600327__weak
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700328void mainboard_memory_init_params(FSPM_UPD *mupd)
Andrey Petrovb4831462016-02-25 17:42:25 -0800329{
330 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
331}
Furquan Shaikhbae63832016-06-17 15:50:24 -0700332
Aaron Durbin64031672018-04-21 14:45:32 -0600333__weak
Ravi Sarawadi15f6f3a2016-08-18 13:31:29 -0700334void mainboard_save_dimm_info(void)
335{
336 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
337}