blob: 5528efa6b69d06c77677115f72250d4b2a1c3ec7 [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>
Patrick Rudolph40e07482024-02-23 09:23:41 +010011#include <intelblocks/acpi.h>
12#include <soc/acpi.h>
Arthur Heymans550f55e2022-08-24 14:44:26 +020013#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
22static 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 Rudolph40e07482024-02-23 09:23:41 +010026#if CONFIG(HAVE_ACPI_TABLES)
27 .acpi_name = soc_acpi_name,
28#endif
Arthur Heymans550f55e2022-08-24 14:44:26 +020029};
30
Patrick Rudolph8c99ebc2024-01-19 17:28:47 +010031static void create_ioat_domain(const union xeon_domain_path dp, struct bus *const upstream,
Arthur Heymans550f55e2022-08-24 14:44:26 +020032 const unsigned int bus_base, const unsigned int bus_limit,
33 const resource_t mem32_base, const resource_t mem32_limit,
Patrick Rudolph40e07482024-02-23 09:23:41 +010034 const resource_t mem64_base, const resource_t mem64_limit,
35 const char *prefix)
Arthur Heymans550f55e2022-08-24 14:44:26 +020036{
Patrick Rudolph8c99ebc2024-01-19 17:28:47 +010037 union xeon_domain_path new_path = {
38 .domain_path = dp.domain_path
39 };
40 new_path.bus = bus_base;
41
Arthur Heymans550f55e2022-08-24 14:44:26 +020042 struct device_path path = {
43 .type = DEVICE_PATH_DOMAIN,
44 .domain = {
Patrick Rudolph8c99ebc2024-01-19 17:28:47 +010045 .domain = new_path.domain_path,
Arthur Heymans550f55e2022-08-24 14:44:26 +020046 },
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 Rudolph40e07482024-02-23 09:23:41 +010053 iio_domain_set_acpi_name(domain, prefix);
Arthur Heymans550f55e2022-08-24 14:44:26 +020054
Arthur Heymans3e99ba02024-01-25 22:26:07 +010055 struct bus *const bus = alloc_bus(domain);
Arthur Heymans550f55e2022-08-24 14:44:26 +020056 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 Rudolph8c99ebc2024-01-19 17:28:47 +010079void 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 +020080{
Arthur Heymans550f55e2022-08-24 14:44:26 +020081 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 Liu08f1f052024-01-20 02:52:17 +080096 on ACPI code in create_dsdt_ioat_resource(), soc_acpi.c: */
Arthur Heymans550f55e2022-08-24 14:44:26 +020097 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 Rudolph40e07482024-02-23 09:23:41 +0100104 create_ioat_domain(path, bus, bus_base, bus_limit, 0, -1, mem64_base, mem64_limit,
105 DOMAIN_TYPE_CPM0);
Arthur Heymans550f55e2022-08-24 14:44:26 +0200106
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 Rudolph40e07482024-02-23 09:23:41 +0100112 create_ioat_domain(path, bus, bus_base, bus_limit, 0, -1, mem64_base, mem64_limit,
113 DOMAIN_TYPE_HQM0);
Arthur Heymans550f55e2022-08-24 14:44:26 +0200114
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 Rudolph40e07482024-02-23 09:23:41 +0100121 create_ioat_domain(path, bus, bus_base, bus_limit, 0, -1, mem64_base, mem64_limit,
122 DOMAIN_TYPE_CPM1);
Arthur Heymans550f55e2022-08-24 14:44:26 +0200123
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 Rudolph40e07482024-02-23 09:23:41 +0100130 create_ioat_domain(path, bus, bus_base, bus_limit, 0, -1, mem64_base, mem64_limit,
131 DOMAIN_TYPE_HQM1);
Arthur Heymans550f55e2022-08-24 14:44:26 +0200132
133 /* DINO */
134 mem64_base = mem64_limit + 1;
135 mem64_limit = sr->PciResourceMem64Limit;
136 bus_base = sr->BusBase;
137 bus_limit = bus_base;
Patrick Rudolph8c99ebc2024-01-19 17:28:47 +0100138 create_ioat_domain(path, bus, bus_base, bus_limit, sr->PciResourceMem32Base, sr->PciResourceMem32Limit,
Patrick Rudolph40e07482024-02-23 09:23:41 +0100139 mem64_base, mem64_limit, DOMAIN_TYPE_DINO);
Arthur Heymans550f55e2022-08-24 14:44:26 +0200140}