blob: 30719ed5b1981e795a39ca616ab264f85ab5c8c6 [file] [log] [blame]
Lijian Zhao2f764f72017-07-14 11:09:10 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2016-2017 Intel Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <chip.h>
Aaron Durbin64031672018-04-21 14:45:32 -060017#include <compiler.h>
Lijian Zhao2f764f72017-07-14 11:09:10 -070018#include <console/console.h>
Pratik Prajapati201fa8f2017-08-16 11:42:40 -070019#include <device/device.h>
Lijian Zhao2f764f72017-07-14 11:09:10 -070020#include <device/pci.h>
21#include <fsp/api.h>
Lijian Zhao2f764f72017-07-14 11:09:10 -070022#include <fsp/util.h>
Subrata Banik98376b82018-05-22 16:18:16 +053023#include <intelblocks/acpi.h>
Subrata Banikf699c142018-06-08 17:57:37 +053024#include <intelblocks/chip.h>
Duncan Laurie2410cd92018-03-26 02:25:07 -070025#include <intelblocks/xdci.h>
Lijian Zhao2f764f72017-07-14 11:09:10 -070026#include <romstage_handoff.h>
Abhay kumarfcf88202017-09-20 15:17:42 -070027#include <soc/intel/common/vbt.h>
Pratik Prajapati9027e1b2017-08-23 17:37:43 -070028#include <soc/pci_devs.h>
Lijian Zhao2f764f72017-07-14 11:09:10 -070029#include <soc/ramstage.h>
30#include <string.h>
31
Lijian Zhao2b074d92017-08-17 14:25:24 -070032#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
Subrata Banik98376b82018-05-22 16:18:16 +053033const char *soc_acpi_name(const struct device *dev)
Lijian Zhao2b074d92017-08-17 14:25:24 -070034{
35 if (dev->path.type == DEVICE_PATH_DOMAIN)
36 return "PCI0";
37
38 if (dev->path.type != DEVICE_PATH_PCI)
39 return NULL;
40
41 switch (dev->path.pci.devfn) {
42 case SA_DEVFN_ROOT: return "MCHC";
43 case SA_DEVFN_IGD: return "GFX0";
44 case PCH_DEVFN_ISH: return "ISHB";
45 case PCH_DEVFN_XHCI: return "XHCI";
46 case PCH_DEVFN_USBOTG: return "XDCI";
47 case PCH_DEVFN_THERMAL: return "THRM";
48 case PCH_DEVFN_I2C0: return "I2C0";
49 case PCH_DEVFN_I2C1: return "I2C1";
50 case PCH_DEVFN_I2C2: return "I2C2";
51 case PCH_DEVFN_I2C3: return "I2C3";
52 case PCH_DEVFN_CSE: return "CSE1";
53 case PCH_DEVFN_CSE_2: return "CSE2";
54 case PCH_DEVFN_CSE_IDER: return "CSED";
55 case PCH_DEVFN_CSE_KT: return "CSKT";
56 case PCH_DEVFN_CSE_3: return "CSE3";
57 case PCH_DEVFN_SATA: return "SATA";
58 case PCH_DEVFN_UART2: return "UAR2";
59 case PCH_DEVFN_I2C4: return "I2C4";
60 case PCH_DEVFN_I2C5: return "I2C5";
61 case PCH_DEVFN_PCIE1: return "RP01";
62 case PCH_DEVFN_PCIE2: return "RP02";
63 case PCH_DEVFN_PCIE3: return "RP03";
64 case PCH_DEVFN_PCIE4: return "RP04";
65 case PCH_DEVFN_PCIE5: return "RP05";
66 case PCH_DEVFN_PCIE6: return "RP06";
67 case PCH_DEVFN_PCIE7: return "RP07";
68 case PCH_DEVFN_PCIE8: return "RP08";
69 case PCH_DEVFN_PCIE9: return "RP09";
70 case PCH_DEVFN_PCIE10: return "RP10";
71 case PCH_DEVFN_PCIE11: return "RP11";
72 case PCH_DEVFN_PCIE12: return "RP12";
Lijian Zhao580bc412017-10-04 13:43:47 -070073 case PCH_DEVFN_PCIE13: return "RP13";
74 case PCH_DEVFN_PCIE14: return "RP14";
75 case PCH_DEVFN_PCIE15: return "RP15";
76 case PCH_DEVFN_PCIE16: return "RP16";
Lijian Zhao2b074d92017-08-17 14:25:24 -070077 case PCH_DEVFN_UART0: return "UAR0";
78 case PCH_DEVFN_UART1: return "UAR1";
79 case PCH_DEVFN_GSPI0: return "SPI0";
80 case PCH_DEVFN_GSPI1: return "SPI1";
81 case PCH_DEVFN_GSPI2: return "SPI2";
82 case PCH_DEVFN_EMMC: return "EMMC";
83 case PCH_DEVFN_SDCARD: return "SDXC";
84 case PCH_DEVFN_LPC: return "LPCB";
85 case PCH_DEVFN_P2SB: return "P2SB";
86 case PCH_DEVFN_PMC: return "PMC_";
87 case PCH_DEVFN_HDA: return "HDAS";
88 case PCH_DEVFN_SMBUS: return "SBUS";
89 case PCH_DEVFN_SPI: return "FSPI";
90 case PCH_DEVFN_GBE: return "IGBE";
91 case PCH_DEVFN_TRACEHUB:return "THUB";
92 }
93
94 return NULL;
95}
96#endif
97
Lijian Zhao08231832017-09-05 18:16:21 -070098static void parse_devicetree(FSP_S_CONFIG *params)
99{
100 struct device *dev = SA_DEV_ROOT;
101 if (!dev) {
102 printk(BIOS_ERR, "Could not find root device\n");
103 return;
104 }
105
106 const config_t *config = dev->chip_info;
107 const int SerialIoDev[] = {
108 PCH_DEVFN_I2C0,
109 PCH_DEVFN_I2C1,
110 PCH_DEVFN_I2C2,
111 PCH_DEVFN_I2C3,
112 PCH_DEVFN_I2C4,
113 PCH_DEVFN_I2C5,
114 PCH_DEVFN_GSPI0,
115 PCH_DEVFN_GSPI1,
116 PCH_DEVFN_GSPI2,
117 PCH_DEVFN_UART0,
118 PCH_DEVFN_UART1,
119 PCH_DEVFN_UART2
120 };
121
122 for (int i = 0; i < ARRAY_SIZE(SerialIoDev); i++) {
123 dev = dev_find_slot(0, SerialIoDev[i]);
124 if (!dev->enabled) {
125 params->SerialIoDevMode[i] = PchSerialIoDisabled;
126 continue;
127 }
128 params->SerialIoDevMode[i] = PchSerialIoPci;
129 if (config->SerialIoDevMode[i] == PchSerialIoAcpi ||
130 config->SerialIoDevMode[i] == PchSerialIoHidden)
131 params->SerialIoDevMode[i] = config->SerialIoDevMode[i];
132 }
133}
134
Lijian Zhao2f764f72017-07-14 11:09:10 -0700135void soc_init_pre_device(void *chip_info)
136{
137 /* Perform silicon specific init. */
138 fsp_silicon_init(romstage_handoff_is_resume());
Subrata Banika8733e32018-01-23 16:40:56 +0530139
140 /* Display FIRMWARE_VERSION_INFO_HOB */
141 fsp_display_fvi_version_hob();
Lijian Zhao2f764f72017-07-14 11:09:10 -0700142}
143
Elyes HAOUAS3c8b5d02018-05-27 16:57:24 +0200144static void pci_domain_set_resources(struct device *dev)
Pratik Prajapati201fa8f2017-08-16 11:42:40 -0700145{
146 assign_resources(dev->link_list);
147}
148
149static struct device_operations pci_domain_ops = {
150 .read_resources = &pci_domain_read_resources,
151 .set_resources = &pci_domain_set_resources,
152 .scan_bus = &pci_domain_scan_bus,
Lijian Zhao2b074d92017-08-17 14:25:24 -0700153 #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
154 .acpi_name = &soc_acpi_name,
155 #endif
Pratik Prajapati201fa8f2017-08-16 11:42:40 -0700156};
157
158static struct device_operations cpu_bus_ops = {
159 .read_resources = DEVICE_NOOP,
160 .set_resources = DEVICE_NOOP,
161 .enable_resources = DEVICE_NOOP,
162 .init = DEVICE_NOOP,
Shaunak Saha95b61752017-10-04 23:08:40 -0700163 .acpi_fill_ssdt_generator = generate_cpu_entries,
Pratik Prajapati201fa8f2017-08-16 11:42:40 -0700164};
165
Elyes HAOUAS3c8b5d02018-05-27 16:57:24 +0200166static void soc_enable(struct device *dev)
Pratik Prajapati201fa8f2017-08-16 11:42:40 -0700167{
168 /* Set the operations if it is a special bus type */
169 if (dev->path.type == DEVICE_PATH_DOMAIN)
170 dev->ops = &pci_domain_ops;
171 else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER)
172 dev->ops = &cpu_bus_ops;
173}
174
Lijian Zhao2f764f72017-07-14 11:09:10 -0700175struct chip_operations soc_intel_cannonlake_ops = {
176 CHIP_NAME("Intel Cannonlake")
Pratik Prajapati201fa8f2017-08-16 11:42:40 -0700177 .enable_dev = &soc_enable,
Lijian Zhao2f764f72017-07-14 11:09:10 -0700178 .init = &soc_init_pre_device,
179};
180
181/* UPD parameters to be initialized before SiliconInit */
182void platform_fsp_silicon_init_params_cb(FSPS_UPD *supd)
183{
184 int i;
185 FSP_S_CONFIG *params = &supd->FspsConfig;
Lijian Zhao91c8e232018-03-12 18:05:53 -0700186 FSP_S_TEST_CONFIG *tconfig = &supd->FspsTestConfig;
Duncan Laurie2410cd92018-03-26 02:25:07 -0700187 struct device *dev = SA_DEV_ROOT;
Lijian Zhao580bc412017-10-04 13:43:47 -0700188 config_t *config = dev->chip_info;
Lijian Zhao2f764f72017-07-14 11:09:10 -0700189
Lijian Zhao08231832017-09-05 18:16:21 -0700190 /* Parse device tree and enable/disable devices */
191 parse_devicetree(params);
192
Abhay kumarfcf88202017-09-20 15:17:42 -0700193 /* Load VBT before devicetree-specific config. */
Patrick Georgi22579592017-10-06 17:36:09 +0200194 params->GraphicsConfigPtr = (uintptr_t)vbt_get();
Abhay kumarfcf88202017-09-20 15:17:42 -0700195
Lijian Zhao2f764f72017-07-14 11:09:10 -0700196 /* Set USB OC pin to 0 first */
197 for (i = 0; i < ARRAY_SIZE(params->Usb2OverCurrentPin); i++) {
198 params->Usb2OverCurrentPin[i] = 0;
199 }
200
201 for (i = 0; i < ARRAY_SIZE(params->Usb3OverCurrentPin); i++) {
202 params->Usb3OverCurrentPin[i] = 0;
203 }
204
205 mainboard_silicon_init_params(params);
Pratik Prajapati9027e1b2017-08-23 17:37:43 -0700206
Caveh Jalali21df67e2018-03-08 17:58:21 -0800207 /* Unlock upper 8 bytes of RTC RAM */
208 params->PchLockDownRtcMemoryLock = 0;
209
Pratik Prajapati9027e1b2017-08-23 17:37:43 -0700210 /* SATA */
211 params->SataEnable = config->SataEnable;
212 params->SataMode = config->SataMode;
213 params->SataSalpSupport = config->SataSalpSupport;
214 memcpy(params->SataPortsEnable, config->SataPortsEnable,
215 sizeof(params->SataPortsEnable));
216 memcpy(params->SataPortsDevSlp, config->SataPortsDevSlp,
217 sizeof(params->SataPortsDevSlp));
218
219 /* Lan */
220 params->PchLanEnable = config->PchLanEnable;
221
222 /* Audio */
223 params->PchHdaDspEnable = config->PchHdaDspEnable;
224 params->PchHdaAudioLinkHda = config->PchHdaAudioLinkHda;
Lijian Zhao416ded82018-01-23 21:58:36 -0800225 params->PchHdaAudioLinkDmic0 = config->PchHdaAudioLinkDmic0;
226 params->PchHdaAudioLinkDmic1 = config->PchHdaAudioLinkDmic1;
227 params->PchHdaAudioLinkSsp0 = config->PchHdaAudioLinkSsp0;
228 params->PchHdaAudioLinkSsp1 = config->PchHdaAudioLinkSsp1;
229 params->PchHdaAudioLinkSsp2 = config->PchHdaAudioLinkSsp2;
230 params->PchHdaAudioLinkSndw1 = config->PchHdaAudioLinkSndw1;
231 params->PchHdaAudioLinkSndw2 = config->PchHdaAudioLinkSndw2;
232 params->PchHdaAudioLinkSndw3 = config->PchHdaAudioLinkSndw3;
233 params->PchHdaAudioLinkSndw4 = config->PchHdaAudioLinkSndw4;
Pratik Prajapati9027e1b2017-08-23 17:37:43 -0700234
Vaibhav Shankar2da6ec42018-03-19 18:56:38 -0700235 /* S0ix */
236 params->PchPmSlpS0Enable = config->s0ix_enable;
237
Pratik Prajapati9027e1b2017-08-23 17:37:43 -0700238 /* USB */
239 for (i = 0; i < ARRAY_SIZE(config->usb2_ports); i++) {
240 params->PortUsb20Enable[i] =
241 config->usb2_ports[i].enable;
242 params->Usb2OverCurrentPin[i] =
243 config->usb2_ports[i].ocpin;
244 params->Usb2AfePetxiset[i] =
245 config->usb2_ports[i].pre_emp_bias;
246 params->Usb2AfeTxiset[i] =
247 config->usb2_ports[i].tx_bias;
248 params->Usb2AfePredeemp[i] =
249 config->usb2_ports[i].tx_emp_enable;
250 params->Usb2AfePehalfbit[i] =
251 config->usb2_ports[i].pre_emp_bit;
252 }
253
254 for (i = 0; i < ARRAY_SIZE(config->usb3_ports); i++) {
255 params->PortUsb30Enable[i] = config->usb3_ports[i].enable;
256 params->Usb3OverCurrentPin[i] = config->usb3_ports[i].ocpin;
257 if (config->usb3_ports[i].tx_de_emp) {
258 params->Usb3HsioTxDeEmphEnable[i] = 1;
259 params->Usb3HsioTxDeEmph[i] =
260 config->usb3_ports[i].tx_de_emp;
261 }
262 if (config->usb3_ports[i].tx_downscale_amp) {
263 params->Usb3HsioTxDownscaleAmpEnable[i] = 1;
264 params->Usb3HsioTxDownscaleAmp[i] =
265 config->usb3_ports[i].tx_downscale_amp;
266 }
267 }
268
Duncan Laurie2410cd92018-03-26 02:25:07 -0700269 /* Enable xDCI controller if enabled in devicetree and allowed */
270 dev = dev_find_slot(0, PCH_DEVFN_USBOTG);
271 if (!xdci_can_enable())
272 dev->enabled = 0;
273 params->XdciEnable = dev->enabled;
Pratik Prajapati9027e1b2017-08-23 17:37:43 -0700274
Lijian Zhao580bc412017-10-04 13:43:47 -0700275 /* PCI Express */
276 for (i = 0; i < ARRAY_SIZE(config->PcieClkSrcUsage); i++) {
277 if (config->PcieClkSrcUsage[i] == 0)
278 config->PcieClkSrcUsage[i] = PCIE_CLK_NOTUSED;
279 }
280 memcpy(params->PcieClkSrcUsage, config->PcieClkSrcUsage,
281 sizeof(config->PcieClkSrcUsage));
282 memcpy(params->PcieClkSrcClkReq, config->PcieClkSrcClkReq,
283 sizeof(config->PcieClkSrcClkReq));
284
Pratik Prajapati9027e1b2017-08-23 17:37:43 -0700285 /* eMMC and SD */
286 params->ScsEmmcEnabled = config->ScsEmmcEnabled;
287 params->ScsEmmcHs400Enabled = config->ScsEmmcHs400Enabled;
Lijian Zhao93fde112018-02-05 18:14:11 -0800288 params->PchScsEmmcHs400DllDataValid = config->EmmcHs400DllNeed;
289 if (config->EmmcHs400DllNeed == 1) {
290 params->PchScsEmmcHs400RxStrobeDll1 =
291 config->EmmcHs400RxStrobeDll1;
292 params->PchScsEmmcHs400TxDataDll = config->EmmcHs400TxDataDll;
293 }
Pratik Prajapati9027e1b2017-08-23 17:37:43 -0700294 params->ScsSdCardEnabled = config->ScsSdCardEnabled;
295 params->ScsUfsEnabled = config->ScsUfsEnabled;
296
297 params->Heci3Enabled = config->Heci3Enabled;
298 params->Device4Enable = config->Device4Enable;
Subrata Banikf699c142018-06-08 17:57:37 +0530299 params->SkipMpInit = !chip_get_fsp_mp_init();
Pratik Prajapati9027e1b2017-08-23 17:37:43 -0700300
301 /* VrConfig Settings for 5 domains
302 * 0 = System Agent, 1 = IA Core, 2 = Ring,
303 * 3 = GT unsliced, 4 = GT sliced */
304 for (i = 0; i < ARRAY_SIZE(config->domain_vr_config); i++)
305 fill_vr_domain_config(params, i, &config->domain_vr_config[i]);
Lijian Zhao91c8e232018-03-12 18:05:53 -0700306
307 /* Vt-D config */
308 tconfig->VtdDisable = config->VtdDisable;
Lijian Zhao2f764f72017-07-14 11:09:10 -0700309}
310
311/* Mainboard GPIO Configuration */
Aaron Durbin64031672018-04-21 14:45:32 -0600312__weak void mainboard_silicon_init_params(FSP_S_CONFIG *params)
Lijian Zhao2f764f72017-07-14 11:09:10 -0700313{
314 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
315}