Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | |
| 3 | #include <soc/acpi.h> |
| 4 | #include <soc/numa.h> |
| 5 | #include <soc/util.h> |
| 6 | |
| 7 | unsigned long cxl_fill_srat(unsigned long current) |
| 8 | { |
| 9 | /* |
| 10 | * Create Generic Initiator Affinity structure |
| 11 | * and Memory Affinity structure for CXL memory. |
| 12 | * In the pds (Proximity Domains structure), Generic Initiator domains |
| 13 | * are after processor domains. |
| 14 | */ |
| 15 | uint16_t seg = 0; |
| 16 | uint8_t bus, dev, func; |
| 17 | uint32_t base, size; |
| 18 | for (uint8_t i = soc_get_num_cpus(); i < pds.num_pds; i++) { |
| 19 | bus = pds.pds[i].device_handle >> 20; |
| 20 | dev = (pds.pds[i].device_handle >> 15) & 0x1f; |
| 21 | func = (pds.pds[i].device_handle >> 12) & 0x07; |
| 22 | printk(BIOS_DEBUG, |
| 23 | "adding srat GIA ID: %d, seg: 0x%x, bus: 0x%x, dev: 0x%x, func: 0x%x\n", |
| 24 | i, seg, bus, dev, func); |
| 25 | /* flags: 1 (enabled) */ |
| 26 | current += acpi_create_srat_gia_pci((acpi_srat_gia_t *)current, i, seg, bus, |
| 27 | dev, func, 1); |
| 28 | base = pds.pds[i].base << 16; |
| 29 | size = pds.pds[i].size << 16; |
| 30 | printk(BIOS_DEBUG, |
| 31 | "adding srat MEM affinity domain: %d, base: 0x%x, size: 0x%x\n", i, base, |
| 32 | size); |
| 33 | current += |
| 34 | acpi_create_srat_mem((acpi_srat_mem_t *)current, i, |
| 35 | pds.pds[i].base << 16, pds.pds[i].size << 16, 1); |
| 36 | } |
| 37 | |
| 38 | return current; |
| 39 | } |
| 40 | |
| 41 | /* |
| 42 | * The current kernel does not use HMAT table. |
| 43 | */ |
| 44 | unsigned long acpi_fill_hmat(unsigned long current) |
| 45 | { |
| 46 | uint32_t pd_initiator = 0; |
| 47 | uint32_t pd_memory = 0; |
| 48 | |
| 49 | /* In CXL2.0, CXL memories attached to different sockets could be ganged |
| 50 | * to form a single CXL memory region. |
| 51 | * For now, we do not consider this case, and assume socket_bitmap has |
| 52 | * only one bit set, eg. a CXL memory region is attached to one socket. |
| 53 | */ |
| 54 | uint8_t j; |
| 55 | for (uint8_t i = soc_get_num_cpus(); i < pds.num_pds; i++) { |
| 56 | pd_memory = i; |
| 57 | /* check socket_bitmap which is type uint8_t */ |
| 58 | for (j = 0; j < 8; j++) |
| 59 | if ((pds.pds[i].socket_bitmap >> j) == 0) |
| 60 | break; |
| 61 | pd_initiator = j - 1; |
| 62 | printk(BIOS_DEBUG, "HMAT: pd_initiator = %d, pd_memory = %d\n", pd_initiator, |
| 63 | pd_memory); |
| 64 | current += acpi_create_hmat_mpda((acpi_hmat_mpda_t *)current, pd_initiator, |
| 65 | pd_memory); |
| 66 | } |
| 67 | |
| 68 | /* |
| 69 | * We created only MPDA structure. In future, we could create |
| 70 | * SLLBI structure to describe latency/bandwidth info when such info |
| 71 | * is available. |
| 72 | */ |
| 73 | |
| 74 | return current; |
| 75 | } |