| 1 |
|
| 2 |
|
| 3 |
#include <acpi/acpigen.h> |
| 4 |
#include <arch/hpet.h> |
| 5 |
#include <arch/ioapic.h> |
| 6 |
#include <assert.h> |
| 7 |
#include <cpu/x86/lapic.h> |
| 8 |
#include <commonlib/sort.h> |
| 9 |
#include <device/mmio.h> |
| 10 |
#include <device/pci.h> |
| 11 |
#include <device/pciexp.h> |
| 12 |
#include <device/pci_ids.h> |
| 13 |
#include <device/pci_ops.h> |
| 14 |
#include <soc/acpi.h> |
| 15 |
#include <soc/chip_common.h> |
| 16 |
#include <soc/hest.h> |
| 17 |
#include <soc/iomap.h> |
| 18 |
#include <soc/numa.h> |
| 19 |
#include <soc/pci_devs.h> |
| 20 |
#include <soc/soc_util.h> |
| 21 |
#include <soc/util.h> |
| 22 |
#include "chip.h" |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
#define MAX_THREAD 2 |
| 28 |
|
| 29 |
unsigned long acpi_create_srat_lapics(unsigned long current) |
| 30 |
{ |
| 31 |
struct device *cpu; |
| 32 |
unsigned int num_cpus = 0; |
| 33 |
int apic_ids[CONFIG_MAX_CPUS] = {}; |
| 34 |
|
| 35 |
unsigned int sort_start = 0; |
| 36 |
for (unsigned int thread_id = 0; thread_id < MAX_THREAD; thread_id++) { |
| 37 |
for (cpu = all_devices; cpu; cpu = cpu->next) { |
| 38 |
if (!is_enabled_cpu(cpu)) |
| 39 |
continue; |
| 40 |
if (num_cpus >= ARRAY_SIZE(apic_ids)) |
| 41 |
break; |
| 42 |
if (cpu->path.apic.thread_id != thread_id) |
| 43 |
continue; |
| 44 |
apic_ids[num_cpus++] = cpu->path.apic.apic_id; |
| 45 |
} |
| 46 |
bubblesort(&apic_ids[sort_start], num_cpus - sort_start, NUM_ASCENDING); |
| 47 |
sort_start = num_cpus; |
| 48 |
} |
| 49 |
|
| 50 |
for (unsigned int i = 0; i < num_cpus; i++) { |
| 51 |
|
| 52 |
for (cpu = all_devices; cpu; cpu = cpu->next) { |
| 53 |
if (!is_enabled_cpu(cpu)) |
| 54 |
continue; |
| 55 |
if (cpu->path.apic.apic_id == apic_ids[i]) |
| 56 |
break; |
| 57 |
} |
| 58 |
if (!cpu) |
| 59 |
continue; |
| 60 |
|
| 61 |
if (is_x2apic_mode()) { |
| 62 |
printk(BIOS_DEBUG, "SRAT: x2apic cpu_index=%04x, node_id=%02x, apic_id=%08x\n", |
| 63 |
i, device_to_pd(cpu), cpu->path.apic.apic_id); |
| 64 |
|
| 65 |
current += acpi_create_srat_x2apic((acpi_srat_x2apic_t *)current, |
| 66 |
device_to_pd(cpu), cpu->path.apic.apic_id); |
| 67 |
} else { |
| 68 |
printk(BIOS_DEBUG, "SRAT: lapic cpu_index=%02x, node_id=%02x, apic_id=%02x\n", |
| 69 |
i, device_to_pd(cpu), cpu->path.apic.apic_id); |
| 70 |
|
| 71 |
current += acpi_create_srat_lapic((acpi_srat_lapic_t *)current, |
| 72 |
device_to_pd(cpu), cpu->path.apic.apic_id); |
| 73 |
} |
| 74 |
} |
| 75 |
return current; |
| 76 |
} |
| 77 |
|
| 78 |
static void acpi_fill_srat_memory(int *cnt, acpi_srat_mem_t *current, |
| 79 |
const struct SystemMemoryMapElement *e) |
| 80 |
{ |
| 81 |
acpi_srat_mem_t srat; |
| 82 |
uint64_t addr, size; |
| 83 |
|
| 84 |
addr = ((uint64_t)e->BaseAddress << MEM_ADDR_64MB_SHIFT_BITS); |
| 85 |
size = ((uint64_t)e->ElementSize << MEM_ADDR_64MB_SHIFT_BITS); |
| 86 |
|
| 87 |
printk(BIOS_DEBUG, " sysmemmap addr: 0x%llx, size: 0x%llx, " |
| 88 |
"type: %d, reserved: %d\n", addr, size, e->Type, |
| 89 |
is_memtype_reserved(e->Type)); |
| 90 |
|
| 91 |
|
| 92 |
if (is_memtype_reserved(e->Type)) |
| 93 |
return; |
| 94 |
|
| 95 |
|
| 96 |
if (CONFIG(SOC_INTEL_HAS_CXL) && |
| 97 |
(!is_memtype_processor_attached(e->Type))) |
| 98 |
return; |
| 99 |
|
| 100 |
|
| 101 |
memset(&srat, 0, sizeof(acpi_srat_mem_t)); |
| 102 |
|
| 103 |
srat.type = 1; |
| 104 |
srat.length = sizeof(acpi_srat_mem_t); |
| 105 |
srat.base_address_low = (uint32_t)(addr & 0xffffffff); |
| 106 |
srat.base_address_high = (uint32_t)(addr >> 32); |
| 107 |
srat.length_low = (uint32_t)(size & 0xffffffff); |
| 108 |
srat.length_high = (uint32_t)(size >> 32); |
| 109 |
srat.proximity_domain = memory_to_pd(e); |
| 110 |
srat.flags = ACPI_SRAT_MEMORY_ENABLED; |
| 111 |
if (is_memtype_non_volatile(e->Type)) |
| 112 |
srat.flags |= ACPI_SRAT_MEMORY_NONVOLATILE; |
| 113 |
|
| 114 |
|
| 115 |
bool skip = false; |
| 116 |
for (int i = 0; i < *cnt; i++) { |
| 117 |
if ((srat.base_address_high == current[-i].base_address_high) && |
| 118 |
(srat.base_address_low == current[-i].base_address_low)) { |
| 119 |
skip = true; |
| 120 |
break; |
| 121 |
} |
| 122 |
} |
| 123 |
|
| 124 |
if (!skip) { |
| 125 |
printk(BIOS_DEBUG, "SRAT: memory %d: addr=0x%x%08x, " |
| 126 |
"length=0x%x%08x, proximity_domain=%d, flags=%x\n", |
| 127 |
*cnt, srat.base_address_high, srat.base_address_low, |
| 128 |
srat.length_high, srat.length_low, srat.proximity_domain, srat.flags); |
| 129 |
|
| 130 |
memcpy(current, &srat, sizeof(acpi_srat_mem_t)); |
| 131 |
(*cnt)++; |
| 132 |
} |
| 133 |
} |
| 134 |
|
| 135 |
static unsigned long acpi_fill_srat(unsigned long current) |
| 136 |
{ |
| 137 |
const struct SystemMemoryMapHob *memory_map; |
| 138 |
acpi_srat_mem_t *acpi_srat; |
| 139 |
int cnt = 0; |
| 140 |
|
| 141 |
memory_map = get_system_memory_map(); |
| 142 |
assert(memory_map); |
| 143 |
printk(BIOS_DEBUG, "SRAT: memory_map: %p\n", memory_map); |
| 144 |
|
| 145 |
|
| 146 |
current = acpi_create_srat_lapics(current); |
| 147 |
acpi_srat = (acpi_srat_mem_t *)current; |
| 148 |
|
| 149 |
for (int i = 0; i < memory_map->numberEntries; ++i) { |
| 150 |
const struct SystemMemoryMapElement *e = &memory_map->Element[i]; |
| 151 |
acpi_fill_srat_memory(&cnt, &acpi_srat[cnt], e); |
| 152 |
} |
| 153 |
printk(BIOS_DEBUG, "SRAT: Added %d memory entries\n", cnt); |
| 154 |
|
| 155 |
current = (unsigned long)&acpi_srat[cnt]; |
| 156 |
|
| 157 |
if (CONFIG(SOC_INTEL_HAS_CXL)) |
| 158 |
current = cxl_fill_srat(current); |
| 159 |
|
| 160 |
return current; |
| 161 |
} |
| 162 |
|
| 163 |
#if CONFIG(SOC_INTEL_SAPPHIRERAPIDS_SP) |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
static unsigned long acpi_fill_slit(unsigned long current) |
| 170 |
{ |
| 171 |
uint8_t *p = (uint8_t *)current; |
| 172 |
|
| 173 |
|
| 174 |
memset(p, 0, 8 + pds.num_pds * pds.num_pds); |
| 175 |
*p = (uint8_t)pds.num_pds; |
| 176 |
p += 8; |
| 177 |
|
| 178 |
for (int i = 0; i < pds.num_pds; i++) { |
| 179 |
for (int j = 0; j < pds.num_pds; j++) |
| 180 |
p[i * pds.num_pds + j] = pds.pds[i].distances[j]; |
| 181 |
} |
| 182 |
|
| 183 |
current += 8 + pds.num_pds * pds.num_pds; |
| 184 |
return current; |
| 185 |
} |
| 186 |
#else |
| 187 |
static unsigned long acpi_fill_slit(unsigned long current) |
| 188 |
{ |
| 189 |
unsigned int nodes = soc_get_num_cpus(); |
| 190 |
|
| 191 |
uint8_t *p = (uint8_t *)current; |
| 192 |
memset(p, 0, 8 + nodes * nodes); |
| 193 |
*p = (uint8_t)nodes; |
| 194 |
p += 8; |
| 195 |
|
| 196 |
|
| 197 |
for (int i = 0; i < nodes; i++) { |
| 198 |
for (int j = 0; j < nodes; j++) { |
| 199 |
if (i == j) |
| 200 |
p[i*nodes+j] = 10; |
| 201 |
else |
| 202 |
p[i*nodes+j] = 16; |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
current += 8 + nodes * nodes; |
| 207 |
return current; |
| 208 |
} |
| 209 |
#endif |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
static unsigned long acpi_create_dmar_ds_pci_br_for_port(unsigned long current, |
| 216 |
const struct device *bridge_dev, |
| 217 |
uint32_t pcie_seg, |
| 218 |
bool is_atsr, bool *first) |
| 219 |
{ |
| 220 |
const uint32_t bus = bridge_dev->upstream->secondary; |
| 221 |
const uint32_t dev = PCI_SLOT(bridge_dev->path.pci.devfn); |
| 222 |
const uint32_t func = PCI_FUNC(bridge_dev->path.pci.devfn); |
| 223 |
|
| 224 |
if (bus == 0) |
| 225 |
return current; |
| 226 |
|
| 227 |
unsigned long atsr_size = 0; |
| 228 |
unsigned long pci_br_size = 0; |
| 229 |
if (is_atsr == true && first && *first == true) { |
| 230 |
printk(BIOS_DEBUG, "[Root Port ATS Capability] Flags: 0x%x, " |
| 231 |
"PCI Segment Number: 0x%x\n", 0, pcie_seg); |
| 232 |
atsr_size = acpi_create_dmar_atsr(current, 0, pcie_seg); |
| 233 |
*first = false; |
| 234 |
} |
| 235 |
|
| 236 |
printk(BIOS_DEBUG, " [PCI Bridge Device] %s\n", dev_path(bridge_dev)); |
| 237 |
pci_br_size = acpi_create_dmar_ds_pci_br(current + atsr_size, bus, dev, func); |
| 238 |
|
| 239 |
return (atsr_size + pci_br_size); |
| 240 |
} |
| 241 |
|
| 242 |
static unsigned long acpi_create_drhd(unsigned long current, struct device *iommu, |
| 243 |
const IIO_UDS *hob) |
| 244 |
{ |
| 245 |
unsigned long tmp = current; |
| 246 |
|
| 247 |
struct resource *resource; |
| 248 |
resource = probe_resource(iommu, VTD_BAR_CSR); |
| 249 |
if (!resource || !resource->base || !resource->size) |
| 250 |
return current; |
| 251 |
|
| 252 |
const uint32_t bus = iommu->upstream->secondary; |
| 253 |
uint32_t pcie_seg = iommu->upstream->segment_group; |
| 254 |
int socket = iio_pci_domain_socket_from_dev(iommu); |
| 255 |
int stack = iio_pci_domain_stack_from_dev(iommu); |
| 256 |
|
| 257 |
printk(BIOS_SPEW, "%s socket: %d, stack: %d, bus: 0x%x, pcie_seg: 0x%x, reg_base: 0x%llx\n", |
| 258 |
__func__, socket, stack, bus, pcie_seg, resource->base); |
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
uint8_t flags = ((!CONFIG(SOC_INTEL_COMMON_IBL_BASE)) && is_dev_on_domain0(iommu)) ? |
| 267 |
DRHD_INCLUDE_PCI_ALL : 0; |
| 268 |
|
| 269 |
printk(BIOS_DEBUG, "[Hardware Unit Definition] Flags: 0x%x, PCI Segment Number: 0x%x, " |
| 270 |
"Register Base Address: 0x%llx\n", |
| 271 |
flags, pcie_seg, resource->base); |
| 272 |
current += acpi_create_dmar_drhd(current, flags, pcie_seg, resource->base, |
| 273 |
resource->size); |
| 274 |
|
| 275 |
|
| 276 |
if (is_dev_on_domain0(iommu)) { |
| 277 |
union p2sb_bdf ioapic_bdf = soc_get_ioapic_bdf(); |
| 278 |
printk(BIOS_DEBUG, " [IOAPIC Device] Enumeration ID: 0x%x, PCI Bus Number: 0x%x, " |
| 279 |
"PCI Path: 0x%x, 0x%x, Address: 0x%x\n", get_ioapic_id(IO_APIC_ADDR), ioapic_bdf.bus, |
| 280 |
ioapic_bdf.dev, ioapic_bdf.fn, IO_APIC_ADDR); |
| 281 |
current += acpi_create_dmar_ds_ioapic_from_hw(current, |
| 282 |
IO_APIC_ADDR, ioapic_bdf.bus, ioapic_bdf.dev, ioapic_bdf.fn); |
| 283 |
} |
| 284 |
|
| 285 |
#if (CONFIG(SOC_INTEL_SKYLAKE_SP) || CONFIG(SOC_INTEL_COOPERLAKE_SP)) |
| 286 |
|
| 287 |
{ |
| 288 |
const struct device *domain = dev_get_domain(iommu); |
| 289 |
struct device *dev = NULL; |
| 290 |
while ((dev = dev_bus_each_child(domain->downstream, dev))) { |
| 291 |
if (!is_pci_ioapic(dev)) |
| 292 |
continue; |
| 293 |
|
| 294 |
const uint32_t b = dev->upstream->secondary; |
| 295 |
const uint32_t d = PCI_SLOT(dev->path.pci.devfn); |
| 296 |
const uint32_t f = PCI_FUNC(dev->path.pci.devfn); |
| 297 |
|
| 298 |
u16 abar = pci_read_config16(dev, APIC_ABAR); |
| 299 |
if (!abar) |
| 300 |
continue; |
| 301 |
const u32 addr = IO_APIC_ADDR | ((abar & 0xfff) << 8); |
| 302 |
|
| 303 |
printk(BIOS_DEBUG, " [IOAPIC Device] Enumeration ID: 0x%x, PCI Bus Number: 0x%x, " |
| 304 |
"PCI Path: 0x%x, 0x%x, Address: 0x%x\n", get_ioapic_id(addr), b, d, f, addr); |
| 305 |
|
| 306 |
current += acpi_create_dmar_ds_ioapic_from_hw( |
| 307 |
current, addr, b, d, f); |
| 308 |
} |
| 309 |
} |
| 310 |
#endif |
| 311 |
|
| 312 |
if (flags != DRHD_INCLUDE_PCI_ALL) { |
| 313 |
|
| 314 |
const struct device *domain = dev_get_domain(iommu); |
| 315 |
struct device *dev = NULL; |
| 316 |
while ((dev = dev_bus_each_child(domain->downstream, dev))) |
| 317 |
if (is_pci_bridge(dev)) |
| 318 |
current += |
| 319 |
acpi_create_dmar_ds_pci_br_for_port( |
| 320 |
current, dev, pcie_seg, false, NULL); |
| 321 |
|
| 322 |
|
| 323 |
dev = NULL; |
| 324 |
while ((dev = dev_find_all_devices_on_stack(socket, stack, |
| 325 |
XEONSP_VENDOR_MAX, XEONSP_DEVICE_MAX, dev))) { |
| 326 |
const uint32_t b = dev->upstream->secondary; |
| 327 |
const uint32_t d = PCI_SLOT(dev->path.pci.devfn); |
| 328 |
const uint32_t f = PCI_FUNC(dev->path.pci.devfn); |
| 329 |
struct device *upstream_dev = dev->upstream->dev; |
| 330 |
|
| 331 |
if (is_pci_bridge(dev)) |
| 332 |
continue; |
| 333 |
|
| 334 |
if (upstream_dev->path.type != DEVICE_PATH_DOMAIN) |
| 335 |
continue; |
| 336 |
|
| 337 |
printk(BIOS_DEBUG, " [PCIE Endpoint Device] %s\n", dev_path(dev)); |
| 338 |
current += acpi_create_dmar_ds_pci(current, b, d, f); |
| 339 |
} |
| 340 |
} |
| 341 |
|
| 342 |
|
| 343 |
if (is_dev_on_domain0(iommu)) { |
| 344 |
uint16_t hpet_capid = read16p(HPET_BASE_ADDRESS + HPET_GEN_CAP_ID); |
| 345 |
|
| 346 |
uint16_t num_hpets = (hpet_capid >> HPET_NUM_TIM_CAP_SHIFT) & HPET_NUM_TIM_CAP_MASK; |
| 347 |
printk(BIOS_SPEW, "%s hpet_capid: 0x%x, num_hpets: 0x%x\n", |
| 348 |
__func__, hpet_capid, num_hpets); |
| 349 |
|
| 350 |
if (num_hpets && (num_hpets != 0x1f) && |
| 351 |
(read32p(HPET_BASE_ADDRESS + HPET_TMR0_CNF_CAP) & (HPET_TIMER_FSB_EN_CNF_MASK))) { |
| 352 |
union p2sb_bdf hpet_bdf = soc_get_hpet_bdf(); |
| 353 |
printk(BIOS_DEBUG, " [Message-capable HPET Device] Enumeration ID: 0x%x, " |
| 354 |
"PCI Bus Number: 0x%x, PCI Path: 0x%x, 0x%x\n", |
| 355 |
0, hpet_bdf.bus, hpet_bdf.dev, hpet_bdf.fn); |
| 356 |
current += acpi_create_dmar_ds_msi_hpet(current, 0, hpet_bdf.bus, |
| 357 |
hpet_bdf.dev, hpet_bdf.fn); |
| 358 |
} |
| 359 |
} |
| 360 |
|
| 361 |
acpi_dmar_drhd_fixup(tmp, current); |
| 362 |
|
| 363 |
return current; |
| 364 |
} |
| 365 |
|
| 366 |
static unsigned long acpi_create_atsr(unsigned long current) |
| 367 |
{ |
| 368 |
struct device *domain = NULL; |
| 369 |
struct device *child, *dev; |
| 370 |
struct resource *resource; |
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
for (int socket = 0; socket < CONFIG_MAX_SOCKET; ++socket) { |
| 380 |
if (!soc_cpu_is_enabled(socket)) |
| 381 |
continue; |
| 382 |
unsigned long tmp = current; |
| 383 |
bool first = true; |
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
while ((domain = dev_find_path(domain, DEVICE_PATH_DOMAIN))) { |
| 388 |
dev = pcidev_path_behind(domain->downstream, |
| 389 |
PCI_DEVFN(VTD_DEV_NUM, VTD_FUNC_NUM)); |
| 390 |
assert(dev); |
| 391 |
if (!dev) |
| 392 |
continue; |
| 393 |
|
| 394 |
if (iio_pci_domain_socket_from_dev(dev) != socket) |
| 395 |
continue; |
| 396 |
|
| 397 |
resource = probe_resource(dev, VTD_BAR_CSR); |
| 398 |
if (!resource) |
| 399 |
continue; |
| 400 |
int stack = iio_pci_domain_stack_from_dev(dev); |
| 401 |
|
| 402 |
uint64_t vtd_mmio_cap = read64(res2mmio(resource, VTD_EXT_CAP_LOW, 0)); |
| 403 |
printk(BIOS_SPEW, "%s socket: %d, stack: %d, bus: 0x%x, vtd_base: %p, " |
| 404 |
"vtd_mmio_cap: 0x%llx\n", |
| 405 |
__func__, socket, stack, dev->upstream->secondary, |
| 406 |
res2mmio(resource, 0, 0), vtd_mmio_cap); |
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
assert(vtd_mmio_cap != 0xffffffffffffffff); |
| 411 |
if ((vtd_mmio_cap & 0x4) == 0) |
| 412 |
continue; |
| 413 |
|
| 414 |
if (dev->upstream->secondary == 0 && dev->upstream->segment_group == 0) |
| 415 |
continue; |
| 416 |
|
| 417 |
for (child = dev->upstream->children; child; child = child->sibling) { |
| 418 |
if (!is_pci_bridge(child)) |
| 419 |
continue; |
| 420 |
current += |
| 421 |
acpi_create_dmar_ds_pci_br_for_port( |
| 422 |
current, child, child->upstream->segment_group, true, &first); |
| 423 |
} |
| 424 |
} |
| 425 |
if (tmp != current) |
| 426 |
acpi_dmar_atsr_fixup(tmp, current); |
| 427 |
} |
| 428 |
|
| 429 |
return current; |
| 430 |
} |
| 431 |
|
| 432 |
static unsigned long acpi_create_rmrr(unsigned long current) |
| 433 |
{ |
| 434 |
return current; |
| 435 |
} |
| 436 |
|
| 437 |
static unsigned long acpi_create_rhsa(unsigned long current) |
| 438 |
{ |
| 439 |
struct device *domain = NULL; |
| 440 |
struct resource *resource; |
| 441 |
struct device *dev; |
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
while ((domain = dev_find_path(domain, DEVICE_PATH_DOMAIN))) { |
| 446 |
dev = pcidev_path_behind(domain->downstream, |
| 447 |
PCI_DEVFN(VTD_DEV_NUM, VTD_FUNC_NUM)); |
| 448 |
assert(dev); |
| 449 |
if (!dev) |
| 450 |
continue; |
| 451 |
|
| 452 |
resource = probe_resource(dev, VTD_BAR_CSR); |
| 453 |
if (!resource) |
| 454 |
continue; |
| 455 |
|
| 456 |
printk(BIOS_DEBUG, "[Remapping Hardware Static Affinity] Base Address: %p, " |
| 457 |
"Proximity Domain: 0x%x\n", res2mmio(resource, 0, 0), device_to_pd(dev)); |
| 458 |
current += acpi_create_dmar_rhsa(current, (uintptr_t)res2mmio(resource, 0, 0), device_to_pd(dev)); |
| 459 |
} |
| 460 |
|
| 461 |
return current; |
| 462 |
} |
| 463 |
|
| 464 |
static unsigned long xeonsp_create_satc(unsigned long current, struct device *domain) |
| 465 |
{ |
| 466 |
struct device *dev = NULL; |
| 467 |
while ((dev = dev_bus_each_child(domain->downstream, dev))) { |
| 468 |
if (pciexp_find_extended_cap(dev, PCIE_EXT_CAP_ID_ATS, 0)) { |
| 469 |
const uint32_t b = domain->downstream->secondary; |
| 470 |
const uint32_t d = PCI_SLOT(dev->path.pci.devfn); |
| 471 |
const uint32_t f = PCI_FUNC(dev->path.pci.devfn); |
| 472 |
printk(BIOS_DEBUG, " [SATC Endpoint Device] %s\n", dev_path(dev)); |
| 473 |
current += acpi_create_dmar_ds_pci(current, b, d, f); |
| 474 |
} |
| 475 |
} |
| 476 |
return current; |
| 477 |
} |
| 478 |
|
| 479 |
|
| 480 |
static unsigned long acpi_create_satc(unsigned long current) |
| 481 |
{ |
| 482 |
unsigned long tmp = current, seg = ~0; |
| 483 |
struct device *dev; |
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
for (int socket = 0; socket < CONFIG_MAX_SOCKET; ++socket) { |
| 498 |
if (!soc_cpu_is_enabled(socket)) |
| 499 |
continue; |
| 500 |
|
| 501 |
dev = NULL; |
| 502 |
while ((dev = dev_find_path(dev, DEVICE_PATH_DOMAIN))) { |
| 503 |
|
| 504 |
if (iio_pci_domain_socket_from_dev(dev) != socket) |
| 505 |
continue; |
| 506 |
|
| 507 |
if (seg != dev->downstream->segment_group) { |
| 508 |
|
| 509 |
if (tmp != current) |
| 510 |
acpi_dmar_satc_fixup(tmp, current); |
| 511 |
|
| 512 |
seg = dev->downstream->segment_group; |
| 513 |
tmp = current; |
| 514 |
printk(BIOS_DEBUG, "[SATC Segment Header] " |
| 515 |
"Flags: 0x%x, PCI segment group: %lx\n", 0, seg); |
| 516 |
|
| 517 |
current += acpi_create_dmar_satc(current, 0, seg); |
| 518 |
} |
| 519 |
current = xeonsp_create_satc(current, dev); |
| 520 |
} |
| 521 |
} |
| 522 |
if (tmp != current) |
| 523 |
acpi_dmar_satc_fixup(tmp, current); |
| 524 |
|
| 525 |
return current; |
| 526 |
} |
| 527 |
|
| 528 |
static unsigned long acpi_fill_dmar(unsigned long current) |
| 529 |
{ |
| 530 |
const IIO_UDS *hob = get_iio_uds(); |
| 531 |
|
| 532 |
|
| 533 |
struct device *domain = NULL; |
| 534 |
struct device *iommu0 = NULL; |
| 535 |
struct device *dev; |
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
while ((domain = dev_find_path(domain, DEVICE_PATH_DOMAIN))) { |
| 540 |
dev = pcidev_path_behind(domain->downstream, |
| 541 |
PCI_DEVFN(VTD_DEV_NUM, VTD_FUNC_NUM)); |
| 542 |
assert(dev); |
| 543 |
if (!dev) |
| 544 |
continue; |
| 545 |
if (is_dev_on_domain0(dev)) { |
| 546 |
iommu0 = dev; |
| 547 |
continue; |
| 548 |
} |
| 549 |
current = acpi_create_drhd(current, dev, hob); |
| 550 |
} |
| 551 |
|
| 552 |
assert(iommu0); |
| 553 |
current = acpi_create_drhd(current, iommu0, hob); |
| 554 |
|
| 555 |
|
| 556 |
current = acpi_create_rmrr(current); |
| 557 |
|
| 558 |
|
| 559 |
current = acpi_create_atsr(current); |
| 560 |
|
| 561 |
|
| 562 |
current = acpi_create_rhsa(current); |
| 563 |
|
| 564 |
|
| 565 |
current = acpi_create_satc(current); |
| 566 |
|
| 567 |
return current; |
| 568 |
} |
| 569 |
|
| 570 |
unsigned long northbridge_write_acpi_tables(const struct device *device, unsigned long current, |
| 571 |
struct acpi_rsdp *rsdp) |
| 572 |
{ |
| 573 |
|
| 574 |
if (!is_domain0(device)) |
| 575 |
return current; |
| 576 |
|
| 577 |
acpi_srat_t *srat; |
| 578 |
acpi_slit_t *slit; |
| 579 |
acpi_dmar_t *dmar; |
| 580 |
acpi_hmat_t *hmat; |
| 581 |
acpi_cedt_t *cedt; |
| 582 |
|
| 583 |
const config_t *const config = config_of(device); |
| 584 |
|
| 585 |
|
| 586 |
current = ALIGN_UP(current, 8); |
| 587 |
printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current); |
| 588 |
srat = (acpi_srat_t *)current; |
| 589 |
acpi_create_srat(srat, acpi_fill_srat); |
| 590 |
current += srat->header.length; |
| 591 |
acpi_add_table(rsdp, srat); |
| 592 |
|
| 593 |
|
| 594 |
current = ALIGN_UP(current, 8); |
| 595 |
printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current); |
| 596 |
slit = (acpi_slit_t *)current; |
| 597 |
acpi_create_slit(slit, acpi_fill_slit); |
| 598 |
current += slit->header.length; |
| 599 |
acpi_add_table(rsdp, slit); |
| 600 |
|
| 601 |
if (CONFIG(SOC_INTEL_HAS_CXL)) { |
| 602 |
|
| 603 |
current = ALIGN_UP(current, 8); |
| 604 |
printk(BIOS_DEBUG, "ACPI: * HMAT at %lx\n", current); |
| 605 |
hmat = (acpi_hmat_t *)current; |
| 606 |
acpi_create_hmat(hmat, acpi_fill_hmat); |
| 607 |
current += hmat->header.length; |
| 608 |
acpi_add_table(rsdp, hmat); |
| 609 |
} |
| 610 |
|
| 611 |
|
| 612 |
if (config->vtd_support) { |
| 613 |
current = ALIGN_UP(current, 8); |
| 614 |
dmar = (acpi_dmar_t *)current; |
| 615 |
enum dmar_flags flags = DMAR_INTR_REMAP; |
| 616 |
printk(BIOS_DEBUG, "ACPI: * DMAR at %lx\n", current); |
| 617 |
printk(BIOS_DEBUG, "[DMA Remapping table] Flags: 0x%x\n", flags); |
| 618 |
acpi_create_dmar(dmar, flags, acpi_fill_dmar); |
| 619 |
current += dmar->header.length; |
| 620 |
current = acpi_align_current(current); |
| 621 |
acpi_add_table(rsdp, dmar); |
| 622 |
} |
| 623 |
|
| 624 |
if (CONFIG(SOC_INTEL_HAS_CXL)) { |
| 625 |
|
| 626 |
if (get_cxl_node_count() > 0) { |
| 627 |
current = ALIGN_UP(current, 8); |
| 628 |
printk(BIOS_DEBUG, "ACPI: * CEDT at %lx\n", current); |
| 629 |
cedt = (acpi_cedt_t *)current; |
| 630 |
acpi_create_cedt(cedt, acpi_fill_cedt); |
| 631 |
current += cedt->header.length; |
| 632 |
acpi_add_table(rsdp, cedt); |
| 633 |
} |
| 634 |
} |
| 635 |
|
| 636 |
if (CONFIG(SOC_ACPI_HEST)) { |
| 637 |
printk(BIOS_DEBUG, "ACPI: * HEST at %lx\n", current); |
| 638 |
current = hest_create(current, rsdp); |
| 639 |
} |
| 640 |
|
| 641 |
return current; |
| 642 |
} |