Angel Pons | 4b42983 | 2020-04-02 23:48:50 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 2 | |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 3 | #include <commonlib/helpers.h> |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 4 | #include <console/console.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 5 | #include <device/pci_ops.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 6 | #include <acpi/acpi.h> |
| 7 | #include <acpi/acpi_ivrs.h> |
Michał Żygowski | 208318c | 2020-03-20 15:54:27 +0100 | [diff] [blame] | 8 | #include <arch/ioapic.h> |
Felix Held | 61dd31c | 2023-06-05 19:38:36 +0200 | [diff] [blame] | 9 | #include <arch/vga.h> |
Elyes HAOUAS | 146d0c2 | 2020-07-22 11:47:08 +0200 | [diff] [blame] | 10 | #include <types.h> |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 11 | #include <device/device.h> |
| 12 | #include <device/pci.h> |
| 13 | #include <device/pci_ids.h> |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 14 | #include <string.h> |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 15 | #include <stdlib.h> |
Michał Kopeć | dc35d2a | 2021-11-30 17:40:52 +0100 | [diff] [blame] | 16 | #include <cpu/x86/mp.h> |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 17 | #include <Porting.h> |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 18 | #include <Topology.h> |
Elyes HAOUAS | 400ce55 | 2018-10-12 10:54:30 +0200 | [diff] [blame] | 19 | #include <cpu/amd/msr.h> |
| 20 | #include <cpu/amd/mtrr.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 21 | #include <acpi/acpigen.h> |
Angel Pons | ec5cf15 | 2020-11-10 20:42:07 +0100 | [diff] [blame] | 22 | #include <northbridge/amd/nb_common.h> |
Kyösti Mälkki | ed8d277 | 2017-07-15 17:12:44 +0300 | [diff] [blame] | 23 | #include <northbridge/amd/agesa/agesa_helper.h> |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 24 | #include <southbridge/amd/pi/hudson/pci_devs.h> |
Arthur Heymans | 44807ac | 2022-09-13 12:43:37 +0200 | [diff] [blame] | 25 | #include <amdblocks/cpu.h> |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 26 | |
Michał Żygowski | 6ca5b47 | 2019-09-10 15:10:22 +0200 | [diff] [blame] | 27 | #define PCIE_CAP_AER BIT(5) |
| 28 | #define PCIE_CAP_ACS BIT(6) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 29 | |
Felix Held | 3eaa850 | 2023-12-16 01:37:34 +0100 | [diff] [blame] | 30 | static int get_dram_base_limit(resource_t *basek, resource_t *limitk) |
Michał Żygowski | 88a0ce6 | 2021-05-05 09:52:59 +0200 | [diff] [blame] | 31 | { |
| 32 | u32 temp; |
| 33 | |
Felix Held | 7a83ab7 | 2023-12-16 23:10:50 +0100 | [diff] [blame] | 34 | temp = pci_read_config32(DEV_PTR(ht_1), 0x40); //[39:24] at [31:16] |
Michał Żygowski | 88a0ce6 | 2021-05-05 09:52:59 +0200 | [diff] [blame] | 35 | if (!(temp & 1)) |
| 36 | return 0; // this memory range is not enabled |
| 37 | /* |
| 38 | * BKDG: {DramBase[39:24], 00_0000h} <= address[39:0] so shift left by 8 bits |
| 39 | * for physical address and the convert to KiB by shifting 10 bits left |
| 40 | */ |
| 41 | *basek = ((temp & 0xffff0000)) >> (10 - 8); |
| 42 | /* |
| 43 | * BKDG address[39:0] <= {DramLimit[39:24], FF_FFFFh} converted as above but |
| 44 | * ORed with 0xffff to get real limit before shifting. |
| 45 | */ |
Felix Held | 7a83ab7 | 2023-12-16 23:10:50 +0100 | [diff] [blame] | 46 | temp = pci_read_config32(DEV_PTR(ht_1), 0x44); //[39:24] at [31:16] |
Michał Żygowski | 88a0ce6 | 2021-05-05 09:52:59 +0200 | [diff] [blame] | 47 | *limitk = ((temp & 0xffff0000) | 0xffff) >> (10 - 8); |
| 48 | *limitk += 1; // round up last byte |
| 49 | |
| 50 | return 1; |
| 51 | } |
| 52 | |
Michał Żygowski | 58d6f96 | 2021-05-05 10:52:08 +0200 | [diff] [blame] | 53 | static void add_fixed_resources(struct device *dev, int index) |
| 54 | { |
| 55 | /* Reserve everything between A segment and 1MB: |
| 56 | * |
| 57 | * 0xa0000 - 0xbffff: legacy VGA |
| 58 | * 0xc0000 - 0xfffff: option ROMs and SeaBIOS (if used) |
| 59 | */ |
Felix Held | 61dd31c | 2023-06-05 19:38:36 +0200 | [diff] [blame] | 60 | mmio_resource_kb(dev, index++, VGA_MMIO_BASE >> 10, VGA_MMIO_SIZE >> 10); |
Kyösti Mälkki | 27d6299 | 2022-05-24 20:25:58 +0300 | [diff] [blame] | 61 | reserved_ram_resource_kb(dev, index++, 0xc0000 >> 10, (0x100000 - 0xc0000) >> 10); |
Michał Żygowski | 58d6f96 | 2021-05-05 10:52:08 +0200 | [diff] [blame] | 62 | |
Michał Żygowski | 58d6f96 | 2021-05-05 10:52:08 +0200 | [diff] [blame] | 63 | /* Check if CC6 save area is enabled (bit 18 CC6SaveEn) */ |
Felix Held | 7a83ab7 | 2023-12-16 23:10:50 +0100 | [diff] [blame] | 64 | if (pci_read_config32(DEV_PTR(ht_2), 0x118) & (1 << 18)) { |
Michał Żygowski | 58d6f96 | 2021-05-05 10:52:08 +0200 | [diff] [blame] | 65 | /* Add CC6 DRAM UC resource residing at DRAM Limit of size 16MB as per BKDG */ |
| 66 | resource_t basek, limitk; |
Felix Held | 3eaa850 | 2023-12-16 01:37:34 +0100 | [diff] [blame] | 67 | if (!get_dram_base_limit(&basek, &limitk)) |
Michał Żygowski | 58d6f96 | 2021-05-05 10:52:08 +0200 | [diff] [blame] | 68 | return; |
Elyes Haouas | f9b535e | 2022-07-16 09:47:42 +0200 | [diff] [blame] | 69 | mmio_resource_kb(dev, index++, limitk, 16 * 1024); |
Michał Żygowski | 58d6f96 | 2021-05-05 10:52:08 +0200 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
Michał Żygowski | fb198c6 | 2021-05-09 13:54:09 +0200 | [diff] [blame] | 73 | static void nb_read_resources(struct device *dev) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 74 | { |
Kyösti Mälkki | 5d49038 | 2015-05-27 07:58:22 +0300 | [diff] [blame] | 75 | /* |
| 76 | * This MMCONF resource must be reserved in the PCI domain. |
| 77 | * It is not honored by the coreboot resource allocator if it is in |
| 78 | * the CPU_CLUSTER. |
| 79 | */ |
Elyes HAOUAS | 400ce55 | 2018-10-12 10:54:30 +0200 | [diff] [blame] | 80 | mmconf_resource(dev, MMIO_CONF_BASE); |
Michał Żygowski | 208318c | 2020-03-20 15:54:27 +0100 | [diff] [blame] | 81 | |
| 82 | /* NB IOAPIC2 resource */ |
Felix Held | 8f0075c | 2023-08-09 19:28:39 +0200 | [diff] [blame] | 83 | mmio_range(dev, IO_APIC2_ADDR, IO_APIC2_ADDR, 0x1000); |
Michał Żygowski | 58d6f96 | 2021-05-05 10:52:08 +0200 | [diff] [blame] | 84 | |
| 85 | add_fixed_resources(dev, 0); |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 86 | } |
| 87 | |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 88 | static void northbridge_init(struct device *dev) |
| 89 | { |
Felix Held | 0d19289 | 2024-02-06 16:55:29 +0100 | [diff] [blame^] | 90 | register_new_ioapic(IO_APIC2_ADDR); |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 91 | } |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 92 | |
Vladimir Serbinenko | 807127f | 2014-11-09 13:36:18 +0100 | [diff] [blame] | 93 | static unsigned long acpi_fill_hest(acpi_hest_t *hest) |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 94 | { |
| 95 | void *addr, *current; |
| 96 | |
| 97 | /* Skip the HEST header. */ |
| 98 | current = (void *)(hest + 1); |
| 99 | |
| 100 | addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE); |
| 101 | if (addr != NULL) |
| 102 | current += acpi_create_hest_error_source(hest, current, 0, (void *)((u32)addr + 2), *(UINT16 *)addr - 2); |
| 103 | |
| 104 | addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC); |
| 105 | if (addr != NULL) |
| 106 | current += acpi_create_hest_error_source(hest, current, 1, (void *)((u32)addr + 2), *(UINT16 *)addr - 2); |
| 107 | |
| 108 | return (unsigned long)current; |
| 109 | } |
| 110 | |
Arthur Heymans | f9ee87f | 2023-06-07 15:29:02 +0200 | [diff] [blame] | 111 | static unsigned long acpi_fill_ivrs_ioapic(acpi_ivrs_t *ivrs, unsigned long current) |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 112 | { |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 113 | /* 8-byte IVHD structures must be aligned to the 8-byte boundary. */ |
| 114 | current = ALIGN_UP(current, 8); |
| 115 | ivrs_ivhd_special_t *ivhd_ioapic = (ivrs_ivhd_special_t *)current; |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 116 | |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 117 | ivhd_ioapic->type = IVHD_DEV_8_BYTE_EXT_SPECIAL_DEV; |
| 118 | ivhd_ioapic->reserved = 0x0000; |
| 119 | ivhd_ioapic->dte_setting = IVHD_DTE_LINT_1_PASS | IVHD_DTE_LINT_0_PASS | |
| 120 | IVHD_DTE_SYS_MGT_NO_TRANS | IVHD_DTE_NMI_PASS | |
| 121 | IVHD_DTE_EXT_INT_PASS | IVHD_DTE_INIT_PASS; |
Felix Held | 0d19289 | 2024-02-06 16:55:29 +0100 | [diff] [blame^] | 122 | ivhd_ioapic->handle = get_ioapic_id(IO_APIC_ADDR); |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 123 | ivhd_ioapic->source_dev_id = PCI_DEVFN(SMBUS_DEV, SMBUS_FUNC); |
| 124 | ivhd_ioapic->variety = IVHD_SPECIAL_DEV_IOAPIC; |
| 125 | current += sizeof(ivrs_ivhd_special_t); |
| 126 | |
| 127 | ivhd_ioapic = (ivrs_ivhd_special_t *)current; |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 128 | ivhd_ioapic->type = IVHD_DEV_8_BYTE_EXT_SPECIAL_DEV; |
| 129 | ivhd_ioapic->reserved = 0x0000; |
| 130 | ivhd_ioapic->dte_setting = 0x00; |
Felix Held | 0d19289 | 2024-02-06 16:55:29 +0100 | [diff] [blame^] | 131 | ivhd_ioapic->handle = get_ioapic_id(IO_APIC2_ADDR); |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 132 | ivhd_ioapic->source_dev_id = PCI_DEVFN(0, 1); |
| 133 | ivhd_ioapic->variety = IVHD_SPECIAL_DEV_IOAPIC; |
| 134 | current += sizeof(ivrs_ivhd_special_t); |
| 135 | |
| 136 | return current; |
| 137 | } |
| 138 | |
| 139 | static unsigned long ivhd_describe_hpet(unsigned long current) |
| 140 | { |
| 141 | /* 8-byte IVHD structures must be aligned to the 8-byte boundary. */ |
| 142 | current = ALIGN_UP(current, 8); |
| 143 | ivrs_ivhd_special_t *ivhd_hpet = (ivrs_ivhd_special_t *)current; |
| 144 | |
| 145 | ivhd_hpet->type = IVHD_DEV_8_BYTE_EXT_SPECIAL_DEV; |
| 146 | ivhd_hpet->reserved = 0x0000; |
| 147 | ivhd_hpet->dte_setting = 0x00; |
| 148 | ivhd_hpet->handle = 0x00; |
| 149 | ivhd_hpet->source_dev_id = PCI_DEVFN(SMBUS_DEV, SMBUS_FUNC); |
| 150 | ivhd_hpet->variety = IVHD_SPECIAL_DEV_HPET; |
| 151 | current += sizeof(ivrs_ivhd_special_t); |
| 152 | |
| 153 | return current; |
| 154 | } |
| 155 | |
| 156 | static unsigned long ivhd_dev_range(unsigned long current, uint16_t start_devid, |
| 157 | uint16_t end_devid, uint8_t setting) |
| 158 | { |
| 159 | /* 4-byte IVHD structures must be aligned to the 4-byte boundary. */ |
| 160 | current = ALIGN_UP(current, 4); |
| 161 | ivrs_ivhd_generic_t *ivhd_range = (ivrs_ivhd_generic_t *)current; |
| 162 | |
| 163 | /* Create the start range IVHD entry */ |
| 164 | ivhd_range->type = IVHD_DEV_4_BYTE_START_RANGE; |
| 165 | ivhd_range->dev_id = start_devid; |
| 166 | ivhd_range->dte_setting = setting; |
| 167 | current += sizeof(ivrs_ivhd_generic_t); |
| 168 | |
| 169 | /* Create the end range IVHD entry */ |
| 170 | ivhd_range = (ivrs_ivhd_generic_t *)current; |
| 171 | ivhd_range->type = IVHD_DEV_4_BYTE_END_RANGE; |
| 172 | ivhd_range->dev_id = end_devid; |
| 173 | ivhd_range->dte_setting = setting; |
| 174 | current += sizeof(ivrs_ivhd_generic_t); |
| 175 | |
| 176 | return current; |
| 177 | } |
| 178 | |
| 179 | static unsigned long add_ivhd_dev_entry(struct device *parent, struct device *dev, |
| 180 | unsigned long *current, uint8_t type, uint8_t data) |
| 181 | { |
| 182 | if (type == IVHD_DEV_4_BYTE_SELECT) { |
| 183 | /* 4-byte IVHD structures must be aligned to the 4-byte boundary. */ |
| 184 | *current = ALIGN_UP(*current, 4); |
| 185 | ivrs_ivhd_generic_t *ivhd_entry = (ivrs_ivhd_generic_t *)*current; |
| 186 | |
| 187 | ivhd_entry->type = type; |
Arthur Heymans | 7fcd4d5 | 2023-08-24 15:12:19 +0200 | [diff] [blame] | 188 | ivhd_entry->dev_id = dev->path.pci.devfn | (dev->upstream->secondary << 8); |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 189 | ivhd_entry->dte_setting = data; |
| 190 | *current += sizeof(ivrs_ivhd_generic_t); |
| 191 | } else if (type == IVHD_DEV_8_BYTE_ALIAS_SELECT) { |
| 192 | /* 8-byte IVHD structures must be aligned to the 8-byte boundary. */ |
| 193 | *current = ALIGN_UP(*current, 8); |
| 194 | ivrs_ivhd_alias_t *ivhd_entry = (ivrs_ivhd_alias_t *)*current; |
| 195 | |
| 196 | ivhd_entry->type = type; |
Arthur Heymans | 7fcd4d5 | 2023-08-24 15:12:19 +0200 | [diff] [blame] | 197 | ivhd_entry->dev_id = dev->path.pci.devfn | (dev->upstream->secondary << 8); |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 198 | ivhd_entry->dte_setting = data; |
| 199 | ivhd_entry->reserved1 = 0; |
| 200 | ivhd_entry->reserved2 = 0; |
| 201 | ivhd_entry->source_dev_id = parent->path.pci.devfn | |
Arthur Heymans | 7fcd4d5 | 2023-08-24 15:12:19 +0200 | [diff] [blame] | 202 | (parent->upstream->secondary << 8); |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 203 | *current += sizeof(ivrs_ivhd_alias_t); |
| 204 | } |
| 205 | |
| 206 | return *current; |
| 207 | } |
| 208 | |
| 209 | static void ivrs_add_device_or_bridge(struct device *parent, struct device *dev, |
| 210 | unsigned long *current, uint16_t *ivhd_length) |
| 211 | { |
| 212 | unsigned int header_type, is_pcie; |
| 213 | unsigned long current_backup; |
| 214 | |
| 215 | header_type = dev->hdr_type & 0x7f; |
| 216 | is_pcie = pci_find_capability(dev, PCI_CAP_ID_PCIE); |
| 217 | |
| 218 | if (((header_type == PCI_HEADER_TYPE_NORMAL) || |
| 219 | (header_type == PCI_HEADER_TYPE_BRIDGE)) && is_pcie) { |
| 220 | /* Device or Bridge is PCIe */ |
| 221 | current_backup = *current; |
| 222 | add_ivhd_dev_entry(parent, dev, current, IVHD_DEV_4_BYTE_SELECT, 0x0); |
| 223 | *ivhd_length += (*current - current_backup); |
| 224 | } else if ((header_type == PCI_HEADER_TYPE_NORMAL) && !is_pcie) { |
| 225 | /* Device is legacy PCI or PCI-X */ |
| 226 | current_backup = *current; |
| 227 | add_ivhd_dev_entry(parent, dev, current, IVHD_DEV_8_BYTE_ALIAS_SELECT, 0x0); |
| 228 | *ivhd_length += (*current - current_backup); |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 229 | } |
| 230 | } |
| 231 | |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 232 | static void add_ivhd_device_entries(struct device *parent, struct device *dev, |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 233 | unsigned int depth, int linknum, int8_t *root_level, |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 234 | unsigned long *current, uint16_t *ivhd_length) |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 235 | { |
| 236 | struct device *sibling; |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 237 | |
| 238 | if (!root_level) { |
| 239 | root_level = malloc(sizeof(int8_t)); |
| 240 | *root_level = -1; |
| 241 | } |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 242 | |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 243 | if (dev->path.type == DEVICE_PATH_PCI) { |
| 244 | |
Arthur Heymans | 7fcd4d5 | 2023-08-24 15:12:19 +0200 | [diff] [blame] | 245 | if ((dev->upstream->secondary == 0x0) && |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 246 | (dev->path.pci.devfn == 0x0)) |
| 247 | *root_level = depth; |
| 248 | |
| 249 | if ((*root_level != -1) && (dev->enabled)) { |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 250 | if (depth != *root_level) |
| 251 | ivrs_add_device_or_bridge(parent, dev, current, ivhd_length); |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | |
Arthur Heymans | 7fcd4d5 | 2023-08-24 15:12:19 +0200 | [diff] [blame] | 255 | if (dev->downstream) { |
| 256 | for (sibling = dev->downstream->children; sibling; sibling = sibling->sibling) |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 257 | add_ivhd_device_entries(dev, sibling, depth + 1, depth, root_level, |
| 258 | current, ivhd_length); |
Arthur Heymans | 80c79a5 | 2023-08-24 15:12:19 +0200 | [diff] [blame] | 259 | } |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 260 | |
| 261 | free(root_level); |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 262 | } |
| 263 | |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 264 | #define IOMMU_MMIO32(x) (*((volatile uint32_t *)(x))) |
| 265 | #define EFR_SUPPORT BIT(27) |
| 266 | |
| 267 | static unsigned long acpi_fill_ivrs11(unsigned long current, acpi_ivrs_t *ivrs_agesa) |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 268 | { |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 269 | acpi_ivrs_ivhd11_t *ivhd_11; |
| 270 | unsigned long current_backup; |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 271 | |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 272 | /* |
| 273 | * These devices should be already found by previous function. |
| 274 | * Do not perform NULL checks. |
| 275 | */ |
| 276 | struct device *nb_dev = pcidev_on_root(0, 0); |
| 277 | struct device *iommu_dev = pcidev_on_root(0, 2); |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 278 | |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 279 | /* |
| 280 | * In order to utilize all features, firmware should expose type 11h |
| 281 | * IVHD which supersedes the type 10h. |
| 282 | */ |
| 283 | memset((void *)current, 0, sizeof(acpi_ivrs_ivhd11_t)); |
| 284 | ivhd_11 = (acpi_ivrs_ivhd11_t *)current; |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 285 | |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 286 | /* Enable EFR */ |
| 287 | ivhd_11->type = IVHD_BLOCK_TYPE_FULL__FIXED; |
| 288 | /* For type 11h bits 6 and 7 are reserved */ |
| 289 | ivhd_11->flags = ivrs_agesa->ivhd.flags & 0x3f; |
| 290 | ivhd_11->length = sizeof(struct acpi_ivrs_ivhd_11); |
| 291 | /* BDF <bus>:00.2 */ |
Arthur Heymans | 7fcd4d5 | 2023-08-24 15:12:19 +0200 | [diff] [blame] | 292 | ivhd_11->device_id = 0x02 | (nb_dev->upstream->secondary << 8); |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 293 | /* PCI Capability block 0x40 (type 0xf, "Secure device") */ |
| 294 | ivhd_11->capability_offset = 0x40; |
| 295 | ivhd_11->iommu_base_low = ivrs_agesa->ivhd.iommu_base_low; |
| 296 | ivhd_11->iommu_base_high = ivrs_agesa->ivhd.iommu_base_high; |
Arthur Heymans | 7fcd4d5 | 2023-08-24 15:12:19 +0200 | [diff] [blame] | 297 | ivhd_11->pci_segment_group = nb_dev->upstream->segment_group; |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 298 | ivhd_11->iommu_info = ivrs_agesa->ivhd.iommu_info; |
| 299 | ivhd_11->iommu_attributes.perf_counters = |
| 300 | (IOMMU_MMIO32(ivhd_11->iommu_base_low + 0x4000) >> 7) & 0xf; |
| 301 | ivhd_11->iommu_attributes.perf_counter_banks = |
| 302 | (IOMMU_MMIO32(ivhd_11->iommu_base_low + 0x4000) >> 12) & 0x3f; |
| 303 | ivhd_11->iommu_attributes.msi_num_ppr = |
| 304 | (pci_read_config32(iommu_dev, ivhd_11->capability_offset + 0x10) >> 27) & 0x1f; |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 305 | |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 306 | if (pci_read_config32(iommu_dev, ivhd_11->capability_offset) & EFR_SUPPORT) { |
| 307 | ivhd_11->efr_reg_image_low = IOMMU_MMIO32(ivhd_11->iommu_base_low + 0x30); |
| 308 | ivhd_11->efr_reg_image_high = IOMMU_MMIO32(ivhd_11->iommu_base_low + 0x34); |
| 309 | } |
| 310 | |
| 311 | current += sizeof(acpi_ivrs_ivhd11_t); |
| 312 | |
| 313 | /* Now repeat all the device entries from type 10h */ |
| 314 | current_backup = current; |
| 315 | current = ivhd_dev_range(current, PCI_DEVFN(1, 0), PCI_DEVFN(0x1f, 6), 0); |
| 316 | ivhd_11->length += (current - current_backup); |
| 317 | add_ivhd_device_entries(NULL, all_devices, 0, -1, NULL, ¤t, &ivhd_11->length); |
| 318 | |
| 319 | /* Describe HPET */ |
| 320 | current_backup = current; |
| 321 | current = ivhd_describe_hpet(current); |
| 322 | ivhd_11->length += (current - current_backup); |
| 323 | |
| 324 | /* Describe IOAPICs */ |
| 325 | current_backup = current; |
| 326 | current = acpi_fill_ivrs_ioapic(ivrs_agesa, current); |
| 327 | ivhd_11->length += (current - current_backup); |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 328 | |
| 329 | return current; |
| 330 | } |
| 331 | |
| 332 | static unsigned long acpi_fill_ivrs(acpi_ivrs_t *ivrs, unsigned long current) |
| 333 | { |
Piotr Król | 063e156 | 2018-07-22 20:52:26 +0200 | [diff] [blame] | 334 | acpi_ivrs_t *ivrs_agesa; |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 335 | unsigned long current_backup; |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 336 | |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 337 | struct device *nb_dev = pcidev_on_root(0, 0); |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 338 | if (!nb_dev) { |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 339 | printk(BIOS_WARNING, "%s: G-series northbridge device not present!\n", __func__); |
| 340 | printk(BIOS_WARNING, "%s: IVRS table not generated...\n", __func__); |
| 341 | |
| 342 | return (unsigned long)ivrs; |
| 343 | } |
| 344 | |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 345 | struct device *iommu_dev = pcidev_on_root(0, 2); |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 346 | |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 347 | if (!iommu_dev) { |
| 348 | printk(BIOS_WARNING, "%s: IOMMU device not found\n", __func__); |
| 349 | |
| 350 | return (unsigned long)ivrs; |
| 351 | } |
| 352 | |
Piotr Król | 063e156 | 2018-07-22 20:52:26 +0200 | [diff] [blame] | 353 | ivrs_agesa = agesawrapper_getlateinitptr(PICK_IVRS); |
| 354 | if (ivrs_agesa != NULL) { |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 355 | ivrs->iv_info = ivrs_agesa->iv_info; |
| 356 | ivrs->ivhd.type = IVHD_BLOCK_TYPE_LEGACY__FIXED; |
| 357 | ivrs->ivhd.flags = ivrs_agesa->ivhd.flags; |
Piotr Król | 063e156 | 2018-07-22 20:52:26 +0200 | [diff] [blame] | 358 | ivrs->ivhd.length = sizeof(struct acpi_ivrs_ivhd); |
| 359 | /* BDF <bus>:00.2 */ |
Arthur Heymans | 7fcd4d5 | 2023-08-24 15:12:19 +0200 | [diff] [blame] | 360 | ivrs->ivhd.device_id = 0x02 | (nb_dev->upstream->secondary << 8); |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 361 | /* PCI Capability block 0x40 (type 0xf, "Secure device") */ |
Piotr Król | 063e156 | 2018-07-22 20:52:26 +0200 | [diff] [blame] | 362 | ivrs->ivhd.capability_offset = 0x40; |
| 363 | ivrs->ivhd.iommu_base_low = ivrs_agesa->ivhd.iommu_base_low; |
| 364 | ivrs->ivhd.iommu_base_high = ivrs_agesa->ivhd.iommu_base_high; |
Arthur Heymans | 7fcd4d5 | 2023-08-24 15:12:19 +0200 | [diff] [blame] | 365 | ivrs->ivhd.pci_segment_group = nb_dev->upstream->segment_group; |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 366 | ivrs->ivhd.iommu_info = ivrs_agesa->ivhd.iommu_info; |
| 367 | ivrs->ivhd.iommu_feature_info = ivrs_agesa->ivhd.iommu_feature_info; |
| 368 | /* Enable EFR if supported */ |
| 369 | if (pci_read_config32(iommu_dev, ivrs->ivhd.capability_offset) & EFR_SUPPORT) |
| 370 | ivrs->iv_info |= IVINFO_EFR_SUPPORTED; |
Piotr Król | 063e156 | 2018-07-22 20:52:26 +0200 | [diff] [blame] | 371 | } else { |
| 372 | printk(BIOS_WARNING, "%s: AGESA returned NULL IVRS\n", __func__); |
| 373 | |
| 374 | return (unsigned long)ivrs; |
| 375 | } |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 376 | |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 377 | /* |
| 378 | * Add all possible PCI devices on bus 0 that can generate transactions |
| 379 | * processed by IOMMU. Start with device 00:01.0 since IOMMU does not |
| 380 | * translate transactions generated by itself. |
| 381 | */ |
| 382 | current_backup = current; |
| 383 | current = ivhd_dev_range(current, PCI_DEVFN(1, 0), PCI_DEVFN(0x1f, 6), 0); |
| 384 | ivrs->ivhd.length += (current - current_backup); |
| 385 | add_ivhd_device_entries(NULL, all_devices, 0, -1, NULL, ¤t, &ivrs->ivhd.length); |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 386 | |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 387 | /* Describe HPET */ |
| 388 | current_backup = current; |
| 389 | current = ivhd_describe_hpet(current); |
| 390 | ivrs->ivhd.length += (current - current_backup); |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 391 | |
| 392 | /* Describe IOAPICs */ |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 393 | current_backup = current; |
| 394 | current = acpi_fill_ivrs_ioapic(ivrs_agesa, current); |
| 395 | ivrs->ivhd.length += (current - current_backup); |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 396 | |
Michał Żygowski | 2f399b7 | 2020-04-02 19:51:37 +0200 | [diff] [blame] | 397 | /* If EFR is not supported, IVHD type 11h is reserved */ |
| 398 | if (!(ivrs->iv_info & IVINFO_EFR_SUPPORTED)) |
| 399 | return current; |
| 400 | |
| 401 | return acpi_fill_ivrs11(current, ivrs_agesa); |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 402 | } |
| 403 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 404 | static void northbridge_fill_ssdt_generator(const struct device *device) |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 405 | { |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 406 | char pscope[] = "\\_SB.PCI0"; |
| 407 | |
| 408 | acpigen_write_scope(pscope); |
Felix Held | e345378 | 2023-04-20 13:06:08 +0200 | [diff] [blame] | 409 | acpigen_write_name_dword("TOM1", get_top_of_mem_below_4gb()); |
| 410 | |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 411 | /* |
| 412 | * Since XP only implements parts of ACPI 2.0, we can't use a qword |
| 413 | * here. |
| 414 | * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt |
| 415 | * slide 22ff. |
| 416 | * Shift value right by 20 bit to make it fit into 32bit, |
| 417 | * giving us 1MB granularity and a limit of almost 4Exabyte of memory. |
| 418 | */ |
Felix Held | 27af3e6 | 2023-04-22 05:59:52 +0200 | [diff] [blame] | 419 | acpigen_write_name_dword("TOM2", get_top_of_mem_above_4gb() >> 20); |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 420 | acpigen_pop_len(); |
| 421 | } |
| 422 | |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 423 | static unsigned long agesa_write_acpi_tables(const struct device *device, |
Alexander Couzens | 83fc32f | 2015-04-12 22:28:37 +0200 | [diff] [blame] | 424 | unsigned long current, |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 425 | acpi_rsdp_t *rsdp) |
| 426 | { |
| 427 | acpi_srat_t *srat; |
| 428 | acpi_slit_t *slit; |
| 429 | acpi_header_t *ssdt; |
| 430 | acpi_header_t *alib; |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 431 | acpi_ivrs_t *ivrs; |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 432 | |
| 433 | /* HEST */ |
Elyes Haouas | d6b6b22 | 2022-10-10 12:34:21 +0200 | [diff] [blame] | 434 | current = ALIGN_UP(current, 8); |
Vladimir Serbinenko | 807127f | 2014-11-09 13:36:18 +0100 | [diff] [blame] | 435 | acpi_write_hest((void *)current, acpi_fill_hest); |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 436 | acpi_add_table(rsdp, (void *)current); |
| 437 | current += ((acpi_header_t *)current)->length; |
| 438 | |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 439 | /* IVRS */ |
Elyes Haouas | d6b6b22 | 2022-10-10 12:34:21 +0200 | [diff] [blame] | 440 | current = ALIGN_UP(current, 8); |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 441 | printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current); |
Elyes Haouas | f9b535e | 2022-07-16 09:47:42 +0200 | [diff] [blame] | 442 | ivrs = (acpi_ivrs_t *)current; |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 443 | acpi_create_ivrs(ivrs, acpi_fill_ivrs); |
| 444 | current += ivrs->header.length; |
| 445 | acpi_add_table(rsdp, ivrs); |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 446 | |
| 447 | /* SRAT */ |
Elyes Haouas | d6b6b22 | 2022-10-10 12:34:21 +0200 | [diff] [blame] | 448 | current = ALIGN_UP(current, 8); |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 449 | printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current); |
Elyes Haouas | f9b535e | 2022-07-16 09:47:42 +0200 | [diff] [blame] | 450 | srat = (acpi_srat_t *)agesawrapper_getlateinitptr(PICK_SRAT); |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 451 | if (srat != NULL) { |
| 452 | memcpy((void *)current, srat, srat->header.length); |
Elyes Haouas | f9b535e | 2022-07-16 09:47:42 +0200 | [diff] [blame] | 453 | srat = (acpi_srat_t *)current; |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 454 | current += srat->header.length; |
| 455 | acpi_add_table(rsdp, srat); |
| 456 | } else { |
| 457 | printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n"); |
| 458 | } |
| 459 | |
| 460 | /* SLIT */ |
Elyes Haouas | d6b6b22 | 2022-10-10 12:34:21 +0200 | [diff] [blame] | 461 | current = ALIGN_UP(current, 8); |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 462 | printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current); |
Elyes Haouas | f9b535e | 2022-07-16 09:47:42 +0200 | [diff] [blame] | 463 | slit = (acpi_slit_t *)agesawrapper_getlateinitptr(PICK_SLIT); |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 464 | if (slit != NULL) { |
| 465 | memcpy((void *)current, slit, slit->header.length); |
Elyes Haouas | f9b535e | 2022-07-16 09:47:42 +0200 | [diff] [blame] | 466 | slit = (acpi_slit_t *)current; |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 467 | current += slit->header.length; |
| 468 | acpi_add_table(rsdp, slit); |
| 469 | } else { |
| 470 | printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n"); |
| 471 | } |
| 472 | |
| 473 | /* ALIB */ |
Elyes Haouas | d6b6b22 | 2022-10-10 12:34:21 +0200 | [diff] [blame] | 474 | current = ALIGN_UP(current, 16); |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 475 | printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current); |
Elyes Haouas | f9b535e | 2022-07-16 09:47:42 +0200 | [diff] [blame] | 476 | alib = (acpi_header_t *)agesawrapper_getlateinitptr(PICK_ALIB); |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 477 | if (alib != NULL) { |
| 478 | memcpy((void *)current, alib, alib->length); |
Elyes Haouas | f9b535e | 2022-07-16 09:47:42 +0200 | [diff] [blame] | 479 | alib = (acpi_header_t *)current; |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 480 | current += alib->length; |
| 481 | acpi_add_table(rsdp, (void *)alib); |
| 482 | } |
| 483 | else { |
| 484 | printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n"); |
| 485 | } |
| 486 | |
| 487 | /* this pstate ssdt may cause Blue Screen: Fixed: Keep this comment for a while. */ |
| 488 | /* SSDT */ |
Elyes Haouas | d6b6b22 | 2022-10-10 12:34:21 +0200 | [diff] [blame] | 489 | current = ALIGN_UP(current, 16); |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 490 | printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current); |
Elyes Haouas | f9b535e | 2022-07-16 09:47:42 +0200 | [diff] [blame] | 491 | ssdt = (acpi_header_t *)agesawrapper_getlateinitptr(PICK_PSTATE); |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 492 | if (ssdt != NULL) { |
| 493 | memcpy((void *)current, ssdt, ssdt->length); |
Elyes Haouas | f9b535e | 2022-07-16 09:47:42 +0200 | [diff] [blame] | 494 | ssdt = (acpi_header_t *)current; |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 495 | current += ssdt->length; |
| 496 | } |
| 497 | else { |
| 498 | printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n"); |
| 499 | } |
Elyes Haouas | f9b535e | 2022-07-16 09:47:42 +0200 | [diff] [blame] | 500 | acpi_add_table(rsdp, ssdt); |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 501 | |
| 502 | printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current); |
| 503 | return current; |
| 504 | } |
| 505 | |
Felix Held | 7b9c647 | 2023-11-16 16:06:49 +0100 | [diff] [blame] | 506 | struct device_operations amd_pi_northbridge_ops = { |
Michał Żygowski | fb198c6 | 2021-05-09 13:54:09 +0200 | [diff] [blame] | 507 | .read_resources = nb_read_resources, |
Felix Held | b986e21 | 2023-12-16 00:58:09 +0100 | [diff] [blame] | 508 | .set_resources = pci_dev_set_resources, |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 509 | .enable_resources = pci_dev_enable_resources, |
| 510 | .init = northbridge_init, |
Michał Żygowski | fb198c6 | 2021-05-09 13:54:09 +0200 | [diff] [blame] | 511 | .ops_pci = &pci_dev_ops_pci, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 512 | .acpi_fill_ssdt = northbridge_fill_ssdt_generator, |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 513 | .write_acpi_tables = agesa_write_acpi_tables, |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 514 | }; |
| 515 | |
Dave Frodin | 891f71a | 2015-01-19 15:58:24 -0700 | [diff] [blame] | 516 | static void fam16_finalize(void *chip_info) |
| 517 | { |
Kyösti Mälkki | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 518 | struct device *dev; |
Kyösti Mälkki | 33ff44c | 2018-05-22 01:15:22 +0300 | [diff] [blame] | 519 | dev = pcidev_on_root(0, 0); /* clear IoapicSbFeatureEn */ |
Elyes Haouas | a1f5ad0 | 2022-02-17 18:14:08 +0100 | [diff] [blame] | 520 | |
Dave Frodin | 891f71a | 2015-01-19 15:58:24 -0700 | [diff] [blame] | 521 | pci_write_config32(dev, 0xF8, 0); |
| 522 | pci_write_config32(dev, 0xFC, 5); /* TODO: move it to dsdt.asl */ |
| 523 | |
Michał Żygowski | 6ca5b47 | 2019-09-10 15:10:22 +0200 | [diff] [blame] | 524 | /* |
| 525 | * Currently it is impossible to enable ACS with AGESA by setting the |
| 526 | * correct bit for AmdInitMid phase. AGESA code path does not call the |
| 527 | * right function that enables these functionalities. Disabled ACS |
| 528 | * result in multiple PCIe devices to be assigned to the same IOMMU |
| 529 | * group. Without IOMMU group separation the devices cannot be passed |
| 530 | * through independently. |
| 531 | */ |
| 532 | |
| 533 | /* Select GPP link core IO Link Strap Control register 0xB0 */ |
| 534 | pci_write_config32(dev, 0xE0, 0x014000B0); |
Michał Żygowski | 6ca5b47 | 2019-09-10 15:10:22 +0200 | [diff] [blame] | 535 | |
| 536 | /* Enable AER (bit 5) and ACS (bit 6 undocumented) */ |
Elyes Haouas | a1f5ad0 | 2022-02-17 18:14:08 +0100 | [diff] [blame] | 537 | pci_or_config32(dev, 0xE4, PCIE_CAP_AER | PCIE_CAP_ACS); |
Michał Żygowski | 6ca5b47 | 2019-09-10 15:10:22 +0200 | [diff] [blame] | 538 | |
| 539 | /* Select GPP link core Wrapper register 0x00 (undocumented) */ |
| 540 | pci_write_config32(dev, 0xE0, 0x01300000); |
Michał Żygowski | 6ca5b47 | 2019-09-10 15:10:22 +0200 | [diff] [blame] | 541 | |
| 542 | /* |
| 543 | * Enable ACS capabilities straps including sub-items. From lspci it |
| 544 | * looks like these bits enable: Source Validation and Translation |
| 545 | * Blocking |
| 546 | */ |
Elyes Haouas | a1f5ad0 | 2022-02-17 18:14:08 +0100 | [diff] [blame] | 547 | pci_or_config32(dev, 0xE4, (BIT(24) | BIT(25) | BIT(26))); |
Michał Żygowski | 6ca5b47 | 2019-09-10 15:10:22 +0200 | [diff] [blame] | 548 | |
Dave Frodin | 891f71a | 2015-01-19 15:58:24 -0700 | [diff] [blame] | 549 | /* disable No Snoop */ |
Kyösti Mälkki | 33ff44c | 2018-05-22 01:15:22 +0300 | [diff] [blame] | 550 | dev = pcidev_on_root(1, 1); |
Kyösti Mälkki | 69f6fd4 | 2019-01-21 14:19:01 +0200 | [diff] [blame] | 551 | if (dev != NULL) { |
Elyes Haouas | a1f5ad0 | 2022-02-17 18:14:08 +0100 | [diff] [blame] | 552 | pci_and_config32(dev, 0x60, ~(1 << 11)); |
Kyösti Mälkki | 69f6fd4 | 2019-01-21 14:19:01 +0200 | [diff] [blame] | 553 | } |
Dave Frodin | 891f71a | 2015-01-19 15:58:24 -0700 | [diff] [blame] | 554 | } |
| 555 | |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 556 | struct hw_mem_hole_info { |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 557 | unsigned int hole_startk; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 558 | int node_id; |
| 559 | }; |
| 560 | static struct hw_mem_hole_info get_hw_mem_hole_info(void) |
| 561 | { |
| 562 | struct hw_mem_hole_info mem_hole; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 563 | mem_hole.node_id = -1; |
Felix Held | a880720 | 2023-11-16 21:29:33 +0100 | [diff] [blame] | 564 | |
| 565 | resource_t basek, limitk; |
Felix Held | 3eaa850 | 2023-12-16 01:37:34 +0100 | [diff] [blame] | 566 | if (get_dram_base_limit(&basek, &limitk)) { // memory on this node |
Felix Held | 7a83ab7 | 2023-12-16 23:10:50 +0100 | [diff] [blame] | 567 | u32 hole = pci_read_config32(DEV_PTR(ht_1), 0xf0); |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 568 | if (hole & 2) { // we find the hole |
Elyes Haouas | f9b535e | 2022-07-16 09:47:42 +0200 | [diff] [blame] | 569 | mem_hole.hole_startk = (hole & (0xff << 24)) >> 10; |
Felix Held | a880720 | 2023-11-16 21:29:33 +0100 | [diff] [blame] | 570 | mem_hole.node_id = 0; // record the node No with hole |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 571 | } |
| 572 | } |
| 573 | return mem_hole; |
| 574 | } |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 575 | |
Michał Żygowski | f5d457d | 2021-05-09 13:58:04 +0200 | [diff] [blame] | 576 | static void domain_read_resources(struct device *dev) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 577 | { |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 578 | unsigned long mmio_basek; |
Felix Held | dcbb1e8 | 2023-12-17 18:20:01 +0100 | [diff] [blame] | 579 | unsigned long idx = 0; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 580 | struct hw_mem_hole_info mem_hole; |
Felix Held | 3f234f8 | 2023-12-17 18:38:08 +0100 | [diff] [blame] | 581 | resource_t basek = 0; |
| 582 | resource_t limitk = 0; |
| 583 | resource_t sizek; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 584 | |
Michał Żygowski | f5d457d | 2021-05-09 13:58:04 +0200 | [diff] [blame] | 585 | pci_domain_read_resources(dev); |
| 586 | |
Michał Żygowski | 58d6f96 | 2021-05-05 10:52:08 +0200 | [diff] [blame] | 587 | /* TOP_MEM MSR is our boundary between DRAM and MMIO under 4G */ |
Felix Held | 5e9afe7 | 2023-04-20 12:55:55 +0200 | [diff] [blame] | 588 | mmio_basek = get_top_of_mem_below_4gb() >> 10; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 589 | |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 590 | /* if the hw mem hole is already set in raminit stage, here we will compare |
| 591 | * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will |
| 592 | * use hole_basek as mmio_basek and we don't need to reset hole. |
| 593 | * otherwise We reset the hole to the mmio_basek |
| 594 | */ |
| 595 | |
| 596 | mem_hole = get_hw_mem_hole_info(); |
| 597 | |
| 598 | // Use hole_basek as mmio_basek, and we don't need to reset hole anymore |
| 599 | if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) { |
| 600 | mmio_basek = mem_hole.hole_startk; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 601 | } |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 602 | |
Felix Held | 3f234f8 | 2023-12-17 18:38:08 +0100 | [diff] [blame] | 603 | get_dram_base_limit(&basek, &limitk); |
| 604 | sizek = limitk - basek; |
| 605 | |
| 606 | printk(BIOS_DEBUG, "basek=%08llx, limitk=%08llx, sizek=%08llx,\n", |
| 607 | basek, limitk, sizek); |
| 608 | |
| 609 | /* See if we need a hole from 0xa0000 (640K) to 0xfffff (1024K) */ |
| 610 | if (basek < 640 && sizek > 1024) { |
| 611 | ram_resource_kb(dev, idx++, basek, 640 - basek); |
| 612 | basek = 1024; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 613 | sizek = limitk - basek; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 614 | } |
| 615 | |
Felix Held | 3f234f8 | 2023-12-17 18:38:08 +0100 | [diff] [blame] | 616 | printk(BIOS_DEBUG, "basek=%08llx, limitk=%08llx, sizek=%08llx,\n", |
| 617 | basek, limitk, sizek); |
| 618 | |
| 619 | /* split the region to accommodate pci memory space */ |
| 620 | if ((basek < 4 * 1024 * 1024) && (limitk > mmio_basek)) { |
| 621 | if (basek <= mmio_basek) { |
| 622 | unsigned int pre_sizek; |
| 623 | pre_sizek = mmio_basek - basek; |
| 624 | if (pre_sizek > 0) { |
| 625 | ram_resource_kb(dev, idx++, basek, pre_sizek); |
| 626 | sizek -= pre_sizek; |
| 627 | } |
| 628 | basek = mmio_basek; |
| 629 | } |
| 630 | if ((basek + sizek) <= 4 * 1024 * 1024) { |
| 631 | sizek = 0; |
| 632 | } else { |
| 633 | uint64_t topmem2 = get_top_of_mem_above_4gb(); |
| 634 | basek = 4 * 1024 * 1024; |
| 635 | sizek = topmem2 / 1024 - basek; |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | ram_resource_kb(dev, idx++, basek, sizek); |
| 640 | printk(BIOS_DEBUG, "mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", |
| 641 | mmio_basek, basek, limitk); |
| 642 | |
Felix Held | dcbb1e8 | 2023-12-17 18:20:01 +0100 | [diff] [blame] | 643 | add_uma_resource_below_tolm(dev, idx++); |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 644 | } |
| 645 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 646 | static const char *domain_acpi_name(const struct device *dev) |
Philipp Deppenwiese | 3067012 | 2017-03-01 02:24:33 +0100 | [diff] [blame] | 647 | { |
| 648 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
| 649 | return "PCI0"; |
| 650 | |
| 651 | return NULL; |
| 652 | } |
| 653 | |
Felix Held | 8ccd314 | 2023-11-16 00:58:30 +0100 | [diff] [blame] | 654 | struct device_operations amd_fam16_mod30_pci_domain_ops = { |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 655 | .read_resources = domain_read_resources, |
Michał Żygowski | f5d457d | 2021-05-09 13:58:04 +0200 | [diff] [blame] | 656 | .set_resources = pci_domain_set_resources, |
Arthur Heymans | 0b0113f | 2023-08-31 17:09:28 +0200 | [diff] [blame] | 657 | .scan_bus = pci_host_bridge_scan_bus, |
Philipp Deppenwiese | 3067012 | 2017-03-01 02:24:33 +0100 | [diff] [blame] | 658 | .acpi_name = domain_acpi_name, |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 659 | }; |
| 660 | |
Michał Kopeć | dc35d2a | 2021-11-30 17:40:52 +0100 | [diff] [blame] | 661 | void mp_init_cpus(struct bus *cpu_bus) |
| 662 | { |
Arthur Heymans | 4fcaccf | 2022-06-02 13:17:37 +0200 | [diff] [blame] | 663 | extern const struct mp_ops amd_mp_ops_no_smm; |
Michał Kopeć | dc35d2a | 2021-11-30 17:40:52 +0100 | [diff] [blame] | 664 | /* TODO: Handle mp_init_with_smm failure? */ |
Arthur Heymans | 4fcaccf | 2022-06-02 13:17:37 +0200 | [diff] [blame] | 665 | mp_init_with_smm(cpu_bus, &amd_mp_ops_no_smm); |
Michał Kopeć | dc35d2a | 2021-11-30 17:40:52 +0100 | [diff] [blame] | 666 | |
| 667 | /* The flash is now no longer cacheable. Reset to WP for performance. */ |
| 668 | mtrr_use_temp_range(OPTIMAL_CACHE_ROM_BASE, OPTIMAL_CACHE_ROM_SIZE, |
| 669 | MTRR_TYPE_WRPROT); |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 670 | } |
| 671 | |
Felix Held | c391bff | 2023-02-16 19:38:49 +0100 | [diff] [blame] | 672 | void generate_cpu_entries(const struct device *device) |
| 673 | { |
| 674 | int cpu; |
| 675 | const int cores = get_cpu_count(); |
| 676 | |
| 677 | printk(BIOS_DEBUG, "ACPI \\_SB report %d core(s)\n", cores); |
| 678 | |
| 679 | /* Generate \_SB.Pxxx */ |
| 680 | for (cpu = 0; cpu < cores; cpu++) { |
| 681 | acpigen_write_processor_device(cpu); |
| 682 | acpigen_write_processor_device_end(); |
| 683 | } |
| 684 | } |
| 685 | |
Felix Held | 8ccd314 | 2023-11-16 00:58:30 +0100 | [diff] [blame] | 686 | struct device_operations amd_fam16_mod30_cpu_bus_ops = { |
Felix Held | c391bff | 2023-02-16 19:38:49 +0100 | [diff] [blame] | 687 | .read_resources = noop_read_resources, |
| 688 | .set_resources = noop_set_resources, |
| 689 | .init = mp_cpu_bus_init, |
| 690 | .acpi_fill_ssdt = generate_cpu_entries, |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 691 | }; |
| 692 | |
Felix Held | 1952d13 | 2023-11-16 00:54:30 +0100 | [diff] [blame] | 693 | struct chip_operations northbridge_amd_pi_00730F01_ops = { |
Nicholas Sudsgaard | bfb11be | 2024-01-30 09:53:46 +0900 | [diff] [blame] | 694 | .name = "AMD FAM16 Root Complex", |
Felix Held | 1952d13 | 2023-11-16 00:54:30 +0100 | [diff] [blame] | 695 | .final = fam16_finalize, |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 696 | }; |
| 697 | |
| 698 | /********************************************************************* |
| 699 | * Change the vendor / device IDs to match the generic VBIOS header. * |
| 700 | *********************************************************************/ |
| 701 | u32 map_oprom_vendev(u32 vendev) |
| 702 | { |
| 703 | u32 new_vendev; |
| 704 | new_vendev = |
| 705 | ((0x10029850 <= vendev) && (vendev <= 0x1002986F)) ? 0x10029850 : vendev; |
| 706 | |
| 707 | if (vendev != new_vendev) |
| 708 | printk(BIOS_NOTICE, "Mapping PCI device %8x to %8x\n", vendev, new_vendev); |
| 709 | |
| 710 | return new_vendev; |
| 711 | } |