blob: 25867408bc16709aceeea8434d7c0b56e56d98bb [file] [log] [blame]
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -07001/* SPDX-License-Identifier: GPL-2.0-only */
2
Felix Helddd882f32021-05-12 01:23:50 +02003#include <acpi/acpigen.h>
Raul E Rangel0b123dd2021-02-12 15:13:57 -07004#include <amdblocks/acpi.h>
Felix Helddd882f32021-05-12 01:23:50 +02005#include <amdblocks/alib.h>
Arthur Heymansce179722023-06-07 15:27:18 +02006#include <amdblocks/data_fabric.h>
Felix Held1ed5a632021-05-04 21:51:43 +02007#include <amdblocks/ioapic.h>
Felix Held12a44822023-06-02 15:30:50 +02008#include <amdblocks/iomap.h>
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -07009#include <amdblocks/memmap.h>
Felix Held3b3d8022023-07-18 20:37:04 +020010#include <amdblocks/root_complex.h>
Felix Held1ed5a632021-05-04 21:51:43 +020011#include <arch/ioapic.h>
Felix Helda4ced632023-06-05 21:22:15 +020012#include <arch/vga.h>
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -070013#include <cbmem.h>
14#include <console/console.h>
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -070015#include <device/device.h>
16#include <device/pci.h>
Felix Held1ed5a632021-05-04 21:51:43 +020017#include <soc/iomap.h>
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -070018#include <stdint.h>
Felix Helddd882f32021-05-12 01:23:50 +020019#include "chip.h"
20
21#define DPTC_TOTAL_UPDATE_PARAMS 4
22
23struct dptc_input {
24 uint16_t size;
25 struct alib_dptc_param params[DPTC_TOTAL_UPDATE_PARAMS];
26} __packed;
27
28#define DPTC_INPUTS(_thermctllmit, _sustained, _fast, _slow) \
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 }
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -070050
51/*
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
70 * | romstage |
71 * | (ROMSTAGE_SIZE) |
72 * +--------------------------------+ ROMSTAGE_ADDR = BOOTBLOCK_END
73 * | | X86_RESET_VECTOR = BOOTBLOCK_END - 0x10
74 * | bootblock |
75 * | (C_ENV_BOOTBLOCK_SIZE) |
76 * +--------------------------------+ BOOTBLOCK_ADDR = BOOTBLOCK_END - C_ENV_BOOTBLOCK_SIZE
77 * | 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 */
Felix Held30f36c32024-01-30 15:15:31 +0100104void read_soc_memmap_resources(struct device *dev, unsigned long *idx)
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700105{
106 uint32_t mem_usable = (uintptr_t)cbmem_top();
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700107
108 uintptr_t early_reserved_dram_start, early_reserved_dram_end;
109 const struct memmap_early_dram *e = memmap_get_early_dram_usage();
110
111 early_reserved_dram_start = e->base;
112 early_reserved_dram_end = e->base + e->size;
113
Felix Held30f36c32024-01-30 15:15:31 +0100114 fixed_io_range_reserved(dev, (*idx)++, PCI_IO_CONFIG_INDEX, PCI_IO_CONFIG_PORT_COUNT);
Felix Heldd0959dc2023-05-10 15:07:47 +0200115
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700116 /* 0x0 - 0x9ffff */
Felix Held30f36c32024-01-30 15:15:31 +0100117 ram_range(dev, (*idx)++, 0, 0xa0000);
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700118
119 /* 0xa0000 - 0xbffff: legacy VGA */
Felix Held30f36c32024-01-30 15:15:31 +0100120 mmio_range(dev, (*idx)++, VGA_MMIO_BASE, VGA_MMIO_SIZE);
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700121
122 /* 0xc0000 - 0xfffff: Option ROM */
Felix Held30f36c32024-01-30 15:15:31 +0100123 reserved_ram_from_to(dev, (*idx)++, 0xc0000, 1 * MiB);
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700124
125 /* 1MiB - bottom of DRAM reserved for early coreboot usage */
Felix Held30f36c32024-01-30 15:15:31 +0100126 ram_from_to(dev, (*idx)++, 1 * MiB, early_reserved_dram_start);
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700127
128 /* DRAM reserved for early coreboot usage */
Felix Held30f36c32024-01-30 15:15:31 +0100129 reserved_ram_from_to(dev, (*idx)++, early_reserved_dram_start, early_reserved_dram_end);
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700130
131 /*
132 * top of DRAM consumed early - low top usable RAM
133 * cbmem_top() accounts for low UMA and TSEG if they are used.
134 */
Felix Held30f36c32024-01-30 15:15:31 +0100135 ram_from_to(dev, (*idx)++, early_reserved_dram_end, mem_usable);
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700136
Felix Held30f36c32024-01-30 15:15:31 +0100137 mmconf_resource(dev, (*idx)++);
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700138
Felix Held12a44822023-06-02 15:30:50 +0200139 /* Reserve fixed IOMMU MMIO region */
Felix Held30f36c32024-01-30 15:15:31 +0100140 mmio_range(dev, (*idx)++, IOMMU_RESERVED_MMIO_BASE, IOMMU_RESERVED_MMIO_SIZE);
Felix Held12a44822023-06-02 15:30:50 +0200141
Felix Held30f36c32024-01-30 15:15:31 +0100142 read_fsp_resources(dev, idx);
Felix Held1ed5a632021-05-04 21:51:43 +0200143}
144
145static void root_complex_init(struct device *dev)
146{
Kyösti Mälkki2e65e9c2021-06-16 11:00:40 +0300147 register_new_ioapic((u8 *)GNB_IO_APIC_ADDR);
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700148}
149
Felix Helddd882f32021-05-12 01:23:50 +0200150static void acipgen_dptci(void)
151{
152 const struct soc_amd_cezanne_config *config = config_of_soc();
153
Tim Van Patten9eac0972022-09-13 15:34:08 -0600154 /* Normal mode DPTC values. */
Felix Helddd882f32021-05-12 01:23:50 +0200155 struct dptc_input default_input = DPTC_INPUTS(config->thermctl_limit_degreeC,
Tim Van Patten92443582022-08-23 16:06:33 -0600156 config->sustained_power_limit_mW,
157 config->fast_ppt_limit_mW,
158 config->slow_ppt_limit_mW);
159 acpigen_write_alib_dptc_default((uint8_t *)&default_input, sizeof(default_input));
Felix Helddd882f32021-05-12 01:23:50 +0200160}
161
Raul E Rangel0b123dd2021-02-12 15:13:57 -0700162static void root_complex_fill_ssdt(const struct device *device)
163{
Tim Van Patten9eac0972022-09-13 15:34:08 -0600164 if (CONFIG(SOC_AMD_COMMON_BLOCK_ACPI_DPTC))
165 acipgen_dptci();
Raul E Rangel0b123dd2021-02-12 15:13:57 -0700166}
167
Felix Heldb28401302021-02-17 00:05:34 +0100168static const char *gnb_acpi_name(const struct device *dev)
169{
170 return "GNB";
171}
172
Arthur Heymansb65f6092022-10-05 21:45:23 +0200173struct device_operations cezanne_root_complex_operations = {
Felix Held30f36c32024-01-30 15:15:31 +0100174 /* The root complex has no PCI BARs implemented, so there's no need to call
175 pci_dev_read_resources for it */
176 .read_resources = noop_read_resources,
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700177 .set_resources = noop_set_resources,
178 .enable_resources = pci_dev_enable_resources,
Felix Held1ed5a632021-05-04 21:51:43 +0200179 .init = root_complex_init,
Felix Heldb28401302021-02-17 00:05:34 +0100180 .acpi_name = gnb_acpi_name,
Raul E Rangel0b123dd2021-02-12 15:13:57 -0700181 .acpi_fill_ssdt = root_complex_fill_ssdt,
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700182};
Felix Held3b3d8022023-07-18 20:37:04 +0200183
184uint32_t get_iohc_misc_smn_base(struct device *domain)
185{
Felix Held69ffebf2023-07-24 21:31:44 +0200186 return SMN_IOHC_MISC_BASE_13B1;
Felix Held3b3d8022023-07-18 20:37:04 +0200187}
188
189static const struct non_pci_mmio_reg non_pci_mmio[] = {
190 { 0x2d8, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
191 { 0x2e0, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
192 { 0x2e8, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
193 /* The hardware has a 256 byte alignment requirement for the IOAPIC MMIO base, but we
194 tell the FSP to configure a 4k-aligned base address and this is reported as 4 KiB
195 resource. */
196 { 0x2f0, 0xffffffffff00ull, 4 * KiB, IOMMU_IOAPIC_IDX },
197 { 0x2f8, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
198 { 0x300, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
199 { 0x308, 0xfffffffff000ull, 4 * KiB, NON_PCI_RES_IDX_AUTO },
200 { 0x318, 0xfffffff80000ull, 512 * KiB, NON_PCI_RES_IDX_AUTO },
201};
202
203const struct non_pci_mmio_reg *get_iohc_non_pci_mmio_regs(size_t *count)
204{
205 *count = ARRAY_SIZE(non_pci_mmio);
206 return non_pci_mmio;
207}
Felix Heldb0ab5452023-08-11 22:24:00 +0200208
209signed int get_iohc_fabric_id(struct device *domain)
210{
211 switch (domain->path.domain.domain) {
212 case 0:
213 return IOMS0_FABRIC_ID;
214 default:
215 return -1;
216 }
217}