blob: 6c721e17c8118556eb8ec926f21ec457f1e4afb8 [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,
20 SUSTAINED_POWER_LIMIT_PARAM_ID = 0x5,
21 FAST_PPT_LIMIT_PARAM_ID = 0x6,
22 SLOW_PPT_LIMIT_PARAM_ID = 0x7,
23 DPTC_TOTAL_UPDATE_PARAMS = 3,
24};
25
26struct dptc_param {
27 uint8_t id;
28 uint32_t value;
29} __packed;
30
31struct dptc_input {
32 uint16_t size;
33 struct dptc_param params[DPTC_TOTAL_UPDATE_PARAMS];
34} __packed;
35
36#define DPTC_INPUTS(_sustained, _fast, _slow) \
37 { \
38 .size = sizeof(struct dptc_input), \
39 .params = { \
40 { \
41 .id = SUSTAINED_POWER_LIMIT_PARAM_ID, \
42 .value = _sustained, \
43 }, \
44 { \
45 .id = FAST_PPT_LIMIT_PARAM_ID, \
46 .value = _fast, \
47 }, \
48 { \
49 .id = SLOW_PPT_LIMIT_PARAM_ID, \
50 .value = _slow, \
51 }, \
52 }, \
53 }
Furquan Shaikhbc456502020-06-10 16:37:23 -070054/*
55 *
56 * +--------------------------------+
57 * | |
58 * | |
59 * | |
60 * | |
61 * | |
62 * | |
63 * | |
64 * reserved_dram_end +--------------------------------+
65 * | |
66 * | verstage (if reqd) |
67 * | (VERSTAGE_SIZE) |
68 * +--------------------------------+ VERSTAGE_ADDR
69 * | |
70 * | FSP-M |
71 * | (FSP_M_SIZE) |
72 * +--------------------------------+ FSP_M_ADDR
73 * | |X86_RESET_VECTOR = ROMSTAGE_ADDR + ROMSTAGE_SIZE - 0x10
74 * | romstage |
75 * | (ROMSTAGE_SIZE) |
76 * +--------------------------------+ ROMSTAGE_ADDR
77 * | bootblock |
78 * | (C_ENV_BOOTBLOCK_SIZE) |
79 * +--------------------------------+ BOOTBLOCK_ADDR
80 * | Unused hole |
81 * | (86KiB) |
82 * +--------------------------------+
83 * | FMAP cache (FMAP_SIZE) |
84 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE + 0x200
85 * | Early Timestamp region (512B) |
86 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE
87 * | Preram CBMEM console |
88 * | (PRERAM_CBMEM_CONSOLE_SIZE) |
89 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE
90 * | PSP shared (vboot workbuf) |
91 * | (PSP_SHAREDMEM_SIZE) |
92 * +--------------------------------+ PSP_SHAREDMEM_BASE
93 * | APOB (64KiB) |
94 * +--------------------------------+ PSP_APOB_DRAM_ADDRESS
95 * | Early BSP stack |
96 * | (EARLYRAM_BSP_STACK_SIZE) |
97 * reserved_dram_start +--------------------------------+ EARLY_RESERVED_DRAM_BASE
98 * | DRAM |
99 * +--------------------------------+ 0x100000
100 * | Option ROM |
101 * +--------------------------------+ 0xc0000
102 * | Legacy VGA |
103 * +--------------------------------+ 0xa0000
104 * | DRAM |
105 * +--------------------------------+ 0x0
106 */
Marshall Dawsoneb724872019-07-16 15:46:35 -0600107static void read_resources(struct device *dev)
108{
109 uint32_t mem_usable = (uintptr_t)cbmem_top();
110 unsigned int idx = 0;
111 const struct hob_header *hob = fsp_get_hob_list();
112 const struct hob_resource *res;
Marshall Dawson39c64b02020-09-04 12:07:27 -0600113 struct resource *gnb_apic;
Marshall Dawsoneb724872019-07-16 15:46:35 -0600114
Furquan Shaikhbc456502020-06-10 16:37:23 -0700115 uintptr_t early_reserved_dram_start, early_reserved_dram_end;
116 const struct memmap_early_dram *e = memmap_get_early_dram_usage();
117
118 early_reserved_dram_start = e->base;
119 early_reserved_dram_end = e->base + e->size;
120
Marshall Dawsoneb724872019-07-16 15:46:35 -0600121 /* 0x0 - 0x9ffff */
122 ram_resource(dev, idx++, 0, 0xa0000 / KiB);
123
124 /* 0xa0000 - 0xbffff: legacy VGA */
125 mmio_resource(dev, idx++, 0xa0000 / KiB, 0x20000 / KiB);
126
127 /* 0xc0000 - 0xfffff: Option ROM */
128 reserved_ram_resource(dev, idx++, 0xc0000 / KiB, 0x40000 / KiB);
129
Furquan Shaikhbc456502020-06-10 16:37:23 -0700130 /* 1MB - bottom of DRAM reserved for early coreboot usage */
131 ram_resource(dev, idx++, (1 * MiB) / KiB,
132 (early_reserved_dram_start - (1 * MiB)) / KiB);
133
134 /* DRAM reserved for early coreboot usage */
135 reserved_ram_resource(dev, idx++, early_reserved_dram_start / KiB,
136 (early_reserved_dram_end - early_reserved_dram_start) / KiB);
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 ram_resource(dev, idx++, early_reserved_dram_end / KiB,
141 (mem_usable - early_reserved_dram_end) / KiB);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600142
143 mmconf_resource(dev, MMIO_CONF_BASE);
144
145 if (!hob) {
146 printk(BIOS_ERR, "Error: %s incomplete because no HOB list was found\n",
147 __func__);
148 return;
149 }
150
151 for (; hob->type != HOB_TYPE_END_OF_HOB_LIST; hob = fsp_next_hob(hob)) {
152
153 if (hob->type != HOB_TYPE_RESOURCE_DESCRIPTOR)
154 continue;
155
156 res = fsp_hob_header_to_resource(hob);
157
158 if (res->type == EFI_RESOURCE_SYSTEM_MEMORY && res->addr < mem_usable)
159 continue; /* 0 through low usable was set above */
160 if (res->type == EFI_RESOURCE_MEMORY_MAPPED_IO)
161 continue; /* Done separately */
162
163 if (res->type == EFI_RESOURCE_SYSTEM_MEMORY)
164 ram_resource(dev, idx++, res->addr / KiB, res->length / KiB);
165 else if (res->type == EFI_RESOURCE_MEMORY_RESERVED)
166 reserved_ram_resource(dev, idx++, res->addr / KiB, res->length / KiB);
167 else
168 printk(BIOS_ERR, "Error: failed to set resources for type %d\n",
169 res->type);
170 }
Marshall Dawson39c64b02020-09-04 12:07:27 -0600171
172 /* GNB IOAPIC resource */
173 gnb_apic = new_resource(dev, GNB_IO_APIC_ADDR);
174 gnb_apic->base = GNB_IO_APIC_ADDR;
175 gnb_apic->size = 0x00001000;
176 gnb_apic->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
Marshall Dawsoneb724872019-07-16 15:46:35 -0600177}
178
Chris Wang4735b1c2020-07-13 23:29:29 +0800179static void dptc_call_alib(const char *buf_name, uint8_t *buffer, size_t size)
180{
181 /* Name (buf_name, Buffer(size) {...} */
182 acpigen_write_name(buf_name);
183 acpigen_write_byte_buffer(buffer, size);
184
185 /* \_SB.ALIB(0xc, buf_name) */
186 acpigen_emit_namestring("\\_SB.ALIB");
187 acpigen_write_integer(ALIB_DPTCI_FUNCTION_ID);
188 acpigen_emit_namestring(buf_name);
189}
190
191static void acipgen_dptci(void)
192{
193 const config_t *config = config_of_soc();
194
195 if (!config->dptc_enable)
196 return;
197
198 struct dptc_input default_input = DPTC_INPUTS(config->sustained_power_limit,
199 config->fast_ppt_limit,
200 config->slow_ppt_limit);
201 struct dptc_input tablet_mode_input = DPTC_INPUTS(
202 config->sustained_power_limit_tablet_mode,
203 config->fast_ppt_limit_tablet_mode,
204 config->slow_ppt_limit_tablet_mode);
205 /* Scope (\_SB) */
206 acpigen_write_scope("\\_SB");
207
208 /* Method(DPTC, 0, Serialized) */
209 acpigen_write_method_serialized("DPTC", 0);
210
211 /* If (LEqual ("\_SB.PCI0.LPCB.EC0.TBMD", 1)) */
212 acpigen_write_if_lequal_namestr_int("\\_SB.PCI0.LPCB.EC0.TBMD", 1);
213
214 dptc_call_alib("TABB", (uint8_t *)(void *)&tablet_mode_input,
215 sizeof(tablet_mode_input));
216
217 acpigen_pop_len(); /* If */
218
219 /* Else */
220 acpigen_write_else();
221
222 dptc_call_alib("DEFB", (uint8_t *)(void *)&default_input, sizeof(default_input));
223
224 acpigen_pop_len(); /* Else */
225
226 acpigen_pop_len(); /* Method DPTC */
227 acpigen_pop_len(); /* Scope \_SB */
228}
229
Marshall Dawsoneb724872019-07-16 15:46:35 -0600230/* Used by \_SB.PCI0._CRS */
231static void root_complex_fill_ssdt(const struct device *device)
232{
233 msr_t msr;
John Zhaof6f1f732020-06-26 10:00:02 -0700234 const char *scope;
Marshall Dawsoneb724872019-07-16 15:46:35 -0600235
John Zhaof6f1f732020-06-26 10:00:02 -0700236 assert(device);
Felix Held3858fb12020-06-27 15:11:36 +0200237
John Zhaof6f1f732020-06-26 10:00:02 -0700238 scope = acpi_device_scope(device);
239 assert(scope);
240 acpigen_write_scope(scope);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600241
242 msr = rdmsr(TOP_MEM);
243 acpigen_write_name_dword("TOM1", msr.lo);
244 msr = rdmsr(TOP_MEM2);
245 /*
246 * Since XP only implements parts of ACPI 2.0, we can't use a qword
247 * here.
248 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
249 * slide 22ff.
250 * Shift value right by 20 bit to make it fit into 32bit,
251 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
252 */
253 acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
254 acpigen_pop_len();
Chris Wang4735b1c2020-07-13 23:29:29 +0800255 acipgen_dptci();
Marshall Dawsoneb724872019-07-16 15:46:35 -0600256}
257
258static struct device_operations root_complex_operations = {
259 .read_resources = read_resources,
260 .enable_resources = pci_dev_enable_resources,
261 .acpi_fill_ssdt = root_complex_fill_ssdt,
262};
263
264static const struct pci_driver family17_root_complex __pci_driver = {
265 .ops = &root_complex_operations,
266 .vendor = PCI_VENDOR_ID_AMD,
267 .device = PCI_DEVICE_ID_AMD_17H_MODEL_101F_NB,
268};