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