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