blob: 9cb758a4cc8ce1d1d141e5141d886fca3963dbb6 [file] [log] [blame]
Martin Rothf95a11e2022-10-21 16:43:08 -06001/* SPDX-License-Identifier: GPL-2.0-only */
2
3/* TODO: Update for Glinda */
4
5#include <acpi/acpigen.h>
6#include <amdblocks/acpi.h>
7#include <amdblocks/alib.h>
8#include <amdblocks/ioapic.h>
9#include <amdblocks/memmap.h>
10#include <arch/ioapic.h>
11#include <cbmem.h>
12#include <console/console.h>
Martin Rothf95a11e2022-10-21 16:43:08 -060013#include <device/device.h>
14#include <device/pci.h>
15#include <fsp/util.h>
16#include <soc/iomap.h>
17#include <stdint.h>
18#include "chip.h"
19
20#define DPTC_TOTAL_UPDATE_PARAMS 7
21
22struct dptc_input {
23 uint16_t size;
24 struct alib_dptc_param params[DPTC_TOTAL_UPDATE_PARAMS];
25} __packed;
26
27#define DPTC_INPUTS(_thermctllmit, _sustained, _fast, _slow, \
28 _vrmCurrentLimit, _vrmMaxCurrentLimit, _vrmSocCurrentLimit) \
29 { \
30 .size = sizeof(struct dptc_input), \
31 .params = { \
32 { \
33 .id = ALIB_DPTC_THERMAL_CONTROL_LIMIT_ID, \
34 .value = _thermctllmit, \
35 }, \
36 { \
37 .id = ALIB_DPTC_SUSTAINED_POWER_LIMIT_ID, \
38 .value = _sustained, \
39 }, \
40 { \
41 .id = ALIB_DPTC_FAST_PPT_LIMIT_ID, \
42 .value = _fast, \
43 }, \
44 { \
45 .id = ALIB_DPTC_SLOW_PPT_LIMIT_ID, \
46 .value = _slow, \
47 }, \
48 { \
49 .id = ALIB_DPTC_VRM_CURRENT_LIMIT_ID, \
50 .value = _vrmCurrentLimit, \
51 }, \
52 { \
53 .id = ALIB_DPTC_VRM_MAXIMUM_CURRENT_LIMIT, \
54 .value = _vrmMaxCurrentLimit, \
55 }, \
56 { \
57 .id = ALIB_DPTC_VRM_SOC_CURRENT_LIMIT_ID, \
58 .value = _vrmSocCurrentLimit, \
59 }, \
60 }, \
61 }
62
63/*
64 *
65 * +--------------------------------+
66 * | |
67 * | |
68 * | |
69 * | |
70 * | |
71 * | |
72 * | |
73 * reserved_dram_end +--------------------------------+
74 * | |
75 * | verstage (if reqd) |
76 * | (VERSTAGE_SIZE) |
77 * +--------------------------------+ VERSTAGE_ADDR
78 * | |
79 * | FSP-M |
80 * | (FSP_M_SIZE) |
81 * +--------------------------------+ FSP_M_ADDR
82 * | romstage |
83 * | (ROMSTAGE_SIZE) |
84 * +--------------------------------+ ROMSTAGE_ADDR = BOOTBLOCK_END
85 * | | X86_RESET_VECTOR = BOOTBLOCK_END - 0x10
86 * | bootblock |
87 * | (C_ENV_BOOTBLOCK_SIZE) |
88 * +--------------------------------+ BOOTBLOCK_ADDR = BOOTBLOCK_END - C_ENV_BOOTBLOCK_SIZE
89 * | Unused hole |
90 * | (30KiB) |
91 * +--------------------------------+
92 * | FMAP cache (FMAP_SIZE) |
93 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE + 0x200
94 * | Early Timestamp region (512B) |
95 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE
96 * | Preram CBMEM console |
97 * | (PRERAM_CBMEM_CONSOLE_SIZE) |
98 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE
99 * | PSP shared (vboot workbuf) |
100 * | (PSP_SHAREDMEM_SIZE) |
101 * +--------------------------------+ PSP_SHAREDMEM_BASE
102 * | APOB (120KiB) |
103 * +--------------------------------+ PSP_APOB_DRAM_ADDRESS
104 * | Early BSP stack |
105 * | (EARLYRAM_BSP_STACK_SIZE) |
106 * reserved_dram_start +--------------------------------+ EARLY_RESERVED_DRAM_BASE
107 * | DRAM |
108 * +--------------------------------+ 0x100000
109 * | Option ROM |
110 * +--------------------------------+ 0xc0000
111 * | Legacy VGA |
112 * +--------------------------------+ 0xa0000
113 * | DRAM |
114 * +--------------------------------+ 0x0
115 */
116static void read_resources(struct device *dev)
117{
118 uint32_t mem_usable = (uintptr_t)cbmem_top();
119 unsigned int idx = 0;
Felix Held2e814362022-11-10 22:44:18 +0100120 const struct hob_header *hob_iterator;
Martin Rothf95a11e2022-10-21 16:43:08 -0600121 const struct hob_resource *res;
122 struct resource *gnb_apic;
123
124 uintptr_t early_reserved_dram_start, early_reserved_dram_end;
125 const struct memmap_early_dram *e = memmap_get_early_dram_usage();
126
127 early_reserved_dram_start = e->base;
128 early_reserved_dram_end = e->base + e->size;
129
130 /* The root complex has no PCI BARs implemented, so there's no need to call
131 pci_dev_read_resources for it */
132
Felix Heldd0959dc2023-05-10 15:07:47 +0200133 fixed_io_range_reserved(dev, idx++, PCI_IO_CONFIG_INDEX, PCI_IO_CONFIG_PORT_COUNT);
134
Martin Rothf95a11e2022-10-21 16:43:08 -0600135 /* 0x0 - 0x9ffff */
136 ram_resource_kb(dev, idx++, 0, 0xa0000 / KiB);
137
138 /* 0xa0000 - 0xbffff: legacy VGA */
139 mmio_resource_kb(dev, idx++, 0xa0000 / KiB, 0x20000 / KiB);
140
141 /* 0xc0000 - 0xfffff: Option ROM */
142 reserved_ram_resource_kb(dev, idx++, 0xc0000 / KiB, 0x40000 / KiB);
143
144 /* 1MiB - bottom of DRAM reserved for early coreboot usage */
145 ram_resource_kb(dev, idx++, (1 * MiB) / KiB,
146 (early_reserved_dram_start - (1 * MiB)) / KiB);
147
148 /* DRAM reserved for early coreboot usage */
149 reserved_ram_resource_kb(dev, idx++, early_reserved_dram_start / KiB,
150 (early_reserved_dram_end - early_reserved_dram_start) / KiB);
151
152 /*
153 * top of DRAM consumed early - low top usable RAM
154 * cbmem_top() accounts for low UMA and TSEG if they are used.
155 */
156 ram_resource_kb(dev, idx++, early_reserved_dram_end / KiB,
157 (mem_usable - early_reserved_dram_end) / KiB);
158
159 mmconf_resource(dev, idx++);
160
Felix Helddafc6192022-11-10 18:19:36 +0100161 /* GNB IOAPIC resource */
162 gnb_apic = new_resource(dev, idx++);
163 gnb_apic->base = GNB_IO_APIC_ADDR;
164 gnb_apic->size = 0x00001000;
165 gnb_apic->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
166
Felix Held2e814362022-11-10 22:44:18 +0100167 if (fsp_hob_iterator_init(&hob_iterator) != CB_SUCCESS) {
Elyes Haouasaba1c942022-11-09 15:05:23 +0100168 printk(BIOS_ERR, "%s incomplete because no HOB list was found\n",
Martin Rothf95a11e2022-10-21 16:43:08 -0600169 __func__);
170 return;
171 }
172
Felix Held2e814362022-11-10 22:44:18 +0100173 while (fsp_hob_iterator_get_next_resource(&hob_iterator, &res) == CB_SUCCESS) {
Martin Rothf95a11e2022-10-21 16:43:08 -0600174 if (res->type == EFI_RESOURCE_SYSTEM_MEMORY && res->addr < mem_usable)
175 continue; /* 0 through low usable was set above */
176 if (res->type == EFI_RESOURCE_MEMORY_MAPPED_IO)
177 continue; /* Done separately */
178
179 if (res->type == EFI_RESOURCE_SYSTEM_MEMORY)
180 ram_resource_kb(dev, idx++, res->addr / KiB, res->length / KiB);
181 else if (res->type == EFI_RESOURCE_MEMORY_RESERVED)
182 reserved_ram_resource_kb(dev, idx++, res->addr / KiB, res->length / KiB);
183 else
Elyes Haouasaba1c942022-11-09 15:05:23 +0100184 printk(BIOS_ERR, "Failed to set resources for type %d\n",
Martin Rothf95a11e2022-10-21 16:43:08 -0600185 res->type);
186 }
Martin Rothf95a11e2022-10-21 16:43:08 -0600187}
188
189static void root_complex_init(struct device *dev)
190{
Kyösti Mälkki2e65e9c2021-06-16 11:00:40 +0300191 register_new_ioapic((u8 *)GNB_IO_APIC_ADDR);
Martin Rothf95a11e2022-10-21 16:43:08 -0600192}
193
194static void acipgen_dptci(void)
195{
196 const struct soc_amd_glinda_config *config = config_of_soc();
197
198 /* Normal mode DPTC values. */
199 struct dptc_input default_input = DPTC_INPUTS(config->thermctl_limit_degreeC,
200 config->sustained_power_limit_mW,
201 config->fast_ppt_limit_mW,
202 config->slow_ppt_limit_mW,
203 config->vrm_current_limit_mA,
204 config->vrm_maximum_current_limit_mA,
205 config->vrm_soc_current_limit_mA);
206 acpigen_write_alib_dptc_default((uint8_t *)&default_input, sizeof(default_input));
207
208 /* Low/No Battery */
209 struct dptc_input no_battery_input = DPTC_INPUTS(
210 config->thermctl_limit_degreeC,
211 config->sustained_power_limit_mW,
212 config->fast_ppt_limit_mW,
213 config->slow_ppt_limit_mW,
214 config->vrm_current_limit_throttle_mA,
215 config->vrm_maximum_current_limit_throttle_mA,
216 config->vrm_soc_current_limit_throttle_mA);
217 acpigen_write_alib_dptc_no_battery((uint8_t *)&no_battery_input,
218 sizeof(no_battery_input));
219}
220
221static void root_complex_fill_ssdt(const struct device *device)
222{
223 acpi_fill_root_complex_tom(device);
224 if (CONFIG(SOC_AMD_COMMON_BLOCK_ACPI_DPTC))
225 acipgen_dptci();
226}
227
228static const char *gnb_acpi_name(const struct device *dev)
229{
230 return "GNB";
231}
232
233struct device_operations glinda_root_complex_operations = {
234 .read_resources = read_resources,
235 .set_resources = noop_set_resources,
236 .enable_resources = pci_dev_enable_resources,
237 .init = root_complex_init,
238 .acpi_name = gnb_acpi_name,
239 .acpi_fill_ssdt = root_complex_fill_ssdt,
240};