blob: 51df5ee72e62d3499e0bbafd1585af7dd2680abf [file] [log] [blame]
zbao2c08f6a2012-07-02 15:32:58 +08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012 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
Paul Menzela46a7122013-02-23 18:37:27 +010017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
zbao2c08f6a2012-07-02 15:32:58 +080018 */
19
20#include <console/console.h>
21#include <arch/io.h>
Kyösti Mälkki8ae16a42014-06-19 20:44:34 +030022#include <arch/acpi.h>
zbao2c08f6a2012-07-02 15:32:58 +080023#include <stdint.h>
24#include <device/device.h>
25#include <device/pci.h>
26#include <device/pci_ids.h>
27#include <device/hypertransport.h>
28#include <stdlib.h>
29#include <string.h>
Ronald G. Minnich5079a0d2012-11-27 11:32:38 -080030#include <lib.h>
zbao2c08f6a2012-07-02 15:32:58 +080031#include <cpu/cpu.h>
32#include <cbmem.h>
Martin Roth73e86a82013-01-17 16:28:30 -070033#include <AGESA.h>
zbao2c08f6a2012-07-02 15:32:58 +080034
35#include <cpu/x86/lapic.h>
Kyösti Mälkkidbc47392012-08-05 12:11:40 +030036#include <cpu/amd/mtrr.h>
zbao2c08f6a2012-07-02 15:32:58 +080037
38#include <Porting.h>
zbao2c08f6a2012-07-02 15:32:58 +080039#include <Options.h>
40#include <Topology.h>
41#include <cpu/amd/amdfam15.h>
42#include <cpuRegisters.h>
43#include "agesawrapper.h"
zbao2c08f6a2012-07-02 15:32:58 +080044#include "northbridge.h"
zbao2c08f6a2012-07-02 15:32:58 +080045
46#define MAX_NODE_NUMS (MAX_NODES * MAX_DIES)
47
48#if (defined CONFIG_EXT_CONF_SUPPORT) && CONFIG_EXT_CONF_SUPPORT == 1
49#error CONFIG_EXT_CONF_SUPPORT == 1 not support anymore!
50#endif
51
52typedef struct dram_base_mask {
53 u32 base; //[47:27] at [28:8]
54 u32 mask; //[47:27] at [28:8] and enable at bit 0
55} dram_base_mask_t;
56
57static unsigned node_nums;
58static unsigned sblink;
59static device_t __f0_dev[MAX_NODE_NUMS];
60static device_t __f1_dev[MAX_NODE_NUMS];
61static device_t __f2_dev[MAX_NODE_NUMS];
62static device_t __f4_dev[MAX_NODE_NUMS];
63static unsigned fx_devs = 0;
64
65static dram_base_mask_t get_dram_base_mask(u32 nodeid)
66{
67 device_t dev;
68 dram_base_mask_t d;
69 dev = __f1_dev[0];
70 u32 temp;
71 temp = pci_read_config32(dev, 0x44 + (nodeid << 3)); //[39:24] at [31:16]
72 d.mask = ((temp & 0xfff80000)>>(8+3)); // mask out DramMask [26:24] too
73 temp = pci_read_config32(dev, 0x144 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
74 d.mask |= temp<<21;
75 temp = pci_read_config32(dev, 0x40 + (nodeid << 3)); //[39:24] at [31:16]
76 d.mask |= (temp & 1); // enable bit
77 d.base = ((temp & 0xfff80000)>>(8+3)); // mask out DramBase [26:24) too
78 temp = pci_read_config32(dev, 0x140 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
79 d.base |= temp<<21;
80 return d;
81}
82
83static void set_io_addr_reg(device_t dev, u32 nodeid, u32 linkn, u32 reg,
84 u32 io_min, u32 io_max)
85{
86 u32 i;
87 u32 tempreg;
88 /* io range allocation */
89 tempreg = (nodeid&0xf) | ((nodeid & 0x30)<<(8-4)) | (linkn<<4) | ((io_max&0xf0)<<(12-4)); //limit
90 for (i=0; i<node_nums; i++)
91 pci_write_config32(__f1_dev[i], reg+4, tempreg);
92 tempreg = 3 /*| ( 3<<4)*/ | ((io_min&0xf0)<<(12-4)); //base :ISA and VGA ?
93#if 0
94 // FIXME: can we use VGA reg instead?
95 if (dev->link[link].bridge_ctrl & PCI_BRIDGE_CTL_VGA) {
96 printk(BIOS_SPEW, "%s, enabling legacy VGA IO forwarding for %s link %s\n",
97 __func__, dev_path(dev), link);
98 tempreg |= PCI_IO_BASE_VGA_EN;
99 }
100 if (dev->link[link].bridge_ctrl & PCI_BRIDGE_CTL_NO_ISA) {
101 tempreg |= PCI_IO_BASE_NO_ISA;
102 }
103#endif
104 for (i=0; i<node_nums; i++)
105 pci_write_config32(__f1_dev[i], reg, tempreg);
106}
107
108static void set_mmio_addr_reg(u32 nodeid, u32 linkn, u32 reg, u32 index, u32 mmio_min, u32 mmio_max, u32 nodes)
109{
110 u32 i;
111 u32 tempreg;
112 /* io range allocation */
113 tempreg = (nodeid&0xf) | (linkn<<4) | (mmio_max&0xffffff00); //limit
114 for (i=0; i<nodes; i++)
115 pci_write_config32(__f1_dev[i], reg+4, tempreg);
116 tempreg = 3 | (nodeid & 0x30) | (mmio_min&0xffffff00);
117 for (i=0; i<node_nums; i++)
118 pci_write_config32(__f1_dev[i], reg, tempreg);
119}
120
121static device_t get_node_pci(u32 nodeid, u32 fn)
122{
zbaod4627362012-07-23 19:49:40 +0800123#if MAX_NODE_NUMS + CONFIG_CDB >= 32
124 if ((CONFIG_CDB + nodeid) < 32) {
zbao2c08f6a2012-07-02 15:32:58 +0800125 return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn));
126 } else {
127 return dev_find_slot(CONFIG_CBB-1, PCI_DEVFN(CONFIG_CDB + nodeid - 32, fn));
128 }
129#else
130 return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn));
131#endif
132}
133
134static void get_fx_devs(void)
135{
136 int i;
137 for (i = 0; i < MAX_NODE_NUMS; i++) {
138 __f0_dev[i] = get_node_pci(i, 0);
139 __f1_dev[i] = get_node_pci(i, 1);
140 __f2_dev[i] = get_node_pci(i, 2);
141 __f4_dev[i] = get_node_pci(i, 4);
142 if (__f0_dev[i] != NULL && __f1_dev[i] != NULL)
143 fx_devs = i+1;
144 }
145 if (__f1_dev[0] == NULL || __f0_dev[0] == NULL || fx_devs == 0) {
146 die("Cannot find 0:0x18.[0|1]\n");
147 }
148 printk(BIOS_DEBUG, "fx_devs=0x%x\n", fx_devs);
149}
150
151static u32 f1_read_config32(unsigned reg)
152{
153 if (fx_devs == 0)
154 get_fx_devs();
155 return pci_read_config32(__f1_dev[0], reg);
156}
157
158static void f1_write_config32(unsigned reg, u32 value)
159{
160 int i;
161 if (fx_devs == 0)
162 get_fx_devs();
163 for(i = 0; i < fx_devs; i++) {
164 device_t dev;
165 dev = __f1_dev[i];
166 if (dev && dev->enabled) {
167 pci_write_config32(dev, reg, value);
168 }
169 }
170}
171
172static u32 amdfam15_nodeid(device_t dev)
173{
174#if MAX_NODE_NUMS == 64
175 unsigned busn;
176 busn = dev->bus->secondary;
177 if (busn != CONFIG_CBB) {
178 return (dev->path.pci.devfn >> 3) - CONFIG_CDB + 32;
179 } else {
180 return (dev->path.pci.devfn >> 3) - CONFIG_CDB;
181 }
182
183#else
184 return (dev->path.pci.devfn >> 3) - CONFIG_CDB;
185#endif
186}
187
188static void set_vga_enable_reg(u32 nodeid, u32 linkn)
189{
190 u32 val;
191
192 val = 1 | (nodeid<<4) | (linkn<<12);
193 /* it will routing
194 * (1)mmio 0xa0000:0xbffff
195 * (2)io 0x3b0:0x3bb, 0x3c0:0x3df
196 */
197 f1_write_config32(0xf4, val);
198
199}
200
201/**
202 * @return
203 * @retval 2 resoure not exist, usable
204 * @retval 0 resource exist, not usable
205 * @retval 1 resource exist, resource has been allocated before
206 */
207static int reg_useable(unsigned reg, device_t goal_dev, unsigned goal_nodeid,
208 unsigned goal_link)
209{
210 struct resource *res;
211 unsigned nodeid, link = 0;
212 int result;
213 res = 0;
214 for (nodeid = 0; !res && (nodeid < fx_devs); nodeid++) {
215 device_t dev;
216 dev = __f0_dev[nodeid];
217 if (!dev)
218 continue;
219 for (link = 0; !res && (link < 8); link++) {
220 res = probe_resource(dev, IOINDEX(0x1000 + reg, link));
221 }
222 }
223 result = 2;
224 if (res) {
225 result = 0;
226 if ((goal_link == (link - 1)) &&
227 (goal_nodeid == (nodeid - 1)) &&
228 (res->flags <= 1)) {
229 result = 1;
230 }
231 }
232 return result;
233}
234
235static struct resource *amdfam15_find_iopair(device_t dev, unsigned nodeid, unsigned link)
236{
237 struct resource *resource;
238 u32 free_reg, reg;
239 resource = 0;
240 free_reg = 0;
241 for (reg = 0xc0; reg <= 0xd8; reg += 0x8) {
242 int result;
243 result = reg_useable(reg, dev, nodeid, link);
244 if (result == 1) {
245 /* I have been allocated this one */
246 break;
247 }
248 else if (result > 1) {
249 /* I have a free register pair */
250 free_reg = reg;
251 }
252 }
253 if (reg > 0xd8) {
254 reg = free_reg; // if no free, the free_reg still be 0
255 }
256
257 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
258
259 return resource;
260}
261
262static struct resource *amdfam15_find_mempair(device_t dev, u32 nodeid, u32 link)
263{
264 struct resource *resource;
265 u32 free_reg, reg;
266 resource = 0;
267 free_reg = 0;
268 for (reg = 0x80; reg <= 0xb8; reg += 0x8) {
269 int result;
270 result = reg_useable(reg, dev, nodeid, link);
271 if (result == 1) {
272 /* I have been allocated this one */
273 break;
274 }
275 else if (result > 1) {
276 /* I have a free register pair */
277 free_reg = reg;
278 }
279 }
280 if (reg > 0xb8) {
281 reg = free_reg;
282 }
283
284 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
285 return resource;
286}
287
288static void amdfam15_link_read_bases(device_t dev, u32 nodeid, u32 link)
289{
290 struct resource *resource;
291
292 /* Initialize the io space constraints on the current bus */
293 resource = amdfam15_find_iopair(dev, nodeid, link);
294 if (resource) {
295 u32 align;
296 align = log2(HT_IO_HOST_ALIGN);
297 resource->base = 0;
298 resource->size = 0;
299 resource->align = align;
300 resource->gran = align;
301 resource->limit = 0xffffUL;
302 resource->flags = IORESOURCE_IO | IORESOURCE_BRIDGE;
303 }
304
305 /* Initialize the prefetchable memory constraints on the current bus */
306 resource = amdfam15_find_mempair(dev, nodeid, link);
307 if (resource) {
308 resource->base = 0;
309 resource->size = 0;
310 resource->align = log2(HT_MEM_HOST_ALIGN);
311 resource->gran = log2(HT_MEM_HOST_ALIGN);
312 resource->limit = 0xffffffffffULL;
313 resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
314 resource->flags |= IORESOURCE_BRIDGE;
315 }
316
317 /* Initialize the memory constraints on the current bus */
318 resource = amdfam15_find_mempair(dev, nodeid, link);
319 if (resource) {
320 resource->base = 0;
321 resource->size = 0;
322 resource->align = log2(HT_MEM_HOST_ALIGN);
323 resource->gran = log2(HT_MEM_HOST_ALIGN);
324 resource->limit = 0xffffffffffULL;
325 resource->flags = IORESOURCE_MEM | IORESOURCE_BRIDGE;
326 }
327
328}
329
Steven Sherkf4340582013-01-29 16:13:35 -0700330static void nb_read_resources(device_t dev)
zbao2c08f6a2012-07-02 15:32:58 +0800331{
332 u32 nodeid;
333 struct bus *link;
334
335 nodeid = amdfam15_nodeid(dev);
336 for (link = dev->link_list; link; link = link->next) {
337 if (link->children) {
338 amdfam15_link_read_bases(dev, nodeid, link->link_num);
339 }
340 }
Steven Sherk1cbabb02013-02-01 09:22:35 -0700341
342 /*
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800343 * This MMCONF resource must be reserved in the PCI domain.
Steven Sherk1cbabb02013-02-01 09:22:35 -0700344 * It is not honored by the coreboot resource allocator if it is in
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800345 * the CPU_CLUSTER.
Steven Sherk1cbabb02013-02-01 09:22:35 -0700346 */
347#if CONFIG_MMCONF_SUPPORT
348 struct resource *resource = new_resource(dev, 0xc0010058);
349 resource->base = CONFIG_MMCONF_BASE_ADDRESS;
350 resource->size = CONFIG_MMCONF_BUS_NUMBER * 4096 * 256;
351 resource->flags = IORESOURCE_MEM | IORESOURCE_RESERVE |
352 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
353#endif
zbao2c08f6a2012-07-02 15:32:58 +0800354}
355
356static void set_resource(device_t dev, struct resource *resource, u32 nodeid)
357{
358 resource_t rbase, rend;
359 unsigned reg, link_num;
360 char buf[50];
361
362 /* Make certain the resource has actually been set */
363 if (!(resource->flags & IORESOURCE_ASSIGNED)) {
364 return;
365 }
366
367 /* If I have already stored this resource don't worry about it */
368 if (resource->flags & IORESOURCE_STORED) {
369 return;
370 }
371
372 /* Only handle PCI memory and IO resources */
373 if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
374 return;
375
376 /* Ensure I am actually looking at a resource of function 1 */
377 if ((resource->index & 0xffff) < 0x1000) {
378 return;
379 }
380 /* Get the base address */
381 rbase = resource->base;
382
383 /* Get the limit (rounded up) */
384 rend = resource_end(resource);
385
386 /* Get the register and link */
387 reg = resource->index & 0xfff; // 4k
388 link_num = IOINDEX_LINK(resource->index);
389
390 if (resource->flags & IORESOURCE_IO) {
391 set_io_addr_reg(dev, nodeid, link_num, reg, rbase>>8, rend>>8);
392 }
393 else if (resource->flags & IORESOURCE_MEM) {
394 set_mmio_addr_reg(nodeid, link_num, reg, (resource->index >>24), rbase>>8, rend>>8, node_nums) ;// [39:8]
395 }
396 resource->flags |= IORESOURCE_STORED;
Vladimir Serbinenkoa37383d2013-11-26 02:41:26 +0100397 snprintf(buf, sizeof (buf), " <node %x link %x>",
zbao2c08f6a2012-07-02 15:32:58 +0800398 nodeid, link_num);
399 report_resource_stored(dev, resource, buf);
400}
401
402/**
403 * I tried to reuse the resource allocation code in set_resource()
404 * but it is too difficult to deal with the resource allocation magic.
405 */
406
407static void create_vga_resource(device_t dev, unsigned nodeid)
408{
409 struct bus *link;
410
411 /* find out which link the VGA card is connected,
412 * we only deal with the 'first' vga card */
413 for (link = dev->link_list; link; link = link->next) {
414 if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) {
zbaod59d6242012-07-23 19:41:03 +0800415#if CONFIG_MULTIPLE_VGA_ADAPTERS
zbao2c08f6a2012-07-02 15:32:58 +0800416 extern device_t vga_pri; // the primary vga device, defined in device.c
417 printk(BIOS_DEBUG, "VGA: vga_pri bus num = %d bus range [%d,%d]\n", vga_pri->bus->secondary,
418 link->secondary,link->subordinate);
419 /* We need to make sure the vga_pri is under the link */
420 if((vga_pri->bus->secondary >= link->secondary ) &&
421 (vga_pri->bus->secondary <= link->subordinate )
422 )
423#endif
424 break;
425 }
426 }
427
428 /* no VGA card installed */
429 if (link == NULL)
430 return;
431
432 printk(BIOS_DEBUG, "VGA: %s (aka node %d) link %d has VGA device\n", dev_path(dev), nodeid, sblink);
433 set_vga_enable_reg(nodeid, sblink);
434}
435
Steven Sherkf4340582013-01-29 16:13:35 -0700436static void nb_set_resources(device_t dev)
zbao2c08f6a2012-07-02 15:32:58 +0800437{
438 unsigned nodeid;
439 struct bus *bus;
440 struct resource *res;
441
442 /* Find the nodeid */
443 nodeid = amdfam15_nodeid(dev);
444
445 create_vga_resource(dev, nodeid); //TODO: do we need this?
446
447 /* Set each resource we have found */
448 for (res = dev->resource_list; res; res = res->next) {
449 set_resource(dev, res, nodeid);
450 }
451
452 for (bus = dev->link_list; bus; bus = bus->next) {
453 if (bus->children) {
454 assign_resources(bus);
455 }
456 }
Steven Sherk1cbabb02013-02-01 09:22:35 -0700457
458 /* Print the MMCONF region if it has been reserved. */
459 res = find_resource(dev, 0xc0010058);
460 if (res) {
461 report_resource_stored(dev, res, " <mmconfig>");
462 }
zbao2c08f6a2012-07-02 15:32:58 +0800463}
464
465static void northbridge_init(struct device *dev)
466{
467}
468
zbaod59d6242012-07-23 19:41:03 +0800469
zbao2c08f6a2012-07-02 15:32:58 +0800470static struct device_operations northbridge_operations = {
Steven Sherkf4340582013-01-29 16:13:35 -0700471 .read_resources = nb_read_resources,
472 .set_resources = nb_set_resources,
zbao2c08f6a2012-07-02 15:32:58 +0800473 .enable_resources = pci_dev_enable_resources,
474 .init = northbridge_init,
zbao2c08f6a2012-07-02 15:32:58 +0800475 .enable = 0,
476 .ops_pci = 0,
477};
478
479static const struct pci_driver family15_northbridge __pci_driver = {
480 .ops = &northbridge_operations,
481 .vendor = PCI_VENDOR_ID_AMD,
482 .device = PCI_DEVICE_ID_AMD_15H_MODEL_001F_NB_HT,
483};
484
485static const struct pci_driver family10_northbridge __pci_driver = {
486 .ops = &northbridge_operations,
487 .vendor = PCI_VENDOR_ID_AMD,
488 .device = PCI_DEVICE_ID_AMD_10H_NB_HT,
489};
490
491struct chip_operations northbridge_amd_agesa_family15tn_ops = {
492 CHIP_NAME("AMD FAM15 Northbridge")
493 .enable_dev = 0,
494};
495
496static void domain_read_resources(device_t dev)
497{
498 unsigned reg;
499
500 /* Find the already assigned resource pairs */
501 get_fx_devs();
502 for (reg = 0x80; reg <= 0xd8; reg+= 0x08) {
503 u32 base, limit;
504 base = f1_read_config32(reg);
505 limit = f1_read_config32(reg + 0x04);
506 /* Is this register allocated? */
507 if ((base & 3) != 0) {
508 unsigned nodeid, reg_link;
509 device_t reg_dev;
510 if (reg<0xc0) { // mmio
511 nodeid = (limit & 0xf) + (base&0x30);
512 } else { // io
513 nodeid = (limit & 0xf) + ((base>>4)&0x30);
514 }
515 reg_link = (limit >> 4) & 7;
516 reg_dev = __f0_dev[nodeid];
517 if (reg_dev) {
518 /* Reserve the resource */
519 struct resource *res;
520 res = new_resource(reg_dev, IOINDEX(0x1000 + reg, reg_link));
521 if (res) {
522 res->flags = 1;
523 }
524 }
525 }
526 }
527 /* FIXME: do we need to check extend conf space?
528 I don't believe that much preset value */
529
zbaod59d6242012-07-23 19:41:03 +0800530#if !CONFIG_PCI_64BIT_PREF_MEM
zbao2c08f6a2012-07-02 15:32:58 +0800531 pci_domain_read_resources(dev);
532
533#else
534 struct bus *link;
535 struct resource *resource;
536 for (link=dev->link_list; link; link = link->next) {
537 /* Initialize the system wide io space constraints */
538 resource = new_resource(dev, 0|(link->link_num<<2));
539 resource->base = 0x400;
540 resource->limit = 0xffffUL;
541 resource->flags = IORESOURCE_IO;
542
543 /* Initialize the system wide prefetchable memory resources constraints */
544 resource = new_resource(dev, 1|(link->link_num<<2));
545 resource->limit = 0xfcffffffffULL;
546 resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
547
548 /* Initialize the system wide memory resources constraints */
549 resource = new_resource(dev, 2|(link->link_num<<2));
550 resource->limit = 0xfcffffffffULL;
551 resource->flags = IORESOURCE_MEM;
552 }
553#endif
554}
555
zbao2c08f6a2012-07-02 15:32:58 +0800556static void domain_enable_resources(device_t dev)
557{
558 u32 val;
Kyösti Mälkki8ae16a42014-06-19 20:44:34 +0300559 if (acpi_is_wakeup_s3())
zbao2c08f6a2012-07-02 15:32:58 +0800560 agesawrapper_fchs3laterestore();
zbao2c08f6a2012-07-02 15:32:58 +0800561
562 /* Must be called after PCI enumeration and resource allocation */
Mike Loptiene133aab2013-01-30 16:00:43 -0700563 printk(BIOS_DEBUG, "\nFam15 - %s: AmdInitMid.\n", __func__);
Kyösti Mälkki8ae16a42014-06-19 20:44:34 +0300564 if (!acpi_is_wakeup_s3()) {
zbao2c08f6a2012-07-02 15:32:58 +0800565 printk(BIOS_DEBUG, "agesawrapper_amdinitmid ");
566 val = agesawrapper_amdinitmid ();
567 if (val)
568 printk(BIOS_DEBUG, "error level: %x \n", val);
569 else
570 printk(BIOS_DEBUG, "passed.\n");
571 }
zbao2c08f6a2012-07-02 15:32:58 +0800572
Mike Loptiene133aab2013-01-30 16:00:43 -0700573 printk(BIOS_DEBUG, " ader - leaving %s.\n", __func__);
zbao2c08f6a2012-07-02 15:32:58 +0800574}
575
576#if CONFIG_HW_MEM_HOLE_SIZEK != 0
577struct hw_mem_hole_info {
578 unsigned hole_startk;
579 int node_id;
580};
581static struct hw_mem_hole_info get_hw_mem_hole_info(void)
582{
583 struct hw_mem_hole_info mem_hole;
584 int i;
585 mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK;
586 mem_hole.node_id = -1;
587 for (i = 0; i < node_nums; i++) {
588 dram_base_mask_t d;
589 u32 hole;
590 d = get_dram_base_mask(i);
591 if (!(d.mask & 1)) continue; // no memory on this node
592 hole = pci_read_config32(__f1_dev[i], 0xf0);
593 if (hole & 1) { // we find the hole
594 mem_hole.hole_startk = (hole & (0xff<<24)) >> 10;
595 mem_hole.node_id = i; // record the node No with hole
596 break; // only one hole
597 }
598 }
599 //We need to double check if there is speical set on base reg and limit reg are not continous instead of hole, it will find out it's hole_startk
600 if (mem_hole.node_id == -1) {
601 resource_t limitk_pri = 0;
602 for (i=0; i<node_nums; i++) {
603 dram_base_mask_t d;
604 resource_t base_k, limit_k;
605 d = get_dram_base_mask(i);
606 if (!(d.base & 1)) continue;
607 base_k = ((resource_t)(d.base & 0x1fffff00)) <<9;
608 if (base_k > 4 *1024 * 1024) break; // don't need to go to check
609 if (limitk_pri != base_k) { // we find the hole
610 mem_hole.hole_startk = (unsigned)limitk_pri; // must beblow 4G
611 mem_hole.node_id = i;
612 break; //only one hole
613 }
zbao15dc3cc2012-08-03 15:56:21 +0800614 limit_k = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
zbao2c08f6a2012-07-02 15:32:58 +0800615 limitk_pri = limit_k;
616 }
617 }
618 return mem_hole;
619}
620#endif
621
zbao405cfe22012-07-23 19:44:29 +0800622#define ONE_MB_SHIFT 20
zbao6db7f342012-07-19 16:38:12 +0800623
Kyösti Mälkki6b5eb1c2012-07-19 19:26:43 +0300624static void setup_uma_memory(void)
zbao6db7f342012-07-19 16:38:12 +0800625{
626#if CONFIG_GFXUMA
Kyösti Mälkkidbc47392012-08-05 12:11:40 +0300627 uint32_t topmem = (uint32_t) bsp_topmem();
zbao6db7f342012-07-19 16:38:12 +0800628 uint32_t sys_mem;
629
zbao6db7f342012-07-19 16:38:12 +0800630 /* refer to UMA Size Consideration in Family15h BKDG. */
631 /* Please reference MemNGetUmaSizeOR () */
632 /*
633 * Total system memory UMASize
634 * >= 2G 512M
635 * >=1G 256M
636 * <1G 64M
637 */
Kyösti Mälkkidbc47392012-08-05 12:11:40 +0300638 sys_mem = topmem + (16 << ONE_MB_SHIFT); // Ignore 16MB allocated for C6 when finding UMA size
639 if ((bsp_topmem2()>>32) || (sys_mem >= 2048 << ONE_MB_SHIFT)) {
zbao405cfe22012-07-23 19:44:29 +0800640 uma_memory_size = 512 << ONE_MB_SHIFT;
641 } else if (sys_mem >= 1024 << ONE_MB_SHIFT) {
642 uma_memory_size = 256 << ONE_MB_SHIFT;
zbao6db7f342012-07-19 16:38:12 +0800643 } else {
zbao405cfe22012-07-23 19:44:29 +0800644 uma_memory_size = 64 << ONE_MB_SHIFT;
zbao6db7f342012-07-19 16:38:12 +0800645 }
Kyösti Mälkkidbc47392012-08-05 12:11:40 +0300646 uma_memory_base = topmem - uma_memory_size; /* TOP_MEM1 */
zbao6db7f342012-07-19 16:38:12 +0800647
648 printk(BIOS_INFO, "%s: uma size 0x%08llx, memory start 0x%08llx\n",
649 __func__, uma_memory_size, uma_memory_base);
zbao6db7f342012-07-19 16:38:12 +0800650#endif
651}
652
653
zbao2c08f6a2012-07-02 15:32:58 +0800654static void domain_set_resources(device_t dev)
655{
zbaod59d6242012-07-23 19:41:03 +0800656#if CONFIG_PCI_64BIT_PREF_MEM
zbao2c08f6a2012-07-02 15:32:58 +0800657 struct resource *io, *mem1, *mem2;
658 struct resource *res;
659#endif
660 unsigned long mmio_basek;
661 u32 pci_tolm;
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300662 u64 ramtop = 0;
zbao2c08f6a2012-07-02 15:32:58 +0800663 int i, idx;
664 struct bus *link;
665#if CONFIG_HW_MEM_HOLE_SIZEK != 0
666 struct hw_mem_hole_info mem_hole;
667 u32 reset_memhole = 1;
668#endif
669
zbaod59d6242012-07-23 19:41:03 +0800670#if CONFIG_PCI_64BIT_PREF_MEM
zbao2c08f6a2012-07-02 15:32:58 +0800671
672 for (link = dev->link_list; link; link = link->next) {
673 /* Now reallocate the pci resources memory with the
674 * highest addresses I can manage.
675 */
676 mem1 = find_resource(dev, 1|(link->link_num<<2));
677 mem2 = find_resource(dev, 2|(link->link_num<<2));
678
679 printk(BIOS_DEBUG, "base1: 0x%08Lx limit1: 0x%08Lx size: 0x%08Lx align: %d\n",
680 mem1->base, mem1->limit, mem1->size, mem1->align);
681 printk(BIOS_DEBUG, "base2: 0x%08Lx limit2: 0x%08Lx size: 0x%08Lx align: %d\n",
682 mem2->base, mem2->limit, mem2->size, mem2->align);
683
684 /* See if both resources have roughly the same limits */
685 if (((mem1->limit <= 0xffffffff) && (mem2->limit <= 0xffffffff)) ||
686 ((mem1->limit > 0xffffffff) && (mem2->limit > 0xffffffff)))
687 {
688 /* If so place the one with the most stringent alignment first */
689 if (mem2->align > mem1->align) {
690 struct resource *tmp;
691 tmp = mem1;
692 mem1 = mem2;
693 mem2 = tmp;
694 }
695 /* Now place the memory as high up as it will go */
696 mem2->base = resource_max(mem2);
697 mem1->limit = mem2->base - 1;
698 mem1->base = resource_max(mem1);
699 }
700 else {
701 /* Place the resources as high up as they will go */
702 mem2->base = resource_max(mem2);
703 mem1->base = resource_max(mem1);
704 }
705
706 printk(BIOS_DEBUG, "base1: 0x%08Lx limit1: 0x%08Lx size: 0x%08Lx align: %d\n",
707 mem1->base, mem1->limit, mem1->size, mem1->align);
708 printk(BIOS_DEBUG, "base2: 0x%08Lx limit2: 0x%08Lx size: 0x%08Lx align: %d\n",
709 mem2->base, mem2->limit, mem2->size, mem2->align);
710 }
711
712 for (res = &dev->resource_list; res; res = res->next)
713 {
714 res->flags |= IORESOURCE_ASSIGNED;
715 res->flags |= IORESOURCE_STORED;
716 report_resource_stored(dev, res, "");
717 }
718#endif
719
720 pci_tolm = 0xffffffffUL;
721 for (link = dev->link_list; link; link = link->next) {
722 pci_tolm = find_pci_tolm(link);
723 }
724
725 // FIXME handle interleaved nodes. If you fix this here, please fix
726 // amdk8, too.
727 mmio_basek = pci_tolm >> 10;
728 /* Round mmio_basek to something the processor can support */
729 mmio_basek &= ~((1 << 6) -1);
730
731 // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M
732 // MMIO hole. If you fix this here, please fix amdk8, too.
733 /* Round the mmio hole to 64M */
734 mmio_basek &= ~((64*1024) - 1);
735
736#if CONFIG_HW_MEM_HOLE_SIZEK != 0
737 /* if the hw mem hole is already set in raminit stage, here we will compare
738 * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will
739 * use hole_basek as mmio_basek and we don't need to reset hole.
740 * otherwise We reset the hole to the mmio_basek
741 */
742
743 mem_hole = get_hw_mem_hole_info();
744
745 // Use hole_basek as mmio_basek, and we don't need to reset hole anymore
746 if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) {
747 mmio_basek = mem_hole.hole_startk;
748 reset_memhole = 0;
749 }
750#endif
751
752 idx = 0x10;
753 for (i = 0; i < node_nums; i++) {
754 dram_base_mask_t d;
755 resource_t basek, limitk, sizek; // 4 1T
756
757 d = get_dram_base_mask(i);
758
759 if (!(d.mask & 1)) continue;
760 basek = ((resource_t)(d.base & 0x1fffff00)) << 9; // could overflow, we may lost 6 bit here
zbao9fd183e2012-08-01 18:23:49 +0800761 limitk = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9 ;
zbao2c08f6a2012-07-02 15:32:58 +0800762
763 sizek = limitk - basek;
764
765 /* see if we need a hole from 0xa0000 to 0xbffff */
766 if ((basek < ((8*64)+(8*16))) && (sizek > ((8*64)+(16*16)))) {
767 ram_resource(dev, (idx | i), basek, ((8*64)+(8*16)) - basek);
768 idx += 0x10;
769 basek = (8*64)+(16*16);
770 sizek = limitk - ((8*64)+(16*16));
771
772 }
773
774 //printk(BIOS_DEBUG, "node %d : mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", i, mmio_basek, basek, limitk);
775
Kyösti Mälkki26c65432014-06-26 05:30:54 +0300776 /* split the region to accommodate pci memory space */
zbao2c08f6a2012-07-02 15:32:58 +0800777 if ((basek < 4*1024*1024 ) && (limitk > mmio_basek)) {
778 if (basek <= mmio_basek) {
779 unsigned pre_sizek;
780 pre_sizek = mmio_basek - basek;
781 if (pre_sizek>0) {
782 ram_resource(dev, (idx | i), basek, pre_sizek);
783 idx += 0x10;
784 sizek -= pre_sizek;
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300785 if (!ramtop)
786 ramtop = mmio_basek * 1024;
zbao2c08f6a2012-07-02 15:32:58 +0800787 }
788 basek = mmio_basek;
789 }
790 if ((basek + sizek) <= 4*1024*1024) {
791 sizek = 0;
792 }
793 else {
Siyuan Wang29840e22013-06-04 19:56:22 +0800794 uint64_t topmem2 = bsp_topmem2();
zbao2c08f6a2012-07-02 15:32:58 +0800795 basek = 4*1024*1024;
Siyuan Wang29840e22013-06-04 19:56:22 +0800796 sizek = topmem2/1024 - basek;
zbao2c08f6a2012-07-02 15:32:58 +0800797 }
798 }
799
zbao2c08f6a2012-07-02 15:32:58 +0800800 ram_resource(dev, (idx | i), basek, sizek);
801 idx += 0x10;
zbao2c08f6a2012-07-02 15:32:58 +0800802 printk(BIOS_DEBUG, "node %d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n",
803 i, mmio_basek, basek, limitk);
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300804 if (!ramtop)
805 ramtop = limitk * 1024;
zbao2c08f6a2012-07-02 15:32:58 +0800806 }
807
Kyösti Mälkki63f8c082012-07-10 13:27:26 +0300808#if CONFIG_GFXUMA
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300809 set_top_of_ram(uma_memory_base);
Kyösti Mälkki63f8c082012-07-10 13:27:26 +0300810 uma_resource(dev, 7, uma_memory_base >> 10, uma_memory_size >> 10);
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300811#else
812 set_top_of_ram(ramtop);
zbao2c08f6a2012-07-02 15:32:58 +0800813#endif
814
815 for(link = dev->link_list; link; link = link->next) {
816 if (link->children) {
817 assign_resources(link);
818 }
819 }
820}
821
822static struct device_operations pci_domain_ops = {
823 .read_resources = domain_read_resources,
824 .set_resources = domain_set_resources,
825 .enable_resources = domain_enable_resources,
826 .init = NULL,
827 .scan_bus = pci_domain_scan_bus,
Kyösti Mälkki872c9222013-07-03 09:44:28 +0300828 .ops_pci_bus = pci_bus_default_ops,
zbao2c08f6a2012-07-02 15:32:58 +0800829};
830
831static void sysconf_init(device_t dev) // first node
832{
833 sblink = (pci_read_config32(dev, 0x64)>>8) & 7; // don't forget sublink1
834 node_nums = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; //NodeCnt[2:0]
835}
836
837static void add_more_links(device_t dev, unsigned total_links)
838{
839 struct bus *link, *last = NULL;
840 int link_num;
841
842 for (link = dev->link_list; link; link = link->next)
843 last = link;
844
845 if (last) {
846 int links = total_links - last->link_num;
847 link_num = last->link_num;
848 if (links > 0) {
849 link = malloc(links*sizeof(*link));
850 if (!link)
851 die("Couldn't allocate more links!\n");
852 memset(link, 0, links*sizeof(*link));
853 last->next = link;
854 }
855 }
856 else {
857 link_num = -1;
858 link = malloc(total_links*sizeof(*link));
859 memset(link, 0, total_links*sizeof(*link));
860 dev->link_list = link;
861 }
862
863 for (link_num = link_num + 1; link_num < total_links; link_num++) {
864 link->link_num = link_num;
865 link->dev = dev;
866 link->next = link + 1;
867 last = link;
868 link = link->next;
869 }
870 last->next = NULL;
871}
872
zbao2c08f6a2012-07-02 15:32:58 +0800873static u32 cpu_bus_scan(device_t dev, u32 max)
874{
875 struct bus *cpu_bus;
876 device_t dev_mc;
877#if CONFIG_CBB
878 device_t pci_domain;
879#endif
880 int i,j;
881 int coreid_bits;
882 int core_max = 0;
883 unsigned ApicIdCoreIdSize;
884 unsigned core_nums;
885 int siblings = 0;
886 unsigned int family;
887
888#if CONFIG_CBB
889 dev_mc = dev_find_slot(0, PCI_DEVFN(CONFIG_CDB, 0)); //0x00
890 if (dev_mc && dev_mc->bus) {
891 printk(BIOS_DEBUG, "%s found", dev_path(dev_mc));
892 pci_domain = dev_mc->bus->dev;
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800893 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
zbao2c08f6a2012-07-02 15:32:58 +0800894 printk(BIOS_DEBUG, "\n%s move to ",dev_path(dev_mc));
895 dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
896 printk(BIOS_DEBUG, "%s",dev_path(dev_mc));
897 } else {
898 printk(BIOS_DEBUG, " but it is not under pci_domain directly ");
899 }
900 printk(BIOS_DEBUG, "\n");
901 }
902 dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
903 if (!dev_mc) {
904 dev_mc = dev_find_slot(0, PCI_DEVFN(0x18, 0));
905 if (dev_mc && dev_mc->bus) {
906 printk(BIOS_DEBUG, "%s found\n", dev_path(dev_mc));
907 pci_domain = dev_mc->bus->dev;
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800908 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
zbao2c08f6a2012-07-02 15:32:58 +0800909 if ((pci_domain->link_list) && (pci_domain->link_list->children == dev_mc)) {
910 printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
911 dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
912 printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
913 while (dev_mc) {
914 printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
915 dev_mc->path.pci.devfn -= PCI_DEVFN(0x18,0);
916 printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
917 dev_mc = dev_mc->sibling;
918 }
919 }
920 }
921 }
922 }
923#endif
924 dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
925 if (!dev_mc) {
926 printk(BIOS_ERR, "%02x:%02x.0 not found", CONFIG_CBB, CONFIG_CDB);
927 die("");
928 }
929 sysconf_init(dev_mc);
930#if CONFIG_CBB && (MAX_NODE_NUMS > 32)
931 if (node_nums>32) { // need to put node 32 to node 63 to bus 0xfe
932 if (pci_domain->link_list && !pci_domain->link_list->next) {
933 struct bus *new_link = new_link(pci_domain);
934 pci_domain->link_list->next = new_link;
935 new_link->link_num = 1;
936 new_link->dev = pci_domain;
937 new_link->children = 0;
938 printk(BIOS_DEBUG, "%s links now 2\n", dev_path(pci_domain));
939 }
940 pci_domain->link_list->next->secondary = CONFIG_CBB - 1;
941 }
942#endif
943
944 /* Get Max Number of cores(MNC) */
945 coreid_bits = (cpuid_ecx(AMD_CPUID_ASIZE_PCCOUNT) & 0x0000F000) >> 12;
946 core_max = 1 << (coreid_bits & 0x000F); //mnc
947
948 ApicIdCoreIdSize = ((cpuid_ecx(0x80000008)>>12) & 0xF);
949 if (ApicIdCoreIdSize) {
950 core_nums = (1 << ApicIdCoreIdSize) - 1;
951 } else {
952 core_nums = 3; //quad core
953 }
954
955 /* Find which cpus are present */
956 cpu_bus = dev->link_list;
957 for (i = 0; i < node_nums; i++) {
Kyösti Mälkkicd9fc1a2012-07-06 19:02:56 +0300958 device_t cdb_dev;
zbao2c08f6a2012-07-02 15:32:58 +0800959 unsigned busn, devn;
960 struct bus *pbus;
961
962 busn = CONFIG_CBB;
963 devn = CONFIG_CDB + i;
964 pbus = dev_mc->bus;
965#if CONFIG_CBB && (MAX_NODE_NUMS > 32)
966 if (i >= 32) {
967 busn--;
968 devn -= 32;
969 pbus = pci_domain->link_list->next;
970 }
971#endif
972
973 /* Find the cpu's pci device */
974 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0));
975 if (!cdb_dev) {
976 /* If I am probing things in a weird order
977 * ensure all of the cpu's pci devices are found.
978 */
979 int fn;
980 for(fn = 0; fn <= 5; fn++) { //FBDIMM?
981 cdb_dev = pci_probe_dev(NULL, pbus,
982 PCI_DEVFN(devn, fn));
983 }
984 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0));
985 } else {
986 /* Ok, We need to set the links for that device.
987 * otherwise the device under it will not be scanned
988 */
989 int linknum;
zbaod59d6242012-07-23 19:41:03 +0800990#if CONFIG_HT3_SUPPORT
zbao2c08f6a2012-07-02 15:32:58 +0800991 linknum = 8;
992#else
993 linknum = 4;
994#endif
995 add_more_links(cdb_dev, linknum);
996 }
997
998 family = cpuid_eax(1);
999 family = (family >> 20) & 0xFF;
1000 if (family == 1) { //f10
1001 u32 dword;
1002 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 3));
1003 dword = pci_read_config32(cdb_dev, 0xe8);
1004 siblings = ((dword & BIT15) >> 13) | ((dword & (BIT13 | BIT12)) >> 12);
1005 } else if (family == 6) {//f15
1006 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 5));
1007 if (cdb_dev && cdb_dev->enabled) {
1008 siblings = pci_read_config32(cdb_dev, 0x84);
1009 siblings &= 0xFF;
1010 }
1011 } else {
1012 siblings = 0; //default one core
1013 }
Kyösti Mälkkicd9fc1a2012-07-06 19:02:56 +03001014 int enable_node = cdb_dev && cdb_dev->enabled;
zbao2c08f6a2012-07-02 15:32:58 +08001015 printk(BIOS_SPEW, "%s family%xh, core_max=0x%x, core_nums=0x%x, siblings=0x%x\n",
1016 dev_path(cdb_dev), 0x0f + family, core_max, core_nums, siblings);
1017
1018 for (j = 0; j <= siblings; j++ ) {
1019 extern CONST OPTIONS_CONFIG_TOPOLOGY ROMDATA TopologyConfiguration;
1020 u32 modules = TopologyConfiguration.PlatformNumberOfModules;
1021 u32 lapicid_start = 0;
1022
zbao2c08f6a2012-07-02 15:32:58 +08001023 /*
1024 * APIC ID calucation is tightly coupled with AGESA v5 code.
1025 * This calculation MUST match the assignment calculation done
1026 * in LocalApicInitializationAtEarly() function.
1027 * And reference GetLocalApicIdForCore()
1028 *
1029 * Apply apic enumeration rules
1030 * For systems with >= 16 APICs, put the IO-APICs at 0..n and
1031 * put the local-APICs at m..z
1032 *
1033 * This is needed because many IO-APIC devices only have 4 bits
1034 * for their APIC id and therefore must reside at 0..15
1035 */
1036#ifndef CFG_PLAT_NUM_IO_APICS /* defined in mainboard buildOpts.c */
1037#define CFG_PLAT_NUM_IO_APICS 3
1038#endif
1039 if ((node_nums * core_max) + CFG_PLAT_NUM_IO_APICS >= 0x10) {
1040 lapicid_start = (CFG_PLAT_NUM_IO_APICS - 1) / core_max;
1041 lapicid_start = (lapicid_start + 1) * core_max;
1042 printk(BIOS_SPEW, "lpaicid_start=0x%x ", lapicid_start);
1043 }
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03001044 u32 apic_id = (lapicid_start * (i/modules + 1)) + ((i % modules) ? (j + (siblings + 1)) : j);
zbao2c08f6a2012-07-02 15:32:58 +08001045 printk(BIOS_SPEW, "node 0x%x core 0x%x apicid=0x%x\n",
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03001046 i, j, apic_id);
zbao2c08f6a2012-07-02 15:32:58 +08001047
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03001048 device_t cpu = add_cpu_device(cpu_bus, apic_id, enable_node);
1049 if (cpu)
1050 amd_cpu_topology(cpu, i, j);
zbao2c08f6a2012-07-02 15:32:58 +08001051 } //j
1052 }
1053 return max;
1054}
1055
1056static void cpu_bus_init(device_t dev)
1057{
1058 initialize_cpus(dev->link_list);
1059}
1060
1061static void cpu_bus_noop(device_t dev)
1062{
1063}
1064
1065static void cpu_bus_read_resources(device_t dev)
1066{
zbao2c08f6a2012-07-02 15:32:58 +08001067}
1068
1069static void cpu_bus_set_resources(device_t dev)
1070{
zbao2c08f6a2012-07-02 15:32:58 +08001071}
1072
1073static struct device_operations cpu_bus_ops = {
1074 .read_resources = cpu_bus_read_resources,
1075 .set_resources = cpu_bus_set_resources,
1076 .enable_resources = cpu_bus_noop,
1077 .init = cpu_bus_init,
1078 .scan_bus = cpu_bus_scan,
1079};
1080
1081static void root_complex_enable_dev(struct device *dev)
1082{
Kyösti Mälkki87213b62012-08-27 20:00:33 +03001083 static int done = 0;
1084
1085 /* Do not delay UMA setup, as a device on the PCI bus may evaluate
1086 the global uma_memory variables already in its enable function. */
1087 if (!done) {
1088 setup_bsp_ramtop();
1089 setup_uma_memory();
1090 done = 1;
1091 }
1092
zbao2c08f6a2012-07-02 15:32:58 +08001093 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -08001094 if (dev->path.type == DEVICE_PATH_DOMAIN) {
zbao2c08f6a2012-07-02 15:32:58 +08001095 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -08001096 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
zbao2c08f6a2012-07-02 15:32:58 +08001097 dev->ops = &cpu_bus_ops;
1098 }
1099}
1100
1101struct chip_operations northbridge_amd_agesa_family15tn_root_complex_ops = {
1102 CHIP_NAME("AMD FAM15 Root Complex")
1103 .enable_dev = root_complex_enable_dev,
1104};
Dave Frodincbf3d402012-12-05 08:20:12 -07001105
1106/********************************************************************
1107* Change the vendor / device IDs to match the generic VBIOS header.
1108********************************************************************/
1109u32 map_oprom_vendev(u32 vendev)
1110{
1111 u32 new_vendev=vendev;
1112
1113 switch(vendev) {
Bruce Griffith42e11f52013-07-08 18:19:08 -06001114 case 0x10029900: /* AMD Radeon HD 7660G (Trinity) */
1115 case 0x10029901: /* AMD Radeon HD 7660D (Trinity) */
1116 case 0x10029903: /* AMD Radeon HD 7640G (Trinity) */
1117 case 0x10029904: /* AMD Radeon HD 7560D (Trinity) */
1118 case 0x10029907: /* AMD Radeon HD 7620G (Trinity) */
1119 case 0x10029908: /* AMD Radeon HD 7600G (Trinity) */
1120 case 0x1002990A: /* AMD Radeon HD 7500G (Trinity) */
1121 case 0x1002990B: /* AMD Radeon HD 8650G (Richland) */
1122 case 0x1002990C: /* AMD Radeon HD 8670D (Richland) */
1123 case 0x1002990D: /* AMD Radeon HD 8550G (Richland) */
1124 case 0x1002990E: /* AMD Radeon HD 8570D (Richland) */
1125 case 0x1002990F: /* AMD Radeon HD 8610G (Richland) */
1126 case 0x10029910: /* AMD Radeon HD 7660G (Trinity) */
1127 case 0x10029913: /* AMD Radeon HD 7640G (Trinity) */
1128 case 0x10029917: /* AMD Radeon HD 7620G (Trinity) */
1129 case 0x10029918: /* AMD Radeon HD 7600G (Trinity) */
1130 case 0x10029919: /* AMD Radeon HD 7500G (Trinity) */
1131 case 0x10029990: /* AMD Radeon HD 7520G (Trinity) */
1132 case 0x10029991: /* AMD Radeon HD 7540D (Trinity) */
1133 case 0x10029992: /* AMD Radeon HD 7420G (Trinity) */
1134 case 0x10029993: /* AMD Radeon HD 7480D (Trinity) */
1135 case 0x10029994: /* AMD Radeon HD 7400G (Trinity) */
1136 case 0x10029995: /* AMD Radeon HD 8450G (Richland) */
1137 case 0x10029996: /* AMD Radeon HD 8470D (Richland) */
1138 case 0x10029997: /* AMD Radeon HD 8350G (Richland) */
1139 case 0x10029998: /* AMD Radeon HD 8370D (Richland) */
1140 case 0x10029999: /* AMD Radeon HD 8510G (Richland) */
1141 case 0x1002999A: /* AMD Radeon HD 8410G (Richland) */
1142 case 0x1002999B: /* AMD Radeon HD 8310G (Richland) */
1143 case 0x1002999C: /* AMD Radeon HD 8650D (Richland) */
1144 case 0x1002999D: /* AMD Radeon HD 8550D (Richland) */
1145 case 0x100299A0: /* AMD Radeon HD 7520G (Trinity) */
1146 case 0x100299A2: /* AMD Radeon HD 7420G (Trinity) */
1147 case 0x100299A4: /* AMD Radeon HD 7400G (Trinity) */
Dave Frodincbf3d402012-12-05 08:20:12 -07001148 new_vendev=0x10029900;
1149 break;
1150 }
1151
1152 return new_vendev;
1153}