blob: ab2e8e8980e25d0bc5dba6944a1056b8b4b2cd43 [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älkkid610c582017-03-05 06:28:18 +020040
Kyösti Mälkkif21c2ac2014-10-19 09:35:18 +030041#include <northbridge/amd/agesa/agesawrapper.h>
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020042#include <northbridge/amd/agesa/state_machine.h>
Kyösti Mälkkid610c582017-03-05 06:28:18 +020043#include <northbridge/amd/agesa/agesa_helper.h>
Siyuan Wang3e32cc02013-07-09 17:16:20 +080044
45#define MAX_NODE_NUMS (MAX_NODES * MAX_DIES)
46
Siyuan Wang3e32cc02013-07-09 17:16:20 +080047typedef struct dram_base_mask {
48 u32 base; //[47:27] at [28:8]
49 u32 mask; //[47:27] at [28:8] and enable at bit 0
50} dram_base_mask_t;
51
52static unsigned node_nums;
53static unsigned sblink;
54static device_t __f0_dev[MAX_NODE_NUMS];
55static device_t __f1_dev[MAX_NODE_NUMS];
56static device_t __f2_dev[MAX_NODE_NUMS];
57static device_t __f4_dev[MAX_NODE_NUMS];
58static unsigned fx_devs = 0;
59
60static dram_base_mask_t get_dram_base_mask(u32 nodeid)
61{
62 device_t dev;
63 dram_base_mask_t d;
64 dev = __f1_dev[0];
65 u32 temp;
66 temp = pci_read_config32(dev, 0x44 + (nodeid << 3)); //[39:24] at [31:16]
67 d.mask = ((temp & 0xfff80000)>>(8+3)); // mask out DramMask [26:24] too
68 temp = pci_read_config32(dev, 0x144 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
Elyes HAOUAS27e18012017-06-27 23:14:51 +020069 d.mask |= temp << 21;
Siyuan Wang3e32cc02013-07-09 17:16:20 +080070 temp = pci_read_config32(dev, 0x40 + (nodeid << 3)); //[39:24] at [31:16]
71 d.mask |= (temp & 1); // enable bit
72 d.base = ((temp & 0xfff80000)>>(8+3)); // mask out DramBase [26:24) too
73 temp = pci_read_config32(dev, 0x140 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
Elyes HAOUAS27e18012017-06-27 23:14:51 +020074 d.base |= temp << 21;
Siyuan Wang3e32cc02013-07-09 17:16:20 +080075 return d;
76}
77
78static void set_io_addr_reg(device_t dev, u32 nodeid, u32 linkn, u32 reg,
79 u32 io_min, u32 io_max)
80{
81 u32 i;
82 u32 tempreg;
83 /* io range allocation */
Elyes HAOUAS27e18012017-06-27 23:14:51 +020084 tempreg = (nodeid&0xf) | ((nodeid & 0x30)<<(8-4)) | (linkn << 4) | ((io_max&0xf0)<<(12-4)); //limit
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020085 for (i = 0; i < node_nums; i++)
Siyuan Wang3e32cc02013-07-09 17:16:20 +080086 pci_write_config32(__f1_dev[i], reg+4, tempreg);
Elyes HAOUAS27e18012017-06-27 23:14:51 +020087 tempreg = 3 /*| (3 << 4)*/ | ((io_min&0xf0)<<(12-4)); //base :ISA and VGA ?
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020088 for (i = 0; i < node_nums; i++)
Siyuan Wang3e32cc02013-07-09 17:16:20 +080089 pci_write_config32(__f1_dev[i], reg, tempreg);
90}
91
92static void set_mmio_addr_reg(u32 nodeid, u32 linkn, u32 reg, u32 index, u32 mmio_min, u32 mmio_max, u32 nodes)
93{
94 u32 i;
95 u32 tempreg;
96 /* io range allocation */
Elyes HAOUAS27e18012017-06-27 23:14:51 +020097 tempreg = (nodeid&0xf) | (linkn << 4) | (mmio_max&0xffffff00); //limit
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020098 for (i = 0; i < nodes; i++)
Siyuan Wang3e32cc02013-07-09 17:16:20 +080099 pci_write_config32(__f1_dev[i], reg+4, tempreg);
100 tempreg = 3 | (nodeid & 0x30) | (mmio_min&0xffffff00);
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200101 for (i = 0; i < node_nums; i++)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800102 pci_write_config32(__f1_dev[i], reg, tempreg);
103}
104
105static device_t get_node_pci(u32 nodeid, u32 fn)
106{
107#if MAX_NODE_NUMS + CONFIG_CDB >= 32
108 if ((CONFIG_CDB + nodeid) < 32) {
109 return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn));
110 } else {
111 return dev_find_slot(CONFIG_CBB-1, PCI_DEVFN(CONFIG_CDB + nodeid - 32, fn));
112 }
113#else
114 return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn));
115#endif
116}
117
118static void get_fx_devs(void)
119{
120 int i;
121 for (i = 0; i < MAX_NODE_NUMS; i++) {
122 __f0_dev[i] = get_node_pci(i, 0);
123 __f1_dev[i] = get_node_pci(i, 1);
124 __f2_dev[i] = get_node_pci(i, 2);
125 __f4_dev[i] = get_node_pci(i, 4);
126 if (__f0_dev[i] != NULL && __f1_dev[i] != NULL)
127 fx_devs = i+1;
128 }
129 if (__f1_dev[0] == NULL || __f0_dev[0] == NULL || fx_devs == 0) {
130 die("Cannot find 0:0x18.[0|1]\n");
131 }
132 printk(BIOS_DEBUG, "fx_devs=0x%x\n", fx_devs);
133}
134
135static u32 f1_read_config32(unsigned reg)
136{
137 if (fx_devs == 0)
138 get_fx_devs();
139 return pci_read_config32(__f1_dev[0], reg);
140}
141
142static void f1_write_config32(unsigned reg, u32 value)
143{
144 int i;
145 if (fx_devs == 0)
146 get_fx_devs();
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200147 for (i = 0; i < fx_devs; i++) {
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800148 device_t dev;
149 dev = __f1_dev[i];
150 if (dev && dev->enabled) {
151 pci_write_config32(dev, reg, value);
152 }
153 }
154}
155
156static u32 amdfam16_nodeid(device_t dev)
157{
158#if MAX_NODE_NUMS == 64
159 unsigned busn;
160 busn = dev->bus->secondary;
161 if (busn != CONFIG_CBB) {
162 return (dev->path.pci.devfn >> 3) - CONFIG_CDB + 32;
163 } else {
164 return (dev->path.pci.devfn >> 3) - CONFIG_CDB;
165 }
166
167#else
168 return (dev->path.pci.devfn >> 3) - CONFIG_CDB;
169#endif
170}
171
172static void set_vga_enable_reg(u32 nodeid, u32 linkn)
173{
174 u32 val;
175
Elyes HAOUAS27e18012017-06-27 23:14:51 +0200176 val = 1 | (nodeid << 4) | (linkn << 12);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800177 /* it will routing
178 * (1)mmio 0xa0000:0xbffff
179 * (2)io 0x3b0:0x3bb, 0x3c0:0x3df
180 */
181 f1_write_config32(0xf4, val);
182
183}
184
185/**
186 * @return
187 * @retval 2 resoure does not exist, usable
188 * @retval 0 resource exists, not usable
189 * @retval 1 resource exist, resource has been allocated before
190 */
191static int reg_useable(unsigned reg, device_t goal_dev, unsigned goal_nodeid,
192 unsigned goal_link)
193{
194 struct resource *res;
195 unsigned nodeid, link = 0;
196 int result;
197 res = 0;
198 for (nodeid = 0; !res && (nodeid < fx_devs); nodeid++) {
199 device_t dev;
200 dev = __f0_dev[nodeid];
201 if (!dev)
202 continue;
203 for (link = 0; !res && (link < 8); link++) {
204 res = probe_resource(dev, IOINDEX(0x1000 + reg, link));
205 }
206 }
207 result = 2;
208 if (res) {
209 result = 0;
210 if ((goal_link == (link - 1)) &&
211 (goal_nodeid == (nodeid - 1)) &&
212 (res->flags <= 1)) {
213 result = 1;
214 }
215 }
216 return result;
217}
218
219static struct resource *amdfam16_find_iopair(device_t dev, unsigned nodeid, unsigned link)
220{
221 struct resource *resource;
222 u32 free_reg, reg;
223 resource = 0;
224 free_reg = 0;
225 for (reg = 0xc0; reg <= 0xd8; reg += 0x8) {
226 int result;
227 result = reg_useable(reg, dev, nodeid, link);
228 if (result == 1) {
229 /* I have been allocated this one */
230 break;
231 }
232 else if (result > 1) {
233 /* I have a free register pair */
234 free_reg = reg;
235 }
236 }
237 if (reg > 0xd8) {
238 reg = free_reg; // if no free, the free_reg still be 0
239 }
240
241 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
242
243 return resource;
244}
245
246static struct resource *amdfam16_find_mempair(device_t dev, u32 nodeid, u32 link)
247{
248 struct resource *resource;
249 u32 free_reg, reg;
250 resource = 0;
251 free_reg = 0;
252 for (reg = 0x80; reg <= 0xb8; reg += 0x8) {
253 int result;
254 result = reg_useable(reg, dev, nodeid, link);
255 if (result == 1) {
256 /* I have been allocated this one */
257 break;
258 }
259 else if (result > 1) {
260 /* I have a free register pair */
261 free_reg = reg;
262 }
263 }
264 if (reg > 0xb8) {
265 reg = free_reg;
266 }
267
268 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
269 return resource;
270}
271
272static void amdfam16_link_read_bases(device_t dev, u32 nodeid, u32 link)
273{
274 struct resource *resource;
275
276 /* Initialize the io space constraints on the current bus */
277 resource = amdfam16_find_iopair(dev, nodeid, link);
278 if (resource) {
279 u32 align;
280 align = log2(HT_IO_HOST_ALIGN);
281 resource->base = 0;
282 resource->size = 0;
283 resource->align = align;
284 resource->gran = align;
285 resource->limit = 0xffffUL;
286 resource->flags = IORESOURCE_IO | IORESOURCE_BRIDGE;
287 }
288
289 /* Initialize the prefetchable memory constraints on the current bus */
290 resource = amdfam16_find_mempair(dev, nodeid, link);
291 if (resource) {
292 resource->base = 0;
293 resource->size = 0;
294 resource->align = log2(HT_MEM_HOST_ALIGN);
295 resource->gran = log2(HT_MEM_HOST_ALIGN);
296 resource->limit = 0xffffffffffULL;
297 resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
298 resource->flags |= IORESOURCE_BRIDGE;
299 }
300
301 /* Initialize the 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_BRIDGE;
310 }
311
312}
313
314static void read_resources(device_t dev)
315{
316 u32 nodeid;
317 struct bus *link;
318
319 nodeid = amdfam16_nodeid(dev);
320 for (link = dev->link_list; link; link = link->next) {
321 if (link->children) {
322 amdfam16_link_read_bases(dev, nodeid, link->link_num);
323 }
324 }
Edward O'Callaghan66c65322014-11-21 01:43:38 +1100325
326 /*
327 * This MMCONF resource must be reserved in the PCI_DOMAIN.
328 * It is not honored by the coreboot resource allocator if it is in
329 * the APIC_CLUSTER.
330 */
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +0200331 mmconf_resource(dev, 0xc0010058);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800332}
333
334static void set_resource(device_t dev, struct resource *resource, u32 nodeid)
335{
336 resource_t rbase, rend;
337 unsigned reg, link_num;
338 char buf[50];
339
340 /* Make certain the resource has actually been set */
341 if (!(resource->flags & IORESOURCE_ASSIGNED)) {
342 return;
343 }
344
345 /* If I have already stored this resource don't worry about it */
346 if (resource->flags & IORESOURCE_STORED) {
347 return;
348 }
349
350 /* Only handle PCI memory and IO resources */
351 if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
352 return;
353
354 /* Ensure I am actually looking at a resource of function 1 */
355 if ((resource->index & 0xffff) < 0x1000) {
356 return;
357 }
358 /* Get the base address */
359 rbase = resource->base;
360
361 /* Get the limit (rounded up) */
362 rend = resource_end(resource);
363
364 /* Get the register and link */
365 reg = resource->index & 0xfff; // 4k
366 link_num = IOINDEX_LINK(resource->index);
367
368 if (resource->flags & IORESOURCE_IO) {
369 set_io_addr_reg(dev, nodeid, link_num, reg, rbase>>8, rend>>8);
370 }
371 else if (resource->flags & IORESOURCE_MEM) {
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100372 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 +0800373 }
374 resource->flags |= IORESOURCE_STORED;
Elyes HAOUAS0d4b11a2016-10-03 21:57:21 +0200375 snprintf(buf, sizeof(buf), " <node %x link %x>",
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800376 nodeid, link_num);
377 report_resource_stored(dev, resource, buf);
378}
379
380/**
381 * I tried to reuse the resource allocation code in set_resource()
382 * but it is too difficult to deal with the resource allocation magic.
383 */
384
385static void create_vga_resource(device_t dev, unsigned nodeid)
386{
387 struct bus *link;
388
389 /* find out which link the VGA card is connected,
390 * we only deal with the 'first' vga card */
391 for (link = dev->link_list; link; link = link->next) {
392 if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) {
Martin Roth77a58b92017-06-24 14:45:48 -0600393#if IS_ENABLED(CONFIG_MULTIPLE_VGA_ADAPTERS)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800394 extern device_t vga_pri; // the primary vga device, defined in device.c
395 printk(BIOS_DEBUG, "VGA: vga_pri bus num = %d bus range [%d,%d]\n", vga_pri->bus->secondary,
396 link->secondary,link->subordinate);
397 /* We need to make sure the vga_pri is under the link */
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200398 if ((vga_pri->bus->secondary >= link->secondary) &&
399 (vga_pri->bus->secondary <= link->subordinate))
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800400#endif
401 break;
402 }
403 }
404
405 /* no VGA card installed */
406 if (link == NULL)
407 return;
408
409 printk(BIOS_DEBUG, "VGA: %s (aka node %d) link %d has VGA device\n", dev_path(dev), nodeid, sblink);
410 set_vga_enable_reg(nodeid, sblink);
411}
412
413static void set_resources(device_t dev)
414{
415 unsigned nodeid;
416 struct bus *bus;
417 struct resource *res;
418
419 /* Find the nodeid */
420 nodeid = amdfam16_nodeid(dev);
421
422 create_vga_resource(dev, nodeid); //TODO: do we need this?
423
424 /* Set each resource we have found */
425 for (res = dev->resource_list; res; res = res->next) {
426 set_resource(dev, res, nodeid);
427 }
428
429 for (bus = dev->link_list; bus; bus = bus->next) {
430 if (bus->children) {
431 assign_resources(bus);
432 }
433 }
434}
435
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200436
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100437static unsigned long acpi_fill_hest(acpi_hest_t *hest)
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200438{
439 void *addr, *current;
440
441 /* Skip the HEST header. */
442 current = (void *)(hest + 1);
443
444 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
445 if (addr != NULL)
Stefan Reinauer77a1d1a2015-07-21 12:48:17 -0700446 current += acpi_create_hest_error_source(hest, current, 0,
447 addr + 2, *(UINT16 *)addr - 2);
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200448
449 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
450 if (addr != NULL)
Stefan Reinauer77a1d1a2015-07-21 12:48:17 -0700451 current += acpi_create_hest_error_source(hest, current, 1,
452 addr + 2, *(UINT16 *)addr - 2);
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200453
454 return (unsigned long)current;
455}
456
Alexander Couzens5eea4582015-04-12 22:18:55 +0200457static void northbridge_fill_ssdt_generator(device_t device)
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200458{
459 msr_t msr;
460 char pscope[] = "\\_SB.PCI0";
461
462 acpigen_write_scope(pscope);
463 msr = rdmsr(TOP_MEM);
464 acpigen_write_name_dword("TOM1", msr.lo);
465 msr = rdmsr(TOP_MEM2);
466 /*
467 * Since XP only implements parts of ACPI 2.0, we can't use a qword
468 * here.
469 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
470 * slide 22ff.
471 * Shift value right by 20 bit to make it fit into 32bit,
472 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
473 */
474 acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
475 acpigen_pop_len();
476}
477
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200478static unsigned long agesa_write_acpi_tables(device_t device,
479 unsigned long current,
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200480 acpi_rsdp_t *rsdp)
481{
482 acpi_srat_t *srat;
483 acpi_slit_t *slit;
484 acpi_header_t *ssdt;
485 acpi_header_t *alib;
486 acpi_header_t *ivrs;
487 acpi_hest_t *hest;
488
489 /* HEST */
490 current = ALIGN(current, 8);
491 hest = (acpi_hest_t *)current;
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100492 acpi_write_hest((void *)current, acpi_fill_hest);
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200493 acpi_add_table(rsdp, (void *)current);
494 current += ((acpi_header_t *)current)->length;
495
496 current = ALIGN(current, 8);
497 printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current);
498 ivrs = agesawrapper_getlateinitptr(PICK_IVRS);
499 if (ivrs != NULL) {
500 memcpy((void *)current, ivrs, ivrs->length);
501 ivrs = (acpi_header_t *) current;
502 current += ivrs->length;
503 acpi_add_table(rsdp, ivrs);
504 } else {
505 printk(BIOS_DEBUG, " AGESA IVRS table NULL. Skipping.\n");
506 }
507
508 /* SRAT */
509 current = ALIGN(current, 8);
510 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
511 srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
512 if (srat != NULL) {
513 memcpy((void *)current, srat, srat->header.length);
514 srat = (acpi_srat_t *) current;
515 current += srat->header.length;
516 acpi_add_table(rsdp, srat);
517 } else {
518 printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n");
519 }
520
521 /* SLIT */
522 current = ALIGN(current, 8);
523 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
524 slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
525 if (slit != NULL) {
526 memcpy((void *)current, slit, slit->header.length);
527 slit = (acpi_slit_t *) current;
528 current += slit->header.length;
529 acpi_add_table(rsdp, slit);
530 } else {
531 printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n");
532 }
533
534 /* ALIB */
535 current = ALIGN(current, 16);
536 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
537 alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB);
538 if (alib != NULL) {
539 memcpy((void *)current, alib, alib->length);
540 alib = (acpi_header_t *) current;
541 current += alib->length;
542 acpi_add_table(rsdp, (void *)alib);
543 }
544 else {
545 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n");
546 }
547
548 /* this pstate ssdt may cause Blue Screen: Fixed: Keep this comment for a while. */
549 /* SSDT */
550 current = ALIGN(current, 16);
551 printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current);
552 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
553 if (ssdt != NULL) {
554 memcpy((void *)current, ssdt, ssdt->length);
555 ssdt = (acpi_header_t *) current;
556 current += ssdt->length;
557 }
558 else {
559 printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n");
560 }
561 acpi_add_table(rsdp,ssdt);
562
563 printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current);
564
565 return current;
566}
567
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800568static struct device_operations northbridge_operations = {
569 .read_resources = read_resources,
570 .set_resources = set_resources,
571 .enable_resources = pci_dev_enable_resources,
Edward O'Callaghand994ef12014-11-21 02:22:33 +1100572 .init = DEVICE_NOOP,
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200573 .acpi_fill_ssdt_generator = northbridge_fill_ssdt_generator,
574 .write_acpi_tables = agesa_write_acpi_tables,
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800575 .enable = 0,
576 .ops_pci = 0,
577};
578
579static const struct pci_driver family16_northbridge __pci_driver = {
580 .ops = &northbridge_operations,
581 .vendor = PCI_VENDOR_ID_AMD,
582 .device = PCI_DEVICE_ID_AMD_16H_MODEL_000F_NB_HT,
583};
584
585static const struct pci_driver family10_northbridge __pci_driver = {
586 .ops = &northbridge_operations,
587 .vendor = PCI_VENDOR_ID_AMD,
588 .device = PCI_DEVICE_ID_AMD_10H_NB_HT,
589};
590
Kyösti Mälkki4ee82c62014-11-25 16:03:12 +0200591static void fam16_finalize(void *chip_info)
592{
593 device_t dev;
594 u32 value;
595 dev = dev_find_slot(0, PCI_DEVFN(0, 0)); /* clear IoapicSbFeatureEn */
596 pci_write_config32(dev, 0xF8, 0);
597 pci_write_config32(dev, 0xFC, 5); /* TODO: move it to dsdt.asl */
598
599 /* disable No Snoop */
600 dev = dev_find_slot(0, PCI_DEVFN(1, 1));
601 value = pci_read_config32(dev, 0x60);
602 value &= ~(1 << 11);
603 pci_write_config32(dev, 0x60, value);
604}
605
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800606struct chip_operations northbridge_amd_agesa_family16kb_ops = {
607 CHIP_NAME("AMD FAM16 Northbridge")
608 .enable_dev = 0,
Kyösti Mälkki4ee82c62014-11-25 16:03:12 +0200609 .final = fam16_finalize,
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800610};
611
612static void domain_read_resources(device_t dev)
613{
614 unsigned reg;
615
616 /* Find the already assigned resource pairs */
617 get_fx_devs();
618 for (reg = 0x80; reg <= 0xd8; reg+= 0x08) {
619 u32 base, limit;
620 base = f1_read_config32(reg);
621 limit = f1_read_config32(reg + 0x04);
622 /* Is this register allocated? */
623 if ((base & 3) != 0) {
624 unsigned nodeid, reg_link;
625 device_t reg_dev;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200626 if (reg < 0xc0) { // mmio
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800627 nodeid = (limit & 0xf) + (base&0x30);
628 } else { // io
629 nodeid = (limit & 0xf) + ((base>>4)&0x30);
630 }
631 reg_link = (limit >> 4) & 7;
632 reg_dev = __f0_dev[nodeid];
633 if (reg_dev) {
634 /* Reserve the resource */
635 struct resource *res;
636 res = new_resource(reg_dev, IOINDEX(0x1000 + reg, reg_link));
637 if (res) {
638 res->flags = 1;
639 }
640 }
641 }
642 }
643 /* FIXME: do we need to check extend conf space?
644 I don't believe that much preset value */
645
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800646 pci_domain_read_resources(dev);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800647}
648
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800649static void domain_enable_resources(device_t dev)
650{
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +0200651#if IS_ENABLED(CONFIG_AGESA_LEGACY_WRAPPER)
Kyösti Mälkki8ae16a42014-06-19 20:44:34 +0300652 if (acpi_is_wakeup_s3())
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300653 agesawrapper_fchs3laterestore();
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800654
655 /* Must be called after PCI enumeration and resource allocation */
Kyösti Mälkkib139b5e2014-10-20 07:41:20 +0300656 if (!acpi_is_wakeup_s3()) {
657 /* Enable MMIO on AMD CPU Address Map Controller */
Kyösti Mälkki48518f02014-11-25 14:20:57 +0200658 amd_initcpuio();
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800659
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300660 agesawrapper_amdinitmid();
Kyösti Mälkkib139b5e2014-10-20 07:41:20 +0300661 }
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800662 printk(BIOS_DEBUG, " ader - leaving domain_enable_resources.\n");
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +0200663#endif
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800664}
665
666#if CONFIG_HW_MEM_HOLE_SIZEK != 0
667struct hw_mem_hole_info {
668 unsigned hole_startk;
669 int node_id;
670};
671static struct hw_mem_hole_info get_hw_mem_hole_info(void)
672{
673 struct hw_mem_hole_info mem_hole;
674 int i;
675 mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK;
676 mem_hole.node_id = -1;
677 for (i = 0; i < node_nums; i++) {
678 dram_base_mask_t d;
679 u32 hole;
680 d = get_dram_base_mask(i);
681 if (!(d.mask & 1)) continue; // no memory on this node
682 hole = pci_read_config32(__f1_dev[i], 0xf0);
683 if (hole & 2) { // we find the hole
Elyes HAOUAS27e18012017-06-27 23:14:51 +0200684 mem_hole.hole_startk = (hole & (0xff << 24)) >> 10;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800685 mem_hole.node_id = i; // record the node No with hole
686 break; // only one hole
687 }
688 }
Kyösti Mälkki2f9b3af2014-06-26 05:30:54 +0300689
690 /* We need to double check if there is special set on base reg and limit reg
691 * are not continuous instead of hole, it will find out its hole_startk.
692 */
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800693 if (mem_hole.node_id == -1) {
694 resource_t limitk_pri = 0;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200695 for (i = 0; i < node_nums; i++) {
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800696 dram_base_mask_t d;
697 resource_t base_k, limit_k;
698 d = get_dram_base_mask(i);
699 if (!(d.base & 1)) continue;
700 base_k = ((resource_t)(d.base & 0x1fffff00)) <<9;
701 if (base_k > 4 *1024 * 1024) break; // don't need to go to check
702 if (limitk_pri != base_k) { // we find the hole
703 mem_hole.hole_startk = (unsigned)limitk_pri; // must beblow 4G
704 mem_hole.node_id = i;
705 break; //only one hole
706 }
707 limit_k = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
708 limitk_pri = limit_k;
709 }
710 }
711 return mem_hole;
712}
713#endif
714
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800715static void domain_set_resources(device_t dev)
716{
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800717 unsigned long mmio_basek;
718 u32 pci_tolm;
719 int i, idx;
720 struct bus *link;
721#if CONFIG_HW_MEM_HOLE_SIZEK != 0
722 struct hw_mem_hole_info mem_hole;
723 u32 reset_memhole = 1;
724#endif
725
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800726 pci_tolm = 0xffffffffUL;
727 for (link = dev->link_list; link; link = link->next) {
728 pci_tolm = find_pci_tolm(link);
729 }
730
731 // FIXME handle interleaved nodes. If you fix this here, please fix
732 // amdk8, too.
733 mmio_basek = pci_tolm >> 10;
734 /* Round mmio_basek to something the processor can support */
735 mmio_basek &= ~((1 << 6) -1);
736
737 // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M
738 // MMIO hole. If you fix this here, please fix amdk8, too.
739 /* Round the mmio hole to 64M */
740 mmio_basek &= ~((64*1024) - 1);
741
742#if CONFIG_HW_MEM_HOLE_SIZEK != 0
743 /* if the hw mem hole is already set in raminit stage, here we will compare
744 * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will
745 * use hole_basek as mmio_basek and we don't need to reset hole.
746 * otherwise We reset the hole to the mmio_basek
747 */
748
749 mem_hole = get_hw_mem_hole_info();
750
751 // Use hole_basek as mmio_basek, and we don't need to reset hole anymore
752 if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) {
753 mmio_basek = mem_hole.hole_startk;
754 reset_memhole = 0;
755 }
756#endif
757
758 idx = 0x10;
759 for (i = 0; i < node_nums; i++) {
760 dram_base_mask_t d;
761 resource_t basek, limitk, sizek; // 4 1T
762
763 d = get_dram_base_mask(i);
764
765 if (!(d.mask & 1)) continue;
766 basek = ((resource_t)(d.base & 0x1fffff00)) << 9; // could overflow, we may lost 6 bit here
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100767 limitk = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800768
769 sizek = limitk - basek;
770
771 /* see if we need a hole from 0xa0000 to 0xbffff */
772 if ((basek < ((8*64)+(8*16))) && (sizek > ((8*64)+(16*16)))) {
773 ram_resource(dev, (idx | i), basek, ((8*64)+(8*16)) - basek);
774 idx += 0x10;
775 basek = (8*64)+(16*16);
776 sizek = limitk - ((8*64)+(16*16));
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800777 }
778
779 //printk(BIOS_DEBUG, "node %d : mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", i, mmio_basek, basek, limitk);
780
Kyösti Mälkki26c65432014-06-26 05:30:54 +0300781 /* split the region to accommodate pci memory space */
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200782 if ((basek < 4*1024*1024) && (limitk > mmio_basek)) {
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800783 if (basek <= mmio_basek) {
784 unsigned pre_sizek;
785 pre_sizek = mmio_basek - basek;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200786 if (pre_sizek > 0) {
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800787 ram_resource(dev, (idx | i), basek, pre_sizek);
788 idx += 0x10;
789 sizek -= pre_sizek;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800790 }
791 basek = mmio_basek;
792 }
793 if ((basek + sizek) <= 4*1024*1024) {
794 sizek = 0;
795 }
796 else {
797 uint64_t topmem2 = bsp_topmem2();
798 basek = 4*1024*1024;
799 sizek = topmem2/1024 - basek;
800 }
801 }
802
803 ram_resource(dev, (idx | i), basek, sizek);
804 idx += 0x10;
805 printk(BIOS_DEBUG, "node %d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n",
806 i, mmio_basek, basek, limitk);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800807 }
808
Kyösti Mälkki61be3602017-04-15 20:07:53 +0300809 add_uma_resource_below_tolm(dev, 7);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800810
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200811 for (link = dev->link_list; link; link = link->next) {
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800812 if (link->children) {
813 assign_resources(link);
814 }
815 }
816}
817
818static struct device_operations pci_domain_ops = {
819 .read_resources = domain_read_resources,
820 .set_resources = domain_set_resources,
821 .enable_resources = domain_enable_resources,
Edward O'Callaghane9e1d7a2015-01-02 15:11:49 +1100822 .init = DEVICE_NOOP,
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800823 .scan_bus = pci_domain_scan_bus,
824 .ops_pci_bus = pci_bus_default_ops,
825};
826
827static void sysconf_init(device_t dev) // first node
828{
829 sblink = (pci_read_config32(dev, 0x64)>>8) & 7; // don't forget sublink1
830 node_nums = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; //NodeCnt[2:0]
831}
832
833static void add_more_links(device_t dev, unsigned total_links)
834{
835 struct bus *link, *last = NULL;
836 int link_num;
837
838 for (link = dev->link_list; link; link = link->next)
839 last = link;
840
841 if (last) {
842 int links = total_links - last->link_num;
843 link_num = last->link_num;
844 if (links > 0) {
845 link = malloc(links*sizeof(*link));
846 if (!link)
847 die("Couldn't allocate more links!\n");
848 memset(link, 0, links*sizeof(*link));
849 last->next = link;
850 }
851 }
852 else {
853 link_num = -1;
854 link = malloc(total_links*sizeof(*link));
855 memset(link, 0, total_links*sizeof(*link));
856 dev->link_list = link;
857 }
858
859 for (link_num = link_num + 1; link_num < total_links; link_num++) {
860 link->link_num = link_num;
861 link->dev = dev;
862 link->next = link + 1;
863 last = link;
864 link = link->next;
865 }
866 last->next = NULL;
867}
868
Kyösti Mälkki580e7222015-03-19 21:04:23 +0200869static void cpu_bus_scan(device_t dev)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800870{
871 struct bus *cpu_bus;
872 device_t dev_mc;
873#if CONFIG_CBB
874 device_t pci_domain;
875#endif
876 int i,j;
877 int coreid_bits;
878 int core_max = 0;
879 unsigned ApicIdCoreIdSize;
880 unsigned core_nums;
881 int siblings = 0;
882 unsigned int family;
883
884#if CONFIG_CBB
885 dev_mc = dev_find_slot(0, PCI_DEVFN(CONFIG_CDB, 0)); //0x00
886 if (dev_mc && dev_mc->bus) {
887 printk(BIOS_DEBUG, "%s found", dev_path(dev_mc));
888 pci_domain = dev_mc->bus->dev;
889 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
890 printk(BIOS_DEBUG, "\n%s move to ",dev_path(dev_mc));
891 dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
892 printk(BIOS_DEBUG, "%s",dev_path(dev_mc));
893 } else {
894 printk(BIOS_DEBUG, " but it is not under pci_domain directly ");
895 }
896 printk(BIOS_DEBUG, "\n");
897 }
898 dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
899 if (!dev_mc) {
900 dev_mc = dev_find_slot(0, PCI_DEVFN(0x18, 0));
901 if (dev_mc && dev_mc->bus) {
902 printk(BIOS_DEBUG, "%s found\n", dev_path(dev_mc));
903 pci_domain = dev_mc->bus->dev;
904 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
905 if ((pci_domain->link_list) && (pci_domain->link_list->children == dev_mc)) {
906 printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
907 dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
908 printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
909 while (dev_mc) {
910 printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
911 dev_mc->path.pci.devfn -= PCI_DEVFN(0x18,0);
912 printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
913 dev_mc = dev_mc->sibling;
914 }
915 }
916 }
917 }
918 }
919#endif
920 dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
921 if (!dev_mc) {
922 printk(BIOS_ERR, "%02x:%02x.0 not found", CONFIG_CBB, CONFIG_CDB);
923 die("");
924 }
925 sysconf_init(dev_mc);
926#if CONFIG_CBB && (MAX_NODE_NUMS > 32)
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200927 if (node_nums > 32) { // need to put node 32 to node 63 to bus 0xfe
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800928 if (pci_domain->link_list && !pci_domain->link_list->next) {
929 struct bus *new_link = new_link(pci_domain);
930 pci_domain->link_list->next = new_link;
931 new_link->link_num = 1;
932 new_link->dev = pci_domain;
933 new_link->children = 0;
934 printk(BIOS_DEBUG, "%s links now 2\n", dev_path(pci_domain));
935 }
936 pci_domain->link_list->next->secondary = CONFIG_CBB - 1;
937 }
938#endif
939
940 /* Get Max Number of cores(MNC) */
941 coreid_bits = (cpuid_ecx(AMD_CPUID_ASIZE_PCCOUNT) & 0x0000F000) >> 12;
942 core_max = 1 << (coreid_bits & 0x000F); //mnc
943
944 ApicIdCoreIdSize = ((cpuid_ecx(0x80000008)>>12) & 0xF);
945 if (ApicIdCoreIdSize) {
946 core_nums = (1 << ApicIdCoreIdSize) - 1;
947 } else {
948 core_nums = 3; //quad core
949 }
950
951 /* Find which cpus are present */
952 cpu_bus = dev->link_list;
953 for (i = 0; i < node_nums; i++) {
954 device_t cdb_dev;
955 unsigned busn, devn;
956 struct bus *pbus;
957
958 busn = CONFIG_CBB;
959 devn = CONFIG_CDB + i;
960 pbus = dev_mc->bus;
961#if CONFIG_CBB && (MAX_NODE_NUMS > 32)
962 if (i >= 32) {
963 busn--;
964 devn -= 32;
965 pbus = pci_domain->link_list->next;
966 }
967#endif
968
969 /* Find the cpu's pci device */
970 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0));
971 if (!cdb_dev) {
972 /* If I am probing things in a weird order
973 * ensure all of the cpu's pci devices are found.
974 */
975 int fn;
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200976 for (fn = 0; fn <= 5; fn++) { //FBDIMM?
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800977 cdb_dev = pci_probe_dev(NULL, pbus,
978 PCI_DEVFN(devn, fn));
979 }
980 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0));
981 } else {
982 /* Ok, We need to set the links for that device.
983 * otherwise the device under it will not be scanned
984 */
Kyösti Mälkki2a2d6132015-02-04 13:25:37 +0200985 add_more_links(cdb_dev, 4);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800986 }
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 == 7) {//f16
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 }
1004 int enable_node = cdb_dev && cdb_dev->enabled;
1005 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
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +02001008 for (j = 0; j <= siblings; j++) {
Siyuan Wang3e32cc02013-07-09 17:16:20 +08001009 extern CONST OPTIONS_CONFIG_TOPOLOGY ROMDATA TopologyConfiguration;
1010 u32 modules = TopologyConfiguration.PlatformNumberOfModules;
1011 u32 lapicid_start = 0;
1012
1013 /*
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
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +02001025 */
Kyösti Mälkki50036322016-05-18 13:35:21 +03001026
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +02001027 u8 plat_num_io_apics = 3; /* FIXME */
Kyösti Mälkki50036322016-05-18 13:35:21 +03001028
1029 if ((node_nums * core_max) + plat_num_io_apics >= 0x10) {
1030 lapicid_start = (plat_num_io_apics - 1) / core_max;
Siyuan Wang3e32cc02013-07-09 17:16:20 +08001031 lapicid_start = (lapicid_start + 1) * core_max;
1032 printk(BIOS_SPEW, "lpaicid_start=0x%x ", lapicid_start);
1033 }
1034 u32 apic_id = (lapicid_start * (i/modules + 1)) + ((i % modules) ? (j + (siblings + 1)) : j);
1035 printk(BIOS_SPEW, "node 0x%x core 0x%x apicid=0x%x\n",
1036 i, j, apic_id);
1037
1038 device_t cpu = add_cpu_device(cpu_bus, apic_id, enable_node);
1039 if (cpu)
1040 amd_cpu_topology(cpu, i, j);
1041 } //j
1042 }
Siyuan Wang3e32cc02013-07-09 17:16:20 +08001043}
1044
1045static void cpu_bus_init(device_t dev)
1046{
1047 initialize_cpus(dev->link_list);
1048}
1049
Siyuan Wang3e32cc02013-07-09 17:16:20 +08001050static struct device_operations cpu_bus_ops = {
Edward O'Callaghan66c65322014-11-21 01:43:38 +11001051 .read_resources = DEVICE_NOOP,
1052 .set_resources = DEVICE_NOOP,
Edward O'Callaghan812d2a42014-10-31 08:17:23 +11001053 .enable_resources = DEVICE_NOOP,
Siyuan Wang3e32cc02013-07-09 17:16:20 +08001054 .init = cpu_bus_init,
1055 .scan_bus = cpu_bus_scan,
1056};
1057
1058static void root_complex_enable_dev(struct device *dev)
1059{
1060 static int done = 0;
1061
Siyuan Wang3e32cc02013-07-09 17:16:20 +08001062 if (!done) {
1063 setup_bsp_ramtop();
Siyuan Wang3e32cc02013-07-09 17:16:20 +08001064 done = 1;
1065 }
1066
1067 /* Set the operations if it is a special bus type */
1068 if (dev->path.type == DEVICE_PATH_DOMAIN) {
1069 dev->ops = &pci_domain_ops;
1070 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
1071 dev->ops = &cpu_bus_ops;
1072 }
1073}
1074
1075struct chip_operations northbridge_amd_agesa_family16kb_root_complex_ops = {
1076 CHIP_NAME("AMD FAM16 Root Complex")
1077 .enable_dev = root_complex_enable_dev,
1078};
Bruce Griffith76db07e2013-07-07 02:06:53 -06001079
1080/*********************************************************************
1081 * Change the vendor / device IDs to match the generic VBIOS header. *
1082 *********************************************************************/
1083u32 map_oprom_vendev(u32 vendev)
1084{
1085 u32 new_vendev = vendev;
1086
1087 switch(vendev) {
1088 case 0x10029830:
1089 case 0x10029831:
1090 case 0x10029832:
1091 case 0x10029833:
1092 case 0x10029834:
1093 case 0x10029835:
1094 case 0x10029836:
1095 case 0x10029837:
1096 case 0x10029838:
1097 case 0x10029839:
1098 case 0x1002983A:
1099 case 0x1002983D:
1100 new_vendev = 0x10029830; // This is the default value in AMD-generated VBIOS
1101 break;
1102 default:
1103 break;
1104 }
1105
1106 if (vendev != new_vendev)
1107 printk(BIOS_NOTICE, "Mapping PCI device %8x to %8x\n", vendev, new_vendev);
1108
1109 return new_vendev;
1110}