blob: 8b348dccdea9bafe48356aa5034c5dd128ea14a7 [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 Heldf9608cd2020-12-03 16:57:02 +01005#include <arch/ioapic.h>
John Zhaof6f1f732020-06-26 10:00:02 -07006#include <assert.h>
Marshall Dawsoneb724872019-07-16 15:46:35 -06007#include <cbmem.h>
8#include <console/console.h>
9#include <cpu/amd/msr.h>
10#include <cpu/amd/mtrr.h>
11#include <device/device.h>
12#include <device/pci.h>
13#include <device/pci_ids.h>
14#include <fsp/util.h>
15#include <stdint.h>
Marshall Dawson39c64b02020-09-04 12:07:27 -060016#include <soc/iomap.h>
Chris Wang4735b1c2020-07-13 23:29:29 +080017#include "chip.h"
Marshall Dawsoneb724872019-07-16 15:46:35 -060018
Chris Wang4735b1c2020-07-13 23:29:29 +080019enum {
20 ALIB_DPTCI_FUNCTION_ID = 0xc,
Kevin Chiucdd9f5c2020-09-18 17:30:30 +080021 THERMAL_CONTROL_LIMIT_ID = 0x3,
Chris Wang4735b1c2020-07-13 23:29:29 +080022 SUSTAINED_POWER_LIMIT_PARAM_ID = 0x5,
23 FAST_PPT_LIMIT_PARAM_ID = 0x6,
24 SLOW_PPT_LIMIT_PARAM_ID = 0x7,
Kevin Chiucdd9f5c2020-09-18 17:30:30 +080025 DPTC_TOTAL_UPDATE_PARAMS = 4,
Chris Wang4735b1c2020-07-13 23:29:29 +080026};
27
28struct dptc_param {
29 uint8_t id;
30 uint32_t value;
31} __packed;
32
33struct dptc_input {
34 uint16_t size;
35 struct dptc_param params[DPTC_TOTAL_UPDATE_PARAMS];
36} __packed;
37
Kevin Chiucdd9f5c2020-09-18 17:30:30 +080038#define DPTC_INPUTS(_thermctllmit, _sustained, _fast, _slow) \
Chris Wang4735b1c2020-07-13 23:29:29 +080039 { \
40 .size = sizeof(struct dptc_input), \
41 .params = { \
42 { \
Kevin Chiucdd9f5c2020-09-18 17:30:30 +080043 .id = THERMAL_CONTROL_LIMIT_ID, \
44 .value = _thermctllmit, \
45 }, \
46 { \
Chris Wang4735b1c2020-07-13 23:29:29 +080047 .id = SUSTAINED_POWER_LIMIT_PARAM_ID, \
48 .value = _sustained, \
49 }, \
50 { \
51 .id = FAST_PPT_LIMIT_PARAM_ID, \
52 .value = _fast, \
53 }, \
54 { \
55 .id = SLOW_PPT_LIMIT_PARAM_ID, \
56 .value = _slow, \
57 }, \
58 }, \
59 }
Furquan Shaikhbc456502020-06-10 16:37:23 -070060/*
61 *
62 * +--------------------------------+
63 * | |
64 * | |
65 * | |
66 * | |
67 * | |
68 * | |
69 * | |
70 * reserved_dram_end +--------------------------------+
71 * | |
72 * | verstage (if reqd) |
73 * | (VERSTAGE_SIZE) |
74 * +--------------------------------+ VERSTAGE_ADDR
75 * | |
76 * | FSP-M |
77 * | (FSP_M_SIZE) |
78 * +--------------------------------+ FSP_M_ADDR
Furquan Shaikhbc456502020-06-10 16:37:23 -070079 * | romstage |
80 * | (ROMSTAGE_SIZE) |
Kyösti Mälkkib3621f82020-12-04 19:51:17 +020081 * +--------------------------------+ ROMSTAGE_ADDR = BOOTBLOCK_END
82 * | | X86_RESET_VECTOR = BOOTBLOCK_END - 0x10
Furquan Shaikhbc456502020-06-10 16:37:23 -070083 * | bootblock |
84 * | (C_ENV_BOOTBLOCK_SIZE) |
Kyösti Mälkkib3621f82020-12-04 19:51:17 +020085 * +--------------------------------+ BOOTBLOCK_ADDR = BOOTBLOCK_END - C_ENV_BOOTBLOCK_SIZE
Furquan Shaikhbc456502020-06-10 16:37:23 -070086 * | Unused hole |
87 * | (86KiB) |
88 * +--------------------------------+
89 * | FMAP cache (FMAP_SIZE) |
90 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE + 0x200
91 * | Early Timestamp region (512B) |
92 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE
93 * | Preram CBMEM console |
94 * | (PRERAM_CBMEM_CONSOLE_SIZE) |
95 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE
96 * | PSP shared (vboot workbuf) |
97 * | (PSP_SHAREDMEM_SIZE) |
98 * +--------------------------------+ PSP_SHAREDMEM_BASE
99 * | APOB (64KiB) |
100 * +--------------------------------+ PSP_APOB_DRAM_ADDRESS
101 * | Early BSP stack |
102 * | (EARLYRAM_BSP_STACK_SIZE) |
103 * reserved_dram_start +--------------------------------+ EARLY_RESERVED_DRAM_BASE
104 * | DRAM |
105 * +--------------------------------+ 0x100000
106 * | Option ROM |
107 * +--------------------------------+ 0xc0000
108 * | Legacy VGA |
109 * +--------------------------------+ 0xa0000
110 * | DRAM |
111 * +--------------------------------+ 0x0
112 */
Marshall Dawsoneb724872019-07-16 15:46:35 -0600113static void read_resources(struct device *dev)
114{
115 uint32_t mem_usable = (uintptr_t)cbmem_top();
116 unsigned int idx = 0;
117 const struct hob_header *hob = fsp_get_hob_list();
118 const struct hob_resource *res;
Marshall Dawson39c64b02020-09-04 12:07:27 -0600119 struct resource *gnb_apic;
Marshall Dawsoneb724872019-07-16 15:46:35 -0600120
Furquan Shaikhbc456502020-06-10 16:37:23 -0700121 uintptr_t early_reserved_dram_start, early_reserved_dram_end;
122 const struct memmap_early_dram *e = memmap_get_early_dram_usage();
123
124 early_reserved_dram_start = e->base;
125 early_reserved_dram_end = e->base + e->size;
126
Marshall Dawsoneb724872019-07-16 15:46:35 -0600127 /* 0x0 - 0x9ffff */
128 ram_resource(dev, idx++, 0, 0xa0000 / KiB);
129
130 /* 0xa0000 - 0xbffff: legacy VGA */
131 mmio_resource(dev, idx++, 0xa0000 / KiB, 0x20000 / KiB);
132
133 /* 0xc0000 - 0xfffff: Option ROM */
134 reserved_ram_resource(dev, idx++, 0xc0000 / KiB, 0x40000 / KiB);
135
Furquan Shaikhbc456502020-06-10 16:37:23 -0700136 /* 1MB - bottom of DRAM reserved for early coreboot usage */
137 ram_resource(dev, idx++, (1 * MiB) / KiB,
138 (early_reserved_dram_start - (1 * MiB)) / KiB);
139
140 /* DRAM reserved for early coreboot usage */
141 reserved_ram_resource(dev, idx++, early_reserved_dram_start / KiB,
142 (early_reserved_dram_end - early_reserved_dram_start) / KiB);
143
144 /* top of DRAM consumed early - low top usable RAM
145 * cbmem_top() accounts for low UMA and TSEG if they are used. */
146 ram_resource(dev, idx++, early_reserved_dram_end / KiB,
147 (mem_usable - early_reserved_dram_end) / KiB);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600148
149 mmconf_resource(dev, MMIO_CONF_BASE);
150
151 if (!hob) {
152 printk(BIOS_ERR, "Error: %s incomplete because no HOB list was found\n",
153 __func__);
154 return;
155 }
156
157 for (; hob->type != HOB_TYPE_END_OF_HOB_LIST; hob = fsp_next_hob(hob)) {
158
159 if (hob->type != HOB_TYPE_RESOURCE_DESCRIPTOR)
160 continue;
161
162 res = fsp_hob_header_to_resource(hob);
163
164 if (res->type == EFI_RESOURCE_SYSTEM_MEMORY && res->addr < mem_usable)
165 continue; /* 0 through low usable was set above */
166 if (res->type == EFI_RESOURCE_MEMORY_MAPPED_IO)
167 continue; /* Done separately */
168
169 if (res->type == EFI_RESOURCE_SYSTEM_MEMORY)
170 ram_resource(dev, idx++, res->addr / KiB, res->length / KiB);
171 else if (res->type == EFI_RESOURCE_MEMORY_RESERVED)
172 reserved_ram_resource(dev, idx++, res->addr / KiB, res->length / KiB);
173 else
174 printk(BIOS_ERR, "Error: failed to set resources for type %d\n",
175 res->type);
176 }
Marshall Dawson39c64b02020-09-04 12:07:27 -0600177
178 /* GNB IOAPIC resource */
179 gnb_apic = new_resource(dev, GNB_IO_APIC_ADDR);
180 gnb_apic->base = GNB_IO_APIC_ADDR;
181 gnb_apic->size = 0x00001000;
182 gnb_apic->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
Marshall Dawsoneb724872019-07-16 15:46:35 -0600183}
184
Felix Heldf9608cd2020-12-03 16:57:02 +0100185static void root_complex_init(struct device *dev)
186{
187 setup_ioapic((u8 *)GNB_IO_APIC_ADDR, CONFIG_PICASSO_GNB_IOAPIC_ID);
188}
189
Chris Wang4735b1c2020-07-13 23:29:29 +0800190static void dptc_call_alib(const char *buf_name, uint8_t *buffer, size_t size)
191{
192 /* Name (buf_name, Buffer(size) {...} */
193 acpigen_write_name(buf_name);
194 acpigen_write_byte_buffer(buffer, size);
195
196 /* \_SB.ALIB(0xc, buf_name) */
197 acpigen_emit_namestring("\\_SB.ALIB");
198 acpigen_write_integer(ALIB_DPTCI_FUNCTION_ID);
199 acpigen_emit_namestring(buf_name);
200}
201
202static void acipgen_dptci(void)
203{
Felix Held507fc032020-12-05 01:55:27 +0100204 const struct soc_amd_picasso_config *config = config_of_soc();
Chris Wang4735b1c2020-07-13 23:29:29 +0800205
206 if (!config->dptc_enable)
207 return;
208
Zheng Bao795d73c2020-10-27 15:36:55 +0800209 struct dptc_input default_input = DPTC_INPUTS(config->thermctl_limit_degreeC,
210 config->sustained_power_limit_mW,
211 config->fast_ppt_limit_mW,
212 config->slow_ppt_limit_mW);
Chris Wang4735b1c2020-07-13 23:29:29 +0800213 struct dptc_input tablet_mode_input = DPTC_INPUTS(
Zheng Bao795d73c2020-10-27 15:36:55 +0800214 config->thermctl_limit_tablet_mode_degreeC,
215 config->sustained_power_limit_tablet_mode_mW,
216 config->fast_ppt_limit_tablet_mode_mW,
217 config->slow_ppt_limit_tablet_mode_mW);
Chris Wang4735b1c2020-07-13 23:29:29 +0800218 /* Scope (\_SB) */
219 acpigen_write_scope("\\_SB");
220
221 /* Method(DPTC, 0, Serialized) */
222 acpigen_write_method_serialized("DPTC", 0);
223
224 /* If (LEqual ("\_SB.PCI0.LPCB.EC0.TBMD", 1)) */
225 acpigen_write_if_lequal_namestr_int("\\_SB.PCI0.LPCB.EC0.TBMD", 1);
226
227 dptc_call_alib("TABB", (uint8_t *)(void *)&tablet_mode_input,
228 sizeof(tablet_mode_input));
229
230 acpigen_pop_len(); /* If */
231
232 /* 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 -0600243/* Used by \_SB.PCI0._CRS */
244static void root_complex_fill_ssdt(const struct device *device)
245{
246 msr_t msr;
John Zhaof6f1f732020-06-26 10:00:02 -0700247 const char *scope;
Marshall Dawsoneb724872019-07-16 15:46:35 -0600248
John Zhaof6f1f732020-06-26 10:00:02 -0700249 assert(device);
Felix Held3858fb12020-06-27 15:11:36 +0200250
John Zhaof6f1f732020-06-26 10:00:02 -0700251 scope = acpi_device_scope(device);
252 assert(scope);
253 acpigen_write_scope(scope);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600254
255 msr = rdmsr(TOP_MEM);
256 acpigen_write_name_dword("TOM1", msr.lo);
257 msr = rdmsr(TOP_MEM2);
258 /*
259 * Since XP only implements parts of ACPI 2.0, we can't use a qword
260 * here.
261 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
262 * slide 22ff.
263 * Shift value right by 20 bit to make it fit into 32bit,
264 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
265 */
266 acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
267 acpigen_pop_len();
Chris Wang4735b1c2020-07-13 23:29:29 +0800268 acipgen_dptci();
Marshall Dawsoneb724872019-07-16 15:46:35 -0600269}
270
271static struct device_operations root_complex_operations = {
272 .read_resources = read_resources,
Felix Held9541d172021-01-05 00:56:10 +0100273 .set_resources = noop_set_resources,
Marshall Dawsoneb724872019-07-16 15:46:35 -0600274 .enable_resources = pci_dev_enable_resources,
Felix Heldf9608cd2020-12-03 16:57:02 +0100275 .init = root_complex_init,
Marshall Dawsoneb724872019-07-16 15:46:35 -0600276 .acpi_fill_ssdt = root_complex_fill_ssdt,
277};
278
279static const struct pci_driver family17_root_complex __pci_driver = {
280 .ops = &root_complex_operations,
281 .vendor = PCI_VENDOR_ID_AMD,
282 .device = PCI_DEVICE_ID_AMD_17H_MODEL_101F_NB,
283};