blob: 692805b905f7caea1662e8495c68a1c9869f7c81 [file] [log] [blame]
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001/*
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.
Bruce Griffith27ed80b2014-08-15 11:46:25 -060014 */
15
16#include <console/console.h>
17#include <arch/io.h>
18#include <arch/acpi.h>
19#include <stdint.h>
20#include <device/device.h>
21#include <device/pci.h>
22#include <device/pci_ids.h>
23#include <device/hypertransport.h>
24#include <stdlib.h>
25#include <string.h>
26#include <lib.h>
27#include <cpu/cpu.h>
28#include <cbmem.h>
29
30#include <Porting.h>
31#include <AGESA.h>
32#include <FieldAccessors.h>
33#include <Options.h>
34#include <Topology.h>
35#include <cpu/amd/amdfam16.h>
36#include <cpuRegisters.h>
Kyösti Mälkkied8d2772017-07-15 17:12:44 +030037#include <northbridge/amd/agesa/agesa_helper.h>
Kyösti Mälkki903ce252016-11-25 11:21:02 +020038#if IS_ENABLED(CONFIG_BINARYPI_LEGACY_WRAPPER)
Kyösti Mälkki023ed1f2014-10-22 08:05:36 +030039#include <northbridge/amd/pi/agesawrapper.h>
Kyösti Mälkkie4c17ce2014-10-21 18:22:32 +030040#include <northbridge/amd/pi/agesawrapper_call.h>
Kyösti Mälkki903ce252016-11-25 11:21:02 +020041#endif
Bruce Griffith27ed80b2014-08-15 11:46:25 -060042#include "northbridge.h"
43
44#include <cpu/x86/lapic.h>
45#include <cpu/amd/mtrr.h>
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +020046#include <arch/acpi.h>
47#include <arch/acpigen.h>
Bruce Griffith27ed80b2014-08-15 11:46:25 -060048
49#define MAX_NODE_NUMS (MAX_NODES * MAX_DIES)
50
Bruce Griffith27ed80b2014-08-15 11:46:25 -060051typedef struct dram_base_mask {
52 u32 base; //[47:27] at [28:8]
53 u32 mask; //[47:27] at [28:8] and enable at bit 0
54} dram_base_mask_t;
55
56static unsigned node_nums;
57static unsigned sblink;
58static device_t __f0_dev[MAX_NODE_NUMS];
59static device_t __f1_dev[MAX_NODE_NUMS];
60static device_t __f2_dev[MAX_NODE_NUMS];
61static device_t __f4_dev[MAX_NODE_NUMS];
62static unsigned fx_devs = 0;
63
64static dram_base_mask_t get_dram_base_mask(u32 nodeid)
65{
66 device_t dev;
67 dram_base_mask_t d;
68 dev = __f1_dev[0];
69 u32 temp;
70 temp = pci_read_config32(dev, 0x44 + (nodeid << 3)); //[39:24] at [31:16]
71 d.mask = ((temp & 0xfff80000)>>(8+3)); // mask out DramMask [26:24] too
72 temp = pci_read_config32(dev, 0x144 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
73 d.mask |= temp<<21;
74 temp = pci_read_config32(dev, 0x40 + (nodeid << 3)); //[39:24] at [31:16]
75 d.mask |= (temp & 1); // enable bit
76 d.base = ((temp & 0xfff80000)>>(8+3)); // mask out DramBase [26:24) too
77 temp = pci_read_config32(dev, 0x140 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
78 d.base |= temp<<21;
79 return d;
80}
81
82static void set_io_addr_reg(device_t dev, u32 nodeid, u32 linkn, u32 reg,
83 u32 io_min, u32 io_max)
84{
85 u32 i;
86 u32 tempreg;
87 /* io range allocation */
88 tempreg = (nodeid&0xf) | ((nodeid & 0x30)<<(8-4)) | (linkn<<4) | ((io_max&0xf0)<<(12-4)); //limit
Elyes HAOUASa8131602016-09-19 10:27:57 -060089 for (i = 0; i < node_nums; i++)
Bruce Griffith27ed80b2014-08-15 11:46:25 -060090 pci_write_config32(__f1_dev[i], reg+4, tempreg);
Elyes HAOUASa8131602016-09-19 10:27:57 -060091 tempreg = 3 /*| (3<<4)*/ | ((io_min&0xf0)<<(12-4)); //base :ISA and VGA ?
Elyes HAOUASa8131602016-09-19 10:27:57 -060092 for (i = 0; i < node_nums; i++)
Bruce Griffith27ed80b2014-08-15 11:46:25 -060093 pci_write_config32(__f1_dev[i], reg, tempreg);
94}
95
96static void set_mmio_addr_reg(u32 nodeid, u32 linkn, u32 reg, u32 index, u32 mmio_min, u32 mmio_max, u32 nodes)
97{
98 u32 i;
99 u32 tempreg;
100 /* io range allocation */
101 tempreg = (nodeid&0xf) | (linkn<<4) | (mmio_max&0xffffff00); //limit
Elyes HAOUASa8131602016-09-19 10:27:57 -0600102 for (i = 0; i < nodes; i++)
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600103 pci_write_config32(__f1_dev[i], reg+4, tempreg);
104 tempreg = 3 | (nodeid & 0x30) | (mmio_min&0xffffff00);
Elyes HAOUASa8131602016-09-19 10:27:57 -0600105 for (i = 0; i < node_nums; i++)
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600106 pci_write_config32(__f1_dev[i], reg, tempreg);
107}
108
109static device_t get_node_pci(u32 nodeid, u32 fn)
110{
111#if MAX_NODE_NUMS + CONFIG_CDB >= 32
112 if ((CONFIG_CDB + nodeid) < 32) {
113 return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn));
114 } else {
115 return dev_find_slot(CONFIG_CBB-1, PCI_DEVFN(CONFIG_CDB + nodeid - 32, fn));
116 }
117#else
118 return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn));
119#endif
120}
121
122static void get_fx_devs(void)
123{
124 int i;
125 for (i = 0; i < MAX_NODE_NUMS; i++) {
126 __f0_dev[i] = get_node_pci(i, 0);
127 __f1_dev[i] = get_node_pci(i, 1);
128 __f2_dev[i] = get_node_pci(i, 2);
129 __f4_dev[i] = get_node_pci(i, 4);
130 if (__f0_dev[i] != NULL && __f1_dev[i] != NULL)
131 fx_devs = i+1;
132 }
133 if (__f1_dev[0] == NULL || __f0_dev[0] == NULL || fx_devs == 0) {
134 die("Cannot find 0:0x18.[0|1]\n");
135 }
Elyes HAOUASa8131602016-09-19 10:27:57 -0600136 printk(BIOS_DEBUG, "fx_devs = 0x%x\n", fx_devs);
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600137}
138
139static u32 f1_read_config32(unsigned reg)
140{
141 if (fx_devs == 0)
142 get_fx_devs();
143 return pci_read_config32(__f1_dev[0], reg);
144}
145
146static void f1_write_config32(unsigned reg, u32 value)
147{
148 int i;
149 if (fx_devs == 0)
150 get_fx_devs();
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200151 for (i = 0; i < fx_devs; i++) {
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600152 device_t dev;
153 dev = __f1_dev[i];
154 if (dev && dev->enabled) {
155 pci_write_config32(dev, reg, value);
156 }
157 }
158}
159
160static u32 amdfam16_nodeid(device_t dev)
161{
162#if MAX_NODE_NUMS == 64
163 unsigned busn;
164 busn = dev->bus->secondary;
165 if (busn != CONFIG_CBB) {
166 return (dev->path.pci.devfn >> 3) - CONFIG_CDB + 32;
167 } else {
168 return (dev->path.pci.devfn >> 3) - CONFIG_CDB;
169 }
170
171#else
172 return (dev->path.pci.devfn >> 3) - CONFIG_CDB;
173#endif
174}
175
176static void set_vga_enable_reg(u32 nodeid, u32 linkn)
177{
178 u32 val;
179
180 val = 1 | (nodeid<<4) | (linkn<<12);
181 /* it will routing
182 * (1)mmio 0xa0000:0xbffff
183 * (2)io 0x3b0:0x3bb, 0x3c0:0x3df
184 */
185 f1_write_config32(0xf4, val);
186
187}
188
189/**
190 * @return
191 * @retval 2 resoure does not exist, usable
192 * @retval 0 resource exists, not usable
193 * @retval 1 resource exist, resource has been allocated before
194 */
195static int reg_useable(unsigned reg, device_t goal_dev, unsigned goal_nodeid,
196 unsigned goal_link)
197{
198 struct resource *res;
199 unsigned nodeid, link = 0;
200 int result;
201 res = 0;
202 for (nodeid = 0; !res && (nodeid < fx_devs); nodeid++) {
203 device_t dev;
204 dev = __f0_dev[nodeid];
205 if (!dev)
206 continue;
207 for (link = 0; !res && (link < 8); link++) {
208 res = probe_resource(dev, IOINDEX(0x1000 + reg, link));
209 }
210 }
211 result = 2;
212 if (res) {
213 result = 0;
214 if ((goal_link == (link - 1)) &&
215 (goal_nodeid == (nodeid - 1)) &&
216 (res->flags <= 1)) {
217 result = 1;
218 }
219 }
220 return result;
221}
222
223static struct resource *amdfam16_find_iopair(device_t dev, unsigned nodeid, unsigned link)
224{
225 struct resource *resource;
226 u32 free_reg, reg;
227 resource = 0;
228 free_reg = 0;
229 for (reg = 0xc0; reg <= 0xd8; reg += 0x8) {
230 int result;
231 result = reg_useable(reg, dev, nodeid, link);
232 if (result == 1) {
233 /* I have been allocated this one */
234 break;
235 }
236 else if (result > 1) {
237 /* I have a free register pair */
238 free_reg = reg;
239 }
240 }
241 if (reg > 0xd8) {
242 reg = free_reg; // if no free, the free_reg still be 0
243 }
244
245 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
246
247 return resource;
248}
249
250static struct resource *amdfam16_find_mempair(device_t dev, u32 nodeid, u32 link)
251{
252 struct resource *resource;
253 u32 free_reg, reg;
254 resource = 0;
255 free_reg = 0;
256 for (reg = 0x80; reg <= 0xb8; reg += 0x8) {
257 int result;
258 result = reg_useable(reg, dev, nodeid, link);
259 if (result == 1) {
260 /* I have been allocated this one */
261 break;
262 }
263 else if (result > 1) {
264 /* I have a free register pair */
265 free_reg = reg;
266 }
267 }
268 if (reg > 0xb8) {
269 reg = free_reg;
270 }
271
272 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
273 return resource;
274}
275
276static void amdfam16_link_read_bases(device_t dev, u32 nodeid, u32 link)
277{
278 struct resource *resource;
279
280 /* Initialize the io space constraints on the current bus */
281 resource = amdfam16_find_iopair(dev, nodeid, link);
282 if (resource) {
283 u32 align;
284 align = log2(HT_IO_HOST_ALIGN);
285 resource->base = 0;
286 resource->size = 0;
287 resource->align = align;
288 resource->gran = align;
289 resource->limit = 0xffffUL;
290 resource->flags = IORESOURCE_IO | IORESOURCE_BRIDGE;
291 }
292
293 /* Initialize the prefetchable memory constraints on the current bus */
294 resource = amdfam16_find_mempair(dev, nodeid, link);
295 if (resource) {
296 resource->base = 0;
297 resource->size = 0;
298 resource->align = log2(HT_MEM_HOST_ALIGN);
299 resource->gran = log2(HT_MEM_HOST_ALIGN);
300 resource->limit = 0xffffffffffULL;
301 resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
302 resource->flags |= IORESOURCE_BRIDGE;
303 }
304
305 /* Initialize the memory constraints on the current bus */
306 resource = amdfam16_find_mempair(dev, nodeid, link);
307 if (resource) {
308 resource->base = 0;
309 resource->size = 0;
310 resource->align = log2(HT_MEM_HOST_ALIGN);
311 resource->gran = log2(HT_MEM_HOST_ALIGN);
312 resource->limit = 0xffffffffffULL;
313 resource->flags = IORESOURCE_MEM | IORESOURCE_BRIDGE;
314 }
315
316}
317
318static void read_resources(device_t dev)
319{
320 u32 nodeid;
321 struct bus *link;
322
323 nodeid = amdfam16_nodeid(dev);
324 for (link = dev->link_list; link; link = link->next) {
325 if (link->children) {
326 amdfam16_link_read_bases(dev, nodeid, link->link_num);
327 }
328 }
Kyösti Mälkki5d490382015-05-27 07:58:22 +0300329
330 /*
331 * This MMCONF resource must be reserved in the PCI domain.
332 * It is not honored by the coreboot resource allocator if it is in
333 * the CPU_CLUSTER.
334 */
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +0200335 mmconf_resource(dev, 0xc0010058);
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600336}
337
338static void set_resource(device_t dev, struct resource *resource, u32 nodeid)
339{
340 resource_t rbase, rend;
341 unsigned reg, link_num;
342 char buf[50];
343
344 /* Make certain the resource has actually been set */
345 if (!(resource->flags & IORESOURCE_ASSIGNED)) {
346 return;
347 }
348
349 /* If I have already stored this resource don't worry about it */
350 if (resource->flags & IORESOURCE_STORED) {
351 return;
352 }
353
354 /* Only handle PCI memory and IO resources */
355 if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
356 return;
357
358 /* Ensure I am actually looking at a resource of function 1 */
359 if ((resource->index & 0xffff) < 0x1000) {
360 return;
361 }
362 /* Get the base address */
363 rbase = resource->base;
364
365 /* Get the limit (rounded up) */
366 rend = resource_end(resource);
367
368 /* Get the register and link */
369 reg = resource->index & 0xfff; // 4k
370 link_num = IOINDEX_LINK(resource->index);
371
372 if (resource->flags & IORESOURCE_IO) {
373 set_io_addr_reg(dev, nodeid, link_num, reg, rbase>>8, rend>>8);
374 }
375 else if (resource->flags & IORESOURCE_MEM) {
Elyes HAOUAS7db506c2016-10-02 11:56:39 +0200376 set_mmio_addr_reg(nodeid, link_num, reg, (resource->index >>24), rbase>>8, rend>>8, node_nums); // [39:8]
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600377 }
378 resource->flags |= IORESOURCE_STORED;
Elyes HAOUAS0d4b11a2016-10-03 21:57:21 +0200379 snprintf(buf, sizeof(buf), " <node %x link %x>",
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600380 nodeid, link_num);
381 report_resource_stored(dev, resource, buf);
382}
383
384/**
385 * I tried to reuse the resource allocation code in set_resource()
386 * but it is too difficult to deal with the resource allocation magic.
387 */
388
389static void create_vga_resource(device_t dev, unsigned nodeid)
390{
391 struct bus *link;
392
393 /* find out which link the VGA card is connected,
394 * we only deal with the 'first' vga card */
395 for (link = dev->link_list; link; link = link->next) {
396 if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) {
Martin Roth77a58b92017-06-24 14:45:48 -0600397#if IS_ENABLED(CONFIG_MULTIPLE_VGA_ADAPTERS)
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600398 extern device_t vga_pri; // the primary vga device, defined in device.c
399 printk(BIOS_DEBUG, "VGA: vga_pri bus num = %d bus range [%d,%d]\n", vga_pri->bus->secondary,
400 link->secondary,link->subordinate);
401 /* We need to make sure the vga_pri is under the link */
Elyes HAOUASa8131602016-09-19 10:27:57 -0600402 if ((vga_pri->bus->secondary >= link->secondary) &&
403 (vga_pri->bus->secondary <= link->subordinate))
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600404#endif
405 break;
406 }
407 }
408
409 /* no VGA card installed */
410 if (link == NULL)
411 return;
412
413 printk(BIOS_DEBUG, "VGA: %s (aka node %d) link %d has VGA device\n", dev_path(dev), nodeid, sblink);
414 set_vga_enable_reg(nodeid, sblink);
415}
416
417static void set_resources(device_t dev)
418{
419 unsigned nodeid;
420 struct bus *bus;
421 struct resource *res;
422
423 /* Find the nodeid */
424 nodeid = amdfam16_nodeid(dev);
425
426 create_vga_resource(dev, nodeid); //TODO: do we need this?
427
428 /* Set each resource we have found */
429 for (res = dev->resource_list; res; res = res->next) {
430 set_resource(dev, res, nodeid);
431 }
432
433 for (bus = dev->link_list; bus; bus = bus->next) {
434 if (bus->children) {
435 assign_resources(bus);
436 }
437 }
438}
439
440static void northbridge_init(struct device *dev)
441{
442}
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200443
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100444static unsigned long acpi_fill_hest(acpi_hest_t *hest)
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200445{
446 void *addr, *current;
447
448 /* Skip the HEST header. */
449 current = (void *)(hest + 1);
450
451 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
452 if (addr != NULL)
453 current += acpi_create_hest_error_source(hest, current, 0, (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
454
455 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
456 if (addr != NULL)
457 current += acpi_create_hest_error_source(hest, current, 1, (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
458
459 return (unsigned long)current;
460}
461
Alexander Couzens5eea4582015-04-12 22:18:55 +0200462static void northbridge_fill_ssdt_generator(device_t device)
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200463{
464 msr_t msr;
465 char pscope[] = "\\_SB.PCI0";
466
467 acpigen_write_scope(pscope);
468 msr = rdmsr(TOP_MEM);
469 acpigen_write_name_dword("TOM1", msr.lo);
470 msr = rdmsr(TOP_MEM2);
471 /*
472 * Since XP only implements parts of ACPI 2.0, we can't use a qword
473 * here.
474 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
475 * slide 22ff.
476 * Shift value right by 20 bit to make it fit into 32bit,
477 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
478 */
479 acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
480 acpigen_pop_len();
481}
482
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200483static unsigned long agesa_write_acpi_tables(device_t device,
484 unsigned long current,
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200485 acpi_rsdp_t *rsdp)
486{
487 acpi_srat_t *srat;
488 acpi_slit_t *slit;
489 acpi_header_t *ssdt;
490 acpi_header_t *alib;
491 acpi_header_t *ivrs;
492 acpi_hest_t *hest;
493
494 /* HEST */
495 current = ALIGN(current, 8);
496 hest = (acpi_hest_t *)current;
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100497 acpi_write_hest((void *)current, acpi_fill_hest);
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200498 acpi_add_table(rsdp, (void *)current);
499 current += ((acpi_header_t *)current)->length;
500
501 current = ALIGN(current, 8);
502 printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current);
503 ivrs = agesawrapper_getlateinitptr(PICK_IVRS);
504 if (ivrs != NULL) {
505 memcpy((void *)current, ivrs, ivrs->length);
506 ivrs = (acpi_header_t *) current;
507 current += ivrs->length;
508 acpi_add_table(rsdp, ivrs);
509 } else {
510 printk(BIOS_DEBUG, " AGESA IVRS table NULL. Skipping.\n");
511 }
512
513 /* SRAT */
514 current = ALIGN(current, 8);
515 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
516 srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
517 if (srat != NULL) {
518 memcpy((void *)current, srat, srat->header.length);
519 srat = (acpi_srat_t *) current;
520 current += srat->header.length;
521 acpi_add_table(rsdp, srat);
522 } else {
523 printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n");
524 }
525
526 /* SLIT */
527 current = ALIGN(current, 8);
528 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
529 slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
530 if (slit != NULL) {
531 memcpy((void *)current, slit, slit->header.length);
532 slit = (acpi_slit_t *) current;
533 current += slit->header.length;
534 acpi_add_table(rsdp, slit);
535 } else {
536 printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n");
537 }
538
539 /* ALIB */
540 current = ALIGN(current, 16);
541 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
542 alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB);
543 if (alib != NULL) {
544 memcpy((void *)current, alib, alib->length);
545 alib = (acpi_header_t *) current;
546 current += alib->length;
547 acpi_add_table(rsdp, (void *)alib);
548 }
549 else {
550 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n");
551 }
552
553 /* this pstate ssdt may cause Blue Screen: Fixed: Keep this comment for a while. */
554 /* SSDT */
555 current = ALIGN(current, 16);
556 printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current);
557 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
558 if (ssdt != NULL) {
559 memcpy((void *)current, ssdt, ssdt->length);
560 ssdt = (acpi_header_t *) current;
561 current += ssdt->length;
562 }
563 else {
564 printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n");
565 }
566 acpi_add_table(rsdp,ssdt);
567
568 printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current);
569 return current;
570}
571
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600572static struct device_operations northbridge_operations = {
573 .read_resources = read_resources,
574 .set_resources = set_resources,
575 .enable_resources = pci_dev_enable_resources,
576 .init = northbridge_init,
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200577 .acpi_fill_ssdt_generator = northbridge_fill_ssdt_generator,
578 .write_acpi_tables = agesa_write_acpi_tables,
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600579 .enable = 0,
580 .ops_pci = 0,
581};
582
583static const struct pci_driver family16_northbridge __pci_driver = {
584 .ops = &northbridge_operations,
585 .vendor = PCI_VENDOR_ID_AMD,
Marshall Dawson463f46e2016-10-14 20:46:08 -0600586 .device = PCI_DEVICE_ID_AMD_16H_MODEL_303F_NB_HT,
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600587};
588
589static const struct pci_driver family10_northbridge __pci_driver = {
590 .ops = &northbridge_operations,
591 .vendor = PCI_VENDOR_ID_AMD,
592 .device = PCI_DEVICE_ID_AMD_10H_NB_HT,
593};
594
Dave Frodin891f71a2015-01-19 15:58:24 -0700595static void fam16_finalize(void *chip_info)
596{
597 device_t dev;
598 u32 value;
599 dev = dev_find_slot(0, PCI_DEVFN(0, 0)); /* clear IoapicSbFeatureEn */
600 pci_write_config32(dev, 0xF8, 0);
601 pci_write_config32(dev, 0xFC, 5); /* TODO: move it to dsdt.asl */
602
603 /* disable No Snoop */
604 dev = dev_find_slot(0, PCI_DEVFN(1, 1));
605 value = pci_read_config32(dev, 0x60);
606 value &= ~(1 << 11);
607 pci_write_config32(dev, 0x60, value);
608}
609
Kyösti Mälkkie4c17ce2014-10-21 18:22:32 +0300610struct chip_operations northbridge_amd_pi_00730F01_ops = {
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600611 CHIP_NAME("AMD FAM16 Northbridge")
612 .enable_dev = 0,
Dave Frodin891f71a2015-01-19 15:58:24 -0700613 .final = fam16_finalize,
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600614};
615
616static void domain_read_resources(device_t dev)
617{
618 unsigned reg;
619
620 /* Find the already assigned resource pairs */
621 get_fx_devs();
622 for (reg = 0x80; reg <= 0xd8; reg+= 0x08) {
623 u32 base, limit;
624 base = f1_read_config32(reg);
625 limit = f1_read_config32(reg + 0x04);
626 /* Is this register allocated? */
627 if ((base & 3) != 0) {
628 unsigned nodeid, reg_link;
629 device_t reg_dev;
Elyes HAOUASa8131602016-09-19 10:27:57 -0600630 if (reg < 0xc0) { // mmio
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600631 nodeid = (limit & 0xf) + (base&0x30);
632 } else { // io
633 nodeid = (limit & 0xf) + ((base>>4)&0x30);
634 }
635 reg_link = (limit >> 4) & 7;
636 reg_dev = __f0_dev[nodeid];
637 if (reg_dev) {
638 /* Reserve the resource */
639 struct resource *res;
640 res = new_resource(reg_dev, IOINDEX(0x1000 + reg, reg_link));
641 if (res) {
642 res->flags = 1;
643 }
644 }
645 }
646 }
647 /* FIXME: do we need to check extend conf space?
648 I don't believe that much preset value */
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600649 pci_domain_read_resources(dev);
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600650}
651
652static void domain_enable_resources(device_t dev)
653{
Kyösti Mälkki903ce252016-11-25 11:21:02 +0200654#if IS_ENABLED(CONFIG_BINARYPI_LEGACY_WRAPPER)
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600655 /* Must be called after PCI enumeration and resource allocation */
656 if (!acpi_is_wakeup_s3())
657 AGESAWRAPPER(amdinitmid);
658
659 printk(BIOS_DEBUG, " ader - leaving domain_enable_resources.\n");
Kyösti Mälkki903ce252016-11-25 11:21:02 +0200660#endif
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600661}
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 }
686
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 */
690 if (mem_hole.node_id == -1) {
691 resource_t limitk_pri = 0;
Elyes HAOUASa8131602016-09-19 10:27:57 -0600692 for (i = 0; i < node_nums; i++) {
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600693 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
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600712static void domain_set_resources(device_t dev)
713{
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600714 unsigned long mmio_basek;
715 u32 pci_tolm;
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600716 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
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600723 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
Elyes HAOUAS7db506c2016-10-02 11:56:39 +0200764 limitk = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600765
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));
774
775 }
776
777 //printk(BIOS_DEBUG, "node %d : mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", i, mmio_basek, basek, limitk);
778
779 /* split the region to accommodate pci memory space */
Elyes HAOUASa8131602016-09-19 10:27:57 -0600780 if ((basek < 4*1024*1024) && (limitk > mmio_basek)) {
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600781 if (basek <= mmio_basek) {
782 unsigned pre_sizek;
783 pre_sizek = mmio_basek - basek;
Elyes HAOUASa8131602016-09-19 10:27:57 -0600784 if (pre_sizek > 0) {
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600785 ram_resource(dev, (idx | i), basek, pre_sizek);
786 idx += 0x10;
787 sizek -= pre_sizek;
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600788 }
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);
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600805 }
806
Kyösti Mälkkie87564f2017-04-15 20:07:53 +0300807 add_uma_resource_below_tolm(dev, 7);
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600808
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200809 for (link = dev->link_list; link; link = link->next) {
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600810 if (link->children) {
811 assign_resources(link);
812 }
813 }
814}
815
Aaron Durbinaa090cb2017-09-13 16:01:52 -0600816static const char *domain_acpi_name(const struct device *dev)
Philipp Deppenwiese30670122017-03-01 02:24:33 +0100817{
818 if (dev->path.type == DEVICE_PATH_DOMAIN)
819 return "PCI0";
820
821 return NULL;
822}
823
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600824static struct device_operations pci_domain_ops = {
825 .read_resources = domain_read_resources,
826 .set_resources = domain_set_resources,
827 .enable_resources = domain_enable_resources,
828 .init = NULL,
829 .scan_bus = pci_domain_scan_bus,
830 .ops_pci_bus = pci_bus_default_ops,
Philipp Deppenwiese30670122017-03-01 02:24:33 +0100831 .acpi_name = domain_acpi_name,
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600832};
833
834static void sysconf_init(device_t dev) // first node
835{
836 sblink = (pci_read_config32(dev, 0x64)>>8) & 7; // don't forget sublink1
837 node_nums = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; //NodeCnt[2:0]
838}
839
840static void add_more_links(device_t dev, unsigned total_links)
841{
842 struct bus *link, *last = NULL;
843 int link_num;
844
845 for (link = dev->link_list; link; link = link->next)
846 last = link;
847
848 if (last) {
849 int links = total_links - last->link_num;
850 link_num = last->link_num;
851 if (links > 0) {
852 link = malloc(links*sizeof(*link));
853 if (!link)
854 die("Couldn't allocate more links!\n");
855 memset(link, 0, links*sizeof(*link));
856 last->next = link;
857 }
858 }
859 else {
860 link_num = -1;
861 link = malloc(total_links*sizeof(*link));
862 memset(link, 0, total_links*sizeof(*link));
863 dev->link_list = link;
864 }
865
866 for (link_num = link_num + 1; link_num < total_links; link_num++) {
867 link->link_num = link_num;
868 link->dev = dev;
869 link->next = link + 1;
870 last = link;
871 link = link->next;
872 }
873 last->next = NULL;
874}
875
Kyösti Mälkki580e7222015-03-19 21:04:23 +0200876static void cpu_bus_scan(device_t dev)
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600877{
878 struct bus *cpu_bus;
879 device_t dev_mc;
880#if CONFIG_CBB
881 device_t pci_domain;
882#endif
883 int i,j;
884 int coreid_bits;
885 int core_max = 0;
886 unsigned ApicIdCoreIdSize;
887 unsigned core_nums;
888 int siblings = 0;
889 unsigned int family;
890 u32 modules = 0;
891 VOID* modules_ptr = &modules;
892 BUILD_OPT_CFG* options = NULL;
893 int ioapic_count = 0;
894
895 // TODO Remove the printk's.
896 printk(BIOS_SPEW, "MullinsPI Debug: Grabbing the AMD Topology Information.\n");
897 AmdGetValue(AMD_GLOBAL_USER_OPTIONS, (VOID**)&options, sizeof(options));
898 AmdGetValue(AMD_GLOBAL_NUM_MODULES, &modules_ptr, sizeof(modules));
Alexandru Gagniuc2e0cf142014-12-28 20:38:32 -0600899 modules = *(u32*)modules_ptr;
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600900 ASSERT(modules > 0);
901 ASSERT(options);
902 ioapic_count = (int)options->CfgPlatNumIoApics;
903 ASSERT(ioapic_count > 0);
904 printk(BIOS_SPEW, "MullinsPI Debug: AMD Topology Number of Modules (@0x%p) is %d\n", modules_ptr, modules);
905 printk(BIOS_SPEW, "MullinsPI Debug: AMD Topology Number of IOAPICs (@0x%p) is %d\n", options, (int)options->CfgPlatNumIoApics);
906
907#if CONFIG_CBB
908 dev_mc = dev_find_slot(0, PCI_DEVFN(CONFIG_CDB, 0)); //0x00
909 if (dev_mc && dev_mc->bus) {
910 printk(BIOS_DEBUG, "%s found", dev_path(dev_mc));
911 pci_domain = dev_mc->bus->dev;
912 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
913 printk(BIOS_DEBUG, "\n%s move to ",dev_path(dev_mc));
914 dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
915 printk(BIOS_DEBUG, "%s",dev_path(dev_mc));
916 } else {
917 printk(BIOS_DEBUG, " but it is not under pci_domain directly ");
918 }
919 printk(BIOS_DEBUG, "\n");
920 }
921 dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
922 if (!dev_mc) {
923 dev_mc = dev_find_slot(0, PCI_DEVFN(0x18, 0));
924 if (dev_mc && dev_mc->bus) {
925 printk(BIOS_DEBUG, "%s found\n", dev_path(dev_mc));
926 pci_domain = dev_mc->bus->dev;
927 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
928 if ((pci_domain->link_list) && (pci_domain->link_list->children == dev_mc)) {
929 printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
930 dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
931 printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
932 while (dev_mc) {
933 printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
934 dev_mc->path.pci.devfn -= PCI_DEVFN(0x18,0);
935 printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
936 dev_mc = dev_mc->sibling;
937 }
938 }
939 }
940 }
941 }
942#endif
943 dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
944 if (!dev_mc) {
945 printk(BIOS_ERR, "%02x:%02x.0 not found", CONFIG_CBB, CONFIG_CDB);
946 die("");
947 }
948 sysconf_init(dev_mc);
949#if CONFIG_CBB && (MAX_NODE_NUMS > 32)
Elyes HAOUASa8131602016-09-19 10:27:57 -0600950 if (node_nums > 32) { // need to put node 32 to node 63 to bus 0xfe
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600951 if (pci_domain->link_list && !pci_domain->link_list->next) {
952 struct bus *new_link = new_link(pci_domain);
953 pci_domain->link_list->next = new_link;
954 new_link->link_num = 1;
955 new_link->dev = pci_domain;
956 new_link->children = 0;
957 printk(BIOS_DEBUG, "%s links now 2\n", dev_path(pci_domain));
958 }
959 pci_domain->link_list->next->secondary = CONFIG_CBB - 1;
960 }
961#endif
962
963 /* Get Max Number of cores(MNC) */
964 coreid_bits = (cpuid_ecx(AMD_CPUID_ASIZE_PCCOUNT) & 0x0000F000) >> 12;
965 core_max = 1 << (coreid_bits & 0x000F); //mnc
966
967 ApicIdCoreIdSize = ((cpuid_ecx(0x80000008)>>12) & 0xF);
968 if (ApicIdCoreIdSize) {
969 core_nums = (1 << ApicIdCoreIdSize) - 1;
970 } else {
971 core_nums = 3; //quad core
972 }
973
974 /* Find which cpus are present */
975 cpu_bus = dev->link_list;
976 for (i = 0; i < node_nums; i++) {
977 device_t cdb_dev;
978 unsigned busn, devn;
979 struct bus *pbus;
980
981 busn = CONFIG_CBB;
982 devn = CONFIG_CDB + i;
983 pbus = dev_mc->bus;
984#if CONFIG_CBB && (MAX_NODE_NUMS > 32)
985 if (i >= 32) {
986 busn--;
987 devn -= 32;
988 pbus = pci_domain->link_list->next;
989 }
990#endif
991
992 /* Find the cpu's pci device */
993 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0));
994 if (!cdb_dev) {
995 /* If I am probing things in a weird order
996 * ensure all of the cpu's pci devices are found.
997 */
998 int fn;
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200999 for (fn = 0; fn <= 5; fn++) { //FBDIMM?
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001000 cdb_dev = pci_probe_dev(NULL, pbus,
1001 PCI_DEVFN(devn, fn));
1002 }
1003 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0));
1004 } else {
1005 /* Ok, We need to set the links for that device.
1006 * otherwise the device under it will not be scanned
1007 */
Kyösti Mälkkic5163ed82015-02-04 13:25:37 +02001008
1009 add_more_links(cdb_dev, 4);
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001010 }
1011
1012 family = cpuid_eax(1);
1013 family = (family >> 20) & 0xFF;
1014 if (family == 1) { //f10
1015 u32 dword;
1016 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 3));
1017 dword = pci_read_config32(cdb_dev, 0xe8);
1018 siblings = ((dword & BIT15) >> 13) | ((dword & (BIT13 | BIT12)) >> 12);
1019 } else if (family == 7) {//f16
1020 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 5));
1021 if (cdb_dev && cdb_dev->enabled) {
1022 siblings = pci_read_config32(cdb_dev, 0x84);
1023 siblings &= 0xFF;
1024 }
1025 } else {
1026 siblings = 0; //default one core
1027 }
1028 int enable_node = cdb_dev && cdb_dev->enabled;
Elyes HAOUASa8131602016-09-19 10:27:57 -06001029 printk(BIOS_SPEW, "%s family%xh, core_max = 0x%x, core_nums = 0x%x, siblings = 0x%x\n",
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001030 dev_path(cdb_dev), 0x0f + family, core_max, core_nums, siblings);
1031
Elyes HAOUASa8131602016-09-19 10:27:57 -06001032 for (j = 0; j <= siblings; j++) {
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001033 u32 lapicid_start = 0;
1034
1035 /*
1036 * APIC ID calucation is tightly coupled with AGESA v5 code.
1037 * This calculation MUST match the assignment calculation done
1038 * in LocalApicInitializationAtEarly() function.
1039 * And reference GetLocalApicIdForCore()
1040 *
1041 * Apply apic enumeration rules
1042 * For systems with >= 16 APICs, put the IO-APICs at 0..n and
1043 * put the local-APICs at m..z
1044 *
1045 * This is needed because many IO-APIC devices only have 4 bits
1046 * for their APIC id and therefore must reside at 0..15
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +02001047 */
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001048 if ((node_nums * core_max) + ioapic_count >= 0x10) {
1049 lapicid_start = (ioapic_count - 1) / core_max;
1050 lapicid_start = (lapicid_start + 1) * core_max;
Elyes HAOUASa8131602016-09-19 10:27:57 -06001051 printk(BIOS_SPEW, "lpaicid_start = 0x%x ", lapicid_start);
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001052 }
1053 u32 apic_id = (lapicid_start * (i/modules + 1)) + ((i % modules) ? (j + (siblings + 1)) : j);
Elyes HAOUASa8131602016-09-19 10:27:57 -06001054 printk(BIOS_SPEW, "node 0x%x core 0x%x apicid = 0x%x\n",
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001055 i, j, apic_id);
1056
1057 device_t cpu = add_cpu_device(cpu_bus, apic_id, enable_node);
1058 if (cpu)
1059 amd_cpu_topology(cpu, i, j);
1060 } //j
1061 }
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001062}
1063
1064static void cpu_bus_init(device_t dev)
1065{
1066 initialize_cpus(dev->link_list);
1067}
1068
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001069static struct device_operations cpu_bus_ops = {
Kyösti Mälkki48f82a92016-12-02 16:02:30 +02001070 .read_resources = DEVICE_NOOP,
1071 .set_resources = DEVICE_NOOP,
Edward O'Callaghan812d2a42014-10-31 08:17:23 +11001072 .enable_resources = DEVICE_NOOP,
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001073 .init = cpu_bus_init,
1074 .scan_bus = cpu_bus_scan,
1075};
1076
1077static void root_complex_enable_dev(struct device *dev)
1078{
1079 static int done = 0;
1080
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001081 if (!done) {
1082 setup_bsp_ramtop();
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001083 done = 1;
1084 }
1085
1086 /* Set the operations if it is a special bus type */
1087 if (dev->path.type == DEVICE_PATH_DOMAIN) {
1088 dev->ops = &pci_domain_ops;
1089 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
1090 dev->ops = &cpu_bus_ops;
1091 }
1092}
1093
Kyösti Mälkkie4c17ce2014-10-21 18:22:32 +03001094struct chip_operations northbridge_amd_pi_00730F01_root_complex_ops = {
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001095 CHIP_NAME("AMD FAM16 Root Complex")
1096 .enable_dev = root_complex_enable_dev,
1097};
1098
1099/*********************************************************************
1100 * Change the vendor / device IDs to match the generic VBIOS header. *
1101 *********************************************************************/
1102u32 map_oprom_vendev(u32 vendev)
1103{
1104 u32 new_vendev;
1105 new_vendev =
1106 ((0x10029850 <= vendev) && (vendev <= 0x1002986F)) ? 0x10029850 : vendev;
1107
1108 if (vendev != new_vendev)
1109 printk(BIOS_NOTICE, "Mapping PCI device %8x to %8x\n", vendev, new_vendev);
1110
1111 return new_vendev;
1112}