Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | /* |
| 4 | * This file is created based on Intel Alder Lake Processor SA Datasheet |
| 5 | * Document number: 619503 |
| 6 | * Chapter number: 3 |
| 7 | */ |
| 8 | |
Eran Mitrani | ca74105 | 2022-06-09 10:50:22 -0700 | [diff] [blame] | 9 | #include <arch/ioapic.h> |
Sumeet Pawnikar | aa49608 | 2021-05-07 20:11:53 +0530 | [diff] [blame] | 10 | #include <console/console.h> |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 11 | #include <device/device.h> |
| 12 | #include <device/pci.h> |
Sumeet R Pawnikar | 77298c6 | 2021-03-10 21:09:37 +0530 | [diff] [blame] | 13 | #include <delay.h> |
Eran Mitrani | ca74105 | 2022-06-09 10:50:22 -0700 | [diff] [blame] | 14 | #include <intelblocks/cpulib.h> |
| 15 | #include <intelblocks/msr.h> |
Sumeet R Pawnikar | 77298c6 | 2021-03-10 21:09:37 +0530 | [diff] [blame] | 16 | #include <intelblocks/power_limit.h> |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 17 | #include <intelblocks/systemagent.h> |
| 18 | #include <soc/iomap.h> |
Sumeet R Pawnikar | 77298c6 | 2021-03-10 21:09:37 +0530 | [diff] [blame] | 19 | #include <soc/soc_chip.h> |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 20 | #include <soc/systemagent.h> |
Eran Mitrani | ca74105 | 2022-06-09 10:50:22 -0700 | [diff] [blame] | 21 | #include <spi_flash.h> |
| 22 | #include "stddef.h" |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 23 | |
| 24 | /* |
| 25 | * SoC implementation |
| 26 | * |
| 27 | * Add all known fixed memory ranges for Host Controller/Memory |
| 28 | * controller. |
| 29 | */ |
| 30 | void soc_add_fixed_mmio_resources(struct device *dev, int *index) |
| 31 | { |
| 32 | static const struct sa_mmio_descriptor soc_fixed_resources[] = { |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 33 | { MCHBAR, MCH_BASE_ADDRESS, MCH_BASE_SIZE, "MCHBAR" }, |
| 34 | { DMIBAR, DMI_BASE_ADDRESS, DMI_BASE_SIZE, "DMIBAR" }, |
| 35 | { EPBAR, EP_BASE_ADDRESS, EP_BASE_SIZE, "EPBAR" }, |
| 36 | { REGBAR, REG_BASE_ADDRESS, REG_BASE_SIZE, "REGBAR" }, |
| 37 | { EDRAMBAR, EDRAM_BASE_ADDRESS, EDRAM_BASE_SIZE, "EDRAMBAR" }, |
Eran Mitrani | ca74105 | 2022-06-09 10:50:22 -0700 | [diff] [blame] | 38 | |
| 39 | /* first field (sa_mmio_descriptor.index) is not used, setting to 0: */ |
| 40 | { 0, CRAB_ABORT_BASE_ADDR, CRAB_ABORT_SIZE, "CRAB_ABORT" }, |
| 41 | { 0, TPM_BASE_ADDRESS, TPM_SIZE, "TPM" }, |
| 42 | { 0, LT_SECURITY_BASE_ADDR, LT_SECURITY_SIZE, "LT_SECURITY" }, |
| 43 | { 0, IO_APIC_ADDR, APIC_SIZE, "APIC" }, |
| 44 | // PCH_PRESERVERD covers: |
| 45 | // TraceHub SW BAR, SBREG, PMC MBAR, SPI BAR0, SerialIo BAR in ACPI mode |
| 46 | // eSPI LGMR BAR, eSPI2 SEGMR BAR, TraceHub MTB BAR, TraceHub FW BAR |
| 47 | // see fsp/ClientOneSiliconPkg/Fru/AdlPch/Include/PchReservedResourcesAdpP.h |
| 48 | { 0, PCH_PRESERVED_BASE_ADDRESS, PCH_PRESERVED_BASE_SIZE, "PCH_RESERVED" }, |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | sa_add_fixed_mmio_resources(dev, index, soc_fixed_resources, |
| 52 | ARRAY_SIZE(soc_fixed_resources)); |
| 53 | |
| 54 | /* Add Vt-d resources if VT-d is enabled */ |
| 55 | if ((pci_read_config32(dev, CAPID0_A) & VTD_DISABLE)) |
| 56 | return; |
| 57 | |
| 58 | sa_add_fixed_mmio_resources(dev, index, soc_vtd_resources, |
| 59 | ARRAY_SIZE(soc_vtd_resources)); |
| 60 | } |
| 61 | |
| 62 | /* |
Eran Mitrani | ca74105 | 2022-06-09 10:50:22 -0700 | [diff] [blame] | 63 | * set MMIO resource's fields |
| 64 | */ |
| 65 | static void set_mmio_resource( |
| 66 | struct sa_mmio_descriptor *resource, |
| 67 | uint64_t base, |
| 68 | uint64_t size, |
| 69 | const char *description) |
| 70 | { |
| 71 | if (resource == NULL) { |
| 72 | printk(BIOS_ERR, "%s: argument resource is NULL for %s\n", |
| 73 | __func__, description); |
| 74 | return; |
| 75 | } |
| 76 | resource->base = base; |
| 77 | resource->size = size; |
| 78 | resource->description = description; |
| 79 | } |
| 80 | |
| 81 | /* |
| 82 | * SoC implementation |
| 83 | * |
| 84 | * Add all known configurable memory ranges for Host Controller/Memory |
| 85 | * controller. |
| 86 | */ |
| 87 | void soc_add_configurable_mmio_resources(struct device *dev, int *resource_cnt) |
| 88 | { |
| 89 | uint64_t size, base, tseg_base; |
| 90 | int count = 0; |
| 91 | struct sa_mmio_descriptor cfg_rsrc[6]; /* Increase size when adding more resources */ |
| 92 | |
| 93 | /* MMCONF */ |
| 94 | size = get_mmcfg_size(dev); |
| 95 | if (size > 0) |
| 96 | set_mmio_resource(&(cfg_rsrc[count++]), CONFIG_ECAM_MMCONF_BASE_ADDRESS, |
| 97 | size, "MMCONF"); |
| 98 | |
| 99 | /* DSM */ |
| 100 | size = get_dsm_size(dev); |
| 101 | if (size > 0) { |
| 102 | base = pci_read_config32(dev, DSM_BASE_ADDR_REG) & 0xFFF00000; |
| 103 | set_mmio_resource(&(cfg_rsrc[count++]), base, size, "DSM"); |
| 104 | } |
| 105 | |
| 106 | /* TSEG */ |
| 107 | size = sa_get_tseg_size(); |
| 108 | tseg_base = sa_get_tseg_base(); |
| 109 | if (size > 0) |
| 110 | set_mmio_resource(&(cfg_rsrc[count++]), tseg_base, size, "TSEG"); |
| 111 | |
| 112 | /* PMRR */ |
| 113 | size = get_valid_prmrr_size(); |
| 114 | if (size > 0) { |
| 115 | uint64_t mask = pci_read_config32(dev, MSR_PRMRR_PHYS_MASK); |
| 116 | base = pci_read_config32(dev, MSR_PRMRR_PHYS_BASE) & mask; |
| 117 | set_mmio_resource(&(cfg_rsrc[count++]), base, size, "PMRR"); |
| 118 | } |
| 119 | |
| 120 | /* GSM */ |
| 121 | size = get_gsm_size(dev); |
| 122 | if (size > 0) { |
| 123 | base = sa_get_gsm_base(); |
| 124 | set_mmio_resource(&(cfg_rsrc[count++]), base, size, "GSM"); |
| 125 | } |
| 126 | |
| 127 | /* DPR */ |
| 128 | size = get_dpr_size(dev); |
| 129 | if (size > 0) { |
| 130 | /* DPR just below TSEG: */ |
| 131 | base = tseg_base - size; |
| 132 | set_mmio_resource(&(cfg_rsrc[count++]), base, size, "DPR"); |
| 133 | } |
| 134 | |
| 135 | /* Add all the above */ |
| 136 | sa_add_fixed_mmio_resources(dev, resource_cnt, cfg_rsrc, count); |
| 137 | } |
| 138 | |
| 139 | /* |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 140 | * SoC implementation |
| 141 | * |
| 142 | * Perform System Agent Initialization during Ramstage phase. |
| 143 | */ |
| 144 | void soc_systemagent_init(struct device *dev) |
| 145 | { |
Sumeet R Pawnikar | 77298c6 | 2021-03-10 21:09:37 +0530 | [diff] [blame] | 146 | struct soc_power_limits_config *soc_config; |
Sumeet Pawnikar | aa49608 | 2021-05-07 20:11:53 +0530 | [diff] [blame] | 147 | struct device *sa; |
| 148 | uint16_t sa_pci_id; |
Sumeet Pawnikar | eaf87a9 | 2021-08-31 17:01:02 +0530 | [diff] [blame] | 149 | u8 tdp; |
| 150 | size_t i; |
Sumeet R Pawnikar | 77298c6 | 2021-03-10 21:09:37 +0530 | [diff] [blame] | 151 | config_t *config; |
| 152 | |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 153 | /* Enable Power Aware Interrupt Routing */ |
| 154 | enable_power_aware_intr(); |
| 155 | |
Sumeet R Pawnikar | 77298c6 | 2021-03-10 21:09:37 +0530 | [diff] [blame] | 156 | config = config_of_soc(); |
Sumeet Pawnikar | aa49608 | 2021-05-07 20:11:53 +0530 | [diff] [blame] | 157 | |
| 158 | /* Get System Agent PCI ID */ |
| 159 | sa = pcidev_path_on_root(SA_DEVFN_ROOT); |
| 160 | sa_pci_id = sa ? pci_read_config16(sa, PCI_DEVICE_ID) : 0xFFFF; |
| 161 | |
Sumeet Pawnikar | eaf87a9 | 2021-08-31 17:01:02 +0530 | [diff] [blame] | 162 | tdp = get_cpu_tdp(); |
| 163 | |
| 164 | /* Choose power limits configuration based on the CPU SA PCI ID and |
| 165 | * CPU TDP value. */ |
| 166 | for (i = 0; i < ARRAY_SIZE(cpuid_to_adl); i++) { |
| 167 | if (sa_pci_id == cpuid_to_adl[i].cpu_id && |
| 168 | tdp == cpuid_to_adl[i].cpu_tdp) { |
| 169 | soc_config = &config->power_limits_config[cpuid_to_adl[i].limits]; |
| 170 | set_power_limits(MOBILE_SKU_PL1_TIME_SEC, soc_config); |
| 171 | break; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | if (i == ARRAY_SIZE(cpuid_to_adl)) { |
Julius Werner | e966595 | 2022-01-21 17:06:20 -0800 | [diff] [blame] | 176 | printk(BIOS_ERR, "unknown SA ID: 0x%4x, skipped power limits configuration.\n", |
Sumeet Pawnikar | aa49608 | 2021-05-07 20:11:53 +0530 | [diff] [blame] | 177 | sa_pci_id); |
| 178 | return; |
| 179 | } |
Subrata Banik | 2871e0e | 2020-09-27 11:30:58 +0530 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | uint32_t soc_systemagent_max_chan_capacity_mib(u8 capid0_a_ddrsz) |
| 183 | { |
| 184 | switch (capid0_a_ddrsz) { |
| 185 | case 1: |
| 186 | return 8192; |
| 187 | case 2: |
| 188 | return 4096; |
| 189 | case 3: |
| 190 | return 2048; |
| 191 | default: |
| 192 | return 65536; |
| 193 | } |
| 194 | } |
Eran Mitrani | ca74105 | 2022-06-09 10:50:22 -0700 | [diff] [blame] | 195 | |
| 196 | uint64_t get_mmcfg_size(struct device *dev) |
| 197 | { |
| 198 | uint32_t pciexbar_reg; |
| 199 | uint64_t mmcfg_length; |
| 200 | |
| 201 | if (!dev) { |
| 202 | printk(BIOS_DEBUG, "%s : device is null\n", __func__); |
| 203 | return 0; |
| 204 | } |
| 205 | |
| 206 | pciexbar_reg = pci_read_config32(dev, PCIEXBAR); |
| 207 | |
| 208 | if (!(pciexbar_reg & (1 << 0))) { |
| 209 | printk(BIOS_DEBUG, "%s : PCIEXBAR disabled\n", __func__); |
| 210 | return 0; |
| 211 | } |
| 212 | |
| 213 | switch ((pciexbar_reg & MASK_PCIEXBAR_LENGTH) >> PCIEXBAR_LENGTH_LSB) { |
| 214 | case PCIEXBAR_LENGTH_4096MB: |
| 215 | mmcfg_length = 4 * ((uint64_t)GiB); |
| 216 | break; |
| 217 | case PCIEXBAR_LENGTH_2048MB: |
| 218 | mmcfg_length = 2 * ((uint64_t)GiB); |
| 219 | break; |
| 220 | case PCIEXBAR_LENGTH_1024MB: |
| 221 | mmcfg_length = 1 * GiB; |
| 222 | break; |
| 223 | case PCIEXBAR_LENGTH_512MB: |
| 224 | mmcfg_length = 512 * MiB; |
| 225 | break; |
| 226 | case PCIEXBAR_LENGTH_256MB: |
| 227 | mmcfg_length = 256 * MiB; |
| 228 | break; |
| 229 | case PCIEXBAR_LENGTH_128MB: |
| 230 | mmcfg_length = 128 * MiB; |
| 231 | break; |
| 232 | case PCIEXBAR_LENGTH_64MB: |
| 233 | mmcfg_length = 64 * MiB; |
| 234 | break; |
| 235 | default: |
| 236 | printk(BIOS_DEBUG, "%s : PCIEXBAR - invalid length (0x%x)\n", __func__, |
| 237 | pciexbar_reg & MASK_PCIEXBAR_LENGTH); |
| 238 | mmcfg_length = 0x0; |
| 239 | break; |
| 240 | } |
| 241 | |
| 242 | return mmcfg_length; |
| 243 | } |
| 244 | |
| 245 | uint64_t get_dsm_size(struct device *dev) |
| 246 | { |
| 247 | // - size : B0/D0/F0:R 50h [15:8] |
| 248 | uint32_t reg32 = pci_read_config32(dev, GGC); |
| 249 | uint64_t size; |
| 250 | uint32_t size_field = (reg32 & MASK_DSM_LENGTH) >> MASK_DSM_LENGTH_LSB; |
| 251 | if (size_field <= 0x10) { // 0x0 - 0x10 |
| 252 | size = size_field * 32 * MiB; |
| 253 | } else if ((size_field >= 0xF0) && (size_field >= 0xFE)) { |
| 254 | size = (size_field - 0xEF) * 4 * MiB; |
| 255 | } else { |
| 256 | switch (size_field) { |
| 257 | case 0x20: |
| 258 | size = 1 * GiB; |
| 259 | break; |
| 260 | case 0x30: |
| 261 | size = 1536 * MiB; |
| 262 | break; |
| 263 | case 0x40: |
| 264 | size = 2 * (uint64_t)GiB; |
| 265 | break; |
| 266 | default: |
| 267 | printk(BIOS_DEBUG, "%s : DSM - invalid length (0x%x)\n", |
| 268 | __func__, size_field); |
| 269 | size = 0x0; |
| 270 | break; |
| 271 | } |
| 272 | } |
| 273 | return size; |
| 274 | } |
| 275 | |
| 276 | uint64_t get_gsm_size(struct device *dev) |
| 277 | { |
| 278 | const u32 gsm_size = pci_read_config32(dev, GGC); |
| 279 | uint64_t size; |
| 280 | uint32_t size_field = (gsm_size & MASK_GSM_LENGTH) >> MASK_GSM_LENGTH_LSB; |
| 281 | switch (size_field) { |
| 282 | case 0x0: |
| 283 | size = 0; |
| 284 | break; |
| 285 | case 0x1: |
| 286 | size = 2 * MiB; |
| 287 | break; |
| 288 | case 0x2: |
| 289 | size = 4 * MiB; |
| 290 | break; |
| 291 | case 0x3: |
| 292 | size = 8 * MiB; |
| 293 | break; |
| 294 | default: |
| 295 | size = 0; |
| 296 | break; |
| 297 | } |
| 298 | return size; |
| 299 | } |
| 300 | uint64_t get_dpr_size(struct device *dev) |
| 301 | { |
| 302 | uint64_t size; |
| 303 | uint32_t dpr_reg = pci_read_config32(dev, DPR_REG); |
| 304 | uint32_t size_field = (dpr_reg & MASK_DPR_LENGTH) >> MASK_DPR_LENGTH_LSB; |
| 305 | size = size_field * MiB; |
| 306 | return size; |
| 307 | } |