Debian Codegraph @

src/soc/intel/apollolake/bootblock/bootblock.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 #include <bootblock_common.h>
4 #include <cpu/x86/pae.h>
5 #include <device/pci.h>
6 #include <device/pci_ops.h>
7 #include <gpio.h>
8 #include <intelblocks/cpulib.h>
9 #include <intelblocks/fast_spi.h>
10 #include <intelblocks/lpc_lib.h>
11 #include <intelblocks/p2sb.h>
12 #include <intelblocks/pcr.h>
13 #include <intelblocks/rtc.h>
14 #include <intelblocks/systemagent.h>
15 #include <intelblocks/pmclib.h>
16 #include <intelblocks/tco.h>
17 #include <intelblocks/uart.h>
18 #include <soc/iomap.h>
19 #include <soc/cpu.h>
20 #include <soc/loader.h>
21 #include <soc/gpio.h>
22 #include <soc/measured_boot.h>
23 #include <soc/soc_chip.h>
24 #include <soc/systemagent.h>
25 #include <soc/pci_devs.h>
26 #include <soc/pm.h>
27 #include <spi-generic.h>
28 #include <static.h>
29
30 static const struct pad_config tpm_spi_configs[] = {
31 #if CONFIG(SOC_INTEL_GEMINILAKE)
32 PAD_CFG_NF(GPIO_81, NATIVE, DEEP, NF3), /* FST_SPI_CS2_N */
33 #else
34 PAD_CFG_NF(GPIO_106, NATIVE, DEEP, NF3), /* FST_SPI_CS2_N */
35 #endif
36 };
37
38 static void tpm_enable(void)
39 {
40 /* Configure gpios */
41 gpio_configure_pads(tpm_spi_configs, ARRAY_SIZE(tpm_spi_configs));
42 }
43
44 asmlinkage void bootblock_c_entry(uint64_t base_timestamp)
45 {
46 pci_devfn_t dev;
47 bool ibb_exists;
48 struct boot_policy_manifest bpm_info;
49
50 bootblock_systemagent_early_init();
51
52 p2sb_enable_bar();
53 p2sb_configure_hpet();
54
55 /* Decode the ACPI I/O port range for early firmware verification.*/
56 dev = PCH_DEV_PMC;
57 pci_write_config16(dev, PCI_BASE_ADDRESS_4, ACPI_BASE_ADDRESS);
58 pci_write_config16(dev, PCI_COMMAND,
59 PCI_COMMAND_IO | PCI_COMMAND_MASTER);
60
61 /*
62 * Check the status of the BPM, and measured the IBB and OBB
63 * if required. Returns 1 if IBB exists.
64 */
65 if (CONFIG(IFWI_MEASURED_BOOT))
66 ibb_exists = fetch_pre_rbp_data(&bpm_info);
67
68 enable_rtc_upper_bank();
69
70 if (CONFIG(IFWI_IBBM_LOAD)) {
71 load_ibb(CONFIG_IBBM_ROM_ADDR, CONFIG_IBBM_ROM_SIZE);
72 flush_l1d_to_l2();
73 }
74
75 /*
76 * If the IBB exists, measure it after it has been loaded via
77 * the CSEs RBP.
78 */
79 if (CONFIG(IFWI_MEASURED_BOOT) && ibb_exists)
80 fetch_post_rbp_data(&bpm_info);
81
82 /* Call lib/bootblock.c main */
83 bootblock_main_with_basetime(base_timestamp);
84 }
85
86 static void enable_pmcbar(void)
87 {
88 pci_devfn_t pmc = PCH_DEV_PMC;
89
90 /* Set PMC base addresses and enable decoding. */
91 pci_write_config32(pmc, PCI_BASE_ADDRESS_0, PCH_PWRM_BASE_ADDRESS);
92 pci_write_config32(pmc, PCI_BASE_ADDRESS_1, 0); /* 64-bit BAR */
93 pci_write_config32(pmc, PCI_BASE_ADDRESS_2, PMC_BAR1);
94 pci_write_config32(pmc, PCI_BASE_ADDRESS_3, 0); /* 64-bit BAR */
95 pci_write_config16(pmc, PCI_BASE_ADDRESS_4, ACPI_BASE_ADDRESS);
96 pci_write_config16(pmc, PCI_COMMAND,
97 PCI_COMMAND_IO | PCI_COMMAND_MEMORY |
98 PCI_COMMAND_MASTER);
99 }
100
101 void bootblock_soc_early_init(void)
102 {
103 enable_pmcbar();
104
105 /* Clear global reset promotion bit */
106 pmc_global_reset_enable(0);
107
108 /* Prepare UART for serial console. */
109 if (CONFIG(INTEL_LPSS_UART_FOR_CONSOLE))
110 uart_bootblock_init();
111
112 uint16_t io_enables = LPC_IOE_SUPERIO_2E_2F | LPC_IOE_KBC_60_64 |
113 LPC_IOE_EC_62_66;
114
115 const config_t *config = config_of_soc();
116
117
118 if (config->lpc_ioe) {
119 io_enables = config->lpc_ioe & 0x3f0f;
120 lpc_set_fixed_io_ranges(config->lpc_iod, 0x1377);
121 } else {
122 /* IO Decode Range */
123 if (CONFIG(DRIVERS_UART_8250IO))
124 lpc_io_setup_comm_a_b();
125 }
126
127 /* IO Decode Enable */
128 lpc_enable_fixed_io_ranges(io_enables);
129
130 /* Program generic IO Decode Range */
131 pch_enable_lpc();
132
133 if (CONFIG(TPM_ON_FAST_SPI))
134 tpm_enable();
135
136 enable_pm_timer_emulation();
137
138 fast_spi_early_init(SPI_BASE_ADDRESS);
139
140 fast_spi_cache_bios_region();
141
142 /* Initialize GPE for use as interrupt status */
143 pmc_gpe_init();
144
145 /* Program TCO Timer Halt */
146 tco_configure();
147
148 /* Use Nx and paging to prevent the frontend from writing back dirty
149 * cache-as-ram lines to backing store that doesn't exist when the L1I
150 * speculatively fetches a line that is sitting in the L1D. */
151 if (CONFIG(PAGING_IN_CACHE_AS_RAM)) {
152 paging_set_nxe(1);
153 paging_set_default_pat();
154 paging_enable_for_car("pdpt", "pt");
155 }
156 }