Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2012 Advanced Micro Devices, Inc. |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 5 | * Copyright (C) 2016 Raptor Engineering, LLC |
| 6 | * Copyright (C) 2018 3mdeb Embedded Systems Consulting |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; version 2 of the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <console/console.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 19 | #include <device/pci_ops.h> |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 20 | #include <arch/acpi.h> |
| 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> |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 26 | #include <string.h> |
| 27 | #include <lib.h> |
| 28 | #include <cpu/cpu.h> |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 29 | #include <Porting.h> |
| 30 | #include <AGESA.h> |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 31 | #include <Topology.h> |
Elyes HAOUAS | 400ce55 | 2018-10-12 10:54:30 +0200 | [diff] [blame] | 32 | #include <cpu/x86/lapic.h> |
| 33 | #include <cpu/amd/msr.h> |
| 34 | #include <cpu/amd/mtrr.h> |
Elyes HAOUAS | 400ce55 | 2018-10-12 10:54:30 +0200 | [diff] [blame] | 35 | #include <arch/acpigen.h> |
Kyösti Mälkki | bbd2377 | 2019-01-10 05:41:23 +0200 | [diff] [blame] | 36 | #include <northbridge/amd/pi/nb_common.h> |
Kyösti Mälkki | ed8d277 | 2017-07-15 17:12:44 +0300 | [diff] [blame] | 37 | #include <northbridge/amd/agesa/agesa_helper.h> |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 38 | |
Kyösti Mälkki | 113f670 | 2018-05-20 20:12:32 +0300 | [diff] [blame] | 39 | #define MAX_NODE_NUMS MAX_NODES |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 40 | |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 41 | typedef struct dram_base_mask { |
| 42 | u32 base; //[47:27] at [28:8] |
| 43 | u32 mask; //[47:27] at [28:8] and enable at bit 0 |
| 44 | } dram_base_mask_t; |
| 45 | |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 46 | static unsigned int node_nums; |
| 47 | static unsigned int sblink; |
Kyösti Mälkki | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 48 | static struct device *__f0_dev[MAX_NODE_NUMS]; |
| 49 | static struct device *__f1_dev[MAX_NODE_NUMS]; |
| 50 | static struct device *__f2_dev[MAX_NODE_NUMS]; |
| 51 | static struct device *__f4_dev[MAX_NODE_NUMS]; |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 52 | static unsigned int fx_devs = 0; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 53 | |
| 54 | static dram_base_mask_t get_dram_base_mask(u32 nodeid) |
| 55 | { |
Kyösti Mälkki | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 56 | struct device *dev; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 57 | dram_base_mask_t d; |
| 58 | dev = __f1_dev[0]; |
| 59 | u32 temp; |
| 60 | temp = pci_read_config32(dev, 0x44 + (nodeid << 3)); //[39:24] at [31:16] |
| 61 | d.mask = ((temp & 0xfff80000)>>(8+3)); // mask out DramMask [26:24] too |
| 62 | temp = pci_read_config32(dev, 0x144 + (nodeid <<3)) & 0xff; //[47:40] at [7:0] |
| 63 | d.mask |= temp<<21; |
| 64 | temp = pci_read_config32(dev, 0x40 + (nodeid << 3)); //[39:24] at [31:16] |
| 65 | d.mask |= (temp & 1); // enable bit |
| 66 | d.base = ((temp & 0xfff80000)>>(8+3)); // mask out DramBase [26:24) too |
| 67 | temp = pci_read_config32(dev, 0x140 + (nodeid <<3)) & 0xff; //[47:40] at [7:0] |
| 68 | d.base |= temp<<21; |
| 69 | return d; |
| 70 | } |
| 71 | |
Kyösti Mälkki | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 72 | static void set_io_addr_reg(struct device *dev, u32 nodeid, u32 linkn, u32 reg, |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 73 | u32 io_min, u32 io_max) |
| 74 | { |
| 75 | u32 i; |
| 76 | u32 tempreg; |
| 77 | /* io range allocation */ |
| 78 | tempreg = (nodeid&0xf) | ((nodeid & 0x30)<<(8-4)) | (linkn<<4) | ((io_max&0xf0)<<(12-4)); //limit |
Elyes HAOUAS | a813160 | 2016-09-19 10:27:57 -0600 | [diff] [blame] | 79 | for (i = 0; i < node_nums; i++) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 80 | pci_write_config32(__f1_dev[i], reg+4, tempreg); |
Elyes HAOUAS | a813160 | 2016-09-19 10:27:57 -0600 | [diff] [blame] | 81 | tempreg = 3 /*| (3<<4)*/ | ((io_min&0xf0)<<(12-4)); //base :ISA and VGA ? |
Elyes HAOUAS | a813160 | 2016-09-19 10:27:57 -0600 | [diff] [blame] | 82 | for (i = 0; i < node_nums; i++) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 83 | pci_write_config32(__f1_dev[i], reg, tempreg); |
| 84 | } |
| 85 | |
| 86 | static void set_mmio_addr_reg(u32 nodeid, u32 linkn, u32 reg, u32 index, u32 mmio_min, u32 mmio_max, u32 nodes) |
| 87 | { |
| 88 | u32 i; |
| 89 | u32 tempreg; |
| 90 | /* io range allocation */ |
| 91 | tempreg = (nodeid&0xf) | (linkn<<4) | (mmio_max&0xffffff00); //limit |
Elyes HAOUAS | a813160 | 2016-09-19 10:27:57 -0600 | [diff] [blame] | 92 | for (i = 0; i < nodes; i++) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 93 | pci_write_config32(__f1_dev[i], reg+4, tempreg); |
| 94 | tempreg = 3 | (nodeid & 0x30) | (mmio_min&0xffffff00); |
Elyes HAOUAS | a813160 | 2016-09-19 10:27:57 -0600 | [diff] [blame] | 95 | for (i = 0; i < node_nums; i++) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 96 | pci_write_config32(__f1_dev[i], reg, tempreg); |
| 97 | } |
| 98 | |
Kyösti Mälkki | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 99 | static struct device *get_node_pci(u32 nodeid, u32 fn) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 100 | { |
Kyösti Mälkki | bbd2377 | 2019-01-10 05:41:23 +0200 | [diff] [blame] | 101 | return pcidev_on_root(DEV_CDB + nodeid, fn); |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | static void get_fx_devs(void) |
| 105 | { |
| 106 | int i; |
| 107 | for (i = 0; i < MAX_NODE_NUMS; i++) { |
| 108 | __f0_dev[i] = get_node_pci(i, 0); |
| 109 | __f1_dev[i] = get_node_pci(i, 1); |
| 110 | __f2_dev[i] = get_node_pci(i, 2); |
| 111 | __f4_dev[i] = get_node_pci(i, 4); |
| 112 | if (__f0_dev[i] != NULL && __f1_dev[i] != NULL) |
| 113 | fx_devs = i+1; |
| 114 | } |
| 115 | if (__f1_dev[0] == NULL || __f0_dev[0] == NULL || fx_devs == 0) { |
| 116 | die("Cannot find 0:0x18.[0|1]\n"); |
| 117 | } |
Elyes HAOUAS | a813160 | 2016-09-19 10:27:57 -0600 | [diff] [blame] | 118 | printk(BIOS_DEBUG, "fx_devs = 0x%x\n", fx_devs); |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 119 | } |
| 120 | |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 121 | static u32 f1_read_config32(unsigned int reg) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 122 | { |
| 123 | if (fx_devs == 0) |
| 124 | get_fx_devs(); |
| 125 | return pci_read_config32(__f1_dev[0], reg); |
| 126 | } |
| 127 | |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 128 | static void f1_write_config32(unsigned int reg, u32 value) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 129 | { |
| 130 | int i; |
| 131 | if (fx_devs == 0) |
| 132 | get_fx_devs(); |
Elyes HAOUAS | 5a7e72f | 2016-08-23 21:36:02 +0200 | [diff] [blame] | 133 | for (i = 0; i < fx_devs; i++) { |
Kyösti Mälkki | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 134 | struct device *dev; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 135 | dev = __f1_dev[i]; |
| 136 | if (dev && dev->enabled) { |
| 137 | pci_write_config32(dev, reg, value); |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | |
Kyösti Mälkki | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 142 | static u32 amdfam16_nodeid(struct device *dev) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 143 | { |
Kyösti Mälkki | bbd2377 | 2019-01-10 05:41:23 +0200 | [diff] [blame] | 144 | return (dev->path.pci.devfn >> 3) - DEV_CDB; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | static void set_vga_enable_reg(u32 nodeid, u32 linkn) |
| 148 | { |
| 149 | u32 val; |
| 150 | |
| 151 | val = 1 | (nodeid<<4) | (linkn<<12); |
| 152 | /* it will routing |
| 153 | * (1)mmio 0xa0000:0xbffff |
| 154 | * (2)io 0x3b0:0x3bb, 0x3c0:0x3df |
| 155 | */ |
| 156 | f1_write_config32(0xf4, val); |
| 157 | |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * @return |
Elyes HAOUAS | 99b075a | 2019-12-30 14:29:31 +0100 | [diff] [blame^] | 162 | * @retval 2 resource does not exist, usable |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 163 | * @retval 0 resource exists, not usable |
| 164 | * @retval 1 resource exist, resource has been allocated before |
| 165 | */ |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 166 | static int reg_useable(unsigned int reg, struct device *goal_dev, |
| 167 | unsigned int goal_nodeid, unsigned int goal_link) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 168 | { |
| 169 | struct resource *res; |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 170 | unsigned int nodeid, link = 0; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 171 | int result; |
| 172 | res = 0; |
| 173 | for (nodeid = 0; !res && (nodeid < fx_devs); nodeid++) { |
Kyösti Mälkki | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 174 | struct device *dev; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 175 | dev = __f0_dev[nodeid]; |
| 176 | if (!dev) |
| 177 | continue; |
| 178 | for (link = 0; !res && (link < 8); link++) { |
| 179 | res = probe_resource(dev, IOINDEX(0x1000 + reg, link)); |
| 180 | } |
| 181 | } |
| 182 | result = 2; |
| 183 | if (res) { |
| 184 | result = 0; |
| 185 | if ((goal_link == (link - 1)) && |
| 186 | (goal_nodeid == (nodeid - 1)) && |
| 187 | (res->flags <= 1)) { |
| 188 | result = 1; |
| 189 | } |
| 190 | } |
| 191 | return result; |
| 192 | } |
| 193 | |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 194 | static struct resource *amdfam16_find_iopair(struct device *dev, |
| 195 | unsigned int nodeid, unsigned int link) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [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 | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 222 | static struct resource *amdfam16_find_mempair(struct device *dev, u32 nodeid, u32 link) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [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 | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 248 | static void amdfam16_link_read_bases(struct device *dev, u32 nodeid, u32 link) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 249 | { |
| 250 | struct resource *resource; |
| 251 | |
| 252 | /* Initialize the io space constraints on the current bus */ |
| 253 | resource = amdfam16_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 = amdfam16_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 = amdfam16_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 | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 290 | static void read_resources(struct device *dev) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 291 | { |
| 292 | u32 nodeid; |
| 293 | struct bus *link; |
| 294 | |
| 295 | nodeid = amdfam16_nodeid(dev); |
| 296 | for (link = dev->link_list; link; link = link->next) { |
| 297 | if (link->children) { |
| 298 | amdfam16_link_read_bases(dev, nodeid, link->link_num); |
| 299 | } |
| 300 | } |
Kyösti Mälkki | 5d49038 | 2015-05-27 07:58:22 +0300 | [diff] [blame] | 301 | |
| 302 | /* |
| 303 | * This MMCONF resource must be reserved in the PCI domain. |
| 304 | * It is not honored by the coreboot resource allocator if it is in |
| 305 | * the CPU_CLUSTER. |
| 306 | */ |
Elyes HAOUAS | 400ce55 | 2018-10-12 10:54:30 +0200 | [diff] [blame] | 307 | mmconf_resource(dev, MMIO_CONF_BASE); |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 308 | } |
| 309 | |
Kyösti Mälkki | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 310 | static void set_resource(struct device *dev, struct resource *resource, u32 nodeid) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 311 | { |
| 312 | resource_t rbase, rend; |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 313 | unsigned int reg, link_num; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 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) { |
Elyes HAOUAS | 7db506c | 2016-10-02 11:56:39 +0200 | [diff] [blame] | 348 | set_mmio_addr_reg(nodeid, link_num, reg, (resource->index >>24), rbase>>8, rend>>8, node_nums); // [39:8] |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [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>", |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [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 | |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 361 | static void create_vga_resource(struct device *dev, unsigned int nodeid) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [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) { |
Julius Werner | cd49cce | 2019-03-05 16:53:33 -0800 | [diff] [blame] | 369 | #if CONFIG(MULTIPLE_VGA_ADAPTERS) |
Kyösti Mälkki | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 370 | extern struct device *vga_pri; // the primary vga device, defined in device.c |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [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 | a813160 | 2016-09-19 10:27:57 -0600 | [diff] [blame] | 374 | if ((vga_pri->bus->secondary >= link->secondary) && |
| 375 | (vga_pri->bus->secondary <= link->subordinate)) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [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 | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 389 | static void set_resources(struct device *dev) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 390 | { |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 391 | unsigned int nodeid; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 392 | struct bus *bus; |
| 393 | struct resource *res; |
| 394 | |
| 395 | /* Find the nodeid */ |
| 396 | nodeid = amdfam16_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 | |
| 412 | static void northbridge_init(struct device *dev) |
| 413 | { |
| 414 | } |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 415 | |
Vladimir Serbinenko | 807127f | 2014-11-09 13:36:18 +0100 | [diff] [blame] | 416 | static unsigned long acpi_fill_hest(acpi_hest_t *hest) |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 417 | { |
| 418 | void *addr, *current; |
| 419 | |
| 420 | /* Skip the HEST header. */ |
| 421 | current = (void *)(hest + 1); |
| 422 | |
| 423 | addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE); |
| 424 | if (addr != NULL) |
| 425 | current += acpi_create_hest_error_source(hest, current, 0, (void *)((u32)addr + 2), *(UINT16 *)addr - 2); |
| 426 | |
| 427 | addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC); |
| 428 | if (addr != NULL) |
| 429 | current += acpi_create_hest_error_source(hest, current, 1, (void *)((u32)addr + 2), *(UINT16 *)addr - 2); |
| 430 | |
| 431 | return (unsigned long)current; |
| 432 | } |
| 433 | |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 434 | static void add_ivhd_dev_entry(struct device *parent, struct device *dev, |
| 435 | unsigned long *current, uint16_t *length, |
| 436 | uint8_t type, uint8_t data) |
| 437 | { |
| 438 | uint8_t *p; |
| 439 | p = (uint8_t *) *current; |
| 440 | |
| 441 | if (type == 0x2) { |
| 442 | /* Entry type */ |
| 443 | p[0] = type; |
| 444 | /* Device */ |
| 445 | p[1] = dev->path.pci.devfn; |
| 446 | /* Bus */ |
| 447 | p[2] = dev->bus->secondary; |
| 448 | /* Data */ |
| 449 | p[3] = data; |
| 450 | /* [4:7] Padding */ |
| 451 | p[4] = 0x0; |
| 452 | p[5] = 0x0; |
| 453 | p[6] = 0x0; |
| 454 | p[7] = 0x0; |
| 455 | *length += 8; |
| 456 | *current += 8; |
| 457 | } else if (type == 0x42) { |
| 458 | /* Entry type */ |
| 459 | p[0] = type; |
| 460 | /* Device */ |
| 461 | p[1] = dev->path.pci.devfn; |
| 462 | /* Bus */ |
| 463 | p[2] = dev->bus->secondary; |
| 464 | /* Data */ |
| 465 | p[3] = 0x0; |
| 466 | /* Reserved */ |
| 467 | p[4] = 0x0; |
| 468 | /* Device */ |
| 469 | p[5] = parent->path.pci.devfn; |
| 470 | /* Bus */ |
| 471 | p[6] = parent->bus->secondary; |
| 472 | /* Reserved */ |
| 473 | p[7] = 0x0; |
| 474 | *length += 8; |
| 475 | *current += 8; |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | static void add_ivrs_device_entries(struct device *parent, struct device *dev, |
| 480 | unsigned int depth, int linknum, int8_t *root_level, |
| 481 | unsigned long *current, uint16_t *length) |
| 482 | { |
| 483 | struct device *sibling; |
| 484 | struct bus *link; |
| 485 | unsigned int header_type; |
| 486 | unsigned int is_pcie; |
| 487 | |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 488 | if (dev->path.type == DEVICE_PATH_PCI) { |
| 489 | |
| 490 | if ((dev->bus->secondary == 0x0) && |
| 491 | (dev->path.pci.devfn == 0x0)) |
| 492 | *root_level = depth; |
| 493 | |
| 494 | if ((*root_level != -1) && (dev->enabled)) { |
| 495 | if (depth == *root_level) { |
| 496 | if (dev->path.pci.devfn == (0x14 << 3)) { |
| 497 | /* SMBUS controller */ |
| 498 | add_ivhd_dev_entry(parent, dev, current, length, 0x2, 0x97); |
| 499 | } else if (dev->path.pci.devfn != 0x2 && |
| 500 | dev->path.pci.devfn < (0x2 << 3)) { |
| 501 | /* FCH control device */ |
| 502 | } else { |
| 503 | /* Other devices */ |
| 504 | add_ivhd_dev_entry(parent, dev, current, length, 0x2, 0x0); |
| 505 | } |
| 506 | } else { |
| 507 | header_type = dev->hdr_type & 0x7f; |
| 508 | is_pcie = pci_find_capability(dev, PCI_CAP_ID_PCIE); |
| 509 | if (((header_type == PCI_HEADER_TYPE_NORMAL) || |
| 510 | (header_type == PCI_HEADER_TYPE_BRIDGE)) |
| 511 | && is_pcie) { |
| 512 | /* Device or Bridge is PCIe */ |
| 513 | add_ivhd_dev_entry(parent, dev, current, length, 0x2, 0x0); |
| 514 | } else if ((header_type == PCI_HEADER_TYPE_NORMAL) && |
| 515 | !is_pcie) { |
| 516 | add_ivhd_dev_entry(parent, dev, current, length, 0x42, 0x0); |
| 517 | /* Device is legacy PCI or PCI-X */ |
| 518 | } |
| 519 | } |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | for (link = dev->link_list; link; link = link->next) |
| 524 | for (sibling = link->children; sibling; sibling = |
| 525 | sibling->sibling) |
| 526 | add_ivrs_device_entries(dev, sibling, depth + 1, depth, |
| 527 | root_level, current, length); |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | unsigned long acpi_fill_ivrs_ioapic(acpi_ivrs_t *ivrs, unsigned long current) |
| 531 | { |
| 532 | uint8_t *p; |
| 533 | |
| 534 | uint32_t apicid_sb800; |
| 535 | uint32_t apicid_northbridge; |
| 536 | |
| 537 | apicid_sb800 = CONFIG_MAX_CPUS; |
| 538 | apicid_northbridge = CONFIG_MAX_CPUS + 1; |
| 539 | |
| 540 | /* Describe NB IOAPIC */ |
| 541 | p = (uint8_t *)current; |
| 542 | p[0] = 0x48; /* Entry type */ |
| 543 | p[1] = 0; /* Device */ |
| 544 | p[2] = 0; /* Bus */ |
| 545 | p[3] = 0x0; /* Data */ |
| 546 | p[4] = apicid_northbridge; /* IOAPIC ID */ |
| 547 | p[5] = 0x0; /* Device 0 Function 0 */ |
| 548 | p[6] = 0x0; /* Northbridge bus */ |
| 549 | p[7] = 0x1; /* Variety */ |
| 550 | current += 8; |
| 551 | |
| 552 | /* Describe SB IOAPIC */ |
| 553 | p = (uint8_t *)current; |
| 554 | p[0] = 0x48; /* Entry type */ |
| 555 | p[1] = 0; /* Device */ |
| 556 | p[2] = 0; /* Bus */ |
| 557 | p[3] = 0xd7; /* Data */ |
| 558 | p[4] = apicid_sb800; /* IOAPIC ID */ |
| 559 | p[5] = 0x14 << 3; /* Device 0x14 Function 0 */ |
| 560 | p[6] = 0x0; /* Southbridge bus */ |
| 561 | p[7] = 0x1; /* Variety */ |
| 562 | current += 8; |
| 563 | |
| 564 | return current; |
| 565 | } |
| 566 | |
| 567 | static unsigned long acpi_fill_ivrs(acpi_ivrs_t *ivrs, unsigned long current) |
| 568 | { |
| 569 | uint8_t *p; |
Piotr Król | 063e156 | 2018-07-22 20:52:26 +0200 | [diff] [blame] | 570 | acpi_ivrs_t *ivrs_agesa; |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 571 | |
Kyösti Mälkki | 33ff44c | 2018-05-22 01:15:22 +0300 | [diff] [blame] | 572 | struct device *nb_dev = pcidev_on_root(0x0, 0); |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 573 | if (!nb_dev) { |
| 574 | |
| 575 | printk(BIOS_WARNING, "%s: G-series northbridge device not present!\n", __func__); |
| 576 | printk(BIOS_WARNING, "%s: IVRS table not generated...\n", __func__); |
| 577 | |
| 578 | return (unsigned long)ivrs; |
| 579 | } |
| 580 | |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 581 | |
Piotr Król | 063e156 | 2018-07-22 20:52:26 +0200 | [diff] [blame] | 582 | /* obtain IOMMU base address */ |
| 583 | ivrs_agesa = agesawrapper_getlateinitptr(PICK_IVRS); |
| 584 | if (ivrs_agesa != NULL) { |
| 585 | ivrs->iv_info = 0x0; |
| 586 | /* Maximum supported virtual address size */ |
| 587 | ivrs->iv_info |= (0x40 << 15); |
| 588 | /* Maximum supported physical address size */ |
| 589 | ivrs->iv_info |= (0x30 << 8); |
| 590 | /* Guest virtual address width */ |
| 591 | ivrs->iv_info |= (0x2 << 5); |
| 592 | |
| 593 | ivrs->ivhd.type = 0x10; |
| 594 | ivrs->ivhd.flags = 0x0e; |
| 595 | /* Enable ATS support */ |
| 596 | ivrs->ivhd.flags |= 0x10; |
| 597 | ivrs->ivhd.length = sizeof(struct acpi_ivrs_ivhd); |
| 598 | /* BDF <bus>:00.2 */ |
| 599 | ivrs->ivhd.device_id = 0x2 | (nb_dev->bus->secondary << 8); |
| 600 | /* Capability block 0x40 (type 0xf, "Secure device") */ |
| 601 | ivrs->ivhd.capability_offset = 0x40; |
| 602 | ivrs->ivhd.iommu_base_low = ivrs_agesa->ivhd.iommu_base_low; |
| 603 | ivrs->ivhd.iommu_base_high = ivrs_agesa->ivhd.iommu_base_high; |
| 604 | ivrs->ivhd.pci_segment_group = 0x0; |
| 605 | ivrs->ivhd.iommu_info = 0x0; |
| 606 | ivrs->ivhd.iommu_info |= (0x13 << 8); |
| 607 | /* use only performance counters related bits: |
| 608 | * PNCounters[16:13] and |
| 609 | * PNBanks[22:17], |
| 610 | * otherwise 0 */ |
| 611 | ivrs->ivhd.iommu_feature_info = |
| 612 | ivrs_agesa->ivhd.iommu_feature_info & 0x7fe000; |
| 613 | } else { |
| 614 | printk(BIOS_WARNING, "%s: AGESA returned NULL IVRS\n", __func__); |
| 615 | |
| 616 | return (unsigned long)ivrs; |
| 617 | } |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 618 | |
| 619 | /* Describe HPET */ |
| 620 | p = (uint8_t *)current; |
| 621 | p[0] = 0x48; /* Entry type */ |
| 622 | p[1] = 0; /* Device */ |
| 623 | p[2] = 0; /* Bus */ |
| 624 | p[3] = 0xd7; /* Data */ |
| 625 | p[4] = 0x0; /* HPET number */ |
| 626 | p[5] = 0x14 << 3; /* HPET device */ |
| 627 | p[6] = nb_dev->bus->secondary; /* HPET bus */ |
| 628 | p[7] = 0x2; /* Variety */ |
| 629 | ivrs->ivhd.length += 8; |
| 630 | current += 8; |
| 631 | |
| 632 | /* Describe PCI devices */ |
Jacob Garber | 293e6a9 | 2019-07-17 11:47:19 -0600 | [diff] [blame] | 633 | int8_t root_level = -1; |
| 634 | add_ivrs_device_entries(NULL, all_devices, 0, -1, &root_level, ¤t, |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 635 | &ivrs->ivhd.length); |
| 636 | |
| 637 | /* Describe IOAPICs */ |
| 638 | unsigned long prev_current = current; |
| 639 | current = acpi_fill_ivrs_ioapic(ivrs, current); |
| 640 | ivrs->ivhd.length += (current - prev_current); |
| 641 | |
| 642 | return current; |
| 643 | } |
| 644 | |
Kyösti Mälkki | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 645 | static void northbridge_fill_ssdt_generator(struct device *device) |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 646 | { |
| 647 | msr_t msr; |
| 648 | char pscope[] = "\\_SB.PCI0"; |
| 649 | |
| 650 | acpigen_write_scope(pscope); |
| 651 | msr = rdmsr(TOP_MEM); |
| 652 | acpigen_write_name_dword("TOM1", msr.lo); |
| 653 | msr = rdmsr(TOP_MEM2); |
| 654 | /* |
| 655 | * Since XP only implements parts of ACPI 2.0, we can't use a qword |
| 656 | * here. |
| 657 | * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt |
| 658 | * slide 22ff. |
| 659 | * Shift value right by 20 bit to make it fit into 32bit, |
| 660 | * giving us 1MB granularity and a limit of almost 4Exabyte of memory. |
| 661 | */ |
| 662 | acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20); |
| 663 | acpigen_pop_len(); |
| 664 | } |
| 665 | |
Kyösti Mälkki | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 666 | static unsigned long agesa_write_acpi_tables(struct device *device, |
Alexander Couzens | 83fc32f | 2015-04-12 22:28:37 +0200 | [diff] [blame] | 667 | unsigned long current, |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 668 | acpi_rsdp_t *rsdp) |
| 669 | { |
| 670 | acpi_srat_t *srat; |
| 671 | acpi_slit_t *slit; |
| 672 | acpi_header_t *ssdt; |
| 673 | acpi_header_t *alib; |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 674 | acpi_ivrs_t *ivrs; |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 675 | |
| 676 | /* HEST */ |
| 677 | current = ALIGN(current, 8); |
Vladimir Serbinenko | 807127f | 2014-11-09 13:36:18 +0100 | [diff] [blame] | 678 | acpi_write_hest((void *)current, acpi_fill_hest); |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 679 | acpi_add_table(rsdp, (void *)current); |
| 680 | current += ((acpi_header_t *)current)->length; |
| 681 | |
Timothy Pearson | 9ef07d8 | 2016-06-13 13:48:58 -0500 | [diff] [blame] | 682 | /* IVRS */ |
| 683 | current = ALIGN(current, 8); |
| 684 | printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current); |
| 685 | ivrs = (acpi_ivrs_t *) current; |
| 686 | acpi_create_ivrs(ivrs, acpi_fill_ivrs); |
| 687 | current += ivrs->header.length; |
| 688 | acpi_add_table(rsdp, ivrs); |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 689 | |
| 690 | /* SRAT */ |
| 691 | current = ALIGN(current, 8); |
| 692 | printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current); |
| 693 | srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT); |
| 694 | if (srat != NULL) { |
| 695 | memcpy((void *)current, srat, srat->header.length); |
| 696 | srat = (acpi_srat_t *) current; |
| 697 | current += srat->header.length; |
| 698 | acpi_add_table(rsdp, srat); |
| 699 | } else { |
| 700 | printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n"); |
| 701 | } |
| 702 | |
| 703 | /* SLIT */ |
| 704 | current = ALIGN(current, 8); |
| 705 | printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current); |
| 706 | slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT); |
| 707 | if (slit != NULL) { |
| 708 | memcpy((void *)current, slit, slit->header.length); |
| 709 | slit = (acpi_slit_t *) current; |
| 710 | current += slit->header.length; |
| 711 | acpi_add_table(rsdp, slit); |
| 712 | } else { |
| 713 | printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n"); |
| 714 | } |
| 715 | |
| 716 | /* ALIB */ |
| 717 | current = ALIGN(current, 16); |
| 718 | printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current); |
| 719 | alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB); |
| 720 | if (alib != NULL) { |
| 721 | memcpy((void *)current, alib, alib->length); |
| 722 | alib = (acpi_header_t *) current; |
| 723 | current += alib->length; |
| 724 | acpi_add_table(rsdp, (void *)alib); |
| 725 | } |
| 726 | else { |
| 727 | printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n"); |
| 728 | } |
| 729 | |
| 730 | /* this pstate ssdt may cause Blue Screen: Fixed: Keep this comment for a while. */ |
| 731 | /* SSDT */ |
| 732 | current = ALIGN(current, 16); |
| 733 | printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current); |
| 734 | ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE); |
| 735 | if (ssdt != NULL) { |
| 736 | memcpy((void *)current, ssdt, ssdt->length); |
| 737 | ssdt = (acpi_header_t *) current; |
| 738 | current += ssdt->length; |
| 739 | } |
| 740 | else { |
| 741 | printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n"); |
| 742 | } |
| 743 | acpi_add_table(rsdp,ssdt); |
| 744 | |
| 745 | printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current); |
| 746 | return current; |
| 747 | } |
| 748 | |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 749 | static struct device_operations northbridge_operations = { |
| 750 | .read_resources = read_resources, |
| 751 | .set_resources = set_resources, |
| 752 | .enable_resources = pci_dev_enable_resources, |
| 753 | .init = northbridge_init, |
Kyösti Mälkki | 0b5b541 | 2014-11-26 08:11:07 +0200 | [diff] [blame] | 754 | .acpi_fill_ssdt_generator = northbridge_fill_ssdt_generator, |
| 755 | .write_acpi_tables = agesa_write_acpi_tables, |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 756 | .enable = 0, |
| 757 | .ops_pci = 0, |
| 758 | }; |
| 759 | |
| 760 | static const struct pci_driver family16_northbridge __pci_driver = { |
| 761 | .ops = &northbridge_operations, |
| 762 | .vendor = PCI_VENDOR_ID_AMD, |
Marshall Dawson | 463f46e | 2016-10-14 20:46:08 -0600 | [diff] [blame] | 763 | .device = PCI_DEVICE_ID_AMD_16H_MODEL_303F_NB_HT, |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 764 | }; |
| 765 | |
| 766 | static const struct pci_driver family10_northbridge __pci_driver = { |
| 767 | .ops = &northbridge_operations, |
| 768 | .vendor = PCI_VENDOR_ID_AMD, |
| 769 | .device = PCI_DEVICE_ID_AMD_10H_NB_HT, |
| 770 | }; |
| 771 | |
Dave Frodin | 891f71a | 2015-01-19 15:58:24 -0700 | [diff] [blame] | 772 | static void fam16_finalize(void *chip_info) |
| 773 | { |
Kyösti Mälkki | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 774 | struct device *dev; |
Dave Frodin | 891f71a | 2015-01-19 15:58:24 -0700 | [diff] [blame] | 775 | u32 value; |
Kyösti Mälkki | 33ff44c | 2018-05-22 01:15:22 +0300 | [diff] [blame] | 776 | dev = pcidev_on_root(0, 0); /* clear IoapicSbFeatureEn */ |
Dave Frodin | 891f71a | 2015-01-19 15:58:24 -0700 | [diff] [blame] | 777 | pci_write_config32(dev, 0xF8, 0); |
| 778 | pci_write_config32(dev, 0xFC, 5); /* TODO: move it to dsdt.asl */ |
| 779 | |
| 780 | /* disable No Snoop */ |
Kyösti Mälkki | 33ff44c | 2018-05-22 01:15:22 +0300 | [diff] [blame] | 781 | dev = pcidev_on_root(1, 1); |
Kyösti Mälkki | 69f6fd4 | 2019-01-21 14:19:01 +0200 | [diff] [blame] | 782 | if (dev != NULL) { |
| 783 | value = pci_read_config32(dev, 0x60); |
| 784 | value &= ~(1 << 11); |
| 785 | pci_write_config32(dev, 0x60, value); |
| 786 | } |
Dave Frodin | 891f71a | 2015-01-19 15:58:24 -0700 | [diff] [blame] | 787 | } |
| 788 | |
Kyösti Mälkki | e4c17ce | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 789 | struct chip_operations northbridge_amd_pi_00730F01_ops = { |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 790 | CHIP_NAME("AMD FAM16 Northbridge") |
| 791 | .enable_dev = 0, |
Dave Frodin | 891f71a | 2015-01-19 15:58:24 -0700 | [diff] [blame] | 792 | .final = fam16_finalize, |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 793 | }; |
| 794 | |
Kyösti Mälkki | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 795 | static void domain_read_resources(struct device *dev) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 796 | { |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 797 | unsigned int reg; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 798 | |
| 799 | /* Find the already assigned resource pairs */ |
| 800 | get_fx_devs(); |
| 801 | for (reg = 0x80; reg <= 0xd8; reg+= 0x08) { |
| 802 | u32 base, limit; |
| 803 | base = f1_read_config32(reg); |
| 804 | limit = f1_read_config32(reg + 0x04); |
| 805 | /* Is this register allocated? */ |
| 806 | if ((base & 3) != 0) { |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 807 | unsigned int nodeid, reg_link; |
Kyösti Mälkki | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 808 | struct device *reg_dev; |
Elyes HAOUAS | a813160 | 2016-09-19 10:27:57 -0600 | [diff] [blame] | 809 | if (reg < 0xc0) { // mmio |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 810 | nodeid = (limit & 0xf) + (base&0x30); |
| 811 | } else { // io |
| 812 | nodeid = (limit & 0xf) + ((base>>4)&0x30); |
| 813 | } |
| 814 | reg_link = (limit >> 4) & 7; |
| 815 | reg_dev = __f0_dev[nodeid]; |
| 816 | if (reg_dev) { |
| 817 | /* Reserve the resource */ |
| 818 | struct resource *res; |
| 819 | res = new_resource(reg_dev, IOINDEX(0x1000 + reg, reg_link)); |
| 820 | if (res) { |
| 821 | res->flags = 1; |
| 822 | } |
| 823 | } |
| 824 | } |
| 825 | } |
| 826 | /* FIXME: do we need to check extend conf space? |
| 827 | I don't believe that much preset value */ |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 828 | pci_domain_read_resources(dev); |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 829 | } |
| 830 | |
Kyösti Mälkki | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 831 | static void domain_enable_resources(struct device *dev) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 832 | { |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
| 836 | struct hw_mem_hole_info { |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 837 | unsigned int hole_startk; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 838 | int node_id; |
| 839 | }; |
| 840 | static struct hw_mem_hole_info get_hw_mem_hole_info(void) |
| 841 | { |
| 842 | struct hw_mem_hole_info mem_hole; |
| 843 | int i; |
| 844 | mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK; |
| 845 | mem_hole.node_id = -1; |
| 846 | for (i = 0; i < node_nums; i++) { |
| 847 | dram_base_mask_t d; |
| 848 | u32 hole; |
| 849 | d = get_dram_base_mask(i); |
| 850 | if (!(d.mask & 1)) continue; // no memory on this node |
| 851 | hole = pci_read_config32(__f1_dev[i], 0xf0); |
| 852 | if (hole & 2) { // we find the hole |
| 853 | mem_hole.hole_startk = (hole & (0xff<<24)) >> 10; |
| 854 | mem_hole.node_id = i; // record the node No with hole |
| 855 | break; // only one hole |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | /* We need to double check if there is special set on base reg and limit reg |
| 860 | * are not continuous instead of hole, it will find out its hole_startk. |
| 861 | */ |
| 862 | if (mem_hole.node_id == -1) { |
| 863 | resource_t limitk_pri = 0; |
Elyes HAOUAS | a813160 | 2016-09-19 10:27:57 -0600 | [diff] [blame] | 864 | for (i = 0; i < node_nums; i++) { |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 865 | dram_base_mask_t d; |
| 866 | resource_t base_k, limit_k; |
| 867 | d = get_dram_base_mask(i); |
| 868 | if (!(d.base & 1)) continue; |
| 869 | base_k = ((resource_t)(d.base & 0x1fffff00)) <<9; |
| 870 | if (base_k > 4 *1024 * 1024) break; // don't need to go to check |
| 871 | if (limitk_pri != base_k) { // we find the hole |
Martin Roth | 468d02c | 2019-10-23 21:44:42 -0600 | [diff] [blame] | 872 | mem_hole.hole_startk = (unsigned int)limitk_pri; // must beblow 4G |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 873 | mem_hole.node_id = i; |
| 874 | break; //only one hole |
| 875 | } |
| 876 | limit_k = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9; |
| 877 | limitk_pri = limit_k; |
| 878 | } |
| 879 | } |
| 880 | return mem_hole; |
| 881 | } |
| 882 | #endif |
| 883 | |
Kyösti Mälkki | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 884 | static void domain_set_resources(struct device *dev) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 885 | { |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 886 | unsigned long mmio_basek; |
| 887 | u32 pci_tolm; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 888 | int i, idx; |
| 889 | struct bus *link; |
| 890 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
| 891 | struct hw_mem_hole_info mem_hole; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 892 | #endif |
| 893 | |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 894 | pci_tolm = 0xffffffffUL; |
| 895 | for (link = dev->link_list; link; link = link->next) { |
| 896 | pci_tolm = find_pci_tolm(link); |
| 897 | } |
| 898 | |
| 899 | // FIXME handle interleaved nodes. If you fix this here, please fix |
| 900 | // amdk8, too. |
| 901 | mmio_basek = pci_tolm >> 10; |
| 902 | /* Round mmio_basek to something the processor can support */ |
| 903 | mmio_basek &= ~((1 << 6) -1); |
| 904 | |
| 905 | // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M |
| 906 | // MMIO hole. If you fix this here, please fix amdk8, too. |
| 907 | /* Round the mmio hole to 64M */ |
| 908 | mmio_basek &= ~((64*1024) - 1); |
| 909 | |
| 910 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
| 911 | /* if the hw mem hole is already set in raminit stage, here we will compare |
| 912 | * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will |
| 913 | * use hole_basek as mmio_basek and we don't need to reset hole. |
| 914 | * otherwise We reset the hole to the mmio_basek |
| 915 | */ |
| 916 | |
| 917 | mem_hole = get_hw_mem_hole_info(); |
| 918 | |
| 919 | // Use hole_basek as mmio_basek, and we don't need to reset hole anymore |
| 920 | if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) { |
| 921 | mmio_basek = mem_hole.hole_startk; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 922 | } |
| 923 | #endif |
| 924 | |
| 925 | idx = 0x10; |
| 926 | for (i = 0; i < node_nums; i++) { |
| 927 | dram_base_mask_t d; |
| 928 | resource_t basek, limitk, sizek; // 4 1T |
| 929 | |
| 930 | d = get_dram_base_mask(i); |
| 931 | |
| 932 | if (!(d.mask & 1)) continue; |
| 933 | basek = ((resource_t)(d.base & 0x1fffff00)) << 9; // could overflow, we may lost 6 bit here |
Elyes HAOUAS | 7db506c | 2016-10-02 11:56:39 +0200 | [diff] [blame] | 934 | limitk = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 935 | |
| 936 | sizek = limitk - basek; |
| 937 | |
| 938 | /* see if we need a hole from 0xa0000 to 0xbffff */ |
| 939 | if ((basek < ((8*64)+(8*16))) && (sizek > ((8*64)+(16*16)))) { |
| 940 | ram_resource(dev, (idx | i), basek, ((8*64)+(8*16)) - basek); |
| 941 | idx += 0x10; |
| 942 | basek = (8*64)+(16*16); |
| 943 | sizek = limitk - ((8*64)+(16*16)); |
| 944 | |
| 945 | } |
| 946 | |
| 947 | //printk(BIOS_DEBUG, "node %d : mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", i, mmio_basek, basek, limitk); |
| 948 | |
| 949 | /* split the region to accommodate pci memory space */ |
Elyes HAOUAS | a813160 | 2016-09-19 10:27:57 -0600 | [diff] [blame] | 950 | if ((basek < 4*1024*1024) && (limitk > mmio_basek)) { |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 951 | if (basek <= mmio_basek) { |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 952 | unsigned int pre_sizek; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 953 | pre_sizek = mmio_basek - basek; |
Elyes HAOUAS | a813160 | 2016-09-19 10:27:57 -0600 | [diff] [blame] | 954 | if (pre_sizek > 0) { |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 955 | ram_resource(dev, (idx | i), basek, pre_sizek); |
| 956 | idx += 0x10; |
| 957 | sizek -= pre_sizek; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 958 | } |
| 959 | basek = mmio_basek; |
| 960 | } |
| 961 | if ((basek + sizek) <= 4*1024*1024) { |
| 962 | sizek = 0; |
| 963 | } |
| 964 | else { |
| 965 | uint64_t topmem2 = bsp_topmem2(); |
| 966 | basek = 4*1024*1024; |
| 967 | sizek = topmem2/1024 - basek; |
| 968 | } |
| 969 | } |
| 970 | |
| 971 | ram_resource(dev, (idx | i), basek, sizek); |
| 972 | idx += 0x10; |
| 973 | printk(BIOS_DEBUG, "node %d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", |
| 974 | i, mmio_basek, basek, limitk); |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 975 | } |
| 976 | |
Kyösti Mälkki | e87564f | 2017-04-15 20:07:53 +0300 | [diff] [blame] | 977 | add_uma_resource_below_tolm(dev, 7); |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 978 | |
Elyes HAOUAS | 5a7e72f | 2016-08-23 21:36:02 +0200 | [diff] [blame] | 979 | for (link = dev->link_list; link; link = link->next) { |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 980 | if (link->children) { |
| 981 | assign_resources(link); |
| 982 | } |
| 983 | } |
| 984 | } |
| 985 | |
Aaron Durbin | aa090cb | 2017-09-13 16:01:52 -0600 | [diff] [blame] | 986 | static const char *domain_acpi_name(const struct device *dev) |
Philipp Deppenwiese | 3067012 | 2017-03-01 02:24:33 +0100 | [diff] [blame] | 987 | { |
| 988 | if (dev->path.type == DEVICE_PATH_DOMAIN) |
| 989 | return "PCI0"; |
| 990 | |
| 991 | return NULL; |
| 992 | } |
| 993 | |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 994 | static struct device_operations pci_domain_ops = { |
| 995 | .read_resources = domain_read_resources, |
| 996 | .set_resources = domain_set_resources, |
| 997 | .enable_resources = domain_enable_resources, |
| 998 | .init = NULL, |
| 999 | .scan_bus = pci_domain_scan_bus, |
Philipp Deppenwiese | 3067012 | 2017-03-01 02:24:33 +0100 | [diff] [blame] | 1000 | .acpi_name = domain_acpi_name, |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1001 | }; |
| 1002 | |
Kyösti Mälkki | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 1003 | static void sysconf_init(struct device *dev) // first node |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1004 | { |
| 1005 | sblink = (pci_read_config32(dev, 0x64)>>8) & 7; // don't forget sublink1 |
| 1006 | node_nums = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; //NodeCnt[2:0] |
| 1007 | } |
| 1008 | |
Kyösti Mälkki | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 1009 | static void cpu_bus_scan(struct device *dev) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1010 | { |
| 1011 | struct bus *cpu_bus; |
Kyösti Mälkki | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 1012 | struct device *dev_mc; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1013 | int i,j; |
| 1014 | int coreid_bits; |
| 1015 | int core_max = 0; |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 1016 | unsigned int ApicIdCoreIdSize; |
| 1017 | unsigned int core_nums; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1018 | int siblings = 0; |
| 1019 | unsigned int family; |
| 1020 | u32 modules = 0; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1021 | int ioapic_count = 0; |
| 1022 | |
Michał Żygowski | e719288 | 2019-11-23 19:02:19 +0100 | [diff] [blame] | 1023 | /* For binaryPI there is no multiprocessor configuration, the number of |
| 1024 | * modules will always be 1. */ |
| 1025 | modules = 1; |
| 1026 | ioapic_count = CONFIG_NUM_OF_IOAPICS; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1027 | |
Kyösti Mälkki | bbd2377 | 2019-01-10 05:41:23 +0200 | [diff] [blame] | 1028 | dev_mc = pcidev_on_root(DEV_CDB, 0); |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1029 | if (!dev_mc) { |
Kyösti Mälkki | bbd2377 | 2019-01-10 05:41:23 +0200 | [diff] [blame] | 1030 | printk(BIOS_ERR, "0:%02x.0 not found", DEV_CDB); |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1031 | die(""); |
| 1032 | } |
| 1033 | sysconf_init(dev_mc); |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1034 | |
| 1035 | /* Get Max Number of cores(MNC) */ |
Kyösti Mälkki | d41feed | 2017-09-24 16:23:57 +0300 | [diff] [blame] | 1036 | coreid_bits = (cpuid_ecx(0x80000008) & 0x0000F000) >> 12; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1037 | core_max = 1 << (coreid_bits & 0x000F); //mnc |
| 1038 | |
| 1039 | ApicIdCoreIdSize = ((cpuid_ecx(0x80000008)>>12) & 0xF); |
| 1040 | if (ApicIdCoreIdSize) { |
| 1041 | core_nums = (1 << ApicIdCoreIdSize) - 1; |
| 1042 | } else { |
| 1043 | core_nums = 3; //quad core |
| 1044 | } |
| 1045 | |
| 1046 | /* Find which cpus are present */ |
| 1047 | cpu_bus = dev->link_list; |
| 1048 | for (i = 0; i < node_nums; i++) { |
Kyösti Mälkki | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 1049 | struct device *cdb_dev; |
Subrata Banik | b1434fc | 2019-03-15 22:20:41 +0530 | [diff] [blame] | 1050 | unsigned int devn; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1051 | struct bus *pbus; |
| 1052 | |
Kyösti Mälkki | bbd2377 | 2019-01-10 05:41:23 +0200 | [diff] [blame] | 1053 | devn = DEV_CDB + i; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1054 | pbus = dev_mc->bus; |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1055 | |
| 1056 | /* Find the cpu's pci device */ |
Kyösti Mälkki | 33ff44c | 2018-05-22 01:15:22 +0300 | [diff] [blame] | 1057 | cdb_dev = pcidev_on_root(devn, 0); |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1058 | if (!cdb_dev) { |
| 1059 | /* If I am probing things in a weird order |
| 1060 | * ensure all of the cpu's pci devices are found. |
| 1061 | */ |
| 1062 | int fn; |
Elyes HAOUAS | 5a7e72f | 2016-08-23 21:36:02 +0200 | [diff] [blame] | 1063 | for (fn = 0; fn <= 5; fn++) { //FBDIMM? |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1064 | cdb_dev = pci_probe_dev(NULL, pbus, |
| 1065 | PCI_DEVFN(devn, fn)); |
| 1066 | } |
Kyösti Mälkki | 33ff44c | 2018-05-22 01:15:22 +0300 | [diff] [blame] | 1067 | cdb_dev = pcidev_on_root(devn, 0); |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1068 | } else { |
| 1069 | /* Ok, We need to set the links for that device. |
| 1070 | * otherwise the device under it will not be scanned |
| 1071 | */ |
Kyösti Mälkki | c5163ed8 | 2015-02-04 13:25:37 +0200 | [diff] [blame] | 1072 | |
| 1073 | add_more_links(cdb_dev, 4); |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | family = cpuid_eax(1); |
| 1077 | family = (family >> 20) & 0xFF; |
| 1078 | if (family == 1) { //f10 |
| 1079 | u32 dword; |
Kyösti Mälkki | 33ff44c | 2018-05-22 01:15:22 +0300 | [diff] [blame] | 1080 | cdb_dev = pcidev_on_root(devn, 3); |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1081 | dword = pci_read_config32(cdb_dev, 0xe8); |
| 1082 | siblings = ((dword & BIT15) >> 13) | ((dword & (BIT13 | BIT12)) >> 12); |
| 1083 | } else if (family == 7) {//f16 |
Kyösti Mälkki | 33ff44c | 2018-05-22 01:15:22 +0300 | [diff] [blame] | 1084 | cdb_dev = pcidev_on_root(devn, 5); |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1085 | if (cdb_dev && cdb_dev->enabled) { |
| 1086 | siblings = pci_read_config32(cdb_dev, 0x84); |
| 1087 | siblings &= 0xFF; |
| 1088 | } |
| 1089 | } else { |
| 1090 | siblings = 0; //default one core |
| 1091 | } |
| 1092 | int enable_node = cdb_dev && cdb_dev->enabled; |
Elyes HAOUAS | a813160 | 2016-09-19 10:27:57 -0600 | [diff] [blame] | 1093 | printk(BIOS_SPEW, "%s family%xh, core_max = 0x%x, core_nums = 0x%x, siblings = 0x%x\n", |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1094 | dev_path(cdb_dev), 0x0f + family, core_max, core_nums, siblings); |
| 1095 | |
Elyes HAOUAS | a813160 | 2016-09-19 10:27:57 -0600 | [diff] [blame] | 1096 | for (j = 0; j <= siblings; j++) { |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1097 | u32 lapicid_start = 0; |
| 1098 | |
| 1099 | /* |
| 1100 | * APIC ID calucation is tightly coupled with AGESA v5 code. |
| 1101 | * This calculation MUST match the assignment calculation done |
| 1102 | * in LocalApicInitializationAtEarly() function. |
| 1103 | * And reference GetLocalApicIdForCore() |
| 1104 | * |
| 1105 | * Apply apic enumeration rules |
| 1106 | * For systems with >= 16 APICs, put the IO-APICs at 0..n and |
| 1107 | * put the local-APICs at m..z |
| 1108 | * |
| 1109 | * This is needed because many IO-APIC devices only have 4 bits |
| 1110 | * for their APIC id and therefore must reside at 0..15 |
Elyes HAOUAS | 6e8b3c1 | 2016-09-02 19:22:00 +0200 | [diff] [blame] | 1111 | */ |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1112 | if ((node_nums * core_max) + ioapic_count >= 0x10) { |
| 1113 | lapicid_start = (ioapic_count - 1) / core_max; |
| 1114 | lapicid_start = (lapicid_start + 1) * core_max; |
Elyes HAOUAS | a813160 | 2016-09-19 10:27:57 -0600 | [diff] [blame] | 1115 | printk(BIOS_SPEW, "lpaicid_start = 0x%x ", lapicid_start); |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1116 | } |
| 1117 | u32 apic_id = (lapicid_start * (i/modules + 1)) + ((i % modules) ? (j + (siblings + 1)) : j); |
Elyes HAOUAS | a813160 | 2016-09-19 10:27:57 -0600 | [diff] [blame] | 1118 | printk(BIOS_SPEW, "node 0x%x core 0x%x apicid = 0x%x\n", |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1119 | i, j, apic_id); |
| 1120 | |
Kyösti Mälkki | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 1121 | struct device *cpu = add_cpu_device(cpu_bus, apic_id, enable_node); |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1122 | if (cpu) |
| 1123 | amd_cpu_topology(cpu, i, j); |
| 1124 | } //j |
| 1125 | } |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1126 | } |
| 1127 | |
Kyösti Mälkki | 90ac736 | 2018-05-20 20:59:52 +0300 | [diff] [blame] | 1128 | static void cpu_bus_init(struct device *dev) |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1129 | { |
| 1130 | initialize_cpus(dev->link_list); |
| 1131 | } |
| 1132 | |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1133 | static struct device_operations cpu_bus_ops = { |
Kyösti Mälkki | 48f82a9 | 2016-12-02 16:02:30 +0200 | [diff] [blame] | 1134 | .read_resources = DEVICE_NOOP, |
| 1135 | .set_resources = DEVICE_NOOP, |
Edward O'Callaghan | 812d2a4 | 2014-10-31 08:17:23 +1100 | [diff] [blame] | 1136 | .enable_resources = DEVICE_NOOP, |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1137 | .init = cpu_bus_init, |
| 1138 | .scan_bus = cpu_bus_scan, |
| 1139 | }; |
| 1140 | |
| 1141 | static void root_complex_enable_dev(struct device *dev) |
| 1142 | { |
| 1143 | static int done = 0; |
| 1144 | |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1145 | if (!done) { |
| 1146 | setup_bsp_ramtop(); |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1147 | done = 1; |
| 1148 | } |
| 1149 | |
| 1150 | /* Set the operations if it is a special bus type */ |
| 1151 | if (dev->path.type == DEVICE_PATH_DOMAIN) { |
| 1152 | dev->ops = &pci_domain_ops; |
| 1153 | } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) { |
| 1154 | dev->ops = &cpu_bus_ops; |
| 1155 | } |
| 1156 | } |
| 1157 | |
Kyösti Mälkki | e4c17ce | 2014-10-21 18:22:32 +0300 | [diff] [blame] | 1158 | struct chip_operations northbridge_amd_pi_00730F01_root_complex_ops = { |
Bruce Griffith | 27ed80b | 2014-08-15 11:46:25 -0600 | [diff] [blame] | 1159 | CHIP_NAME("AMD FAM16 Root Complex") |
| 1160 | .enable_dev = root_complex_enable_dev, |
| 1161 | }; |
| 1162 | |
| 1163 | /********************************************************************* |
| 1164 | * Change the vendor / device IDs to match the generic VBIOS header. * |
| 1165 | *********************************************************************/ |
| 1166 | u32 map_oprom_vendev(u32 vendev) |
| 1167 | { |
| 1168 | u32 new_vendev; |
| 1169 | new_vendev = |
| 1170 | ((0x10029850 <= vendev) && (vendev <= 0x1002986F)) ? 0x10029850 : vendev; |
| 1171 | |
| 1172 | if (vendev != new_vendev) |
| 1173 | printk(BIOS_NOTICE, "Mapping PCI device %8x to %8x\n", vendev, new_vendev); |
| 1174 | |
| 1175 | return new_vendev; |
| 1176 | } |