blob: ee9764cb7dbcac5c1e4d0404d61fe319cf0de051 [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 Rangel899be1b2021-02-05 15:50:20 -07004#include <amdblocks/memmap.h>
Felix Held604ffa62021-02-12 00:43:20 +01005#include <amdblocks/ioapic.h>
Felix Heldf9608cd2020-12-03 16:57:02 +01006#include <arch/ioapic.h>
John Zhaof6f1f732020-06-26 10:00:02 -07007#include <assert.h>
Marshall Dawsoneb724872019-07-16 15:46:35 -06008#include <cbmem.h>
9#include <console/console.h>
10#include <cpu/amd/msr.h>
11#include <cpu/amd/mtrr.h>
12#include <device/device.h>
13#include <device/pci.h>
14#include <device/pci_ids.h>
15#include <fsp/util.h>
16#include <stdint.h>
Marshall Dawson39c64b02020-09-04 12:07:27 -060017#include <soc/iomap.h>
Chris Wang4735b1c2020-07-13 23:29:29 +080018#include "chip.h"
Marshall Dawsoneb724872019-07-16 15:46:35 -060019
Chris Wang4735b1c2020-07-13 23:29:29 +080020enum {
21 ALIB_DPTCI_FUNCTION_ID = 0xc,
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,
Kevin Chiucdd9f5c2020-09-18 17:30:30 +080026 DPTC_TOTAL_UPDATE_PARAMS = 4,
Chris Wang4735b1c2020-07-13 23:29:29 +080027};
28
29struct dptc_param {
30 uint8_t id;
31 uint32_t value;
32} __packed;
33
34struct dptc_input {
35 uint16_t size;
36 struct dptc_param params[DPTC_TOTAL_UPDATE_PARAMS];
37} __packed;
38
Kevin Chiucdd9f5c2020-09-18 17:30:30 +080039#define DPTC_INPUTS(_thermctllmit, _sustained, _fast, _slow) \
Chris Wang4735b1c2020-07-13 23:29:29 +080040 { \
41 .size = sizeof(struct dptc_input), \
42 .params = { \
43 { \
Kevin Chiucdd9f5c2020-09-18 17:30:30 +080044 .id = THERMAL_CONTROL_LIMIT_ID, \
45 .value = _thermctllmit, \
46 }, \
47 { \
Chris Wang4735b1c2020-07-13 23:29:29 +080048 .id = SUSTAINED_POWER_LIMIT_PARAM_ID, \
49 .value = _sustained, \
50 }, \
51 { \
52 .id = FAST_PPT_LIMIT_PARAM_ID, \
53 .value = _fast, \
54 }, \
55 { \
56 .id = SLOW_PPT_LIMIT_PARAM_ID, \
57 .value = _slow, \
58 }, \
59 }, \
60 }
Furquan Shaikhbc456502020-06-10 16:37:23 -070061/*
62 *
63 * +--------------------------------+
64 * | |
65 * | |
66 * | |
67 * | |
68 * | |
69 * | |
70 * | |
71 * reserved_dram_end +--------------------------------+
72 * | |
73 * | verstage (if reqd) |
74 * | (VERSTAGE_SIZE) |
75 * +--------------------------------+ VERSTAGE_ADDR
76 * | |
77 * | FSP-M |
78 * | (FSP_M_SIZE) |
79 * +--------------------------------+ FSP_M_ADDR
Furquan Shaikhbc456502020-06-10 16:37:23 -070080 * | romstage |
81 * | (ROMSTAGE_SIZE) |
Kyösti Mälkkib3621f82020-12-04 19:51:17 +020082 * +--------------------------------+ ROMSTAGE_ADDR = BOOTBLOCK_END
83 * | | X86_RESET_VECTOR = BOOTBLOCK_END - 0x10
Furquan Shaikhbc456502020-06-10 16:37:23 -070084 * | bootblock |
85 * | (C_ENV_BOOTBLOCK_SIZE) |
Kyösti Mälkkib3621f82020-12-04 19:51:17 +020086 * +--------------------------------+ BOOTBLOCK_ADDR = BOOTBLOCK_END - C_ENV_BOOTBLOCK_SIZE
Furquan Shaikhbc456502020-06-10 16:37:23 -070087 * | Unused hole |
88 * | (86KiB) |
89 * +--------------------------------+
90 * | FMAP cache (FMAP_SIZE) |
91 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE + 0x200
92 * | Early Timestamp region (512B) |
93 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE
94 * | Preram CBMEM console |
95 * | (PRERAM_CBMEM_CONSOLE_SIZE) |
96 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE
97 * | PSP shared (vboot workbuf) |
98 * | (PSP_SHAREDMEM_SIZE) |
99 * +--------------------------------+ PSP_SHAREDMEM_BASE
100 * | APOB (64KiB) |
101 * +--------------------------------+ PSP_APOB_DRAM_ADDRESS
102 * | Early BSP stack |
103 * | (EARLYRAM_BSP_STACK_SIZE) |
104 * reserved_dram_start +--------------------------------+ EARLY_RESERVED_DRAM_BASE
105 * | DRAM |
106 * +--------------------------------+ 0x100000
107 * | Option ROM |
108 * +--------------------------------+ 0xc0000
109 * | Legacy VGA |
110 * +--------------------------------+ 0xa0000
111 * | DRAM |
112 * +--------------------------------+ 0x0
113 */
Marshall Dawsoneb724872019-07-16 15:46:35 -0600114static void read_resources(struct device *dev)
115{
116 uint32_t mem_usable = (uintptr_t)cbmem_top();
117 unsigned int idx = 0;
118 const struct hob_header *hob = fsp_get_hob_list();
119 const struct hob_resource *res;
Marshall Dawson39c64b02020-09-04 12:07:27 -0600120 struct resource *gnb_apic;
Marshall Dawsoneb724872019-07-16 15:46:35 -0600121
Furquan Shaikhbc456502020-06-10 16:37:23 -0700122 uintptr_t early_reserved_dram_start, early_reserved_dram_end;
123 const struct memmap_early_dram *e = memmap_get_early_dram_usage();
124
125 early_reserved_dram_start = e->base;
126 early_reserved_dram_end = e->base + e->size;
127
Marshall Dawsoneb724872019-07-16 15:46:35 -0600128 /* 0x0 - 0x9ffff */
129 ram_resource(dev, idx++, 0, 0xa0000 / KiB);
130
131 /* 0xa0000 - 0xbffff: legacy VGA */
132 mmio_resource(dev, idx++, 0xa0000 / KiB, 0x20000 / KiB);
133
134 /* 0xc0000 - 0xfffff: Option ROM */
135 reserved_ram_resource(dev, idx++, 0xc0000 / KiB, 0x40000 / KiB);
136
Furquan Shaikhbc456502020-06-10 16:37:23 -0700137 /* 1MB - bottom of DRAM reserved for early coreboot usage */
138 ram_resource(dev, idx++, (1 * MiB) / KiB,
139 (early_reserved_dram_start - (1 * MiB)) / KiB);
140
141 /* DRAM reserved for early coreboot usage */
142 reserved_ram_resource(dev, idx++, early_reserved_dram_start / KiB,
143 (early_reserved_dram_end - early_reserved_dram_start) / KiB);
144
145 /* top of DRAM consumed early - low top usable RAM
146 * cbmem_top() accounts for low UMA and TSEG if they are used. */
147 ram_resource(dev, idx++, early_reserved_dram_end / KiB,
148 (mem_usable - early_reserved_dram_end) / KiB);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600149
150 mmconf_resource(dev, MMIO_CONF_BASE);
151
152 if (!hob) {
153 printk(BIOS_ERR, "Error: %s incomplete because no HOB list was found\n",
154 __func__);
155 return;
156 }
157
158 for (; hob->type != HOB_TYPE_END_OF_HOB_LIST; hob = fsp_next_hob(hob)) {
159
160 if (hob->type != HOB_TYPE_RESOURCE_DESCRIPTOR)
161 continue;
162
163 res = fsp_hob_header_to_resource(hob);
164
165 if (res->type == EFI_RESOURCE_SYSTEM_MEMORY && res->addr < mem_usable)
166 continue; /* 0 through low usable was set above */
167 if (res->type == EFI_RESOURCE_MEMORY_MAPPED_IO)
168 continue; /* Done separately */
169
170 if (res->type == EFI_RESOURCE_SYSTEM_MEMORY)
171 ram_resource(dev, idx++, res->addr / KiB, res->length / KiB);
172 else if (res->type == EFI_RESOURCE_MEMORY_RESERVED)
173 reserved_ram_resource(dev, idx++, res->addr / KiB, res->length / KiB);
174 else
175 printk(BIOS_ERR, "Error: failed to set resources for type %d\n",
176 res->type);
177 }
Marshall Dawson39c64b02020-09-04 12:07:27 -0600178
179 /* GNB IOAPIC resource */
180 gnb_apic = new_resource(dev, GNB_IO_APIC_ADDR);
181 gnb_apic->base = GNB_IO_APIC_ADDR;
182 gnb_apic->size = 0x00001000;
183 gnb_apic->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
Marshall Dawsoneb724872019-07-16 15:46:35 -0600184}
185
Felix Heldf9608cd2020-12-03 16:57:02 +0100186static void root_complex_init(struct device *dev)
187{
Felix Held604ffa62021-02-12 00:43:20 +0100188 setup_ioapic((u8 *)GNB_IO_APIC_ADDR, GNB_IOAPIC_ID);
Felix Heldf9608cd2020-12-03 16:57:02 +0100189}
190
Chris Wang4735b1c2020-07-13 23:29:29 +0800191static void dptc_call_alib(const char *buf_name, uint8_t *buffer, size_t size)
192{
193 /* Name (buf_name, Buffer(size) {...} */
194 acpigen_write_name(buf_name);
195 acpigen_write_byte_buffer(buffer, size);
196
197 /* \_SB.ALIB(0xc, buf_name) */
198 acpigen_emit_namestring("\\_SB.ALIB");
199 acpigen_write_integer(ALIB_DPTCI_FUNCTION_ID);
200 acpigen_emit_namestring(buf_name);
201}
202
203static void acipgen_dptci(void)
204{
Felix Held507fc032020-12-05 01:55:27 +0100205 const struct soc_amd_picasso_config *config = config_of_soc();
Chris Wang4735b1c2020-07-13 23:29:29 +0800206
207 if (!config->dptc_enable)
208 return;
209
Zheng Bao795d73c2020-10-27 15:36:55 +0800210 struct dptc_input default_input = DPTC_INPUTS(config->thermctl_limit_degreeC,
211 config->sustained_power_limit_mW,
212 config->fast_ppt_limit_mW,
213 config->slow_ppt_limit_mW);
Chris Wang4735b1c2020-07-13 23:29:29 +0800214 struct dptc_input tablet_mode_input = DPTC_INPUTS(
Zheng Bao795d73c2020-10-27 15:36:55 +0800215 config->thermctl_limit_tablet_mode_degreeC,
216 config->sustained_power_limit_tablet_mode_mW,
217 config->fast_ppt_limit_tablet_mode_mW,
218 config->slow_ppt_limit_tablet_mode_mW);
Chris Wang4735b1c2020-07-13 23:29:29 +0800219 /* Scope (\_SB) */
220 acpigen_write_scope("\\_SB");
221
222 /* Method(DPTC, 0, Serialized) */
223 acpigen_write_method_serialized("DPTC", 0);
224
225 /* If (LEqual ("\_SB.PCI0.LPCB.EC0.TBMD", 1)) */
226 acpigen_write_if_lequal_namestr_int("\\_SB.PCI0.LPCB.EC0.TBMD", 1);
227
228 dptc_call_alib("TABB", (uint8_t *)(void *)&tablet_mode_input,
229 sizeof(tablet_mode_input));
230
231 acpigen_pop_len(); /* If */
232
233 /* Else */
234 acpigen_write_else();
235
236 dptc_call_alib("DEFB", (uint8_t *)(void *)&default_input, sizeof(default_input));
237
238 acpigen_pop_len(); /* Else */
239
240 acpigen_pop_len(); /* Method DPTC */
241 acpigen_pop_len(); /* Scope \_SB */
242}
243
Marshall Dawsoneb724872019-07-16 15:46:35 -0600244/* Used by \_SB.PCI0._CRS */
245static void root_complex_fill_ssdt(const struct device *device)
246{
247 msr_t msr;
John Zhaof6f1f732020-06-26 10:00:02 -0700248 const char *scope;
Marshall Dawsoneb724872019-07-16 15:46:35 -0600249
John Zhaof6f1f732020-06-26 10:00:02 -0700250 assert(device);
Felix Held3858fb12020-06-27 15:11:36 +0200251
John Zhaof6f1f732020-06-26 10:00:02 -0700252 scope = acpi_device_scope(device);
253 assert(scope);
254 acpigen_write_scope(scope);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600255
256 msr = rdmsr(TOP_MEM);
257 acpigen_write_name_dword("TOM1", msr.lo);
258 msr = rdmsr(TOP_MEM2);
259 /*
260 * Since XP only implements parts of ACPI 2.0, we can't use a qword
261 * here.
262 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
263 * slide 22ff.
264 * Shift value right by 20 bit to make it fit into 32bit,
265 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
266 */
267 acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
268 acpigen_pop_len();
Chris Wang4735b1c2020-07-13 23:29:29 +0800269 acipgen_dptci();
Marshall Dawsoneb724872019-07-16 15:46:35 -0600270}
271
Felix Heldff092d42021-02-17 00:04:59 +0100272static const char *gnb_acpi_name(const struct device *dev)
273{
274 return "GNB";
275}
276
Marshall Dawsoneb724872019-07-16 15:46:35 -0600277static struct device_operations root_complex_operations = {
278 .read_resources = read_resources,
Felix Held9541d172021-01-05 00:56:10 +0100279 .set_resources = noop_set_resources,
Marshall Dawsoneb724872019-07-16 15:46:35 -0600280 .enable_resources = pci_dev_enable_resources,
Felix Heldf9608cd2020-12-03 16:57:02 +0100281 .init = root_complex_init,
Felix Heldff092d42021-02-17 00:04:59 +0100282 .acpi_name = gnb_acpi_name,
Marshall Dawsoneb724872019-07-16 15:46:35 -0600283 .acpi_fill_ssdt = root_complex_fill_ssdt,
284};
285
286static const struct pci_driver family17_root_complex __pci_driver = {
287 .ops = &root_complex_operations,
288 .vendor = PCI_VENDOR_ID_AMD,
289 .device = PCI_DEVICE_ID_AMD_17H_MODEL_101F_NB,
290};