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