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