Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <acpi/acpigen.h> |
Raul E Rangel | 58a8ad1 | 2021-02-18 16:36:08 -0700 | [diff] [blame] | 4 | #include <amdblocks/acpi.h> |
Felix Held | 95f1bb8 | 2021-05-07 18:46:36 +0200 | [diff] [blame] | 5 | #include <amdblocks/alib.h> |
Arthur Heymans | ce17972 | 2023-06-07 15:27:18 +0200 | [diff] [blame] | 6 | #include <amdblocks/data_fabric.h> |
Raul E Rangel | 899be1b | 2021-02-05 15:50:20 -0700 | [diff] [blame] | 7 | #include <amdblocks/memmap.h> |
Felix Held | 604ffa6 | 2021-02-12 00:43:20 +0100 | [diff] [blame] | 8 | #include <amdblocks/ioapic.h> |
Felix Held | 12a4482 | 2023-06-02 15:30:50 +0200 | [diff] [blame] | 9 | #include <amdblocks/iomap.h> |
Felix Held | f9608cd | 2020-12-03 16:57:02 +0100 | [diff] [blame] | 10 | #include <arch/ioapic.h> |
Felix Held | a4ced63 | 2023-06-05 21:22:15 +0200 | [diff] [blame] | 11 | #include <arch/vga.h> |
John Zhao | f6f1f73 | 2020-06-26 10:00:02 -0700 | [diff] [blame] | 12 | #include <assert.h> |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 13 | #include <cbmem.h> |
| 14 | #include <console/console.h> |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 15 | #include <device/device.h> |
| 16 | #include <device/pci.h> |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 17 | #include <fsp/util.h> |
| 18 | #include <stdint.h> |
Marshall Dawson | 39c64b0 | 2020-09-04 12:07:27 -0600 | [diff] [blame] | 19 | #include <soc/iomap.h> |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 20 | #include "chip.h" |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 21 | |
Felix Held | ef51157 | 2021-05-07 19:02:45 +0200 | [diff] [blame] | 22 | #define DPTC_TOTAL_UPDATE_PARAMS 4 |
| 23 | |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 24 | struct dptc_input { |
| 25 | uint16_t size; |
Felix Held | f061017 | 2021-05-07 19:21:08 +0200 | [diff] [blame] | 26 | struct alib_dptc_param params[DPTC_TOTAL_UPDATE_PARAMS]; |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 27 | } __packed; |
| 28 | |
Kevin Chiu | cdd9f5c | 2020-09-18 17:30:30 +0800 | [diff] [blame] | 29 | #define DPTC_INPUTS(_thermctllmit, _sustained, _fast, _slow) \ |
Felix Held | 3acafa2 | 2021-05-07 19:17:51 +0200 | [diff] [blame] | 30 | { \ |
| 31 | .size = sizeof(struct dptc_input), \ |
| 32 | .params = { \ |
| 33 | { \ |
| 34 | .id = ALIB_DPTC_THERMAL_CONTROL_LIMIT_ID, \ |
| 35 | .value = _thermctllmit, \ |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 36 | }, \ |
Felix Held | 3acafa2 | 2021-05-07 19:17:51 +0200 | [diff] [blame] | 37 | { \ |
| 38 | .id = ALIB_DPTC_SUSTAINED_POWER_LIMIT_ID, \ |
| 39 | .value = _sustained, \ |
| 40 | }, \ |
| 41 | { \ |
| 42 | .id = ALIB_DPTC_FAST_PPT_LIMIT_ID, \ |
| 43 | .value = _fast, \ |
| 44 | }, \ |
| 45 | { \ |
| 46 | .id = ALIB_DPTC_SLOW_PPT_LIMIT_ID, \ |
| 47 | .value = _slow, \ |
| 48 | }, \ |
| 49 | }, \ |
| 50 | } |
Furquan Shaikh | bc45650 | 2020-06-10 16:37:23 -0700 | [diff] [blame] | 51 | /* |
| 52 | * |
| 53 | * +--------------------------------+ |
| 54 | * | | |
| 55 | * | | |
| 56 | * | | |
| 57 | * | | |
| 58 | * | | |
| 59 | * | | |
| 60 | * | | |
| 61 | * reserved_dram_end +--------------------------------+ |
| 62 | * | | |
| 63 | * | verstage (if reqd) | |
| 64 | * | (VERSTAGE_SIZE) | |
| 65 | * +--------------------------------+ VERSTAGE_ADDR |
| 66 | * | | |
| 67 | * | FSP-M | |
| 68 | * | (FSP_M_SIZE) | |
| 69 | * +--------------------------------+ FSP_M_ADDR |
Furquan Shaikh | bc45650 | 2020-06-10 16:37:23 -0700 | [diff] [blame] | 70 | * | romstage | |
| 71 | * | (ROMSTAGE_SIZE) | |
Kyösti Mälkki | b3621f8 | 2020-12-04 19:51:17 +0200 | [diff] [blame] | 72 | * +--------------------------------+ ROMSTAGE_ADDR = BOOTBLOCK_END |
| 73 | * | | X86_RESET_VECTOR = BOOTBLOCK_END - 0x10 |
Furquan Shaikh | bc45650 | 2020-06-10 16:37:23 -0700 | [diff] [blame] | 74 | * | bootblock | |
| 75 | * | (C_ENV_BOOTBLOCK_SIZE) | |
Kyösti Mälkki | b3621f8 | 2020-12-04 19:51:17 +0200 | [diff] [blame] | 76 | * +--------------------------------+ BOOTBLOCK_ADDR = BOOTBLOCK_END - C_ENV_BOOTBLOCK_SIZE |
Furquan Shaikh | bc45650 | 2020-06-10 16:37:23 -0700 | [diff] [blame] | 77 | * | Unused hole | |
| 78 | * | (86KiB) | |
| 79 | * +--------------------------------+ |
| 80 | * | FMAP cache (FMAP_SIZE) | |
| 81 | * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE + 0x200 |
| 82 | * | Early Timestamp region (512B) | |
| 83 | * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE |
| 84 | * | Preram CBMEM console | |
| 85 | * | (PRERAM_CBMEM_CONSOLE_SIZE) | |
| 86 | * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE |
| 87 | * | PSP shared (vboot workbuf) | |
| 88 | * | (PSP_SHAREDMEM_SIZE) | |
| 89 | * +--------------------------------+ PSP_SHAREDMEM_BASE |
| 90 | * | APOB (64KiB) | |
| 91 | * +--------------------------------+ PSP_APOB_DRAM_ADDRESS |
| 92 | * | Early BSP stack | |
| 93 | * | (EARLYRAM_BSP_STACK_SIZE) | |
| 94 | * reserved_dram_start +--------------------------------+ EARLY_RESERVED_DRAM_BASE |
| 95 | * | DRAM | |
| 96 | * +--------------------------------+ 0x100000 |
| 97 | * | Option ROM | |
| 98 | * +--------------------------------+ 0xc0000 |
| 99 | * | Legacy VGA | |
| 100 | * +--------------------------------+ 0xa0000 |
| 101 | * | DRAM | |
| 102 | * +--------------------------------+ 0x0 |
| 103 | */ |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 104 | static void read_resources(struct device *dev) |
| 105 | { |
| 106 | uint32_t mem_usable = (uintptr_t)cbmem_top(); |
| 107 | unsigned int idx = 0; |
Felix Held | 2e81436 | 2022-11-10 22:44:18 +0100 | [diff] [blame] | 108 | const struct hob_header *hob_iterator; |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 109 | const struct hob_resource *res; |
| 110 | |
Furquan Shaikh | bc45650 | 2020-06-10 16:37:23 -0700 | [diff] [blame] | 111 | 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 Held | af17f0b | 2022-03-02 23:36:55 +0100 | [diff] [blame] | 117 | /* The root complex has no PCI BARs implemented, so there's no need to call |
| 118 | pci_dev_read_resources for it */ |
| 119 | |
Felix Held | d0959dc | 2023-05-10 15:07:47 +0200 | [diff] [blame] | 120 | fixed_io_range_reserved(dev, idx++, PCI_IO_CONFIG_INDEX, PCI_IO_CONFIG_PORT_COUNT); |
| 121 | |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 122 | /* 0x0 - 0x9ffff */ |
Kyösti Mälkki | 27d6299 | 2022-05-24 20:25:58 +0300 | [diff] [blame] | 123 | ram_resource_kb(dev, idx++, 0, 0xa0000 / KiB); |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 124 | |
| 125 | /* 0xa0000 - 0xbffff: legacy VGA */ |
Felix Held | a4ced63 | 2023-06-05 21:22:15 +0200 | [diff] [blame] | 126 | mmio_resource_kb(dev, idx++, VGA_MMIO_BASE / KiB, VGA_MMIO_SIZE / KiB); |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 127 | |
| 128 | /* 0xc0000 - 0xfffff: Option ROM */ |
Kyösti Mälkki | 27d6299 | 2022-05-24 20:25:58 +0300 | [diff] [blame] | 129 | reserved_ram_resource_kb(dev, idx++, 0xc0000 / KiB, 0x40000 / KiB); |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 130 | |
Furquan Shaikh | bc45650 | 2020-06-10 16:37:23 -0700 | [diff] [blame] | 131 | /* 1MB - bottom of DRAM reserved for early coreboot usage */ |
Kyösti Mälkki | 27d6299 | 2022-05-24 20:25:58 +0300 | [diff] [blame] | 132 | ram_resource_kb(dev, idx++, (1 * MiB) / KiB, |
Furquan Shaikh | bc45650 | 2020-06-10 16:37:23 -0700 | [diff] [blame] | 133 | (early_reserved_dram_start - (1 * MiB)) / KiB); |
| 134 | |
| 135 | /* DRAM reserved for early coreboot usage */ |
Kyösti Mälkki | 27d6299 | 2022-05-24 20:25:58 +0300 | [diff] [blame] | 136 | reserved_ram_resource_kb(dev, idx++, early_reserved_dram_start / KiB, |
Furquan Shaikh | bc45650 | 2020-06-10 16:37:23 -0700 | [diff] [blame] | 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. */ |
Kyösti Mälkki | 27d6299 | 2022-05-24 20:25:58 +0300 | [diff] [blame] | 141 | ram_resource_kb(dev, idx++, early_reserved_dram_end / KiB, |
Furquan Shaikh | bc45650 | 2020-06-10 16:37:23 -0700 | [diff] [blame] | 142 | (mem_usable - early_reserved_dram_end) / KiB); |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 143 | |
Felix Held | 56b037b | 2022-03-02 22:57:01 +0100 | [diff] [blame] | 144 | mmconf_resource(dev, idx++); |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 145 | |
Felix Held | dafc619 | 2022-11-10 18:19:36 +0100 | [diff] [blame] | 146 | /* GNB IOAPIC resource */ |
Arthur Heymans | 61daf9b | 2023-06-15 09:59:58 +0200 | [diff] [blame] | 147 | mmio_range(dev, IOMMU_IOAPIC_IDX, GNB_IO_APIC_ADDR, 0x1000); |
Felix Held | dafc619 | 2022-11-10 18:19:36 +0100 | [diff] [blame] | 148 | |
Felix Held | 12a4482 | 2023-06-02 15:30:50 +0200 | [diff] [blame] | 149 | /* Reserve fixed IOMMU MMIO region */ |
| 150 | mmio_range(dev, idx++, IOMMU_RESERVED_MMIO_BASE, IOMMU_RESERVED_MMIO_SIZE); |
| 151 | |
Felix Held | 2e81436 | 2022-11-10 22:44:18 +0100 | [diff] [blame] | 152 | if (fsp_hob_iterator_init(&hob_iterator) != CB_SUCCESS) { |
| 153 | printk(BIOS_ERR, "%s incomplete because no HOB list was found\n", __func__); |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 154 | return; |
| 155 | } |
| 156 | |
Felix Held | 2e81436 | 2022-11-10 22:44:18 +0100 | [diff] [blame] | 157 | while (fsp_hob_iterator_get_next_resource(&hob_iterator, &res) == CB_SUCCESS) { |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 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) |
Kyösti Mälkki | 27d6299 | 2022-05-24 20:25:58 +0300 | [diff] [blame] | 164 | ram_resource_kb(dev, idx++, res->addr / KiB, res->length / KiB); |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 165 | else if (res->type == EFI_RESOURCE_MEMORY_RESERVED) |
Kyösti Mälkki | 27d6299 | 2022-05-24 20:25:58 +0300 | [diff] [blame] | 166 | reserved_ram_resource_kb(dev, idx++, res->addr / KiB, res->length / KiB); |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 167 | else |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 168 | printk(BIOS_ERR, "failed to set resources for type %d\n", |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 169 | res->type); |
| 170 | } |
| 171 | } |
| 172 | |
Felix Held | f9608cd | 2020-12-03 16:57:02 +0100 | [diff] [blame] | 173 | static void root_complex_init(struct device *dev) |
| 174 | { |
Kyösti Mälkki | 2e65e9c | 2021-06-16 11:00:40 +0300 | [diff] [blame] | 175 | register_new_ioapic((u8 *)GNB_IO_APIC_ADDR); |
Felix Held | f9608cd | 2020-12-03 16:57:02 +0100 | [diff] [blame] | 176 | } |
| 177 | |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 178 | static void acipgen_dptci(void) |
| 179 | { |
Felix Held | 507fc03 | 2020-12-05 01:55:27 +0100 | [diff] [blame] | 180 | const struct soc_amd_picasso_config *config = config_of_soc(); |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 181 | |
Tim Van Patten | 54ce4aa | 2022-09-13 14:37:32 -0600 | [diff] [blame] | 182 | /* Normal mode DPTC values. */ |
Zheng Bao | 795d73c | 2020-10-27 15:36:55 +0800 | [diff] [blame] | 183 | 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 Patten | 9244358 | 2022-08-23 16:06:33 -0600 | [diff] [blame] | 187 | acpigen_write_alib_dptc_default((uint8_t *)&default_input, sizeof(default_input)); |
| 188 | |
| 189 | /* Tablet Mode */ |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 190 | struct dptc_input tablet_mode_input = DPTC_INPUTS( |
Zheng Bao | 795d73c | 2020-10-27 15:36:55 +0800 | [diff] [blame] | 191 | 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 Patten | 9244358 | 2022-08-23 16:06:33 -0600 | [diff] [blame] | 195 | acpigen_write_alib_dptc_tablet((uint8_t *)&tablet_mode_input, |
| 196 | sizeof(tablet_mode_input)); |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 197 | } |
| 198 | |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 199 | static void root_complex_fill_ssdt(const struct device *device) |
| 200 | { |
Tim Van Patten | 54ce4aa | 2022-09-13 14:37:32 -0600 | [diff] [blame] | 201 | if (CONFIG(SOC_AMD_COMMON_BLOCK_ACPI_DPTC)) |
| 202 | acipgen_dptci(); |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 203 | } |
| 204 | |
Felix Held | ff092d4 | 2021-02-17 00:04:59 +0100 | [diff] [blame] | 205 | static const char *gnb_acpi_name(const struct device *dev) |
| 206 | { |
| 207 | return "GNB"; |
| 208 | } |
| 209 | |
Arthur Heymans | 826955d | 2022-09-20 17:26:30 +0200 | [diff] [blame] | 210 | struct device_operations picasso_root_complex_operations = { |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 211 | .read_resources = read_resources, |
Felix Held | 9541d17 | 2021-01-05 00:56:10 +0100 | [diff] [blame] | 212 | .set_resources = noop_set_resources, |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 213 | .enable_resources = pci_dev_enable_resources, |
Felix Held | f9608cd | 2020-12-03 16:57:02 +0100 | [diff] [blame] | 214 | .init = root_complex_init, |
Felix Held | ff092d4 | 2021-02-17 00:04:59 +0100 | [diff] [blame] | 215 | .acpi_name = gnb_acpi_name, |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 216 | .acpi_fill_ssdt = root_complex_fill_ssdt, |
| 217 | }; |