blob: ac42e0054aa4c7b5d0c91049bcdb5648f584b2fa [file] [log] [blame]
Angel Ponsf5627e82020-04-05 15:46:52 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Rizwan Qureshi742c6fe2018-09-18 22:43:41 +05302
3#include <assert.h>
Christian Walterb2f8ce72020-03-11 18:04:58 +01004#include <device/pci_def.h>
5#include <device/pci.h>
Lijian Zhao68890b92019-03-27 17:06:41 -07006#include <cpu/x86/msr.h>
Rizwan Qureshi742c6fe2018-09-18 22:43:41 +05307#include <console/console.h>
8#include <fsp/util.h>
Michael Niewöhner7736bfc2019-10-22 23:05:06 +02009#include <intelblocks/cpulib.h>
Duncan Laurie52b5b582019-01-23 14:55:47 -080010#include <intelblocks/pmclib.h>
Rizwan Qureshi742c6fe2018-09-18 22:43:41 +053011#include <soc/iomap.h>
Lijian Zhao68890b92019-03-27 17:06:41 -070012#include <soc/msr.h>
Rizwan Qureshi742c6fe2018-09-18 22:43:41 +053013#include <soc/pci_devs.h>
14#include <soc/romstage.h>
Duncan Laurie52b5b582019-01-23 14:55:47 -080015#include <vendorcode/google/chromeos/chromeos.h>
Rizwan Qureshi742c6fe2018-09-18 22:43:41 +053016
Elyes HAOUASc3385072019-03-21 15:38:06 +010017#include "../chip.h"
18
Christian Walterb2f8ce72020-03-11 18:04:58 +010019static void soc_memory_init_params(FSPM_UPD *mupd, const config_t *config)
Rizwan Qureshi742c6fe2018-09-18 22:43:41 +053020{
Christian Walterb2f8ce72020-03-11 18:04:58 +010021 FSP_M_CONFIG *m_cfg = &mupd->FspmConfig;
22 FSP_M_TEST_CONFIG *tconfig = &mupd->FspmTestConfig;
23
Rizwan Qureshi742c6fe2018-09-18 22:43:41 +053024 unsigned int i;
25 uint32_t mask = 0;
Christian Walterb2f8ce72020-03-11 18:04:58 +010026 const struct device *dev = pcidev_path_on_root(SA_DEVFN_IGD);
Rizwan Qureshi742c6fe2018-09-18 22:43:41 +053027
Christian Walterb2f8ce72020-03-11 18:04:58 +010028 /*
29 * Probe for no IGD and disable InternalGfx and panel power to prevent a
30 * crash in FSP-M.
31 */
32 if (dev && dev->enabled && pci_read_config16(SA_DEV_IGD, PCI_VENDOR_ID) != 0xffff) {
33 /* Set IGD stolen size to 64MB. */
34 m_cfg->InternalGfx = 1;
35 m_cfg->IgdDvmt50PreAlloc = 2;
36 } else {
37 m_cfg->InternalGfx = 0;
38 m_cfg->IgdDvmt50PreAlloc = 0;
39 tconfig->PanelPowerEnable = 0;
40 }
Rizwan Qureshi742c6fe2018-09-18 22:43:41 +053041 m_cfg->TsegSize = CONFIG_SMM_TSEG_SIZE;
42 m_cfg->IedSize = CONFIG_IED_REGION_SIZE;
43 m_cfg->SaGv = config->SaGv;
Julius Wernercd49cce2019-03-05 16:53:33 -080044 if (CONFIG(SOC_INTEL_CANNONLAKE_PCH_H))
praveen hodagatta praneshe26c4a42018-09-20 03:49:45 +080045 m_cfg->UserBd = BOARD_TYPE_DESKTOP;
46 else
47 m_cfg->UserBd = BOARD_TYPE_ULT_ULX;
Rizwan Qureshi742c6fe2018-09-18 22:43:41 +053048 m_cfg->RMT = config->RMT;
49
50 for (i = 0; i < ARRAY_SIZE(config->PcieRpEnable); i++) {
51 if (config->PcieRpEnable[i])
52 mask |= (1 << i);
53 }
54 m_cfg->PcieRpEnableMask = mask;
Michael Niewöhner7736bfc2019-10-22 23:05:06 +020055 m_cfg->PrmrrSize = get_prmrr_size();
Rizwan Qureshi742c6fe2018-09-18 22:43:41 +053056 m_cfg->EnableC6Dram = config->enable_c6dram;
Aamir Bohra2973d1e2019-05-17 12:31:51 +053057#if CONFIG(SOC_INTEL_COMETLAKE)
58 m_cfg->SerialIoUartDebugControllerNumber = CONFIG_UART_FOR_CONSOLE;
59#else
Rizwan Qureshi742c6fe2018-09-18 22:43:41 +053060 m_cfg->PcdSerialIoUartNumber = CONFIG_UART_FOR_CONSOLE;
Aamir Bohra2973d1e2019-05-17 12:31:51 +053061#endif
Maulik V Vaghelabfe4a592019-03-13 18:16:01 +053062 /*
63 * PcdDebugInterfaceFlags
64 * This config will allow coreboot to pass information to the FSP
65 * regarding which debug interface is being used.
66 * Debug Interfaces:
67 * BIT0-RAM, BIT1-Legacy Uart BIT3-USB3, BIT4-LPSS Uart, BIT5-TraceHub
68 * BIT2 - Not used.
69 */
70 m_cfg->PcdDebugInterfaceFlags =
71 CONFIG(DRIVERS_UART_8250IO) ? 0x02 : 0x10;
72
Ronak Kanabar250dfc02019-03-29 13:25:09 +053073 /* Change VmxEnable UPD value according to ENABLE_VMX Kconfig */
74 m_cfg->VmxEnable = CONFIG(ENABLE_VMX);
Subrata Banikcf32fd12018-12-19 18:02:17 +053075
Arthur Heymans4821a0e2019-06-18 13:19:29 +020076#if CONFIG(SOC_INTEL_CANNONLAKE_ALTERNATE_HEADERS)
Martin Rothc25c1eb2020-07-24 12:26:21 -060077 m_cfg->SkipMpInit = !CONFIG(USE_INTEL_FSP_MP_INIT);
Rizwan Qureshi742c6fe2018-09-18 22:43:41 +053078#endif
Duncan Laurie52b5b582019-01-23 14:55:47 -080079
Subrata Banike1470ea2019-11-18 14:08:08 +053080 if (config->cpu_ratio_override) {
81 m_cfg->CpuRatio = config->cpu_ratio_override;
82 } else {
83 /* Set CpuRatio to match existing MSR value */
84 msr_t flex_ratio;
85 flex_ratio = rdmsr(MSR_FLEX_RATIO);
86 m_cfg->CpuRatio = (flex_ratio.lo >> 8) & 0xff;
87 }
Duncan Laurie52b5b582019-01-23 14:55:47 -080088
Christian Walterb2f8ce72020-03-11 18:04:58 +010089 dev = pcidev_path_on_root(PCH_DEVFN_ISH);
Lijian Zhaofe701ee2018-10-25 09:29:10 -070090 /* If ISH is enabled, enable ISH elements */
91 if (!dev)
92 m_cfg->PchIshEnable = 0;
93 else
94 m_cfg->PchIshEnable = dev->enabled;
Lijian Zhao3ef74492018-12-06 17:29:55 -080095
96 /* If HDA is enabled, enable HDA elements */
Kyösti Mälkki903b40a2019-07-03 07:25:59 +030097 dev = pcidev_path_on_root(PCH_DEVFN_HDA);
Lijian Zhao3ef74492018-12-06 17:29:55 -080098 if (!dev)
99 m_cfg->PchHdaEnable = 0;
100 else
101 m_cfg->PchHdaEnable = dev->enabled;
102
V Sowmya0bc3e3d2019-01-07 13:11:29 +0530103 /* Enable IPU only if the device is enabled */
104 m_cfg->SaIpuEnable = 0;
105 dev = pcidev_path_on_root(SA_DEVFN_IPU);
106 if (dev)
107 m_cfg->SaIpuEnable = dev->enabled;
Jamie Chenc004857da2020-01-15 11:17:21 +0800108
109 /* SATA Gen3 strength */
110 for (i = 0; i < SOC_INTEL_CML_SATA_DEV_MAX; i++) {
111 if (config->sata_port[i].RxGen3EqBoostMagEnable) {
112 m_cfg->PchSataHsioRxGen3EqBoostMagEnable[i] =
113 config->sata_port[i].RxGen3EqBoostMagEnable;
114 m_cfg->PchSataHsioRxGen3EqBoostMag[i] =
115 config->sata_port[i].RxGen3EqBoostMag;
116 }
117 if (config->sata_port[i].TxGen3DownscaleAmpEnable) {
118 m_cfg->PchSataHsioTxGen3DownscaleAmpEnable[i] =
119 config->sata_port[i].TxGen3DownscaleAmpEnable;
120 m_cfg->PchSataHsioTxGen3DownscaleAmp[i] =
121 config->sata_port[i].TxGen3DownscaleAmp;
122 }
123 if (config->sata_port[i].TxGen3DeEmphEnable) {
124 m_cfg->PchSataHsioTxGen3DeEmphEnable[i] =
125 config->sata_port[i].TxGen3DeEmphEnable;
126 m_cfg->PchSataHsioTxGen3DeEmph[i] =
127 config->sata_port[i].TxGen3DeEmph;
128 }
129 }
Christian Waltere01054d2020-04-27 18:11:51 +0200130#if !CONFIG(SOC_INTEL_COMETLAKE)
131 if (config->DisableHeciRetry)
132 tconfig->DisableHeciRetry = config->DisableHeciRetry;
133#endif
Rizwan Qureshi742c6fe2018-09-18 22:43:41 +0530134}
135
136void platform_fsp_memory_init_params_cb(FSPM_UPD *mupd, uint32_t version)
137{
Kyösti Mälkki903b40a2019-07-03 07:25:59 +0300138 const struct device *dev = pcidev_path_on_root(PCH_DEVFN_LPC);
139 const struct device *smbus = pcidev_path_on_root(PCH_DEVFN_SMBUS);
Rizwan Qureshi742c6fe2018-09-18 22:43:41 +0530140 assert(dev != NULL);
Kyösti Mälkki8950cfb2019-07-13 22:16:25 +0300141 const config_t *config = config_of(dev);
Rizwan Qureshi742c6fe2018-09-18 22:43:41 +0530142 FSP_M_CONFIG *m_cfg = &mupd->FspmConfig;
John Zhao1159a162019-04-22 10:45:51 -0700143 FSP_M_TEST_CONFIG *tconfig = &mupd->FspmTestConfig;
Rizwan Qureshi742c6fe2018-09-18 22:43:41 +0530144
Christian Walterb2f8ce72020-03-11 18:04:58 +0100145 soc_memory_init_params(mupd, config);
Rizwan Qureshi742c6fe2018-09-18 22:43:41 +0530146
147 /* Enable SMBus controller based on config */
Duncan Laurie25b387a2018-11-08 15:48:14 -0700148 if (!smbus)
149 m_cfg->SmbusEnable = 0;
150 else
151 m_cfg->SmbusEnable = smbus->enabled;
Rizwan Qureshi742c6fe2018-09-18 22:43:41 +0530152
Kane Chen37172562019-04-11 21:55:20 +0800153 /* Set debug probe type */
154 m_cfg->PlatformDebugConsent =
155 CONFIG_SOC_INTEL_CANNONLAKE_DEBUG_CONSENT;
John Zhao1159a162019-04-22 10:45:51 -0700156
157 /* Configure VT-d */
158 tconfig->VtdDisable = 0;
159
Sridhar Siricillaa91c9192020-08-05 16:16:52 +0530160 /* Set HECI1 PCI BAR address */
161 m_cfg->Heci1BarAddress = HECI1_BASE_ADDRESS;
162
Rizwan Qureshi742c6fe2018-09-18 22:43:41 +0530163 mainboard_memory_init_params(mupd);
164}
165
166__weak void mainboard_memory_init_params(FSPM_UPD *mupd)
167{
168 printk(BIOS_DEBUG, "WEAK: %s/%s called\n", __FILE__, __func__);
169}