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