blob: cb35662af7209ef17e2710c521870dcd0b178cfd [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>
Felix Held1ed5a632021-05-04 21:51:43 +02006#include <amdblocks/ioapic.h>
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -07007#include <amdblocks/memmap.h>
Felix Held1ed5a632021-05-04 21:51:43 +02008#include <arch/ioapic.h>
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -07009#include <cbmem.h>
10#include <console/console.h>
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -070011#include <device/device.h>
12#include <device/pci.h>
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -070013#include <fsp/util.h>
Felix Held1ed5a632021-05-04 21:51:43 +020014#include <soc/iomap.h>
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -070015#include <stdint.h>
Felix Helddd882f32021-05-12 01:23:50 +020016#include "chip.h"
17
18#define DPTC_TOTAL_UPDATE_PARAMS 4
19
20struct dptc_input {
21 uint16_t size;
22 struct alib_dptc_param params[DPTC_TOTAL_UPDATE_PARAMS];
23} __packed;
24
25#define DPTC_INPUTS(_thermctllmit, _sustained, _fast, _slow) \
26 { \
27 .size = sizeof(struct dptc_input), \
28 .params = { \
29 { \
30 .id = ALIB_DPTC_THERMAL_CONTROL_LIMIT_ID, \
31 .value = _thermctllmit, \
32 }, \
33 { \
34 .id = ALIB_DPTC_SUSTAINED_POWER_LIMIT_ID, \
35 .value = _sustained, \
36 }, \
37 { \
38 .id = ALIB_DPTC_FAST_PPT_LIMIT_ID, \
39 .value = _fast, \
40 }, \
41 { \
42 .id = ALIB_DPTC_SLOW_PPT_LIMIT_ID, \
43 .value = _slow, \
44 }, \
45 }, \
46 }
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -070047
48/*
49 *
50 * +--------------------------------+
51 * | |
52 * | |
53 * | |
54 * | |
55 * | |
56 * | |
57 * | |
58 * reserved_dram_end +--------------------------------+
59 * | |
60 * | verstage (if reqd) |
61 * | (VERSTAGE_SIZE) |
62 * +--------------------------------+ VERSTAGE_ADDR
63 * | |
64 * | FSP-M |
65 * | (FSP_M_SIZE) |
66 * +--------------------------------+ FSP_M_ADDR
67 * | romstage |
68 * | (ROMSTAGE_SIZE) |
69 * +--------------------------------+ ROMSTAGE_ADDR = BOOTBLOCK_END
70 * | | X86_RESET_VECTOR = BOOTBLOCK_END - 0x10
71 * | bootblock |
72 * | (C_ENV_BOOTBLOCK_SIZE) |
73 * +--------------------------------+ BOOTBLOCK_ADDR = BOOTBLOCK_END - C_ENV_BOOTBLOCK_SIZE
74 * | Unused hole |
75 * | (86KiB) |
76 * +--------------------------------+
77 * | FMAP cache (FMAP_SIZE) |
78 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE + 0x200
79 * | Early Timestamp region (512B) |
80 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE
81 * | Preram CBMEM console |
82 * | (PRERAM_CBMEM_CONSOLE_SIZE) |
83 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE
84 * | PSP shared (vboot workbuf) |
85 * | (PSP_SHAREDMEM_SIZE) |
86 * +--------------------------------+ PSP_SHAREDMEM_BASE
87 * | APOB (64KiB) |
88 * +--------------------------------+ PSP_APOB_DRAM_ADDRESS
89 * | Early BSP stack |
90 * | (EARLYRAM_BSP_STACK_SIZE) |
91 * reserved_dram_start +--------------------------------+ EARLY_RESERVED_DRAM_BASE
92 * | DRAM |
93 * +--------------------------------+ 0x100000
94 * | Option ROM |
95 * +--------------------------------+ 0xc0000
96 * | Legacy VGA |
97 * +--------------------------------+ 0xa0000
98 * | DRAM |
99 * +--------------------------------+ 0x0
100 */
101static void read_resources(struct device *dev)
102{
103 uint32_t mem_usable = (uintptr_t)cbmem_top();
104 unsigned int idx = 0;
Felix Held2e814362022-11-10 22:44:18 +0100105 const struct hob_header *hob_iterator;
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700106 const struct hob_resource *res;
Felix Held1ed5a632021-05-04 21:51:43 +0200107 struct resource *gnb_apic;
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 */
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300121 ram_resource_kb(dev, idx++, 0, 0xa0000 / KiB);
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700122
123 /* 0xa0000 - 0xbffff: legacy VGA */
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300124 mmio_resource_kb(dev, idx++, 0xa0000 / KiB, 0x20000 / KiB);
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700125
126 /* 0xc0000 - 0xfffff: Option ROM */
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300127 reserved_ram_resource_kb(dev, idx++, 0xc0000 / KiB, 0x40000 / KiB);
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700128
129 /* 1MiB - bottom of DRAM reserved for early coreboot usage */
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300130 ram_resource_kb(dev, idx++, (1 * MiB) / KiB,
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700131 (early_reserved_dram_start - (1 * MiB)) / KiB);
132
133 /* DRAM reserved for early coreboot usage */
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300134 reserved_ram_resource_kb(dev, idx++, early_reserved_dram_start / KiB,
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700135 (early_reserved_dram_end - early_reserved_dram_start) / KiB);
136
137 /*
138 * top of DRAM consumed early - low top usable RAM
139 * cbmem_top() accounts for low UMA and TSEG if they are used.
140 */
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300141 ram_resource_kb(dev, idx++, early_reserved_dram_end / KiB,
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700142 (mem_usable - early_reserved_dram_end) / KiB);
143
Felix Held56b037b2022-03-02 22:57:01 +0100144 mmconf_resource(dev, idx++);
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700145
Felix Helddafc6192022-11-10 18:19:36 +0100146 /* GNB IOAPIC resource */
147 gnb_apic = new_resource(dev, idx++);
148 gnb_apic->base = GNB_IO_APIC_ADDR;
149 gnb_apic->size = 0x00001000;
150 gnb_apic->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
151
Felix Held2e814362022-11-10 22:44:18 +0100152 if (fsp_hob_iterator_init(&hob_iterator) != CB_SUCCESS) {
Julius Wernere9665952022-01-21 17:06:20 -0800153 printk(BIOS_ERR, "%s incomplete because no HOB list was found\n",
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700154 __func__);
155 return;
156 }
157
Felix Held2e814362022-11-10 22:44:18 +0100158 while (fsp_hob_iterator_get_next_resource(&hob_iterator, &res) == CB_SUCCESS) {
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700159 if (res->type == EFI_RESOURCE_SYSTEM_MEMORY && res->addr < mem_usable)
160 continue; /* 0 through low usable was set above */
161 if (res->type == EFI_RESOURCE_MEMORY_MAPPED_IO)
162 continue; /* Done separately */
163
164 if (res->type == EFI_RESOURCE_SYSTEM_MEMORY)
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300165 ram_resource_kb(dev, idx++, res->addr / KiB, res->length / KiB);
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700166 else if (res->type == EFI_RESOURCE_MEMORY_RESERVED)
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300167 reserved_ram_resource_kb(dev, idx++, res->addr / KiB, res->length / KiB);
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700168 else
Julius Wernere9665952022-01-21 17:06:20 -0800169 printk(BIOS_ERR, "failed to set resources for type %d\n",
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700170 res->type);
171 }
Felix Held1ed5a632021-05-04 21:51:43 +0200172}
173
174static void root_complex_init(struct device *dev)
175{
Kyösti Mälkki2e65e9c2021-06-16 11:00:40 +0300176 register_new_ioapic((u8 *)GNB_IO_APIC_ADDR);
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700177}
178
Felix Helddd882f32021-05-12 01:23:50 +0200179static void acipgen_dptci(void)
180{
181 const struct soc_amd_cezanne_config *config = config_of_soc();
182
Tim Van Patten9eac0972022-09-13 15:34:08 -0600183 /* Normal mode DPTC values. */
Felix Helddd882f32021-05-12 01:23:50 +0200184 struct dptc_input default_input = DPTC_INPUTS(config->thermctl_limit_degreeC,
Tim Van Patten92443582022-08-23 16:06:33 -0600185 config->sustained_power_limit_mW,
186 config->fast_ppt_limit_mW,
187 config->slow_ppt_limit_mW);
188 acpigen_write_alib_dptc_default((uint8_t *)&default_input, sizeof(default_input));
Felix Helddd882f32021-05-12 01:23:50 +0200189}
190
Raul E Rangel0b123dd2021-02-12 15:13:57 -0700191static void root_complex_fill_ssdt(const struct device *device)
192{
Tim Van Patten9eac0972022-09-13 15:34:08 -0600193 if (CONFIG(SOC_AMD_COMMON_BLOCK_ACPI_DPTC))
194 acipgen_dptci();
Raul E Rangel0b123dd2021-02-12 15:13:57 -0700195}
196
Felix Heldb28401302021-02-17 00:05:34 +0100197static const char *gnb_acpi_name(const struct device *dev)
198{
199 return "GNB";
200}
201
Arthur Heymansb65f6092022-10-05 21:45:23 +0200202struct device_operations cezanne_root_complex_operations = {
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700203 .read_resources = read_resources,
204 .set_resources = noop_set_resources,
205 .enable_resources = pci_dev_enable_resources,
Felix Held1ed5a632021-05-04 21:51:43 +0200206 .init = root_complex_init,
Felix Heldb28401302021-02-17 00:05:34 +0100207 .acpi_name = gnb_acpi_name,
Raul E Rangel0b123dd2021-02-12 15:13:57 -0700208 .acpi_fill_ssdt = root_complex_fill_ssdt,
Raul E Rangelcf6dc7d2021-02-05 16:00:41 -0700209};