blob: 557c9c4bbdf33c4603152ed6a819cd42fb163272 [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>
Kyösti Mälkkid610c582017-03-05 06:28:18 +020038
Kyösti Mälkkif21c2ac2014-10-19 09:35:18 +030039#include <northbridge/amd/agesa/agesawrapper.h>
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +020040#include <northbridge/amd/agesa/state_machine.h>
Kyösti Mälkkid610c582017-03-05 06:28:18 +020041#include <northbridge/amd/agesa/agesa_helper.h>
Siyuan Wang3e32cc02013-07-09 17:16:20 +080042
43#define MAX_NODE_NUMS (MAX_NODES * MAX_DIES)
44
Siyuan Wang3e32cc02013-07-09 17:16:20 +080045typedef struct dram_base_mask {
46 u32 base; //[47:27] at [28:8]
47 u32 mask; //[47:27] at [28:8] and enable at bit 0
48} dram_base_mask_t;
49
50static unsigned node_nums;
51static unsigned sblink;
52static device_t __f0_dev[MAX_NODE_NUMS];
53static device_t __f1_dev[MAX_NODE_NUMS];
54static device_t __f2_dev[MAX_NODE_NUMS];
55static device_t __f4_dev[MAX_NODE_NUMS];
56static unsigned fx_devs = 0;
57
58static dram_base_mask_t get_dram_base_mask(u32 nodeid)
59{
60 device_t dev;
61 dram_base_mask_t d;
62 dev = __f1_dev[0];
63 u32 temp;
64 temp = pci_read_config32(dev, 0x44 + (nodeid << 3)); //[39:24] at [31:16]
65 d.mask = ((temp & 0xfff80000)>>(8+3)); // mask out DramMask [26:24] too
66 temp = pci_read_config32(dev, 0x144 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
Elyes HAOUAS27e18012017-06-27 23:14:51 +020067 d.mask |= temp << 21;
Siyuan Wang3e32cc02013-07-09 17:16:20 +080068 temp = pci_read_config32(dev, 0x40 + (nodeid << 3)); //[39:24] at [31:16]
69 d.mask |= (temp & 1); // enable bit
70 d.base = ((temp & 0xfff80000)>>(8+3)); // mask out DramBase [26:24) too
71 temp = pci_read_config32(dev, 0x140 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
Elyes HAOUAS27e18012017-06-27 23:14:51 +020072 d.base |= temp << 21;
Siyuan Wang3e32cc02013-07-09 17:16:20 +080073 return d;
74}
75
76static void set_io_addr_reg(device_t dev, u32 nodeid, u32 linkn, u32 reg,
77 u32 io_min, u32 io_max)
78{
79 u32 i;
80 u32 tempreg;
81 /* io range allocation */
Elyes HAOUAS27e18012017-06-27 23:14:51 +020082 tempreg = (nodeid&0xf) | ((nodeid & 0x30)<<(8-4)) | (linkn << 4) | ((io_max&0xf0)<<(12-4)); //limit
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020083 for (i = 0; i < node_nums; i++)
Siyuan Wang3e32cc02013-07-09 17:16:20 +080084 pci_write_config32(__f1_dev[i], reg+4, tempreg);
Elyes HAOUAS27e18012017-06-27 23:14:51 +020085 tempreg = 3 /*| (3 << 4)*/ | ((io_min&0xf0)<<(12-4)); //base :ISA and VGA ?
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020086 for (i = 0; i < node_nums; i++)
Siyuan Wang3e32cc02013-07-09 17:16:20 +080087 pci_write_config32(__f1_dev[i], reg, tempreg);
88}
89
90static void set_mmio_addr_reg(u32 nodeid, u32 linkn, u32 reg, u32 index, u32 mmio_min, u32 mmio_max, u32 nodes)
91{
92 u32 i;
93 u32 tempreg;
94 /* io range allocation */
Elyes HAOUAS27e18012017-06-27 23:14:51 +020095 tempreg = (nodeid&0xf) | (linkn << 4) | (mmio_max&0xffffff00); //limit
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020096 for (i = 0; i < nodes; i++)
Siyuan Wang3e32cc02013-07-09 17:16:20 +080097 pci_write_config32(__f1_dev[i], reg+4, tempreg);
98 tempreg = 3 | (nodeid & 0x30) | (mmio_min&0xffffff00);
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020099 for (i = 0; i < node_nums; i++)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800100 pci_write_config32(__f1_dev[i], reg, tempreg);
101}
102
103static device_t get_node_pci(u32 nodeid, u32 fn)
104{
105#if MAX_NODE_NUMS + CONFIG_CDB >= 32
106 if ((CONFIG_CDB + nodeid) < 32) {
107 return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn));
108 } else {
109 return dev_find_slot(CONFIG_CBB-1, PCI_DEVFN(CONFIG_CDB + nodeid - 32, fn));
110 }
111#else
112 return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn));
113#endif
114}
115
116static void get_fx_devs(void)
117{
118 int i;
119 for (i = 0; i < MAX_NODE_NUMS; i++) {
120 __f0_dev[i] = get_node_pci(i, 0);
121 __f1_dev[i] = get_node_pci(i, 1);
122 __f2_dev[i] = get_node_pci(i, 2);
123 __f4_dev[i] = get_node_pci(i, 4);
124 if (__f0_dev[i] != NULL && __f1_dev[i] != NULL)
125 fx_devs = i+1;
126 }
127 if (__f1_dev[0] == NULL || __f0_dev[0] == NULL || fx_devs == 0) {
128 die("Cannot find 0:0x18.[0|1]\n");
129 }
130 printk(BIOS_DEBUG, "fx_devs=0x%x\n", fx_devs);
131}
132
133static u32 f1_read_config32(unsigned reg)
134{
135 if (fx_devs == 0)
136 get_fx_devs();
137 return pci_read_config32(__f1_dev[0], reg);
138}
139
140static void f1_write_config32(unsigned reg, u32 value)
141{
142 int i;
143 if (fx_devs == 0)
144 get_fx_devs();
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200145 for (i = 0; i < fx_devs; i++) {
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800146 device_t dev;
147 dev = __f1_dev[i];
148 if (dev && dev->enabled) {
149 pci_write_config32(dev, reg, value);
150 }
151 }
152}
153
154static u32 amdfam16_nodeid(device_t dev)
155{
156#if MAX_NODE_NUMS == 64
157 unsigned busn;
158 busn = dev->bus->secondary;
159 if (busn != CONFIG_CBB) {
160 return (dev->path.pci.devfn >> 3) - CONFIG_CDB + 32;
161 } else {
162 return (dev->path.pci.devfn >> 3) - CONFIG_CDB;
163 }
164
165#else
166 return (dev->path.pci.devfn >> 3) - CONFIG_CDB;
167#endif
168}
169
170static void set_vga_enable_reg(u32 nodeid, u32 linkn)
171{
172 u32 val;
173
Elyes HAOUAS27e18012017-06-27 23:14:51 +0200174 val = 1 | (nodeid << 4) | (linkn << 12);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800175 /* it will routing
176 * (1)mmio 0xa0000:0xbffff
177 * (2)io 0x3b0:0x3bb, 0x3c0:0x3df
178 */
179 f1_write_config32(0xf4, val);
180
181}
182
183/**
184 * @return
185 * @retval 2 resoure does not exist, usable
186 * @retval 0 resource exists, not usable
187 * @retval 1 resource exist, resource has been allocated before
188 */
189static int reg_useable(unsigned reg, device_t goal_dev, unsigned goal_nodeid,
190 unsigned goal_link)
191{
192 struct resource *res;
193 unsigned nodeid, link = 0;
194 int result;
195 res = 0;
196 for (nodeid = 0; !res && (nodeid < fx_devs); nodeid++) {
197 device_t dev;
198 dev = __f0_dev[nodeid];
199 if (!dev)
200 continue;
201 for (link = 0; !res && (link < 8); link++) {
202 res = probe_resource(dev, IOINDEX(0x1000 + reg, link));
203 }
204 }
205 result = 2;
206 if (res) {
207 result = 0;
208 if ((goal_link == (link - 1)) &&
209 (goal_nodeid == (nodeid - 1)) &&
210 (res->flags <= 1)) {
211 result = 1;
212 }
213 }
214 return result;
215}
216
217static struct resource *amdfam16_find_iopair(device_t dev, unsigned nodeid, unsigned link)
218{
219 struct resource *resource;
220 u32 free_reg, reg;
221 resource = 0;
222 free_reg = 0;
223 for (reg = 0xc0; reg <= 0xd8; reg += 0x8) {
224 int result;
225 result = reg_useable(reg, dev, nodeid, link);
226 if (result == 1) {
227 /* I have been allocated this one */
228 break;
229 }
230 else if (result > 1) {
231 /* I have a free register pair */
232 free_reg = reg;
233 }
234 }
235 if (reg > 0xd8) {
236 reg = free_reg; // if no free, the free_reg still be 0
237 }
238
239 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
240
241 return resource;
242}
243
244static struct resource *amdfam16_find_mempair(device_t dev, u32 nodeid, u32 link)
245{
246 struct resource *resource;
247 u32 free_reg, reg;
248 resource = 0;
249 free_reg = 0;
250 for (reg = 0x80; reg <= 0xb8; reg += 0x8) {
251 int result;
252 result = reg_useable(reg, dev, nodeid, link);
253 if (result == 1) {
254 /* I have been allocated this one */
255 break;
256 }
257 else if (result > 1) {
258 /* I have a free register pair */
259 free_reg = reg;
260 }
261 }
262 if (reg > 0xb8) {
263 reg = free_reg;
264 }
265
266 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
267 return resource;
268}
269
270static void amdfam16_link_read_bases(device_t dev, u32 nodeid, u32 link)
271{
272 struct resource *resource;
273
274 /* Initialize the io space constraints on the current bus */
275 resource = amdfam16_find_iopair(dev, nodeid, link);
276 if (resource) {
277 u32 align;
278 align = log2(HT_IO_HOST_ALIGN);
279 resource->base = 0;
280 resource->size = 0;
281 resource->align = align;
282 resource->gran = align;
283 resource->limit = 0xffffUL;
284 resource->flags = IORESOURCE_IO | IORESOURCE_BRIDGE;
285 }
286
287 /* Initialize the prefetchable memory constraints on the current bus */
288 resource = amdfam16_find_mempair(dev, nodeid, link);
289 if (resource) {
290 resource->base = 0;
291 resource->size = 0;
292 resource->align = log2(HT_MEM_HOST_ALIGN);
293 resource->gran = log2(HT_MEM_HOST_ALIGN);
294 resource->limit = 0xffffffffffULL;
295 resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
296 resource->flags |= IORESOURCE_BRIDGE;
297 }
298
299 /* Initialize the memory constraints on the current bus */
300 resource = amdfam16_find_mempair(dev, nodeid, link);
301 if (resource) {
302 resource->base = 0;
303 resource->size = 0;
304 resource->align = log2(HT_MEM_HOST_ALIGN);
305 resource->gran = log2(HT_MEM_HOST_ALIGN);
306 resource->limit = 0xffffffffffULL;
307 resource->flags = IORESOURCE_MEM | IORESOURCE_BRIDGE;
308 }
309
310}
311
312static void read_resources(device_t dev)
313{
314 u32 nodeid;
315 struct bus *link;
316
317 nodeid = amdfam16_nodeid(dev);
318 for (link = dev->link_list; link; link = link->next) {
319 if (link->children) {
320 amdfam16_link_read_bases(dev, nodeid, link->link_num);
321 }
322 }
Edward O'Callaghan66c65322014-11-21 01:43:38 +1100323
324 /*
325 * This MMCONF resource must be reserved in the PCI_DOMAIN.
326 * It is not honored by the coreboot resource allocator if it is in
327 * the APIC_CLUSTER.
328 */
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +0200329 mmconf_resource(dev, 0xc0010058);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800330}
331
332static void set_resource(device_t dev, struct resource *resource, u32 nodeid)
333{
334 resource_t rbase, rend;
335 unsigned reg, link_num;
336 char buf[50];
337
338 /* Make certain the resource has actually been set */
339 if (!(resource->flags & IORESOURCE_ASSIGNED)) {
340 return;
341 }
342
343 /* If I have already stored this resource don't worry about it */
344 if (resource->flags & IORESOURCE_STORED) {
345 return;
346 }
347
348 /* Only handle PCI memory and IO resources */
349 if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
350 return;
351
352 /* Ensure I am actually looking at a resource of function 1 */
353 if ((resource->index & 0xffff) < 0x1000) {
354 return;
355 }
356 /* Get the base address */
357 rbase = resource->base;
358
359 /* Get the limit (rounded up) */
360 rend = resource_end(resource);
361
362 /* Get the register and link */
363 reg = resource->index & 0xfff; // 4k
364 link_num = IOINDEX_LINK(resource->index);
365
366 if (resource->flags & IORESOURCE_IO) {
367 set_io_addr_reg(dev, nodeid, link_num, reg, rbase>>8, rend>>8);
368 }
369 else if (resource->flags & IORESOURCE_MEM) {
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100370 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 +0800371 }
372 resource->flags |= IORESOURCE_STORED;
Elyes HAOUAS0d4b11a2016-10-03 21:57:21 +0200373 snprintf(buf, sizeof(buf), " <node %x link %x>",
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800374 nodeid, link_num);
375 report_resource_stored(dev, resource, buf);
376}
377
378/**
379 * I tried to reuse the resource allocation code in set_resource()
380 * but it is too difficult to deal with the resource allocation magic.
381 */
382
383static void create_vga_resource(device_t dev, unsigned nodeid)
384{
385 struct bus *link;
386
387 /* find out which link the VGA card is connected,
388 * we only deal with the 'first' vga card */
389 for (link = dev->link_list; link; link = link->next) {
390 if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) {
Martin Roth77a58b92017-06-24 14:45:48 -0600391#if IS_ENABLED(CONFIG_MULTIPLE_VGA_ADAPTERS)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800392 extern device_t vga_pri; // the primary vga device, defined in device.c
393 printk(BIOS_DEBUG, "VGA: vga_pri bus num = %d bus range [%d,%d]\n", vga_pri->bus->secondary,
394 link->secondary,link->subordinate);
395 /* We need to make sure the vga_pri is under the link */
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200396 if ((vga_pri->bus->secondary >= link->secondary) &&
397 (vga_pri->bus->secondary <= link->subordinate))
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800398#endif
399 break;
400 }
401 }
402
403 /* no VGA card installed */
404 if (link == NULL)
405 return;
406
407 printk(BIOS_DEBUG, "VGA: %s (aka node %d) link %d has VGA device\n", dev_path(dev), nodeid, sblink);
408 set_vga_enable_reg(nodeid, sblink);
409}
410
411static void set_resources(device_t dev)
412{
413 unsigned nodeid;
414 struct bus *bus;
415 struct resource *res;
416
417 /* Find the nodeid */
418 nodeid = amdfam16_nodeid(dev);
419
420 create_vga_resource(dev, nodeid); //TODO: do we need this?
421
422 /* Set each resource we have found */
423 for (res = dev->resource_list; res; res = res->next) {
424 set_resource(dev, res, nodeid);
425 }
426
427 for (bus = dev->link_list; bus; bus = bus->next) {
428 if (bus->children) {
429 assign_resources(bus);
430 }
431 }
432}
433
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200434
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100435static unsigned long acpi_fill_hest(acpi_hest_t *hest)
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200436{
437 void *addr, *current;
438
439 /* Skip the HEST header. */
440 current = (void *)(hest + 1);
441
442 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
443 if (addr != NULL)
Stefan Reinauer77a1d1a2015-07-21 12:48:17 -0700444 current += acpi_create_hest_error_source(hest, current, 0,
445 addr + 2, *(UINT16 *)addr - 2);
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200446
447 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
448 if (addr != NULL)
Stefan Reinauer77a1d1a2015-07-21 12:48:17 -0700449 current += acpi_create_hest_error_source(hest, current, 1,
450 addr + 2, *(UINT16 *)addr - 2);
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200451
452 return (unsigned long)current;
453}
454
Alexander Couzens5eea4582015-04-12 22:18:55 +0200455static void northbridge_fill_ssdt_generator(device_t device)
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200456{
457 msr_t msr;
458 char pscope[] = "\\_SB.PCI0";
459
460 acpigen_write_scope(pscope);
461 msr = rdmsr(TOP_MEM);
462 acpigen_write_name_dword("TOM1", msr.lo);
463 msr = rdmsr(TOP_MEM2);
464 /*
465 * Since XP only implements parts of ACPI 2.0, we can't use a qword
466 * here.
467 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
468 * slide 22ff.
469 * Shift value right by 20 bit to make it fit into 32bit,
470 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
471 */
472 acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
473 acpigen_pop_len();
474}
475
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200476static unsigned long agesa_write_acpi_tables(device_t device,
477 unsigned long current,
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200478 acpi_rsdp_t *rsdp)
479{
480 acpi_srat_t *srat;
481 acpi_slit_t *slit;
482 acpi_header_t *ssdt;
483 acpi_header_t *alib;
484 acpi_header_t *ivrs;
485 acpi_hest_t *hest;
486
487 /* HEST */
488 current = ALIGN(current, 8);
489 hest = (acpi_hest_t *)current;
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100490 acpi_write_hest((void *)current, acpi_fill_hest);
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200491 acpi_add_table(rsdp, (void *)current);
492 current += ((acpi_header_t *)current)->length;
493
494 current = ALIGN(current, 8);
495 printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current);
496 ivrs = agesawrapper_getlateinitptr(PICK_IVRS);
497 if (ivrs != NULL) {
498 memcpy((void *)current, ivrs, ivrs->length);
499 ivrs = (acpi_header_t *) current;
500 current += ivrs->length;
501 acpi_add_table(rsdp, ivrs);
502 } else {
503 printk(BIOS_DEBUG, " AGESA IVRS table NULL. Skipping.\n");
504 }
505
506 /* SRAT */
507 current = ALIGN(current, 8);
508 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
509 srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
510 if (srat != NULL) {
511 memcpy((void *)current, srat, srat->header.length);
512 srat = (acpi_srat_t *) current;
513 current += srat->header.length;
514 acpi_add_table(rsdp, srat);
515 } else {
516 printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n");
517 }
518
519 /* SLIT */
520 current = ALIGN(current, 8);
521 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
522 slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
523 if (slit != NULL) {
524 memcpy((void *)current, slit, slit->header.length);
525 slit = (acpi_slit_t *) current;
526 current += slit->header.length;
527 acpi_add_table(rsdp, slit);
528 } else {
529 printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n");
530 }
531
532 /* ALIB */
533 current = ALIGN(current, 16);
534 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
535 alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB);
536 if (alib != NULL) {
537 memcpy((void *)current, alib, alib->length);
538 alib = (acpi_header_t *) current;
539 current += alib->length;
540 acpi_add_table(rsdp, (void *)alib);
541 }
542 else {
543 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n");
544 }
545
546 /* this pstate ssdt may cause Blue Screen: Fixed: Keep this comment for a while. */
547 /* SSDT */
548 current = ALIGN(current, 16);
549 printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current);
550 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
551 if (ssdt != NULL) {
552 memcpy((void *)current, ssdt, ssdt->length);
553 ssdt = (acpi_header_t *) current;
554 current += ssdt->length;
555 }
556 else {
557 printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n");
558 }
559 acpi_add_table(rsdp,ssdt);
560
561 printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current);
562
563 return current;
564}
565
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800566static struct device_operations northbridge_operations = {
567 .read_resources = read_resources,
568 .set_resources = set_resources,
569 .enable_resources = pci_dev_enable_resources,
Edward O'Callaghand994ef12014-11-21 02:22:33 +1100570 .init = DEVICE_NOOP,
Vladimir Serbinenkodb09b0622014-10-08 22:15:17 +0200571 .acpi_fill_ssdt_generator = northbridge_fill_ssdt_generator,
572 .write_acpi_tables = agesa_write_acpi_tables,
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800573 .enable = 0,
574 .ops_pci = 0,
575};
576
577static const struct pci_driver family16_northbridge __pci_driver = {
578 .ops = &northbridge_operations,
579 .vendor = PCI_VENDOR_ID_AMD,
580 .device = PCI_DEVICE_ID_AMD_16H_MODEL_000F_NB_HT,
581};
582
583static const struct pci_driver family10_northbridge __pci_driver = {
584 .ops = &northbridge_operations,
585 .vendor = PCI_VENDOR_ID_AMD,
586 .device = PCI_DEVICE_ID_AMD_10H_NB_HT,
587};
588
Kyösti Mälkki4ee82c62014-11-25 16:03:12 +0200589static void fam16_finalize(void *chip_info)
590{
591 device_t dev;
592 u32 value;
593 dev = dev_find_slot(0, PCI_DEVFN(0, 0)); /* clear IoapicSbFeatureEn */
594 pci_write_config32(dev, 0xF8, 0);
595 pci_write_config32(dev, 0xFC, 5); /* TODO: move it to dsdt.asl */
596
597 /* disable No Snoop */
598 dev = dev_find_slot(0, PCI_DEVFN(1, 1));
599 value = pci_read_config32(dev, 0x60);
600 value &= ~(1 << 11);
601 pci_write_config32(dev, 0x60, value);
602}
603
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800604struct chip_operations northbridge_amd_agesa_family16kb_ops = {
605 CHIP_NAME("AMD FAM16 Northbridge")
606 .enable_dev = 0,
Kyösti Mälkki4ee82c62014-11-25 16:03:12 +0200607 .final = fam16_finalize,
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800608};
609
610static void domain_read_resources(device_t dev)
611{
612 unsigned reg;
613
614 /* Find the already assigned resource pairs */
615 get_fx_devs();
616 for (reg = 0x80; reg <= 0xd8; reg+= 0x08) {
617 u32 base, limit;
618 base = f1_read_config32(reg);
619 limit = f1_read_config32(reg + 0x04);
620 /* Is this register allocated? */
621 if ((base & 3) != 0) {
622 unsigned nodeid, reg_link;
623 device_t reg_dev;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200624 if (reg < 0xc0) { // mmio
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800625 nodeid = (limit & 0xf) + (base&0x30);
626 } else { // io
627 nodeid = (limit & 0xf) + ((base>>4)&0x30);
628 }
629 reg_link = (limit >> 4) & 7;
630 reg_dev = __f0_dev[nodeid];
631 if (reg_dev) {
632 /* Reserve the resource */
633 struct resource *res;
634 res = new_resource(reg_dev, IOINDEX(0x1000 + reg, reg_link));
635 if (res) {
636 res->flags = 1;
637 }
638 }
639 }
640 }
641 /* FIXME: do we need to check extend conf space?
642 I don't believe that much preset value */
643
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800644 pci_domain_read_resources(dev);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800645}
646
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800647static void domain_enable_resources(device_t dev)
648{
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +0200649#if IS_ENABLED(CONFIG_AGESA_LEGACY_WRAPPER)
Kyösti Mälkki8ae16a42014-06-19 20:44:34 +0300650 if (acpi_is_wakeup_s3())
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300651 agesawrapper_fchs3laterestore();
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800652
653 /* Must be called after PCI enumeration and resource allocation */
Kyösti Mälkkib139b5e2014-10-20 07:41:20 +0300654 if (!acpi_is_wakeup_s3()) {
655 /* Enable MMIO on AMD CPU Address Map Controller */
Kyösti Mälkki48518f02014-11-25 14:20:57 +0200656 amd_initcpuio();
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800657
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300658 agesawrapper_amdinitmid();
Kyösti Mälkkib139b5e2014-10-20 07:41:20 +0300659 }
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800660 printk(BIOS_DEBUG, " ader - leaving domain_enable_resources.\n");
Kyösti Mälkki28c4d2f2016-11-25 11:21:02 +0200661#endif
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800662}
663
664#if CONFIG_HW_MEM_HOLE_SIZEK != 0
665struct hw_mem_hole_info {
666 unsigned hole_startk;
667 int node_id;
668};
669static struct hw_mem_hole_info get_hw_mem_hole_info(void)
670{
671 struct hw_mem_hole_info mem_hole;
672 int i;
673 mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK;
674 mem_hole.node_id = -1;
675 for (i = 0; i < node_nums; i++) {
676 dram_base_mask_t d;
677 u32 hole;
678 d = get_dram_base_mask(i);
679 if (!(d.mask & 1)) continue; // no memory on this node
680 hole = pci_read_config32(__f1_dev[i], 0xf0);
681 if (hole & 2) { // we find the hole
Elyes HAOUAS27e18012017-06-27 23:14:51 +0200682 mem_hole.hole_startk = (hole & (0xff << 24)) >> 10;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800683 mem_hole.node_id = i; // record the node No with hole
684 break; // only one hole
685 }
686 }
Kyösti Mälkki2f9b3af2014-06-26 05:30:54 +0300687
688 /* We need to double check if there is special set on base reg and limit reg
689 * are not continuous instead of hole, it will find out its hole_startk.
690 */
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800691 if (mem_hole.node_id == -1) {
692 resource_t limitk_pri = 0;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200693 for (i = 0; i < node_nums; i++) {
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800694 dram_base_mask_t d;
695 resource_t base_k, limit_k;
696 d = get_dram_base_mask(i);
697 if (!(d.base & 1)) continue;
698 base_k = ((resource_t)(d.base & 0x1fffff00)) <<9;
699 if (base_k > 4 *1024 * 1024) break; // don't need to go to check
700 if (limitk_pri != base_k) { // we find the hole
701 mem_hole.hole_startk = (unsigned)limitk_pri; // must beblow 4G
702 mem_hole.node_id = i;
703 break; //only one hole
704 }
705 limit_k = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
706 limitk_pri = limit_k;
707 }
708 }
709 return mem_hole;
710}
711#endif
712
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800713static void domain_set_resources(device_t dev)
714{
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800715 unsigned long mmio_basek;
716 u32 pci_tolm;
717 int i, idx;
718 struct bus *link;
719#if CONFIG_HW_MEM_HOLE_SIZEK != 0
720 struct hw_mem_hole_info mem_hole;
721 u32 reset_memhole = 1;
722#endif
723
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800724 pci_tolm = 0xffffffffUL;
725 for (link = dev->link_list; link; link = link->next) {
726 pci_tolm = find_pci_tolm(link);
727 }
728
729 // FIXME handle interleaved nodes. If you fix this here, please fix
730 // amdk8, too.
731 mmio_basek = pci_tolm >> 10;
732 /* Round mmio_basek to something the processor can support */
733 mmio_basek &= ~((1 << 6) -1);
734
735 // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M
736 // MMIO hole. If you fix this here, please fix amdk8, too.
737 /* Round the mmio hole to 64M */
738 mmio_basek &= ~((64*1024) - 1);
739
740#if CONFIG_HW_MEM_HOLE_SIZEK != 0
741 /* if the hw mem hole is already set in raminit stage, here we will compare
742 * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will
743 * use hole_basek as mmio_basek and we don't need to reset hole.
744 * otherwise We reset the hole to the mmio_basek
745 */
746
747 mem_hole = get_hw_mem_hole_info();
748
749 // Use hole_basek as mmio_basek, and we don't need to reset hole anymore
750 if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) {
751 mmio_basek = mem_hole.hole_startk;
752 reset_memhole = 0;
753 }
754#endif
755
756 idx = 0x10;
757 for (i = 0; i < node_nums; i++) {
758 dram_base_mask_t d;
759 resource_t basek, limitk, sizek; // 4 1T
760
761 d = get_dram_base_mask(i);
762
763 if (!(d.mask & 1)) continue;
764 basek = ((resource_t)(d.base & 0x1fffff00)) << 9; // could overflow, we may lost 6 bit here
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100765 limitk = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800766
767 sizek = limitk - basek;
768
769 /* see if we need a hole from 0xa0000 to 0xbffff */
770 if ((basek < ((8*64)+(8*16))) && (sizek > ((8*64)+(16*16)))) {
771 ram_resource(dev, (idx | i), basek, ((8*64)+(8*16)) - basek);
772 idx += 0x10;
773 basek = (8*64)+(16*16);
774 sizek = limitk - ((8*64)+(16*16));
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800775 }
776
777 //printk(BIOS_DEBUG, "node %d : mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", i, mmio_basek, basek, limitk);
778
Kyösti Mälkki26c65432014-06-26 05:30:54 +0300779 /* split the region to accommodate pci memory space */
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200780 if ((basek < 4*1024*1024) && (limitk > mmio_basek)) {
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800781 if (basek <= mmio_basek) {
782 unsigned pre_sizek;
783 pre_sizek = mmio_basek - basek;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200784 if (pre_sizek > 0) {
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800785 ram_resource(dev, (idx | i), basek, pre_sizek);
786 idx += 0x10;
787 sizek -= pre_sizek;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800788 }
789 basek = mmio_basek;
790 }
791 if ((basek + sizek) <= 4*1024*1024) {
792 sizek = 0;
793 }
794 else {
795 uint64_t topmem2 = bsp_topmem2();
796 basek = 4*1024*1024;
797 sizek = topmem2/1024 - basek;
798 }
799 }
800
801 ram_resource(dev, (idx | i), basek, sizek);
802 idx += 0x10;
803 printk(BIOS_DEBUG, "node %d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n",
804 i, mmio_basek, basek, limitk);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800805 }
806
Kyösti Mälkki61be3602017-04-15 20:07:53 +0300807 add_uma_resource_below_tolm(dev, 7);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800808
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200809 for (link = dev->link_list; link; link = link->next) {
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800810 if (link->children) {
811 assign_resources(link);
812 }
813 }
814}
815
816static struct device_operations pci_domain_ops = {
817 .read_resources = domain_read_resources,
818 .set_resources = domain_set_resources,
819 .enable_resources = domain_enable_resources,
Edward O'Callaghane9e1d7a2015-01-02 15:11:49 +1100820 .init = DEVICE_NOOP,
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800821 .scan_bus = pci_domain_scan_bus,
822 .ops_pci_bus = pci_bus_default_ops,
823};
824
825static void sysconf_init(device_t dev) // first node
826{
827 sblink = (pci_read_config32(dev, 0x64)>>8) & 7; // don't forget sublink1
828 node_nums = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; //NodeCnt[2:0]
829}
830
831static void add_more_links(device_t dev, unsigned total_links)
832{
833 struct bus *link, *last = NULL;
834 int link_num;
835
836 for (link = dev->link_list; link; link = link->next)
837 last = link;
838
839 if (last) {
840 int links = total_links - last->link_num;
841 link_num = last->link_num;
842 if (links > 0) {
843 link = malloc(links*sizeof(*link));
844 if (!link)
845 die("Couldn't allocate more links!\n");
846 memset(link, 0, links*sizeof(*link));
847 last->next = link;
848 }
849 }
850 else {
851 link_num = -1;
852 link = malloc(total_links*sizeof(*link));
853 memset(link, 0, total_links*sizeof(*link));
854 dev->link_list = link;
855 }
856
857 for (link_num = link_num + 1; link_num < total_links; link_num++) {
858 link->link_num = link_num;
859 link->dev = dev;
860 link->next = link + 1;
861 last = link;
862 link = link->next;
863 }
864 last->next = NULL;
865}
866
Kyösti Mälkki580e7222015-03-19 21:04:23 +0200867static void cpu_bus_scan(device_t dev)
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800868{
869 struct bus *cpu_bus;
870 device_t dev_mc;
871#if CONFIG_CBB
872 device_t pci_domain;
873#endif
874 int i,j;
875 int coreid_bits;
876 int core_max = 0;
877 unsigned ApicIdCoreIdSize;
878 unsigned core_nums;
879 int siblings = 0;
880 unsigned int family;
881
882#if CONFIG_CBB
883 dev_mc = dev_find_slot(0, PCI_DEVFN(CONFIG_CDB, 0)); //0x00
884 if (dev_mc && dev_mc->bus) {
885 printk(BIOS_DEBUG, "%s found", dev_path(dev_mc));
886 pci_domain = dev_mc->bus->dev;
887 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
888 printk(BIOS_DEBUG, "\n%s move to ",dev_path(dev_mc));
889 dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
890 printk(BIOS_DEBUG, "%s",dev_path(dev_mc));
891 } else {
892 printk(BIOS_DEBUG, " but it is not under pci_domain directly ");
893 }
894 printk(BIOS_DEBUG, "\n");
895 }
896 dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
897 if (!dev_mc) {
898 dev_mc = dev_find_slot(0, PCI_DEVFN(0x18, 0));
899 if (dev_mc && dev_mc->bus) {
900 printk(BIOS_DEBUG, "%s found\n", dev_path(dev_mc));
901 pci_domain = dev_mc->bus->dev;
902 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
903 if ((pci_domain->link_list) && (pci_domain->link_list->children == dev_mc)) {
904 printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
905 dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
906 printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
907 while (dev_mc) {
908 printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
909 dev_mc->path.pci.devfn -= PCI_DEVFN(0x18,0);
910 printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
911 dev_mc = dev_mc->sibling;
912 }
913 }
914 }
915 }
916 }
917#endif
918 dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
919 if (!dev_mc) {
920 printk(BIOS_ERR, "%02x:%02x.0 not found", CONFIG_CBB, CONFIG_CDB);
921 die("");
922 }
923 sysconf_init(dev_mc);
924#if CONFIG_CBB && (MAX_NODE_NUMS > 32)
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200925 if (node_nums > 32) { // need to put node 32 to node 63 to bus 0xfe
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800926 if (pci_domain->link_list && !pci_domain->link_list->next) {
927 struct bus *new_link = new_link(pci_domain);
928 pci_domain->link_list->next = new_link;
929 new_link->link_num = 1;
930 new_link->dev = pci_domain;
931 new_link->children = 0;
932 printk(BIOS_DEBUG, "%s links now 2\n", dev_path(pci_domain));
933 }
934 pci_domain->link_list->next->secondary = CONFIG_CBB - 1;
935 }
936#endif
937
938 /* Get Max Number of cores(MNC) */
Kyösti Mälkkid41feed2017-09-24 16:23:57 +0300939 coreid_bits = (cpuid_ecx(0x80000008) & 0x0000F000) >> 12;
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800940 core_max = 1 << (coreid_bits & 0x000F); //mnc
941
942 ApicIdCoreIdSize = ((cpuid_ecx(0x80000008)>>12) & 0xF);
943 if (ApicIdCoreIdSize) {
944 core_nums = (1 << ApicIdCoreIdSize) - 1;
945 } else {
946 core_nums = 3; //quad core
947 }
948
949 /* Find which cpus are present */
950 cpu_bus = dev->link_list;
951 for (i = 0; i < node_nums; i++) {
952 device_t cdb_dev;
953 unsigned busn, devn;
954 struct bus *pbus;
955
956 busn = CONFIG_CBB;
957 devn = CONFIG_CDB + i;
958 pbus = dev_mc->bus;
959#if CONFIG_CBB && (MAX_NODE_NUMS > 32)
960 if (i >= 32) {
961 busn--;
962 devn -= 32;
963 pbus = pci_domain->link_list->next;
964 }
965#endif
966
967 /* Find the cpu's pci device */
968 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0));
969 if (!cdb_dev) {
970 /* If I am probing things in a weird order
971 * ensure all of the cpu's pci devices are found.
972 */
973 int fn;
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200974 for (fn = 0; fn <= 5; fn++) { //FBDIMM?
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800975 cdb_dev = pci_probe_dev(NULL, pbus,
976 PCI_DEVFN(devn, fn));
977 }
978 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0));
979 } else {
980 /* Ok, We need to set the links for that device.
981 * otherwise the device under it will not be scanned
982 */
Kyösti Mälkki2a2d6132015-02-04 13:25:37 +0200983 add_more_links(cdb_dev, 4);
Siyuan Wang3e32cc02013-07-09 17:16:20 +0800984 }
985
986 family = cpuid_eax(1);
987 family = (family >> 20) & 0xFF;
988 if (family == 1) { //f10
989 u32 dword;
990 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 3));
991 dword = pci_read_config32(cdb_dev, 0xe8);
992 siblings = ((dword & BIT15) >> 13) | ((dword & (BIT13 | BIT12)) >> 12);
993 } else if (family == 7) {//f16
994 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 5));
995 if (cdb_dev && cdb_dev->enabled) {
996 siblings = pci_read_config32(cdb_dev, 0x84);
997 siblings &= 0xFF;
998 }
999 } else {
1000 siblings = 0; //default one core
1001 }
1002 int enable_node = cdb_dev && cdb_dev->enabled;
1003 printk(BIOS_SPEW, "%s family%xh, core_max=0x%x, core_nums=0x%x, siblings=0x%x\n",
1004 dev_path(cdb_dev), 0x0f + family, core_max, core_nums, siblings);
1005
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +02001006 for (j = 0; j <= siblings; j++) {
Siyuan Wang3e32cc02013-07-09 17:16:20 +08001007 extern CONST OPTIONS_CONFIG_TOPOLOGY ROMDATA TopologyConfiguration;
1008 u32 modules = TopologyConfiguration.PlatformNumberOfModules;
1009 u32 lapicid_start = 0;
1010
1011 /*
1012 * APIC ID calucation is tightly coupled with AGESA v5 code.
1013 * This calculation MUST match the assignment calculation done
1014 * in LocalApicInitializationAtEarly() function.
1015 * And reference GetLocalApicIdForCore()
1016 *
1017 * Apply apic enumeration rules
1018 * For systems with >= 16 APICs, put the IO-APICs at 0..n and
1019 * put the local-APICs at m..z
1020 *
1021 * This is needed because many IO-APIC devices only have 4 bits
1022 * for their APIC id and therefore must reside at 0..15
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +02001023 */
Kyösti Mälkki50036322016-05-18 13:35:21 +03001024
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +02001025 u8 plat_num_io_apics = 3; /* FIXME */
Kyösti Mälkki50036322016-05-18 13:35:21 +03001026
1027 if ((node_nums * core_max) + plat_num_io_apics >= 0x10) {
1028 lapicid_start = (plat_num_io_apics - 1) / core_max;
Siyuan Wang3e32cc02013-07-09 17:16:20 +08001029 lapicid_start = (lapicid_start + 1) * core_max;
1030 printk(BIOS_SPEW, "lpaicid_start=0x%x ", lapicid_start);
1031 }
1032 u32 apic_id = (lapicid_start * (i/modules + 1)) + ((i % modules) ? (j + (siblings + 1)) : j);
1033 printk(BIOS_SPEW, "node 0x%x core 0x%x apicid=0x%x\n",
1034 i, j, apic_id);
1035
1036 device_t cpu = add_cpu_device(cpu_bus, apic_id, enable_node);
1037 if (cpu)
1038 amd_cpu_topology(cpu, i, j);
1039 } //j
1040 }
Siyuan Wang3e32cc02013-07-09 17:16:20 +08001041}
1042
1043static void cpu_bus_init(device_t dev)
1044{
1045 initialize_cpus(dev->link_list);
1046}
1047
Siyuan Wang3e32cc02013-07-09 17:16:20 +08001048static struct device_operations cpu_bus_ops = {
Edward O'Callaghan66c65322014-11-21 01:43:38 +11001049 .read_resources = DEVICE_NOOP,
1050 .set_resources = DEVICE_NOOP,
Edward O'Callaghan812d2a42014-10-31 08:17:23 +11001051 .enable_resources = DEVICE_NOOP,
Siyuan Wang3e32cc02013-07-09 17:16:20 +08001052 .init = cpu_bus_init,
1053 .scan_bus = cpu_bus_scan,
1054};
1055
1056static void root_complex_enable_dev(struct device *dev)
1057{
1058 static int done = 0;
1059
Siyuan Wang3e32cc02013-07-09 17:16:20 +08001060 if (!done) {
1061 setup_bsp_ramtop();
Siyuan Wang3e32cc02013-07-09 17:16:20 +08001062 done = 1;
1063 }
1064
1065 /* Set the operations if it is a special bus type */
1066 if (dev->path.type == DEVICE_PATH_DOMAIN) {
1067 dev->ops = &pci_domain_ops;
1068 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
1069 dev->ops = &cpu_bus_ops;
1070 }
1071}
1072
1073struct chip_operations northbridge_amd_agesa_family16kb_root_complex_ops = {
1074 CHIP_NAME("AMD FAM16 Root Complex")
1075 .enable_dev = root_complex_enable_dev,
1076};
Bruce Griffith76db07e2013-07-07 02:06:53 -06001077
1078/*********************************************************************
1079 * Change the vendor / device IDs to match the generic VBIOS header. *
1080 *********************************************************************/
1081u32 map_oprom_vendev(u32 vendev)
1082{
1083 u32 new_vendev = vendev;
1084
1085 switch(vendev) {
1086 case 0x10029830:
1087 case 0x10029831:
1088 case 0x10029832:
1089 case 0x10029833:
1090 case 0x10029834:
1091 case 0x10029835:
1092 case 0x10029836:
1093 case 0x10029837:
1094 case 0x10029838:
1095 case 0x10029839:
1096 case 0x1002983A:
1097 case 0x1002983D:
1098 new_vendev = 0x10029830; // This is the default value in AMD-generated VBIOS
1099 break;
1100 default:
1101 break;
1102 }
1103
1104 if (vendev != new_vendev)
1105 printk(BIOS_NOTICE, "Mapping PCI device %8x to %8x\n", vendev, new_vendev);
1106
1107 return new_vendev;
1108}