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 | |
Shuo Liu | 6c708d8 | 2024-04-29 18:16:30 +0800 | [diff] [blame] | 64 | if (mem32_base <= mem32_limit) |
| 65 | domain_mem_window_from_to(domain, index++, mem32_base, mem32_limit + 1); |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 66 | |
Shuo Liu | 6c708d8 | 2024-04-29 18:16:30 +0800 | [diff] [blame] | 67 | if (mem64_base <= mem64_limit) |
| 68 | domain_mem_window_from_to(domain, index++, mem64_base, mem64_limit + 1); |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 69 | } |
| 70 | |
Shuo Liu | ec58beb | 2024-03-11 07:14:07 +0800 | [diff] [blame] | 71 | void create_ioat_domains(const union xeon_domain_path path, |
| 72 | struct bus *const bus, |
| 73 | const STACK_RES *const sr, |
| 74 | const size_t pci_segment_group) |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 75 | { |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 76 | if (sr->BusLimit < sr->BusBase + HQM_BUS_OFFSET + HQM_RESERVED_BUS) { |
| 77 | printk(BIOS_WARNING, |
| 78 | "Ignoring IOAT domain with limited bus range.\n"); |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | if (sr->PciResourceMem64Limit - sr->PciResourceMem64Base + 1 |
| 83 | < 2 * CPM_MMIO_SIZE + 2 * HQM_MMIO_SIZE) { |
| 84 | printk(BIOS_WARNING, |
| 85 | "Ignoring IOAT domain with limited 64-bit MMIO window.\n"); |
| 86 | return; |
| 87 | } |
| 88 | |
| 89 | /* The FSP HOB doesn't provide accurate information about the |
| 90 | resource allocation. Hence use pre-defined offsets. Based |
Shuo Liu | 08f1f05 | 2024-01-20 02:52:17 +0800 | [diff] [blame] | 91 | on ACPI code in create_dsdt_ioat_resource(), soc_acpi.c: */ |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 92 | resource_t mem64_base, mem64_limit, bus_base, bus_limit; |
| 93 | |
| 94 | /* CPM0 */ |
| 95 | mem64_base = sr->PciResourceMem64Base; |
| 96 | mem64_limit = mem64_base + CPM_MMIO_SIZE - 1; |
| 97 | bus_base = sr->BusBase + CPM_BUS_OFFSET; |
| 98 | bus_limit = bus_base + CPM_RESERVED_BUS; |
Patrick Rudolph | 7d83441 | 2024-02-29 18:08:09 +0100 | [diff] [blame] | 99 | 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] | 100 | DOMAIN_TYPE_CPM0, pci_segment_group); |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 101 | |
| 102 | /* HQM0 */ |
| 103 | mem64_base = mem64_limit + 1; |
| 104 | mem64_limit = mem64_base + HQM_MMIO_SIZE - 1; |
| 105 | bus_base = sr->BusBase + HQM_BUS_OFFSET; |
| 106 | bus_limit = bus_base + HQM_RESERVED_BUS; |
Patrick Rudolph | 7d83441 | 2024-02-29 18:08:09 +0100 | [diff] [blame] | 107 | 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] | 108 | DOMAIN_TYPE_HQM0, pci_segment_group); |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 109 | |
| 110 | /* CPM1 (optional) */ |
| 111 | mem64_base = mem64_limit + 1; |
| 112 | mem64_limit = mem64_base + CPM_MMIO_SIZE - 1; |
| 113 | bus_base = sr->BusBase + CPM1_BUS_OFFSET; |
| 114 | bus_limit = bus_base + CPM_RESERVED_BUS; |
| 115 | if (bus_limit <= sr->BusLimit) |
Patrick Rudolph | 7d83441 | 2024-02-29 18:08:09 +0100 | [diff] [blame] | 116 | 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] | 117 | DOMAIN_TYPE_CPM1, pci_segment_group); |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 118 | |
| 119 | /* HQM1 (optional) */ |
| 120 | mem64_base = mem64_limit + 1; |
| 121 | mem64_limit = mem64_base + HQM_MMIO_SIZE - 1; |
| 122 | bus_base = sr->BusBase + HQM1_BUS_OFFSET; |
| 123 | bus_limit = bus_base + HQM_RESERVED_BUS; |
| 124 | if (bus_limit <= sr->BusLimit) |
Patrick Rudolph | 7d83441 | 2024-02-29 18:08:09 +0100 | [diff] [blame] | 125 | 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] | 126 | DOMAIN_TYPE_HQM1, pci_segment_group); |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 127 | |
| 128 | /* DINO */ |
| 129 | mem64_base = mem64_limit + 1; |
| 130 | mem64_limit = sr->PciResourceMem64Limit; |
| 131 | bus_base = sr->BusBase; |
| 132 | bus_limit = bus_base; |
Patrick Rudolph | 8c99ebc | 2024-01-19 17:28:47 +0100 | [diff] [blame] | 133 | 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] | 134 | mem64_base, mem64_limit, DOMAIN_TYPE_DINO, pci_segment_group); |
Arthur Heymans | 550f55e | 2022-08-24 14:44:26 +0200 | [diff] [blame] | 135 | } |