Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | |
| 3 | #include <acpi/acpigen.h> |
Felix Held | 4b2464f | 2022-02-23 17:54:20 +0100 | [diff] [blame] | 4 | #include <arch/hpet.h> |
Patrick Rudolph | 57ddd68 | 2023-02-28 09:17:40 +0100 | [diff] [blame] | 5 | #include <arch/ioapic.h> |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 6 | #include <assert.h> |
| 7 | #include <cbmem.h> |
Naresh Solanki | 559f9ed | 2023-01-20 19:38:07 +0100 | [diff] [blame] | 8 | #include <cpu/x86/lapic.h> |
Arthur Heymans | 36e6f9b | 2022-10-27 15:11:05 +0200 | [diff] [blame] | 9 | #include <commonlib/sort.h> |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 10 | #include <device/mmio.h> |
| 11 | #include <device/pci.h> |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 12 | #include <device/pciexp.h> |
Patrick Rudolph | 425e421 | 2024-02-15 16:30:16 +0100 | [diff] [blame] | 13 | #include <device/pci_ids.h> |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 14 | #include <soc/acpi.h> |
Patrick Rudolph | 425e421 | 2024-02-15 16:30:16 +0100 | [diff] [blame] | 15 | #include <soc/chip_common.h> |
Rocky Phagura | d4db36e | 2021-04-03 08:49:32 -0700 | [diff] [blame] | 16 | #include <soc/hest.h> |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 17 | #include <soc/iomap.h> |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 18 | #include <soc/numa.h> |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 19 | #include <soc/pci_devs.h> |
| 20 | #include <soc/soc_util.h> |
Marc Jones | 18960ce | 2020-11-02 12:41:12 -0700 | [diff] [blame] | 21 | #include <soc/util.h> |
Arthur Heymans | 695dd29 | 2020-11-12 21:05:09 +0100 | [diff] [blame] | 22 | #include <intelblocks/p2sb.h> |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 23 | #include "chip.h" |
| 24 | |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 25 | /* NUMA related ACPI table generation. SRAT, SLIT, etc */ |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 26 | |
Arthur Heymans | 36e6f9b | 2022-10-27 15:11:05 +0200 | [diff] [blame] | 27 | /* Increase if necessary. Currently all x86 CPUs only have 2 SMP threads */ |
| 28 | #define MAX_THREAD 2 |
| 29 | |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 30 | unsigned long acpi_create_srat_lapics(unsigned long current) |
| 31 | { |
| 32 | struct device *cpu; |
Arthur Heymans | 36e6f9b | 2022-10-27 15:11:05 +0200 | [diff] [blame] | 33 | unsigned int num_cpus = 0; |
| 34 | int apic_ids[CONFIG_MAX_CPUS] = {}; |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 35 | |
Arthur Heymans | 36e6f9b | 2022-10-27 15:11:05 +0200 | [diff] [blame] | 36 | unsigned int sort_start = 0; |
| 37 | for (unsigned int thread_id = 0; thread_id < MAX_THREAD; thread_id++) { |
| 38 | for (cpu = all_devices; cpu; cpu = cpu->next) { |
| 39 | if (!is_enabled_cpu(cpu)) |
| 40 | continue; |
| 41 | if (num_cpus >= ARRAY_SIZE(apic_ids)) |
| 42 | break; |
| 43 | if (cpu->path.apic.thread_id != thread_id) |
| 44 | continue; |
| 45 | apic_ids[num_cpus++] = cpu->path.apic.apic_id; |
| 46 | } |
| 47 | bubblesort(&apic_ids[sort_start], num_cpus - sort_start, NUM_ASCENDING); |
| 48 | sort_start = num_cpus; |
| 49 | } |
| 50 | |
| 51 | for (unsigned int i = 0; i < num_cpus; i++) { |
| 52 | /* Match the sorted apic_ids to a struct device */ |
| 53 | for (cpu = all_devices; cpu; cpu = cpu->next) { |
| 54 | if (!is_enabled_cpu(cpu)) |
| 55 | continue; |
| 56 | if (cpu->path.apic.apic_id == apic_ids[i]) |
| 57 | break; |
| 58 | } |
| 59 | if (!cpu) |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 60 | continue; |
Naresh Solanki | 559f9ed | 2023-01-20 19:38:07 +0100 | [diff] [blame] | 61 | |
| 62 | if (is_x2apic_mode()) { |
Arthur Heymans | 36e6f9b | 2022-10-27 15:11:05 +0200 | [diff] [blame] | 63 | printk(BIOS_DEBUG, "SRAT: x2apic cpu_index=%04x, node_id=%02x, apic_id=%08x\n", |
| 64 | i, cpu->path.apic.node_id, cpu->path.apic.apic_id); |
Naresh Solanki | 559f9ed | 2023-01-20 19:38:07 +0100 | [diff] [blame] | 65 | |
| 66 | current += acpi_create_srat_x2apic((acpi_srat_x2apic_t *)current, |
| 67 | cpu->path.apic.node_id, cpu->path.apic.apic_id); |
| 68 | } else { |
| 69 | printk(BIOS_DEBUG, "SRAT: lapic cpu_index=%02x, node_id=%02x, apic_id=%02x\n", |
Arthur Heymans | 36e6f9b | 2022-10-27 15:11:05 +0200 | [diff] [blame] | 70 | i, cpu->path.apic.node_id, cpu->path.apic.apic_id); |
Naresh Solanki | 559f9ed | 2023-01-20 19:38:07 +0100 | [diff] [blame] | 71 | |
| 72 | current += acpi_create_srat_lapic((acpi_srat_lapic_t *)current, |
| 73 | cpu->path.apic.node_id, cpu->path.apic.apic_id); |
| 74 | } |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 75 | } |
| 76 | return current; |
| 77 | } |
| 78 | |
| 79 | static unsigned int get_srat_memory_entries(acpi_srat_mem_t *srat_mem) |
| 80 | { |
| 81 | const struct SystemMemoryMapHob *memory_map; |
| 82 | unsigned int mmap_index; |
| 83 | |
| 84 | memory_map = get_system_memory_map(); |
Elyes Haouas | f1ba7d6 | 2022-09-13 10:03:44 +0200 | [diff] [blame] | 85 | assert(memory_map); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 86 | printk(BIOS_DEBUG, "memory_map: %p\n", memory_map); |
| 87 | |
| 88 | mmap_index = 0; |
| 89 | for (int e = 0; e < memory_map->numberEntries; ++e) { |
| 90 | const struct SystemMemoryMapElement *mem_element = &memory_map->Element[e]; |
| 91 | uint64_t addr = |
Elyes Haouas | 9018dee | 2022-11-18 15:07:33 +0100 | [diff] [blame] | 92 | (uint64_t)((uint64_t)mem_element->BaseAddress << |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 93 | MEM_ADDR_64MB_SHIFT_BITS); |
| 94 | uint64_t size = |
Elyes Haouas | 9018dee | 2022-11-18 15:07:33 +0100 | [diff] [blame] | 95 | (uint64_t)((uint64_t)mem_element->ElementSize << |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 96 | MEM_ADDR_64MB_SHIFT_BITS); |
| 97 | |
| 98 | printk(BIOS_DEBUG, "memory_map %d addr: 0x%llx, BaseAddress: 0x%x, size: 0x%llx, " |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 99 | "ElementSize: 0x%x, type: %d, reserved: %d\n", |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 100 | e, addr, mem_element->BaseAddress, size, |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 101 | mem_element->ElementSize, mem_element->Type, |
Shuo Liu | a5bdf8e | 2024-02-20 01:06:10 +0800 | [diff] [blame] | 102 | is_memtype_reserved(mem_element->Type)); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 103 | |
| 104 | assert(mmap_index < MAX_ACPI_MEMORY_AFFINITY_COUNT); |
| 105 | |
| 106 | /* skip reserved memory region */ |
Shuo Liu | a5bdf8e | 2024-02-20 01:06:10 +0800 | [diff] [blame] | 107 | if (is_memtype_reserved(mem_element->Type)) |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 108 | continue; |
Shuo Liu | a5bdf8e | 2024-02-20 01:06:10 +0800 | [diff] [blame] | 109 | /* skip all non processor attached memory regions */ |
| 110 | if (CONFIG(SOC_INTEL_HAS_CXL) && |
| 111 | (!is_memtype_processor_attached(mem_element->Type))) |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 112 | continue; |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 113 | |
| 114 | /* skip if this address is already added */ |
| 115 | bool skip = false; |
| 116 | for (int idx = 0; idx < mmap_index; ++idx) { |
| 117 | uint64_t base_addr = ((uint64_t)srat_mem[idx].base_address_high << 32) + |
| 118 | srat_mem[idx].base_address_low; |
| 119 | if (addr == base_addr) { |
| 120 | skip = true; |
| 121 | break; |
| 122 | } |
| 123 | } |
| 124 | if (skip) |
| 125 | continue; |
| 126 | |
| 127 | srat_mem[mmap_index].type = 1; /* Memory affinity structure */ |
| 128 | srat_mem[mmap_index].length = sizeof(acpi_srat_mem_t); |
Elyes Haouas | 9018dee | 2022-11-18 15:07:33 +0100 | [diff] [blame] | 129 | srat_mem[mmap_index].base_address_low = (uint32_t)(addr & 0xffffffff); |
| 130 | srat_mem[mmap_index].base_address_high = (uint32_t)(addr >> 32); |
| 131 | srat_mem[mmap_index].length_low = (uint32_t)(size & 0xffffffff); |
| 132 | srat_mem[mmap_index].length_high = (uint32_t)(size >> 32); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 133 | srat_mem[mmap_index].proximity_domain = mem_element->SocketId; |
Shuo Liu | 3108ba5 | 2022-07-05 22:56:28 +0800 | [diff] [blame] | 134 | srat_mem[mmap_index].flags = ACPI_SRAT_MEMORY_ENABLED; |
Shuo Liu | a5bdf8e | 2024-02-20 01:06:10 +0800 | [diff] [blame] | 135 | if (is_memtype_non_volatile(mem_element->Type)) |
Shuo Liu | 3108ba5 | 2022-07-05 22:56:28 +0800 | [diff] [blame] | 136 | srat_mem[mmap_index].flags |= ACPI_SRAT_MEMORY_NONVOLATILE; |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 137 | ++mmap_index; |
| 138 | } |
| 139 | |
| 140 | return mmap_index; |
| 141 | } |
| 142 | |
| 143 | static unsigned long acpi_fill_srat(unsigned long current) |
| 144 | { |
| 145 | acpi_srat_mem_t srat_mem[MAX_ACPI_MEMORY_AFFINITY_COUNT]; |
| 146 | unsigned int mem_count; |
| 147 | |
| 148 | /* create all subtables for processors */ |
| 149 | current = acpi_create_srat_lapics(current); |
| 150 | |
Naresh Solanki | 9fd5c69 | 2023-05-22 16:47:47 +0200 | [diff] [blame] | 151 | memset(srat_mem, 0, sizeof(srat_mem)); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 152 | mem_count = get_srat_memory_entries(srat_mem); |
| 153 | for (int i = 0; i < mem_count; ++i) { |
| 154 | printk(BIOS_DEBUG, "adding srat memory %d entry length: %d, addr: 0x%x%x, " |
| 155 | "length: 0x%x%x, proximity_domain: %d, flags: %x\n", |
| 156 | i, srat_mem[i].length, |
| 157 | srat_mem[i].base_address_high, srat_mem[i].base_address_low, |
| 158 | srat_mem[i].length_high, srat_mem[i].length_low, |
| 159 | srat_mem[i].proximity_domain, srat_mem[i].flags); |
| 160 | memcpy((acpi_srat_mem_t *)current, &srat_mem[i], sizeof(srat_mem[i])); |
| 161 | current += srat_mem[i].length; |
| 162 | } |
| 163 | |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 164 | if (CONFIG(SOC_INTEL_HAS_CXL)) |
| 165 | current = cxl_fill_srat(current); |
| 166 | |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 167 | return current; |
| 168 | } |
| 169 | |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 170 | #if CONFIG(SOC_INTEL_SAPPHIRERAPIDS_SP) |
| 171 | /* |
| 172 | Because pds.num_pds comes from spr/numa.c function fill_pds(). |
| 173 | pds.num_pds = soc_get_num_cpus() + get_cxl_node_count(). |
| 174 | */ |
| 175 | /* SPR-SP platform has Generic Initiator domain in addition to processor domain */ |
| 176 | static unsigned long acpi_fill_slit(unsigned long current) |
| 177 | { |
| 178 | uint8_t *p = (uint8_t *)current; |
| 179 | /* According to table 5.60 of ACPI 6.4 spec, "Number of System Localities" field takes |
| 180 | up 8 bytes. Following that, each matrix entry takes up 1 byte. */ |
| 181 | memset(p, 0, 8 + pds.num_pds * pds.num_pds); |
| 182 | *p = (uint8_t)pds.num_pds; |
| 183 | p += 8; |
| 184 | |
| 185 | for (int i = 0; i < pds.num_pds; i++) { |
| 186 | for (int j = 0; j < pds.num_pds; j++) |
| 187 | p[i * pds.num_pds + j] = pds.pds[i].distances[j]; |
| 188 | } |
| 189 | |
| 190 | current += 8 + pds.num_pds * pds.num_pds; |
| 191 | return current; |
| 192 | } |
| 193 | #else |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 194 | static unsigned long acpi_fill_slit(unsigned long current) |
| 195 | { |
Marc Jones | 70907b0 | 2020-10-28 17:00:31 -0600 | [diff] [blame] | 196 | unsigned int nodes = soc_get_num_cpus(); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 197 | |
| 198 | uint8_t *p = (uint8_t *)current; |
| 199 | memset(p, 0, 8 + nodes * nodes); |
| 200 | *p = (uint8_t)nodes; |
| 201 | p += 8; |
| 202 | |
| 203 | /* this assumes fully connected socket topology */ |
| 204 | for (int i = 0; i < nodes; i++) { |
| 205 | for (int j = 0; j < nodes; j++) { |
| 206 | if (i == j) |
| 207 | p[i*nodes+j] = 10; |
| 208 | else |
| 209 | p[i*nodes+j] = 16; |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | current += 8 + nodes * nodes; |
| 214 | return current; |
| 215 | } |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 216 | #endif |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 217 | |
| 218 | /* |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 219 | * This function adds PCIe bridge device entry in DMAR table. If it is called |
| 220 | * in the context of ATSR subtable, it adds ATSR subtable when it is first called. |
| 221 | */ |
| 222 | static unsigned long acpi_create_dmar_ds_pci_br_for_port(unsigned long current, |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 223 | const struct device *bridge_dev, |
| 224 | uint32_t pcie_seg, |
| 225 | bool is_atsr, bool *first) |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 226 | { |
Arthur Heymans | 7fcd4d5 | 2023-08-24 15:12:19 +0200 | [diff] [blame] | 227 | const uint32_t bus = bridge_dev->upstream->secondary; |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 228 | const uint32_t dev = PCI_SLOT(bridge_dev->path.pci.devfn); |
| 229 | const uint32_t func = PCI_FUNC(bridge_dev->path.pci.devfn); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 230 | |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 231 | if (bus == 0) |
| 232 | return current; |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 233 | |
| 234 | unsigned long atsr_size = 0; |
| 235 | unsigned long pci_br_size = 0; |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 236 | if (is_atsr == true && first && *first == true) { |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 237 | printk(BIOS_DEBUG, "[Root Port ATS Capability] Flags: 0x%x, " |
| 238 | "PCI Segment Number: 0x%x\n", 0, pcie_seg); |
| 239 | atsr_size = acpi_create_dmar_atsr(current, 0, pcie_seg); |
| 240 | *first = false; |
| 241 | } |
| 242 | |
| 243 | printk(BIOS_DEBUG, " [PCI Bridge Device] Enumeration ID: 0x%x, " |
| 244 | "PCI Bus Number: 0x%x, PCI Path: 0x%x, 0x%x\n", |
| 245 | 0, bus, dev, func); |
| 246 | pci_br_size = acpi_create_dmar_ds_pci_br(current + atsr_size, bus, dev, func); |
| 247 | |
| 248 | return (atsr_size + pci_br_size); |
| 249 | } |
| 250 | |
Martin L Roth | 014ec7c | 2024-03-13 17:02:25 +0000 | [diff] [blame] | 251 | static unsigned long acpi_create_drhd(unsigned long current, int socket, |
| 252 | int stack, const IIO_UDS *hob) |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 253 | { |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 254 | unsigned long tmp = current; |
Martin L Roth | 092a139 | 2024-03-13 17:03:13 +0000 | [diff] [blame] | 255 | const STACK_RES *ri = &hob->PlatformData.IIO_resource[socket].StackRes[stack]; |
| 256 | const uint32_t bus = ri->BusBase; |
| 257 | const uint32_t pcie_seg = hob->PlatformData.CpuQpiInfo[socket].PcieSegment; |
| 258 | const uint32_t reg_base = ri->VtdBarAddress; |
Shuo Liu | 6995efb | 2024-03-08 19:15:28 +0800 | [diff] [blame] | 259 | printk(BIOS_SPEW, "%s socket: %d, stack: %d, bus: 0x%x, pcie_seg: 0x%x, reg_base: 0x%x\n", |
| 260 | __func__, socket, stack, bus, pcie_seg, reg_base); |
| 261 | |
Martin L Roth | 092a139 | 2024-03-13 17:03:13 +0000 | [diff] [blame] | 262 | /* Do not generate DRHD for non-PCIe stack */ |
| 263 | if (!reg_base) |
| 264 | return current; |
| 265 | |
Arthur Heymans | a1c4ad3 | 2021-05-04 18:40:28 +0200 | [diff] [blame] | 266 | // Add DRHD Hardware Unit |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 267 | |
Martin L Roth | 092a139 | 2024-03-13 17:03:13 +0000 | [diff] [blame] | 268 | if (socket == 0 && stack == IioStack0) { |
Arthur Heymans | a1c4ad3 | 2021-05-04 18:40:28 +0200 | [diff] [blame] | 269 | printk(BIOS_DEBUG, "[Hardware Unit Definition] Flags: 0x%x, PCI Segment Number: 0x%x, " |
| 270 | "Register Base Address: 0x%x\n", |
| 271 | DRHD_INCLUDE_PCI_ALL, pcie_seg, reg_base); |
| 272 | current += acpi_create_dmar_drhd(current, DRHD_INCLUDE_PCI_ALL, |
| 273 | pcie_seg, reg_base); |
| 274 | } else { |
| 275 | printk(BIOS_DEBUG, "[Hardware Unit Definition] Flags: 0x%x, PCI Segment Number: 0x%x, " |
| 276 | "Register Base Address: 0x%x\n", 0, pcie_seg, reg_base); |
| 277 | current += acpi_create_dmar_drhd(current, 0, pcie_seg, reg_base); |
| 278 | } |
| 279 | |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 280 | // Add PCH IOAPIC |
Martin L Roth | 092a139 | 2024-03-13 17:03:13 +0000 | [diff] [blame] | 281 | if (socket == 0 && stack == IioStack0) { |
Arthur Heymans | 6e425e1 | 2020-11-12 21:12:05 +0100 | [diff] [blame] | 282 | union p2sb_bdf ioapic_bdf = p2sb_get_ioapic_bdf(); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 283 | printk(BIOS_DEBUG, " [IOAPIC Device] Enumeration ID: 0x%x, PCI Bus Number: 0x%x, " |
Felix Held | 0d19289 | 2024-02-06 16:55:29 +0100 | [diff] [blame] | 284 | "PCI Path: 0x%x, 0x%x\n", get_ioapic_id(IO_APIC_ADDR), ioapic_bdf.bus, |
Patrick Rudolph | 57ddd68 | 2023-02-28 09:17:40 +0100 | [diff] [blame] | 285 | ioapic_bdf.dev, ioapic_bdf.fn); |
| 286 | current += acpi_create_dmar_ds_ioapic_from_hw(current, |
| 287 | IO_APIC_ADDR, ioapic_bdf.bus, ioapic_bdf.dev, ioapic_bdf.fn); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 288 | } |
| 289 | |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 290 | /* SPR has no per stack IOAPIC or CBDMA devices */ |
| 291 | #if CONFIG(SOC_INTEL_SKYLAKE_SP) || CONFIG(SOC_INTEL_COOPERLAKE_SP) |
| 292 | uint32_t enum_id; |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 293 | // Add IOAPIC entry |
Arthur Heymans | a1cc557 | 2020-11-06 12:53:33 +0100 | [diff] [blame] | 294 | enum_id = soc_get_iio_ioapicid(socket, stack); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 295 | printk(BIOS_DEBUG, " [IOAPIC Device] Enumeration ID: 0x%x, PCI Bus Number: 0x%x, " |
| 296 | "PCI Path: 0x%x, 0x%x\n", enum_id, bus, APIC_DEV_NUM, APIC_FUNC_NUM); |
| 297 | current += acpi_create_dmar_ds_ioapic(current, enum_id, bus, |
| 298 | APIC_DEV_NUM, APIC_FUNC_NUM); |
| 299 | |
| 300 | // Add CBDMA devices for CSTACK |
| 301 | if (socket != 0 && stack == CSTACK) { |
| 302 | for (int cbdma_func_id = 0; cbdma_func_id < 8; ++cbdma_func_id) { |
| 303 | printk(BIOS_DEBUG, " [PCI Endpoint Device] Enumeration ID: 0x%x, " |
| 304 | "PCI Bus Number: 0x%x, PCI Path: 0x%x, 0x%x\n", |
| 305 | 0, bus, CBDMA_DEV_NUM, cbdma_func_id); |
| 306 | current += acpi_create_dmar_ds_pci(current, |
| 307 | bus, CBDMA_DEV_NUM, cbdma_func_id); |
| 308 | } |
| 309 | } |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 310 | #endif |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 311 | |
| 312 | // Add PCIe Ports |
Martin L Roth | 092a139 | 2024-03-13 17:03:13 +0000 | [diff] [blame] | 313 | if (socket != 0 || stack != IioStack0) { |
| 314 | struct device *dev = pcidev_path_on_bus(bus, PCI_DEVFN(0, 0)); |
| 315 | while (dev) { |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 316 | if ((dev->hdr_type & 0x7f) == PCI_HEADER_TYPE_BRIDGE) |
| 317 | current += |
| 318 | acpi_create_dmar_ds_pci_br_for_port( |
| 319 | current, dev, pcie_seg, false, NULL); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 320 | |
Martin L Roth | 092a139 | 2024-03-13 17:03:13 +0000 | [diff] [blame] | 321 | dev = dev->sibling; |
| 322 | } |
| 323 | |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 324 | #if CONFIG(SOC_INTEL_SKYLAKE_SP) || CONFIG(SOC_INTEL_COOPERLAKE_SP) |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 325 | // Add VMD |
| 326 | if (hob->PlatformData.VMDStackEnable[socket][stack] && |
| 327 | stack >= PSTACK0 && stack <= PSTACK2) { |
| 328 | printk(BIOS_DEBUG, " [PCI Endpoint Device] Enumeration ID: 0x%x, " |
| 329 | "PCI Bus Number: 0x%x, PCI Path: 0x%x, 0x%x\n", |
| 330 | 0, bus, VMD_DEV_NUM, VMD_FUNC_NUM); |
| 331 | current += acpi_create_dmar_ds_pci(current, |
| 332 | bus, VMD_DEV_NUM, VMD_FUNC_NUM); |
| 333 | } |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 334 | #endif |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 335 | } |
| 336 | |
Shuo Liu | 08f1f05 | 2024-01-20 02:52:17 +0800 | [diff] [blame] | 337 | // Add IOAT End Points (with memory resources. We don't report every End Point device.) |
Martin L Roth | 092a139 | 2024-03-13 17:03:13 +0000 | [diff] [blame] | 338 | if (CONFIG(HAVE_IOAT_DOMAINS) && is_ioat_iio_stack_res(ri)) { |
| 339 | for (int b = ri->BusBase; b <= ri->BusLimit; ++b) { |
| 340 | struct device *dev = pcidev_path_on_bus(b, PCI_DEVFN(0, 0)); |
| 341 | while (dev) { |
| 342 | /* This may also require a check for IORESOURCE_PREFETCH, |
| 343 | * but that would not include the FPU (4942/0) */ |
| 344 | if ((dev->resource_list->flags & |
| 345 | (IORESOURCE_MEM | IORESOURCE_PCI64 | IORESOURCE_ASSIGNED)) == |
| 346 | (IORESOURCE_MEM | IORESOURCE_PCI64 | IORESOURCE_ASSIGNED)) { |
| 347 | const uint32_t d = PCI_SLOT(dev->path.pci.devfn); |
| 348 | const uint32_t f = PCI_FUNC(dev->path.pci.devfn); |
| 349 | printk(BIOS_DEBUG, " [PCIE Endpoint Device] " |
| 350 | "Enumeration ID: 0x%x, PCI Bus Number: 0x%x, " |
| 351 | " PCI Path: 0x%x, 0x%x\n", 0, b, d, f); |
| 352 | current += acpi_create_dmar_ds_pci(current, b, d, f); |
| 353 | } |
| 354 | dev = dev->sibling; |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 355 | } |
Martin L Roth | 092a139 | 2024-03-13 17:03:13 +0000 | [diff] [blame] | 356 | } |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 357 | } |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 358 | |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 359 | // Add HPET |
Martin L Roth | 092a139 | 2024-03-13 17:03:13 +0000 | [diff] [blame] | 360 | if (socket == 0 && stack == IioStack0) { |
Elyes Haouas | 167b7fcd | 2022-12-11 10:38:35 +0100 | [diff] [blame] | 361 | uint16_t hpet_capid = read16p(HPET_BASE_ADDRESS); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 362 | uint16_t num_hpets = (hpet_capid >> 0x08) & 0x1F; // Bits [8:12] has hpet count |
| 363 | printk(BIOS_SPEW, "%s hpet_capid: 0x%x, num_hpets: 0x%x\n", |
| 364 | __func__, hpet_capid, num_hpets); |
| 365 | //BIT 15 |
| 366 | if (num_hpets && (num_hpets != 0x1f) && |
Elyes Haouas | 167b7fcd | 2022-12-11 10:38:35 +0100 | [diff] [blame] | 367 | (read32p(HPET_BASE_ADDRESS + 0x100) & (0x00008000))) { |
Arthur Heymans | 695dd29 | 2020-11-12 21:05:09 +0100 | [diff] [blame] | 368 | union p2sb_bdf hpet_bdf = p2sb_get_hpet_bdf(); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 369 | printk(BIOS_DEBUG, " [Message-capable HPET Device] Enumeration ID: 0x%x, " |
| 370 | "PCI Bus Number: 0x%x, PCI Path: 0x%x, 0x%x\n", |
Arthur Heymans | 695dd29 | 2020-11-12 21:05:09 +0100 | [diff] [blame] | 371 | 0, hpet_bdf.bus, hpet_bdf.dev, hpet_bdf.fn); |
| 372 | current += acpi_create_dmar_ds_msi_hpet(current, 0, hpet_bdf.bus, |
| 373 | hpet_bdf.dev, hpet_bdf.fn); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | |
| 377 | acpi_dmar_drhd_fixup(tmp, current); |
| 378 | |
| 379 | return current; |
| 380 | } |
| 381 | |
Patrick Rudolph | abc2744 | 2024-03-12 14:48:16 +0100 | [diff] [blame^] | 382 | static unsigned long acpi_create_atsr(unsigned long current) |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 383 | { |
Patrick Rudolph | 425e421 | 2024-02-15 16:30:16 +0100 | [diff] [blame] | 384 | struct device *child, *dev; |
| 385 | struct resource *resource; |
| 386 | |
| 387 | /* |
| 388 | * The assumption made here is that the host bridges on a socket share the |
| 389 | * PCI segment group and thus only one ATSR header needs to be emitted for |
| 390 | * a single socket. |
| 391 | * This is easier than to sort the host bridges by PCI segment group first |
| 392 | * and then generate one ATSR header for every new segment. |
| 393 | */ |
Patrick Rudolph | abc2744 | 2024-03-12 14:48:16 +0100 | [diff] [blame^] | 394 | for (int socket = 0; socket < CONFIG_MAX_SOCKET; ++socket) { |
Patrick Rudolph | ac02857 | 2023-07-14 17:44:33 +0200 | [diff] [blame] | 395 | if (!soc_cpu_is_enabled(socket)) |
| 396 | continue; |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 397 | unsigned long tmp = current; |
| 398 | bool first = true; |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 399 | |
Patrick Rudolph | 425e421 | 2024-02-15 16:30:16 +0100 | [diff] [blame] | 400 | dev = NULL; |
| 401 | while ((dev = dev_find_device(PCI_VID_INTEL, MMAP_VTD_CFG_REG_DEVID, dev))) { |
| 402 | /* Only add devices for the current socket */ |
| 403 | if (iio_pci_domain_socket_from_dev(dev) != socket) |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 404 | continue; |
Patrick Rudolph | 425e421 | 2024-02-15 16:30:16 +0100 | [diff] [blame] | 405 | /* See if there is a resource with the appropriate index. */ |
| 406 | resource = probe_resource(dev, VTD_BAR_CSR); |
| 407 | if (!resource) |
| 408 | continue; |
| 409 | int stack = iio_pci_domain_stack_from_dev(dev); |
| 410 | |
| 411 | uint64_t vtd_mmio_cap = read64(res2mmio(resource, VTD_EXT_CAP_LOW, 0)); |
| 412 | printk(BIOS_SPEW, "%s socket: %d, stack: %d, bus: 0x%x, vtd_base: %p, " |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 413 | "vtd_mmio_cap: 0x%llx\n", |
Patrick Rudolph | 425e421 | 2024-02-15 16:30:16 +0100 | [diff] [blame] | 414 | __func__, socket, stack, dev->upstream->secondary, |
| 415 | res2mmio(resource, 0, 0), vtd_mmio_cap); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 416 | |
| 417 | // ATSR is applicable only for platform supporting device IOTLBs |
| 418 | // through the VT-d extended capability register |
| 419 | assert(vtd_mmio_cap != 0xffffffffffffffff); |
| 420 | if ((vtd_mmio_cap & 0x4) == 0) // BIT 2 |
| 421 | continue; |
| 422 | |
Patrick Rudolph | 425e421 | 2024-02-15 16:30:16 +0100 | [diff] [blame] | 423 | if (dev->upstream->secondary == 0 && dev->upstream->segment_group == 0) |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 424 | continue; |
| 425 | |
Patrick Rudolph | 425e421 | 2024-02-15 16:30:16 +0100 | [diff] [blame] | 426 | for (child = dev->upstream->children; child; child = child->sibling) { |
| 427 | if ((child->hdr_type & 0x7f) != PCI_HEADER_TYPE_BRIDGE) |
| 428 | continue; |
| 429 | current += |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 430 | acpi_create_dmar_ds_pci_br_for_port( |
Patrick Rudolph | 425e421 | 2024-02-15 16:30:16 +0100 | [diff] [blame] | 431 | current, child, child->upstream->segment_group, true, &first); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 432 | } |
| 433 | } |
| 434 | if (tmp != current) |
| 435 | acpi_dmar_atsr_fixup(tmp, current); |
| 436 | } |
| 437 | |
| 438 | return current; |
| 439 | } |
| 440 | |
| 441 | static unsigned long acpi_create_rmrr(unsigned long current) |
| 442 | { |
| 443 | uint32_t size = ALIGN_UP(MEM_BLK_COUNT * sizeof(MEM_BLK), 0x1000); |
| 444 | |
| 445 | uint32_t *ptr; |
| 446 | |
| 447 | // reserve memory |
| 448 | ptr = cbmem_find(CBMEM_ID_STORAGE_DATA); |
| 449 | if (!ptr) { |
| 450 | ptr = cbmem_add(CBMEM_ID_STORAGE_DATA, size); |
Elyes Haouas | f1ba7d6 | 2022-09-13 10:03:44 +0200 | [diff] [blame] | 451 | assert(ptr); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 452 | memset(ptr, 0, size); |
| 453 | } |
| 454 | |
| 455 | unsigned long tmp = current; |
| 456 | printk(BIOS_DEBUG, "[Reserved Memory Region] PCI Segment Number: 0x%x, Base Address: 0x%x, " |
| 457 | "End Address (limit): 0x%x\n", |
Elyes Haouas | 9018dee | 2022-11-18 15:07:33 +0100 | [diff] [blame] | 458 | 0, (uint32_t)ptr, (uint32_t)((uint32_t)ptr + size - 1)); |
| 459 | current += acpi_create_dmar_rmrr(current, 0, (uint32_t)ptr, |
| 460 | (uint32_t)((uint32_t)ptr + size - 1)); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 461 | |
| 462 | printk(BIOS_DEBUG, " [PCI Endpoint Device] Enumeration ID: 0x%x, PCI Bus Number: 0x%x, " |
| 463 | "PCI Path: 0x%x, 0x%x\n", |
| 464 | 0, XHCI_BUS_NUMBER, PCH_DEV_SLOT_XHCI, XHCI_FUNC_NUM); |
| 465 | current += acpi_create_dmar_ds_pci(current, XHCI_BUS_NUMBER, |
| 466 | PCH_DEV_SLOT_XHCI, XHCI_FUNC_NUM); |
| 467 | |
| 468 | acpi_dmar_rmrr_fixup(tmp, current); |
| 469 | |
| 470 | return current; |
| 471 | } |
| 472 | |
| 473 | static unsigned long acpi_create_rhsa(unsigned long current) |
| 474 | { |
Patrick Rudolph | 425e421 | 2024-02-15 16:30:16 +0100 | [diff] [blame] | 475 | struct device *dev = NULL; |
| 476 | struct resource *resource; |
| 477 | int socket; |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 478 | |
Patrick Rudolph | 425e421 | 2024-02-15 16:30:16 +0100 | [diff] [blame] | 479 | while ((dev = dev_find_device(PCI_VID_INTEL, MMAP_VTD_CFG_REG_DEVID, dev))) { |
| 480 | /* See if there is a resource with the appropriate index. */ |
| 481 | resource = probe_resource(dev, VTD_BAR_CSR); |
| 482 | if (!resource) |
Patrick Rudolph | ac02857 | 2023-07-14 17:44:33 +0200 | [diff] [blame] | 483 | continue; |
Patrick Rudolph | ac02857 | 2023-07-14 17:44:33 +0200 | [diff] [blame] | 484 | |
Patrick Rudolph | 425e421 | 2024-02-15 16:30:16 +0100 | [diff] [blame] | 485 | socket = iio_pci_domain_socket_from_dev(dev); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 486 | |
Patrick Rudolph | 425e421 | 2024-02-15 16:30:16 +0100 | [diff] [blame] | 487 | printk(BIOS_DEBUG, "[Remapping Hardware Static Affinity] Base Address: %p, " |
| 488 | "Proximity Domain: 0x%x\n", res2mmio(resource, 0, 0), socket); |
| 489 | current += acpi_create_dmar_rhsa(current, (uintptr_t)res2mmio(resource, 0, 0), socket); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 490 | } |
| 491 | |
| 492 | return current; |
| 493 | } |
| 494 | |
Shuo Liu | a0b7c06 | 2024-03-06 00:24:02 +0800 | [diff] [blame] | 495 | static unsigned long xeonsp_create_satc(unsigned long current, struct device *domain) |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 496 | { |
Shuo Liu | a0b7c06 | 2024-03-06 00:24:02 +0800 | [diff] [blame] | 497 | struct device *dev = NULL; |
| 498 | while ((dev = dev_bus_each_child(domain->downstream, dev))) { |
| 499 | if (pciexp_find_extended_cap(dev, PCIE_EXT_CAP_ID_ATS, 0)) { |
| 500 | const uint32_t b = domain->downstream->secondary; |
| 501 | const uint32_t d = PCI_SLOT(dev->path.pci.devfn); |
| 502 | const uint32_t f = PCI_FUNC(dev->path.pci.devfn); |
| 503 | printk(BIOS_DEBUG, " [SATC Endpoint Device] " |
| 504 | "Enumeration ID: 0x%x, PCI Bus Number: 0x%x, " |
| 505 | " PCI Path: 0x%x, 0x%x\n", 0, b, d, f); |
| 506 | current += acpi_create_dmar_ds_pci(current, b, d, f); |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 507 | } |
| 508 | } |
| 509 | return current; |
| 510 | } |
| 511 | |
| 512 | /* SoC Integrated Address Translation Cache */ |
Shuo Liu | a0b7c06 | 2024-03-06 00:24:02 +0800 | [diff] [blame] | 513 | static unsigned long acpi_create_satc(unsigned long current) |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 514 | { |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 515 | const unsigned long tmp = current; |
| 516 | |
| 517 | // Add the SATC header |
| 518 | current += acpi_create_dmar_satc(current, 0, 0); |
| 519 | |
Shuo Liu | a0b7c06 | 2024-03-06 00:24:02 +0800 | [diff] [blame] | 520 | struct device *dev = NULL; |
| 521 | while ((dev = dev_find_path(dev, DEVICE_PATH_DOMAIN))) |
| 522 | current = xeonsp_create_satc(current, dev); |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 523 | |
| 524 | acpi_dmar_satc_fixup(tmp, current); |
| 525 | return current; |
| 526 | } |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 527 | |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 528 | static unsigned long acpi_fill_dmar(unsigned long current) |
| 529 | { |
Arthur Heymans | 83b2622 | 2020-11-06 11:50:55 +0100 | [diff] [blame] | 530 | const IIO_UDS *hob = get_iio_uds(); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 531 | |
Martin L Roth | 014ec7c | 2024-03-13 17:02:25 +0000 | [diff] [blame] | 532 | // DRHD - socket 0 stack 0 must be the last DRHD entry. |
| 533 | for (int socket = (CONFIG_MAX_SOCKET - 1); socket >= 0; --socket) { |
| 534 | if (!soc_cpu_is_enabled(socket)) |
Patrick Rudolph | ac02857 | 2023-07-14 17:44:33 +0200 | [diff] [blame] | 535 | continue; |
Martin L Roth | 014ec7c | 2024-03-13 17:02:25 +0000 | [diff] [blame] | 536 | for (int stack = (MAX_LOGIC_IIO_STACK - 1); stack >= 0; --stack) |
| 537 | current = acpi_create_drhd(current, socket, stack, hob); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 538 | } |
| 539 | |
| 540 | // RMRR |
| 541 | current = acpi_create_rmrr(current); |
| 542 | |
| 543 | // Root Port ATS Capability |
Patrick Rudolph | abc2744 | 2024-03-12 14:48:16 +0100 | [diff] [blame^] | 544 | current = acpi_create_atsr(current); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 545 | |
| 546 | // RHSA |
| 547 | current = acpi_create_rhsa(current); |
| 548 | |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 549 | // SATC |
Shuo Liu | a0b7c06 | 2024-03-06 00:24:02 +0800 | [diff] [blame] | 550 | current = acpi_create_satc(current); |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 551 | |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 552 | return current; |
| 553 | } |
| 554 | |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 555 | unsigned long northbridge_write_acpi_tables(const struct device *device, unsigned long current, |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 556 | struct acpi_rsdp *rsdp) |
| 557 | { |
Shuo Liu | 255f927 | 2023-03-29 20:14:11 +0800 | [diff] [blame] | 558 | /* Only write uncore ACPI tables for domain0 */ |
| 559 | if (device->path.domain.domain != 0) |
| 560 | return current; |
| 561 | |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 562 | acpi_srat_t *srat; |
| 563 | acpi_slit_t *slit; |
| 564 | acpi_dmar_t *dmar; |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 565 | acpi_hmat_t *hmat; |
| 566 | acpi_cedt_t *cedt; |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 567 | |
| 568 | const config_t *const config = config_of(device); |
| 569 | |
| 570 | /* SRAT */ |
Elyes Haouas | d6b6b22 | 2022-10-10 12:34:21 +0200 | [diff] [blame] | 571 | current = ALIGN_UP(current, 8); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 572 | printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current); |
Elyes Haouas | 9018dee | 2022-11-18 15:07:33 +0100 | [diff] [blame] | 573 | srat = (acpi_srat_t *)current; |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 574 | acpi_create_srat(srat, acpi_fill_srat); |
| 575 | current += srat->header.length; |
| 576 | acpi_add_table(rsdp, srat); |
| 577 | |
| 578 | /* SLIT */ |
Elyes Haouas | d6b6b22 | 2022-10-10 12:34:21 +0200 | [diff] [blame] | 579 | current = ALIGN_UP(current, 8); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 580 | printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current); |
Elyes Haouas | 9018dee | 2022-11-18 15:07:33 +0100 | [diff] [blame] | 581 | slit = (acpi_slit_t *)current; |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 582 | acpi_create_slit(slit, acpi_fill_slit); |
| 583 | current += slit->header.length; |
| 584 | acpi_add_table(rsdp, slit); |
| 585 | |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 586 | if (CONFIG(SOC_INTEL_HAS_CXL)) { |
| 587 | /* HMAT*/ |
| 588 | current = ALIGN_UP(current, 8); |
| 589 | printk(BIOS_DEBUG, "ACPI: * HMAT at %lx\n", current); |
| 590 | hmat = (acpi_hmat_t *)current; |
| 591 | acpi_create_hmat(hmat, acpi_fill_hmat); |
| 592 | current += hmat->header.length; |
| 593 | acpi_add_table(rsdp, hmat); |
| 594 | } |
| 595 | |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 596 | /* DMAR */ |
| 597 | if (config->vtd_support) { |
Elyes Haouas | d6b6b22 | 2022-10-10 12:34:21 +0200 | [diff] [blame] | 598 | current = ALIGN_UP(current, 8); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 599 | dmar = (acpi_dmar_t *)current; |
Marc Jones | b7e591e | 2020-11-13 15:55:31 -0700 | [diff] [blame] | 600 | enum dmar_flags flags = DMAR_INTR_REMAP; |
| 601 | |
| 602 | /* SKX FSP doesn't support X2APIC, but CPX FSP does */ |
| 603 | if (CONFIG(SOC_INTEL_SKYLAKE_SP)) |
| 604 | flags |= DMAR_X2APIC_OPT_OUT; |
| 605 | |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 606 | printk(BIOS_DEBUG, "ACPI: * DMAR at %lx\n", current); |
Marc Jones | b7e591e | 2020-11-13 15:55:31 -0700 | [diff] [blame] | 607 | printk(BIOS_DEBUG, "[DMA Remapping table] Flags: 0x%x\n", flags); |
| 608 | acpi_create_dmar(dmar, flags, acpi_fill_dmar); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 609 | current += dmar->header.length; |
| 610 | current = acpi_align_current(current); |
| 611 | acpi_add_table(rsdp, dmar); |
| 612 | } |
| 613 | |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 614 | if (CONFIG(SOC_INTEL_HAS_CXL)) { |
| 615 | /* CEDT: CXL Early Discovery Table */ |
| 616 | if (get_cxl_node_count() > 0) { |
| 617 | current = ALIGN_UP(current, 8); |
| 618 | printk(BIOS_DEBUG, "ACPI: * CEDT at %lx\n", current); |
| 619 | cedt = (acpi_cedt_t *)current; |
| 620 | acpi_create_cedt(cedt, acpi_fill_cedt); |
| 621 | current += cedt->header.length; |
| 622 | acpi_add_table(rsdp, cedt); |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | if (CONFIG(SOC_ACPI_HEST)) { |
| 627 | printk(BIOS_DEBUG, "ACPI: * HEST at %lx\n", current); |
Rocky Phagura | d4db36e | 2021-04-03 08:49:32 -0700 | [diff] [blame] | 628 | current = hest_create(current, rsdp); |
Tim Chu | 5c19640 | 2022-12-13 12:09:44 +0000 | [diff] [blame] | 629 | } |
Rocky Phagura | d4db36e | 2021-04-03 08:49:32 -0700 | [diff] [blame] | 630 | |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 631 | return current; |
| 632 | } |