blob: 2ab182571e321d76fedbcc7f356f48db9cca5f04 [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>
15#include <soc/gpio_soc_defs.h>
16#include <soc/intel/common/vbt.h>
17#include <soc/pci_devs.h>
Eric Lai5b302b22020-12-05 16:49:43 +080018#include <soc/pcie.h>
Subrata Banik2871e0e2020-09-27 11:30:58 +053019#include <soc/ramstage.h>
20#include <soc/soc_chip.h>
21#include <string.h>
22
23/* THC assignment definition */
24#define THC_NONE 0
25#define THC_0 1
26#define THC_1 2
27
28/* SATA DEVSLP idle timeout default values */
29#define DEF_DMVAL 15
30#define DEF_DITOVAL 625
31
32/*
33 * Chip config parameter PcieRpL1Substates uses (UPD value + 1)
34 * because UPD value of 0 for PcieRpL1Substates means disabled for FSP.
35 * In order to ensure that mainboard setting does not disable L1 substates
36 * incorrectly, chip config parameter values are offset by 1 with 0 meaning
37 * use FSP UPD default. get_l1_substate_control() ensures that the right UPD
38 * value is set in fsp_params.
39 * 0: Use FSP UPD default
40 * 1: Disable L1 substates
41 * 2: Use L1.1
42 * 3: Use L1.2 (FSP UPD default)
43 */
44static int get_l1_substate_control(enum L1_substates_control ctl)
45{
46 if ((ctl > L1_SS_L1_2) || (ctl == L1_SS_FSP_DEFAULT))
47 ctl = L1_SS_L1_2;
48 return ctl - 1;
49}
50
51static void parse_devicetree(FSP_S_CONFIG *params)
52{
53 const struct soc_intel_alderlake_config *config;
54 config = config_of_soc();
55
56 for (int i = 0; i < CONFIG_SOC_INTEL_I2C_DEV_MAX; i++)
57 params->SerialIoI2cMode[i] = config->SerialIoI2cMode[i];
58
59 for (int i = 0; i < CONFIG_SOC_INTEL_COMMON_BLOCK_GSPI_MAX; i++) {
60 params->SerialIoSpiMode[i] = config->SerialIoGSpiMode[i];
61 params->SerialIoSpiCsMode[i] = config->SerialIoGSpiCsMode[i];
62 params->SerialIoSpiCsState[i] = config->SerialIoGSpiCsState[i];
63 }
64
65 for (int i = 0; i < CONFIG_SOC_INTEL_UART_DEV_MAX; i++)
66 params->SerialIoUartMode[i] = config->SerialIoUartMode[i];
67}
68
69static const pci_devfn_t serial_io_dev[] = {
70 PCH_DEVFN_I2C0,
71 PCH_DEVFN_I2C1,
72 PCH_DEVFN_I2C2,
73 PCH_DEVFN_I2C3,
74 PCH_DEVFN_I2C4,
75 PCH_DEVFN_I2C5,
76 PCH_DEVFN_GSPI0,
77 PCH_DEVFN_GSPI1,
78 PCH_DEVFN_GSPI2,
79 PCH_DEVFN_GSPI3,
80 PCH_DEVFN_UART0,
81 PCH_DEVFN_UART1,
82 PCH_DEVFN_UART2
83};
84
85__weak void mainboard_update_soc_chip_config(struct soc_intel_alderlake_config *config)
86{
87 /* Override settings per board. */
88}
89
90/* UPD parameters to be initialized before SiliconInit */
91void platform_fsp_silicon_init_params_cb(FSPS_UPD *supd)
92{
93 int i;
Subrata Banik99289a82020-12-22 10:54:44 +053094 const struct microcode *microcode_file;
95 size_t microcode_len;
Subrata Banik2871e0e2020-09-27 11:30:58 +053096 FSP_S_CONFIG *params = &supd->FspsConfig;
Eric Lai5b302b22020-12-05 16:49:43 +080097 uint32_t enable_mask;
Subrata Banik2871e0e2020-09-27 11:30:58 +053098
99 struct device *dev;
100 struct soc_intel_alderlake_config *config;
101 config = config_of_soc();
102 mainboard_update_soc_chip_config(config);
103
104 /* Parse device tree and enable/disable Serial I/O devices */
105 parse_devicetree(params);
106
Subrata Banik99289a82020-12-22 10:54:44 +0530107 microcode_file = cbfs_map("cpu_microcode_blob.bin", &microcode_len);
108
109 if ((microcode_file != NULL) && (microcode_len != 0)) {
110 /* Update CPU Microcode patch base address/size */
111 params->MicrocodeRegionBase = (uint32_t)microcode_file;
112 params->MicrocodeRegionSize = (uint32_t)microcode_len;
113 }
114
Subrata Banik2871e0e2020-09-27 11:30:58 +0530115 /* Load VBT before devicetree-specific config. */
116 params->GraphicsConfigPtr = (uintptr_t)vbt_get();
117
118 /* Check if IGD is present and fill Graphics init param accordingly */
119 dev = pcidev_path_on_root(SA_DEVFN_IGD);
120 params->PeiGraphicsPeimInit = CONFIG(RUN_FSP_GOP) && is_dev_enabled(dev);
Ronak Kanabar812b54e2021-02-22 18:11:18 +0530121 params->LidStatus = CONFIG(RUN_FSP_GOP);
Subrata Banik2871e0e2020-09-27 11:30:58 +0530122
123 /* Use coreboot MP PPI services if Kconfig is enabled */
124 if (CONFIG(USE_INTEL_FSP_TO_CALL_COREBOOT_PUBLISH_MP_PPI))
125 params->CpuMpPpi = (uintptr_t) mp_fill_ppi_services_data();
126
127 /* D3Hot and D3Cold for TCSS */
128 params->D3HotEnable = !config->TcssD3HotDisable;
129 params->D3ColdEnable = !config->TcssD3ColdDisable;
130
131 params->TcssAuxOri = config->TcssAuxOri;
132 for (i = 0; i < 8; i++)
133 params->IomTypeCPortPadCfg[i] = config->IomTypeCPortPadCfg[i];
134
135 /*
136 * Set FSPS UPD ITbtConnectTopologyTimeoutInMs with value 0. FSP will
137 * evaluate this UPD value and skip sending command. There will be no
138 * delay for command completion.
139 */
140 params->ITbtConnectTopologyTimeoutInMs = 0;
141
142 /* Chipset Lockdown */
143 if (get_lockdown_config() == CHIPSET_LOCKDOWN_COREBOOT) {
144 params->PchLockDownGlobalSmi = 0;
145 params->PchLockDownBiosInterface = 0;
146 params->PchUnlockGpioPads = 1;
147 params->RtcMemoryLock = 0;
148 } else {
149 params->PchLockDownGlobalSmi = 1;
150 params->PchLockDownBiosInterface = 1;
151 params->PchUnlockGpioPads = 0;
152 params->RtcMemoryLock = 1;
153 }
154
155 /* USB */
156 for (i = 0; i < ARRAY_SIZE(config->usb2_ports); i++) {
157 params->PortUsb20Enable[i] = config->usb2_ports[i].enable;
158 params->Usb2PhyPetxiset[i] = config->usb2_ports[i].pre_emp_bias;
159 params->Usb2PhyTxiset[i] = config->usb2_ports[i].tx_bias;
160 params->Usb2PhyPredeemp[i] = config->usb2_ports[i].tx_emp_enable;
161 params->Usb2PhyPehalfbit[i] = config->usb2_ports[i].pre_emp_bit;
162
163 if (config->usb2_ports[i].enable)
164 params->Usb2OverCurrentPin[i] = config->usb2_ports[i].ocpin;
165 else
166 params->Usb2OverCurrentPin[i] = OC_SKIP;
167 }
168
169 for (i = 0; i < ARRAY_SIZE(config->usb3_ports); i++) {
170 params->PortUsb30Enable[i] = config->usb3_ports[i].enable;
171 if (config->usb3_ports[i].enable)
172 params->Usb3OverCurrentPin[i] = config->usb3_ports[i].ocpin;
173 else
174 params->Usb3OverCurrentPin[i] = OC_SKIP;
175
176 if (config->usb3_ports[i].tx_de_emp) {
177 params->Usb3HsioTxDeEmphEnable[i] = 1;
178 params->Usb3HsioTxDeEmph[i] = config->usb3_ports[i].tx_de_emp;
179 }
180 if (config->usb3_ports[i].tx_downscale_amp) {
181 params->Usb3HsioTxDownscaleAmpEnable[i] = 1;
182 params->Usb3HsioTxDownscaleAmp[i] =
183 config->usb3_ports[i].tx_downscale_amp;
184 }
185 }
186
Maulik V Vaghela69353502021-04-14 14:01:02 +0530187 for (i = 0; i < ARRAY_SIZE(config->tcss_ports); i++) {
188 if (config->tcss_ports[i].enable)
189 params->CpuUsb3OverCurrentPin[i] = config->tcss_ports[i].ocpin;
190 }
191
Subrata Banik2871e0e2020-09-27 11:30:58 +0530192 /* Enable xDCI controller if enabled in devicetree and allowed */
193 dev = pcidev_path_on_root(PCH_DEVFN_USBOTG);
194 if (dev) {
195 if (!xdci_can_enable())
196 dev->enabled = 0;
197 params->XdciEnable = dev->enabled;
198 } else {
199 params->XdciEnable = 0;
200 }
201
202 /* PCH UART selection for FSP Debug */
203 params->SerialIoDebugUartNumber = CONFIG_UART_FOR_CONSOLE;
204 ASSERT(ARRAY_SIZE(params->SerialIoUartAutoFlow) > CONFIG_UART_FOR_CONSOLE);
205 params->SerialIoUartAutoFlow[CONFIG_UART_FOR_CONSOLE] = 0;
206
207 /* SATA */
208 dev = pcidev_path_on_root(PCH_DEVFN_SATA);
209 params->SataEnable = is_dev_enabled(dev);
210 if (params->SataEnable) {
211 params->SataMode = config->SataMode;
212 params->SataSalpSupport = config->SataSalpSupport;
213 memcpy(params->SataPortsEnable, config->SataPortsEnable,
214 sizeof(params->SataPortsEnable));
215 memcpy(params->SataPortsDevSlp, config->SataPortsDevSlp,
216 sizeof(params->SataPortsDevSlp));
217 }
218
219 /*
220 * Power Optimizer for DMI and SATA.
221 * DmiPwrOptimizeDisable and SataPwrOptimizeDisable is default to 0.
222 * Boards not needing the optimizers explicitly disables them by setting
223 * these disable variables to 1 in devicetree overrides.
224 */
225 params->PchPwrOptEnable = !(config->DmiPwrOptimizeDisable);
226 params->SataPwrOptEnable = !(config->SataPwrOptimizeDisable);
227
228 /*
229 * Enable DEVSLP Idle Timeout settings DmVal and DitoVal.
230 * SataPortsDmVal is the DITO multiplier. Default is 15.
231 * SataPortsDitoVal is the DEVSLP Idle Timeout (DITO), Default is 625ms.
232 * The default values can be changed from devicetree.
233 */
234 for (i = 0; i < ARRAY_SIZE(config->SataPortsEnableDitoConfig); i++) {
235 if (config->SataPortsEnableDitoConfig[i]) {
236 params->SataPortsDmVal[i] = config->SataPortsDmVal[i];
237 params->SataPortsDitoVal[i] = config->SataPortsDitoVal[i];
238 }
239 }
240
241 /* Enable TCPU for processor thermal control */
242 dev = pcidev_path_on_root(SA_DEVFN_DPTF);
243 params->Device4Enable = is_dev_enabled(dev);
244
245 /* Set TccActivationOffset */
246 params->TccActivationOffset = config->tcc_offset;
247
248 /* LAN */
249 dev = pcidev_path_on_root(PCH_DEVFN_GBE);
250 params->PchLanEnable = is_dev_enabled(dev);
251
252 /* CNVi */
253 dev = pcidev_path_on_root(PCH_DEVFN_CNVI_WIFI);
254 params->CnviMode = is_dev_enabled(dev);
Cliff Huangbc1941f2021-02-10 17:41:41 -0800255 params->CnviBtCore = config->CnviBtCore;
Subrata Banik2871e0e2020-09-27 11:30:58 +0530256 params->CnviBtAudioOffload = config->CnviBtAudioOffload;
Cliff Huangbc1941f2021-02-10 17:41:41 -0800257 /* Assert if CNVi BT is enabled without CNVi being enabled. */
258 assert(params->CnviMode || !params->CnviBtCore);
259 /* Assert if CNVi BT offload is enabled without CNVi BT being enabled. */
260 assert(params->CnviBtCore || !params->CnviBtAudioOffload);
Subrata Banik2871e0e2020-09-27 11:30:58 +0530261
262 /* VMD */
263 dev = pcidev_path_on_root(SA_DEVFN_VMD);
264 params->VmdEnable = is_dev_enabled(dev);
265
266 /* THC */
267 dev = pcidev_path_on_root(PCH_DEVFN_THC0);
268 params->ThcPort0Assignment = is_dev_enabled(dev) ? THC_0 : THC_NONE;
269
270 dev = pcidev_path_on_root(PCH_DEVFN_THC1);
271 params->ThcPort1Assignment = is_dev_enabled(dev) ? THC_1 : THC_NONE;
272
273 /* Legacy 8254 timer support */
274 params->Enable8254ClockGating = !CONFIG(USE_LEGACY_8254_TIMER);
275 params->Enable8254ClockGatingOnS3 = !CONFIG(USE_LEGACY_8254_TIMER);
276
277 /* Enable Hybrid storage auto detection */
278 params->HybridStorageMode = config->HybridStorageMode;
279
Eric Lai5b302b22020-12-05 16:49:43 +0800280 enable_mask = pcie_rp_enable_mask(get_pch_pcie_rp_table());
Subrata Banik85144d92021-01-09 16:17:45 +0530281 for (i = 0; i < CONFIG_MAX_PCH_ROOT_PORTS; i++) {
Eric Lai5b302b22020-12-05 16:49:43 +0800282 if (!(enable_mask & BIT(i)))
283 continue;
284 const struct pcie_rp_config *rp_cfg = &config->pch_pcie_rp[i];
Subrata Banik2871e0e2020-09-27 11:30:58 +0530285 params->PcieRpL1Substates[i] =
Eric Lai5b302b22020-12-05 16:49:43 +0800286 get_l1_substate_control(rp_cfg->PcieRpL1Substates);
287 params->PcieRpLtrEnable[i] = !!(rp_cfg->flags & PCIE_RP_LTR);
288 params->PcieRpAdvancedErrorReporting[i] = !!(rp_cfg->flags & PCIE_RP_AER);
289 params->PcieRpHotPlug[i] = !!(rp_cfg->flags & PCIE_RP_HOTPLUG);
290 params->PcieRpClkReqDetect[i] = !!(rp_cfg->flags & PCIE_RP_CLK_REQ_DETECT);
Subrata Banik2871e0e2020-09-27 11:30:58 +0530291 }
292
Subrata Banik2871e0e2020-09-27 11:30:58 +0530293 params->PmSupport = 1;
294 params->Hwp = 1;
295 params->Cx = 1;
296 params->PsOnEnable = 1;
297
298 mainboard_silicon_init_params(params);
299}
300
301int soc_fsp_multi_phase_init_is_enable(void)
302{
303 return 0;
304}
305
306/*
307 * Callbacks for SoC/Mainboard specific overrides for FspMultiPhaseSiInit
308 * This platform supports below MultiPhaseSIInit Phase(s):
309 * Phase | FSP return point | Purpose
310 * ------- + ------------------------------------------------ + -------------------------------
311 * 1 | After TCSS initialization completed | for TCSS specific init
312 */
313void platform_fsp_multi_phase_init_cb(uint32_t phase_index)
314{
315 switch (phase_index) {
316 case 1:
317 /* TCSS specific initialization here */
318 break;
319 default:
320 break;
321 }
322}
323
324/* Mainboard GPIO Configuration */
325__weak void mainboard_silicon_init_params(FSP_S_CONFIG *params)
326{
327 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
328}
329
330/* Return list of SOC LPSS controllers */
331const pci_devfn_t *soc_lpss_controllers_list(size_t *size)
332{
333 *size = ARRAY_SIZE(serial_io_dev);
334 return serial_io_dev;
335}