blob: ecb1991caec568d1b34a2bd8e4d5d15de35c2dc8 [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 */
104static void read_resources(struct device *dev)
105{
106 uint32_t mem_usable = (uintptr_t)cbmem_top();
107 unsigned int idx = 0;
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700108
109 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
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700120 /* 0x0 - 0x9ffff */
Arthur Heymansb2de1a32023-07-05 12:15:51 +0200121 ram_range(dev, idx++, 0, 0xa0000);
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700122
123 /* 0xa0000 - 0xbffff: legacy VGA */
Arthur Heymansb2de1a32023-07-05 12:15:51 +0200124 mmio_range(dev, idx++, VGA_MMIO_BASE, VGA_MMIO_SIZE);
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700125
126 /* 0xc0000 - 0xfffff: Option ROM */
Arthur Heymansb2de1a32023-07-05 12:15:51 +0200127 reserved_ram_from_to(dev, idx++, 0xc0000, 1 * MiB);
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700128
129 /* 1MiB - 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);
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -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);
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700134
135 /*
136 * top of DRAM consumed early - low top usable RAM
137 * cbmem_top() accounts for low UMA and TSEG if they are used.
138 */
Arthur Heymansb2de1a32023-07-05 12:15:51 +0200139 ram_from_to(dev, idx++, early_reserved_dram_end, mem_usable);
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700140
Felix Held56b037b2022-03-02 22:57:01 +0100141 mmconf_resource(dev, idx++);
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700142
Felix Held12a44822023-06-02 15:30:50 +0200143 /* Reserve fixed IOMMU MMIO region */
144 mmio_range(dev, idx++, IOMMU_RESERVED_MMIO_BASE, IOMMU_RESERVED_MMIO_SIZE);
145
Felix Held6b248a22023-07-26 16:42:46 +0200146 read_fsp_resources(dev, &idx);
Felix Held1ed5a632021-05-04 21:51:43 +0200147}
148
149static void root_complex_init(struct device *dev)
150{
Kyösti Mälkki2e65e9c2021-06-16 11:00:40 +0300151 register_new_ioapic((u8 *)GNB_IO_APIC_ADDR);
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700152}
153
Felix Helddd882f32021-05-12 01:23:50 +0200154static void acipgen_dptci(void)
155{
156 const struct soc_amd_cezanne_config *config = config_of_soc();
157
Tim Van Patten9eac0972022-09-13 15:34:08 -0600158 /* Normal mode DPTC values. */
Felix Helddd882f32021-05-12 01:23:50 +0200159 struct dptc_input default_input = DPTC_INPUTS(config->thermctl_limit_degreeC,
Tim Van Patten92443582022-08-23 16:06:33 -0600160 config->sustained_power_limit_mW,
161 config->fast_ppt_limit_mW,
162 config->slow_ppt_limit_mW);
163 acpigen_write_alib_dptc_default((uint8_t *)&default_input, sizeof(default_input));
Felix Helddd882f32021-05-12 01:23:50 +0200164}
165
Raul E Rangel0b123dd2021-02-12 15:13:57 -0700166static void root_complex_fill_ssdt(const struct device *device)
167{
Tim Van Patten9eac0972022-09-13 15:34:08 -0600168 if (CONFIG(SOC_AMD_COMMON_BLOCK_ACPI_DPTC))
169 acipgen_dptci();
Raul E Rangel0b123dd2021-02-12 15:13:57 -0700170}
171
Felix Heldb28401302021-02-17 00:05:34 +0100172static const char *gnb_acpi_name(const struct device *dev)
173{
174 return "GNB";
175}
176
Arthur Heymansb65f6092022-10-05 21:45:23 +0200177struct device_operations cezanne_root_complex_operations = {
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700178 .read_resources = read_resources,
179 .set_resources = noop_set_resources,
180 .enable_resources = pci_dev_enable_resources,
Felix Held1ed5a632021-05-04 21:51:43 +0200181 .init = root_complex_init,
Felix Heldb28401302021-02-17 00:05:34 +0100182 .acpi_name = gnb_acpi_name,
Raul E Rangel0b123dd2021-02-12 15:13:57 -0700183 .acpi_fill_ssdt = root_complex_fill_ssdt,
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700184};
Felix Held3b3d8022023-07-18 20:37:04 +0200185
186uint32_t get_iohc_misc_smn_base(struct device *domain)
187{
Felix Held69ffebf2023-07-24 21:31:44 +0200188 return SMN_IOHC_MISC_BASE_13B1;
Felix Held3b3d8022023-07-18 20:37:04 +0200189}
190
191static const struct non_pci_mmio_reg non_pci_mmio[] = {
192 { 0x2d8, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
193 { 0x2e0, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
194 { 0x2e8, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
195 /* The hardware has a 256 byte alignment requirement for the IOAPIC MMIO base, but we
196 tell the FSP to configure a 4k-aligned base address and this is reported as 4 KiB
197 resource. */
198 { 0x2f0, 0xffffffffff00ull, 4 * KiB, IOMMU_IOAPIC_IDX },
199 { 0x2f8, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
200 { 0x300, 0xfffffff00000ull, 1 * MiB, NON_PCI_RES_IDX_AUTO },
201 { 0x308, 0xfffffffff000ull, 4 * KiB, NON_PCI_RES_IDX_AUTO },
202 { 0x318, 0xfffffff80000ull, 512 * KiB, NON_PCI_RES_IDX_AUTO },
203};
204
205const struct non_pci_mmio_reg *get_iohc_non_pci_mmio_regs(size_t *count)
206{
207 *count = ARRAY_SIZE(non_pci_mmio);
208 return non_pci_mmio;
209}