blob: 259419cb97e290228ee8513332d53b7492ce5bbd [file] [log] [blame]
Marshall Dawsoneb724872019-07-16 15:46:35 -06001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <acpi/acpigen.h>
John Zhaof6f1f732020-06-26 10:00:02 -07004#include <assert.h>
Marshall Dawsoneb724872019-07-16 15:46:35 -06005#include <cbmem.h>
6#include <console/console.h>
7#include <cpu/amd/msr.h>
8#include <cpu/amd/mtrr.h>
9#include <device/device.h>
10#include <device/pci.h>
11#include <device/pci_ids.h>
12#include <fsp/util.h>
13#include <stdint.h>
Furquan Shaikhbc456502020-06-10 16:37:23 -070014#include <soc/memmap.h>
Marshall Dawson39c64b02020-09-04 12:07:27 -060015#include <soc/iomap.h>
Chris Wang4735b1c2020-07-13 23:29:29 +080016#include "chip.h"
Marshall Dawsoneb724872019-07-16 15:46:35 -060017
Chris Wang4735b1c2020-07-13 23:29:29 +080018enum {
19 ALIB_DPTCI_FUNCTION_ID = 0xc,
Kevin Chiucdd9f5c2020-09-18 17:30:30 +080020 THERMAL_CONTROL_LIMIT_ID = 0x3,
Chris Wang4735b1c2020-07-13 23:29:29 +080021 SUSTAINED_POWER_LIMIT_PARAM_ID = 0x5,
22 FAST_PPT_LIMIT_PARAM_ID = 0x6,
23 SLOW_PPT_LIMIT_PARAM_ID = 0x7,
Kevin Chiucdd9f5c2020-09-18 17:30:30 +080024 DPTC_TOTAL_UPDATE_PARAMS = 4,
Chris Wang4735b1c2020-07-13 23:29:29 +080025};
26
27struct dptc_param {
28 uint8_t id;
29 uint32_t value;
30} __packed;
31
32struct dptc_input {
33 uint16_t size;
34 struct dptc_param params[DPTC_TOTAL_UPDATE_PARAMS];
35} __packed;
36
Kevin Chiucdd9f5c2020-09-18 17:30:30 +080037#define DPTC_INPUTS(_thermctllmit, _sustained, _fast, _slow) \
Chris Wang4735b1c2020-07-13 23:29:29 +080038 { \
39 .size = sizeof(struct dptc_input), \
40 .params = { \
41 { \
Kevin Chiucdd9f5c2020-09-18 17:30:30 +080042 .id = THERMAL_CONTROL_LIMIT_ID, \
43 .value = _thermctllmit, \
44 }, \
45 { \
Chris Wang4735b1c2020-07-13 23:29:29 +080046 .id = SUSTAINED_POWER_LIMIT_PARAM_ID, \
47 .value = _sustained, \
48 }, \
49 { \
50 .id = FAST_PPT_LIMIT_PARAM_ID, \
51 .value = _fast, \
52 }, \
53 { \
54 .id = SLOW_PPT_LIMIT_PARAM_ID, \
55 .value = _slow, \
56 }, \
57 }, \
58 }
Furquan Shaikhbc456502020-06-10 16:37:23 -070059/*
60 *
61 * +--------------------------------+
62 * | |
63 * | |
64 * | |
65 * | |
66 * | |
67 * | |
68 * | |
69 * reserved_dram_end +--------------------------------+
70 * | |
71 * | verstage (if reqd) |
72 * | (VERSTAGE_SIZE) |
73 * +--------------------------------+ VERSTAGE_ADDR
74 * | |
75 * | FSP-M |
76 * | (FSP_M_SIZE) |
77 * +--------------------------------+ FSP_M_ADDR
Furquan Shaikhbc456502020-06-10 16:37:23 -070078 * | romstage |
79 * | (ROMSTAGE_SIZE) |
80 * +--------------------------------+ ROMSTAGE_ADDR
Kyösti Mälkki21cad6c2020-12-04 19:52:08 +020081 * | | X86_RESET_VECTOR = BOOTBLOCK_ADDR + C_ENV_BOOTBLOCK_SIZE - 0x10
Furquan Shaikhbc456502020-06-10 16:37:23 -070082 * | bootblock |
83 * | (C_ENV_BOOTBLOCK_SIZE) |
84 * +--------------------------------+ BOOTBLOCK_ADDR
85 * | Unused hole |
86 * | (86KiB) |
87 * +--------------------------------+
88 * | FMAP cache (FMAP_SIZE) |
89 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE + 0x200
90 * | Early Timestamp region (512B) |
91 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE
92 * | Preram CBMEM console |
93 * | (PRERAM_CBMEM_CONSOLE_SIZE) |
94 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE
95 * | PSP shared (vboot workbuf) |
96 * | (PSP_SHAREDMEM_SIZE) |
97 * +--------------------------------+ PSP_SHAREDMEM_BASE
98 * | APOB (64KiB) |
99 * +--------------------------------+ PSP_APOB_DRAM_ADDRESS
100 * | Early BSP stack |
101 * | (EARLYRAM_BSP_STACK_SIZE) |
102 * reserved_dram_start +--------------------------------+ EARLY_RESERVED_DRAM_BASE
103 * | DRAM |
104 * +--------------------------------+ 0x100000
105 * | Option ROM |
106 * +--------------------------------+ 0xc0000
107 * | Legacy VGA |
108 * +--------------------------------+ 0xa0000
109 * | DRAM |
110 * +--------------------------------+ 0x0
111 */
Marshall Dawsoneb724872019-07-16 15:46:35 -0600112static void read_resources(struct device *dev)
113{
114 uint32_t mem_usable = (uintptr_t)cbmem_top();
115 unsigned int idx = 0;
116 const struct hob_header *hob = fsp_get_hob_list();
117 const struct hob_resource *res;
Marshall Dawson39c64b02020-09-04 12:07:27 -0600118 struct resource *gnb_apic;
Marshall Dawsoneb724872019-07-16 15:46:35 -0600119
Furquan Shaikhbc456502020-06-10 16:37:23 -0700120 uintptr_t early_reserved_dram_start, early_reserved_dram_end;
121 const struct memmap_early_dram *e = memmap_get_early_dram_usage();
122
123 early_reserved_dram_start = e->base;
124 early_reserved_dram_end = e->base + e->size;
125
Marshall Dawsoneb724872019-07-16 15:46:35 -0600126 /* 0x0 - 0x9ffff */
127 ram_resource(dev, idx++, 0, 0xa0000 / KiB);
128
129 /* 0xa0000 - 0xbffff: legacy VGA */
130 mmio_resource(dev, idx++, 0xa0000 / KiB, 0x20000 / KiB);
131
132 /* 0xc0000 - 0xfffff: Option ROM */
133 reserved_ram_resource(dev, idx++, 0xc0000 / KiB, 0x40000 / KiB);
134
Furquan Shaikhbc456502020-06-10 16:37:23 -0700135 /* 1MB - bottom of DRAM reserved for early coreboot usage */
136 ram_resource(dev, idx++, (1 * MiB) / KiB,
137 (early_reserved_dram_start - (1 * MiB)) / KiB);
138
139 /* DRAM reserved for early coreboot usage */
140 reserved_ram_resource(dev, idx++, early_reserved_dram_start / KiB,
141 (early_reserved_dram_end - early_reserved_dram_start) / KiB);
142
143 /* top of DRAM consumed early - low top usable RAM
144 * cbmem_top() accounts for low UMA and TSEG if they are used. */
145 ram_resource(dev, idx++, early_reserved_dram_end / KiB,
146 (mem_usable - early_reserved_dram_end) / KiB);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600147
148 mmconf_resource(dev, MMIO_CONF_BASE);
149
150 if (!hob) {
151 printk(BIOS_ERR, "Error: %s incomplete because no HOB list was found\n",
152 __func__);
153 return;
154 }
155
156 for (; hob->type != HOB_TYPE_END_OF_HOB_LIST; hob = fsp_next_hob(hob)) {
157
158 if (hob->type != HOB_TYPE_RESOURCE_DESCRIPTOR)
159 continue;
160
161 res = fsp_hob_header_to_resource(hob);
162
163 if (res->type == EFI_RESOURCE_SYSTEM_MEMORY && res->addr < mem_usable)
164 continue; /* 0 through low usable was set above */
165 if (res->type == EFI_RESOURCE_MEMORY_MAPPED_IO)
166 continue; /* Done separately */
167
168 if (res->type == EFI_RESOURCE_SYSTEM_MEMORY)
169 ram_resource(dev, idx++, res->addr / KiB, res->length / KiB);
170 else if (res->type == EFI_RESOURCE_MEMORY_RESERVED)
171 reserved_ram_resource(dev, idx++, res->addr / KiB, res->length / KiB);
172 else
173 printk(BIOS_ERR, "Error: failed to set resources for type %d\n",
174 res->type);
175 }
Marshall Dawson39c64b02020-09-04 12:07:27 -0600176
177 /* GNB IOAPIC resource */
178 gnb_apic = new_resource(dev, GNB_IO_APIC_ADDR);
179 gnb_apic->base = GNB_IO_APIC_ADDR;
180 gnb_apic->size = 0x00001000;
181 gnb_apic->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
Marshall Dawsoneb724872019-07-16 15:46:35 -0600182}
183
Chris Wang4735b1c2020-07-13 23:29:29 +0800184static void dptc_call_alib(const char *buf_name, uint8_t *buffer, size_t size)
185{
186 /* Name (buf_name, Buffer(size) {...} */
187 acpigen_write_name(buf_name);
188 acpigen_write_byte_buffer(buffer, size);
189
190 /* \_SB.ALIB(0xc, buf_name) */
191 acpigen_emit_namestring("\\_SB.ALIB");
192 acpigen_write_integer(ALIB_DPTCI_FUNCTION_ID);
193 acpigen_emit_namestring(buf_name);
194}
195
196static void acipgen_dptci(void)
197{
Felix Held507fc032020-12-05 01:55:27 +0100198 const struct soc_amd_picasso_config *config = config_of_soc();
Chris Wang4735b1c2020-07-13 23:29:29 +0800199
200 if (!config->dptc_enable)
201 return;
202
Zheng Bao795d73c2020-10-27 15:36:55 +0800203 struct dptc_input default_input = DPTC_INPUTS(config->thermctl_limit_degreeC,
204 config->sustained_power_limit_mW,
205 config->fast_ppt_limit_mW,
206 config->slow_ppt_limit_mW);
Chris Wang4735b1c2020-07-13 23:29:29 +0800207 struct dptc_input tablet_mode_input = DPTC_INPUTS(
Zheng Bao795d73c2020-10-27 15:36:55 +0800208 config->thermctl_limit_tablet_mode_degreeC,
209 config->sustained_power_limit_tablet_mode_mW,
210 config->fast_ppt_limit_tablet_mode_mW,
211 config->slow_ppt_limit_tablet_mode_mW);
Chris Wang4735b1c2020-07-13 23:29:29 +0800212 /* Scope (\_SB) */
213 acpigen_write_scope("\\_SB");
214
215 /* Method(DPTC, 0, Serialized) */
216 acpigen_write_method_serialized("DPTC", 0);
217
218 /* If (LEqual ("\_SB.PCI0.LPCB.EC0.TBMD", 1)) */
219 acpigen_write_if_lequal_namestr_int("\\_SB.PCI0.LPCB.EC0.TBMD", 1);
220
221 dptc_call_alib("TABB", (uint8_t *)(void *)&tablet_mode_input,
222 sizeof(tablet_mode_input));
223
224 acpigen_pop_len(); /* If */
225
226 /* Else */
227 acpigen_write_else();
228
229 dptc_call_alib("DEFB", (uint8_t *)(void *)&default_input, sizeof(default_input));
230
231 acpigen_pop_len(); /* Else */
232
233 acpigen_pop_len(); /* Method DPTC */
234 acpigen_pop_len(); /* Scope \_SB */
235}
236
Marshall Dawsoneb724872019-07-16 15:46:35 -0600237/* Used by \_SB.PCI0._CRS */
238static void root_complex_fill_ssdt(const struct device *device)
239{
240 msr_t msr;
John Zhaof6f1f732020-06-26 10:00:02 -0700241 const char *scope;
Marshall Dawsoneb724872019-07-16 15:46:35 -0600242
John Zhaof6f1f732020-06-26 10:00:02 -0700243 assert(device);
Felix Held3858fb12020-06-27 15:11:36 +0200244
John Zhaof6f1f732020-06-26 10:00:02 -0700245 scope = acpi_device_scope(device);
246 assert(scope);
247 acpigen_write_scope(scope);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600248
249 msr = rdmsr(TOP_MEM);
250 acpigen_write_name_dword("TOM1", msr.lo);
251 msr = rdmsr(TOP_MEM2);
252 /*
253 * Since XP only implements parts of ACPI 2.0, we can't use a qword
254 * here.
255 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
256 * slide 22ff.
257 * Shift value right by 20 bit to make it fit into 32bit,
258 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
259 */
260 acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
261 acpigen_pop_len();
Chris Wang4735b1c2020-07-13 23:29:29 +0800262 acipgen_dptci();
Marshall Dawsoneb724872019-07-16 15:46:35 -0600263}
264
265static struct device_operations root_complex_operations = {
266 .read_resources = read_resources,
267 .enable_resources = pci_dev_enable_resources,
268 .acpi_fill_ssdt = root_complex_fill_ssdt,
269};
270
271static const struct pci_driver family17_root_complex __pci_driver = {
272 .ops = &root_complex_operations,
273 .vendor = PCI_VENDOR_ID_AMD,
274 .device = PCI_DEVICE_ID_AMD_17H_MODEL_101F_NB,
275};