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> |
John Zhao | f6f1f73 | 2020-06-26 10:00:02 -0700 | [diff] [blame] | 4 | #include <assert.h> |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 5 | #include <cbmem.h> |
| 6 | #include <console/console.h> |
| 7 | #include <cpu/amd/msr.h> |
| 8 | #include <cpu/amd/mtrr.h> |
| 9 | #include <device/device.h> |
| 10 | #include <device/pci.h> |
| 11 | #include <device/pci_ids.h> |
| 12 | #include <fsp/util.h> |
| 13 | #include <stdint.h> |
Furquan Shaikh | bc45650 | 2020-06-10 16:37:23 -0700 | [diff] [blame] | 14 | #include <soc/memmap.h> |
Marshall Dawson | 39c64b0 | 2020-09-04 12:07:27 -0600 | [diff] [blame] | 15 | #include <soc/iomap.h> |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 16 | #include "chip.h" |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 17 | |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 18 | enum { |
| 19 | ALIB_DPTCI_FUNCTION_ID = 0xc, |
Kevin Chiu | cdd9f5c | 2020-09-18 17:30:30 +0800 | [diff] [blame] | 20 | THERMAL_CONTROL_LIMIT_ID = 0x3, |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 21 | SUSTAINED_POWER_LIMIT_PARAM_ID = 0x5, |
| 22 | FAST_PPT_LIMIT_PARAM_ID = 0x6, |
| 23 | SLOW_PPT_LIMIT_PARAM_ID = 0x7, |
Kevin Chiu | cdd9f5c | 2020-09-18 17:30:30 +0800 | [diff] [blame] | 24 | DPTC_TOTAL_UPDATE_PARAMS = 4, |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 25 | }; |
| 26 | |
| 27 | struct dptc_param { |
| 28 | uint8_t id; |
| 29 | uint32_t value; |
| 30 | } __packed; |
| 31 | |
| 32 | struct dptc_input { |
| 33 | uint16_t size; |
| 34 | struct dptc_param params[DPTC_TOTAL_UPDATE_PARAMS]; |
| 35 | } __packed; |
| 36 | |
Kevin Chiu | cdd9f5c | 2020-09-18 17:30:30 +0800 | [diff] [blame] | 37 | #define DPTC_INPUTS(_thermctllmit, _sustained, _fast, _slow) \ |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 38 | { \ |
| 39 | .size = sizeof(struct dptc_input), \ |
| 40 | .params = { \ |
| 41 | { \ |
Kevin Chiu | cdd9f5c | 2020-09-18 17:30:30 +0800 | [diff] [blame] | 42 | .id = THERMAL_CONTROL_LIMIT_ID, \ |
| 43 | .value = _thermctllmit, \ |
| 44 | }, \ |
| 45 | { \ |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 46 | .id = SUSTAINED_POWER_LIMIT_PARAM_ID, \ |
| 47 | .value = _sustained, \ |
| 48 | }, \ |
| 49 | { \ |
| 50 | .id = FAST_PPT_LIMIT_PARAM_ID, \ |
| 51 | .value = _fast, \ |
| 52 | }, \ |
| 53 | { \ |
| 54 | .id = SLOW_PPT_LIMIT_PARAM_ID, \ |
| 55 | .value = _slow, \ |
| 56 | }, \ |
| 57 | }, \ |
| 58 | } |
Furquan Shaikh | bc45650 | 2020-06-10 16:37:23 -0700 | [diff] [blame] | 59 | /* |
| 60 | * |
| 61 | * +--------------------------------+ |
| 62 | * | | |
| 63 | * | | |
| 64 | * | | |
| 65 | * | | |
| 66 | * | | |
| 67 | * | | |
| 68 | * | | |
| 69 | * reserved_dram_end +--------------------------------+ |
| 70 | * | | |
| 71 | * | verstage (if reqd) | |
| 72 | * | (VERSTAGE_SIZE) | |
| 73 | * +--------------------------------+ VERSTAGE_ADDR |
| 74 | * | | |
| 75 | * | FSP-M | |
| 76 | * | (FSP_M_SIZE) | |
| 77 | * +--------------------------------+ FSP_M_ADDR |
Furquan Shaikh | bc45650 | 2020-06-10 16:37:23 -0700 | [diff] [blame] | 78 | * | romstage | |
| 79 | * | (ROMSTAGE_SIZE) | |
| 80 | * +--------------------------------+ ROMSTAGE_ADDR |
Kyösti Mälkki | 21cad6c | 2020-12-04 19:52:08 +0200 | [diff] [blame] | 81 | * | | X86_RESET_VECTOR = BOOTBLOCK_ADDR + C_ENV_BOOTBLOCK_SIZE - 0x10 |
Furquan Shaikh | bc45650 | 2020-06-10 16:37:23 -0700 | [diff] [blame] | 82 | * | bootblock | |
| 83 | * | (C_ENV_BOOTBLOCK_SIZE) | |
| 84 | * +--------------------------------+ BOOTBLOCK_ADDR |
| 85 | * | Unused hole | |
| 86 | * | (86KiB) | |
| 87 | * +--------------------------------+ |
| 88 | * | FMAP cache (FMAP_SIZE) | |
| 89 | * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE + 0x200 |
| 90 | * | Early Timestamp region (512B) | |
| 91 | * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE + PRERAM_CBMEM_CONSOLE_SIZE |
| 92 | * | Preram CBMEM console | |
| 93 | * | (PRERAM_CBMEM_CONSOLE_SIZE) | |
| 94 | * +--------------------------------+ PSP_SHAREDMEM_BASE + PSP_SHAREDMEM_SIZE |
| 95 | * | PSP shared (vboot workbuf) | |
| 96 | * | (PSP_SHAREDMEM_SIZE) | |
| 97 | * +--------------------------------+ PSP_SHAREDMEM_BASE |
| 98 | * | APOB (64KiB) | |
| 99 | * +--------------------------------+ PSP_APOB_DRAM_ADDRESS |
| 100 | * | Early BSP stack | |
| 101 | * | (EARLYRAM_BSP_STACK_SIZE) | |
| 102 | * reserved_dram_start +--------------------------------+ EARLY_RESERVED_DRAM_BASE |
| 103 | * | DRAM | |
| 104 | * +--------------------------------+ 0x100000 |
| 105 | * | Option ROM | |
| 106 | * +--------------------------------+ 0xc0000 |
| 107 | * | Legacy VGA | |
| 108 | * +--------------------------------+ 0xa0000 |
| 109 | * | DRAM | |
| 110 | * +--------------------------------+ 0x0 |
| 111 | */ |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 112 | static void read_resources(struct device *dev) |
| 113 | { |
| 114 | uint32_t mem_usable = (uintptr_t)cbmem_top(); |
| 115 | unsigned int idx = 0; |
| 116 | const struct hob_header *hob = fsp_get_hob_list(); |
| 117 | const struct hob_resource *res; |
Marshall Dawson | 39c64b0 | 2020-09-04 12:07:27 -0600 | [diff] [blame] | 118 | struct resource *gnb_apic; |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 119 | |
Furquan Shaikh | bc45650 | 2020-06-10 16:37:23 -0700 | [diff] [blame] | 120 | uintptr_t early_reserved_dram_start, early_reserved_dram_end; |
| 121 | const struct memmap_early_dram *e = memmap_get_early_dram_usage(); |
| 122 | |
| 123 | early_reserved_dram_start = e->base; |
| 124 | early_reserved_dram_end = e->base + e->size; |
| 125 | |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 126 | /* 0x0 - 0x9ffff */ |
| 127 | ram_resource(dev, idx++, 0, 0xa0000 / KiB); |
| 128 | |
| 129 | /* 0xa0000 - 0xbffff: legacy VGA */ |
| 130 | mmio_resource(dev, idx++, 0xa0000 / KiB, 0x20000 / KiB); |
| 131 | |
| 132 | /* 0xc0000 - 0xfffff: Option ROM */ |
| 133 | reserved_ram_resource(dev, idx++, 0xc0000 / KiB, 0x40000 / KiB); |
| 134 | |
Furquan Shaikh | bc45650 | 2020-06-10 16:37:23 -0700 | [diff] [blame] | 135 | /* 1MB - bottom of DRAM reserved for early coreboot usage */ |
| 136 | ram_resource(dev, idx++, (1 * MiB) / KiB, |
| 137 | (early_reserved_dram_start - (1 * MiB)) / KiB); |
| 138 | |
| 139 | /* DRAM reserved for early coreboot usage */ |
| 140 | reserved_ram_resource(dev, idx++, early_reserved_dram_start / KiB, |
| 141 | (early_reserved_dram_end - early_reserved_dram_start) / KiB); |
| 142 | |
| 143 | /* top of DRAM consumed early - low top usable RAM |
| 144 | * cbmem_top() accounts for low UMA and TSEG if they are used. */ |
| 145 | ram_resource(dev, idx++, early_reserved_dram_end / KiB, |
| 146 | (mem_usable - early_reserved_dram_end) / KiB); |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 147 | |
| 148 | mmconf_resource(dev, MMIO_CONF_BASE); |
| 149 | |
| 150 | if (!hob) { |
| 151 | printk(BIOS_ERR, "Error: %s incomplete because no HOB list was found\n", |
| 152 | __func__); |
| 153 | return; |
| 154 | } |
| 155 | |
| 156 | for (; hob->type != HOB_TYPE_END_OF_HOB_LIST; hob = fsp_next_hob(hob)) { |
| 157 | |
| 158 | if (hob->type != HOB_TYPE_RESOURCE_DESCRIPTOR) |
| 159 | continue; |
| 160 | |
| 161 | res = fsp_hob_header_to_resource(hob); |
| 162 | |
| 163 | if (res->type == EFI_RESOURCE_SYSTEM_MEMORY && res->addr < mem_usable) |
| 164 | continue; /* 0 through low usable was set above */ |
| 165 | if (res->type == EFI_RESOURCE_MEMORY_MAPPED_IO) |
| 166 | continue; /* Done separately */ |
| 167 | |
| 168 | if (res->type == EFI_RESOURCE_SYSTEM_MEMORY) |
| 169 | ram_resource(dev, idx++, res->addr / KiB, res->length / KiB); |
| 170 | else if (res->type == EFI_RESOURCE_MEMORY_RESERVED) |
| 171 | reserved_ram_resource(dev, idx++, res->addr / KiB, res->length / KiB); |
| 172 | else |
| 173 | printk(BIOS_ERR, "Error: failed to set resources for type %d\n", |
| 174 | res->type); |
| 175 | } |
Marshall Dawson | 39c64b0 | 2020-09-04 12:07:27 -0600 | [diff] [blame] | 176 | |
| 177 | /* GNB IOAPIC resource */ |
| 178 | gnb_apic = new_resource(dev, GNB_IO_APIC_ADDR); |
| 179 | gnb_apic->base = GNB_IO_APIC_ADDR; |
| 180 | gnb_apic->size = 0x00001000; |
| 181 | gnb_apic->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 182 | } |
| 183 | |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 184 | static void dptc_call_alib(const char *buf_name, uint8_t *buffer, size_t size) |
| 185 | { |
| 186 | /* Name (buf_name, Buffer(size) {...} */ |
| 187 | acpigen_write_name(buf_name); |
| 188 | acpigen_write_byte_buffer(buffer, size); |
| 189 | |
| 190 | /* \_SB.ALIB(0xc, buf_name) */ |
| 191 | acpigen_emit_namestring("\\_SB.ALIB"); |
| 192 | acpigen_write_integer(ALIB_DPTCI_FUNCTION_ID); |
| 193 | acpigen_emit_namestring(buf_name); |
| 194 | } |
| 195 | |
| 196 | static void acipgen_dptci(void) |
| 197 | { |
Felix Held | 507fc03 | 2020-12-05 01:55:27 +0100 | [diff] [blame] | 198 | const struct soc_amd_picasso_config *config = config_of_soc(); |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 199 | |
| 200 | if (!config->dptc_enable) |
| 201 | return; |
| 202 | |
Zheng Bao | 795d73c | 2020-10-27 15:36:55 +0800 | [diff] [blame] | 203 | struct dptc_input default_input = DPTC_INPUTS(config->thermctl_limit_degreeC, |
| 204 | config->sustained_power_limit_mW, |
| 205 | config->fast_ppt_limit_mW, |
| 206 | config->slow_ppt_limit_mW); |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 207 | struct dptc_input tablet_mode_input = DPTC_INPUTS( |
Zheng Bao | 795d73c | 2020-10-27 15:36:55 +0800 | [diff] [blame] | 208 | config->thermctl_limit_tablet_mode_degreeC, |
| 209 | config->sustained_power_limit_tablet_mode_mW, |
| 210 | config->fast_ppt_limit_tablet_mode_mW, |
| 211 | config->slow_ppt_limit_tablet_mode_mW); |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 212 | /* Scope (\_SB) */ |
| 213 | acpigen_write_scope("\\_SB"); |
| 214 | |
| 215 | /* Method(DPTC, 0, Serialized) */ |
| 216 | acpigen_write_method_serialized("DPTC", 0); |
| 217 | |
| 218 | /* If (LEqual ("\_SB.PCI0.LPCB.EC0.TBMD", 1)) */ |
| 219 | acpigen_write_if_lequal_namestr_int("\\_SB.PCI0.LPCB.EC0.TBMD", 1); |
| 220 | |
| 221 | dptc_call_alib("TABB", (uint8_t *)(void *)&tablet_mode_input, |
| 222 | sizeof(tablet_mode_input)); |
| 223 | |
| 224 | acpigen_pop_len(); /* If */ |
| 225 | |
| 226 | /* Else */ |
| 227 | acpigen_write_else(); |
| 228 | |
| 229 | dptc_call_alib("DEFB", (uint8_t *)(void *)&default_input, sizeof(default_input)); |
| 230 | |
| 231 | acpigen_pop_len(); /* Else */ |
| 232 | |
| 233 | acpigen_pop_len(); /* Method DPTC */ |
| 234 | acpigen_pop_len(); /* Scope \_SB */ |
| 235 | } |
| 236 | |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 237 | /* Used by \_SB.PCI0._CRS */ |
| 238 | static void root_complex_fill_ssdt(const struct device *device) |
| 239 | { |
| 240 | msr_t msr; |
John Zhao | f6f1f73 | 2020-06-26 10:00:02 -0700 | [diff] [blame] | 241 | const char *scope; |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 242 | |
John Zhao | f6f1f73 | 2020-06-26 10:00:02 -0700 | [diff] [blame] | 243 | assert(device); |
Felix Held | 3858fb1 | 2020-06-27 15:11:36 +0200 | [diff] [blame] | 244 | |
John Zhao | f6f1f73 | 2020-06-26 10:00:02 -0700 | [diff] [blame] | 245 | scope = acpi_device_scope(device); |
| 246 | assert(scope); |
| 247 | acpigen_write_scope(scope); |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 248 | |
| 249 | msr = rdmsr(TOP_MEM); |
| 250 | acpigen_write_name_dword("TOM1", msr.lo); |
| 251 | msr = rdmsr(TOP_MEM2); |
| 252 | /* |
| 253 | * Since XP only implements parts of ACPI 2.0, we can't use a qword |
| 254 | * here. |
| 255 | * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt |
| 256 | * slide 22ff. |
| 257 | * Shift value right by 20 bit to make it fit into 32bit, |
| 258 | * giving us 1MB granularity and a limit of almost 4Exabyte of memory. |
| 259 | */ |
| 260 | acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20); |
| 261 | acpigen_pop_len(); |
Chris Wang | 4735b1c | 2020-07-13 23:29:29 +0800 | [diff] [blame] | 262 | acipgen_dptci(); |
Marshall Dawson | eb72487 | 2019-07-16 15:46:35 -0600 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | static struct device_operations root_complex_operations = { |
| 266 | .read_resources = read_resources, |
| 267 | .enable_resources = pci_dev_enable_resources, |
| 268 | .acpi_fill_ssdt = root_complex_fill_ssdt, |
| 269 | }; |
| 270 | |
| 271 | static const struct pci_driver family17_root_complex __pci_driver = { |
| 272 | .ops = &root_complex_operations, |
| 273 | .vendor = PCI_VENDOR_ID_AMD, |
| 274 | .device = PCI_DEVICE_ID_AMD_17H_MODEL_101F_NB, |
| 275 | }; |