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