blob: b0e61b62ae1df2418f591dc06b7d3d40664a05be [file] [log] [blame]
Andrey Petrov2e410752020-03-20 12:08:32 -07001/* SPDX-License-Identifier: GPL-2.0-only */
Patrick Rudolphe357ac32024-02-23 09:47:24 +01002#include <acpi/acpigen_pci.h>
Andrey Petrov2e410752020-03-20 12:08:32 -07003#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>
Patrick Rudolph106d7b32024-01-18 09:14:03 +01009#include <device/pci_def.h>
Dinesh Gehlot6fecff22023-01-17 06:02:16 +000010#include <gpio.h>
Marc Jones81ef9c22021-01-21 10:53:47 -070011#include <intelblocks/acpi.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>
Arthur Heymans3d802532020-11-12 21:17:56 +010016#include <soc/pch.h>
Tim Chu13c44452022-11-25 10:31:00 +000017#include <soc/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
Andrey Petrov2e410752020-03-20 12:08:32 -070030static struct device_operations cpu_bus_ops = {
Nico Huber2f8ba692020-04-05 14:05:24 +020031 .read_resources = noop_read_resources,
32 .set_resources = noop_set_resources,
Arthur Heymans829e8e62023-01-30 19:09:34 +010033 .init = mp_cpu_bus_init,
Jonathan Zhangc1105952020-06-03 15:55:28 -070034 .acpi_fill_ssdt = generate_cpu_entries,
Andrey Petrov2e410752020-03-20 12:08:32 -070035};
36
Andrey Petrov2e410752020-03-20 12:08:32 -070037struct pci_operations soc_pci_ops = {
38 .set_subsystem = pci_dev_set_subsystem,
39};
40
Jonathan Zhang7919d612020-04-02 17:27:54 -070041static void chip_enable_dev(struct device *dev)
42{
43 /* Set the operations if it is a special bus type */
44 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Shuo Liu255f9272023-03-29 20:14:11 +080045 /* domain ops are assigned at their creation */
Jonathan Zhang7919d612020-04-02 17:27:54 -070046 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
47 dev->ops = &cpu_bus_ops;
Michael Niewöhner8913b782020-12-11 22:13:44 +010048 } else if (dev->path.type == DEVICE_PATH_GPIO) {
49 block_gpio_enable(dev);
Jonathan Zhang7919d612020-04-02 17:27:54 -070050 }
51}
52
Rocky Phaguraafefa502021-02-16 21:45:24 -080053static void iio_write_mask(u16 bus, u16 dev, u8 func)
54{
55 pci_devfn_t device = PCI_DEV(bus, dev, func);
56 u32 val = pci_s_read_config32(device, IIO_XPUNCCERRMSK_REG);
57 val |= (SENT_PCIE_UNSUPP_MASK | RCVD_PCIE_CA_STS_MASK | RCVD_PCIE_UR_STS_MASK);
58 pci_s_write_config32(device, IIO_XPUNCCERRMSK_REG, val);
59
60 val = pci_s_read_config32(device, RP_UNCERRMSK);
61 val |= (SURPRISE_DWN_ERR_MSK | UNSUPPORTED_REQ_ERR_MSK);
62 pci_s_write_config32(device, RP_UNCERRMSK, val);
63}
64
65static void iio_dmi_en_masks(void)
66{
67 pci_devfn_t device;
68 u32 val;
69 device = PCI_DEV(DMI_BUS_INDEX, DMI_DEV, DMI_FUNC);
70 val = pci_s_read_config32(device, IIO_XPUNCCERRMSK_REG);
71 val |= (SENT_PCIE_UNSUPP_MASK | RCVD_PCIE_CA_STS_MASK | RCVD_PCIE_UR_STS_MASK);
72 pci_s_write_config32(device, IIO_XPUNCCERRMSK_REG, val);
73
74 val = pci_s_read_config32(device, DMI_UNCERRMSK);
75 val |= (ECRC_ERR | MLFRMD_TLP | RCV_BUF_OVRFLOW | FLOW_CNTR | POISON_TLP | DLL_PRT_ERR);
76 pci_s_write_config32(device, DMI_UNCERRMSK, val);
77}
78
79static void iio_enable_masks(void)
80{
81 struct iiostack_resource iio = {0};
82 get_iiostack_info(&iio);
83 int i, k;
84 for (i = 0; i < iio.no_of_stacks; i++) {
85 const STACK_RES *st = &iio.res[i];
86 if (st->BusBase > 0 && st->BusBase != 0xff) {
87 for (k = 0; k < DEVICES_PER_IIO_STACK; k++) {
88 printk(BIOS_DEBUG, "%s: bus:%x dev:%x func:%x\n", __func__,
89 st->BusBase, k, 0);
90 iio_write_mask(st->BusBase, k, 0);
91 }
92 }
93 }
94 iio_dmi_en_masks();
95}
Marc Jones4de76102021-03-12 14:36:48 -070096
97static void set_pcu_locks(void)
98{
Patrick Rudolph106d7b32024-01-18 09:14:03 +010099 struct device *dev = NULL;
Marc Jones4de76102021-03-12 14:36:48 -0700100
Patrick Rudolph106d7b32024-01-18 09:14:03 +0100101 while ((dev = dev_find_device(PCI_VID_INTEL, PCU_CR0_DEVID, dev))) {
102 printk(BIOS_SPEW, "%s: locking registers\n", dev_path(dev));
103 pci_or_config32(dev, PCU_CR0_P_STATE_LIMITS, P_STATE_LIMITS_LOCK);
104 pci_or_config32(dev, PCU_CR0_PACKAGE_RAPL_LIMIT_UPR,
105 PKG_PWR_LIM_LOCK_UPR);
106 pci_or_config32(dev, PCU_CR0_TURBO_ACTIVATION_RATIO,
107 TURBO_ACTIVATION_RATIO_LOCK);
Marc Jones4de76102021-03-12 14:36:48 -0700108 }
109
Patrick Rudolph106d7b32024-01-18 09:14:03 +0100110 dev = NULL;
111 while ((dev = dev_find_device(PCI_VID_INTEL, PCU_CR1_DEVID, dev))) {
112 printk(BIOS_SPEW, "%s: locking registers\n", dev_path(dev));
113 pci_or_config32(dev, PCU_CR1_SAPMCTL, SAPMCTL_LOCK_MASK);
114 }
115
116 dev = NULL;
117 while ((dev = dev_find_device(PCI_VID_INTEL, PCU_CR2_DEVID, dev))) {
118 printk(BIOS_SPEW, "%s: locking registers\n", dev_path(dev));
119 pci_or_config32(dev, PCU_CR2_DRAM_PLANE_POWER_LIMIT,
120 PP_PWR_LIM_LOCK);
121 pci_or_config32(dev, PCU_CR2_DRAM_POWER_INFO_UPR,
122 DRAM_POWER_INFO_LOCK_UPR);
123 }
124
125 dev = NULL;
126 while ((dev = dev_find_device(PCI_VID_INTEL, PCU_CR3_DEVID, dev))) {
127 printk(BIOS_SPEW, "%s: locking registers\n", dev_path(dev));
128 pci_or_config32(dev, PCU_CR3_CONFIG_TDP_CONTROL, TDP_LOCK);
129 pci_or_config32(dev, PCU_CR3_FLEX_RATIO, OC_LOCK);
130 }
Marc Jones4de76102021-03-12 14:36:48 -0700131}
132
Marc Jones456b7ba2021-04-15 16:24:54 -0600133static void set_imc_locks(void)
134{
135 struct device *dev = 0;
Felix Singer43b7f412022-03-07 04:34:52 +0100136 while ((dev = dev_find_device(PCI_VID_INTEL, IMC_M2MEM_DEVID, dev)))
Marc Jones456b7ba2021-04-15 16:24:54 -0600137 pci_or_config32(dev, IMC_M2MEM_TIMEOUT, TIMEOUT_LOCK);
138}
139
Marc Jonesb20d6942021-04-15 16:25:49 -0600140static void set_upi_locks(void)
141{
142 struct device *dev = 0;
Felix Singer43b7f412022-03-07 04:34:52 +0100143 while ((dev = dev_find_device(PCI_VID_INTEL, UPI_LL_CR_DEVID, dev)))
Marc Jonesb20d6942021-04-15 16:25:49 -0600144 pci_or_config32(dev, UPI_LL_CR_KTIMISCMODLCK, KTIMISCMODLCK_LOCK);
145}
146
Andrey Petrov2e410752020-03-20 12:08:32 -0700147static void chip_final(void *data)
148{
Arthur Heymans0f91e9c2020-10-16 13:15:50 +0200149 /* Lock SBI */
150 pci_or_config32(PCH_DEV_P2SB, P2SBC, SBILOCK);
Arthur Heymans19185532020-10-27 17:40:22 +0100151
152 /* LOCK PAM */
153 pci_or_config32(pcidev_path_on_root(PCI_DEVFN(0, 0)), 0x80, 1 << 0);
154
Marc Jones4de76102021-03-12 14:36:48 -0700155 set_pcu_locks();
Marc Jones456b7ba2021-04-15 16:24:54 -0600156 set_imc_locks();
Marc Jonesb20d6942021-04-15 16:25:49 -0600157 set_upi_locks();
Marc Jones4de76102021-03-12 14:36:48 -0700158
Andrey Petrov4e48ac02020-04-30 14:08:19 -0700159 p2sb_hide();
Rocky Phaguraafefa502021-02-16 21:45:24 -0800160 iio_enable_masks();
Jonathan Zhangbea19802020-04-13 19:34:53 -0700161 set_bios_init_completion();
Andrey Petrov2e410752020-03-20 12:08:32 -0700162}
163
Shuo Liu42fa6242024-03-21 00:43:10 +0800164/* Only call this code from socket0! */
165static void unlock_pam_regions(void)
166{
167 uint32_t pam0123_unlock_dram = 0x33333330;
168 uint32_t pam456_unlock_dram = 0x00333333;
169 /* Get UBOX(1) for socket0 */
170 uint32_t bus1 = socket0_get_ubox_busno(PCU_IIO_STACK);
171
172 /* Assume socket0 owns PCI segment 0 */
173 pci_io_write_config32(PCI_DEV(bus1, SAD_ALL_DEV, SAD_ALL_FUNC),
174 SAD_ALL_PAM0123_CSR, pam0123_unlock_dram);
175 pci_io_write_config32(PCI_DEV(bus1, SAD_ALL_DEV, SAD_ALL_FUNC),
176 SAD_ALL_PAM456_CSR, pam456_unlock_dram);
177
178 uint32_t reg1 = pci_io_read_config32(PCI_DEV(bus1, SAD_ALL_DEV,
179 SAD_ALL_FUNC), SAD_ALL_PAM0123_CSR);
180 uint32_t reg2 = pci_io_read_config32(PCI_DEV(bus1, SAD_ALL_DEV,
181 SAD_ALL_FUNC), SAD_ALL_PAM456_CSR);
182 printk(BIOS_DEBUG, "%s:%s pam0123_csr: 0x%x, pam456_csr: 0x%x\n",
183 __FILE__, __func__, reg1, reg2);
184}
185
Andrey Petrov2e410752020-03-20 12:08:32 -0700186static void chip_init(void *data)
187{
Shuo Liu42fa6242024-03-21 00:43:10 +0800188 unlock_pam_regions();
189
Andrey Petrov2e410752020-03-20 12:08:32 -0700190 printk(BIOS_DEBUG, "coreboot: calling fsp_silicon_init\n");
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +0200191 fsp_silicon_init();
Shuo Liu255f9272023-03-29 20:14:11 +0800192
193 attach_iio_stacks();
194
Arthur Heymans3d802532020-11-12 21:17:56 +0100195 override_hpet_ioapic_bdf();
Subrata Banik1366e442020-09-29 13:55:50 +0530196 pch_enable_ioapic();
Arthur Heymans83463072020-12-16 11:30:40 +0100197 pch_lock_dmictl();
Andrey Petrov4e48ac02020-04-30 14:08:19 -0700198 p2sb_unhide();
Andrey Petrov2e410752020-03-20 12:08:32 -0700199}
200
201struct chip_operations soc_intel_xeon_sp_cpx_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900202 .name = "Intel Cooper Lake-SP",
Andrey Petrov2e410752020-03-20 12:08:32 -0700203 .enable_dev = chip_enable_dev,
204 .init = chip_init,
Jonathan Zhang7919d612020-04-02 17:27:54 -0700205 .final = chip_final,
Andrey Petrov2e410752020-03-20 12:08:32 -0700206};