blob: d955bcf666d30be692b7645afe0dbf48e62a47ed [file] [log] [blame]
Frank Vibrans39fca802011-02-14 18:35:15 +00001/*
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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <console/console.h>
21#include <arch/io.h>
22#include <stdint.h>
23#include <device/device.h>
24#include <device/pci.h>
25#include <device/pci_ids.h>
26#include <device/hypertransport.h>
27#include <stdlib.h>
28#include <string.h>
Ronald G. Minnich5079a0d2012-11-27 11:32:38 -080029#include <lib.h>
Frank Vibrans39fca802011-02-14 18:35:15 +000030#include <cpu/cpu.h>
Marc Jones5750ed22012-03-15 13:21:41 -060031#include <cbmem.h>
Frank Vibrans39fca802011-02-14 18:35:15 +000032
33#include <cpu/x86/lapic.h>
Kyösti Mälkki55fff9302012-07-11 08:02:39 +030034#include <cpu/amd/mtrr.h>
Frank Vibrans39fca802011-02-14 18:35:15 +000035
efdesign983f5ebd62011-09-14 13:47:17 -060036#include "agesawrapper.h"
Frank Vibrans39fca802011-02-14 18:35:15 +000037#include "northbridge.h"
Kerry Shefeed3292011-08-18 18:03:44 +080038#if CONFIG_AMD_SB_CIMX
39#include <sb_cimx.h>
40#endif
Frank Vibrans39fca802011-02-14 18:35:15 +000041
Frank Vibrans39fca802011-02-14 18:35:15 +000042//#define FX_DEVS NODE_NUMS
43#define FX_DEVS 1
44
45static device_t __f0_dev[FX_DEVS];
46static device_t __f1_dev[FX_DEVS];
47static device_t __f2_dev[FX_DEVS];
48static device_t __f4_dev[FX_DEVS];
Marc Jones8d595692012-03-15 12:55:26 -060049static unsigned fx_devs = 0;
Frank Vibrans39fca802011-02-14 18:35:15 +000050
51device_t get_node_pci(u32 nodeid, u32 fn)
52{
zbao49bb26a42012-08-03 15:44:42 +080053 if ((CONFIG_CDB + nodeid) < 32) {
54 return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn));
55 } else {
56 return dev_find_slot(CONFIG_CBB-1, PCI_DEVFN(CONFIG_CDB + nodeid - 32, fn));
57 }
Frank Vibrans39fca802011-02-14 18:35:15 +000058}
59
Frank Vibrans39fca802011-02-14 18:35:15 +000060static void get_fx_devs(void)
61{
Marc Jones8d595692012-03-15 12:55:26 -060062 int i;
63 for (i = 0; i < FX_DEVS; i++) {
64 __f0_dev[i] = get_node_pci(i, 0);
65 __f1_dev[i] = get_node_pci(i, 1);
66 __f2_dev[i] = get_node_pci(i, 2);
67 __f4_dev[i] = get_node_pci(i, 4);
68 if (__f0_dev[i] != NULL && __f1_dev[i] != NULL)
69 fx_devs = i + 1;
70 }
71 if (__f1_dev[0] == NULL || __f0_dev[0] == NULL || fx_devs == 0) {
72 die("Cannot find 0:0x18.[0|1]\n");
73 }
Frank Vibrans39fca802011-02-14 18:35:15 +000074}
75
Frank Vibrans39fca802011-02-14 18:35:15 +000076static u32 f1_read_config32(unsigned reg)
77{
Marc Jones8d595692012-03-15 12:55:26 -060078 if (fx_devs == 0)
79 get_fx_devs();
80 return pci_read_config32(__f1_dev[0], reg);
Frank Vibrans39fca802011-02-14 18:35:15 +000081}
82
Frank Vibrans39fca802011-02-14 18:35:15 +000083static void f1_write_config32(unsigned reg, u32 value)
84{
Marc Jones8d595692012-03-15 12:55:26 -060085 int i;
86 if (fx_devs == 0)
87 get_fx_devs();
88 for (i = 0; i < fx_devs; i++) {
89 device_t dev;
90 dev = __f1_dev[i];
91 if (dev && dev->enabled) {
92 pci_write_config32(dev, reg, value);
93 }
94 }
Frank Vibrans39fca802011-02-14 18:35:15 +000095}
96
Frank Vibrans39fca802011-02-14 18:35:15 +000097static u32 amdfam14_nodeid(device_t dev)
98{
Marc Jones8d595692012-03-15 12:55:26 -060099 return (dev->path.pci.devfn >> 3) - CONFIG_CDB;
Frank Vibrans39fca802011-02-14 18:35:15 +0000100}
101
Frank Vibrans39fca802011-02-14 18:35:15 +0000102#include "amdfam14_conf.c"
103
Frank Vibrans39fca802011-02-14 18:35:15 +0000104static void northbridge_init(device_t dev)
105{
Marc Jones8d595692012-03-15 12:55:26 -0600106 printk(BIOS_DEBUG, "Northbridge init\n");
Frank Vibrans39fca802011-02-14 18:35:15 +0000107}
108
Frank Vibrans39fca802011-02-14 18:35:15 +0000109static void set_vga_enable_reg(u32 nodeid, u32 linkn)
110{
Marc Jones8d595692012-03-15 12:55:26 -0600111 u32 val;
Frank Vibrans39fca802011-02-14 18:35:15 +0000112
Marc Jones8d595692012-03-15 12:55:26 -0600113 val = 1 | (nodeid << 4) | (linkn << 12);
114 /* it will routing (1)mmio 0xa0000:0xbffff (2) io 0x3b0:0x3bb,
115 0x3c0:0x3df */
116 f1_write_config32(0xf4, val);
Frank Vibrans39fca802011-02-14 18:35:15 +0000117
118}
119
Frank Vibrans39fca802011-02-14 18:35:15 +0000120static int reg_useable(unsigned reg, device_t goal_dev, unsigned goal_nodeid,
Marc Jones8d595692012-03-15 12:55:26 -0600121 unsigned goal_link)
Frank Vibrans39fca802011-02-14 18:35:15 +0000122{
Marc Jones8d595692012-03-15 12:55:26 -0600123 struct resource *res;
124 unsigned nodeid, link = 0;
125 int result;
126 res = 0;
127 for (nodeid = 0; !res && (nodeid < fx_devs); nodeid++) {
128 device_t dev;
129 dev = __f0_dev[nodeid];
130 if (!dev)
131 continue;
132 for (link = 0; !res && (link < 8); link++) {
133 res = probe_resource(dev, IOINDEX(0x1000 + reg, link));
134 }
135 }
136 result = 2;
137 if (res) {
138 result = 0;
139 if ((goal_link == (link - 1)) &&
140 (goal_nodeid == (nodeid - 1)) && (res->flags <= 1)) {
141 result = 1;
142 }
143 }
144 return result;
Frank Vibrans39fca802011-02-14 18:35:15 +0000145}
146
Marc Jones8d595692012-03-15 12:55:26 -0600147static struct resource *amdfam14_find_iopair(device_t dev, unsigned nodeid,
148 unsigned link)
Frank Vibrans39fca802011-02-14 18:35:15 +0000149{
Marc Jones8d595692012-03-15 12:55:26 -0600150 struct resource *resource;
151 u32 result, reg;
152 resource = 0;
153 reg = 0;
154 result = reg_useable(0xc0, dev, nodeid, link);
155 if (result >= 1) {
156 /* I have been allocated this one */
157 reg = 0xc0;
158 }
159 /* Ext conf space */
160 if (!reg) {
161 /* Because of Extend conf space, we will never run out of reg,
162 * but we need one index to differ them. So ,same node and same
163 * link can have multi range
164 */
165 u32 index = get_io_addr_index(nodeid, link);
166 reg = 0x110 + (index << 24) + (4 << 20); // index could be 0, 255
167 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000168
Marc Jones8d595692012-03-15 12:55:26 -0600169 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
Frank Vibrans39fca802011-02-14 18:35:15 +0000170
Marc Jones8d595692012-03-15 12:55:26 -0600171 return resource;
Frank Vibrans39fca802011-02-14 18:35:15 +0000172}
173
Marc Jones8d595692012-03-15 12:55:26 -0600174static struct resource *amdfam14_find_mempair(device_t dev, u32 nodeid,
175 u32 link)
Frank Vibrans39fca802011-02-14 18:35:15 +0000176{
Marc Jones8d595692012-03-15 12:55:26 -0600177 struct resource *resource;
178 u32 free_reg, reg;
179 resource = 0;
180 free_reg = 0;
181 for (reg = 0x80; reg <= 0xb8; reg += 0x8) {
182 int result;
183 result = reg_useable(reg, dev, nodeid, link);
184 if (result == 1) {
185 /* I have been allocated this one */
186 break;
187 } else if (result > 1) {
188 /* I have a free register pair */
189 free_reg = reg;
190 }
191 }
192 if (reg > 0xb8) {
193 reg = free_reg;
194 }
195 /* Ext conf space */
196 if (!reg) {
197 /* Because of Extend conf space, we will never run out of reg,
198 * but we need one index to differ them. So ,same node and same
199 * link can have multi range
200 */
201 u32 index = get_mmio_addr_index(nodeid, link);
202 reg = 0x110 + (index << 24) + (6 << 20); // index could be 0, 63
Frank Vibrans39fca802011-02-14 18:35:15 +0000203
Marc Jones8d595692012-03-15 12:55:26 -0600204 }
205 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
206 return resource;
Frank Vibrans39fca802011-02-14 18:35:15 +0000207}
208
Frank Vibrans39fca802011-02-14 18:35:15 +0000209static void amdfam14_link_read_bases(device_t dev, u32 nodeid, u32 link)
210{
Marc Jones8d595692012-03-15 12:55:26 -0600211 struct resource *resource;
Frank Vibrans39fca802011-02-14 18:35:15 +0000212
Marc Jones8d595692012-03-15 12:55:26 -0600213 /* Initialize the io space constraints on the current bus */
214 resource = amdfam14_find_iopair(dev, nodeid, link);
215 if (resource) {
216 u32 align;
Patrick Georgie1667822012-05-05 15:29:32 +0200217#if CONFIG_EXT_CONF_SUPPORT
Marc Jones8d595692012-03-15 12:55:26 -0600218 if ((resource->index & 0x1fff) == 0x1110) { // ext
219 align = 8;
220 } else
Frank Vibrans39fca802011-02-14 18:35:15 +0000221#endif
Marc Jones8d595692012-03-15 12:55:26 -0600222 align = log2(HT_IO_HOST_ALIGN);
223 resource->base = 0;
224 resource->size = 0;
225 resource->align = align;
226 resource->gran = align;
227 resource->limit = 0xffffUL;
228 resource->flags = IORESOURCE_IO | IORESOURCE_BRIDGE;
229 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000230
Marc Jones8d595692012-03-15 12:55:26 -0600231 /* Initialize the prefetchable memory constraints on the current bus */
232 resource = amdfam14_find_mempair(dev, nodeid, link);
233 if (resource) {
234 resource->base = 0;
235 resource->size = 0;
236 resource->align = log2(HT_MEM_HOST_ALIGN);
237 resource->gran = log2(HT_MEM_HOST_ALIGN);
238 resource->limit = 0xffffffffffULL;
239 resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
240 resource->flags |= IORESOURCE_BRIDGE;
Frank Vibrans39fca802011-02-14 18:35:15 +0000241
Patrick Georgie1667822012-05-05 15:29:32 +0200242#if CONFIG_EXT_CONF_SUPPORT
Marc Jones8d595692012-03-15 12:55:26 -0600243 if ((resource->index & 0x1fff) == 0x1110) { // ext
244 normalize_resource(resource);
245 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000246#endif
247
Marc Jones8d595692012-03-15 12:55:26 -0600248 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000249
Marc Jones8d595692012-03-15 12:55:26 -0600250 /* Initialize the memory constraints on the current bus */
251 resource = amdfam14_find_mempair(dev, nodeid, link);
252 if (resource) {
253 resource->base = 0;
254 resource->size = 0;
255 resource->align = log2(HT_MEM_HOST_ALIGN);
256 resource->gran = log2(HT_MEM_HOST_ALIGN);
257 resource->limit = 0xffffffffffULL;
258 resource->flags = IORESOURCE_MEM | IORESOURCE_BRIDGE;
Patrick Georgie1667822012-05-05 15:29:32 +0200259#if CONFIG_EXT_CONF_SUPPORT
Marc Jones8d595692012-03-15 12:55:26 -0600260 if ((resource->index & 0x1fff) == 0x1110) { // ext
261 normalize_resource(resource);
262 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000263#endif
Marc Jones8d595692012-03-15 12:55:26 -0600264 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000265}
266
267static u32 my_find_pci_tolm(struct bus *bus, u32 tolm)
268{
Marc Jones8d595692012-03-15 12:55:26 -0600269 struct resource *min;
270 min = 0;
271 search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test,
272 &min);
273 if (min && tolm > min->base) {
274 tolm = min->base;
275 }
276 return tolm;
Frank Vibrans39fca802011-02-14 18:35:15 +0000277}
278
279#if CONFIG_HW_MEM_HOLE_SIZEK != 0
280
281struct hw_mem_hole_info {
Marc Jones8d595692012-03-15 12:55:26 -0600282 unsigned hole_startk;
283 int node_id;
Frank Vibrans39fca802011-02-14 18:35:15 +0000284};
285
286static struct hw_mem_hole_info get_hw_mem_hole_info(void)
287{
Marc Jones8d595692012-03-15 12:55:26 -0600288 struct hw_mem_hole_info mem_hole;
Frank Vibrans39fca802011-02-14 18:35:15 +0000289
Marc Jones8d595692012-03-15 12:55:26 -0600290 mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK;
291 mem_hole.node_id = -1;
Frank Vibrans39fca802011-02-14 18:35:15 +0000292
Marc Jones8d595692012-03-15 12:55:26 -0600293 struct dram_base_mask_t d;
294 u32 hole;
295 d = get_dram_base_mask(0);
296 if (d.mask & 1) {
297 hole = pci_read_config32(__f1_dev[0], 0xf0);
298 if (hole & 1) { // we find the hole
299 mem_hole.hole_startk = (hole & (0xff << 24)) >> 10;
300 mem_hole.node_id = 0; // record the node No with hole
301 }
302 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000303#if 0
Marc Jones8d595692012-03-15 12:55:26 -0600304 /* We need to double check if there is speical set on base reg and limit reg
305 * are not continous instead of hole, it will find out it's hole_startk
306 */
307 if (mem_hole.node_id == -1) {
308 resource_t limitk_pri = 0;
309 struct dram_base_mask_t d;
310 resource_t base_k, limit_k;
311 d = get_dram_base_mask(0);
312 if (d.base & 1) {
313 base_k = ((resource_t) (d.base & 0x1fffff00)) << 9;
314 if (base_k <= 4 * 1024 * 1024) {
315 if (limitk_pri != base_k) { // we find the hole
316 mem_hole.hole_startk = (unsigned)limitk_pri; // must be below 4G
317 mem_hole.node_id = 0;
318 }
319 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000320
Marc Jones8d595692012-03-15 12:55:26 -0600321 limit_k =
322 ((resource_t) ((d.mask + 0x00000100) & 0x1fffff00))
323 << 9;
324 limitk_pri = limit_k;
325 }
326 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000327#endif
efdesign9805a89ab2011-06-20 17:38:49 -0700328
Marc Jones8d595692012-03-15 12:55:26 -0600329 return mem_hole;
Frank Vibrans39fca802011-02-14 18:35:15 +0000330}
331#endif
332
Marc Jones8a49ac72013-01-16 17:02:20 -0700333static void nb_read_resources(device_t dev)
Frank Vibrans39fca802011-02-14 18:35:15 +0000334{
Marc Jones8d595692012-03-15 12:55:26 -0600335 u32 nodeid;
336 struct bus *link;
Frank Vibrans39fca802011-02-14 18:35:15 +0000337
Mike Loptien58089e82013-01-29 15:45:09 -0700338 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
Frank Vibrans39fca802011-02-14 18:35:15 +0000339
Marc Jones8d595692012-03-15 12:55:26 -0600340 nodeid = amdfam14_nodeid(dev);
341 for (link = dev->link_list; link; link = link->next) {
342 if (link->children) {
343 amdfam14_link_read_bases(dev, nodeid, link->link_num);
344 }
345 }
Marc Jonesd5c998b2013-01-16 17:14:24 -0700346
347 /*
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800348 * This MMCONF resource must be reserved in the PCI domain.
Marc Jonesd5c998b2013-01-16 17:14:24 -0700349 * It is not honored by the coreboot resource allocator if it is in
350 * the APIC_CLUSTER.
351 */
352#if CONFIG_MMCONF_SUPPORT
353 struct resource *resource = new_resource(dev, 0xc0010058);
354 resource->base = CONFIG_MMCONF_BASE_ADDRESS;
355 resource->size = CONFIG_MMCONF_BUS_NUMBER * 4096 * 256;
356 resource->flags = IORESOURCE_MEM | IORESOURCE_RESERVE |
357 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
358#endif
Frank Vibrans39fca802011-02-14 18:35:15 +0000359}
360
Marc Jones8d595692012-03-15 12:55:26 -0600361static void set_resource(device_t dev, struct resource *resource, u32 nodeid)
Frank Vibrans39fca802011-02-14 18:35:15 +0000362{
Marc Jones8d595692012-03-15 12:55:26 -0600363 resource_t rbase, rend;
364 unsigned reg, link_num;
365 char buf[50];
Frank Vibrans39fca802011-02-14 18:35:15 +0000366
Mike Loptien58089e82013-01-29 15:45:09 -0700367 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
Frank Vibrans39fca802011-02-14 18:35:15 +0000368
Marc Jones8d595692012-03-15 12:55:26 -0600369 /* Make certain the resource has actually been set */
370 if (!(resource->flags & IORESOURCE_ASSIGNED)) {
371 return;
372 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000373
Marc Jones8d595692012-03-15 12:55:26 -0600374 /* If I have already stored this resource don't worry about it */
375 if (resource->flags & IORESOURCE_STORED) {
376 return;
377 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000378
Marc Jones8d595692012-03-15 12:55:26 -0600379 /* Only handle PCI memory and IO resources */
380 if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
381 return;
Frank Vibrans39fca802011-02-14 18:35:15 +0000382
Marc Jones8d595692012-03-15 12:55:26 -0600383 /* Ensure I am actually looking at a resource of function 1 */
384 if ((resource->index & 0xffff) < 0x1000) {
385 return;
386 }
387 /* Get the base address */
388 rbase = resource->base;
Frank Vibrans39fca802011-02-14 18:35:15 +0000389
Marc Jones8d595692012-03-15 12:55:26 -0600390 /* Get the limit (rounded up) */
391 rend = resource_end(resource);
Frank Vibrans39fca802011-02-14 18:35:15 +0000392
Marc Jones8d595692012-03-15 12:55:26 -0600393 /* Get the register and link */
394 reg = resource->index & 0xfff; // 4k
395 link_num = IOINDEX_LINK(resource->index);
Frank Vibrans39fca802011-02-14 18:35:15 +0000396
Marc Jones8d595692012-03-15 12:55:26 -0600397 if (resource->flags & IORESOURCE_IO) {
398 set_io_addr_reg(dev, nodeid, link_num, reg, rbase >> 8,
399 rend >> 8);
400 } else if (resource->flags & IORESOURCE_MEM) {
401 set_mmio_addr_reg(nodeid, link_num, reg, (resource->index >> 24),
402 rbase >> 8, rend >> 8, 1); // [39:8]
403 }
404 resource->flags |= IORESOURCE_STORED;
405 sprintf(buf, " <node %x link %x>", nodeid, link_num);
406 report_resource_stored(dev, resource, buf);
Frank Vibrans39fca802011-02-14 18:35:15 +0000407}
408
efdesign983f5ebd62011-09-14 13:47:17 -0600409#if CONFIG_CONSOLE_VGA_MULTI
Marc Jones8d595692012-03-15 12:55:26 -0600410extern device_t vga_pri; // the primary vga device, defined in device.c
Frank Vibrans39fca802011-02-14 18:35:15 +0000411#endif
412
413static void create_vga_resource(device_t dev, unsigned nodeid)
414{
Marc Jones8d595692012-03-15 12:55:26 -0600415 struct bus *link;
Frank Vibrans39fca802011-02-14 18:35:15 +0000416
Mike Loptien58089e82013-01-29 15:45:09 -0700417 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
Frank Vibrans39fca802011-02-14 18:35:15 +0000418
Marc Jones8d595692012-03-15 12:55:26 -0600419 /* find out which link the VGA card is connected,
420 * we only deal with the 'first' vga card */
421 for (link = dev->link_list; link; link = link->next) {
422 if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) {
efdesign983f5ebd62011-09-14 13:47:17 -0600423#if CONFIG_CONSOLE_VGA_MULTI
Marc Jones8d595692012-03-15 12:55:26 -0600424 printk(BIOS_DEBUG,
425 "VGA: vga_pri bus num = %d bus range [%d,%d]\n",
426 vga_pri->bus->secondary, link->secondary,
427 link->subordinate);
428 /* We need to make sure the vga_pri is under the link */
429 if ((vga_pri->bus->secondary >= link->secondary) &&
430 (vga_pri->bus->secondary <= link->subordinate))
Frank Vibrans39fca802011-02-14 18:35:15 +0000431#endif
Marc Jones8d595692012-03-15 12:55:26 -0600432 break;
433 }
434 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000435
Marc Jones8d595692012-03-15 12:55:26 -0600436 /* no VGA card installed */
437 if (link == NULL)
438 return;
Frank Vibrans39fca802011-02-14 18:35:15 +0000439
Marc Jones8d595692012-03-15 12:55:26 -0600440 printk(BIOS_DEBUG, "VGA: %s (aka node %d) link %d has VGA device\n",
441 dev_path(dev), nodeid, link->link_num);
442 set_vga_enable_reg(nodeid, link->link_num);
Frank Vibrans39fca802011-02-14 18:35:15 +0000443}
444
Marc Jones8a49ac72013-01-16 17:02:20 -0700445static void nb_set_resources(device_t dev)
Frank Vibrans39fca802011-02-14 18:35:15 +0000446{
Marc Jones8d595692012-03-15 12:55:26 -0600447 unsigned nodeid;
448 struct bus *bus;
449 struct resource *res;
Frank Vibrans39fca802011-02-14 18:35:15 +0000450
Mike Loptien58089e82013-01-29 15:45:09 -0700451 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
efdesign9805a89ab2011-06-20 17:38:49 -0700452
Marc Jones8d595692012-03-15 12:55:26 -0600453 /* Find the nodeid */
454 nodeid = amdfam14_nodeid(dev);
Frank Vibrans39fca802011-02-14 18:35:15 +0000455
Marc Jones8d595692012-03-15 12:55:26 -0600456 create_vga_resource(dev, nodeid);
Frank Vibrans39fca802011-02-14 18:35:15 +0000457
Marc Jones8d595692012-03-15 12:55:26 -0600458 /* Set each resource we have found */
459 for (res = dev->resource_list; res; res = res->next) {
460 set_resource(dev, res, nodeid);
461 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000462
Marc Jones8d595692012-03-15 12:55:26 -0600463 for (bus = dev->link_list; bus; bus = bus->next) {
464 if (bus->children) {
465 assign_resources(bus);
466 }
467 }
Marc Jonesd5c998b2013-01-16 17:14:24 -0700468
469 /* Print the MMCONF region if it has been reserved. */
470 res = find_resource(dev, 0xc0010058);
471 if (res) {
472 report_resource_stored(dev, res, " <mmconfig>");
473 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000474}
475
Frank Vibrans39fca802011-02-14 18:35:15 +0000476/* Domain/Root Complex related code */
477
478static void domain_read_resources(device_t dev)
479{
Marc Jones8d595692012-03-15 12:55:26 -0600480 unsigned reg;
Frank Vibrans39fca802011-02-14 18:35:15 +0000481
Mike Loptien58089e82013-01-29 15:45:09 -0700482 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
Frank Vibrans39fca802011-02-14 18:35:15 +0000483
Marc Jones8d595692012-03-15 12:55:26 -0600484 /* Find the already assigned resource pairs */
485 get_fx_devs();
486 for (reg = 0x80; reg <= 0xc0; reg += 0x08) {
487 u32 base, limit;
488 base = f1_read_config32(reg);
489 limit = f1_read_config32(reg + 0x04);
490 /* Is this register allocated? */
491 if ((base & 3) != 0) {
492 unsigned nodeid, reg_link;
493 device_t reg_dev;
494 if (reg < 0xc0) { // mmio
495 nodeid = (limit & 0xf) + (base & 0x30);
496 } else { // io
497 nodeid = (limit & 0xf) + ((base >> 4) & 0x30);
498 }
499 reg_link = (limit >> 4) & 7;
500 reg_dev = __f0_dev[nodeid];
501 if (reg_dev) {
502 /* Reserve the resource */
503 struct resource *res;
504 res =
505 new_resource(reg_dev,
506 IOINDEX(0x1000 + reg,
507 reg_link));
508 if (res) {
509 res->flags = 1;
510 }
511 }
512 }
513 }
514 /* FIXME: do we need to check extend conf space?
515 I don't believe that much preset value */
Frank Vibrans39fca802011-02-14 18:35:15 +0000516
Patrick Georgie1667822012-05-05 15:29:32 +0200517#if !CONFIG_PCI_64BIT_PREF_MEM
Marc Jones8d595692012-03-15 12:55:26 -0600518 pci_domain_read_resources(dev);
Frank Vibrans39fca802011-02-14 18:35:15 +0000519#else
Marc Jones8d595692012-03-15 12:55:26 -0600520 struct bus *link;
521 struct resource *resource;
522 for (link = dev->link_list; link; link = link->next) {
523 /* Initialize the system wide io space constraints */
524 resource = new_resource(dev, 0 | (link->link_num << 2));
525 resource->base = 0x400;
526 resource->limit = 0xffffUL;
527 resource->flags = IORESOURCE_IO;
Frank Vibrans39fca802011-02-14 18:35:15 +0000528
Marc Jones8d595692012-03-15 12:55:26 -0600529 /* Initialize the system wide prefetchable memory resources constraints */
530 resource = new_resource(dev, 1 | (link->link_num << 2));
531 resource->limit = 0xfcffffffffULL;
532 resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
Frank Vibrans39fca802011-02-14 18:35:15 +0000533
Marc Jones8d595692012-03-15 12:55:26 -0600534 /* Initialize the system wide memory resources constraints */
535 resource = new_resource(dev, 2 | (link->link_num << 2));
536 resource->limit = 0xfcffffffffULL;
537 resource->flags = IORESOURCE_MEM;
538 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000539#endif
540}
541
Kyösti Mälkki6b5eb1c2012-07-19 19:26:43 +0300542static void setup_uma_memory(void)
Kyösti Mälkki55fff9302012-07-11 08:02:39 +0300543{
544#if CONFIG_GFXUMA
Kyösti Mälkkidbc47392012-08-05 12:11:40 +0300545 uint32_t topmem = (uint32_t) bsp_topmem();
Kyösti Mälkki55fff9302012-07-11 08:02:39 +0300546 uint32_t sys_mem;
547
Kyösti Mälkki55fff9302012-07-11 08:02:39 +0300548 /* refer to UMA Size Consideration in Family14h BKDG. */
Kyösti Mälkkidbc47392012-08-05 12:11:40 +0300549 sys_mem = topmem + 0x1000000; // Ignore 16MB allocated for C6 when finding UMA size, refer MemNGetUmaSizeON()
550 if ((bsp_topmem2()>>32) || (sys_mem >= 0x80000000)) {
Kyösti Mälkki55fff9302012-07-11 08:02:39 +0300551 uma_memory_size = 0x18000000; /* >= 2G memory, 384M recommended UMA */
552 }
553 else {
554 if (sys_mem >= 0x40000000) {
555 uma_memory_size = 0x10000000; /* >= 1G memory, 256M recommended UMA */
556 } else {
557 uma_memory_size = 0x4000000; /* <1G memory, 64M recommended UMA */
558 }
559 }
560
Kyösti Mälkkidbc47392012-08-05 12:11:40 +0300561 uma_memory_base = topmem - uma_memory_size; /* TOP_MEM1 */
Kyösti Mälkki55fff9302012-07-11 08:02:39 +0300562 printk(BIOS_INFO, "%s: uma size 0x%08llx, memory start 0x%08llx\n",
563 __func__, uma_memory_size, uma_memory_base);
Kyösti Mälkki55fff9302012-07-11 08:02:39 +0300564#endif
565}
566
Frank Vibrans39fca802011-02-14 18:35:15 +0000567static void domain_set_resources(device_t dev)
568{
Mike Loptien58089e82013-01-29 15:45:09 -0700569 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
Marc Jones8d595692012-03-15 12:55:26 -0600570 printk(BIOS_DEBUG, " amsr - incoming dev = %08x\n", (u32) dev);
Frank Vibrans39fca802011-02-14 18:35:15 +0000571
Patrick Georgie1667822012-05-05 15:29:32 +0200572#if CONFIG_PCI_64BIT_PREF_MEM
Marc Jones8d595692012-03-15 12:55:26 -0600573 struct resource *io, *mem1, *mem2;
574 struct resource *res;
Frank Vibrans39fca802011-02-14 18:35:15 +0000575#endif
Marc Jones8d595692012-03-15 12:55:26 -0600576 unsigned long mmio_basek;
577 u32 pci_tolm;
578 int idx;
579 struct bus *link;
Frank Vibrans39fca802011-02-14 18:35:15 +0000580#if CONFIG_HW_MEM_HOLE_SIZEK != 0
Marc Jones8d595692012-03-15 12:55:26 -0600581 struct hw_mem_hole_info mem_hole;
582 u32 reset_memhole = 1;
Frank Vibrans39fca802011-02-14 18:35:15 +0000583#endif
584
Patrick Georgie1667822012-05-05 15:29:32 +0200585#if CONFIG_PCI_64BIT_PREF_MEM
Frank Vibrans39fca802011-02-14 18:35:15 +0000586
Marc Jones8d595692012-03-15 12:55:26 -0600587 printk(BIOS_DEBUG, "adsr - CONFIG_PCI_64BIT_PREF_MEM is true.\n");
588 for (link = dev->link_list; link; link = link->next) {
589 /* Now reallocate the pci resources memory with the
590 * highest addresses I can manage.
591 */
592 mem1 = find_resource(dev, 1 | (link->link_num << 2));
593 mem2 = find_resource(dev, 2 | (link->link_num << 2));
Frank Vibrans39fca802011-02-14 18:35:15 +0000594
Marc Jones8d595692012-03-15 12:55:26 -0600595 printk(BIOS_DEBUG,
596 "base1: 0x%08Lx limit1: 0x%08Lx size: 0x%08Lx align: %d\n",
597 (u32) (mem1->base), (u32) (mem1->limit),
598 (u32) (mem1->size), u32) (mem1->align));
599 printk(BIOS_DEBUG,
600 "base2: 0x%08Lx limit2: 0x%08Lx size: 0x%08Lx align: %d\n",
601 (u32) (mem2->base), (u32) (mem2->limit),
602 (u32) (mem2->size), (u32) (mem2->align));
Frank Vibrans39fca802011-02-14 18:35:15 +0000603
Marc Jones8d595692012-03-15 12:55:26 -0600604 /* See if both resources have roughly the same limits */
605 if (((mem1->limit <= 0xffffffff) && (mem2->limit <= 0xffffffff))
606 || ((mem1->limit > 0xffffffff)
607 && (mem2->limit > 0xffffffff))) {
608 /* If so place the one with the most stringent alignment first
609 */
610 if (mem2->align > mem1->align) {
611 struct resource *tmp;
612 tmp = mem1;
613 mem1 = mem2;
614 mem2 = tmp;
615 }
616 /* Now place the memory as high up as it will go */
617 mem2->base = resource_max(mem2);
618 mem1->limit = mem2->base - 1;
619 mem1->base = resource_max(mem1);
620 } else {
621 /* Place the resources as high up as they will go */
622 mem2->base = resource_max(mem2);
623 mem1->base = resource_max(mem1);
624 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000625
Marc Jones8d595692012-03-15 12:55:26 -0600626 printk(BIOS_DEBUG,
627 "base1: 0x%08Lx limit1: 0x%08Lx size: 0x%08Lx align: %d\n",
628 mem1->base, mem1->limit, mem1->size, mem1->align);
629 printk(BIOS_DEBUG,
630 "base2: 0x%08Lx limit2: 0x%08Lx size: 0x%08Lx align: %d\n",
631 mem2->base, mem2->limit, mem2->size, mem2->align);
632 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000633
Marc Jones8d595692012-03-15 12:55:26 -0600634 for (res = &dev->resource_list; res; res = res->next) {
635 res->flags |= IORESOURCE_ASSIGNED;
636 res->flags |= IORESOURCE_STORED;
637 report_resource_stored(dev, res, "");
638 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000639#endif
640
Marc Jones8d595692012-03-15 12:55:26 -0600641 pci_tolm = 0xffffffffUL;
642 for (link = dev->link_list; link; link = link->next) {
643 pci_tolm = my_find_pci_tolm(link, pci_tolm);
644 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000645
Marc Jones8d595692012-03-15 12:55:26 -0600646 // FIXME handle interleaved nodes. If you fix this here, please fix
647 // amdk8, too.
648 mmio_basek = pci_tolm >> 10;
649 /* Round mmio_basek to something the processor can support */
650 mmio_basek &= ~((1 << 6) - 1);
Frank Vibrans39fca802011-02-14 18:35:15 +0000651
Marc Jones8d595692012-03-15 12:55:26 -0600652 // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M
653 // MMIO hole. If you fix this here, please fix amdk8, too.
654 /* Round the mmio hole to 64M */
655 mmio_basek &= ~((64 * 1024) - 1);
Frank Vibrans39fca802011-02-14 18:35:15 +0000656
657#if CONFIG_HW_MEM_HOLE_SIZEK != 0
658/* if the hw mem hole is already set in raminit stage, here we will compare
659 * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will
660 * use hole_basek as mmio_basek and we don't need to reset hole.
661 * otherwise We reset the hole to the mmio_basek
662 */
663
Marc Jones8d595692012-03-15 12:55:26 -0600664 mem_hole = get_hw_mem_hole_info();
Frank Vibrans39fca802011-02-14 18:35:15 +0000665
Marc Jones8d595692012-03-15 12:55:26 -0600666 // Use hole_basek as mmio_basek, and we don't need to reset hole anymore
667 if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) {
668 mmio_basek = mem_hole.hole_startk;
669 reset_memhole = 0;
670 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000671#endif
672
Marc Jones8d595692012-03-15 12:55:26 -0600673 idx = 0x10;
Frank Vibrans39fca802011-02-14 18:35:15 +0000674
Marc Jones8d595692012-03-15 12:55:26 -0600675 struct dram_base_mask_t d;
676 resource_t basek, limitk, sizek; // 4 1T
Frank Vibrans39fca802011-02-14 18:35:15 +0000677
Marc Jones8d595692012-03-15 12:55:26 -0600678 d = get_dram_base_mask(0);
Frank Vibrans39fca802011-02-14 18:35:15 +0000679
Marc Jones8d595692012-03-15 12:55:26 -0600680 if (d.mask & 1) {
681 basek = ((resource_t) ((u64) d.base)) << 8;
682 limitk = (resource_t) (((u64) d.mask << 8) | 0xFFFFFF);
683 printk(BIOS_DEBUG,
684 "adsr: (before) basek = %llx, limitk = %llx.\n", basek,
685 limitk);
Frank Vibrans39fca802011-02-14 18:35:15 +0000686
Marc Jones8d595692012-03-15 12:55:26 -0600687 /* Convert these values to multiples of 1K for ease of math. */
688 basek >>= 10;
689 limitk >>= 10;
690 sizek = limitk - basek + 1;
Frank Vibrans39fca802011-02-14 18:35:15 +0000691
Marc Jones8d595692012-03-15 12:55:26 -0600692 printk(BIOS_DEBUG,
693 "adsr: (after) basek = %llx, limitk = %llx, sizek = %llx.\n",
694 basek, limitk, sizek);
Frank Vibrans39fca802011-02-14 18:35:15 +0000695
Marc Jones8d595692012-03-15 12:55:26 -0600696 /* see if we need a hole from 0xa0000 to 0xbffff */
697 if ((basek < 640) && (sizek > 768)) {
698 printk(BIOS_DEBUG,"adsr - 0xa0000 to 0xbffff resource.\n");
699 ram_resource(dev, (idx | 0), basek, 640 - basek);
700 idx += 0x10;
701 basek = 768;
702 sizek = limitk - 768;
703 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000704
Marc Jones8d595692012-03-15 12:55:26 -0600705 printk(BIOS_DEBUG,
706 "adsr: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n",
707 mmio_basek, basek, limitk);
Frank Vibrans39fca802011-02-14 18:35:15 +0000708
Marc Jones8d595692012-03-15 12:55:26 -0600709 /* split the region to accomodate pci memory space */
710 if ((basek < 4 * 1024 * 1024) && (limitk > mmio_basek)) {
711 if (basek <= mmio_basek) {
712 unsigned pre_sizek;
713 pre_sizek = mmio_basek - basek;
714 if (pre_sizek > 0) {
715 ram_resource(dev, idx, basek,
716 pre_sizek);
717 idx += 0x10;
718 sizek -= pre_sizek;
Patrick Georgie1667822012-05-05 15:29:32 +0200719#if CONFIG_WRITE_HIGH_TABLES
Marc Jones8d595692012-03-15 12:55:26 -0600720 if (high_tables_base == 0) {
721 /* Leave some space for ACPI, PIRQ and MP tables */
Patrick Georgie1667822012-05-05 15:29:32 +0200722#if CONFIG_GFXUMA
Marc Jones5750ed22012-03-15 13:21:41 -0600723 high_tables_base = uma_memory_base - HIGH_MEMORY_SIZE;
Frank Vibrans39fca802011-02-14 18:35:15 +0000724#else
Marc Jones5750ed22012-03-15 13:21:41 -0600725 high_tables_base = (mmio_basek * 1024) - HIGH_MEMORY_SIZE;
Frank Vibrans39fca802011-02-14 18:35:15 +0000726#endif
Marc Jones5750ed22012-03-15 13:21:41 -0600727 high_tables_size = HIGH_MEMORY_SIZE;
728 printk(BIOS_DEBUG, " split: %dK table at =%08llx\n",
729 (u32)(high_tables_size / 1024), high_tables_base);
Marc Jones8d595692012-03-15 12:55:26 -0600730 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000731#endif
Marc Jones8d595692012-03-15 12:55:26 -0600732 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000733
Marc Jones8d595692012-03-15 12:55:26 -0600734 basek = mmio_basek;
735 }
736 if ((basek + sizek) <= 4 * 1024 * 1024) {
737 sizek = 0;
738 } else {
739 basek = 4 * 1024 * 1024;
740 sizek -= (4 * 1024 * 1024 - mmio_basek);
741 }
742 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000743
Marc Jones8d595692012-03-15 12:55:26 -0600744 ram_resource(dev, (idx | 0), basek, sizek);
745 idx += 0x10;
Patrick Georgie1667822012-05-05 15:29:32 +0200746#if CONFIG_WRITE_HIGH_TABLES
Marc Jones8d595692012-03-15 12:55:26 -0600747 printk(BIOS_DEBUG,
748 "%d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", 0,
749 mmio_basek, basek, limitk);
750 if (high_tables_base == 0) {
751 /* Leave some space for ACPI, PIRQ and MP tables */
Patrick Georgie1667822012-05-05 15:29:32 +0200752#if CONFIG_GFXUMA
Marc Jones5750ed22012-03-15 13:21:41 -0600753 high_tables_base = uma_memory_base - HIGH_MEMORY_SIZE;
Marc Jones8d595692012-03-15 12:55:26 -0600754 printk(BIOS_DEBUG, " adsr - uma_memory_base = %llx.\n", uma_memory_base);
Frank Vibrans39fca802011-02-14 18:35:15 +0000755#else
Marc Jones5750ed22012-03-15 13:21:41 -0600756 high_tables_base = (limitk * 1024) - HIGH_MEMORY_SIZE;
Frank Vibrans39fca802011-02-14 18:35:15 +0000757#endif
Marc Jones5750ed22012-03-15 13:21:41 -0600758 high_tables_size = HIGH_MEMORY_SIZE;
Marc Jones8d595692012-03-15 12:55:26 -0600759 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000760#endif
Marc Jones8d595692012-03-15 12:55:26 -0600761 }
762 printk(BIOS_DEBUG, " adsr - mmio_basek = %lx.\n", mmio_basek);
763 printk(BIOS_DEBUG, " adsr - high_tables_size = %llx.\n",
764 high_tables_size);
Frank Vibrans39fca802011-02-14 18:35:15 +0000765
Patrick Georgie1667822012-05-05 15:29:32 +0200766#if CONFIG_GFXUMA
Kyösti Mälkki63f8c082012-07-10 13:27:26 +0300767 uma_resource(dev, 7, uma_memory_base >> 10, uma_memory_size >> 10);
Frank Vibrans39fca802011-02-14 18:35:15 +0000768#endif
769
Marc Jones8d595692012-03-15 12:55:26 -0600770 for (link = dev->link_list; link; link = link->next) {
771 if (link->children) {
772 assign_resources(link);
773 }
774 }
775 printk(BIOS_DEBUG, " adsr - leaving this lovely routine.\n");
Frank Vibrans39fca802011-02-14 18:35:15 +0000776}
777
zbaof7223732012-04-13 13:42:15 +0800778extern u8 acpi_slp_type;
779
780static void domain_enable_resources(device_t dev)
781{
Marc Jones8d595692012-03-15 12:55:26 -0600782 u32 val;
Kerry Shefeed3292011-08-18 18:03:44 +0800783
784#if CONFIG_AMD_SB_CIMX
zbaof7223732012-04-13 13:42:15 +0800785 #if CONFIG_HAVE_ACPI_RESUME
786 if (acpi_slp_type != 3) {
787 sb_After_Pci_Init();
788 sb_Mid_Post_Init();
789 } else {
790 sb_After_Pci_Restore_Init();
791 }
792 #else
Marc Jones8d595692012-03-15 12:55:26 -0600793 sb_After_Pci_Init();
794 sb_Mid_Post_Init();
zbaof7223732012-04-13 13:42:15 +0800795 #endif
Kerry Shefeed3292011-08-18 18:03:44 +0800796#endif
797
Marc Jones8d595692012-03-15 12:55:26 -0600798 /* Must be called after PCI enumeration and resource allocation */
Mike Loptien58089e82013-01-29 15:45:09 -0700799 printk(BIOS_DEBUG, "\nFam14h - %s\n", __func__);
zbaof7223732012-04-13 13:42:15 +0800800
801#if CONFIG_HAVE_ACPI_RESUME
802 if (acpi_slp_type != 3) {
803 printk(BIOS_DEBUG, "agesawrapper_amdinitmid ");
804 val = agesawrapper_amdinitmid ();
805 if (val)
806 printk(BIOS_DEBUG, "error level: %x \n", val);
807 else
808 printk(BIOS_DEBUG, "passed.\n");
Marc Jones8d595692012-03-15 12:55:26 -0600809 }
zbaof7223732012-04-13 13:42:15 +0800810#else
811 printk(BIOS_DEBUG, "agesawrapper_amdinitmid ");
812 val = agesawrapper_amdinitmid ();
813 if (val)
814 printk(BIOS_DEBUG, "error level: %x \n", val);
815 else
816 printk(BIOS_DEBUG, "passed.\n");
817#endif
efdesign9805a89ab2011-06-20 17:38:49 -0700818
Marc Jones8d595692012-03-15 12:55:26 -0600819 printk(BIOS_DEBUG, " ader - leaving domain_enable_resources.\n");
Frank Vibrans39fca802011-02-14 18:35:15 +0000820}
821
Frank Vibrans39fca802011-02-14 18:35:15 +0000822/* Bus related code */
823
Marc Jonesd5c998b2013-01-16 17:14:24 -0700824static void cpu_bus_read_resources(device_t dev)
825{
Frank Vibrans39fca802011-02-14 18:35:15 +0000826}
827
Marc Jonesd5c998b2013-01-16 17:14:24 -0700828static void cpu_bus_set_resources(device_t dev)
829{
Frank Vibrans39fca802011-02-14 18:35:15 +0000830}
efdesign9805a89ab2011-06-20 17:38:49 -0700831
zbaof7223732012-04-13 13:42:15 +0800832static u32 cpu_bus_scan(device_t dev, u32 max)
833{
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +0300834 struct bus *cpu_bus = dev->link_list;
Scott Duplichan9ab3c6c2011-05-15 21:45:46 +0000835 device_t cpu;
zbaof7223732012-04-13 13:42:15 +0800836 int apic_id, cores_found;
Scott Duplichan9ab3c6c2011-05-15 21:45:46 +0000837
zbaof7223732012-04-13 13:42:15 +0800838 /* There is only one node for fam14, but there may be multiple cores. */
839 cpu = dev_find_slot(0, PCI_DEVFN(0x18, 0));
840 if (!cpu)
841 printk(BIOS_ERR, "ERROR: %02x:%02x.0 not found", 0, 0x18);
Scott Duplichan9ab3c6c2011-05-15 21:45:46 +0000842
zbaof7223732012-04-13 13:42:15 +0800843 cores_found = (pci_read_config32(dev_find_slot(0,PCI_DEVFN(0x18,0x3)), 0xe8) >> 12) & 3;
844 printk(BIOS_DEBUG, " AP siblings=%d\n", cores_found);
845
zbaof7223732012-04-13 13:42:15 +0800846 for (apic_id = 0; apic_id <= cores_found; apic_id++) {
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +0300847 cpu = add_cpu_device(cpu_bus, apic_id, 1);
848 if (cpu)
849 amd_cpu_topology(cpu, 0, apic_id);
Marc Jones8d595692012-03-15 12:55:26 -0600850 }
zbaof7223732012-04-13 13:42:15 +0800851 return max;
852}
853
854static void cpu_bus_init(device_t dev)
855{
856 initialize_cpus(dev->link_list);
Frank Vibrans39fca802011-02-14 18:35:15 +0000857}
858
Frank Vibrans39fca802011-02-14 18:35:15 +0000859/* North Bridge Structures */
860
861static struct device_operations northbridge_operations = {
Marc Jones8a49ac72013-01-16 17:02:20 -0700862 .read_resources = nb_read_resources,
863 .set_resources = nb_set_resources,
Marc Jones8d595692012-03-15 12:55:26 -0600864 .enable_resources = pci_dev_enable_resources,
865 .init = northbridge_init,
866 .enable = 0,.ops_pci = 0,
Frank Vibrans39fca802011-02-14 18:35:15 +0000867};
868
Frank Vibrans39fca802011-02-14 18:35:15 +0000869static const struct pci_driver northbridge_driver __pci_driver = {
Marc Jones8d595692012-03-15 12:55:26 -0600870 .ops = &northbridge_operations,
871 .vendor = PCI_VENDOR_ID_AMD,
872 .device = 0x1510,
Frank Vibrans39fca802011-02-14 18:35:15 +0000873};
874
efdesign9805a89ab2011-06-20 17:38:49 -0700875struct chip_operations northbridge_amd_agesa_family14_ops = {
Marc Jones8d595692012-03-15 12:55:26 -0600876 CHIP_NAME("AMD Family 14h Northbridge")
877 .enable_dev = 0,
Frank Vibrans39fca802011-02-14 18:35:15 +0000878};
879
Frank Vibrans39fca802011-02-14 18:35:15 +0000880/* Root Complex Structures */
881
Frank Vibrans39fca802011-02-14 18:35:15 +0000882static struct device_operations pci_domain_ops = {
Marc Jones8d595692012-03-15 12:55:26 -0600883 .read_resources = domain_read_resources,
884 .set_resources = domain_set_resources,
885 .enable_resources = domain_enable_resources,
886 .init = NULL,
887 .scan_bus = pci_domain_scan_bus,
Frank Vibrans39fca802011-02-14 18:35:15 +0000888};
889
Frank Vibrans39fca802011-02-14 18:35:15 +0000890static struct device_operations cpu_bus_ops = {
Marc Jones8d595692012-03-15 12:55:26 -0600891 .read_resources = cpu_bus_read_resources,
892 .set_resources = cpu_bus_set_resources,
893 .enable_resources = NULL,
894 .init = cpu_bus_init,
zbaof7223732012-04-13 13:42:15 +0800895 .scan_bus = cpu_bus_scan,
Frank Vibrans39fca802011-02-14 18:35:15 +0000896};
897
Kyösti Mälkki87213b62012-08-27 20:00:33 +0300898static void root_complex_enable_dev(struct device *dev)
899{
900 static int done = 0;
901
902 /* Do not delay UMA setup, as a device on the PCI bus may evaluate
903 the global uma_memory variables already in its enable function. */
904 if (!done) {
905 setup_bsp_ramtop();
906 setup_uma_memory();
907 done = 1;
908 }
909
Marc Jones8d595692012-03-15 12:55:26 -0600910 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800911 if (dev->path.type == DEVICE_PATH_DOMAIN) {
Marc Jones8d595692012-03-15 12:55:26 -0600912 dev->ops = &pci_domain_ops;
913 } else if (dev->path.type == DEVICE_PATH_APIC_CLUSTER) {
914 dev->ops = &cpu_bus_ops;
915 }
Frank Vibrans39fca802011-02-14 18:35:15 +0000916}
917
efdesign9805a89ab2011-06-20 17:38:49 -0700918struct chip_operations northbridge_amd_agesa_family14_root_complex_ops = {
Marc Jones8d595692012-03-15 12:55:26 -0600919 CHIP_NAME("AMD Family 14h Root Complex")
920 .enable_dev = root_complex_enable_dev,
Frank Vibrans39fca802011-02-14 18:35:15 +0000921};