Marc Jones | 392bcca | 2020-09-28 11:19:39 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <acpi/acpi_gnvs.h> |
| 4 | #include <acpi/acpigen.h> |
| 5 | #include <arch/smp/mpspec.h> |
| 6 | #include <assert.h> |
| 7 | #include <cbmem.h> |
| 8 | #include <cpu/intel/turbo.h> |
| 9 | #include <device/mmio.h> |
| 10 | #include <device/pci.h> |
| 11 | #include <intelblocks/acpi.h> |
| 12 | #include <soc/acpi.h> |
| 13 | #include <soc/cpu.h> |
| 14 | #include <soc/iomap.h> |
| 15 | #include <soc/msr.h> |
| 16 | #include <soc/pci_devs.h> |
| 17 | #include <soc/pm.h> |
| 18 | #include <soc/soc_util.h> |
| 19 | |
| 20 | #include "chip.h" |
| 21 | |
| 22 | /* TODO: Check if the common/acpi weak function can be used */ |
| 23 | unsigned long acpi_fill_mcfg(unsigned long current) |
| 24 | { |
| 25 | current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current, |
| 26 | CONFIG_MMCONF_BASE_ADDRESS, 0, 0, 255); |
| 27 | return current; |
| 28 | } |
| 29 | |
| 30 | void acpi_create_gnvs(struct global_nvs *gnvs) |
| 31 | { |
| 32 | /* CPU core count */ |
| 33 | gnvs->pcnt = dev_count_cpu(); |
| 34 | printk(BIOS_DEBUG, "%s gnvs->pcnt: %d\n", __func__, gnvs->pcnt); |
| 35 | } |
| 36 | |
| 37 | int soc_madt_sci_irq_polarity(int sci) |
| 38 | { |
| 39 | if (sci >= 20) |
| 40 | return MP_IRQ_POLARITY_LOW; |
| 41 | else |
| 42 | return MP_IRQ_POLARITY_HIGH; |
| 43 | } |
| 44 | |
Marc Jones | 70ddbd8 | 2020-09-28 12:25:03 -0600 | [diff] [blame] | 45 | uint32_t soc_read_sci_irq_select(void) |
| 46 | { |
| 47 | struct device *dev = PCH_DEV_PMC; |
| 48 | |
| 49 | if (!dev) |
| 50 | return 0; |
| 51 | |
| 52 | return pci_read_config32(dev, PMC_ACPI_CNT); |
| 53 | } |
| 54 | |
Marc Jones | 2560ad3 | 2020-09-28 15:23:35 -0600 | [diff] [blame^] | 55 | void soc_fill_fadt(acpi_fadt_t *fadt) |
| 56 | { |
| 57 | /* Clear flags set by common/block/acpi/acpi.c acpi_fill_fadt() */ |
| 58 | fadt->flags &= ~(ACPI_FADT_SLEEP_BUTTON | ACPI_FADT_SEALED_CASE | |
| 59 | ACPI_FADT_S4_RTC_WAKE); |
| 60 | } |
| 61 | |
Marc Jones | 392bcca | 2020-09-28 11:19:39 -0600 | [diff] [blame] | 62 | /* |
| 63 | * Currently called in southbridge_inject_dsdt(). Change to soc_southbridge_inject_dsdt() |
| 64 | * with a call from the common/function or find another way to call this at the correct place |
| 65 | */ |
| 66 | void uncore_inject_dsdt(void) |
| 67 | { |
| 68 | struct iiostack_resource stack_info = {0}; |
| 69 | |
| 70 | get_iiostack_info(&stack_info); |
| 71 | |
| 72 | acpigen_write_scope("\\_SB"); |
| 73 | |
| 74 | for (uint8_t stack = 0; stack < stack_info.no_of_stacks; ++stack) { |
| 75 | const STACK_RES *ri = &stack_info.res[stack]; |
| 76 | char rtname[16]; |
| 77 | |
| 78 | snprintf(rtname, sizeof(rtname), "RT%02x", stack); |
| 79 | |
| 80 | acpigen_write_name(rtname); |
| 81 | printk(BIOS_DEBUG, "\tCreating ResourceTemplate %s for stack: %d\n", |
| 82 | rtname, stack); |
| 83 | |
| 84 | acpigen_write_resourcetemplate_header(); |
| 85 | |
| 86 | /* bus resource */ |
| 87 | acpigen_resource_word(2, 0xc, 0, 0, ri->BusBase, ri->BusLimit, |
| 88 | 0x0, (ri->BusLimit - ri->BusBase + 1)); |
| 89 | |
| 90 | /* additional io resources on socket 0 bus 0 */ |
| 91 | if (stack == 0) { |
| 92 | /* ACPI 6.4.2.5 I/O Port Descriptor */ |
| 93 | acpigen_write_io16(0xCF8, 0xCFF, 0x1, 0x8, 1); |
| 94 | |
| 95 | /* IO decode CF8-CFF */ |
| 96 | acpigen_resource_word(1, 0xc, 0x3, 0, 0x0000, 0x03AF, 0, 0x03B0); |
| 97 | acpigen_resource_word(1, 0xc, 0x3, 0, 0x03E0, 0x0CF7, 0, 0x0918); |
| 98 | acpigen_resource_word(1, 0xc, 0x3, 0, 0x03B0, 0x03BB, 0, 0x000C); |
| 99 | acpigen_resource_word(1, 0xc, 0x3, 0, 0x03C0, 0x03DF, 0, 0x0020); |
| 100 | } |
| 101 | |
| 102 | /* IO resource */ |
| 103 | acpigen_resource_word(1, 0xc, 0x3, 0, ri->PciResourceIoBase, |
| 104 | ri->PciResourceIoLimit, 0x0, |
| 105 | (ri->PciResourceIoLimit - ri->PciResourceIoBase + 1)); |
| 106 | |
| 107 | /* additional mem32 resources on socket 0 bus 0 */ |
| 108 | if (stack == 0) { |
| 109 | acpigen_resource_dword(0, 0xc, 3, 0, VGA_BASE_ADDRESS, |
| 110 | (VGA_BASE_ADDRESS + VGA_BASE_SIZE - 1), 0x0, |
| 111 | VGA_BASE_SIZE); |
| 112 | acpigen_resource_dword(0, 0xc, 1, 0, SPI_BASE_ADDRESS, |
| 113 | (SPI_BASE_ADDRESS + SPI_BASE_SIZE - 1), 0x0, |
| 114 | SPI_BASE_SIZE); |
| 115 | } |
| 116 | |
| 117 | /* Mem32 resource */ |
| 118 | acpigen_resource_dword(0, 0xc, 1, 0, ri->PciResourceMem32Base, |
| 119 | ri->PciResourceMem32Limit, 0x0, |
| 120 | (ri->PciResourceMem32Limit - ri->PciResourceMem32Base + 1)); |
| 121 | |
| 122 | /* Mem64 resource */ |
| 123 | acpigen_resource_qword(0, 0xc, 1, 0, ri->PciResourceMem64Base, |
| 124 | ri->PciResourceMem64Limit, 0x0, |
| 125 | (ri->PciResourceMem64Limit - ri->PciResourceMem64Base + 1)); |
| 126 | |
| 127 | acpigen_write_resourcetemplate_footer(); |
| 128 | } |
| 129 | acpigen_pop_len(); |
| 130 | } |
| 131 | |
| 132 | /* To be renamed soc_power_states_generation() */ |
| 133 | void cpx_generate_p_state_entries(int core, int cores_per_package) |
| 134 | { |
| 135 | int ratio_min, ratio_max, ratio_turbo, ratio_step; |
| 136 | int coord_type, power_max, power_unit, num_entries; |
| 137 | int ratio, power, clock, clock_max; |
| 138 | msr_t msr; |
| 139 | |
| 140 | /* Determine P-state coordination type from MISC_PWR_MGMT[0] */ |
| 141 | msr = rdmsr(MSR_MISC_PWR_MGMT); |
| 142 | if (msr.lo & MISC_PWR_MGMT_EIST_HW_DIS) |
| 143 | coord_type = SW_ANY; |
| 144 | else |
| 145 | coord_type = HW_ALL; |
| 146 | |
| 147 | /* Get bus ratio limits and calculate clock speeds */ |
| 148 | msr = rdmsr(MSR_PLATFORM_INFO); |
| 149 | ratio_min = (msr.hi >> (40-32)) & 0xff; /* Max Efficiency Ratio */ |
| 150 | |
| 151 | /* Determine if this CPU has configurable TDP */ |
| 152 | if (cpu_config_tdp_levels()) { |
| 153 | /* Set max ratio to nominal TDP ratio */ |
| 154 | msr = rdmsr(MSR_CONFIG_TDP_NOMINAL); |
| 155 | ratio_max = msr.lo & 0xff; |
| 156 | } else { |
| 157 | /* Max Non-Turbo Ratio */ |
| 158 | ratio_max = (msr.lo >> 8) & 0xff; |
| 159 | } |
| 160 | clock_max = ratio_max * CONFIG_CPU_BCLK_MHZ; |
| 161 | |
| 162 | /* Calculate CPU TDP in mW */ |
| 163 | msr = rdmsr(MSR_PKG_POWER_SKU_UNIT); |
| 164 | power_unit = 2 << ((msr.lo & 0xf) - 1); |
| 165 | msr = rdmsr(MSR_PKG_POWER_SKU); |
| 166 | power_max = ((msr.lo & 0x7fff) / power_unit) * 1000; |
| 167 | |
| 168 | /* Write _PCT indicating use of FFixedHW */ |
| 169 | acpigen_write_empty_PCT(); |
| 170 | |
| 171 | /* Write _PPC with no limit on supported P-state */ |
| 172 | acpigen_write_PPC_NVS(); |
| 173 | |
| 174 | /* Write PSD indicating configured coordination type */ |
| 175 | acpigen_write_PSD_package(core, 1, coord_type); |
| 176 | |
| 177 | /* Add P-state entries in _PSS table */ |
| 178 | acpigen_write_name("_PSS"); |
| 179 | |
| 180 | /* Determine ratio points */ |
| 181 | ratio_step = PSS_RATIO_STEP; |
| 182 | num_entries = ((ratio_max - ratio_min) / ratio_step) + 1; |
| 183 | if (num_entries > PSS_MAX_ENTRIES) { |
| 184 | ratio_step += 1; |
| 185 | num_entries = ((ratio_max - ratio_min) / ratio_step) + 1; |
| 186 | } |
| 187 | |
| 188 | /* P[T] is Turbo state if enabled */ |
| 189 | if (get_turbo_state() == TURBO_ENABLED) { |
| 190 | /* _PSS package count including Turbo */ |
| 191 | acpigen_write_package(num_entries + 2); |
| 192 | |
| 193 | msr = rdmsr(MSR_TURBO_RATIO_LIMIT); |
| 194 | ratio_turbo = msr.lo & 0xff; |
| 195 | |
| 196 | /* Add entry for Turbo ratio */ |
| 197 | acpigen_write_PSS_package( |
| 198 | clock_max + 1, /* MHz */ |
| 199 | power_max, /* mW */ |
| 200 | PSS_LATENCY_TRANSITION, /* lat1 */ |
| 201 | PSS_LATENCY_BUSMASTER, /* lat2 */ |
| 202 | ratio_turbo << 8, /* control */ |
| 203 | ratio_turbo << 8); /* status */ |
| 204 | } else { |
| 205 | /* _PSS package count without Turbo */ |
| 206 | acpigen_write_package(num_entries + 1); |
| 207 | } |
| 208 | |
| 209 | /* First regular entry is max non-turbo ratio */ |
| 210 | acpigen_write_PSS_package( |
| 211 | clock_max, /* MHz */ |
| 212 | power_max, /* mW */ |
| 213 | PSS_LATENCY_TRANSITION, /* lat1 */ |
| 214 | PSS_LATENCY_BUSMASTER, /* lat2 */ |
| 215 | ratio_max << 8, /* control */ |
| 216 | ratio_max << 8); /* status */ |
| 217 | |
| 218 | /* Generate the remaining entries */ |
| 219 | for (ratio = ratio_min + ((num_entries - 1) * ratio_step); |
| 220 | ratio >= ratio_min; ratio -= ratio_step) { |
| 221 | |
| 222 | /* Calculate power at this ratio */ |
| 223 | power = calculate_power(power_max, ratio_max, ratio); |
| 224 | clock = ratio * CONFIG_CPU_BCLK_MHZ; |
| 225 | //clock = 1; |
| 226 | acpigen_write_PSS_package( |
| 227 | clock, /* MHz */ |
| 228 | power, /* mW */ |
| 229 | PSS_LATENCY_TRANSITION, /* lat1 */ |
| 230 | PSS_LATENCY_BUSMASTER, /* lat2 */ |
| 231 | ratio << 8, /* control */ |
| 232 | ratio << 8); /* status */ |
| 233 | } |
| 234 | |
| 235 | /* Fix package length */ |
| 236 | acpigen_pop_len(); |
| 237 | } |
| 238 | |
| 239 | unsigned long xeonsp_acpi_create_madt_lapics(unsigned long current) |
| 240 | { |
| 241 | struct device *cpu; |
| 242 | uint8_t num_cpus = 0; |
| 243 | |
| 244 | for (cpu = all_devices; cpu; cpu = cpu->next) { |
| 245 | if ((cpu->path.type != DEVICE_PATH_APIC) || |
| 246 | (cpu->bus->dev->path.type != DEVICE_PATH_CPU_CLUSTER)) { |
| 247 | continue; |
| 248 | } |
| 249 | if (!cpu->enabled) |
| 250 | continue; |
| 251 | current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current, |
| 252 | num_cpus, cpu->path.apic.apic_id); |
| 253 | num_cpus++; |
| 254 | } |
| 255 | |
| 256 | return current; |
| 257 | } |
| 258 | |
| 259 | unsigned long acpi_create_srat_lapics(unsigned long current) |
| 260 | { |
| 261 | struct device *cpu; |
| 262 | unsigned int cpu_index = 0; |
| 263 | |
| 264 | for (cpu = all_devices; cpu; cpu = cpu->next) { |
| 265 | if ((cpu->path.type != DEVICE_PATH_APIC) || |
| 266 | (cpu->bus->dev->path.type != DEVICE_PATH_CPU_CLUSTER)) { |
| 267 | continue; |
| 268 | } |
| 269 | if (!cpu->enabled) |
| 270 | continue; |
| 271 | printk(BIOS_DEBUG, "SRAT: lapic cpu_index=%02x, node_id=%02x, apic_id=%02x\n", |
| 272 | cpu_index, cpu->path.apic.node_id, cpu->path.apic.apic_id); |
| 273 | current += acpi_create_srat_lapic((acpi_srat_lapic_t *)current, |
| 274 | cpu->path.apic.node_id, cpu->path.apic.apic_id); |
| 275 | cpu_index++; |
| 276 | } |
| 277 | return current; |
| 278 | } |
| 279 | |
| 280 | static unsigned int get_srat_memory_entries(acpi_srat_mem_t *srat_mem) |
| 281 | { |
| 282 | const struct SystemMemoryMapHob *memory_map; |
| 283 | unsigned int mmap_index; |
| 284 | |
| 285 | memory_map = get_system_memory_map(); |
| 286 | assert(memory_map != NULL); |
| 287 | printk(BIOS_DEBUG, "memory_map: %p\n", memory_map); |
| 288 | |
| 289 | mmap_index = 0; |
| 290 | for (int e = 0; e < memory_map->numberEntries; ++e) { |
| 291 | const struct SystemMemoryMapElement *mem_element = &memory_map->Element[e]; |
| 292 | uint64_t addr = |
| 293 | (uint64_t) ((uint64_t)mem_element->BaseAddress << |
| 294 | MEM_ADDR_64MB_SHIFT_BITS); |
| 295 | uint64_t size = |
| 296 | (uint64_t) ((uint64_t)mem_element->ElementSize << |
| 297 | MEM_ADDR_64MB_SHIFT_BITS); |
| 298 | |
| 299 | printk(BIOS_DEBUG, "memory_map %d addr: 0x%llx, BaseAddress: 0x%x, size: 0x%llx, " |
| 300 | "ElementSize: 0x%x, reserved: %d\n", |
| 301 | e, addr, mem_element->BaseAddress, size, |
| 302 | mem_element->ElementSize, (mem_element->Type & MEM_TYPE_RESERVED)); |
| 303 | |
| 304 | assert(mmap_index < MAX_ACPI_MEMORY_AFFINITY_COUNT); |
| 305 | |
| 306 | /* skip reserved memory region */ |
| 307 | if (mem_element->Type & MEM_TYPE_RESERVED) |
| 308 | continue; |
| 309 | |
| 310 | /* skip if this address is already added */ |
| 311 | bool skip = false; |
| 312 | for (int idx = 0; idx < mmap_index; ++idx) { |
| 313 | uint64_t base_addr = ((uint64_t)srat_mem[idx].base_address_high << 32) + |
| 314 | srat_mem[idx].base_address_low; |
| 315 | if (addr == base_addr) { |
| 316 | skip = true; |
| 317 | break; |
| 318 | } |
| 319 | } |
| 320 | if (skip) |
| 321 | continue; |
| 322 | |
| 323 | srat_mem[mmap_index].type = 1; /* Memory affinity structure */ |
| 324 | srat_mem[mmap_index].length = sizeof(acpi_srat_mem_t); |
| 325 | srat_mem[mmap_index].base_address_low = (uint32_t) (addr & 0xffffffff); |
| 326 | srat_mem[mmap_index].base_address_high = (uint32_t) (addr >> 32); |
| 327 | srat_mem[mmap_index].length_low = (uint32_t) (size & 0xffffffff); |
| 328 | srat_mem[mmap_index].length_high = (uint32_t) (size >> 32); |
| 329 | srat_mem[mmap_index].proximity_domain = mem_element->SocketId; |
| 330 | srat_mem[mmap_index].flags = SRAT_ACPI_MEMORY_ENABLED; |
| 331 | if ((mem_element->Type & MEMTYPE_VOLATILE_MASK) == 0) |
| 332 | srat_mem[mmap_index].flags |= SRAT_ACPI_MEMORY_NONVOLATILE; |
| 333 | ++mmap_index; |
| 334 | } |
| 335 | |
| 336 | return mmap_index; |
| 337 | } |
| 338 | |
| 339 | static unsigned long acpi_fill_srat(unsigned long current) |
| 340 | { |
| 341 | acpi_srat_mem_t srat_mem[MAX_ACPI_MEMORY_AFFINITY_COUNT]; |
| 342 | unsigned int mem_count; |
| 343 | |
| 344 | /* create all subtables for processors */ |
| 345 | current = acpi_create_srat_lapics(current); |
| 346 | |
| 347 | mem_count = get_srat_memory_entries(srat_mem); |
| 348 | for (int i = 0; i < mem_count; ++i) { |
| 349 | printk(BIOS_DEBUG, "adding srat memory %d entry length: %d, addr: 0x%x%x, " |
| 350 | "length: 0x%x%x, proximity_domain: %d, flags: %x\n", |
| 351 | i, srat_mem[i].length, |
| 352 | srat_mem[i].base_address_high, srat_mem[i].base_address_low, |
| 353 | srat_mem[i].length_high, srat_mem[i].length_low, |
| 354 | srat_mem[i].proximity_domain, srat_mem[i].flags); |
| 355 | memcpy((acpi_srat_mem_t *)current, &srat_mem[i], sizeof(srat_mem[i])); |
| 356 | current += srat_mem[i].length; |
| 357 | } |
| 358 | |
| 359 | return current; |
| 360 | } |
| 361 | |
| 362 | static unsigned long acpi_fill_slit(unsigned long current) |
| 363 | { |
| 364 | unsigned int nodes = xeon_sp_get_socket_count(); |
| 365 | |
| 366 | uint8_t *p = (uint8_t *)current; |
| 367 | memset(p, 0, 8 + nodes * nodes); |
| 368 | *p = (uint8_t)nodes; |
| 369 | p += 8; |
| 370 | |
| 371 | /* this assumes fully connected socket topology */ |
| 372 | for (int i = 0; i < nodes; i++) { |
| 373 | for (int j = 0; j < nodes; j++) { |
| 374 | if (i == j) |
| 375 | p[i*nodes+j] = 10; |
| 376 | else |
| 377 | p[i*nodes+j] = 16; |
| 378 | } |
| 379 | } |
| 380 | |
| 381 | current += 8 + nodes * nodes; |
| 382 | return current; |
| 383 | } |
| 384 | |
| 385 | /* |
| 386 | * Ports Stack Stack(HOB) IioConfigIou |
| 387 | * ========================================== |
| 388 | * 0 CSTACK stack 0 IOU0 |
| 389 | * 1A..1D PSTACK0 stack 1 IOU1 |
| 390 | * 2A..2D PSTACK1 stack 2 IOU2 |
| 391 | * 3A..3D PSTACK2 stack 4 IOU3 |
| 392 | */ |
| 393 | static int get_stack_for_port(int port) |
| 394 | { |
| 395 | if (port == PORT_0) |
| 396 | return CSTACK; |
| 397 | else if (port >= PORT_1A && port <= PORT_1D) |
| 398 | return PSTACK0; |
| 399 | else if (port >= PORT_2A && port <= PORT_2D) |
| 400 | return PSTACK1; |
| 401 | else if (port >= PORT_3A && port <= PORT_3D) |
| 402 | return PSTACK2; |
| 403 | else |
| 404 | return -1; |
| 405 | } |
| 406 | |
| 407 | /* |
| 408 | * This function adds PCIe bridge device entry in DMAR table. If it is called |
| 409 | * in the context of ATSR subtable, it adds ATSR subtable when it is first called. |
| 410 | */ |
| 411 | static unsigned long acpi_create_dmar_ds_pci_br_for_port(unsigned long current, |
| 412 | int port, int stack, IIO_RESOURCE_INSTANCE iio_resource, uint32_t pcie_seg, |
| 413 | bool is_atsr, bool *first) |
| 414 | { |
| 415 | |
| 416 | if (get_stack_for_port(port) != stack) |
| 417 | return 0; |
| 418 | |
| 419 | const uint32_t bus = iio_resource.StackRes[stack].BusBase; |
| 420 | const uint32_t dev = iio_resource.PcieInfo.PortInfo[port].Device; |
| 421 | const uint32_t func = iio_resource.PcieInfo.PortInfo[port].Function; |
| 422 | |
| 423 | const uint32_t id = pci_mmio_read_config32(PCI_DEV(bus, dev, func), |
| 424 | PCI_VENDOR_ID); |
| 425 | if (id == 0xffffffff) |
| 426 | return 0; |
| 427 | |
| 428 | unsigned long atsr_size = 0; |
| 429 | unsigned long pci_br_size = 0; |
| 430 | if (is_atsr == true && first && *first == true) { |
| 431 | printk(BIOS_DEBUG, "[Root Port ATS Capability] Flags: 0x%x, " |
| 432 | "PCI Segment Number: 0x%x\n", 0, pcie_seg); |
| 433 | atsr_size = acpi_create_dmar_atsr(current, 0, pcie_seg); |
| 434 | *first = false; |
| 435 | } |
| 436 | |
| 437 | printk(BIOS_DEBUG, " [PCI Bridge Device] Enumeration ID: 0x%x, " |
| 438 | "PCI Bus Number: 0x%x, PCI Path: 0x%x, 0x%x\n", |
| 439 | 0, bus, dev, func); |
| 440 | pci_br_size = acpi_create_dmar_ds_pci_br(current + atsr_size, bus, dev, func); |
| 441 | |
| 442 | return (atsr_size + pci_br_size); |
| 443 | } |
| 444 | |
| 445 | static unsigned long acpi_create_drhd(unsigned long current, int socket, |
| 446 | int stack, const IIO_UDS *hob) |
| 447 | { |
| 448 | int IoApicID[] = { |
| 449 | // socket 0 |
| 450 | PC00_IOAPIC_ID, PC01_IOAPIC_ID, PC02_IOAPIC_ID, PC03_IOAPIC_ID, |
| 451 | PC04_IOAPIC_ID, PC05_IOAPIC_ID, |
| 452 | // socket 1 |
| 453 | PC06_IOAPIC_ID, PC07_IOAPIC_ID, PC08_IOAPIC_ID, PC09_IOAPIC_ID, |
| 454 | PC10_IOAPIC_ID, PC11_IOAPIC_ID, |
| 455 | }; |
| 456 | |
| 457 | uint32_t enum_id; |
| 458 | unsigned long tmp = current; |
| 459 | |
| 460 | uint32_t bus = hob->PlatformData.IIO_resource[socket].StackRes[stack].BusBase; |
| 461 | uint32_t pcie_seg = hob->PlatformData.CpuQpiInfo[socket].PcieSegment; |
| 462 | uint32_t reg_base = |
| 463 | hob->PlatformData.IIO_resource[socket].StackRes[stack].VtdBarAddress; |
| 464 | printk(BIOS_SPEW, "%s socket: %d, stack: %d, bus: 0x%x, pcie_seg: 0x%x, reg_base: 0x%x\n", |
| 465 | __func__, socket, stack, bus, pcie_seg, reg_base); |
| 466 | |
Jonathan Zhang | 1c3fef2 | 2020-10-08 10:35:05 -0700 | [diff] [blame] | 467 | /* Do not generate DRHD for non-PCIe stack */ |
| 468 | if (!reg_base) |
| 469 | return current; |
| 470 | |
Marc Jones | 392bcca | 2020-09-28 11:19:39 -0600 | [diff] [blame] | 471 | // Add DRHD Hardware Unit |
| 472 | if (socket == 0 && stack == CSTACK) { |
| 473 | printk(BIOS_DEBUG, "[Hardware Unit Definition] Flags: 0x%x, PCI Segment Number: 0x%x, " |
| 474 | "Register Base Address: 0x%x\n", |
| 475 | DRHD_INCLUDE_PCI_ALL, pcie_seg, reg_base); |
| 476 | current += acpi_create_dmar_drhd(current, DRHD_INCLUDE_PCI_ALL, |
| 477 | pcie_seg, reg_base); |
| 478 | } else { |
| 479 | printk(BIOS_DEBUG, "[Hardware Unit Definition] Flags: 0x%x, PCI Segment Number: 0x%x, " |
| 480 | "Register Base Address: 0x%x\n", 0, pcie_seg, reg_base); |
| 481 | current += acpi_create_dmar_drhd(current, 0, pcie_seg, reg_base); |
| 482 | } |
| 483 | |
| 484 | // Add PCH IOAPIC |
| 485 | if (socket == 0 && stack == CSTACK) { |
| 486 | printk(BIOS_DEBUG, " [IOAPIC Device] Enumeration ID: 0x%x, PCI Bus Number: 0x%x, " |
| 487 | "PCI Path: 0x%x, 0x%x\n", |
| 488 | PCH_IOAPIC_ID, PCH_IOAPIC_BUS_NUMBER, |
| 489 | PCH_IOAPIC_DEV_NUM, PCH_IOAPIC_FUNC_NUM); |
| 490 | current += acpi_create_dmar_ds_ioapic(current, PCH_IOAPIC_ID, |
| 491 | PCH_IOAPIC_BUS_NUMBER, PCH_IOAPIC_DEV_NUM, PCH_IOAPIC_FUNC_NUM); |
| 492 | } |
| 493 | |
| 494 | // Add IOAPIC entry |
| 495 | enum_id = IoApicID[(socket*MAX_IIO_STACK)+stack]; |
| 496 | printk(BIOS_DEBUG, " [IOAPIC Device] Enumeration ID: 0x%x, PCI Bus Number: 0x%x, " |
| 497 | "PCI Path: 0x%x, 0x%x\n", enum_id, bus, APIC_DEV_NUM, APIC_FUNC_NUM); |
| 498 | current += acpi_create_dmar_ds_ioapic(current, enum_id, bus, |
| 499 | APIC_DEV_NUM, APIC_FUNC_NUM); |
| 500 | |
| 501 | // Add CBDMA devices for CSTACK |
| 502 | if (socket != 0 && stack == CSTACK) { |
| 503 | for (int cbdma_func_id = 0; cbdma_func_id < 8; ++cbdma_func_id) { |
| 504 | printk(BIOS_DEBUG, " [PCI Endpoint Device] Enumeration ID: 0x%x, " |
| 505 | "PCI Bus Number: 0x%x, PCI Path: 0x%x, 0x%x\n", |
| 506 | 0, bus, CBDMA_DEV_NUM, cbdma_func_id); |
| 507 | current += acpi_create_dmar_ds_pci(current, |
| 508 | bus, CBDMA_DEV_NUM, cbdma_func_id); |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | // Add PCIe Ports |
| 513 | if (socket != 0 || stack != CSTACK) { |
| 514 | IIO_RESOURCE_INSTANCE iio_resource = |
| 515 | hob->PlatformData.IIO_resource[socket]; |
| 516 | for (int p = PORT_0; p < MAX_PORTS; ++p) |
| 517 | current += acpi_create_dmar_ds_pci_br_for_port(current, p, stack, |
| 518 | iio_resource, pcie_seg, false, NULL); |
| 519 | |
| 520 | // Add VMD |
| 521 | if (hob->PlatformData.VMDStackEnable[socket][stack] && |
| 522 | stack >= PSTACK0 && stack <= PSTACK2) { |
| 523 | printk(BIOS_DEBUG, " [PCI Endpoint Device] Enumeration ID: 0x%x, " |
| 524 | "PCI Bus Number: 0x%x, PCI Path: 0x%x, 0x%x\n", |
| 525 | 0, bus, VMD_DEV_NUM, VMD_FUNC_NUM); |
| 526 | current += acpi_create_dmar_ds_pci(current, |
| 527 | bus, VMD_DEV_NUM, VMD_FUNC_NUM); |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | // Add HPET |
| 532 | if (socket == 0 && stack == CSTACK) { |
| 533 | uint16_t hpet_capid = read16((void *)HPET_BASE_ADDRESS); |
| 534 | uint16_t num_hpets = (hpet_capid >> 0x08) & 0x1F; // Bits [8:12] has hpet count |
| 535 | printk(BIOS_SPEW, "%s hpet_capid: 0x%x, num_hpets: 0x%x\n", |
| 536 | __func__, hpet_capid, num_hpets); |
| 537 | //BIT 15 |
| 538 | if (num_hpets && (num_hpets != 0x1f) && |
| 539 | (read32((void *)(HPET_BASE_ADDRESS + 0x100)) & (0x00008000))) { |
| 540 | printk(BIOS_DEBUG, " [Message-capable HPET Device] Enumeration ID: 0x%x, " |
| 541 | "PCI Bus Number: 0x%x, PCI Path: 0x%x, 0x%x\n", |
| 542 | 0, HPET_BUS_NUM, HPET_DEV_NUM, HPET0_FUNC_NUM); |
| 543 | current += acpi_create_dmar_ds_msi_hpet(current, 0, HPET_BUS_NUM, |
| 544 | HPET_DEV_NUM, HPET0_FUNC_NUM); |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | acpi_dmar_drhd_fixup(tmp, current); |
| 549 | |
| 550 | return current; |
| 551 | } |
| 552 | |
| 553 | static unsigned long acpi_create_atsr(unsigned long current, const IIO_UDS *hob) |
| 554 | { |
| 555 | for (int socket = 0; socket < hob->PlatformData.numofIIO; ++socket) { |
| 556 | uint32_t pcie_seg = hob->PlatformData.CpuQpiInfo[socket].PcieSegment; |
| 557 | unsigned long tmp = current; |
| 558 | bool first = true; |
| 559 | IIO_RESOURCE_INSTANCE iio_resource = |
| 560 | hob->PlatformData.IIO_resource[socket]; |
| 561 | |
| 562 | for (int stack = 0; stack <= PSTACK2; ++stack) { |
| 563 | uint32_t bus = iio_resource.StackRes[stack].BusBase; |
| 564 | uint32_t vtd_base = iio_resource.StackRes[stack].VtdBarAddress; |
| 565 | if (!vtd_base) |
| 566 | continue; |
| 567 | uint64_t vtd_mmio_cap = read64((void *)(vtd_base + VTD_EXT_CAP_LOW)); |
| 568 | printk(BIOS_SPEW, "%s socket: %d, stack: %d, bus: 0x%x, vtd_base: 0x%x, " |
| 569 | "vtd_mmio_cap: 0x%llx\n", |
| 570 | __func__, socket, stack, bus, vtd_base, vtd_mmio_cap); |
| 571 | |
| 572 | // ATSR is applicable only for platform supporting device IOTLBs |
| 573 | // through the VT-d extended capability register |
| 574 | assert(vtd_mmio_cap != 0xffffffffffffffff); |
| 575 | if ((vtd_mmio_cap & 0x4) == 0) // BIT 2 |
| 576 | continue; |
| 577 | |
| 578 | for (int p = PORT_0; p < MAX_PORTS; ++p) { |
| 579 | if (socket == 0 && p == PORT_0) |
| 580 | continue; |
| 581 | current += acpi_create_dmar_ds_pci_br_for_port(current, p, |
| 582 | stack, iio_resource, pcie_seg, true, &first); |
| 583 | } |
| 584 | } |
| 585 | if (tmp != current) |
| 586 | acpi_dmar_atsr_fixup(tmp, current); |
| 587 | } |
| 588 | |
| 589 | return current; |
| 590 | } |
| 591 | |
| 592 | static unsigned long acpi_create_rmrr(unsigned long current) |
| 593 | { |
| 594 | uint32_t size = ALIGN_UP(MEM_BLK_COUNT * sizeof(MEM_BLK), 0x1000); |
| 595 | |
| 596 | uint32_t *ptr; |
| 597 | |
| 598 | // reserve memory |
| 599 | ptr = cbmem_find(CBMEM_ID_STORAGE_DATA); |
| 600 | if (!ptr) { |
| 601 | ptr = cbmem_add(CBMEM_ID_STORAGE_DATA, size); |
| 602 | assert(ptr != NULL); |
| 603 | memset(ptr, 0, size); |
| 604 | } |
| 605 | |
| 606 | unsigned long tmp = current; |
| 607 | printk(BIOS_DEBUG, "[Reserved Memory Region] PCI Segment Number: 0x%x, Base Address: 0x%x, " |
| 608 | "End Address (limit): 0x%x\n", |
| 609 | 0, (uint32_t) ptr, (uint32_t) ((uint32_t) ptr + size - 1)); |
| 610 | current += acpi_create_dmar_rmrr(current, 0, (uint32_t) ptr, |
| 611 | (uint32_t) ((uint32_t) ptr + size - 1)); |
| 612 | |
| 613 | printk(BIOS_DEBUG, " [PCI Endpoint Device] Enumeration ID: 0x%x, PCI Bus Number: 0x%x, " |
| 614 | "PCI Path: 0x%x, 0x%x\n", |
| 615 | 0, XHCI_BUS_NUMBER, PCH_DEV_SLOT_XHCI, XHCI_FUNC_NUM); |
| 616 | current += acpi_create_dmar_ds_pci(current, XHCI_BUS_NUMBER, |
| 617 | PCH_DEV_SLOT_XHCI, XHCI_FUNC_NUM); |
| 618 | |
| 619 | acpi_dmar_rmrr_fixup(tmp, current); |
| 620 | |
| 621 | return current; |
| 622 | } |
| 623 | |
| 624 | static unsigned long acpi_create_rhsa(unsigned long current) |
| 625 | { |
| 626 | size_t hob_size; |
| 627 | const uint8_t uds_guid[16] = FSP_HOB_IIO_UNIVERSAL_DATA_GUID; |
| 628 | const IIO_UDS *hob = fsp_find_extension_hob_by_guid(uds_guid, &hob_size); |
| 629 | assert(hob != NULL && hob_size != 0); |
| 630 | |
| 631 | for (int socket = 0; socket < hob->PlatformData.numofIIO; ++socket) { |
| 632 | IIO_RESOURCE_INSTANCE iio_resource = |
| 633 | hob->PlatformData.IIO_resource[socket]; |
| 634 | for (int stack = 0; stack <= PSTACK2; ++stack) { |
| 635 | uint32_t vtd_base = iio_resource.StackRes[stack].VtdBarAddress; |
| 636 | if (!vtd_base) |
| 637 | continue; |
| 638 | |
| 639 | printk(BIOS_DEBUG, "[Remapping Hardware Static Affinity] Base Address: 0x%x, " |
| 640 | "Proximity Domain: 0x%x\n", vtd_base, socket); |
| 641 | current += acpi_create_dmar_rhsa(current, vtd_base, socket); |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | return current; |
| 646 | } |
| 647 | |
| 648 | static unsigned long acpi_fill_dmar(unsigned long current) |
| 649 | { |
| 650 | size_t hob_size; |
| 651 | const uint8_t uds_guid[16] = FSP_HOB_IIO_UNIVERSAL_DATA_GUID; |
| 652 | const IIO_UDS *hob = fsp_find_extension_hob_by_guid(uds_guid, &hob_size); |
| 653 | assert(hob != NULL && hob_size != 0); |
| 654 | |
| 655 | // DRHD |
| 656 | for (int iio = 1; iio <= hob->PlatformData.numofIIO; ++iio) { |
| 657 | int socket = iio; |
| 658 | if (socket == hob->PlatformData.numofIIO) // socket 0 should be last DRHD entry |
| 659 | socket = 0; |
| 660 | |
| 661 | if (socket == 0) { |
| 662 | for (int stack = 1; stack <= PSTACK2; ++stack) |
| 663 | current = acpi_create_drhd(current, socket, stack, hob); |
| 664 | current = acpi_create_drhd(current, socket, CSTACK, hob); |
| 665 | } else { |
| 666 | for (int stack = 0; stack <= PSTACK2; ++stack) |
| 667 | current = acpi_create_drhd(current, socket, stack, hob); |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | // RMRR |
| 672 | current = acpi_create_rmrr(current); |
| 673 | |
| 674 | // Root Port ATS Capability |
| 675 | current = acpi_create_atsr(current, hob); |
| 676 | |
| 677 | // RHSA |
| 678 | current = acpi_create_rhsa(current); |
| 679 | |
| 680 | return current; |
| 681 | } |
| 682 | |
| 683 | unsigned long northbridge_write_acpi_tables(const struct device *device, |
| 684 | unsigned long current, |
| 685 | struct acpi_rsdp *rsdp) |
| 686 | { |
| 687 | acpi_srat_t *srat; |
| 688 | acpi_slit_t *slit; |
| 689 | acpi_dmar_t *dmar; |
| 690 | |
Marc Jones | 3c667a2 | 2020-10-05 12:35:57 -0600 | [diff] [blame] | 691 | const config_t *const config = config_of(device); |
Marc Jones | 392bcca | 2020-09-28 11:19:39 -0600 | [diff] [blame] | 692 | |
| 693 | /* SRAT */ |
| 694 | current = ALIGN(current, 8); |
| 695 | printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current); |
| 696 | srat = (acpi_srat_t *) current; |
| 697 | acpi_create_srat(srat, acpi_fill_srat); |
| 698 | current += srat->header.length; |
| 699 | acpi_add_table(rsdp, srat); |
| 700 | |
| 701 | /* SLIT */ |
| 702 | current = ALIGN(current, 8); |
| 703 | printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current); |
| 704 | slit = (acpi_slit_t *) current; |
| 705 | acpi_create_slit(slit, acpi_fill_slit); |
| 706 | current += slit->header.length; |
| 707 | acpi_add_table(rsdp, slit); |
| 708 | |
| 709 | /* DMAR */ |
| 710 | if (config->vtd_support) { |
| 711 | current = ALIGN(current, 8); |
| 712 | dmar = (acpi_dmar_t *)current; |
| 713 | printk(BIOS_DEBUG, "ACPI: * DMAR\n"); |
| 714 | printk(BIOS_DEBUG, "[DMA Remapping table] Flags: 0x%x\n", DMAR_INTR_REMAP); |
| 715 | acpi_create_dmar(dmar, DMAR_INTR_REMAP, acpi_fill_dmar); |
| 716 | current += dmar->header.length; |
| 717 | current = acpi_align_current(current); |
| 718 | acpi_add_table(rsdp, dmar); |
| 719 | } |
| 720 | |
| 721 | return current; |
| 722 | } |