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