blob: 92ed0bf82c6e61fea08e4ed1f66e3e29768195dc [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);
22 printk(BIOS_DEBUG, "\t\tdevice_handle:0x%x\n", pds.pds[i].device_handle);
23 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();
32
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 */
52 uint8_t i, j;
53 struct device *dev;
54 for (i = 0; i < num_sockets; i++) {
55 pds.pds[i].pd_type = PD_TYPE_PROCESSOR;
56 pds.pds[i].socket_bitmap = 1 << i;
57 pds.pds[i].distances = malloc(sizeof(uint8_t) * pds.num_pds);
58 if (!pds.pds[i].distances)
Nico Huberfeba51b2023-05-15 18:33:50 +020059 die("%s %d out of memory.", __FILE__, __LINE__);
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080060 /* hard code the distances for now, till we know how to calculate them. */
61 for (j = 0; j < pds.num_pds; j++) {
62 if (j == i)
63 pds.pds[i].distances[j] = 0x0a;
64 else
65 pds.pds[i].distances[j] = 0x0e;
66 }
67 }
68
69 /* If there are no CXL nodes, we are done */
70 if (num_cxlnodes == 0)
71 return CB_SUCCESS;
72
73 /* There are CXL nodes, fill in generic initiator domain after the processors pds */
74 uint8_t skt_id, cxl_id;
75 const CXL_NODE_SOCKET *cxl_hob = get_cxl_node();
76 for (skt_id = 0, i = num_sockets; skt_id < MAX_SOCKET; skt_id++, i++) {
77 for (cxl_id = 0; cxl_id < cxl_hob[skt_id].CxlNodeCount; ++cxl_id) {
78 const CXL_NODE_INFO node = cxl_hob[skt_id].CxlNodeInfo[cxl_id];
79 pds.pds[i].pd_type = PD_TYPE_GENERIC_INITIATOR;
80 pds.pds[i].socket_bitmap = node.SocketBitmap;
81 pds.pds[i].base = node.Address;
82 pds.pds[i].size = node.Size;
83 dev = pcie_find_dsn(node.SerialNumber, node.VendorId, 0);
84 pds.pds[i].device_handle = PCI_BDF(dev);
85 pds.pds[i].distances = malloc(sizeof(uint8_t) * pds.num_pds);
86 if (!pds.pds[i].distances)
Nico Huberfeba51b2023-05-15 18:33:50 +020087 die("%s %d out of memory.", __FILE__, __LINE__);
Jonathan Zhang3ed903f2023-01-25 11:37:27 -080088 /* hard code the distances until we know how to calculate them */
89 for (j = 0; j < pds.num_pds; j++) {
90 if (j == i)
91 pds.pds[i].distances[j] = 0x0a;
92 else
93 pds.pds[i].distances[j] = 0x0e;
94 }
95 }
96 }
97
98 return CB_SUCCESS;
99}
100
101/*
102 * Return the total size of memory regions in generic initiator affinity domains.
103 * The size is in unit of 64MB.
104 */
105uint32_t get_generic_initiator_mem_size(void)
106{
107 uint8_t i;
108 uint32_t size = 0;
109
110 for (i = 0; i < pds.num_pds; i++) {
111 if (pds.pds[i].pd_type == PD_TYPE_PROCESSOR)
112 continue;
113 size += pds.pds[i].size;
114 }
115
116 return size;
117}