Debian Codegraph @

src/soc/intel/meteorlake/fsp_params.c

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