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