Debian Codegraph @

src/soc/intel/xeon_sp/spr/chip.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #include <acpi/acpigen_pci.h>
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/acpi.h>
11 #include <intelblocks/gpio.h>
12 #include <intelblocks/lpc_lib.h>
13 #include <intelblocks/p2sb.h>
14 #include <intelblocks/pcr.h>
15 #include <intelblocks/tco.h>
16 #include <soc/acpi.h>
17 #include <soc/chip_common.h>
18 #include <soc/crashlog.h>
19 #include <soc/numa.h>
20 #include <soc/p2sb.h>
21 #include <soc/pch.h>
22 #include <soc/soc_pch.h>
23 #include <soc/pci_devs.h>
24 #include <soc/ramstage.h>
25 #include <soc/soc_util.h>
26 #include <soc/util.h>
27 #include <soc/xhci.h>
28
29 __weak void mainboard_silicon_init_params(FSPS_UPD *params)
30 {
31 }
32
33 /* UPD parameters to be initialized before SiliconInit */
34 void platform_fsp_silicon_init_params_cb(FSPS_UPD *silupd)
35 {
36 mainboard_silicon_init_params(silupd);
37 }
38
39 static struct device_operations cpu_bus_ops = {
40 .read_resources = noop_read_resources,
41 .set_resources = noop_set_resources,
42 .init = mp_cpu_bus_init,
43 .acpi_fill_ssdt = generate_cpu_entries,
44 };
45
46 struct pci_operations soc_pci_ops = {
47 .set_subsystem = pci_dev_set_subsystem,
48 };
49
50 static void chip_enable_dev(struct device *dev)
51 {
52 /* Set the operations if it is a special bus type */
53 if (dev->path.type == DEVICE_PATH_DOMAIN) {
54 /* domain ops are assigned at their creation */
55 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
56 dev->ops = &cpu_bus_ops;
57 } else if (dev->path.type == DEVICE_PATH_GPIO) {
58 block_gpio_enable(dev);
59 }
60 }
61
62 static void chip_final(void *data)
63 {
64 /* Lock SBI */
65 pci_or_config32(PCH_DEV_P2SB, P2SBC, SBILOCK);
66
67 /* LOCK PAM */
68 pci_or_config32(pcidev_path_on_root(PCI_DEVFN(0, 0)), 0x80, 1 << 0);
69
70 tco_lockdown();
71
72 p2sb_hide();
73
74 /* Accessing xHCI CSR needs to be done after PCI enumeration. */
75 lock_oc_cfg(false);
76 mainboard_override_usb_oc();
77 lock_oc_cfg(true);
78 /* Disable CPU Crashlog to avoid conflict between CPU Crashlog and BMC ACD. */
79 disable_cpu_crashlog();
80 }
81
82 static void chip_init(void *data)
83 {
84 printk(BIOS_DEBUG, "coreboot: calling fsp_silicon_init\n");
85 fsp_silicon_init();
86
87 setup_pds();
88 attach_iio_stacks();
89
90 override_hpet_ioapic_bdf();
91 pch_enable_ioapic();
92 pch_lock_dmictl();
93 p2sb_unhide();
94 lock_gpio(false);
95 mainboard_override_fsp_gpio();
96 lock_gpio(true);
97 }
98
99 struct chip_operations soc_intel_xeon_sp_spr_ops = {
100 .name = "Intel SapphireRapids-SP",
101 .enable_dev = chip_enable_dev,
102 .init = chip_init,
103 .final = chip_final,
104 };
105
106 void lock_gpio(bool lock)
107 {
108 if (lock) {
109 pcr_write32(gpio_get_pad_portid(GPPC_B0), PAD_CFG_LOCK_B, 0xffffffff);
110 pcr_write32(gpio_get_pad_portid(GPP_D0), PAD_CFG_LOCK_D, 0xffffffff);
111 } else {
112 pcr_write32(gpio_get_pad_portid(GPPC_B0), PAD_CFG_LOCK_B, 0);
113 pcr_write32(gpio_get_pad_portid(GPP_D0), PAD_CFG_LOCK_D, 0);
114 }
115 }
116
117 /* Root Complex Event Collector */
118 static void rcec_init(struct device *dev)
119 {
120 /* Set up RCEC EA extended capability, section 7.9.10 of PCIe 5.0 spec */
121 const unsigned int rcecea_cap =
122 pciexp_find_extended_cap(dev, PCIE_EXT_CAP_RCECEA_ID, 0);
123 if (!rcecea_cap)
124 return;
125
126 pci_devfn_t ecrc_bdf = PCI_BDF(dev);
127 uint32_t ecrc_bus = (ecrc_bdf >> 20) & 0xFFF;
128 uint32_t ecrc_dev = (ecrc_bdf >> 15) & 0x1F;
129
130 /*
131 * Find all CXL devices, and match them with RCEC.
132 * With CXL 1.1, the bus# of CXL device (RCiEP) is 1 bigger than
133 * the bus# of RCEC.
134 */
135 uint32_t ep_bus;
136 uint8_t i;
137 for (i = 0; i < pds.num_pds; i++) {
138 if (pds.pds[i].pd_type != PD_TYPE_GENERIC_INITIATOR)
139 continue;
140 ep_bus = PCI_BDF(pds.pds[i].dev) >> 20;
141 if (ep_bus == ecrc_bus + 1)
142 break;
143 }
144 if (i == pds.num_pds)
145 return;
146
147 printk(BIOS_DEBUG, "ep_bus: %x, ecrc_dev: %x\n", ep_bus, ecrc_dev);
148 u32 rcecea_bitmap = 0x1 << ecrc_dev;
149 u32 rcecea_busnum = (ep_bus << 8) | (ep_bus << 16);
150 pci_write_config32(dev, rcecea_cap + PCI_RCECEA_BITMAP, rcecea_bitmap);
151 pci_write_config32(dev, rcecea_cap + PCI_RCECEA_BUSNUM, rcecea_busnum);
152 }
153
154 #define SPR_IEH 0x0b23
155
156 static const unsigned short rcec_ids[] = {
157 SPR_IEH,
158 0
159 };
160
161 static struct device_operations rcec_ops = {
162 .read_resources = pci_dev_read_resources,
163 .set_resources = pci_dev_set_resources,
164 .enable_resources = pci_dev_enable_resources,
165 .init = rcec_init,
166 .ops_pci = &soc_pci_ops,
167 };
168
169 static const struct pci_driver rcec_driver __pci_driver = {
170 .ops = &rcec_ops,
171 .vendor = PCI_VID_INTEL,
172 .devices = rcec_ids,
173 };