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> |
Raul E Rangel | 899be1b | 2021-02-05 15:50:20 -0700 | [diff] [blame] | 6 | #include <amdblocks/memmap.h> |
Felix Held | 604ffa6 | 2021-02-12 00:43:20 +0100 | [diff] [blame] | 7 | #include <amdblocks/ioapic.h> |
Felix Held | f9608cd | 2020-12-03 16:57:02 +0100 | [diff] [blame] | 8 | #include <arch/ioapic.h> |
John Zhao | f6f1f73 | 2020-06-26 10:00:02 -0700 | [diff] [blame] | 9 | #include <assert.h> |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 10 | #include <cbmem.h> |
| 11 | #include <console/console.h> |
| 12 | #include <cpu/amd/msr.h> |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 13 | #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 Dawson | 39c64b0 | 2020-09-04 12:07:27 -0600 | [diff] [blame] | 18 | #include <soc/iomap.h> |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 19 | #include "chip.h" |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 20 | |
Felix Held | ef51157 | 2021-05-07 19:02:45 +0200 | [diff] [blame] | 21 | #define DPTC_TOTAL_UPDATE_PARAMS 4 |
| 22 | |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 23 | struct dptc_input { |
| 24 | uint16_t size; |
Felix Held | f061017 | 2021-05-07 19:21:08 +0200 | [diff] [blame] | 25 | struct alib_dptc_param params[DPTC_TOTAL_UPDATE_PARAMS]; |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 26 | } __packed; |
| 27 | |
Kevin Chiu | cdd9f5c | 2020-09-18 17:30:30 +0800 | [diff] [blame] | 28 | #define DPTC_INPUTS(_thermctllmit, _sustained, _fast, _slow) \ |
Felix Held | 3acafa2 | 2021-05-07 19:17:51 +0200 | [diff] [blame] | 29 | { \ |
| 30 | .size = sizeof(struct dptc_input), \ |
| 31 | .params = { \ |
| 32 | { \ |
| 33 | .id = ALIB_DPTC_THERMAL_CONTROL_LIMIT_ID, \ |
| 34 | .value = _thermctllmit, \ |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 35 | }, \ |
Felix Held | 3acafa2 | 2021-05-07 19:17:51 +0200 | [diff] [blame] | 36 | { \ |
| 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 Shaikh | bc45650 | 2020-06-10 16:37:23 -0700 | [diff] [blame] | 50 | /* |
| 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 Shaikh | bc45650 | 2020-06-10 16:37:23 -0700 | [diff] [blame] | 69 | * | romstage | |
| 70 | * | (ROMSTAGE_SIZE) | |
Kyösti Mälkki | b3621f8 | 2020-12-04 19:51:17 +0200 | [diff] [blame] | 71 | * +--------------------------------+ ROMSTAGE_ADDR = BOOTBLOCK_END |
| 72 | * | | X86_RESET_VECTOR = BOOTBLOCK_END - 0x10 |
Furquan Shaikh | bc45650 | 2020-06-10 16:37:23 -0700 | [diff] [blame] | 73 | * | bootblock | |
| 74 | * | (C_ENV_BOOTBLOCK_SIZE) | |
Kyösti Mälkki | b3621f8 | 2020-12-04 19:51:17 +0200 | [diff] [blame] | 75 | * +--------------------------------+ BOOTBLOCK_ADDR = BOOTBLOCK_END - C_ENV_BOOTBLOCK_SIZE |
Furquan Shaikh | bc45650 | 2020-06-10 16:37:23 -0700 | [diff] [blame] | 76 | * | 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 Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 103 | static void read_resources(struct device *dev) |
| 104 | { |
| 105 | uint32_t mem_usable = (uintptr_t)cbmem_top(); |
| 106 | unsigned int idx = 0; |
| 107 | const struct hob_header *hob = fsp_get_hob_list(); |
| 108 | const struct hob_resource *res; |
Marshall Dawson | 39c64b0 | 2020-09-04 12:07:27 -0600 | [diff] [blame] | 109 | struct resource *gnb_apic; |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 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 | |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 120 | /* 0x0 - 0x9ffff */ |
Kyösti Mälkki | 27d6299 | 2022-05-24 20:25:58 +0300 | [diff] [blame] | 121 | ram_resource_kb(dev, idx++, 0, 0xa0000 / KiB); |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 122 | |
| 123 | /* 0xa0000 - 0xbffff: legacy VGA */ |
Kyösti Mälkki | 27d6299 | 2022-05-24 20:25:58 +0300 | [diff] [blame] | 124 | mmio_resource_kb(dev, idx++, 0xa0000 / KiB, 0x20000 / KiB); |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 125 | |
| 126 | /* 0xc0000 - 0xfffff: Option ROM */ |
Kyösti Mälkki | 27d6299 | 2022-05-24 20:25:58 +0300 | [diff] [blame] | 127 | reserved_ram_resource_kb(dev, idx++, 0xc0000 / KiB, 0x40000 / KiB); |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 128 | |
Furquan Shaikh | bc45650 | 2020-06-10 16:37:23 -0700 | [diff] [blame] | 129 | /* 1MB - bottom of DRAM reserved for early coreboot usage */ |
Kyösti Mälkki | 27d6299 | 2022-05-24 20:25:58 +0300 | [diff] [blame] | 130 | ram_resource_kb(dev, idx++, (1 * MiB) / KiB, |
Furquan Shaikh | bc45650 | 2020-06-10 16:37:23 -0700 | [diff] [blame] | 131 | (early_reserved_dram_start - (1 * MiB)) / KiB); |
| 132 | |
| 133 | /* DRAM reserved for early coreboot usage */ |
Kyösti Mälkki | 27d6299 | 2022-05-24 20:25:58 +0300 | [diff] [blame] | 134 | reserved_ram_resource_kb(dev, idx++, early_reserved_dram_start / KiB, |
Furquan Shaikh | bc45650 | 2020-06-10 16:37:23 -0700 | [diff] [blame] | 135 | (early_reserved_dram_end - early_reserved_dram_start) / KiB); |
| 136 | |
| 137 | /* top of DRAM consumed early - low top usable RAM |
| 138 | * 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] | 139 | ram_resource_kb(dev, idx++, early_reserved_dram_end / KiB, |
Furquan Shaikh | bc45650 | 2020-06-10 16:37:23 -0700 | [diff] [blame] | 140 | (mem_usable - early_reserved_dram_end) / KiB); |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 141 | |
Felix Held | 56b037b | 2022-03-02 22:57:01 +0100 | [diff] [blame] | 142 | mmconf_resource(dev, idx++); |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 143 | |
| 144 | if (!hob) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 145 | printk(BIOS_ERR, "%s incomplete because no HOB list was found\n", |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 146 | __func__); |
| 147 | return; |
| 148 | } |
| 149 | |
| 150 | for (; hob->type != HOB_TYPE_END_OF_HOB_LIST; hob = fsp_next_hob(hob)) { |
| 151 | |
| 152 | if (hob->type != HOB_TYPE_RESOURCE_DESCRIPTOR) |
| 153 | continue; |
| 154 | |
| 155 | res = fsp_hob_header_to_resource(hob); |
| 156 | |
| 157 | if (res->type == EFI_RESOURCE_SYSTEM_MEMORY && res->addr < mem_usable) |
| 158 | continue; /* 0 through low usable was set above */ |
| 159 | if (res->type == EFI_RESOURCE_MEMORY_MAPPED_IO) |
| 160 | continue; /* Done separately */ |
| 161 | |
| 162 | if (res->type == EFI_RESOURCE_SYSTEM_MEMORY) |
Kyösti Mälkki | 27d6299 | 2022-05-24 20:25:58 +0300 | [diff] [blame] | 163 | ram_resource_kb(dev, idx++, res->addr / KiB, res->length / KiB); |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 164 | else if (res->type == EFI_RESOURCE_MEMORY_RESERVED) |
Kyösti Mälkki | 27d6299 | 2022-05-24 20:25:58 +0300 | [diff] [blame] | 165 | reserved_ram_resource_kb(dev, idx++, res->addr / KiB, res->length / KiB); |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 166 | else |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 167 | printk(BIOS_ERR, "failed to set resources for type %d\n", |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 168 | res->type); |
| 169 | } |
Marshall Dawson | 39c64b0 | 2020-09-04 12:07:27 -0600 | [diff] [blame] | 170 | |
| 171 | /* GNB IOAPIC resource */ |
Felix Held | b1197af | 2022-03-02 23:02:31 +0100 | [diff] [blame] | 172 | gnb_apic = new_resource(dev, idx++); |
Marshall Dawson | 39c64b0 | 2020-09-04 12:07:27 -0600 | [diff] [blame] | 173 | gnb_apic->base = GNB_IO_APIC_ADDR; |
| 174 | gnb_apic->size = 0x00001000; |
| 175 | gnb_apic->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 176 | } |
| 177 | |
Felix Held | f9608cd | 2020-12-03 16:57:02 +0100 | [diff] [blame] | 178 | static void root_complex_init(struct device *dev) |
| 179 | { |
Felix Held | 604ffa6 | 2021-02-12 00:43:20 +0100 | [diff] [blame] | 180 | setup_ioapic((u8 *)GNB_IO_APIC_ADDR, GNB_IOAPIC_ID); |
Felix Held | f9608cd | 2020-12-03 16:57:02 +0100 | [diff] [blame] | 181 | } |
| 182 | |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 183 | static void acipgen_dptci(void) |
| 184 | { |
Felix Held | 507fc03 | 2020-12-05 01:55:27 +0100 | [diff] [blame] | 185 | const struct soc_amd_picasso_config *config = config_of_soc(); |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 186 | |
Tim Van Patten | 54ce4aa | 2022-09-13 14:37:32 -0600 | [diff] [blame^] | 187 | /* Normal mode DPTC values. */ |
Zheng Bao | 795d73c | 2020-10-27 15:36:55 +0800 | [diff] [blame] | 188 | struct dptc_input default_input = DPTC_INPUTS(config->thermctl_limit_degreeC, |
| 189 | config->sustained_power_limit_mW, |
| 190 | config->fast_ppt_limit_mW, |
| 191 | config->slow_ppt_limit_mW); |
Tim Van Patten | 9244358 | 2022-08-23 16:06:33 -0600 | [diff] [blame] | 192 | acpigen_write_alib_dptc_default((uint8_t *)&default_input, sizeof(default_input)); |
| 193 | |
| 194 | /* Tablet Mode */ |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 195 | struct dptc_input tablet_mode_input = DPTC_INPUTS( |
Zheng Bao | 795d73c | 2020-10-27 15:36:55 +0800 | [diff] [blame] | 196 | config->thermctl_limit_tablet_mode_degreeC, |
| 197 | config->sustained_power_limit_tablet_mode_mW, |
| 198 | config->fast_ppt_limit_tablet_mode_mW, |
| 199 | config->slow_ppt_limit_tablet_mode_mW); |
Tim Van Patten | 9244358 | 2022-08-23 16:06:33 -0600 | [diff] [blame] | 200 | acpigen_write_alib_dptc_tablet((uint8_t *)&tablet_mode_input, |
| 201 | sizeof(tablet_mode_input)); |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 202 | } |
| 203 | |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 204 | static void root_complex_fill_ssdt(const struct device *device) |
| 205 | { |
Raul E Rangel | 58a8ad1 | 2021-02-18 16:36:08 -0700 | [diff] [blame] | 206 | acpi_fill_root_complex_tom(device); |
Tim Van Patten | 54ce4aa | 2022-09-13 14:37:32 -0600 | [diff] [blame^] | 207 | if (CONFIG(SOC_AMD_COMMON_BLOCK_ACPI_DPTC)) |
| 208 | acipgen_dptci(); |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 209 | } |
| 210 | |
Felix Held | ff092d4 | 2021-02-17 00:04:59 +0100 | [diff] [blame] | 211 | static const char *gnb_acpi_name(const struct device *dev) |
| 212 | { |
| 213 | return "GNB"; |
| 214 | } |
| 215 | |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 216 | static struct device_operations root_complex_operations = { |
| 217 | .read_resources = read_resources, |
Felix Held | 9541d17 | 2021-01-05 00:56:10 +0100 | [diff] [blame] | 218 | .set_resources = noop_set_resources, |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 219 | .enable_resources = pci_dev_enable_resources, |
Felix Held | f9608cd | 2020-12-03 16:57:02 +0100 | [diff] [blame] | 220 | .init = root_complex_init, |
Felix Held | ff092d4 | 2021-02-17 00:04:59 +0100 | [diff] [blame] | 221 | .acpi_name = gnb_acpi_name, |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 222 | .acpi_fill_ssdt = root_complex_fill_ssdt, |
| 223 | }; |
| 224 | |
| 225 | static const struct pci_driver family17_root_complex __pci_driver = { |
| 226 | .ops = &root_complex_operations, |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 227 | .vendor = PCI_VID_AMD, |
| 228 | .device = PCI_DID_AMD_17H_MODEL_101F_NB, |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 229 | }; |