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