Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Patrick Rudolph | e357ac3 | 2024-02-23 09:47:24 +0100 | [diff] [blame] | 2 | #include <acpi/acpigen_pci.h> |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 3 | #include <stdbool.h> |
| 4 | |
| 5 | #include <console/console.h> |
| 6 | #include <device/device.h> |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 7 | |
| 8 | #include <defs_iio.h> |
| 9 | #include <hob_iiouds.h> |
Patrick Rudolph | 40e0748 | 2024-02-23 09:23:41 +0100 | [diff] [blame] | 10 | #include <intelblocks/acpi.h> |
| 11 | #include <soc/acpi.h> |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 12 | #include <IioPcieConfigUpd.h> |
| 13 | |
| 14 | #include <soc/chip_common.h> |
| 15 | |
| 16 | /* |
| 17 | * Used for IIO stacks for accelerators and other functionality (IOAT). |
| 18 | * Those have only integrated PCI endpoints (no bridges) behind the host bridge. |
| 19 | */ |
| 20 | |
| 21 | static struct device_operations ioat_domain_ops = { |
| 22 | .read_resources = noop_read_resources, |
| 23 | .set_resources = pci_domain_set_resources, |
| 24 | .scan_bus = pci_host_bridge_scan_bus, |
Patrick Rudolph | 40e0748 | 2024-02-23 09:23:41 +0100 | [diff] [blame] | 25 | #if CONFIG(HAVE_ACPI_TABLES) |
| 26 | .acpi_name = soc_acpi_name, |
Shuo Liu | 255f927 | 2023-03-29 20:14:11 +0800 | [diff] [blame] | 27 | .write_acpi_tables = northbridge_write_acpi_tables, |
Patrick Rudolph | e357ac3 | 2024-02-23 09:47:24 +0100 | [diff] [blame] | 28 | .acpi_fill_ssdt = pci_domain_fill_ssdt, |
Patrick Rudolph | 40e0748 | 2024-02-23 09:23:41 +0100 | [diff] [blame] | 29 | #endif |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 30 | }; |
| 31 | |
Patrick Rudolph | 8c99ebc | 2024-01-19 17:28:47 +0100 | [diff] [blame] | 32 | static void create_ioat_domain(const union xeon_domain_path dp, struct bus *const upstream, |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 33 | const unsigned int bus_base, const unsigned int bus_limit, |
| 34 | const resource_t mem32_base, const resource_t mem32_limit, |
Patrick Rudolph | 40e0748 | 2024-02-23 09:23:41 +0100 | [diff] [blame] | 35 | const resource_t mem64_base, const resource_t mem64_limit, |
Patrick Rudolph | 8061957 | 2024-03-12 18:32:35 +0100 | [diff] [blame] | 36 | const char *prefix, const size_t pci_segment_group) |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 37 | { |
Patrick Rudolph | 8c99ebc | 2024-01-19 17:28:47 +0100 | [diff] [blame] | 38 | union xeon_domain_path new_path = { |
| 39 | .domain_path = dp.domain_path |
| 40 | }; |
| 41 | new_path.bus = bus_base; |
| 42 | |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 43 | struct device_path path = { |
| 44 | .type = DEVICE_PATH_DOMAIN, |
| 45 | .domain = { |
Patrick Rudolph | 8c99ebc | 2024-01-19 17:28:47 +0100 | [diff] [blame] | 46 | .domain = new_path.domain_path, |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 47 | }, |
| 48 | }; |
Shuo Liu | 255f927 | 2023-03-29 20:14:11 +0800 | [diff] [blame] | 49 | struct device *const domain = alloc_find_dev(upstream, &path); |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 50 | if (!domain) |
| 51 | die("%s: out of memory.\n", __func__); |
| 52 | |
| 53 | domain->ops = &ioat_domain_ops; |
Patrick Rudolph | 40e0748 | 2024-02-23 09:23:41 +0100 | [diff] [blame] | 54 | iio_domain_set_acpi_name(domain, prefix); |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 55 | |
Arthur Heymans | 3e99ba0 | 2024-01-25 22:26:07 +0100 | [diff] [blame] | 56 | struct bus *const bus = alloc_bus(domain); |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 57 | bus->secondary = bus_base; |
| 58 | bus->subordinate = bus->secondary; |
| 59 | bus->max_subordinate = bus_limit; |
Patrick Rudolph | 8061957 | 2024-03-12 18:32:35 +0100 | [diff] [blame] | 60 | bus->segment_group = pci_segment_group; |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 61 | |
| 62 | unsigned int index = 0; |
| 63 | |
| 64 | if (mem32_base <= mem32_limit) { |
| 65 | struct resource *const res = new_resource(domain, index++); |
| 66 | res->base = mem32_base; |
| 67 | res->limit = mem32_limit; |
| 68 | res->size = res->limit - res->base + 1; |
| 69 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED; |
| 70 | } |
| 71 | |
| 72 | if (mem64_base <= mem64_limit) { |
| 73 | struct resource *const res = new_resource(domain, index++); |
| 74 | res->base = mem64_base; |
| 75 | res->limit = mem64_limit; |
| 76 | res->size = res->limit - res->base + 1; |
| 77 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED; |
| 78 | } |
| 79 | } |
| 80 | |
Shuo Liu | ec58beb | 2024-03-11 07:14:07 +0800 | [diff] [blame] | 81 | void create_ioat_domains(const union xeon_domain_path path, |
| 82 | struct bus *const bus, |
| 83 | const STACK_RES *const sr, |
| 84 | const size_t pci_segment_group) |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 85 | { |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 86 | if (sr->BusLimit < sr->BusBase + HQM_BUS_OFFSET + HQM_RESERVED_BUS) { |
| 87 | printk(BIOS_WARNING, |
| 88 | "Ignoring IOAT domain with limited bus range.\n"); |
| 89 | return; |
| 90 | } |
| 91 | |
| 92 | if (sr->PciResourceMem64Limit - sr->PciResourceMem64Base + 1 |
| 93 | < 2 * CPM_MMIO_SIZE + 2 * HQM_MMIO_SIZE) { |
| 94 | printk(BIOS_WARNING, |
| 95 | "Ignoring IOAT domain with limited 64-bit MMIO window.\n"); |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | /* The FSP HOB doesn't provide accurate information about the |
| 100 | resource allocation. Hence use pre-defined offsets. Based |
Shuo Liu | 08f1f05 | 2024-01-20 02:52:17 +0800 | [diff] [blame] | 101 | on ACPI code in create_dsdt_ioat_resource(), soc_acpi.c: */ |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 102 | resource_t mem64_base, mem64_limit, bus_base, bus_limit; |
| 103 | |
| 104 | /* CPM0 */ |
| 105 | mem64_base = sr->PciResourceMem64Base; |
| 106 | mem64_limit = mem64_base + CPM_MMIO_SIZE - 1; |
| 107 | bus_base = sr->BusBase + CPM_BUS_OFFSET; |
| 108 | bus_limit = bus_base + CPM_RESERVED_BUS; |
Patrick Rudolph | 7d83441 | 2024-02-29 18:08:09 +0100 | [diff] [blame] | 109 | create_ioat_domain(path, bus, bus_base, bus_limit, -1, 0, mem64_base, mem64_limit, |
Patrick Rudolph | 8061957 | 2024-03-12 18:32:35 +0100 | [diff] [blame] | 110 | DOMAIN_TYPE_CPM0, pci_segment_group); |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 111 | |
| 112 | /* HQM0 */ |
| 113 | mem64_base = mem64_limit + 1; |
| 114 | mem64_limit = mem64_base + HQM_MMIO_SIZE - 1; |
| 115 | bus_base = sr->BusBase + HQM_BUS_OFFSET; |
| 116 | bus_limit = bus_base + HQM_RESERVED_BUS; |
Patrick Rudolph | 7d83441 | 2024-02-29 18:08:09 +0100 | [diff] [blame] | 117 | create_ioat_domain(path, bus, bus_base, bus_limit, -1, 0, mem64_base, mem64_limit, |
Patrick Rudolph | 8061957 | 2024-03-12 18:32:35 +0100 | [diff] [blame] | 118 | DOMAIN_TYPE_HQM0, pci_segment_group); |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 119 | |
| 120 | /* CPM1 (optional) */ |
| 121 | mem64_base = mem64_limit + 1; |
| 122 | mem64_limit = mem64_base + CPM_MMIO_SIZE - 1; |
| 123 | bus_base = sr->BusBase + CPM1_BUS_OFFSET; |
| 124 | bus_limit = bus_base + CPM_RESERVED_BUS; |
| 125 | if (bus_limit <= sr->BusLimit) |
Patrick Rudolph | 7d83441 | 2024-02-29 18:08:09 +0100 | [diff] [blame] | 126 | create_ioat_domain(path, bus, bus_base, bus_limit, -1, 0, mem64_base, mem64_limit, |
Patrick Rudolph | 8061957 | 2024-03-12 18:32:35 +0100 | [diff] [blame] | 127 | DOMAIN_TYPE_CPM1, pci_segment_group); |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 128 | |
| 129 | /* HQM1 (optional) */ |
| 130 | mem64_base = mem64_limit + 1; |
| 131 | mem64_limit = mem64_base + HQM_MMIO_SIZE - 1; |
| 132 | bus_base = sr->BusBase + HQM1_BUS_OFFSET; |
| 133 | bus_limit = bus_base + HQM_RESERVED_BUS; |
| 134 | if (bus_limit <= sr->BusLimit) |
Patrick Rudolph | 7d83441 | 2024-02-29 18:08:09 +0100 | [diff] [blame] | 135 | create_ioat_domain(path, bus, bus_base, bus_limit, -1, 0, mem64_base, mem64_limit, |
Patrick Rudolph | 8061957 | 2024-03-12 18:32:35 +0100 | [diff] [blame] | 136 | DOMAIN_TYPE_HQM1, pci_segment_group); |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 137 | |
| 138 | /* DINO */ |
| 139 | mem64_base = mem64_limit + 1; |
| 140 | mem64_limit = sr->PciResourceMem64Limit; |
| 141 | bus_base = sr->BusBase; |
| 142 | bus_limit = bus_base; |
Patrick Rudolph | 8c99ebc | 2024-01-19 17:28:47 +0100 | [diff] [blame] | 143 | create_ioat_domain(path, bus, bus_base, bus_limit, sr->PciResourceMem32Base, sr->PciResourceMem32Limit, |
Patrick Rudolph | 8061957 | 2024-03-12 18:32:35 +0100 | [diff] [blame] | 144 | mem64_base, mem64_limit, DOMAIN_TYPE_DINO, pci_segment_group); |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 145 | } |