blob: c0b444fa36bb135eb1f2fada215e9b788441a399 [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
Felix Heldef511572021-05-07 19:02:45 +020021#define DPTC_TOTAL_UPDATE_PARAMS 4
22
Chris Wang4735b1c2020-07-13 23:29:29 +080023struct dptc_param {
24 uint8_t id;
25 uint32_t value;
26} __packed;
27
28struct dptc_input {
29 uint16_t size;
30 struct dptc_param params[DPTC_TOTAL_UPDATE_PARAMS];
31} __packed;
32
Kevin Chiucdd9f5c2020-09-18 17:30:30 +080033#define DPTC_INPUTS(_thermctllmit, _sustained, _fast, _slow) \
Felix Held3acafa22021-05-07 19:17:51 +020034 { \
35 .size = sizeof(struct dptc_input), \
36 .params = { \
37 { \
38 .id = ALIB_DPTC_THERMAL_CONTROL_LIMIT_ID, \
39 .value = _thermctllmit, \
Chris Wang4735b1c2020-07-13 23:29:29 +080040 }, \
Felix Held3acafa22021-05-07 19:17:51 +020041 { \
42 .id = ALIB_DPTC_SUSTAINED_POWER_LIMIT_ID, \
43 .value = _sustained, \
44 }, \
45 { \
46 .id = ALIB_DPTC_FAST_PPT_LIMIT_ID, \
47 .value = _fast, \
48 }, \
49 { \
50 .id = ALIB_DPTC_SLOW_PPT_LIMIT_ID, \
51 .value = _slow, \
52 }, \
53 }, \
54 }
Furquan Shaikhbc456502020-06-10 16:37:23 -070055/*
56 *
57 * +--------------------------------+
58 * | |
59 * | |
60 * | |
61 * | |
62 * | |
63 * | |
64 * | |
65 * reserved_dram_end +--------------------------------+
66 * | |
67 * | verstage (if reqd) |
68 * | (VERSTAGE_SIZE) |
69 * +--------------------------------+ VERSTAGE_ADDR
70 * | |
71 * | FSP-M |
72 * | (FSP_M_SIZE) |
73 * +--------------------------------+ FSP_M_ADDR
Furquan Shaikhbc456502020-06-10 16:37:23 -070074 * | romstage |
75 * | (ROMSTAGE_SIZE) |
Kyösti Mälkkib3621f82020-12-04 19:51:17 +020076 * +--------------------------------+ ROMSTAGE_ADDR = BOOTBLOCK_END
77 * | | X86_RESET_VECTOR = BOOTBLOCK_END - 0x10
Furquan Shaikhbc456502020-06-10 16:37:23 -070078 * | bootblock |
79 * | (C_ENV_BOOTBLOCK_SIZE) |
Kyösti Mälkkib3621f82020-12-04 19:51:17 +020080 * +--------------------------------+ BOOTBLOCK_ADDR = BOOTBLOCK_END - C_ENV_BOOTBLOCK_SIZE
Furquan Shaikhbc456502020-06-10 16:37:23 -070081 * | Unused hole |
82 * | (86KiB) |
83 * +--------------------------------+
84 * | FMAP cache (FMAP_SIZE) |
85 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE + 0x200
86 * | Early Timestamp region (512B) |
87 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE
88 * | Preram CBMEM console |
89 * | (PRERAM_CBMEM_CONSOLE_SIZE) |
90 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE
91 * | PSP shared (vboot workbuf) |
92 * | (PSP_SHAREDMEM_SIZE) |
93 * +--------------------------------+ PSP_SHAREDMEM_BASE
94 * | APOB (64KiB) |
95 * +--------------------------------+ PSP_APOB_DRAM_ADDRESS
96 * | Early BSP stack |
97 * | (EARLYRAM_BSP_STACK_SIZE) |
98 * reserved_dram_start +--------------------------------+ EARLY_RESERVED_DRAM_BASE
99 * | DRAM |
100 * +--------------------------------+ 0x100000
101 * | Option ROM |
102 * +--------------------------------+ 0xc0000
103 * | Legacy VGA |
104 * +--------------------------------+ 0xa0000
105 * | DRAM |
106 * +--------------------------------+ 0x0
107 */
Marshall Dawsoneb724872019-07-16 15:46:35 -0600108static void read_resources(struct device *dev)
109{
110 uint32_t mem_usable = (uintptr_t)cbmem_top();
111 unsigned int idx = 0;
112 const struct hob_header *hob = fsp_get_hob_list();
113 const struct hob_resource *res;
Marshall Dawson39c64b02020-09-04 12:07:27 -0600114 struct resource *gnb_apic;
Marshall Dawsoneb724872019-07-16 15:46:35 -0600115
Furquan Shaikhbc456502020-06-10 16:37:23 -0700116 uintptr_t early_reserved_dram_start, early_reserved_dram_end;
117 const struct memmap_early_dram *e = memmap_get_early_dram_usage();
118
119 early_reserved_dram_start = e->base;
120 early_reserved_dram_end = e->base + e->size;
121
Marshall Dawsoneb724872019-07-16 15:46:35 -0600122 /* 0x0 - 0x9ffff */
123 ram_resource(dev, idx++, 0, 0xa0000 / KiB);
124
125 /* 0xa0000 - 0xbffff: legacy VGA */
126 mmio_resource(dev, idx++, 0xa0000 / KiB, 0x20000 / KiB);
127
128 /* 0xc0000 - 0xfffff: Option ROM */
129 reserved_ram_resource(dev, idx++, 0xc0000 / KiB, 0x40000 / KiB);
130
Furquan Shaikhbc456502020-06-10 16:37:23 -0700131 /* 1MB - bottom of DRAM reserved for early coreboot usage */
132 ram_resource(dev, idx++, (1 * MiB) / KiB,
133 (early_reserved_dram_start - (1 * MiB)) / KiB);
134
135 /* DRAM reserved for early coreboot usage */
136 reserved_ram_resource(dev, idx++, early_reserved_dram_start / KiB,
137 (early_reserved_dram_end - early_reserved_dram_start) / KiB);
138
139 /* top of DRAM consumed early - low top usable RAM
140 * cbmem_top() accounts for low UMA and TSEG if they are used. */
141 ram_resource(dev, idx++, early_reserved_dram_end / KiB,
142 (mem_usable - early_reserved_dram_end) / KiB);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600143
144 mmconf_resource(dev, MMIO_CONF_BASE);
145
146 if (!hob) {
147 printk(BIOS_ERR, "Error: %s incomplete because no HOB list was found\n",
148 __func__);
149 return;
150 }
151
152 for (; hob->type != HOB_TYPE_END_OF_HOB_LIST; hob = fsp_next_hob(hob)) {
153
154 if (hob->type != HOB_TYPE_RESOURCE_DESCRIPTOR)
155 continue;
156
157 res = fsp_hob_header_to_resource(hob);
158
159 if (res->type == EFI_RESOURCE_SYSTEM_MEMORY && res->addr < mem_usable)
160 continue; /* 0 through low usable was set above */
161 if (res->type == EFI_RESOURCE_MEMORY_MAPPED_IO)
162 continue; /* Done separately */
163
164 if (res->type == EFI_RESOURCE_SYSTEM_MEMORY)
165 ram_resource(dev, idx++, res->addr / KiB, res->length / KiB);
166 else if (res->type == EFI_RESOURCE_MEMORY_RESERVED)
167 reserved_ram_resource(dev, idx++, res->addr / KiB, res->length / KiB);
168 else
169 printk(BIOS_ERR, "Error: failed to set resources for type %d\n",
170 res->type);
171 }
Marshall Dawson39c64b02020-09-04 12:07:27 -0600172
173 /* GNB IOAPIC resource */
174 gnb_apic = new_resource(dev, GNB_IO_APIC_ADDR);
175 gnb_apic->base = GNB_IO_APIC_ADDR;
176 gnb_apic->size = 0x00001000;
177 gnb_apic->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
Marshall Dawsoneb724872019-07-16 15:46:35 -0600178}
179
Felix Heldf9608cd2020-12-03 16:57:02 +0100180static void root_complex_init(struct device *dev)
181{
Felix Held604ffa62021-02-12 00:43:20 +0100182 setup_ioapic((u8 *)GNB_IO_APIC_ADDR, GNB_IOAPIC_ID);
Felix Heldf9608cd2020-12-03 16:57:02 +0100183}
184
Chris Wang4735b1c2020-07-13 23:29:29 +0800185static void dptc_call_alib(const char *buf_name, uint8_t *buffer, size_t size)
186{
187 /* Name (buf_name, Buffer(size) {...} */
188 acpigen_write_name(buf_name);
189 acpigen_write_byte_buffer(buffer, size);
190
191 /* \_SB.ALIB(0xc, buf_name) */
192 acpigen_emit_namestring("\\_SB.ALIB");
Felix Held95f1bb82021-05-07 18:46:36 +0200193 acpigen_write_integer(ALIB_FUNCTION_DYNAMIC_POWER_THERMAL_CONFIG);
Chris Wang4735b1c2020-07-13 23:29:29 +0800194 acpigen_emit_namestring(buf_name);
195}
196
197static void acipgen_dptci(void)
198{
Felix Held507fc032020-12-05 01:55:27 +0100199 const struct soc_amd_picasso_config *config = config_of_soc();
Chris Wang4735b1c2020-07-13 23:29:29 +0800200
201 if (!config->dptc_enable)
202 return;
203
Zheng Bao795d73c2020-10-27 15:36:55 +0800204 struct dptc_input default_input = DPTC_INPUTS(config->thermctl_limit_degreeC,
205 config->sustained_power_limit_mW,
206 config->fast_ppt_limit_mW,
207 config->slow_ppt_limit_mW);
Chris Wang4735b1c2020-07-13 23:29:29 +0800208 struct dptc_input tablet_mode_input = DPTC_INPUTS(
Zheng Bao795d73c2020-10-27 15:36:55 +0800209 config->thermctl_limit_tablet_mode_degreeC,
210 config->sustained_power_limit_tablet_mode_mW,
211 config->fast_ppt_limit_tablet_mode_mW,
212 config->slow_ppt_limit_tablet_mode_mW);
Chris Wang4735b1c2020-07-13 23:29:29 +0800213 /* Scope (\_SB) */
214 acpigen_write_scope("\\_SB");
215
216 /* Method(DPTC, 0, Serialized) */
217 acpigen_write_method_serialized("DPTC", 0);
218
219 /* If (LEqual ("\_SB.PCI0.LPCB.EC0.TBMD", 1)) */
220 acpigen_write_if_lequal_namestr_int("\\_SB.PCI0.LPCB.EC0.TBMD", 1);
221
222 dptc_call_alib("TABB", (uint8_t *)(void *)&tablet_mode_input,
223 sizeof(tablet_mode_input));
224
Chris Wang4735b1c2020-07-13 23:29:29 +0800225 /* Else */
226 acpigen_write_else();
227
228 dptc_call_alib("DEFB", (uint8_t *)(void *)&default_input, sizeof(default_input));
229
230 acpigen_pop_len(); /* Else */
231
232 acpigen_pop_len(); /* Method DPTC */
233 acpigen_pop_len(); /* Scope \_SB */
234}
235
Marshall Dawsoneb724872019-07-16 15:46:35 -0600236static void root_complex_fill_ssdt(const struct device *device)
237{
Raul E Rangel58a8ad12021-02-18 16:36:08 -0700238 acpi_fill_root_complex_tom(device);
Chris Wang4735b1c2020-07-13 23:29:29 +0800239 acipgen_dptci();
Marshall Dawsoneb724872019-07-16 15:46:35 -0600240}
241
Felix Heldff092d42021-02-17 00:04:59 +0100242static const char *gnb_acpi_name(const struct device *dev)
243{
244 return "GNB";
245}
246
Marshall Dawsoneb724872019-07-16 15:46:35 -0600247static struct device_operations root_complex_operations = {
248 .read_resources = read_resources,
Felix Held9541d172021-01-05 00:56:10 +0100249 .set_resources = noop_set_resources,
Marshall Dawsoneb724872019-07-16 15:46:35 -0600250 .enable_resources = pci_dev_enable_resources,
Felix Heldf9608cd2020-12-03 16:57:02 +0100251 .init = root_complex_init,
Felix Heldff092d42021-02-17 00:04:59 +0100252 .acpi_name = gnb_acpi_name,
Marshall Dawsoneb724872019-07-16 15:46:35 -0600253 .acpi_fill_ssdt = root_complex_fill_ssdt,
254};
255
256static const struct pci_driver family17_root_complex __pci_driver = {
257 .ops = &root_complex_operations,
258 .vendor = PCI_VENDOR_ID_AMD,
259 .device = PCI_DEVICE_ID_AMD_17H_MODEL_101F_NB,
260};