Debian Codegraph @

src/soc/intel/pantherlake/fsp_params.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <boot/coreboot_tables.h>
4 #include <bootmode.h>
5 #include <cbfs.h>
6 #include <cpu/intel/microcode.h>
7 #include <fsp/api.h>
8 #include <fsp/debug.h>
9 #include <fsp/fsp_debug_event.h>
10 #include <fsp/fsp_gop_blt.h>
11 #include <fsp/ppi/mp_service_ppi.h>
12 #include <intelblocks/irq.h>
13 #include <intelblocks/mp_init.h>
14 #include <intelblocks/pmclib.h>
15 #include <intelblocks/systemagent.h>
16 #include <intelblocks/xdci.h>
17 #include <intelpch/lockdown.h>
18 #include <option.h>
19 #include <soc/cpu.h>
20 #include <soc/intel/common/vbt.h>
21 #include <soc/pcie.h>
22 #include <soc/ramstage.h>
23 #include <static.h>
24
25 #define MAX_ONBOARD_PCIE_DEVICES 256
26
27 /* THC assignment definition */
28 enum {
29 THC_NONE,
30 THC_0,
31 THC_1
32 };
33
34 /* LPSS UART Power Gating mode */
35 enum {
36 LPSS_UART_PG_DISABLED,
37 LPSS_UART_PG_ENABLED,
38 LPSS_UART_PG_AUTO
39 };
40
41 static const pci_devfn_t i2c_dev[] = {
42 PCI_DEVFN_I2C0,
43 PCI_DEVFN_I2C1,
44 PCI_DEVFN_I2C2,
45 PCI_DEVFN_I2C3,
46 PCI_DEVFN_I2C4,
47 PCI_DEVFN_I2C5,
48 };
49
50 static const pci_devfn_t uart_dev[] = {
51 PCI_DEVFN_UART0,
52 PCI_DEVFN_UART1,
53 PCI_DEVFN_UART2
54 };
55
56 static const pci_devfn_t gspi_dev[] = {
57 PCI_DEVFN_GSPI0,
58 PCI_DEVFN_GSPI1,
59 PCI_DEVFN_GSPI2
60 };
61
62 /*
63 * Chip config parameter PcieRpL1Substates uses (UPD value + 1)
64 * because UPD value of 0 for PcieRpL1Substates means disabled for FSP.
65 * In order to ensure that mainboard setting does not disable L1 substates
66 * incorrectly, chip config parameter values are offset by 1 with 0 meaning
67 * use FSP UPD default. get_l1_substate_control() ensures that the right UPD
68 * value is set in fsp_params.
69 * 0: Use FSP UPD default
70 * 1: Disable L1 substates
71 * 2: Use L1.1
72 * 3: Use L1.2 (FSP UPD default)
73 */
74 static int get_l1_substate_control(enum L1_substates_control ctl)
75 {
76 if (CONFIG(SOC_INTEL_COMPLIANCE_TEST_MODE))
77 ctl = L1_SS_DISABLED;
78 else if (ctl > L1_SS_L1_2 || ctl == L1_SS_FSP_DEFAULT)
79 ctl = L1_SS_L1_2;
80 return ctl - 1;
81 }
82
83 /*
84 * Chip config parameter pcie_rp_aspm uses (UPD value + 1) because
85 * a UPD value of 0 for pcie_rp_aspm means disabled. In order to ensure
86 * that the mainboard setting does not disable ASPM incorrectly, chip
87 * config parameter values are offset by 1 with 0 meaning use FSP UPD default.
88 * get_aspm_control() ensures that the right UPD value is set in fsp_params.
89 * 0: Use FSP UPD default
90 * 1: Disable ASPM
91 * 2: L0s only
92 * 3: L1 only
93 * 4: L0s and L1
94 * 5: Auto configuration
95 */
96 static unsigned int get_aspm_control(enum ASPM_control ctl)
97 {
98 if (ctl > ASPM_AUTO || ctl == ASPM_DEFAULT)
99 ctl = ASPM_AUTO;
100 return ctl - 1;
101 }
102
103 __weak void mainboard_update_soc_chip_config(struct soc_intel_pantherlake_config *config)
104 {
105 /* Override settings per board. */
106 }
107
108 static const struct slot_irq_constraints irq_constraints[] = {
109 {
110 .slot = PCI_DEV_SLOT_IGD,
111 .fns = {
112 /* INTERRUPT_PIN is RO/0x01 */
113 FIXED_INT_ANY_PIRQ(PCI_DEVFN_IGD, PCI_INT_A),
114 },
115 },
116 {
117 .slot = PCI_DEV_SLOT_DPTF,
118 .fns = {
119 /* Dynamic Tuning Technology (DTT) device IRQ is not
120 programmable and is INT_A/PIRQ_A (IRQ 16) */
121 FIXED_INT_PIRQ(PCI_DEVFN_DPTF, PCI_INT_A, PIRQ_A),
122 },
123 },
124 #if CONFIG(SOC_INTEL_PANTHERLAKE)
125 {
126 .slot = PCI_DEV_SLOT_IPU,
127 .fns = {
128 /* INTERRUPT_PIN is RO/0x01, and INTERRUPT_LINE is RW,
129 but S0ix fails when not set to 16 (b/193434192) */
130 FIXED_INT_PIRQ(PCI_DEVFN_IPU, PCI_INT_A, PIRQ_A),
131 },
132 },
133 #endif
134 {
135 .slot = PCI_DEV_SLOT_PCIE_2,
136 .fns = {
137 #if CONFIG(SOC_INTEL_WILDCATLAKE)
138 FIXED_INT_PIRQ(PCI_DEVFN_PCIE5, PCI_INT_A, PIRQ_A),
139 FIXED_INT_PIRQ(PCI_DEVFN_PCIE6, PCI_INT_B, PIRQ_B),
140 #else
141 FIXED_INT_PIRQ(PCI_DEVFN_PCIE9, PCI_INT_A, PIRQ_A),
142 FIXED_INT_PIRQ(PCI_DEVFN_PCIE10, PCI_INT_B, PIRQ_B),
143 #if CONFIG(SOC_INTEL_PANTHERLAKE_H)
144 FIXED_INT_PIRQ(PCI_DEVFN_PCIE11, PCI_INT_C, PIRQ_C),
145 FIXED_INT_PIRQ(PCI_DEVFN_PCIE12, PCI_INT_D, PIRQ_D),
146 #endif
147 #endif
148 },
149 },
150 {
151 .slot = PCI_DEV_SLOT_TBT,
152 .fns = {
153 ANY_PIRQ(PCI_DEVFN_TBT0),
154 ANY_PIRQ(PCI_DEVFN_TBT1),
155 #if CONFIG(SOC_INTEL_PANTHERLAKE)
156 ANY_PIRQ(PCI_DEVFN_TBT2),
157 ANY_PIRQ(PCI_DEVFN_TBT3),
158 #endif
159 },
160 },
161 {
162 .slot = PCI_DEV_SLOT_NPU,
163 .fns = {
164 /* INTERRUPT_PIN is RO/0x01 */
165 FIXED_INT_ANY_PIRQ(PCI_DEVFN_NPU, PCI_INT_A),
166 },
167 },
168 {
169 .slot = PCI_DEV_SLOT_TCSS,
170 .fns = {
171 ANY_PIRQ(PCI_DEVFN_TCSS_XHCI),
172 },
173 },
174 {
175 .slot = PCI_DEV_SLOT_THC,
176 .fns = {
177 ANY_PIRQ(PCI_DEVFN_THC0),
178 ANY_PIRQ(PCI_DEVFN_THC1),
179 },
180 },
181 {
182 .slot = PCI_DEV_SLOT_ISH,
183 .fns = {
184 DIRECT_IRQ(PCI_DEVFN_ISH),
185 },
186 },
187 {
188 .slot = PCI_DEV_SLOT_XHCI,
189 .fns = {
190 ANY_PIRQ(PCI_DEVFN_XHCI),
191 DIRECT_IRQ(PCI_DEVFN_USBOTG),
192 ANY_PIRQ(PCI_DEVFN_CNVI_WIFI),
193 },
194 },
195 {
196 .slot = PCI_DEV_SLOT_SIO0,
197 .fns = {
198 DIRECT_IRQ(PCI_DEVFN_I2C0),
199 DIRECT_IRQ(PCI_DEVFN_I2C1),
200 DIRECT_IRQ(PCI_DEVFN_I2C2),
201 DIRECT_IRQ(PCI_DEVFN_I2C3),
202 },
203 },
204 {
205 .slot = PCI_DEV_SLOT_CSE,
206 .fns = {
207 ANY_PIRQ(PCI_DEVFN_CSE),
208 ANY_PIRQ(PCI_DEVFN_CSE_2),
209 ANY_PIRQ(PCI_DEVFN_CSE_IDER),
210 ANY_PIRQ(PCI_DEVFN_CSE_KT),
211 ANY_PIRQ(PCI_DEVFN_CSE_3),
212 ANY_PIRQ(PCI_DEVFN_CSE_4),
213 },
214 },
215 #if (CONFIG(SOC_INTEL_WILDCATLAKE))
216 {
217 .slot = PCI_DEV_SLOT_UFS,
218 .fns = {
219 ANY_PIRQ(PCI_DEVFN_UFS),
220 },
221 },
222 #endif
223 {
224 .slot = PCI_DEV_SLOT_SIO1,
225 .fns = {
226 DIRECT_IRQ(PCI_DEVFN_I2C4),
227 DIRECT_IRQ(PCI_DEVFN_I2C5),
228 DIRECT_IRQ(PCI_DEVFN_UART2),
229 },
230 },
231 {
232 .slot = PCI_DEV_SLOT_PCIE_1,
233 .fns = {
234 FIXED_INT_PIRQ(PCI_DEVFN_PCIE1, PCI_INT_A, PIRQ_A),
235 FIXED_INT_PIRQ(PCI_DEVFN_PCIE2, PCI_INT_B, PIRQ_B),
236 FIXED_INT_PIRQ(PCI_DEVFN_PCIE3, PCI_INT_C, PIRQ_C),
237 FIXED_INT_PIRQ(PCI_DEVFN_PCIE4, PCI_INT_D, PIRQ_D),
238 #if CONFIG(SOC_INTEL_PANTHERLAKE)
239 FIXED_INT_PIRQ(PCI_DEVFN_PCIE5, PCI_INT_A, PIRQ_A),
240 FIXED_INT_PIRQ(PCI_DEVFN_PCIE6, PCI_INT_B, PIRQ_B),
241 FIXED_INT_PIRQ(PCI_DEVFN_PCIE7, PCI_INT_C, PIRQ_C),
242 FIXED_INT_PIRQ(PCI_DEVFN_PCIE8, PCI_INT_D, PIRQ_D),
243 #endif
244 },
245 },
246 {
247 .slot = PCI_DEV_SLOT_SIO2,
248 .fns = {
249 /* UART0 shares an interrupt line with TSN0, so must use
250 a PIRQ */
251 FIXED_INT_ANY_PIRQ(PCI_DEVFN_UART0, PCI_INT_A),
252 /* UART1 shares an interrupt line with TSN1, so must use
253 a PIRQ */
254 FIXED_INT_ANY_PIRQ(PCI_DEVFN_UART1, PCI_INT_B),
255 DIRECT_IRQ(PCI_DEVFN_GSPI0),
256 DIRECT_IRQ(PCI_DEVFN_GSPI1),
257 },
258 },
259 {
260 .slot = PCI_DEV_SLOT_ESPI,
261 .fns = {
262 ANY_PIRQ(PCI_DEVFN_HDA),
263 ANY_PIRQ(PCI_DEVFN_SMBUS),
264 ANY_PIRQ(PCI_DEVFN_GBE),
265 /* INTERRUPT_PIN is RO/0x01 */
266 FIXED_INT_ANY_PIRQ(PCI_DEVFN_NPK, PCI_INT_A),
267 },
268 },
269 };
270
271 static void fill_fsps_lpss_params(FSP_S_CONFIG *s_cfg,
272 const struct soc_intel_pantherlake_config *config)
273 {
274 size_t i;
275
276 for (i = 0; i < CONFIG_SOC_INTEL_I2C_DEV_MAX; i++)
277 s_cfg->SerialIoI2cMode[i] =
278 is_devfn_enabled(i2c_dev[i]) ? config->serial_io_i2c_mode[i] : 0;
279
280 for (i = 0; i < CONFIG_SOC_INTEL_COMMON_BLOCK_GSPI_MAX; i++) {
281 s_cfg->SerialIoLpssSpiCsMode[i] = config->serial_io_gspi_cs_mode[i];
282 s_cfg->SerialIoLpssSpiCsState[i] = config->serial_io_gspi_cs_state[i];
283 s_cfg->SerialIoLpssSpiMode[i] =
284 is_devfn_enabled(gspi_dev[i]) ? config->serial_io_gspi_mode[i] : 0;
285 }
286
287 for (i = 0; i < CONFIG_SOC_INTEL_UART_DEV_MAX; i++) {
288 s_cfg->SerialIoUartMode[i] = is_devfn_enabled(uart_dev[i]) ?
289 config->serial_io_uart_mode[i] : 0;
290 s_cfg->SerialIoUartPowerGating[i] = is_devfn_enabled(uart_dev[i]) ?
291 LPSS_UART_PG_ENABLED : LPSS_UART_PG_AUTO;
292 }
293 }
294
295 static void fill_fsps_cpu_params(FSP_S_CONFIG *s_cfg,
296 const struct soc_intel_pantherlake_config *config)
297 {
298 if (!CONFIG(USE_INTEL_FSP_TO_CALL_COREBOOT_PUBLISH_MP_PPI))
299 return;
300
301 s_cfg->CpuMpPpi = (uintptr_t)mp_fill_ppi_services_data();
302 }
303
304 static void fill_fsps_microcode_params(FSP_S_CONFIG *s_cfg,
305 const struct soc_intel_pantherlake_config *config)
306 {
307 const struct microcode *microcode;
308 size_t length;
309
310 if (!CONFIG(USE_FSP_FEATURE_PROGRAM_ON_APS))
311 return;
312
313 /* Locate microcode and pass to FSP-S for 2nd microcode loading */
314 microcode = intel_microcode_find();
315 if (!microcode)
316 return;
317
318 length = get_microcode_size(microcode);
319 if (!length)
320 return;
321
322 /* Update CPU Microcode patch base address/size */
323 s_cfg->MicrocodeRegionBase = (uint32_t)(uintptr_t)microcode;
324 s_cfg->MicrocodeRegionSize = (uint32_t)length;
325 }
326
327 static void fill_fsps_igd_params(FSP_S_CONFIG *s_cfg,
328 const struct soc_intel_pantherlake_config *config)
329 {
330 /* Load VBT before devicetree-specific config. */
331 s_cfg->GraphicsConfigPtr = (uintptr_t)vbt_get();
332
333 /* Check if IGD is present and fill Graphics init param accordingly */
334 s_cfg->PeiGraphicsPeimInit = CONFIG(RUN_FSP_GOP) && is_devfn_enabled(PCI_DEVFN_IGD);
335 s_cfg->LidStatus = CONFIG(VBOOT_LID_SWITCH) ? get_lid_switch() : CONFIG(RUN_FSP_GOP);
336 s_cfg->PavpEnable = CONFIG(PAVP);
337 }
338
339 static void fill_fsps_tcss_params(FSP_S_CONFIG *s_cfg,
340 const struct soc_intel_pantherlake_config *config)
341 {
342 s_cfg->TcssAuxOri = config->tcss_aux_ori;
343
344 /* Explicitly clear this field to avoid using defaults */
345 memset(s_cfg->IomTypeCPortPadCfg, 0, sizeof(s_cfg->IomTypeCPortPadCfg));
346
347 /* D3Cold for TCSS */
348 s_cfg->D3ColdEnable = !config->tcss_d3_cold_disable;
349 s_cfg->UsbTcPortEn = 0;
350
351 for (size_t i = 0; i < MAX_TYPE_C_PORTS; i++)
352 if (config->tcss_ports[i].enable)
353 s_cfg->UsbTcPortEn |= BIT(i);
354 }
355
356 static void fill_fsps_chipset_lockdown_params(FSP_S_CONFIG *s_cfg,
357 const struct soc_intel_pantherlake_config *config)
358 {
359 /* Chipset Lockdown */
360 const bool lockdown_by_fsp = get_lockdown_config() == CHIPSET_LOCKDOWN_FSP;
361
362 s_cfg->PchLockDownGlobalSmi = lockdown_by_fsp;
363 s_cfg->PchLockDownBiosInterface = lockdown_by_fsp;
364 s_cfg->PchUnlockGpioPads = !lockdown_by_fsp;
365 s_cfg->RtcMemoryLock = lockdown_by_fsp;
366 s_cfg->SkipPamLock = !lockdown_by_fsp;
367
368 /* coreboot will send EOP before loading payload */
369 s_cfg->EndOfPostMessage = 0; /* EOP disable */
370
371 s_cfg->CpuCrashLogEnable = CONFIG(SOC_INTEL_CRASHLOG);
372 }
373
374 static void fill_fsps_xhci_params(FSP_S_CONFIG *s_cfg,
375 const struct soc_intel_pantherlake_config *config)
376 {
377 size_t i;
378
379 for (i = 0; i < CONFIG_SOC_INTEL_USB2_DEV_MAX; i++) {
380 s_cfg->PortUsb20Enable[i] = config->usb2_ports[i].enable;
381 s_cfg->Usb2PhyPetxiset[i] = config->usb2_ports[i].pre_emp_bias;
382 s_cfg->Usb2PhyTxiset[i] = config->usb2_ports[i].tx_bias;
383 s_cfg->Usb2PhyPredeemp[i] = config->usb2_ports[i].tx_emp_enable;
384 s_cfg->Usb2PhyPehalfbit[i] = config->usb2_ports[i].pre_emp_bit;
385
386 if (config->usb2_ports[i].enable)
387 s_cfg->Usb2OverCurrentPin[i] = config->usb2_ports[i].ocpin;
388 else
389 s_cfg->Usb2OverCurrentPin[i] = OC_SKIP;
390
391 s_cfg->PortResetMessageEnable[i] = config->usb2_ports[i].type_c;
392 }
393
394 for (i = 0; i < CONFIG_SOC_INTEL_USB3_DEV_MAX; i++) {
395 s_cfg->PortUsb30Enable[i] = config->usb3_ports[i].enable;
396 if (config->usb3_ports[i].enable)
397 s_cfg->Usb3OverCurrentPin[i] = config->usb3_ports[i].ocpin;
398 else
399 s_cfg->Usb3OverCurrentPin[i] = OC_SKIP;
400
401 if (config->usb3_ports[i].tx_de_emp) {
402 s_cfg->Usb3HsioTxDeEmphEnable[i] = 1;
403 s_cfg->Usb3HsioTxDeEmph[i] = config->usb3_ports[i].tx_de_emp;
404 }
405 if (config->usb3_ports[i].tx_downscale_amp) {
406 s_cfg->Usb3HsioTxDownscaleAmpEnable[i] = 1;
407 s_cfg->Usb3HsioTxDownscaleAmp[i] =
408 config->usb3_ports[i].tx_downscale_amp;
409 }
410 }
411
412 for (i = 0; i < MAX_TYPE_C_PORTS; i++)
413 if (config->tcss_ports[i].enable)
414 s_cfg->CpuUsb3OverCurrentPin[i] = config->tcss_ports[i].ocpin;
415 }
416
417 static void fill_fsps_xdci_params(FSP_S_CONFIG *s_cfg,
418 const struct soc_intel_pantherlake_config *config)
419 {
420 s_cfg->XdciEnable = xdci_can_enable(PCI_DEVFN_USBOTG);
421 }
422
423 static void fill_fsps_thermal_params(FSP_S_CONFIG *s_cfg,
424 const struct soc_intel_pantherlake_config *config)
425 {
426 s_cfg->Device4Enable = is_devfn_enabled(PCI_DEVFN_DPTF);
427 }
428
429 static const SI_PCH_DEVICE_INTERRUPT_CONFIG *pci_irq_to_fsp(size_t *out_count)
430 {
431 const struct pci_irq_entry *entry = get_cached_pci_irqs();
432 SI_PCH_DEVICE_INTERRUPT_CONFIG *config;
433 size_t pch_total = 0, cfg_count = 0;
434
435 if (!entry)
436 return NULL;
437
438 /* Count PCH devices */
439 while (entry) {
440 if (is_pch_slot(entry->devfn))
441 pch_total++;
442 entry = entry->next;
443 }
444
445 /* Convert PCH device entries to FSP format */
446 config = calloc(pch_total, sizeof(*config));
447 entry = get_cached_pci_irqs();
448 while (entry) {
449 if (!is_pch_slot(entry->devfn)) {
450 entry = entry->next;
451 continue;
452 }
453
454 config[cfg_count].Device = PCI_SLOT(entry->devfn);
455 config[cfg_count].Function = PCI_FUNC(entry->devfn);
456 config[cfg_count].IntX = (SI_PCH_INT_PIN)entry->pin;
457 config[cfg_count].Irq = entry->irq;
458 cfg_count++;
459
460 entry = entry->next;
461 }
462
463 *out_count = cfg_count;
464
465 return config;
466 }
467
468 static void fill_fsps_irq_params(FSP_S_CONFIG *s_cfg,
469 const struct soc_intel_pantherlake_config *config)
470 {
471 if (!assign_pci_irqs(irq_constraints, ARRAY_SIZE(irq_constraints)))
472 die("ERROR: Unable to assign PCI IRQs, and no _PRT table available\n");
473
474 size_t pch_count = 0;
475 const SI_PCH_DEVICE_INTERRUPT_CONFIG *upd_irqs = pci_irq_to_fsp(&pch_count);
476
477 s_cfg->DevIntConfigPtr = (UINT32)((uintptr_t)upd_irqs);
478 s_cfg->NumOfDevIntConfig = pch_count;
479 printk(BIOS_INFO, "IRQ: Using dynamically assigned PCI IO-APIC IRQs\n");
480 }
481
482 static void evaluate_ssid(const struct device *dev, uint16_t *svid, uint16_t *ssid)
483 {
484 if (!(dev && svid && ssid))
485 return;
486
487 *svid = CONFIG_SUBSYSTEM_VENDOR_ID ? : (dev->subsystem_vendor ? : 0x8086);
488 *ssid = CONFIG_SUBSYSTEM_DEVICE_ID ? : (dev->subsystem_device ? : 0xfffe);
489 }
490
491 /*
492 * Programming SSID before FSP-S is important because SSID registers of a few PCIE
493 * devices (e.g. IPU, Crashlog, XHCI, TCSS_XHCI etc.) are locked after FSP-S hence
494 * provide a custom SSID (same as DID by default) value via UPD.
495 */
496 static void fill_fsps_pci_ssid_params(FSP_S_CONFIG *s_cfg,
497 const struct soc_intel_pantherlake_config *config)
498 {
499 struct svid_ssid_init_entry {
500 union {
501 struct {
502 uint64_t reg:12;
503 uint64_t function:3;
504 uint64_t device:5;
505 uint64_t bus:8;
506 uint64_t ignore1:4;
507 uint64_t segment:16;
508 uint64_t ignore2:16;
509 };
510 uint64_t data;
511 };
512 struct {
513 uint16_t svid;
514 uint16_t ssid;
515 };
516 uint32_t ignore3;
517 };
518
519 static struct svid_ssid_init_entry ssid_table[MAX_ONBOARD_PCIE_DEVICES];
520 const struct device *dev;
521 size_t i = 0;
522
523 for (dev = all_devices; dev; dev = dev->next) {
524 if (!(is_dev_enabled(dev) && dev->path.type == DEVICE_PATH_PCI &&
525 dev->upstream->secondary == 0))
526 continue;
527
528 if (dev->path.pci.devfn == PCI_DEVFN_ROOT) {
529 evaluate_ssid(dev, &s_cfg->SiCustomizedSvid, &s_cfg->SiCustomizedSsid);
530 } else {
531 ssid_table[i].reg = PCI_SUBSYSTEM_VENDOR_ID;
532 ssid_table[i].device = PCI_SLOT(dev->path.pci.devfn);
533 ssid_table[i].function = PCI_FUNC(dev->path.pci.devfn);
534 evaluate_ssid(dev, &ssid_table[i].svid, &ssid_table[i].ssid);
535 i++;
536 }
537 }
538
539 s_cfg->SiSsidTablePtr = (uintptr_t)ssid_table;
540 s_cfg->SiNumberOfSsidTableEntry = i;
541
542 /* Ensure FSP will program the registers */
543 s_cfg->SiSkipSsidProgramming = 0;
544 }
545
546 static void fill_fsps_lan_params(FSP_S_CONFIG *s_cfg,
547 const struct soc_intel_pantherlake_config *config)
548 {
549 s_cfg->PchLanEnable = is_devfn_enabled(PCI_DEVFN_GBE);
550 }
551
552 static void fill_fsps_cnvi_params(FSP_S_CONFIG *s_cfg,
553 const struct soc_intel_pantherlake_config *config)
554 {
555 s_cfg->CnviMode = is_devfn_enabled(PCI_DEVFN_CNVI_WIFI);
556 s_cfg->CnviWifiCore = config->cnvi_wifi_core;
557 s_cfg->CnviBtCore = config->cnvi_bt_core;
558 s_cfg->CnviBtAudioOffload = config->cnvi_bt_audio_offload;
559
560 if (!s_cfg->CnviMode && s_cfg->CnviWifiCore) {
561 printk(BIOS_ERR, "CNVi WiFi is enabled without CNVi being enabled\n");
562 s_cfg->CnviWifiCore = 0;
563 }
564 if (!s_cfg->CnviBtCore && s_cfg->CnviBtAudioOffload) {
565 printk(BIOS_ERR, "BT offload is enabled without CNVi BT being enabled\n");
566 s_cfg->CnviBtAudioOffload = 0;
567 }
568 if (!s_cfg->CnviMode && s_cfg->CnviBtCore) {
569 printk(BIOS_ERR, "CNVi BT is enabled without CNVi being enabled\n");
570 s_cfg->CnviBtCore = 0;
571 s_cfg->CnviBtAudioOffload = 0;
572 }
573
574 s_cfg->CnviBtInterface = is_devfn_enabled(PCI_DEVFN_CNVI_BT) ? 2 : 1;
575 }
576
577 static void fill_fsps_vmd_params(FSP_S_CONFIG *s_cfg,
578 const struct soc_intel_pantherlake_config *config)
579 {
580 s_cfg->VmdEnable = is_devfn_enabled(PCI_DEVFN_VMD);
581 }
582
583 static void fill_fsps_pmcpd_params(FSP_S_CONFIG *s_cfg,
584 const struct soc_intel_pantherlake_config *config)
585 {
586 s_cfg->PmcPdEnable = 1;
587 }
588
589 static void fill_fsps_thc_params(FSP_S_CONFIG *s_cfg,
590 const struct soc_intel_pantherlake_config *config)
591 {
592 for (size_t i = 0; i < NUM_THC; i++) {
593 if (!is_devfn_enabled(_PCI_DEVFN(THC, i))) {
594 s_cfg->ThcAssignment[i] = THC_NONE;
595 continue;
596 }
597 s_cfg->ThcAssignment[i] = THC_0 + i;
598 s_cfg->ThcMode[i] = config->thc_mode[i];
599 s_cfg->ThcWakeOnTouch[i] = config->thc_wake_on_touch[i];
600 }
601 }
602
603 static void fill_fsps_8254_params(FSP_S_CONFIG *s_cfg,
604 const struct soc_intel_pantherlake_config *config)
605 {
606 bool use_8254 = get_uint_option("legacy_8254_timer", CONFIG(USE_LEGACY_8254_TIMER));
607 s_cfg->Enable8254ClockGating = !use_8254;
608 s_cfg->Enable8254ClockGatingOnS3 = !use_8254;
609 }
610
611 static void fill_fsps_pm_timer_params(FSP_S_CONFIG *s_cfg,
612 const struct soc_intel_pantherlake_config *config)
613 {
614 /*
615 * Legacy PM ACPI Timer (and TCO Timer)
616 * This *must* be 1 in any case to keep FSP from
617 * 1) enabling PM ACPI Timer emulation in uCode.
618 * 2) disabling the PM ACPI Timer.
619 * We handle both by ourself!
620 */
621 s_cfg->EnableTcoTimer = 1;
622 }
623
624 static void fill_fsps_pcie_params(FSP_S_CONFIG *s_cfg,
625 const struct soc_intel_pantherlake_config *config)
626 {
627 uint32_t enable_mask = pcie_rp_enable_mask(get_pcie_rp_table());
628
629 for (size_t i = 0; i < CONFIG_MAX_ROOT_PORTS; i++) {
630 const struct pcie_rp_config *rp_cfg = &config->pcie_rp[i];
631 if (!(enable_mask & BIT(i)))
632 continue;
633 s_cfg->PcieRpL1Substates[i] =
634 get_l1_substate_control(rp_cfg->PcieRpL1Substates);
635 s_cfg->PcieRpLtrEnable[i] = !!(rp_cfg->flags & PCIE_RP_LTR);
636 s_cfg->PcieRpAdvancedErrorReporting[i] = !!(rp_cfg->flags & PCIE_RP_AER);
637 s_cfg->PcieRpHotPlug[i] =
638 !!(rp_cfg->flags & PCIE_RP_HOTPLUG) || CONFIG(SOC_INTEL_COMPLIANCE_TEST_MODE);
639 s_cfg->PcieRpClkReqDetect[i] = !!(rp_cfg->flags & PCIE_RP_CLK_REQ_DETECT);
640 if (rp_cfg->pcie_rp_aspm)
641 s_cfg->PcieRpAspm[i] = get_aspm_control(rp_cfg->pcie_rp_aspm);
642 }
643
644 s_cfg->PcieComplianceTestMode = CONFIG(SOC_INTEL_COMPLIANCE_TEST_MODE);
645 }
646
647 static void fill_fsps_misc_power_params(FSP_S_CONFIG *s_cfg,
648 const struct soc_intel_pantherlake_config *config)
649 {
650 /* Skip setting D0I3 bit for all HECI devices */
651 s_cfg->DisableD0I3SettingForHeci = 1;
652
653 s_cfg->Hwp = 1;
654 s_cfg->Cx = 1;
655 /* Enable the energy efficient turbo mode */
656 s_cfg->EnergyEfficientTurbo = 1;
657 s_cfg->PmcLpmS0ixSubStateEnableMask = get_supported_lpm_mask();
658 /* Un-Demotion from Demoted C1 need to be disable when
659 C1 auto demotion is disabled. */
660 s_cfg->C1StateUnDemotion = !config->disable_c1_state_auto_demotion;
661 s_cfg->C1StateAutoDemotion = !config->disable_c1_state_auto_demotion;
662 s_cfg->PkgCStateDemotion = !config->disable_package_c_state_demotion;
663 s_cfg->PkgCStateUnDemotion = !config->disable_package_c_state_demotion;
664 s_cfg->PmcV1p05PhyExtFetControlEn = 1;
665
666 /* Enable/Disable PCH to CPU energy report feature. */
667 s_cfg->PchPmDisableEnergyReport = !config->pch_pm_energy_report_enable;
668
669 /* Apply PCH PM minimum assertion width settings */
670 if (config->pch_slp_s3_min_assertion_width == SLP_S3_ASSERTION_DEFAULT)
671 s_cfg->PchPmSlpS3MinAssert = SLP_S3_ASSERTION_50_MS;
672 else
673 s_cfg->PchPmSlpS3MinAssert = config->pch_slp_s3_min_assertion_width;
674
675 if (config->pch_slp_s4_min_assertion_width == SLP_S4_ASSERTION_DEFAULT)
676 s_cfg->PchPmSlpS4MinAssert = SLP_S4_ASSERTION_1S;
677 else
678 s_cfg->PchPmSlpS4MinAssert = config->pch_slp_s4_min_assertion_width;
679
680 if (config->pch_slp_sus_min_assertion_width == SLP_SUS_ASSERTION_DEFAULT)
681 s_cfg->PchPmSlpSusMinAssert = SLP_SUS_ASSERTION_4_S;
682 else
683 s_cfg->PchPmSlpSusMinAssert = config->pch_slp_sus_min_assertion_width;
684
685 if (config->pch_slp_a_min_assertion_width == SLP_A_ASSERTION_DEFAULT)
686 s_cfg->PchPmSlpAMinAssert = SLP_A_ASSERTION_2_S;
687 else
688 s_cfg->PchPmSlpAMinAssert = config->pch_slp_a_min_assertion_width;
689
690 /*
691 * The Reset Power Cycle Duration starts at 20ms and increases by 20ms for each step,
692 * beginning from 0x0 to 0xFF. Each subsequent increment corresponds to an additional
693 * 20 milliseconds in duration.
694 * PCH PM Reset Power Cycle Duration = (PchPmPwrCycDur + 1) * 20ms
695 */
696 const uint8_t fsp_pm_pwr_cyc_dur_list[] = {
697 0xc7, /* POWER_CYCLE_DURATION_DEFAULT */
698 0x31, /* POWER_CYCLE_DURATION_1S */
699 0x63, /* POWER_CYCLE_DURATION_2S */
700 0x95, /* POWER_CYCLE_DURATION_3S */
701 0xc7 /* POWER_CYCLE_DURATION_4S */
702 };
703 if (config->pch_reset_power_cycle_duration) {
704 uint8_t pwr_cyc_dur = get_pm_pwr_cyc_dur(s_cfg->PchPmSlpS4MinAssert,
705 s_cfg->PchPmSlpS3MinAssert,
706 s_cfg->PchPmSlpAMinAssert,
707 config->pch_reset_power_cycle_duration);
708 s_cfg->PchPmPwrCycDur = fsp_pm_pwr_cyc_dur_list[pwr_cyc_dur];
709 } else {
710 s_cfg->PchPmPwrCycDur = fsp_pm_pwr_cyc_dur_list[POWER_CYCLE_DURATION_DEFAULT];
711 }
712 }
713
714 static void fill_fsps_npu_params(FSP_S_CONFIG *s_cfg,
715 const struct soc_intel_pantherlake_config *config)
716 {
717 s_cfg->NpuEnable = is_devfn_enabled(PCI_DEVFN_NPU);
718 }
719
720 static void fill_fsps_audio_params(FSP_S_CONFIG *s_cfg,
721 const struct soc_intel_pantherlake_config *config)
722 {
723 if (!is_devfn_enabled(PCI_DEVFN_HDA))
724 return;
725
726 /* Fill MIC privacy settings */
727 s_cfg->PchHdaMicPrivacyHwModeSoundWire0 = 1;
728 s_cfg->PchHdaMicPrivacyHwModeSoundWire1 = 1;
729 s_cfg->PchHdaMicPrivacyHwModeSoundWire2 = 1;
730 s_cfg->PchHdaMicPrivacyHwModeSoundWire3 = 1;
731 s_cfg->PchHdaMicPrivacyHwModeSoundWire4 = 1;
732 s_cfg->PchHdaMicPrivacyHwModeDmic = 1;
733 }
734
735 static void fill_fsps_iax_params(FSP_S_CONFIG *s_cfg,
736 const struct soc_intel_pantherlake_config *config)
737 {
738 s_cfg->IaxEnable = is_devfn_enabled(PCI_DEVFN_IAA);
739 }
740
741 static void fill_fsps_ufs_params(FSP_S_CONFIG *s_cfg,
742 const struct soc_intel_pantherlake_config *config)
743 {
744 #if CONFIG(SOC_INTEL_WILDCATLAKE)
745 /* Setting FSP UPD (1,0) to enable controller 0 */
746 s_cfg->UfsEnable[0] = is_devfn_enabled(PCI_DEVFN_UFS);
747 s_cfg->UfsEnable[1] = 0;
748 #else
749 /* Setting FSP UPD (0,0) to keep both controllers disabled */
750 s_cfg->UfsEnable[0] = 0;
751 s_cfg->UfsEnable[1] = 0;
752 #endif
753 }
754
755 static void arch_silicon_init_params(FSPS_ARCH2_UPD *s_arch_cfg)
756 {
757 /* Assign FspEventHandler arch Upd to use coreboot debug event handler */
758 if (CONFIG(FSP_USES_CB_DEBUG_EVENT_HANDLER)
759 && CONFIG(CONSOLE_SERIAL)
760 && CONFIG(FSP_ENABLE_SERIAL_DEBUG) && fsp_get_pcd_debug_log_level())
761 s_arch_cfg->FspEventHandler = (uintptr_t)((FSP_EVENT_HANDLER *)
762 fsp_debug_event_handler);
763
764 }
765
766 static void soc_silicon_init_params(FSP_S_CONFIG *s_cfg,
767 const struct soc_intel_pantherlake_config *config)
768 {
769 void (*fill_fsps_params[])(FSP_S_CONFIG *s_cfg,
770 const struct soc_intel_pantherlake_config *config) = {
771 fill_fsps_lpss_params,
772 fill_fsps_cpu_params,
773 fill_fsps_microcode_params,
774 fill_fsps_igd_params,
775 fill_fsps_tcss_params,
776 fill_fsps_chipset_lockdown_params,
777 fill_fsps_xhci_params,
778 fill_fsps_xdci_params,
779 fill_fsps_thermal_params,
780 fill_fsps_irq_params,
781 fill_fsps_pci_ssid_params,
782 fill_fsps_lan_params,
783 fill_fsps_cnvi_params,
784 fill_fsps_vmd_params,
785 fill_fsps_pmcpd_params,
786 fill_fsps_thc_params,
787 fill_fsps_8254_params,
788 fill_fsps_pm_timer_params,
789 fill_fsps_pcie_params,
790 fill_fsps_misc_power_params,
791 fill_fsps_npu_params,
792 fill_fsps_audio_params,
793 fill_fsps_iax_params,
794 fill_fsps_ufs_params,
795 };
796
797 for (size_t i = 0; i < ARRAY_SIZE(fill_fsps_params); i++)
798 fill_fsps_params[i](s_cfg, config);
799 }
800
801 /* UPD parameters to be initialized before SiliconInit */
802 void platform_fsp_silicon_init_params_cb(FSPS_UPD *supd)
803 {
804 struct soc_intel_pantherlake_config *config;
805 FSP_S_CONFIG *s_cfg = &supd->FspsConfig;
806 FSPS_ARCH2_UPD *s_arch_cfg = &supd->FspsArchUpd;
807
808 config = config_of_soc();
809 arch_silicon_init_params(s_arch_cfg);
810 /* Override settings per board if required. */
811 mainboard_update_soc_chip_config(config);
812 soc_silicon_init_params(s_cfg, config);
813 mainboard_silicon_init_params(s_cfg);
814 }
815
816 /*
817 * Callbacks for SoC/Mainboard specific overrides for FspMultiPhaseSiInit
818 * This platform supports below MultiPhaseSIInit Phase(s):
819 *
820 * Phase | FSP return point | Purpose
821 * ----- + -------------------------------------+ ------------------------
822 * 1 | After TCSS initialization completed | for TCSS specific init
823 */
824 void platform_fsp_silicon_multi_phase_init_cb(uint32_t phase_index)
825 {
826 switch (phase_index) {
827 case 1:
828 /* TCSS specific initialization here */
829 printk(BIOS_DEBUG, "FSP MultiPhaseSiInit %s/%s called\n",
830 __FILE__, __func__);
831
832 if (CONFIG(SOC_INTEL_COMMON_BLOCK_TCSS)) {
833 const struct soc_intel_pantherlake_config *config = config_of_soc();
834 tcss_configure(config->typec_aux_bias_pads);
835 }
836
837 /* Allow CBFS preload transfers to complete before FSP-S locks SPI DMA. */
838 struct soc_intel_common_config *config = chip_get_common_soc_structure();
839 if (config->chipset_lockdown == CHIPSET_LOCKDOWN_FSP)
840 cbfs_preload_wait_for_all();
841 break;
842 default:
843 break;
844 }
845 }
846
847 /* Mainboard GPIO Configuration */
848 __weak void mainboard_silicon_init_params(FSP_S_CONFIG *s_cfg)
849 {
850 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
851 }
852
853 /* Handle FSP logo params */
854 void soc_load_logo_by_fsp(FSPS_UPD *supd)
855 {
856 efi_uintn_t logo, blt_size;
857 uint32_t logo_size;
858 struct soc_intel_common_config *config = chip_get_common_soc_structure();
859 FSP_S_CONFIG *s_cfg = &supd->FspsConfig;
860
861 /*
862 * Adjusts panel orientation for external display when the lid is closed.
863 *
864 * When the lid is closed (LidStatus == 0), indicating the onboard display is inactive,
865 * this function forces the panel orientation to normal. This ensures proper display
866 * on an external monitor, as rotated orientations are typically not suitable in
867 * such state.
868 */
869 if (s_cfg->LidStatus == 0)
870 config->panel_orientation = LB_FB_ORIENTATION_NORMAL;
871
872 fsp_load_and_convert_bmp_to_gop_blt(&logo, &logo_size,
873 &supd->FspsConfig.BltBufferAddress,
874 &blt_size,
875 &supd->FspsConfig.LogoPixelHeight,
876 &supd->FspsConfig.LogoPixelWidth,
877 config->panel_orientation);
878 }