blob: ba865e32b2e36e4647ab26b018543ea6ddf72b44 [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>
Sean Rhodesbe8cd6b2022-06-01 11:32:05 +010016#include <intelblocks/cse.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
Sean Rhodesbe8cd6b2022-06-01 11:32:05 +0100168 /* Initialize Heci interfaces */
169 heci_init();
170
Shaunak Saha93cdc8b2017-04-18 15:42:09 -0700171 s3wake = pmc_fill_power_state(ps) == ACPI_S3;
Lee Leahy9671faa2016-07-24 18:18:52 -0700172 fsp_memory_init(s3wake);
Shaunak Sahaa0122542016-10-10 12:34:28 -0700173
174 if (punit_init())
175 set_max_freq();
176 else
177 printk(BIOS_DEBUG, "Punit failed to initialize properly\n");
178
Andrey Petrov96e9ff12016-11-04 16:18:30 -0700179 /* Stash variable MRC data and let cache system update it later */
180 new_var_data = fsp_find_extension_hob_by_guid(hob_variable_guid,
181 &var_size);
182 if (new_var_data)
Aaron Durbin31be2c92016-12-03 22:08:20 -0600183 mrc_cache_stash_data(MRC_VARIABLE_DATA,
Arthur Heymans6d6945b2018-12-29 14:00:46 +0100184 fsp_version, new_var_data,
Aaron Durbin31be2c92016-12-03 22:08:20 -0600185 var_size);
Andrey Petrov96e9ff12016-11-04 16:18:30 -0700186 else
187 printk(BIOS_ERR, "Failed to determine variable data\n");
188
Ravi Sarawadi15f6f3a2016-08-18 13:31:29 -0700189 mainboard_save_dimm_info();
Kyösti Mälkkicd7a70f2019-08-17 20:51:08 +0300190}
191
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700192static void fill_console_params(FSPM_UPD *mupd)
Andrey Petrovb4831462016-02-25 17:42:25 -0800193{
Julius Wernercd49cce2019-03-05 16:53:33 -0800194 if (CONFIG(CONSOLE_SERIAL)) {
195 if (CONFIG(INTEL_LPSS_UART_FOR_CONSOLE)) {
Mario Scheithauer9e9cf272017-05-15 17:24:56 +0200196 mupd->FspmConfig.SerialDebugPortDevice =
197 CONFIG_UART_FOR_CONSOLE;
198 /* use MMIO port type */
199 mupd->FspmConfig.SerialDebugPortType = 2;
200 /* use 4 byte register stride */
201 mupd->FspmConfig.SerialDebugPortStrideSize = 2;
202 /* used only for port type set to external */
203 mupd->FspmConfig.SerialDebugPortAddress = 0;
Julius Wernercd49cce2019-03-05 16:53:33 -0800204 } else if (CONFIG(DRIVERS_UART_8250IO)) {
Mario Scheithauer9e9cf272017-05-15 17:24:56 +0200205 /* use external UART for debug */
206 mupd->FspmConfig.SerialDebugPortDevice = 3;
207 /* use I/O port type */
208 mupd->FspmConfig.SerialDebugPortType = 1;
209 /* use 1 byte register stride */
210 mupd->FspmConfig.SerialDebugPortStrideSize = 0;
211 /* used only for port type set to external */
212 mupd->FspmConfig.SerialDebugPortAddress =
213 CONFIG_TTYS0_BASE;
214 }
Andrey Petrovb4831462016-02-25 17:42:25 -0800215 } else {
216 mupd->FspmConfig.SerialDebugPortType = 0;
217 }
218}
219
Aaron Durbin9c86aafe2017-04-26 15:02:51 -0500220static void check_full_retrain(const FSPM_UPD *mupd)
221{
222 struct chipset_power_state *ps;
223
224 if (mupd->FspmArchUpd.BootMode != FSP_BOOT_WITH_FULL_CONFIGURATION)
225 return;
226
Patrick Georgic6202e82017-10-25 18:47:27 -0400227 ps = pmc_get_power_state();
Aaron Durbin9c86aafe2017-04-26 15:02:51 -0500228
229 if (ps->gen_pmcon1 & WARM_RESET_STS) {
230 printk(BIOS_INFO, "Full retrain unsupported on warm reboot.\n");
Patrick Rudolphf677d172018-10-01 19:17:11 +0200231 full_reset();
Aaron Durbin9c86aafe2017-04-26 15:02:51 -0500232 }
233}
234
Maxim Polyakov1a4496e2020-06-20 17:26:21 +0300235static void soc_gpu_init_params(FSPM_UPD *mupd)
236{
237 enum {
Werner Zehf2234422022-03-17 08:37:34 +0100238 GPU_PRIMARY_IGD = 0,
239 GPU_PRIMARY_PCI = 1,
Maxim Polyakov1a4496e2020-06-20 17:26:21 +0300240 };
241 /* Select primary GPU device */
242 if (CONFIG(ONBOARD_VGA_IS_PRIMARY) && is_devfn_enabled(SA_DEVFN_IGD))
243 mupd->FspmConfig.PrimaryVideoAdaptor = GPU_PRIMARY_IGD;
244 else
245 mupd->FspmConfig.PrimaryVideoAdaptor = GPU_PRIMARY_PCI;
246}
247
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700248static void soc_memory_init_params(FSPM_UPD *mupd)
249{
Angel Ponsb36100f2020-09-07 13:18:10 +0200250#if CONFIG(SOC_INTEL_GEMINILAKE)
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700251 /* Only for GLK */
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700252 FSP_M_CONFIG *m_cfg = &mupd->FspmConfig;
253
Michael Niewöhner490546f2020-09-15 12:20:08 +0200254 m_cfg->PrmrrSize = get_valid_prmrr_size();
Shamile Khan3d9462a2018-03-21 14:43:42 -0700255
Srinidhi N Kaushik5af546c2018-05-14 23:33:55 -0700256 /*
257 * CpuMemoryTest in FSP tests 0 to 1M of the RAM after MRC init.
258 * With PAGING_IN_CACHE_AS_RAM enabled for GLK, there was no page
259 * table entry for this range which caused a page fault. Since this
260 * test is anyway not exhaustive, skipping the memory test in FSP.
Shamile Khan3d9462a2018-03-21 14:43:42 -0700261 */
Srinidhi N Kaushik5af546c2018-05-14 23:33:55 -0700262 m_cfg->SkipMemoryTestUpd = 1;
263
264 /*
265 * PCIe power sequence can be done from within FSP when provided
266 * with the GPIOs used for PERST to FSP. Since this is done in
267 * coreboot, skipping the PCIe power sequence done by FSP.
268 */
269 m_cfg->SkipPciePowerSequence = 1;
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700270#endif
271}
272
Shaunak Saha6681cf02018-03-22 06:29:57 -0700273static void parse_devicetree_setting(FSPM_UPD *m_upd)
274{
Angel Ponsb36100f2020-09-07 13:18:10 +0200275#if CONFIG(SOC_INTEL_GEMINILAKE)
Subrata Banik54a34172021-06-09 03:54:58 +0530276 m_upd->FspmConfig.TraceHubEn = is_devfn_enabled(PCH_DEVFN_NPK);
Maxim Polyakov7b98e3e2020-02-16 11:51:57 +0300277#else
Subrata Banik54a34172021-06-09 03:54:58 +0530278 m_upd->FspmConfig.NpkEn = is_devfn_enabled(PCH_DEVFN_NPK);
Shaunak Saha6681cf02018-03-22 06:29:57 -0700279#endif
280}
281
Andrey Petrovf796c6e2016-11-18 14:57:51 -0800282void platform_fsp_memory_init_params_cb(FSPM_UPD *mupd, uint32_t version)
Andrey Petrovb4831462016-02-25 17:42:25 -0800283{
Aaron Durbin9c86aafe2017-04-26 15:02:51 -0500284 check_full_retrain(mupd);
285
Andrey Petrovb4831462016-02-25 17:42:25 -0800286 fill_console_params(mupd);
Maxim Polyakov1a4496e2020-06-20 17:26:21 +0300287 soc_gpu_init_params(mupd);
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700288
Angel Ponsb36100f2020-09-07 13:18:10 +0200289 if (CONFIG(SOC_INTEL_GEMINILAKE))
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -0700290 soc_memory_init_params(mupd);
291
Andrey Petrovb4831462016-02-25 17:42:25 -0800292 mainboard_memory_init_params(mupd);
293
Shaunak Saha6681cf02018-03-22 06:29:57 -0700294 parse_devicetree_setting(mupd);
295
Andrey Petrovb4831462016-02-25 17:42:25 -0800296 /* Do NOT let FSP do any GPIO pad configuration */
Elyes Haouas9018dee2022-11-18 15:07:33 +0100297 mupd->FspmConfig.PreMemGpioTablePtr = (uintptr_t)NULL;
Andrey Petrov24a594f2016-06-28 17:37:09 -0700298
Sean Rhodesfafcb742022-01-20 21:28:31 +0000299 mupd->FspmConfig.SkipCseRbp = CONFIG(SKIP_CSE_RBP);
Andrey Petrov0910f4e2016-10-03 16:05:20 -0700300
301 /*
302 * Converged Security Engine (CSE) has secure storage functionality.
303 * HECI2 device can be used to access that functionality. However, part
304 * of S3 resume flow involves resetting HECI2 which takes 136ms. Since
305 * coreboot does not use secure storage functionality, instruct FSP to
306 * skip HECI2 reset.
307 */
308 mupd->FspmConfig.EnableS3Heci2 = 0;
Andrey Petrov96e9ff12016-11-04 16:18:30 -0700309
310 /*
311 * Apollolake splits MRC cache into two parts: constant and variable.
312 * The constant part is not expected to change often and variable is.
313 * Currently variable part consists of parameters that change on cold
314 * boots such as scrambler seed and some memory controller registers.
315 * Scrambler seed is vital for S3 resume case because attempt to use
316 * wrong/missing key renders DRAM contents useless.
317 */
318
Shelley Chenad9cd682020-07-23 16:10:52 -0700319 mupd->FspmConfig.VariableNvsBufferPtr =
320 mrc_cache_current_mmap_leak(MRC_VARIABLE_DATA, version,
321 NULL);
322
323 assert(CONFIG(BOOT_DEVICE_MEMORY_MAPPED));
Andrey Petrov96e9ff12016-11-04 16:18:30 -0700324
Arthur Heymans6d6945b2018-12-29 14:00:46 +0100325 fsp_version = version;
Andrey Petrovb4831462016-02-25 17:42:25 -0800326}
327
Aaron Durbin64031672018-04-21 14:45:32 -0600328__weak
Brandon Breitensteinc31ba0e2016-07-27 17:34:45 -0700329void mainboard_memory_init_params(FSPM_UPD *mupd)
Andrey Petrovb4831462016-02-25 17:42:25 -0800330{
331 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
332}
Furquan Shaikhbae63832016-06-17 15:50:24 -0700333
Aaron Durbin64031672018-04-21 14:45:32 -0600334__weak
Ravi Sarawadi15f6f3a2016-08-18 13:31:29 -0700335void mainboard_save_dimm_info(void)
336{
337 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
338}