Debian Codegraph @

src/soc/intel/xeon_sp/chip_gen1.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 #include <acpi/acpigen_pci.h>
4 #include <assert.h>
5 #include <device/pci.h>
6 #include <device/pci_ids.h>
7 #include <soc/pci_devs.h>
8 #include <intelblocks/acpi.h>
9 #include <intelblocks/vtd.h>
10 #include <soc/acpi.h>
11 #include <soc/chip_common.h>
12 #include <soc/soc_util.h>
13 #include <soc/util.h>
14
15 static const STACK_RES *domain_to_stack_res(const struct device *dev)
16 {
17 assert(dev->path.type == DEVICE_PATH_DOMAIN);
18 const union xeon_domain_path dn = {
19 .domain_path = dev_get_domain_id(dev)
20 };
21
22 const IIO_UDS *hob = get_iio_uds();
23 assert(hob != NULL);
24
25 return &hob->PlatformData.IIO_resource[dn.socket].StackRes[dn.stack];
26 }
27
28 static void iio_pci_domain_read_resources(struct device *dev)
29 {
30 const STACK_RES *sr = domain_to_stack_res(dev);
31 struct device *vtd_dev;
32
33 if (!sr)
34 return;
35
36 int index = 0;
37
38 if (is_domain0(dev)) {
39 /* The 0 - 0xfff IO range is not reported by the HOB but still gets decoded */
40 struct resource *res = new_resource(dev, index++);
41 res->base = 0;
42 res->size = 0x1000;
43 res->limit = 0xfff;
44 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
45 }
46
47 if (sr->PciResourceIoBase < sr->PciResourceIoLimit)
48 domain_io_window_from_to(dev, index++,
49 sr->PciResourceIoBase, sr->PciResourceIoLimit + 1);
50
51 if (sr->PciResourceMem32Base < sr->PciResourceMem32Limit)
52 domain_mem_window_from_to(dev, index++,
53 sr->PciResourceMem32Base, sr->PciResourceMem32Limit + 1);
54
55 if (sr->PciResourceMem64Base < sr->PciResourceMem64Limit)
56 domain_mem_window_from_to(dev, index++,
57 sr->PciResourceMem64Base, sr->PciResourceMem64Limit + 1);
58
59 /* Declare domain reserved MMIO */
60 vtd_dev = pcidev_on_root(VTD_DEV_NUM, VTD_FUNC_NUM);
61 assert(vtd_dev);
62
63 uint64_t reserved_mmio = sr->VtdBarAddress + vtd_probe_bar_size(vtd_dev);
64 if ((reserved_mmio >= sr->PciResourceMem32Base) &&
65 (reserved_mmio <= sr->PciResourceMem32Limit))
66 mmio_range(dev, index++, reserved_mmio,
67 sr->PciResourceMem32Limit - reserved_mmio + 1);
68 }
69
70 /*
71 * Used by IIO stacks for PCIe bridges. Those contain 1 PCI host bridges,
72 * all the bus numbers on the IIO stack can be used for this bridge
73 */
74 static struct device_operations iio_pcie_domain_ops = {
75 .read_resources = iio_pci_domain_read_resources,
76 .set_resources = pci_domain_set_resources,
77 .scan_bus = pci_host_bridge_scan_bus,
78 #if CONFIG(HAVE_ACPI_TABLES)
79 .acpi_name = soc_acpi_name,
80 .write_acpi_tables = northbridge_write_acpi_tables,
81 .acpi_fill_ssdt = pci_domain_fill_ssdt,
82 #endif
83 };
84
85 /*
86 * Used by UBOX stacks. Those contain multiple PCI host bridges, each having
87 * only one bus with UBOX devices. UBOX devices have no resources.
88 */
89 static struct device_operations ubox_pcie_domain_ops = {
90 .read_resources = noop_read_resources,
91 .set_resources = noop_set_resources,
92 .scan_bus = pci_host_bridge_scan_bus,
93 #if CONFIG(HAVE_ACPI_TABLES)
94 .acpi_name = soc_acpi_name,
95 .write_acpi_tables = northbridge_write_acpi_tables,
96 .acpi_fill_ssdt = pci_domain_fill_ssdt,
97 #endif
98 };
99
100 static void create_pcie_domains(const union xeon_domain_path dp, struct bus *upstream,
101 const STACK_RES *sr, const size_t pci_segment_group)
102 {
103 create_domain(dp, upstream, sr->BusBase, sr->BusLimit, DOMAIN_TYPE_PCIE,
104 &iio_pcie_domain_ops, pci_segment_group);
105 }
106
107 /*
108 * On the first Xeon-SP generations there are no separate UBOX stacks,
109 * and the UBOX devices reside on the first and second IIO. Starting
110 * with 3rd gen Xeon-SP the UBOX devices are located on their own IIO.
111 */
112 static void create_ubox_domains(const union xeon_domain_path dp, struct bus *upstream,
113 const STACK_RES *sr, const size_t pci_segment_group)
114 {
115 /* Only expect 2 UBOX buses here */
116 assert(sr->BusBase + 1 == sr->BusLimit);
117
118 create_domain(dp, upstream, sr->BusBase, sr->BusBase, DOMAIN_TYPE_UBX0,
119 &ubox_pcie_domain_ops, pci_segment_group);
120 create_domain(dp, upstream, sr->BusLimit, sr->BusLimit, DOMAIN_TYPE_UBX1,
121 &ubox_pcie_domain_ops, pci_segment_group);
122 }
123
124 void create_cxl_domains(const union xeon_domain_path dp, struct bus *bus,
125 const STACK_RES *sr, const size_t pci_segment_group);
126
127 #if CONFIG(SOC_INTEL_HAS_CXL)
128 static void iio_cxl_domain_read_resources(struct device *dev)
129 {
130 const STACK_RES *sr = domain_to_stack_res(dev);
131
132 if (!sr)
133 return;
134
135 int index = 0;
136
137 if (sr->IoBase < sr->PciResourceIoBase)
138 domain_io_window_from_to(dev, index++,
139 sr->IoBase, sr->PciResourceIoBase);
140
141 if (sr->Mmio32Base < sr->PciResourceMem32Base)
142 domain_mem_window_from_to(dev, index++,
143 sr->Mmio32Base, sr->PciResourceMem32Base);
144
145 if (sr->Mmio64Base < sr->PciResourceMem64Base)
146 domain_mem_window_from_to(dev, index++,
147 sr->Mmio64Base, sr->PciResourceMem64Base);
148 }
149
150 static struct device_operations iio_cxl_domain_ops = {
151 .read_resources = iio_cxl_domain_read_resources,
152 .set_resources = pci_domain_set_resources,
153 .scan_bus = pci_host_bridge_scan_bus,
154 #if CONFIG(HAVE_ACPI_TABLES)
155 .acpi_name = soc_acpi_name,
156 .write_acpi_tables = northbridge_write_acpi_tables,
157 .acpi_fill_ssdt = pci_domain_fill_ssdt,
158 #endif
159 };
160
161 void create_cxl_domains(const union xeon_domain_path dp, struct bus *bus,
162 const STACK_RES *sr, const size_t pci_segment_group)
163 {
164 assert(sr->BusBase + 1 <= sr->BusLimit);
165
166 /* 1st domain contains PCIe RCiEPs */
167 create_domain(dp, bus, sr->BusBase, sr->BusBase, DOMAIN_TYPE_PCIE,
168 &iio_pcie_domain_ops, pci_segment_group);
169 /* 2nd domain contains CXL 1.1 end-points */
170 create_domain(dp, bus, sr->BusBase + 1, sr->BusLimit, DOMAIN_TYPE_CXL,
171 &iio_cxl_domain_ops, pci_segment_group);
172 }
173 #endif //CONFIG(SOC_INTEL_HAS_CXL)
174
175 void create_xeonsp_domains(const union xeon_domain_path dp, struct bus *bus,
176 const STACK_RES *sr, const size_t pci_segment_group)
177 {
178 if (is_ubox_stack_res(sr))
179 create_ubox_domains(dp, bus, sr, pci_segment_group);
180 else if (CONFIG(SOC_INTEL_HAS_CXL) && is_iio_cxl_stack_res(sr))
181 create_cxl_domains(dp, bus, sr, pci_segment_group);
182 else if (is_pcie_iio_stack_res(sr))
183 create_pcie_domains(dp, bus, sr, pci_segment_group);
184 else if (CONFIG(HAVE_IOAT_DOMAINS) && is_ioat_iio_stack_res(sr))
185 create_ioat_domains(dp, bus, sr, pci_segment_group);
186 }