Lijian Zhao | 2f764f7 | 2017-07-14 11:09:10 -0700 | [diff] [blame] | 1 | /* |
| 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 Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 17 | #include <compiler.h> |
Lijian Zhao | 2f764f7 | 2017-07-14 11:09:10 -0700 | [diff] [blame] | 18 | #include <console/console.h> |
Pratik Prajapati | 201fa8f | 2017-08-16 11:42:40 -0700 | [diff] [blame] | 19 | #include <device/device.h> |
Lijian Zhao | 2f764f7 | 2017-07-14 11:09:10 -0700 | [diff] [blame] | 20 | #include <device/pci.h> |
| 21 | #include <fsp/api.h> |
Lijian Zhao | 2f764f7 | 2017-07-14 11:09:10 -0700 | [diff] [blame] | 22 | #include <fsp/util.h> |
Subrata Banik | 98376b8 | 2018-05-22 16:18:16 +0530 | [diff] [blame] | 23 | #include <intelblocks/acpi.h> |
Subrata Banik | f699c14 | 2018-06-08 17:57:37 +0530 | [diff] [blame^] | 24 | #include <intelblocks/chip.h> |
Duncan Laurie | 2410cd9 | 2018-03-26 02:25:07 -0700 | [diff] [blame] | 25 | #include <intelblocks/xdci.h> |
Lijian Zhao | 2f764f7 | 2017-07-14 11:09:10 -0700 | [diff] [blame] | 26 | #include <romstage_handoff.h> |
Abhay kumar | fcf8820 | 2017-09-20 15:17:42 -0700 | [diff] [blame] | 27 | #include <soc/intel/common/vbt.h> |
Pratik Prajapati | 9027e1b | 2017-08-23 17:37:43 -0700 | [diff] [blame] | 28 | #include <soc/pci_devs.h> |
Lijian Zhao | 2f764f7 | 2017-07-14 11:09:10 -0700 | [diff] [blame] | 29 | #include <soc/ramstage.h> |
| 30 | #include <string.h> |
| 31 | |
Lijian Zhao | 2b074d9 | 2017-08-17 14:25:24 -0700 | [diff] [blame] | 32 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
Subrata Banik | 98376b8 | 2018-05-22 16:18:16 +0530 | [diff] [blame] | 33 | const char *soc_acpi_name(const struct device *dev) |
Lijian Zhao | 2b074d9 | 2017-08-17 14:25:24 -0700 | [diff] [blame] | 34 | { |
| 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 Zhao | 580bc41 | 2017-10-04 13:43:47 -0700 | [diff] [blame] | 73 | 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 Zhao | 2b074d9 | 2017-08-17 14:25:24 -0700 | [diff] [blame] | 77 | 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 Zhao | 0823183 | 2017-09-05 18:16:21 -0700 | [diff] [blame] | 98 | static 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 Zhao | 2f764f7 | 2017-07-14 11:09:10 -0700 | [diff] [blame] | 135 | void soc_init_pre_device(void *chip_info) |
| 136 | { |
| 137 | /* Perform silicon specific init. */ |
| 138 | fsp_silicon_init(romstage_handoff_is_resume()); |
Subrata Banik | a8733e3 | 2018-01-23 16:40:56 +0530 | [diff] [blame] | 139 | |
| 140 | /* Display FIRMWARE_VERSION_INFO_HOB */ |
| 141 | fsp_display_fvi_version_hob(); |
Lijian Zhao | 2f764f7 | 2017-07-14 11:09:10 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Elyes HAOUAS | 3c8b5d0 | 2018-05-27 16:57:24 +0200 | [diff] [blame] | 144 | static void pci_domain_set_resources(struct device *dev) |
Pratik Prajapati | 201fa8f | 2017-08-16 11:42:40 -0700 | [diff] [blame] | 145 | { |
| 146 | assign_resources(dev->link_list); |
| 147 | } |
| 148 | |
| 149 | static 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 Zhao | 2b074d9 | 2017-08-17 14:25:24 -0700 | [diff] [blame] | 153 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
| 154 | .acpi_name = &soc_acpi_name, |
| 155 | #endif |
Pratik Prajapati | 201fa8f | 2017-08-16 11:42:40 -0700 | [diff] [blame] | 156 | }; |
| 157 | |
| 158 | static 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 Saha | 95b6175 | 2017-10-04 23:08:40 -0700 | [diff] [blame] | 163 | .acpi_fill_ssdt_generator = generate_cpu_entries, |
Pratik Prajapati | 201fa8f | 2017-08-16 11:42:40 -0700 | [diff] [blame] | 164 | }; |
| 165 | |
Elyes HAOUAS | 3c8b5d0 | 2018-05-27 16:57:24 +0200 | [diff] [blame] | 166 | static void soc_enable(struct device *dev) |
Pratik Prajapati | 201fa8f | 2017-08-16 11:42:40 -0700 | [diff] [blame] | 167 | { |
| 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 Zhao | 2f764f7 | 2017-07-14 11:09:10 -0700 | [diff] [blame] | 175 | struct chip_operations soc_intel_cannonlake_ops = { |
| 176 | CHIP_NAME("Intel Cannonlake") |
Pratik Prajapati | 201fa8f | 2017-08-16 11:42:40 -0700 | [diff] [blame] | 177 | .enable_dev = &soc_enable, |
Lijian Zhao | 2f764f7 | 2017-07-14 11:09:10 -0700 | [diff] [blame] | 178 | .init = &soc_init_pre_device, |
| 179 | }; |
| 180 | |
| 181 | /* UPD parameters to be initialized before SiliconInit */ |
| 182 | void platform_fsp_silicon_init_params_cb(FSPS_UPD *supd) |
| 183 | { |
| 184 | int i; |
| 185 | FSP_S_CONFIG *params = &supd->FspsConfig; |
Lijian Zhao | 91c8e23 | 2018-03-12 18:05:53 -0700 | [diff] [blame] | 186 | FSP_S_TEST_CONFIG *tconfig = &supd->FspsTestConfig; |
Duncan Laurie | 2410cd9 | 2018-03-26 02:25:07 -0700 | [diff] [blame] | 187 | struct device *dev = SA_DEV_ROOT; |
Lijian Zhao | 580bc41 | 2017-10-04 13:43:47 -0700 | [diff] [blame] | 188 | config_t *config = dev->chip_info; |
Lijian Zhao | 2f764f7 | 2017-07-14 11:09:10 -0700 | [diff] [blame] | 189 | |
Lijian Zhao | 0823183 | 2017-09-05 18:16:21 -0700 | [diff] [blame] | 190 | /* Parse device tree and enable/disable devices */ |
| 191 | parse_devicetree(params); |
| 192 | |
Abhay kumar | fcf8820 | 2017-09-20 15:17:42 -0700 | [diff] [blame] | 193 | /* Load VBT before devicetree-specific config. */ |
Patrick Georgi | 2257959 | 2017-10-06 17:36:09 +0200 | [diff] [blame] | 194 | params->GraphicsConfigPtr = (uintptr_t)vbt_get(); |
Abhay kumar | fcf8820 | 2017-09-20 15:17:42 -0700 | [diff] [blame] | 195 | |
Lijian Zhao | 2f764f7 | 2017-07-14 11:09:10 -0700 | [diff] [blame] | 196 | /* 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 Prajapati | 9027e1b | 2017-08-23 17:37:43 -0700 | [diff] [blame] | 206 | |
Caveh Jalali | 21df67e | 2018-03-08 17:58:21 -0800 | [diff] [blame] | 207 | /* Unlock upper 8 bytes of RTC RAM */ |
| 208 | params->PchLockDownRtcMemoryLock = 0; |
| 209 | |
Pratik Prajapati | 9027e1b | 2017-08-23 17:37:43 -0700 | [diff] [blame] | 210 | /* 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 Zhao | 416ded8 | 2018-01-23 21:58:36 -0800 | [diff] [blame] | 225 | 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 Prajapati | 9027e1b | 2017-08-23 17:37:43 -0700 | [diff] [blame] | 234 | |
Vaibhav Shankar | 2da6ec4 | 2018-03-19 18:56:38 -0700 | [diff] [blame] | 235 | /* S0ix */ |
| 236 | params->PchPmSlpS0Enable = config->s0ix_enable; |
| 237 | |
Pratik Prajapati | 9027e1b | 2017-08-23 17:37:43 -0700 | [diff] [blame] | 238 | /* 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 Laurie | 2410cd9 | 2018-03-26 02:25:07 -0700 | [diff] [blame] | 269 | /* 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 Prajapati | 9027e1b | 2017-08-23 17:37:43 -0700 | [diff] [blame] | 274 | |
Lijian Zhao | 580bc41 | 2017-10-04 13:43:47 -0700 | [diff] [blame] | 275 | /* 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 Prajapati | 9027e1b | 2017-08-23 17:37:43 -0700 | [diff] [blame] | 285 | /* eMMC and SD */ |
| 286 | params->ScsEmmcEnabled = config->ScsEmmcEnabled; |
| 287 | params->ScsEmmcHs400Enabled = config->ScsEmmcHs400Enabled; |
Lijian Zhao | 93fde11 | 2018-02-05 18:14:11 -0800 | [diff] [blame] | 288 | params->PchScsEmmcHs400DllDataValid = config->EmmcHs400DllNeed; |
| 289 | if (config->EmmcHs400DllNeed == 1) { |
| 290 | params->PchScsEmmcHs400RxStrobeDll1 = |
| 291 | config->EmmcHs400RxStrobeDll1; |
| 292 | params->PchScsEmmcHs400TxDataDll = config->EmmcHs400TxDataDll; |
| 293 | } |
Pratik Prajapati | 9027e1b | 2017-08-23 17:37:43 -0700 | [diff] [blame] | 294 | params->ScsSdCardEnabled = config->ScsSdCardEnabled; |
| 295 | params->ScsUfsEnabled = config->ScsUfsEnabled; |
| 296 | |
| 297 | params->Heci3Enabled = config->Heci3Enabled; |
| 298 | params->Device4Enable = config->Device4Enable; |
Subrata Banik | f699c14 | 2018-06-08 17:57:37 +0530 | [diff] [blame^] | 299 | params->SkipMpInit = !chip_get_fsp_mp_init(); |
Pratik Prajapati | 9027e1b | 2017-08-23 17:37:43 -0700 | [diff] [blame] | 300 | |
| 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 Zhao | 91c8e23 | 2018-03-12 18:05:53 -0700 | [diff] [blame] | 306 | |
| 307 | /* Vt-D config */ |
| 308 | tconfig->VtdDisable = config->VtdDisable; |
Lijian Zhao | 2f764f7 | 2017-07-14 11:09:10 -0700 | [diff] [blame] | 309 | } |
| 310 | |
| 311 | /* Mainboard GPIO Configuration */ |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 312 | __weak void mainboard_silicon_init_params(FSP_S_CONFIG *params) |
Lijian Zhao | 2f764f7 | 2017-07-14 11:09:10 -0700 | [diff] [blame] | 313 | { |
| 314 | printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__); |
| 315 | } |