blob: d3f00bdfc9c4420ae4acdb09d3b790f5ef2d049c [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"
Kyösti Mälkki7b23ae02014-07-04 16:14:37 +030044#include <northbridge/amd/agesa/agesawrapper_call.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
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100203 * @retval 2 resoure does not exist, usable
204 * @retval 0 resource exists, not usable
zbao2c08f6a2012-07-02 15:32:58 +0800205 * @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) {
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100394 set_mmio_addr_reg(nodeid, link_num, reg, (resource->index >>24), rbase>>8, rend>>8, node_nums);// [39:8]
zbao2c08f6a2012-07-02 15:32:58 +0800395 }
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
zbao2c08f6a2012-07-02 15:32:58 +0800465static struct device_operations northbridge_operations = {
Steven Sherkf4340582013-01-29 16:13:35 -0700466 .read_resources = nb_read_resources,
467 .set_resources = nb_set_resources,
zbao2c08f6a2012-07-02 15:32:58 +0800468 .enable_resources = pci_dev_enable_resources,
Edward O'Callaghand994ef12014-11-21 02:22:33 +1100469 .init = DEVICE_NOOP,
zbao2c08f6a2012-07-02 15:32:58 +0800470 .enable = 0,
471 .ops_pci = 0,
472};
473
474static const struct pci_driver family15_northbridge __pci_driver = {
475 .ops = &northbridge_operations,
476 .vendor = PCI_VENDOR_ID_AMD,
477 .device = PCI_DEVICE_ID_AMD_15H_MODEL_001F_NB_HT,
478};
479
480static const struct pci_driver family10_northbridge __pci_driver = {
481 .ops = &northbridge_operations,
482 .vendor = PCI_VENDOR_ID_AMD,
483 .device = PCI_DEVICE_ID_AMD_10H_NB_HT,
484};
485
486struct chip_operations northbridge_amd_agesa_family15tn_ops = {
487 CHIP_NAME("AMD FAM15 Northbridge")
488 .enable_dev = 0,
489};
490
491static void domain_read_resources(device_t dev)
492{
493 unsigned reg;
494
495 /* Find the already assigned resource pairs */
496 get_fx_devs();
497 for (reg = 0x80; reg <= 0xd8; reg+= 0x08) {
498 u32 base, limit;
499 base = f1_read_config32(reg);
500 limit = f1_read_config32(reg + 0x04);
501 /* Is this register allocated? */
502 if ((base & 3) != 0) {
503 unsigned nodeid, reg_link;
504 device_t reg_dev;
505 if (reg<0xc0) { // mmio
506 nodeid = (limit & 0xf) + (base&0x30);
507 } else { // io
508 nodeid = (limit & 0xf) + ((base>>4)&0x30);
509 }
510 reg_link = (limit >> 4) & 7;
511 reg_dev = __f0_dev[nodeid];
512 if (reg_dev) {
513 /* Reserve the resource */
514 struct resource *res;
515 res = new_resource(reg_dev, IOINDEX(0x1000 + reg, reg_link));
516 if (res) {
517 res->flags = 1;
518 }
519 }
520 }
521 }
522 /* FIXME: do we need to check extend conf space?
523 I don't believe that much preset value */
524
zbaod59d6242012-07-23 19:41:03 +0800525#if !CONFIG_PCI_64BIT_PREF_MEM
zbao2c08f6a2012-07-02 15:32:58 +0800526 pci_domain_read_resources(dev);
527
528#else
529 struct bus *link;
530 struct resource *resource;
531 for (link=dev->link_list; link; link = link->next) {
532 /* Initialize the system wide io space constraints */
533 resource = new_resource(dev, 0|(link->link_num<<2));
534 resource->base = 0x400;
535 resource->limit = 0xffffUL;
536 resource->flags = IORESOURCE_IO;
537
538 /* Initialize the system wide prefetchable memory resources constraints */
539 resource = new_resource(dev, 1|(link->link_num<<2));
540 resource->limit = 0xfcffffffffULL;
541 resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
542
543 /* Initialize the system wide memory resources constraints */
544 resource = new_resource(dev, 2|(link->link_num<<2));
545 resource->limit = 0xfcffffffffULL;
546 resource->flags = IORESOURCE_MEM;
547 }
548#endif
549}
550
zbao2c08f6a2012-07-02 15:32:58 +0800551static void domain_enable_resources(device_t dev)
552{
Kyösti Mälkki8ae16a42014-06-19 20:44:34 +0300553 if (acpi_is_wakeup_s3())
Kyösti Mälkki7b23ae02014-07-04 16:14:37 +0300554 AGESAWRAPPER(fchs3laterestore);
zbao2c08f6a2012-07-02 15:32:58 +0800555
556 /* Must be called after PCI enumeration and resource allocation */
Kyösti Mälkki7b23ae02014-07-04 16:14:37 +0300557 if (!acpi_is_wakeup_s3())
558 AGESAWRAPPER(amdinitmid);
zbao2c08f6a2012-07-02 15:32:58 +0800559
Mike Loptiene133aab2013-01-30 16:00:43 -0700560 printk(BIOS_DEBUG, " ader - leaving %s.\n", __func__);
zbao2c08f6a2012-07-02 15:32:58 +0800561}
562
563#if CONFIG_HW_MEM_HOLE_SIZEK != 0
564struct hw_mem_hole_info {
565 unsigned hole_startk;
566 int node_id;
567};
568static struct hw_mem_hole_info get_hw_mem_hole_info(void)
569{
570 struct hw_mem_hole_info mem_hole;
571 int i;
572 mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK;
573 mem_hole.node_id = -1;
574 for (i = 0; i < node_nums; i++) {
575 dram_base_mask_t d;
576 u32 hole;
577 d = get_dram_base_mask(i);
578 if (!(d.mask & 1)) continue; // no memory on this node
579 hole = pci_read_config32(__f1_dev[i], 0xf0);
580 if (hole & 1) { // we find the hole
581 mem_hole.hole_startk = (hole & (0xff<<24)) >> 10;
582 mem_hole.node_id = i; // record the node No with hole
583 break; // only one hole
584 }
585 }
Kyösti Mälkki2f9b3af2014-06-26 05:30:54 +0300586
587 /* We need to double check if there is special set on base reg and limit reg
588 * are not continuous instead of hole, it will find out its hole_startk.
589 */
zbao2c08f6a2012-07-02 15:32:58 +0800590 if (mem_hole.node_id == -1) {
591 resource_t limitk_pri = 0;
592 for (i=0; i<node_nums; i++) {
593 dram_base_mask_t d;
594 resource_t base_k, limit_k;
595 d = get_dram_base_mask(i);
596 if (!(d.base & 1)) continue;
597 base_k = ((resource_t)(d.base & 0x1fffff00)) <<9;
598 if (base_k > 4 *1024 * 1024) break; // don't need to go to check
599 if (limitk_pri != base_k) { // we find the hole
600 mem_hole.hole_startk = (unsigned)limitk_pri; // must beblow 4G
601 mem_hole.node_id = i;
602 break; //only one hole
603 }
zbao15dc3cc2012-08-03 15:56:21 +0800604 limit_k = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
zbao2c08f6a2012-07-02 15:32:58 +0800605 limitk_pri = limit_k;
606 }
607 }
608 return mem_hole;
609}
610#endif
611
zbao405cfe22012-07-23 19:44:29 +0800612#define ONE_MB_SHIFT 20
zbao6db7f342012-07-19 16:38:12 +0800613
Kyösti Mälkki6b5eb1c2012-07-19 19:26:43 +0300614static void setup_uma_memory(void)
zbao6db7f342012-07-19 16:38:12 +0800615{
616#if CONFIG_GFXUMA
Kyösti Mälkkidbc47392012-08-05 12:11:40 +0300617 uint32_t topmem = (uint32_t) bsp_topmem();
zbao6db7f342012-07-19 16:38:12 +0800618 uint32_t sys_mem;
619
zbao6db7f342012-07-19 16:38:12 +0800620 /* refer to UMA Size Consideration in Family15h BKDG. */
621 /* Please reference MemNGetUmaSizeOR () */
622 /*
623 * Total system memory UMASize
624 * >= 2G 512M
625 * >=1G 256M
626 * <1G 64M
627 */
Kyösti Mälkkidbc47392012-08-05 12:11:40 +0300628 sys_mem = topmem + (16 << ONE_MB_SHIFT); // Ignore 16MB allocated for C6 when finding UMA size
629 if ((bsp_topmem2()>>32) || (sys_mem >= 2048 << ONE_MB_SHIFT)) {
zbao405cfe22012-07-23 19:44:29 +0800630 uma_memory_size = 512 << ONE_MB_SHIFT;
631 } else if (sys_mem >= 1024 << ONE_MB_SHIFT) {
632 uma_memory_size = 256 << ONE_MB_SHIFT;
zbao6db7f342012-07-19 16:38:12 +0800633 } else {
zbao405cfe22012-07-23 19:44:29 +0800634 uma_memory_size = 64 << ONE_MB_SHIFT;
zbao6db7f342012-07-19 16:38:12 +0800635 }
Kyösti Mälkkidbc47392012-08-05 12:11:40 +0300636 uma_memory_base = topmem - uma_memory_size; /* TOP_MEM1 */
zbao6db7f342012-07-19 16:38:12 +0800637
638 printk(BIOS_INFO, "%s: uma size 0x%08llx, memory start 0x%08llx\n",
639 __func__, uma_memory_size, uma_memory_base);
zbao6db7f342012-07-19 16:38:12 +0800640#endif
641}
642
643
zbao2c08f6a2012-07-02 15:32:58 +0800644static void domain_set_resources(device_t dev)
645{
zbaod59d6242012-07-23 19:41:03 +0800646#if CONFIG_PCI_64BIT_PREF_MEM
zbao2c08f6a2012-07-02 15:32:58 +0800647 struct resource *io, *mem1, *mem2;
648 struct resource *res;
649#endif
650 unsigned long mmio_basek;
651 u32 pci_tolm;
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300652 u64 ramtop = 0;
zbao2c08f6a2012-07-02 15:32:58 +0800653 int i, idx;
654 struct bus *link;
655#if CONFIG_HW_MEM_HOLE_SIZEK != 0
656 struct hw_mem_hole_info mem_hole;
657 u32 reset_memhole = 1;
658#endif
659
zbaod59d6242012-07-23 19:41:03 +0800660#if CONFIG_PCI_64BIT_PREF_MEM
zbao2c08f6a2012-07-02 15:32:58 +0800661
662 for (link = dev->link_list; link; link = link->next) {
663 /* Now reallocate the pci resources memory with the
664 * highest addresses I can manage.
665 */
666 mem1 = find_resource(dev, 1|(link->link_num<<2));
667 mem2 = find_resource(dev, 2|(link->link_num<<2));
668
669 printk(BIOS_DEBUG, "base1: 0x%08Lx limit1: 0x%08Lx size: 0x%08Lx align: %d\n",
670 mem1->base, mem1->limit, mem1->size, mem1->align);
671 printk(BIOS_DEBUG, "base2: 0x%08Lx limit2: 0x%08Lx size: 0x%08Lx align: %d\n",
672 mem2->base, mem2->limit, mem2->size, mem2->align);
673
674 /* See if both resources have roughly the same limits */
675 if (((mem1->limit <= 0xffffffff) && (mem2->limit <= 0xffffffff)) ||
676 ((mem1->limit > 0xffffffff) && (mem2->limit > 0xffffffff)))
677 {
678 /* If so place the one with the most stringent alignment first */
679 if (mem2->align > mem1->align) {
680 struct resource *tmp;
681 tmp = mem1;
682 mem1 = mem2;
683 mem2 = tmp;
684 }
685 /* Now place the memory as high up as it will go */
686 mem2->base = resource_max(mem2);
687 mem1->limit = mem2->base - 1;
688 mem1->base = resource_max(mem1);
689 }
690 else {
691 /* Place the resources as high up as they will go */
692 mem2->base = resource_max(mem2);
693 mem1->base = resource_max(mem1);
694 }
695
696 printk(BIOS_DEBUG, "base1: 0x%08Lx limit1: 0x%08Lx size: 0x%08Lx align: %d\n",
697 mem1->base, mem1->limit, mem1->size, mem1->align);
698 printk(BIOS_DEBUG, "base2: 0x%08Lx limit2: 0x%08Lx size: 0x%08Lx align: %d\n",
699 mem2->base, mem2->limit, mem2->size, mem2->align);
700 }
701
702 for (res = &dev->resource_list; res; res = res->next)
703 {
704 res->flags |= IORESOURCE_ASSIGNED;
705 res->flags |= IORESOURCE_STORED;
706 report_resource_stored(dev, res, "");
707 }
708#endif
709
710 pci_tolm = 0xffffffffUL;
711 for (link = dev->link_list; link; link = link->next) {
712 pci_tolm = find_pci_tolm(link);
713 }
714
715 // FIXME handle interleaved nodes. If you fix this here, please fix
716 // amdk8, too.
717 mmio_basek = pci_tolm >> 10;
718 /* Round mmio_basek to something the processor can support */
719 mmio_basek &= ~((1 << 6) -1);
720
721 // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M
722 // MMIO hole. If you fix this here, please fix amdk8, too.
723 /* Round the mmio hole to 64M */
724 mmio_basek &= ~((64*1024) - 1);
725
726#if CONFIG_HW_MEM_HOLE_SIZEK != 0
727 /* if the hw mem hole is already set in raminit stage, here we will compare
728 * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will
729 * use hole_basek as mmio_basek and we don't need to reset hole.
730 * otherwise We reset the hole to the mmio_basek
731 */
732
733 mem_hole = get_hw_mem_hole_info();
734
735 // Use hole_basek as mmio_basek, and we don't need to reset hole anymore
736 if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) {
737 mmio_basek = mem_hole.hole_startk;
738 reset_memhole = 0;
739 }
740#endif
741
742 idx = 0x10;
743 for (i = 0; i < node_nums; i++) {
744 dram_base_mask_t d;
745 resource_t basek, limitk, sizek; // 4 1T
746
747 d = get_dram_base_mask(i);
748
749 if (!(d.mask & 1)) continue;
750 basek = ((resource_t)(d.base & 0x1fffff00)) << 9; // could overflow, we may lost 6 bit here
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100751 limitk = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
zbao2c08f6a2012-07-02 15:32:58 +0800752
753 sizek = limitk - basek;
754
755 /* see if we need a hole from 0xa0000 to 0xbffff */
756 if ((basek < ((8*64)+(8*16))) && (sizek > ((8*64)+(16*16)))) {
757 ram_resource(dev, (idx | i), basek, ((8*64)+(8*16)) - basek);
758 idx += 0x10;
759 basek = (8*64)+(16*16);
760 sizek = limitk - ((8*64)+(16*16));
761
762 }
763
764 //printk(BIOS_DEBUG, "node %d : mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", i, mmio_basek, basek, limitk);
765
Kyösti Mälkki26c65432014-06-26 05:30:54 +0300766 /* split the region to accommodate pci memory space */
zbao2c08f6a2012-07-02 15:32:58 +0800767 if ((basek < 4*1024*1024 ) && (limitk > mmio_basek)) {
768 if (basek <= mmio_basek) {
769 unsigned pre_sizek;
770 pre_sizek = mmio_basek - basek;
771 if (pre_sizek>0) {
772 ram_resource(dev, (idx | i), basek, pre_sizek);
773 idx += 0x10;
774 sizek -= pre_sizek;
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300775 if (!ramtop)
776 ramtop = mmio_basek * 1024;
zbao2c08f6a2012-07-02 15:32:58 +0800777 }
778 basek = mmio_basek;
779 }
780 if ((basek + sizek) <= 4*1024*1024) {
781 sizek = 0;
782 }
783 else {
Siyuan Wang29840e22013-06-04 19:56:22 +0800784 uint64_t topmem2 = bsp_topmem2();
zbao2c08f6a2012-07-02 15:32:58 +0800785 basek = 4*1024*1024;
Siyuan Wang29840e22013-06-04 19:56:22 +0800786 sizek = topmem2/1024 - basek;
zbao2c08f6a2012-07-02 15:32:58 +0800787 }
788 }
789
zbao2c08f6a2012-07-02 15:32:58 +0800790 ram_resource(dev, (idx | i), basek, sizek);
791 idx += 0x10;
zbao2c08f6a2012-07-02 15:32:58 +0800792 printk(BIOS_DEBUG, "node %d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n",
793 i, mmio_basek, basek, limitk);
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300794 if (!ramtop)
795 ramtop = limitk * 1024;
zbao2c08f6a2012-07-02 15:32:58 +0800796 }
797
Kyösti Mälkki63f8c082012-07-10 13:27:26 +0300798#if CONFIG_GFXUMA
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300799 set_top_of_ram(uma_memory_base);
Kyösti Mälkki63f8c082012-07-10 13:27:26 +0300800 uma_resource(dev, 7, uma_memory_base >> 10, uma_memory_size >> 10);
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300801#else
802 set_top_of_ram(ramtop);
zbao2c08f6a2012-07-02 15:32:58 +0800803#endif
804
805 for(link = dev->link_list; link; link = link->next) {
806 if (link->children) {
807 assign_resources(link);
808 }
809 }
810}
811
812static struct device_operations pci_domain_ops = {
813 .read_resources = domain_read_resources,
814 .set_resources = domain_set_resources,
815 .enable_resources = domain_enable_resources,
816 .init = NULL,
817 .scan_bus = pci_domain_scan_bus,
Kyösti Mälkki872c9222013-07-03 09:44:28 +0300818 .ops_pci_bus = pci_bus_default_ops,
zbao2c08f6a2012-07-02 15:32:58 +0800819};
820
821static void sysconf_init(device_t dev) // first node
822{
823 sblink = (pci_read_config32(dev, 0x64)>>8) & 7; // don't forget sublink1
824 node_nums = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; //NodeCnt[2:0]
825}
826
827static void add_more_links(device_t dev, unsigned total_links)
828{
829 struct bus *link, *last = NULL;
830 int link_num;
831
832 for (link = dev->link_list; link; link = link->next)
833 last = link;
834
835 if (last) {
836 int links = total_links - last->link_num;
837 link_num = last->link_num;
838 if (links > 0) {
839 link = malloc(links*sizeof(*link));
840 if (!link)
841 die("Couldn't allocate more links!\n");
842 memset(link, 0, links*sizeof(*link));
843 last->next = link;
844 }
845 }
846 else {
847 link_num = -1;
848 link = malloc(total_links*sizeof(*link));
849 memset(link, 0, total_links*sizeof(*link));
850 dev->link_list = link;
851 }
852
853 for (link_num = link_num + 1; link_num < total_links; link_num++) {
854 link->link_num = link_num;
855 link->dev = dev;
856 link->next = link + 1;
857 last = link;
858 link = link->next;
859 }
860 last->next = NULL;
861}
862
zbao2c08f6a2012-07-02 15:32:58 +0800863static u32 cpu_bus_scan(device_t dev, u32 max)
864{
865 struct bus *cpu_bus;
866 device_t dev_mc;
867#if CONFIG_CBB
868 device_t pci_domain;
869#endif
870 int i,j;
871 int coreid_bits;
872 int core_max = 0;
873 unsigned ApicIdCoreIdSize;
874 unsigned core_nums;
875 int siblings = 0;
876 unsigned int family;
877
878#if CONFIG_CBB
879 dev_mc = dev_find_slot(0, PCI_DEVFN(CONFIG_CDB, 0)); //0x00
880 if (dev_mc && dev_mc->bus) {
881 printk(BIOS_DEBUG, "%s found", dev_path(dev_mc));
882 pci_domain = dev_mc->bus->dev;
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800883 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
zbao2c08f6a2012-07-02 15:32:58 +0800884 printk(BIOS_DEBUG, "\n%s move to ",dev_path(dev_mc));
885 dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
886 printk(BIOS_DEBUG, "%s",dev_path(dev_mc));
887 } else {
888 printk(BIOS_DEBUG, " but it is not under pci_domain directly ");
889 }
890 printk(BIOS_DEBUG, "\n");
891 }
892 dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
893 if (!dev_mc) {
894 dev_mc = dev_find_slot(0, PCI_DEVFN(0x18, 0));
895 if (dev_mc && dev_mc->bus) {
896 printk(BIOS_DEBUG, "%s found\n", dev_path(dev_mc));
897 pci_domain = dev_mc->bus->dev;
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800898 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
zbao2c08f6a2012-07-02 15:32:58 +0800899 if ((pci_domain->link_list) && (pci_domain->link_list->children == dev_mc)) {
900 printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
901 dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
902 printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
903 while (dev_mc) {
904 printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
905 dev_mc->path.pci.devfn -= PCI_DEVFN(0x18,0);
906 printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
907 dev_mc = dev_mc->sibling;
908 }
909 }
910 }
911 }
912 }
913#endif
914 dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
915 if (!dev_mc) {
916 printk(BIOS_ERR, "%02x:%02x.0 not found", CONFIG_CBB, CONFIG_CDB);
917 die("");
918 }
919 sysconf_init(dev_mc);
920#if CONFIG_CBB && (MAX_NODE_NUMS > 32)
921 if (node_nums>32) { // need to put node 32 to node 63 to bus 0xfe
922 if (pci_domain->link_list && !pci_domain->link_list->next) {
923 struct bus *new_link = new_link(pci_domain);
924 pci_domain->link_list->next = new_link;
925 new_link->link_num = 1;
926 new_link->dev = pci_domain;
927 new_link->children = 0;
928 printk(BIOS_DEBUG, "%s links now 2\n", dev_path(pci_domain));
929 }
930 pci_domain->link_list->next->secondary = CONFIG_CBB - 1;
931 }
932#endif
933
934 /* Get Max Number of cores(MNC) */
935 coreid_bits = (cpuid_ecx(AMD_CPUID_ASIZE_PCCOUNT) & 0x0000F000) >> 12;
936 core_max = 1 << (coreid_bits & 0x000F); //mnc
937
938 ApicIdCoreIdSize = ((cpuid_ecx(0x80000008)>>12) & 0xF);
939 if (ApicIdCoreIdSize) {
940 core_nums = (1 << ApicIdCoreIdSize) - 1;
941 } else {
942 core_nums = 3; //quad core
943 }
944
945 /* Find which cpus are present */
946 cpu_bus = dev->link_list;
947 for (i = 0; i < node_nums; i++) {
Kyösti Mälkkicd9fc1a2012-07-06 19:02:56 +0300948 device_t cdb_dev;
zbao2c08f6a2012-07-02 15:32:58 +0800949 unsigned busn, devn;
950 struct bus *pbus;
951
952 busn = CONFIG_CBB;
953 devn = CONFIG_CDB + i;
954 pbus = dev_mc->bus;
955#if CONFIG_CBB && (MAX_NODE_NUMS > 32)
956 if (i >= 32) {
957 busn--;
958 devn -= 32;
959 pbus = pci_domain->link_list->next;
960 }
961#endif
962
963 /* Find the cpu's pci device */
964 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0));
965 if (!cdb_dev) {
966 /* If I am probing things in a weird order
967 * ensure all of the cpu's pci devices are found.
968 */
969 int fn;
970 for(fn = 0; fn <= 5; fn++) { //FBDIMM?
971 cdb_dev = pci_probe_dev(NULL, pbus,
972 PCI_DEVFN(devn, fn));
973 }
974 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0));
975 } else {
976 /* Ok, We need to set the links for that device.
977 * otherwise the device under it will not be scanned
978 */
979 int linknum;
zbaod59d6242012-07-23 19:41:03 +0800980#if CONFIG_HT3_SUPPORT
zbao2c08f6a2012-07-02 15:32:58 +0800981 linknum = 8;
982#else
983 linknum = 4;
984#endif
985 add_more_links(cdb_dev, linknum);
986 }
987
988 family = cpuid_eax(1);
989 family = (family >> 20) & 0xFF;
990 if (family == 1) { //f10
991 u32 dword;
992 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 3));
993 dword = pci_read_config32(cdb_dev, 0xe8);
994 siblings = ((dword & BIT15) >> 13) | ((dword & (BIT13 | BIT12)) >> 12);
995 } else if (family == 6) {//f15
996 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 5));
997 if (cdb_dev && cdb_dev->enabled) {
998 siblings = pci_read_config32(cdb_dev, 0x84);
999 siblings &= 0xFF;
1000 }
1001 } else {
1002 siblings = 0; //default one core
1003 }
Kyösti Mälkkicd9fc1a2012-07-06 19:02:56 +03001004 int enable_node = cdb_dev && cdb_dev->enabled;
zbao2c08f6a2012-07-02 15:32:58 +08001005 printk(BIOS_SPEW, "%s family%xh, core_max=0x%x, core_nums=0x%x, siblings=0x%x\n",
1006 dev_path(cdb_dev), 0x0f + family, core_max, core_nums, siblings);
1007
1008 for (j = 0; j <= siblings; j++ ) {
1009 extern CONST OPTIONS_CONFIG_TOPOLOGY ROMDATA TopologyConfiguration;
1010 u32 modules = TopologyConfiguration.PlatformNumberOfModules;
1011 u32 lapicid_start = 0;
1012
zbao2c08f6a2012-07-02 15:32:58 +08001013 /*
1014 * APIC ID calucation is tightly coupled with AGESA v5 code.
1015 * This calculation MUST match the assignment calculation done
1016 * in LocalApicInitializationAtEarly() function.
1017 * And reference GetLocalApicIdForCore()
1018 *
1019 * Apply apic enumeration rules
1020 * For systems with >= 16 APICs, put the IO-APICs at 0..n and
1021 * put the local-APICs at m..z
1022 *
1023 * This is needed because many IO-APIC devices only have 4 bits
1024 * for their APIC id and therefore must reside at 0..15
1025 */
1026#ifndef CFG_PLAT_NUM_IO_APICS /* defined in mainboard buildOpts.c */
1027#define CFG_PLAT_NUM_IO_APICS 3
1028#endif
1029 if ((node_nums * core_max) + CFG_PLAT_NUM_IO_APICS >= 0x10) {
1030 lapicid_start = (CFG_PLAT_NUM_IO_APICS - 1) / core_max;
1031 lapicid_start = (lapicid_start + 1) * core_max;
1032 printk(BIOS_SPEW, "lpaicid_start=0x%x ", lapicid_start);
1033 }
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03001034 u32 apic_id = (lapicid_start * (i/modules + 1)) + ((i % modules) ? (j + (siblings + 1)) : j);
zbao2c08f6a2012-07-02 15:32:58 +08001035 printk(BIOS_SPEW, "node 0x%x core 0x%x apicid=0x%x\n",
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03001036 i, j, apic_id);
zbao2c08f6a2012-07-02 15:32:58 +08001037
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03001038 device_t cpu = add_cpu_device(cpu_bus, apic_id, enable_node);
1039 if (cpu)
1040 amd_cpu_topology(cpu, i, j);
zbao2c08f6a2012-07-02 15:32:58 +08001041 } //j
1042 }
1043 return max;
1044}
1045
1046static void cpu_bus_init(device_t dev)
1047{
1048 initialize_cpus(dev->link_list);
1049}
1050
zbao2c08f6a2012-07-02 15:32:58 +08001051static struct device_operations cpu_bus_ops = {
Edward O'Callaghan2837ab22014-11-06 08:57:40 +11001052 .read_resources = DEVICE_NOOP,
1053 .set_resources = DEVICE_NOOP,
Edward O'Callaghan812d2a42014-10-31 08:17:23 +11001054 .enable_resources = DEVICE_NOOP,
zbao2c08f6a2012-07-02 15:32:58 +08001055 .init = cpu_bus_init,
1056 .scan_bus = cpu_bus_scan,
1057};
1058
1059static void root_complex_enable_dev(struct device *dev)
1060{
Kyösti Mälkki87213b62012-08-27 20:00:33 +03001061 static int done = 0;
1062
1063 /* Do not delay UMA setup, as a device on the PCI bus may evaluate
1064 the global uma_memory variables already in its enable function. */
1065 if (!done) {
1066 setup_bsp_ramtop();
1067 setup_uma_memory();
1068 done = 1;
1069 }
1070
zbao2c08f6a2012-07-02 15:32:58 +08001071 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -08001072 if (dev->path.type == DEVICE_PATH_DOMAIN) {
zbao2c08f6a2012-07-02 15:32:58 +08001073 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -08001074 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
zbao2c08f6a2012-07-02 15:32:58 +08001075 dev->ops = &cpu_bus_ops;
1076 }
1077}
1078
1079struct chip_operations northbridge_amd_agesa_family15tn_root_complex_ops = {
Edward O'Callaghanae5fd342014-11-20 19:58:09 +11001080 CHIP_NAME("AMD FAM15tn Root Complex")
zbao2c08f6a2012-07-02 15:32:58 +08001081 .enable_dev = root_complex_enable_dev,
1082};
Dave Frodincbf3d402012-12-05 08:20:12 -07001083
Edward O'Callaghanae5fd342014-11-20 19:58:09 +11001084/*********************************************************************
1085 * Change the vendor / device IDs to match the generic VBIOS header. *
1086 *********************************************************************/
Dave Frodincbf3d402012-12-05 08:20:12 -07001087u32 map_oprom_vendev(u32 vendev)
1088{
Edward O'Callaghanae5fd342014-11-20 19:58:09 +11001089 u32 new_vendev = vendev;
Dave Frodincbf3d402012-12-05 08:20:12 -07001090
1091 switch(vendev) {
Bruce Griffith42e11f52013-07-08 18:19:08 -06001092 case 0x10029900: /* AMD Radeon HD 7660G (Trinity) */
1093 case 0x10029901: /* AMD Radeon HD 7660D (Trinity) */
1094 case 0x10029903: /* AMD Radeon HD 7640G (Trinity) */
1095 case 0x10029904: /* AMD Radeon HD 7560D (Trinity) */
1096 case 0x10029907: /* AMD Radeon HD 7620G (Trinity) */
1097 case 0x10029908: /* AMD Radeon HD 7600G (Trinity) */
1098 case 0x1002990A: /* AMD Radeon HD 7500G (Trinity) */
1099 case 0x1002990B: /* AMD Radeon HD 8650G (Richland) */
1100 case 0x1002990C: /* AMD Radeon HD 8670D (Richland) */
1101 case 0x1002990D: /* AMD Radeon HD 8550G (Richland) */
1102 case 0x1002990E: /* AMD Radeon HD 8570D (Richland) */
1103 case 0x1002990F: /* AMD Radeon HD 8610G (Richland) */
1104 case 0x10029910: /* AMD Radeon HD 7660G (Trinity) */
1105 case 0x10029913: /* AMD Radeon HD 7640G (Trinity) */
1106 case 0x10029917: /* AMD Radeon HD 7620G (Trinity) */
1107 case 0x10029918: /* AMD Radeon HD 7600G (Trinity) */
1108 case 0x10029919: /* AMD Radeon HD 7500G (Trinity) */
1109 case 0x10029990: /* AMD Radeon HD 7520G (Trinity) */
1110 case 0x10029991: /* AMD Radeon HD 7540D (Trinity) */
1111 case 0x10029992: /* AMD Radeon HD 7420G (Trinity) */
1112 case 0x10029993: /* AMD Radeon HD 7480D (Trinity) */
1113 case 0x10029994: /* AMD Radeon HD 7400G (Trinity) */
1114 case 0x10029995: /* AMD Radeon HD 8450G (Richland) */
1115 case 0x10029996: /* AMD Radeon HD 8470D (Richland) */
1116 case 0x10029997: /* AMD Radeon HD 8350G (Richland) */
1117 case 0x10029998: /* AMD Radeon HD 8370D (Richland) */
1118 case 0x10029999: /* AMD Radeon HD 8510G (Richland) */
1119 case 0x1002999A: /* AMD Radeon HD 8410G (Richland) */
1120 case 0x1002999B: /* AMD Radeon HD 8310G (Richland) */
1121 case 0x1002999C: /* AMD Radeon HD 8650D (Richland) */
1122 case 0x1002999D: /* AMD Radeon HD 8550D (Richland) */
1123 case 0x100299A0: /* AMD Radeon HD 7520G (Trinity) */
1124 case 0x100299A2: /* AMD Radeon HD 7420G (Trinity) */
1125 case 0x100299A4: /* AMD Radeon HD 7400G (Trinity) */
Edward O'Callaghanae5fd342014-11-20 19:58:09 +11001126 new_vendev = 0x10029901;
Dave Frodincbf3d402012-12-05 08:20:12 -07001127 break;
1128 }
1129
1130 return new_vendev;
1131}