blob: 62657dce1f91f12e473d0cc5cd705c9af30c5799 [file] [log] [blame]
Jonathan Zhang3ed903f2023-01-25 11:37:27 -08001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <console/console.h>
Jonathan Zhang3ed903f2023-01-25 11:37:27 -08004#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>
12
13void dump_pds(void)
14{
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);
Patrick Rudolphf25d58c2024-01-31 11:31:55 +010021 printk(BIOS_DEBUG, "\t\tdevice:%s\n", pds.pds[i].dev ? dev_path(pds.pds[i].dev) : "");
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080022 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);
24 }
25}
26
Patrick Rudolph8bbc07e2024-02-14 10:44:11 +010027void fill_pds(void)
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080028{
29 uint8_t num_sockets = soc_get_num_cpus();
30 uint8_t num_cxlnodes = get_cxl_node_count();
Patrick Rudolph92904bc2023-07-14 17:50:52 +020031 const IIO_UDS *hob = get_iio_uds();
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080032
33 /*
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.
43 */
44 pds.num_pds = num_cxlnodes + num_sockets;
45 pds.pds = xmalloc(sizeof(struct proximity_domain) * pds.num_pds);
46 if (!pds.pds)
Nico Huberfeba51b2023-05-15 18:33:50 +020047 die("%s %d out of memory.", __FILE__, __LINE__);
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080048
49 memset(pds.pds, 0, sizeof(struct proximity_domain) * pds.num_pds);
50
51 /* Fill in processor domains */
Patrick Rudolphac028572023-07-14 17:44:33 +020052 uint8_t i, j, socket;
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080053 struct device *dev;
Patrick Rudolphac028572023-07-14 17:44:33 +020054 for (socket = 0, i = 0; i < num_sockets; socket++) {
55 if (!soc_cpu_is_enabled(socket))
56 continue;
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080057 pds.pds[i].pd_type = PD_TYPE_PROCESSOR;
Patrick Rudolphac028572023-07-14 17:44:33 +020058 pds.pds[i].socket_bitmap = 1 << hob->PlatformData.IIO_resource[socket].SocketID;
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080059 pds.pds[i].distances = malloc(sizeof(uint8_t) * pds.num_pds);
60 if (!pds.pds[i].distances)
Nico Huberfeba51b2023-05-15 18:33:50 +020061 die("%s %d out of memory.", __FILE__, __LINE__);
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080062 /* 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;
68 }
Patrick Rudolphac028572023-07-14 17:44:33 +020069 i++;
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080070 }
71
72 /* If there are no CXL nodes, we are done */
73 if (num_cxlnodes == 0)
Patrick Rudolph8bbc07e2024-02-14 10:44:11 +010074 return;
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080075
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);
Patrick Rudolphf25d58c2024-01-31 11:31:55 +010087 pds.pds[i].dev = dev;
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080088 pds.pds[i].distances = malloc(sizeof(uint8_t) * pds.num_pds);
89 if (!pds.pds[i].distances)
Nico Huberfeba51b2023-05-15 18:33:50 +020090 die("%s %d out of memory.", __FILE__, __LINE__);
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080091 /* 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;
97 }
98 }
99 }
Jonathan Zhang3ed903f2023-01-25 11:37:27 -0800100}
101
102/*
103 * Return the total size of memory regions in generic initiator affinity domains.
104 * The size is in unit of 64MB.
105 */
106uint32_t get_generic_initiator_mem_size(void)
107{
108 uint8_t i;
109 uint32_t size = 0;
110
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;
115 }
116
117 return size;
118}