blob: 500f83e41abf8ca2420c96ad2e5051ad674553e1 [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>
7#include <device/pci.h>
Marc Jones81ef9c22021-01-21 10:53:47 -07008#include <intelblocks/acpi.h>
Michael Niewöhner8913b782020-12-11 22:13:44 +01009#include <intelblocks/gpio.h>
Subrata Banik1366e442020-09-29 13:55:50 +053010#include <intelblocks/lpc_lib.h>
Andrey Petrov4e48ac02020-04-30 14:08:19 -070011#include <intelblocks/p2sb.h>
Jonathan Zhang3172f982020-05-28 17:53:48 -070012#include <soc/acpi.h>
Marc Jones1f500842020-10-15 14:32:51 -060013#include <soc/chip_common.h>
Andrey Petrov8670e822020-03-30 12:25:06 -070014#include <soc/cpu.h>
Arthur Heymans3d802532020-11-12 21:17:56 +010015#include <soc/pch.h>
Andrey Petrov2e410752020-03-20 12:08:32 -070016#include <soc/ramstage.h>
Arthur Heymans0f91e9c2020-10-16 13:15:50 +020017#include <soc/p2sb.h>
Jonathan Zhang7919d612020-04-02 17:27:54 -070018#include <soc/soc_util.h>
Marc Jones5851f9d2020-11-02 15:30:10 -070019#include <soc/util.h>
Arthur Heymans0f91e9c2020-10-16 13:15:50 +020020#include <soc/pci_devs.h>
Jonathan Zhang7919d612020-04-02 17:27:54 -070021
Marc Jonesb9365ef2020-10-11 15:00:36 -060022/* UPD parameters to be initialized before SiliconInit */
Andrey Petrov2e410752020-03-20 12:08:32 -070023void platform_fsp_silicon_init_params_cb(FSPS_UPD *silupd)
24{
Marc Jonesb9365ef2020-10-11 15:00:36 -060025 mainboard_silicon_init_params(silupd);
Andrey Petrov2e410752020-03-20 12:08:32 -070026}
27
Jonathan Zhang1ba42a92020-09-21 17:14:44 -070028#if CONFIG(HAVE_ACPI_TABLES)
Marc Jones81ef9c22021-01-21 10:53:47 -070029const char *soc_acpi_name(const struct device *dev)
Jonathan Zhang1ba42a92020-09-21 17:14:44 -070030{
31 if (dev->path.type == DEVICE_PATH_DOMAIN)
32 return "PC00";
33 return NULL;
34}
35#endif
36
Andrey Petrov2e410752020-03-20 12:08:32 -070037static struct device_operations pci_domain_ops = {
38 .read_resources = &pci_domain_read_resources,
Marc Jones1f500842020-10-15 14:32:51 -060039 .set_resources = &xeonsp_pci_domain_set_resources,
40 .scan_bus = &xeonsp_pci_domain_scan_bus,
Jonathan Zhang1ba42a92020-09-21 17:14:44 -070041#if CONFIG(HAVE_ACPI_TABLES)
Jonathan Zhang3172f982020-05-28 17:53:48 -070042 .write_acpi_tables = &northbridge_write_acpi_tables,
Jonathan Zhang1ba42a92020-09-21 17:14:44 -070043 .acpi_name = soc_acpi_name
44#endif
Andrey Petrov2e410752020-03-20 12:08:32 -070045};
46
Andrey Petrov2e410752020-03-20 12:08:32 -070047static struct device_operations cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +020048 .read_resources = noop_read_resources,
49 .set_resources = noop_set_resources,
Andrey Petrov8670e822020-03-30 12:25:06 -070050 .init = cpx_init_cpus,
Jonathan Zhangc1105952020-06-03 15:55:28 -070051 .acpi_fill_ssdt = generate_cpu_entries,
Andrey Petrov2e410752020-03-20 12:08:32 -070052};
53
Andrey Petrov2e410752020-03-20 12:08:32 -070054struct pci_operations soc_pci_ops = {
55 .set_subsystem = pci_dev_set_subsystem,
56};
57
Jonathan Zhang7919d612020-04-02 17:27:54 -070058static void chip_enable_dev(struct device *dev)
59{
60 /* Set the operations if it is a special bus type */
61 if (dev->path.type == DEVICE_PATH_DOMAIN) {
62 dev->ops = &pci_domain_ops;
63 attach_iio_stacks(dev);
64 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
65 dev->ops = &cpu_bus_ops;
Michael Niewöhner8913b782020-12-11 22:13:44 +010066 } else if (dev->path.type == DEVICE_PATH_GPIO) {
67 block_gpio_enable(dev);
Jonathan Zhang7919d612020-04-02 17:27:54 -070068 }
69}
70
Rocky Phaguraafefa502021-02-16 21:45:24 -080071static void iio_write_mask(u16 bus, u16 dev, u8 func)
72{
73 pci_devfn_t device = PCI_DEV(bus, dev, func);
74 u32 val = pci_s_read_config32(device, IIO_XPUNCCERRMSK_REG);
75 val |= (SENT_PCIE_UNSUPP_MASK | RCVD_PCIE_CA_STS_MASK | RCVD_PCIE_UR_STS_MASK);
76 pci_s_write_config32(device, IIO_XPUNCCERRMSK_REG, val);
77
78 val = pci_s_read_config32(device, RP_UNCERRMSK);
79 val |= (SURPRISE_DWN_ERR_MSK | UNSUPPORTED_REQ_ERR_MSK);
80 pci_s_write_config32(device, RP_UNCERRMSK, val);
81}
82
83static void iio_dmi_en_masks(void)
84{
85 pci_devfn_t device;
86 u32 val;
87 device = PCI_DEV(DMI_BUS_INDEX, DMI_DEV, DMI_FUNC);
88 val = pci_s_read_config32(device, IIO_XPUNCCERRMSK_REG);
89 val |= (SENT_PCIE_UNSUPP_MASK | RCVD_PCIE_CA_STS_MASK | RCVD_PCIE_UR_STS_MASK);
90 pci_s_write_config32(device, IIO_XPUNCCERRMSK_REG, val);
91
92 val = pci_s_read_config32(device, DMI_UNCERRMSK);
93 val |= (ECRC_ERR | MLFRMD_TLP | RCV_BUF_OVRFLOW | FLOW_CNTR | POISON_TLP | DLL_PRT_ERR);
94 pci_s_write_config32(device, DMI_UNCERRMSK, val);
95}
96
97static void iio_enable_masks(void)
98{
99 struct iiostack_resource iio = {0};
100 get_iiostack_info(&iio);
101 int i, k;
102 for (i = 0; i < iio.no_of_stacks; i++) {
103 const STACK_RES *st = &iio.res[i];
104 if (st->BusBase > 0 && st->BusBase != 0xff) {
105 for (k = 0; k < DEVICES_PER_IIO_STACK; k++) {
106 printk(BIOS_DEBUG, "%s: bus:%x dev:%x func:%x\n", __func__,
107 st->BusBase, k, 0);
108 iio_write_mask(st->BusBase, k, 0);
109 }
110 }
111 }
112 iio_dmi_en_masks();
113}
Marc Jones4de76102021-03-12 14:36:48 -0700114
115static void set_pcu_locks(void)
116{
117 for (uint32_t socket = 0; socket < soc_get_num_cpus(); ++socket) {
118 uint32_t bus = get_socket_stack_busno(socket, PCU_IIO_STACK);
119
120 /* configure PCU_CR0_FUN csrs */
121 const struct device *cr0_dev = PCU_DEV_CR0(bus);
122 pci_or_config32(cr0_dev, PCU_CR0_P_STATE_LIMITS, P_STATE_LIMITS_LOCK);
123 pci_or_config32(cr0_dev, PCU_CR0_PACKAGE_RAPL_LIMIT_UPR, PKG_PWR_LIM_LOCK_UPR);
Marc Jones4fad28f2021-04-01 14:47:52 -0600124 pci_or_config32(cr0_dev, PCU_CR0_TURBO_ACTIVATION_RATIO, TURBO_ACTIVATION_RATIO_LOCK);
125
Marc Jones4de76102021-03-12 14:36:48 -0700126
127 /* configure PCU_CR1_FUN csrs */
128 const struct device *cr1_dev = PCU_DEV_CR1(bus);
129 pci_or_config32(cr1_dev, PCU_CR1_SAPMCTL, SAPMCTL_LOCK_MASK);
130
131 /* configure PCU_CR2_FUN csrs */
132 const struct device *cr2_dev = PCU_DEV_CR2(bus);
133 pci_or_config32(cr2_dev, PCU_CR2_DRAM_PLANE_POWER_LIMIT, PP_PWR_LIM_LOCK);
Marc Jones4fad28f2021-04-01 14:47:52 -0600134 pci_or_config32(cr2_dev, PCU_CR2_DRAM_POWER_INFO_UPR, DRAM_POWER_INFO_LOCK_UPR);
Marc Jones4de76102021-03-12 14:36:48 -0700135
136 /* configure PCU_CR3_FUN csrs */
137 const struct device *cr3_dev = PCU_DEV_CR3(bus);
138 pci_or_config32(cr3_dev, PCU_CR3_CONFIG_TDP_CONTROL, TDP_LOCK);
Marc Jones4fad28f2021-04-01 14:47:52 -0600139 pci_or_config32(cr3_dev, PCU_CR3_FLEX_RATIO, OC_LOCK);
Marc Jones4de76102021-03-12 14:36:48 -0700140 }
141
142}
143
Andrey Petrov2e410752020-03-20 12:08:32 -0700144static void chip_final(void *data)
145{
Arthur Heymans0f91e9c2020-10-16 13:15:50 +0200146 /* Lock SBI */
147 pci_or_config32(PCH_DEV_P2SB, P2SBC, SBILOCK);
Arthur Heymans19185532020-10-27 17:40:22 +0100148
149 /* LOCK PAM */
150 pci_or_config32(pcidev_path_on_root(PCI_DEVFN(0, 0)), 0x80, 1 << 0);
151
152 /*
153 * LOCK SMRAM
154 * According to the CedarIsland FSP Integration Guide this needs to
155 * be done with legacy 0xCF8/0xCFC IO ops.
156 */
157 uint8_t reg8 = pci_io_read_config8(PCI_DEV(0, 0, 0), 0x88);
158 pci_io_write_config8(PCI_DEV(0, 0, 0), 0x88, reg8 | (1 << 4));
159
Marc Jones4de76102021-03-12 14:36:48 -0700160 set_pcu_locks();
161
Andrey Petrov4e48ac02020-04-30 14:08:19 -0700162 p2sb_hide();
Rocky Phaguraafefa502021-02-16 21:45:24 -0800163 iio_enable_masks();
Jonathan Zhangbea19802020-04-13 19:34:53 -0700164 set_bios_init_completion();
Andrey Petrov2e410752020-03-20 12:08:32 -0700165}
166
167static void chip_init(void *data)
168{
169 printk(BIOS_DEBUG, "coreboot: calling fsp_silicon_init\n");
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +0200170 fsp_silicon_init();
Arthur Heymans3d802532020-11-12 21:17:56 +0100171 override_hpet_ioapic_bdf();
Subrata Banik1366e442020-09-29 13:55:50 +0530172 pch_enable_ioapic();
Arthur Heymans83463072020-12-16 11:30:40 +0100173 pch_lock_dmictl();
Andrey Petrov2e410752020-03-20 12:08:32 -0700174 setup_lapic();
Andrey Petrov4e48ac02020-04-30 14:08:19 -0700175 p2sb_unhide();
Andrey Petrov2e410752020-03-20 12:08:32 -0700176}
177
178struct chip_operations soc_intel_xeon_sp_cpx_ops = {
179 CHIP_NAME("Intel Cooperlake-SP")
180 .enable_dev = chip_enable_dev,
181 .init = chip_init,
Jonathan Zhang7919d612020-04-02 17:27:54 -0700182 .final = chip_final,
Andrey Petrov2e410752020-03-20 12:08:32 -0700183};