Debian Codegraph @

src/soc/intel/alderlake/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 <console/console.h>
8 #include <cpu/intel/microcode.h>
9 #include <delay.h>
10 #include <device/device.h>
11 #include <device/pci.h>
12 #include <device/pci_ids.h>
13 #include <device/pci_ops.h>
14 #include <drivers/intel/gma/i915_reg.h>
15 #include <drivers/usb/acpi/chip.h>
16 #include <fsp/api.h>
17 #include <fsp/fsp_debug_event.h>
18 #include <fsp/fsp_gop_blt.h>
19 #include <fsp/ppi/mp_service_ppi.h>
20 #include <fsp/util.h>
21 #include <gpio.h>
22 #include <intelblocks/aspm.h>
23 #include <intelblocks/irq.h>
24 #include <intelblocks/lpss.h>
25 #include <intelblocks/mp_init.h>
26 #include <intelblocks/pmclib.h>
27 #include <intelblocks/xdci.h>
28 #include <intelpch/lockdown.h>
29 #include <intelblocks/systemagent.h>
30 #include <intelblocks/tcss.h>
31 #include <option.h>
32 #include <soc/cpu.h>
33 #include <soc/intel/common/vbt.h>
34 #include <soc/pci_devs.h>
35 #include <soc/pcie.h>
36 #include <soc/ramstage.h>
37 #include <soc/soc_chip.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 /* VccIn Aux Imon IccMax values in mA */
53 #define MILLIAMPS_TO_AMPS 1000
54 #define ICC_MAX_TDP_45W 34250
55 #define ICC_MAX_TDP_15W_28W 32000
56 #define ICC_MAX_ID_ADL_M_MA 12000
57 #define ICC_MAX_ID_ADL_N_MA 27000
58 #define ICC_MAX_ADL_S 33000
59 #define ICC_MAX_RPL_S 36000
60
61 /*
62 * ME End of Post configuration
63 * 0 - Disable EOP.
64 * 1 - Send in PEI (Applicable for FSP in API mode)
65 * 2 - Send in DXE (Not applicable for FSP in API mode)
66 */
67 enum fsp_end_of_post {
68 EOP_DISABLE = 0,
69 EOP_PEI = 1,
70 EOP_DXE = 2,
71 };
72
73 static const struct slot_irq_constraints irq_constraints[] = {
74 {
75 .slot = SA_DEV_SLOT_CPU_1,
76 .fns = {
77 FIXED_INT_PIRQ(SA_DEVFN_CPU_PCIE1_0, PCI_INT_A, PIRQ_A),
78 },
79 },
80 {
81 .slot = SA_DEV_SLOT_IGD,
82 .fns = {
83 /* INTERRUPT_PIN is RO/0x01 */
84 FIXED_INT_ANY_PIRQ(SA_DEVFN_IGD, PCI_INT_A),
85 },
86 },
87 {
88 .slot = SA_DEV_SLOT_DPTF,
89 .fns = {
90 ANY_PIRQ(SA_DEVFN_DPTF),
91 },
92 },
93 {
94 .slot = SA_DEV_SLOT_IPU,
95 .fns = {
96 /* INTERRUPT_PIN is RO/0x01, and INTERRUPT_LINE is RW,
97 but S0ix fails when not set to 16 (b/193434192) */
98 FIXED_INT_PIRQ(SA_DEVFN_IPU, PCI_INT_A, PIRQ_A),
99 },
100 },
101 {
102 .slot = SA_DEV_SLOT_CPU_6,
103 .fns = {
104 FIXED_INT_PIRQ(SA_DEVFN_CPU_PCIE6_0, PCI_INT_D, PIRQ_A),
105 FIXED_INT_PIRQ(SA_DEVFN_CPU_PCIE6_2, PCI_INT_B, PIRQ_C),
106 },
107 },
108 {
109 .slot = SA_DEV_SLOT_TBT,
110 .fns = {
111 ANY_PIRQ(SA_DEVFN_TBT0),
112 ANY_PIRQ(SA_DEVFN_TBT1),
113 ANY_PIRQ(SA_DEVFN_TBT2),
114 ANY_PIRQ(SA_DEVFN_TBT3),
115 },
116 },
117 {
118 .slot = SA_DEV_SLOT_GNA,
119 .fns = {
120 /* INTERRUPT_PIN is RO/0x01 */
121 FIXED_INT_ANY_PIRQ(SA_DEVFN_GNA, PCI_INT_A),
122 },
123 },
124 {
125 .slot = SA_DEV_SLOT_TCSS,
126 .fns = {
127 ANY_PIRQ(SA_DEVFN_TCSS_XHCI),
128 ANY_PIRQ(SA_DEVFN_TCSS_XDCI),
129 },
130 },
131 {
132 .slot = PCH_DEV_SLOT_SIO0,
133 .fns = {
134 DIRECT_IRQ(PCH_DEVFN_I2C6),
135 DIRECT_IRQ(PCH_DEVFN_I2C7),
136 ANY_PIRQ(PCH_DEVFN_THC0),
137 ANY_PIRQ(PCH_DEVFN_THC1),
138 },
139 },
140 {
141 .slot = PCH_DEV_SLOT_SIO6,
142 .fns = {
143 DIRECT_IRQ(PCH_DEVFN_UART3),
144 DIRECT_IRQ(PCH_DEVFN_UART4),
145 DIRECT_IRQ(PCH_DEVFN_UART5),
146 DIRECT_IRQ(PCH_DEVFN_UART6),
147 },
148 },
149 {
150 .slot = PCH_DEV_SLOT_ISH,
151 .fns = {
152 DIRECT_IRQ(PCH_DEVFN_ISH),
153 DIRECT_IRQ(PCH_DEVFN_GSPI2),
154 ANY_PIRQ(PCH_DEVFN_UFS),
155 },
156 },
157 {
158 .slot = PCH_DEV_SLOT_SIO2,
159 .fns = {
160 DIRECT_IRQ(PCH_DEVFN_GSPI3),
161 DIRECT_IRQ(PCH_DEVFN_GSPI4),
162 DIRECT_IRQ(PCH_DEVFN_GSPI5),
163 DIRECT_IRQ(PCH_DEVFN_GSPI6),
164 },
165 },
166 {
167 .slot = PCH_DEV_SLOT_XHCI,
168 .fns = {
169 ANY_PIRQ(PCH_DEVFN_XHCI),
170 DIRECT_IRQ(PCH_DEVFN_USBOTG),
171 ANY_PIRQ(PCH_DEVFN_CNVI_WIFI),
172 },
173 },
174 {
175 .slot = PCH_DEV_SLOT_SIO3,
176 .fns = {
177 DIRECT_IRQ(PCH_DEVFN_I2C0),
178 DIRECT_IRQ(PCH_DEVFN_I2C1),
179 DIRECT_IRQ(PCH_DEVFN_I2C2),
180 DIRECT_IRQ(PCH_DEVFN_I2C3),
181 },
182 },
183 {
184 .slot = PCH_DEV_SLOT_CSE,
185 .fns = {
186 ANY_PIRQ(PCH_DEVFN_CSE),
187 ANY_PIRQ(PCH_DEVFN_CSE_2),
188 ANY_PIRQ(PCH_DEVFN_CSE_IDER),
189 ANY_PIRQ(PCH_DEVFN_CSE_KT),
190 ANY_PIRQ(PCH_DEVFN_CSE_3),
191 ANY_PIRQ(PCH_DEVFN_CSE_4),
192 },
193 },
194 {
195 .slot = PCH_DEV_SLOT_SATA,
196 .fns = {
197 ANY_PIRQ(PCH_DEVFN_SATA),
198 },
199 },
200 {
201 .slot = PCH_DEV_SLOT_SIO4,
202 .fns = {
203 DIRECT_IRQ(PCH_DEVFN_I2C4),
204 DIRECT_IRQ(PCH_DEVFN_I2C5),
205 DIRECT_IRQ(PCH_DEVFN_UART2),
206 },
207 },
208 #if CONFIG(SOC_INTEL_ALDERLAKE_PCH_N)
209 {
210 .slot = PCH_DEV_SLOT_EMMC,
211 .fns = {
212 ANY_PIRQ(PCH_DEVFN_EMMC),
213 },
214 },
215 #endif
216 {
217 .slot = PCH_DEV_SLOT_PCIE,
218 .fns = {
219 FIXED_INT_PIRQ(PCH_DEVFN_PCIE1, PCI_INT_A, PIRQ_A),
220 FIXED_INT_PIRQ(PCH_DEVFN_PCIE2, PCI_INT_B, PIRQ_B),
221 FIXED_INT_PIRQ(PCH_DEVFN_PCIE3, PCI_INT_C, PIRQ_C),
222 FIXED_INT_PIRQ(PCH_DEVFN_PCIE4, PCI_INT_D, PIRQ_D),
223 FIXED_INT_PIRQ(PCH_DEVFN_PCIE5, PCI_INT_A, PIRQ_A),
224 FIXED_INT_PIRQ(PCH_DEVFN_PCIE6, PCI_INT_B, PIRQ_B),
225 FIXED_INT_PIRQ(PCH_DEVFN_PCIE7, PCI_INT_C, PIRQ_C),
226 FIXED_INT_PIRQ(PCH_DEVFN_PCIE8, PCI_INT_D, PIRQ_D),
227 },
228 },
229 {
230 .slot = PCH_DEV_SLOT_PCIE_1,
231 .fns = {
232 FIXED_INT_PIRQ(PCH_DEVFN_PCIE9, PCI_INT_A, PIRQ_A),
233 FIXED_INT_PIRQ(PCH_DEVFN_PCIE10, PCI_INT_B, PIRQ_B),
234 FIXED_INT_PIRQ(PCH_DEVFN_PCIE11, PCI_INT_C, PIRQ_C),
235 FIXED_INT_PIRQ(PCH_DEVFN_PCIE12, PCI_INT_D, PIRQ_D),
236 },
237 },
238 {
239 .slot = PCH_DEV_SLOT_SIO5,
240 .fns = {
241 /* UART0 shares an interrupt line with TSN0, so must use
242 a PIRQ */
243 FIXED_INT_ANY_PIRQ(PCH_DEVFN_UART0, PCI_INT_A),
244 /* UART1 shares an interrupt line with TSN1, so must use
245 a PIRQ */
246 FIXED_INT_ANY_PIRQ(PCH_DEVFN_UART1, PCI_INT_B),
247 DIRECT_IRQ(PCH_DEVFN_GSPI0),
248 DIRECT_IRQ(PCH_DEVFN_GSPI1),
249 },
250 },
251 {
252 .slot = PCH_DEV_SLOT_ESPI,
253 .fns = {
254 ANY_PIRQ(PCH_DEVFN_HDA),
255 ANY_PIRQ(PCH_DEVFN_SMBUS),
256 ANY_PIRQ(PCH_DEVFN_GBE),
257 /* INTERRUPT_PIN is RO/0x01 */
258 FIXED_INT_ANY_PIRQ(PCH_DEVFN_TRACEHUB, PCI_INT_A),
259 },
260 },
261 };
262
263 static const struct slot_irq_constraints irq_constraints_pch_s[] = {
264 {
265 .slot = SA_DEV_SLOT_CPU_1,
266 .fns = {
267 FIXED_INT_PIRQ(SA_DEVFN_CPU_PCIE1_0, PCI_INT_A, PIRQ_A),
268 FIXED_INT_PIRQ(SA_DEVFN_CPU_PCIE1_1, PCI_INT_B, PIRQ_B),
269 },
270 },
271 {
272 .slot = SA_DEV_SLOT_IGD,
273 .fns = {
274 /* INTERRUPT_PIN is RO/0x01 */
275 FIXED_INT_ANY_PIRQ(SA_DEVFN_IGD, PCI_INT_A),
276 },
277 },
278 {
279 .slot = SA_DEV_SLOT_DPTF,
280 .fns = {
281 ANY_PIRQ(SA_DEVFN_DPTF),
282 },
283 },
284 {
285 .slot = SA_DEV_SLOT_CPU_6,
286 .fns = {
287 FIXED_INT_PIRQ(SA_DEVFN_CPU_PCIE6_0, PCI_INT_D, PIRQ_A),
288 },
289 },
290 {
291 .slot = SA_DEV_SLOT_GNA,
292 .fns = {
293 /* INTERRUPT_PIN is RO/0x01 */
294 FIXED_INT_ANY_PIRQ(SA_DEVFN_GNA, PCI_INT_A),
295 },
296 },
297 {
298 .slot = PCH_DEV_SLOT_SIO6,
299 .fns = {
300 DIRECT_IRQ(PCH_DEVFN_UART3),
301 },
302 },
303 {
304 .slot = PCH_DEV_SLOT_ISH,
305 .fns = {
306 DIRECT_IRQ(PCH_DEVFN_ISH),
307 DIRECT_IRQ(PCH_DEVFN_GSPI2),
308 },
309 },
310 {
311 .slot = PCH_DEV_SLOT_SIO2,
312 .fns = {
313 DIRECT_IRQ(PCH_DEVFN_GSPI3),
314 },
315 },
316 {
317 .slot = PCH_DEV_SLOT_XHCI,
318 .fns = {
319 ANY_PIRQ(PCH_DEVFN_XHCI),
320 DIRECT_IRQ(PCH_DEVFN_USBOTG),
321 ANY_PIRQ(PCH_DEVFN_CNVI_WIFI),
322 },
323 },
324 {
325 .slot = PCH_DEV_SLOT_SIO3,
326 .fns = {
327 DIRECT_IRQ(PCH_DEVFN_I2C0),
328 DIRECT_IRQ(PCH_DEVFN_I2C1),
329 DIRECT_IRQ(PCH_DEVFN_I2C2),
330 DIRECT_IRQ(PCH_DEVFN_I2C3),
331 },
332 },
333 {
334 .slot = PCH_DEV_SLOT_CSE,
335 .fns = {
336 ANY_PIRQ(PCH_DEVFN_CSE),
337 ANY_PIRQ(PCH_DEVFN_CSE_2),
338 ANY_PIRQ(PCH_DEVFN_CSE_IDER),
339 ANY_PIRQ(PCH_DEVFN_CSE_KT),
340 ANY_PIRQ(PCH_DEVFN_CSE_3),
341 ANY_PIRQ(PCH_DEVFN_CSE_4),
342 },
343 },
344 {
345 .slot = PCH_DEV_SLOT_SATA,
346 .fns = {
347 ANY_PIRQ(PCH_DEVFN_SATA),
348 },
349 },
350 {
351 .slot = PCH_DEV_SLOT_SIO4,
352 .fns = {
353 DIRECT_IRQ(PCH_DEVFN_I2C4),
354 DIRECT_IRQ(PCH_DEVFN_I2C5),
355 DIRECT_IRQ(PCH_DEVFN_UART2),
356 },
357 },
358 {
359 .slot = PCH_DEV_SLOT_PCIE,
360 .fns = {
361 FIXED_INT_PIRQ(PCH_DEVFN_PCIE1, PCI_INT_A, PIRQ_A),
362 FIXED_INT_PIRQ(PCH_DEVFN_PCIE2, PCI_INT_B, PIRQ_B),
363 FIXED_INT_PIRQ(PCH_DEVFN_PCIE3, PCI_INT_C, PIRQ_C),
364 FIXED_INT_PIRQ(PCH_DEVFN_PCIE4, PCI_INT_D, PIRQ_D),
365 FIXED_INT_PIRQ(PCH_DEVFN_PCIE5, PCI_INT_A, PIRQ_A),
366 FIXED_INT_PIRQ(PCH_DEVFN_PCIE6, PCI_INT_B, PIRQ_B),
367 FIXED_INT_PIRQ(PCH_DEVFN_PCIE7, PCI_INT_C, PIRQ_C),
368 FIXED_INT_PIRQ(PCH_DEVFN_PCIE8, PCI_INT_D, PIRQ_D),
369 },
370 },
371 {
372 .slot = PCH_DEV_SLOT_PCIE_1,
373 .fns = {
374 FIXED_INT_PIRQ(PCH_DEVFN_PCIE9, PCI_INT_A, PIRQ_A),
375 FIXED_INT_PIRQ(PCH_DEVFN_PCIE10, PCI_INT_B, PIRQ_B),
376 FIXED_INT_PIRQ(PCH_DEVFN_PCIE11, PCI_INT_C, PIRQ_C),
377 FIXED_INT_PIRQ(PCH_DEVFN_PCIE12, PCI_INT_D, PIRQ_D),
378 FIXED_INT_PIRQ(PCH_DEVFN_PCIE13, PCI_INT_A, PIRQ_A),
379 FIXED_INT_PIRQ(PCH_DEVFN_PCIE14, PCI_INT_B, PIRQ_B),
380 FIXED_INT_PIRQ(PCH_DEVFN_PCIE15, PCI_INT_C, PIRQ_C),
381 FIXED_INT_PIRQ(PCH_DEVFN_PCIE16, PCI_INT_D, PIRQ_D),
382 },
383 },
384 {
385 .slot = PCH_DEV_SLOT_PCIE_2,
386 .fns = {
387 FIXED_INT_PIRQ(PCH_DEVFN_PCIE17, PCI_INT_A, PIRQ_A),
388 FIXED_INT_PIRQ(PCH_DEVFN_PCIE18, PCI_INT_B, PIRQ_B),
389 FIXED_INT_PIRQ(PCH_DEVFN_PCIE19, PCI_INT_C, PIRQ_C),
390 FIXED_INT_PIRQ(PCH_DEVFN_PCIE20, PCI_INT_D, PIRQ_D),
391 FIXED_INT_PIRQ(PCH_DEVFN_PCIE21, PCI_INT_A, PIRQ_A),
392 FIXED_INT_PIRQ(PCH_DEVFN_PCIE22, PCI_INT_B, PIRQ_B),
393 FIXED_INT_PIRQ(PCH_DEVFN_PCIE23, PCI_INT_C, PIRQ_C),
394 FIXED_INT_PIRQ(PCH_DEVFN_PCIE24, PCI_INT_D, PIRQ_D),
395 },
396 },
397 {
398 .slot = PCH_DEV_SLOT_PCIE_3,
399 .fns = {
400 FIXED_INT_PIRQ(PCH_DEVFN_PCIE25, PCI_INT_A, PIRQ_A),
401 FIXED_INT_PIRQ(PCH_DEVFN_PCIE26, PCI_INT_B, PIRQ_B),
402 FIXED_INT_PIRQ(PCH_DEVFN_PCIE27, PCI_INT_C, PIRQ_C),
403 FIXED_INT_PIRQ(PCH_DEVFN_PCIE28, PCI_INT_D, PIRQ_D),
404 },
405 },
406 {
407 .slot = PCH_DEV_SLOT_SIO5,
408 .fns = {
409 /* UART0 shares an interrupt line with TSN0, so must use
410 a PIRQ */
411 FIXED_INT_ANY_PIRQ(PCH_DEVFN_UART0, PCI_INT_A),
412 /* UART1 shares an interrupt line with TSN1, so must use
413 a PIRQ */
414 FIXED_INT_ANY_PIRQ(PCH_DEVFN_UART1, PCI_INT_B),
415 DIRECT_IRQ(PCH_DEVFN_GSPI0),
416 DIRECT_IRQ(PCH_DEVFN_GSPI1),
417 },
418 },
419 {
420 .slot = PCH_DEV_SLOT_ESPI,
421 .fns = {
422 ANY_PIRQ(PCH_DEVFN_HDA),
423 ANY_PIRQ(PCH_DEVFN_SMBUS),
424 ANY_PIRQ(PCH_DEVFN_GBE),
425 /* INTERRUPT_PIN is RO/0x01 */
426 FIXED_INT_ANY_PIRQ(PCH_DEVFN_TRACEHUB, PCI_INT_A),
427 },
428 },
429 };
430
431 static const SI_PCH_DEVICE_INTERRUPT_CONFIG *pci_irq_to_fsp(size_t *out_count)
432 {
433 const struct pci_irq_entry *entry = get_cached_pci_irqs();
434 SI_PCH_DEVICE_INTERRUPT_CONFIG *config;
435 size_t pch_total = 0;
436 size_t cfg_count = 0;
437
438 if (!entry)
439 return NULL;
440
441 /* Count PCH devices */
442 while (entry) {
443 if (is_pch_slot(entry->devfn))
444 ++pch_total;
445 entry = entry->next;
446 }
447
448 /* Convert PCH device entries to FSP format */
449 config = calloc(pch_total, sizeof(*config));
450 entry = get_cached_pci_irqs();
451 while (entry) {
452 if (!is_pch_slot(entry->devfn)) {
453 entry = entry->next;
454 continue;
455 }
456
457 config[cfg_count].Device = PCI_SLOT(entry->devfn);
458 config[cfg_count].Function = PCI_FUNC(entry->devfn);
459 config[cfg_count].IntX = (SI_PCH_INT_PIN)entry->pin;
460 config[cfg_count].Irq = entry->irq;
461 ++cfg_count;
462
463 entry = entry->next;
464 }
465
466 *out_count = cfg_count;
467
468 return config;
469 }
470
471 /* This function returns the VccIn Aux Imon IccMax values for ADL and RPL
472 SKU's */
473 static uint16_t get_vccin_aux_imon_iccmax(const struct soc_intel_alderlake_config *config)
474 {
475 struct device *dev = pcidev_path_on_root(SA_DEVFN_ROOT);
476 uint16_t mch_id = dev ? pci_read_config16(dev, PCI_DEVICE_ID) : 0xffff;
477 uint8_t tdp;
478
479 switch (mch_id) {
480 case PCI_DID_INTEL_ADL_P_ID_1:
481 case PCI_DID_INTEL_ADL_P_ID_3:
482 case PCI_DID_INTEL_ADL_P_ID_4:
483 case PCI_DID_INTEL_ADL_P_ID_5:
484 case PCI_DID_INTEL_ADL_P_ID_6:
485 case PCI_DID_INTEL_ADL_P_ID_7:
486 case PCI_DID_INTEL_ADL_P_ID_8:
487 case PCI_DID_INTEL_ADL_P_ID_9:
488 case PCI_DID_INTEL_ADL_P_ID_10:
489 case PCI_DID_INTEL_RPL_P_ID_1:
490 case PCI_DID_INTEL_RPL_P_ID_2:
491 case PCI_DID_INTEL_RPL_P_ID_3:
492 case PCI_DID_INTEL_RPL_P_ID_4:
493 case PCI_DID_INTEL_RPL_P_ID_5:
494 case PCI_DID_INTEL_RPL_P_ID_6:
495 case PCI_DID_INTEL_RPL_P_ID_7:
496 case PCI_DID_INTEL_RPL_P_ID_8:
497 tdp = get_cpu_tdp();
498 if (tdp == TDP_45W)
499 return ICC_MAX_TDP_45W;
500 return ICC_MAX_TDP_15W_28W;
501 case PCI_DID_INTEL_ADL_M_ID_1:
502 case PCI_DID_INTEL_ADL_M_ID_2:
503 return ICC_MAX_ID_ADL_M_MA;
504 case PCI_DID_INTEL_ADL_N_ID_1:
505 case PCI_DID_INTEL_ADL_N_ID_2:
506 case PCI_DID_INTEL_ADL_N_ID_3:
507 case PCI_DID_INTEL_ADL_N_ID_4:
508 case PCI_DID_INTEL_ADL_N_ID_5:
509 case PCI_DID_INTEL_ADL_N_ID_6:
510 case PCI_DID_INTEL_ADL_N_ID_7:
511 case PCI_DID_INTEL_ADL_N_ID_8:
512 case PCI_DID_INTEL_ADL_N_ID_9:
513 return config->vccin_aux_imon_iccmax
514 ? config->vccin_aux_imon_iccmax : ICC_MAX_ID_ADL_N_MA;
515 case PCI_DID_INTEL_ADL_S_ID_1:
516 case PCI_DID_INTEL_ADL_S_ID_3:
517 case PCI_DID_INTEL_ADL_S_ID_8:
518 case PCI_DID_INTEL_ADL_S_ID_10:
519 case PCI_DID_INTEL_ADL_S_ID_11:
520 case PCI_DID_INTEL_ADL_S_ID_12:
521 case PCI_DID_INTEL_ASL_ID_1:
522 case PCI_DID_INTEL_ASL_ID_2:
523 case PCI_DID_INTEL_ASL_ID_3:
524 case PCI_DID_INTEL_RPL_HX_ID_1:
525 case PCI_DID_INTEL_RPL_HX_ID_2:
526 case PCI_DID_INTEL_RPL_HX_ID_3:
527 case PCI_DID_INTEL_RPL_HX_ID_4:
528 case PCI_DID_INTEL_RPL_HX_ID_5:
529 case PCI_DID_INTEL_RPL_HX_ID_6:
530 case PCI_DID_INTEL_RPL_HX_ID_7:
531 case PCI_DID_INTEL_RPL_HX_ID_8:
532 return ICC_MAX_ADL_S;
533 case PCI_DID_INTEL_RPL_S_ID_1:
534 case PCI_DID_INTEL_RPL_S_ID_2:
535 case PCI_DID_INTEL_RPL_S_ID_3:
536 case PCI_DID_INTEL_RPL_S_ID_4:
537 case PCI_DID_INTEL_RPL_S_ID_5:
538 return ICC_MAX_RPL_S;
539 default:
540 printk(BIOS_ERR, "Unknown MCH ID: 0x%4x, skipping VccInAuxImonIccMax config\n",
541 mch_id);
542 return 0;
543 }
544 }
545
546 __weak void mainboard_update_soc_chip_config(struct soc_intel_alderlake_config *config)
547 {
548 /* Override settings per board. */
549 }
550
551 static void fill_fsps_lpss_params(FSP_S_CONFIG *s_cfg,
552 const struct soc_intel_alderlake_config *config)
553 {
554 for (int i = 0; i < CONFIG_SOC_INTEL_I2C_DEV_MAX; i++)
555 s_cfg->SerialIoI2cMode[i] = config->serial_io_i2c_mode[i];
556
557 for (int i = 0; i < CONFIG_SOC_INTEL_COMMON_BLOCK_GSPI_MAX; i++) {
558 s_cfg->SerialIoSpiMode[i] = config->serial_io_gspi_mode[i];
559 s_cfg->SerialIoSpiCsMode[i] = config->serial_io_gspi_cs_mode[i];
560 s_cfg->SerialIoSpiCsState[i] = config->serial_io_gspi_cs_state[i];
561 }
562
563 for (int i = 0; i < CONFIG_SOC_INTEL_UART_DEV_MAX; i++)
564 s_cfg->SerialIoUartMode[i] = config->serial_io_uart_mode[i];
565 }
566
567 static void fill_fsps_microcode_params(FSP_S_CONFIG *s_cfg,
568 const struct soc_intel_alderlake_config *config)
569 {
570 const struct microcode *microcode_file;
571 size_t microcode_len;
572
573 /* Locate microcode and pass to FSP-S for 2nd microcode loading */
574 microcode_file = intel_microcode_find();
575
576 if (microcode_file != NULL) {
577 microcode_len = get_microcode_size(microcode_file);
578 if (microcode_len != 0) {
579 /* Update CPU Microcode patch base address/size */
580 s_cfg->MicrocodeRegionBase = (uint32_t)(uintptr_t)microcode_file;
581 s_cfg->MicrocodeRegionSize = (uint32_t)microcode_len;
582 }
583 }
584 }
585
586 static void fill_fsps_cpu_params(FSP_S_CONFIG *s_cfg,
587 const struct soc_intel_alderlake_config *config)
588 {
589 /*
590 * FIXME: FSP assumes ownership of the APs (Application Processors)
591 * upon passing `NULL` pointer to the CpuMpPpi FSP-S UPD.
592 * Hence, pass a valid pointer to the CpuMpPpi UPD unconditionally.
593 * This would avoid APs from getting hijacked by FSP while coreboot
594 * decides to set SkipMpInit UPD.
595 */
596 s_cfg->CpuMpPpi = (uintptr_t)mp_fill_ppi_services_data();
597
598 if (CONFIG(USE_FSP_FEATURE_PROGRAM_ON_APS))
599 /*
600 * Fill `2nd microcode loading FSP UPD` if FSP is running CPU feature
601 * programming.
602 */
603 fill_fsps_microcode_params(s_cfg, config);
604 else
605 s_cfg->SkipMpInit = !CONFIG(USE_INTEL_FSP_MP_INIT);
606 }
607
608 static void fill_fsps_igd_params(FSP_S_CONFIG *s_cfg,
609 const struct soc_intel_alderlake_config *config)
610 {
611 /* Load VBT before devicetree-specific config. */
612 s_cfg->GraphicsConfigPtr = (uintptr_t)vbt_get();
613
614 /* Check if IGD is present and fill Graphics init param accordingly */
615 s_cfg->PeiGraphicsPeimInit = CONFIG(RUN_FSP_GOP) && is_devfn_enabled(SA_DEVFN_IGD);
616 s_cfg->LidStatus = CONFIG(VBOOT_LID_SWITCH) ? get_lid_switch() : CONFIG(RUN_FSP_GOP);
617 s_cfg->PavpEnable = CONFIG(PAVP);
618 }
619
620 WEAK_DEV_PTR(tcss_usb3_port1);
621 WEAK_DEV_PTR(tcss_usb3_port2);
622 WEAK_DEV_PTR(tcss_usb3_port3);
623 WEAK_DEV_PTR(tcss_usb3_port4);
624
625 static void fill_fsps_tcss_params(FSP_S_CONFIG *s_cfg,
626 const struct soc_intel_alderlake_config *config)
627 {
628 const struct device *tcss_port_arr[] = {
629 DEV_PTR(tcss_usb3_port1),
630 DEV_PTR(tcss_usb3_port2),
631 DEV_PTR(tcss_usb3_port3),
632 DEV_PTR(tcss_usb3_port4),
633 };
634
635 s_cfg->TcssAuxOri = config->tcss_aux_ori;
636
637 /* Explicitly clear this field to avoid using defaults */
638 memset(s_cfg->IomTypeCPortPadCfg, 0, sizeof(s_cfg->IomTypeCPortPadCfg));
639
640 /*
641 * Set FSPS UPD ITbtConnectTopologyTimeoutInMs with value 0. FSP will
642 * evaluate this UPD value and skip sending command. There will be no
643 * delay for command completion.
644 */
645 s_cfg->ITbtConnectTopologyTimeoutInMs = 0;
646
647 /* D3Hot and D3Cold for TCSS */
648 s_cfg->D3HotEnable = !config->tcss_d3_hot_disable;
649 s_cfg->D3ColdEnable = CONFIG(D3COLD_SUPPORT);
650
651 s_cfg->UsbTcPortEn = 0;
652 for (int i = 0; i < MAX_TYPE_C_PORTS; i++) {
653 if (is_dev_enabled(tcss_port_arr[i]))
654 s_cfg->UsbTcPortEn |= BIT(i);
655 }
656
657 for (int i = 0; i < MAX_TYPE_C_PORTS; i++) {
658 if (config->enabletcsscovtypea[i]) {
659 s_cfg->EnableTcssCovTypeA[i] = config->enabletcsscovtypea[i];
660 s_cfg->MappingPchXhciUsbA[i] = config->mappingpchxhciusba[i];
661 }
662 }
663
664 s_cfg->Usb4CmMode = CONFIG(SOFTWARE_CONNECTION_MANAGER);
665 }
666
667 static void fill_fsps_chipset_lockdown_params(FSP_S_CONFIG *s_cfg,
668 const struct soc_intel_alderlake_config *config)
669 {
670 /* Chipset Lockdown */
671 const bool lockdown_by_fsp = get_lockdown_config() == CHIPSET_LOCKDOWN_FSP;
672 s_cfg->PchLockDownGlobalSmi = lockdown_by_fsp;
673 s_cfg->PchLockDownBiosInterface = lockdown_by_fsp;
674 s_cfg->PchUnlockGpioPads = !lockdown_by_fsp;
675 s_cfg->RtcMemoryLock = lockdown_by_fsp;
676 s_cfg->SkipPamLock = !lockdown_by_fsp;
677
678 /* coreboot will send EOP before loading payload */
679 s_cfg->EndOfPostMessage = EOP_DISABLE;
680 }
681
682 static void fill_fsps_xhci_params(FSP_S_CONFIG *s_cfg,
683 const struct soc_intel_alderlake_config *config)
684 {
685 int i;
686 /* USB */
687 for (i = 0; i < ARRAY_SIZE(config->usb2_ports); i++) {
688 s_cfg->PortUsb20Enable[i] = config->usb2_ports[i].enable;
689 s_cfg->Usb2PhyPetxiset[i] = config->usb2_ports[i].pre_emp_bias;
690 s_cfg->Usb2PhyTxiset[i] = config->usb2_ports[i].tx_bias;
691 s_cfg->Usb2PhyPredeemp[i] = config->usb2_ports[i].tx_emp_enable;
692 s_cfg->Usb2PhyPehalfbit[i] = config->usb2_ports[i].pre_emp_bit;
693
694 if (config->usb2_ports[i].enable)
695 s_cfg->Usb2OverCurrentPin[i] = config->usb2_ports[i].ocpin;
696 else
697 s_cfg->Usb2OverCurrentPin[i] = OC_SKIP;
698
699 if (config->usb2_ports[i].type_c)
700 s_cfg->PortResetMessageEnable[i] = 1;
701 }
702
703 for (i = 0; i < ARRAY_SIZE(config->usb3_ports); i++) {
704 s_cfg->PortUsb30Enable[i] = config->usb3_ports[i].enable;
705 if (config->usb3_ports[i].enable)
706 s_cfg->Usb3OverCurrentPin[i] = config->usb3_ports[i].ocpin;
707 else
708 s_cfg->Usb3OverCurrentPin[i] = OC_SKIP;
709
710 if (config->usb3_ports[i].tx_de_emp) {
711 s_cfg->Usb3HsioTxDeEmphEnable[i] = 1;
712 s_cfg->Usb3HsioTxDeEmph[i] = config->usb3_ports[i].tx_de_emp;
713 }
714 if (config->usb3_ports[i].tx_downscale_amp) {
715 s_cfg->Usb3HsioTxDownscaleAmpEnable[i] = 1;
716 s_cfg->Usb3HsioTxDownscaleAmp[i] =
717 config->usb3_ports[i].tx_downscale_amp;
718 }
719 if (config->usb3_ports[i].tx_rate2_uniq_tran) {
720 s_cfg->Usb3HsioTxRate2UniqTranEnable[i] = 1;
721 s_cfg->Usb3HsioTxRate2UniqTran[i] =
722 config->usb3_ports[i].tx_rate2_uniq_tran;
723 }
724 if (config->usb3_ports[i].ctrl_adapt_offset_cfg_enable) {
725 s_cfg->PchUsb3HsioCtrlAdaptOffsetCfgEnable[i] = 1;
726 s_cfg->PchUsb3HsioCtrlAdaptOffsetCfg[i] =
727 config->usb3_ports[i].ctrl_adapt_offset_cfg;
728 }
729 if (config->usb3_ports[i].olfps_cfg_pull_up_dwn_res) {
730 s_cfg->PchUsb3HsioOlfpsCfgPullUpDwnResEnable[i] = 1;
731 s_cfg->PchUsb3HsioOlfpsCfgPullUpDwnRes[i] =
732 config->usb3_ports[i].olfps_cfg_pull_up_dwn_res;
733 }
734 if (config->usb3_ports[i].filter_sel_n) {
735 s_cfg->PchUsb3HsioFilterSelNEnable[i] = 1;
736 s_cfg->PchUsb3HsioFilterSelN[i] =
737 config->usb3_ports[i].filter_sel_n;
738 }
739 if (config->usb3_ports[i].filter_sel_p) {
740 s_cfg->PchUsb3HsioFilterSelPEnable[i] = 1;
741 s_cfg->PchUsb3HsioFilterSelP[i] =
742 config->usb3_ports[i].filter_sel_p;
743 }
744 }
745
746 for (i = 0; i < ARRAY_SIZE(config->tcss_ports); i++) {
747 if (config->tcss_ports[i].enable)
748 s_cfg->CpuUsb3OverCurrentPin[i] = config->tcss_ports[i].ocpin;
749 }
750
751 s_cfg->PmcUsb2PhySusPgEnable = !config->usb2_phy_sus_pg_disable;
752 }
753
754 static void fill_fsps_xdci_params(FSP_S_CONFIG *s_cfg,
755 const struct soc_intel_alderlake_config *config)
756 {
757 s_cfg->XdciEnable = xdci_can_enable(PCH_DEVFN_USBOTG);
758 }
759
760 static void fill_fsps_uart_params(FSP_S_CONFIG *s_cfg,
761 const struct soc_intel_alderlake_config *config)
762 {
763 if (CONFIG(FSP_USES_CB_DEBUG_EVENT_HANDLER) && CONFIG(CONSOLE_SERIAL) &&
764 CONFIG(FSP_ENABLE_SERIAL_DEBUG))
765 s_cfg->FspEventHandler = (UINT32)((FSP_EVENT_HANDLER *)
766 fsp_debug_event_handler);
767 /* PCH UART selection for FSP Debug */
768 s_cfg->SerialIoDebugUartNumber = CONFIG_UART_FOR_CONSOLE;
769 ASSERT(ARRAY_SIZE(s_cfg->SerialIoUartAutoFlow) > CONFIG_UART_FOR_CONSOLE);
770 s_cfg->SerialIoUartAutoFlow[CONFIG_UART_FOR_CONSOLE] = 0;
771 }
772
773 static void fill_fsps_sata_params(FSP_S_CONFIG *s_cfg,
774 const struct soc_intel_alderlake_config *config)
775 {
776 /* SATA */
777 s_cfg->SataEnable = is_devfn_enabled(PCH_DEVFN_SATA);
778 if (s_cfg->SataEnable) {
779 s_cfg->SataMode = config->sata_mode;
780 s_cfg->SataSalpSupport = config->sata_salp_support;
781 s_cfg->SataSpeedLimit = config->sata_speed;
782 memcpy(s_cfg->SataPortsEnable, config->sata_ports_enable,
783 sizeof(s_cfg->SataPortsEnable));
784 memcpy(s_cfg->SataPortsDevSlp, config->sata_ports_dev_slp,
785 sizeof(s_cfg->SataPortsDevSlp));
786 }
787
788 /*
789 * Power Optimizer for SATA.
790 * SataPwrOptimizeDisable is default to 0.
791 * Boards not needing the optimizers explicitly disables them by setting
792 * these disable variables to 1 in devicetree overrides.
793 */
794 s_cfg->SataPwrOptEnable = !(config->sata_pwr_optimize_disable);
795 /* Test mode for SATA margining */
796 s_cfg->SataTestMode = CONFIG(ENABLE_SATA_TEST_MODE);
797 /*
798 * Enable DEVSLP Idle Timeout settings DmVal and DitoVal.
799 * SataPortsDmVal is the DITO multiplier. Default is 15.
800 * SataPortsDitoVal is the DEVSLP Idle Timeout (DITO), Default is 625ms.
801 * The default values can be changed from devicetree.
802 */
803 for (size_t i = 0; i < ARRAY_SIZE(config->sata_ports_enable_dito_config); i++) {
804 if (config->sata_ports_enable_dito_config[i]) {
805 s_cfg->SataPortsDmVal[i] = config->sata_ports_dm_val[i];
806 s_cfg->SataPortsDitoVal[i] = config->sata_ports_dito_val[i];
807 }
808 }
809 }
810
811 static void fill_fsps_thermal_params(FSP_S_CONFIG *s_cfg,
812 const struct soc_intel_alderlake_config *config)
813 {
814 /* Enable TCPU for processor thermal control */
815 s_cfg->Device4Enable = is_devfn_enabled(SA_DEVFN_DPTF);
816
817 /* Set TccActivationOffset */
818 s_cfg->TccActivationOffset = config->tcc_offset;
819 }
820
821 static void fill_fsps_gna_params(FSP_S_CONFIG *s_cfg,
822 const struct soc_intel_alderlake_config *config)
823 {
824 s_cfg->GnaEnable = is_devfn_enabled(SA_DEVFN_GNA);
825 }
826
827 static void fill_fsps_lan_params(FSP_S_CONFIG *s_cfg,
828 const struct soc_intel_alderlake_config *config)
829 {
830 /* LAN */
831 s_cfg->PchLanEnable = is_devfn_enabled(PCH_DEVFN_GBE);
832 }
833
834 static void fill_fsps_cnvi_params(FSP_S_CONFIG *s_cfg,
835 const struct soc_intel_alderlake_config *config)
836 {
837 struct device *port = NULL;
838 struct drivers_usb_acpi_config *usb_cfg = NULL;
839 bool usb_audio_offload = false;
840
841 /* Search through the devicetree for matching USB devices */
842 while ((port = dev_find_path(port, DEVICE_PATH_USB)) != NULL) {
843 /* Skip ports that are not enabled or not of USB type */
844 if (!port->enabled || port->path.type != DEVICE_PATH_USB)
845 continue;
846
847 usb_cfg = port->chip_info;
848 if (usb_cfg && usb_cfg->cnvi_bt_audio_offload) {
849 usb_audio_offload = true;
850 break;
851 }
852 }
853
854 /* CNVi */
855 s_cfg->CnviWifiCore = is_devfn_enabled(PCH_DEVFN_CNVI_WIFI);
856 s_cfg->CnviMode = is_devfn_enabled(PCH_DEVFN_CNVI_WIFI);
857 s_cfg->CnviBtCore = config->cnvi_bt_core;
858 s_cfg->CnviBtAudioOffload = config->cnvi_bt_audio_offload;
859
860 if (!s_cfg->CnviBtCore && s_cfg->CnviBtAudioOffload) {
861 printk(BIOS_ERR, "BT offload is enabled without CNVi BT being enabled\n");
862 s_cfg->CnviBtAudioOffload = 0;
863 }
864 if (!s_cfg->CnviMode && s_cfg->CnviBtCore) {
865 printk(BIOS_ERR, "CNVi BT is enabled without CNVi being enabled\n");
866 s_cfg->CnviBtCore = 0;
867 s_cfg->CnviBtAudioOffload = 0;
868 }
869 if (s_cfg->CnviBtAudioOffload && !usb_audio_offload) {
870 printk(BIOS_WARNING, "CNVi BT Audio offload enabled but not in USB driver.\n");
871 }
872 if (!s_cfg->CnviBtAudioOffload && usb_cfg && usb_audio_offload) {
873 printk(BIOS_ERR, "USB BT Audio offload enabled but CNVi BT offload disabled\n");
874 usb_cfg->cnvi_bt_audio_offload = 0;
875 }
876 }
877
878 static void fill_fsps_vmd_params(FSP_S_CONFIG *s_cfg,
879 const struct soc_intel_alderlake_config *config)
880 {
881 /* VMD */
882 s_cfg->VmdEnable = is_devfn_enabled(SA_DEVFN_VMD);
883 }
884
885 static void fill_fsps_thc_params(FSP_S_CONFIG *s_cfg,
886 const struct soc_intel_alderlake_config *config)
887 {
888 /* THC */
889 s_cfg->ThcPort0Assignment = is_devfn_enabled(PCH_DEVFN_THC0) ? THC_0 : THC_NONE;
890 s_cfg->ThcPort1Assignment = is_devfn_enabled(PCH_DEVFN_THC1) ? THC_1 : THC_NONE;
891 }
892
893 static void fill_fsps_tbt_params(FSP_S_CONFIG *s_cfg,
894 const struct soc_intel_alderlake_config *config)
895 {
896 /* USB4/TBT */
897 for (int i = 0; i < ARRAY_SIZE(s_cfg->ITbtPcieRootPortEn); i++)
898 s_cfg->ITbtPcieRootPortEn[i] = is_devfn_enabled(SA_DEVFN_TBT(i));
899 }
900
901 static void fill_fsps_8254_params(FSP_S_CONFIG *s_cfg,
902 const struct soc_intel_alderlake_config *config)
903 {
904 /* Legacy 8254 timer support */
905 bool use_8254 = get_uint_option("legacy_8254_timer", CONFIG(USE_LEGACY_8254_TIMER));
906 s_cfg->Enable8254ClockGating = !use_8254;
907 s_cfg->Enable8254ClockGatingOnS3 = !use_8254;
908 }
909
910 static void fill_fsps_pm_timer_params(FSP_S_CONFIG *s_cfg,
911 const struct soc_intel_alderlake_config *config)
912 {
913 /*
914 * Legacy PM ACPI Timer (and TCO Timer)
915 * This *must* be 1 in any case to keep FSP from
916 * 1) enabling PM ACPI Timer emulation in uCode.
917 * 2) disabling the PM ACPI Timer.
918 * We handle both by ourself!
919 */
920 s_cfg->EnableTcoTimer = 1;
921 }
922
923 static void fill_fsps_storage_params(FSP_S_CONFIG *s_cfg,
924 const struct soc_intel_alderlake_config *config)
925 {
926 #if CONFIG(SOC_INTEL_ALDERLAKE_PCH_N)
927 /* eMMC Configuration */
928 s_cfg->ScsEmmcEnabled = is_devfn_enabled(PCH_DEVFN_EMMC);
929 if (s_cfg->ScsEmmcEnabled)
930 s_cfg->ScsEmmcHs400Enabled = config->emmc_enable_hs400_mode;
931 #endif
932
933 /* UFS Configuration */
934 s_cfg->UfsEnable[0] = 0; /* UFS Controller 0 is fuse disabled */
935 s_cfg->UfsEnable[1] = is_devfn_enabled(PCH_DEVFN_UFS);
936
937 /* Enable Hybrid storage auto detection */
938 s_cfg->HybridStorageMode = config->hybrid_storage_mode;
939 }
940
941 static void fill_fsps_pcie_params(FSP_S_CONFIG *s_cfg,
942 const struct soc_intel_alderlake_config *config)
943 {
944 uint32_t enable_mask = pcie_rp_enable_mask(get_pch_pcie_rp_table());
945 for (int i = 0; i < CONFIG_MAX_PCH_ROOT_PORTS; i++) {
946 if (!(enable_mask & BIT(i)))
947 continue;
948 const struct pcie_rp_config *rp_cfg = &config->pch_pcie_rp[i];
949 s_cfg->PcieRpLtrEnable[i] = !!(rp_cfg->flags & PCIE_RP_LTR);
950 s_cfg->PcieRpAdvancedErrorReporting[i] = !!(rp_cfg->flags & PCIE_RP_AER);
951 s_cfg->PcieRpHotPlug[i] = !!(rp_cfg->flags & PCIE_RP_HOTPLUG)
952 || CONFIG(SOC_INTEL_COMPLIANCE_TEST_MODE);
953 s_cfg->PcieRpClkReqDetect[i] = !!(rp_cfg->flags & PCIE_RP_CLK_REQ_DETECT);
954 /* PcieRpSlotImplemented default to 1 (slot implemented) in FSP; 0: built-in */
955 if (!!(rp_cfg->flags & PCIE_RP_BUILT_IN))
956 s_cfg->PcieRpSlotImplemented[i] = false;
957 s_cfg->PcieRpDetectTimeoutMs[i] = rp_cfg->pcie_rp_detect_timeout_ms;
958 configure_pch_rp_power_management(s_cfg, rp_cfg, i);
959 }
960 s_cfg->PcieComplianceTestMode = CONFIG(SOC_INTEL_COMPLIANCE_TEST_MODE);
961
962 #if CONFIG(FSP_TYPE_IOT)
963 /*
964 * Intel requires that all enabled PCH PCIe ports have a CLK_REQ signal connected.
965 * The CLK_REQ is used to wake the silicon when link entered L1 link-state. L1
966 * link-state is also entered on PCI-PM D3, even with ASPM L1 disabled.
967 * When no CLK_REQ signal is used, for example when it's using a free running
968 * clock the Root port silicon will never wake from L1 link state.
969 * This will trigger a MCE.
970 *
971 * Starting with FSP MR4 the UPD 'PchPcieClockGating' allows to work around
972 * this issue by disabling ClockGating. Disabling ClockGating should be avoided
973 * as the silicon draws more power when it is idle.
974 */
975 for (int i = 0; i < CONFIG_MAX_PCH_ROOT_PORTS; i++) {
976 bool clk_req_missing = false;
977 if (!(enable_mask & BIT(i)))
978 continue;
979 const struct pcie_rp_config *rp_cfg = &config->pch_pcie_rp[i];
980 if (CONFIG(SOC_INTEL_COMPLIANCE_TEST_MODE)) {
981 clk_req_missing = true;
982 } else if (!rp_cfg->flags && rp_cfg->clk_src == 0 && rp_cfg->clk_req == 0) {
983 clk_req_missing = true;
984 } else if (rp_cfg->flags & PCIE_RP_CLK_REQ_UNUSED) {
985 clk_req_missing = true;
986 }
987 if (clk_req_missing) {
988 printk(BIOS_INFO, "PCH PCIe port %d has no CLK_REQ\n", i + 1);
989 printk(BIOS_INFO, "Disabling PCH PCIE ClockGating+PowerGating.\n");
990 s_cfg->PchPcieClockGating = false;
991 s_cfg->PchPciePowerGating = false;
992 break;
993 }
994 }
995 #endif
996 }
997
998 static void fill_fsps_cpu_pcie_params(FSP_S_CONFIG *s_cfg,
999 const struct soc_intel_alderlake_config *config)
1000 {
1001 if (!CONFIG_MAX_CPU_ROOT_PORTS)
1002 return;
1003
1004 const uint32_t enable_mask = pcie_rp_enable_mask(get_cpu_pcie_rp_table());
1005 for (int i = 0; i < CONFIG_MAX_CPU_ROOT_PORTS; i++) {
1006 if (!(enable_mask & BIT(i)))
1007 continue;
1008
1009 const struct pcie_rp_config *rp_cfg = &config->cpu_pcie_rp[i];
1010 s_cfg->CpuPcieRpLtrEnable[i] = !!(rp_cfg->flags & PCIE_RP_LTR);
1011 s_cfg->CpuPcieRpAdvancedErrorReporting[i] = !!(rp_cfg->flags & PCIE_RP_AER);
1012 s_cfg->CpuPcieRpHotPlug[i] = !!(rp_cfg->flags & PCIE_RP_HOTPLUG)
1013 || CONFIG(SOC_INTEL_COMPLIANCE_TEST_MODE);
1014 s_cfg->CpuPcieRpDetectTimeoutMs[i] = rp_cfg->pcie_rp_detect_timeout_ms;
1015 s_cfg->PtmEnabled[i] = 0;
1016
1017 if (!!(rp_cfg->flags & PCIE_RP_BUILT_IN))
1018 s_cfg->CpuPcieRpSlotImplemented[i] = 0;
1019 configure_cpu_rp_power_management(s_cfg, rp_cfg, i);
1020 }
1021 s_cfg->CpuPcieComplianceTestMode = CONFIG(SOC_INTEL_COMPLIANCE_TEST_MODE);
1022 }
1023
1024 static void fill_fsps_misc_power_params(FSP_S_CONFIG *s_cfg,
1025 const struct soc_intel_alderlake_config *config)
1026 {
1027 u32 cpu_id = cpu_get_cpuid();
1028 /* Skip setting D0I3 bit for all HECI devices */
1029 s_cfg->DisableD0I3SettingForHeci = 1;
1030 /*
1031 * Power Optimizer for DMI
1032 * DmiPwrOptimizeDisable is default to 0.
1033 * Boards not needing the optimizers explicitly disables them by setting
1034 * these disable variables to 1 in devicetree overrides.
1035 */
1036 s_cfg->PchPwrOptEnable = !(config->dmi_power_optimize_disable);
1037 s_cfg->PmSupport = 1;
1038 s_cfg->Hwp = 1;
1039 s_cfg->Cx = 1;
1040 s_cfg->PsOnEnable = 1;
1041 s_cfg->PkgCStateLimit = LIMIT_AUTO;
1042
1043 /* Set Energy Efficient Turbo mode */
1044 s_cfg->EnergyEfficientTurbo = config->energy_efficient_turbo;
1045
1046 /* VccIn Aux Imon IccMax. Values are in 1/4 Amp increments and range is 0-512. */
1047 s_cfg->VccInAuxImonIccImax =
1048 get_vccin_aux_imon_iccmax(config) * 4 / MILLIAMPS_TO_AMPS;
1049
1050 /* VrConfig Settings for IA and GT domains */
1051 for (size_t i = 0; i < ARRAY_SIZE(config->domain_vr_config); i++)
1052 fill_vr_domain_config(s_cfg, i, &config->domain_vr_config[i]);
1053
1054 s_cfg->PmcLpmS0ixSubStateEnableMask = get_supported_lpm_mask();
1055
1056 /* Apply minimum assertion width settings */
1057 if (config->pch_slp_s3_min_assertion_width == SLP_S3_ASSERTION_DEFAULT)
1058 s_cfg->PchPmSlpS3MinAssert = SLP_S3_ASSERTION_50_MS;
1059 else
1060 s_cfg->PchPmSlpS3MinAssert = config->pch_slp_s3_min_assertion_width;
1061
1062 if (config->pch_slp_s4_min_assertion_width == SLP_S4_ASSERTION_DEFAULT)
1063 s_cfg->PchPmSlpS4MinAssert = SLP_S4_ASSERTION_1S;
1064 else
1065 s_cfg->PchPmSlpS4MinAssert = config->pch_slp_s4_min_assertion_width;
1066
1067 if (config->pch_slp_sus_min_assertion_width == SLP_SUS_ASSERTION_DEFAULT)
1068 s_cfg->PchPmSlpSusMinAssert = SLP_SUS_ASSERTION_4_S;
1069 else
1070 s_cfg->PchPmSlpSusMinAssert = config->pch_slp_sus_min_assertion_width;
1071
1072 if (config->pch_slp_a_min_assertion_width == SLP_A_ASSERTION_DEFAULT)
1073 s_cfg->PchPmSlpAMinAssert = SLP_A_ASSERTION_2_S;
1074 else
1075 s_cfg->PchPmSlpAMinAssert = config->pch_slp_a_min_assertion_width;
1076
1077 unsigned int power_cycle_duration = config->pch_reset_power_cycle_duration;
1078 if (power_cycle_duration == POWER_CYCLE_DURATION_DEFAULT)
1079 power_cycle_duration = POWER_CYCLE_DURATION_4S;
1080
1081 s_cfg->PchPmPwrCycDur = get_pm_pwr_cyc_dur(s_cfg->PchPmSlpS4MinAssert,
1082 s_cfg->PchPmSlpS3MinAssert,
1083 s_cfg->PchPmSlpAMinAssert,
1084 power_cycle_duration);
1085
1086 /* Set PsysPmax if it is available from DT */
1087 if (config->platform_pmax) {
1088 printk(BIOS_DEBUG, "PsysPmax = %dW\n", config->platform_pmax);
1089 /* PsysPmax is in unit of 1/8 Watt */
1090 s_cfg->PsysPmax = config->platform_pmax * 8;
1091 }
1092
1093 s_cfg->C1StateAutoDemotion = !config->disable_c1_state_auto_demotion;
1094
1095 s_cfg->VrPowerDeliveryDesign = config->vr_power_delivery_design;
1096
1097 /* C state demotion must be disabled for Raptorlake J0 and Q0 SKUs */
1098 assert(!(config->s0ix_enable && ((cpu_id == CPUID_RAPTORLAKE_J0) ||
1099 (cpu_id == CPUID_RAPTORLAKE_Q0)) &&
1100 !config->disable_package_c_state_demotion));
1101
1102 s_cfg->PkgCStateDemotion = !config->disable_package_c_state_demotion;
1103
1104 if (cpu_id == CPUID_RAPTORLAKE_J0 || cpu_id == CPUID_RAPTORLAKE_Q0)
1105 s_cfg->C1e = config->enable_c1e;
1106 else
1107 s_cfg->C1e = 1;
1108 #if CONFIG(SOC_INTEL_RAPTORLAKE) && !CONFIG(FSP_USE_REPO)
1109 s_cfg->EnableHwpScalabilityTracking = config->enable_hwp_scalability_tracking;
1110 #endif
1111 }
1112
1113 static void fill_fsps_irq_params(FSP_S_CONFIG *s_cfg,
1114 const struct soc_intel_alderlake_config *config)
1115 {
1116 const struct slot_irq_constraints *constraints;
1117 size_t num_slots;
1118
1119 if (CONFIG(SOC_INTEL_ALDERLAKE_PCH_S)) {
1120 constraints = irq_constraints_pch_s;
1121 num_slots = ARRAY_SIZE(irq_constraints_pch_s);
1122 } else {
1123 constraints = irq_constraints;
1124 num_slots = ARRAY_SIZE(irq_constraints);
1125 }
1126
1127 if (!assign_pci_irqs(constraints, num_slots))
1128 die("ERROR: Unable to assign PCI IRQs, and no _PRT table available\n");
1129
1130 size_t pch_count = 0;
1131 const SI_PCH_DEVICE_INTERRUPT_CONFIG *upd_irqs = pci_irq_to_fsp(&pch_count);
1132
1133 s_cfg->DevIntConfigPtr = (UINT32)((uintptr_t)upd_irqs);
1134 s_cfg->NumOfDevIntConfig = pch_count;
1135 printk(BIOS_INFO, "IRQ: Using dynamically assigned PCI IO-APIC IRQs\n");
1136 }
1137
1138 static void fill_fsps_fivr_params(FSP_S_CONFIG *s_cfg,
1139 const struct soc_intel_alderlake_config *config)
1140 {
1141 #if CONFIG(SOC_INTEL_ALDERLAKE_PCH_N)
1142 /* Enable the FIVR VCCST ICCMax Control for ADL-N.
1143 * TODO:Right now the UPD is update in partial headers for only ADL-N and when its
1144 * updated for ADL-P then we will remove the config since this needs to be enabled for
1145 * all the Alderlake platforms.
1146 */
1147 s_cfg->PchFivrVccstIccMaxControl = 1;
1148 #endif
1149
1150 /* PCH FIVR settings override */
1151 if (!config->ext_fivr_settings.configure_ext_fivr)
1152 return;
1153
1154 s_cfg->PchFivrExtV1p05RailEnabledStates =
1155 config->ext_fivr_settings.v1p05_enable_bitmap;
1156
1157 s_cfg->PchFivrExtV1p05RailSupportedVoltageStates =
1158 config->ext_fivr_settings.v1p05_supported_voltage_bitmap;
1159
1160 s_cfg->PchFivrExtVnnRailEnabledStates =
1161 config->ext_fivr_settings.vnn_enable_bitmap;
1162
1163 s_cfg->PchFivrExtVnnRailSupportedVoltageStates =
1164 config->ext_fivr_settings.vnn_supported_voltage_bitmap;
1165
1166 s_cfg->PchFivrExtVnnRailSxEnabledStates =
1167 config->ext_fivr_settings.vnn_sx_enable_bitmap;
1168
1169 /* Convert the voltages to increments of 2.5mv */
1170 s_cfg->PchFivrExtV1p05RailVoltage =
1171 (config->ext_fivr_settings.v1p05_voltage_mv * 10) / 25;
1172
1173 s_cfg->PchFivrExtVnnRailVoltage =
1174 (config->ext_fivr_settings.vnn_voltage_mv * 10) / 25;
1175
1176 s_cfg->PchFivrExtVnnRailSxVoltage =
1177 (config->ext_fivr_settings.vnn_sx_voltage_mv * 10 / 25);
1178
1179 s_cfg->PchFivrExtV1p05RailIccMaximum =
1180 config->ext_fivr_settings.v1p05_icc_max_ma;
1181
1182 s_cfg->PchFivrExtVnnRailIccMaximum =
1183 config->ext_fivr_settings.vnn_icc_max_ma;
1184 }
1185
1186 static void fill_fsps_fivr_rfi_params(FSP_S_CONFIG *s_cfg,
1187 const struct soc_intel_alderlake_config *config)
1188 {
1189 /* transform from Hz to 100 KHz */
1190 s_cfg->FivrRfiFrequency = config->fivr_rfi_frequency / (100 * KHz);
1191 s_cfg->FivrSpreadSpectrum = config->fivr_spread_spectrum;
1192 }
1193
1194 static void fill_fsps_acoustic_params(FSP_S_CONFIG *s_cfg,
1195 const struct soc_intel_alderlake_config *config)
1196 {
1197 s_cfg->AcousticNoiseMitigation = config->acoustic_noise_mitigation;
1198
1199 if (s_cfg->AcousticNoiseMitigation) {
1200 s_cfg->PreWake = config->PreWake;
1201 for (int i = 0; i < NUM_VR_DOMAINS; i++) {
1202 s_cfg->FastPkgCRampDisable[i] = config->fast_pkg_c_ramp_disable[i];
1203 s_cfg->SlowSlewRate[i] = config->slow_slew_rate[i];
1204 }
1205 }
1206 }
1207
1208 static void fill_fsps_pci_ssid_params(FSP_S_CONFIG *s_cfg,
1209 const struct soc_intel_alderlake_config *config)
1210 {
1211 struct device *dev;
1212 int i;
1213 /*
1214 * Prevent FSP from programming write-once subsystem IDs by providing
1215 * a custom SSID table. Must have at least one entry for the FSP to
1216 * use the table.
1217 */
1218 struct svid_ssid_init_entry {
1219 union {
1220 struct {
1221 uint64_t reg:12; /* Register offset */
1222 uint64_t function:3;
1223 uint64_t device:5;
1224 uint64_t bus:8;
1225 uint64_t :4;
1226 uint64_t segment:16;
1227 uint64_t :16;
1228 };
1229 uint64_t segbusdevfuncregister;
1230 };
1231 struct {
1232 uint16_t svid;
1233 uint16_t ssid;
1234 };
1235 uint32_t reserved;
1236 };
1237
1238 /*
1239 * The xHCI and HDA devices have RW/L rather than RW/O registers for
1240 * subsystem IDs and so must be written before FspSiliconInit locks
1241 * them with their default values.
1242 */
1243 const pci_devfn_t devfn_table[] = { PCH_DEVFN_XHCI, PCH_DEVFN_HDA };
1244 static struct svid_ssid_init_entry ssid_table[ARRAY_SIZE(devfn_table)];
1245
1246 for (i = 0; i < ARRAY_SIZE(devfn_table); i++) {
1247 ssid_table[i].reg = PCI_SUBSYSTEM_VENDOR_ID;
1248 ssid_table[i].device = PCI_SLOT(devfn_table[i]);
1249 ssid_table[i].function = PCI_FUNC(devfn_table[i]);
1250 dev = pcidev_path_on_root(devfn_table[i]);
1251 if (dev) {
1252 ssid_table[i].svid = dev->subsystem_vendor;
1253 ssid_table[i].ssid = dev->subsystem_device;
1254 }
1255 }
1256
1257 s_cfg->SiSsidTablePtr = (uintptr_t)ssid_table;
1258 s_cfg->SiNumberOfSsidTableEntry = ARRAY_SIZE(ssid_table);
1259
1260 /*
1261 * Replace the default SVID:SSID value with the values specified in
1262 * the devicetree for the root device.
1263 */
1264 dev = pcidev_path_on_root(SA_DEVFN_ROOT);
1265 s_cfg->SiCustomizedSvid = dev->subsystem_vendor;
1266 s_cfg->SiCustomizedSsid = dev->subsystem_device;
1267
1268 /* Ensure FSP will program the registers */
1269 s_cfg->SiSkipSsidProgramming = 0;
1270 }
1271
1272 static void soc_silicon_init_params(FSP_S_CONFIG *s_cfg,
1273 struct soc_intel_alderlake_config *config)
1274 {
1275 /* Override settings per board if required. */
1276 mainboard_update_soc_chip_config(config);
1277
1278 /* Runtime configuration of S0ix */
1279 config->s0ix_enable = get_uint_option("s0ix_enable", config->s0ix_enable);
1280
1281 void (*const fill_fsps_params[])(FSP_S_CONFIG *s_cfg,
1282 const struct soc_intel_alderlake_config *config) = {
1283 fill_fsps_lpss_params,
1284 fill_fsps_cpu_params,
1285 fill_fsps_igd_params,
1286 fill_fsps_tcss_params,
1287 fill_fsps_chipset_lockdown_params,
1288 fill_fsps_xhci_params,
1289 fill_fsps_xdci_params,
1290 fill_fsps_uart_params,
1291 fill_fsps_sata_params,
1292 fill_fsps_thermal_params,
1293 fill_fsps_gna_params,
1294 fill_fsps_lan_params,
1295 fill_fsps_cnvi_params,
1296 fill_fsps_vmd_params,
1297 fill_fsps_thc_params,
1298 fill_fsps_tbt_params,
1299 fill_fsps_8254_params,
1300 fill_fsps_pm_timer_params,
1301 fill_fsps_storage_params,
1302 fill_fsps_pcie_params,
1303 fill_fsps_cpu_pcie_params,
1304 fill_fsps_misc_power_params,
1305 fill_fsps_irq_params,
1306 fill_fsps_fivr_params,
1307 fill_fsps_fivr_rfi_params,
1308 fill_fsps_acoustic_params,
1309 fill_fsps_pci_ssid_params,
1310 };
1311
1312 for (size_t i = 0; i < ARRAY_SIZE(fill_fsps_params); i++)
1313 fill_fsps_params[i](s_cfg, config);
1314 }
1315
1316 /*
1317 * The Alder Lake PEIM graphics driver executed as part of the FSP does not wait
1318 * for the panel power cycle to complete before it initializes communication
1319 * with the display. It can result in AUX channel communication time out and
1320 * PEIM graphics driver failing to bring up graphics.
1321 *
1322 * If we have performed some graphics operations in romstage, it is possible
1323 * that a panel power cycle is still in progress. To prevent any issue with the
1324 * PEIM graphics driver it is preferable to ensure that panel power cycle is
1325 * complete.
1326 *
1327 * BUG:b:264526798
1328 */
1329 static void wait_for_panel_power_cycle_done(const struct soc_intel_alderlake_config *config)
1330 {
1331 const struct i915_gpu_panel_config *panel_cfg;
1332 uint32_t bar0;
1333 void *mmio;
1334
1335 if (!CONFIG(RUN_FSP_GOP))
1336 return;
1337
1338 bar0 = pci_s_read_config32(SA_DEV_IGD, PCI_BASE_ADDRESS_0);
1339 mmio = (void *)(bar0 & ~PCI_BASE_ADDRESS_MEM_ATTR_MASK);
1340 if (!mmio)
1341 return;
1342
1343 panel_cfg = &config->panel_cfg;
1344 for (size_t i = 0;; i++) {
1345 uint32_t status = read32(mmio + PCH_PP_STATUS);
1346 if (!(status & PANEL_POWER_CYCLE_ACTIVE))
1347 break;
1348 if (i == panel_cfg->cycle_delay_ms) {
1349 printk(BIOS_ERR, "Panel power cycle is still active.\n");
1350 break;
1351 }
1352 mdelay(1);
1353 }
1354 }
1355
1356 /* UPD parameters to be initialized before SiliconInit */
1357 void platform_fsp_silicon_init_params_cb(FSPS_UPD *supd)
1358 {
1359 struct soc_intel_alderlake_config *config;
1360 FSP_S_CONFIG *s_cfg = &supd->FspsConfig;
1361
1362 config = config_of_soc();
1363 soc_silicon_init_params(s_cfg, config);
1364 mainboard_silicon_init_params(s_cfg);
1365
1366 wait_for_panel_power_cycle_done(config);
1367 }
1368
1369 /*
1370 * Callbacks for SoC/Mainboard specific overrides for FspMultiPhaseSiInit
1371 * This platform supports below MultiPhaseSIInit Phase(s):
1372 * Phase | FSP return point | Purpose
1373 * ------- + ------------------------------------------------ + -------------------------------
1374 * 1 | After TCSS initialization completed | for TCSS specific init
1375 * 2 | Before BIOS Reset CPL is set by FSP-S | for CPU specific init
1376 */
1377 void platform_fsp_silicon_multi_phase_init_cb(uint32_t phase_index)
1378 {
1379 switch (phase_index) {
1380 case 1:
1381 /* TCSS specific initialization here */
1382 printk(BIOS_DEBUG, "FSP MultiPhaseSiInit %s/%s called\n",
1383 __FILE__, __func__);
1384
1385 if (CONFIG(SOC_INTEL_COMMON_BLOCK_TCSS)) {
1386 const config_t *config = config_of_soc();
1387 tcss_configure(config->typec_aux_bias_pads);
1388 }
1389 break;
1390 case 2:
1391 /* CPU specific initialization here */
1392 printk(BIOS_DEBUG, "FSP MultiPhaseSiInit %s/%s called\n",
1393 __FILE__, __func__);
1394 before_post_cpus_init();
1395 /* Enable BIOS Reset CPL */
1396 enable_bios_reset_cpl();
1397 break;
1398 default:
1399 break;
1400 }
1401 }
1402
1403 /* Mainboard GPIO Configuration */
1404 __weak void mainboard_silicon_init_params(FSP_S_CONFIG *s_cfg)
1405 {
1406 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
1407 }
1408
1409 /* Handle FSP logo params */
1410 void soc_load_logo_by_fsp(FSPS_UPD *supd)
1411 {
1412 struct soc_intel_common_config *config = chip_get_common_soc_structure();
1413 FSP_S_CONFIG *s_cfg = &supd->FspsConfig;
1414
1415 /*
1416 * Adjusts panel orientation for external display when the lid is closed.
1417 *
1418 * When the lid is closed (LidStatus == 0), indicating the onboard display is inactive,
1419 * this function forces the panel orientation to normal. This ensures proper display
1420 * on an external monitor, as rotated orientations are typically not suitable in
1421 * such state.
1422 */
1423 if (s_cfg->LidStatus == 0)
1424 config->panel_orientation = LB_FB_ORIENTATION_NORMAL;
1425
1426 fsp_load_and_convert_bmp_to_gop_blt(&supd->FspsConfig.LogoPtr,
1427 &supd->FspsConfig.LogoSize,
1428 &supd->FspsConfig.BltBufferAddress,
1429 &supd->FspsConfig.BltBufferSize,
1430 &supd->FspsConfig.LogoPixelHeight,
1431 &supd->FspsConfig.LogoPixelWidth,
1432 config->panel_orientation);
1433 }