blob: 9af9c0a78d91f3217a21924325496ffc434d9413 [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>
Marshall Dawsoneb724872019-07-16 15:46:35 -060015#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
Felix Heldef511572021-05-07 19:02:45 +020020#define DPTC_TOTAL_UPDATE_PARAMS 4
21
Chris Wang4735b1c2020-07-13 23:29:29 +080022struct dptc_input {
23 uint16_t size;
Felix Heldf0610172021-05-07 19:21:08 +020024 struct alib_dptc_param params[DPTC_TOTAL_UPDATE_PARAMS];
Chris Wang4735b1c2020-07-13 23:29:29 +080025} __packed;
26
Kevin Chiucdd9f5c2020-09-18 17:30:30 +080027#define DPTC_INPUTS(_thermctllmit, _sustained, _fast, _slow) \
Felix Held3acafa22021-05-07 19:17:51 +020028 { \
29 .size = sizeof(struct dptc_input), \
30 .params = { \
31 { \
32 .id = ALIB_DPTC_THERMAL_CONTROL_LIMIT_ID, \
33 .value = _thermctllmit, \
Chris Wang4735b1c2020-07-13 23:29:29 +080034 }, \
Felix Held3acafa22021-05-07 19:17:51 +020035 { \
36 .id = ALIB_DPTC_SUSTAINED_POWER_LIMIT_ID, \
37 .value = _sustained, \
38 }, \
39 { \
40 .id = ALIB_DPTC_FAST_PPT_LIMIT_ID, \
41 .value = _fast, \
42 }, \
43 { \
44 .id = ALIB_DPTC_SLOW_PPT_LIMIT_ID, \
45 .value = _slow, \
46 }, \
47 }, \
48 }
Furquan Shaikhbc456502020-06-10 16:37:23 -070049/*
50 *
51 * +--------------------------------+
52 * | |
53 * | |
54 * | |
55 * | |
56 * | |
57 * | |
58 * | |
59 * reserved_dram_end +--------------------------------+
60 * | |
61 * | verstage (if reqd) |
62 * | (VERSTAGE_SIZE) |
63 * +--------------------------------+ VERSTAGE_ADDR
64 * | |
65 * | FSP-M |
66 * | (FSP_M_SIZE) |
67 * +--------------------------------+ FSP_M_ADDR
Furquan Shaikhbc456502020-06-10 16:37:23 -070068 * | romstage |
69 * | (ROMSTAGE_SIZE) |
Kyösti Mälkkib3621f82020-12-04 19:51:17 +020070 * +--------------------------------+ ROMSTAGE_ADDR = BOOTBLOCK_END
71 * | | X86_RESET_VECTOR = BOOTBLOCK_END - 0x10
Furquan Shaikhbc456502020-06-10 16:37:23 -070072 * | bootblock |
73 * | (C_ENV_BOOTBLOCK_SIZE) |
Kyösti Mälkkib3621f82020-12-04 19:51:17 +020074 * +--------------------------------+ BOOTBLOCK_ADDR = BOOTBLOCK_END - C_ENV_BOOTBLOCK_SIZE
Furquan Shaikhbc456502020-06-10 16:37:23 -070075 * | Unused hole |
76 * | (86KiB) |
77 * +--------------------------------+
78 * | FMAP cache (FMAP_SIZE) |
79 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE + 0x200
80 * | Early Timestamp region (512B) |
81 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE
82 * | Preram CBMEM console |
83 * | (PRERAM_CBMEM_CONSOLE_SIZE) |
84 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE
85 * | PSP shared (vboot workbuf) |
86 * | (PSP_SHAREDMEM_SIZE) |
87 * +--------------------------------+ PSP_SHAREDMEM_BASE
88 * | APOB (64KiB) |
89 * +--------------------------------+ PSP_APOB_DRAM_ADDRESS
90 * | Early BSP stack |
91 * | (EARLYRAM_BSP_STACK_SIZE) |
92 * reserved_dram_start +--------------------------------+ EARLY_RESERVED_DRAM_BASE
93 * | DRAM |
94 * +--------------------------------+ 0x100000
95 * | Option ROM |
96 * +--------------------------------+ 0xc0000
97 * | Legacy VGA |
98 * +--------------------------------+ 0xa0000
99 * | DRAM |
100 * +--------------------------------+ 0x0
101 */
Marshall Dawsoneb724872019-07-16 15:46:35 -0600102static void read_resources(struct device *dev)
103{
104 uint32_t mem_usable = (uintptr_t)cbmem_top();
105 unsigned int idx = 0;
Felix Held2e814362022-11-10 22:44:18 +0100106 const struct hob_header *hob_iterator;
Marshall Dawsoneb724872019-07-16 15:46:35 -0600107 const struct hob_resource *res;
Marshall Dawson39c64b02020-09-04 12:07:27 -0600108 struct resource *gnb_apic;
Marshall Dawsoneb724872019-07-16 15:46:35 -0600109
Furquan Shaikhbc456502020-06-10 16:37:23 -0700110 uintptr_t early_reserved_dram_start, early_reserved_dram_end;
111 const struct memmap_early_dram *e = memmap_get_early_dram_usage();
112
113 early_reserved_dram_start = e->base;
114 early_reserved_dram_end = e->base + e->size;
115
Felix Heldaf17f0b2022-03-02 23:36:55 +0100116 /* The root complex has no PCI BARs implemented, so there's no need to call
117 pci_dev_read_resources for it */
118
Marshall Dawsoneb724872019-07-16 15:46:35 -0600119 /* 0x0 - 0x9ffff */
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300120 ram_resource_kb(dev, idx++, 0, 0xa0000 / KiB);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600121
122 /* 0xa0000 - 0xbffff: legacy VGA */
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300123 mmio_resource_kb(dev, idx++, 0xa0000 / KiB, 0x20000 / KiB);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600124
125 /* 0xc0000 - 0xfffff: Option ROM */
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300126 reserved_ram_resource_kb(dev, idx++, 0xc0000 / KiB, 0x40000 / KiB);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600127
Furquan Shaikhbc456502020-06-10 16:37:23 -0700128 /* 1MB - bottom of DRAM reserved for early coreboot usage */
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300129 ram_resource_kb(dev, idx++, (1 * MiB) / KiB,
Furquan Shaikhbc456502020-06-10 16:37:23 -0700130 (early_reserved_dram_start - (1 * MiB)) / KiB);
131
132 /* DRAM reserved for early coreboot usage */
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300133 reserved_ram_resource_kb(dev, idx++, early_reserved_dram_start / KiB,
Furquan Shaikhbc456502020-06-10 16:37:23 -0700134 (early_reserved_dram_end - early_reserved_dram_start) / KiB);
135
136 /* top of DRAM consumed early - low top usable RAM
137 * cbmem_top() accounts for low UMA and TSEG if they are used. */
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300138 ram_resource_kb(dev, idx++, early_reserved_dram_end / KiB,
Furquan Shaikhbc456502020-06-10 16:37:23 -0700139 (mem_usable - early_reserved_dram_end) / KiB);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600140
Felix Held56b037b2022-03-02 22:57:01 +0100141 mmconf_resource(dev, idx++);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600142
Felix Helddafc6192022-11-10 18:19:36 +0100143 /* GNB IOAPIC resource */
144 gnb_apic = new_resource(dev, idx++);
145 gnb_apic->base = GNB_IO_APIC_ADDR;
146 gnb_apic->size = 0x00001000;
147 gnb_apic->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
148
Felix Held2e814362022-11-10 22:44:18 +0100149 if (fsp_hob_iterator_init(&hob_iterator) != CB_SUCCESS) {
150 printk(BIOS_ERR, "%s incomplete because no HOB list was found\n", __func__);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600151 return;
152 }
153
Felix Held2e814362022-11-10 22:44:18 +0100154 while (fsp_hob_iterator_get_next_resource(&hob_iterator, &res) == CB_SUCCESS) {
Marshall Dawsoneb724872019-07-16 15:46:35 -0600155 if (res->type == EFI_RESOURCE_SYSTEM_MEMORY && res->addr < mem_usable)
156 continue; /* 0 through low usable was set above */
157 if (res->type == EFI_RESOURCE_MEMORY_MAPPED_IO)
158 continue; /* Done separately */
159
160 if (res->type == EFI_RESOURCE_SYSTEM_MEMORY)
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300161 ram_resource_kb(dev, idx++, res->addr / KiB, res->length / KiB);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600162 else if (res->type == EFI_RESOURCE_MEMORY_RESERVED)
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300163 reserved_ram_resource_kb(dev, idx++, res->addr / KiB, res->length / KiB);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600164 else
Julius Wernere9665952022-01-21 17:06:20 -0800165 printk(BIOS_ERR, "failed to set resources for type %d\n",
Marshall Dawsoneb724872019-07-16 15:46:35 -0600166 res->type);
167 }
168}
169
Felix Heldf9608cd2020-12-03 16:57:02 +0100170static void root_complex_init(struct device *dev)
171{
Kyösti Mälkki2e65e9c2021-06-16 11:00:40 +0300172 register_new_ioapic((u8 *)GNB_IO_APIC_ADDR);
Felix Heldf9608cd2020-12-03 16:57:02 +0100173}
174
Chris Wang4735b1c2020-07-13 23:29:29 +0800175static void acipgen_dptci(void)
176{
Felix Held507fc032020-12-05 01:55:27 +0100177 const struct soc_amd_picasso_config *config = config_of_soc();
Chris Wang4735b1c2020-07-13 23:29:29 +0800178
Tim Van Patten54ce4aa2022-09-13 14:37:32 -0600179 /* Normal mode DPTC values. */
Zheng Bao795d73c2020-10-27 15:36:55 +0800180 struct dptc_input default_input = DPTC_INPUTS(config->thermctl_limit_degreeC,
181 config->sustained_power_limit_mW,
182 config->fast_ppt_limit_mW,
183 config->slow_ppt_limit_mW);
Tim Van Patten92443582022-08-23 16:06:33 -0600184 acpigen_write_alib_dptc_default((uint8_t *)&default_input, sizeof(default_input));
185
186 /* Tablet Mode */
Chris Wang4735b1c2020-07-13 23:29:29 +0800187 struct dptc_input tablet_mode_input = DPTC_INPUTS(
Zheng Bao795d73c2020-10-27 15:36:55 +0800188 config->thermctl_limit_tablet_mode_degreeC,
189 config->sustained_power_limit_tablet_mode_mW,
190 config->fast_ppt_limit_tablet_mode_mW,
191 config->slow_ppt_limit_tablet_mode_mW);
Tim Van Patten92443582022-08-23 16:06:33 -0600192 acpigen_write_alib_dptc_tablet((uint8_t *)&tablet_mode_input,
193 sizeof(tablet_mode_input));
Chris Wang4735b1c2020-07-13 23:29:29 +0800194}
195
Marshall Dawsoneb724872019-07-16 15:46:35 -0600196static void root_complex_fill_ssdt(const struct device *device)
197{
Raul E Rangel58a8ad12021-02-18 16:36:08 -0700198 acpi_fill_root_complex_tom(device);
Tim Van Patten54ce4aa2022-09-13 14:37:32 -0600199 if (CONFIG(SOC_AMD_COMMON_BLOCK_ACPI_DPTC))
200 acipgen_dptci();
Marshall Dawsoneb724872019-07-16 15:46:35 -0600201}
202
Felix Heldff092d42021-02-17 00:04:59 +0100203static const char *gnb_acpi_name(const struct device *dev)
204{
205 return "GNB";
206}
207
Arthur Heymans826955d2022-09-20 17:26:30 +0200208struct device_operations picasso_root_complex_operations = {
Marshall Dawsoneb724872019-07-16 15:46:35 -0600209 .read_resources = read_resources,
Felix Held9541d172021-01-05 00:56:10 +0100210 .set_resources = noop_set_resources,
Marshall Dawsoneb724872019-07-16 15:46:35 -0600211 .enable_resources = pci_dev_enable_resources,
Felix Heldf9608cd2020-12-03 16:57:02 +0100212 .init = root_complex_init,
Felix Heldff092d42021-02-17 00:04:59 +0100213 .acpi_name = gnb_acpi_name,
Marshall Dawsoneb724872019-07-16 15:46:35 -0600214 .acpi_fill_ssdt = root_complex_fill_ssdt,
215};