Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 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. |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <console/console.h> |
| 17 | #include <arch/io.h> |
Kyösti Mälkki | 8ae16a4 | 2014-06-19 20:44:34 +0300 | [diff] [blame] | 18 | #include <arch/acpi.h> |
Kyösti Mälkki | 68a83df | 2014-11-26 09:51:14 +0200 | [diff] [blame] | 19 | #include <arch/acpigen.h> |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 20 | #include <stdint.h> |
| 21 | #include <device/device.h> |
| 22 | #include <device/pci.h> |
| 23 | #include <device/pci_ids.h> |
| 24 | #include <device/hypertransport.h> |
| 25 | #include <stdlib.h> |
| 26 | #include <string.h> |
Ronald G. Minnich | 5079a0d | 2012-11-27 11:32:38 -0800 | [diff] [blame] | 27 | #include <lib.h> |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 28 | #include <cpu/cpu.h> |
Marc Jones | 5750ed2 | 2012-03-15 13:21:41 -0600 | [diff] [blame] | 29 | #include <cbmem.h> |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 30 | |
| 31 | #include <cpu/x86/lapic.h> |
Kyösti Mälkki | 55fff930 | 2012-07-11 08:02:39 +0300 | [diff] [blame] | 32 | #include <cpu/amd/mtrr.h> |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 33 | |
Kyösti Mälkki | f21c2ac | 2014-10-19 09:35:18 +0300 | [diff] [blame] | 34 | #include <northbridge/amd/agesa/agesawrapper.h> |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 35 | #if CONFIG_AMD_SB_CIMX |
| 36 | #include <sb_cimx.h> |
| 37 | #endif |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 38 | |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 39 | #define FX_DEVS 1 |
| 40 | |
| 41 | static device_t __f0_dev[FX_DEVS]; |
| 42 | static device_t __f1_dev[FX_DEVS]; |
| 43 | static device_t __f2_dev[FX_DEVS]; |
| 44 | static device_t __f4_dev[FX_DEVS]; |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 45 | static unsigned fx_devs = 0; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 46 | |
Edward O'Callaghan | 541ac59 | 2014-11-21 00:37:02 +1100 | [diff] [blame] | 47 | static device_t get_node_pci(u32 nodeid, u32 fn) |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 48 | { |
zbao | 49bb26a4 | 2012-08-03 15:44:42 +0800 | [diff] [blame] | 49 | if ((CONFIG_CDB + nodeid) < 32) { |
| 50 | return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn)); |
| 51 | } else { |
| 52 | return dev_find_slot(CONFIG_CBB-1, PCI_DEVFN(CONFIG_CDB + nodeid - 32, fn)); |
| 53 | } |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 54 | } |
| 55 | |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 56 | static void get_fx_devs(void) |
| 57 | { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 58 | int i; |
| 59 | for (i = 0; i < FX_DEVS; i++) { |
| 60 | __f0_dev[i] = get_node_pci(i, 0); |
| 61 | __f1_dev[i] = get_node_pci(i, 1); |
| 62 | __f2_dev[i] = get_node_pci(i, 2); |
| 63 | __f4_dev[i] = get_node_pci(i, 4); |
| 64 | if (__f0_dev[i] != NULL && __f1_dev[i] != NULL) |
| 65 | fx_devs = i + 1; |
| 66 | } |
| 67 | if (__f1_dev[0] == NULL || __f0_dev[0] == NULL || fx_devs == 0) { |
| 68 | die("Cannot find 0:0x18.[0|1]\n"); |
| 69 | } |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 70 | } |
| 71 | |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 72 | static u32 f1_read_config32(unsigned reg) |
| 73 | { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 74 | if (fx_devs == 0) |
| 75 | get_fx_devs(); |
| 76 | return pci_read_config32(__f1_dev[0], reg); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 79 | static void f1_write_config32(unsigned reg, u32 value) |
| 80 | { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 81 | int i; |
| 82 | if (fx_devs == 0) |
| 83 | get_fx_devs(); |
| 84 | for (i = 0; i < fx_devs; i++) { |
| 85 | device_t dev; |
| 86 | dev = __f1_dev[i]; |
| 87 | if (dev && dev->enabled) { |
| 88 | pci_write_config32(dev, reg, value); |
| 89 | } |
| 90 | } |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 91 | } |
| 92 | |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 93 | static u32 amdfam14_nodeid(device_t dev) |
| 94 | { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 95 | return (dev->path.pci.devfn >> 3) - CONFIG_CDB; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 98 | #include "amdfam14_conf.c" |
| 99 | |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 100 | static void northbridge_init(device_t dev) |
| 101 | { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 102 | printk(BIOS_DEBUG, "Northbridge init\n"); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 103 | } |
| 104 | |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 105 | static void set_vga_enable_reg(u32 nodeid, u32 linkn) |
| 106 | { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 107 | u32 val; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 108 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 109 | val = 1 | (nodeid << 4) | (linkn << 12); |
| 110 | /* it will routing (1)mmio 0xa0000:0xbffff (2) io 0x3b0:0x3bb, |
| 111 | 0x3c0:0x3df */ |
| 112 | f1_write_config32(0xf4, val); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 113 | |
| 114 | } |
| 115 | |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 116 | static int reg_useable(unsigned reg, device_t goal_dev, unsigned goal_nodeid, |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 117 | unsigned goal_link) |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 118 | { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 119 | struct resource *res; |
| 120 | unsigned nodeid, link = 0; |
| 121 | int result; |
| 122 | res = 0; |
| 123 | for (nodeid = 0; !res && (nodeid < fx_devs); nodeid++) { |
| 124 | device_t dev; |
| 125 | dev = __f0_dev[nodeid]; |
| 126 | if (!dev) |
| 127 | continue; |
| 128 | for (link = 0; !res && (link < 8); link++) { |
| 129 | res = probe_resource(dev, IOINDEX(0x1000 + reg, link)); |
| 130 | } |
| 131 | } |
| 132 | result = 2; |
| 133 | if (res) { |
| 134 | result = 0; |
| 135 | if ((goal_link == (link - 1)) && |
| 136 | (goal_nodeid == (nodeid - 1)) && (res->flags <= 1)) { |
| 137 | result = 1; |
| 138 | } |
| 139 | } |
| 140 | return result; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 143 | static struct resource *amdfam14_find_iopair(device_t dev, unsigned nodeid, |
| 144 | unsigned link) |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 145 | { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 146 | struct resource *resource; |
| 147 | u32 result, reg; |
| 148 | resource = 0; |
| 149 | reg = 0; |
| 150 | result = reg_useable(0xc0, dev, nodeid, link); |
| 151 | if (result >= 1) { |
| 152 | /* I have been allocated this one */ |
| 153 | reg = 0xc0; |
| 154 | } |
| 155 | /* Ext conf space */ |
| 156 | if (!reg) { |
| 157 | /* Because of Extend conf space, we will never run out of reg, |
| 158 | * but we need one index to differ them. So ,same node and same |
| 159 | * link can have multi range |
| 160 | */ |
| 161 | u32 index = get_io_addr_index(nodeid, link); |
| 162 | reg = 0x110 + (index << 24) + (4 << 20); // index could be 0, 255 |
| 163 | } |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 164 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 165 | resource = new_resource(dev, IOINDEX(0x1000 + reg, link)); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 166 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 167 | return resource; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 168 | } |
| 169 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 170 | static struct resource *amdfam14_find_mempair(device_t dev, u32 nodeid, |
| 171 | u32 link) |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 172 | { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 173 | struct resource *resource; |
| 174 | u32 free_reg, reg; |
| 175 | resource = 0; |
| 176 | free_reg = 0; |
| 177 | for (reg = 0x80; reg <= 0xb8; reg += 0x8) { |
| 178 | int result; |
| 179 | result = reg_useable(reg, dev, nodeid, link); |
| 180 | if (result == 1) { |
| 181 | /* I have been allocated this one */ |
| 182 | break; |
| 183 | } else if (result > 1) { |
| 184 | /* I have a free register pair */ |
| 185 | free_reg = reg; |
| 186 | } |
| 187 | } |
| 188 | if (reg > 0xb8) { |
| 189 | reg = free_reg; |
| 190 | } |
| 191 | /* Ext conf space */ |
| 192 | if (!reg) { |
| 193 | /* Because of Extend conf space, we will never run out of reg, |
| 194 | * but we need one index to differ them. So ,same node and same |
| 195 | * link can have multi range |
| 196 | */ |
| 197 | u32 index = get_mmio_addr_index(nodeid, link); |
| 198 | reg = 0x110 + (index << 24) + (6 << 20); // index could be 0, 63 |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 199 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 200 | } |
| 201 | resource = new_resource(dev, IOINDEX(0x1000 + reg, link)); |
| 202 | return resource; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 203 | } |
| 204 | |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 205 | static void amdfam14_link_read_bases(device_t dev, u32 nodeid, u32 link) |
| 206 | { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 207 | struct resource *resource; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 208 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 209 | /* Initialize the io space constraints on the current bus */ |
| 210 | resource = amdfam14_find_iopair(dev, nodeid, link); |
| 211 | if (resource) { |
| 212 | u32 align; |
Kyösti Mälkki | ac7402d | 2014-12-14 08:30:17 +0200 | [diff] [blame] | 213 | align = log2(HT_IO_HOST_ALIGN); |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 214 | resource->base = 0; |
| 215 | resource->size = 0; |
| 216 | resource->align = align; |
| 217 | resource->gran = align; |
| 218 | resource->limit = 0xffffUL; |
| 219 | resource->flags = IORESOURCE_IO | IORESOURCE_BRIDGE; |
| 220 | } |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 221 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 222 | /* Initialize the prefetchable memory constraints on the current bus */ |
| 223 | resource = amdfam14_find_mempair(dev, nodeid, link); |
| 224 | if (resource) { |
| 225 | resource->base = 0; |
| 226 | resource->size = 0; |
| 227 | resource->align = log2(HT_MEM_HOST_ALIGN); |
| 228 | resource->gran = log2(HT_MEM_HOST_ALIGN); |
| 229 | resource->limit = 0xffffffffffULL; |
| 230 | resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH; |
| 231 | resource->flags |= IORESOURCE_BRIDGE; |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 232 | } |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 233 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 234 | /* Initialize the memory constraints on the current bus */ |
| 235 | resource = amdfam14_find_mempair(dev, nodeid, link); |
| 236 | if (resource) { |
| 237 | resource->base = 0; |
| 238 | resource->size = 0; |
| 239 | resource->align = log2(HT_MEM_HOST_ALIGN); |
| 240 | resource->gran = log2(HT_MEM_HOST_ALIGN); |
| 241 | resource->limit = 0xffffffffffULL; |
| 242 | resource->flags = IORESOURCE_MEM | IORESOURCE_BRIDGE; |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 243 | } |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | static u32 my_find_pci_tolm(struct bus *bus, u32 tolm) |
| 247 | { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 248 | struct resource *min; |
| 249 | min = 0; |
| 250 | search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test, |
| 251 | &min); |
| 252 | if (min && tolm > min->base) { |
| 253 | tolm = min->base; |
| 254 | } |
| 255 | return tolm; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
| 259 | |
| 260 | struct hw_mem_hole_info { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 261 | unsigned hole_startk; |
| 262 | int node_id; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 263 | }; |
| 264 | |
| 265 | static struct hw_mem_hole_info get_hw_mem_hole_info(void) |
| 266 | { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 267 | struct hw_mem_hole_info mem_hole; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 268 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 269 | mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK; |
| 270 | mem_hole.node_id = -1; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 271 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 272 | struct dram_base_mask_t d; |
| 273 | u32 hole; |
| 274 | d = get_dram_base_mask(0); |
| 275 | if (d.mask & 1) { |
| 276 | hole = pci_read_config32(__f1_dev[0], 0xf0); |
| 277 | if (hole & 1) { // we find the hole |
| 278 | mem_hole.hole_startk = (hole & (0xff << 24)) >> 10; |
| 279 | mem_hole.node_id = 0; // record the node No with hole |
| 280 | } |
| 281 | } |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 282 | return mem_hole; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 283 | } |
| 284 | #endif |
| 285 | |
Marc Jones | 8a49ac7 | 2013-01-16 17:02:20 -0700 | [diff] [blame] | 286 | static void nb_read_resources(device_t dev) |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 287 | { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 288 | u32 nodeid; |
| 289 | struct bus *link; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 290 | |
Mike Loptien | 58089e8 | 2013-01-29 15:45:09 -0700 | [diff] [blame] | 291 | printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 292 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 293 | nodeid = amdfam14_nodeid(dev); |
| 294 | for (link = dev->link_list; link; link = link->next) { |
| 295 | if (link->children) { |
| 296 | amdfam14_link_read_bases(dev, nodeid, link->link_num); |
| 297 | } |
| 298 | } |
Marc Jones | d5c998b | 2013-01-16 17:14:24 -0700 | [diff] [blame] | 299 | |
| 300 | /* |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 301 | * This MMCONF resource must be reserved in the PCI domain. |
Marc Jones | d5c998b | 2013-01-16 17:14:24 -0700 | [diff] [blame] | 302 | * It is not honored by the coreboot resource allocator if it is in |
Stefan Reinauer | 0aa37c4 | 2013-02-12 15:20:54 -0800 | [diff] [blame] | 303 | * the CPU_CLUSTER. |
Marc Jones | d5c998b | 2013-01-16 17:14:24 -0700 | [diff] [blame] | 304 | */ |
Kyösti Mälkki | e25b5ef | 2016-12-02 08:56:05 +0200 | [diff] [blame] | 305 | mmconf_resource(dev, 0xc0010058); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 308 | static void set_resource(device_t dev, struct resource *resource, u32 nodeid) |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 309 | { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 310 | resource_t rbase, rend; |
| 311 | unsigned reg, link_num; |
| 312 | char buf[50]; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 313 | |
Mike Loptien | 58089e8 | 2013-01-29 15:45:09 -0700 | [diff] [blame] | 314 | printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 315 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 316 | /* Make certain the resource has actually been set */ |
| 317 | if (!(resource->flags & IORESOURCE_ASSIGNED)) { |
| 318 | return; |
| 319 | } |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 320 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 321 | /* If I have already stored this resource don't worry about it */ |
| 322 | if (resource->flags & IORESOURCE_STORED) { |
| 323 | return; |
| 324 | } |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 325 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 326 | /* Only handle PCI memory and IO resources */ |
| 327 | if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO))) |
| 328 | return; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 329 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 330 | /* Ensure I am actually looking at a resource of function 1 */ |
| 331 | if ((resource->index & 0xffff) < 0x1000) { |
| 332 | return; |
| 333 | } |
| 334 | /* Get the base address */ |
| 335 | rbase = resource->base; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 336 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 337 | /* Get the limit (rounded up) */ |
| 338 | rend = resource_end(resource); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 339 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 340 | /* Get the register and link */ |
| 341 | reg = resource->index & 0xfff; // 4k |
| 342 | link_num = IOINDEX_LINK(resource->index); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 343 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 344 | if (resource->flags & IORESOURCE_IO) { |
| 345 | set_io_addr_reg(dev, nodeid, link_num, reg, rbase >> 8, |
| 346 | rend >> 8); |
| 347 | } else if (resource->flags & IORESOURCE_MEM) { |
| 348 | set_mmio_addr_reg(nodeid, link_num, reg, (resource->index >> 24), |
| 349 | rbase >> 8, rend >> 8, 1); // [39:8] |
| 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>", nodeid, link_num); |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 353 | report_resource_stored(dev, resource, buf); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 354 | } |
| 355 | |
efdesign98 | 3f5ebd6 | 2011-09-14 13:47:17 -0600 | [diff] [blame] | 356 | #if CONFIG_CONSOLE_VGA_MULTI |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 357 | extern device_t vga_pri; // the primary vga device, defined in device.c |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 358 | #endif |
| 359 | |
| 360 | static void create_vga_resource(device_t dev, unsigned nodeid) |
| 361 | { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 362 | struct bus *link; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 363 | |
Mike Loptien | 58089e8 | 2013-01-29 15:45:09 -0700 | [diff] [blame] | 364 | printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 365 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 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) { |
efdesign98 | 3f5ebd6 | 2011-09-14 13:47:17 -0600 | [diff] [blame] | 370 | #if CONFIG_CONSOLE_VGA_MULTI |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 371 | printk(BIOS_DEBUG, |
| 372 | "VGA: vga_pri bus num = %d bus range [%d,%d]\n", |
| 373 | vga_pri->bus->secondary, link->secondary, |
| 374 | link->subordinate); |
| 375 | /* We need to make sure the vga_pri is under the link */ |
| 376 | if ((vga_pri->bus->secondary >= link->secondary) && |
| 377 | (vga_pri->bus->secondary <= link->subordinate)) |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 378 | #endif |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 379 | break; |
| 380 | } |
| 381 | } |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 382 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 383 | /* no VGA card installed */ |
| 384 | if (link == NULL) |
| 385 | return; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 386 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 387 | printk(BIOS_DEBUG, "VGA: %s (aka node %d) link %d has VGA device\n", |
| 388 | dev_path(dev), nodeid, link->link_num); |
| 389 | set_vga_enable_reg(nodeid, link->link_num); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 390 | } |
| 391 | |
Marc Jones | 8a49ac7 | 2013-01-16 17:02:20 -0700 | [diff] [blame] | 392 | static void nb_set_resources(device_t dev) |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 393 | { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 394 | unsigned nodeid; |
| 395 | struct bus *bus; |
| 396 | struct resource *res; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 397 | |
Mike Loptien | 58089e8 | 2013-01-29 15:45:09 -0700 | [diff] [blame] | 398 | printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__); |
efdesign98 | 05a89ab | 2011-06-20 17:38:49 -0700 | [diff] [blame] | 399 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 400 | /* Find the nodeid */ |
| 401 | nodeid = amdfam14_nodeid(dev); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 402 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 403 | create_vga_resource(dev, nodeid); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 404 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 405 | /* Set each resource we have found */ |
| 406 | for (res = dev->resource_list; res; res = res->next) { |
| 407 | set_resource(dev, res, nodeid); |
| 408 | } |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 409 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 410 | for (bus = dev->link_list; bus; bus = bus->next) { |
| 411 | if (bus->children) { |
| 412 | assign_resources(bus); |
| 413 | } |
| 414 | } |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 415 | } |
| 416 | |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 417 | /* Domain/Root Complex related code */ |
| 418 | |
| 419 | static void domain_read_resources(device_t dev) |
| 420 | { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 421 | unsigned reg; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 422 | |
Mike Loptien | 58089e8 | 2013-01-29 15:45:09 -0700 | [diff] [blame] | 423 | printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 424 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 425 | /* Find the already assigned resource pairs */ |
| 426 | get_fx_devs(); |
| 427 | for (reg = 0x80; reg <= 0xc0; reg += 0x08) { |
| 428 | u32 base, limit; |
| 429 | base = f1_read_config32(reg); |
| 430 | limit = f1_read_config32(reg + 0x04); |
| 431 | /* Is this register allocated? */ |
| 432 | if ((base & 3) != 0) { |
| 433 | unsigned nodeid, reg_link; |
| 434 | device_t reg_dev; |
| 435 | if (reg < 0xc0) { // mmio |
| 436 | nodeid = (limit & 0xf) + (base & 0x30); |
| 437 | } else { // io |
| 438 | nodeid = (limit & 0xf) + ((base >> 4) & 0x30); |
| 439 | } |
| 440 | reg_link = (limit >> 4) & 7; |
| 441 | reg_dev = __f0_dev[nodeid]; |
| 442 | if (reg_dev) { |
| 443 | /* Reserve the resource */ |
| 444 | struct resource *res; |
| 445 | res = |
| 446 | new_resource(reg_dev, |
| 447 | IOINDEX(0x1000 + reg, |
| 448 | reg_link)); |
| 449 | if (res) { |
| 450 | res->flags = 1; |
| 451 | } |
| 452 | } |
| 453 | } |
| 454 | } |
| 455 | /* FIXME: do we need to check extend conf space? |
| 456 | I don't believe that much preset value */ |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 457 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 458 | pci_domain_read_resources(dev); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 459 | } |
| 460 | |
Kyösti Mälkki | 6b5eb1c | 2012-07-19 19:26:43 +0300 | [diff] [blame] | 461 | static void setup_uma_memory(void) |
Kyösti Mälkki | 55fff930 | 2012-07-11 08:02:39 +0300 | [diff] [blame] | 462 | { |
| 463 | #if CONFIG_GFXUMA |
Kyösti Mälkki | dbc4739 | 2012-08-05 12:11:40 +0300 | [diff] [blame] | 464 | uint32_t topmem = (uint32_t) bsp_topmem(); |
Kyösti Mälkki | 55fff930 | 2012-07-11 08:02:39 +0300 | [diff] [blame] | 465 | uint32_t sys_mem; |
| 466 | |
Kyösti Mälkki | 55fff930 | 2012-07-11 08:02:39 +0300 | [diff] [blame] | 467 | /* refer to UMA Size Consideration in Family14h BKDG. */ |
Kyösti Mälkki | dbc4739 | 2012-08-05 12:11:40 +0300 | [diff] [blame] | 468 | sys_mem = topmem + 0x1000000; // Ignore 16MB allocated for C6 when finding UMA size, refer MemNGetUmaSizeON() |
| 469 | if ((bsp_topmem2()>>32) || (sys_mem >= 0x80000000)) { |
Kyösti Mälkki | 55fff930 | 2012-07-11 08:02:39 +0300 | [diff] [blame] | 470 | uma_memory_size = 0x18000000; /* >= 2G memory, 384M recommended UMA */ |
| 471 | } |
| 472 | else { |
| 473 | if (sys_mem >= 0x40000000) { |
| 474 | uma_memory_size = 0x10000000; /* >= 1G memory, 256M recommended UMA */ |
| 475 | } else { |
| 476 | uma_memory_size = 0x4000000; /* <1G memory, 64M recommended UMA */ |
| 477 | } |
| 478 | } |
| 479 | |
Kyösti Mälkki | dbc4739 | 2012-08-05 12:11:40 +0300 | [diff] [blame] | 480 | uma_memory_base = topmem - uma_memory_size; /* TOP_MEM1 */ |
Kyösti Mälkki | 55fff930 | 2012-07-11 08:02:39 +0300 | [diff] [blame] | 481 | printk(BIOS_INFO, "%s: uma size 0x%08llx, memory start 0x%08llx\n", |
| 482 | __func__, uma_memory_size, uma_memory_base); |
Kyösti Mälkki | 55fff930 | 2012-07-11 08:02:39 +0300 | [diff] [blame] | 483 | #endif |
| 484 | } |
| 485 | |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 486 | static void domain_set_resources(device_t dev) |
| 487 | { |
Mike Loptien | 58089e8 | 2013-01-29 15:45:09 -0700 | [diff] [blame] | 488 | printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__); |
Stefan Reinauer | 29e6548 | 2015-06-18 01:18:09 -0700 | [diff] [blame] | 489 | printk(BIOS_DEBUG, " amsr - incoming dev = %p\n", dev); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 490 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 491 | unsigned long mmio_basek; |
| 492 | u32 pci_tolm; |
Kyösti Mälkki | 2b790f6 | 2013-09-03 05:25:57 +0300 | [diff] [blame] | 493 | u64 ramtop = 0; |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 494 | int idx; |
| 495 | struct bus *link; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 496 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 497 | struct hw_mem_hole_info mem_hole; |
| 498 | u32 reset_memhole = 1; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 499 | #endif |
| 500 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 501 | pci_tolm = 0xffffffffUL; |
| 502 | for (link = dev->link_list; link; link = link->next) { |
| 503 | pci_tolm = my_find_pci_tolm(link, pci_tolm); |
| 504 | } |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 505 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 506 | // FIXME handle interleaved nodes. If you fix this here, please fix |
| 507 | // amdk8, too. |
| 508 | mmio_basek = pci_tolm >> 10; |
| 509 | /* Round mmio_basek to something the processor can support */ |
| 510 | mmio_basek &= ~((1 << 6) - 1); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 511 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 512 | // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M |
| 513 | // MMIO hole. If you fix this here, please fix amdk8, too. |
| 514 | /* Round the mmio hole to 64M */ |
| 515 | mmio_basek &= ~((64 * 1024) - 1); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 516 | |
| 517 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
| 518 | /* if the hw mem hole is already set in raminit stage, here we will compare |
| 519 | * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will |
| 520 | * use hole_basek as mmio_basek and we don't need to reset hole. |
| 521 | * otherwise We reset the hole to the mmio_basek |
| 522 | */ |
| 523 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 524 | mem_hole = get_hw_mem_hole_info(); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 525 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 526 | // Use hole_basek as mmio_basek, and we don't need to reset hole anymore |
| 527 | if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) { |
| 528 | mmio_basek = mem_hole.hole_startk; |
| 529 | reset_memhole = 0; |
| 530 | } |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 531 | #endif |
| 532 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 533 | idx = 0x10; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 534 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 535 | struct dram_base_mask_t d; |
| 536 | resource_t basek, limitk, sizek; // 4 1T |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 537 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 538 | d = get_dram_base_mask(0); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 539 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 540 | if (d.mask & 1) { |
| 541 | basek = ((resource_t) ((u64) d.base)) << 8; |
| 542 | limitk = (resource_t) (((u64) d.mask << 8) | 0xFFFFFF); |
| 543 | printk(BIOS_DEBUG, |
| 544 | "adsr: (before) basek = %llx, limitk = %llx.\n", basek, |
| 545 | limitk); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 546 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 547 | /* Convert these values to multiples of 1K for ease of math. */ |
| 548 | basek >>= 10; |
| 549 | limitk >>= 10; |
| 550 | sizek = limitk - basek + 1; |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 551 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 552 | printk(BIOS_DEBUG, |
| 553 | "adsr: (after) basek = %llx, limitk = %llx, sizek = %llx.\n", |
| 554 | basek, limitk, sizek); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 555 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 556 | /* see if we need a hole from 0xa0000 to 0xbffff */ |
| 557 | if ((basek < 640) && (sizek > 768)) { |
| 558 | printk(BIOS_DEBUG,"adsr - 0xa0000 to 0xbffff resource.\n"); |
| 559 | ram_resource(dev, (idx | 0), basek, 640 - basek); |
| 560 | idx += 0x10; |
| 561 | basek = 768; |
| 562 | sizek = limitk - 768; |
| 563 | } |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 564 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 565 | printk(BIOS_DEBUG, |
| 566 | "adsr: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", |
| 567 | mmio_basek, basek, limitk); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 568 | |
Kyösti Mälkki | 26c6543 | 2014-06-26 05:30:54 +0300 | [diff] [blame] | 569 | /* split the region to accommodate pci memory space */ |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 570 | if ((basek < 4 * 1024 * 1024) && (limitk > mmio_basek)) { |
| 571 | if (basek <= mmio_basek) { |
| 572 | unsigned pre_sizek; |
| 573 | pre_sizek = mmio_basek - basek; |
| 574 | if (pre_sizek > 0) { |
| 575 | ram_resource(dev, idx, basek, |
| 576 | pre_sizek); |
| 577 | idx += 0x10; |
| 578 | sizek -= pre_sizek; |
Kyösti Mälkki | 2b790f6 | 2013-09-03 05:25:57 +0300 | [diff] [blame] | 579 | if (!ramtop) |
| 580 | ramtop = mmio_basek * 1024; |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 581 | } |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 582 | basek = mmio_basek; |
| 583 | } |
| 584 | if ((basek + sizek) <= 4 * 1024 * 1024) { |
| 585 | sizek = 0; |
| 586 | } else { |
| 587 | basek = 4 * 1024 * 1024; |
| 588 | sizek -= (4 * 1024 * 1024 - mmio_basek); |
| 589 | } |
| 590 | } |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 591 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 592 | ram_resource(dev, (idx | 0), basek, sizek); |
| 593 | idx += 0x10; |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 594 | printk(BIOS_DEBUG, |
| 595 | "%d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", 0, |
| 596 | mmio_basek, basek, limitk); |
Kyösti Mälkki | 2b790f6 | 2013-09-03 05:25:57 +0300 | [diff] [blame] | 597 | if (!ramtop) |
| 598 | ramtop = limitk * 1024; |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 599 | } |
| 600 | printk(BIOS_DEBUG, " adsr - mmio_basek = %lx.\n", mmio_basek); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 601 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 602 | #if CONFIG_GFXUMA |
Kyösti Mälkki | 2b790f6 | 2013-09-03 05:25:57 +0300 | [diff] [blame] | 603 | set_top_of_ram(uma_memory_base); |
Kyösti Mälkki | 63f8c08 | 2012-07-10 13:27:26 +0300 | [diff] [blame] | 604 | 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] | 605 | #else |
| 606 | set_top_of_ram(ramtop); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 607 | #endif |
| 608 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 609 | for (link = dev->link_list; link; link = link->next) { |
| 610 | if (link->children) { |
| 611 | assign_resources(link); |
| 612 | } |
| 613 | } |
| 614 | printk(BIOS_DEBUG, " adsr - leaving this lovely routine.\n"); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 615 | } |
| 616 | |
zbao | f722373 | 2012-04-13 13:42:15 +0800 | [diff] [blame] | 617 | static void domain_enable_resources(device_t dev) |
| 618 | { |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 619 | #if CONFIG_AMD_SB_CIMX |
Kyösti Mälkki | c551caa | 2014-06-20 12:31:23 +0300 | [diff] [blame] | 620 | if (!acpi_is_wakeup_s3()) { |
zbao | f722373 | 2012-04-13 13:42:15 +0800 | [diff] [blame] | 621 | sb_After_Pci_Init(); |
| 622 | sb_Mid_Post_Init(); |
| 623 | } else { |
| 624 | sb_After_Pci_Restore_Init(); |
| 625 | } |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 626 | #endif |
| 627 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 628 | /* Must be called after PCI enumeration and resource allocation */ |
Mike Loptien | 58089e8 | 2013-01-29 15:45:09 -0700 | [diff] [blame] | 629 | printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__); |
zbao | f722373 | 2012-04-13 13:42:15 +0800 | [diff] [blame] | 630 | |
Kyösti Mälkki | b139b5e | 2014-10-20 07:41:20 +0300 | [diff] [blame] | 631 | if (!acpi_is_wakeup_s3()) { |
| 632 | /* Enable MMIO on AMD CPU Address Map Controller */ |
Kyösti Mälkki | 48518f0 | 2014-11-25 14:20:57 +0200 | [diff] [blame] | 633 | amd_initcpuio(); |
Kyösti Mälkki | b139b5e | 2014-10-20 07:41:20 +0300 | [diff] [blame] | 634 | |
Kyösti Mälkki | 1aa35c6 | 2014-10-21 14:19:04 +0300 | [diff] [blame] | 635 | agesawrapper_amdinitmid(); |
Kyösti Mälkki | b139b5e | 2014-10-20 07:41:20 +0300 | [diff] [blame] | 636 | } |
efdesign98 | 05a89ab | 2011-06-20 17:38:49 -0700 | [diff] [blame] | 637 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 638 | printk(BIOS_DEBUG, " ader - leaving domain_enable_resources.\n"); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 639 | } |
| 640 | |
Tobias Diedrich | d8a2c1f | 2017-02-20 02:46:19 +0100 | [diff] [blame^] | 641 | static const char *domain_acpi_name(struct device *dev) |
| 642 | { |
| 643 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
| 644 | return "PCI0"; |
| 645 | |
| 646 | return NULL; |
| 647 | } |
| 648 | |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 649 | /* Bus related code */ |
| 650 | |
Kyösti Mälkki | 580e722 | 2015-03-19 21:04:23 +0200 | [diff] [blame] | 651 | static void cpu_bus_scan(struct device *dev) |
zbao | f722373 | 2012-04-13 13:42:15 +0800 | [diff] [blame] | 652 | { |
Kyösti Mälkki | c33f1e9 | 2012-08-07 17:12:11 +0300 | [diff] [blame] | 653 | struct bus *cpu_bus = dev->link_list; |
Scott Duplichan | 9ab3c6c | 2011-05-15 21:45:46 +0000 | [diff] [blame] | 654 | device_t cpu; |
zbao | f722373 | 2012-04-13 13:42:15 +0800 | [diff] [blame] | 655 | int apic_id, cores_found; |
Scott Duplichan | 9ab3c6c | 2011-05-15 21:45:46 +0000 | [diff] [blame] | 656 | |
zbao | f722373 | 2012-04-13 13:42:15 +0800 | [diff] [blame] | 657 | /* There is only one node for fam14, but there may be multiple cores. */ |
| 658 | cpu = dev_find_slot(0, PCI_DEVFN(0x18, 0)); |
| 659 | if (!cpu) |
| 660 | printk(BIOS_ERR, "ERROR: %02x:%02x.0 not found", 0, 0x18); |
Scott Duplichan | 9ab3c6c | 2011-05-15 21:45:46 +0000 | [diff] [blame] | 661 | |
zbao | f722373 | 2012-04-13 13:42:15 +0800 | [diff] [blame] | 662 | cores_found = (pci_read_config32(dev_find_slot(0,PCI_DEVFN(0x18,0x3)), 0xe8) >> 12) & 3; |
| 663 | printk(BIOS_DEBUG, " AP siblings=%d\n", cores_found); |
| 664 | |
zbao | f722373 | 2012-04-13 13:42:15 +0800 | [diff] [blame] | 665 | for (apic_id = 0; apic_id <= cores_found; apic_id++) { |
Kyösti Mälkki | c33f1e9 | 2012-08-07 17:12:11 +0300 | [diff] [blame] | 666 | cpu = add_cpu_device(cpu_bus, apic_id, 1); |
| 667 | if (cpu) |
| 668 | amd_cpu_topology(cpu, 0, apic_id); |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 669 | } |
zbao | f722373 | 2012-04-13 13:42:15 +0800 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | static void cpu_bus_init(device_t dev) |
| 673 | { |
| 674 | initialize_cpus(dev->link_list); |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 675 | } |
| 676 | |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 677 | /* North Bridge Structures */ |
| 678 | |
Alexander Couzens | 5eea458 | 2015-04-12 22:18:55 +0200 | [diff] [blame] | 679 | static void northbridge_fill_ssdt_generator(device_t device) |
Vladimir Serbinenko | 4ab588b | 2014-10-08 21:18:31 +0200 | [diff] [blame] | 680 | { |
| 681 | msr_t msr; |
| 682 | char pscope[] = "\\_SB.PCI0"; |
| 683 | |
| 684 | acpigen_write_scope(pscope); |
| 685 | msr = rdmsr(TOP_MEM); |
| 686 | acpigen_write_name_dword("TOM1", msr.lo); |
| 687 | msr = rdmsr(TOP_MEM2); |
| 688 | /* |
| 689 | * Since XP only implements parts of ACPI 2.0, we can't use a qword |
| 690 | * here. |
| 691 | * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt |
| 692 | * slide 22ff. |
| 693 | * Shift value right by 20 bit to make it fit into 32bit, |
| 694 | * giving us 1MB granularity and a limit of almost 4Exabyte of memory. |
| 695 | */ |
| 696 | acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20); |
| 697 | acpigen_pop_len(); |
| 698 | } |
| 699 | |
Vladimir Serbinenko | 807127f | 2014-11-09 13:36:18 +0100 | [diff] [blame] | 700 | static unsigned long acpi_fill_hest(acpi_hest_t *hest) |
Vladimir Serbinenko | 4ab588b | 2014-10-08 21:18:31 +0200 | [diff] [blame] | 701 | { |
| 702 | void *addr, *current; |
| 703 | |
| 704 | /* Skip the HEST header. */ |
| 705 | current = (void *)(hest + 1); |
| 706 | |
| 707 | addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE); |
| 708 | if (addr != NULL) |
Stefan Reinauer | 29e6548 | 2015-06-18 01:18:09 -0700 | [diff] [blame] | 709 | current += acpi_create_hest_error_source(hest, current, 0, |
| 710 | addr + 2, *(UINT16 *)addr - 2); |
Vladimir Serbinenko | 4ab588b | 2014-10-08 21:18:31 +0200 | [diff] [blame] | 711 | |
| 712 | addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC); |
| 713 | if (addr != NULL) |
Stefan Reinauer | 29e6548 | 2015-06-18 01:18:09 -0700 | [diff] [blame] | 714 | current += acpi_create_hest_error_source(hest, current, 1, |
| 715 | addr + 2, *(UINT16 *)addr - 2); |
Vladimir Serbinenko | 4ab588b | 2014-10-08 21:18:31 +0200 | [diff] [blame] | 716 | |
| 717 | return (unsigned long)current; |
| 718 | } |
| 719 | |
Alexander Couzens | 83fc32f | 2015-04-12 22:28:37 +0200 | [diff] [blame] | 720 | static unsigned long agesa_write_acpi_tables(device_t device, |
| 721 | unsigned long current, |
Vladimir Serbinenko | 4ab588b | 2014-10-08 21:18:31 +0200 | [diff] [blame] | 722 | acpi_rsdp_t *rsdp) |
| 723 | { |
| 724 | acpi_srat_t *srat; |
| 725 | acpi_slit_t *slit; |
| 726 | acpi_header_t *ssdt; |
| 727 | acpi_header_t *alib; |
| 728 | acpi_hest_t *hest; |
| 729 | |
| 730 | /* HEST */ |
| 731 | current = ALIGN(current, 8); |
| 732 | hest = (acpi_hest_t *)current; |
Vladimir Serbinenko | 807127f | 2014-11-09 13:36:18 +0100 | [diff] [blame] | 733 | acpi_write_hest((void *)current, acpi_fill_hest); |
Vladimir Serbinenko | 4ab588b | 2014-10-08 21:18:31 +0200 | [diff] [blame] | 734 | acpi_add_table(rsdp, (void *)current); |
| 735 | current += ((acpi_header_t *)current)->length; |
| 736 | |
| 737 | /* SRAT */ |
| 738 | current = ALIGN(current, 8); |
| 739 | printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current); |
| 740 | srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT); |
| 741 | if (srat != NULL) { |
| 742 | memcpy((void *)current, srat, srat->header.length); |
| 743 | srat = (acpi_srat_t *) current; |
| 744 | current += srat->header.length; |
| 745 | acpi_add_table(rsdp, srat); |
| 746 | } |
| 747 | else { |
| 748 | printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n"); |
| 749 | } |
| 750 | |
| 751 | /* SLIT */ |
| 752 | current = ALIGN(current, 8); |
| 753 | printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current); |
| 754 | slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT); |
| 755 | if (slit != NULL) { |
| 756 | memcpy((void *)current, slit, slit->header.length); |
| 757 | slit = (acpi_slit_t *) current; |
| 758 | current += slit->header.length; |
| 759 | acpi_add_table(rsdp, slit); |
| 760 | } |
| 761 | else { |
| 762 | printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n"); |
| 763 | } |
| 764 | |
| 765 | /* SSDT */ |
| 766 | current = ALIGN(current, 16); |
| 767 | printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current); |
| 768 | alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB); |
| 769 | if (alib != NULL) { |
| 770 | memcpy((void *)current, alib, alib->length); |
| 771 | alib = (acpi_header_t *) current; |
| 772 | current += alib->length; |
| 773 | acpi_add_table(rsdp, (void *)alib); |
| 774 | } else { |
| 775 | printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n"); |
| 776 | } |
| 777 | |
| 778 | /* The DSDT needs additional work for the AGESA SSDT Pstate table */ |
| 779 | /* Keep the comment for a while. */ |
| 780 | current = ALIGN(current, 16); |
| 781 | printk(BIOS_DEBUG, "ACPI: * AGESA SSDT Pstate at %lx\n", current); |
| 782 | ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE); |
| 783 | if (ssdt != NULL) { |
| 784 | memcpy((void *)current, ssdt, ssdt->length); |
| 785 | ssdt = (acpi_header_t *) current; |
| 786 | current += ssdt->length; |
| 787 | acpi_add_table(rsdp,ssdt); |
| 788 | } else { |
| 789 | printk(BIOS_DEBUG, " AGESA SSDT Pstate table NULL. Skipping.\n"); |
| 790 | } |
| 791 | |
| 792 | return current; |
| 793 | } |
| 794 | |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 795 | static struct device_operations northbridge_operations = { |
Marc Jones | 8a49ac7 | 2013-01-16 17:02:20 -0700 | [diff] [blame] | 796 | .read_resources = nb_read_resources, |
| 797 | .set_resources = nb_set_resources, |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 798 | .enable_resources = pci_dev_enable_resources, |
Vladimir Serbinenko | 4ab588b | 2014-10-08 21:18:31 +0200 | [diff] [blame] | 799 | .acpi_fill_ssdt_generator = northbridge_fill_ssdt_generator, |
| 800 | .write_acpi_tables = agesa_write_acpi_tables, |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 801 | .init = northbridge_init, |
| 802 | .enable = 0,.ops_pci = 0, |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 803 | }; |
| 804 | |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 805 | static const struct pci_driver northbridge_driver __pci_driver = { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 806 | .ops = &northbridge_operations, |
| 807 | .vendor = PCI_VENDOR_ID_AMD, |
| 808 | .device = 0x1510, |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 809 | }; |
| 810 | |
efdesign98 | 05a89ab | 2011-06-20 17:38:49 -0700 | [diff] [blame] | 811 | struct chip_operations northbridge_amd_agesa_family14_ops = { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 812 | CHIP_NAME("AMD Family 14h Northbridge") |
| 813 | .enable_dev = 0, |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 814 | }; |
| 815 | |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 816 | /* Root Complex Structures */ |
| 817 | |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 818 | static struct device_operations pci_domain_ops = { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 819 | .read_resources = domain_read_resources, |
| 820 | .set_resources = domain_set_resources, |
| 821 | .enable_resources = domain_enable_resources, |
Edward O'Callaghan | e9e1d7a | 2015-01-02 15:11:49 +1100 | [diff] [blame] | 822 | .init = DEVICE_NOOP, |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 823 | .scan_bus = pci_domain_scan_bus, |
Tobias Diedrich | d8a2c1f | 2017-02-20 02:46:19 +0100 | [diff] [blame^] | 824 | .acpi_name = domain_acpi_name, |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 825 | }; |
| 826 | |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 827 | static struct device_operations cpu_bus_ops = { |
Edward O'Callaghan | 2837ab2 | 2014-11-06 08:57:40 +1100 | [diff] [blame] | 828 | .read_resources = DEVICE_NOOP, |
| 829 | .set_resources = DEVICE_NOOP, |
Edward O'Callaghan | e9e1d7a | 2015-01-02 15:11:49 +1100 | [diff] [blame] | 830 | .enable_resources = DEVICE_NOOP, |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 831 | .init = cpu_bus_init, |
zbao | f722373 | 2012-04-13 13:42:15 +0800 | [diff] [blame] | 832 | .scan_bus = cpu_bus_scan, |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 833 | }; |
| 834 | |
Kyösti Mälkki | 87213b6 | 2012-08-27 20:00:33 +0300 | [diff] [blame] | 835 | static void root_complex_enable_dev(struct device *dev) |
| 836 | { |
| 837 | static int done = 0; |
| 838 | |
| 839 | /* Do not delay UMA setup, as a device on the PCI bus may evaluate |
| 840 | the global uma_memory variables already in its enable function. */ |
| 841 | if (!done) { |
| 842 | setup_bsp_ramtop(); |
| 843 | setup_uma_memory(); |
| 844 | done = 1; |
| 845 | } |
| 846 | |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 847 | /* Set the operations if it is a special bus type */ |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 848 | if (dev->path.type == DEVICE_PATH_DOMAIN) { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 849 | dev->ops = &pci_domain_ops; |
Stefan Reinauer | 0aa37c4 | 2013-02-12 15:20:54 -0800 | [diff] [blame] | 850 | } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 851 | dev->ops = &cpu_bus_ops; |
| 852 | } |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 853 | } |
| 854 | |
efdesign98 | 05a89ab | 2011-06-20 17:38:49 -0700 | [diff] [blame] | 855 | struct chip_operations northbridge_amd_agesa_family14_root_complex_ops = { |
Marc Jones | 8d59569 | 2012-03-15 12:55:26 -0600 | [diff] [blame] | 856 | CHIP_NAME("AMD Family 14h Root Complex") |
| 857 | .enable_dev = root_complex_enable_dev, |
Frank Vibrans | 39fca80 | 2011-02-14 18:35:15 +0000 | [diff] [blame] | 858 | }; |