Angel Pons | 4b42983 | 2020-04-02 23:48:50 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 2 | |
| 3 | #include <console/console.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 4 | #include <device/pci_ops.h> |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 5 | #include <acpi/acpi.h> |
| 6 | #include <acpi/acpigen.h> |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 7 | #include <stdint.h> |
| 8 | #include <device/device.h> |
| 9 | #include <device/pci.h> |
| 10 | #include <device/pci_ids.h> |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 11 | #include <string.h> |
Ronald G. Minnich | 5079a0d | 2012-11-27 11:32:38 -0800 | [diff] [blame] | 12 | #include <lib.h> |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 13 | #include <cpu/cpu.h> |
Martin Roth | 73e86a8 | 2013-01-17 16:28:30 -0700 | [diff] [blame] | 14 | #include <AGESA.h> |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 15 | #include <cpu/x86/lapic.h> |
Elyes HAOUAS | 400ce55 | 2018-10-12 10:54:30 +0200 | [diff] [blame] | 16 | #include <cpu/amd/msr.h> |
Kyösti Mälkki | dbc4739 | 2012-08-05 12:11:40 +0300 | [diff] [blame] | 17 | #include <cpu/amd/mtrr.h> |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 18 | #include <Porting.h> |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 19 | #include <Options.h> |
| 20 | #include <Topology.h> |
Angel Pons | ec5cf15 | 2020-11-10 20:42:07 +0100 | [diff] [blame] | 21 | #include <northbridge/amd/nb_common.h> |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 22 | #include <northbridge/amd/agesa/state_machine.h> |
Kyösti Mälkki | d610c58 | 2017-03-05 06:28:18 +0200 | [diff] [blame] | 23 | #include <northbridge/amd/agesa/agesa_helper.h> |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 24 | |
Kyösti Mälkki | 113f670 | 2018-05-20 20:12:32 +0300 | [diff] [blame] | 25 | #define MAX_NODE_NUMS MAX_NODES |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 26 | |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 27 | static unsigned int node_nums; |
| 28 | static unsigned int sblink; |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 29 | static struct device *__f0_dev[MAX_NODE_NUMS]; |
| 30 | static struct device *__f1_dev[MAX_NODE_NUMS]; |
| 31 | static struct device *__f2_dev[MAX_NODE_NUMS]; |
| 32 | static struct device *__f4_dev[MAX_NODE_NUMS]; |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 33 | static unsigned int fx_devs = 0; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 34 | |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 35 | static struct device *get_node_pci(u32 nodeid, u32 fn) |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 36 | { |
Kyösti Mälkki | 3d3152e | 2019-01-10 09:05:30 +0200 | [diff] [blame] | 37 | return pcidev_on_root(DEV_CDB + nodeid, fn); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | static void get_fx_devs(void) |
| 41 | { |
| 42 | int i; |
| 43 | for (i = 0; i < MAX_NODE_NUMS; i++) { |
| 44 | __f0_dev[i] = get_node_pci(i, 0); |
| 45 | __f1_dev[i] = get_node_pci(i, 1); |
| 46 | __f2_dev[i] = get_node_pci(i, 2); |
| 47 | __f4_dev[i] = get_node_pci(i, 4); |
| 48 | if (__f0_dev[i] != NULL && __f1_dev[i] != NULL) |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 49 | fx_devs = i + 1; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 50 | } |
| 51 | if (__f1_dev[0] == NULL || __f0_dev[0] == NULL || fx_devs == 0) { |
| 52 | die("Cannot find 0:0x18.[0|1]\n"); |
| 53 | } |
| 54 | printk(BIOS_DEBUG, "fx_devs=0x%x\n", fx_devs); |
| 55 | } |
| 56 | |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 57 | static u32 f1_read_config32(unsigned int reg) |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 58 | { |
| 59 | if (fx_devs == 0) |
| 60 | get_fx_devs(); |
| 61 | return pci_read_config32(__f1_dev[0], reg); |
| 62 | } |
| 63 | |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 64 | static void f1_write_config32(unsigned int reg, u32 value) |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 65 | { |
| 66 | int i; |
| 67 | if (fx_devs == 0) |
| 68 | get_fx_devs(); |
Elyes HAOUAS | 5a7e72f | 2016-08-23 21:36:02 +0200 | [diff] [blame] | 69 | for (i = 0; i < fx_devs; i++) { |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 70 | struct device *dev; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 71 | dev = __f1_dev[i]; |
| 72 | if (dev && dev->enabled) { |
| 73 | pci_write_config32(dev, reg, value); |
| 74 | } |
| 75 | } |
| 76 | } |
| 77 | |
Michał Żygowski | 88a0ce6 | 2021-05-05 09:52:59 +0200 | [diff] [blame] | 78 | static int get_dram_base_limit(u32 nodeid, resource_t *basek, resource_t *limitk) |
| 79 | { |
| 80 | u32 temp; |
| 81 | |
| 82 | if (fx_devs == 0) |
| 83 | get_fx_devs(); |
| 84 | |
| 85 | |
| 86 | temp = pci_read_config32(__f1_dev[nodeid], 0x40 + (nodeid << 3)); //[39:24] at [31:16] |
| 87 | if (!(temp & 1)) |
| 88 | return 0; // this memory range is not enabled |
| 89 | /* |
| 90 | * BKDG: {DramBase[47:24], 00_0000h} <= address[47:0] so shift left by 8 bits |
| 91 | * for physical address and the convert to KiB by shifting 10 bits left |
| 92 | */ |
| 93 | *basek = ((temp & 0xffff0000)) >> (10 - 8); |
| 94 | /* Now high bits [47:40] */ |
| 95 | temp = pci_read_config32(__f1_dev[nodeid], 0x140 + (nodeid << 3)); //[47:40] at [7:0] |
| 96 | *basek = *basek | ((resource_t)temp << (40 - 10)); |
| 97 | /* |
| 98 | * BKDG address[39:0] <= {DramLimit[47:24], FF_FFFFh} converted as above but |
| 99 | * ORed with 0xffff to get real limit before shifting. |
| 100 | */ |
| 101 | temp = pci_read_config32(__f1_dev[nodeid], 0x44 + (nodeid << 3)); //[39:24] at [31:16] |
| 102 | *limitk = ((temp & 0xffff0000) | 0xffff) >> (10 - 8); |
| 103 | /* Now high bits [47:40] */ |
| 104 | temp = pci_read_config32(__f1_dev[nodeid], 0x144 + (nodeid << 3)); //[47:40] at [7:0] |
| 105 | *limitk = *limitk | ((resource_t)temp << (40 - 10)); |
| 106 | *limitk += 1; // round up last byte |
| 107 | |
| 108 | return 1; |
| 109 | } |
| 110 | |
Kyösti Mälkki | 2900d4b | 2017-07-25 14:55:29 +0300 | [diff] [blame] | 111 | static u32 amdfam15_nodeid(struct device *dev) |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 112 | { |
Kyösti Mälkki | 3d3152e | 2019-01-10 09:05:30 +0200 | [diff] [blame] | 113 | return (dev->path.pci.devfn >> 3) - DEV_CDB; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | static void set_vga_enable_reg(u32 nodeid, u32 linkn) |
| 117 | { |
| 118 | u32 val; |
| 119 | |
Elyes HAOUAS | 27e1801 | 2017-06-27 23:14:51 +0200 | [diff] [blame] | 120 | val = 1 | (nodeid << 4) | (linkn << 12); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 121 | /* it will routing |
| 122 | * (1)mmio 0xa0000:0xbffff |
| 123 | * (2)io 0x3b0:0x3bb, 0x3c0:0x3df |
| 124 | */ |
| 125 | f1_write_config32(0xf4, val); |
| 126 | |
| 127 | } |
| 128 | |
Kyösti Mälkki | 2900d4b | 2017-07-25 14:55:29 +0300 | [diff] [blame] | 129 | static void nb_read_resources(struct device *dev) |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 130 | { |
Steven Sherk | 1cbabb0 | 2013-02-01 09:22:35 -0700 | [diff] [blame] | 131 | /* |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 132 | * This MMCONF resource must be reserved in the PCI domain. |
Steven Sherk | 1cbabb0 | 2013-02-01 09:22:35 -0700 | [diff] [blame] | 133 | * It is not honored by the coreboot resource allocator if it is in |
Stefan Reinauer | 0aa37c4 | 2013-02-12 15:20:54 -0800 | [diff] [blame] | 134 | * the CPU_CLUSTER. |
Steven Sherk | 1cbabb0 | 2013-02-01 09:22:35 -0700 | [diff] [blame] | 135 | */ |
Elyes HAOUAS | 400ce55 | 2018-10-12 10:54:30 +0200 | [diff] [blame] | 136 | mmconf_resource(dev, MMIO_CONF_BASE); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 137 | |
Arthur Heymans | 6fa6e11 | 2022-10-13 18:26:04 +0200 | [diff] [blame^] | 138 | /* There should be no BAR on this device. */ |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /** |
| 142 | * I tried to reuse the resource allocation code in set_resource() |
| 143 | * but it is too difficult to deal with the resource allocation magic. |
| 144 | */ |
| 145 | |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 146 | static void create_vga_resource(struct device *dev, unsigned int nodeid) |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 147 | { |
| 148 | struct bus *link; |
| 149 | |
| 150 | /* find out which link the VGA card is connected, |
| 151 | * we only deal with the 'first' vga card */ |
| 152 | for (link = dev->link_list; link; link = link->next) { |
| 153 | if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) { |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 154 | #if CONFIG(MULTIPLE_VGA_ADAPTERS) |
Kyösti Mälkki | 2900d4b | 2017-07-25 14:55:29 +0300 | [diff] [blame] | 155 | extern struct device *vga_pri; // the primary vga device, defined in device.c |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 156 | printk(BIOS_DEBUG, "VGA: vga_pri bus num = %d bus range [%d,%d]\n", vga_pri->bus->secondary, |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 157 | link->secondary, link->subordinate); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 158 | /* We need to make sure the vga_pri is under the link */ |
Elyes HAOUAS | 1d8daa6 | 2016-09-18 08:50:54 +0200 | [diff] [blame] | 159 | if ((vga_pri->bus->secondary >= link->secondary) && |
Kyösti Mälkki | 2900d4b | 2017-07-25 14:55:29 +0300 | [diff] [blame] | 160 | (vga_pri->bus->secondary <= link->subordinate)) |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 161 | #endif |
| 162 | break; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | /* no VGA card installed */ |
| 167 | if (link == NULL) |
| 168 | return; |
| 169 | |
| 170 | printk(BIOS_DEBUG, "VGA: %s (aka node %d) link %d has VGA device\n", dev_path(dev), nodeid, sblink); |
| 171 | set_vga_enable_reg(nodeid, sblink); |
| 172 | } |
| 173 | |
Kyösti Mälkki | 2900d4b | 2017-07-25 14:55:29 +0300 | [diff] [blame] | 174 | static void nb_set_resources(struct device *dev) |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 175 | { |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 176 | unsigned int nodeid; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 177 | |
| 178 | /* Find the nodeid */ |
| 179 | nodeid = amdfam15_nodeid(dev); |
| 180 | |
| 181 | create_vga_resource(dev, nodeid); //TODO: do we need this? |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 182 | } |
| 183 | |
Vladimir Serbinenko | 807127f | 2014-11-09 13:36:18 +0100 | [diff] [blame] | 184 | static unsigned long acpi_fill_hest(acpi_hest_t *hest) |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 185 | { |
| 186 | void *addr, *current; |
| 187 | |
| 188 | /* Skip the HEST header. */ |
| 189 | current = (void *)(hest + 1); |
| 190 | |
| 191 | addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE); |
| 192 | if (addr != NULL) |
Stefan Reinauer | 77a1d1a | 2015-07-21 12:48:17 -0700 | [diff] [blame] | 193 | current += acpi_create_hest_error_source(hest, current, 0, |
| 194 | addr + 2, *(UINT16 *)addr - 2); |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 195 | |
| 196 | addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC); |
| 197 | if (addr != NULL) |
Stefan Reinauer | 77a1d1a | 2015-07-21 12:48:17 -0700 | [diff] [blame] | 198 | current += acpi_create_hest_error_source(hest, current, 1, |
| 199 | addr + 2, *(UINT16 *)addr - 2); |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 200 | |
| 201 | return (unsigned long)current; |
| 202 | } |
| 203 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 204 | static void northbridge_fill_ssdt_generator(const struct device *device) |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 205 | { |
| 206 | msr_t msr; |
| 207 | char pscope[] = "\\_SB.PCI0"; |
| 208 | |
| 209 | acpigen_write_scope(pscope); |
| 210 | msr = rdmsr(TOP_MEM); |
| 211 | acpigen_write_name_dword("TOM1", msr.lo); |
| 212 | msr = rdmsr(TOP_MEM2); |
| 213 | /* |
| 214 | * Since XP only implements parts of ACPI 2.0, we can't use a qword |
| 215 | * here. |
| 216 | * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt |
| 217 | * slide 22ff. |
| 218 | * Shift value right by 20 bit to make it fit into 32bit, |
| 219 | * giving us 1MB granularity and a limit of almost 4Exabyte of memory. |
| 220 | */ |
| 221 | acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20); |
| 222 | acpigen_pop_len(); |
| 223 | } |
| 224 | |
Michał Żygowski | 9550e97 | 2020-03-20 13:56:46 +0100 | [diff] [blame] | 225 | static void patch_ssdt_processor_scope(acpi_header_t *ssdt) |
| 226 | { |
| 227 | unsigned int len = ssdt->length - sizeof(acpi_header_t); |
| 228 | unsigned int i; |
| 229 | |
| 230 | for (i = sizeof(acpi_header_t); i < len; i++) { |
| 231 | /* Search for _PR_ scope and replace it with _SB_ */ |
| 232 | if (*(uint32_t *)((unsigned long)ssdt + i) == 0x5f52505f) |
| 233 | *(uint32_t *)((unsigned long)ssdt + i) = 0x5f42535f; |
| 234 | } |
| 235 | /* Recalculate checksum */ |
| 236 | ssdt->checksum = 0; |
| 237 | ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length); |
| 238 | } |
| 239 | |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 240 | static unsigned long agesa_write_acpi_tables(const struct device *device, |
Alexander Couzens | 83fc32f | 2015-04-12 22:28:37 +0200 | [diff] [blame] | 241 | unsigned long current, |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 242 | acpi_rsdp_t *rsdp) |
| 243 | { |
| 244 | acpi_srat_t *srat; |
| 245 | acpi_slit_t *slit; |
| 246 | acpi_header_t *ssdt; |
| 247 | acpi_header_t *alib; |
| 248 | acpi_header_t *ivrs; |
| 249 | acpi_hest_t *hest; |
| 250 | |
| 251 | /* HEST */ |
Elyes Haouas | d6b6b22 | 2022-10-10 12:34:21 +0200 | [diff] [blame] | 252 | current = ALIGN_UP(current, 8); |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 253 | hest = (acpi_hest_t *)current; |
Arthur Heymans | cc66ff3 | 2022-03-23 21:33:15 +0100 | [diff] [blame] | 254 | acpi_write_hest(hest, acpi_fill_hest); |
| 255 | acpi_add_table(rsdp, hest); |
| 256 | current += hest->header.length; |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 257 | |
Elyes Haouas | d6b6b22 | 2022-10-10 12:34:21 +0200 | [diff] [blame] | 258 | current = ALIGN_UP(current, 8); |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 259 | printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current); |
| 260 | ivrs = agesawrapper_getlateinitptr(PICK_IVRS); |
| 261 | if (ivrs != NULL) { |
| 262 | memcpy((void *)current, ivrs, ivrs->length); |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 263 | ivrs = (acpi_header_t *)current; |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 264 | current += ivrs->length; |
| 265 | acpi_add_table(rsdp, ivrs); |
| 266 | } else { |
| 267 | printk(BIOS_DEBUG, " AGESA IVRS table NULL. Skipping.\n"); |
| 268 | } |
| 269 | |
| 270 | /* SRAT */ |
Elyes Haouas | d6b6b22 | 2022-10-10 12:34:21 +0200 | [diff] [blame] | 271 | current = ALIGN_UP(current, 8); |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 272 | printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current); |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 273 | srat = (acpi_srat_t *)agesawrapper_getlateinitptr(PICK_SRAT); |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 274 | if (srat != NULL) { |
| 275 | memcpy((void *)current, srat, srat->header.length); |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 276 | srat = (acpi_srat_t *)current; |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 277 | current += srat->header.length; |
| 278 | acpi_add_table(rsdp, srat); |
| 279 | } else { |
| 280 | printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n"); |
| 281 | } |
| 282 | |
| 283 | /* SLIT */ |
Elyes Haouas | d6b6b22 | 2022-10-10 12:34:21 +0200 | [diff] [blame] | 284 | current = ALIGN_UP(current, 8); |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 285 | printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current); |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 286 | slit = (acpi_slit_t *)agesawrapper_getlateinitptr(PICK_SLIT); |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 287 | if (slit != NULL) { |
| 288 | memcpy((void *)current, slit, slit->header.length); |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 289 | slit = (acpi_slit_t *)current; |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 290 | current += slit->header.length; |
| 291 | acpi_add_table(rsdp, slit); |
| 292 | } else { |
| 293 | printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n"); |
| 294 | } |
| 295 | |
| 296 | /* ALIB */ |
Elyes Haouas | d6b6b22 | 2022-10-10 12:34:21 +0200 | [diff] [blame] | 297 | current = ALIGN_UP(current, 16); |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 298 | printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current); |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 299 | alib = (acpi_header_t *)agesawrapper_getlateinitptr(PICK_ALIB); |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 300 | if (alib != NULL) { |
| 301 | memcpy((void *)current, alib, alib->length); |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 302 | alib = (acpi_header_t *)current; |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 303 | current += alib->length; |
| 304 | acpi_add_table(rsdp, (void *)alib); |
| 305 | } |
| 306 | else { |
| 307 | printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n"); |
| 308 | } |
| 309 | |
| 310 | /* this pstate ssdt may cause Blue Screen: Fixed: Keep this comment for a while. */ |
| 311 | /* SSDT */ |
Elyes Haouas | d6b6b22 | 2022-10-10 12:34:21 +0200 | [diff] [blame] | 312 | current = ALIGN_UP(current, 16); |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 313 | printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current); |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 314 | ssdt = (acpi_header_t *)agesawrapper_getlateinitptr(PICK_PSTATE); |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 315 | if (ssdt != NULL) { |
Michał Żygowski | 9550e97 | 2020-03-20 13:56:46 +0100 | [diff] [blame] | 316 | patch_ssdt_processor_scope(ssdt); |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 317 | memcpy((void *)current, ssdt, ssdt->length); |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 318 | ssdt = (acpi_header_t *)current; |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 319 | current += ssdt->length; |
| 320 | } |
| 321 | else { |
| 322 | printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n"); |
| 323 | } |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 324 | acpi_add_table(rsdp, ssdt); |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 325 | |
| 326 | printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current); |
| 327 | |
| 328 | return current; |
| 329 | } |
| 330 | |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 331 | static struct device_operations northbridge_operations = { |
Steven Sherk | f434058 | 2013-01-29 16:13:35 -0700 | [diff] [blame] | 332 | .read_resources = nb_read_resources, |
| 333 | .set_resources = nb_set_resources, |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 334 | .enable_resources = pci_dev_enable_resources, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 335 | .acpi_fill_ssdt = northbridge_fill_ssdt_generator, |
Vladimir Serbinenko | 56f46d8 | 2014-10-08 22:06:27 +0200 | [diff] [blame] | 336 | .write_acpi_tables = agesa_write_acpi_tables, |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 337 | }; |
| 338 | |
| 339 | static const struct pci_driver family15_northbridge __pci_driver = { |
| 340 | .ops = &northbridge_operations, |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 341 | .vendor = PCI_VID_AMD, |
| 342 | .device = PCI_DID_AMD_15H_MODEL_101F_NB_HT, |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 343 | }; |
| 344 | |
| 345 | static const struct pci_driver family10_northbridge __pci_driver = { |
| 346 | .ops = &northbridge_operations, |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 347 | .vendor = PCI_VID_AMD, |
| 348 | .device = PCI_DID_AMD_10H_NB_HT, |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 349 | }; |
| 350 | |
| 351 | struct chip_operations northbridge_amd_agesa_family15tn_ops = { |
| 352 | CHIP_NAME("AMD FAM15 Northbridge") |
| 353 | .enable_dev = 0, |
| 354 | }; |
| 355 | |
Kyösti Mälkki | 2900d4b | 2017-07-25 14:55:29 +0300 | [diff] [blame] | 356 | static void domain_read_resources(struct device *dev) |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 357 | { |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 358 | unsigned int reg; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 359 | |
| 360 | /* Find the already assigned resource pairs */ |
| 361 | get_fx_devs(); |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 362 | for (reg = 0x80; reg <= 0xd8; reg += 0x08) { |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 363 | u32 base, limit; |
| 364 | base = f1_read_config32(reg); |
| 365 | limit = f1_read_config32(reg + 0x04); |
| 366 | /* Is this register allocated? */ |
| 367 | if ((base & 3) != 0) { |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 368 | unsigned int nodeid, reg_link; |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 369 | struct device *reg_dev; |
Elyes HAOUAS | 1d8daa6 | 2016-09-18 08:50:54 +0200 | [diff] [blame] | 370 | if (reg < 0xc0) { // mmio |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 371 | nodeid = (limit & 0xf) + (base & 0x30); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 372 | } else { // io |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 373 | nodeid = (limit & 0xf) + ((base >> 4) & 0x30); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 374 | } |
| 375 | reg_link = (limit >> 4) & 7; |
| 376 | reg_dev = __f0_dev[nodeid]; |
| 377 | if (reg_dev) { |
| 378 | /* Reserve the resource */ |
| 379 | struct resource *res; |
| 380 | res = new_resource(reg_dev, IOINDEX(0x1000 + reg, reg_link)); |
| 381 | if (res) { |
| 382 | res->flags = 1; |
| 383 | } |
| 384 | } |
| 385 | } |
| 386 | } |
| 387 | /* FIXME: do we need to check extend conf space? |
| 388 | I don't believe that much preset value */ |
| 389 | |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 390 | pci_domain_read_resources(dev); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 391 | } |
| 392 | |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 393 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
| 394 | struct hw_mem_hole_info { |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 395 | unsigned int hole_startk; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 396 | int node_id; |
| 397 | }; |
| 398 | static struct hw_mem_hole_info get_hw_mem_hole_info(void) |
| 399 | { |
| 400 | struct hw_mem_hole_info mem_hole; |
| 401 | int i; |
| 402 | mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK; |
| 403 | mem_hole.node_id = -1; |
| 404 | for (i = 0; i < node_nums; i++) { |
Michał Żygowski | 88a0ce6 | 2021-05-05 09:52:59 +0200 | [diff] [blame] | 405 | resource_t basek, limitk; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 406 | u32 hole; |
Michał Żygowski | 88a0ce6 | 2021-05-05 09:52:59 +0200 | [diff] [blame] | 407 | if (!get_dram_base_limit(i, &basek, &limitk)) |
| 408 | continue; // no memory on this node |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 409 | hole = pci_read_config32(__f1_dev[i], 0xf0); |
| 410 | if (hole & 1) { // we find the hole |
Elyes HAOUAS | 27e1801 | 2017-06-27 23:14:51 +0200 | [diff] [blame] | 411 | mem_hole.hole_startk = (hole & (0xff << 24)) >> 10; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 412 | mem_hole.node_id = i; // record the node No with hole |
| 413 | break; // only one hole |
| 414 | } |
| 415 | } |
Kyösti Mälkki | 2f9b3af | 2014-06-26 05:30:54 +0300 | [diff] [blame] | 416 | |
| 417 | /* We need to double check if there is special set on base reg and limit reg |
| 418 | * are not continuous instead of hole, it will find out its hole_startk. |
| 419 | */ |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 420 | if (mem_hole.node_id == -1) { |
| 421 | resource_t limitk_pri = 0; |
Elyes HAOUAS | 1d8daa6 | 2016-09-18 08:50:54 +0200 | [diff] [blame] | 422 | for (i = 0; i < node_nums; i++) { |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 423 | resource_t base_k, limit_k; |
Michał Żygowski | 88a0ce6 | 2021-05-05 09:52:59 +0200 | [diff] [blame] | 424 | if (!get_dram_base_limit(i, &base_k, &limit_k)) |
| 425 | continue; // no memory on this node |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 426 | if (base_k > 4 * 1024 * 1024) break; // don't need to go to check |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 427 | if (limitk_pri != base_k) { // we find the hole |
Martin Roth | 468d02c | 2019-10-23 21:44:42 -0600 | [diff] [blame] | 428 | mem_hole.hole_startk = (unsigned int)limitk_pri; // must beblow 4G |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 429 | mem_hole.node_id = i; |
| 430 | break; //only one hole |
| 431 | } |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 432 | limitk_pri = limit_k; |
| 433 | } |
| 434 | } |
| 435 | return mem_hole; |
| 436 | } |
| 437 | #endif |
| 438 | |
Kyösti Mälkki | 2900d4b | 2017-07-25 14:55:29 +0300 | [diff] [blame] | 439 | static void domain_set_resources(struct device *dev) |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 440 | { |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 441 | unsigned long mmio_basek; |
| 442 | u32 pci_tolm; |
| 443 | int i, idx; |
| 444 | struct bus *link; |
| 445 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
| 446 | struct hw_mem_hole_info mem_hole; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 447 | #endif |
| 448 | |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 449 | pci_tolm = 0xffffffffUL; |
| 450 | for (link = dev->link_list; link; link = link->next) { |
| 451 | pci_tolm = find_pci_tolm(link); |
| 452 | } |
| 453 | |
| 454 | // FIXME handle interleaved nodes. If you fix this here, please fix |
| 455 | // amdk8, too. |
| 456 | mmio_basek = pci_tolm >> 10; |
| 457 | /* Round mmio_basek to something the processor can support */ |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 458 | mmio_basek &= ~((1 << 6) - 1); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 459 | |
| 460 | // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M |
| 461 | // MMIO hole. If you fix this here, please fix amdk8, too. |
| 462 | /* Round the mmio hole to 64M */ |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 463 | mmio_basek &= ~((64 * 1024) - 1); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 464 | |
| 465 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
| 466 | /* if the hw mem hole is already set in raminit stage, here we will compare |
| 467 | * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will |
| 468 | * use hole_basek as mmio_basek and we don't need to reset hole. |
| 469 | * otherwise We reset the hole to the mmio_basek |
| 470 | */ |
| 471 | |
| 472 | mem_hole = get_hw_mem_hole_info(); |
| 473 | |
| 474 | // Use hole_basek as mmio_basek, and we don't need to reset hole anymore |
Arthur Heymans | 99eab34 | 2022-03-23 21:34:20 +0100 | [diff] [blame] | 475 | if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 476 | mmio_basek = mem_hole.hole_startk; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 477 | #endif |
| 478 | |
| 479 | idx = 0x10; |
| 480 | for (i = 0; i < node_nums; i++) { |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 481 | resource_t basek, limitk, sizek; // 4 1T |
| 482 | |
Michał Żygowski | 88a0ce6 | 2021-05-05 09:52:59 +0200 | [diff] [blame] | 483 | if (!get_dram_base_limit(i, &basek, &limitk)) |
| 484 | continue; // no memory on this node |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 485 | |
| 486 | sizek = limitk - basek; |
| 487 | |
Elyes Haouas | 5213b19 | 2022-02-25 18:13:03 +0100 | [diff] [blame] | 488 | /* See if we need a hole from 0xa0000 (640K) to 0xbffff (768K) */ |
Elyes Haouas | 9d8df30 | 2022-02-25 18:23:01 +0100 | [diff] [blame] | 489 | if (basek < 640 && sizek > 768) { |
Kyösti Mälkki | 27d6299 | 2022-05-24 20:25:58 +0300 | [diff] [blame] | 490 | ram_resource_kb(dev, (idx | i), basek, 640 - basek); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 491 | idx += 0x10; |
Elyes Haouas | 9d8df30 | 2022-02-25 18:23:01 +0100 | [diff] [blame] | 492 | basek = 768; |
| 493 | sizek = limitk - basek; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 494 | |
| 495 | } |
| 496 | |
Kyösti Mälkki | 26c6543 | 2014-06-26 05:30:54 +0300 | [diff] [blame] | 497 | /* split the region to accommodate pci memory space */ |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 498 | if ((basek < 4 * 1024 * 1024) && (limitk > mmio_basek)) { |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 499 | if (basek <= mmio_basek) { |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 500 | unsigned int pre_sizek; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 501 | pre_sizek = mmio_basek - basek; |
Elyes HAOUAS | 1d8daa6 | 2016-09-18 08:50:54 +0200 | [diff] [blame] | 502 | if (pre_sizek > 0) { |
Kyösti Mälkki | 27d6299 | 2022-05-24 20:25:58 +0300 | [diff] [blame] | 503 | ram_resource_kb(dev, (idx | i), basek, pre_sizek); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 504 | idx += 0x10; |
| 505 | sizek -= pre_sizek; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 506 | } |
| 507 | basek = mmio_basek; |
| 508 | } |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 509 | if ((basek + sizek) <= 4 * 1024 * 1024) { |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 510 | sizek = 0; |
| 511 | } |
| 512 | else { |
Arthur Heymans | c435038 | 2021-10-28 12:35:39 +0200 | [diff] [blame] | 513 | uint64_t topmem2 = amd_topmem2(); |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 514 | basek = 4 * 1024 * 1024; |
| 515 | sizek = topmem2 / 1024 - basek; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 516 | } |
| 517 | } |
| 518 | |
Kyösti Mälkki | 27d6299 | 2022-05-24 20:25:58 +0300 | [diff] [blame] | 519 | ram_resource_kb(dev, (idx | i), basek, sizek); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 520 | idx += 0x10; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 521 | printk(BIOS_DEBUG, "node %d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", |
| 522 | i, mmio_basek, basek, limitk); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 523 | } |
| 524 | |
Kyösti Mälkki | 61be360 | 2017-04-15 20:07:53 +0300 | [diff] [blame] | 525 | add_uma_resource_below_tolm(dev, 7); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 526 | |
Elyes HAOUAS | 5a7e72f | 2016-08-23 21:36:02 +0200 | [diff] [blame] | 527 | for (link = dev->link_list; link; link = link->next) { |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 528 | if (link->children) { |
| 529 | assign_resources(link); |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | static struct device_operations pci_domain_ops = { |
| 535 | .read_resources = domain_read_resources, |
| 536 | .set_resources = domain_set_resources, |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 537 | .scan_bus = pci_domain_scan_bus, |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 538 | }; |
| 539 | |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 540 | static void sysconf_init(struct device *dev) // first node |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 541 | { |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 542 | sblink = (pci_read_config32(dev, 0x64) >> 8) & 7; // don't forget sublink1 |
| 543 | node_nums = ((pci_read_config32(dev, 0x60) >> 4) & 7) + 1; //NodeCnt[2:0] |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 544 | } |
| 545 | |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 546 | static void cpu_bus_scan(struct device *dev) |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 547 | { |
| 548 | struct bus *cpu_bus; |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 549 | struct device *dev_mc; |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 550 | int i, j; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 551 | int coreid_bits; |
| 552 | int core_max = 0; |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 553 | unsigned int ApicIdCoreIdSize; |
| 554 | unsigned int core_nums; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 555 | int siblings = 0; |
| 556 | unsigned int family; |
| 557 | |
Kyösti Mälkki | 3d3152e | 2019-01-10 09:05:30 +0200 | [diff] [blame] | 558 | dev_mc = pcidev_on_root(DEV_CDB, 0); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 559 | if (!dev_mc) { |
Kyösti Mälkki | 3d3152e | 2019-01-10 09:05:30 +0200 | [diff] [blame] | 560 | printk(BIOS_ERR, "0:%02x.0 not found", DEV_CDB); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 561 | die(""); |
| 562 | } |
| 563 | sysconf_init(dev_mc); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 564 | |
| 565 | /* Get Max Number of cores(MNC) */ |
Kyösti Mälkki | d41feed | 2017-09-24 16:23:57 +0300 | [diff] [blame] | 566 | coreid_bits = (cpuid_ecx(0x80000008) & 0x0000F000) >> 12; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 567 | core_max = 1 << (coreid_bits & 0x000F); //mnc |
| 568 | |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 569 | ApicIdCoreIdSize = ((cpuid_ecx(0x80000008) >> 12) & 0xF); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 570 | if (ApicIdCoreIdSize) { |
| 571 | core_nums = (1 << ApicIdCoreIdSize) - 1; |
| 572 | } else { |
| 573 | core_nums = 3; //quad core |
| 574 | } |
| 575 | |
| 576 | /* Find which cpus are present */ |
| 577 | cpu_bus = dev->link_list; |
| 578 | for (i = 0; i < node_nums; i++) { |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 579 | struct device *cdb_dev; |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 580 | unsigned int devn; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 581 | struct bus *pbus; |
| 582 | |
Kyösti Mälkki | 3d3152e | 2019-01-10 09:05:30 +0200 | [diff] [blame] | 583 | devn = DEV_CDB + i; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 584 | pbus = dev_mc->bus; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 585 | |
| 586 | /* Find the cpu's pci device */ |
Kyösti Mälkki | 4ad7f5b | 2018-05-22 01:15:17 +0300 | [diff] [blame] | 587 | cdb_dev = pcidev_on_root(devn, 0); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 588 | if (!cdb_dev) { |
| 589 | /* If I am probing things in a weird order |
| 590 | * ensure all of the cpu's pci devices are found. |
| 591 | */ |
| 592 | int fn; |
Elyes HAOUAS | 5a7e72f | 2016-08-23 21:36:02 +0200 | [diff] [blame] | 593 | for (fn = 0; fn <= 5; fn++) { //FBDIMM? |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 594 | cdb_dev = pci_probe_dev(NULL, pbus, |
| 595 | PCI_DEVFN(devn, fn)); |
| 596 | } |
Kyösti Mälkki | 4ad7f5b | 2018-05-22 01:15:17 +0300 | [diff] [blame] | 597 | cdb_dev = pcidev_on_root(devn, 0); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 598 | } else { |
| 599 | /* Ok, We need to set the links for that device. |
| 600 | * otherwise the device under it will not be scanned |
| 601 | */ |
Kyösti Mälkki | 2a2d613 | 2015-02-04 13:25:37 +0200 | [diff] [blame] | 602 | add_more_links(cdb_dev, 4); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | family = cpuid_eax(1); |
| 606 | family = (family >> 20) & 0xFF; |
| 607 | if (family == 1) { //f10 |
| 608 | u32 dword; |
Kyösti Mälkki | 4ad7f5b | 2018-05-22 01:15:17 +0300 | [diff] [blame] | 609 | cdb_dev = pcidev_on_root(devn, 3); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 610 | dword = pci_read_config32(cdb_dev, 0xe8); |
| 611 | siblings = ((dword & BIT15) >> 13) | ((dword & (BIT13 | BIT12)) >> 12); |
| 612 | } else if (family == 6) {//f15 |
Kyösti Mälkki | 4ad7f5b | 2018-05-22 01:15:17 +0300 | [diff] [blame] | 613 | cdb_dev = pcidev_on_root(devn, 5); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 614 | if (cdb_dev && cdb_dev->enabled) { |
| 615 | siblings = pci_read_config32(cdb_dev, 0x84); |
| 616 | siblings &= 0xFF; |
| 617 | } |
| 618 | } else { |
| 619 | siblings = 0; //default one core |
| 620 | } |
Kyösti Mälkki | cd9fc1a | 2012-07-06 19:02:56 +0300 | [diff] [blame] | 621 | int enable_node = cdb_dev && cdb_dev->enabled; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 622 | printk(BIOS_SPEW, "%s family%xh, core_max=0x%x, core_nums=0x%x, siblings=0x%x\n", |
| 623 | dev_path(cdb_dev), 0x0f + family, core_max, core_nums, siblings); |
| 624 | |
Elyes HAOUAS | 1d8daa6 | 2016-09-18 08:50:54 +0200 | [diff] [blame] | 625 | for (j = 0; j <= siblings; j++) { |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 626 | extern CONST OPTIONS_CONFIG_TOPOLOGY ROMDATA TopologyConfiguration; |
| 627 | u32 modules = TopologyConfiguration.PlatformNumberOfModules; |
| 628 | u32 lapicid_start = 0; |
| 629 | |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 630 | /* |
| 631 | * APIC ID calucation is tightly coupled with AGESA v5 code. |
| 632 | * This calculation MUST match the assignment calculation done |
| 633 | * in LocalApicInitializationAtEarly() function. |
| 634 | * And reference GetLocalApicIdForCore() |
| 635 | * |
Elyes HAOUAS | a5b0bc4 | 2020-02-20 20:04:29 +0100 | [diff] [blame] | 636 | * Apply APIC enumeration rules |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 637 | * For systems with >= 16 APICs, put the IO-APICs at 0..n and |
| 638 | * put the local-APICs at m..z |
| 639 | * |
| 640 | * This is needed because many IO-APIC devices only have 4 bits |
| 641 | * for their APIC id and therefore must reside at 0..15 |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 642 | */ |
Kyösti Mälkki | 5003632 | 2016-05-18 13:35:21 +0300 | [diff] [blame] | 643 | |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 644 | u8 plat_num_io_apics = 3; /* FIXME */ |
Kyösti Mälkki | 5003632 | 2016-05-18 13:35:21 +0300 | [diff] [blame] | 645 | |
| 646 | if ((node_nums * core_max) + plat_num_io_apics >= 0x10) { |
| 647 | lapicid_start = (plat_num_io_apics - 1) / core_max; |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 648 | lapicid_start = (lapicid_start + 1) * core_max; |
| 649 | printk(BIOS_SPEW, "lpaicid_start=0x%x ", lapicid_start); |
| 650 | } |
Elyes Haouas | 3adfde9 | 2022-07-16 09:36:01 +0200 | [diff] [blame] | 651 | u32 apic_id = (lapicid_start * (i / modules + 1)) + ((i % modules) ? (j + (siblings + 1)) : j); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 652 | printk(BIOS_SPEW, "node 0x%x core 0x%x apicid=0x%x\n", |
Kyösti Mälkki | c33f1e9 | 2012-08-07 17:12:11 +0300 | [diff] [blame] | 653 | i, j, apic_id); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 654 | |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 655 | struct device *cpu = add_cpu_device(cpu_bus, apic_id, enable_node); |
Kyösti Mälkki | c33f1e9 | 2012-08-07 17:12:11 +0300 | [diff] [blame] | 656 | if (cpu) |
| 657 | amd_cpu_topology(cpu, i, j); |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 658 | } //j |
| 659 | } |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 660 | } |
| 661 | |
Kyösti Mälkki | 2900d4b | 2017-07-25 14:55:29 +0300 | [diff] [blame] | 662 | static void cpu_bus_init(struct device *dev) |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 663 | { |
| 664 | initialize_cpus(dev->link_list); |
| 665 | } |
| 666 | |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 667 | static struct device_operations cpu_bus_ops = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 668 | .read_resources = noop_read_resources, |
| 669 | .set_resources = noop_set_resources, |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 670 | .init = cpu_bus_init, |
| 671 | .scan_bus = cpu_bus_scan, |
| 672 | }; |
| 673 | |
| 674 | static void root_complex_enable_dev(struct device *dev) |
| 675 | { |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 676 | /* Set the operations if it is a special bus type */ |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 677 | if (dev->path.type == DEVICE_PATH_DOMAIN) { |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 678 | dev->ops = &pci_domain_ops; |
Stefan Reinauer | 0aa37c4 | 2013-02-12 15:20:54 -0800 | [diff] [blame] | 679 | } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) { |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 680 | dev->ops = &cpu_bus_ops; |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | struct chip_operations northbridge_amd_agesa_family15tn_root_complex_ops = { |
Kyösti Mälkki | 2900d4b | 2017-07-25 14:55:29 +0300 | [diff] [blame] | 685 | CHIP_NAME("AMD Family 15tn Root Complex") |
zbao | 2c08f6a | 2012-07-02 15:32:58 +0800 | [diff] [blame] | 686 | .enable_dev = root_complex_enable_dev, |
| 687 | }; |
Dave Frodin | cbf3d40 | 2012-12-05 08:20:12 -0700 | [diff] [blame] | 688 | |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 689 | /********************************************************************* |
| 690 | * Change the vendor / device IDs to match the generic VBIOS header. * |
| 691 | *********************************************************************/ |
Dave Frodin | cbf3d40 | 2012-12-05 08:20:12 -0700 | [diff] [blame] | 692 | u32 map_oprom_vendev(u32 vendev) |
| 693 | { |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 694 | u32 new_vendev = vendev; |
Dave Frodin | cbf3d40 | 2012-12-05 08:20:12 -0700 | [diff] [blame] | 695 | |
Elyes HAOUAS | 0ce41f1 | 2018-11-13 10:03:31 +0100 | [diff] [blame] | 696 | switch (vendev) { |
Bruce Griffith | 42e11f5 | 2013-07-08 18:19:08 -0600 | [diff] [blame] | 697 | case 0x10029900: /* AMD Radeon HD 7660G (Trinity) */ |
| 698 | case 0x10029901: /* AMD Radeon HD 7660D (Trinity) */ |
| 699 | case 0x10029903: /* AMD Radeon HD 7640G (Trinity) */ |
| 700 | case 0x10029904: /* AMD Radeon HD 7560D (Trinity) */ |
| 701 | case 0x10029907: /* AMD Radeon HD 7620G (Trinity) */ |
| 702 | case 0x10029908: /* AMD Radeon HD 7600G (Trinity) */ |
| 703 | case 0x1002990A: /* AMD Radeon HD 7500G (Trinity) */ |
| 704 | case 0x1002990B: /* AMD Radeon HD 8650G (Richland) */ |
| 705 | case 0x1002990C: /* AMD Radeon HD 8670D (Richland) */ |
| 706 | case 0x1002990D: /* AMD Radeon HD 8550G (Richland) */ |
| 707 | case 0x1002990E: /* AMD Radeon HD 8570D (Richland) */ |
| 708 | case 0x1002990F: /* AMD Radeon HD 8610G (Richland) */ |
| 709 | case 0x10029910: /* AMD Radeon HD 7660G (Trinity) */ |
| 710 | case 0x10029913: /* AMD Radeon HD 7640G (Trinity) */ |
| 711 | case 0x10029917: /* AMD Radeon HD 7620G (Trinity) */ |
| 712 | case 0x10029918: /* AMD Radeon HD 7600G (Trinity) */ |
| 713 | case 0x10029919: /* AMD Radeon HD 7500G (Trinity) */ |
| 714 | case 0x10029990: /* AMD Radeon HD 7520G (Trinity) */ |
| 715 | case 0x10029991: /* AMD Radeon HD 7540D (Trinity) */ |
| 716 | case 0x10029992: /* AMD Radeon HD 7420G (Trinity) */ |
| 717 | case 0x10029993: /* AMD Radeon HD 7480D (Trinity) */ |
| 718 | case 0x10029994: /* AMD Radeon HD 7400G (Trinity) */ |
| 719 | case 0x10029995: /* AMD Radeon HD 8450G (Richland) */ |
| 720 | case 0x10029996: /* AMD Radeon HD 8470D (Richland) */ |
| 721 | case 0x10029997: /* AMD Radeon HD 8350G (Richland) */ |
| 722 | case 0x10029998: /* AMD Radeon HD 8370D (Richland) */ |
| 723 | case 0x10029999: /* AMD Radeon HD 8510G (Richland) */ |
| 724 | case 0x1002999A: /* AMD Radeon HD 8410G (Richland) */ |
| 725 | case 0x1002999B: /* AMD Radeon HD 8310G (Richland) */ |
| 726 | case 0x1002999C: /* AMD Radeon HD 8650D (Richland) */ |
| 727 | case 0x1002999D: /* AMD Radeon HD 8550D (Richland) */ |
| 728 | case 0x100299A0: /* AMD Radeon HD 7520G (Trinity) */ |
| 729 | case 0x100299A2: /* AMD Radeon HD 7420G (Trinity) */ |
| 730 | case 0x100299A4: /* AMD Radeon HD 7400G (Trinity) */ |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 731 | new_vendev = 0x10029901; |
Dave Frodin | cbf3d40 | 2012-12-05 08:20:12 -0700 | [diff] [blame] | 732 | break; |
| 733 | } |
| 734 | |
| 735 | return new_vendev; |
| 736 | } |