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