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. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #include <console/console.h> |
| 21 | #include <arch/io.h> |
Kyösti Mälkki | 8ae16a4 | 2014-06-19 20:44:34 +0300 | [diff] [blame] | 22 | #include <arch/acpi.h> |
Vladimir Serbinenko | db09b062 | 2014-10-08 22:15:17 +0200 | [diff] [blame] | 23 | #include <arch/acpigen.h> |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 24 | #include <stdint.h> |
| 25 | #include <device/device.h> |
| 26 | #include <device/pci.h> |
| 27 | #include <device/pci_ids.h> |
| 28 | #include <device/hypertransport.h> |
| 29 | #include <stdlib.h> |
| 30 | #include <string.h> |
| 31 | #include <lib.h> |
| 32 | #include <cpu/cpu.h> |
| 33 | #include <cbmem.h> |
| 34 | |
| 35 | #include <cpu/x86/lapic.h> |
| 36 | #include <cpu/amd/mtrr.h> |
| 37 | |
| 38 | #include <Porting.h> |
| 39 | #include <AGESA.h> |
| 40 | #include <Options.h> |
| 41 | #include <Topology.h> |
| 42 | #include <cpu/amd/amdfam16.h> |
| 43 | #include <cpuRegisters.h> |
Kyösti Mälkki | f21c2ac | 2014-10-19 09:35:18 +0300 | [diff] [blame^] | 44 | #include <northbridge/amd/agesa/agesawrapper.h> |
Kyösti Mälkki | 7b23ae0 | 2014-07-04 16:14:37 +0300 | [diff] [blame] | 45 | #include <northbridge/amd/agesa/agesawrapper_call.h> |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 46 | |
| 47 | #define MAX_NODE_NUMS (MAX_NODES * MAX_DIES) |
| 48 | |
| 49 | #if (defined CONFIG_EXT_CONF_SUPPORT) && CONFIG_EXT_CONF_SUPPORT == 1 |
| 50 | #error CONFIG_EXT_CONF_SUPPORT == 1 not support anymore! |
| 51 | #endif |
| 52 | |
| 53 | typedef struct dram_base_mask { |
| 54 | u32 base; //[47:27] at [28:8] |
| 55 | u32 mask; //[47:27] at [28:8] and enable at bit 0 |
| 56 | } dram_base_mask_t; |
| 57 | |
| 58 | static unsigned node_nums; |
| 59 | static unsigned sblink; |
| 60 | static device_t __f0_dev[MAX_NODE_NUMS]; |
| 61 | static device_t __f1_dev[MAX_NODE_NUMS]; |
| 62 | static device_t __f2_dev[MAX_NODE_NUMS]; |
| 63 | static device_t __f4_dev[MAX_NODE_NUMS]; |
| 64 | static unsigned fx_devs = 0; |
| 65 | |
| 66 | static dram_base_mask_t get_dram_base_mask(u32 nodeid) |
| 67 | { |
| 68 | device_t dev; |
| 69 | dram_base_mask_t d; |
| 70 | dev = __f1_dev[0]; |
| 71 | u32 temp; |
| 72 | temp = pci_read_config32(dev, 0x44 + (nodeid << 3)); //[39:24] at [31:16] |
| 73 | d.mask = ((temp & 0xfff80000)>>(8+3)); // mask out DramMask [26:24] too |
| 74 | temp = pci_read_config32(dev, 0x144 + (nodeid <<3)) & 0xff; //[47:40] at [7:0] |
| 75 | d.mask |= temp<<21; |
| 76 | temp = pci_read_config32(dev, 0x40 + (nodeid << 3)); //[39:24] at [31:16] |
| 77 | d.mask |= (temp & 1); // enable bit |
| 78 | d.base = ((temp & 0xfff80000)>>(8+3)); // mask out DramBase [26:24) too |
| 79 | temp = pci_read_config32(dev, 0x140 + (nodeid <<3)) & 0xff; //[47:40] at [7:0] |
| 80 | d.base |= temp<<21; |
| 81 | return d; |
| 82 | } |
| 83 | |
| 84 | static void set_io_addr_reg(device_t dev, u32 nodeid, u32 linkn, u32 reg, |
| 85 | u32 io_min, u32 io_max) |
| 86 | { |
| 87 | u32 i; |
| 88 | u32 tempreg; |
| 89 | /* io range allocation */ |
| 90 | tempreg = (nodeid&0xf) | ((nodeid & 0x30)<<(8-4)) | (linkn<<4) | ((io_max&0xf0)<<(12-4)); //limit |
| 91 | for (i=0; i<node_nums; i++) |
| 92 | pci_write_config32(__f1_dev[i], reg+4, tempreg); |
| 93 | tempreg = 3 /*| ( 3<<4)*/ | ((io_min&0xf0)<<(12-4)); //base :ISA and VGA ? |
| 94 | #if 0 |
| 95 | // FIXME: can we use VGA reg instead? |
| 96 | if (dev->link[link].bridge_ctrl & PCI_BRIDGE_CTL_VGA) { |
| 97 | printk(BIOS_SPEW, "%s, enabling legacy VGA IO forwarding for %s link %s\n", |
| 98 | __func__, dev_path(dev), link); |
| 99 | tempreg |= PCI_IO_BASE_VGA_EN; |
| 100 | } |
| 101 | if (dev->link[link].bridge_ctrl & PCI_BRIDGE_CTL_NO_ISA) { |
| 102 | tempreg |= PCI_IO_BASE_NO_ISA; |
| 103 | } |
| 104 | #endif |
| 105 | for (i=0; i<node_nums; i++) |
| 106 | pci_write_config32(__f1_dev[i], reg, tempreg); |
| 107 | } |
| 108 | |
| 109 | static void set_mmio_addr_reg(u32 nodeid, u32 linkn, u32 reg, u32 index, u32 mmio_min, u32 mmio_max, u32 nodes) |
| 110 | { |
| 111 | u32 i; |
| 112 | u32 tempreg; |
| 113 | /* io range allocation */ |
| 114 | tempreg = (nodeid&0xf) | (linkn<<4) | (mmio_max&0xffffff00); //limit |
| 115 | for (i=0; i<nodes; i++) |
| 116 | pci_write_config32(__f1_dev[i], reg+4, tempreg); |
| 117 | tempreg = 3 | (nodeid & 0x30) | (mmio_min&0xffffff00); |
| 118 | for (i=0; i<node_nums; i++) |
| 119 | pci_write_config32(__f1_dev[i], reg, tempreg); |
| 120 | } |
| 121 | |
| 122 | static device_t get_node_pci(u32 nodeid, u32 fn) |
| 123 | { |
| 124 | #if MAX_NODE_NUMS + CONFIG_CDB >= 32 |
| 125 | if ((CONFIG_CDB + nodeid) < 32) { |
| 126 | return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn)); |
| 127 | } else { |
| 128 | return dev_find_slot(CONFIG_CBB-1, PCI_DEVFN(CONFIG_CDB + nodeid - 32, fn)); |
| 129 | } |
| 130 | #else |
| 131 | return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn)); |
| 132 | #endif |
| 133 | } |
| 134 | |
| 135 | static void get_fx_devs(void) |
| 136 | { |
| 137 | int i; |
| 138 | for (i = 0; i < MAX_NODE_NUMS; i++) { |
| 139 | __f0_dev[i] = get_node_pci(i, 0); |
| 140 | __f1_dev[i] = get_node_pci(i, 1); |
| 141 | __f2_dev[i] = get_node_pci(i, 2); |
| 142 | __f4_dev[i] = get_node_pci(i, 4); |
| 143 | if (__f0_dev[i] != NULL && __f1_dev[i] != NULL) |
| 144 | fx_devs = i+1; |
| 145 | } |
| 146 | if (__f1_dev[0] == NULL || __f0_dev[0] == NULL || fx_devs == 0) { |
| 147 | die("Cannot find 0:0x18.[0|1]\n"); |
| 148 | } |
| 149 | printk(BIOS_DEBUG, "fx_devs=0x%x\n", fx_devs); |
| 150 | } |
| 151 | |
| 152 | static u32 f1_read_config32(unsigned reg) |
| 153 | { |
| 154 | if (fx_devs == 0) |
| 155 | get_fx_devs(); |
| 156 | return pci_read_config32(__f1_dev[0], reg); |
| 157 | } |
| 158 | |
| 159 | static void f1_write_config32(unsigned reg, u32 value) |
| 160 | { |
| 161 | int i; |
| 162 | if (fx_devs == 0) |
| 163 | get_fx_devs(); |
| 164 | for(i = 0; i < fx_devs; i++) { |
| 165 | device_t dev; |
| 166 | dev = __f1_dev[i]; |
| 167 | if (dev && dev->enabled) { |
| 168 | pci_write_config32(dev, reg, value); |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | static u32 amdfam16_nodeid(device_t dev) |
| 174 | { |
| 175 | #if MAX_NODE_NUMS == 64 |
| 176 | unsigned busn; |
| 177 | busn = dev->bus->secondary; |
| 178 | if (busn != CONFIG_CBB) { |
| 179 | return (dev->path.pci.devfn >> 3) - CONFIG_CDB + 32; |
| 180 | } else { |
| 181 | return (dev->path.pci.devfn >> 3) - CONFIG_CDB; |
| 182 | } |
| 183 | |
| 184 | #else |
| 185 | return (dev->path.pci.devfn >> 3) - CONFIG_CDB; |
| 186 | #endif |
| 187 | } |
| 188 | |
| 189 | static void set_vga_enable_reg(u32 nodeid, u32 linkn) |
| 190 | { |
| 191 | u32 val; |
| 192 | |
| 193 | val = 1 | (nodeid<<4) | (linkn<<12); |
| 194 | /* it will routing |
| 195 | * (1)mmio 0xa0000:0xbffff |
| 196 | * (2)io 0x3b0:0x3bb, 0x3c0:0x3df |
| 197 | */ |
| 198 | f1_write_config32(0xf4, val); |
| 199 | |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * @return |
| 204 | * @retval 2 resoure does not exist, usable |
| 205 | * @retval 0 resource exists, not usable |
| 206 | * @retval 1 resource exist, resource has been allocated before |
| 207 | */ |
| 208 | static int reg_useable(unsigned reg, device_t goal_dev, unsigned goal_nodeid, |
| 209 | unsigned goal_link) |
| 210 | { |
| 211 | struct resource *res; |
| 212 | unsigned nodeid, link = 0; |
| 213 | int result; |
| 214 | res = 0; |
| 215 | for (nodeid = 0; !res && (nodeid < fx_devs); nodeid++) { |
| 216 | device_t dev; |
| 217 | dev = __f0_dev[nodeid]; |
| 218 | if (!dev) |
| 219 | continue; |
| 220 | for (link = 0; !res && (link < 8); link++) { |
| 221 | res = probe_resource(dev, IOINDEX(0x1000 + reg, link)); |
| 222 | } |
| 223 | } |
| 224 | result = 2; |
| 225 | if (res) { |
| 226 | result = 0; |
| 227 | if ((goal_link == (link - 1)) && |
| 228 | (goal_nodeid == (nodeid - 1)) && |
| 229 | (res->flags <= 1)) { |
| 230 | result = 1; |
| 231 | } |
| 232 | } |
| 233 | return result; |
| 234 | } |
| 235 | |
| 236 | static struct resource *amdfam16_find_iopair(device_t dev, unsigned nodeid, unsigned link) |
| 237 | { |
| 238 | struct resource *resource; |
| 239 | u32 free_reg, reg; |
| 240 | resource = 0; |
| 241 | free_reg = 0; |
| 242 | for (reg = 0xc0; reg <= 0xd8; reg += 0x8) { |
| 243 | int result; |
| 244 | result = reg_useable(reg, dev, nodeid, link); |
| 245 | if (result == 1) { |
| 246 | /* I have been allocated this one */ |
| 247 | break; |
| 248 | } |
| 249 | else if (result > 1) { |
| 250 | /* I have a free register pair */ |
| 251 | free_reg = reg; |
| 252 | } |
| 253 | } |
| 254 | if (reg > 0xd8) { |
| 255 | reg = free_reg; // if no free, the free_reg still be 0 |
| 256 | } |
| 257 | |
| 258 | resource = new_resource(dev, IOINDEX(0x1000 + reg, link)); |
| 259 | |
| 260 | return resource; |
| 261 | } |
| 262 | |
| 263 | static struct resource *amdfam16_find_mempair(device_t dev, u32 nodeid, u32 link) |
| 264 | { |
| 265 | struct resource *resource; |
| 266 | u32 free_reg, reg; |
| 267 | resource = 0; |
| 268 | free_reg = 0; |
| 269 | for (reg = 0x80; reg <= 0xb8; reg += 0x8) { |
| 270 | int result; |
| 271 | result = reg_useable(reg, dev, nodeid, link); |
| 272 | if (result == 1) { |
| 273 | /* I have been allocated this one */ |
| 274 | break; |
| 275 | } |
| 276 | else if (result > 1) { |
| 277 | /* I have a free register pair */ |
| 278 | free_reg = reg; |
| 279 | } |
| 280 | } |
| 281 | if (reg > 0xb8) { |
| 282 | reg = free_reg; |
| 283 | } |
| 284 | |
| 285 | resource = new_resource(dev, IOINDEX(0x1000 + reg, link)); |
| 286 | return resource; |
| 287 | } |
| 288 | |
| 289 | static void amdfam16_link_read_bases(device_t dev, u32 nodeid, u32 link) |
| 290 | { |
| 291 | struct resource *resource; |
| 292 | |
| 293 | /* Initialize the io space constraints on the current bus */ |
| 294 | resource = amdfam16_find_iopair(dev, nodeid, link); |
| 295 | if (resource) { |
| 296 | u32 align; |
| 297 | align = log2(HT_IO_HOST_ALIGN); |
| 298 | resource->base = 0; |
| 299 | resource->size = 0; |
| 300 | resource->align = align; |
| 301 | resource->gran = align; |
| 302 | resource->limit = 0xffffUL; |
| 303 | resource->flags = IORESOURCE_IO | IORESOURCE_BRIDGE; |
| 304 | } |
| 305 | |
| 306 | /* Initialize the prefetchable memory constraints on the current bus */ |
| 307 | resource = amdfam16_find_mempair(dev, nodeid, link); |
| 308 | if (resource) { |
| 309 | resource->base = 0; |
| 310 | resource->size = 0; |
| 311 | resource->align = log2(HT_MEM_HOST_ALIGN); |
| 312 | resource->gran = log2(HT_MEM_HOST_ALIGN); |
| 313 | resource->limit = 0xffffffffffULL; |
| 314 | resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH; |
| 315 | resource->flags |= IORESOURCE_BRIDGE; |
| 316 | } |
| 317 | |
| 318 | /* Initialize the memory constraints on the current bus */ |
| 319 | resource = amdfam16_find_mempair(dev, nodeid, link); |
| 320 | if (resource) { |
| 321 | resource->base = 0; |
| 322 | resource->size = 0; |
| 323 | resource->align = log2(HT_MEM_HOST_ALIGN); |
| 324 | resource->gran = log2(HT_MEM_HOST_ALIGN); |
| 325 | resource->limit = 0xffffffffffULL; |
| 326 | resource->flags = IORESOURCE_MEM | IORESOURCE_BRIDGE; |
| 327 | } |
| 328 | |
| 329 | } |
| 330 | |
| 331 | static void read_resources(device_t dev) |
| 332 | { |
| 333 | u32 nodeid; |
| 334 | struct bus *link; |
| 335 | |
| 336 | nodeid = amdfam16_nodeid(dev); |
| 337 | for (link = dev->link_list; link; link = link->next) { |
| 338 | if (link->children) { |
| 339 | amdfam16_link_read_bases(dev, nodeid, link->link_num); |
| 340 | } |
| 341 | } |
Edward O'Callaghan | 66c6532 | 2014-11-21 01:43:38 +1100 | [diff] [blame] | 342 | |
| 343 | /* |
| 344 | * This MMCONF resource must be reserved in the PCI_DOMAIN. |
| 345 | * It is not honored by the coreboot resource allocator if it is in |
| 346 | * the APIC_CLUSTER. |
| 347 | */ |
| 348 | #if CONFIG_MMCONF_SUPPORT |
| 349 | struct resource *resource = new_resource(dev, 0xc0010058); |
| 350 | resource->base = CONFIG_MMCONF_BASE_ADDRESS; |
| 351 | resource->size = CONFIG_MMCONF_BUS_NUMBER * 4096 * 256; |
| 352 | resource->flags = IORESOURCE_MEM | IORESOURCE_RESERVE | |
| 353 | IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED; |
| 354 | #endif |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | static void set_resource(device_t dev, struct resource *resource, u32 nodeid) |
| 358 | { |
| 359 | resource_t rbase, rend; |
| 360 | unsigned reg, link_num; |
| 361 | char buf[50]; |
| 362 | |
| 363 | /* Make certain the resource has actually been set */ |
| 364 | if (!(resource->flags & IORESOURCE_ASSIGNED)) { |
| 365 | return; |
| 366 | } |
| 367 | |
| 368 | /* If I have already stored this resource don't worry about it */ |
| 369 | if (resource->flags & IORESOURCE_STORED) { |
| 370 | return; |
| 371 | } |
| 372 | |
| 373 | /* Only handle PCI memory and IO resources */ |
| 374 | if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO))) |
| 375 | return; |
| 376 | |
| 377 | /* Ensure I am actually looking at a resource of function 1 */ |
| 378 | if ((resource->index & 0xffff) < 0x1000) { |
| 379 | return; |
| 380 | } |
| 381 | /* Get the base address */ |
| 382 | rbase = resource->base; |
| 383 | |
| 384 | /* Get the limit (rounded up) */ |
| 385 | rend = resource_end(resource); |
| 386 | |
| 387 | /* Get the register and link */ |
| 388 | reg = resource->index & 0xfff; // 4k |
| 389 | link_num = IOINDEX_LINK(resource->index); |
| 390 | |
| 391 | if (resource->flags & IORESOURCE_IO) { |
| 392 | set_io_addr_reg(dev, nodeid, link_num, reg, rbase>>8, rend>>8); |
| 393 | } |
| 394 | else if (resource->flags & IORESOURCE_MEM) { |
Edward O'Callaghan | ae5fd34 | 2014-11-20 19:58:09 +1100 | [diff] [blame] | 395 | 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] | 396 | } |
| 397 | resource->flags |= IORESOURCE_STORED; |
Vladimir Serbinenko | a37383d | 2013-11-26 02:41:26 +0100 | [diff] [blame] | 398 | snprintf(buf, sizeof (buf), " <node %x link %x>", |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 399 | nodeid, link_num); |
| 400 | report_resource_stored(dev, resource, buf); |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * I tried to reuse the resource allocation code in set_resource() |
| 405 | * but it is too difficult to deal with the resource allocation magic. |
| 406 | */ |
| 407 | |
| 408 | static void create_vga_resource(device_t dev, unsigned nodeid) |
| 409 | { |
| 410 | struct bus *link; |
| 411 | |
| 412 | /* find out which link the VGA card is connected, |
| 413 | * we only deal with the 'first' vga card */ |
| 414 | for (link = dev->link_list; link; link = link->next) { |
| 415 | if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) { |
| 416 | #if CONFIG_MULTIPLE_VGA_ADAPTERS |
| 417 | extern device_t vga_pri; // the primary vga device, defined in device.c |
| 418 | printk(BIOS_DEBUG, "VGA: vga_pri bus num = %d bus range [%d,%d]\n", vga_pri->bus->secondary, |
| 419 | link->secondary,link->subordinate); |
| 420 | /* We need to make sure the vga_pri is under the link */ |
| 421 | if((vga_pri->bus->secondary >= link->secondary ) && |
| 422 | (vga_pri->bus->secondary <= link->subordinate ) |
| 423 | ) |
| 424 | #endif |
| 425 | break; |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | /* no VGA card installed */ |
| 430 | if (link == NULL) |
| 431 | return; |
| 432 | |
| 433 | printk(BIOS_DEBUG, "VGA: %s (aka node %d) link %d has VGA device\n", dev_path(dev), nodeid, sblink); |
| 434 | set_vga_enable_reg(nodeid, sblink); |
| 435 | } |
| 436 | |
| 437 | static void set_resources(device_t dev) |
| 438 | { |
| 439 | unsigned nodeid; |
| 440 | struct bus *bus; |
| 441 | struct resource *res; |
| 442 | |
| 443 | /* Find the nodeid */ |
| 444 | nodeid = amdfam16_nodeid(dev); |
| 445 | |
| 446 | create_vga_resource(dev, nodeid); //TODO: do we need this? |
| 447 | |
| 448 | /* Set each resource we have found */ |
| 449 | for (res = dev->resource_list; res; res = res->next) { |
| 450 | set_resource(dev, res, nodeid); |
| 451 | } |
| 452 | |
| 453 | for (bus = dev->link_list; bus; bus = bus->next) { |
| 454 | if (bus->children) { |
| 455 | assign_resources(bus); |
| 456 | } |
| 457 | } |
Edward O'Callaghan | 66c6532 | 2014-11-21 01:43:38 +1100 | [diff] [blame] | 458 | |
| 459 | /* Print the MMCONF region if it has been reserved. */ |
| 460 | res = find_resource(dev, 0xc0010058); |
| 461 | if (res) { |
| 462 | report_resource_stored(dev, res, " <mmconfig>"); |
| 463 | } |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 464 | } |
| 465 | |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 466 | #if 0 /* TODO: Check if needed. */ |
| 467 | static unsigned scan_chains(device_t dev, unsigned max) |
| 468 | { |
| 469 | unsigned nodeid; |
| 470 | struct bus *link; |
| 471 | device_t io_hub = NULL; |
| 472 | u32 next_unitid = 0x18; |
| 473 | nodeid = amdfam16_nodeid(dev); |
| 474 | if (nodeid == 0) { |
| 475 | for (link = dev->link_list; link; link = link->next) { |
| 476 | //if (link->link_num == sblink) { /* devicetree put IO Hub on link_lsit[sblink] */ |
| 477 | if (link->link_num == 0) { /* devicetree put IO Hub on link_lsit[0] */ |
| 478 | io_hub = link->children; |
| 479 | if (!io_hub || !io_hub->enabled) { |
| 480 | die("I can't find the IO Hub, or IO Hub not enabled, please check the device tree.\n"); |
| 481 | } |
| 482 | /* Now that nothing is overlapping it is safe to scan the children. */ |
| 483 | max = pci_scan_bus(link, 0x00, ((next_unitid - 1) << 3) | 7, 0); |
| 484 | } |
| 485 | } |
| 486 | } |
| 487 | return max; |
| 488 | } |
| 489 | #endif |
Vladimir Serbinenko | db09b062 | 2014-10-08 22:15:17 +0200 | [diff] [blame] | 490 | |
| 491 | |
| 492 | unsigned long acpi_fill_hest(acpi_hest_t *hest) |
| 493 | { |
| 494 | void *addr, *current; |
| 495 | |
| 496 | /* Skip the HEST header. */ |
| 497 | current = (void *)(hest + 1); |
| 498 | |
| 499 | addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE); |
| 500 | if (addr != NULL) |
| 501 | current += acpi_create_hest_error_source(hest, current, 0, (void *)((u32)addr + 2), *(UINT16 *)addr - 2); |
| 502 | |
| 503 | addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC); |
| 504 | if (addr != NULL) |
| 505 | current += acpi_create_hest_error_source(hest, current, 1, (void *)((u32)addr + 2), *(UINT16 *)addr - 2); |
| 506 | |
| 507 | return (unsigned long)current; |
| 508 | } |
| 509 | |
| 510 | /* Implemented with AGESA-specific code. Dummy to keep linker happy. */ |
| 511 | unsigned long acpi_fill_slit(unsigned long current) |
| 512 | { |
| 513 | return current; |
| 514 | } |
| 515 | |
| 516 | /* Implemented with AGESA-specific code. Dummy to keep linker happy. */ |
| 517 | unsigned long acpi_fill_srat(unsigned long current) |
| 518 | { |
| 519 | return current; |
| 520 | } |
| 521 | |
| 522 | static void northbridge_fill_ssdt_generator(void) |
| 523 | { |
| 524 | msr_t msr; |
| 525 | char pscope[] = "\\_SB.PCI0"; |
| 526 | |
| 527 | acpigen_write_scope(pscope); |
| 528 | msr = rdmsr(TOP_MEM); |
| 529 | acpigen_write_name_dword("TOM1", msr.lo); |
| 530 | msr = rdmsr(TOP_MEM2); |
| 531 | /* |
| 532 | * Since XP only implements parts of ACPI 2.0, we can't use a qword |
| 533 | * here. |
| 534 | * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt |
| 535 | * slide 22ff. |
| 536 | * Shift value right by 20 bit to make it fit into 32bit, |
| 537 | * giving us 1MB granularity and a limit of almost 4Exabyte of memory. |
| 538 | */ |
| 539 | acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20); |
| 540 | acpigen_pop_len(); |
| 541 | } |
| 542 | |
| 543 | static unsigned long agesa_write_acpi_tables(unsigned long current, |
| 544 | acpi_rsdp_t *rsdp) |
| 545 | { |
| 546 | acpi_srat_t *srat; |
| 547 | acpi_slit_t *slit; |
| 548 | acpi_header_t *ssdt; |
| 549 | acpi_header_t *alib; |
| 550 | acpi_header_t *ivrs; |
| 551 | acpi_hest_t *hest; |
| 552 | |
| 553 | /* HEST */ |
| 554 | current = ALIGN(current, 8); |
| 555 | hest = (acpi_hest_t *)current; |
| 556 | acpi_write_hest((void *)current); |
| 557 | acpi_add_table(rsdp, (void *)current); |
| 558 | current += ((acpi_header_t *)current)->length; |
| 559 | |
| 560 | current = ALIGN(current, 8); |
| 561 | printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current); |
| 562 | ivrs = agesawrapper_getlateinitptr(PICK_IVRS); |
| 563 | if (ivrs != NULL) { |
| 564 | memcpy((void *)current, ivrs, ivrs->length); |
| 565 | ivrs = (acpi_header_t *) current; |
| 566 | current += ivrs->length; |
| 567 | acpi_add_table(rsdp, ivrs); |
| 568 | } else { |
| 569 | printk(BIOS_DEBUG, " AGESA IVRS table NULL. Skipping.\n"); |
| 570 | } |
| 571 | |
| 572 | /* SRAT */ |
| 573 | current = ALIGN(current, 8); |
| 574 | printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current); |
| 575 | srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT); |
| 576 | if (srat != NULL) { |
| 577 | memcpy((void *)current, srat, srat->header.length); |
| 578 | srat = (acpi_srat_t *) current; |
| 579 | current += srat->header.length; |
| 580 | acpi_add_table(rsdp, srat); |
| 581 | } else { |
| 582 | printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n"); |
| 583 | } |
| 584 | |
| 585 | /* SLIT */ |
| 586 | current = ALIGN(current, 8); |
| 587 | printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current); |
| 588 | slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT); |
| 589 | if (slit != NULL) { |
| 590 | memcpy((void *)current, slit, slit->header.length); |
| 591 | slit = (acpi_slit_t *) current; |
| 592 | current += slit->header.length; |
| 593 | acpi_add_table(rsdp, slit); |
| 594 | } else { |
| 595 | printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n"); |
| 596 | } |
| 597 | |
| 598 | /* ALIB */ |
| 599 | current = ALIGN(current, 16); |
| 600 | printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current); |
| 601 | alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB); |
| 602 | if (alib != NULL) { |
| 603 | memcpy((void *)current, alib, alib->length); |
| 604 | alib = (acpi_header_t *) current; |
| 605 | current += alib->length; |
| 606 | acpi_add_table(rsdp, (void *)alib); |
| 607 | } |
| 608 | else { |
| 609 | printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n"); |
| 610 | } |
| 611 | |
| 612 | /* this pstate ssdt may cause Blue Screen: Fixed: Keep this comment for a while. */ |
| 613 | /* SSDT */ |
| 614 | current = ALIGN(current, 16); |
| 615 | printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current); |
| 616 | ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE); |
| 617 | if (ssdt != NULL) { |
| 618 | memcpy((void *)current, ssdt, ssdt->length); |
| 619 | ssdt = (acpi_header_t *) current; |
| 620 | current += ssdt->length; |
| 621 | } |
| 622 | else { |
| 623 | printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n"); |
| 624 | } |
| 625 | acpi_add_table(rsdp,ssdt); |
| 626 | |
| 627 | printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current); |
| 628 | |
| 629 | return current; |
| 630 | } |
| 631 | |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 632 | static struct device_operations northbridge_operations = { |
| 633 | .read_resources = read_resources, |
| 634 | .set_resources = set_resources, |
| 635 | .enable_resources = pci_dev_enable_resources, |
Edward O'Callaghan | d994ef1 | 2014-11-21 02:22:33 +1100 | [diff] [blame] | 636 | .init = DEVICE_NOOP, |
Vladimir Serbinenko | db09b062 | 2014-10-08 22:15:17 +0200 | [diff] [blame] | 637 | .acpi_fill_ssdt_generator = northbridge_fill_ssdt_generator, |
| 638 | .write_acpi_tables = agesa_write_acpi_tables, |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 639 | //.scan_bus = scan_chains, /* TODO: */ |
| 640 | .enable = 0, |
| 641 | .ops_pci = 0, |
| 642 | }; |
| 643 | |
| 644 | static const struct pci_driver family16_northbridge __pci_driver = { |
| 645 | .ops = &northbridge_operations, |
| 646 | .vendor = PCI_VENDOR_ID_AMD, |
| 647 | .device = PCI_DEVICE_ID_AMD_16H_MODEL_000F_NB_HT, |
| 648 | }; |
| 649 | |
| 650 | static const struct pci_driver family10_northbridge __pci_driver = { |
| 651 | .ops = &northbridge_operations, |
| 652 | .vendor = PCI_VENDOR_ID_AMD, |
| 653 | .device = PCI_DEVICE_ID_AMD_10H_NB_HT, |
| 654 | }; |
| 655 | |
| 656 | struct chip_operations northbridge_amd_agesa_family16kb_ops = { |
| 657 | CHIP_NAME("AMD FAM16 Northbridge") |
| 658 | .enable_dev = 0, |
| 659 | }; |
| 660 | |
| 661 | static void domain_read_resources(device_t dev) |
| 662 | { |
| 663 | unsigned reg; |
| 664 | |
| 665 | /* Find the already assigned resource pairs */ |
| 666 | get_fx_devs(); |
| 667 | for (reg = 0x80; reg <= 0xd8; reg+= 0x08) { |
| 668 | u32 base, limit; |
| 669 | base = f1_read_config32(reg); |
| 670 | limit = f1_read_config32(reg + 0x04); |
| 671 | /* Is this register allocated? */ |
| 672 | if ((base & 3) != 0) { |
| 673 | unsigned nodeid, reg_link; |
| 674 | device_t reg_dev; |
| 675 | if (reg<0xc0) { // mmio |
| 676 | nodeid = (limit & 0xf) + (base&0x30); |
| 677 | } else { // io |
| 678 | nodeid = (limit & 0xf) + ((base>>4)&0x30); |
| 679 | } |
| 680 | reg_link = (limit >> 4) & 7; |
| 681 | reg_dev = __f0_dev[nodeid]; |
| 682 | if (reg_dev) { |
| 683 | /* Reserve the resource */ |
| 684 | struct resource *res; |
| 685 | res = new_resource(reg_dev, IOINDEX(0x1000 + reg, reg_link)); |
| 686 | if (res) { |
| 687 | res->flags = 1; |
| 688 | } |
| 689 | } |
| 690 | } |
| 691 | } |
| 692 | /* FIXME: do we need to check extend conf space? |
| 693 | I don't believe that much preset value */ |
| 694 | |
| 695 | #if !CONFIG_PCI_64BIT_PREF_MEM |
| 696 | pci_domain_read_resources(dev); |
| 697 | |
| 698 | #else |
| 699 | struct bus *link; |
| 700 | struct resource *resource; |
| 701 | for (link=dev->link_list; link; link = link->next) { |
| 702 | /* Initialize the system wide io space constraints */ |
| 703 | resource = new_resource(dev, 0|(link->link_num<<2)); |
| 704 | resource->base = 0x400; |
| 705 | resource->limit = 0xffffUL; |
| 706 | resource->flags = IORESOURCE_IO; |
| 707 | |
| 708 | /* Initialize the system wide prefetchable memory resources constraints */ |
| 709 | resource = new_resource(dev, 1|(link->link_num<<2)); |
| 710 | resource->limit = 0xfcffffffffULL; |
| 711 | resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH; |
| 712 | |
| 713 | /* Initialize the system wide memory resources constraints */ |
| 714 | resource = new_resource(dev, 2|(link->link_num<<2)); |
| 715 | resource->limit = 0xfcffffffffULL; |
| 716 | resource->flags = IORESOURCE_MEM; |
| 717 | } |
| 718 | #endif |
| 719 | } |
| 720 | |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 721 | static void domain_enable_resources(device_t dev) |
| 722 | { |
Kyösti Mälkki | 8ae16a4 | 2014-06-19 20:44:34 +0300 | [diff] [blame] | 723 | if (acpi_is_wakeup_s3()) |
Kyösti Mälkki | 7b23ae0 | 2014-07-04 16:14:37 +0300 | [diff] [blame] | 724 | AGESAWRAPPER(fchs3laterestore); |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 725 | |
| 726 | /* Must be called after PCI enumeration and resource allocation */ |
Kyösti Mälkki | 7b23ae0 | 2014-07-04 16:14:37 +0300 | [diff] [blame] | 727 | if (!acpi_is_wakeup_s3()) |
| 728 | AGESAWRAPPER(amdinitmid); |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 729 | |
| 730 | printk(BIOS_DEBUG, " ader - leaving domain_enable_resources.\n"); |
| 731 | } |
| 732 | |
| 733 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
| 734 | struct hw_mem_hole_info { |
| 735 | unsigned hole_startk; |
| 736 | int node_id; |
| 737 | }; |
| 738 | static struct hw_mem_hole_info get_hw_mem_hole_info(void) |
| 739 | { |
| 740 | struct hw_mem_hole_info mem_hole; |
| 741 | int i; |
| 742 | mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK; |
| 743 | mem_hole.node_id = -1; |
| 744 | for (i = 0; i < node_nums; i++) { |
| 745 | dram_base_mask_t d; |
| 746 | u32 hole; |
| 747 | d = get_dram_base_mask(i); |
| 748 | if (!(d.mask & 1)) continue; // no memory on this node |
| 749 | hole = pci_read_config32(__f1_dev[i], 0xf0); |
| 750 | if (hole & 2) { // we find the hole |
| 751 | mem_hole.hole_startk = (hole & (0xff<<24)) >> 10; |
| 752 | mem_hole.node_id = i; // record the node No with hole |
| 753 | break; // only one hole |
| 754 | } |
| 755 | } |
Kyösti Mälkki | 2f9b3af | 2014-06-26 05:30:54 +0300 | [diff] [blame] | 756 | |
| 757 | /* We need to double check if there is special set on base reg and limit reg |
| 758 | * are not continuous instead of hole, it will find out its hole_startk. |
| 759 | */ |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 760 | if (mem_hole.node_id == -1) { |
| 761 | resource_t limitk_pri = 0; |
| 762 | for (i=0; i<node_nums; i++) { |
| 763 | dram_base_mask_t d; |
| 764 | resource_t base_k, limit_k; |
| 765 | d = get_dram_base_mask(i); |
| 766 | if (!(d.base & 1)) continue; |
| 767 | base_k = ((resource_t)(d.base & 0x1fffff00)) <<9; |
| 768 | if (base_k > 4 *1024 * 1024) break; // don't need to go to check |
| 769 | if (limitk_pri != base_k) { // we find the hole |
| 770 | mem_hole.hole_startk = (unsigned)limitk_pri; // must beblow 4G |
| 771 | mem_hole.node_id = i; |
| 772 | break; //only one hole |
| 773 | } |
| 774 | limit_k = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9; |
| 775 | limitk_pri = limit_k; |
| 776 | } |
| 777 | } |
| 778 | return mem_hole; |
| 779 | } |
| 780 | #endif |
| 781 | |
| 782 | #define ONE_MB_SHIFT 20 |
| 783 | |
| 784 | static void setup_uma_memory(void) |
| 785 | { |
| 786 | #if CONFIG_GFXUMA |
| 787 | uint32_t topmem = (uint32_t) bsp_topmem(); |
| 788 | uint32_t sys_mem; |
| 789 | |
| 790 | /* refer to UMA Size Consideration in Family16h BKDG. */ |
| 791 | /* Please reference MemNGetUmaSizeOR () */ |
| 792 | /* |
| 793 | * Total system memory UMASize |
| 794 | * >= 2G 512M |
| 795 | * >=1G 256M |
| 796 | * <1G 64M |
| 797 | */ |
| 798 | sys_mem = topmem + (16 << ONE_MB_SHIFT); // Ignore 16MB allocated for C6 when finding UMA size |
| 799 | if ((bsp_topmem2()>>32) || (sys_mem >= 2048 << ONE_MB_SHIFT)) { |
| 800 | uma_memory_size = 512 << ONE_MB_SHIFT; |
| 801 | } else if (sys_mem >= 1024 << ONE_MB_SHIFT) { |
| 802 | uma_memory_size = 256 << ONE_MB_SHIFT; |
| 803 | } else { |
| 804 | uma_memory_size = 64 << ONE_MB_SHIFT; |
| 805 | } |
| 806 | uma_memory_base = topmem - uma_memory_size; /* TOP_MEM1 */ |
| 807 | |
| 808 | printk(BIOS_INFO, "%s: uma size 0x%08llx, memory start 0x%08llx\n", |
| 809 | __func__, uma_memory_size, uma_memory_base); |
| 810 | |
| 811 | /* TODO: TOP_MEM2 */ |
| 812 | #endif |
| 813 | } |
| 814 | |
| 815 | |
| 816 | static void domain_set_resources(device_t dev) |
| 817 | { |
| 818 | #if CONFIG_PCI_64BIT_PREF_MEM |
| 819 | struct resource *io, *mem1, *mem2; |
| 820 | struct resource *res; |
| 821 | #endif |
| 822 | unsigned long mmio_basek; |
| 823 | u32 pci_tolm; |
Kyösti Mälkki | 2b790f6 | 2013-09-03 05:25:57 +0300 | [diff] [blame] | 824 | u64 ramtop = 0; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 825 | int i, idx; |
| 826 | struct bus *link; |
| 827 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
| 828 | struct hw_mem_hole_info mem_hole; |
| 829 | u32 reset_memhole = 1; |
| 830 | #endif |
| 831 | |
| 832 | #if CONFIG_PCI_64BIT_PREF_MEM |
| 833 | |
| 834 | for (link = dev->link_list; link; link = link->next) { |
| 835 | /* Now reallocate the pci resources memory with the |
| 836 | * highest addresses I can manage. |
| 837 | */ |
| 838 | mem1 = find_resource(dev, 1|(link->link_num<<2)); |
| 839 | mem2 = find_resource(dev, 2|(link->link_num<<2)); |
| 840 | |
| 841 | printk(BIOS_DEBUG, "base1: 0x%08Lx limit1: 0x%08Lx size: 0x%08Lx align: %d\n", |
| 842 | mem1->base, mem1->limit, mem1->size, mem1->align); |
| 843 | printk(BIOS_DEBUG, "base2: 0x%08Lx limit2: 0x%08Lx size: 0x%08Lx align: %d\n", |
| 844 | mem2->base, mem2->limit, mem2->size, mem2->align); |
| 845 | |
| 846 | /* See if both resources have roughly the same limits */ |
| 847 | if (((mem1->limit <= 0xffffffff) && (mem2->limit <= 0xffffffff)) || |
| 848 | ((mem1->limit > 0xffffffff) && (mem2->limit > 0xffffffff))) |
| 849 | { |
| 850 | /* If so place the one with the most stringent alignment first */ |
| 851 | if (mem2->align > mem1->align) { |
| 852 | struct resource *tmp; |
| 853 | tmp = mem1; |
| 854 | mem1 = mem2; |
| 855 | mem2 = tmp; |
| 856 | } |
| 857 | /* Now place the memory as high up as it will go */ |
| 858 | mem2->base = resource_max(mem2); |
| 859 | mem1->limit = mem2->base - 1; |
| 860 | mem1->base = resource_max(mem1); |
| 861 | } |
| 862 | else { |
| 863 | /* Place the resources as high up as they will go */ |
| 864 | mem2->base = resource_max(mem2); |
| 865 | mem1->base = resource_max(mem1); |
| 866 | } |
| 867 | |
| 868 | printk(BIOS_DEBUG, "base1: 0x%08Lx limit1: 0x%08Lx size: 0x%08Lx align: %d\n", |
| 869 | mem1->base, mem1->limit, mem1->size, mem1->align); |
| 870 | printk(BIOS_DEBUG, "base2: 0x%08Lx limit2: 0x%08Lx size: 0x%08Lx align: %d\n", |
| 871 | mem2->base, mem2->limit, mem2->size, mem2->align); |
| 872 | } |
| 873 | |
| 874 | for (res = &dev->resource_list; res; res = res->next) |
| 875 | { |
| 876 | res->flags |= IORESOURCE_ASSIGNED; |
| 877 | res->flags |= IORESOURCE_STORED; |
| 878 | report_resource_stored(dev, res, ""); |
| 879 | } |
| 880 | #endif |
| 881 | |
| 882 | pci_tolm = 0xffffffffUL; |
| 883 | for (link = dev->link_list; link; link = link->next) { |
| 884 | pci_tolm = find_pci_tolm(link); |
| 885 | } |
| 886 | |
| 887 | // FIXME handle interleaved nodes. If you fix this here, please fix |
| 888 | // amdk8, too. |
| 889 | mmio_basek = pci_tolm >> 10; |
| 890 | /* Round mmio_basek to something the processor can support */ |
| 891 | mmio_basek &= ~((1 << 6) -1); |
| 892 | |
| 893 | // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M |
| 894 | // MMIO hole. If you fix this here, please fix amdk8, too. |
| 895 | /* Round the mmio hole to 64M */ |
| 896 | mmio_basek &= ~((64*1024) - 1); |
| 897 | |
| 898 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
| 899 | /* if the hw mem hole is already set in raminit stage, here we will compare |
| 900 | * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will |
| 901 | * use hole_basek as mmio_basek and we don't need to reset hole. |
| 902 | * otherwise We reset the hole to the mmio_basek |
| 903 | */ |
| 904 | |
| 905 | mem_hole = get_hw_mem_hole_info(); |
| 906 | |
| 907 | // Use hole_basek as mmio_basek, and we don't need to reset hole anymore |
| 908 | if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) { |
| 909 | mmio_basek = mem_hole.hole_startk; |
| 910 | reset_memhole = 0; |
| 911 | } |
| 912 | #endif |
| 913 | |
| 914 | idx = 0x10; |
| 915 | for (i = 0; i < node_nums; i++) { |
| 916 | dram_base_mask_t d; |
| 917 | resource_t basek, limitk, sizek; // 4 1T |
| 918 | |
| 919 | d = get_dram_base_mask(i); |
| 920 | |
| 921 | if (!(d.mask & 1)) continue; |
| 922 | 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] | 923 | limitk = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 924 | |
| 925 | sizek = limitk - basek; |
| 926 | |
| 927 | /* see if we need a hole from 0xa0000 to 0xbffff */ |
| 928 | if ((basek < ((8*64)+(8*16))) && (sizek > ((8*64)+(16*16)))) { |
| 929 | ram_resource(dev, (idx | i), basek, ((8*64)+(8*16)) - basek); |
| 930 | idx += 0x10; |
| 931 | basek = (8*64)+(16*16); |
| 932 | sizek = limitk - ((8*64)+(16*16)); |
| 933 | |
| 934 | } |
| 935 | |
| 936 | //printk(BIOS_DEBUG, "node %d : mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", i, mmio_basek, basek, limitk); |
| 937 | |
Kyösti Mälkki | 26c6543 | 2014-06-26 05:30:54 +0300 | [diff] [blame] | 938 | /* split the region to accommodate pci memory space */ |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 939 | if ((basek < 4*1024*1024 ) && (limitk > mmio_basek)) { |
| 940 | if (basek <= mmio_basek) { |
| 941 | unsigned pre_sizek; |
| 942 | pre_sizek = mmio_basek - basek; |
| 943 | if (pre_sizek>0) { |
| 944 | ram_resource(dev, (idx | i), basek, pre_sizek); |
| 945 | idx += 0x10; |
| 946 | sizek -= pre_sizek; |
Kyösti Mälkki | 2b790f6 | 2013-09-03 05:25:57 +0300 | [diff] [blame] | 947 | if (!ramtop) |
| 948 | ramtop = mmio_basek * 1024; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 949 | } |
| 950 | basek = mmio_basek; |
| 951 | } |
| 952 | if ((basek + sizek) <= 4*1024*1024) { |
| 953 | sizek = 0; |
| 954 | } |
| 955 | else { |
| 956 | uint64_t topmem2 = bsp_topmem2(); |
| 957 | basek = 4*1024*1024; |
| 958 | sizek = topmem2/1024 - basek; |
| 959 | } |
| 960 | } |
| 961 | |
| 962 | ram_resource(dev, (idx | i), basek, sizek); |
| 963 | idx += 0x10; |
| 964 | printk(BIOS_DEBUG, "node %d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", |
| 965 | i, mmio_basek, basek, limitk); |
Kyösti Mälkki | 2b790f6 | 2013-09-03 05:25:57 +0300 | [diff] [blame] | 966 | if (!ramtop) |
| 967 | ramtop = limitk * 1024; |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | #if CONFIG_GFXUMA |
Kyösti Mälkki | 2b790f6 | 2013-09-03 05:25:57 +0300 | [diff] [blame] | 971 | set_top_of_ram(uma_memory_base); |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 972 | uma_resource(dev, 7, uma_memory_base >> 10, uma_memory_size >> 10); |
Kyösti Mälkki | 2b790f6 | 2013-09-03 05:25:57 +0300 | [diff] [blame] | 973 | #else |
| 974 | set_top_of_ram(ramtop); |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 975 | #endif |
| 976 | |
| 977 | for(link = dev->link_list; link; link = link->next) { |
| 978 | if (link->children) { |
| 979 | assign_resources(link); |
| 980 | } |
| 981 | } |
| 982 | } |
| 983 | |
| 984 | static struct device_operations pci_domain_ops = { |
| 985 | .read_resources = domain_read_resources, |
| 986 | .set_resources = domain_set_resources, |
| 987 | .enable_resources = domain_enable_resources, |
| 988 | .init = NULL, |
| 989 | .scan_bus = pci_domain_scan_bus, |
| 990 | .ops_pci_bus = pci_bus_default_ops, |
| 991 | }; |
| 992 | |
| 993 | static void sysconf_init(device_t dev) // first node |
| 994 | { |
| 995 | sblink = (pci_read_config32(dev, 0x64)>>8) & 7; // don't forget sublink1 |
| 996 | node_nums = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; //NodeCnt[2:0] |
| 997 | } |
| 998 | |
| 999 | static void add_more_links(device_t dev, unsigned total_links) |
| 1000 | { |
| 1001 | struct bus *link, *last = NULL; |
| 1002 | int link_num; |
| 1003 | |
| 1004 | for (link = dev->link_list; link; link = link->next) |
| 1005 | last = link; |
| 1006 | |
| 1007 | if (last) { |
| 1008 | int links = total_links - last->link_num; |
| 1009 | link_num = last->link_num; |
| 1010 | if (links > 0) { |
| 1011 | link = malloc(links*sizeof(*link)); |
| 1012 | if (!link) |
| 1013 | die("Couldn't allocate more links!\n"); |
| 1014 | memset(link, 0, links*sizeof(*link)); |
| 1015 | last->next = link; |
| 1016 | } |
| 1017 | } |
| 1018 | else { |
| 1019 | link_num = -1; |
| 1020 | link = malloc(total_links*sizeof(*link)); |
| 1021 | memset(link, 0, total_links*sizeof(*link)); |
| 1022 | dev->link_list = link; |
| 1023 | } |
| 1024 | |
| 1025 | for (link_num = link_num + 1; link_num < total_links; link_num++) { |
| 1026 | link->link_num = link_num; |
| 1027 | link->dev = dev; |
| 1028 | link->next = link + 1; |
| 1029 | last = link; |
| 1030 | link = link->next; |
| 1031 | } |
| 1032 | last->next = NULL; |
| 1033 | } |
| 1034 | |
| 1035 | static u32 cpu_bus_scan(device_t dev, u32 max) |
| 1036 | { |
| 1037 | struct bus *cpu_bus; |
| 1038 | device_t dev_mc; |
| 1039 | #if CONFIG_CBB |
| 1040 | device_t pci_domain; |
| 1041 | #endif |
| 1042 | int i,j; |
| 1043 | int coreid_bits; |
| 1044 | int core_max = 0; |
| 1045 | unsigned ApicIdCoreIdSize; |
| 1046 | unsigned core_nums; |
| 1047 | int siblings = 0; |
| 1048 | unsigned int family; |
| 1049 | |
| 1050 | #if CONFIG_CBB |
| 1051 | dev_mc = dev_find_slot(0, PCI_DEVFN(CONFIG_CDB, 0)); //0x00 |
| 1052 | if (dev_mc && dev_mc->bus) { |
| 1053 | printk(BIOS_DEBUG, "%s found", dev_path(dev_mc)); |
| 1054 | pci_domain = dev_mc->bus->dev; |
| 1055 | if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) { |
| 1056 | printk(BIOS_DEBUG, "\n%s move to ",dev_path(dev_mc)); |
| 1057 | dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff |
| 1058 | printk(BIOS_DEBUG, "%s",dev_path(dev_mc)); |
| 1059 | } else { |
| 1060 | printk(BIOS_DEBUG, " but it is not under pci_domain directly "); |
| 1061 | } |
| 1062 | printk(BIOS_DEBUG, "\n"); |
| 1063 | } |
| 1064 | dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0)); |
| 1065 | if (!dev_mc) { |
| 1066 | dev_mc = dev_find_slot(0, PCI_DEVFN(0x18, 0)); |
| 1067 | if (dev_mc && dev_mc->bus) { |
| 1068 | printk(BIOS_DEBUG, "%s found\n", dev_path(dev_mc)); |
| 1069 | pci_domain = dev_mc->bus->dev; |
| 1070 | if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) { |
| 1071 | if ((pci_domain->link_list) && (pci_domain->link_list->children == dev_mc)) { |
| 1072 | printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc)); |
| 1073 | dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff |
| 1074 | printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc)); |
| 1075 | while (dev_mc) { |
| 1076 | printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc)); |
| 1077 | dev_mc->path.pci.devfn -= PCI_DEVFN(0x18,0); |
| 1078 | printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc)); |
| 1079 | dev_mc = dev_mc->sibling; |
| 1080 | } |
| 1081 | } |
| 1082 | } |
| 1083 | } |
| 1084 | } |
| 1085 | #endif |
| 1086 | dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0)); |
| 1087 | if (!dev_mc) { |
| 1088 | printk(BIOS_ERR, "%02x:%02x.0 not found", CONFIG_CBB, CONFIG_CDB); |
| 1089 | die(""); |
| 1090 | } |
| 1091 | sysconf_init(dev_mc); |
| 1092 | #if CONFIG_CBB && (MAX_NODE_NUMS > 32) |
| 1093 | if (node_nums>32) { // need to put node 32 to node 63 to bus 0xfe |
| 1094 | if (pci_domain->link_list && !pci_domain->link_list->next) { |
| 1095 | struct bus *new_link = new_link(pci_domain); |
| 1096 | pci_domain->link_list->next = new_link; |
| 1097 | new_link->link_num = 1; |
| 1098 | new_link->dev = pci_domain; |
| 1099 | new_link->children = 0; |
| 1100 | printk(BIOS_DEBUG, "%s links now 2\n", dev_path(pci_domain)); |
| 1101 | } |
| 1102 | pci_domain->link_list->next->secondary = CONFIG_CBB - 1; |
| 1103 | } |
| 1104 | #endif |
| 1105 | |
| 1106 | /* Get Max Number of cores(MNC) */ |
| 1107 | coreid_bits = (cpuid_ecx(AMD_CPUID_ASIZE_PCCOUNT) & 0x0000F000) >> 12; |
| 1108 | core_max = 1 << (coreid_bits & 0x000F); //mnc |
| 1109 | |
| 1110 | ApicIdCoreIdSize = ((cpuid_ecx(0x80000008)>>12) & 0xF); |
| 1111 | if (ApicIdCoreIdSize) { |
| 1112 | core_nums = (1 << ApicIdCoreIdSize) - 1; |
| 1113 | } else { |
| 1114 | core_nums = 3; //quad core |
| 1115 | } |
| 1116 | |
| 1117 | /* Find which cpus are present */ |
| 1118 | cpu_bus = dev->link_list; |
| 1119 | for (i = 0; i < node_nums; i++) { |
| 1120 | device_t cdb_dev; |
| 1121 | unsigned busn, devn; |
| 1122 | struct bus *pbus; |
| 1123 | |
| 1124 | busn = CONFIG_CBB; |
| 1125 | devn = CONFIG_CDB + i; |
| 1126 | pbus = dev_mc->bus; |
| 1127 | #if CONFIG_CBB && (MAX_NODE_NUMS > 32) |
| 1128 | if (i >= 32) { |
| 1129 | busn--; |
| 1130 | devn -= 32; |
| 1131 | pbus = pci_domain->link_list->next; |
| 1132 | } |
| 1133 | #endif |
| 1134 | |
| 1135 | /* Find the cpu's pci device */ |
| 1136 | cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0)); |
| 1137 | if (!cdb_dev) { |
| 1138 | /* If I am probing things in a weird order |
| 1139 | * ensure all of the cpu's pci devices are found. |
| 1140 | */ |
| 1141 | int fn; |
| 1142 | for(fn = 0; fn <= 5; fn++) { //FBDIMM? |
| 1143 | cdb_dev = pci_probe_dev(NULL, pbus, |
| 1144 | PCI_DEVFN(devn, fn)); |
| 1145 | } |
| 1146 | cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0)); |
| 1147 | } else { |
| 1148 | /* Ok, We need to set the links for that device. |
| 1149 | * otherwise the device under it will not be scanned |
| 1150 | */ |
| 1151 | int linknum; |
| 1152 | #if CONFIG_HT3_SUPPORT |
| 1153 | linknum = 8; |
| 1154 | #else |
| 1155 | linknum = 4; |
| 1156 | #endif |
| 1157 | add_more_links(cdb_dev, linknum); |
| 1158 | } |
| 1159 | |
| 1160 | family = cpuid_eax(1); |
| 1161 | family = (family >> 20) & 0xFF; |
| 1162 | if (family == 1) { //f10 |
| 1163 | u32 dword; |
| 1164 | cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 3)); |
| 1165 | dword = pci_read_config32(cdb_dev, 0xe8); |
| 1166 | siblings = ((dword & BIT15) >> 13) | ((dword & (BIT13 | BIT12)) >> 12); |
| 1167 | } else if (family == 7) {//f16 |
| 1168 | cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 5)); |
| 1169 | if (cdb_dev && cdb_dev->enabled) { |
| 1170 | siblings = pci_read_config32(cdb_dev, 0x84); |
| 1171 | siblings &= 0xFF; |
| 1172 | } |
| 1173 | } else { |
| 1174 | siblings = 0; //default one core |
| 1175 | } |
| 1176 | int enable_node = cdb_dev && cdb_dev->enabled; |
| 1177 | printk(BIOS_SPEW, "%s family%xh, core_max=0x%x, core_nums=0x%x, siblings=0x%x\n", |
| 1178 | dev_path(cdb_dev), 0x0f + family, core_max, core_nums, siblings); |
| 1179 | |
| 1180 | for (j = 0; j <= siblings; j++ ) { |
| 1181 | extern CONST OPTIONS_CONFIG_TOPOLOGY ROMDATA TopologyConfiguration; |
| 1182 | u32 modules = TopologyConfiguration.PlatformNumberOfModules; |
| 1183 | u32 lapicid_start = 0; |
| 1184 | |
| 1185 | /* |
| 1186 | * APIC ID calucation is tightly coupled with AGESA v5 code. |
| 1187 | * This calculation MUST match the assignment calculation done |
| 1188 | * in LocalApicInitializationAtEarly() function. |
| 1189 | * And reference GetLocalApicIdForCore() |
| 1190 | * |
| 1191 | * Apply apic enumeration rules |
| 1192 | * For systems with >= 16 APICs, put the IO-APICs at 0..n and |
| 1193 | * put the local-APICs at m..z |
| 1194 | * |
| 1195 | * This is needed because many IO-APIC devices only have 4 bits |
| 1196 | * for their APIC id and therefore must reside at 0..15 |
| 1197 | */ |
| 1198 | #ifndef CFG_PLAT_NUM_IO_APICS /* defined in mainboard buildOpts.c */ |
| 1199 | #define CFG_PLAT_NUM_IO_APICS 3 |
| 1200 | #endif |
| 1201 | if ((node_nums * core_max) + CFG_PLAT_NUM_IO_APICS >= 0x10) { |
| 1202 | lapicid_start = (CFG_PLAT_NUM_IO_APICS - 1) / core_max; |
| 1203 | lapicid_start = (lapicid_start + 1) * core_max; |
| 1204 | printk(BIOS_SPEW, "lpaicid_start=0x%x ", lapicid_start); |
| 1205 | } |
| 1206 | u32 apic_id = (lapicid_start * (i/modules + 1)) + ((i % modules) ? (j + (siblings + 1)) : j); |
| 1207 | printk(BIOS_SPEW, "node 0x%x core 0x%x apicid=0x%x\n", |
| 1208 | i, j, apic_id); |
| 1209 | |
| 1210 | device_t cpu = add_cpu_device(cpu_bus, apic_id, enable_node); |
| 1211 | if (cpu) |
| 1212 | amd_cpu_topology(cpu, i, j); |
| 1213 | } //j |
| 1214 | } |
| 1215 | return max; |
| 1216 | } |
| 1217 | |
| 1218 | static void cpu_bus_init(device_t dev) |
| 1219 | { |
| 1220 | initialize_cpus(dev->link_list); |
| 1221 | } |
| 1222 | |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 1223 | static struct device_operations cpu_bus_ops = { |
Edward O'Callaghan | 66c6532 | 2014-11-21 01:43:38 +1100 | [diff] [blame] | 1224 | .read_resources = DEVICE_NOOP, |
| 1225 | .set_resources = DEVICE_NOOP, |
Edward O'Callaghan | 812d2a4 | 2014-10-31 08:17:23 +1100 | [diff] [blame] | 1226 | .enable_resources = DEVICE_NOOP, |
Siyuan Wang | 3e32cc0 | 2013-07-09 17:16:20 +0800 | [diff] [blame] | 1227 | .init = cpu_bus_init, |
| 1228 | .scan_bus = cpu_bus_scan, |
| 1229 | }; |
| 1230 | |
| 1231 | static void root_complex_enable_dev(struct device *dev) |
| 1232 | { |
| 1233 | static int done = 0; |
| 1234 | |
| 1235 | /* Do not delay UMA setup, as a device on the PCI bus may evaluate |
| 1236 | the global uma_memory variables already in its enable function. */ |
| 1237 | if (!done) { |
| 1238 | setup_bsp_ramtop(); |
| 1239 | setup_uma_memory(); |
| 1240 | done = 1; |
| 1241 | } |
| 1242 | |
| 1243 | /* Set the operations if it is a special bus type */ |
| 1244 | if (dev->path.type == DEVICE_PATH_DOMAIN) { |
| 1245 | dev->ops = &pci_domain_ops; |
| 1246 | } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) { |
| 1247 | dev->ops = &cpu_bus_ops; |
| 1248 | } |
| 1249 | } |
| 1250 | |
| 1251 | struct chip_operations northbridge_amd_agesa_family16kb_root_complex_ops = { |
| 1252 | CHIP_NAME("AMD FAM16 Root Complex") |
| 1253 | .enable_dev = root_complex_enable_dev, |
| 1254 | }; |
Bruce Griffith | 76db07e | 2013-07-07 02:06:53 -0600 | [diff] [blame] | 1255 | |
| 1256 | /********************************************************************* |
| 1257 | * Change the vendor / device IDs to match the generic VBIOS header. * |
| 1258 | *********************************************************************/ |
| 1259 | u32 map_oprom_vendev(u32 vendev) |
| 1260 | { |
| 1261 | u32 new_vendev = vendev; |
| 1262 | |
| 1263 | switch(vendev) { |
| 1264 | case 0x10029830: |
| 1265 | case 0x10029831: |
| 1266 | case 0x10029832: |
| 1267 | case 0x10029833: |
| 1268 | case 0x10029834: |
| 1269 | case 0x10029835: |
| 1270 | case 0x10029836: |
| 1271 | case 0x10029837: |
| 1272 | case 0x10029838: |
| 1273 | case 0x10029839: |
| 1274 | case 0x1002983A: |
| 1275 | case 0x1002983D: |
| 1276 | new_vendev = 0x10029830; // This is the default value in AMD-generated VBIOS |
| 1277 | break; |
| 1278 | default: |
| 1279 | break; |
| 1280 | } |
| 1281 | |
| 1282 | if (vendev != new_vendev) |
| 1283 | printk(BIOS_NOTICE, "Mapping PCI device %8x to %8x\n", vendev, new_vendev); |
| 1284 | |
| 1285 | return new_vendev; |
| 1286 | } |