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