blob: ba263d53297aa3ad2b8e19fa49cad87f749d18f0 [file] [log] [blame]
Martin Roth1a3de8e2022-10-06 15:57:21 -06001/* SPDX-License-Identifier: GPL-2.0-only */
2
Martin Roth20646cd2023-01-04 21:27:06 -07003/* TODO: Update for Phoenix */
Martin Roth1a3de8e2022-10-06 15:57:21 -06004
5#include <acpi/acpigen.h>
6#include <amdblocks/acpi.h>
7#include <amdblocks/alib.h>
Arthur Heymansce179722023-06-07 15:27:18 +02008#include <amdblocks/data_fabric.h>
Martin Roth1a3de8e2022-10-06 15:57:21 -06009#include <amdblocks/ioapic.h>
Felix Held12a44822023-06-02 15:30:50 +020010#include <amdblocks/iomap.h>
Martin Roth1a3de8e2022-10-06 15:57:21 -060011#include <amdblocks/memmap.h>
Felix Helde0850ad2023-07-18 20:37:50 +020012#include <amdblocks/root_complex.h>
Martin Roth1a3de8e2022-10-06 15:57:21 -060013#include <arch/ioapic.h>
Felix Helda4ced632023-06-05 21:22:15 +020014#include <arch/vga.h>
Martin Roth1a3de8e2022-10-06 15:57:21 -060015#include <cbmem.h>
16#include <console/console.h>
Martin Roth1a3de8e2022-10-06 15:57:21 -060017#include <device/device.h>
18#include <device/pci.h>
Martin Roth1a3de8e2022-10-06 15:57:21 -060019#include <soc/iomap.h>
20#include <stdint.h>
21#include "chip.h"
22
23#define DPTC_TOTAL_UPDATE_PARAMS 7
24
25struct dptc_input {
26 uint16_t size;
27 struct alib_dptc_param params[DPTC_TOTAL_UPDATE_PARAMS];
28} __packed;
29
30#define DPTC_INPUTS(_thermctllmit, _sustained, _fast, _slow, \
31 _vrmCurrentLimit, _vrmMaxCurrentLimit, _vrmSocCurrentLimit) \
32 { \
33 .size = sizeof(struct dptc_input), \
34 .params = { \
35 { \
36 .id = ALIB_DPTC_THERMAL_CONTROL_LIMIT_ID, \
37 .value = _thermctllmit, \
38 }, \
39 { \
40 .id = ALIB_DPTC_SUSTAINED_POWER_LIMIT_ID, \
41 .value = _sustained, \
42 }, \
43 { \
44 .id = ALIB_DPTC_FAST_PPT_LIMIT_ID, \
45 .value = _fast, \
46 }, \
47 { \
48 .id = ALIB_DPTC_SLOW_PPT_LIMIT_ID, \
49 .value = _slow, \
50 }, \
51 { \
52 .id = ALIB_DPTC_VRM_CURRENT_LIMIT_ID, \
53 .value = _vrmCurrentLimit, \
54 }, \
55 { \
56 .id = ALIB_DPTC_VRM_MAXIMUM_CURRENT_LIMIT, \
57 .value = _vrmMaxCurrentLimit, \
58 }, \
59 { \
60 .id = ALIB_DPTC_VRM_SOC_CURRENT_LIMIT_ID, \
61 .value = _vrmSocCurrentLimit, \
62 }, \
63 }, \
64 }
65
66/*
67 *
68 * +--------------------------------+
69 * | |
70 * | |
71 * | |
72 * | |
73 * | |
74 * | |
75 * | |
76 * reserved_dram_end +--------------------------------+
77 * | |
78 * | verstage (if reqd) |
79 * | (VERSTAGE_SIZE) |
80 * +--------------------------------+ VERSTAGE_ADDR
81 * | |
82 * | FSP-M |
83 * | (FSP_M_SIZE) |
84 * +--------------------------------+ FSP_M_ADDR
85 * | romstage |
86 * | (ROMSTAGE_SIZE) |
87 * +--------------------------------+ ROMSTAGE_ADDR = BOOTBLOCK_END
88 * | | X86_RESET_VECTOR = BOOTBLOCK_END - 0x10
89 * | bootblock |
90 * | (C_ENV_BOOTBLOCK_SIZE) |
91 * +--------------------------------+ BOOTBLOCK_ADDR = BOOTBLOCK_END - C_ENV_BOOTBLOCK_SIZE
92 * | Unused hole |
93 * | (30KiB) |
94 * +--------------------------------+
95 * | FMAP cache (FMAP_SIZE) |
96 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE + 0x200
97 * | Early Timestamp region (512B) |
98 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE
99 * | Preram CBMEM console |
100 * | (PRERAM_CBMEM_CONSOLE_SIZE) |
101 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE
102 * | PSP shared (vboot workbuf) |
103 * | (PSP_SHAREDMEM_SIZE) |
104 * +--------------------------------+ PSP_SHAREDMEM_BASE
105 * | APOB (120KiB) |
106 * +--------------------------------+ PSP_APOB_DRAM_ADDRESS
107 * | Early BSP stack |
108 * | (EARLYRAM_BSP_STACK_SIZE) |
109 * reserved_dram_start +--------------------------------+ EARLY_RESERVED_DRAM_BASE
110 * | DRAM |
111 * +--------------------------------+ 0x100000
112 * | Option ROM |
113 * +--------------------------------+ 0xc0000
114 * | Legacy VGA |
115 * +--------------------------------+ 0xa0000
116 * | DRAM |
117 * +--------------------------------+ 0x0
118 */
119static void read_resources(struct device *dev)
120{
121 uint32_t mem_usable = (uintptr_t)cbmem_top();
122 unsigned int idx = 0;
Martin Roth1a3de8e2022-10-06 15:57:21 -0600123
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 Roth1a3de8e2022-10-06 15:57:21 -0600135 /* 0x0 - 0x9ffff */
Arthur Heymansb2de1a32023-07-05 12:15:51 +0200136 ram_range(dev, idx++, 0, 0xa0000);
Martin Roth1a3de8e2022-10-06 15:57:21 -0600137
138 /* 0xa0000 - 0xbffff: legacy VGA */
Arthur Heymansb2de1a32023-07-05 12:15:51 +0200139 mmio_range(dev, idx++, VGA_MMIO_BASE, VGA_MMIO_SIZE);
Martin Roth1a3de8e2022-10-06 15:57:21 -0600140
141 /* 0xc0000 - 0xfffff: Option ROM */
Arthur Heymansb2de1a32023-07-05 12:15:51 +0200142 reserved_ram_from_to(dev, idx++, 0xc0000, 1 * MiB);
Martin Roth1a3de8e2022-10-06 15:57:21 -0600143
144 /* 1MiB - bottom of DRAM reserved for early coreboot usage */
Arthur Heymansb2de1a32023-07-05 12:15:51 +0200145 ram_from_to(dev, idx++, 1 * MiB, early_reserved_dram_start);
Martin Roth1a3de8e2022-10-06 15:57:21 -0600146
147 /* DRAM reserved for early coreboot usage */
Arthur Heymansb2de1a32023-07-05 12:15:51 +0200148 reserved_ram_from_to(dev, idx++, early_reserved_dram_start, early_reserved_dram_end);
Martin Roth1a3de8e2022-10-06 15:57:21 -0600149
150 /*
151 * top of DRAM consumed early - low top usable RAM
152 * cbmem_top() accounts for low UMA and TSEG if they are used.
153 */
Arthur Heymansb2de1a32023-07-05 12:15:51 +0200154 ram_from_to(dev, idx++, early_reserved_dram_end, mem_usable);
Martin Roth1a3de8e2022-10-06 15:57:21 -0600155
156 mmconf_resource(dev, idx++);
157
Felix Held12a44822023-06-02 15:30:50 +0200158 /* Reserve fixed IOMMU MMIO region */
159 mmio_range(dev, idx++, IOMMU_RESERVED_MMIO_BASE, IOMMU_RESERVED_MMIO_SIZE);
160
Felix Held6b248a22023-07-26 16:42:46 +0200161 read_fsp_resources(dev, &idx);
Martin Roth1a3de8e2022-10-06 15:57:21 -0600162}
163
164static void root_complex_init(struct device *dev)
165{
Kyösti Mälkki2e65e9c2021-06-16 11:00:40 +0300166 register_new_ioapic((u8 *)GNB_IO_APIC_ADDR);
Martin Roth1a3de8e2022-10-06 15:57:21 -0600167}
168
169static void acipgen_dptci(void)
170{
Martin Roth20646cd2023-01-04 21:27:06 -0700171 const struct soc_amd_phoenix_config *config = config_of_soc();
Martin Roth1a3de8e2022-10-06 15:57:21 -0600172
173 /* Normal mode DPTC values. */
174 struct dptc_input default_input = DPTC_INPUTS(config->thermctl_limit_degreeC,
175 config->sustained_power_limit_mW,
176 config->fast_ppt_limit_mW,
177 config->slow_ppt_limit_mW,
178 config->vrm_current_limit_mA,
179 config->vrm_maximum_current_limit_mA,
180 config->vrm_soc_current_limit_mA);
181 acpigen_write_alib_dptc_default((uint8_t *)&default_input, sizeof(default_input));
182
183 /* Low/No Battery */
184 struct dptc_input no_battery_input = DPTC_INPUTS(
185 config->thermctl_limit_degreeC,
186 config->sustained_power_limit_mW,
187 config->fast_ppt_limit_mW,
188 config->slow_ppt_limit_mW,
189 config->vrm_current_limit_throttle_mA,
190 config->vrm_maximum_current_limit_throttle_mA,
191 config->vrm_soc_current_limit_throttle_mA);
192 acpigen_write_alib_dptc_no_battery((uint8_t *)&no_battery_input,
193 sizeof(no_battery_input));
194}
195
196static void root_complex_fill_ssdt(const struct device *device)
197{
Martin Roth1a3de8e2022-10-06 15:57:21 -0600198 if (CONFIG(SOC_AMD_COMMON_BLOCK_ACPI_DPTC))
199 acipgen_dptci();
200}
201
202static const char *gnb_acpi_name(const struct device *dev)
203{
204 return "GNB";
205}
206
Martin Roth20646cd2023-01-04 21:27:06 -0700207struct device_operations phoenix_root_complex_operations = {
Martin Roth1a3de8e2022-10-06 15:57:21 -0600208 .read_resources = read_resources,
209 .set_resources = noop_set_resources,
210 .enable_resources = pci_dev_enable_resources,
211 .init = root_complex_init,
212 .acpi_name = gnb_acpi_name,
213 .acpi_fill_ssdt = root_complex_fill_ssdt,
214};
Felix Helde0850ad2023-07-18 20:37:50 +0200215
216uint32_t get_iohc_misc_smn_base(struct device *domain)
217{
Felix Held69ffebf2023-07-24 21:31:44 +0200218 return SMN_IOHC_MISC_BASE_13B1;
Felix Helde0850ad2023-07-18 20:37:50 +0200219}
220
221static const struct non_pci_mmio_reg non_pci_mmio[] = {
222 { 0x2d0, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
223 { 0x2d8, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
224 { 0x2e0, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
225 { 0x2e8, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
226 /* The hardware has a 256 byte alignment requirement for the IOAPIC MMIO base, but we
227 tell the FSP to configure a 4k-aligned base address and this is reported as 4 KiB
228 resource. */
229 { 0x2f0, 0xffffffffff00ull, 4 * KiB, IOMMU_IOAPIC_IDX },
230 { 0x2f8, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
231 { 0x300, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
232 { 0x308, 0xfffffffff000ull, 4 * KiB, NON_PCI_RES_IDX_AUTO },
233 { 0x310, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
234 { 0x318, 0xfffffff80000ull, 512 * KiB, NON_PCI_RES_IDX_AUTO },
235 { 0x320, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
236};
237
238const struct non_pci_mmio_reg *get_iohc_non_pci_mmio_regs(size_t *count)
239{
240 *count = ARRAY_SIZE(non_pci_mmio);
241 return non_pci_mmio;
242}
Felix Heldb0ab5452023-08-11 22:24:00 +0200243
244signed int get_iohc_fabric_id(struct device *domain)
245{
246 switch (domain->path.domain.domain) {
247 case 0:
248 return IOMS0_FABRIC_ID;
249 default:
250 return -1;
251 }
252}