Jonathan Zhang | 3ed903f | 2023-01-25 11:37:27 -0800 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <console/console.h> |
Jonathan Zhang | 3ed903f | 2023-01-25 11:37:27 -0800 | [diff] [blame] | 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> |
| 12 | |
| 13 | void 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 Rudolph | f25d58c | 2024-01-31 11:31:55 +0100 | [diff] [blame] | 21 | printk(BIOS_DEBUG, "\t\tdevice:%s\n", pds.pds[i].dev ? dev_path(pds.pds[i].dev) : ""); |
Jonathan Zhang | 3ed903f | 2023-01-25 11:37:27 -0800 | [diff] [blame] | 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); |
| 24 | } |
| 25 | } |
| 26 | |
Patrick Rudolph | 8bbc07e | 2024-02-14 10:44:11 +0100 | [diff] [blame] | 27 | void fill_pds(void) |
Jonathan Zhang | 3ed903f | 2023-01-25 11:37:27 -0800 | [diff] [blame] | 28 | { |
| 29 | uint8_t num_sockets = soc_get_num_cpus(); |
| 30 | uint8_t num_cxlnodes = get_cxl_node_count(); |
Patrick Rudolph | 92904bc | 2023-07-14 17:50:52 +0200 | [diff] [blame] | 31 | const IIO_UDS *hob = get_iio_uds(); |
Jonathan Zhang | 3ed903f | 2023-01-25 11:37:27 -0800 | [diff] [blame] | 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 Huber | feba51b | 2023-05-15 18:33:50 +0200 | [diff] [blame] | 47 | die("%s %d out of memory.", __FILE__, __LINE__); |
Jonathan Zhang | 3ed903f | 2023-01-25 11:37:27 -0800 | [diff] [blame] | 48 | |
| 49 | memset(pds.pds, 0, sizeof(struct proximity_domain) * pds.num_pds); |
| 50 | |
| 51 | /* Fill in processor domains */ |
Patrick Rudolph | ac02857 | 2023-07-14 17:44:33 +0200 | [diff] [blame] | 52 | uint8_t i, j, socket; |
Jonathan Zhang | 3ed903f | 2023-01-25 11:37:27 -0800 | [diff] [blame] | 53 | struct device *dev; |
Patrick Rudolph | ac02857 | 2023-07-14 17:44:33 +0200 | [diff] [blame] | 54 | for (socket = 0, i = 0; i < num_sockets; socket++) { |
| 55 | if (!soc_cpu_is_enabled(socket)) |
| 56 | continue; |
Jonathan Zhang | 3ed903f | 2023-01-25 11:37:27 -0800 | [diff] [blame] | 57 | pds.pds[i].pd_type = PD_TYPE_PROCESSOR; |
Patrick Rudolph | ac02857 | 2023-07-14 17:44:33 +0200 | [diff] [blame] | 58 | pds.pds[i].socket_bitmap = 1 << hob->PlatformData.IIO_resource[socket].SocketID; |
Jonathan Zhang | 3ed903f | 2023-01-25 11:37:27 -0800 | [diff] [blame] | 59 | pds.pds[i].distances = malloc(sizeof(uint8_t) * pds.num_pds); |
| 60 | if (!pds.pds[i].distances) |
Nico Huber | feba51b | 2023-05-15 18:33:50 +0200 | [diff] [blame] | 61 | die("%s %d out of memory.", __FILE__, __LINE__); |
Jonathan Zhang | 3ed903f | 2023-01-25 11:37:27 -0800 | [diff] [blame] | 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; |
| 68 | } |
Patrick Rudolph | ac02857 | 2023-07-14 17:44:33 +0200 | [diff] [blame] | 69 | i++; |
Jonathan Zhang | 3ed903f | 2023-01-25 11:37:27 -0800 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | /* If there are no CXL nodes, we are done */ |
| 73 | if (num_cxlnodes == 0) |
Patrick Rudolph | 8bbc07e | 2024-02-14 10:44:11 +0100 | [diff] [blame] | 74 | return; |
Jonathan Zhang | 3ed903f | 2023-01-25 11:37:27 -0800 | [diff] [blame] | 75 | |
| 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 Rudolph | f25d58c | 2024-01-31 11:31:55 +0100 | [diff] [blame] | 87 | pds.pds[i].dev = dev; |
Jonathan Zhang | 3ed903f | 2023-01-25 11:37:27 -0800 | [diff] [blame] | 88 | pds.pds[i].distances = malloc(sizeof(uint8_t) * pds.num_pds); |
| 89 | if (!pds.pds[i].distances) |
Nico Huber | feba51b | 2023-05-15 18:33:50 +0200 | [diff] [blame] | 90 | die("%s %d out of memory.", __FILE__, __LINE__); |
Jonathan Zhang | 3ed903f | 2023-01-25 11:37:27 -0800 | [diff] [blame] | 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; |
| 97 | } |
| 98 | } |
| 99 | } |
Jonathan Zhang | 3ed903f | 2023-01-25 11:37:27 -0800 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | /* |
| 103 | * Return the total size of memory regions in generic initiator affinity domains. |
| 104 | * The size is in unit of 64MB. |
| 105 | */ |
| 106 | uint32_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 | } |