blob: 2e3baa3cb04d2dd24a59111d1d36a966ea26c8d9 [file] [log] [blame]
Arthur Heymans550f55e2022-08-24 14:44:26 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Patrick Rudolphe357ac32024-02-23 09:47:24 +01002#include <acpi/acpigen_pci.h>
Arthur Heymans550f55e2022-08-24 14:44:26 +02003#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,
Shuo Liu255f9272023-03-29 20:14:11 +080028 .write_acpi_tables = northbridge_write_acpi_tables,
Patrick Rudolphe357ac32024-02-23 09:47:24 +010029 .acpi_fill_ssdt = pci_domain_fill_ssdt,
Patrick Rudolph40e07482024-02-23 09:23:41 +010030#endif
Arthur Heymans550f55e2022-08-24 14:44:26 +020031};
32
Patrick Rudolph8c99ebc2024-01-19 17:28:47 +010033static void create_ioat_domain(const union xeon_domain_path dp, struct bus *const upstream,
Arthur Heymans550f55e2022-08-24 14:44:26 +020034 const unsigned int bus_base, const unsigned int bus_limit,
35 const resource_t mem32_base, const resource_t mem32_limit,
Patrick Rudolph40e07482024-02-23 09:23:41 +010036 const resource_t mem64_base, const resource_t mem64_limit,
37 const char *prefix)
Arthur Heymans550f55e2022-08-24 14:44:26 +020038{
Patrick Rudolph8c99ebc2024-01-19 17:28:47 +010039 union xeon_domain_path new_path = {
40 .domain_path = dp.domain_path
41 };
42 new_path.bus = bus_base;
43
Arthur Heymans550f55e2022-08-24 14:44:26 +020044 struct device_path path = {
45 .type = DEVICE_PATH_DOMAIN,
46 .domain = {
Patrick Rudolph8c99ebc2024-01-19 17:28:47 +010047 .domain = new_path.domain_path,
Arthur Heymans550f55e2022-08-24 14:44:26 +020048 },
49 };
Shuo Liu255f9272023-03-29 20:14:11 +080050 struct device *const domain = alloc_find_dev(upstream, &path);
Arthur Heymans550f55e2022-08-24 14:44:26 +020051 if (!domain)
52 die("%s: out of memory.\n", __func__);
53
54 domain->ops = &ioat_domain_ops;
Patrick Rudolph40e07482024-02-23 09:23:41 +010055 iio_domain_set_acpi_name(domain, prefix);
Arthur Heymans550f55e2022-08-24 14:44:26 +020056
Arthur Heymans3e99ba02024-01-25 22:26:07 +010057 struct bus *const bus = alloc_bus(domain);
Arthur Heymans550f55e2022-08-24 14:44:26 +020058 bus->secondary = bus_base;
59 bus->subordinate = bus->secondary;
60 bus->max_subordinate = bus_limit;
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
Patrick Rudolph8c99ebc2024-01-19 17:28:47 +010081void 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 +020082{
Arthur Heymans550f55e2022-08-24 14:44:26 +020083 if (sr->BusLimit < sr->BusBase + HQM_BUS_OFFSET + HQM_RESERVED_BUS) {
84 printk(BIOS_WARNING,
85 "Ignoring IOAT domain with limited bus range.\n");
86 return;
87 }
88
89 if (sr->PciResourceMem64Limit - sr->PciResourceMem64Base + 1
90 < 2 * CPM_MMIO_SIZE + 2 * HQM_MMIO_SIZE) {
91 printk(BIOS_WARNING,
92 "Ignoring IOAT domain with limited 64-bit MMIO window.\n");
93 return;
94 }
95
96 /* The FSP HOB doesn't provide accurate information about the
97 resource allocation. Hence use pre-defined offsets. Based
Shuo Liu08f1f052024-01-20 02:52:17 +080098 on ACPI code in create_dsdt_ioat_resource(), soc_acpi.c: */
Arthur Heymans550f55e2022-08-24 14:44:26 +020099 resource_t mem64_base, mem64_limit, bus_base, bus_limit;
100
101 /* CPM0 */
102 mem64_base = sr->PciResourceMem64Base;
103 mem64_limit = mem64_base + CPM_MMIO_SIZE - 1;
104 bus_base = sr->BusBase + CPM_BUS_OFFSET;
105 bus_limit = bus_base + CPM_RESERVED_BUS;
Patrick Rudolph7d834412024-02-29 18:08:09 +0100106 create_ioat_domain(path, bus, bus_base, bus_limit, -1, 0, mem64_base, mem64_limit,
Patrick Rudolph40e07482024-02-23 09:23:41 +0100107 DOMAIN_TYPE_CPM0);
Arthur Heymans550f55e2022-08-24 14:44:26 +0200108
109 /* HQM0 */
110 mem64_base = mem64_limit + 1;
111 mem64_limit = mem64_base + HQM_MMIO_SIZE - 1;
112 bus_base = sr->BusBase + HQM_BUS_OFFSET;
113 bus_limit = bus_base + HQM_RESERVED_BUS;
Patrick Rudolph7d834412024-02-29 18:08:09 +0100114 create_ioat_domain(path, bus, bus_base, bus_limit, -1, 0, mem64_base, mem64_limit,
Patrick Rudolph40e07482024-02-23 09:23:41 +0100115 DOMAIN_TYPE_HQM0);
Arthur Heymans550f55e2022-08-24 14:44:26 +0200116
117 /* CPM1 (optional) */
118 mem64_base = mem64_limit + 1;
119 mem64_limit = mem64_base + CPM_MMIO_SIZE - 1;
120 bus_base = sr->BusBase + CPM1_BUS_OFFSET;
121 bus_limit = bus_base + CPM_RESERVED_BUS;
122 if (bus_limit <= sr->BusLimit)
Patrick Rudolph7d834412024-02-29 18:08:09 +0100123 create_ioat_domain(path, bus, bus_base, bus_limit, -1, 0, mem64_base, mem64_limit,
Patrick Rudolph40e07482024-02-23 09:23:41 +0100124 DOMAIN_TYPE_CPM1);
Arthur Heymans550f55e2022-08-24 14:44:26 +0200125
126 /* HQM1 (optional) */
127 mem64_base = mem64_limit + 1;
128 mem64_limit = mem64_base + HQM_MMIO_SIZE - 1;
129 bus_base = sr->BusBase + HQM1_BUS_OFFSET;
130 bus_limit = bus_base + HQM_RESERVED_BUS;
131 if (bus_limit <= sr->BusLimit)
Patrick Rudolph7d834412024-02-29 18:08:09 +0100132 create_ioat_domain(path, bus, bus_base, bus_limit, -1, 0, mem64_base, mem64_limit,
Patrick Rudolph40e07482024-02-23 09:23:41 +0100133 DOMAIN_TYPE_HQM1);
Arthur Heymans550f55e2022-08-24 14:44:26 +0200134
135 /* DINO */
136 mem64_base = mem64_limit + 1;
137 mem64_limit = sr->PciResourceMem64Limit;
138 bus_base = sr->BusBase;
139 bus_limit = bus_base;
Patrick Rudolph8c99ebc2024-01-19 17:28:47 +0100140 create_ioat_domain(path, bus, bus_base, bus_limit, sr->PciResourceMem32Base, sr->PciResourceMem32Limit,
Patrick Rudolph40e07482024-02-23 09:23:41 +0100141 mem64_base, mem64_limit, DOMAIN_TYPE_DINO);
Arthur Heymans550f55e2022-08-24 14:44:26 +0200142}