Raul E Rangel | cf6dc7d | 2021-02-05 16:00:41 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Felix Held | dd882f3 | 2021-05-12 01:23:50 +0200 | [diff] [blame] | 3 | #include <acpi/acpigen.h> |
Raul E Rangel | 0b123dd | 2021-02-12 15:13:57 -0700 | [diff] [blame] | 4 | #include <amdblocks/acpi.h> |
Felix Held | dd882f3 | 2021-05-12 01:23:50 +0200 | [diff] [blame] | 5 | #include <amdblocks/alib.h> |
Felix Held | 1ed5a63 | 2021-05-04 21:51:43 +0200 | [diff] [blame] | 6 | #include <amdblocks/ioapic.h> |
Raul E Rangel | cf6dc7d | 2021-02-05 16:00:41 -0700 | [diff] [blame] | 7 | #include <amdblocks/memmap.h> |
Felix Held | 1ed5a63 | 2021-05-04 21:51:43 +0200 | [diff] [blame] | 8 | #include <arch/ioapic.h> |
Raul E Rangel | cf6dc7d | 2021-02-05 16:00:41 -0700 | [diff] [blame] | 9 | #include <cbmem.h> |
| 10 | #include <console/console.h> |
| 11 | #include <cpu/amd/msr.h> |
| 12 | #include <device/device.h> |
| 13 | #include <device/pci.h> |
| 14 | #include <device/pci_ids.h> |
| 15 | #include <fsp/util.h> |
Felix Held | 1ed5a63 | 2021-05-04 21:51:43 +0200 | [diff] [blame] | 16 | #include <soc/iomap.h> |
Raul E Rangel | cf6dc7d | 2021-02-05 16:00:41 -0700 | [diff] [blame] | 17 | #include <stdint.h> |
Felix Held | dd882f3 | 2021-05-12 01:23:50 +0200 | [diff] [blame] | 18 | #include "chip.h" |
| 19 | |
| 20 | #define DPTC_TOTAL_UPDATE_PARAMS 4 |
| 21 | |
| 22 | struct dptc_input { |
| 23 | uint16_t size; |
| 24 | struct alib_dptc_param params[DPTC_TOTAL_UPDATE_PARAMS]; |
| 25 | } __packed; |
| 26 | |
| 27 | #define DPTC_INPUTS(_thermctllmit, _sustained, _fast, _slow) \ |
| 28 | { \ |
| 29 | .size = sizeof(struct dptc_input), \ |
| 30 | .params = { \ |
| 31 | { \ |
| 32 | .id = ALIB_DPTC_THERMAL_CONTROL_LIMIT_ID, \ |
| 33 | .value = _thermctllmit, \ |
| 34 | }, \ |
| 35 | { \ |
| 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 | } |
Raul E Rangel | cf6dc7d | 2021-02-05 16:00:41 -0700 | [diff] [blame] | 49 | |
| 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 |
| 69 | * | romstage | |
| 70 | * | (ROMSTAGE_SIZE) | |
| 71 | * +--------------------------------+ ROMSTAGE_ADDR = BOOTBLOCK_END |
| 72 | * | | X86_RESET_VECTOR = BOOTBLOCK_END - 0x10 |
| 73 | * | bootblock | |
| 74 | * | (C_ENV_BOOTBLOCK_SIZE) | |
| 75 | * +--------------------------------+ BOOTBLOCK_ADDR = BOOTBLOCK_END - C_ENV_BOOTBLOCK_SIZE |
| 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 | */ |
| 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; |
Felix Held | 1ed5a63 | 2021-05-04 21:51:43 +0200 | [diff] [blame] | 109 | struct resource *gnb_apic; |
Raul E Rangel | cf6dc7d | 2021-02-05 16:00:41 -0700 | [diff] [blame] | 110 | |
| 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 | |
| 117 | /* 0x0 - 0x9ffff */ |
| 118 | ram_resource(dev, idx++, 0, 0xa0000 / KiB); |
| 119 | |
| 120 | /* 0xa0000 - 0xbffff: legacy VGA */ |
| 121 | mmio_resource(dev, idx++, 0xa0000 / KiB, 0x20000 / KiB); |
| 122 | |
| 123 | /* 0xc0000 - 0xfffff: Option ROM */ |
| 124 | reserved_ram_resource(dev, idx++, 0xc0000 / KiB, 0x40000 / KiB); |
| 125 | |
| 126 | /* 1MiB - bottom of DRAM reserved for early coreboot usage */ |
| 127 | ram_resource(dev, idx++, (1 * MiB) / KiB, |
| 128 | (early_reserved_dram_start - (1 * MiB)) / KiB); |
| 129 | |
| 130 | /* DRAM reserved for early coreboot usage */ |
| 131 | reserved_ram_resource(dev, idx++, early_reserved_dram_start / KiB, |
| 132 | (early_reserved_dram_end - early_reserved_dram_start) / KiB); |
| 133 | |
| 134 | /* |
| 135 | * top of DRAM consumed early - low top usable RAM |
| 136 | * cbmem_top() accounts for low UMA and TSEG if they are used. |
| 137 | */ |
| 138 | ram_resource(dev, idx++, early_reserved_dram_end / KiB, |
| 139 | (mem_usable - early_reserved_dram_end) / KiB); |
| 140 | |
Felix Held | 56b037b | 2022-03-02 22:57:01 +0100 | [diff] [blame] | 141 | mmconf_resource(dev, idx++); |
Raul E Rangel | cf6dc7d | 2021-02-05 16:00:41 -0700 | [diff] [blame] | 142 | |
| 143 | if (!hob) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 144 | printk(BIOS_ERR, "%s incomplete because no HOB list was found\n", |
Raul E Rangel | cf6dc7d | 2021-02-05 16:00:41 -0700 | [diff] [blame] | 145 | __func__); |
| 146 | return; |
| 147 | } |
| 148 | |
| 149 | for (; hob->type != HOB_TYPE_END_OF_HOB_LIST; hob = fsp_next_hob(hob)) { |
| 150 | |
| 151 | if (hob->type != HOB_TYPE_RESOURCE_DESCRIPTOR) |
| 152 | continue; |
| 153 | |
| 154 | res = fsp_hob_header_to_resource(hob); |
| 155 | |
| 156 | if (res->type == EFI_RESOURCE_SYSTEM_MEMORY && res->addr < mem_usable) |
| 157 | continue; /* 0 through low usable was set above */ |
| 158 | if (res->type == EFI_RESOURCE_MEMORY_MAPPED_IO) |
| 159 | continue; /* Done separately */ |
| 160 | |
| 161 | if (res->type == EFI_RESOURCE_SYSTEM_MEMORY) |
| 162 | ram_resource(dev, idx++, res->addr / KiB, res->length / KiB); |
| 163 | else if (res->type == EFI_RESOURCE_MEMORY_RESERVED) |
| 164 | reserved_ram_resource(dev, idx++, res->addr / KiB, res->length / KiB); |
| 165 | else |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 166 | printk(BIOS_ERR, "failed to set resources for type %d\n", |
Raul E Rangel | cf6dc7d | 2021-02-05 16:00:41 -0700 | [diff] [blame] | 167 | res->type); |
| 168 | } |
Felix Held | 1ed5a63 | 2021-05-04 21:51:43 +0200 | [diff] [blame] | 169 | |
| 170 | /* GNB IOAPIC resource */ |
Felix Held | b1197af | 2022-03-02 23:02:31 +0100 | [diff] [blame^] | 171 | gnb_apic = new_resource(dev, idx++); |
Felix Held | 1ed5a63 | 2021-05-04 21:51:43 +0200 | [diff] [blame] | 172 | gnb_apic->base = GNB_IO_APIC_ADDR; |
| 173 | gnb_apic->size = 0x00001000; |
| 174 | gnb_apic->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 175 | } |
| 176 | |
| 177 | static void root_complex_init(struct device *dev) |
| 178 | { |
| 179 | setup_ioapic((u8 *)GNB_IO_APIC_ADDR, GNB_IOAPIC_ID); |
Raul E Rangel | cf6dc7d | 2021-02-05 16:00:41 -0700 | [diff] [blame] | 180 | } |
| 181 | |
Felix Held | dd882f3 | 2021-05-12 01:23:50 +0200 | [diff] [blame] | 182 | static void acipgen_dptci(void) |
| 183 | { |
| 184 | const struct soc_amd_cezanne_config *config = config_of_soc(); |
| 185 | |
| 186 | if (!config->dptc_enable) |
| 187 | return; |
| 188 | |
| 189 | struct dptc_input default_input = DPTC_INPUTS(config->thermctl_limit_degreeC, |
| 190 | config->sustained_power_limit_mW, |
| 191 | config->fast_ppt_limit_mW, |
| 192 | config->slow_ppt_limit_mW); |
| 193 | struct dptc_input tablet_mode_input = DPTC_INPUTS( |
| 194 | config->thermctl_limit_tablet_mode_degreeC, |
| 195 | config->sustained_power_limit_tablet_mode_mW, |
| 196 | config->fast_ppt_limit_tablet_mode_mW, |
| 197 | config->slow_ppt_limit_tablet_mode_mW); |
Felix Held | dd882f3 | 2021-05-12 01:23:50 +0200 | [diff] [blame] | 198 | |
Felix Held | 2d0bf34 | 2021-05-12 01:42:37 +0200 | [diff] [blame] | 199 | acpigen_write_alib_dptc((uint8_t *)&default_input, sizeof(default_input), |
| 200 | (uint8_t *)&tablet_mode_input, sizeof(tablet_mode_input)); |
Felix Held | dd882f3 | 2021-05-12 01:23:50 +0200 | [diff] [blame] | 201 | } |
| 202 | |
Raul E Rangel | 0b123dd | 2021-02-12 15:13:57 -0700 | [diff] [blame] | 203 | static void root_complex_fill_ssdt(const struct device *device) |
| 204 | { |
| 205 | acpi_fill_root_complex_tom(device); |
Felix Held | dd882f3 | 2021-05-12 01:23:50 +0200 | [diff] [blame] | 206 | acipgen_dptci(); |
Raul E Rangel | 0b123dd | 2021-02-12 15:13:57 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Felix Held | b2840130 | 2021-02-17 00:05:34 +0100 | [diff] [blame] | 209 | static const char *gnb_acpi_name(const struct device *dev) |
| 210 | { |
| 211 | return "GNB"; |
| 212 | } |
| 213 | |
Raul E Rangel | cf6dc7d | 2021-02-05 16:00:41 -0700 | [diff] [blame] | 214 | static struct device_operations root_complex_operations = { |
| 215 | .read_resources = read_resources, |
| 216 | .set_resources = noop_set_resources, |
| 217 | .enable_resources = pci_dev_enable_resources, |
Felix Held | 1ed5a63 | 2021-05-04 21:51:43 +0200 | [diff] [blame] | 218 | .init = root_complex_init, |
Felix Held | b2840130 | 2021-02-17 00:05:34 +0100 | [diff] [blame] | 219 | .acpi_name = gnb_acpi_name, |
Raul E Rangel | 0b123dd | 2021-02-12 15:13:57 -0700 | [diff] [blame] | 220 | .acpi_fill_ssdt = root_complex_fill_ssdt, |
Raul E Rangel | cf6dc7d | 2021-02-05 16:00:41 -0700 | [diff] [blame] | 221 | }; |
| 222 | |
| 223 | static const struct pci_driver family17_root_complex __pci_driver = { |
| 224 | .ops = &root_complex_operations, |
| 225 | .vendor = PCI_VENDOR_ID_AMD, |
| 226 | .device = PCI_DEVICE_ID_AMD_17H_MODEL_606F_NB, |
| 227 | }; |