blob: 8664fe6f46941bd0ae53fdb83e16955ace5afbbc [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
70static const pci_devfn_t serial_io_dev[] = {
71 PCH_DEVFN_I2C0,
72 PCH_DEVFN_I2C1,
73 PCH_DEVFN_I2C2,
74 PCH_DEVFN_I2C3,
75 PCH_DEVFN_I2C4,
76 PCH_DEVFN_I2C5,
77 PCH_DEVFN_GSPI0,
78 PCH_DEVFN_GSPI1,
79 PCH_DEVFN_GSPI2,
80 PCH_DEVFN_GSPI3,
81 PCH_DEVFN_UART0,
82 PCH_DEVFN_UART1,
83 PCH_DEVFN_UART2
84};
85
86__weak void mainboard_update_soc_chip_config(struct soc_intel_alderlake_config *config)
87{
88 /* Override settings per board. */
89}
90
91/* UPD parameters to be initialized before SiliconInit */
92void platform_fsp_silicon_init_params_cb(FSPS_UPD *supd)
93{
94 int i;
Subrata Banik99289a82020-12-22 10:54:44 +053095 const struct microcode *microcode_file;
96 size_t microcode_len;
Subrata Banik2871e0e2020-09-27 11:30:58 +053097 FSP_S_CONFIG *params = &supd->FspsConfig;
Deepti Deshatty8e7facf2021-05-12 17:45:37 +053098 FSPS_ARCH_UPD *pfsps_arch_upd = &supd->FspsArchUpd;
Eric Lai5b302b22020-12-05 16:49:43 +080099 uint32_t enable_mask;
Subrata Banik2871e0e2020-09-27 11:30:58 +0530100
101 struct device *dev;
102 struct soc_intel_alderlake_config *config;
103 config = config_of_soc();
104 mainboard_update_soc_chip_config(config);
105
106 /* Parse device tree and enable/disable Serial I/O devices */
107 parse_devicetree(params);
108
Subrata Banik99289a82020-12-22 10:54:44 +0530109 microcode_file = cbfs_map("cpu_microcode_blob.bin", &microcode_len);
110
111 if ((microcode_file != NULL) && (microcode_len != 0)) {
112 /* Update CPU Microcode patch base address/size */
113 params->MicrocodeRegionBase = (uint32_t)microcode_file;
114 params->MicrocodeRegionSize = (uint32_t)microcode_len;
115 }
116
Subrata Banik2871e0e2020-09-27 11:30:58 +0530117 /* Load VBT before devicetree-specific config. */
118 params->GraphicsConfigPtr = (uintptr_t)vbt_get();
119
120 /* Check if IGD is present and fill Graphics init param accordingly */
121 dev = pcidev_path_on_root(SA_DEVFN_IGD);
122 params->PeiGraphicsPeimInit = CONFIG(RUN_FSP_GOP) && is_dev_enabled(dev);
Ronak Kanabar812b54e2021-02-22 18:11:18 +0530123 params->LidStatus = CONFIG(RUN_FSP_GOP);
Subrata Banik2871e0e2020-09-27 11:30:58 +0530124
125 /* Use coreboot MP PPI services if Kconfig is enabled */
126 if (CONFIG(USE_INTEL_FSP_TO_CALL_COREBOOT_PUBLISH_MP_PPI))
127 params->CpuMpPpi = (uintptr_t) mp_fill_ppi_services_data();
128
129 /* D3Hot and D3Cold for TCSS */
130 params->D3HotEnable = !config->TcssD3HotDisable;
131 params->D3ColdEnable = !config->TcssD3ColdDisable;
132
133 params->TcssAuxOri = config->TcssAuxOri;
Deepti Deshatty8e7facf2021-05-12 17:45:37 +0530134
135 /* Explicitly clear this field to avoid using defaults */
136 memset(params->IomTypeCPortPadCfg, 0, sizeof(params->IomTypeCPortPadCfg));
Subrata Banik2871e0e2020-09-27 11:30:58 +0530137
138 /*
139 * Set FSPS UPD ITbtConnectTopologyTimeoutInMs with value 0. FSP will
140 * evaluate this UPD value and skip sending command. There will be no
141 * delay for command completion.
142 */
143 params->ITbtConnectTopologyTimeoutInMs = 0;
144
145 /* Chipset Lockdown */
146 if (get_lockdown_config() == CHIPSET_LOCKDOWN_COREBOOT) {
147 params->PchLockDownGlobalSmi = 0;
148 params->PchLockDownBiosInterface = 0;
149 params->PchUnlockGpioPads = 1;
150 params->RtcMemoryLock = 0;
151 } else {
152 params->PchLockDownGlobalSmi = 1;
153 params->PchLockDownBiosInterface = 1;
154 params->PchUnlockGpioPads = 0;
155 params->RtcMemoryLock = 1;
156 }
157
158 /* USB */
159 for (i = 0; i < ARRAY_SIZE(config->usb2_ports); i++) {
160 params->PortUsb20Enable[i] = config->usb2_ports[i].enable;
161 params->Usb2PhyPetxiset[i] = config->usb2_ports[i].pre_emp_bias;
162 params->Usb2PhyTxiset[i] = config->usb2_ports[i].tx_bias;
163 params->Usb2PhyPredeemp[i] = config->usb2_ports[i].tx_emp_enable;
164 params->Usb2PhyPehalfbit[i] = config->usb2_ports[i].pre_emp_bit;
165
166 if (config->usb2_ports[i].enable)
167 params->Usb2OverCurrentPin[i] = config->usb2_ports[i].ocpin;
168 else
169 params->Usb2OverCurrentPin[i] = OC_SKIP;
170 }
171
172 for (i = 0; i < ARRAY_SIZE(config->usb3_ports); i++) {
173 params->PortUsb30Enable[i] = config->usb3_ports[i].enable;
174 if (config->usb3_ports[i].enable)
175 params->Usb3OverCurrentPin[i] = config->usb3_ports[i].ocpin;
176 else
177 params->Usb3OverCurrentPin[i] = OC_SKIP;
178
179 if (config->usb3_ports[i].tx_de_emp) {
180 params->Usb3HsioTxDeEmphEnable[i] = 1;
181 params->Usb3HsioTxDeEmph[i] = config->usb3_ports[i].tx_de_emp;
182 }
183 if (config->usb3_ports[i].tx_downscale_amp) {
184 params->Usb3HsioTxDownscaleAmpEnable[i] = 1;
185 params->Usb3HsioTxDownscaleAmp[i] =
186 config->usb3_ports[i].tx_downscale_amp;
187 }
188 }
189
Maulik V Vaghela69353502021-04-14 14:01:02 +0530190 for (i = 0; i < ARRAY_SIZE(config->tcss_ports); i++) {
191 if (config->tcss_ports[i].enable)
192 params->CpuUsb3OverCurrentPin[i] = config->tcss_ports[i].ocpin;
193 }
194
Deepti Deshatty8e7facf2021-05-12 17:45:37 +0530195 /* EnableMultiPhaseSiliconInit for running MultiPhaseSiInit */
196 pfsps_arch_upd->EnableMultiPhaseSiliconInit = 1;
197
Subrata Banik2871e0e2020-09-27 11:30:58 +0530198 /* Enable xDCI controller if enabled in devicetree and allowed */
199 dev = pcidev_path_on_root(PCH_DEVFN_USBOTG);
200 if (dev) {
201 if (!xdci_can_enable())
202 dev->enabled = 0;
203 params->XdciEnable = dev->enabled;
204 } else {
205 params->XdciEnable = 0;
206 }
207
208 /* PCH UART selection for FSP Debug */
209 params->SerialIoDebugUartNumber = CONFIG_UART_FOR_CONSOLE;
210 ASSERT(ARRAY_SIZE(params->SerialIoUartAutoFlow) > CONFIG_UART_FOR_CONSOLE);
211 params->SerialIoUartAutoFlow[CONFIG_UART_FOR_CONSOLE] = 0;
212
213 /* SATA */
214 dev = pcidev_path_on_root(PCH_DEVFN_SATA);
215 params->SataEnable = is_dev_enabled(dev);
216 if (params->SataEnable) {
217 params->SataMode = config->SataMode;
218 params->SataSalpSupport = config->SataSalpSupport;
219 memcpy(params->SataPortsEnable, config->SataPortsEnable,
220 sizeof(params->SataPortsEnable));
221 memcpy(params->SataPortsDevSlp, config->SataPortsDevSlp,
222 sizeof(params->SataPortsDevSlp));
223 }
224
225 /*
226 * Power Optimizer for DMI and SATA.
227 * DmiPwrOptimizeDisable and SataPwrOptimizeDisable is default to 0.
228 * Boards not needing the optimizers explicitly disables them by setting
229 * these disable variables to 1 in devicetree overrides.
230 */
231 params->PchPwrOptEnable = !(config->DmiPwrOptimizeDisable);
232 params->SataPwrOptEnable = !(config->SataPwrOptimizeDisable);
233
234 /*
235 * Enable DEVSLP Idle Timeout settings DmVal and DitoVal.
236 * SataPortsDmVal is the DITO multiplier. Default is 15.
237 * SataPortsDitoVal is the DEVSLP Idle Timeout (DITO), Default is 625ms.
238 * The default values can be changed from devicetree.
239 */
240 for (i = 0; i < ARRAY_SIZE(config->SataPortsEnableDitoConfig); i++) {
241 if (config->SataPortsEnableDitoConfig[i]) {
242 params->SataPortsDmVal[i] = config->SataPortsDmVal[i];
243 params->SataPortsDitoVal[i] = config->SataPortsDitoVal[i];
244 }
245 }
246
247 /* Enable TCPU for processor thermal control */
248 dev = pcidev_path_on_root(SA_DEVFN_DPTF);
249 params->Device4Enable = is_dev_enabled(dev);
250
251 /* Set TccActivationOffset */
252 params->TccActivationOffset = config->tcc_offset;
253
254 /* LAN */
255 dev = pcidev_path_on_root(PCH_DEVFN_GBE);
256 params->PchLanEnable = is_dev_enabled(dev);
257
258 /* CNVi */
259 dev = pcidev_path_on_root(PCH_DEVFN_CNVI_WIFI);
260 params->CnviMode = is_dev_enabled(dev);
Cliff Huangbc1941f2021-02-10 17:41:41 -0800261 params->CnviBtCore = config->CnviBtCore;
Subrata Banik2871e0e2020-09-27 11:30:58 +0530262 params->CnviBtAudioOffload = config->CnviBtAudioOffload;
Cliff Huangbc1941f2021-02-10 17:41:41 -0800263 /* Assert if CNVi BT is enabled without CNVi being enabled. */
264 assert(params->CnviMode || !params->CnviBtCore);
265 /* Assert if CNVi BT offload is enabled without CNVi BT being enabled. */
266 assert(params->CnviBtCore || !params->CnviBtAudioOffload);
Subrata Banik2871e0e2020-09-27 11:30:58 +0530267
268 /* VMD */
269 dev = pcidev_path_on_root(SA_DEVFN_VMD);
270 params->VmdEnable = is_dev_enabled(dev);
271
272 /* THC */
273 dev = pcidev_path_on_root(PCH_DEVFN_THC0);
274 params->ThcPort0Assignment = is_dev_enabled(dev) ? THC_0 : THC_NONE;
275
276 dev = pcidev_path_on_root(PCH_DEVFN_THC1);
277 params->ThcPort1Assignment = is_dev_enabled(dev) ? THC_1 : THC_NONE;
278
279 /* Legacy 8254 timer support */
280 params->Enable8254ClockGating = !CONFIG(USE_LEGACY_8254_TIMER);
281 params->Enable8254ClockGatingOnS3 = !CONFIG(USE_LEGACY_8254_TIMER);
282
283 /* Enable Hybrid storage auto detection */
284 params->HybridStorageMode = config->HybridStorageMode;
285
Eric Lai5b302b22020-12-05 16:49:43 +0800286 enable_mask = pcie_rp_enable_mask(get_pch_pcie_rp_table());
Subrata Banik85144d92021-01-09 16:17:45 +0530287 for (i = 0; i < CONFIG_MAX_PCH_ROOT_PORTS; i++) {
Eric Lai5b302b22020-12-05 16:49:43 +0800288 if (!(enable_mask & BIT(i)))
289 continue;
290 const struct pcie_rp_config *rp_cfg = &config->pch_pcie_rp[i];
Subrata Banik2871e0e2020-09-27 11:30:58 +0530291 params->PcieRpL1Substates[i] =
Eric Lai5b302b22020-12-05 16:49:43 +0800292 get_l1_substate_control(rp_cfg->PcieRpL1Substates);
293 params->PcieRpLtrEnable[i] = !!(rp_cfg->flags & PCIE_RP_LTR);
294 params->PcieRpAdvancedErrorReporting[i] = !!(rp_cfg->flags & PCIE_RP_AER);
295 params->PcieRpHotPlug[i] = !!(rp_cfg->flags & PCIE_RP_HOTPLUG);
296 params->PcieRpClkReqDetect[i] = !!(rp_cfg->flags & PCIE_RP_CLK_REQ_DETECT);
Subrata Banik2871e0e2020-09-27 11:30:58 +0530297 }
298
Subrata Banik2871e0e2020-09-27 11:30:58 +0530299 params->PmSupport = 1;
300 params->Hwp = 1;
301 params->Cx = 1;
302 params->PsOnEnable = 1;
303
304 mainboard_silicon_init_params(params);
305}
306
Subrata Banik2871e0e2020-09-27 11:30:58 +0530307/*
308 * Callbacks for SoC/Mainboard specific overrides for FspMultiPhaseSiInit
309 * This platform supports below MultiPhaseSIInit Phase(s):
310 * Phase | FSP return point | Purpose
311 * ------- + ------------------------------------------------ + -------------------------------
312 * 1 | After TCSS initialization completed | for TCSS specific init
313 */
314void platform_fsp_multi_phase_init_cb(uint32_t phase_index)
315{
316 switch (phase_index) {
317 case 1:
318 /* TCSS specific initialization here */
Deepti Deshatty8e7facf2021-05-12 17:45:37 +0530319 printk(BIOS_DEBUG, "FSP MultiPhaseSiInit %s/%s called\n",
320 __FILE__, __func__);
321
322 if (CONFIG(SOC_INTEL_COMMON_BLOCK_TCSS)) {
323 const config_t *config = config_of_soc();
324 tcss_configure(config->typec_aux_bias_pads);
325 }
Subrata Banik2871e0e2020-09-27 11:30:58 +0530326 break;
327 default:
328 break;
329 }
330}
331
332/* Mainboard GPIO Configuration */
333__weak void mainboard_silicon_init_params(FSP_S_CONFIG *params)
334{
335 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
336}
337
338/* Return list of SOC LPSS controllers */
339const pci_devfn_t *soc_lpss_controllers_list(size_t *size)
340{
341 *size = ARRAY_SIZE(serial_io_dev);
342 return serial_io_dev;
343}