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