blob: f347dd0cf5f61bf4cc44b59e56294f788c7e5316 [file] [log] [blame]
Marshall Dawsoneb724872019-07-16 15:46:35 -06001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <acpi/acpigen.h>
Raul E Rangel58a8ad12021-02-18 16:36:08 -07004#include <amdblocks/acpi.h>
Felix Held95f1bb82021-05-07 18:46:36 +02005#include <amdblocks/alib.h>
Arthur Heymansce179722023-06-07 15:27:18 +02006#include <amdblocks/data_fabric.h>
Raul E Rangel899be1b2021-02-05 15:50:20 -07007#include <amdblocks/memmap.h>
Felix Held604ffa62021-02-12 00:43:20 +01008#include <amdblocks/ioapic.h>
Felix Held12a44822023-06-02 15:30:50 +02009#include <amdblocks/iomap.h>
Felix Held43662b52023-07-18 20:36:34 +020010#include <amdblocks/root_complex.h>
Felix Heldf9608cd2020-12-03 16:57:02 +010011#include <arch/ioapic.h>
Felix Helda4ced632023-06-05 21:22:15 +020012#include <arch/vga.h>
John Zhaof6f1f732020-06-26 10:00:02 -070013#include <assert.h>
Marshall Dawsoneb724872019-07-16 15:46:35 -060014#include <cbmem.h>
15#include <console/console.h>
Marshall Dawsoneb724872019-07-16 15:46:35 -060016#include <device/device.h>
17#include <device/pci.h>
Marshall Dawsoneb724872019-07-16 15:46:35 -060018#include <stdint.h>
Marshall Dawson39c64b02020-09-04 12:07:27 -060019#include <soc/iomap.h>
Chris Wang4735b1c2020-07-13 23:29:29 +080020#include "chip.h"
Marshall Dawsoneb724872019-07-16 15:46:35 -060021
Felix Heldef511572021-05-07 19:02:45 +020022#define DPTC_TOTAL_UPDATE_PARAMS 4
23
Chris Wang4735b1c2020-07-13 23:29:29 +080024struct dptc_input {
25 uint16_t size;
Felix Heldf0610172021-05-07 19:21:08 +020026 struct alib_dptc_param params[DPTC_TOTAL_UPDATE_PARAMS];
Chris Wang4735b1c2020-07-13 23:29:29 +080027} __packed;
28
Kevin Chiucdd9f5c2020-09-18 17:30:30 +080029#define DPTC_INPUTS(_thermctllmit, _sustained, _fast, _slow) \
Felix Held3acafa22021-05-07 19:17:51 +020030 { \
31 .size = sizeof(struct dptc_input), \
32 .params = { \
33 { \
34 .id = ALIB_DPTC_THERMAL_CONTROL_LIMIT_ID, \
35 .value = _thermctllmit, \
Chris Wang4735b1c2020-07-13 23:29:29 +080036 }, \
Felix Held3acafa22021-05-07 19:17:51 +020037 { \
38 .id = ALIB_DPTC_SUSTAINED_POWER_LIMIT_ID, \
39 .value = _sustained, \
40 }, \
41 { \
42 .id = ALIB_DPTC_FAST_PPT_LIMIT_ID, \
43 .value = _fast, \
44 }, \
45 { \
46 .id = ALIB_DPTC_SLOW_PPT_LIMIT_ID, \
47 .value = _slow, \
48 }, \
49 }, \
50 }
Furquan Shaikhbc456502020-06-10 16:37:23 -070051/*
52 *
53 * +--------------------------------+
54 * | |
55 * | |
56 * | |
57 * | |
58 * | |
59 * | |
60 * | |
61 * reserved_dram_end +--------------------------------+
62 * | |
63 * | verstage (if reqd) |
64 * | (VERSTAGE_SIZE) |
65 * +--------------------------------+ VERSTAGE_ADDR
66 * | |
67 * | FSP-M |
68 * | (FSP_M_SIZE) |
69 * +--------------------------------+ FSP_M_ADDR
Furquan Shaikhbc456502020-06-10 16:37:23 -070070 * | romstage |
71 * | (ROMSTAGE_SIZE) |
Kyösti Mälkkib3621f82020-12-04 19:51:17 +020072 * +--------------------------------+ ROMSTAGE_ADDR = BOOTBLOCK_END
73 * | | X86_RESET_VECTOR = BOOTBLOCK_END - 0x10
Furquan Shaikhbc456502020-06-10 16:37:23 -070074 * | bootblock |
75 * | (C_ENV_BOOTBLOCK_SIZE) |
Kyösti Mälkkib3621f82020-12-04 19:51:17 +020076 * +--------------------------------+ BOOTBLOCK_ADDR = BOOTBLOCK_END - C_ENV_BOOTBLOCK_SIZE
Furquan Shaikhbc456502020-06-10 16:37:23 -070077 * | Unused hole |
78 * | (86KiB) |
79 * +--------------------------------+
80 * | FMAP cache (FMAP_SIZE) |
81 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE + 0x200
82 * | Early Timestamp region (512B) |
83 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE
84 * | Preram CBMEM console |
85 * | (PRERAM_CBMEM_CONSOLE_SIZE) |
86 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE
87 * | PSP shared (vboot workbuf) |
88 * | (PSP_SHAREDMEM_SIZE) |
89 * +--------------------------------+ PSP_SHAREDMEM_BASE
90 * | APOB (64KiB) |
91 * +--------------------------------+ PSP_APOB_DRAM_ADDRESS
92 * | Early BSP stack |
93 * | (EARLYRAM_BSP_STACK_SIZE) |
94 * reserved_dram_start +--------------------------------+ EARLY_RESERVED_DRAM_BASE
95 * | DRAM |
96 * +--------------------------------+ 0x100000
97 * | Option ROM |
98 * +--------------------------------+ 0xc0000
99 * | Legacy VGA |
100 * +--------------------------------+ 0xa0000
101 * | DRAM |
102 * +--------------------------------+ 0x0
103 */
Marshall Dawsoneb724872019-07-16 15:46:35 -0600104static void read_resources(struct device *dev)
105{
106 uint32_t mem_usable = (uintptr_t)cbmem_top();
107 unsigned int idx = 0;
Marshall Dawsoneb724872019-07-16 15:46:35 -0600108
Furquan Shaikhbc456502020-06-10 16:37:23 -0700109 uintptr_t early_reserved_dram_start, early_reserved_dram_end;
110 const struct memmap_early_dram *e = memmap_get_early_dram_usage();
111
112 early_reserved_dram_start = e->base;
113 early_reserved_dram_end = e->base + e->size;
114
Felix Heldaf17f0b2022-03-02 23:36:55 +0100115 /* The root complex has no PCI BARs implemented, so there's no need to call
116 pci_dev_read_resources for it */
117
Felix Heldd0959dc2023-05-10 15:07:47 +0200118 fixed_io_range_reserved(dev, idx++, PCI_IO_CONFIG_INDEX, PCI_IO_CONFIG_PORT_COUNT);
119
Marshall Dawsoneb724872019-07-16 15:46:35 -0600120 /* 0x0 - 0x9ffff */
Arthur Heymansb2de1a32023-07-05 12:15:51 +0200121 ram_range(dev, idx++, 0, 0xa0000);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600122
123 /* 0xa0000 - 0xbffff: legacy VGA */
Arthur Heymansb2de1a32023-07-05 12:15:51 +0200124 mmio_range(dev, idx++, VGA_MMIO_BASE, VGA_MMIO_SIZE);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600125
126 /* 0xc0000 - 0xfffff: Option ROM */
Arthur Heymansb2de1a32023-07-05 12:15:51 +0200127 reserved_ram_from_to(dev, idx++, 0xc0000, 1 * MiB);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600128
Furquan Shaikhbc456502020-06-10 16:37:23 -0700129 /* 1MB - bottom of DRAM reserved for early coreboot usage */
Arthur Heymansb2de1a32023-07-05 12:15:51 +0200130 ram_from_to(dev, idx++, 1 * MiB, early_reserved_dram_start);
Furquan Shaikhbc456502020-06-10 16:37:23 -0700131
132 /* DRAM reserved for early coreboot usage */
Arthur Heymansb2de1a32023-07-05 12:15:51 +0200133 reserved_ram_from_to(dev, idx++, early_reserved_dram_start, early_reserved_dram_end);
Furquan Shaikhbc456502020-06-10 16:37:23 -0700134
135 /* top of DRAM consumed early - low top usable RAM
136 * cbmem_top() accounts for low UMA and TSEG if they are used. */
Arthur Heymansb2de1a32023-07-05 12:15:51 +0200137 ram_from_to(dev, idx++, early_reserved_dram_end, mem_usable);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600138
Felix Held56b037b2022-03-02 22:57:01 +0100139 mmconf_resource(dev, idx++);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600140
Felix Held12a44822023-06-02 15:30:50 +0200141 /* Reserve fixed IOMMU MMIO region */
142 mmio_range(dev, idx++, IOMMU_RESERVED_MMIO_BASE, IOMMU_RESERVED_MMIO_SIZE);
143
Felix Held6b248a22023-07-26 16:42:46 +0200144 read_fsp_resources(dev, &idx);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600145}
146
Felix Heldf9608cd2020-12-03 16:57:02 +0100147static void root_complex_init(struct device *dev)
148{
Kyösti Mälkki2e65e9c2021-06-16 11:00:40 +0300149 register_new_ioapic((u8 *)GNB_IO_APIC_ADDR);
Felix Heldf9608cd2020-12-03 16:57:02 +0100150}
151
Chris Wang4735b1c2020-07-13 23:29:29 +0800152static void acipgen_dptci(void)
153{
Felix Held507fc032020-12-05 01:55:27 +0100154 const struct soc_amd_picasso_config *config = config_of_soc();
Chris Wang4735b1c2020-07-13 23:29:29 +0800155
Tim Van Patten54ce4aa2022-09-13 14:37:32 -0600156 /* Normal mode DPTC values. */
Zheng Bao795d73c2020-10-27 15:36:55 +0800157 struct dptc_input default_input = DPTC_INPUTS(config->thermctl_limit_degreeC,
158 config->sustained_power_limit_mW,
159 config->fast_ppt_limit_mW,
160 config->slow_ppt_limit_mW);
Tim Van Patten92443582022-08-23 16:06:33 -0600161 acpigen_write_alib_dptc_default((uint8_t *)&default_input, sizeof(default_input));
162
163 /* Tablet Mode */
Chris Wang4735b1c2020-07-13 23:29:29 +0800164 struct dptc_input tablet_mode_input = DPTC_INPUTS(
Zheng Bao795d73c2020-10-27 15:36:55 +0800165 config->thermctl_limit_tablet_mode_degreeC,
166 config->sustained_power_limit_tablet_mode_mW,
167 config->fast_ppt_limit_tablet_mode_mW,
168 config->slow_ppt_limit_tablet_mode_mW);
Tim Van Patten92443582022-08-23 16:06:33 -0600169 acpigen_write_alib_dptc_tablet((uint8_t *)&tablet_mode_input,
170 sizeof(tablet_mode_input));
Chris Wang4735b1c2020-07-13 23:29:29 +0800171}
172
Marshall Dawsoneb724872019-07-16 15:46:35 -0600173static void root_complex_fill_ssdt(const struct device *device)
174{
Tim Van Patten54ce4aa2022-09-13 14:37:32 -0600175 if (CONFIG(SOC_AMD_COMMON_BLOCK_ACPI_DPTC))
176 acipgen_dptci();
Marshall Dawsoneb724872019-07-16 15:46:35 -0600177}
178
Felix Heldff092d42021-02-17 00:04:59 +0100179static const char *gnb_acpi_name(const struct device *dev)
180{
181 return "GNB";
182}
183
Arthur Heymans826955d2022-09-20 17:26:30 +0200184struct device_operations picasso_root_complex_operations = {
Marshall Dawsoneb724872019-07-16 15:46:35 -0600185 .read_resources = read_resources,
Felix Held9541d172021-01-05 00:56:10 +0100186 .set_resources = noop_set_resources,
Marshall Dawsoneb724872019-07-16 15:46:35 -0600187 .enable_resources = pci_dev_enable_resources,
Felix Heldf9608cd2020-12-03 16:57:02 +0100188 .init = root_complex_init,
Felix Heldff092d42021-02-17 00:04:59 +0100189 .acpi_name = gnb_acpi_name,
Marshall Dawsoneb724872019-07-16 15:46:35 -0600190 .acpi_fill_ssdt = root_complex_fill_ssdt,
191};
Felix Held43662b52023-07-18 20:36:34 +0200192
193uint32_t get_iohc_misc_smn_base(struct device *domain)
194{
Felix Held69ffebf2023-07-24 21:31:44 +0200195 return SMN_IOHC_MISC_BASE_13B1;
Felix Held43662b52023-07-18 20:36:34 +0200196}
197
198static const struct non_pci_mmio_reg non_pci_mmio[] = {
199 { 0x2e0, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
200 { 0x2e8, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
201 /* The hardware has a 256 byte alignment requirement for the IOAPIC MMIO base, but we
202 tell the FSP to configure a 4k-aligned base address and this is reported as 4 KiB
203 resource. */
204 { 0x2f0, 0xffffffffff00ull, 4 * KiB, IOMMU_IOAPIC_IDX },
205 { 0x2f8, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
206 { 0x300, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
207 { 0x308, 0xfffffffff000ull, 4 * KiB, NON_PCI_RES_IDX_AUTO },
208 { 0x318, 0xfffffff80000ull, 512 * KiB, NON_PCI_RES_IDX_AUTO },
209};
210
211const struct non_pci_mmio_reg *get_iohc_non_pci_mmio_regs(size_t *count)
212{
213 *count = ARRAY_SIZE(non_pci_mmio);
214 return non_pci_mmio;
215}
Felix Heldb0ab5452023-08-11 22:24:00 +0200216
217signed int get_iohc_fabric_id(struct device *domain)
218{
219 switch (domain->path.domain.domain) {
220 case 0:
221 return IOMS0_FABRIC_ID;
222 default:
223 return -1;
224 }
225}