blob: 34e0e27936a011d5c5389a461b27011ac66f4cc4 [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 Jones81ef9c22021-01-21 10:53:47 -07009#include <intelblocks/acpi.h>
Michael Niewöhner8913b782020-12-11 22:13:44 +010010#include <intelblocks/gpio.h>
Subrata Banik1366e442020-09-29 13:55:50 +053011#include <intelblocks/lpc_lib.h>
Andrey Petrov4e48ac02020-04-30 14:08:19 -070012#include <intelblocks/p2sb.h>
Jonathan Zhang3172f982020-05-28 17:53:48 -070013#include <soc/acpi.h>
Marc Jones1f500842020-10-15 14:32:51 -060014#include <soc/chip_common.h>
Andrey Petrov8670e822020-03-30 12:25:06 -070015#include <soc/cpu.h>
Marc Jones64c62232021-04-06 14:09:30 -060016#include <soc/msr.h>
Arthur Heymans3d802532020-11-12 21:17:56 +010017#include <soc/pch.h>
Andrey Petrov2e410752020-03-20 12:08:32 -070018#include <soc/ramstage.h>
Arthur Heymans0f91e9c2020-10-16 13:15:50 +020019#include <soc/p2sb.h>
Jonathan Zhang7919d612020-04-02 17:27:54 -070020#include <soc/soc_util.h>
Marc Jones5851f9d2020-11-02 15:30:10 -070021#include <soc/util.h>
Arthur Heymans0f91e9c2020-10-16 13:15:50 +020022#include <soc/pci_devs.h>
Jonathan Zhang7919d612020-04-02 17:27:54 -070023
Marc Jonesb9365ef2020-10-11 15:00:36 -060024/* UPD parameters to be initialized before SiliconInit */
Andrey Petrov2e410752020-03-20 12:08:32 -070025void platform_fsp_silicon_init_params_cb(FSPS_UPD *silupd)
26{
Marc Jonesb9365ef2020-10-11 15:00:36 -060027 mainboard_silicon_init_params(silupd);
Andrey Petrov2e410752020-03-20 12:08:32 -070028}
29
Jonathan Zhang1ba42a92020-09-21 17:14:44 -070030#if CONFIG(HAVE_ACPI_TABLES)
Marc Jones81ef9c22021-01-21 10:53:47 -070031const char *soc_acpi_name(const struct device *dev)
Jonathan Zhang1ba42a92020-09-21 17:14:44 -070032{
33 if (dev->path.type == DEVICE_PATH_DOMAIN)
34 return "PC00";
35 return NULL;
36}
37#endif
38
Andrey Petrov2e410752020-03-20 12:08:32 -070039static struct device_operations pci_domain_ops = {
40 .read_resources = &pci_domain_read_resources,
Marc Jones1f500842020-10-15 14:32:51 -060041 .set_resources = &xeonsp_pci_domain_set_resources,
42 .scan_bus = &xeonsp_pci_domain_scan_bus,
Jonathan Zhang1ba42a92020-09-21 17:14:44 -070043#if CONFIG(HAVE_ACPI_TABLES)
Jonathan Zhang3172f982020-05-28 17:53:48 -070044 .write_acpi_tables = &northbridge_write_acpi_tables,
Jonathan Zhang1ba42a92020-09-21 17:14:44 -070045 .acpi_name = soc_acpi_name
46#endif
Andrey Petrov2e410752020-03-20 12:08:32 -070047};
48
Andrey Petrov2e410752020-03-20 12:08:32 -070049static struct device_operations cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +020050 .read_resources = noop_read_resources,
51 .set_resources = noop_set_resources,
Andrey Petrov8670e822020-03-30 12:25:06 -070052 .init = cpx_init_cpus,
Jonathan Zhangc1105952020-06-03 15:55:28 -070053 .acpi_fill_ssdt = generate_cpu_entries,
Andrey Petrov2e410752020-03-20 12:08:32 -070054};
55
Andrey Petrov2e410752020-03-20 12:08:32 -070056struct pci_operations soc_pci_ops = {
57 .set_subsystem = pci_dev_set_subsystem,
58};
59
Jonathan Zhang7919d612020-04-02 17:27:54 -070060static void chip_enable_dev(struct device *dev)
61{
62 /* Set the operations if it is a special bus type */
63 if (dev->path.type == DEVICE_PATH_DOMAIN) {
64 dev->ops = &pci_domain_ops;
65 attach_iio_stacks(dev);
66 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
67 dev->ops = &cpu_bus_ops;
Michael Niewöhner8913b782020-12-11 22:13:44 +010068 } else if (dev->path.type == DEVICE_PATH_GPIO) {
69 block_gpio_enable(dev);
Jonathan Zhang7919d612020-04-02 17:27:54 -070070 }
71}
72
Rocky Phaguraafefa502021-02-16 21:45:24 -080073static void iio_write_mask(u16 bus, u16 dev, u8 func)
74{
75 pci_devfn_t device = PCI_DEV(bus, dev, func);
76 u32 val = pci_s_read_config32(device, IIO_XPUNCCERRMSK_REG);
77 val |= (SENT_PCIE_UNSUPP_MASK | RCVD_PCIE_CA_STS_MASK | RCVD_PCIE_UR_STS_MASK);
78 pci_s_write_config32(device, IIO_XPUNCCERRMSK_REG, val);
79
80 val = pci_s_read_config32(device, RP_UNCERRMSK);
81 val |= (SURPRISE_DWN_ERR_MSK | UNSUPPORTED_REQ_ERR_MSK);
82 pci_s_write_config32(device, RP_UNCERRMSK, val);
83}
84
85static void iio_dmi_en_masks(void)
86{
87 pci_devfn_t device;
88 u32 val;
89 device = PCI_DEV(DMI_BUS_INDEX, DMI_DEV, DMI_FUNC);
90 val = pci_s_read_config32(device, IIO_XPUNCCERRMSK_REG);
91 val |= (SENT_PCIE_UNSUPP_MASK | RCVD_PCIE_CA_STS_MASK | RCVD_PCIE_UR_STS_MASK);
92 pci_s_write_config32(device, IIO_XPUNCCERRMSK_REG, val);
93
94 val = pci_s_read_config32(device, DMI_UNCERRMSK);
95 val |= (ECRC_ERR | MLFRMD_TLP | RCV_BUF_OVRFLOW | FLOW_CNTR | POISON_TLP | DLL_PRT_ERR);
96 pci_s_write_config32(device, DMI_UNCERRMSK, val);
97}
98
99static void iio_enable_masks(void)
100{
101 struct iiostack_resource iio = {0};
102 get_iiostack_info(&iio);
103 int i, k;
104 for (i = 0; i < iio.no_of_stacks; i++) {
105 const STACK_RES *st = &iio.res[i];
106 if (st->BusBase > 0 && st->BusBase != 0xff) {
107 for (k = 0; k < DEVICES_PER_IIO_STACK; k++) {
108 printk(BIOS_DEBUG, "%s: bus:%x dev:%x func:%x\n", __func__,
109 st->BusBase, k, 0);
110 iio_write_mask(st->BusBase, k, 0);
111 }
112 }
113 }
114 iio_dmi_en_masks();
115}
Marc Jones4de76102021-03-12 14:36:48 -0700116
117static void set_pcu_locks(void)
118{
119 for (uint32_t socket = 0; socket < soc_get_num_cpus(); ++socket) {
120 uint32_t bus = get_socket_stack_busno(socket, PCU_IIO_STACK);
121
122 /* configure PCU_CR0_FUN csrs */
123 const struct device *cr0_dev = PCU_DEV_CR0(bus);
124 pci_or_config32(cr0_dev, PCU_CR0_P_STATE_LIMITS, P_STATE_LIMITS_LOCK);
125 pci_or_config32(cr0_dev, PCU_CR0_PACKAGE_RAPL_LIMIT_UPR, PKG_PWR_LIM_LOCK_UPR);
Marc Jones4fad28f2021-04-01 14:47:52 -0600126 pci_or_config32(cr0_dev, PCU_CR0_TURBO_ACTIVATION_RATIO, TURBO_ACTIVATION_RATIO_LOCK);
127
Marc Jones4de76102021-03-12 14:36:48 -0700128
129 /* configure PCU_CR1_FUN csrs */
130 const struct device *cr1_dev = PCU_DEV_CR1(bus);
131 pci_or_config32(cr1_dev, PCU_CR1_SAPMCTL, SAPMCTL_LOCK_MASK);
132
133 /* configure PCU_CR2_FUN csrs */
134 const struct device *cr2_dev = PCU_DEV_CR2(bus);
135 pci_or_config32(cr2_dev, PCU_CR2_DRAM_PLANE_POWER_LIMIT, PP_PWR_LIM_LOCK);
Marc Jones4fad28f2021-04-01 14:47:52 -0600136 pci_or_config32(cr2_dev, PCU_CR2_DRAM_POWER_INFO_UPR, DRAM_POWER_INFO_LOCK_UPR);
Marc Jones4de76102021-03-12 14:36:48 -0700137
138 /* configure PCU_CR3_FUN csrs */
139 const struct device *cr3_dev = PCU_DEV_CR3(bus);
140 pci_or_config32(cr3_dev, PCU_CR3_CONFIG_TDP_CONTROL, TDP_LOCK);
Marc Jones4fad28f2021-04-01 14:47:52 -0600141 pci_or_config32(cr3_dev, PCU_CR3_FLEX_RATIO, OC_LOCK);
Marc Jones4de76102021-03-12 14:36:48 -0700142 }
143
144}
145
Marc Jones64c62232021-04-06 14:09:30 -0600146static void set_msr_locks(void *unused)
147{
148 /* The MSRs and CSRS have the same register layout. Use the CSRS bit definitions */
149 msr_t msr;
150
151 /* Lock Turbo */
152 msr = rdmsr(MSR_TURBO_ACTIVATION_RATIO);
153 msr.lo |= (TURBO_ACTIVATION_RATIO_LOCK);
154 wrmsr(MSR_TURBO_ACTIVATION_RATIO, msr);
155
156 /* Lock AES enable */
157 msr = rdmsr(MSR_FEATURE_CONFIG);
158 msr.lo |= FEATURE_CONFIG_LOCK;
159 wrmsr(MSR_FEATURE_CONFIG, msr);
160}
161
Andrey Petrov2e410752020-03-20 12:08:32 -0700162static void chip_final(void *data)
163{
Arthur Heymans0f91e9c2020-10-16 13:15:50 +0200164 /* Lock SBI */
165 pci_or_config32(PCH_DEV_P2SB, P2SBC, SBILOCK);
Arthur Heymans19185532020-10-27 17:40:22 +0100166
167 /* LOCK PAM */
168 pci_or_config32(pcidev_path_on_root(PCI_DEVFN(0, 0)), 0x80, 1 << 0);
169
170 /*
171 * LOCK SMRAM
172 * According to the CedarIsland FSP Integration Guide this needs to
173 * be done with legacy 0xCF8/0xCFC IO ops.
174 */
175 uint8_t reg8 = pci_io_read_config8(PCI_DEV(0, 0, 0), 0x88);
176 pci_io_write_config8(PCI_DEV(0, 0, 0), 0x88, reg8 | (1 << 4));
177
Marc Jones64c62232021-04-06 14:09:30 -0600178 mp_run_on_all_cpus(set_msr_locks, NULL);
Marc Jones4de76102021-03-12 14:36:48 -0700179 set_pcu_locks();
180
Andrey Petrov4e48ac02020-04-30 14:08:19 -0700181 p2sb_hide();
Rocky Phaguraafefa502021-02-16 21:45:24 -0800182 iio_enable_masks();
Jonathan Zhangbea19802020-04-13 19:34:53 -0700183 set_bios_init_completion();
Andrey Petrov2e410752020-03-20 12:08:32 -0700184}
185
186static void chip_init(void *data)
187{
188 printk(BIOS_DEBUG, "coreboot: calling fsp_silicon_init\n");
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +0200189 fsp_silicon_init();
Arthur Heymans3d802532020-11-12 21:17:56 +0100190 override_hpet_ioapic_bdf();
Subrata Banik1366e442020-09-29 13:55:50 +0530191 pch_enable_ioapic();
Arthur Heymans83463072020-12-16 11:30:40 +0100192 pch_lock_dmictl();
Andrey Petrov2e410752020-03-20 12:08:32 -0700193 setup_lapic();
Andrey Petrov4e48ac02020-04-30 14:08:19 -0700194 p2sb_unhide();
Andrey Petrov2e410752020-03-20 12:08:32 -0700195}
196
197struct chip_operations soc_intel_xeon_sp_cpx_ops = {
198 CHIP_NAME("Intel Cooperlake-SP")
199 .enable_dev = chip_enable_dev,
200 .init = chip_init,
Jonathan Zhang7919d612020-04-02 17:27:54 -0700201 .final = chip_final,
Andrey Petrov2e410752020-03-20 12:08:32 -0700202};