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