| 1 |
|
| 2 |
#include <acpi/acpigen_pci.h> |
| 3 |
#include <stdbool.h> |
| 4 |
|
| 5 |
#include <console/console.h> |
| 6 |
#include <device/device.h> |
| 7 |
|
| 8 |
#include <defs_iio.h> |
| 9 |
#include <hob_iiouds.h> |
| 10 |
#include <intelblocks/acpi.h> |
| 11 |
#include <intelblocks/vtd.h> |
| 12 |
#include <soc/acpi.h> |
| 13 |
#include <soc/pci_devs.h> |
| 14 |
#include <IioPcieConfigUpd.h> |
| 15 |
#include <soc/chip_common.h> |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
static struct device_operations ioat_domain_ops = { |
| 23 |
.read_resources = noop_read_resources, |
| 24 |
.set_resources = pci_domain_set_resources, |
| 25 |
.scan_bus = pci_host_bridge_scan_bus, |
| 26 |
#if CONFIG(HAVE_ACPI_TABLES) |
| 27 |
.acpi_name = soc_acpi_name, |
| 28 |
.write_acpi_tables = northbridge_write_acpi_tables, |
| 29 |
.acpi_fill_ssdt = pci_domain_fill_ssdt, |
| 30 |
#endif |
| 31 |
}; |
| 32 |
|
| 33 |
static struct device *const create_ioat_domain(const union xeon_domain_path dp, struct bus *const upstream, |
| 34 |
const unsigned int bus_base, const unsigned int bus_limit, |
| 35 |
const resource_t mem32_base, const resource_t mem32_limit, |
| 36 |
const resource_t mem64_base, const resource_t mem64_limit, |
| 37 |
const char *prefix, const size_t pci_segment_group, int *res_index) |
| 38 |
{ |
| 39 |
union xeon_domain_path new_path = { |
| 40 |
.domain_path = dp.domain_path |
| 41 |
}; |
| 42 |
new_path.bus = bus_base; |
| 43 |
|
| 44 |
struct device_path path = { |
| 45 |
.type = DEVICE_PATH_DOMAIN, |
| 46 |
.domain = { |
| 47 |
.domain_id = new_path.domain_path, |
| 48 |
}, |
| 49 |
}; |
| 50 |
struct device *const domain = alloc_find_dev(upstream, &path); |
| 51 |
if (!domain) |
| 52 |
die("%s: out of memory.\n", __func__); |
| 53 |
|
| 54 |
domain->ops = &ioat_domain_ops; |
| 55 |
iio_domain_set_acpi_name(domain, prefix); |
| 56 |
|
| 57 |
struct bus *const bus = alloc_bus(domain); |
| 58 |
bus->secondary = bus_base; |
| 59 |
bus->subordinate = bus->secondary; |
| 60 |
bus->max_subordinate = bus_limit; |
| 61 |
bus->segment_group = pci_segment_group; |
| 62 |
|
| 63 |
unsigned int index = res_index ? *res_index : 0; |
| 64 |
|
| 65 |
if (mem32_base <= mem32_limit) |
| 66 |
domain_mem_window_from_to(domain, index++, mem32_base, mem32_limit + 1); |
| 67 |
|
| 68 |
if (mem64_base <= mem64_limit) |
| 69 |
domain_mem_window_from_to(domain, index++, mem64_base, mem64_limit + 1); |
| 70 |
|
| 71 |
if (res_index) |
| 72 |
*res_index = index; |
| 73 |
|
| 74 |
return domain; |
| 75 |
} |
| 76 |
|
| 77 |
void create_ioat_domains(const union xeon_domain_path path, |
| 78 |
struct bus *const bus, |
| 79 |
const STACK_RES *const sr, |
| 80 |
const size_t pci_segment_group) |
| 81 |
{ |
| 82 |
struct device *vtd_dev; |
| 83 |
|
| 84 |
if (sr->BusLimit < sr->BusBase + HQM_BUS_OFFSET + HQM_RESERVED_BUS) { |
| 85 |
printk(BIOS_WARNING, |
| 86 |
"Ignoring IOAT domain with limited bus range.\n"); |
| 87 |
return; |
| 88 |
} |
| 89 |
|
| 90 |
if (sr->PciResourceMem64Limit - sr->PciResourceMem64Base + 1 |
| 91 |
< 2 * CPM_MMIO_SIZE + 2 * HQM_MMIO_SIZE) { |
| 92 |
printk(BIOS_WARNING, |
| 93 |
"Ignoring IOAT domain with limited 64-bit MMIO window.\n"); |
| 94 |
return; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
resource_t mem64_base, mem64_limit, bus_base, bus_limit; |
| 101 |
|
| 102 |
|
| 103 |
mem64_base = sr->PciResourceMem64Base; |
| 104 |
mem64_limit = mem64_base + CPM_MMIO_SIZE - 1; |
| 105 |
bus_base = sr->BusBase + CPM_BUS_OFFSET; |
| 106 |
bus_limit = bus_base + CPM_RESERVED_BUS; |
| 107 |
create_ioat_domain(path, bus, bus_base, bus_limit, -1, 0, mem64_base, mem64_limit, |
| 108 |
DOMAIN_TYPE_CPM0, pci_segment_group, NULL); |
| 109 |
|
| 110 |
|
| 111 |
mem64_base = mem64_limit + 1; |
| 112 |
mem64_limit = mem64_base + HQM_MMIO_SIZE - 1; |
| 113 |
bus_base = sr->BusBase + HQM_BUS_OFFSET; |
| 114 |
bus_limit = bus_base + HQM_RESERVED_BUS; |
| 115 |
create_ioat_domain(path, bus, bus_base, bus_limit, -1, 0, mem64_base, mem64_limit, |
| 116 |
DOMAIN_TYPE_HQM0, pci_segment_group, NULL); |
| 117 |
|
| 118 |
|
| 119 |
mem64_base = mem64_limit + 1; |
| 120 |
mem64_limit = mem64_base + CPM_MMIO_SIZE - 1; |
| 121 |
bus_base = sr->BusBase + CPM1_BUS_OFFSET; |
| 122 |
bus_limit = bus_base + CPM_RESERVED_BUS; |
| 123 |
if (bus_limit <= sr->BusLimit) |
| 124 |
create_ioat_domain(path, bus, bus_base, bus_limit, -1, 0, mem64_base, mem64_limit, |
| 125 |
DOMAIN_TYPE_CPM1, pci_segment_group, NULL); |
| 126 |
|
| 127 |
|
| 128 |
mem64_base = mem64_limit + 1; |
| 129 |
mem64_limit = mem64_base + HQM_MMIO_SIZE - 1; |
| 130 |
bus_base = sr->BusBase + HQM1_BUS_OFFSET; |
| 131 |
bus_limit = bus_base + HQM_RESERVED_BUS; |
| 132 |
if (bus_limit <= sr->BusLimit) |
| 133 |
create_ioat_domain(path, bus, bus_base, bus_limit, -1, 0, mem64_base, mem64_limit, |
| 134 |
DOMAIN_TYPE_HQM1, pci_segment_group, NULL); |
| 135 |
|
| 136 |
|
| 137 |
mem64_base = mem64_limit + 1; |
| 138 |
mem64_limit = sr->PciResourceMem64Limit; |
| 139 |
bus_base = sr->BusBase; |
| 140 |
bus_limit = bus_base; |
| 141 |
int index = 0; |
| 142 |
struct device *const dev = create_ioat_domain(path, bus, bus_base, bus_limit, |
| 143 |
sr->PciResourceMem32Base, sr->PciResourceMem32Limit, |
| 144 |
mem64_base, mem64_limit, DOMAIN_TYPE_DINO, pci_segment_group, |
| 145 |
&index); |
| 146 |
|
| 147 |
|
| 148 |
vtd_dev = pcidev_on_root(VTD_DEV_NUM, VTD_FUNC_NUM); |
| 149 |
assert(vtd_dev); |
| 150 |
|
| 151 |
uint64_t reserved_mmio = sr->VtdBarAddress + vtd_probe_bar_size(vtd_dev); |
| 152 |
if ((reserved_mmio >= sr->PciResourceMem32Base) && |
| 153 |
(reserved_mmio <= sr->PciResourceMem32Limit)) |
| 154 |
mmio_range(dev, index, reserved_mmio, |
| 155 |
sr->PciResourceMem32Limit - reserved_mmio + 1); |
| 156 |
} |