blob: eff81762eb824f5f0cca3fba0663c3a0b84ab195 [file] [log] [blame]
Ravi Sarawadi91ffac82022-05-07 16:37:09 -07001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <assert.h>
Subrata Banike4f0df72023-05-15 17:22:39 +05304#include <bootsplash.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -07005#include <cbfs.h>
6#include <console/console.h>
7#include <cpu/intel/cpu_ids.h>
Subrata Banik10929ef2022-12-09 13:31:47 +05308#include <cpu/intel/microcode.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -07009#include <device/device.h>
10#include <device/pci.h>
11#include <fsp/api.h>
Subrata Banike88bee72022-06-27 16:51:44 +053012#include <fsp/fsp_debug_event.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070013#include <fsp/ppi/mp_service_ppi.h>
14#include <fsp/util.h>
Dinesh Gehlote7c1f7d2022-12-06 10:58:48 +000015#include <option.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070016#include <intelblocks/cse.h>
Kapil Porwalcca3c902022-12-19 23:57:15 +053017#include <intelblocks/irq.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070018#include <intelblocks/lpss.h>
Subrata Banikf251a6a2022-12-11 16:39:05 +053019#include <intelblocks/mp_init.h>
20#include <intelblocks/systemagent.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070021#include <intelblocks/xdci.h>
22#include <intelpch/lockdown.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070023#include <security/vboot/vboot_common.h>
John Zhao54a03e42022-08-03 20:07:03 -070024#include <soc/cpu.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070025#include <soc/gpio_soc_defs.h>
26#include <soc/intel/common/vbt.h>
27#include <soc/pci_devs.h>
28#include <soc/pcie.h>
29#include <soc/ramstage.h>
30#include <soc/soc_chip.h>
31#include <soc/soc_info.h>
Kapil Porwalcca3c902022-12-19 23:57:15 +053032#include <stdlib.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070033#include <string.h>
Dinesh Gehlote7c1f7d2022-12-06 10:58:48 +000034#include <types.h>
Ravi Sarawadi91ffac82022-05-07 16:37:09 -070035
36/* THC assignment definition */
37#define THC_NONE 0
38#define THC_0 1
39#define THC_1 2
40
41/* SATA DEVSLP idle timeout default values */
42#define DEF_DMVAL 15
43#define DEF_DITOVAL 625
44
Kapil Porwalcca3c902022-12-19 23:57:15 +053045static const struct slot_irq_constraints irq_constraints[] = {
46 {
47 .slot = PCI_DEV_SLOT_PCIE_3,
48 .fns = {
49 FIXED_INT_PIRQ(PCI_DEVFN_PCIE12, PCI_INT_A, PIRQ_A),
50 },
51 },
52 {
53 .slot = PCI_DEV_SLOT_IGD,
54 .fns = {
55 /* INTERRUPT_PIN is RO/0x01 */
56 FIXED_INT_ANY_PIRQ(PCI_DEV_SLOT_IGD, PCI_INT_A),
57 },
58 },
59 {
60 .slot = PCI_DEV_SLOT_DPTF,
61 .fns = {
62 ANY_PIRQ(PCI_DEVFN_DPTF),
63 },
64 },
65 {
66 .slot = PCI_DEV_SLOT_IPU,
67 .fns = {
68 /* INTERRUPT_PIN is RO/0x01, and INTERRUPT_LINE is RW,
69 but S0ix fails when not set to 16 (b/193434192) */
70 FIXED_INT_PIRQ(PCI_DEVFN_IPU, PCI_INT_A, PIRQ_A),
71 },
72 },
73 {
74 .slot = PCI_DEV_SLOT_PCIE_2,
75 .fns = {
76 FIXED_INT_PIRQ(PCI_DEVFN_PCIE9, PCI_INT_A, PIRQ_A),
77 FIXED_INT_PIRQ(PCI_DEVFN_PCIE10, PCI_INT_B, PIRQ_B),
78 FIXED_INT_PIRQ(PCI_DEVFN_PCIE11, PCI_INT_C, PIRQ_C),
79 },
80 },
81 {
82 .slot = PCI_DEV_SLOT_TBT,
83 .fns = {
84 ANY_PIRQ(PCI_DEVFN_TBT0),
85 ANY_PIRQ(PCI_DEVFN_TBT1),
86 ANY_PIRQ(PCI_DEVFN_TBT2),
87 ANY_PIRQ(PCI_DEVFN_TBT3),
88 },
89 },
90 {
91 .slot = PCI_DEV_SLOT_GNA,
92 .fns = {
93 /* INTERRUPT_PIN is RO/0x01 */
94 FIXED_INT_ANY_PIRQ(PCI_DEVFN_GNA, PCI_INT_A),
95 },
96 },
97 {
98 .slot = PCI_DEV_SLOT_VPU,
99 .fns = {
100 /* INTERRUPT_PIN is RO/0x01 */
101 FIXED_INT_ANY_PIRQ(PCI_DEVFN_VPU, PCI_INT_A),
102 },
103 },
104 {
105 .slot = PCI_DEV_SLOT_TCSS,
106 .fns = {
107 ANY_PIRQ(PCI_DEVFN_TCSS_XHCI),
108 ANY_PIRQ(PCI_DEVFN_TCSS_XDCI),
109 },
110 },
111 {
112 .slot = PCI_DEV_SLOT_THC,
113 .fns = {
114 ANY_PIRQ(PCI_DEVFN_THC0),
115 ANY_PIRQ(PCI_DEVFN_THC1),
116 },
117 },
118 {
119 .slot = PCI_DEV_SLOT_ISH,
120 .fns = {
121 DIRECT_IRQ(PCI_DEVFN_ISH),
122 DIRECT_IRQ(PCI_DEVFN_GSPI2),
123 ANY_PIRQ(PCI_DEVFN_UFS),
124 },
125 },
126 {
127 .slot = PCI_DEV_SLOT_XHCI,
128 .fns = {
129 ANY_PIRQ(PCI_DEVFN_XHCI),
130 DIRECT_IRQ(PCI_DEVFN_USBOTG),
131 ANY_PIRQ(PCI_DEVFN_CNVI_WIFI),
132 },
133 },
134 {
135 .slot = PCI_DEV_SLOT_SIO0,
136 .fns = {
137 DIRECT_IRQ(PCI_DEVFN_I2C0),
138 DIRECT_IRQ(PCI_DEVFN_I2C1),
139 DIRECT_IRQ(PCI_DEVFN_I2C2),
140 DIRECT_IRQ(PCI_DEVFN_I2C3),
141 },
142 },
143 {
144 .slot = PCI_DEV_SLOT_CSE,
145 .fns = {
146 ANY_PIRQ(PCI_DEVFN_CSE),
147 ANY_PIRQ(PCI_DEVFN_CSE_2),
148 ANY_PIRQ(PCI_DEVFN_CSE_IDER),
149 ANY_PIRQ(PCI_DEVFN_CSE_KT),
150 ANY_PIRQ(PCI_DEVFN_CSE_3),
151 ANY_PIRQ(PCI_DEVFN_CSE_4),
152 },
153 },
154 {
155 .slot = PCI_DEV_SLOT_SATA,
156 .fns = {
157 ANY_PIRQ(PCI_DEVFN_SATA),
158 },
159 },
160 {
161 .slot = PCI_DEV_SLOT_SIO1,
162 .fns = {
163 DIRECT_IRQ(PCI_DEVFN_I2C4),
164 DIRECT_IRQ(PCI_DEVFN_I2C5),
165 DIRECT_IRQ(PCI_DEVFN_UART2),
166 },
167 },
168 {
169 .slot = PCI_DEV_SLOT_PCIE_1,
170 .fns = {
171 FIXED_INT_PIRQ(PCI_DEVFN_PCIE1, PCI_INT_A, PIRQ_A),
172 FIXED_INT_PIRQ(PCI_DEVFN_PCIE2, PCI_INT_B, PIRQ_B),
173 FIXED_INT_PIRQ(PCI_DEVFN_PCIE3, PCI_INT_C, PIRQ_C),
174 FIXED_INT_PIRQ(PCI_DEVFN_PCIE4, PCI_INT_D, PIRQ_D),
175 FIXED_INT_PIRQ(PCI_DEVFN_PCIE5, PCI_INT_A, PIRQ_A),
176 FIXED_INT_PIRQ(PCI_DEVFN_PCIE6, PCI_INT_B, PIRQ_B),
177 FIXED_INT_PIRQ(PCI_DEVFN_PCIE7, PCI_INT_C, PIRQ_C),
178 FIXED_INT_PIRQ(PCI_DEVFN_PCIE8, PCI_INT_D, PIRQ_D),
179 },
180 },
181 {
182 .slot = PCI_DEV_SLOT_SIO2,
183 .fns = {
184 /* UART0 shares an interrupt line with TSN0, so must use
185 a PIRQ */
186 FIXED_INT_ANY_PIRQ(PCI_DEVFN_UART0, PCI_INT_A),
187 /* UART1 shares an interrupt line with TSN1, so must use
188 a PIRQ */
189 FIXED_INT_ANY_PIRQ(PCI_DEVFN_UART1, PCI_INT_B),
190 DIRECT_IRQ(PCI_DEVFN_GSPI0),
191 DIRECT_IRQ(PCI_DEVFN_GSPI1),
192 },
193 },
194 {
195 .slot = PCI_DEV_SLOT_ESPI,
196 .fns = {
197 ANY_PIRQ(PCI_DEVFN_HDA),
198 ANY_PIRQ(PCI_DEVFN_SMBUS),
199 ANY_PIRQ(PCI_DEVFN_GBE),
200 /* INTERRUPT_PIN is RO/0x01 */
201 FIXED_INT_ANY_PIRQ(PCI_DEVFN_NPK, PCI_INT_A),
202 },
203 },
204};
205
206bool is_pch_slot(unsigned int devfn)
207{
208 if (PCI_SLOT(devfn) >= MIN_PCH_SLOT)
209 return true;
210 const struct pcie_rp_group *group;
211 for (group = get_pcie_rp_table(); group->count; ++group) {
212 if (PCI_SLOT(devfn) == group->slot)
213 return true;
214 }
215 return false;
216}
217
218static const SI_PCH_DEVICE_INTERRUPT_CONFIG *pci_irq_to_fsp(size_t *out_count)
219{
220 const struct pci_irq_entry *entry = get_cached_pci_irqs();
221 SI_PCH_DEVICE_INTERRUPT_CONFIG *config;
222 size_t pch_total = 0;
223 size_t cfg_count = 0;
224
225 if (!entry)
226 return NULL;
227
228 /* Count PCH devices */
229 while (entry) {
230 if (is_pch_slot(entry->devfn))
231 ++pch_total;
232 entry = entry->next;
233 }
234
235 /* Convert PCH device entries to FSP format */
236 config = calloc(pch_total, sizeof(*config));
237 entry = get_cached_pci_irqs();
238 while (entry) {
239 if (!is_pch_slot(entry->devfn)) {
240 entry = entry->next;
241 continue;
242 }
243
244 config[cfg_count].Device = PCI_SLOT(entry->devfn);
245 config[cfg_count].Function = PCI_FUNC(entry->devfn);
246 config[cfg_count].IntX = (SI_PCH_INT_PIN)entry->pin;
247 config[cfg_count].Irq = entry->irq;
248 ++cfg_count;
249
250 entry = entry->next;
251 }
252
253 *out_count = cfg_count;
254
255 return config;
256}
257
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700258/*
259 * ME End of Post configuration
260 * 0 - Disable EOP.
261 * 1 - Send in PEI (Applicable for FSP in API mode)
262 * 2 - Send in DXE (Not applicable for FSP in API mode)
263 */
264enum fsp_end_of_post {
265 EOP_DISABLE = 0,
266 EOP_PEI = 1,
267 EOP_DXE = 2,
268};
269
270static const pci_devfn_t i2c_dev[] = {
271 PCI_DEVFN_I2C0,
272 PCI_DEVFN_I2C1,
273 PCI_DEVFN_I2C2,
274 PCI_DEVFN_I2C3,
275 PCI_DEVFN_I2C4,
276 PCI_DEVFN_I2C5,
277};
278
279static const pci_devfn_t gspi_dev[] = {
280 PCI_DEVFN_GSPI0,
281 PCI_DEVFN_GSPI1,
Angel Ponsc7c746c2022-07-16 12:37:38 +0200282 PCI_DEVFN_GSPI2,
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700283};
284
285static const pci_devfn_t uart_dev[] = {
286 PCI_DEVFN_UART0,
287 PCI_DEVFN_UART1,
288 PCI_DEVFN_UART2
289};
290
291/*
292 * Chip config parameter PcieRpL1Substates uses (UPD value + 1)
293 * because UPD value of 0 for PcieRpL1Substates means disabled for FSP.
294 * In order to ensure that mainboard setting does not disable L1 substates
295 * incorrectly, chip config parameter values are offset by 1 with 0 meaning
296 * use FSP UPD default. get_l1_substate_control() ensures that the right UPD
297 * value is set in fsp_params.
298 * 0: Use FSP UPD default
299 * 1: Disable L1 substates
300 * 2: Use L1.1
301 * 3: Use L1.2 (FSP UPD default)
302 */
303static int get_l1_substate_control(enum L1_substates_control ctl)
304{
Subrata Banikad6c4072022-12-21 11:41:33 +0530305 if (CONFIG(SOC_INTEL_COMPLIANCE_TEST_MODE))
306 ctl = L1_SS_DISABLED;
307 else if ((ctl > L1_SS_L1_2) || (ctl == L1_SS_FSP_DEFAULT))
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700308 ctl = L1_SS_L1_2;
309 return ctl - 1;
310}
311
Dinesh Gehlot36b6b052022-12-12 08:48:14 +0000312/*
313 * get_aspm_control() ensures that the right UPD value is set in fsp_params.
314 * 0: Disable ASPM
315 * 1: L0s only
316 * 2: L1 only
317 * 3: L0s and L1
318 * 4: Auto configuration
319 */
320static unsigned int get_aspm_control(enum ASPM_control ctl)
321{
322 if (ctl > ASPM_AUTO)
323 ctl = ASPM_AUTO;
324 return ctl;
325}
326
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700327__weak void mainboard_update_soc_chip_config(struct soc_intel_meteorlake_config *config)
328{
329 /* Override settings per board. */
330}
331
332static void fill_fsps_lpss_params(FSP_S_CONFIG *s_cfg,
333 const struct soc_intel_meteorlake_config *config)
334{
335 int max_port, i;
336
337 max_port = get_max_i2c_port();
338 for (i = 0; i < max_port; i++) {
339 s_cfg->SerialIoI2cMode[i] = is_devfn_enabled(i2c_dev[i]) ?
340 config->serial_io_i2c_mode[i] : 0;
341 }
342
343 max_port = get_max_gspi_port();
344 for (i = 0; i < max_port; i++) {
345 s_cfg->SerialIoSpiCsMode[i] = config->serial_io_gspi_cs_mode[i];
346 s_cfg->SerialIoSpiCsState[i] = config->serial_io_gspi_cs_state[i];
347 s_cfg->SerialIoSpiMode[i] = is_devfn_enabled(gspi_dev[i]) ?
348 config->serial_io_gspi_mode[i] : 0;
349 }
350
351 max_port = get_max_uart_port();
352 for (i = 0; i < max_port; i++) {
353 s_cfg->SerialIoUartMode[i] = is_devfn_enabled(uart_dev[i]) ?
354 config->serial_io_uart_mode[i] : 0;
355 }
356}
357
Subrata Banik10929ef2022-12-09 13:31:47 +0530358static void fill_fsps_microcode_params(FSP_S_CONFIG *s_cfg,
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700359 const struct soc_intel_meteorlake_config *config)
360{
361 const struct microcode *microcode_file;
362 size_t microcode_len;
363
364 /* Locate microcode and pass to FSP-S for 2nd microcode loading */
Subrata Banik10929ef2022-12-09 13:31:47 +0530365 microcode_file = intel_microcode_find();
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700366
Subrata Banik10929ef2022-12-09 13:31:47 +0530367 if (microcode_file != NULL) {
368 microcode_len = get_microcode_size(microcode_file);
369 if (microcode_len != 0) {
370 /* Update CPU Microcode patch base address/size */
371 s_cfg->MicrocodeRegionBase = (uint32_t)(uintptr_t)microcode_file;
372 s_cfg->MicrocodeRegionSize = (uint32_t)microcode_len;
373 }
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700374 }
Subrata Banik10929ef2022-12-09 13:31:47 +0530375}
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700376
Subrata Banik10929ef2022-12-09 13:31:47 +0530377static void fill_fsps_cpu_params(FSP_S_CONFIG *s_cfg,
378 const struct soc_intel_meteorlake_config *config)
379{
Subrata Banik848c37d2022-12-09 13:38:26 +0530380 /*
381 * FIXME: FSP assumes ownership of the APs (Application Processors)
382 * upon passing `NULL` pointer to the CpuMpPpi FSP-S UPD.
383 * Hence, pass a valid pointer to the CpuMpPpi UPD unconditionally.
384 * This would avoid APs from getting hijacked by FSP while coreboot
385 * decides to set SkipMpInit UPD.
386 */
387 s_cfg->CpuMpPpi = (uintptr_t) mp_fill_ppi_services_data();
388
389 /*
390 * Fill `2nd microcode loading FSP UPD` if FSP is running CPU feature
391 * programming.
392 */
Subrata Banika2473192023-02-22 13:03:04 +0000393 if (CONFIG(USE_FSP_FEATURE_PROGRAM_ON_APS))
Subrata Banik10929ef2022-12-09 13:31:47 +0530394 fill_fsps_microcode_params(s_cfg, config);
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700395}
396
397
398static void fill_fsps_igd_params(FSP_S_CONFIG *s_cfg,
399 const struct soc_intel_meteorlake_config *config)
400{
401 /* Load VBT before devicetree-specific config. */
402 s_cfg->GraphicsConfigPtr = (uintptr_t)vbt_get();
403
404 /* Check if IGD is present and fill Graphics init param accordingly */
405 s_cfg->PeiGraphicsPeimInit = CONFIG(RUN_FSP_GOP) && is_devfn_enabled(PCI_DEVFN_IGD);
406 s_cfg->LidStatus = CONFIG(RUN_FSP_GOP);
Subrata Banik4cc8a6c2022-09-07 09:48:28 -0700407 s_cfg->PavpEnable = CONFIG(PAVP);
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700408}
409
410static void fill_fsps_tcss_params(FSP_S_CONFIG *s_cfg,
411 const struct soc_intel_meteorlake_config *config)
412{
413 const struct device *tcss_port_arr[] = {
414 DEV_PTR(tcss_usb3_port1),
415 DEV_PTR(tcss_usb3_port2),
416 DEV_PTR(tcss_usb3_port3),
417 DEV_PTR(tcss_usb3_port4),
418 };
419
420 s_cfg->TcssAuxOri = config->tcss_aux_ori;
421
422 /* Explicitly clear this field to avoid using defaults */
423 memset(s_cfg->IomTypeCPortPadCfg, 0, sizeof(s_cfg->IomTypeCPortPadCfg));
424
425 /* D3Hot and D3Cold for TCSS */
426 s_cfg->D3HotEnable = !config->tcss_d3_hot_disable;
Sean Rhodes2dcb2e22023-04-17 20:37:46 +0100427 s_cfg->D3ColdEnable = CONFIG(D3COLD_SUPPORT);
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700428 s_cfg->UsbTcPortEn = 0;
429
430 for (int i = 0; i < MAX_TYPE_C_PORTS; i++) {
431 if (is_dev_enabled(tcss_port_arr[i]))
432 s_cfg->UsbTcPortEn |= BIT(i);
433 }
434}
435
436static void fill_fsps_chipset_lockdown_params(FSP_S_CONFIG *s_cfg,
437 const struct soc_intel_meteorlake_config *config)
438{
439 /* Chipset Lockdown */
440 const bool lockdown_by_fsp = get_lockdown_config() == CHIPSET_LOCKDOWN_FSP;
441 s_cfg->PchLockDownGlobalSmi = lockdown_by_fsp;
442 s_cfg->PchLockDownBiosInterface = lockdown_by_fsp;
443 s_cfg->PchUnlockGpioPads = !lockdown_by_fsp;
444 s_cfg->RtcMemoryLock = lockdown_by_fsp;
445 s_cfg->SkipPamLock = !lockdown_by_fsp;
446
447 /* coreboot will send EOP before loading payload */
448 s_cfg->EndOfPostMessage = EOP_DISABLE;
449}
450
451static void fill_fsps_xhci_params(FSP_S_CONFIG *s_cfg,
452 const struct soc_intel_meteorlake_config *config)
453{
454 int i, max_port;
455
456 max_port = get_max_usb20_port();
457 for (i = 0; i < max_port; i++) {
458 s_cfg->PortUsb20Enable[i] = config->usb2_ports[i].enable;
459 s_cfg->Usb2PhyPetxiset[i] = config->usb2_ports[i].pre_emp_bias;
460 s_cfg->Usb2PhyTxiset[i] = config->usb2_ports[i].tx_bias;
461 s_cfg->Usb2PhyPredeemp[i] = config->usb2_ports[i].tx_emp_enable;
462 s_cfg->Usb2PhyPehalfbit[i] = config->usb2_ports[i].pre_emp_bit;
463
464 if (config->usb2_ports[i].enable)
465 s_cfg->Usb2OverCurrentPin[i] = config->usb2_ports[i].ocpin;
466 else
467 s_cfg->Usb2OverCurrentPin[i] = OC_SKIP;
468 }
469
470 max_port = get_max_usb30_port();
471 for (i = 0; i < max_port; i++) {
472 s_cfg->PortUsb30Enable[i] = config->usb3_ports[i].enable;
473 if (config->usb3_ports[i].enable)
474 s_cfg->Usb3OverCurrentPin[i] = config->usb3_ports[i].ocpin;
475 else
476 s_cfg->Usb3OverCurrentPin[i] = OC_SKIP;
477
478 if (config->usb3_ports[i].tx_de_emp) {
479 s_cfg->Usb3HsioTxDeEmphEnable[i] = 1;
480 s_cfg->Usb3HsioTxDeEmph[i] = config->usb3_ports[i].tx_de_emp;
481 }
482 if (config->usb3_ports[i].tx_downscale_amp) {
483 s_cfg->Usb3HsioTxDownscaleAmpEnable[i] = 1;
484 s_cfg->Usb3HsioTxDownscaleAmp[i] =
485 config->usb3_ports[i].tx_downscale_amp;
486 }
487 }
488
489 max_port = get_max_tcss_port();
490 for (i = 0; i < max_port; i++) {
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700491 if (config->tcss_ports[i].enable)
492 s_cfg->CpuUsb3OverCurrentPin[i] = config->tcss_ports[i].ocpin;
493 }
494}
495
496static void fill_fsps_xdci_params(FSP_S_CONFIG *s_cfg,
497 const struct soc_intel_meteorlake_config *config)
498{
499 s_cfg->XdciEnable = xdci_can_enable(PCI_DEVFN_USBOTG);
500}
501
Subrata Banike88bee72022-06-27 16:51:44 +0530502static void fill_fsps_uart_params(FSP_S_CONFIG *s_cfg,
503 const struct soc_intel_meteorlake_config *config)
504{
Subrata Banike88bee72022-06-27 16:51:44 +0530505 ASSERT(ARRAY_SIZE(s_cfg->SerialIoUartAutoFlow) > CONFIG_UART_FOR_CONSOLE);
506 s_cfg->SerialIoUartAutoFlow[CONFIG_UART_FOR_CONSOLE] = 0;
507}
508
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700509static void fill_fsps_sata_params(FSP_S_CONFIG *s_cfg,
510 const struct soc_intel_meteorlake_config *config)
511{
512 /* SATA */
513 s_cfg->SataEnable = is_devfn_enabled(PCI_DEVFN_SATA);
514 if (s_cfg->SataEnable) {
515 s_cfg->SataMode = config->sata_mode;
516 s_cfg->SataSalpSupport = config->sata_salp_support;
517 memcpy(s_cfg->SataPortsEnable, config->sata_ports_enable,
518 sizeof(s_cfg->SataPortsEnable));
519 memcpy(s_cfg->SataPortsDevSlp, config->sata_ports_dev_slp,
520 sizeof(s_cfg->SataPortsDevSlp));
521 }
522
523 /*
524 * Power Optimizer for SATA.
525 * SataPwrOptimizeDisable is default to 0.
526 * Boards not needing the optimizers explicitly disables them by setting
527 * these disable variables to 1 in devicetree overrides.
528 */
529 s_cfg->SataPwrOptEnable = !(config->sata_pwr_optimize_disable);
530 /*
531 * Enable DEVSLP Idle Timeout settings DmVal and DitoVal.
532 * SataPortsDmVal is the DITO multiplier. Default is 15.
533 * SataPortsDitoVal is the DEVSLP Idle Timeout (DITO), Default is 625ms.
534 * The default values can be changed from devicetree.
535 */
536 for (size_t i = 0; i < ARRAY_SIZE(config->sata_ports_enable_dito_config); i++) {
537 if (config->sata_ports_enable_dito_config[i]) {
538 s_cfg->SataPortsDmVal[i] = config->sata_ports_dm_val[i];
539 s_cfg->SataPortsDitoVal[i] = config->sata_ports_dito_val[i];
540 }
541 }
542}
543
544static void fill_fsps_thermal_params(FSP_S_CONFIG *s_cfg,
545 const struct soc_intel_meteorlake_config *config)
546{
547 /* Enable TCPU for processor thermal control */
548 s_cfg->Device4Enable = is_devfn_enabled(PCI_DEVFN_DPTF);
549
550 /* Set TccActivationOffset */
551 s_cfg->TccActivationOffset = config->tcc_offset;
552}
553
554static void fill_fsps_lan_params(FSP_S_CONFIG *s_cfg,
555 const struct soc_intel_meteorlake_config *config)
556{
557 /* LAN */
558 s_cfg->PchLanEnable = is_devfn_enabled(PCI_DEVFN_GBE);
559}
560
561static void fill_fsps_cnvi_params(FSP_S_CONFIG *s_cfg,
562 const struct soc_intel_meteorlake_config *config)
563{
564 /* CNVi */
565 s_cfg->CnviMode = is_devfn_enabled(PCI_DEVFN_CNVI_WIFI);
Kapil Porwal78cc76d2023-04-12 10:30:48 +0530566 s_cfg->CnviWifiCore = config->cnvi_wifi_core;
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700567 s_cfg->CnviBtCore = config->cnvi_bt_core;
568 s_cfg->CnviBtAudioOffload = config->cnvi_bt_audio_offload;
Kapil Porwal4e498e12023-04-12 16:16:36 +0530569 if (!s_cfg->CnviMode && s_cfg->CnviWifiCore) {
570 printk(BIOS_ERR, "CNVi WiFi is enabled without CNVi being enabled\n");
571 s_cfg->CnviWifiCore = 0;
572 }
573 if (!s_cfg->CnviBtCore && s_cfg->CnviBtAudioOffload) {
574 printk(BIOS_ERR, "BT offload is enabled without CNVi BT being enabled\n");
575 s_cfg->CnviBtAudioOffload = 0;
576 }
577 if (!s_cfg->CnviMode && s_cfg->CnviBtCore) {
578 printk(BIOS_ERR, "CNVi BT is enabled without CNVi being enabled\n");
579 s_cfg->CnviBtCore = 0;
580 s_cfg->CnviBtAudioOffload = 0;
581 }
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700582}
583
584static void fill_fsps_vmd_params(FSP_S_CONFIG *s_cfg,
585 const struct soc_intel_meteorlake_config *config)
586{
587 /* VMD */
588 s_cfg->VmdEnable = is_devfn_enabled(PCI_DEVFN_VMD);
589}
590
591static void fill_fsps_tbt_params(FSP_S_CONFIG *s_cfg,
592 const struct soc_intel_meteorlake_config *config)
593{
Sridhar Siricillacb4d4642022-09-26 12:12:20 +0530594 for (int i = 0; i < ARRAY_SIZE(s_cfg->ITbtPcieRootPortEn); i++)
595 s_cfg->ITbtPcieRootPortEn[i] = is_devfn_enabled(PCI_DEVFN_TBT(i));
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700596}
597
598static void fill_fsps_8254_params(FSP_S_CONFIG *s_cfg,
599 const struct soc_intel_meteorlake_config *config)
600{
601 /* Legacy 8254 timer support */
Dinesh Gehlote7c1f7d2022-12-06 10:58:48 +0000602 bool use_8254 = get_uint_option("legacy_8254_timer", CONFIG(USE_LEGACY_8254_TIMER));
603 s_cfg->Enable8254ClockGating = !use_8254;
604 s_cfg->Enable8254ClockGatingOnS3 = !use_8254;
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700605}
606
Kapil Porwal89ea3122022-11-15 19:06:49 +0530607static void fill_fsps_pm_timer_params(FSP_S_CONFIG *s_cfg,
608 const struct soc_intel_meteorlake_config *config)
609{
610 /*
611 * Legacy PM ACPI Timer (and TCO Timer)
612 * This *must* be 1 in any case to keep FSP from
613 * 1) enabling PM ACPI Timer emulation in uCode.
614 * 2) disabling the PM ACPI Timer.
615 * We handle both by ourself!
616 */
617 s_cfg->EnableTcoTimer = 1;
618}
619
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700620static void fill_fsps_pcie_params(FSP_S_CONFIG *s_cfg,
621 const struct soc_intel_meteorlake_config *config)
622{
623 int max_port = get_max_pcie_port();
624 uint32_t enable_mask = pcie_rp_enable_mask(get_pcie_rp_table());
625 for (int i = 0; i < max_port; i++) {
626 if (!(enable_mask & BIT(i)))
627 continue;
628 const struct pcie_rp_config *rp_cfg = &config->pcie_rp[i];
629 s_cfg->PcieRpL1Substates[i] =
630 get_l1_substate_control(rp_cfg->PcieRpL1Substates);
631 s_cfg->PcieRpLtrEnable[i] = !!(rp_cfg->flags & PCIE_RP_LTR);
632 s_cfg->PcieRpAdvancedErrorReporting[i] = !!(rp_cfg->flags & PCIE_RP_AER);
Subrata Banikc0f4b122022-12-06 14:03:07 +0530633 s_cfg->PcieRpHotPlug[i] = !!(rp_cfg->flags & PCIE_RP_HOTPLUG)
634 || CONFIG(SOC_INTEL_COMPLIANCE_TEST_MODE);
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700635 s_cfg->PcieRpClkReqDetect[i] = !!(rp_cfg->flags & PCIE_RP_CLK_REQ_DETECT);
Dinesh Gehlot36b6b052022-12-12 08:48:14 +0000636 if (rp_cfg->pcie_rp_aspm)
637 s_cfg->PcieRpAspm[i] = get_aspm_control(rp_cfg->pcie_rp_aspm);
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700638 }
Subrata Banikc0f4b122022-12-06 14:03:07 +0530639 s_cfg->PcieComplianceTestMode = CONFIG(SOC_INTEL_COMPLIANCE_TEST_MODE);
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700640}
641
642static void fill_fsps_misc_power_params(FSP_S_CONFIG *s_cfg,
643 const struct soc_intel_meteorlake_config *config)
644{
Kapil Porwal66e44e32022-11-16 10:19:17 +0530645 /* Skip setting D0I3 bit for all HECI devices */
646 s_cfg->DisableD0I3SettingForHeci = 1;
647
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700648 s_cfg->Hwp = 1;
649 s_cfg->Cx = 1;
650 s_cfg->PsOnEnable = 1;
Kapil Porwalae5ba372023-01-04 21:49:36 +0530651 s_cfg->PkgCStateLimit = LIMIT_AUTO;
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700652 /* Enable the energy efficient turbo mode */
653 s_cfg->EnergyEfficientTurbo = 1;
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700654 s_cfg->PmcLpmS0ixSubStateEnableMask = get_supported_lpm_mask();
Kapil Porwalae5bc432023-01-04 22:03:02 +0530655 s_cfg->PkgCStateDemotion = !config->disable_package_c_state_demotion;
Subrata Banik794137e2023-02-01 17:19:50 +0530656 s_cfg->PmcV1p05PhyExtFetControlEn = 1;
Yong Zhi309d5a52023-02-14 17:25:17 -0600657
658 /* Enable PCH to CPU energy report feature. */
659 s_cfg->PchPmDisableEnergyReport = !config->pch_pm_energy_report_enable;
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700660}
661
662
663static void fill_fsps_ufs_params(FSP_S_CONFIG *s_cfg,
664 const struct soc_intel_meteorlake_config *config)
665{
666 s_cfg->UfsEnable[0] = is_devfn_enabled(PCI_DEVFN_UFS);
667}
668
669static void fill_fsps_ai_params(FSP_S_CONFIG *s_cfg,
670 const struct soc_intel_meteorlake_config *config)
671{
672 s_cfg->GnaEnable = is_devfn_enabled(PCI_DEVFN_GNA);
Srinidhi N Kaushik9f6e25d2022-08-08 20:38:19 -0700673 s_cfg->VpuEnable = is_devfn_enabled(PCI_DEVFN_VPU);
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700674}
675
Kapil Porwalcca3c902022-12-19 23:57:15 +0530676static void fill_fsps_irq_params(FSP_S_CONFIG *s_cfg,
677 const struct soc_intel_meteorlake_config *config)
678{
679 if (!assign_pci_irqs(irq_constraints, ARRAY_SIZE(irq_constraints)))
680 die("ERROR: Unable to assign PCI IRQs, and no _PRT table available\n");
681
682 size_t pch_count = 0;
683 const SI_PCH_DEVICE_INTERRUPT_CONFIG *upd_irqs = pci_irq_to_fsp(&pch_count);
684
685 s_cfg->DevIntConfigPtr = (UINT32)((uintptr_t)upd_irqs);
686 s_cfg->NumOfDevIntConfig = pch_count;
687 printk(BIOS_INFO, "IRQ: Using dynamically assigned PCI IO-APIC IRQs\n");
688}
689
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700690static void arch_silicon_init_params(FSPS_ARCH_UPD *s_arch_cfg)
691{
zhaojohn9f5fea92022-09-20 08:12:47 -0700692 /*
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700693 * EnableMultiPhaseSiliconInit for running MultiPhaseSiInit
694 */
zhaojohn9f5fea92022-09-20 08:12:47 -0700695 s_arch_cfg->EnableMultiPhaseSiliconInit = 1;
Srinidhi N Kaushik9a690022022-07-25 22:12:34 -0700696
697 /* Assign FspEventHandler arch Upd to use coreboot debug event handler */
698 if (CONFIG(FSP_USES_CB_DEBUG_EVENT_HANDLER) && CONFIG(CONSOLE_SERIAL) &&
699 CONFIG(FSP_ENABLE_SERIAL_DEBUG))
700 s_arch_cfg->FspEventHandler = (FSP_EVENT_HANDLER)
701 fsp_debug_event_handler;
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700702}
703
704static void soc_silicon_init_params(FSP_S_CONFIG *s_cfg,
705 struct soc_intel_meteorlake_config *config)
706{
707 /* Override settings per board if required. */
708 mainboard_update_soc_chip_config(config);
709
Arthur Heymans4081d6c2022-07-29 10:45:52 +0200710 void (*fill_fsps_params[])(FSP_S_CONFIG *s_cfg,
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700711 const struct soc_intel_meteorlake_config *config) = {
712 fill_fsps_lpss_params,
713 fill_fsps_cpu_params,
714 fill_fsps_igd_params,
715 fill_fsps_tcss_params,
716 fill_fsps_chipset_lockdown_params,
717 fill_fsps_xhci_params,
718 fill_fsps_xdci_params,
Subrata Banike88bee72022-06-27 16:51:44 +0530719 fill_fsps_uart_params,
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700720 fill_fsps_sata_params,
721 fill_fsps_thermal_params,
722 fill_fsps_lan_params,
723 fill_fsps_cnvi_params,
724 fill_fsps_vmd_params,
725 fill_fsps_tbt_params,
726 fill_fsps_8254_params,
Kapil Porwal89ea3122022-11-15 19:06:49 +0530727 fill_fsps_pm_timer_params,
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700728 fill_fsps_pcie_params,
729 fill_fsps_misc_power_params,
730 fill_fsps_ufs_params,
731 fill_fsps_ai_params,
Kapil Porwalcca3c902022-12-19 23:57:15 +0530732 fill_fsps_irq_params,
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700733 };
734
735 for (size_t i = 0; i < ARRAY_SIZE(fill_fsps_params); i++)
736 fill_fsps_params[i](s_cfg, config);
737}
738
739/* UPD parameters to be initialized before SiliconInit */
740void platform_fsp_silicon_init_params_cb(FSPS_UPD *supd)
741{
742 struct soc_intel_meteorlake_config *config;
743 FSP_S_CONFIG *s_cfg = &supd->FspsConfig;
744 FSPS_ARCH_UPD *s_arch_cfg = &supd->FspsArchUpd;
745
746 config = config_of_soc();
747 arch_silicon_init_params(s_arch_cfg);
748 soc_silicon_init_params(s_cfg, config);
749 mainboard_silicon_init_params(s_cfg);
750}
751
752/*
753 * Callbacks for SoC/Mainboard specific overrides for FspMultiPhaseSiInit
754 * This platform supports below MultiPhaseSIInit Phase(s):
755 * Phase | FSP return point | Purpose
756 * ------- + ------------------------------------------------ + -------------------------------
757 * 1 | After TCSS initialization completed | for TCSS specific init
Subrata Banikf251a6a2022-12-11 16:39:05 +0530758 * 2 | Before BIOS Reset CPL is set by FSP-S | for CPU specific init
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700759 */
760void platform_fsp_multi_phase_init_cb(uint32_t phase_index)
761{
762 switch (phase_index) {
763 case 1:
764 /* TCSS specific initialization here */
765 printk(BIOS_DEBUG, "FSP MultiPhaseSiInit %s/%s called\n",
766 __FILE__, __func__);
767
768 if (CONFIG(SOC_INTEL_COMMON_BLOCK_TCSS)) {
769 const config_t *config = config_of_soc();
770 tcss_configure(config->typec_aux_bias_pads);
771 }
772 break;
Subrata Banikf251a6a2022-12-11 16:39:05 +0530773 case 2:
774 /* CPU specific initialization here */
775 printk(BIOS_DEBUG, "FSP MultiPhaseSiInit %s/%s called\n",
776 __FILE__, __func__);
777 before_post_cpus_init();
778 /* Enable BIOS Reset CPL */
779 enable_bios_reset_cpl();
780 break;
Ravi Sarawadi91ffac82022-05-07 16:37:09 -0700781 default:
782 break;
783 }
784}
785
786/* Mainboard GPIO Configuration */
787__weak void mainboard_silicon_init_params(FSP_S_CONFIG *s_cfg)
788{
789 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
790}
Subrata Banike4f0df72023-05-15 17:22:39 +0530791
792/* Handle FSP logo params */
793void soc_load_logo(FSPS_UPD *supd)
794{
795 bmp_load_logo(&supd->FspsConfig.LogoPtr, &supd->FspsConfig.LogoSize);
796}