blob: 0987b41bf255a255bb3ae53b4800fa4267fc752b [file] [log] [blame]
Subrata Banik2871e0e2020-09-27 11:30:58 +05301/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <assert.h>
Subrata Banik99289a82020-12-22 10:54:44 +05304#include <cbfs.h>
Subrata Banik2871e0e2020-09-27 11:30:58 +05305#include <console/console.h>
6#include <device/device.h>
7#include <device/pci.h>
8#include <fsp/api.h>
9#include <fsp/ppi/mp_service_ppi.h>
10#include <fsp/util.h>
11#include <intelblocks/lpss.h>
12#include <intelblocks/xdci.h>
13#include <intelpch/lockdown.h>
14#include <intelblocks/mp_init.h>
Deepti Deshatty8e7facf2021-05-12 17:45:37 +053015#include <intelblocks/tcss.h>
Subrata Banik2871e0e2020-09-27 11:30:58 +053016#include <soc/gpio_soc_defs.h>
17#include <soc/intel/common/vbt.h>
18#include <soc/pci_devs.h>
Eric Lai5b302b22020-12-05 16:49:43 +080019#include <soc/pcie.h>
Subrata Banik2871e0e2020-09-27 11:30:58 +053020#include <soc/ramstage.h>
21#include <soc/soc_chip.h>
22#include <string.h>
23
24/* THC assignment definition */
25#define THC_NONE 0
26#define THC_0 1
27#define THC_1 2
28
29/* SATA DEVSLP idle timeout default values */
30#define DEF_DMVAL 15
31#define DEF_DITOVAL 625
32
33/*
34 * Chip config parameter PcieRpL1Substates uses (UPD value + 1)
35 * because UPD value of 0 for PcieRpL1Substates means disabled for FSP.
36 * In order to ensure that mainboard setting does not disable L1 substates
37 * incorrectly, chip config parameter values are offset by 1 with 0 meaning
38 * use FSP UPD default. get_l1_substate_control() ensures that the right UPD
39 * value is set in fsp_params.
40 * 0: Use FSP UPD default
41 * 1: Disable L1 substates
42 * 2: Use L1.1
43 * 3: Use L1.2 (FSP UPD default)
44 */
45static int get_l1_substate_control(enum L1_substates_control ctl)
46{
47 if ((ctl > L1_SS_L1_2) || (ctl == L1_SS_FSP_DEFAULT))
48 ctl = L1_SS_L1_2;
49 return ctl - 1;
50}
51
52static void parse_devicetree(FSP_S_CONFIG *params)
53{
54 const struct soc_intel_alderlake_config *config;
55 config = config_of_soc();
56
57 for (int i = 0; i < CONFIG_SOC_INTEL_I2C_DEV_MAX; i++)
58 params->SerialIoI2cMode[i] = config->SerialIoI2cMode[i];
59
60 for (int i = 0; i < CONFIG_SOC_INTEL_COMMON_BLOCK_GSPI_MAX; i++) {
61 params->SerialIoSpiMode[i] = config->SerialIoGSpiMode[i];
62 params->SerialIoSpiCsMode[i] = config->SerialIoGSpiCsMode[i];
63 params->SerialIoSpiCsState[i] = config->SerialIoGSpiCsState[i];
64 }
65
66 for (int i = 0; i < CONFIG_SOC_INTEL_UART_DEV_MAX; i++)
67 params->SerialIoUartMode[i] = config->SerialIoUartMode[i];
68}
69
Subrata Banik2871e0e2020-09-27 11:30:58 +053070__weak void mainboard_update_soc_chip_config(struct soc_intel_alderlake_config *config)
71{
72 /* Override settings per board. */
73}
74
75/* UPD parameters to be initialized before SiliconInit */
76void platform_fsp_silicon_init_params_cb(FSPS_UPD *supd)
77{
78 int i;
Subrata Banik99289a82020-12-22 10:54:44 +053079 const struct microcode *microcode_file;
80 size_t microcode_len;
Subrata Banik2871e0e2020-09-27 11:30:58 +053081 FSP_S_CONFIG *params = &supd->FspsConfig;
Deepti Deshatty8e7facf2021-05-12 17:45:37 +053082 FSPS_ARCH_UPD *pfsps_arch_upd = &supd->FspsArchUpd;
Eric Lai5b302b22020-12-05 16:49:43 +080083 uint32_t enable_mask;
Subrata Banik2871e0e2020-09-27 11:30:58 +053084
Subrata Banik2871e0e2020-09-27 11:30:58 +053085 struct soc_intel_alderlake_config *config;
86 config = config_of_soc();
87 mainboard_update_soc_chip_config(config);
88
89 /* Parse device tree and enable/disable Serial I/O devices */
90 parse_devicetree(params);
91
Subrata Banik99289a82020-12-22 10:54:44 +053092 microcode_file = cbfs_map("cpu_microcode_blob.bin", &microcode_len);
93
94 if ((microcode_file != NULL) && (microcode_len != 0)) {
95 /* Update CPU Microcode patch base address/size */
96 params->MicrocodeRegionBase = (uint32_t)microcode_file;
97 params->MicrocodeRegionSize = (uint32_t)microcode_len;
98 }
99
Subrata Banik2871e0e2020-09-27 11:30:58 +0530100 /* Load VBT before devicetree-specific config. */
101 params->GraphicsConfigPtr = (uintptr_t)vbt_get();
102
103 /* Check if IGD is present and fill Graphics init param accordingly */
Subrata Banik50134ec2021-06-09 04:14:50 +0530104 params->PeiGraphicsPeimInit = CONFIG(RUN_FSP_GOP) && is_devfn_enabled(SA_DEVFN_IGD);
Ronak Kanabar812b54e2021-02-22 18:11:18 +0530105 params->LidStatus = CONFIG(RUN_FSP_GOP);
Subrata Banik2871e0e2020-09-27 11:30:58 +0530106
107 /* Use coreboot MP PPI services if Kconfig is enabled */
108 if (CONFIG(USE_INTEL_FSP_TO_CALL_COREBOOT_PUBLISH_MP_PPI))
109 params->CpuMpPpi = (uintptr_t) mp_fill_ppi_services_data();
110
111 /* D3Hot and D3Cold for TCSS */
112 params->D3HotEnable = !config->TcssD3HotDisable;
113 params->D3ColdEnable = !config->TcssD3ColdDisable;
114
115 params->TcssAuxOri = config->TcssAuxOri;
Deepti Deshatty8e7facf2021-05-12 17:45:37 +0530116
117 /* Explicitly clear this field to avoid using defaults */
118 memset(params->IomTypeCPortPadCfg, 0, sizeof(params->IomTypeCPortPadCfg));
Subrata Banik2871e0e2020-09-27 11:30:58 +0530119
120 /*
121 * Set FSPS UPD ITbtConnectTopologyTimeoutInMs with value 0. FSP will
122 * evaluate this UPD value and skip sending command. There will be no
123 * delay for command completion.
124 */
125 params->ITbtConnectTopologyTimeoutInMs = 0;
126
127 /* Chipset Lockdown */
128 if (get_lockdown_config() == CHIPSET_LOCKDOWN_COREBOOT) {
129 params->PchLockDownGlobalSmi = 0;
130 params->PchLockDownBiosInterface = 0;
131 params->PchUnlockGpioPads = 1;
132 params->RtcMemoryLock = 0;
133 } else {
134 params->PchLockDownGlobalSmi = 1;
135 params->PchLockDownBiosInterface = 1;
136 params->PchUnlockGpioPads = 0;
137 params->RtcMemoryLock = 1;
138 }
139
140 /* USB */
141 for (i = 0; i < ARRAY_SIZE(config->usb2_ports); i++) {
142 params->PortUsb20Enable[i] = config->usb2_ports[i].enable;
143 params->Usb2PhyPetxiset[i] = config->usb2_ports[i].pre_emp_bias;
144 params->Usb2PhyTxiset[i] = config->usb2_ports[i].tx_bias;
145 params->Usb2PhyPredeemp[i] = config->usb2_ports[i].tx_emp_enable;
146 params->Usb2PhyPehalfbit[i] = config->usb2_ports[i].pre_emp_bit;
147
148 if (config->usb2_ports[i].enable)
149 params->Usb2OverCurrentPin[i] = config->usb2_ports[i].ocpin;
150 else
151 params->Usb2OverCurrentPin[i] = OC_SKIP;
152 }
153
154 for (i = 0; i < ARRAY_SIZE(config->usb3_ports); i++) {
155 params->PortUsb30Enable[i] = config->usb3_ports[i].enable;
156 if (config->usb3_ports[i].enable)
157 params->Usb3OverCurrentPin[i] = config->usb3_ports[i].ocpin;
158 else
159 params->Usb3OverCurrentPin[i] = OC_SKIP;
160
161 if (config->usb3_ports[i].tx_de_emp) {
162 params->Usb3HsioTxDeEmphEnable[i] = 1;
163 params->Usb3HsioTxDeEmph[i] = config->usb3_ports[i].tx_de_emp;
164 }
165 if (config->usb3_ports[i].tx_downscale_amp) {
166 params->Usb3HsioTxDownscaleAmpEnable[i] = 1;
167 params->Usb3HsioTxDownscaleAmp[i] =
168 config->usb3_ports[i].tx_downscale_amp;
169 }
170 }
171
Maulik V Vaghela69353502021-04-14 14:01:02 +0530172 for (i = 0; i < ARRAY_SIZE(config->tcss_ports); i++) {
173 if (config->tcss_ports[i].enable)
174 params->CpuUsb3OverCurrentPin[i] = config->tcss_ports[i].ocpin;
175 }
176
Deepti Deshatty8e7facf2021-05-12 17:45:37 +0530177 /* EnableMultiPhaseSiliconInit for running MultiPhaseSiInit */
178 pfsps_arch_upd->EnableMultiPhaseSiliconInit = 1;
179
Subrata Banik2871e0e2020-09-27 11:30:58 +0530180 /* Enable xDCI controller if enabled in devicetree and allowed */
Subrata Banike6338042021-06-21 19:26:10 +0530181 if (!xdci_can_enable())
182 devfn_disable(pci_root_bus(), PCH_DEVFN_USBOTG);
183 params->XdciEnable = is_devfn_enabled(PCH_DEVFN_USBOTG);
Subrata Banik2871e0e2020-09-27 11:30:58 +0530184
185 /* PCH UART selection for FSP Debug */
186 params->SerialIoDebugUartNumber = CONFIG_UART_FOR_CONSOLE;
187 ASSERT(ARRAY_SIZE(params->SerialIoUartAutoFlow) > CONFIG_UART_FOR_CONSOLE);
188 params->SerialIoUartAutoFlow[CONFIG_UART_FOR_CONSOLE] = 0;
189
190 /* SATA */
Subrata Banik50134ec2021-06-09 04:14:50 +0530191 params->SataEnable = is_devfn_enabled(PCH_DEVFN_SATA);
Subrata Banik2871e0e2020-09-27 11:30:58 +0530192 if (params->SataEnable) {
193 params->SataMode = config->SataMode;
194 params->SataSalpSupport = config->SataSalpSupport;
195 memcpy(params->SataPortsEnable, config->SataPortsEnable,
196 sizeof(params->SataPortsEnable));
197 memcpy(params->SataPortsDevSlp, config->SataPortsDevSlp,
198 sizeof(params->SataPortsDevSlp));
199 }
200
201 /*
202 * Power Optimizer for DMI and SATA.
203 * DmiPwrOptimizeDisable and SataPwrOptimizeDisable is default to 0.
204 * Boards not needing the optimizers explicitly disables them by setting
205 * these disable variables to 1 in devicetree overrides.
206 */
207 params->PchPwrOptEnable = !(config->DmiPwrOptimizeDisable);
208 params->SataPwrOptEnable = !(config->SataPwrOptimizeDisable);
209
210 /*
211 * Enable DEVSLP Idle Timeout settings DmVal and DitoVal.
212 * SataPortsDmVal is the DITO multiplier. Default is 15.
213 * SataPortsDitoVal is the DEVSLP Idle Timeout (DITO), Default is 625ms.
214 * The default values can be changed from devicetree.
215 */
216 for (i = 0; i < ARRAY_SIZE(config->SataPortsEnableDitoConfig); i++) {
217 if (config->SataPortsEnableDitoConfig[i]) {
218 params->SataPortsDmVal[i] = config->SataPortsDmVal[i];
219 params->SataPortsDitoVal[i] = config->SataPortsDitoVal[i];
220 }
221 }
222
223 /* Enable TCPU for processor thermal control */
Subrata Banik50134ec2021-06-09 04:14:50 +0530224 params->Device4Enable = is_devfn_enabled(SA_DEVFN_DPTF);
Subrata Banik2871e0e2020-09-27 11:30:58 +0530225
226 /* Set TccActivationOffset */
227 params->TccActivationOffset = config->tcc_offset;
228
229 /* LAN */
Subrata Banik50134ec2021-06-09 04:14:50 +0530230 params->PchLanEnable = is_devfn_enabled(PCH_DEVFN_GBE);
Subrata Banik2871e0e2020-09-27 11:30:58 +0530231
232 /* CNVi */
Subrata Banik50134ec2021-06-09 04:14:50 +0530233 params->CnviMode = is_devfn_enabled(PCH_DEVFN_CNVI_WIFI);
Cliff Huangbc1941f2021-02-10 17:41:41 -0800234 params->CnviBtCore = config->CnviBtCore;
Subrata Banik2871e0e2020-09-27 11:30:58 +0530235 params->CnviBtAudioOffload = config->CnviBtAudioOffload;
Cliff Huangbc1941f2021-02-10 17:41:41 -0800236 /* Assert if CNVi BT is enabled without CNVi being enabled. */
237 assert(params->CnviMode || !params->CnviBtCore);
238 /* Assert if CNVi BT offload is enabled without CNVi BT being enabled. */
239 assert(params->CnviBtCore || !params->CnviBtAudioOffload);
Subrata Banik2871e0e2020-09-27 11:30:58 +0530240
241 /* VMD */
Subrata Banik50134ec2021-06-09 04:14:50 +0530242 params->VmdEnable = is_devfn_enabled(SA_DEVFN_VMD);
Subrata Banik2871e0e2020-09-27 11:30:58 +0530243
244 /* THC */
Subrata Banik50134ec2021-06-09 04:14:50 +0530245 params->ThcPort0Assignment = is_devfn_enabled(PCH_DEVFN_THC0) ? THC_0 : THC_NONE;
246 params->ThcPort1Assignment = is_devfn_enabled(PCH_DEVFN_THC1) ? THC_1 : THC_NONE;
Subrata Banik2871e0e2020-09-27 11:30:58 +0530247
Bernardo Perez Priego095f97b2021-05-18 18:39:19 -0700248 /* USB4/TBT */
249 for (i = 0; i < ARRAY_SIZE(params->ITbtPcieRootPortEn); i++)
250 params->ITbtPcieRootPortEn[i] = is_devfn_enabled(SA_DEVFN_TBT(i));
251
Subrata Banik2871e0e2020-09-27 11:30:58 +0530252 /* Legacy 8254 timer support */
253 params->Enable8254ClockGating = !CONFIG(USE_LEGACY_8254_TIMER);
254 params->Enable8254ClockGatingOnS3 = !CONFIG(USE_LEGACY_8254_TIMER);
255
256 /* Enable Hybrid storage auto detection */
257 params->HybridStorageMode = config->HybridStorageMode;
258
Eric Lai5b302b22020-12-05 16:49:43 +0800259 enable_mask = pcie_rp_enable_mask(get_pch_pcie_rp_table());
Subrata Banik85144d92021-01-09 16:17:45 +0530260 for (i = 0; i < CONFIG_MAX_PCH_ROOT_PORTS; i++) {
Eric Lai5b302b22020-12-05 16:49:43 +0800261 if (!(enable_mask & BIT(i)))
262 continue;
263 const struct pcie_rp_config *rp_cfg = &config->pch_pcie_rp[i];
Subrata Banik2871e0e2020-09-27 11:30:58 +0530264 params->PcieRpL1Substates[i] =
Eric Lai5b302b22020-12-05 16:49:43 +0800265 get_l1_substate_control(rp_cfg->PcieRpL1Substates);
266 params->PcieRpLtrEnable[i] = !!(rp_cfg->flags & PCIE_RP_LTR);
267 params->PcieRpAdvancedErrorReporting[i] = !!(rp_cfg->flags & PCIE_RP_AER);
268 params->PcieRpHotPlug[i] = !!(rp_cfg->flags & PCIE_RP_HOTPLUG);
269 params->PcieRpClkReqDetect[i] = !!(rp_cfg->flags & PCIE_RP_CLK_REQ_DETECT);
Subrata Banik2871e0e2020-09-27 11:30:58 +0530270 }
271
Subrata Banik2871e0e2020-09-27 11:30:58 +0530272 params->PmSupport = 1;
273 params->Hwp = 1;
274 params->Cx = 1;
275 params->PsOnEnable = 1;
276
277 mainboard_silicon_init_params(params);
278}
279
Subrata Banik2871e0e2020-09-27 11:30:58 +0530280/*
281 * Callbacks for SoC/Mainboard specific overrides for FspMultiPhaseSiInit
282 * This platform supports below MultiPhaseSIInit Phase(s):
283 * Phase | FSP return point | Purpose
284 * ------- + ------------------------------------------------ + -------------------------------
285 * 1 | After TCSS initialization completed | for TCSS specific init
286 */
287void platform_fsp_multi_phase_init_cb(uint32_t phase_index)
288{
289 switch (phase_index) {
290 case 1:
291 /* TCSS specific initialization here */
Deepti Deshatty8e7facf2021-05-12 17:45:37 +0530292 printk(BIOS_DEBUG, "FSP MultiPhaseSiInit %s/%s called\n",
293 __FILE__, __func__);
294
295 if (CONFIG(SOC_INTEL_COMMON_BLOCK_TCSS)) {
296 const config_t *config = config_of_soc();
297 tcss_configure(config->typec_aux_bias_pads);
298 }
Subrata Banik2871e0e2020-09-27 11:30:58 +0530299 break;
300 default:
301 break;
302 }
303}
304
305/* Mainboard GPIO Configuration */
306__weak void mainboard_silicon_init_params(FSP_S_CONFIG *params)
307{
308 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
309}