blob: abab0d24132f160fc9c49b646ff72d3a7ea0ad37 [file] [log] [blame]
Jonathan Zhang3ed903f2023-01-25 11:37:27 -08001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <arch/ioapic.h>
4#include <console/console.h>
5#include <console/debug.h>
6#include <cpu/x86/lapic.h>
7#include <device/pci.h>
8#include <device/pci_ids.h>
9#include <device/pciexp.h>
10#include <intelblocks/gpio.h>
11#include <intelblocks/lpc_lib.h>
12#include <intelblocks/p2sb.h>
13#include <intelblocks/pcr.h>
14#include <intelblocks/tco.h>
15#include <soc/acpi.h>
16#include <soc/chip_common.h>
17#include <soc/crashlog.h>
18#include <soc/numa.h>
19#include <soc/p2sb.h>
20#include <soc/pch.h>
21#include <soc/soc_pch.h>
22#include <soc/pci_devs.h>
23#include <soc/ramstage.h>
24#include <soc/soc_util.h>
25#include <soc/util.h>
26#include <soc/xhci.h>
27
28__weak void mainboard_silicon_init_params(FSPS_UPD *params)
29{
30
31}
32
33/* UPD parameters to be initialized before SiliconInit */
34void platform_fsp_silicon_init_params_cb(FSPS_UPD *silupd)
35{
36 mainboard_silicon_init_params(silupd);
37}
38
39#if CONFIG(HAVE_ACPI_TABLES)
40const char *soc_acpi_name(const struct device *dev);
41const char *soc_acpi_name(const struct device *dev)
42{
43 if (dev->path.type == DEVICE_PATH_DOMAIN)
44 return "PC00";
45 return NULL;
46}
47#endif
48
49static struct device_operations pci_domain_ops = {
Arthur Heymans550f55e2022-08-24 14:44:26 +020050 .read_resources = iio_pci_domain_read_resources,
51 .set_resources = pci_domain_set_resources,
52 .scan_bus = iio_pci_domain_scan_bus,
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080053#if CONFIG(HAVE_ACPI_TABLES)
54 .write_acpi_tables = &northbridge_write_acpi_tables,
55 .acpi_name = soc_acpi_name
56#endif
57};
58
59static struct device_operations cpu_bus_ops = {
60 .read_resources = noop_read_resources,
61 .set_resources = noop_set_resources,
62 .init = mp_cpu_bus_init,
63 .acpi_fill_ssdt = generate_cpu_entries,
64};
65
66struct pci_operations soc_pci_ops = {
67 .set_subsystem = pci_dev_set_subsystem,
68};
69
70static void chip_enable_dev(struct device *dev)
71{
72 /* Set the operations if it is a special bus type */
73 if (dev->path.type == DEVICE_PATH_DOMAIN) {
74 dev->ops = &pci_domain_ops;
75 attach_iio_stacks(dev);
76 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
77 dev->ops = &cpu_bus_ops;
78 } else if (dev->path.type == DEVICE_PATH_GPIO) {
79 block_gpio_enable(dev);
80 }
81}
82
83static void pcu_pci_or_config32(u8 bus, u8 func, u32 reg, u32 orval)
84{
85 u32 data;
86 const uint32_t pcie_offset = PCI_DEV(bus, PCU_DEV, func);
87
88 data = pci_s_read_config32(pcie_offset, reg);
89 data |= orval;
90 pci_s_write_config32(pcie_offset, reg, data);
91}
92
93static void set_pcu_locks(void)
94{
Patrick Rudolphac028572023-07-14 17:44:33 +020095 for (uint32_t socket = 0; socket < CONFIG_MAX_SOCKET; ++socket) {
96 if (!soc_cpu_is_enabled(socket))
97 continue;
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080098 const uint32_t bus = get_ubox_busno(socket, UNCORE_BUS_1);
99
100 /* configure PCU_CR0_FUN csrs */
101 pcu_pci_or_config32(bus, PCU_CR0_FUN, PCU_CR0_P_STATE_LIMITS,
102 P_STATE_LIMITS_LOCK);
103 pcu_pci_or_config32(bus, PCU_CR0_FUN, PCU_CR0_PACKAGE_RAPL_LIMIT_UPR,
104 PKG_PWR_LIM_LOCK_UPR);
105 pcu_pci_or_config32(bus, PCU_CR0_FUN, PCU_CR0_TURBO_ACTIVATION_RATIO,
106 TURBO_ACTIVATION_RATIO_LOCK);
107
108 /* configure PCU_CR2_FUN csrs */
109 pcu_pci_or_config32(bus, PCU_CR2_FUN, PCU_CR2_DRAM_POWER_INFO_UPR,
110 DRAM_POWER_INFO_LOCK_UPR);
111 pcu_pci_or_config32(bus, PCU_CR2_FUN, PCU_CR2_DRAM_PLANE_POWER_LIMIT_UPR,
112 PP_PWR_LIM_LOCK_UPR);
113
114 /* configure PCU_CR3_FUN csrs */
115 pcu_pci_or_config32(bus, PCU_CR3_FUN, PCU_CR3_CONFIG_TDP_CONTROL, TDP_LOCK);
116
117 /* configure PCU_CR6_FUN csrs */
118 pcu_pci_or_config32(bus, PCU_CR6_FUN, PCU_CR6_PLATFORM_RAPL_LIMIT_CFG_UPR,
119 PLT_PWR_LIM_LOCK_UPR);
120 pcu_pci_or_config32(bus, PCU_CR6_FUN, PCU_CR6_PLATFORM_POWER_INFO_CFG_UPR,
121 PLT_PWR_INFO_LOCK_UPR);
122 }
123}
124
125static void chip_final(void *data)
126{
127 /* Lock SBI */
128 pci_or_config32(PCH_DEV_P2SB, P2SBC, SBILOCK);
129
130 /* LOCK PAM */
131 pci_or_config32(pcidev_path_on_root(PCI_DEVFN(0, 0)), 0x80, 1 << 0);
132
133 set_pcu_locks();
134 tco_lockdown();
135
136 p2sb_hide();
137
138 /* Accessing xHCI CSR needs to be done after PCI enumeration. */
139 lock_oc_cfg(false);
140 mainboard_override_usb_oc();
141 lock_oc_cfg(true);
142 /* Disable CPU Crashlog to avoid conflict between CPU Crashlog and BMC ACD. */
143 disable_cpu_crashlog();
144
145 set_bios_init_completion();
146}
147
148static void chip_init(void *data)
149{
150 printk(BIOS_DEBUG, "coreboot: calling fsp_silicon_init\n");
151 fsp_silicon_init();
152 override_hpet_ioapic_bdf();
153 pch_enable_ioapic();
154 pch_lock_dmictl();
155 p2sb_unhide();
156 lock_gpio(false);
157 mainboard_override_fsp_gpio();
158 lock_gpio(true);
159}
160
161struct chip_operations soc_intel_xeon_sp_spr_ops = {
Nicholas Sudsgaardbfb11be2024-01-30 09:53:46 +0900162 .name = "Intel SapphireRapids-SP",
163 .enable_dev = chip_enable_dev,
Jonathan Zhang3ed903f2023-01-25 11:37:27 -0800164 .init = chip_init,
165 .final = chip_final,
166};
167
168void lock_gpio(bool lock)
169{
170 if (lock) {
171 pcr_write32(gpio_get_pad_portid(GPPC_B0), PAD_CFG_LOCK_B, 0xffffffff);
172 pcr_write32(gpio_get_pad_portid(GPP_D0), PAD_CFG_LOCK_D, 0xffffffff);
173 } else {
174 pcr_write32(gpio_get_pad_portid(GPPC_B0), PAD_CFG_LOCK_B, 0);
175 pcr_write32(gpio_get_pad_portid(GPP_D0), PAD_CFG_LOCK_D, 0);
176 }
177}
178
179/* Root Complex Event Collector */
180static void rcec_init(struct device *dev)
181{
182 /* Set up RCEC EA extended capability, section 7.9.10 of PCIe 5.0 spec */
183 const unsigned int rcecea_cap =
184 pciexp_find_extended_cap(dev, PCIE_EXT_CAP_RCECEA_ID, 0);
185 if (!rcecea_cap)
186 return;
187
188 pci_devfn_t ecrc_bdf = PCI_BDF(dev);
189 uint32_t ecrc_bus = (ecrc_bdf >> 20) & 0xFFF;
190 uint32_t ecrc_dev = (ecrc_bdf >> 15) & 0x1F;
191
192 /*
193 * Find all CXL devices, and match them with RCEC.
194 * With CXL 1.1, the bus# of CXL device (RCiEP) is 1 bigger than
195 * the bus# of RCEC.
196 */
197 uint32_t ep_bus;
198 uint8_t i;
199 for (i = 0; i < pds.num_pds; i++) {
200 if (pds.pds[i].pd_type == PD_TYPE_PROCESSOR)
201 continue;
202 ep_bus = pds.pds[i].device_handle >> 20;
203 if (ep_bus == ecrc_bus + 1)
204 break;
205 }
206 if (i == pds.num_pds)
207 return;
208
209 printk(BIOS_DEBUG, "ep_bus: %x, ecrc_dev: %x\n", ep_bus, ecrc_dev);
210 u32 rcecea_bitmap = 0x1 << ecrc_dev;
211 u32 rcecea_busnum = (ep_bus << 8) | (ep_bus << 16);
212 pci_write_config32(dev, rcecea_cap + PCI_RCECEA_BITMAP, rcecea_bitmap);
213 pci_write_config32(dev, rcecea_cap + PCI_RCECEA_BUSNUM, rcecea_busnum);
214}
215
216#define SPR_IEH 0x0b23
217
218static const unsigned short rcec_ids[] = {
219 SPR_IEH,
220 0
221};
222
223static struct device_operations rcec_ops = {
224 .read_resources = pci_dev_read_resources,
225 .set_resources = pci_dev_set_resources,
226 .enable_resources = pci_dev_enable_resources,
227 .init = rcec_init,
228 .ops_pci = &soc_pci_ops,
229};
230
231static const struct pci_driver rcec_driver __pci_driver = {
232 .ops = &rcec_ops,
233 .vendor = PCI_VID_INTEL,
234 .devices = rcec_ids,
235};