blob: 1e84dd5a5ceda527d9662af9d44b4661007bcde2 [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>
Marc Jones64c62232021-04-06 14:09:30 -06006#include <cpu/x86/mp.h>
Andrey Petrov2e410752020-03-20 12:08:32 -07007#include <device/pci.h>
Marc Jones456b7ba2021-04-15 16:24:54 -06008#include <device/pci_ids.h>
Dinesh Gehlot6fecff22023-01-17 06:02:16 +00009#include <gpio.h>
Marc Jones81ef9c22021-01-21 10:53:47 -070010#include <intelblocks/acpi.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>
Arthur Heymans3d802532020-11-12 21:17:56 +010015#include <soc/pch.h>
Tim Chu13c44452022-11-25 10:31:00 +000016#include <soc/soc_pch.h>
Andrey Petrov2e410752020-03-20 12:08:32 -070017#include <soc/ramstage.h>
Arthur Heymans0f91e9c2020-10-16 13:15:50 +020018#include <soc/p2sb.h>
Jonathan Zhang7919d612020-04-02 17:27:54 -070019#include <soc/soc_util.h>
Marc Jones5851f9d2020-11-02 15:30:10 -070020#include <soc/util.h>
Arthur Heymans0f91e9c2020-10-16 13:15:50 +020021#include <soc/pci_devs.h>
Jonathan Zhang7919d612020-04-02 17:27:54 -070022
Marc Jonesb9365ef2020-10-11 15:00:36 -060023/* UPD parameters to be initialized before SiliconInit */
Andrey Petrov2e410752020-03-20 12:08:32 -070024void platform_fsp_silicon_init_params_cb(FSPS_UPD *silupd)
25{
Marc Jonesb9365ef2020-10-11 15:00:36 -060026 mainboard_silicon_init_params(silupd);
Andrey Petrov2e410752020-03-20 12:08:32 -070027}
28
Jonathan Zhang1ba42a92020-09-21 17:14:44 -070029#if CONFIG(HAVE_ACPI_TABLES)
Marc Jones81ef9c22021-01-21 10:53:47 -070030const char *soc_acpi_name(const struct device *dev)
Jonathan Zhang1ba42a92020-09-21 17:14:44 -070031{
32 if (dev->path.type == DEVICE_PATH_DOMAIN)
33 return "PC00";
34 return NULL;
35}
36#endif
37
Andrey Petrov2e410752020-03-20 12:08:32 -070038static struct device_operations pci_domain_ops = {
Arthur Heymans550f55e2022-08-24 14:44:26 +020039 .read_resources = iio_pci_domain_read_resources,
40 .set_resources = pci_domain_set_resources,
41 .scan_bus = iio_pci_domain_scan_bus,
Jonathan Zhang1ba42a92020-09-21 17:14:44 -070042#if CONFIG(HAVE_ACPI_TABLES)
Jonathan Zhang3172f982020-05-28 17:53:48 -070043 .write_acpi_tables = &northbridge_write_acpi_tables,
Jonathan Zhang1ba42a92020-09-21 17:14:44 -070044 .acpi_name = soc_acpi_name
45#endif
Andrey Petrov2e410752020-03-20 12:08:32 -070046};
47
Andrey Petrov2e410752020-03-20 12:08:32 -070048static struct device_operations cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +020049 .read_resources = noop_read_resources,
50 .set_resources = noop_set_resources,
Arthur Heymans829e8e62023-01-30 19:09:34 +010051 .init = mp_cpu_bus_init,
Jonathan Zhangc1105952020-06-03 15:55:28 -070052 .acpi_fill_ssdt = generate_cpu_entries,
Andrey Petrov2e410752020-03-20 12:08:32 -070053};
54
Andrey Petrov2e410752020-03-20 12:08:32 -070055struct pci_operations soc_pci_ops = {
56 .set_subsystem = pci_dev_set_subsystem,
57};
58
Jonathan Zhang7919d612020-04-02 17:27:54 -070059static void chip_enable_dev(struct device *dev)
60{
61 /* Set the operations if it is a special bus type */
62 if (dev->path.type == DEVICE_PATH_DOMAIN) {
63 dev->ops = &pci_domain_ops;
64 attach_iio_stacks(dev);
65 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
66 dev->ops = &cpu_bus_ops;
Michael Niewöhner8913b782020-12-11 22:13:44 +010067 } else if (dev->path.type == DEVICE_PATH_GPIO) {
68 block_gpio_enable(dev);
Jonathan Zhang7919d612020-04-02 17:27:54 -070069 }
70}
71
Rocky Phaguraafefa502021-02-16 21:45:24 -080072static void iio_write_mask(u16 bus, u16 dev, u8 func)
73{
74 pci_devfn_t device = PCI_DEV(bus, dev, func);
75 u32 val = pci_s_read_config32(device, IIO_XPUNCCERRMSK_REG);
76 val |= (SENT_PCIE_UNSUPP_MASK | RCVD_PCIE_CA_STS_MASK | RCVD_PCIE_UR_STS_MASK);
77 pci_s_write_config32(device, IIO_XPUNCCERRMSK_REG, val);
78
79 val = pci_s_read_config32(device, RP_UNCERRMSK);
80 val |= (SURPRISE_DWN_ERR_MSK | UNSUPPORTED_REQ_ERR_MSK);
81 pci_s_write_config32(device, RP_UNCERRMSK, val);
82}
83
84static void iio_dmi_en_masks(void)
85{
86 pci_devfn_t device;
87 u32 val;
88 device = PCI_DEV(DMI_BUS_INDEX, DMI_DEV, DMI_FUNC);
89 val = pci_s_read_config32(device, IIO_XPUNCCERRMSK_REG);
90 val |= (SENT_PCIE_UNSUPP_MASK | RCVD_PCIE_CA_STS_MASK | RCVD_PCIE_UR_STS_MASK);
91 pci_s_write_config32(device, IIO_XPUNCCERRMSK_REG, val);
92
93 val = pci_s_read_config32(device, DMI_UNCERRMSK);
94 val |= (ECRC_ERR | MLFRMD_TLP | RCV_BUF_OVRFLOW | FLOW_CNTR | POISON_TLP | DLL_PRT_ERR);
95 pci_s_write_config32(device, DMI_UNCERRMSK, val);
96}
97
98static void iio_enable_masks(void)
99{
100 struct iiostack_resource iio = {0};
101 get_iiostack_info(&iio);
102 int i, k;
103 for (i = 0; i < iio.no_of_stacks; i++) {
104 const STACK_RES *st = &iio.res[i];
105 if (st->BusBase > 0 && st->BusBase != 0xff) {
106 for (k = 0; k < DEVICES_PER_IIO_STACK; k++) {
107 printk(BIOS_DEBUG, "%s: bus:%x dev:%x func:%x\n", __func__,
108 st->BusBase, k, 0);
109 iio_write_mask(st->BusBase, k, 0);
110 }
111 }
112 }
113 iio_dmi_en_masks();
114}
Marc Jones4de76102021-03-12 14:36:48 -0700115
116static void set_pcu_locks(void)
117{
Patrick Rudolphac028572023-07-14 17:44:33 +0200118 for (uint32_t socket = 0; socket < CONFIG_MAX_SOCKET; ++socket) {
119 if (!soc_cpu_is_enabled(socket))
120 continue;
Marc Jones4de76102021-03-12 14:36:48 -0700121 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 Jones456b7ba2021-04-15 16:24:54 -0600147static void set_imc_locks(void)
148{
149 struct device *dev = 0;
Felix Singer43b7f412022-03-07 04:34:52 +0100150 while ((dev = dev_find_device(PCI_VID_INTEL, IMC_M2MEM_DEVID, dev)))
Marc Jones456b7ba2021-04-15 16:24:54 -0600151 pci_or_config32(dev, IMC_M2MEM_TIMEOUT, TIMEOUT_LOCK);
152}
153
Marc Jonesb20d6942021-04-15 16:25:49 -0600154static void set_upi_locks(void)
155{
156 struct device *dev = 0;
Felix Singer43b7f412022-03-07 04:34:52 +0100157 while ((dev = dev_find_device(PCI_VID_INTEL, UPI_LL_CR_DEVID, dev)))
Marc Jonesb20d6942021-04-15 16:25:49 -0600158 pci_or_config32(dev, UPI_LL_CR_KTIMISCMODLCK, KTIMISCMODLCK_LOCK);
159}
160
Andrey Petrov2e410752020-03-20 12:08:32 -0700161static void chip_final(void *data)
162{
Arthur Heymans0f91e9c2020-10-16 13:15:50 +0200163 /* Lock SBI */
164 pci_or_config32(PCH_DEV_P2SB, P2SBC, SBILOCK);
Arthur Heymans19185532020-10-27 17:40:22 +0100165
166 /* LOCK PAM */
167 pci_or_config32(pcidev_path_on_root(PCI_DEVFN(0, 0)), 0x80, 1 << 0);
168
Marc Jones4de76102021-03-12 14:36:48 -0700169 set_pcu_locks();
Marc Jones456b7ba2021-04-15 16:24:54 -0600170 set_imc_locks();
Marc Jonesb20d6942021-04-15 16:25:49 -0600171 set_upi_locks();
Marc Jones4de76102021-03-12 14:36:48 -0700172
Andrey Petrov4e48ac02020-04-30 14:08:19 -0700173 p2sb_hide();
Rocky Phaguraafefa502021-02-16 21:45:24 -0800174 iio_enable_masks();
Jonathan Zhangbea19802020-04-13 19:34:53 -0700175 set_bios_init_completion();
Andrey Petrov2e410752020-03-20 12:08:32 -0700176}
177
178static void chip_init(void *data)
179{
180 printk(BIOS_DEBUG, "coreboot: calling fsp_silicon_init\n");
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +0200181 fsp_silicon_init();
Arthur Heymans3d802532020-11-12 21:17:56 +0100182 override_hpet_ioapic_bdf();
Subrata Banik1366e442020-09-29 13:55:50 +0530183 pch_enable_ioapic();
Arthur Heymans83463072020-12-16 11:30:40 +0100184 pch_lock_dmictl();
Andrey Petrov4e48ac02020-04-30 14:08:19 -0700185 p2sb_unhide();
Andrey Petrov2e410752020-03-20 12:08:32 -0700186}
187
188struct chip_operations soc_intel_xeon_sp_cpx_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900189 .name = "Intel Cooper Lake-SP",
Andrey Petrov2e410752020-03-20 12:08:32 -0700190 .enable_dev = chip_enable_dev,
191 .init = chip_init,
Jonathan Zhang7919d612020-04-02 17:27:54 -0700192 .final = chip_final,
Andrey Petrov2e410752020-03-20 12:08:32 -0700193};