soc/intel: Remove blank lines before '}' and after '{'
[coreboot2.git] / src / soc / intel / xeon_sp / numa.c
blob62657dce1f91f12e473d0cc5cd705c9af30c5799
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <console/console.h>
4 #include <device/device.h>
5 #include <device/pci_ops.h>
6 #include <device/pci.h>
7 #include <device/pciexp.h>
8 #include <soc/numa.h>
9 #include <soc/soc_util.h>
10 #include <soc/util.h>
11 #include <types.h>
13 void dump_pds(void)
15 printk(BIOS_DEBUG, "====== Proximity Domain Dump ======\n");
16 printk(BIOS_DEBUG, "number of proximity domains: %d\n", pds.num_pds);
17 for (uint8_t i = 0; i < pds.num_pds; i++) {
18 printk(BIOS_DEBUG, "\tproximity domain %d:\n", i);
19 printk(BIOS_DEBUG, "\t\ttype:%d\n", pds.pds[i].pd_type);
20 printk(BIOS_DEBUG, "\t\tsocket_bitmap:0x%x\n", pds.pds[i].socket_bitmap);
21 printk(BIOS_DEBUG, "\t\tdevice:%s\n", pds.pds[i].dev ? dev_path(pds.pds[i].dev) : "");
22 printk(BIOS_DEBUG, "\t\tbase(64MB):0x%x\n", pds.pds[i].base);
23 printk(BIOS_DEBUG, "\t\tsize(64MB):0x%x\n", pds.pds[i].size);
27 void fill_pds(void)
29 uint8_t num_sockets = soc_get_num_cpus();
30 uint8_t num_cxlnodes = get_cxl_node_count();
31 const IIO_UDS *hob = get_iio_uds();
34 * Rules/assumptions:
35 * 1. Each processor has a processor proximity domain regardless whether
36 * a processor has DIMM attached to it or not.
37 * 2. All system memory map elements are either from processor attached memory,
38 * or from CXL memory. Each CXL node info entry has a corresponding entry
39 * in system memory map elements.
40 * 3. Each CXL device may have multiple HDMs (Host-managed Device Memory). Each
41 * HDM has one and only one CXL node info entry. Each CXL node info entry
42 * represents a generic initiator proximity domain.
44 pds.num_pds = num_cxlnodes + num_sockets;
45 pds.pds = xmalloc(sizeof(struct proximity_domain) * pds.num_pds);
46 if (!pds.pds)
47 die("%s %d out of memory.", __FILE__, __LINE__);
49 memset(pds.pds, 0, sizeof(struct proximity_domain) * pds.num_pds);
51 /* Fill in processor domains */
52 uint8_t i, j, socket;
53 struct device *dev;
54 for (socket = 0, i = 0; i < num_sockets; socket++) {
55 if (!soc_cpu_is_enabled(socket))
56 continue;
57 pds.pds[i].pd_type = PD_TYPE_PROCESSOR;
58 pds.pds[i].socket_bitmap = 1 << hob->PlatformData.IIO_resource[socket].SocketID;
59 pds.pds[i].distances = malloc(sizeof(uint8_t) * pds.num_pds);
60 if (!pds.pds[i].distances)
61 die("%s %d out of memory.", __FILE__, __LINE__);
62 /* hard code the distances for now, till we know how to calculate them. */
63 for (j = 0; j < pds.num_pds; j++) {
64 if (j == i)
65 pds.pds[i].distances[j] = 0x0a;
66 else
67 pds.pds[i].distances[j] = 0x0e;
69 i++;
72 /* If there are no CXL nodes, we are done */
73 if (num_cxlnodes == 0)
74 return;
76 /* There are CXL nodes, fill in generic initiator domain after the processors pds */
77 uint8_t skt_id, cxl_id;
78 const CXL_NODE_SOCKET *cxl_hob = get_cxl_node();
79 for (skt_id = 0, i = num_sockets; skt_id < MAX_SOCKET; skt_id++, i++) {
80 for (cxl_id = 0; cxl_id < cxl_hob[skt_id].CxlNodeCount; ++cxl_id) {
81 const CXL_NODE_INFO node = cxl_hob[skt_id].CxlNodeInfo[cxl_id];
82 pds.pds[i].pd_type = PD_TYPE_GENERIC_INITIATOR;
83 pds.pds[i].socket_bitmap = node.SocketBitmap;
84 pds.pds[i].base = node.Address;
85 pds.pds[i].size = node.Size;
86 dev = pcie_find_dsn(node.SerialNumber, node.VendorId, 0);
87 pds.pds[i].dev = dev;
88 pds.pds[i].distances = malloc(sizeof(uint8_t) * pds.num_pds);
89 if (!pds.pds[i].distances)
90 die("%s %d out of memory.", __FILE__, __LINE__);
91 /* hard code the distances until we know how to calculate them */
92 for (j = 0; j < pds.num_pds; j++) {
93 if (j == i)
94 pds.pds[i].distances[j] = 0x0a;
95 else
96 pds.pds[i].distances[j] = 0x0e;
103 * Return the total size of memory regions in generic initiator affinity domains.
104 * The size is in unit of 64MB.
106 uint32_t get_generic_initiator_mem_size(void)
108 uint8_t i;
109 uint32_t size = 0;
111 for (i = 0; i < pds.num_pds; i++) {
112 if (pds.pds[i].pd_type == PD_TYPE_PROCESSOR)
113 continue;
114 size += pds.pds[i].size;
117 return size;