blob: 16e059b34ac0a8b40d494da44253a94cbbb0c7e0 [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 = {
50 .read_resources = &pci_domain_read_resources,
51 .set_resources = &xeonsp_pci_domain_set_resources,
52 .scan_bus = &xeonsp_pci_domain_scan_bus,
53#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{
95 for (uint32_t socket = 0; socket < soc_get_num_cpus(); ++socket) {
96 const uint32_t bus = get_ubox_busno(socket, UNCORE_BUS_1);
97
98 /* configure PCU_CR0_FUN csrs */
99 pcu_pci_or_config32(bus, PCU_CR0_FUN, PCU_CR0_P_STATE_LIMITS,
100 P_STATE_LIMITS_LOCK);
101 pcu_pci_or_config32(bus, PCU_CR0_FUN, PCU_CR0_PACKAGE_RAPL_LIMIT_UPR,
102 PKG_PWR_LIM_LOCK_UPR);
103 pcu_pci_or_config32(bus, PCU_CR0_FUN, PCU_CR0_TURBO_ACTIVATION_RATIO,
104 TURBO_ACTIVATION_RATIO_LOCK);
105
106 /* configure PCU_CR2_FUN csrs */
107 pcu_pci_or_config32(bus, PCU_CR2_FUN, PCU_CR2_DRAM_POWER_INFO_UPR,
108 DRAM_POWER_INFO_LOCK_UPR);
109 pcu_pci_or_config32(bus, PCU_CR2_FUN, PCU_CR2_DRAM_PLANE_POWER_LIMIT_UPR,
110 PP_PWR_LIM_LOCK_UPR);
111
112 /* configure PCU_CR3_FUN csrs */
113 pcu_pci_or_config32(bus, PCU_CR3_FUN, PCU_CR3_CONFIG_TDP_CONTROL, TDP_LOCK);
114
115 /* configure PCU_CR6_FUN csrs */
116 pcu_pci_or_config32(bus, PCU_CR6_FUN, PCU_CR6_PLATFORM_RAPL_LIMIT_CFG_UPR,
117 PLT_PWR_LIM_LOCK_UPR);
118 pcu_pci_or_config32(bus, PCU_CR6_FUN, PCU_CR6_PLATFORM_POWER_INFO_CFG_UPR,
119 PLT_PWR_INFO_LOCK_UPR);
120 }
121}
122
123static void chip_final(void *data)
124{
125 /* Lock SBI */
126 pci_or_config32(PCH_DEV_P2SB, P2SBC, SBILOCK);
127
128 /* LOCK PAM */
129 pci_or_config32(pcidev_path_on_root(PCI_DEVFN(0, 0)), 0x80, 1 << 0);
130
131 set_pcu_locks();
132 tco_lockdown();
133
134 p2sb_hide();
135
136 /* Accessing xHCI CSR needs to be done after PCI enumeration. */
137 lock_oc_cfg(false);
138 mainboard_override_usb_oc();
139 lock_oc_cfg(true);
140 /* Disable CPU Crashlog to avoid conflict between CPU Crashlog and BMC ACD. */
141 disable_cpu_crashlog();
142
143 set_bios_init_completion();
144}
145
146static void chip_init(void *data)
147{
148 printk(BIOS_DEBUG, "coreboot: calling fsp_silicon_init\n");
149 fsp_silicon_init();
150 override_hpet_ioapic_bdf();
151 pch_enable_ioapic();
152 pch_lock_dmictl();
153 p2sb_unhide();
154 lock_gpio(false);
155 mainboard_override_fsp_gpio();
156 lock_gpio(true);
157}
158
159struct chip_operations soc_intel_xeon_sp_spr_ops = {
160 CHIP_NAME("Intel SapphireRapids-SP").enable_dev = chip_enable_dev,
161 .init = chip_init,
162 .final = chip_final,
163};
164
165void lock_gpio(bool lock)
166{
167 if (lock) {
168 pcr_write32(gpio_get_pad_portid(GPPC_B0), PAD_CFG_LOCK_B, 0xffffffff);
169 pcr_write32(gpio_get_pad_portid(GPP_D0), PAD_CFG_LOCK_D, 0xffffffff);
170 } else {
171 pcr_write32(gpio_get_pad_portid(GPPC_B0), PAD_CFG_LOCK_B, 0);
172 pcr_write32(gpio_get_pad_portid(GPP_D0), PAD_CFG_LOCK_D, 0);
173 }
174}
175
176/* Root Complex Event Collector */
177static void rcec_init(struct device *dev)
178{
179 /* Set up RCEC EA extended capability, section 7.9.10 of PCIe 5.0 spec */
180 const unsigned int rcecea_cap =
181 pciexp_find_extended_cap(dev, PCIE_EXT_CAP_RCECEA_ID, 0);
182 if (!rcecea_cap)
183 return;
184
185 pci_devfn_t ecrc_bdf = PCI_BDF(dev);
186 uint32_t ecrc_bus = (ecrc_bdf >> 20) & 0xFFF;
187 uint32_t ecrc_dev = (ecrc_bdf >> 15) & 0x1F;
188
189 /*
190 * Find all CXL devices, and match them with RCEC.
191 * With CXL 1.1, the bus# of CXL device (RCiEP) is 1 bigger than
192 * the bus# of RCEC.
193 */
194 uint32_t ep_bus;
195 uint8_t i;
196 for (i = 0; i < pds.num_pds; i++) {
197 if (pds.pds[i].pd_type == PD_TYPE_PROCESSOR)
198 continue;
199 ep_bus = pds.pds[i].device_handle >> 20;
200 if (ep_bus == ecrc_bus + 1)
201 break;
202 }
203 if (i == pds.num_pds)
204 return;
205
206 printk(BIOS_DEBUG, "ep_bus: %x, ecrc_dev: %x\n", ep_bus, ecrc_dev);
207 u32 rcecea_bitmap = 0x1 << ecrc_dev;
208 u32 rcecea_busnum = (ep_bus << 8) | (ep_bus << 16);
209 pci_write_config32(dev, rcecea_cap + PCI_RCECEA_BITMAP, rcecea_bitmap);
210 pci_write_config32(dev, rcecea_cap + PCI_RCECEA_BUSNUM, rcecea_busnum);
211}
212
213#define SPR_IEH 0x0b23
214
215static const unsigned short rcec_ids[] = {
216 SPR_IEH,
217 0
218};
219
220static struct device_operations rcec_ops = {
221 .read_resources = pci_dev_read_resources,
222 .set_resources = pci_dev_set_resources,
223 .enable_resources = pci_dev_enable_resources,
224 .init = rcec_init,
225 .ops_pci = &soc_pci_ops,
226};
227
228static const struct pci_driver rcec_driver __pci_driver = {
229 .ops = &rcec_ops,
230 .vendor = PCI_VID_INTEL,
231 .devices = rcec_ids,
232};