blob: 0d2cdec290bff5d6ee641e8f2808b1e87985d77a [file] [log] [blame]
Siyuan Wang3e32cc02013-07-09 17:16:20 +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
Patrick Georgib890a122015-03-26 15:17:45 +010017 * Foundation, Inc.
Siyuan Wang3e32cc02013-07-09 17:16:20 +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>
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +020023#include <arch/acpigen.h>
Siyuan Wang3e32cc02013-07-09 17:16:20 +080024#include <stdint.h>
25#include <device/device.h>
26#include <device/pci.h>
27#include <device/pci_ids.h>
28#include <device/hypertransport.h>
29#include <stdlib.h>
30#include <string.h>
31#include <lib.h>
32#include <cpu/cpu.h>
33#include <cbmem.h>
34
35#include <cpu/x86/lapic.h>
36#include <cpu/amd/mtrr.h>
37
38#include <Porting.h>
39#include <AGESA.h>
40#include <Options.h>
41#include <Topology.h>
42#include <cpu/amd/amdfam16.h>
43#include <cpuRegisters.h>
Kyösti Mälkkif21c2ac2014-10-19 09:35:18 +030044#include <northbridge/amd/agesa/agesawrapper.h>
Siyuan Wang3e32cc02013-07-09 17:16:20 +080045
46#define MAX_NODE_NUMS (MAX_NODES * MAX_DIES)
47
Siyuan Wang3e32cc02013-07-09 17:16:20 +080048typedef struct dram_base_mask {
49 u32 base; //[47:27] at [28:8]
50 u32 mask; //[47:27] at [28:8] and enable at bit 0
51} dram_base_mask_t;
52
53static unsigned node_nums;
54static unsigned sblink;
55static device_t __f0_dev[MAX_NODE_NUMS];
56static device_t __f1_dev[MAX_NODE_NUMS];
57static device_t __f2_dev[MAX_NODE_NUMS];
58static device_t __f4_dev[MAX_NODE_NUMS];
59static unsigned fx_devs = 0;
60
61static dram_base_mask_t get_dram_base_mask(u32 nodeid)
62{
63 device_t dev;
64 dram_base_mask_t d;
65 dev = __f1_dev[0];
66 u32 temp;
67 temp = pci_read_config32(dev, 0x44 + (nodeid << 3)); //[39:24] at [31:16]
68 d.mask = ((temp & 0xfff80000)>>(8+3)); // mask out DramMask [26:24] too
69 temp = pci_read_config32(dev, 0x144 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
70 d.mask |= temp<<21;
71 temp = pci_read_config32(dev, 0x40 + (nodeid << 3)); //[39:24] at [31:16]
72 d.mask |= (temp & 1); // enable bit
73 d.base = ((temp & 0xfff80000)>>(8+3)); // mask out DramBase [26:24) too
74 temp = pci_read_config32(dev, 0x140 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
75 d.base |= temp<<21;
76 return d;
77}
78
79static void set_io_addr_reg(device_t dev, u32 nodeid, u32 linkn, u32 reg,
80 u32 io_min, u32 io_max)
81{
82 u32 i;
83 u32 tempreg;
84 /* io range allocation */
85 tempreg = (nodeid&0xf) | ((nodeid & 0x30)<<(8-4)) | (linkn<<4) | ((io_max&0xf0)<<(12-4)); //limit
86 for (i=0; i<node_nums; i++)
87 pci_write_config32(__f1_dev[i], reg+4, tempreg);
88 tempreg = 3 /*| ( 3<<4)*/ | ((io_min&0xf0)<<(12-4)); //base :ISA and VGA ?
89#if 0
90 // FIXME: can we use VGA reg instead?
91 if (dev->link[link].bridge_ctrl & PCI_BRIDGE_CTL_VGA) {
92 printk(BIOS_SPEW, "%s, enabling legacy VGA IO forwarding for %s link %s\n",
93 __func__, dev_path(dev), link);
94 tempreg |= PCI_IO_BASE_VGA_EN;
95 }
96 if (dev->link[link].bridge_ctrl & PCI_BRIDGE_CTL_NO_ISA) {
97 tempreg |= PCI_IO_BASE_NO_ISA;
98 }
99#endif
100 for (i=0; i<node_nums; i++)
101 pci_write_config32(__f1_dev[i], reg, tempreg);
102}
103
104static void set_mmio_addr_reg(u32 nodeid, u32 linkn, u32 reg, u32 index, u32 mmio_min, u32 mmio_max, u32 nodes)
105{
106 u32 i;
107 u32 tempreg;
108 /* io range allocation */
109 tempreg = (nodeid&0xf) | (linkn<<4) | (mmio_max&0xffffff00); //limit
110 for (i=0; i<nodes; i++)
111 pci_write_config32(__f1_dev[i], reg+4, tempreg);
112 tempreg = 3 | (nodeid & 0x30) | (mmio_min&0xffffff00);
113 for (i=0; i<node_nums; i++)
114 pci_write_config32(__f1_dev[i], reg, tempreg);
115}
116
117static device_t get_node_pci(u32 nodeid, u32 fn)
118{
119#if MAX_NODE_NUMS + CONFIG_CDB >= 32
120 if ((CONFIG_CDB + nodeid) < 32) {
121 return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn));
122 } else {
123 return dev_find_slot(CONFIG_CBB-1, PCI_DEVFN(CONFIG_CDB + nodeid - 32, fn));
124 }
125#else
126 return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn));
127#endif
128}
129
130static void get_fx_devs(void)
131{
132 int i;
133 for (i = 0; i < MAX_NODE_NUMS; i++) {
134 __f0_dev[i] = get_node_pci(i, 0);
135 __f1_dev[i] = get_node_pci(i, 1);
136 __f2_dev[i] = get_node_pci(i, 2);
137 __f4_dev[i] = get_node_pci(i, 4);
138 if (__f0_dev[i] != NULL && __f1_dev[i] != NULL)
139 fx_devs = i+1;
140 }
141 if (__f1_dev[0] == NULL || __f0_dev[0] == NULL || fx_devs == 0) {
142 die("Cannot find 0:0x18.[0|1]\n");
143 }
144 printk(BIOS_DEBUG, "fx_devs=0x%x\n", fx_devs);
145}
146
147static u32 f1_read_config32(unsigned reg)
148{
149 if (fx_devs == 0)
150 get_fx_devs();
151 return pci_read_config32(__f1_dev[0], reg);
152}
153
154static void f1_write_config32(unsigned reg, u32 value)
155{
156 int i;
157 if (fx_devs == 0)
158 get_fx_devs();
159 for(i = 0; i < fx_devs; i++) {
160 device_t dev;
161 dev = __f1_dev[i];
162 if (dev && dev->enabled) {
163 pci_write_config32(dev, reg, value);
164 }
165 }
166}
167
168static u32 amdfam16_nodeid(device_t dev)
169{
170#if MAX_NODE_NUMS == 64
171 unsigned busn;
172 busn = dev->bus->secondary;
173 if (busn != CONFIG_CBB) {
174 return (dev->path.pci.devfn >> 3) - CONFIG_CDB + 32;
175 } else {
176 return (dev->path.pci.devfn >> 3) - CONFIG_CDB;
177 }
178
179#else
180 return (dev->path.pci.devfn >> 3) - CONFIG_CDB;
181#endif
182}
183
184static void set_vga_enable_reg(u32 nodeid, u32 linkn)
185{
186 u32 val;
187
188 val = 1 | (nodeid<<4) | (linkn<<12);
189 /* it will routing
190 * (1)mmio 0xa0000:0xbffff
191 * (2)io 0x3b0:0x3bb, 0x3c0:0x3df
192 */
193 f1_write_config32(0xf4, val);
194
195}
196
197/**
198 * @return
199 * @retval 2 resoure does not exist, usable
200 * @retval 0 resource exists, not usable
201 * @retval 1 resource exist, resource has been allocated before
202 */
203static int reg_useable(unsigned reg, device_t goal_dev, unsigned goal_nodeid,
204 unsigned goal_link)
205{
206 struct resource *res;
207 unsigned nodeid, link = 0;
208 int result;
209 res = 0;
210 for (nodeid = 0; !res && (nodeid < fx_devs); nodeid++) {
211 device_t dev;
212 dev = __f0_dev[nodeid];
213 if (!dev)
214 continue;
215 for (link = 0; !res && (link < 8); link++) {
216 res = probe_resource(dev, IOINDEX(0x1000 + reg, link));
217 }
218 }
219 result = 2;
220 if (res) {
221 result = 0;
222 if ((goal_link == (link - 1)) &&
223 (goal_nodeid == (nodeid - 1)) &&
224 (res->flags <= 1)) {
225 result = 1;
226 }
227 }
228 return result;
229}
230
231static struct resource *amdfam16_find_iopair(device_t dev, unsigned nodeid, unsigned link)
232{
233 struct resource *resource;
234 u32 free_reg, reg;
235 resource = 0;
236 free_reg = 0;
237 for (reg = 0xc0; reg <= 0xd8; reg += 0x8) {
238 int result;
239 result = reg_useable(reg, dev, nodeid, link);
240 if (result == 1) {
241 /* I have been allocated this one */
242 break;
243 }
244 else if (result > 1) {
245 /* I have a free register pair */
246 free_reg = reg;
247 }
248 }
249 if (reg > 0xd8) {
250 reg = free_reg; // if no free, the free_reg still be 0
251 }
252
253 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
254
255 return resource;
256}
257
258static struct resource *amdfam16_find_mempair(device_t dev, u32 nodeid, u32 link)
259{
260 struct resource *resource;
261 u32 free_reg, reg;
262 resource = 0;
263 free_reg = 0;
264 for (reg = 0x80; reg <= 0xb8; reg += 0x8) {
265 int result;
266 result = reg_useable(reg, dev, nodeid, link);
267 if (result == 1) {
268 /* I have been allocated this one */
269 break;
270 }
271 else if (result > 1) {
272 /* I have a free register pair */
273 free_reg = reg;
274 }
275 }
276 if (reg > 0xb8) {
277 reg = free_reg;
278 }
279
280 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
281 return resource;
282}
283
284static void amdfam16_link_read_bases(device_t dev, u32 nodeid, u32 link)
285{
286 struct resource *resource;
287
288 /* Initialize the io space constraints on the current bus */
289 resource = amdfam16_find_iopair(dev, nodeid, link);
290 if (resource) {
291 u32 align;
292 align = log2(HT_IO_HOST_ALIGN);
293 resource->base = 0;
294 resource->size = 0;
295 resource->align = align;
296 resource->gran = align;
297 resource->limit = 0xffffUL;
298 resource->flags = IORESOURCE_IO | IORESOURCE_BRIDGE;
299 }
300
301 /* Initialize the prefetchable memory constraints on the current bus */
302 resource = amdfam16_find_mempair(dev, nodeid, link);
303 if (resource) {
304 resource->base = 0;
305 resource->size = 0;
306 resource->align = log2(HT_MEM_HOST_ALIGN);
307 resource->gran = log2(HT_MEM_HOST_ALIGN);
308 resource->limit = 0xffffffffffULL;
309 resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
310 resource->flags |= IORESOURCE_BRIDGE;
311 }
312
313 /* Initialize the memory constraints on the current bus */
314 resource = amdfam16_find_mempair(dev, nodeid, link);
315 if (resource) {
316 resource->base = 0;
317 resource->size = 0;
318 resource->align = log2(HT_MEM_HOST_ALIGN);
319 resource->gran = log2(HT_MEM_HOST_ALIGN);
320 resource->limit = 0xffffffffffULL;
321 resource->flags = IORESOURCE_MEM | IORESOURCE_BRIDGE;
322 }
323
324}
325
326static void read_resources(device_t dev)
327{
328 u32 nodeid;
329 struct bus *link;
330
331 nodeid = amdfam16_nodeid(dev);
332 for (link = dev->link_list; link; link = link->next) {
333 if (link->children) {
334 amdfam16_link_read_bases(dev, nodeid, link->link_num);
335 }
336 }
Edward O'Callaghan66c65322014-11-21 01:43:38 +1100337
338 /*
339 * This MMCONF resource must be reserved in the PCI_DOMAIN.
340 * It is not honored by the coreboot resource allocator if it is in
341 * the APIC_CLUSTER.
342 */
343#if CONFIG_MMCONF_SUPPORT
344 struct resource *resource = new_resource(dev, 0xc0010058);
345 resource->base = CONFIG_MMCONF_BASE_ADDRESS;
346 resource->size = CONFIG_MMCONF_BUS_NUMBER * 4096 * 256;
347 resource->flags = IORESOURCE_MEM | IORESOURCE_RESERVE |
348 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
349#endif
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800350}
351
352static void set_resource(device_t dev, struct resource *resource, u32 nodeid)
353{
354 resource_t rbase, rend;
355 unsigned reg, link_num;
356 char buf[50];
357
358 /* Make certain the resource has actually been set */
359 if (!(resource->flags & IORESOURCE_ASSIGNED)) {
360 return;
361 }
362
363 /* If I have already stored this resource don't worry about it */
364 if (resource->flags & IORESOURCE_STORED) {
365 return;
366 }
367
368 /* Only handle PCI memory and IO resources */
369 if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
370 return;
371
372 /* Ensure I am actually looking at a resource of function 1 */
373 if ((resource->index & 0xffff) < 0x1000) {
374 return;
375 }
376 /* Get the base address */
377 rbase = resource->base;
378
379 /* Get the limit (rounded up) */
380 rend = resource_end(resource);
381
382 /* Get the register and link */
383 reg = resource->index & 0xfff; // 4k
384 link_num = IOINDEX_LINK(resource->index);
385
386 if (resource->flags & IORESOURCE_IO) {
387 set_io_addr_reg(dev, nodeid, link_num, reg, rbase>>8, rend>>8);
388 }
389 else if (resource->flags & IORESOURCE_MEM) {
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100390 set_mmio_addr_reg(nodeid, link_num, reg, (resource->index >>24), rbase>>8, rend>>8, node_nums);// [39:8]
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800391 }
392 resource->flags |= IORESOURCE_STORED;
Vladimir Serbinenkoa37383d2013-11-26 02:41:26 +0100393 snprintf(buf, sizeof (buf), " <node %x link %x>",
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800394 nodeid, link_num);
395 report_resource_stored(dev, resource, buf);
396}
397
398/**
399 * I tried to reuse the resource allocation code in set_resource()
400 * but it is too difficult to deal with the resource allocation magic.
401 */
402
403static void create_vga_resource(device_t dev, unsigned nodeid)
404{
405 struct bus *link;
406
407 /* find out which link the VGA card is connected,
408 * we only deal with the 'first' vga card */
409 for (link = dev->link_list; link; link = link->next) {
410 if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) {
411#if CONFIG_MULTIPLE_VGA_ADAPTERS
412 extern device_t vga_pri; // the primary vga device, defined in device.c
413 printk(BIOS_DEBUG, "VGA: vga_pri bus num = %d bus range [%d,%d]\n", vga_pri->bus->secondary,
414 link->secondary,link->subordinate);
415 /* We need to make sure the vga_pri is under the link */
416 if((vga_pri->bus->secondary >= link->secondary ) &&
417 (vga_pri->bus->secondary <= link->subordinate )
418 )
419#endif
420 break;
421 }
422 }
423
424 /* no VGA card installed */
425 if (link == NULL)
426 return;
427
428 printk(BIOS_DEBUG, "VGA: %s (aka node %d) link %d has VGA device\n", dev_path(dev), nodeid, sblink);
429 set_vga_enable_reg(nodeid, sblink);
430}
431
432static void set_resources(device_t dev)
433{
434 unsigned nodeid;
435 struct bus *bus;
436 struct resource *res;
437
438 /* Find the nodeid */
439 nodeid = amdfam16_nodeid(dev);
440
441 create_vga_resource(dev, nodeid); //TODO: do we need this?
442
443 /* Set each resource we have found */
444 for (res = dev->resource_list; res; res = res->next) {
445 set_resource(dev, res, nodeid);
446 }
447
448 for (bus = dev->link_list; bus; bus = bus->next) {
449 if (bus->children) {
450 assign_resources(bus);
451 }
452 }
Edward O'Callaghan66c65322014-11-21 01:43:38 +1100453
454 /* Print the MMCONF region if it has been reserved. */
455 res = find_resource(dev, 0xc0010058);
456 if (res) {
457 report_resource_stored(dev, res, " <mmconfig>");
458 }
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800459}
460
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200461
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100462static unsigned long acpi_fill_hest(acpi_hest_t *hest)
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200463{
464 void *addr, *current;
465
466 /* Skip the HEST header. */
467 current = (void *)(hest + 1);
468
469 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
470 if (addr != NULL)
Stefan Reinauer77a1d1a2015-07-21 12:48:17 -0700471 current += acpi_create_hest_error_source(hest, current, 0,
472 addr + 2, *(UINT16 *)addr - 2);
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200473
474 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
475 if (addr != NULL)
Stefan Reinauer77a1d1a2015-07-21 12:48:17 -0700476 current += acpi_create_hest_error_source(hest, current, 1,
477 addr + 2, *(UINT16 *)addr - 2);
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200478
479 return (unsigned long)current;
480}
481
Alexander Couzens5eea4582015-04-12 22:18:55 +0200482static void northbridge_fill_ssdt_generator(device_t device)
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200483{
484 msr_t msr;
485 char pscope[] = "\\_SB.PCI0";
486
487 acpigen_write_scope(pscope);
488 msr = rdmsr(TOP_MEM);
489 acpigen_write_name_dword("TOM1", msr.lo);
490 msr = rdmsr(TOP_MEM2);
491 /*
492 * Since XP only implements parts of ACPI 2.0, we can't use a qword
493 * here.
494 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
495 * slide 22ff.
496 * Shift value right by 20 bit to make it fit into 32bit,
497 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
498 */
499 acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
500 acpigen_pop_len();
501}
502
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200503static unsigned long agesa_write_acpi_tables(device_t device,
504 unsigned long current,
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200505 acpi_rsdp_t *rsdp)
506{
507 acpi_srat_t *srat;
508 acpi_slit_t *slit;
509 acpi_header_t *ssdt;
510 acpi_header_t *alib;
511 acpi_header_t *ivrs;
512 acpi_hest_t *hest;
513
514 /* HEST */
515 current = ALIGN(current, 8);
516 hest = (acpi_hest_t *)current;
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100517 acpi_write_hest((void *)current, acpi_fill_hest);
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200518 acpi_add_table(rsdp, (void *)current);
519 current += ((acpi_header_t *)current)->length;
520
521 current = ALIGN(current, 8);
522 printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current);
523 ivrs = agesawrapper_getlateinitptr(PICK_IVRS);
524 if (ivrs != NULL) {
525 memcpy((void *)current, ivrs, ivrs->length);
526 ivrs = (acpi_header_t *) current;
527 current += ivrs->length;
528 acpi_add_table(rsdp, ivrs);
529 } else {
530 printk(BIOS_DEBUG, " AGESA IVRS table NULL. Skipping.\n");
531 }
532
533 /* SRAT */
534 current = ALIGN(current, 8);
535 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
536 srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
537 if (srat != NULL) {
538 memcpy((void *)current, srat, srat->header.length);
539 srat = (acpi_srat_t *) current;
540 current += srat->header.length;
541 acpi_add_table(rsdp, srat);
542 } else {
543 printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n");
544 }
545
546 /* SLIT */
547 current = ALIGN(current, 8);
548 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
549 slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
550 if (slit != NULL) {
551 memcpy((void *)current, slit, slit->header.length);
552 slit = (acpi_slit_t *) current;
553 current += slit->header.length;
554 acpi_add_table(rsdp, slit);
555 } else {
556 printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n");
557 }
558
559 /* ALIB */
560 current = ALIGN(current, 16);
561 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
562 alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB);
563 if (alib != NULL) {
564 memcpy((void *)current, alib, alib->length);
565 alib = (acpi_header_t *) current;
566 current += alib->length;
567 acpi_add_table(rsdp, (void *)alib);
568 }
569 else {
570 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n");
571 }
572
573 /* this pstate ssdt may cause Blue Screen: Fixed: Keep this comment for a while. */
574 /* SSDT */
575 current = ALIGN(current, 16);
576 printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current);
577 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
578 if (ssdt != NULL) {
579 memcpy((void *)current, ssdt, ssdt->length);
580 ssdt = (acpi_header_t *) current;
581 current += ssdt->length;
582 }
583 else {
584 printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n");
585 }
586 acpi_add_table(rsdp,ssdt);
587
588 printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current);
589
590 return current;
591}
592
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800593static struct device_operations northbridge_operations = {
594 .read_resources = read_resources,
595 .set_resources = set_resources,
596 .enable_resources = pci_dev_enable_resources,
Edward O'Callaghand994ef12014-11-21 02:22:33 +1100597 .init = DEVICE_NOOP,
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200598 .acpi_fill_ssdt_generator = northbridge_fill_ssdt_generator,
599 .write_acpi_tables = agesa_write_acpi_tables,
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800600 .enable = 0,
601 .ops_pci = 0,
602};
603
604static const struct pci_driver family16_northbridge __pci_driver = {
605 .ops = &northbridge_operations,
606 .vendor = PCI_VENDOR_ID_AMD,
607 .device = PCI_DEVICE_ID_AMD_16H_MODEL_000F_NB_HT,
608};
609
610static const struct pci_driver family10_northbridge __pci_driver = {
611 .ops = &northbridge_operations,
612 .vendor = PCI_VENDOR_ID_AMD,
613 .device = PCI_DEVICE_ID_AMD_10H_NB_HT,
614};
615
Kyösti Mälkki4ee82c62014-11-25 16:03:12 +0200616static void fam16_finalize(void *chip_info)
617{
618 device_t dev;
619 u32 value;
620 dev = dev_find_slot(0, PCI_DEVFN(0, 0)); /* clear IoapicSbFeatureEn */
621 pci_write_config32(dev, 0xF8, 0);
622 pci_write_config32(dev, 0xFC, 5); /* TODO: move it to dsdt.asl */
623
624 /* disable No Snoop */
625 dev = dev_find_slot(0, PCI_DEVFN(1, 1));
626 value = pci_read_config32(dev, 0x60);
627 value &= ~(1 << 11);
628 pci_write_config32(dev, 0x60, value);
629}
630
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800631struct chip_operations northbridge_amd_agesa_family16kb_ops = {
632 CHIP_NAME("AMD FAM16 Northbridge")
633 .enable_dev = 0,
Kyösti Mälkki4ee82c62014-11-25 16:03:12 +0200634 .final = fam16_finalize,
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800635};
636
637static void domain_read_resources(device_t dev)
638{
639 unsigned reg;
640
641 /* Find the already assigned resource pairs */
642 get_fx_devs();
643 for (reg = 0x80; reg <= 0xd8; reg+= 0x08) {
644 u32 base, limit;
645 base = f1_read_config32(reg);
646 limit = f1_read_config32(reg + 0x04);
647 /* Is this register allocated? */
648 if ((base & 3) != 0) {
649 unsigned nodeid, reg_link;
650 device_t reg_dev;
651 if (reg<0xc0) { // mmio
652 nodeid = (limit & 0xf) + (base&0x30);
653 } else { // io
654 nodeid = (limit & 0xf) + ((base>>4)&0x30);
655 }
656 reg_link = (limit >> 4) & 7;
657 reg_dev = __f0_dev[nodeid];
658 if (reg_dev) {
659 /* Reserve the resource */
660 struct resource *res;
661 res = new_resource(reg_dev, IOINDEX(0x1000 + reg, reg_link));
662 if (res) {
663 res->flags = 1;
664 }
665 }
666 }
667 }
668 /* FIXME: do we need to check extend conf space?
669 I don't believe that much preset value */
670
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800671 pci_domain_read_resources(dev);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800672}
673
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800674static void domain_enable_resources(device_t dev)
675{
Kyösti Mälkki8ae16a42014-06-19 20:44:34 +0300676 if (acpi_is_wakeup_s3())
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300677 agesawrapper_fchs3laterestore();
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800678
679 /* Must be called after PCI enumeration and resource allocation */
Kyösti Mälkkib139b5e2014-10-20 07:41:20 +0300680 if (!acpi_is_wakeup_s3()) {
681 /* Enable MMIO on AMD CPU Address Map Controller */
Kyösti Mälkki48518f02014-11-25 14:20:57 +0200682 amd_initcpuio();
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800683
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300684 agesawrapper_amdinitmid();
Kyösti Mälkkib139b5e2014-10-20 07:41:20 +0300685 }
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800686 printk(BIOS_DEBUG, " ader - leaving domain_enable_resources.\n");
687}
688
689#if CONFIG_HW_MEM_HOLE_SIZEK != 0
690struct hw_mem_hole_info {
691 unsigned hole_startk;
692 int node_id;
693};
694static struct hw_mem_hole_info get_hw_mem_hole_info(void)
695{
696 struct hw_mem_hole_info mem_hole;
697 int i;
698 mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK;
699 mem_hole.node_id = -1;
700 for (i = 0; i < node_nums; i++) {
701 dram_base_mask_t d;
702 u32 hole;
703 d = get_dram_base_mask(i);
704 if (!(d.mask & 1)) continue; // no memory on this node
705 hole = pci_read_config32(__f1_dev[i], 0xf0);
706 if (hole & 2) { // we find the hole
707 mem_hole.hole_startk = (hole & (0xff<<24)) >> 10;
708 mem_hole.node_id = i; // record the node No with hole
709 break; // only one hole
710 }
711 }
Kyösti Mälkki2f9b3af2014-06-26 05:30:54 +0300712
713 /* We need to double check if there is special set on base reg and limit reg
714 * are not continuous instead of hole, it will find out its hole_startk.
715 */
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800716 if (mem_hole.node_id == -1) {
717 resource_t limitk_pri = 0;
718 for (i=0; i<node_nums; i++) {
719 dram_base_mask_t d;
720 resource_t base_k, limit_k;
721 d = get_dram_base_mask(i);
722 if (!(d.base & 1)) continue;
723 base_k = ((resource_t)(d.base & 0x1fffff00)) <<9;
724 if (base_k > 4 *1024 * 1024) break; // don't need to go to check
725 if (limitk_pri != base_k) { // we find the hole
726 mem_hole.hole_startk = (unsigned)limitk_pri; // must beblow 4G
727 mem_hole.node_id = i;
728 break; //only one hole
729 }
730 limit_k = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
731 limitk_pri = limit_k;
732 }
733 }
734 return mem_hole;
735}
736#endif
737
738#define ONE_MB_SHIFT 20
739
740static void setup_uma_memory(void)
741{
742#if CONFIG_GFXUMA
743 uint32_t topmem = (uint32_t) bsp_topmem();
744 uint32_t sys_mem;
745
746 /* refer to UMA Size Consideration in Family16h BKDG. */
747 /* Please reference MemNGetUmaSizeOR () */
748 /*
749 * Total system memory UMASize
750 * >= 2G 512M
751 * >=1G 256M
752 * <1G 64M
753 */
754 sys_mem = topmem + (16 << ONE_MB_SHIFT); // Ignore 16MB allocated for C6 when finding UMA size
755 if ((bsp_topmem2()>>32) || (sys_mem >= 2048 << ONE_MB_SHIFT)) {
756 uma_memory_size = 512 << ONE_MB_SHIFT;
757 } else if (sys_mem >= 1024 << ONE_MB_SHIFT) {
758 uma_memory_size = 256 << ONE_MB_SHIFT;
759 } else {
760 uma_memory_size = 64 << ONE_MB_SHIFT;
761 }
762 uma_memory_base = topmem - uma_memory_size; /* TOP_MEM1 */
763
764 printk(BIOS_INFO, "%s: uma size 0x%08llx, memory start 0x%08llx\n",
765 __func__, uma_memory_size, uma_memory_base);
766
767 /* TODO: TOP_MEM2 */
768#endif
769}
770
771
772static void domain_set_resources(device_t dev)
773{
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800774 unsigned long mmio_basek;
775 u32 pci_tolm;
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300776 u64 ramtop = 0;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800777 int i, idx;
778 struct bus *link;
779#if CONFIG_HW_MEM_HOLE_SIZEK != 0
780 struct hw_mem_hole_info mem_hole;
781 u32 reset_memhole = 1;
782#endif
783
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800784 pci_tolm = 0xffffffffUL;
785 for (link = dev->link_list; link; link = link->next) {
786 pci_tolm = find_pci_tolm(link);
787 }
788
789 // FIXME handle interleaved nodes. If you fix this here, please fix
790 // amdk8, too.
791 mmio_basek = pci_tolm >> 10;
792 /* Round mmio_basek to something the processor can support */
793 mmio_basek &= ~((1 << 6) -1);
794
795 // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M
796 // MMIO hole. If you fix this here, please fix amdk8, too.
797 /* Round the mmio hole to 64M */
798 mmio_basek &= ~((64*1024) - 1);
799
800#if CONFIG_HW_MEM_HOLE_SIZEK != 0
801 /* if the hw mem hole is already set in raminit stage, here we will compare
802 * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will
803 * use hole_basek as mmio_basek and we don't need to reset hole.
804 * otherwise We reset the hole to the mmio_basek
805 */
806
807 mem_hole = get_hw_mem_hole_info();
808
809 // Use hole_basek as mmio_basek, and we don't need to reset hole anymore
810 if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) {
811 mmio_basek = mem_hole.hole_startk;
812 reset_memhole = 0;
813 }
814#endif
815
816 idx = 0x10;
817 for (i = 0; i < node_nums; i++) {
818 dram_base_mask_t d;
819 resource_t basek, limitk, sizek; // 4 1T
820
821 d = get_dram_base_mask(i);
822
823 if (!(d.mask & 1)) continue;
824 basek = ((resource_t)(d.base & 0x1fffff00)) << 9; // could overflow, we may lost 6 bit here
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100825 limitk = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800826
827 sizek = limitk - basek;
828
829 /* see if we need a hole from 0xa0000 to 0xbffff */
830 if ((basek < ((8*64)+(8*16))) && (sizek > ((8*64)+(16*16)))) {
831 ram_resource(dev, (idx | i), basek, ((8*64)+(8*16)) - basek);
832 idx += 0x10;
833 basek = (8*64)+(16*16);
834 sizek = limitk - ((8*64)+(16*16));
835
836 }
837
838 //printk(BIOS_DEBUG, "node %d : mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", i, mmio_basek, basek, limitk);
839
Kyösti Mälkki26c65432014-06-26 05:30:54 +0300840 /* split the region to accommodate pci memory space */
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800841 if ((basek < 4*1024*1024 ) && (limitk > mmio_basek)) {
842 if (basek <= mmio_basek) {
843 unsigned pre_sizek;
844 pre_sizek = mmio_basek - basek;
845 if (pre_sizek>0) {
846 ram_resource(dev, (idx | i), basek, pre_sizek);
847 idx += 0x10;
848 sizek -= pre_sizek;
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300849 if (!ramtop)
850 ramtop = mmio_basek * 1024;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800851 }
852 basek = mmio_basek;
853 }
854 if ((basek + sizek) <= 4*1024*1024) {
855 sizek = 0;
856 }
857 else {
858 uint64_t topmem2 = bsp_topmem2();
859 basek = 4*1024*1024;
860 sizek = topmem2/1024 - basek;
861 }
862 }
863
864 ram_resource(dev, (idx | i), basek, sizek);
865 idx += 0x10;
866 printk(BIOS_DEBUG, "node %d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n",
867 i, mmio_basek, basek, limitk);
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300868 if (!ramtop)
869 ramtop = limitk * 1024;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800870 }
871
872#if CONFIG_GFXUMA
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300873 set_top_of_ram(uma_memory_base);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800874 uma_resource(dev, 7, uma_memory_base >> 10, uma_memory_size >> 10);
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300875#else
876 set_top_of_ram(ramtop);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800877#endif
878
879 for(link = dev->link_list; link; link = link->next) {
880 if (link->children) {
881 assign_resources(link);
882 }
883 }
884}
885
886static struct device_operations pci_domain_ops = {
887 .read_resources = domain_read_resources,
888 .set_resources = domain_set_resources,
889 .enable_resources = domain_enable_resources,
Edward O'Callaghane9e1d7a2015-01-02 15:11:49 +1100890 .init = DEVICE_NOOP,
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800891 .scan_bus = pci_domain_scan_bus,
892 .ops_pci_bus = pci_bus_default_ops,
893};
894
895static void sysconf_init(device_t dev) // first node
896{
897 sblink = (pci_read_config32(dev, 0x64)>>8) & 7; // don't forget sublink1
898 node_nums = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; //NodeCnt[2:0]
899}
900
901static void add_more_links(device_t dev, unsigned total_links)
902{
903 struct bus *link, *last = NULL;
904 int link_num;
905
906 for (link = dev->link_list; link; link = link->next)
907 last = link;
908
909 if (last) {
910 int links = total_links - last->link_num;
911 link_num = last->link_num;
912 if (links > 0) {
913 link = malloc(links*sizeof(*link));
914 if (!link)
915 die("Couldn't allocate more links!\n");
916 memset(link, 0, links*sizeof(*link));
917 last->next = link;
918 }
919 }
920 else {
921 link_num = -1;
922 link = malloc(total_links*sizeof(*link));
923 memset(link, 0, total_links*sizeof(*link));
924 dev->link_list = link;
925 }
926
927 for (link_num = link_num + 1; link_num < total_links; link_num++) {
928 link->link_num = link_num;
929 link->dev = dev;
930 link->next = link + 1;
931 last = link;
932 link = link->next;
933 }
934 last->next = NULL;
935}
936
Kyösti Mälkki580e7222015-03-19 21:04:23 +0200937static void cpu_bus_scan(device_t dev)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800938{
939 struct bus *cpu_bus;
940 device_t dev_mc;
941#if CONFIG_CBB
942 device_t pci_domain;
943#endif
944 int i,j;
945 int coreid_bits;
946 int core_max = 0;
947 unsigned ApicIdCoreIdSize;
948 unsigned core_nums;
949 int siblings = 0;
950 unsigned int family;
951
952#if CONFIG_CBB
953 dev_mc = dev_find_slot(0, PCI_DEVFN(CONFIG_CDB, 0)); //0x00
954 if (dev_mc && dev_mc->bus) {
955 printk(BIOS_DEBUG, "%s found", dev_path(dev_mc));
956 pci_domain = dev_mc->bus->dev;
957 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
958 printk(BIOS_DEBUG, "\n%s move to ",dev_path(dev_mc));
959 dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
960 printk(BIOS_DEBUG, "%s",dev_path(dev_mc));
961 } else {
962 printk(BIOS_DEBUG, " but it is not under pci_domain directly ");
963 }
964 printk(BIOS_DEBUG, "\n");
965 }
966 dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
967 if (!dev_mc) {
968 dev_mc = dev_find_slot(0, PCI_DEVFN(0x18, 0));
969 if (dev_mc && dev_mc->bus) {
970 printk(BIOS_DEBUG, "%s found\n", dev_path(dev_mc));
971 pci_domain = dev_mc->bus->dev;
972 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
973 if ((pci_domain->link_list) && (pci_domain->link_list->children == dev_mc)) {
974 printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
975 dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
976 printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
977 while (dev_mc) {
978 printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
979 dev_mc->path.pci.devfn -= PCI_DEVFN(0x18,0);
980 printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
981 dev_mc = dev_mc->sibling;
982 }
983 }
984 }
985 }
986 }
987#endif
988 dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
989 if (!dev_mc) {
990 printk(BIOS_ERR, "%02x:%02x.0 not found", CONFIG_CBB, CONFIG_CDB);
991 die("");
992 }
993 sysconf_init(dev_mc);
994#if CONFIG_CBB && (MAX_NODE_NUMS > 32)
995 if (node_nums>32) { // need to put node 32 to node 63 to bus 0xfe
996 if (pci_domain->link_list && !pci_domain->link_list->next) {
997 struct bus *new_link = new_link(pci_domain);
998 pci_domain->link_list->next = new_link;
999 new_link->link_num = 1;
1000 new_link->dev = pci_domain;
1001 new_link->children = 0;
1002 printk(BIOS_DEBUG, "%s links now 2\n", dev_path(pci_domain));
1003 }
1004 pci_domain->link_list->next->secondary = CONFIG_CBB - 1;
1005 }
1006#endif
1007
1008 /* Get Max Number of cores(MNC) */
1009 coreid_bits = (cpuid_ecx(AMD_CPUID_ASIZE_PCCOUNT) & 0x0000F000) >> 12;
1010 core_max = 1 << (coreid_bits & 0x000F); //mnc
1011
1012 ApicIdCoreIdSize = ((cpuid_ecx(0x80000008)>>12) & 0xF);
1013 if (ApicIdCoreIdSize) {
1014 core_nums = (1 << ApicIdCoreIdSize) - 1;
1015 } else {
1016 core_nums = 3; //quad core
1017 }
1018
1019 /* Find which cpus are present */
1020 cpu_bus = dev->link_list;
1021 for (i = 0; i < node_nums; i++) {
1022 device_t cdb_dev;
1023 unsigned busn, devn;
1024 struct bus *pbus;
1025
1026 busn = CONFIG_CBB;
1027 devn = CONFIG_CDB + i;
1028 pbus = dev_mc->bus;
1029#if CONFIG_CBB && (MAX_NODE_NUMS > 32)
1030 if (i >= 32) {
1031 busn--;
1032 devn -= 32;
1033 pbus = pci_domain->link_list->next;
1034 }
1035#endif
1036
1037 /* Find the cpu's pci device */
1038 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0));
1039 if (!cdb_dev) {
1040 /* If I am probing things in a weird order
1041 * ensure all of the cpu's pci devices are found.
1042 */
1043 int fn;
1044 for(fn = 0; fn <= 5; fn++) { //FBDIMM?
1045 cdb_dev = pci_probe_dev(NULL, pbus,
1046 PCI_DEVFN(devn, fn));
1047 }
1048 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0));
1049 } else {
1050 /* Ok, We need to set the links for that device.
1051 * otherwise the device under it will not be scanned
1052 */
Kyösti Mälkki2a2d6132015-02-04 13:25:37 +02001053 add_more_links(cdb_dev, 4);
Siyuan Wang3e32cc02013-07-09 17:16:20 +08001054 }
1055
1056 family = cpuid_eax(1);
1057 family = (family >> 20) & 0xFF;
1058 if (family == 1) { //f10
1059 u32 dword;
1060 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 3));
1061 dword = pci_read_config32(cdb_dev, 0xe8);
1062 siblings = ((dword & BIT15) >> 13) | ((dword & (BIT13 | BIT12)) >> 12);
1063 } else if (family == 7) {//f16
1064 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 5));
1065 if (cdb_dev && cdb_dev->enabled) {
1066 siblings = pci_read_config32(cdb_dev, 0x84);
1067 siblings &= 0xFF;
1068 }
1069 } else {
1070 siblings = 0; //default one core
1071 }
1072 int enable_node = cdb_dev && cdb_dev->enabled;
1073 printk(BIOS_SPEW, "%s family%xh, core_max=0x%x, core_nums=0x%x, siblings=0x%x\n",
1074 dev_path(cdb_dev), 0x0f + family, core_max, core_nums, siblings);
1075
1076 for (j = 0; j <= siblings; j++ ) {
1077 extern CONST OPTIONS_CONFIG_TOPOLOGY ROMDATA TopologyConfiguration;
1078 u32 modules = TopologyConfiguration.PlatformNumberOfModules;
1079 u32 lapicid_start = 0;
1080
1081 /*
1082 * APIC ID calucation is tightly coupled with AGESA v5 code.
1083 * This calculation MUST match the assignment calculation done
1084 * in LocalApicInitializationAtEarly() function.
1085 * And reference GetLocalApicIdForCore()
1086 *
1087 * Apply apic enumeration rules
1088 * For systems with >= 16 APICs, put the IO-APICs at 0..n and
1089 * put the local-APICs at m..z
1090 *
1091 * This is needed because many IO-APIC devices only have 4 bits
1092 * for their APIC id and therefore must reside at 0..15
1093 */
1094#ifndef CFG_PLAT_NUM_IO_APICS /* defined in mainboard buildOpts.c */
1095#define CFG_PLAT_NUM_IO_APICS 3
1096#endif
1097 if ((node_nums * core_max) + CFG_PLAT_NUM_IO_APICS >= 0x10) {
1098 lapicid_start = (CFG_PLAT_NUM_IO_APICS - 1) / core_max;
1099 lapicid_start = (lapicid_start + 1) * core_max;
1100 printk(BIOS_SPEW, "lpaicid_start=0x%x ", lapicid_start);
1101 }
1102 u32 apic_id = (lapicid_start * (i/modules + 1)) + ((i % modules) ? (j + (siblings + 1)) : j);
1103 printk(BIOS_SPEW, "node 0x%x core 0x%x apicid=0x%x\n",
1104 i, j, apic_id);
1105
1106 device_t cpu = add_cpu_device(cpu_bus, apic_id, enable_node);
1107 if (cpu)
1108 amd_cpu_topology(cpu, i, j);
1109 } //j
1110 }
Siyuan Wang3e32cc02013-07-09 17:16:20 +08001111}
1112
1113static void cpu_bus_init(device_t dev)
1114{
1115 initialize_cpus(dev->link_list);
1116}
1117
Siyuan Wang3e32cc02013-07-09 17:16:20 +08001118static struct device_operations cpu_bus_ops = {
Edward O'Callaghan66c65322014-11-21 01:43:38 +11001119 .read_resources = DEVICE_NOOP,
1120 .set_resources = DEVICE_NOOP,
Edward O'Callaghan812d2a42014-10-31 08:17:23 +11001121 .enable_resources = DEVICE_NOOP,
Siyuan Wang3e32cc02013-07-09 17:16:20 +08001122 .init = cpu_bus_init,
1123 .scan_bus = cpu_bus_scan,
1124};
1125
1126static void root_complex_enable_dev(struct device *dev)
1127{
1128 static int done = 0;
1129
1130 /* Do not delay UMA setup, as a device on the PCI bus may evaluate
1131 the global uma_memory variables already in its enable function. */
1132 if (!done) {
1133 setup_bsp_ramtop();
1134 setup_uma_memory();
1135 done = 1;
1136 }
1137
1138 /* Set the operations if it is a special bus type */
1139 if (dev->path.type == DEVICE_PATH_DOMAIN) {
1140 dev->ops = &pci_domain_ops;
1141 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
1142 dev->ops = &cpu_bus_ops;
1143 }
1144}
1145
1146struct chip_operations northbridge_amd_agesa_family16kb_root_complex_ops = {
1147 CHIP_NAME("AMD FAM16 Root Complex")
1148 .enable_dev = root_complex_enable_dev,
1149};
Bruce Griffith76db07e2013-07-07 02:06:53 -06001150
1151/*********************************************************************
1152 * Change the vendor / device IDs to match the generic VBIOS header. *
1153 *********************************************************************/
1154u32 map_oprom_vendev(u32 vendev)
1155{
1156 u32 new_vendev = vendev;
1157
1158 switch(vendev) {
1159 case 0x10029830:
1160 case 0x10029831:
1161 case 0x10029832:
1162 case 0x10029833:
1163 case 0x10029834:
1164 case 0x10029835:
1165 case 0x10029836:
1166 case 0x10029837:
1167 case 0x10029838:
1168 case 0x10029839:
1169 case 0x1002983A:
1170 case 0x1002983D:
1171 new_vendev = 0x10029830; // This is the default value in AMD-generated VBIOS
1172 break;
1173 default:
1174 break;
1175 }
1176
1177 if (vendev != new_vendev)
1178 printk(BIOS_NOTICE, "Mapping PCI device %8x to %8x\n", vendev, new_vendev);
1179
1180 return new_vendev;
1181}