blob: f4a9e8282b5f9e04f3036ebd1323db903686b852 [file] [log] [blame]
Andrey Petrov2e410752020-03-20 12:08:32 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Andrey Petrov2e410752020-03-20 12:08:32 -07002
3#include <arch/ioapic.h>
Andrey Petrov2e410752020-03-20 12:08:32 -07004#include <console/console.h>
Marc Jones8b522db2020-10-12 11:58:46 -06005#include <console/debug.h>
Andrey Petrov2e410752020-03-20 12:08:32 -07006#include <cpu/x86/lapic.h>
Marc Jones64c62232021-04-06 14:09:30 -06007#include <cpu/x86/mp.h>
Andrey Petrov2e410752020-03-20 12:08:32 -07008#include <device/pci.h>
Marc Jones456b7ba2021-04-15 16:24:54 -06009#include <device/pci_ids.h>
Marc Jones81ef9c22021-01-21 10:53:47 -070010#include <intelblocks/acpi.h>
Michael Niewöhner8913b782020-12-11 22:13:44 +010011#include <intelblocks/gpio.h>
Subrata Banik1366e442020-09-29 13:55:50 +053012#include <intelblocks/lpc_lib.h>
Andrey Petrov4e48ac02020-04-30 14:08:19 -070013#include <intelblocks/p2sb.h>
Jonathan Zhang3172f982020-05-28 17:53:48 -070014#include <soc/acpi.h>
Marc Jones1f500842020-10-15 14:32:51 -060015#include <soc/chip_common.h>
Andrey Petrov8670e822020-03-30 12:25:06 -070016#include <soc/cpu.h>
Marc Jones64c62232021-04-06 14:09:30 -060017#include <soc/msr.h>
Arthur Heymans3d802532020-11-12 21:17:56 +010018#include <soc/pch.h>
Andrey Petrov2e410752020-03-20 12:08:32 -070019#include <soc/ramstage.h>
Arthur Heymans0f91e9c2020-10-16 13:15:50 +020020#include <soc/p2sb.h>
Jonathan Zhang7919d612020-04-02 17:27:54 -070021#include <soc/soc_util.h>
Marc Jones5851f9d2020-11-02 15:30:10 -070022#include <soc/util.h>
Arthur Heymans0f91e9c2020-10-16 13:15:50 +020023#include <soc/pci_devs.h>
Jonathan Zhang7919d612020-04-02 17:27:54 -070024
Marc Jonesb9365ef2020-10-11 15:00:36 -060025/* UPD parameters to be initialized before SiliconInit */
Andrey Petrov2e410752020-03-20 12:08:32 -070026void platform_fsp_silicon_init_params_cb(FSPS_UPD *silupd)
27{
Marc Jonesb9365ef2020-10-11 15:00:36 -060028 mainboard_silicon_init_params(silupd);
Andrey Petrov2e410752020-03-20 12:08:32 -070029}
30
Jonathan Zhang1ba42a92020-09-21 17:14:44 -070031#if CONFIG(HAVE_ACPI_TABLES)
Marc Jones81ef9c22021-01-21 10:53:47 -070032const char *soc_acpi_name(const struct device *dev)
Jonathan Zhang1ba42a92020-09-21 17:14:44 -070033{
34 if (dev->path.type == DEVICE_PATH_DOMAIN)
35 return "PC00";
36 return NULL;
37}
38#endif
39
Andrey Petrov2e410752020-03-20 12:08:32 -070040static struct device_operations pci_domain_ops = {
41 .read_resources = &pci_domain_read_resources,
Marc Jones1f500842020-10-15 14:32:51 -060042 .set_resources = &xeonsp_pci_domain_set_resources,
43 .scan_bus = &xeonsp_pci_domain_scan_bus,
Jonathan Zhang1ba42a92020-09-21 17:14:44 -070044#if CONFIG(HAVE_ACPI_TABLES)
Jonathan Zhang3172f982020-05-28 17:53:48 -070045 .write_acpi_tables = &northbridge_write_acpi_tables,
Jonathan Zhang1ba42a92020-09-21 17:14:44 -070046 .acpi_name = soc_acpi_name
47#endif
Andrey Petrov2e410752020-03-20 12:08:32 -070048};
49
Andrey Petrov2e410752020-03-20 12:08:32 -070050static struct device_operations cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +020051 .read_resources = noop_read_resources,
52 .set_resources = noop_set_resources,
Andrey Petrov8670e822020-03-30 12:25:06 -070053 .init = cpx_init_cpus,
Jonathan Zhangc1105952020-06-03 15:55:28 -070054 .acpi_fill_ssdt = generate_cpu_entries,
Andrey Petrov2e410752020-03-20 12:08:32 -070055};
56
Andrey Petrov2e410752020-03-20 12:08:32 -070057struct pci_operations soc_pci_ops = {
58 .set_subsystem = pci_dev_set_subsystem,
59};
60
Jonathan Zhang7919d612020-04-02 17:27:54 -070061static void chip_enable_dev(struct device *dev)
62{
63 /* Set the operations if it is a special bus type */
64 if (dev->path.type == DEVICE_PATH_DOMAIN) {
65 dev->ops = &pci_domain_ops;
66 attach_iio_stacks(dev);
67 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
68 dev->ops = &cpu_bus_ops;
Michael Niewöhner8913b782020-12-11 22:13:44 +010069 } else if (dev->path.type == DEVICE_PATH_GPIO) {
70 block_gpio_enable(dev);
Jonathan Zhang7919d612020-04-02 17:27:54 -070071 }
72}
73
Rocky Phaguraafefa502021-02-16 21:45:24 -080074static void iio_write_mask(u16 bus, u16 dev, u8 func)
75{
76 pci_devfn_t device = PCI_DEV(bus, dev, func);
77 u32 val = pci_s_read_config32(device, IIO_XPUNCCERRMSK_REG);
78 val |= (SENT_PCIE_UNSUPP_MASK | RCVD_PCIE_CA_STS_MASK | RCVD_PCIE_UR_STS_MASK);
79 pci_s_write_config32(device, IIO_XPUNCCERRMSK_REG, val);
80
81 val = pci_s_read_config32(device, RP_UNCERRMSK);
82 val |= (SURPRISE_DWN_ERR_MSK | UNSUPPORTED_REQ_ERR_MSK);
83 pci_s_write_config32(device, RP_UNCERRMSK, val);
84}
85
86static void iio_dmi_en_masks(void)
87{
88 pci_devfn_t device;
89 u32 val;
90 device = PCI_DEV(DMI_BUS_INDEX, DMI_DEV, DMI_FUNC);
91 val = pci_s_read_config32(device, IIO_XPUNCCERRMSK_REG);
92 val |= (SENT_PCIE_UNSUPP_MASK | RCVD_PCIE_CA_STS_MASK | RCVD_PCIE_UR_STS_MASK);
93 pci_s_write_config32(device, IIO_XPUNCCERRMSK_REG, val);
94
95 val = pci_s_read_config32(device, DMI_UNCERRMSK);
96 val |= (ECRC_ERR | MLFRMD_TLP | RCV_BUF_OVRFLOW | FLOW_CNTR | POISON_TLP | DLL_PRT_ERR);
97 pci_s_write_config32(device, DMI_UNCERRMSK, val);
98}
99
100static void iio_enable_masks(void)
101{
102 struct iiostack_resource iio = {0};
103 get_iiostack_info(&iio);
104 int i, k;
105 for (i = 0; i < iio.no_of_stacks; i++) {
106 const STACK_RES *st = &iio.res[i];
107 if (st->BusBase > 0 && st->BusBase != 0xff) {
108 for (k = 0; k < DEVICES_PER_IIO_STACK; k++) {
109 printk(BIOS_DEBUG, "%s: bus:%x dev:%x func:%x\n", __func__,
110 st->BusBase, k, 0);
111 iio_write_mask(st->BusBase, k, 0);
112 }
113 }
114 }
115 iio_dmi_en_masks();
116}
Marc Jones4de76102021-03-12 14:36:48 -0700117
118static void set_pcu_locks(void)
119{
120 for (uint32_t socket = 0; socket < soc_get_num_cpus(); ++socket) {
121 uint32_t bus = get_socket_stack_busno(socket, PCU_IIO_STACK);
122
123 /* configure PCU_CR0_FUN csrs */
124 const struct device *cr0_dev = PCU_DEV_CR0(bus);
125 pci_or_config32(cr0_dev, PCU_CR0_P_STATE_LIMITS, P_STATE_LIMITS_LOCK);
126 pci_or_config32(cr0_dev, PCU_CR0_PACKAGE_RAPL_LIMIT_UPR, PKG_PWR_LIM_LOCK_UPR);
Marc Jones4fad28f2021-04-01 14:47:52 -0600127 pci_or_config32(cr0_dev, PCU_CR0_TURBO_ACTIVATION_RATIO, TURBO_ACTIVATION_RATIO_LOCK);
128
Marc Jones4de76102021-03-12 14:36:48 -0700129
130 /* configure PCU_CR1_FUN csrs */
131 const struct device *cr1_dev = PCU_DEV_CR1(bus);
132 pci_or_config32(cr1_dev, PCU_CR1_SAPMCTL, SAPMCTL_LOCK_MASK);
133
134 /* configure PCU_CR2_FUN csrs */
135 const struct device *cr2_dev = PCU_DEV_CR2(bus);
136 pci_or_config32(cr2_dev, PCU_CR2_DRAM_PLANE_POWER_LIMIT, PP_PWR_LIM_LOCK);
Marc Jones4fad28f2021-04-01 14:47:52 -0600137 pci_or_config32(cr2_dev, PCU_CR2_DRAM_POWER_INFO_UPR, DRAM_POWER_INFO_LOCK_UPR);
Marc Jones4de76102021-03-12 14:36:48 -0700138
139 /* configure PCU_CR3_FUN csrs */
140 const struct device *cr3_dev = PCU_DEV_CR3(bus);
141 pci_or_config32(cr3_dev, PCU_CR3_CONFIG_TDP_CONTROL, TDP_LOCK);
Marc Jones4fad28f2021-04-01 14:47:52 -0600142 pci_or_config32(cr3_dev, PCU_CR3_FLEX_RATIO, OC_LOCK);
Marc Jones4de76102021-03-12 14:36:48 -0700143 }
144
145}
146
Marc Jones64c62232021-04-06 14:09:30 -0600147static void set_msr_locks(void *unused)
148{
149 /* The MSRs and CSRS have the same register layout. Use the CSRS bit definitions */
150 msr_t msr;
151
152 /* Lock Turbo */
153 msr = rdmsr(MSR_TURBO_ACTIVATION_RATIO);
154 msr.lo |= (TURBO_ACTIVATION_RATIO_LOCK);
155 wrmsr(MSR_TURBO_ACTIVATION_RATIO, msr);
156
157 /* Lock AES enable */
158 msr = rdmsr(MSR_FEATURE_CONFIG);
159 msr.lo |= FEATURE_CONFIG_LOCK;
160 wrmsr(MSR_FEATURE_CONFIG, msr);
161}
162
Marc Jones456b7ba2021-04-15 16:24:54 -0600163static void set_imc_locks(void)
164{
165 struct device *dev = 0;
166 while ((dev = dev_find_device(PCI_VENDOR_ID_INTEL, IMC_M2MEM_DEVID, dev)))
167 pci_or_config32(dev, IMC_M2MEM_TIMEOUT, TIMEOUT_LOCK);
168}
169
Andrey Petrov2e410752020-03-20 12:08:32 -0700170static void chip_final(void *data)
171{
Arthur Heymans0f91e9c2020-10-16 13:15:50 +0200172 /* Lock SBI */
173 pci_or_config32(PCH_DEV_P2SB, P2SBC, SBILOCK);
Arthur Heymans19185532020-10-27 17:40:22 +0100174
175 /* LOCK PAM */
176 pci_or_config32(pcidev_path_on_root(PCI_DEVFN(0, 0)), 0x80, 1 << 0);
177
178 /*
179 * LOCK SMRAM
180 * According to the CedarIsland FSP Integration Guide this needs to
181 * be done with legacy 0xCF8/0xCFC IO ops.
182 */
183 uint8_t reg8 = pci_io_read_config8(PCI_DEV(0, 0, 0), 0x88);
184 pci_io_write_config8(PCI_DEV(0, 0, 0), 0x88, reg8 | (1 << 4));
185
Marc Jones64c62232021-04-06 14:09:30 -0600186 mp_run_on_all_cpus(set_msr_locks, NULL);
Marc Jones4de76102021-03-12 14:36:48 -0700187 set_pcu_locks();
Marc Jones456b7ba2021-04-15 16:24:54 -0600188 set_imc_locks();
Marc Jones4de76102021-03-12 14:36:48 -0700189
Andrey Petrov4e48ac02020-04-30 14:08:19 -0700190 p2sb_hide();
Rocky Phaguraafefa502021-02-16 21:45:24 -0800191 iio_enable_masks();
Jonathan Zhangbea19802020-04-13 19:34:53 -0700192 set_bios_init_completion();
Andrey Petrov2e410752020-03-20 12:08:32 -0700193}
194
195static void chip_init(void *data)
196{
197 printk(BIOS_DEBUG, "coreboot: calling fsp_silicon_init\n");
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +0200198 fsp_silicon_init();
Arthur Heymans3d802532020-11-12 21:17:56 +0100199 override_hpet_ioapic_bdf();
Subrata Banik1366e442020-09-29 13:55:50 +0530200 pch_enable_ioapic();
Arthur Heymans83463072020-12-16 11:30:40 +0100201 pch_lock_dmictl();
Andrey Petrov2e410752020-03-20 12:08:32 -0700202 setup_lapic();
Andrey Petrov4e48ac02020-04-30 14:08:19 -0700203 p2sb_unhide();
Andrey Petrov2e410752020-03-20 12:08:32 -0700204}
205
206struct chip_operations soc_intel_xeon_sp_cpx_ops = {
207 CHIP_NAME("Intel Cooperlake-SP")
208 .enable_dev = chip_enable_dev,
209 .init = chip_init,
Jonathan Zhang7919d612020-04-02 17:27:54 -0700210 .final = chip_final,
Andrey Petrov2e410752020-03-20 12:08:32 -0700211};