Debian Codegraph @

src/soc/intel/apollolake/chip.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 #include <acpi/acpi.h>
4 #include <bootsplash.h>
5 #include <bootstate.h>
6 #include <console/console.h>
7 #include <cpu/x86/mp.h>
8 #include <device/mmio.h>
9 #include <device/device.h>
10 #include <device/pci.h>
11 #include <device/pci_ops.h>
12 #include <intelblocks/acpi.h>
13 #include <intelblocks/cfg.h>
14 #include <intelblocks/fast_spi.h>
15 #include <intelblocks/msr.h>
16 #include <intelblocks/p2sb.h>
17 #include <intelblocks/power_limit.h>
18 #include <intelblocks/xdci.h>
19 #include <fsp/api.h>
20 #include <fsp/util.h>
21 #include <gpio.h>
22 #include <intelblocks/cpulib.h>
23 #include <intelblocks/itss.h>
24 #include <intelblocks/pmclib.h>
25 #include <intelblocks/systemagent.h>
26 #include <option.h>
27 #include <soc/ahci.h>
28 #include <soc/cpu.h>
29 #include <soc/heci.h>
30 #include <soc/intel/common/vbt.h>
31 #include <soc/iomap.h>
32 #include <soc/itss.h>
33 #include <soc/msr.h>
34 #include <soc/pci_devs.h>
35 #include <soc/pm.h>
36 #include <soc/systemagent.h>
37 #include <spi-generic.h>
38 #include <static.h>
39 #include <timer.h>
40 #include <soc/ramstage.h>
41 #include <soc/soc_chip.h>
42 #include <types.h>
43
44 #include "chip.h"
45
46 #define DUAL_ROLE_CFG0 0x80d8
47 #define SW_VBUS_VALID_MASK (1 << 24)
48 #define SW_IDPIN_EN_MASK (1 << 21)
49 #define SW_IDPIN_MASK (1 << 20)
50 #define SW_IDPIN_HOST (0 << 20)
51 #define DUAL_ROLE_CFG1 0x80dc
52 #define DRD_MODE_MASK (1 << 29)
53 #define DRD_MODE_HOST (1 << 29)
54
55 #define CFG_XHCLKGTEN 0x8650
56 /* Naking USB2.0 EPs for Backbone Clock Gating and PLL Shutdown */
57 #define NUEFBCGPS (1 << 28)
58 /* SRAM Power Gate Enable */
59 #define SRAMPGTEN (1 << 27)
60 /* SS Link PLL Shutdown Enable */
61 #define SSLSE (1 << 26)
62 /* USB2 PLL Shutdown Enable */
63 #define USB2PLLSE (1 << 25)
64 /* IOSF Sideband Trunk Clock Gating Enable */
65 #define IOSFSTCGE (1 << 24)
66 /* BIT[23:20] HS Backbone PXP Trunk Clock Gate Enable */
67 #define HSTCGE (1 << 23 | 1 << 22)
68 /* BIT[19:16] SS Backbone PXP Trunk Clock Gate Enable */
69 #define SSTCGE (1 << 19 | 1 << 18 | 1 << 17)
70 /* XHC Ignore_EU3S */
71 #define XHCIGEU3S (1 << 15)
72 /* XHC Frame Timer Clock Shutdown Enable */
73 #define XHCFTCLKSE (1 << 14)
74 /* XHC Backbone PXP Trunk Clock Gate In Presence of ISOCH EP */
75 #define XHCBBTCGIPISO (1 << 13)
76 /* XHC HS Backbone PXP Trunk Clock Gate U2 non RWE */
77 #define XHCHSTCGU2NRWE (1 << 12)
78 /* BIT[11:10] XHC USB2 PLL Shutdown Lx Enable */
79 #define XHCUSB2PLLSDLE (1 << 11 | 1 << 10)
80 /* BIT[9:8] HS Backbone PXP PLL Shutdown Ux Enable */
81 #define HSUXDMIPLLSE (1 << 9)
82 /* BIT[7:5] SS Backbone PXP PLL shutdown Ux Enable */
83 #define SSPLLSUE (1 << 6)
84 /* XHC Backbone Local Clock Gating Enable */
85 #define XHCBLCGE (1 << 4)
86 /* HS Link Trunk Clock Gating Enable */
87 #define HSLTCGE (1 << 3)
88 /* SS Link Trunk Clock Gating Enable */
89 #define SSLTCGE (1 << 2)
90 /* IOSF Backbone Trunk Clock Gating Enable */
91 #define IOSFBTCGE (1 << 1)
92 /* IOSF Gasket Backbone Local Clock Gating Enable */
93 #define IOSFGBLCGE (1 << 0)
94
95 #define CFG_XHCPMCTRL 0x80a4
96 /* BIT[7:4] LFPS periodic sampling for USB3 Ports */
97 #define LFPS_PM_DISABLE_MASK 0xFFFFFF0F
98
99 const char *soc_acpi_name(const struct device *dev)
100 {
101 if (dev->path.type == DEVICE_PATH_DOMAIN)
102 return "PCI0";
103
104 if (dev->path.type == DEVICE_PATH_USB) {
105 switch (dev->path.usb.port_type) {
106 case 0:
107 /* Root Hub */
108 return "RHUB";
109 case 2:
110 /* USB2 ports */
111 switch (dev->path.usb.port_id) {
112 case 0: return "HS01";
113 case 1: return "HS02";
114 case 2: return "HS03";
115 case 3: return "HS04";
116 case 4: return "HS05";
117 case 5: return "HS06";
118 case 6: return "HS07";
119 case 7: return "HS08";
120 case 8:
121 if (CONFIG(SOC_INTEL_GEMINILAKE))
122 return "HS09";
123 }
124 break;
125 case 3:
126 /* USB3 ports */
127 switch (dev->path.usb.port_id) {
128 case 0: return "SS01";
129 case 1: return "SS02";
130 case 2: return "SS03";
131 case 3: return "SS04";
132 case 4: return "SS05";
133 case 5: return "SS06";
134 }
135 break;
136 }
137 return NULL;
138 }
139
140 if (dev->path.type != DEVICE_PATH_PCI)
141 return NULL;
142
143 switch (dev->path.pci.devfn) {
144 /* DSDT: acpi/northbridge.asl */
145 case SA_DEVFN_ROOT:
146 return "MCHC";
147 /* DSDT: acpi/xhci.asl */
148 case PCH_DEVFN_XHCI:
149 return "XHCI";
150 /* DSDT: acpi/pch_hda.asl */
151 case PCH_DEVFN_HDA:
152 return "HDAS";
153 /* DSDT: acpi/lpss.asl */
154 case PCH_DEVFN_UART0:
155 return "URT1";
156 case PCH_DEVFN_UART1:
157 return "URT2";
158 case PCH_DEVFN_UART2:
159 return "URT3";
160 case PCH_DEVFN_UART3:
161 return "URT4";
162 case PCH_DEVFN_SPI0:
163 return "SPI1";
164 case PCH_DEVFN_SPI1:
165 return "SPI2";
166 case PCH_DEVFN_SPI2:
167 return "SPI3";
168 case PCH_DEVFN_PWM:
169 return "PWM";
170 case PCH_DEVFN_I2C0:
171 return "I2C0";
172 case PCH_DEVFN_I2C1:
173 return "I2C1";
174 case PCH_DEVFN_I2C2:
175 return "I2C2";
176 case PCH_DEVFN_I2C3:
177 return "I2C3";
178 case PCH_DEVFN_I2C4:
179 return "I2C4";
180 case PCH_DEVFN_I2C5:
181 return "I2C5";
182 case PCH_DEVFN_I2C6:
183 return "I2C6";
184 case PCH_DEVFN_I2C7:
185 return "I2C7";
186 /* Storage */
187 case PCH_DEVFN_SDCARD:
188 return "SDCD";
189 case PCH_DEVFN_EMMC:
190 return "EMMC";
191 case PCH_DEVFN_SDIO:
192 return "SDIO";
193 /* PCIe */
194 case PCH_DEVFN_PCIE1:
195 return "RP03";
196 case PCH_DEVFN_PCIE5:
197 return "RP01";
198 }
199
200 return NULL;
201 }
202
203 static struct device_operations pci_domain_ops = {
204 .read_resources = pci_domain_read_resources,
205 .set_resources = pci_domain_set_resources,
206 .scan_bus = pci_host_bridge_scan_bus,
207 .acpi_name = &soc_acpi_name,
208 .acpi_fill_ssdt = ssdt_set_above_4g_pci,
209 };
210
211 struct device_operations apl_cpu_bus_ops = {
212 .read_resources = noop_read_resources,
213 .set_resources = noop_set_resources,
214 .init = mp_cpu_bus_init,
215 .acpi_fill_ssdt = generate_cpu_entries,
216 };
217
218 struct device_operations glk_cpu_bus_ops = {
219 .read_resources = noop_read_resources,
220 .set_resources = noop_set_resources,
221 .acpi_fill_ssdt = generate_cpu_entries,
222 };
223
224 static void enable_dev(struct device *dev)
225 {
226 /* Set the operations if it is a special bus type */
227 if (dev->path.type == DEVICE_PATH_DOMAIN)
228 dev->ops = &pci_domain_ops;
229 else if (dev->path.type == DEVICE_PATH_GPIO)
230 block_gpio_enable(dev);
231 }
232
233 /*
234 * If the PCIe root port at function 0 is disabled,
235 * the PCIe root ports might be coalesced after FSP silicon init.
236 * The below function will swap the devfn of the first enabled device
237 * in devicetree and function 0 resides a pci device
238 * so that it won't confuse coreboot.
239 */
240 static void pcie_update_device_tree(unsigned int devfn0, int num_funcs)
241 {
242 struct device *func0;
243 unsigned int devfn;
244 int i;
245 unsigned int inc = PCI_DEVFN(0, 1);
246
247 func0 = pcidev_path_on_root(devfn0);
248 if (func0 == NULL)
249 return;
250
251 /* No more functions if function 0 is disabled. */
252 if (pci_read_config32(func0, PCI_VENDOR_ID) == 0xffffffff)
253 return;
254
255 devfn = devfn0 + inc;
256
257 /*
258 * Increase function by 1.
259 * Then find first enabled device to replace func0
260 * as that port was move to func0.
261 */
262 for (i = 1; i < num_funcs; i++, devfn += inc) {
263 struct device *dev = pcidev_path_on_root(devfn);
264 if (dev == NULL)
265 continue;
266
267 if (!dev->enabled)
268 continue;
269 /* Found the first enabled device in given dev number */
270 func0->path.pci.devfn = dev->path.pci.devfn;
271 dev->path.pci.devfn = devfn0;
272 break;
273 }
274 }
275
276 static void pcie_override_devicetree_after_silicon_init(void)
277 {
278 pcie_update_device_tree(PCH_DEVFN_PCIE1, 4);
279 pcie_update_device_tree(PCH_DEVFN_PCIE5, 2);
280 }
281
282 /* Overwrites the SCI IRQ if another IRQ number is given by device tree. */
283 static void set_sci_irq(void)
284 {
285 struct soc_intel_apollolake_config *cfg;
286 uint32_t scis;
287
288 cfg = config_of_soc();
289
290 /* Change only if a device tree entry exists. */
291 if (cfg->sci_irq) {
292 scis = soc_read_sci_irq_select();
293 scis &= ~SCI_IRQ_SEL;
294 scis |= (cfg->sci_irq << SCI_IRQ_ADJUST) & SCI_IRQ_SEL;
295 soc_write_sci_irq_select(scis);
296 }
297 }
298
299 static void soc_init(void *data)
300 {
301 struct soc_power_limits_config *soc_config;
302 config_t *config;
303
304 /* Snapshot the current GPIO IRQ polarities. FSP is setting a
305 * default policy that doesn't honor boards' requirements. */
306 itss_snapshot_irq_polarities(GPIO_IRQ_START, GPIO_IRQ_END);
307
308 /*
309 * Clear the GPI interrupt status and enable registers. These
310 * registers do not get reset to default state when booting from S5.
311 */
312 gpi_clear_int_cfg();
313
314 fsp_silicon_init();
315
316 /* Restore GPIO IRQ polarities back to previous settings. */
317 itss_restore_irq_polarities(GPIO_IRQ_START, GPIO_IRQ_END);
318
319 /* override 'enabled' setting in device tree if needed */
320 pcie_override_devicetree_after_silicon_init();
321
322 /*
323 * Keep the P2SB device visible so it and the other devices are
324 * visible in coreboot for driver support and PCI resource allocation.
325 * There is a UPD setting for this, but it's more consistent to use
326 * hide and unhide symmetrically.
327 */
328 p2sb_unhide();
329
330 config = config_of_soc();
331 /* Set RAPL MSR for Package power limits */
332 soc_config = &config->power_limits_config;
333 set_power_limits(MOBILE_SKU_PL1_TIME_SEC, soc_config);
334
335 /*
336 * FSP-S routes SCI to IRQ 9. With the help of this function you can
337 * select another IRQ for SCI.
338 */
339 set_sci_irq();
340 }
341
342 static void soc_final(void *data)
343 {
344 /* Make sure payload/OS can't trigger global reset */
345 pmc_global_reset_disable_and_lock();
346 }
347
348 static void disable_dev(struct device *dev, FSP_S_CONFIG *silconfig)
349 {
350 switch (dev->path.pci.devfn) {
351 case PCH_DEVFN_NPK:
352 /*
353 * Disable this device in the parse_devicetree_setting() function
354 * in romstage.c
355 */
356 break;
357 case PCH_DEVFN_ISH:
358 silconfig->IshEnable = 0;
359 break;
360 case PCH_DEVFN_SATA:
361 silconfig->EnableSata = 0;
362 break;
363 case PCH_DEVFN_PCIE5:
364 silconfig->PcieRootPortEn[0] = 0;
365 silconfig->PcieRpHotPlug[0] = 0;
366 break;
367 case PCH_DEVFN_PCIE6:
368 silconfig->PcieRootPortEn[1] = 0;
369 silconfig->PcieRpHotPlug[1] = 0;
370 break;
371 case PCH_DEVFN_PCIE1:
372 silconfig->PcieRootPortEn[2] = 0;
373 silconfig->PcieRpHotPlug[2] = 0;
374 break;
375 case PCH_DEVFN_PCIE2:
376 silconfig->PcieRootPortEn[3] = 0;
377 silconfig->PcieRpHotPlug[3] = 0;
378 break;
379 case PCH_DEVFN_PCIE3:
380 silconfig->PcieRootPortEn[4] = 0;
381 silconfig->PcieRpHotPlug[4] = 0;
382 break;
383 case PCH_DEVFN_PCIE4:
384 silconfig->PcieRootPortEn[5] = 0;
385 silconfig->PcieRpHotPlug[5] = 0;
386 break;
387 case PCH_DEVFN_XHCI:
388 silconfig->Usb30Mode = 0;
389 break;
390 case PCH_DEVFN_XDCI:
391 silconfig->UsbOtg = 0;
392 break;
393 case PCH_DEVFN_I2C0:
394 silconfig->I2c0Enable = 0;
395 break;
396 case PCH_DEVFN_I2C1:
397 silconfig->I2c1Enable = 0;
398 break;
399 case PCH_DEVFN_I2C2:
400 silconfig->I2c2Enable = 0;
401 break;
402 case PCH_DEVFN_I2C3:
403 silconfig->I2c3Enable = 0;
404 break;
405 case PCH_DEVFN_I2C4:
406 silconfig->I2c4Enable = 0;
407 break;
408 case PCH_DEVFN_I2C5:
409 silconfig->I2c5Enable = 0;
410 break;
411 case PCH_DEVFN_I2C6:
412 silconfig->I2c6Enable = 0;
413 break;
414 case PCH_DEVFN_I2C7:
415 silconfig->I2c7Enable = 0;
416 break;
417 case PCH_DEVFN_UART0:
418 silconfig->Hsuart0Enable = 0;
419 break;
420 case PCH_DEVFN_UART1:
421 silconfig->Hsuart1Enable = 0;
422 break;
423 case PCH_DEVFN_UART2:
424 silconfig->Hsuart2Enable = 0;
425 break;
426 case PCH_DEVFN_UART3:
427 silconfig->Hsuart3Enable = 0;
428 break;
429 case PCH_DEVFN_SPI0:
430 silconfig->Spi0Enable = 0;
431 break;
432 case PCH_DEVFN_SPI1:
433 silconfig->Spi1Enable = 0;
434 break;
435 case PCH_DEVFN_SPI2:
436 silconfig->Spi2Enable = 0;
437 break;
438 case PCH_DEVFN_SDCARD:
439 silconfig->SdcardEnabled = 0;
440 break;
441 case PCH_DEVFN_EMMC:
442 silconfig->eMMCEnabled = 0;
443 break;
444 case PCH_DEVFN_SDIO:
445 silconfig->SdioEnabled = 0;
446 break;
447 case PCH_DEVFN_SMBUS:
448 silconfig->SmbusEnable = 0;
449 break;
450 #if !CONFIG(SOC_INTEL_GEMINILAKE)
451 case SA_DEVFN_IPU:
452 silconfig->IpuEn = 0;
453 break;
454 #else
455 case PCH_DEVFN_CNVI:
456 silconfig->CnviMode = 0;
457 break;
458 case PCH_DEVFN_UFS:
459 silconfig->UfsEnabled = 0;
460 break;
461 #endif
462 case PCH_DEVFN_HDA:
463 silconfig->HdaEnable = 0;
464 break;
465 default:
466 printk(BIOS_WARNING, "PCI:%02x.%01x: Could not disable the device\n",
467 PCI_SLOT(dev->path.pci.devfn),
468 PCI_FUNC(dev->path.pci.devfn));
469 break;
470 }
471 }
472
473 static void parse_devicetree(FSP_S_CONFIG *silconfig)
474 {
475 struct device *dev = pcidev_path_on_root(SA_DEVFN_ROOT);
476
477 if (!dev) {
478 printk(BIOS_ERR, "Could not find root device\n");
479 return;
480 }
481 /* Only disable bus 0 devices. */
482 for (dev = dev->upstream->children; dev; dev = dev->sibling) {
483 if (!dev->enabled)
484 disable_dev(dev, silconfig);
485 }
486 }
487
488 static void apl_fsp_silicon_init_params_cb(struct soc_intel_apollolake_config
489 *cfg, FSP_S_CONFIG *silconfig)
490 {
491 #if !CONFIG(SOC_INTEL_GEMINILAKE) /* GLK FSP does not have these fields in FspsUpd.h yet */
492 uint8_t port;
493
494 for (port = 0; port < APOLLOLAKE_USB2_PORT_MAX; port++) {
495 if (cfg->usb_config_override) {
496 if (!cfg->usb2_port[port].enable)
497 continue;
498
499 silconfig->PortUsb20Enable[port] = 1;
500 silconfig->PortUs20bOverCurrentPin[port] = cfg->usb2_port[port].oc_pin;
501 }
502
503 if (cfg->usb2eye[port].Usb20PerPortTxPeHalf != 0)
504 silconfig->PortUsb20PerPortTxPeHalf[port] =
505 cfg->usb2eye[port].Usb20PerPortTxPeHalf;
506
507 if (cfg->usb2eye[port].Usb20PerPortPeTxiSet != 0)
508 silconfig->PortUsb20PerPortPeTxiSet[port] =
509 cfg->usb2eye[port].Usb20PerPortPeTxiSet;
510
511 if (cfg->usb2eye[port].Usb20PerPortTxiSet != 0)
512 silconfig->PortUsb20PerPortTxiSet[port] =
513 cfg->usb2eye[port].Usb20PerPortTxiSet;
514
515 if (cfg->usb2eye[port].Usb20HsSkewSel != 0)
516 silconfig->PortUsb20HsSkewSel[port] =
517 cfg->usb2eye[port].Usb20HsSkewSel;
518
519 if (cfg->usb2eye[port].Usb20IUsbTxEmphasisEn != 0)
520 silconfig->PortUsb20IUsbTxEmphasisEn[port] =
521 cfg->usb2eye[port].Usb20IUsbTxEmphasisEn;
522
523 if (cfg->usb2eye[port].Usb20PerPortRXISet != 0)
524 silconfig->PortUsb20PerPortRXISet[port] =
525 cfg->usb2eye[port].Usb20PerPortRXISet;
526
527 if (cfg->usb2eye[port].Usb20HsNpreDrvSel != 0)
528 silconfig->PortUsb20HsNpreDrvSel[port] =
529 cfg->usb2eye[port].Usb20HsNpreDrvSel;
530 }
531
532 if (cfg->usb_config_override) {
533 for (port = 0; port < APOLLOLAKE_USB3_PORT_MAX; port++) {
534 if (!cfg->usb3_port[port].enable)
535 continue;
536
537 silconfig->PortUsb30Enable[port] = 1;
538 silconfig->PortUs30bOverCurrentPin[port] = cfg->usb3_port[port].oc_pin;
539 }
540 }
541 #endif
542 }
543
544 static void glk_fsp_silicon_init_params_cb(
545 struct soc_intel_apollolake_config *cfg, FSP_S_CONFIG *silconfig)
546 {
547 #if CONFIG(SOC_INTEL_GEMINILAKE)
548 uint8_t port;
549
550 /*
551 * UsbPerPortCtl was retired in Fsp 2.0.0+, so PDO programming must be
552 * enabled to configure individual ports in what Fsp thinks is PEI.
553 */
554 silconfig->UsbPdoProgramming = cfg->usb_config_override;
555
556 for (port = 0; port < APOLLOLAKE_USB2_PORT_MAX; port++) {
557 if (cfg->usb_config_override) {
558 silconfig->PortUsb20Enable[port] = cfg->usb2_port[port].enable;
559 silconfig->PortUs20bOverCurrentPin[port] = cfg->usb2_port[port].oc_pin;
560 }
561
562 if (!cfg->usb2eye[port].Usb20OverrideEn)
563 continue;
564
565 silconfig->Usb2AfePehalfbit[port] =
566 cfg->usb2eye[port].Usb20PerPortTxPeHalf;
567 silconfig->Usb2AfePetxiset[port] =
568 cfg->usb2eye[port].Usb20PerPortPeTxiSet;
569 silconfig->Usb2AfeTxiset[port] =
570 cfg->usb2eye[port].Usb20PerPortTxiSet;
571 silconfig->Usb2AfePredeemp[port] =
572 cfg->usb2eye[port].Usb20IUsbTxEmphasisEn;
573 }
574
575 if (cfg->usb_config_override) {
576 for (port = 0; port < APOLLOLAKE_USB3_PORT_MAX; port++) {
577 silconfig->PortUsb30Enable[port] = cfg->usb3_port[port].enable;
578 silconfig->PortUs30bOverCurrentPin[port] = cfg->usb3_port[port].oc_pin;
579 }
580 }
581
582 silconfig->Gmm = is_devfn_enabled(SA_GLK_DEVFN_GMM);
583
584 /* On Geminilake, we need to override the default FSP PCIe de-emphasis
585 * settings using the device tree settings. This is because PCIe
586 * de-emphasis is enabled by default and Thunderpeak PCIe WiFi detection
587 * requires de-emphasis disabled. If we make this change common to both
588 * Apollolake and Geminilake, then we need to add mainboard device tree
589 * de-emphasis settings of 1 to Apollolake systems.
590 */
591 memcpy(silconfig->PcieRpSelectableDeemphasis,
592 cfg->pcie_rp_deemphasis_enable,
593 sizeof(silconfig->PcieRpSelectableDeemphasis));
594 /*
595 * FSP does not know what the clock requirements are for the
596 * device on SPI bus, hence it should not modify what coreboot
597 * has set up. Hence skipping in FSP.
598 */
599 silconfig->SkipSpiPCP = 1;
600
601 /*
602 * FSP provides UPD interface to execute IPC command. In order to
603 * improve boot performance, configure PmicPmcIpcCtrl for PMC to program
604 * PMIC PCH_PWROK delay.
605 */
606 silconfig->PmicPmcIpcCtrl = cfg->pmic_pmc_ipc_ctrl;
607
608 /*
609 * Options to disable XHCI Link Compliance Mode.
610 */
611 silconfig->DisableComplianceMode = cfg->disable_compliance_mode;
612
613 /*
614 * Options to change USB3 ModPhy setting for Integrated Filter value.
615 */
616 silconfig->ModPhyIfValue = cfg->mod_phy_if_value;
617
618 /*
619 * Options to bump USB3 LDO voltage with 40mv.
620 */
621 silconfig->ModPhyVoltageBump = cfg->mod_phy_voltage_bump;
622
623 /*
624 * Options to adjust PMIC Vdd2 voltage.
625 */
626 silconfig->PmicVdd2Voltage = cfg->pmic_vdd2_voltage;
627
628 /* FSP should let coreboot set subsystem IDs, which are read/write-once */
629 silconfig->SiSVID = 0;
630 silconfig->SiSSID = 0;
631 silconfig->HgSubSystemId = 0;
632 #endif
633 }
634
635 void __weak mainboard_devtree_update(struct device *dev)
636 {
637 /* Override dev tree settings per board */
638 }
639
640 void platform_fsp_silicon_init_params_cb(FSPS_UPD *silupd)
641 {
642 FSP_S_CONFIG *silconfig = &silupd->FspsConfig;
643 struct soc_intel_apollolake_config *cfg;
644 struct device *dev;
645
646 /* Load VBT before devicetree-specific config. */
647 silconfig->GraphicsConfigPtr = (uintptr_t)vbt_get();
648
649 dev = pcidev_path_on_root(SA_DEVFN_ROOT);
650 cfg = config_of(dev);
651
652 mainboard_devtree_update(dev);
653
654 /* Parse device tree and disable unused device*/
655 parse_devicetree(silconfig);
656
657 memcpy(silconfig->PcieRpClkReqNumber, cfg->pcie_rp_clkreq_pin,
658 sizeof(silconfig->PcieRpClkReqNumber));
659
660 memcpy(silconfig->PcieRpHotPlug, cfg->pcie_rp_hotplug_enable,
661 sizeof(silconfig->PcieRpHotPlug));
662
663 switch (cfg->serirq_mode) {
664 case SERIRQ_QUIET:
665 silconfig->SirqEnable = 1;
666 silconfig->SirqMode = 0;
667 break;
668 case SERIRQ_CONTINUOUS:
669 silconfig->SirqEnable = 1;
670 silconfig->SirqMode = 1;
671 break;
672 case SERIRQ_OFF:
673 default:
674 silconfig->SirqEnable = 0;
675 break;
676 }
677
678 if (cfg->emmc_tx_cmd_cntl != 0)
679 silconfig->EmmcTxCmdCntl = cfg->emmc_tx_cmd_cntl;
680 if (cfg->emmc_tx_data_cntl1 != 0)
681 silconfig->EmmcTxDataCntl1 = cfg->emmc_tx_data_cntl1;
682 if (cfg->emmc_tx_data_cntl2 != 0)
683 silconfig->EmmcTxDataCntl2 = cfg->emmc_tx_data_cntl2;
684 if (cfg->emmc_rx_cmd_data_cntl1 != 0)
685 silconfig->EmmcRxCmdDataCntl1 = cfg->emmc_rx_cmd_data_cntl1;
686 if (cfg->emmc_rx_strobe_cntl != 0)
687 silconfig->EmmcRxStrobeCntl = cfg->emmc_rx_strobe_cntl;
688 if (cfg->emmc_rx_cmd_data_cntl2 != 0)
689 silconfig->EmmcRxCmdDataCntl2 = cfg->emmc_rx_cmd_data_cntl2;
690 if (cfg->emmc_host_max_speed != 0)
691 silconfig->eMMCHostMaxSpeed = cfg->emmc_host_max_speed;
692
693 memcpy(silconfig->SataPortsHotPlug, cfg->sata_ports_hot_plug,
694 sizeof(silconfig->SataPortsHotPlug));
695
696 cfg->lpss_s0ix_enable = get_uint_option("s0ix_enable", cfg->lpss_s0ix_enable);
697 silconfig->LPSS_S0ixEnable = cfg->lpss_s0ix_enable;
698
699 /* Disable monitor mwait since it is broken due to a hardware bug
700 * without a fix. Specific to Apollolake.
701 */
702 if (!CONFIG(SOC_INTEL_GEMINILAKE))
703 silconfig->MonitorMwaitEnable = 0;
704
705 silconfig->SkipMpInit = !CONFIG(USE_INTEL_FSP_MP_INIT);
706
707 /* coreboot handles the lockdown */
708 silconfig->LockDownGlobalSmi = 0;
709 silconfig->BiosLock = 0;
710 silconfig->BiosInterface = 0;
711 silconfig->WriteProtectionEnable[0] = 0;
712 silconfig->SpiEiss = 0;
713 silconfig->RtcLock = 0;
714
715 /* Enable Audio clk gate and power gate */
716 silconfig->HDAudioClkGate = cfg->hdaudio_clk_gate_enable;
717 silconfig->HDAudioPwrGate = cfg->hdaudio_pwr_gate_enable;
718 /* BIOS config lockdown Audio clk and power gate */
719 silconfig->BiosCfgLockDown = cfg->hdaudio_bios_config_lockdown;
720 if (CONFIG(SOC_INTEL_GEMINILAKE))
721 glk_fsp_silicon_init_params_cb(cfg, silconfig);
722 else
723 apl_fsp_silicon_init_params_cb(cfg, silconfig);
724
725 silconfig->UsbOtg = xdci_can_enable(PCH_DEVFN_XDCI);
726
727 silconfig->VmxEnable = CONFIG(ENABLE_VMX);
728
729 /* Enable enhanced C-states */
730 silconfig->C1e = cfg->enhanced_cstates;
731
732 /* Set VTD feature according to devicetree */
733 silconfig->VtdEnable = get_uint_option("vtd", cfg->enable_vtd);
734
735 silconfig->PeiGraphicsPeimInit = CONFIG(RUN_FSP_GOP) && is_devfn_enabled(SA_DEVFN_IGD);
736
737 silconfig->PavpEnable = CONFIG(PAVP);
738
739 /* SATA config */
740 if (is_devfn_enabled(PCH_DEVFN_SATA)) {
741 silconfig->SataSalpSupport = !(cfg->disable_sata_salp_support);
742 ahci_set_speed(cfg->sata_speed);
743 memcpy(silconfig->SataPortsEnable, cfg->sata_ports_enable,
744 sizeof(silconfig->SataPortsEnable));
745 memcpy(silconfig->SataPortsSolidStateDrive, cfg->sata_ports_ssd,
746 sizeof(silconfig->SataPortsSolidStateDrive));
747 }
748
749 /* Sata Power Optimisation */
750 silconfig->SataPwrOptEnable = !(cfg->sata_pwr_optimize_disable);
751
752 /* 8254 Timer */
753 bool use_8254 = get_uint_option("legacy_8254_timer", CONFIG(USE_LEGACY_8254_TIMER));
754 silconfig->Timer8254ClkSetting = !use_8254;
755
756 /* FSP should let coreboot set subsystem IDs, which are read/write-once */
757 silconfig->SubSystemVendorId = 0;
758 silconfig->SubSystemId = 0;
759
760 mainboard_silicon_init_params(silconfig);
761 }
762
763 struct chip_operations soc_intel_apollolake_ops = {
764 .name = "Intel Apollolake SOC",
765 .enable_dev = &enable_dev,
766 .init = &soc_init,
767 .final = &soc_final
768 };
769
770 static void soc_enable_untrusted_mode(void *unused)
771 {
772 /*
773 * Set Bit 6 (ENABLE_IA_UNTRUSTED_MODE) of MSR 0x120
774 * UCODE_PCR_POWER_MISC MSR to enter IA Untrusted Mode.
775 */
776 msr_set(MSR_POWER_MISC, ENABLE_IA_UNTRUSTED);
777 }
778
779 static void drop_privilege_all(void)
780 {
781 /* Drop privilege level on all the CPUs */
782 if (mp_run_on_all_cpus(&soc_enable_untrusted_mode, NULL) != CB_SUCCESS)
783 printk(BIOS_ERR, "failed to enable untrusted mode\n");
784 }
785
786 static void configure_xhci_host_mode_port0(void)
787 {
788 uint32_t *cfg0;
789 uint32_t *cfg1;
790 const struct resource *res;
791 uint32_t reg;
792 struct stopwatch sw;
793 struct device *xhci_dev = PCH_DEV_XHCI;
794
795 printk(BIOS_INFO, "Putting xHCI port 0 into host mode.\n");
796 res = find_resource(xhci_dev, PCI_BASE_ADDRESS_0);
797 cfg0 = (void *)(uintptr_t)(res->base + DUAL_ROLE_CFG0);
798 cfg1 = (void *)(uintptr_t)(res->base + DUAL_ROLE_CFG1);
799 reg = read32(cfg0);
800 if (!(reg & SW_IDPIN_EN_MASK))
801 return;
802
803 reg &= ~(SW_IDPIN_MASK | SW_VBUS_VALID_MASK);
804 write32(cfg0, reg);
805
806 stopwatch_init_msecs_expire(&sw, 10);
807 /* Wait for the host mode status bit. */
808 while ((read32(cfg1) & DRD_MODE_MASK) != DRD_MODE_HOST) {
809 if (stopwatch_expired(&sw)) {
810 printk(BIOS_ERR, "Timed out waiting for host mode.\n");
811 return;
812 }
813 }
814
815 printk(BIOS_INFO, "xHCI port 0 host switch over took %lld ms\n",
816 stopwatch_duration_msecs(&sw));
817 }
818
819 static int check_xdci_enable(void)
820 {
821 return is_dev_enabled(pcidev_path_on_root(PCH_DEVFN_XDCI));
822 }
823
824 static void disable_xhci_lfps_pm(void)
825 {
826 struct soc_intel_apollolake_config *cfg;
827
828 cfg = config_of_soc();
829
830 if (cfg->disable_xhci_lfps_pm) {
831 void *addr;
832 const struct resource *res;
833 uint32_t reg;
834 struct device *xhci_dev = PCH_DEV_XHCI;
835
836 res = find_resource(xhci_dev, PCI_BASE_ADDRESS_0);
837 addr = (void *)(uintptr_t)(res->base + CFG_XHCPMCTRL);
838 reg = read32(addr);
839 printk(BIOS_DEBUG, "XHCI PM: control reg=0x%x.\n", reg);
840 if (reg) {
841 reg &= LFPS_PM_DISABLE_MASK;
842 write32(addr, reg);
843 printk(BIOS_INFO, "XHCI PM: Disable xHCI LFPS as configured in devicetree.\n");
844 }
845 }
846 }
847
848 void platform_fsp_notify_status(enum fsp_notify_phase phase)
849 {
850 if (phase == END_OF_FIRMWARE) {
851 /*
852 * Before hiding P2SB device and dropping privilege level,
853 * dump CSE status and disable HECI1 interface.
854 */
855 heci_cse_lockdown();
856
857 /* Hide the P2SB device to align with previous behavior. */
858 p2sb_hide();
859
860 /*
861 * As per guidelines BIOS is recommended to drop CPU privilege
862 * level to IA_UNTRUSTED. After that certain device registers
863 * and MSRs become inaccessible supposedly increasing system
864 * security.
865 */
866 drop_privilege_all();
867
868 /*
869 * When USB OTG is set, GLK FSP enables xHCI SW ID pin and
870 * configures USB-C as device mode. Force USB-C into host mode.
871 */
872 if (check_xdci_enable())
873 configure_xhci_host_mode_port0();
874
875 /*
876 * Override GLK xhci clock gating register(XHCLKGTEN) to
877 * mitigate USB device suspend and resume failure.
878 */
879 if (CONFIG(SOC_INTEL_GEMINILAKE)) {
880 uint32_t *cfg;
881 const struct resource *res;
882 uint32_t reg;
883 struct device *xhci_dev = PCH_DEV_XHCI;
884
885 res = find_resource(xhci_dev, PCI_BASE_ADDRESS_0);
886 cfg = (void *)(uintptr_t)(res->base + CFG_XHCLKGTEN);
887 reg = SRAMPGTEN | SSLSE | USB2PLLSE | IOSFSTCGE |
888 HSTCGE | HSUXDMIPLLSE | SSTCGE | XHCFTCLKSE |
889 XHCBBTCGIPISO | XHCUSB2PLLSDLE | SSPLLSUE |
890 XHCBLCGE | HSLTCGE | SSLTCGE | IOSFBTCGE |
891 IOSFGBLCGE;
892 write32(cfg, reg);
893 }
894
895 /* Disable XHCI LFPS power management if the option in dev tree is set. */
896 disable_xhci_lfps_pm();
897 }
898 }
899
900 /*
901 * spi_flash init() needs to run unconditionally on every boot (including
902 * resume) to allow write protect to be disabled for eventlog and nvram
903 * updates. This needs to be done as early as possible in ramstage. Thus, add a
904 * callback for entry into BS_PRE_DEVICE.
905 */
906 static void spi_flash_init_cb(void *unused)
907 {
908 fast_spi_init();
909 }
910
911 __weak
912 void mainboard_silicon_init_params(FSP_S_CONFIG *silconfig)
913 {
914 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
915 }
916
917 /* Handle FSP logo params */
918 void soc_load_logo_by_fsp(FSPS_UPD *supd)
919 {
920 size_t logo_size;
921 supd->FspsConfig.LogoPtr = (uint32_t)(uintptr_t)bmp_load_logo(&logo_size);
922 supd->FspsConfig.LogoSize = (uint32_t)logo_size;
923 }
924
925 BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_ENTRY, spi_flash_init_cb, NULL);