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> |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 9 | #include <device/mmio.h> |
| 10 | #include <device/pci.h> |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 11 | #include <soc/acpi.h> |
Rocky Phagura | d4db36e | 2021-04-03 08:49:32 -0700 | [diff] [blame] | 12 | #include <soc/hest.h> |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 13 | #include <soc/iomap.h> |
| 14 | #include <soc/pci_devs.h> |
| 15 | #include <soc/soc_util.h> |
Marc Jones | 18960ce | 2020-11-02 12:41:12 -0700 | [diff] [blame] | 16 | #include <soc/util.h> |
Arthur Heymans | 695dd29 | 2020-11-12 21:05:09 +0100 | [diff] [blame] | 17 | #include <intelblocks/p2sb.h> |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 18 | |
| 19 | #include "chip.h" |
| 20 | |
| 21 | /* Northbridge(NUMA) ACPI table generation. SRAT, SLIT, etc */ |
| 22 | |
| 23 | unsigned long acpi_create_srat_lapics(unsigned long current) |
| 24 | { |
| 25 | struct device *cpu; |
| 26 | unsigned int cpu_index = 0; |
| 27 | |
| 28 | for (cpu = all_devices; cpu; cpu = cpu->next) { |
Fabio Aiuto | 45aae7f | 2022-09-23 16:51:34 +0200 | [diff] [blame] | 29 | if (!is_enabled_cpu(cpu)) |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 30 | continue; |
Naresh Solanki | 559f9ed | 2023-01-20 19:38:07 +0100 | [diff] [blame] | 31 | |
| 32 | if (is_x2apic_mode()) { |
| 33 | printk(BIOS_DEBUG, "SRAT: x2apic cpu_index=%08x, node_id=%02x, apic_id=%08x\n", |
| 34 | cpu_index, cpu->path.apic.node_id, cpu->path.apic.apic_id); |
| 35 | |
| 36 | current += acpi_create_srat_x2apic((acpi_srat_x2apic_t *)current, |
| 37 | cpu->path.apic.node_id, cpu->path.apic.apic_id); |
| 38 | } else { |
| 39 | printk(BIOS_DEBUG, "SRAT: lapic cpu_index=%02x, node_id=%02x, apic_id=%02x\n", |
| 40 | cpu_index, cpu->path.apic.node_id, cpu->path.apic.apic_id); |
| 41 | |
| 42 | current += acpi_create_srat_lapic((acpi_srat_lapic_t *)current, |
| 43 | cpu->path.apic.node_id, cpu->path.apic.apic_id); |
| 44 | } |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 45 | cpu_index++; |
| 46 | } |
| 47 | return current; |
| 48 | } |
| 49 | |
| 50 | static unsigned int get_srat_memory_entries(acpi_srat_mem_t *srat_mem) |
| 51 | { |
| 52 | const struct SystemMemoryMapHob *memory_map; |
| 53 | unsigned int mmap_index; |
| 54 | |
| 55 | memory_map = get_system_memory_map(); |
Elyes Haouas | f1ba7d6 | 2022-09-13 10:03:44 +0200 | [diff] [blame] | 56 | assert(memory_map); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 57 | printk(BIOS_DEBUG, "memory_map: %p\n", memory_map); |
| 58 | |
| 59 | mmap_index = 0; |
| 60 | for (int e = 0; e < memory_map->numberEntries; ++e) { |
| 61 | const struct SystemMemoryMapElement *mem_element = &memory_map->Element[e]; |
| 62 | uint64_t addr = |
Elyes Haouas | 9018dee | 2022-11-18 15:07:33 +0100 | [diff] [blame] | 63 | (uint64_t)((uint64_t)mem_element->BaseAddress << |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 64 | MEM_ADDR_64MB_SHIFT_BITS); |
| 65 | uint64_t size = |
Elyes Haouas | 9018dee | 2022-11-18 15:07:33 +0100 | [diff] [blame] | 66 | (uint64_t)((uint64_t)mem_element->ElementSize << |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 67 | MEM_ADDR_64MB_SHIFT_BITS); |
| 68 | |
| 69 | printk(BIOS_DEBUG, "memory_map %d addr: 0x%llx, BaseAddress: 0x%x, size: 0x%llx, " |
| 70 | "ElementSize: 0x%x, reserved: %d\n", |
| 71 | e, addr, mem_element->BaseAddress, size, |
| 72 | mem_element->ElementSize, (mem_element->Type & MEM_TYPE_RESERVED)); |
| 73 | |
| 74 | assert(mmap_index < MAX_ACPI_MEMORY_AFFINITY_COUNT); |
| 75 | |
| 76 | /* skip reserved memory region */ |
| 77 | if (mem_element->Type & MEM_TYPE_RESERVED) |
| 78 | continue; |
| 79 | |
| 80 | /* skip if this address is already added */ |
| 81 | bool skip = false; |
| 82 | for (int idx = 0; idx < mmap_index; ++idx) { |
| 83 | uint64_t base_addr = ((uint64_t)srat_mem[idx].base_address_high << 32) + |
| 84 | srat_mem[idx].base_address_low; |
| 85 | if (addr == base_addr) { |
| 86 | skip = true; |
| 87 | break; |
| 88 | } |
| 89 | } |
| 90 | if (skip) |
| 91 | continue; |
| 92 | |
| 93 | srat_mem[mmap_index].type = 1; /* Memory affinity structure */ |
| 94 | srat_mem[mmap_index].length = sizeof(acpi_srat_mem_t); |
Elyes Haouas | 9018dee | 2022-11-18 15:07:33 +0100 | [diff] [blame] | 95 | srat_mem[mmap_index].base_address_low = (uint32_t)(addr & 0xffffffff); |
| 96 | srat_mem[mmap_index].base_address_high = (uint32_t)(addr >> 32); |
| 97 | srat_mem[mmap_index].length_low = (uint32_t)(size & 0xffffffff); |
| 98 | srat_mem[mmap_index].length_high = (uint32_t)(size >> 32); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 99 | srat_mem[mmap_index].proximity_domain = mem_element->SocketId; |
| 100 | srat_mem[mmap_index].flags = SRAT_ACPI_MEMORY_ENABLED; |
| 101 | if ((mem_element->Type & MEMTYPE_VOLATILE_MASK) == 0) |
| 102 | srat_mem[mmap_index].flags |= SRAT_ACPI_MEMORY_NONVOLATILE; |
| 103 | ++mmap_index; |
| 104 | } |
| 105 | |
| 106 | return mmap_index; |
| 107 | } |
| 108 | |
| 109 | static unsigned long acpi_fill_srat(unsigned long current) |
| 110 | { |
| 111 | acpi_srat_mem_t srat_mem[MAX_ACPI_MEMORY_AFFINITY_COUNT]; |
| 112 | unsigned int mem_count; |
| 113 | |
| 114 | /* create all subtables for processors */ |
| 115 | current = acpi_create_srat_lapics(current); |
| 116 | |
| 117 | mem_count = get_srat_memory_entries(srat_mem); |
| 118 | for (int i = 0; i < mem_count; ++i) { |
| 119 | printk(BIOS_DEBUG, "adding srat memory %d entry length: %d, addr: 0x%x%x, " |
| 120 | "length: 0x%x%x, proximity_domain: %d, flags: %x\n", |
| 121 | i, srat_mem[i].length, |
| 122 | srat_mem[i].base_address_high, srat_mem[i].base_address_low, |
| 123 | srat_mem[i].length_high, srat_mem[i].length_low, |
| 124 | srat_mem[i].proximity_domain, srat_mem[i].flags); |
| 125 | memcpy((acpi_srat_mem_t *)current, &srat_mem[i], sizeof(srat_mem[i])); |
| 126 | current += srat_mem[i].length; |
| 127 | } |
| 128 | |
| 129 | return current; |
| 130 | } |
| 131 | |
| 132 | static unsigned long acpi_fill_slit(unsigned long current) |
| 133 | { |
Marc Jones | 70907b0 | 2020-10-28 17:00:31 -0600 | [diff] [blame] | 134 | unsigned int nodes = soc_get_num_cpus(); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 135 | |
| 136 | uint8_t *p = (uint8_t *)current; |
| 137 | memset(p, 0, 8 + nodes * nodes); |
| 138 | *p = (uint8_t)nodes; |
| 139 | p += 8; |
| 140 | |
| 141 | /* this assumes fully connected socket topology */ |
| 142 | for (int i = 0; i < nodes; i++) { |
| 143 | for (int j = 0; j < nodes; j++) { |
| 144 | if (i == j) |
| 145 | p[i*nodes+j] = 10; |
| 146 | else |
| 147 | p[i*nodes+j] = 16; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | current += 8 + nodes * nodes; |
| 152 | return current; |
| 153 | } |
| 154 | |
| 155 | /* |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 156 | * This function adds PCIe bridge device entry in DMAR table. If it is called |
| 157 | * in the context of ATSR subtable, it adds ATSR subtable when it is first called. |
| 158 | */ |
| 159 | static unsigned long acpi_create_dmar_ds_pci_br_for_port(unsigned long current, |
Jacob Garber | 6df3870 | 2020-10-24 16:23:45 -0600 | [diff] [blame] | 160 | int port, int stack, const IIO_RESOURCE_INSTANCE *iio_resource, uint32_t pcie_seg, |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 161 | bool is_atsr, bool *first) |
| 162 | { |
| 163 | |
Marc Jones | 995a7e2 | 2020-10-28 17:08:54 -0600 | [diff] [blame] | 164 | if (soc_get_stack_for_port(port) != stack) |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 165 | return 0; |
| 166 | |
Jacob Garber | 6df3870 | 2020-10-24 16:23:45 -0600 | [diff] [blame] | 167 | const uint32_t bus = iio_resource->StackRes[stack].BusBase; |
| 168 | const uint32_t dev = iio_resource->PcieInfo.PortInfo[port].Device; |
| 169 | const uint32_t func = iio_resource->PcieInfo.PortInfo[port].Function; |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 170 | |
Nico Huber | f4f365f | 2021-10-14 18:16:39 +0200 | [diff] [blame] | 171 | const uint32_t id = pci_s_read_config32(PCI_DEV(bus, dev, func), |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 172 | PCI_VENDOR_ID); |
| 173 | if (id == 0xffffffff) |
| 174 | return 0; |
| 175 | |
| 176 | unsigned long atsr_size = 0; |
| 177 | unsigned long pci_br_size = 0; |
Elyes HAOUAS | fa99982 | 2022-01-27 14:27:05 +0100 | [diff] [blame] | 178 | if (is_atsr && first && *first) { |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 179 | printk(BIOS_DEBUG, "[Root Port ATS Capability] Flags: 0x%x, " |
| 180 | "PCI Segment Number: 0x%x\n", 0, pcie_seg); |
| 181 | atsr_size = acpi_create_dmar_atsr(current, 0, pcie_seg); |
| 182 | *first = false; |
| 183 | } |
| 184 | |
| 185 | printk(BIOS_DEBUG, " [PCI Bridge Device] Enumeration ID: 0x%x, " |
| 186 | "PCI Bus Number: 0x%x, PCI Path: 0x%x, 0x%x\n", |
| 187 | 0, bus, dev, func); |
| 188 | pci_br_size = acpi_create_dmar_ds_pci_br(current + atsr_size, bus, dev, func); |
| 189 | |
| 190 | return (atsr_size + pci_br_size); |
| 191 | } |
| 192 | |
| 193 | static unsigned long acpi_create_drhd(unsigned long current, int socket, |
| 194 | int stack, const IIO_UDS *hob) |
| 195 | { |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 196 | uint32_t enum_id; |
| 197 | unsigned long tmp = current; |
| 198 | |
| 199 | uint32_t bus = hob->PlatformData.IIO_resource[socket].StackRes[stack].BusBase; |
| 200 | uint32_t pcie_seg = hob->PlatformData.CpuQpiInfo[socket].PcieSegment; |
| 201 | uint32_t reg_base = |
| 202 | hob->PlatformData.IIO_resource[socket].StackRes[stack].VtdBarAddress; |
| 203 | printk(BIOS_SPEW, "%s socket: %d, stack: %d, bus: 0x%x, pcie_seg: 0x%x, reg_base: 0x%x\n", |
| 204 | __func__, socket, stack, bus, pcie_seg, reg_base); |
| 205 | |
| 206 | /* Do not generate DRHD for non-PCIe stack */ |
| 207 | if (!reg_base) |
| 208 | return current; |
| 209 | |
Arthur Heymans | a1c4ad3 | 2021-05-04 18:40:28 +0200 | [diff] [blame] | 210 | // Add DRHD Hardware Unit |
| 211 | if (socket == 0 && stack == CSTACK) { |
| 212 | printk(BIOS_DEBUG, "[Hardware Unit Definition] Flags: 0x%x, PCI Segment Number: 0x%x, " |
| 213 | "Register Base Address: 0x%x\n", |
| 214 | DRHD_INCLUDE_PCI_ALL, pcie_seg, reg_base); |
| 215 | current += acpi_create_dmar_drhd(current, DRHD_INCLUDE_PCI_ALL, |
| 216 | pcie_seg, reg_base); |
| 217 | } else { |
| 218 | printk(BIOS_DEBUG, "[Hardware Unit Definition] Flags: 0x%x, PCI Segment Number: 0x%x, " |
| 219 | "Register Base Address: 0x%x\n", 0, pcie_seg, reg_base); |
| 220 | current += acpi_create_dmar_drhd(current, 0, pcie_seg, reg_base); |
| 221 | } |
| 222 | |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 223 | // Add PCH IOAPIC |
| 224 | if (socket == 0 && stack == CSTACK) { |
Arthur Heymans | 6e425e1 | 2020-11-12 21:12:05 +0100 | [diff] [blame] | 225 | union p2sb_bdf ioapic_bdf = p2sb_get_ioapic_bdf(); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 226 | printk(BIOS_DEBUG, " [IOAPIC Device] Enumeration ID: 0x%x, PCI Bus Number: 0x%x, " |
Patrick Rudolph | 57ddd68 | 2023-02-28 09:17:40 +0100 | [diff] [blame^] | 227 | "PCI Path: 0x%x, 0x%x\n", get_ioapic_id(VIO_APIC_VADDR), ioapic_bdf.bus, |
| 228 | ioapic_bdf.dev, ioapic_bdf.fn); |
| 229 | current += acpi_create_dmar_ds_ioapic_from_hw(current, |
| 230 | IO_APIC_ADDR, ioapic_bdf.bus, ioapic_bdf.dev, ioapic_bdf.fn); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | // Add IOAPIC entry |
Arthur Heymans | a1cc557 | 2020-11-06 12:53:33 +0100 | [diff] [blame] | 234 | enum_id = soc_get_iio_ioapicid(socket, stack); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 235 | printk(BIOS_DEBUG, " [IOAPIC Device] Enumeration ID: 0x%x, PCI Bus Number: 0x%x, " |
| 236 | "PCI Path: 0x%x, 0x%x\n", enum_id, bus, APIC_DEV_NUM, APIC_FUNC_NUM); |
| 237 | current += acpi_create_dmar_ds_ioapic(current, enum_id, bus, |
| 238 | APIC_DEV_NUM, APIC_FUNC_NUM); |
| 239 | |
| 240 | // Add CBDMA devices for CSTACK |
| 241 | if (socket != 0 && stack == CSTACK) { |
| 242 | for (int cbdma_func_id = 0; cbdma_func_id < 8; ++cbdma_func_id) { |
| 243 | printk(BIOS_DEBUG, " [PCI Endpoint Device] Enumeration ID: 0x%x, " |
| 244 | "PCI Bus Number: 0x%x, PCI Path: 0x%x, 0x%x\n", |
| 245 | 0, bus, CBDMA_DEV_NUM, cbdma_func_id); |
| 246 | current += acpi_create_dmar_ds_pci(current, |
| 247 | bus, CBDMA_DEV_NUM, cbdma_func_id); |
| 248 | } |
| 249 | } |
| 250 | |
| 251 | // Add PCIe Ports |
| 252 | if (socket != 0 || stack != CSTACK) { |
| 253 | IIO_RESOURCE_INSTANCE iio_resource = |
| 254 | hob->PlatformData.IIO_resource[socket]; |
| 255 | for (int p = PORT_0; p < MAX_PORTS; ++p) |
| 256 | current += acpi_create_dmar_ds_pci_br_for_port(current, p, stack, |
Jacob Garber | 6df3870 | 2020-10-24 16:23:45 -0600 | [diff] [blame] | 257 | &iio_resource, pcie_seg, false, NULL); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 258 | |
| 259 | // Add VMD |
| 260 | if (hob->PlatformData.VMDStackEnable[socket][stack] && |
| 261 | stack >= PSTACK0 && stack <= PSTACK2) { |
| 262 | printk(BIOS_DEBUG, " [PCI Endpoint Device] Enumeration ID: 0x%x, " |
| 263 | "PCI Bus Number: 0x%x, PCI Path: 0x%x, 0x%x\n", |
| 264 | 0, bus, VMD_DEV_NUM, VMD_FUNC_NUM); |
| 265 | current += acpi_create_dmar_ds_pci(current, |
| 266 | bus, VMD_DEV_NUM, VMD_FUNC_NUM); |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | // Add HPET |
| 271 | if (socket == 0 && stack == CSTACK) { |
Elyes Haouas | 167b7fcd | 2022-12-11 10:38:35 +0100 | [diff] [blame] | 272 | uint16_t hpet_capid = read16p(HPET_BASE_ADDRESS); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 273 | uint16_t num_hpets = (hpet_capid >> 0x08) & 0x1F; // Bits [8:12] has hpet count |
| 274 | printk(BIOS_SPEW, "%s hpet_capid: 0x%x, num_hpets: 0x%x\n", |
| 275 | __func__, hpet_capid, num_hpets); |
| 276 | //BIT 15 |
| 277 | if (num_hpets && (num_hpets != 0x1f) && |
Elyes Haouas | 167b7fcd | 2022-12-11 10:38:35 +0100 | [diff] [blame] | 278 | (read32p(HPET_BASE_ADDRESS + 0x100) & (0x00008000))) { |
Arthur Heymans | 695dd29 | 2020-11-12 21:05:09 +0100 | [diff] [blame] | 279 | union p2sb_bdf hpet_bdf = p2sb_get_hpet_bdf(); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 280 | printk(BIOS_DEBUG, " [Message-capable HPET Device] Enumeration ID: 0x%x, " |
| 281 | "PCI Bus Number: 0x%x, PCI Path: 0x%x, 0x%x\n", |
Arthur Heymans | 695dd29 | 2020-11-12 21:05:09 +0100 | [diff] [blame] | 282 | 0, hpet_bdf.bus, hpet_bdf.dev, hpet_bdf.fn); |
| 283 | current += acpi_create_dmar_ds_msi_hpet(current, 0, hpet_bdf.bus, |
| 284 | hpet_bdf.dev, hpet_bdf.fn); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 285 | } |
| 286 | } |
| 287 | |
| 288 | acpi_dmar_drhd_fixup(tmp, current); |
| 289 | |
| 290 | return current; |
| 291 | } |
| 292 | |
| 293 | static unsigned long acpi_create_atsr(unsigned long current, const IIO_UDS *hob) |
| 294 | { |
| 295 | for (int socket = 0; socket < hob->PlatformData.numofIIO; ++socket) { |
| 296 | uint32_t pcie_seg = hob->PlatformData.CpuQpiInfo[socket].PcieSegment; |
| 297 | unsigned long tmp = current; |
| 298 | bool first = true; |
| 299 | IIO_RESOURCE_INSTANCE iio_resource = |
| 300 | hob->PlatformData.IIO_resource[socket]; |
| 301 | |
| 302 | for (int stack = 0; stack <= PSTACK2; ++stack) { |
| 303 | uint32_t bus = iio_resource.StackRes[stack].BusBase; |
| 304 | uint32_t vtd_base = iio_resource.StackRes[stack].VtdBarAddress; |
| 305 | if (!vtd_base) |
| 306 | continue; |
Elyes Haouas | 167b7fcd | 2022-12-11 10:38:35 +0100 | [diff] [blame] | 307 | uint64_t vtd_mmio_cap = read64p(vtd_base + VTD_EXT_CAP_LOW); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 308 | printk(BIOS_SPEW, "%s socket: %d, stack: %d, bus: 0x%x, vtd_base: 0x%x, " |
| 309 | "vtd_mmio_cap: 0x%llx\n", |
| 310 | __func__, socket, stack, bus, vtd_base, vtd_mmio_cap); |
| 311 | |
| 312 | // ATSR is applicable only for platform supporting device IOTLBs |
| 313 | // through the VT-d extended capability register |
| 314 | assert(vtd_mmio_cap != 0xffffffffffffffff); |
| 315 | if ((vtd_mmio_cap & 0x4) == 0) // BIT 2 |
| 316 | continue; |
| 317 | |
| 318 | for (int p = PORT_0; p < MAX_PORTS; ++p) { |
| 319 | if (socket == 0 && p == PORT_0) |
| 320 | continue; |
| 321 | current += acpi_create_dmar_ds_pci_br_for_port(current, p, |
Jacob Garber | 6df3870 | 2020-10-24 16:23:45 -0600 | [diff] [blame] | 322 | stack, &iio_resource, pcie_seg, true, &first); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | if (tmp != current) |
| 326 | acpi_dmar_atsr_fixup(tmp, current); |
| 327 | } |
| 328 | |
| 329 | return current; |
| 330 | } |
| 331 | |
| 332 | static unsigned long acpi_create_rmrr(unsigned long current) |
| 333 | { |
| 334 | uint32_t size = ALIGN_UP(MEM_BLK_COUNT * sizeof(MEM_BLK), 0x1000); |
| 335 | |
| 336 | uint32_t *ptr; |
| 337 | |
| 338 | // reserve memory |
| 339 | ptr = cbmem_find(CBMEM_ID_STORAGE_DATA); |
| 340 | if (!ptr) { |
| 341 | ptr = cbmem_add(CBMEM_ID_STORAGE_DATA, size); |
Elyes Haouas | f1ba7d6 | 2022-09-13 10:03:44 +0200 | [diff] [blame] | 342 | assert(ptr); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 343 | memset(ptr, 0, size); |
| 344 | } |
| 345 | |
| 346 | unsigned long tmp = current; |
| 347 | printk(BIOS_DEBUG, "[Reserved Memory Region] PCI Segment Number: 0x%x, Base Address: 0x%x, " |
| 348 | "End Address (limit): 0x%x\n", |
Elyes Haouas | 9018dee | 2022-11-18 15:07:33 +0100 | [diff] [blame] | 349 | 0, (uint32_t)ptr, (uint32_t)((uint32_t)ptr + size - 1)); |
| 350 | current += acpi_create_dmar_rmrr(current, 0, (uint32_t)ptr, |
| 351 | (uint32_t)((uint32_t)ptr + size - 1)); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 352 | |
| 353 | printk(BIOS_DEBUG, " [PCI Endpoint Device] Enumeration ID: 0x%x, PCI Bus Number: 0x%x, " |
| 354 | "PCI Path: 0x%x, 0x%x\n", |
| 355 | 0, XHCI_BUS_NUMBER, PCH_DEV_SLOT_XHCI, XHCI_FUNC_NUM); |
| 356 | current += acpi_create_dmar_ds_pci(current, XHCI_BUS_NUMBER, |
| 357 | PCH_DEV_SLOT_XHCI, XHCI_FUNC_NUM); |
| 358 | |
| 359 | acpi_dmar_rmrr_fixup(tmp, current); |
| 360 | |
| 361 | return current; |
| 362 | } |
| 363 | |
| 364 | static unsigned long acpi_create_rhsa(unsigned long current) |
| 365 | { |
Arthur Heymans | 83b2622 | 2020-11-06 11:50:55 +0100 | [diff] [blame] | 366 | const IIO_UDS *hob = get_iio_uds(); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 367 | |
| 368 | for (int socket = 0; socket < hob->PlatformData.numofIIO; ++socket) { |
| 369 | IIO_RESOURCE_INSTANCE iio_resource = |
| 370 | hob->PlatformData.IIO_resource[socket]; |
| 371 | for (int stack = 0; stack <= PSTACK2; ++stack) { |
| 372 | uint32_t vtd_base = iio_resource.StackRes[stack].VtdBarAddress; |
| 373 | if (!vtd_base) |
| 374 | continue; |
| 375 | |
| 376 | printk(BIOS_DEBUG, "[Remapping Hardware Static Affinity] Base Address: 0x%x, " |
| 377 | "Proximity Domain: 0x%x\n", vtd_base, socket); |
| 378 | current += acpi_create_dmar_rhsa(current, vtd_base, socket); |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | return current; |
| 383 | } |
| 384 | |
| 385 | static unsigned long acpi_fill_dmar(unsigned long current) |
| 386 | { |
Arthur Heymans | 83b2622 | 2020-11-06 11:50:55 +0100 | [diff] [blame] | 387 | const IIO_UDS *hob = get_iio_uds(); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 388 | |
| 389 | // DRHD |
| 390 | for (int iio = 1; iio <= hob->PlatformData.numofIIO; ++iio) { |
| 391 | int socket = iio; |
| 392 | if (socket == hob->PlatformData.numofIIO) // socket 0 should be last DRHD entry |
| 393 | socket = 0; |
| 394 | |
| 395 | if (socket == 0) { |
| 396 | for (int stack = 1; stack <= PSTACK2; ++stack) |
| 397 | current = acpi_create_drhd(current, socket, stack, hob); |
| 398 | current = acpi_create_drhd(current, socket, CSTACK, hob); |
| 399 | } else { |
| 400 | for (int stack = 0; stack <= PSTACK2; ++stack) |
| 401 | current = acpi_create_drhd(current, socket, stack, hob); |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | // RMRR |
| 406 | current = acpi_create_rmrr(current); |
| 407 | |
| 408 | // Root Port ATS Capability |
| 409 | current = acpi_create_atsr(current, hob); |
| 410 | |
| 411 | // RHSA |
| 412 | current = acpi_create_rhsa(current); |
| 413 | |
| 414 | return current; |
| 415 | } |
| 416 | |
| 417 | unsigned long northbridge_write_acpi_tables(const struct device *device, |
| 418 | unsigned long current, |
| 419 | struct acpi_rsdp *rsdp) |
| 420 | { |
| 421 | acpi_srat_t *srat; |
| 422 | acpi_slit_t *slit; |
| 423 | acpi_dmar_t *dmar; |
| 424 | |
| 425 | const config_t *const config = config_of(device); |
| 426 | |
| 427 | /* SRAT */ |
Elyes Haouas | d6b6b22 | 2022-10-10 12:34:21 +0200 | [diff] [blame] | 428 | current = ALIGN_UP(current, 8); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 429 | printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current); |
Elyes Haouas | 9018dee | 2022-11-18 15:07:33 +0100 | [diff] [blame] | 430 | srat = (acpi_srat_t *)current; |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 431 | acpi_create_srat(srat, acpi_fill_srat); |
| 432 | current += srat->header.length; |
| 433 | acpi_add_table(rsdp, srat); |
| 434 | |
| 435 | /* SLIT */ |
Elyes Haouas | d6b6b22 | 2022-10-10 12:34:21 +0200 | [diff] [blame] | 436 | current = ALIGN_UP(current, 8); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 437 | printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current); |
Elyes Haouas | 9018dee | 2022-11-18 15:07:33 +0100 | [diff] [blame] | 438 | slit = (acpi_slit_t *)current; |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 439 | acpi_create_slit(slit, acpi_fill_slit); |
| 440 | current += slit->header.length; |
| 441 | acpi_add_table(rsdp, slit); |
| 442 | |
| 443 | /* DMAR */ |
| 444 | if (config->vtd_support) { |
Elyes Haouas | d6b6b22 | 2022-10-10 12:34:21 +0200 | [diff] [blame] | 445 | current = ALIGN_UP(current, 8); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 446 | dmar = (acpi_dmar_t *)current; |
Marc Jones | b7e591e | 2020-11-13 15:55:31 -0700 | [diff] [blame] | 447 | enum dmar_flags flags = DMAR_INTR_REMAP; |
| 448 | |
| 449 | /* SKX FSP doesn't support X2APIC, but CPX FSP does */ |
| 450 | if (CONFIG(SOC_INTEL_SKYLAKE_SP)) |
| 451 | flags |= DMAR_X2APIC_OPT_OUT; |
| 452 | |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 453 | printk(BIOS_DEBUG, "ACPI: * DMAR\n"); |
Marc Jones | b7e591e | 2020-11-13 15:55:31 -0700 | [diff] [blame] | 454 | printk(BIOS_DEBUG, "[DMA Remapping table] Flags: 0x%x\n", flags); |
| 455 | acpi_create_dmar(dmar, flags, acpi_fill_dmar); |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 456 | current += dmar->header.length; |
| 457 | current = acpi_align_current(current); |
| 458 | acpi_add_table(rsdp, dmar); |
| 459 | } |
| 460 | |
Rocky Phagura | d4db36e | 2021-04-03 08:49:32 -0700 | [diff] [blame] | 461 | if (CONFIG(SOC_ACPI_HEST)) |
| 462 | current = hest_create(current, rsdp); |
| 463 | |
Marc Jones | 97321db | 2020-09-28 23:35:08 -0600 | [diff] [blame] | 464 | return current; |
| 465 | } |