Patrick Georgi | ac95903 | 2020-05-05 22:49:26 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 2 | |
| 3 | #include <cbmem.h> |
| 4 | #include <console/console.h> |
Elyes HAOUAS | 32da343 | 2020-05-17 17:15:31 +0200 | [diff] [blame] | 5 | #include <cpu/x86/lapic_def.h> |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 6 | #include <device/pci.h> |
| 7 | #include <device/pci_ids.h> |
Jonathan Zhang | 907b6f5 | 2023-01-30 12:11:52 -0800 | [diff] [blame] | 8 | #include <drivers/ocp/include/vpd.h> |
Marc Jones | 521a03f | 2020-10-19 13:46:59 -0600 | [diff] [blame] | 9 | #include <soc/acpi.h> |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 10 | #include <soc/iomap.h> |
| 11 | #include <soc/pci_devs.h> |
| 12 | #include <soc/ramstage.h> |
Andrey Petrov | 662da6c | 2020-03-16 22:46:57 -0700 | [diff] [blame] | 13 | #include <soc/util.h> |
| 14 | #include <fsp/util.h> |
Arthur Heymans | 77509be | 2020-10-22 17:11:22 +0200 | [diff] [blame] | 15 | #include <security/intel/txt/txt_platform.h> |
Arthur Heymans | 9d8a455 | 2021-02-02 19:21:24 +0100 | [diff] [blame] | 16 | #include <security/intel/txt/txt.h> |
Jonathan Zhang | 907b6f5 | 2023-01-30 12:11:52 -0800 | [diff] [blame] | 17 | #include <soc/numa.h> |
| 18 | #include <soc/soc_util.h> |
Arthur Heymans | 6366059 | 2022-01-06 12:28:44 +0100 | [diff] [blame] | 19 | #include <stdint.h> |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 20 | |
Jonathan Zhang | 907b6f5 | 2023-01-30 12:11:52 -0800 | [diff] [blame] | 21 | struct proximity_domains pds = { |
| 22 | .num_pds = 0, |
| 23 | .pds = NULL, |
| 24 | }; |
| 25 | |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 26 | struct map_entry { |
| 27 | uint32_t reg; |
| 28 | int is_64_bit; |
| 29 | int is_limit; |
| 30 | int mask_bits; |
| 31 | const char *description; |
| 32 | }; |
| 33 | |
| 34 | enum { |
| 35 | TOHM_REG, |
| 36 | MMIOL_REG, |
| 37 | MMCFG_BASE_REG, |
| 38 | MMCFG_LIMIT_REG, |
| 39 | TOLM_REG, |
Jonathan Zhang | 09d2c93 | 2023-01-30 11:23:04 -0800 | [diff] [blame] | 40 | /* NCMEM and ME ranges are mutually exclusive */ |
| 41 | NCMEM_BASE_REG, |
| 42 | NCMEM_LIMIT_REG, |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 43 | ME_BASE_REG, |
| 44 | ME_LIMIT_REG, |
| 45 | TSEG_BASE_REG, |
| 46 | TSEG_LIMIT_REG, |
| 47 | /* Must be last. */ |
| 48 | NUM_MAP_ENTRIES |
| 49 | }; |
| 50 | |
| 51 | static struct map_entry memory_map[NUM_MAP_ENTRIES] = { |
| 52 | [TOHM_REG] = MAP_ENTRY_LIMIT_64(VTD_TOHM_CSR, 26, "TOHM"), |
| 53 | [MMIOL_REG] = MAP_ENTRY_BASE_32(VTD_MMIOL_CSR, "MMIOL"), |
| 54 | [MMCFG_BASE_REG] = MAP_ENTRY_BASE_64(VTD_MMCFG_BASE_CSR, "MMCFG_BASE"), |
| 55 | [MMCFG_LIMIT_REG] = MAP_ENTRY_LIMIT_64(VTD_MMCFG_LIMIT_CSR, 26, "MMCFG_LIMIT"), |
| 56 | [TOLM_REG] = MAP_ENTRY_LIMIT_32(VTD_TOLM_CSR, 26, "TOLM"), |
Jonathan Zhang | 09d2c93 | 2023-01-30 11:23:04 -0800 | [diff] [blame] | 57 | #if CONFIG(SOC_INTEL_HAS_NCMEM) |
| 58 | [NCMEM_BASE_REG] = MAP_ENTRY_BASE_64(VTD_NCMEM_BASE_CSR, "NCMEM_BASE"), |
| 59 | [NCMEM_LIMIT_REG] = MAP_ENTRY_LIMIT_64(VTD_NCMEM_LIMIT_CSR, 19, "NCMEM_LIMIT"), |
| 60 | #else |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 61 | [ME_BASE_REG] = MAP_ENTRY_BASE_64(VTD_ME_BASE_CSR, "ME_BASE"), |
| 62 | [ME_LIMIT_REG] = MAP_ENTRY_LIMIT_64(VTD_ME_LIMIT_CSR, 19, "ME_LIMIT"), |
Jonathan Zhang | 09d2c93 | 2023-01-30 11:23:04 -0800 | [diff] [blame] | 63 | #endif |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 64 | [TSEG_BASE_REG] = MAP_ENTRY_BASE_32(VTD_TSEG_BASE_CSR, "TSEGMB_BASE"), |
| 65 | [TSEG_LIMIT_REG] = MAP_ENTRY_LIMIT_32(VTD_TSEG_LIMIT_CSR, 20, "TSEGMB_LIMIT"), |
| 66 | }; |
| 67 | |
| 68 | static void read_map_entry(struct device *dev, struct map_entry *entry, |
| 69 | uint64_t *result) |
| 70 | { |
| 71 | uint64_t value; |
| 72 | uint64_t mask; |
| 73 | |
| 74 | /* All registers are on a 1MiB granularity. */ |
| 75 | mask = ((1ULL << entry->mask_bits) - 1); |
| 76 | mask = ~mask; |
| 77 | |
| 78 | value = 0; |
| 79 | |
| 80 | if (entry->is_64_bit) { |
| 81 | value = pci_read_config32(dev, entry->reg + sizeof(uint32_t)); |
| 82 | value <<= 32; |
| 83 | } |
| 84 | |
| 85 | value |= (uint64_t)pci_read_config32(dev, entry->reg); |
| 86 | value &= mask; |
| 87 | |
| 88 | if (entry->is_limit) |
| 89 | value |= ~mask; |
| 90 | |
| 91 | *result = value; |
| 92 | } |
| 93 | |
| 94 | static void mc_read_map_entries(struct device *dev, uint64_t *values) |
| 95 | { |
| 96 | int i; |
| 97 | for (i = 0; i < NUM_MAP_ENTRIES; i++) |
| 98 | read_map_entry(dev, &memory_map[i], &values[i]); |
| 99 | } |
| 100 | |
| 101 | static void mc_report_map_entries(struct device *dev, uint64_t *values) |
| 102 | { |
| 103 | int i; |
| 104 | for (i = 0; i < NUM_MAP_ENTRIES; i++) { |
| 105 | printk(BIOS_DEBUG, "MC MAP: %s: 0x%llx\n", |
| 106 | memory_map[i].description, values[i]); |
| 107 | } |
| 108 | } |
| 109 | |
Arthur Heymans | 77509be | 2020-10-22 17:11:22 +0200 | [diff] [blame] | 110 | static void configure_dpr(struct device *dev) |
| 111 | { |
| 112 | const uintptr_t cbmem_top_mb = ALIGN_UP((uintptr_t)cbmem_top(), MiB) / MiB; |
| 113 | union dpr_register dpr = { .raw = pci_read_config32(dev, VTD_LTDPR) }; |
| 114 | |
| 115 | /* The DPR lock bit has to be set sufficiently early. It looks like |
| 116 | * it cannot be set anymore after FSP-S. |
| 117 | */ |
| 118 | dpr.lock = 1; |
| 119 | dpr.epm = 1; |
| 120 | dpr.size = dpr.top - cbmem_top_mb; |
| 121 | pci_write_config32(dev, VTD_LTDPR, dpr.raw); |
| 122 | } |
| 123 | |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 124 | /* |
| 125 | * Host Memory Map: |
| 126 | * |
| 127 | * +--------------------------+ TOCM (2 pow 46 - 1) |
| 128 | * | Reserved | |
| 129 | * +--------------------------+ |
| 130 | * | MMIOH (relocatable) | |
| 131 | * +--------------------------+ |
| 132 | * | PCISeg | |
| 133 | * +--------------------------+ TOHM |
| 134 | * | High DRAM Memory | |
| 135 | * +--------------------------+ 4GiB (0x100000000) |
| 136 | * +--------------------------+ 0xFFFF_FFFF |
| 137 | * | Firmware | |
| 138 | * +--------------------------+ 0xFF00_0000 |
| 139 | * | Reserved | |
| 140 | * +--------------------------+ 0xFEF0_0000 |
| 141 | * | Local xAPIC | |
| 142 | * +--------------------------+ 0xFEE0_0000 |
| 143 | * | HPET/LT/TPM/Others | |
| 144 | * +--------------------------+ 0xFED0_0000 |
| 145 | * | I/O xAPIC | |
| 146 | * +--------------------------+ 0xFEC0_0000 |
| 147 | * | Reserved | |
| 148 | * +--------------------------+ 0xFEB8_0000 |
| 149 | * | Reserved | |
| 150 | * +--------------------------+ 0xFEB0_0000 |
| 151 | * | Reserved | |
| 152 | * +--------------------------+ 0xFE00_0000 |
| 153 | * | MMIOL (relocatable) | |
| 154 | * | P2SB PCR cfg BAR | (0xfd000000 - 0xfdffffff |
| 155 | * | BAR space | [mem 0x90000000-0xfcffffff] available for PCI devices |
| 156 | * +--------------------------+ 0x9000_0000 |
Shelley Chen | 4e9bb33 | 2021-10-20 15:43:45 -0700 | [diff] [blame] | 157 | * |PCIe MMCFG (relocatable) | CONFIG_ECAM_MMCONF_BASE_ADDRESS 64 or 256MB |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 158 | * | | (0x80000000 - 0x8fffffff, 0x40000) |
| 159 | * +--------------------------+ TOLM |
| 160 | * | MEseg (relocatable) | 32, 64, 128 or 256 MB (0x78000000 - 0x7fffffff, 0x20000) |
| 161 | * +--------------------------+ |
| 162 | * | Tseg (relocatable) | N x 8MB (0x70000000 - 0x77ffffff, 0x20000) |
Arthur Heymans | 77509be | 2020-10-22 17:11:22 +0200 | [diff] [blame] | 163 | * +--------------------------+ |
| 164 | * | DPR | |
Jonathan Zhang | 43b0ed7 | 2022-12-19 15:42:56 -0800 | [diff] [blame] | 165 | * +--------------------------+ 1M aligned DPR base |
| 166 | * | Unused memory | |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 167 | * +--------------------------+ cbmem_top |
| 168 | * | Reserved - CBMEM | (0x6fffe000 - 0x6fffffff, 0x2000) |
| 169 | * +--------------------------+ |
| 170 | * | Reserved - FSP | (0x6fbfe000 - 0x6fffdfff, 0x400000) |
| 171 | * +--------------------------+ top_of_ram (0x6fbfdfff) |
| 172 | * | Low DRAM Memory | |
| 173 | * +--------------------------+ FFFFF (1MB) |
| 174 | * | E & F segments | |
| 175 | * +--------------------------+ E0000 |
| 176 | * | C & D segments | |
| 177 | * +--------------------------+ C0000 |
| 178 | * | VGA & SMM Memory | |
| 179 | * +--------------------------+ A0000 |
| 180 | * | Conventional Memory | |
| 181 | * | (DOS Range) | |
| 182 | * +--------------------------+ 0 |
| 183 | */ |
| 184 | |
| 185 | static void mc_add_dram_resources(struct device *dev, int *res_count) |
| 186 | { |
Kyösti Mälkki | 6f9c357 | 2021-06-14 00:40:22 +0300 | [diff] [blame] | 187 | const struct resource *res; |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 188 | uint64_t mc_values[NUM_MAP_ENTRIES]; |
Jonathan Zhang | 43b0ed7 | 2022-12-19 15:42:56 -0800 | [diff] [blame] | 189 | uint64_t top_of_ram; |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 190 | int index = *res_count; |
Jonathan Zhang | 43b0ed7 | 2022-12-19 15:42:56 -0800 | [diff] [blame] | 191 | struct range_entry fsp_mem; |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 192 | |
Marc Jones | 662ac54 | 2020-11-02 21:26:41 -0700 | [diff] [blame] | 193 | /* Only add dram resources once. */ |
| 194 | if (dev->bus->secondary != 0) |
| 195 | return; |
| 196 | |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 197 | /* Read in the MAP registers and report their values. */ |
| 198 | mc_read_map_entries(dev, &mc_values[0]); |
| 199 | mc_report_map_entries(dev, &mc_values[0]); |
| 200 | |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 201 | /* Conventional Memory (DOS region, 0x0 to 0x9FFFF) */ |
Kyösti Mälkki | 6f9c357 | 2021-06-14 00:40:22 +0300 | [diff] [blame] | 202 | res = ram_from_to(dev, index++, 0, 0xa0000); |
| 203 | LOG_RESOURCE("legacy_ram", dev, res); |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 204 | |
Jonathan Zhang | 43b0ed7 | 2022-12-19 15:42:56 -0800 | [diff] [blame] | 205 | /* 1MB -> top_of_ram */ |
| 206 | fsp_find_reserved_memory(&fsp_mem); |
| 207 | top_of_ram = range_entry_base(&fsp_mem) - 1; |
| 208 | res = ram_from_to(dev, index++, 1 * MiB, top_of_ram); |
Kyösti Mälkki | 6f9c357 | 2021-06-14 00:40:22 +0300 | [diff] [blame] | 209 | LOG_RESOURCE("low_ram", dev, res); |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 210 | |
Jonathan Zhang | 43b0ed7 | 2022-12-19 15:42:56 -0800 | [diff] [blame] | 211 | /* top_of_ram -> cbmem_top */ |
| 212 | res = ram_from_to(dev, index++, top_of_ram, (uintptr_t)cbmem_top()); |
| 213 | LOG_RESOURCE("cbmem_ram", dev, res); |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 214 | |
Jonathan Zhang | 2e495b0 | 2023-01-30 11:32:26 -0800 | [diff] [blame] | 215 | /* Mark TSEG/SMM region as reserved */ |
| 216 | res = reserved_ram_from_to(dev, index++, mc_values[TSEG_BASE_REG], |
| 217 | mc_values[TSEG_LIMIT_REG] + 1); |
| 218 | LOG_RESOURCE("mmio_tseg", dev, res); |
| 219 | |
Jonathan Zhang | da538cb | 2022-12-19 15:49:33 -0800 | [diff] [blame] | 220 | /* Reserve DPR region */ |
Arthur Heymans | 77509be | 2020-10-22 17:11:22 +0200 | [diff] [blame] | 221 | union dpr_register dpr = { .raw = pci_read_config32(dev, VTD_LTDPR) }; |
| 222 | if (dpr.size) { |
Jonathan Zhang | 43b0ed7 | 2022-12-19 15:42:56 -0800 | [diff] [blame] | 223 | /* |
| 224 | * cbmem_top -> DPR base: |
| 225 | * DPR has a 1M granularity so it's possible if cbmem_top is not 1M |
| 226 | * aligned that some memory does not get marked as assigned. |
| 227 | */ |
| 228 | res = reserved_ram_from_to(dev, index++, (uintptr_t)cbmem_top(), |
| 229 | (dpr.top - dpr.size) * MiB); |
| 230 | LOG_RESOURCE("unused_dram", dev, res); |
| 231 | |
| 232 | /* DPR base -> DPR top */ |
Kyösti Mälkki | 6f9c357 | 2021-06-14 00:40:22 +0300 | [diff] [blame] | 233 | res = reserved_ram_from_to(dev, index++, (dpr.top - dpr.size) * MiB, |
| 234 | dpr.top * MiB); |
| 235 | LOG_RESOURCE("dpr", dev, res); |
Jonathan Zhang | 43b0ed7 | 2022-12-19 15:42:56 -0800 | [diff] [blame] | 236 | |
Arthur Heymans | 77509be | 2020-10-22 17:11:22 +0200 | [diff] [blame] | 237 | } |
| 238 | |
Jonathan Zhang | 43b0ed7 | 2022-12-19 15:42:56 -0800 | [diff] [blame] | 239 | /* Mark TSEG/SMM region as reserved */ |
| 240 | res = reserved_ram_from_to(dev, index++, mc_values[TSEG_BASE_REG], |
| 241 | mc_values[TSEG_LIMIT_REG] + 1); |
| 242 | LOG_RESOURCE("mmio_tseg", dev, res); |
| 243 | |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 244 | /* Mark region between TSEG - TOLM (eg. MESEG) as reserved */ |
Kyösti Mälkki | 6f9c357 | 2021-06-14 00:40:22 +0300 | [diff] [blame] | 245 | res = reserved_ram_from_to(dev, index++, mc_values[TSEG_LIMIT_REG] + 1, |
| 246 | mc_values[TOLM_REG]); |
| 247 | LOG_RESOURCE("mmio_tolm", dev, res); |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 248 | |
Jonathan Zhang | 907b6f5 | 2023-01-30 12:11:52 -0800 | [diff] [blame] | 249 | if (CONFIG(SOC_INTEL_HAS_CXL)) { |
| 250 | /* 4GiB -> CXL Memory */ |
| 251 | uint32_t gi_mem_size; |
Johnny Lin | 514930c | 2023-04-11 15:30:02 +0800 | [diff] [blame] | 252 | gi_mem_size = get_generic_initiator_mem_size(); /* unit: 64MB */ |
| 253 | /* |
| 254 | * Memory layout when there is CXL HDM (Host-managed Device Memory): |
| 255 | * -------------- <- TOHM |
| 256 | * CXL memory regions (pds global variable records the base/size of them) |
| 257 | * Processor attached high memory |
| 258 | * -------------- <- 0x100000000 (4GB) |
| 259 | */ |
| 260 | res = upper_ram_end(dev, index++, |
| 261 | mc_values[TOHM_REG] - ((uint64_t)gi_mem_size << 26) + 1); |
Jonathan Zhang | 907b6f5 | 2023-01-30 12:11:52 -0800 | [diff] [blame] | 262 | LOG_RESOURCE("high_ram", dev, res); |
| 263 | |
| 264 | /* CXL Memory */ |
| 265 | uint8_t i; |
| 266 | for (i = 0; i < pds.num_pds; i++) { |
| 267 | if (pds.pds[i].pd_type == PD_TYPE_PROCESSOR) |
| 268 | continue; |
| 269 | |
| 270 | if (CONFIG(OCP_VPD)) { |
| 271 | unsigned long flags = IORESOURCE_CACHEABLE; |
| 272 | int cxl_mode = get_cxl_mode_from_vpd(); |
| 273 | if (cxl_mode == CXL_SPM) |
| 274 | flags |= IORESOURCE_SOFT_RESERVE; |
| 275 | else |
| 276 | flags |= IORESOURCE_STORED; |
| 277 | |
Johnny Lin | 514930c | 2023-04-11 15:30:02 +0800 | [diff] [blame] | 278 | res = fixed_mem_range_flags(dev, index++, |
| 279 | (uint64_t)pds.pds[i].base << 26, |
| 280 | (uint64_t)pds.pds[i].size << 26, flags); |
Jonathan Zhang | 907b6f5 | 2023-01-30 12:11:52 -0800 | [diff] [blame] | 281 | if (cxl_mode == CXL_SPM) |
| 282 | LOG_RESOURCE("specific_purpose_memory", dev, res); |
| 283 | else |
| 284 | LOG_RESOURCE("CXL_memory", dev, res); |
| 285 | } |
| 286 | } |
| 287 | } else { |
| 288 | /* 4GiB -> TOHM */ |
| 289 | res = upper_ram_end(dev, index++, mc_values[TOHM_REG] + 1); |
| 290 | LOG_RESOURCE("high_ram", dev, res); |
| 291 | } |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 292 | |
| 293 | /* add MMIO CFG resource */ |
Kyösti Mälkki | 6f9c357 | 2021-06-14 00:40:22 +0300 | [diff] [blame] | 294 | res = mmio_from_to(dev, index++, mc_values[MMCFG_BASE_REG], |
| 295 | mc_values[MMCFG_LIMIT_REG] + 1); |
| 296 | LOG_RESOURCE("mmiocfg_res", dev, res); |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 297 | |
| 298 | /* add Local APIC resource */ |
Kyösti Mälkki | 6f9c357 | 2021-06-14 00:40:22 +0300 | [diff] [blame] | 299 | res = mmio_range(dev, index++, LAPIC_DEFAULT_BASE, 0x00001000); |
| 300 | LOG_RESOURCE("apic_res", dev, res); |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 301 | |
| 302 | /* |
| 303 | * Add legacy region as reserved - 0xa000 - 1MB |
| 304 | * Reserve everything between A segment and 1MB: |
| 305 | * |
| 306 | * 0xa0000 - 0xbffff: legacy VGA |
| 307 | * 0xc0000 - 0xfffff: RAM |
| 308 | */ |
Kyösti Mälkki | 6f9c357 | 2021-06-14 00:40:22 +0300 | [diff] [blame] | 309 | res = mmio_range(dev, index++, VGA_BASE_ADDRESS, VGA_BASE_SIZE); |
| 310 | LOG_RESOURCE("legacy_mmio", dev, res); |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 311 | |
Kyösti Mälkki | 6f9c357 | 2021-06-14 00:40:22 +0300 | [diff] [blame] | 312 | res = reserved_ram_from_to(dev, index++, 0xc0000, 1 * MiB); |
| 313 | LOG_RESOURCE("legacy_write_protect", dev, res); |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 314 | |
| 315 | *res_count = index; |
| 316 | } |
| 317 | |
| 318 | static void mmapvtd_read_resources(struct device *dev) |
| 319 | { |
| 320 | int index = 0; |
| 321 | |
Jonathan Zhang | 907b6f5 | 2023-01-30 12:11:52 -0800 | [diff] [blame] | 322 | if (CONFIG(SOC_INTEL_HAS_CXL)) { |
| 323 | /* Construct NUMA data structure. This is needed for CXL. */ |
| 324 | if (fill_pds() != CB_SUCCESS) |
| 325 | pds.num_pds = 0; |
| 326 | |
| 327 | dump_pds(); |
| 328 | } |
| 329 | |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 330 | /* Read standard PCI resources. */ |
| 331 | pci_dev_read_resources(dev); |
| 332 | |
Jonathan Zhang | da538cb | 2022-12-19 15:49:33 -0800 | [diff] [blame] | 333 | /* set up DPR */ |
| 334 | configure_dpr(dev); |
| 335 | |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 336 | /* Calculate and add DRAM resources. */ |
| 337 | mc_add_dram_resources(dev, &index); |
| 338 | } |
| 339 | |
| 340 | static void mmapvtd_init(struct device *dev) |
| 341 | { |
| 342 | } |
| 343 | |
| 344 | static struct device_operations mmapvtd_ops = { |
| 345 | .read_resources = mmapvtd_read_resources, |
| 346 | .set_resources = pci_dev_set_resources, |
| 347 | .enable_resources = pci_dev_enable_resources, |
| 348 | .init = mmapvtd_init, |
| 349 | .ops_pci = &soc_pci_ops, |
Marc Jones | 521a03f | 2020-10-19 13:46:59 -0600 | [diff] [blame] | 350 | #if CONFIG(HAVE_ACPI_TABLES) |
| 351 | .acpi_inject_dsdt = uncore_inject_dsdt, |
| 352 | #endif |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 353 | }; |
| 354 | |
| 355 | static const unsigned short mmapvtd_ids[] = { |
| 356 | MMAP_VTD_CFG_REG_DEVID, /* Memory Map/Intel® VT-d Configuration Registers */ |
| 357 | 0 |
| 358 | }; |
| 359 | |
| 360 | static const struct pci_driver mmapvtd_driver __pci_driver = { |
| 361 | .ops = &mmapvtd_ops, |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 362 | .vendor = PCI_VID_INTEL, |
Jonathan Zhang | 8f89549 | 2020-01-16 11:16:45 -0800 | [diff] [blame] | 363 | .devices = mmapvtd_ids |
| 364 | }; |
Arthur Heymans | 77509be | 2020-10-22 17:11:22 +0200 | [diff] [blame] | 365 | |
Jonathan Zhang | a5bd580 | 2023-01-30 11:17:25 -0800 | [diff] [blame] | 366 | #if !CONFIG(SOC_INTEL_MMAPVTD_ONLY_FOR_DPR) |
Arthur Heymans | 77509be | 2020-10-22 17:11:22 +0200 | [diff] [blame] | 367 | static void vtd_read_resources(struct device *dev) |
| 368 | { |
| 369 | pci_dev_read_resources(dev); |
| 370 | |
| 371 | configure_dpr(dev); |
| 372 | } |
| 373 | |
| 374 | static struct device_operations vtd_ops = { |
| 375 | .read_resources = vtd_read_resources, |
| 376 | .set_resources = pci_dev_set_resources, |
| 377 | .enable_resources = pci_dev_enable_resources, |
| 378 | .ops_pci = &soc_pci_ops, |
| 379 | }; |
| 380 | |
| 381 | /* VTD devices on other stacks */ |
| 382 | static const struct pci_driver vtd_driver __pci_driver = { |
| 383 | .ops = &vtd_ops, |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 384 | .vendor = PCI_VID_INTEL, |
Arthur Heymans | 77509be | 2020-10-22 17:11:22 +0200 | [diff] [blame] | 385 | .device = MMAP_VTD_STACK_CFG_REG_DEVID, |
| 386 | }; |
Jonathan Zhang | a5bd580 | 2023-01-30 11:17:25 -0800 | [diff] [blame] | 387 | #endif |
Arthur Heymans | 42a6f7e | 2020-11-10 16:46:18 +0100 | [diff] [blame] | 388 | |
| 389 | static void dmi3_init(struct device *dev) |
| 390 | { |
Arthur Heymans | 9d8a455 | 2021-02-02 19:21:24 +0100 | [diff] [blame] | 391 | if (CONFIG(INTEL_TXT) && skip_intel_txt_lockdown()) |
| 392 | return; |
Arthur Heymans | 42a6f7e | 2020-11-10 16:46:18 +0100 | [diff] [blame] | 393 | /* Disable error injection */ |
| 394 | pci_or_config16(dev, ERRINJCON, 1 << 0); |
| 395 | |
| 396 | /* |
| 397 | * DMIRCBAR registers are not TXT lockable, but the BAR enable |
| 398 | * bit is. TXT requires that DMIRCBAR be disabled for security. |
| 399 | */ |
| 400 | pci_and_config32(dev, DMIRCBAR, ~(1 << 0)); |
| 401 | } |
| 402 | |
| 403 | static struct device_operations dmi3_ops = { |
| 404 | .read_resources = pci_dev_read_resources, |
| 405 | .set_resources = pci_dev_set_resources, |
| 406 | .enable_resources = pci_dev_enable_resources, |
| 407 | .init = dmi3_init, |
| 408 | .ops_pci = &soc_pci_ops, |
| 409 | }; |
| 410 | |
| 411 | static const struct pci_driver dmi3_driver __pci_driver = { |
| 412 | .ops = &dmi3_ops, |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 413 | .vendor = PCI_VID_INTEL, |
Arthur Heymans | 42a6f7e | 2020-11-10 16:46:18 +0100 | [diff] [blame] | 414 | .device = DMI3_DEVID, |
| 415 | }; |
Arthur Heymans | 7a36ca5 | 2020-11-10 15:55:31 +0100 | [diff] [blame] | 416 | |
| 417 | static void iio_dfx_global_init(struct device *dev) |
| 418 | { |
Arthur Heymans | 9d8a455 | 2021-02-02 19:21:24 +0100 | [diff] [blame] | 419 | if (CONFIG(INTEL_TXT) && skip_intel_txt_lockdown()) |
| 420 | return; |
| 421 | |
Arthur Heymans | 7a36ca5 | 2020-11-10 15:55:31 +0100 | [diff] [blame] | 422 | uint16_t reg16; |
| 423 | pci_or_config16(dev, IIO_DFX_LCK_CTL, 0x3ff); |
| 424 | reg16 = pci_read_config16(dev, IIO_DFX_TSWCTL0); |
| 425 | reg16 &= ~(1 << 4); // allow ib mmio cfg |
| 426 | reg16 &= ~(1 << 5); // ignore acs p2p ma lpbk |
| 427 | reg16 |= (1 << 3); // me disable |
| 428 | pci_write_config16(dev, IIO_DFX_TSWCTL0, reg16); |
| 429 | } |
| 430 | |
| 431 | static const unsigned short iio_dfx_global_ids[] = { |
| 432 | 0x202d, |
| 433 | 0x203d, |
| 434 | 0 |
| 435 | }; |
| 436 | |
| 437 | static struct device_operations iio_dfx_global_ops = { |
| 438 | .read_resources = pci_dev_read_resources, |
| 439 | .set_resources = pci_dev_set_resources, |
| 440 | .enable_resources = pci_dev_enable_resources, |
| 441 | .init = iio_dfx_global_init, |
| 442 | .ops_pci = &soc_pci_ops, |
| 443 | }; |
| 444 | |
| 445 | static const struct pci_driver iio_dfx_global_driver __pci_driver = { |
| 446 | .ops = &iio_dfx_global_ops, |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 447 | .vendor = PCI_VID_INTEL, |
Arthur Heymans | 7a36ca5 | 2020-11-10 15:55:31 +0100 | [diff] [blame] | 448 | .devices = iio_dfx_global_ids, |
| 449 | }; |