blob: 38bbd93199bfcc2e72916d947cdc9873640cbe38 [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
26static void create_ioat_domain(struct bus *const upstream, const unsigned int domain_base,
27 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{
31 struct device_path path = {
32 .type = DEVICE_PATH_DOMAIN,
33 .domain = {
34 .domain = domain_base + bus_base,
35 },
36 };
37 struct device *const domain = alloc_dev(upstream, &path);
38 if (!domain)
39 die("%s: out of memory.\n", __func__);
40
41 domain->ops = &ioat_domain_ops;
42
43 domain->link_list = calloc(1, sizeof(struct bus));
44 if (!domain->link_list)
45 die("%s: out of memory.\n", __func__);
46
47 struct bus *const bus = domain->link_list;
Patrick Rudolphee0a2f92024-01-19 08:27:13 +010048 bus->dev = domain;
Arthur Heymans550f55e2022-08-24 14:44:26 +020049 bus->secondary = bus_base;
50 bus->subordinate = bus->secondary;
51 bus->max_subordinate = bus_limit;
52
53 unsigned int index = 0;
54
55 if (mem32_base <= mem32_limit) {
56 struct resource *const res = new_resource(domain, index++);
57 res->base = mem32_base;
58 res->limit = mem32_limit;
59 res->size = res->limit - res->base + 1;
60 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED;
61 }
62
63 if (mem64_base <= mem64_limit) {
64 struct resource *const res = new_resource(domain, index++);
65 res->base = mem64_base;
66 res->limit = mem64_limit;
67 res->size = res->limit - res->base + 1;
68 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED;
69 }
70}
71
72void soc_create_ioat_domains(struct bus *const bus, const STACK_RES *const sr)
73{
74 const unsigned int domain_base = MAX_SOCKET * MAX_LOGIC_IIO_STACK;
75
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
91 on ACPI code in create_dsdt_dino_resource(), soc_acpi.c: */
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;
99 create_ioat_domain(bus, domain_base, bus_base, bus_limit, 0, -1, mem64_base, mem64_limit);
100
101 /* HQM0 */
102 mem64_base = mem64_limit + 1;
103 mem64_limit = mem64_base + HQM_MMIO_SIZE - 1;
104 bus_base = sr->BusBase + HQM_BUS_OFFSET;
105 bus_limit = bus_base + HQM_RESERVED_BUS;
106 create_ioat_domain(bus, domain_base, bus_base, bus_limit, 0, -1, mem64_base, mem64_limit);
107
108 /* CPM1 (optional) */
109 mem64_base = mem64_limit + 1;
110 mem64_limit = mem64_base + CPM_MMIO_SIZE - 1;
111 bus_base = sr->BusBase + CPM1_BUS_OFFSET;
112 bus_limit = bus_base + CPM_RESERVED_BUS;
113 if (bus_limit <= sr->BusLimit)
114 create_ioat_domain(bus, domain_base, bus_base, bus_limit, 0, -1, mem64_base, mem64_limit);
115
116 /* HQM1 (optional) */
117 mem64_base = mem64_limit + 1;
118 mem64_limit = mem64_base + HQM_MMIO_SIZE - 1;
119 bus_base = sr->BusBase + HQM1_BUS_OFFSET;
120 bus_limit = bus_base + HQM_RESERVED_BUS;
121 if (bus_limit <= sr->BusLimit)
122 create_ioat_domain(bus, domain_base, bus_base, bus_limit, 0, -1, mem64_base, mem64_limit);
123
124 /* DINO */
125 mem64_base = mem64_limit + 1;
126 mem64_limit = sr->PciResourceMem64Limit;
127 bus_base = sr->BusBase;
128 bus_limit = bus_base;
129 create_ioat_domain(bus, domain_base, bus_base, bus_limit, sr->PciResourceMem32Base, sr->PciResourceMem32Limit,
130 mem64_base, mem64_limit);
131}