blob: cd10fdb7624a7ab5f790d0f038f9fdf6031ed577 [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>
Arthur Heymansce179722023-06-07 15:27:18 +02006#include <amdblocks/data_fabric.h>
Raul E Rangel899be1b2021-02-05 15:50:20 -07007#include <amdblocks/memmap.h>
Felix Held604ffa62021-02-12 00:43:20 +01008#include <amdblocks/ioapic.h>
Felix Heldf9608cd2020-12-03 16:57:02 +01009#include <arch/ioapic.h>
Felix Helda4ced632023-06-05 21:22:15 +020010#include <arch/vga.h>
John Zhaof6f1f732020-06-26 10:00:02 -070011#include <assert.h>
Marshall Dawsoneb724872019-07-16 15:46:35 -060012#include <cbmem.h>
13#include <console/console.h>
Marshall Dawsoneb724872019-07-16 15:46:35 -060014#include <device/device.h>
15#include <device/pci.h>
Marshall Dawsoneb724872019-07-16 15:46:35 -060016#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_input {
24 uint16_t size;
Felix Heldf0610172021-05-07 19:21:08 +020025 struct alib_dptc_param params[DPTC_TOTAL_UPDATE_PARAMS];
Chris Wang4735b1c2020-07-13 23:29:29 +080026} __packed;
27
Kevin Chiucdd9f5c2020-09-18 17:30:30 +080028#define DPTC_INPUTS(_thermctllmit, _sustained, _fast, _slow) \
Felix Held3acafa22021-05-07 19:17:51 +020029 { \
30 .size = sizeof(struct dptc_input), \
31 .params = { \
32 { \
33 .id = ALIB_DPTC_THERMAL_CONTROL_LIMIT_ID, \
34 .value = _thermctllmit, \
Chris Wang4735b1c2020-07-13 23:29:29 +080035 }, \
Felix Held3acafa22021-05-07 19:17:51 +020036 { \
37 .id = ALIB_DPTC_SUSTAINED_POWER_LIMIT_ID, \
38 .value = _sustained, \
39 }, \
40 { \
41 .id = ALIB_DPTC_FAST_PPT_LIMIT_ID, \
42 .value = _fast, \
43 }, \
44 { \
45 .id = ALIB_DPTC_SLOW_PPT_LIMIT_ID, \
46 .value = _slow, \
47 }, \
48 }, \
49 }
Furquan Shaikhbc456502020-06-10 16:37:23 -070050/*
51 *
52 * +--------------------------------+
53 * | |
54 * | |
55 * | |
56 * | |
57 * | |
58 * | |
59 * | |
60 * reserved_dram_end +--------------------------------+
61 * | |
62 * | verstage (if reqd) |
63 * | (VERSTAGE_SIZE) |
64 * +--------------------------------+ VERSTAGE_ADDR
65 * | |
66 * | FSP-M |
67 * | (FSP_M_SIZE) |
68 * +--------------------------------+ FSP_M_ADDR
Furquan Shaikhbc456502020-06-10 16:37:23 -070069 * | romstage |
70 * | (ROMSTAGE_SIZE) |
Kyösti Mälkkib3621f82020-12-04 19:51:17 +020071 * +--------------------------------+ ROMSTAGE_ADDR = BOOTBLOCK_END
72 * | | X86_RESET_VECTOR = BOOTBLOCK_END - 0x10
Furquan Shaikhbc456502020-06-10 16:37:23 -070073 * | bootblock |
74 * | (C_ENV_BOOTBLOCK_SIZE) |
Kyösti Mälkkib3621f82020-12-04 19:51:17 +020075 * +--------------------------------+ BOOTBLOCK_ADDR = BOOTBLOCK_END - C_ENV_BOOTBLOCK_SIZE
Furquan Shaikhbc456502020-06-10 16:37:23 -070076 * | Unused hole |
77 * | (86KiB) |
78 * +--------------------------------+
79 * | FMAP cache (FMAP_SIZE) |
80 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE + 0x200
81 * | Early Timestamp region (512B) |
82 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE
83 * | Preram CBMEM console |
84 * | (PRERAM_CBMEM_CONSOLE_SIZE) |
85 * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE
86 * | PSP shared (vboot workbuf) |
87 * | (PSP_SHAREDMEM_SIZE) |
88 * +--------------------------------+ PSP_SHAREDMEM_BASE
89 * | APOB (64KiB) |
90 * +--------------------------------+ PSP_APOB_DRAM_ADDRESS
91 * | Early BSP stack |
92 * | (EARLYRAM_BSP_STACK_SIZE) |
93 * reserved_dram_start +--------------------------------+ EARLY_RESERVED_DRAM_BASE
94 * | DRAM |
95 * +--------------------------------+ 0x100000
96 * | Option ROM |
97 * +--------------------------------+ 0xc0000
98 * | Legacy VGA |
99 * +--------------------------------+ 0xa0000
100 * | DRAM |
101 * +--------------------------------+ 0x0
102 */
Marshall Dawsoneb724872019-07-16 15:46:35 -0600103static void read_resources(struct device *dev)
104{
105 uint32_t mem_usable = (uintptr_t)cbmem_top();
106 unsigned int idx = 0;
Felix Held2e814362022-11-10 22:44:18 +0100107 const struct hob_header *hob_iterator;
Marshall Dawsoneb724872019-07-16 15:46:35 -0600108 const struct hob_resource *res;
Marshall Dawson39c64b02020-09-04 12:07:27 -0600109 struct resource *gnb_apic;
Marshall Dawsoneb724872019-07-16 15:46:35 -0600110
Furquan Shaikhbc456502020-06-10 16:37:23 -0700111 uintptr_t early_reserved_dram_start, early_reserved_dram_end;
112 const struct memmap_early_dram *e = memmap_get_early_dram_usage();
113
114 early_reserved_dram_start = e->base;
115 early_reserved_dram_end = e->base + e->size;
116
Felix Heldaf17f0b2022-03-02 23:36:55 +0100117 /* The root complex has no PCI BARs implemented, so there's no need to call
118 pci_dev_read_resources for it */
119
Felix Heldd0959dc2023-05-10 15:07:47 +0200120 fixed_io_range_reserved(dev, idx++, PCI_IO_CONFIG_INDEX, PCI_IO_CONFIG_PORT_COUNT);
121
Marshall Dawsoneb724872019-07-16 15:46:35 -0600122 /* 0x0 - 0x9ffff */
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300123 ram_resource_kb(dev, idx++, 0, 0xa0000 / KiB);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600124
125 /* 0xa0000 - 0xbffff: legacy VGA */
Felix Helda4ced632023-06-05 21:22:15 +0200126 mmio_resource_kb(dev, idx++, VGA_MMIO_BASE / KiB, VGA_MMIO_SIZE / KiB);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600127
128 /* 0xc0000 - 0xfffff: Option ROM */
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300129 reserved_ram_resource_kb(dev, idx++, 0xc0000 / KiB, 0x40000 / KiB);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600130
Furquan Shaikhbc456502020-06-10 16:37:23 -0700131 /* 1MB - bottom of DRAM reserved for early coreboot usage */
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300132 ram_resource_kb(dev, idx++, (1 * MiB) / KiB,
Furquan Shaikhbc456502020-06-10 16:37:23 -0700133 (early_reserved_dram_start - (1 * MiB)) / KiB);
134
135 /* DRAM reserved for early coreboot usage */
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300136 reserved_ram_resource_kb(dev, idx++, early_reserved_dram_start / KiB,
Furquan Shaikhbc456502020-06-10 16:37:23 -0700137 (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. */
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300141 ram_resource_kb(dev, idx++, early_reserved_dram_end / KiB,
Furquan Shaikhbc456502020-06-10 16:37:23 -0700142 (mem_usable - early_reserved_dram_end) / KiB);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600143
Felix Held56b037b2022-03-02 22:57:01 +0100144 mmconf_resource(dev, idx++);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600145
Felix Helddafc6192022-11-10 18:19:36 +0100146 /* GNB IOAPIC resource */
Arthur Heymansce179722023-06-07 15:27:18 +0200147 gnb_apic = new_resource(dev, IOMMU_IOAPIC_IDX);
Felix Helddafc6192022-11-10 18:19:36 +0100148 gnb_apic->base = GNB_IO_APIC_ADDR;
149 gnb_apic->size = 0x00001000;
150 gnb_apic->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
151
Felix Held2e814362022-11-10 22:44:18 +0100152 if (fsp_hob_iterator_init(&hob_iterator) != CB_SUCCESS) {
153 printk(BIOS_ERR, "%s incomplete because no HOB list was found\n", __func__);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600154 return;
155 }
156
Felix Held2e814362022-11-10 22:44:18 +0100157 while (fsp_hob_iterator_get_next_resource(&hob_iterator, &res) == CB_SUCCESS) {
Marshall Dawsoneb724872019-07-16 15:46:35 -0600158 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)
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300164 ram_resource_kb(dev, idx++, res->addr / KiB, res->length / KiB);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600165 else if (res->type == EFI_RESOURCE_MEMORY_RESERVED)
Kyösti Mälkki27d62992022-05-24 20:25:58 +0300166 reserved_ram_resource_kb(dev, idx++, res->addr / KiB, res->length / KiB);
Marshall Dawsoneb724872019-07-16 15:46:35 -0600167 else
Julius Wernere9665952022-01-21 17:06:20 -0800168 printk(BIOS_ERR, "failed to set resources for type %d\n",
Marshall Dawsoneb724872019-07-16 15:46:35 -0600169 res->type);
170 }
171}
172
Felix Heldf9608cd2020-12-03 16:57:02 +0100173static void root_complex_init(struct device *dev)
174{
Kyösti Mälkki2e65e9c2021-06-16 11:00:40 +0300175 register_new_ioapic((u8 *)GNB_IO_APIC_ADDR);
Felix Heldf9608cd2020-12-03 16:57:02 +0100176}
177
Chris Wang4735b1c2020-07-13 23:29:29 +0800178static void acipgen_dptci(void)
179{
Felix Held507fc032020-12-05 01:55:27 +0100180 const struct soc_amd_picasso_config *config = config_of_soc();
Chris Wang4735b1c2020-07-13 23:29:29 +0800181
Tim Van Patten54ce4aa2022-09-13 14:37:32 -0600182 /* Normal mode DPTC values. */
Zheng Bao795d73c2020-10-27 15:36:55 +0800183 struct dptc_input default_input = DPTC_INPUTS(config->thermctl_limit_degreeC,
184 config->sustained_power_limit_mW,
185 config->fast_ppt_limit_mW,
186 config->slow_ppt_limit_mW);
Tim Van Patten92443582022-08-23 16:06:33 -0600187 acpigen_write_alib_dptc_default((uint8_t *)&default_input, sizeof(default_input));
188
189 /* Tablet Mode */
Chris Wang4735b1c2020-07-13 23:29:29 +0800190 struct dptc_input tablet_mode_input = DPTC_INPUTS(
Zheng Bao795d73c2020-10-27 15:36:55 +0800191 config->thermctl_limit_tablet_mode_degreeC,
192 config->sustained_power_limit_tablet_mode_mW,
193 config->fast_ppt_limit_tablet_mode_mW,
194 config->slow_ppt_limit_tablet_mode_mW);
Tim Van Patten92443582022-08-23 16:06:33 -0600195 acpigen_write_alib_dptc_tablet((uint8_t *)&tablet_mode_input,
196 sizeof(tablet_mode_input));
Chris Wang4735b1c2020-07-13 23:29:29 +0800197}
198
Marshall Dawsoneb724872019-07-16 15:46:35 -0600199static void root_complex_fill_ssdt(const struct device *device)
200{
Tim Van Patten54ce4aa2022-09-13 14:37:32 -0600201 if (CONFIG(SOC_AMD_COMMON_BLOCK_ACPI_DPTC))
202 acipgen_dptci();
Marshall Dawsoneb724872019-07-16 15:46:35 -0600203}
204
Felix Heldff092d42021-02-17 00:04:59 +0100205static const char *gnb_acpi_name(const struct device *dev)
206{
207 return "GNB";
208}
209
Arthur Heymans826955d2022-09-20 17:26:30 +0200210struct device_operations picasso_root_complex_operations = {
Marshall Dawsoneb724872019-07-16 15:46:35 -0600211 .read_resources = read_resources,
Felix Held9541d172021-01-05 00:56:10 +0100212 .set_resources = noop_set_resources,
Marshall Dawsoneb724872019-07-16 15:46:35 -0600213 .enable_resources = pci_dev_enable_resources,
Felix Heldf9608cd2020-12-03 16:57:02 +0100214 .init = root_complex_init,
Felix Heldff092d42021-02-17 00:04:59 +0100215 .acpi_name = gnb_acpi_name,
Marshall Dawsoneb724872019-07-16 15:46:35 -0600216 .acpi_fill_ssdt = root_complex_fill_ssdt,
217};