blob: 02f35cfe777d8a2eb54b98a68efbc6f31e698d9a [file] [log] [blame]
Arthur Heymans550f55e2022-08-24 14:44:26 +02001/* 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>
11#include <IioPcieConfigUpd.h>
12
13#include <soc/chip_common.h>
14
15/*
16 * Used for IIO stacks for accelerators and other functionality (IOAT).
17 * Those have only integrated PCI endpoints (no bridges) behind the host bridge.
18 */
19
20static struct device_operations ioat_domain_ops = {
21 .read_resources = noop_read_resources,
22 .set_resources = pci_domain_set_resources,
23 .scan_bus = pci_host_bridge_scan_bus,
24};
25
Patrick Rudolph8c99ebc2024-01-19 17:28:47 +010026static void create_ioat_domain(const union xeon_domain_path dp, struct bus *const upstream,
Arthur Heymans550f55e2022-08-24 14:44:26 +020027 const unsigned int bus_base, const unsigned int bus_limit,
28 const resource_t mem32_base, const resource_t mem32_limit,
29 const resource_t mem64_base, const resource_t mem64_limit)
30{
Patrick Rudolph8c99ebc2024-01-19 17:28:47 +010031 union xeon_domain_path new_path = {
32 .domain_path = dp.domain_path
33 };
34 new_path.bus = bus_base;
35
Arthur Heymans550f55e2022-08-24 14:44:26 +020036 struct device_path path = {
37 .type = DEVICE_PATH_DOMAIN,
38 .domain = {
Patrick Rudolph8c99ebc2024-01-19 17:28:47 +010039 .domain = new_path.domain_path,
Arthur Heymans550f55e2022-08-24 14:44:26 +020040 },
41 };
42 struct device *const domain = alloc_dev(upstream, &path);
43 if (!domain)
44 die("%s: out of memory.\n", __func__);
45
46 domain->ops = &ioat_domain_ops;
47
48 domain->link_list = calloc(1, sizeof(struct bus));
49 if (!domain->link_list)
50 die("%s: out of memory.\n", __func__);
51
52 struct bus *const bus = domain->link_list;
Patrick Rudolphee0a2f92024-01-19 08:27:13 +010053 bus->dev = domain;
Arthur Heymans550f55e2022-08-24 14:44:26 +020054 bus->secondary = bus_base;
55 bus->subordinate = bus->secondary;
56 bus->max_subordinate = bus_limit;
57
58 unsigned int index = 0;
59
60 if (mem32_base <= mem32_limit) {
61 struct resource *const res = new_resource(domain, index++);
62 res->base = mem32_base;
63 res->limit = mem32_limit;
64 res->size = res->limit - res->base + 1;
65 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED;
66 }
67
68 if (mem64_base <= mem64_limit) {
69 struct resource *const res = new_resource(domain, index++);
70 res->base = mem64_base;
71 res->limit = mem64_limit;
72 res->size = res->limit - res->base + 1;
73 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED;
74 }
75}
76
Patrick Rudolph8c99ebc2024-01-19 17:28:47 +010077void soc_create_ioat_domains(const union xeon_domain_path path, struct bus *const bus, const STACK_RES *const sr)
Arthur Heymans550f55e2022-08-24 14:44:26 +020078{
Arthur Heymans550f55e2022-08-24 14:44:26 +020079 if (sr->BusLimit < sr->BusBase + HQM_BUS_OFFSET + HQM_RESERVED_BUS) {
80 printk(BIOS_WARNING,
81 "Ignoring IOAT domain with limited bus range.\n");
82 return;
83 }
84
85 if (sr->PciResourceMem64Limit - sr->PciResourceMem64Base + 1
86 < 2 * CPM_MMIO_SIZE + 2 * HQM_MMIO_SIZE) {
87 printk(BIOS_WARNING,
88 "Ignoring IOAT domain with limited 64-bit MMIO window.\n");
89 return;
90 }
91
92 /* The FSP HOB doesn't provide accurate information about the
93 resource allocation. Hence use pre-defined offsets. Based
94 on ACPI code in create_dsdt_dino_resource(), soc_acpi.c: */
95 resource_t mem64_base, mem64_limit, bus_base, bus_limit;
96
97 /* CPM0 */
98 mem64_base = sr->PciResourceMem64Base;
99 mem64_limit = mem64_base + CPM_MMIO_SIZE - 1;
100 bus_base = sr->BusBase + CPM_BUS_OFFSET;
101 bus_limit = bus_base + CPM_RESERVED_BUS;
Patrick Rudolph8c99ebc2024-01-19 17:28:47 +0100102 create_ioat_domain(path, bus, bus_base, bus_limit, 0, -1, mem64_base, mem64_limit);
Arthur Heymans550f55e2022-08-24 14:44:26 +0200103
104 /* HQM0 */
105 mem64_base = mem64_limit + 1;
106 mem64_limit = mem64_base + HQM_MMIO_SIZE - 1;
107 bus_base = sr->BusBase + HQM_BUS_OFFSET;
108 bus_limit = bus_base + HQM_RESERVED_BUS;
Patrick Rudolph8c99ebc2024-01-19 17:28:47 +0100109 create_ioat_domain(path, bus, bus_base, bus_limit, 0, -1, mem64_base, mem64_limit);
Arthur Heymans550f55e2022-08-24 14:44:26 +0200110
111 /* CPM1 (optional) */
112 mem64_base = mem64_limit + 1;
113 mem64_limit = mem64_base + CPM_MMIO_SIZE - 1;
114 bus_base = sr->BusBase + CPM1_BUS_OFFSET;
115 bus_limit = bus_base + CPM_RESERVED_BUS;
116 if (bus_limit <= sr->BusLimit)
Patrick Rudolph8c99ebc2024-01-19 17:28:47 +0100117 create_ioat_domain(path, bus, bus_base, bus_limit, 0, -1, mem64_base, mem64_limit);
Arthur Heymans550f55e2022-08-24 14:44:26 +0200118
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 Rudolph8c99ebc2024-01-19 17:28:47 +0100125 create_ioat_domain(path, bus, bus_base, bus_limit, 0, -1, mem64_base, mem64_limit);
Arthur Heymans550f55e2022-08-24 14:44:26 +0200126
127 /* DINO */
128 mem64_base = mem64_limit + 1;
129 mem64_limit = sr->PciResourceMem64Limit;
130 bus_base = sr->BusBase;
131 bus_limit = bus_base;
Patrick Rudolph8c99ebc2024-01-19 17:28:47 +0100132 create_ioat_domain(path, bus, bus_base, bus_limit, sr->PciResourceMem32Base, sr->PciResourceMem32Limit,
Arthur Heymans550f55e2022-08-24 14:44:26 +0200133 mem64_base, mem64_limit);
134}