Angel Pons | 4b42983 | 2020-04-02 23:48:50 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 3 | |
| 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> |
Kyösti Mälkki | 8ae16a4 | 2014-06-19 20:44:34 +0300 | [diff] [blame] | 6 | #include <arch/acpi.h> |
Vladimir Serbinenko | db09b062 | 2014-10-08 22:15:17 +0200 | [diff] [blame] | 7 | #include <arch/acpigen.h> |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | #include <device/device.h> |
| 10 | #include <device/pci.h> |
| 11 | #include <device/pci_ids.h> |
| 12 | #include <device/hypertransport.h> |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 13 | #include <string.h> |
| 14 | #include <lib.h> |
| 15 | #include <cpu/cpu.h> |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 16 | #include <cpu/x86/lapic.h> |
Elyes HAOUAS | 400ce55 | 2018-10-12 10:54:30 +0200 | [diff] [blame] | 17 | #include <cpu/amd/msr.h> |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 18 | #include <cpu/amd/mtrr.h> |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 19 | #include <Porting.h> |
| 20 | #include <AGESA.h> |
| 21 | #include <Options.h> |
| 22 | #include <Topology.h> |
Kyösti Mälkki | 3d3152e | 2019-01-10 09:05:30 +0200 | [diff] [blame] | 23 | #include <northbridge/amd/agesa/nb_common.h> |
Kyösti Mälkki | 28c4d2f | 2016-11-25 11:21:02 +0200 | [diff] [blame] | 24 | #include <northbridge/amd/agesa/state_machine.h> |
Kyösti Mälkki | d610c58 | 2017-03-05 06:28:18 +0200 | [diff] [blame] | 25 | #include <northbridge/amd/agesa/agesa_helper.h> |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 26 | |
Kyösti Mälkki | 113f670 | 2018-05-20 20:12:32 +0300 | [diff] [blame] | 27 | #define MAX_NODE_NUMS MAX_NODES |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 28 | |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 29 | typedef struct dram_base_mask { |
| 30 | u32 base; //[47:27] at [28:8] |
| 31 | u32 mask; //[47:27] at [28:8] and enable at bit 0 |
| 32 | } dram_base_mask_t; |
| 33 | |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 34 | static unsigned int node_nums; |
| 35 | static unsigned int sblink; |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 36 | static struct device *__f0_dev[MAX_NODE_NUMS]; |
| 37 | static struct device *__f1_dev[MAX_NODE_NUMS]; |
| 38 | static struct device *__f2_dev[MAX_NODE_NUMS]; |
| 39 | static struct device *__f4_dev[MAX_NODE_NUMS]; |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 40 | static unsigned int fx_devs = 0; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 41 | |
| 42 | static dram_base_mask_t get_dram_base_mask(u32 nodeid) |
| 43 | { |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 44 | struct device *dev; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 45 | dram_base_mask_t d; |
| 46 | dev = __f1_dev[0]; |
| 47 | u32 temp; |
| 48 | temp = pci_read_config32(dev, 0x44 + (nodeid << 3)); //[39:24] at [31:16] |
| 49 | d.mask = ((temp & 0xfff80000)>>(8+3)); // mask out DramMask [26:24] too |
| 50 | temp = pci_read_config32(dev, 0x144 + (nodeid <<3)) & 0xff; //[47:40] at [7:0] |
Elyes HAOUAS | 27e1801 | 2017-06-27 23:14:51 +0200 | [diff] [blame] | 51 | d.mask |= temp << 21; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 52 | temp = pci_read_config32(dev, 0x40 + (nodeid << 3)); //[39:24] at [31:16] |
| 53 | d.mask |= (temp & 1); // enable bit |
| 54 | d.base = ((temp & 0xfff80000)>>(8+3)); // mask out DramBase [26:24) too |
| 55 | temp = pci_read_config32(dev, 0x140 + (nodeid <<3)) & 0xff; //[47:40] at [7:0] |
Elyes HAOUAS | 27e1801 | 2017-06-27 23:14:51 +0200 | [diff] [blame] | 56 | d.base |= temp << 21; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 57 | return d; |
| 58 | } |
| 59 | |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 60 | static void set_io_addr_reg(struct device *dev, u32 nodeid, u32 linkn, u32 reg, |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 61 | u32 io_min, u32 io_max) |
| 62 | { |
| 63 | u32 i; |
| 64 | u32 tempreg; |
| 65 | /* io range allocation */ |
Elyes HAOUAS | 27e1801 | 2017-06-27 23:14:51 +0200 | [diff] [blame] | 66 | tempreg = (nodeid&0xf) | ((nodeid & 0x30)<<(8-4)) | (linkn << 4) | ((io_max&0xf0)<<(12-4)); //limit |
Elyes HAOUAS | 1d8daa6 | 2016-09-18 08:50:54 +0200 | [diff] [blame] | 67 | for (i = 0; i < node_nums; i++) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 68 | pci_write_config32(__f1_dev[i], reg+4, tempreg); |
Elyes HAOUAS | 27e1801 | 2017-06-27 23:14:51 +0200 | [diff] [blame] | 69 | tempreg = 3 /*| (3 << 4)*/ | ((io_min&0xf0)<<(12-4)); //base :ISA and VGA ? |
Elyes HAOUAS | 1d8daa6 | 2016-09-18 08:50:54 +0200 | [diff] [blame] | 70 | for (i = 0; i < node_nums; i++) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 71 | pci_write_config32(__f1_dev[i], reg, tempreg); |
| 72 | } |
| 73 | |
| 74 | static void set_mmio_addr_reg(u32 nodeid, u32 linkn, u32 reg, u32 index, u32 mmio_min, u32 mmio_max, u32 nodes) |
| 75 | { |
| 76 | u32 i; |
| 77 | u32 tempreg; |
| 78 | /* io range allocation */ |
Elyes HAOUAS | 27e1801 | 2017-06-27 23:14:51 +0200 | [diff] [blame] | 79 | tempreg = (nodeid&0xf) | (linkn << 4) | (mmio_max&0xffffff00); //limit |
Elyes HAOUAS | 1d8daa6 | 2016-09-18 08:50:54 +0200 | [diff] [blame] | 80 | for (i = 0; i < nodes; i++) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 81 | pci_write_config32(__f1_dev[i], reg+4, tempreg); |
| 82 | tempreg = 3 | (nodeid & 0x30) | (mmio_min&0xffffff00); |
Elyes HAOUAS | 1d8daa6 | 2016-09-18 08:50:54 +0200 | [diff] [blame] | 83 | for (i = 0; i < node_nums; i++) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 84 | pci_write_config32(__f1_dev[i], reg, tempreg); |
| 85 | } |
| 86 | |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 87 | static struct device *get_node_pci(u32 nodeid, u32 fn) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 88 | { |
Kyösti Mälkki | 3d3152e | 2019-01-10 09:05:30 +0200 | [diff] [blame] | 89 | return pcidev_on_root(DEV_CDB + nodeid, fn); |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | static void get_fx_devs(void) |
| 93 | { |
| 94 | int i; |
| 95 | for (i = 0; i < MAX_NODE_NUMS; i++) { |
| 96 | __f0_dev[i] = get_node_pci(i, 0); |
| 97 | __f1_dev[i] = get_node_pci(i, 1); |
| 98 | __f2_dev[i] = get_node_pci(i, 2); |
| 99 | __f4_dev[i] = get_node_pci(i, 4); |
| 100 | if (__f0_dev[i] != NULL && __f1_dev[i] != NULL) |
| 101 | fx_devs = i+1; |
| 102 | } |
| 103 | if (__f1_dev[0] == NULL || __f0_dev[0] == NULL || fx_devs == 0) { |
| 104 | die("Cannot find 0:0x18.[0|1]\n"); |
| 105 | } |
| 106 | printk(BIOS_DEBUG, "fx_devs=0x%x\n", fx_devs); |
| 107 | } |
| 108 | |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 109 | static u32 f1_read_config32(unsigned int reg) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 110 | { |
| 111 | if (fx_devs == 0) |
| 112 | get_fx_devs(); |
| 113 | return pci_read_config32(__f1_dev[0], reg); |
| 114 | } |
| 115 | |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 116 | static void f1_write_config32(unsigned int reg, u32 value) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 117 | { |
| 118 | int i; |
| 119 | if (fx_devs == 0) |
| 120 | get_fx_devs(); |
Elyes HAOUAS | 5a7e72f | 2016-08-23 21:36:02 +0200 | [diff] [blame] | 121 | for (i = 0; i < fx_devs; i++) { |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 122 | struct device *dev; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 123 | dev = __f1_dev[i]; |
| 124 | if (dev && dev->enabled) { |
| 125 | pci_write_config32(dev, reg, value); |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 130 | static u32 amdfam16_nodeid(struct device *dev) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 131 | { |
Kyösti Mälkki | 3d3152e | 2019-01-10 09:05:30 +0200 | [diff] [blame] | 132 | return (dev->path.pci.devfn >> 3) - DEV_CDB; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | static void set_vga_enable_reg(u32 nodeid, u32 linkn) |
| 136 | { |
| 137 | u32 val; |
| 138 | |
Elyes HAOUAS | 27e1801 | 2017-06-27 23:14:51 +0200 | [diff] [blame] | 139 | val = 1 | (nodeid << 4) | (linkn << 12); |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 140 | /* it will routing |
| 141 | * (1)mmio 0xa0000:0xbffff |
| 142 | * (2)io 0x3b0:0x3bb, 0x3c0:0x3df |
| 143 | */ |
| 144 | f1_write_config32(0xf4, val); |
| 145 | |
| 146 | } |
| 147 | |
| 148 | /** |
| 149 | * @return |
Elyes HAOUAS | 99b075a | 2019-12-30 14:29:31 +0100 | [diff] [blame] | 150 | * @retval 2 resource does not exist, usable |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 151 | * @retval 0 resource exists, not usable |
| 152 | * @retval 1 resource exist, resource has been allocated before |
| 153 | */ |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 154 | static int reg_useable(unsigned int reg, struct device *goal_dev, |
| 155 | unsigned int goal_nodeid, unsigned int goal_link) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 156 | { |
| 157 | struct resource *res; |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 158 | unsigned int nodeid, link = 0; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 159 | int result; |
| 160 | res = 0; |
| 161 | for (nodeid = 0; !res && (nodeid < fx_devs); nodeid++) { |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 162 | struct device *dev; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 163 | dev = __f0_dev[nodeid]; |
| 164 | if (!dev) |
| 165 | continue; |
| 166 | for (link = 0; !res && (link < 8); link++) { |
| 167 | res = probe_resource(dev, IOINDEX(0x1000 + reg, link)); |
| 168 | } |
| 169 | } |
| 170 | result = 2; |
| 171 | if (res) { |
| 172 | result = 0; |
| 173 | if ((goal_link == (link - 1)) && |
| 174 | (goal_nodeid == (nodeid - 1)) && |
| 175 | (res->flags <= 1)) { |
| 176 | result = 1; |
| 177 | } |
| 178 | } |
| 179 | return result; |
| 180 | } |
| 181 | |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 182 | static struct resource *amdfam16_find_iopair(struct device *dev, |
| 183 | unsigned int nodeid, unsigned int link) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 184 | { |
| 185 | struct resource *resource; |
| 186 | u32 free_reg, reg; |
| 187 | resource = 0; |
| 188 | free_reg = 0; |
| 189 | for (reg = 0xc0; reg <= 0xd8; reg += 0x8) { |
| 190 | int result; |
| 191 | result = reg_useable(reg, dev, nodeid, link); |
| 192 | if (result == 1) { |
| 193 | /* I have been allocated this one */ |
| 194 | break; |
| 195 | } |
| 196 | else if (result > 1) { |
| 197 | /* I have a free register pair */ |
| 198 | free_reg = reg; |
| 199 | } |
| 200 | } |
| 201 | if (reg > 0xd8) { |
| 202 | reg = free_reg; // if no free, the free_reg still be 0 |
| 203 | } |
| 204 | |
| 205 | resource = new_resource(dev, IOINDEX(0x1000 + reg, link)); |
| 206 | |
| 207 | return resource; |
| 208 | } |
| 209 | |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 210 | static struct resource *amdfam16_find_mempair(struct device *dev, u32 nodeid, u32 link) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 211 | { |
| 212 | struct resource *resource; |
| 213 | u32 free_reg, reg; |
| 214 | resource = 0; |
| 215 | free_reg = 0; |
| 216 | for (reg = 0x80; reg <= 0xb8; reg += 0x8) { |
| 217 | int result; |
| 218 | result = reg_useable(reg, dev, nodeid, link); |
| 219 | if (result == 1) { |
| 220 | /* I have been allocated this one */ |
| 221 | break; |
| 222 | } |
| 223 | else if (result > 1) { |
| 224 | /* I have a free register pair */ |
| 225 | free_reg = reg; |
| 226 | } |
| 227 | } |
| 228 | if (reg > 0xb8) { |
| 229 | reg = free_reg; |
| 230 | } |
| 231 | |
| 232 | resource = new_resource(dev, IOINDEX(0x1000 + reg, link)); |
| 233 | return resource; |
| 234 | } |
| 235 | |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 236 | static void amdfam16_link_read_bases(struct device *dev, u32 nodeid, u32 link) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 237 | { |
| 238 | struct resource *resource; |
| 239 | |
| 240 | /* Initialize the io space constraints on the current bus */ |
| 241 | resource = amdfam16_find_iopair(dev, nodeid, link); |
| 242 | if (resource) { |
| 243 | u32 align; |
| 244 | align = log2(HT_IO_HOST_ALIGN); |
| 245 | resource->base = 0; |
| 246 | resource->size = 0; |
| 247 | resource->align = align; |
| 248 | resource->gran = align; |
| 249 | resource->limit = 0xffffUL; |
| 250 | resource->flags = IORESOURCE_IO | IORESOURCE_BRIDGE; |
| 251 | } |
| 252 | |
| 253 | /* Initialize the prefetchable memory constraints on the current bus */ |
| 254 | resource = amdfam16_find_mempair(dev, nodeid, link); |
| 255 | if (resource) { |
| 256 | resource->base = 0; |
| 257 | resource->size = 0; |
| 258 | resource->align = log2(HT_MEM_HOST_ALIGN); |
| 259 | resource->gran = log2(HT_MEM_HOST_ALIGN); |
| 260 | resource->limit = 0xffffffffffULL; |
| 261 | resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH; |
| 262 | resource->flags |= IORESOURCE_BRIDGE; |
| 263 | } |
| 264 | |
| 265 | /* Initialize the memory constraints on the current bus */ |
| 266 | resource = amdfam16_find_mempair(dev, nodeid, link); |
| 267 | if (resource) { |
| 268 | resource->base = 0; |
| 269 | resource->size = 0; |
| 270 | resource->align = log2(HT_MEM_HOST_ALIGN); |
| 271 | resource->gran = log2(HT_MEM_HOST_ALIGN); |
| 272 | resource->limit = 0xffffffffffULL; |
| 273 | resource->flags = IORESOURCE_MEM | IORESOURCE_BRIDGE; |
| 274 | } |
| 275 | |
| 276 | } |
| 277 | |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 278 | static void read_resources(struct device *dev) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 279 | { |
| 280 | u32 nodeid; |
| 281 | struct bus *link; |
| 282 | |
| 283 | nodeid = amdfam16_nodeid(dev); |
| 284 | for (link = dev->link_list; link; link = link->next) { |
| 285 | if (link->children) { |
| 286 | amdfam16_link_read_bases(dev, nodeid, link->link_num); |
| 287 | } |
| 288 | } |
Edward O'Callaghan | 66c6532 | 2014-11-21 01:43:38 +1100 | [diff] [blame] | 289 | |
| 290 | /* |
| 291 | * This MMCONF resource must be reserved in the PCI_DOMAIN. |
| 292 | * It is not honored by the coreboot resource allocator if it is in |
| 293 | * the APIC_CLUSTER. |
| 294 | */ |
Elyes HAOUAS | 400ce55 | 2018-10-12 10:54:30 +0200 | [diff] [blame] | 295 | mmconf_resource(dev, MMIO_CONF_BASE); |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 296 | } |
| 297 | |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 298 | static void set_resource(struct device *dev, struct resource *resource, u32 nodeid) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 299 | { |
| 300 | resource_t rbase, rend; |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 301 | unsigned int reg, link_num; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 302 | char buf[50]; |
| 303 | |
| 304 | /* Make certain the resource has actually been set */ |
| 305 | if (!(resource->flags & IORESOURCE_ASSIGNED)) { |
| 306 | return; |
| 307 | } |
| 308 | |
| 309 | /* If I have already stored this resource don't worry about it */ |
| 310 | if (resource->flags & IORESOURCE_STORED) { |
| 311 | return; |
| 312 | } |
| 313 | |
| 314 | /* Only handle PCI memory and IO resources */ |
| 315 | if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO))) |
| 316 | return; |
| 317 | |
| 318 | /* Ensure I am actually looking at a resource of function 1 */ |
| 319 | if ((resource->index & 0xffff) < 0x1000) { |
| 320 | return; |
| 321 | } |
| 322 | /* Get the base address */ |
| 323 | rbase = resource->base; |
| 324 | |
| 325 | /* Get the limit (rounded up) */ |
| 326 | rend = resource_end(resource); |
| 327 | |
| 328 | /* Get the register and link */ |
| 329 | reg = resource->index & 0xfff; // 4k |
| 330 | link_num = IOINDEX_LINK(resource->index); |
| 331 | |
| 332 | if (resource->flags & IORESOURCE_IO) { |
| 333 | set_io_addr_reg(dev, nodeid, link_num, reg, rbase>>8, rend>>8); |
| 334 | } |
| 335 | else if (resource->flags & IORESOURCE_MEM) { |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 336 | set_mmio_addr_reg(nodeid, link_num, reg, (resource->index >>24), rbase>>8, rend>>8, node_nums);// [39:8] |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 337 | } |
| 338 | resource->flags |= IORESOURCE_STORED; |
Elyes HAOUAS | 0d4b11a | 2016-10-03 21:57:21 +0200 | [diff] [blame] | 339 | snprintf(buf, sizeof(buf), " <node %x link %x>", |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 340 | nodeid, link_num); |
| 341 | report_resource_stored(dev, resource, buf); |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * I tried to reuse the resource allocation code in set_resource() |
| 346 | * but it is too difficult to deal with the resource allocation magic. |
| 347 | */ |
| 348 | |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 349 | static void create_vga_resource(struct device *dev, unsigned int nodeid) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 350 | { |
| 351 | struct bus *link; |
| 352 | |
| 353 | /* find out which link the VGA card is connected, |
| 354 | * we only deal with the 'first' vga card */ |
| 355 | for (link = dev->link_list; link; link = link->next) { |
| 356 | if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) { |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 357 | #if CONFIG(MULTIPLE_VGA_ADAPTERS) |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 358 | extern struct device *vga_pri; // the primary vga device, defined in device.c |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 359 | printk(BIOS_DEBUG, "VGA: vga_pri bus num = %d bus range [%d,%d]\n", vga_pri->bus->secondary, |
| 360 | link->secondary,link->subordinate); |
| 361 | /* We need to make sure the vga_pri is under the link */ |
Elyes HAOUAS | 1d8daa6 | 2016-09-18 08:50:54 +0200 | [diff] [blame] | 362 | if ((vga_pri->bus->secondary >= link->secondary) && |
| 363 | (vga_pri->bus->secondary <= link->subordinate)) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 364 | #endif |
| 365 | break; |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | /* no VGA card installed */ |
| 370 | if (link == NULL) |
| 371 | return; |
| 372 | |
| 373 | printk(BIOS_DEBUG, "VGA: %s (aka node %d) link %d has VGA device\n", dev_path(dev), nodeid, sblink); |
| 374 | set_vga_enable_reg(nodeid, sblink); |
| 375 | } |
| 376 | |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 377 | static void set_resources(struct device *dev) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 378 | { |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 379 | unsigned int nodeid; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 380 | struct bus *bus; |
| 381 | struct resource *res; |
| 382 | |
| 383 | /* Find the nodeid */ |
| 384 | nodeid = amdfam16_nodeid(dev); |
| 385 | |
| 386 | create_vga_resource(dev, nodeid); //TODO: do we need this? |
| 387 | |
| 388 | /* Set each resource we have found */ |
| 389 | for (res = dev->resource_list; res; res = res->next) { |
| 390 | set_resource(dev, res, nodeid); |
| 391 | } |
| 392 | |
| 393 | for (bus = dev->link_list; bus; bus = bus->next) { |
| 394 | if (bus->children) { |
| 395 | assign_resources(bus); |
| 396 | } |
| 397 | } |
| 398 | } |
| 399 | |
Vladimir Serbinenko | 807127f | 2014-11-09 13:36:18 +0100 | [diff] [blame] | 400 | static unsigned long acpi_fill_hest(acpi_hest_t *hest) |
Vladimir Serbinenko | db09b062 | 2014-10-08 22:15:17 +0200 | [diff] [blame] | 401 | { |
| 402 | void *addr, *current; |
| 403 | |
| 404 | /* Skip the HEST header. */ |
| 405 | current = (void *)(hest + 1); |
| 406 | |
| 407 | addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE); |
| 408 | if (addr != NULL) |
Stefan Reinauer | 77a1d1a | 2015-07-21 12:48:17 -0700 | [diff] [blame] | 409 | current += acpi_create_hest_error_source(hest, current, 0, |
| 410 | addr + 2, *(UINT16 *)addr - 2); |
Vladimir Serbinenko | db09b062 | 2014-10-08 22:15:17 +0200 | [diff] [blame] | 411 | |
| 412 | addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC); |
| 413 | if (addr != NULL) |
Stefan Reinauer | 77a1d1a | 2015-07-21 12:48:17 -0700 | [diff] [blame] | 414 | current += acpi_create_hest_error_source(hest, current, 1, |
| 415 | addr + 2, *(UINT16 *)addr - 2); |
Vladimir Serbinenko | db09b062 | 2014-10-08 22:15:17 +0200 | [diff] [blame] | 416 | |
| 417 | return (unsigned long)current; |
| 418 | } |
| 419 | |
Furquan Shaikh | 7536a39 | 2020-04-24 21:59:21 -0700 | [diff] [blame] | 420 | static void northbridge_fill_ssdt_generator(const struct device *device) |
Vladimir Serbinenko | db09b062 | 2014-10-08 22:15:17 +0200 | [diff] [blame] | 421 | { |
| 422 | msr_t msr; |
| 423 | char pscope[] = "\\_SB.PCI0"; |
| 424 | |
| 425 | acpigen_write_scope(pscope); |
| 426 | msr = rdmsr(TOP_MEM); |
| 427 | acpigen_write_name_dword("TOM1", msr.lo); |
| 428 | msr = rdmsr(TOP_MEM2); |
| 429 | /* |
| 430 | * Since XP only implements parts of ACPI 2.0, we can't use a qword |
| 431 | * here. |
| 432 | * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt |
| 433 | * slide 22ff. |
| 434 | * Shift value right by 20 bit to make it fit into 32bit, |
| 435 | * giving us 1MB granularity and a limit of almost 4Exabyte of memory. |
| 436 | */ |
| 437 | acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20); |
| 438 | acpigen_pop_len(); |
| 439 | } |
| 440 | |
Michał Żygowski | 9550e97 | 2020-03-20 13:56:46 +0100 | [diff] [blame] | 441 | static void patch_ssdt_processor_scope(acpi_header_t *ssdt) |
| 442 | { |
| 443 | unsigned int len = ssdt->length - sizeof(acpi_header_t); |
| 444 | unsigned int i; |
| 445 | |
| 446 | for (i = sizeof(acpi_header_t); i < len; i++) { |
| 447 | /* Search for _PR_ scope and replace it with _SB_ */ |
| 448 | if (*(uint32_t *)((unsigned long)ssdt + i) == 0x5f52505f) |
| 449 | *(uint32_t *)((unsigned long)ssdt + i) = 0x5f42535f; |
| 450 | } |
| 451 | /* Recalculate checksum */ |
| 452 | ssdt->checksum = 0; |
| 453 | ssdt->checksum = acpi_checksum((void *)ssdt, ssdt->length); |
| 454 | } |
| 455 | |
Furquan Shaikh | 0f007d8 | 2020-04-24 06:41:18 -0700 | [diff] [blame] | 456 | static unsigned long agesa_write_acpi_tables(const struct device *device, |
Alexander Couzens | 83fc32f | 2015-04-12 22:28:37 +0200 | [diff] [blame] | 457 | unsigned long current, |
Vladimir Serbinenko | db09b062 | 2014-10-08 22:15:17 +0200 | [diff] [blame] | 458 | acpi_rsdp_t *rsdp) |
| 459 | { |
| 460 | acpi_srat_t *srat; |
| 461 | acpi_slit_t *slit; |
| 462 | acpi_header_t *ssdt; |
| 463 | acpi_header_t *alib; |
| 464 | acpi_header_t *ivrs; |
| 465 | acpi_hest_t *hest; |
| 466 | |
| 467 | /* HEST */ |
| 468 | current = ALIGN(current, 8); |
| 469 | hest = (acpi_hest_t *)current; |
Vladimir Serbinenko | 807127f | 2014-11-09 13:36:18 +0100 | [diff] [blame] | 470 | acpi_write_hest((void *)current, acpi_fill_hest); |
Vladimir Serbinenko | db09b062 | 2014-10-08 22:15:17 +0200 | [diff] [blame] | 471 | acpi_add_table(rsdp, (void *)current); |
| 472 | current += ((acpi_header_t *)current)->length; |
| 473 | |
| 474 | current = ALIGN(current, 8); |
| 475 | printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current); |
| 476 | ivrs = agesawrapper_getlateinitptr(PICK_IVRS); |
| 477 | if (ivrs != NULL) { |
| 478 | memcpy((void *)current, ivrs, ivrs->length); |
| 479 | ivrs = (acpi_header_t *) current; |
| 480 | current += ivrs->length; |
| 481 | acpi_add_table(rsdp, ivrs); |
| 482 | } else { |
| 483 | printk(BIOS_DEBUG, " AGESA IVRS table NULL. Skipping.\n"); |
| 484 | } |
| 485 | |
| 486 | /* SRAT */ |
| 487 | current = ALIGN(current, 8); |
| 488 | printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current); |
| 489 | srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT); |
| 490 | if (srat != NULL) { |
| 491 | memcpy((void *)current, srat, srat->header.length); |
| 492 | srat = (acpi_srat_t *) current; |
| 493 | current += srat->header.length; |
| 494 | acpi_add_table(rsdp, srat); |
| 495 | } else { |
| 496 | printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n"); |
| 497 | } |
| 498 | |
| 499 | /* SLIT */ |
| 500 | current = ALIGN(current, 8); |
| 501 | printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current); |
| 502 | slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT); |
| 503 | if (slit != NULL) { |
| 504 | memcpy((void *)current, slit, slit->header.length); |
| 505 | slit = (acpi_slit_t *) current; |
| 506 | current += slit->header.length; |
| 507 | acpi_add_table(rsdp, slit); |
| 508 | } else { |
| 509 | printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n"); |
| 510 | } |
| 511 | |
| 512 | /* ALIB */ |
| 513 | current = ALIGN(current, 16); |
| 514 | printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current); |
| 515 | alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB); |
| 516 | if (alib != NULL) { |
| 517 | memcpy((void *)current, alib, alib->length); |
| 518 | alib = (acpi_header_t *) current; |
| 519 | current += alib->length; |
| 520 | acpi_add_table(rsdp, (void *)alib); |
| 521 | } |
| 522 | else { |
| 523 | printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n"); |
| 524 | } |
| 525 | |
| 526 | /* this pstate ssdt may cause Blue Screen: Fixed: Keep this comment for a while. */ |
| 527 | /* SSDT */ |
| 528 | current = ALIGN(current, 16); |
| 529 | printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current); |
| 530 | ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE); |
| 531 | if (ssdt != NULL) { |
Michał Żygowski | 9550e97 | 2020-03-20 13:56:46 +0100 | [diff] [blame] | 532 | patch_ssdt_processor_scope(ssdt); |
Vladimir Serbinenko | db09b062 | 2014-10-08 22:15:17 +0200 | [diff] [blame] | 533 | memcpy((void *)current, ssdt, ssdt->length); |
| 534 | ssdt = (acpi_header_t *) current; |
| 535 | current += ssdt->length; |
| 536 | } |
| 537 | else { |
| 538 | printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n"); |
| 539 | } |
| 540 | acpi_add_table(rsdp,ssdt); |
| 541 | |
| 542 | printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current); |
| 543 | |
| 544 | return current; |
| 545 | } |
| 546 | |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 547 | static struct device_operations northbridge_operations = { |
| 548 | .read_resources = read_resources, |
| 549 | .set_resources = set_resources, |
| 550 | .enable_resources = pci_dev_enable_resources, |
Nico Huber | 68680dd | 2020-03-31 17:34:52 +0200 | [diff] [blame] | 551 | .acpi_fill_ssdt = northbridge_fill_ssdt_generator, |
Vladimir Serbinenko | db09b062 | 2014-10-08 22:15:17 +0200 | [diff] [blame] | 552 | .write_acpi_tables = agesa_write_acpi_tables, |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 553 | }; |
| 554 | |
| 555 | static const struct pci_driver family16_northbridge __pci_driver = { |
| 556 | .ops = &northbridge_operations, |
| 557 | .vendor = PCI_VENDOR_ID_AMD, |
| 558 | .device = PCI_DEVICE_ID_AMD_16H_MODEL_000F_NB_HT, |
| 559 | }; |
| 560 | |
| 561 | static const struct pci_driver family10_northbridge __pci_driver = { |
| 562 | .ops = &northbridge_operations, |
| 563 | .vendor = PCI_VENDOR_ID_AMD, |
| 564 | .device = PCI_DEVICE_ID_AMD_10H_NB_HT, |
| 565 | }; |
| 566 | |
Kyösti Mälkki | 4ee82c6 | 2014-11-25 16:03:12 +0200 | [diff] [blame] | 567 | static void fam16_finalize(void *chip_info) |
| 568 | { |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 569 | struct device *dev; |
Kyösti Mälkki | 4ee82c6 | 2014-11-25 16:03:12 +0200 | [diff] [blame] | 570 | u32 value; |
Kyösti Mälkki | 4ad7f5b | 2018-05-22 01:15:17 +0300 | [diff] [blame] | 571 | dev = pcidev_on_root(0, 0); /* clear IoapicSbFeatureEn */ |
Kyösti Mälkki | 4ee82c6 | 2014-11-25 16:03:12 +0200 | [diff] [blame] | 572 | pci_write_config32(dev, 0xF8, 0); |
| 573 | pci_write_config32(dev, 0xFC, 5); /* TODO: move it to dsdt.asl */ |
| 574 | |
| 575 | /* disable No Snoop */ |
Kyösti Mälkki | 4ad7f5b | 2018-05-22 01:15:17 +0300 | [diff] [blame] | 576 | dev = pcidev_on_root(1, 1); |
Kyösti Mälkki | 69f6fd4 | 2019-01-21 14:19:01 +0200 | [diff] [blame] | 577 | if (dev != NULL) { |
| 578 | value = pci_read_config32(dev, 0x60); |
| 579 | value &= ~(1 << 11); |
| 580 | pci_write_config32(dev, 0x60, value); |
| 581 | } |
Kyösti Mälkki | 4ee82c6 | 2014-11-25 16:03:12 +0200 | [diff] [blame] | 582 | } |
| 583 | |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 584 | struct chip_operations northbridge_amd_agesa_family16kb_ops = { |
| 585 | CHIP_NAME("AMD FAM16 Northbridge") |
| 586 | .enable_dev = 0, |
Kyösti Mälkki | 4ee82c6 | 2014-11-25 16:03:12 +0200 | [diff] [blame] | 587 | .final = fam16_finalize, |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 588 | }; |
| 589 | |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 590 | static void domain_read_resources(struct device *dev) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 591 | { |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 592 | unsigned int reg; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 593 | |
| 594 | /* Find the already assigned resource pairs */ |
| 595 | get_fx_devs(); |
| 596 | for (reg = 0x80; reg <= 0xd8; reg+= 0x08) { |
| 597 | u32 base, limit; |
| 598 | base = f1_read_config32(reg); |
| 599 | limit = f1_read_config32(reg + 0x04); |
| 600 | /* Is this register allocated? */ |
| 601 | if ((base & 3) != 0) { |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 602 | unsigned int nodeid, reg_link; |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 603 | struct device *reg_dev; |
Elyes HAOUAS | 1d8daa6 | 2016-09-18 08:50:54 +0200 | [diff] [blame] | 604 | if (reg < 0xc0) { // mmio |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 605 | nodeid = (limit & 0xf) + (base&0x30); |
| 606 | } else { // io |
| 607 | nodeid = (limit & 0xf) + ((base>>4)&0x30); |
| 608 | } |
| 609 | reg_link = (limit >> 4) & 7; |
| 610 | reg_dev = __f0_dev[nodeid]; |
| 611 | if (reg_dev) { |
| 612 | /* Reserve the resource */ |
| 613 | struct resource *res; |
| 614 | res = new_resource(reg_dev, IOINDEX(0x1000 + reg, reg_link)); |
| 615 | if (res) { |
| 616 | res->flags = 1; |
| 617 | } |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | /* FIXME: do we need to check extend conf space? |
| 622 | I don't believe that much preset value */ |
| 623 | |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 624 | pci_domain_read_resources(dev); |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 625 | } |
| 626 | |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 627 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
| 628 | struct hw_mem_hole_info { |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 629 | unsigned int hole_startk; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 630 | int node_id; |
| 631 | }; |
| 632 | static struct hw_mem_hole_info get_hw_mem_hole_info(void) |
| 633 | { |
| 634 | struct hw_mem_hole_info mem_hole; |
| 635 | int i; |
| 636 | mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK; |
| 637 | mem_hole.node_id = -1; |
| 638 | for (i = 0; i < node_nums; i++) { |
| 639 | dram_base_mask_t d; |
| 640 | u32 hole; |
| 641 | d = get_dram_base_mask(i); |
| 642 | if (!(d.mask & 1)) continue; // no memory on this node |
| 643 | hole = pci_read_config32(__f1_dev[i], 0xf0); |
| 644 | if (hole & 2) { // we find the hole |
Elyes HAOUAS | 27e1801 | 2017-06-27 23:14:51 +0200 | [diff] [blame] | 645 | mem_hole.hole_startk = (hole & (0xff << 24)) >> 10; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 646 | mem_hole.node_id = i; // record the node No with hole |
| 647 | break; // only one hole |
| 648 | } |
| 649 | } |
Kyösti Mälkki | 2f9b3af | 2014-06-26 05:30:54 +0300 | [diff] [blame] | 650 | |
| 651 | /* We need to double check if there is special set on base reg and limit reg |
| 652 | * are not continuous instead of hole, it will find out its hole_startk. |
| 653 | */ |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 654 | if (mem_hole.node_id == -1) { |
| 655 | resource_t limitk_pri = 0; |
Elyes HAOUAS | 1d8daa6 | 2016-09-18 08:50:54 +0200 | [diff] [blame] | 656 | for (i = 0; i < node_nums; i++) { |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 657 | dram_base_mask_t d; |
| 658 | resource_t base_k, limit_k; |
| 659 | d = get_dram_base_mask(i); |
| 660 | if (!(d.base & 1)) continue; |
| 661 | base_k = ((resource_t)(d.base & 0x1fffff00)) <<9; |
| 662 | if (base_k > 4 *1024 * 1024) break; // don't need to go to check |
| 663 | if (limitk_pri != base_k) { // we find the hole |
Martin Roth | 468d02c | 2019-10-23 21:44:42 -0600 | [diff] [blame] | 664 | mem_hole.hole_startk = (unsigned int)limitk_pri; // must beblow 4G |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 665 | mem_hole.node_id = i; |
| 666 | break; //only one hole |
| 667 | } |
| 668 | limit_k = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9; |
| 669 | limitk_pri = limit_k; |
| 670 | } |
| 671 | } |
| 672 | return mem_hole; |
| 673 | } |
| 674 | #endif |
| 675 | |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 676 | static void domain_set_resources(struct device *dev) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 677 | { |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 678 | unsigned long mmio_basek; |
| 679 | u32 pci_tolm; |
| 680 | int i, idx; |
| 681 | struct bus *link; |
| 682 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
| 683 | struct hw_mem_hole_info mem_hole; |
| 684 | u32 reset_memhole = 1; |
| 685 | #endif |
| 686 | |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 687 | pci_tolm = 0xffffffffUL; |
| 688 | for (link = dev->link_list; link; link = link->next) { |
| 689 | pci_tolm = find_pci_tolm(link); |
| 690 | } |
| 691 | |
| 692 | // FIXME handle interleaved nodes. If you fix this here, please fix |
| 693 | // amdk8, too. |
| 694 | mmio_basek = pci_tolm >> 10; |
| 695 | /* Round mmio_basek to something the processor can support */ |
| 696 | mmio_basek &= ~((1 << 6) -1); |
| 697 | |
| 698 | // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M |
| 699 | // MMIO hole. If you fix this here, please fix amdk8, too. |
| 700 | /* Round the mmio hole to 64M */ |
| 701 | mmio_basek &= ~((64*1024) - 1); |
| 702 | |
| 703 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
| 704 | /* if the hw mem hole is already set in raminit stage, here we will compare |
| 705 | * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will |
| 706 | * use hole_basek as mmio_basek and we don't need to reset hole. |
| 707 | * otherwise We reset the hole to the mmio_basek |
| 708 | */ |
| 709 | |
| 710 | mem_hole = get_hw_mem_hole_info(); |
| 711 | |
| 712 | // Use hole_basek as mmio_basek, and we don't need to reset hole anymore |
| 713 | if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) { |
| 714 | mmio_basek = mem_hole.hole_startk; |
| 715 | reset_memhole = 0; |
| 716 | } |
| 717 | #endif |
| 718 | |
| 719 | idx = 0x10; |
| 720 | for (i = 0; i < node_nums; i++) { |
| 721 | dram_base_mask_t d; |
| 722 | resource_t basek, limitk, sizek; // 4 1T |
| 723 | |
| 724 | d = get_dram_base_mask(i); |
| 725 | |
| 726 | if (!(d.mask & 1)) continue; |
| 727 | basek = ((resource_t)(d.base & 0x1fffff00)) << 9; // could overflow, we may lost 6 bit here |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 728 | limitk = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 729 | |
| 730 | sizek = limitk - basek; |
| 731 | |
| 732 | /* see if we need a hole from 0xa0000 to 0xbffff */ |
| 733 | if ((basek < ((8*64)+(8*16))) && (sizek > ((8*64)+(16*16)))) { |
| 734 | ram_resource(dev, (idx | i), basek, ((8*64)+(8*16)) - basek); |
| 735 | idx += 0x10; |
| 736 | basek = (8*64)+(16*16); |
| 737 | sizek = limitk - ((8*64)+(16*16)); |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 738 | } |
| 739 | |
| 740 | //printk(BIOS_DEBUG, "node %d : mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", i, mmio_basek, basek, limitk); |
| 741 | |
Kyösti Mälkki | 26c6543 | 2014-06-26 05:30:54 +0300 | [diff] [blame] | 742 | /* split the region to accommodate pci memory space */ |
Elyes HAOUAS | 1d8daa6 | 2016-09-18 08:50:54 +0200 | [diff] [blame] | 743 | if ((basek < 4*1024*1024) && (limitk > mmio_basek)) { |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 744 | if (basek <= mmio_basek) { |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 745 | unsigned int pre_sizek; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 746 | pre_sizek = mmio_basek - basek; |
Elyes HAOUAS | 1d8daa6 | 2016-09-18 08:50:54 +0200 | [diff] [blame] | 747 | if (pre_sizek > 0) { |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 748 | ram_resource(dev, (idx | i), basek, pre_sizek); |
| 749 | idx += 0x10; |
| 750 | sizek -= pre_sizek; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 751 | } |
| 752 | basek = mmio_basek; |
| 753 | } |
| 754 | if ((basek + sizek) <= 4*1024*1024) { |
| 755 | sizek = 0; |
| 756 | } |
| 757 | else { |
| 758 | uint64_t topmem2 = bsp_topmem2(); |
| 759 | basek = 4*1024*1024; |
| 760 | sizek = topmem2/1024 - basek; |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | ram_resource(dev, (idx | i), basek, sizek); |
| 765 | idx += 0x10; |
| 766 | printk(BIOS_DEBUG, "node %d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", |
| 767 | i, mmio_basek, basek, limitk); |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 768 | } |
| 769 | |
Kyösti Mälkki | 61be360 | 2017-04-15 20:07:53 +0300 | [diff] [blame] | 770 | add_uma_resource_below_tolm(dev, 7); |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 771 | |
Elyes HAOUAS | 5a7e72f | 2016-08-23 21:36:02 +0200 | [diff] [blame] | 772 | for (link = dev->link_list; link; link = link->next) { |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 773 | if (link->children) { |
| 774 | assign_resources(link); |
| 775 | } |
| 776 | } |
| 777 | } |
| 778 | |
Kevin Cody-Little | 06d2323 | 2018-05-09 14:22:15 -0400 | [diff] [blame] | 779 | static const char *domain_acpi_name(const struct device *dev) |
| 780 | { |
| 781 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
| 782 | return "PCI0"; |
| 783 | |
| 784 | return NULL; |
| 785 | } |
| 786 | |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 787 | static struct device_operations pci_domain_ops = { |
| 788 | .read_resources = domain_read_resources, |
| 789 | .set_resources = domain_set_resources, |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 790 | .scan_bus = pci_domain_scan_bus, |
Kevin Cody-Little | 06d2323 | 2018-05-09 14:22:15 -0400 | [diff] [blame] | 791 | .acpi_name = domain_acpi_name, |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 792 | }; |
| 793 | |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 794 | static void sysconf_init(struct device *dev) // first node |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 795 | { |
| 796 | sblink = (pci_read_config32(dev, 0x64)>>8) & 7; // don't forget sublink1 |
| 797 | node_nums = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; //NodeCnt[2:0] |
| 798 | } |
| 799 | |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 800 | static void cpu_bus_scan(struct device *dev) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 801 | { |
| 802 | struct bus *cpu_bus; |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 803 | struct device *dev_mc; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 804 | int i,j; |
| 805 | int coreid_bits; |
| 806 | int core_max = 0; |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 807 | unsigned int ApicIdCoreIdSize; |
| 808 | unsigned int core_nums; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 809 | int siblings = 0; |
| 810 | unsigned int family; |
| 811 | |
Kyösti Mälkki | 3d3152e | 2019-01-10 09:05:30 +0200 | [diff] [blame] | 812 | dev_mc = pcidev_on_root(DEV_CDB, 0); |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 813 | if (!dev_mc) { |
Kyösti Mälkki | 3d3152e | 2019-01-10 09:05:30 +0200 | [diff] [blame] | 814 | printk(BIOS_ERR, "0:%02x.0 not found", DEV_CDB); |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 815 | die(""); |
| 816 | } |
| 817 | sysconf_init(dev_mc); |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 818 | |
| 819 | /* Get Max Number of cores(MNC) */ |
Kyösti Mälkki | d41feed | 2017-09-24 16:23:57 +0300 | [diff] [blame] | 820 | coreid_bits = (cpuid_ecx(0x80000008) & 0x0000F000) >> 12; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 821 | core_max = 1 << (coreid_bits & 0x000F); //mnc |
| 822 | |
| 823 | ApicIdCoreIdSize = ((cpuid_ecx(0x80000008)>>12) & 0xF); |
| 824 | if (ApicIdCoreIdSize) { |
| 825 | core_nums = (1 << ApicIdCoreIdSize) - 1; |
| 826 | } else { |
| 827 | core_nums = 3; //quad core |
| 828 | } |
| 829 | |
| 830 | /* Find which cpus are present */ |
| 831 | cpu_bus = dev->link_list; |
| 832 | for (i = 0; i < node_nums; i++) { |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 833 | struct device *cdb_dev; |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 834 | unsigned int devn; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 835 | struct bus *pbus; |
| 836 | |
Kyösti Mälkki | 3d3152e | 2019-01-10 09:05:30 +0200 | [diff] [blame] | 837 | devn = DEV_CDB + i; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 838 | pbus = dev_mc->bus; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 839 | |
| 840 | /* Find the cpu's pci device */ |
Kyösti Mälkki | 4ad7f5b | 2018-05-22 01:15:17 +0300 | [diff] [blame] | 841 | cdb_dev = pcidev_on_root(devn, 0); |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 842 | if (!cdb_dev) { |
| 843 | /* If I am probing things in a weird order |
| 844 | * ensure all of the cpu's pci devices are found. |
| 845 | */ |
| 846 | int fn; |
Elyes HAOUAS | 5a7e72f | 2016-08-23 21:36:02 +0200 | [diff] [blame] | 847 | for (fn = 0; fn <= 5; fn++) { //FBDIMM? |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 848 | cdb_dev = pci_probe_dev(NULL, pbus, |
| 849 | PCI_DEVFN(devn, fn)); |
| 850 | } |
Kyösti Mälkki | 4ad7f5b | 2018-05-22 01:15:17 +0300 | [diff] [blame] | 851 | cdb_dev = pcidev_on_root(devn, 0); |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 852 | } else { |
| 853 | /* Ok, We need to set the links for that device. |
| 854 | * otherwise the device under it will not be scanned |
| 855 | */ |
Kyösti Mälkki | 2a2d613 | 2015-02-04 13:25:37 +0200 | [diff] [blame] | 856 | add_more_links(cdb_dev, 4); |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | family = cpuid_eax(1); |
| 860 | family = (family >> 20) & 0xFF; |
| 861 | if (family == 1) { //f10 |
| 862 | u32 dword; |
Kyösti Mälkki | 4ad7f5b | 2018-05-22 01:15:17 +0300 | [diff] [blame] | 863 | cdb_dev = pcidev_on_root(devn, 3); |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 864 | dword = pci_read_config32(cdb_dev, 0xe8); |
| 865 | siblings = ((dword & BIT15) >> 13) | ((dword & (BIT13 | BIT12)) >> 12); |
| 866 | } else if (family == 7) {//f16 |
Kyösti Mälkki | 4ad7f5b | 2018-05-22 01:15:17 +0300 | [diff] [blame] | 867 | cdb_dev = pcidev_on_root(devn, 5); |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 868 | if (cdb_dev && cdb_dev->enabled) { |
| 869 | siblings = pci_read_config32(cdb_dev, 0x84); |
| 870 | siblings &= 0xFF; |
| 871 | } |
| 872 | } else { |
| 873 | siblings = 0; //default one core |
| 874 | } |
| 875 | int enable_node = cdb_dev && cdb_dev->enabled; |
| 876 | printk(BIOS_SPEW, "%s family%xh, core_max=0x%x, core_nums=0x%x, siblings=0x%x\n", |
| 877 | dev_path(cdb_dev), 0x0f + family, core_max, core_nums, siblings); |
| 878 | |
Elyes HAOUAS | 1d8daa6 | 2016-09-18 08:50:54 +0200 | [diff] [blame] | 879 | for (j = 0; j <= siblings; j++) { |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 880 | extern CONST OPTIONS_CONFIG_TOPOLOGY ROMDATA TopologyConfiguration; |
| 881 | u32 modules = TopologyConfiguration.PlatformNumberOfModules; |
| 882 | u32 lapicid_start = 0; |
| 883 | |
| 884 | /* |
| 885 | * APIC ID calucation is tightly coupled with AGESA v5 code. |
| 886 | * This calculation MUST match the assignment calculation done |
| 887 | * in LocalApicInitializationAtEarly() function. |
| 888 | * And reference GetLocalApicIdForCore() |
| 889 | * |
Elyes HAOUAS | a5b0bc4 | 2020-02-20 20:04:29 +0100 | [diff] [blame] | 890 | * Apply APIC enumeration rules |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 891 | * For systems with >= 16 APICs, put the IO-APICs at 0..n and |
| 892 | * put the local-APICs at m..z |
| 893 | * |
| 894 | * This is needed because many IO-APIC devices only have 4 bits |
| 895 | * for their APIC id and therefore must reside at 0..15 |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 896 | */ |
Kyösti Mälkki | 5003632 | 2016-05-18 13:35:21 +0300 | [diff] [blame] | 897 | |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 898 | u8 plat_num_io_apics = 3; /* FIXME */ |
Kyösti Mälkki | 5003632 | 2016-05-18 13:35:21 +0300 | [diff] [blame] | 899 | |
| 900 | if ((node_nums * core_max) + plat_num_io_apics >= 0x10) { |
| 901 | lapicid_start = (plat_num_io_apics - 1) / core_max; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 902 | lapicid_start = (lapicid_start + 1) * core_max; |
| 903 | printk(BIOS_SPEW, "lpaicid_start=0x%x ", lapicid_start); |
| 904 | } |
| 905 | u32 apic_id = (lapicid_start * (i/modules + 1)) + ((i % modules) ? (j + (siblings + 1)) : j); |
| 906 | printk(BIOS_SPEW, "node 0x%x core 0x%x apicid=0x%x\n", |
| 907 | i, j, apic_id); |
| 908 | |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 909 | struct device *cpu = add_cpu_device(cpu_bus, apic_id, enable_node); |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 910 | if (cpu) |
| 911 | amd_cpu_topology(cpu, i, j); |
| 912 | } //j |
| 913 | } |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 914 | } |
| 915 | |
Kyösti Mälkki | e2c2a4c | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 916 | static void cpu_bus_init(struct device *dev) |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 917 | { |
| 918 | initialize_cpus(dev->link_list); |
| 919 | } |
| 920 | |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 921 | static struct device_operations cpu_bus_ops = { |
Nico Huber | 2f8ba69 | 2020-04-05 14:05:24 +0200 | [diff] [blame] | 922 | .read_resources = noop_read_resources, |
| 923 | .set_resources = noop_set_resources, |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 924 | .init = cpu_bus_init, |
| 925 | .scan_bus = cpu_bus_scan, |
| 926 | }; |
| 927 | |
| 928 | static void root_complex_enable_dev(struct device *dev) |
| 929 | { |
| 930 | static int done = 0; |
| 931 | |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 932 | if (!done) { |
| 933 | setup_bsp_ramtop(); |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 934 | done = 1; |
| 935 | } |
| 936 | |
| 937 | /* Set the operations if it is a special bus type */ |
| 938 | if (dev->path.type == DEVICE_PATH_DOMAIN) { |
| 939 | dev->ops = &pci_domain_ops; |
| 940 | } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) { |
| 941 | dev->ops = &cpu_bus_ops; |
| 942 | } |
| 943 | } |
| 944 | |
| 945 | struct chip_operations northbridge_amd_agesa_family16kb_root_complex_ops = { |
| 946 | CHIP_NAME("AMD FAM16 Root Complex") |
| 947 | .enable_dev = root_complex_enable_dev, |
| 948 | }; |
Bruce Griffith | 76db07e | 2013-07-07 02:06:53 -0600 | [diff] [blame] | 949 | |
| 950 | /********************************************************************* |
| 951 | * Change the vendor / device IDs to match the generic VBIOS header. * |
| 952 | *********************************************************************/ |
| 953 | u32 map_oprom_vendev(u32 vendev) |
| 954 | { |
| 955 | u32 new_vendev = vendev; |
| 956 | |
Elyes HAOUAS | 0ce41f1 | 2018-11-13 10:03:31 +0100 | [diff] [blame] | 957 | switch (vendev) { |
Bruce Griffith | 76db07e | 2013-07-07 02:06:53 -0600 | [diff] [blame] | 958 | case 0x10029830: |
| 959 | case 0x10029831: |
| 960 | case 0x10029832: |
| 961 | case 0x10029833: |
| 962 | case 0x10029834: |
| 963 | case 0x10029835: |
| 964 | case 0x10029836: |
| 965 | case 0x10029837: |
| 966 | case 0x10029838: |
| 967 | case 0x10029839: |
| 968 | case 0x1002983A: |
| 969 | case 0x1002983D: |
| 970 | new_vendev = 0x10029830; // This is the default value in AMD-generated VBIOS |
| 971 | break; |
| 972 | default: |
| 973 | break; |
| 974 | } |
| 975 | |
| 976 | if (vendev != new_vendev) |
| 977 | printk(BIOS_NOTICE, "Mapping PCI device %8x to %8x\n", vendev, new_vendev); |
| 978 | |
| 979 | return new_vendev; |
| 980 | } |