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