Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <assert.h> |
Subrata Banik | 99289a8 | 2020-12-22 10:54:44 +0530 | [diff] [blame] | 4 | #include <cbfs.h> |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 5 | #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 Lai | 5b302b2 | 2020-12-05 16:49:43 +0800 | [diff] [blame^] | 18 | #include <soc/pcie.h> |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 19 | #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 | */ |
| 44 | static 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 | |
| 51 | static 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 | |
| 69 | static 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 */ |
| 91 | void platform_fsp_silicon_init_params_cb(FSPS_UPD *supd) |
| 92 | { |
| 93 | int i; |
Subrata Banik | 99289a8 | 2020-12-22 10:54:44 +0530 | [diff] [blame] | 94 | const struct microcode *microcode_file; |
| 95 | size_t microcode_len; |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 96 | FSP_S_CONFIG *params = &supd->FspsConfig; |
Eric Lai | 5b302b2 | 2020-12-05 16:49:43 +0800 | [diff] [blame^] | 97 | uint32_t enable_mask; |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 98 | |
| 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 Banik | 99289a8 | 2020-12-22 10:54:44 +0530 | [diff] [blame] | 107 | microcode_file = cbfs_map("cpu_microcode_blob.bin", µcode_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 Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 115 | /* 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); |
| 121 | |
| 122 | /* Use coreboot MP PPI services if Kconfig is enabled */ |
| 123 | if (CONFIG(USE_INTEL_FSP_TO_CALL_COREBOOT_PUBLISH_MP_PPI)) |
| 124 | params->CpuMpPpi = (uintptr_t) mp_fill_ppi_services_data(); |
| 125 | |
| 126 | /* D3Hot and D3Cold for TCSS */ |
| 127 | params->D3HotEnable = !config->TcssD3HotDisable; |
| 128 | params->D3ColdEnable = !config->TcssD3ColdDisable; |
| 129 | |
| 130 | params->TcssAuxOri = config->TcssAuxOri; |
| 131 | for (i = 0; i < 8; i++) |
| 132 | params->IomTypeCPortPadCfg[i] = config->IomTypeCPortPadCfg[i]; |
| 133 | |
| 134 | /* |
| 135 | * Set FSPS UPD ITbtConnectTopologyTimeoutInMs with value 0. FSP will |
| 136 | * evaluate this UPD value and skip sending command. There will be no |
| 137 | * delay for command completion. |
| 138 | */ |
| 139 | params->ITbtConnectTopologyTimeoutInMs = 0; |
| 140 | |
| 141 | /* Chipset Lockdown */ |
| 142 | if (get_lockdown_config() == CHIPSET_LOCKDOWN_COREBOOT) { |
| 143 | params->PchLockDownGlobalSmi = 0; |
| 144 | params->PchLockDownBiosInterface = 0; |
| 145 | params->PchUnlockGpioPads = 1; |
| 146 | params->RtcMemoryLock = 0; |
| 147 | } else { |
| 148 | params->PchLockDownGlobalSmi = 1; |
| 149 | params->PchLockDownBiosInterface = 1; |
| 150 | params->PchUnlockGpioPads = 0; |
| 151 | params->RtcMemoryLock = 1; |
| 152 | } |
| 153 | |
| 154 | /* USB */ |
| 155 | for (i = 0; i < ARRAY_SIZE(config->usb2_ports); i++) { |
| 156 | params->PortUsb20Enable[i] = config->usb2_ports[i].enable; |
| 157 | params->Usb2PhyPetxiset[i] = config->usb2_ports[i].pre_emp_bias; |
| 158 | params->Usb2PhyTxiset[i] = config->usb2_ports[i].tx_bias; |
| 159 | params->Usb2PhyPredeemp[i] = config->usb2_ports[i].tx_emp_enable; |
| 160 | params->Usb2PhyPehalfbit[i] = config->usb2_ports[i].pre_emp_bit; |
| 161 | |
| 162 | if (config->usb2_ports[i].enable) |
| 163 | params->Usb2OverCurrentPin[i] = config->usb2_ports[i].ocpin; |
| 164 | else |
| 165 | params->Usb2OverCurrentPin[i] = OC_SKIP; |
| 166 | } |
| 167 | |
| 168 | for (i = 0; i < ARRAY_SIZE(config->usb3_ports); i++) { |
| 169 | params->PortUsb30Enable[i] = config->usb3_ports[i].enable; |
| 170 | if (config->usb3_ports[i].enable) |
| 171 | params->Usb3OverCurrentPin[i] = config->usb3_ports[i].ocpin; |
| 172 | else |
| 173 | params->Usb3OverCurrentPin[i] = OC_SKIP; |
| 174 | |
| 175 | if (config->usb3_ports[i].tx_de_emp) { |
| 176 | params->Usb3HsioTxDeEmphEnable[i] = 1; |
| 177 | params->Usb3HsioTxDeEmph[i] = config->usb3_ports[i].tx_de_emp; |
| 178 | } |
| 179 | if (config->usb3_ports[i].tx_downscale_amp) { |
| 180 | params->Usb3HsioTxDownscaleAmpEnable[i] = 1; |
| 181 | params->Usb3HsioTxDownscaleAmp[i] = |
| 182 | config->usb3_ports[i].tx_downscale_amp; |
| 183 | } |
| 184 | } |
| 185 | |
| 186 | /* Enable xDCI controller if enabled in devicetree and allowed */ |
| 187 | dev = pcidev_path_on_root(PCH_DEVFN_USBOTG); |
| 188 | if (dev) { |
| 189 | if (!xdci_can_enable()) |
| 190 | dev->enabled = 0; |
| 191 | params->XdciEnable = dev->enabled; |
| 192 | } else { |
| 193 | params->XdciEnable = 0; |
| 194 | } |
| 195 | |
| 196 | /* PCH UART selection for FSP Debug */ |
| 197 | params->SerialIoDebugUartNumber = CONFIG_UART_FOR_CONSOLE; |
| 198 | ASSERT(ARRAY_SIZE(params->SerialIoUartAutoFlow) > CONFIG_UART_FOR_CONSOLE); |
| 199 | params->SerialIoUartAutoFlow[CONFIG_UART_FOR_CONSOLE] = 0; |
| 200 | |
| 201 | /* SATA */ |
| 202 | dev = pcidev_path_on_root(PCH_DEVFN_SATA); |
| 203 | params->SataEnable = is_dev_enabled(dev); |
| 204 | if (params->SataEnable) { |
| 205 | params->SataMode = config->SataMode; |
| 206 | params->SataSalpSupport = config->SataSalpSupport; |
| 207 | memcpy(params->SataPortsEnable, config->SataPortsEnable, |
| 208 | sizeof(params->SataPortsEnable)); |
| 209 | memcpy(params->SataPortsDevSlp, config->SataPortsDevSlp, |
| 210 | sizeof(params->SataPortsDevSlp)); |
| 211 | } |
| 212 | |
| 213 | /* |
| 214 | * Power Optimizer for DMI and SATA. |
| 215 | * DmiPwrOptimizeDisable and SataPwrOptimizeDisable is default to 0. |
| 216 | * Boards not needing the optimizers explicitly disables them by setting |
| 217 | * these disable variables to 1 in devicetree overrides. |
| 218 | */ |
| 219 | params->PchPwrOptEnable = !(config->DmiPwrOptimizeDisable); |
| 220 | params->SataPwrOptEnable = !(config->SataPwrOptimizeDisable); |
| 221 | |
| 222 | /* |
| 223 | * Enable DEVSLP Idle Timeout settings DmVal and DitoVal. |
| 224 | * SataPortsDmVal is the DITO multiplier. Default is 15. |
| 225 | * SataPortsDitoVal is the DEVSLP Idle Timeout (DITO), Default is 625ms. |
| 226 | * The default values can be changed from devicetree. |
| 227 | */ |
| 228 | for (i = 0; i < ARRAY_SIZE(config->SataPortsEnableDitoConfig); i++) { |
| 229 | if (config->SataPortsEnableDitoConfig[i]) { |
| 230 | params->SataPortsDmVal[i] = config->SataPortsDmVal[i]; |
| 231 | params->SataPortsDitoVal[i] = config->SataPortsDitoVal[i]; |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | /* Enable TCPU for processor thermal control */ |
| 236 | dev = pcidev_path_on_root(SA_DEVFN_DPTF); |
| 237 | params->Device4Enable = is_dev_enabled(dev); |
| 238 | |
| 239 | /* Set TccActivationOffset */ |
| 240 | params->TccActivationOffset = config->tcc_offset; |
| 241 | |
| 242 | /* LAN */ |
| 243 | dev = pcidev_path_on_root(PCH_DEVFN_GBE); |
| 244 | params->PchLanEnable = is_dev_enabled(dev); |
| 245 | |
| 246 | /* CNVi */ |
| 247 | dev = pcidev_path_on_root(PCH_DEVFN_CNVI_WIFI); |
| 248 | params->CnviMode = is_dev_enabled(dev); |
| 249 | |
| 250 | /* CNVi BT Core */ |
| 251 | dev = pcidev_path_on_root(PCH_DEVFN_CNVI_BT); |
| 252 | params->CnviBtCore = is_dev_enabled(dev); |
| 253 | |
| 254 | /* CNVi BT Audio Offload */ |
| 255 | params->CnviBtAudioOffload = config->CnviBtAudioOffload; |
| 256 | |
| 257 | /* VMD */ |
| 258 | dev = pcidev_path_on_root(SA_DEVFN_VMD); |
| 259 | params->VmdEnable = is_dev_enabled(dev); |
| 260 | |
| 261 | /* THC */ |
| 262 | dev = pcidev_path_on_root(PCH_DEVFN_THC0); |
| 263 | params->ThcPort0Assignment = is_dev_enabled(dev) ? THC_0 : THC_NONE; |
| 264 | |
| 265 | dev = pcidev_path_on_root(PCH_DEVFN_THC1); |
| 266 | params->ThcPort1Assignment = is_dev_enabled(dev) ? THC_1 : THC_NONE; |
| 267 | |
| 268 | /* Legacy 8254 timer support */ |
| 269 | params->Enable8254ClockGating = !CONFIG(USE_LEGACY_8254_TIMER); |
| 270 | params->Enable8254ClockGatingOnS3 = !CONFIG(USE_LEGACY_8254_TIMER); |
| 271 | |
| 272 | /* Enable Hybrid storage auto detection */ |
| 273 | params->HybridStorageMode = config->HybridStorageMode; |
| 274 | |
Eric Lai | 5b302b2 | 2020-12-05 16:49:43 +0800 | [diff] [blame^] | 275 | enable_mask = pcie_rp_enable_mask(get_pch_pcie_rp_table()); |
Subrata Banik | 85144d9 | 2021-01-09 16:17:45 +0530 | [diff] [blame] | 276 | for (i = 0; i < CONFIG_MAX_PCH_ROOT_PORTS; i++) { |
Eric Lai | 5b302b2 | 2020-12-05 16:49:43 +0800 | [diff] [blame^] | 277 | if (!(enable_mask & BIT(i))) |
| 278 | continue; |
| 279 | const struct pcie_rp_config *rp_cfg = &config->pch_pcie_rp[i]; |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 280 | params->PcieRpL1Substates[i] = |
Eric Lai | 5b302b2 | 2020-12-05 16:49:43 +0800 | [diff] [blame^] | 281 | get_l1_substate_control(rp_cfg->PcieRpL1Substates); |
| 282 | params->PcieRpLtrEnable[i] = !!(rp_cfg->flags & PCIE_RP_LTR); |
| 283 | params->PcieRpAdvancedErrorReporting[i] = !!(rp_cfg->flags & PCIE_RP_AER); |
| 284 | params->PcieRpHotPlug[i] = !!(rp_cfg->flags & PCIE_RP_HOTPLUG); |
| 285 | params->PcieRpClkReqDetect[i] = !!(rp_cfg->flags & PCIE_RP_CLK_REQ_DETECT); |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 286 | } |
| 287 | |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 288 | params->PmSupport = 1; |
| 289 | params->Hwp = 1; |
| 290 | params->Cx = 1; |
| 291 | params->PsOnEnable = 1; |
| 292 | |
| 293 | mainboard_silicon_init_params(params); |
| 294 | } |
| 295 | |
| 296 | int soc_fsp_multi_phase_init_is_enable(void) |
| 297 | { |
| 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | /* |
| 302 | * Callbacks for SoC/Mainboard specific overrides for FspMultiPhaseSiInit |
| 303 | * This platform supports below MultiPhaseSIInit Phase(s): |
| 304 | * Phase | FSP return point | Purpose |
| 305 | * ------- + ------------------------------------------------ + ------------------------------- |
| 306 | * 1 | After TCSS initialization completed | for TCSS specific init |
| 307 | */ |
| 308 | void platform_fsp_multi_phase_init_cb(uint32_t phase_index) |
| 309 | { |
| 310 | switch (phase_index) { |
| 311 | case 1: |
| 312 | /* TCSS specific initialization here */ |
| 313 | break; |
| 314 | default: |
| 315 | break; |
| 316 | } |
| 317 | } |
| 318 | |
| 319 | /* Mainboard GPIO Configuration */ |
| 320 | __weak void mainboard_silicon_init_params(FSP_S_CONFIG *params) |
| 321 | { |
| 322 | printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__); |
| 323 | } |
| 324 | |
| 325 | /* Return list of SOC LPSS controllers */ |
| 326 | const pci_devfn_t *soc_lpss_controllers_list(size_t *size) |
| 327 | { |
| 328 | *size = ARRAY_SIZE(serial_io_dev); |
| 329 | return serial_io_dev; |
| 330 | } |