blob: 169f4f848b6009bbe711509bec64edf6a396b1ae [file] [log] [blame]
Jonathan Zhang3ed903f2023-01-25 11:37:27 -08001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <console/console.h>
4#include <commonlib/stdlib.h>
5#include <device/device.h>
6#include <device/pci_ops.h>
7#include <device/pci.h>
8#include <device/pciexp.h>
9#include <soc/numa.h>
10#include <soc/soc_util.h>
11#include <soc/util.h>
12#include <types.h>
13
14void dump_pds(void)
15{
16 printk(BIOS_DEBUG, "====== Proximity Domain Dump ======\n");
17 printk(BIOS_DEBUG, "number of proximity domains: %d\n", pds.num_pds);
18 for (uint8_t i = 0; i < pds.num_pds; i++) {
19 printk(BIOS_DEBUG, "\tproximity domain %d:\n", i);
20 printk(BIOS_DEBUG, "\t\ttype:%d\n", pds.pds[i].pd_type);
21 printk(BIOS_DEBUG, "\t\tsocket_bitmap:0x%x\n", pds.pds[i].socket_bitmap);
Patrick Rudolphf25d58c2024-01-31 11:31:55 +010022 printk(BIOS_DEBUG, "\t\tdevice:%s\n", pds.pds[i].dev ? dev_path(pds.pds[i].dev) : "");
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080023 printk(BIOS_DEBUG, "\t\tbase(64MB):0x%x\n", pds.pds[i].base);
24 printk(BIOS_DEBUG, "\t\tsize(64MB):0x%x\n", pds.pds[i].size);
25 }
26}
27
28enum cb_err fill_pds(void)
29{
30 uint8_t num_sockets = soc_get_num_cpus();
31 uint8_t num_cxlnodes = get_cxl_node_count();
Patrick Rudolph92904bc2023-07-14 17:50:52 +020032 const IIO_UDS *hob = get_iio_uds();
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080033
34 /*
35 * Rules/assumptions:
36 * 1. Each processor has a processor proximity domain regardless whether
37 * a processor has DIMM attached to it or not.
38 * 2. All system memory map elements are either from processor attached memory,
39 * or from CXL memory. Each CXL node info entry has a corresponding entry
40 * in system memory map elements.
41 * 3. Each CXL device may have multiple HDMs (Host-managed Device Memory). Each
42 * HDM has one and only one CXL node info entry. Each CXL node info entry
43 * represents a generic initiator proximity domain.
44 */
45 pds.num_pds = num_cxlnodes + num_sockets;
46 pds.pds = xmalloc(sizeof(struct proximity_domain) * pds.num_pds);
47 if (!pds.pds)
Nico Huberfeba51b2023-05-15 18:33:50 +020048 die("%s %d out of memory.", __FILE__, __LINE__);
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080049
50 memset(pds.pds, 0, sizeof(struct proximity_domain) * pds.num_pds);
51
52 /* Fill in processor domains */
Patrick Rudolphac028572023-07-14 17:44:33 +020053 uint8_t i, j, socket;
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080054 struct device *dev;
Patrick Rudolphac028572023-07-14 17:44:33 +020055 for (socket = 0, i = 0; i < num_sockets; socket++) {
56 if (!soc_cpu_is_enabled(socket))
57 continue;
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080058 pds.pds[i].pd_type = PD_TYPE_PROCESSOR;
Patrick Rudolphac028572023-07-14 17:44:33 +020059 pds.pds[i].socket_bitmap = 1 << hob->PlatformData.IIO_resource[socket].SocketID;
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080060 pds.pds[i].distances = malloc(sizeof(uint8_t) * pds.num_pds);
61 if (!pds.pds[i].distances)
Nico Huberfeba51b2023-05-15 18:33:50 +020062 die("%s %d out of memory.", __FILE__, __LINE__);
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080063 /* hard code the distances for now, till we know how to calculate them. */
64 for (j = 0; j < pds.num_pds; j++) {
65 if (j == i)
66 pds.pds[i].distances[j] = 0x0a;
67 else
68 pds.pds[i].distances[j] = 0x0e;
69 }
Patrick Rudolphac028572023-07-14 17:44:33 +020070 i++;
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080071 }
72
73 /* If there are no CXL nodes, we are done */
74 if (num_cxlnodes == 0)
75 return CB_SUCCESS;
76
77 /* There are CXL nodes, fill in generic initiator domain after the processors pds */
78 uint8_t skt_id, cxl_id;
79 const CXL_NODE_SOCKET *cxl_hob = get_cxl_node();
80 for (skt_id = 0, i = num_sockets; skt_id < MAX_SOCKET; skt_id++, i++) {
81 for (cxl_id = 0; cxl_id < cxl_hob[skt_id].CxlNodeCount; ++cxl_id) {
82 const CXL_NODE_INFO node = cxl_hob[skt_id].CxlNodeInfo[cxl_id];
83 pds.pds[i].pd_type = PD_TYPE_GENERIC_INITIATOR;
84 pds.pds[i].socket_bitmap = node.SocketBitmap;
85 pds.pds[i].base = node.Address;
86 pds.pds[i].size = node.Size;
87 dev = pcie_find_dsn(node.SerialNumber, node.VendorId, 0);
Patrick Rudolphf25d58c2024-01-31 11:31:55 +010088 pds.pds[i].dev = dev;
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080089 pds.pds[i].distances = malloc(sizeof(uint8_t) * pds.num_pds);
90 if (!pds.pds[i].distances)
Nico Huberfeba51b2023-05-15 18:33:50 +020091 die("%s %d out of memory.", __FILE__, __LINE__);
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080092 /* hard code the distances until we know how to calculate them */
93 for (j = 0; j < pds.num_pds; j++) {
94 if (j == i)
95 pds.pds[i].distances[j] = 0x0a;
96 else
97 pds.pds[i].distances[j] = 0x0e;
98 }
99 }
100 }
101
102 return CB_SUCCESS;
103}
104
105/*
106 * Return the total size of memory regions in generic initiator affinity domains.
107 * The size is in unit of 64MB.
108 */
109uint32_t get_generic_initiator_mem_size(void)
110{
111 uint8_t i;
112 uint32_t size = 0;
113
114 for (i = 0; i < pds.num_pds; i++) {
115 if (pds.pds[i].pd_type == PD_TYPE_PROCESSOR)
116 continue;
117 size += pds.pds[i].size;
118 }
119
120 return size;
121}