blob: 932ca766b2d433aa272028c9c8deb8e9df89d419 [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>
Raul E Rangel899be1b2021-02-05 15:50:20 -07006#include <amdblocks/memmap.h>
Felix Held604ffa62021-02-12 00:43:20 +01007#include <amdblocks/ioapic.h>
Felix Heldf9608cd2020-12-03 16:57:02 +01008#include <arch/ioapic.h>
John Zhaof6f1f732020-06-26 10:00:02 -07009#include <assert.h>
Marshall Dawsoneb724872019-07-16 15:46:35 -060010#include <cbmem.h>
11#include <console/console.h>
12#include <cpu/amd/msr.h>
Marshall Dawsoneb724872019-07-16 15:46:35 -060013#include <device/device.h>
14#include <device/pci.h>
15#include <device/pci_ids.h>
16#include <fsp/util.h>
17#include <stdint.h>
Marshall Dawson39c64b02020-09-04 12:07:27 -060018#include <soc/iomap.h>
Chris Wang4735b1c2020-07-13 23:29:29 +080019#include "chip.h"
Marshall Dawsoneb724872019-07-16 15:46:35 -060020
Chris Wang4735b1c2020-07-13 23:29:29 +080021enum {
Kevin Chiucdd9f5c2020-09-18 17:30:30 +080022 THERMAL_CONTROL_LIMIT_ID = 0x3,
Chris Wang4735b1c2020-07-13 23:29:29 +080023 SUSTAINED_POWER_LIMIT_PARAM_ID = 0x5,
24 FAST_PPT_LIMIT_PARAM_ID = 0x6,
25 SLOW_PPT_LIMIT_PARAM_ID = 0x7,
Chris Wang4735b1c2020-07-13 23:29:29 +080026};
27
Felix Heldef511572021-05-07 19:02:45 +020028#define DPTC_TOTAL_UPDATE_PARAMS 4
29
Chris Wang4735b1c2020-07-13 23:29:29 +080030struct dptc_param {
31 uint8_t id;
32 uint32_t value;
33} __packed;
34
35struct dptc_input {
36 uint16_t size;
37 struct dptc_param params[DPTC_TOTAL_UPDATE_PARAMS];
38} __packed;
39
Kevin Chiucdd9f5c2020-09-18 17:30:30 +080040#define DPTC_INPUTS(_thermctllmit, _sustained, _fast, _slow) \
Chris Wang4735b1c2020-07-13 23:29:29 +080041 { \
42 .size = sizeof(struct dptc_input), \
43 .params = { \
44 { \
Kevin Chiucdd9f5c2020-09-18 17:30:30 +080045 .id = THERMAL_CONTROL_LIMIT_ID, \
46 .value = _thermctllmit, \
47 }, \
48 { \
Chris Wang4735b1c2020-07-13 23:29:29 +080049 .id = SUSTAINED_POWER_LIMIT_PARAM_ID, \
50 .value = _sustained, \
51 }, \
52 { \
53 .id = FAST_PPT_LIMIT_PARAM_ID, \
54 .value = _fast, \
55 }, \
56 { \
57 .id = SLOW_PPT_LIMIT_PARAM_ID, \
58 .value = _slow, \
59 }, \
60 }, \
61 }
Furquan Shaikhbc456502020-06-10 16:37:23 -070062/*
63 *
64 * +--------------------------------+
65 * | |
66 * | |
67 * | |
68 * | |
69 * | |
70 * | |
71 * | |
72 * reserved_dram_end +--------------------------------+
73 * | |
74 * | verstage (if reqd) |
75 * | (VERSTAGE_SIZE) |
76 * +--------------------------------+ VERSTAGE_ADDR
77 * | |
78 * | FSP-M |
79 * | (FSP_M_SIZE) |
80 * +--------------------------------+ FSP_M_ADDR
Furquan Shaikhbc456502020-06-10 16:37:23 -070081 * | romstage |
82 * | (ROMSTAGE_SIZE) |
Kyösti Mälkkib3621f82020-12-04 19:51:17 +020083 * +--------------------------------+ ROMSTAGE_ADDR = BOOTBLOCK_END
84 * | | X86_RESET_VECTOR = BOOTBLOCK_END - 0x10
Furquan Shaikhbc456502020-06-10 16:37:23 -070085 * | bootblock |
86 * | (C_ENV_BOOTBLOCK_SIZE) |
Kyösti Mälkkib3621f82020-12-04 19:51:17 +020087 * +--------------------------------+ BOOTBLOCK_ADDR = BOOTBLOCK_END - C_ENV_BOOTBLOCK_SIZE
Furquan Shaikhbc456502020-06-10 16:37:23 -070088 * | Unused hole |
89 * | (86KiB) |
90 * +--------------------------------+
91 * | FMAP cache (FMAP_SIZE) |
92 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE + 0x200
93 * | Early Timestamp region (512B) |
94 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE
95 * | Preram CBMEM console |
96 * | (PRERAM_CBMEM_CONSOLE_SIZE) |
97 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE
98 * | PSP shared (vboot workbuf) |
99 * | (PSP_SHAREDMEM_SIZE) |
100 * +--------------------------------+ PSP_SHAREDMEM_BASE
101 * | APOB (64KiB) |
102 * +--------------------------------+ PSP_APOB_DRAM_ADDRESS
103 * | Early BSP stack |
104 * | (EARLYRAM_BSP_STACK_SIZE) |
105 * reserved_dram_start +--------------------------------+ EARLY_RESERVED_DRAM_BASE
106 * | DRAM |
107 * +--------------------------------+ 0x100000
108 * | Option ROM |
109 * +--------------------------------+ 0xc0000
110 * | Legacy VGA |
111 * +--------------------------------+ 0xa0000
112 * | DRAM |
113 * +--------------------------------+ 0x0
114 */
Marshall Dawsoneb724872019-07-16 15:46:35 -0600115static void read_resources(struct device *dev)
116{
117 uint32_t mem_usable = (uintptr_t)cbmem_top();
118 unsigned int idx = 0;
119 const struct hob_header *hob = fsp_get_hob_list();
120 const struct hob_resource *res;
Marshall Dawson39c64b02020-09-04 12:07:27 -0600121 struct resource *gnb_apic;
Marshall Dawsoneb724872019-07-16 15:46:35 -0600122
Furquan Shaikhbc456502020-06-10 16:37:23 -0700123 uintptr_t early_reserved_dram_start, early_reserved_dram_end;
124 const struct memmap_early_dram *e = memmap_get_early_dram_usage();
125
126 early_reserved_dram_start = e->base;
127 early_reserved_dram_end = e->base + e->size;
128
Marshall Dawsoneb724872019-07-16 15:46:35 -0600129 /* 0x0 - 0x9ffff */
130 ram_resource(dev, idx++, 0, 0xa0000 / KiB);
131
132 /* 0xa0000 - 0xbffff: legacy VGA */
133 mmio_resource(dev, idx++, 0xa0000 / KiB, 0x20000 / KiB);
134
135 /* 0xc0000 - 0xfffff: Option ROM */
136 reserved_ram_resource(dev, idx++, 0xc0000 / KiB, 0x40000 / KiB);
137
Furquan Shaikhbc456502020-06-10 16:37:23 -0700138 /* 1MB - bottom of DRAM reserved for early coreboot usage */
139 ram_resource(dev, idx++, (1 * MiB) / KiB,
140 (early_reserved_dram_start - (1 * MiB)) / KiB);
141
142 /* DRAM reserved for early coreboot usage */
143 reserved_ram_resource(dev, idx++, early_reserved_dram_start / KiB,
144 (early_reserved_dram_end - early_reserved_dram_start) / KiB);
145
146 /* top of DRAM consumed early - low top usable RAM
147 * cbmem_top() accounts for low UMA and TSEG if they are used. */
148 ram_resource(dev, idx++, early_reserved_dram_end / KiB,
149 (mem_usable - early_reserved_dram_end) / KiB);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600150
151 mmconf_resource(dev, MMIO_CONF_BASE);
152
153 if (!hob) {
154 printk(BIOS_ERR, "Error: %s incomplete because no HOB list was found\n",
155 __func__);
156 return;
157 }
158
159 for (; hob->type != HOB_TYPE_END_OF_HOB_LIST; hob = fsp_next_hob(hob)) {
160
161 if (hob->type != HOB_TYPE_RESOURCE_DESCRIPTOR)
162 continue;
163
164 res = fsp_hob_header_to_resource(hob);
165
166 if (res->type == EFI_RESOURCE_SYSTEM_MEMORY && res->addr < mem_usable)
167 continue; /* 0 through low usable was set above */
168 if (res->type == EFI_RESOURCE_MEMORY_MAPPED_IO)
169 continue; /* Done separately */
170
171 if (res->type == EFI_RESOURCE_SYSTEM_MEMORY)
172 ram_resource(dev, idx++, res->addr / KiB, res->length / KiB);
173 else if (res->type == EFI_RESOURCE_MEMORY_RESERVED)
174 reserved_ram_resource(dev, idx++, res->addr / KiB, res->length / KiB);
175 else
176 printk(BIOS_ERR, "Error: failed to set resources for type %d\n",
177 res->type);
178 }
Marshall Dawson39c64b02020-09-04 12:07:27 -0600179
180 /* GNB IOAPIC resource */
181 gnb_apic = new_resource(dev, GNB_IO_APIC_ADDR);
182 gnb_apic->base = GNB_IO_APIC_ADDR;
183 gnb_apic->size = 0x00001000;
184 gnb_apic->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
Marshall Dawsoneb724872019-07-16 15:46:35 -0600185}
186
Felix Heldf9608cd2020-12-03 16:57:02 +0100187static void root_complex_init(struct device *dev)
188{
Felix Held604ffa62021-02-12 00:43:20 +0100189 setup_ioapic((u8 *)GNB_IO_APIC_ADDR, GNB_IOAPIC_ID);
Felix Heldf9608cd2020-12-03 16:57:02 +0100190}
191
Chris Wang4735b1c2020-07-13 23:29:29 +0800192static void dptc_call_alib(const char *buf_name, uint8_t *buffer, size_t size)
193{
194 /* Name (buf_name, Buffer(size) {...} */
195 acpigen_write_name(buf_name);
196 acpigen_write_byte_buffer(buffer, size);
197
198 /* \_SB.ALIB(0xc, buf_name) */
199 acpigen_emit_namestring("\\_SB.ALIB");
Felix Held95f1bb82021-05-07 18:46:36 +0200200 acpigen_write_integer(ALIB_FUNCTION_DYNAMIC_POWER_THERMAL_CONFIG);
Chris Wang4735b1c2020-07-13 23:29:29 +0800201 acpigen_emit_namestring(buf_name);
202}
203
204static void acipgen_dptci(void)
205{
Felix Held507fc032020-12-05 01:55:27 +0100206 const struct soc_amd_picasso_config *config = config_of_soc();
Chris Wang4735b1c2020-07-13 23:29:29 +0800207
208 if (!config->dptc_enable)
209 return;
210
Zheng Bao795d73c2020-10-27 15:36:55 +0800211 struct dptc_input default_input = DPTC_INPUTS(config->thermctl_limit_degreeC,
212 config->sustained_power_limit_mW,
213 config->fast_ppt_limit_mW,
214 config->slow_ppt_limit_mW);
Chris Wang4735b1c2020-07-13 23:29:29 +0800215 struct dptc_input tablet_mode_input = DPTC_INPUTS(
Zheng Bao795d73c2020-10-27 15:36:55 +0800216 config->thermctl_limit_tablet_mode_degreeC,
217 config->sustained_power_limit_tablet_mode_mW,
218 config->fast_ppt_limit_tablet_mode_mW,
219 config->slow_ppt_limit_tablet_mode_mW);
Chris Wang4735b1c2020-07-13 23:29:29 +0800220 /* Scope (\_SB) */
221 acpigen_write_scope("\\_SB");
222
223 /* Method(DPTC, 0, Serialized) */
224 acpigen_write_method_serialized("DPTC", 0);
225
226 /* If (LEqual ("\_SB.PCI0.LPCB.EC0.TBMD", 1)) */
227 acpigen_write_if_lequal_namestr_int("\\_SB.PCI0.LPCB.EC0.TBMD", 1);
228
229 dptc_call_alib("TABB", (uint8_t *)(void *)&tablet_mode_input,
230 sizeof(tablet_mode_input));
231
Chris Wang4735b1c2020-07-13 23:29:29 +0800232 /* Else */
233 acpigen_write_else();
234
235 dptc_call_alib("DEFB", (uint8_t *)(void *)&default_input, sizeof(default_input));
236
237 acpigen_pop_len(); /* Else */
238
239 acpigen_pop_len(); /* Method DPTC */
240 acpigen_pop_len(); /* Scope \_SB */
241}
242
Marshall Dawsoneb724872019-07-16 15:46:35 -0600243static void root_complex_fill_ssdt(const struct device *device)
244{
Raul E Rangel58a8ad12021-02-18 16:36:08 -0700245 acpi_fill_root_complex_tom(device);
Chris Wang4735b1c2020-07-13 23:29:29 +0800246 acipgen_dptci();
Marshall Dawsoneb724872019-07-16 15:46:35 -0600247}
248
Felix Heldff092d42021-02-17 00:04:59 +0100249static const char *gnb_acpi_name(const struct device *dev)
250{
251 return "GNB";
252}
253
Marshall Dawsoneb724872019-07-16 15:46:35 -0600254static struct device_operations root_complex_operations = {
255 .read_resources = read_resources,
Felix Held9541d172021-01-05 00:56:10 +0100256 .set_resources = noop_set_resources,
Marshall Dawsoneb724872019-07-16 15:46:35 -0600257 .enable_resources = pci_dev_enable_resources,
Felix Heldf9608cd2020-12-03 16:57:02 +0100258 .init = root_complex_init,
Felix Heldff092d42021-02-17 00:04:59 +0100259 .acpi_name = gnb_acpi_name,
Marshall Dawsoneb724872019-07-16 15:46:35 -0600260 .acpi_fill_ssdt = root_complex_fill_ssdt,
261};
262
263static const struct pci_driver family17_root_complex __pci_driver = {
264 .ops = &root_complex_operations,
265 .vendor = PCI_VENDOR_ID_AMD,
266 .device = PCI_DEVICE_ID_AMD_17H_MODEL_101F_NB,
267};