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