blob: f39a0b0d3639450b132eb417b3c0b18a50360bfc [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>
Ravi Sarawadi2da008a2016-04-27 15:20:14 -070012#include <device/resource.h>
Andrey Petrovb4831462016-02-25 17:42:25 -080013#include <fsp/api.h>
14#include <fsp/util.h>
Barnali Sarkar66fe0c42017-05-23 18:17:14 +053015#include <intelblocks/cpulib.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
Shaunak Saha93cdc8b2017-04-18 15:42:09 -0700167 s3wake = pmc_fill_power_state(ps) == ACPI_S3;
Lee Leahy9671faa2016-07-24 18:18:52 -0700168 fsp_memory_init(s3wake);
Shaunak Sahaa0122542016-10-10 12:34:28 -0700169
170 if (punit_init())
171 set_max_freq();
172 else
173 printk(BIOS_DEBUG, "Punit failed to initialize properly\n");
174
Andrey Petrov96e9ff12016-11-04 16:18:30 -0700175 /* Stash variable MRC data and let cache system update it later */
176 new_var_data = fsp_find_extension_hob_by_guid(hob_variable_guid,
177 &var_size);
178 if (new_var_data)
Aaron Durbin31be2c92016-12-03 22:08:20 -0600179 mrc_cache_stash_data(MRC_VARIABLE_DATA,
Arthur Heymans6d6945b2018-12-29 14:00:46 +0100180 fsp_version, new_var_data,
Aaron Durbin31be2c92016-12-03 22:08:20 -0600181 var_size);
Andrey Petrov96e9ff12016-11-04 16:18:30 -0700182 else
183 printk(BIOS_ERR, "Failed to determine variable data\n");
184
Ravi Sarawadi15f6f3a2016-08-18 13:31:29 -0700185 mainboard_save_dimm_info();
Kyösti Mälkkicd7a70f2019-08-17 20:51:08 +0300186}
187
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700188static void fill_console_params(FSPM_UPD *mupd)
Andrey Petrovb4831462016-02-25 17:42:25 -0800189{
Julius Wernercd49cce2019-03-05 16:53:33 -0800190 if (CONFIG(CONSOLE_SERIAL)) {
191 if (CONFIG(INTEL_LPSS_UART_FOR_CONSOLE)) {
Mario Scheithauer9e9cf272017-05-15 17:24:56 +0200192 mupd->FspmConfig.SerialDebugPortDevice =
193 CONFIG_UART_FOR_CONSOLE;
194 /* use MMIO port type */
195 mupd->FspmConfig.SerialDebugPortType = 2;
196 /* use 4 byte register stride */
197 mupd->FspmConfig.SerialDebugPortStrideSize = 2;
198 /* used only for port type set to external */
199 mupd->FspmConfig.SerialDebugPortAddress = 0;
Julius Wernercd49cce2019-03-05 16:53:33 -0800200 } else if (CONFIG(DRIVERS_UART_8250IO)) {
Mario Scheithauer9e9cf272017-05-15 17:24:56 +0200201 /* use external UART for debug */
202 mupd->FspmConfig.SerialDebugPortDevice = 3;
203 /* use I/O port type */
204 mupd->FspmConfig.SerialDebugPortType = 1;
205 /* use 1 byte register stride */
206 mupd->FspmConfig.SerialDebugPortStrideSize = 0;
207 /* used only for port type set to external */
208 mupd->FspmConfig.SerialDebugPortAddress =
209 CONFIG_TTYS0_BASE;
210 }
Andrey Petrovb4831462016-02-25 17:42:25 -0800211 } else {
212 mupd->FspmConfig.SerialDebugPortType = 0;
213 }
214}
215
Aaron Durbin9c86aafe2017-04-26 15:02:51 -0500216static void check_full_retrain(const FSPM_UPD *mupd)
217{
218 struct chipset_power_state *ps;
219
220 if (mupd->FspmArchUpd.BootMode != FSP_BOOT_WITH_FULL_CONFIGURATION)
221 return;
222
Patrick Georgic6202e82017-10-25 18:47:27 -0400223 ps = pmc_get_power_state();
Aaron Durbin9c86aafe2017-04-26 15:02:51 -0500224
225 if (ps->gen_pmcon1 & WARM_RESET_STS) {
226 printk(BIOS_INFO, "Full retrain unsupported on warm reboot.\n");
Patrick Rudolphf677d172018-10-01 19:17:11 +0200227 full_reset();
Aaron Durbin9c86aafe2017-04-26 15:02:51 -0500228 }
229}
230
Maxim Polyakov1a4496e2020-06-20 17:26:21 +0300231static void soc_gpu_init_params(FSPM_UPD *mupd)
232{
233 enum {
Werner Zehf2234422022-03-17 08:37:34 +0100234 GPU_PRIMARY_IGD = 0,
235 GPU_PRIMARY_PCI = 1,
Maxim Polyakov1a4496e2020-06-20 17:26:21 +0300236 };
237 /* Select primary GPU device */
238 if (CONFIG(ONBOARD_VGA_IS_PRIMARY) && is_devfn_enabled(SA_DEVFN_IGD))
239 mupd->FspmConfig.PrimaryVideoAdaptor = GPU_PRIMARY_IGD;
240 else
241 mupd->FspmConfig.PrimaryVideoAdaptor = GPU_PRIMARY_PCI;
242}
243
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700244static void soc_memory_init_params(FSPM_UPD *mupd)
245{
Angel Ponsb36100f2020-09-07 13:18:10 +0200246#if CONFIG(SOC_INTEL_GEMINILAKE)
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700247 /* Only for GLK */
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700248 FSP_M_CONFIG *m_cfg = &mupd->FspmConfig;
249
Michael Niewöhner490546f2020-09-15 12:20:08 +0200250 m_cfg->PrmrrSize = get_valid_prmrr_size();
Shamile Khan3d9462a2018-03-21 14:43:42 -0700251
Srinidhi N Kaushik5af546c2018-05-14 23:33:55 -0700252 /*
253 * CpuMemoryTest in FSP tests 0 to 1M of the RAM after MRC init.
254 * With PAGING_IN_CACHE_AS_RAM enabled for GLK, there was no page
255 * table entry for this range which caused a page fault. Since this
256 * test is anyway not exhaustive, skipping the memory test in FSP.
Shamile Khan3d9462a2018-03-21 14:43:42 -0700257 */
Srinidhi N Kaushik5af546c2018-05-14 23:33:55 -0700258 m_cfg->SkipMemoryTestUpd = 1;
259
260 /*
261 * PCIe power sequence can be done from within FSP when provided
262 * with the GPIOs used for PERST to FSP. Since this is done in
263 * coreboot, skipping the PCIe power sequence done by FSP.
264 */
265 m_cfg->SkipPciePowerSequence = 1;
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700266#endif
267}
268
Shaunak Saha6681cf02018-03-22 06:29:57 -0700269static void parse_devicetree_setting(FSPM_UPD *m_upd)
270{
Angel Ponsb36100f2020-09-07 13:18:10 +0200271#if CONFIG(SOC_INTEL_GEMINILAKE)
Subrata Banik54a34172021-06-09 03:54:58 +0530272 m_upd->FspmConfig.TraceHubEn = is_devfn_enabled(PCH_DEVFN_NPK);
Maxim Polyakov7b98e3e2020-02-16 11:51:57 +0300273#else
Subrata Banik54a34172021-06-09 03:54:58 +0530274 m_upd->FspmConfig.NpkEn = is_devfn_enabled(PCH_DEVFN_NPK);
Shaunak Saha6681cf02018-03-22 06:29:57 -0700275#endif
276}
277
Andrey Petrovf796c6e2016-11-18 14:57:51 -0800278void platform_fsp_memory_init_params_cb(FSPM_UPD *mupd, uint32_t version)
Andrey Petrovb4831462016-02-25 17:42:25 -0800279{
Aaron Durbin9c86aafe2017-04-26 15:02:51 -0500280 check_full_retrain(mupd);
281
Andrey Petrovb4831462016-02-25 17:42:25 -0800282 fill_console_params(mupd);
Maxim Polyakov1a4496e2020-06-20 17:26:21 +0300283 soc_gpu_init_params(mupd);
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700284
Angel Ponsb36100f2020-09-07 13:18:10 +0200285 if (CONFIG(SOC_INTEL_GEMINILAKE))
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700286 soc_memory_init_params(mupd);
287
Andrey Petrovb4831462016-02-25 17:42:25 -0800288 mainboard_memory_init_params(mupd);
289
Shaunak Saha6681cf02018-03-22 06:29:57 -0700290 parse_devicetree_setting(mupd);
291
Andrey Petrovb4831462016-02-25 17:42:25 -0800292 /* Do NOT let FSP do any GPIO pad configuration */
Bora Guvendikde4b09f2016-05-09 17:18:26 -0700293 mupd->FspmConfig.PreMemGpioTablePtr = (uintptr_t) NULL;
Andrey Petrov24a594f2016-06-28 17:37:09 -0700294
Sean Rhodesfafcb742022-01-20 21:28:31 +0000295 mupd->FspmConfig.SkipCseRbp = CONFIG(SKIP_CSE_RBP);
Andrey Petrov0910f4e2016-10-03 16:05:20 -0700296
297 /*
298 * Converged Security Engine (CSE) has secure storage functionality.
299 * HECI2 device can be used to access that functionality. However, part
300 * of S3 resume flow involves resetting HECI2 which takes 136ms. Since
301 * coreboot does not use secure storage functionality, instruct FSP to
302 * skip HECI2 reset.
303 */
304 mupd->FspmConfig.EnableS3Heci2 = 0;
Andrey Petrov96e9ff12016-11-04 16:18:30 -0700305
306 /*
307 * Apollolake splits MRC cache into two parts: constant and variable.
308 * The constant part is not expected to change often and variable is.
309 * Currently variable part consists of parameters that change on cold
310 * boots such as scrambler seed and some memory controller registers.
311 * Scrambler seed is vital for S3 resume case because attempt to use
312 * wrong/missing key renders DRAM contents useless.
313 */
314
Shelley Chenad9cd682020-07-23 16:10:52 -0700315 mupd->FspmConfig.VariableNvsBufferPtr =
316 mrc_cache_current_mmap_leak(MRC_VARIABLE_DATA, version,
317 NULL);
318
319 assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED));
Andrey Petrov96e9ff12016-11-04 16:18:30 -0700320
Arthur Heymans6d6945b2018-12-29 14:00:46 +0100321 fsp_version = version;
Aaron Durbin5c9df702018-04-18 01:05:25 -0600322
Andrey Petrovb4831462016-02-25 17:42:25 -0800323}
324
Aaron Durbin64031672018-04-21 14:45:32 -0600325__weak
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700326void mainboard_memory_init_params(FSPM_UPD *mupd)
Andrey Petrovb4831462016-02-25 17:42:25 -0800327{
328 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
329}
Furquan Shaikhbae63832016-06-17 15:50:24 -0700330
Aaron Durbin64031672018-04-21 14:45:32 -0600331__weak
Ravi Sarawadi15f6f3a2016-08-18 13:31:29 -0700332void mainboard_save_dimm_info(void)
333{
334 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
335}