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