blob: 21d6e1748ee542c043816a9c0cbd38ccc309b9b3 [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>
Andrey Petrov8670e822020-03-30 12:25:06 -070015#include <soc/cpu.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
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 Jones456b7ba2021-04-15 16:24:54 -0600146static void set_imc_locks(void)
147{
148 struct device *dev = 0;
Felix Singer43b7f412022-03-07 04:34:52 +0100149 while ((dev = dev_find_device(PCI_VID_INTEL, IMC_M2MEM_DEVID, dev)))
Marc Jones456b7ba2021-04-15 16:24:54 -0600150 pci_or_config32(dev, IMC_M2MEM_TIMEOUT, TIMEOUT_LOCK);
151}
152
Marc Jonesb20d6942021-04-15 16:25:49 -0600153static void set_upi_locks(void)
154{
155 struct device *dev = 0;
Felix Singer43b7f412022-03-07 04:34:52 +0100156 while ((dev = dev_find_device(PCI_VID_INTEL, UPI_LL_CR_DEVID, dev)))
Marc Jonesb20d6942021-04-15 16:25:49 -0600157 pci_or_config32(dev, UPI_LL_CR_KTIMISCMODLCK, KTIMISCMODLCK_LOCK);
158}
159
Andrey Petrov2e410752020-03-20 12:08:32 -0700160static void chip_final(void *data)
161{
Arthur Heymans0f91e9c2020-10-16 13:15:50 +0200162 /* Lock SBI */
163 pci_or_config32(PCH_DEV_P2SB, P2SBC, SBILOCK);
Arthur Heymans19185532020-10-27 17:40:22 +0100164
165 /* LOCK PAM */
166 pci_or_config32(pcidev_path_on_root(PCI_DEVFN(0, 0)), 0x80, 1 << 0);
167
Marc Jones4de76102021-03-12 14:36:48 -0700168 set_pcu_locks();
Marc Jones456b7ba2021-04-15 16:24:54 -0600169 set_imc_locks();
Marc Jonesb20d6942021-04-15 16:25:49 -0600170 set_upi_locks();
Marc Jones4de76102021-03-12 14:36:48 -0700171
Andrey Petrov4e48ac02020-04-30 14:08:19 -0700172 p2sb_hide();
Rocky Phaguraafefa502021-02-16 21:45:24 -0800173 iio_enable_masks();
Jonathan Zhangbea19802020-04-13 19:34:53 -0700174 set_bios_init_completion();
Andrey Petrov2e410752020-03-20 12:08:32 -0700175}
176
177static void chip_init(void *data)
178{
179 printk(BIOS_DEBUG, "coreboot: calling fsp_silicon_init\n");
Kyösti Mälkkicc93c6e2021-01-09 22:53:52 +0200180 fsp_silicon_init();
Arthur Heymans3d802532020-11-12 21:17:56 +0100181 override_hpet_ioapic_bdf();
Subrata Banik1366e442020-09-29 13:55:50 +0530182 pch_enable_ioapic();
Arthur Heymans83463072020-12-16 11:30:40 +0100183 pch_lock_dmictl();
Andrey Petrov4e48ac02020-04-30 14:08:19 -0700184 p2sb_unhide();
Andrey Petrov2e410752020-03-20 12:08:32 -0700185}
186
187struct chip_operations soc_intel_xeon_sp_cpx_ops = {
Paul Menzel55542262021-11-09 08:09:40 +0100188 CHIP_NAME("Intel Cooper Lake-SP")
Andrey Petrov2e410752020-03-20 12:08:32 -0700189 .enable_dev = chip_enable_dev,
190 .init = chip_init,
Jonathan Zhang7919d612020-04-02 17:27:54 -0700191 .final = chip_final,
Andrey Petrov2e410752020-03-20 12:08:32 -0700192};