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