blob: f10863a607689601d5165f811d037f3479d381ab [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;
48 bus->secondary = bus_base;
49 bus->subordinate = bus->secondary;
50 bus->max_subordinate = bus_limit;
51
52 unsigned int index = 0;
53
54 if (mem32_base <= mem32_limit) {
55 struct resource *const res = new_resource(domain, index++);
56 res->base = mem32_base;
57 res->limit = mem32_limit;
58 res->size = res->limit - res->base + 1;
59 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED;
60 }
61
62 if (mem64_base <= mem64_limit) {
63 struct resource *const res = new_resource(domain, index++);
64 res->base = mem64_base;
65 res->limit = mem64_limit;
66 res->size = res->limit - res->base + 1;
67 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED;
68 }
69}
70
71void soc_create_ioat_domains(struct bus *const bus, const STACK_RES *const sr)
72{
73 const unsigned int domain_base = MAX_SOCKET * MAX_LOGIC_IIO_STACK;
74
75 if (sr->BusLimit < sr->BusBase + HQM_BUS_OFFSET + HQM_RESERVED_BUS) {
76 printk(BIOS_WARNING,
77 "Ignoring IOAT domain with limited bus range.\n");
78 return;
79 }
80
81 if (sr->PciResourceMem64Limit - sr->PciResourceMem64Base + 1
82 < 2 * CPM_MMIO_SIZE + 2 * HQM_MMIO_SIZE) {
83 printk(BIOS_WARNING,
84 "Ignoring IOAT domain with limited 64-bit MMIO window.\n");
85 return;
86 }
87
88 /* The FSP HOB doesn't provide accurate information about the
89 resource allocation. Hence use pre-defined offsets. Based
90 on ACPI code in create_dsdt_dino_resource(), soc_acpi.c: */
91 resource_t mem64_base, mem64_limit, bus_base, bus_limit;
92
93 /* CPM0 */
94 mem64_base = sr->PciResourceMem64Base;
95 mem64_limit = mem64_base + CPM_MMIO_SIZE - 1;
96 bus_base = sr->BusBase + CPM_BUS_OFFSET;
97 bus_limit = bus_base + CPM_RESERVED_BUS;
98 create_ioat_domain(bus, domain_base, bus_base, bus_limit, 0, -1, mem64_base, mem64_limit);
99
100 /* HQM0 */
101 mem64_base = mem64_limit + 1;
102 mem64_limit = mem64_base + HQM_MMIO_SIZE - 1;
103 bus_base = sr->BusBase + HQM_BUS_OFFSET;
104 bus_limit = bus_base + HQM_RESERVED_BUS;
105 create_ioat_domain(bus, domain_base, bus_base, bus_limit, 0, -1, mem64_base, mem64_limit);
106
107 /* CPM1 (optional) */
108 mem64_base = mem64_limit + 1;
109 mem64_limit = mem64_base + CPM_MMIO_SIZE - 1;
110 bus_base = sr->BusBase + CPM1_BUS_OFFSET;
111 bus_limit = bus_base + CPM_RESERVED_BUS;
112 if (bus_limit <= sr->BusLimit)
113 create_ioat_domain(bus, domain_base, bus_base, bus_limit, 0, -1, mem64_base, mem64_limit);
114
115 /* HQM1 (optional) */
116 mem64_base = mem64_limit + 1;
117 mem64_limit = mem64_base + HQM_MMIO_SIZE - 1;
118 bus_base = sr->BusBase + HQM1_BUS_OFFSET;
119 bus_limit = bus_base + HQM_RESERVED_BUS;
120 if (bus_limit <= sr->BusLimit)
121 create_ioat_domain(bus, domain_base, bus_base, bus_limit, 0, -1, mem64_base, mem64_limit);
122
123 /* DINO */
124 mem64_base = mem64_limit + 1;
125 mem64_limit = sr->PciResourceMem64Limit;
126 bus_base = sr->BusBase;
127 bus_limit = bus_base;
128 create_ioat_domain(bus, domain_base, bus_base, bus_limit, sr->PciResourceMem32Base, sr->PciResourceMem32Limit,
129 mem64_base, mem64_limit);
130}