blob: 334cdb215cc1ee0dacdf3f2256d32abb4795ac5a [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älkki023ed1f2014-10-22 08:05:36 +030037#include <northbridge/amd/pi/agesawrapper.h>
Kyösti Mälkkie4c17ce2014-10-21 18:22:32 +030038#include <northbridge/amd/pi/agesawrapper_call.h>
Bruce Griffith27ed80b2014-08-15 11:46:25 -060039#include "northbridge.h"
40
41#include <cpu/x86/lapic.h>
42#include <cpu/amd/mtrr.h>
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +020043#include <arch/acpi.h>
44#include <arch/acpigen.h>
Bruce Griffith27ed80b2014-08-15 11:46:25 -060045
46#define MAX_NODE_NUMS (MAX_NODES * MAX_DIES)
47
Bruce Griffith27ed80b2014-08-15 11:46:25 -060048typedef struct dram_base_mask {
49 u32 base; //[47:27] at [28:8]
50 u32 mask; //[47:27] at [28:8] and enable at bit 0
51} dram_base_mask_t;
52
53static unsigned node_nums;
54static unsigned sblink;
55static device_t __f0_dev[MAX_NODE_NUMS];
56static device_t __f1_dev[MAX_NODE_NUMS];
57static device_t __f2_dev[MAX_NODE_NUMS];
58static device_t __f4_dev[MAX_NODE_NUMS];
59static unsigned fx_devs = 0;
60
61static dram_base_mask_t get_dram_base_mask(u32 nodeid)
62{
63 device_t dev;
64 dram_base_mask_t d;
65 dev = __f1_dev[0];
66 u32 temp;
67 temp = pci_read_config32(dev, 0x44 + (nodeid << 3)); //[39:24] at [31:16]
68 d.mask = ((temp & 0xfff80000)>>(8+3)); // mask out DramMask [26:24] too
69 temp = pci_read_config32(dev, 0x144 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
70 d.mask |= temp<<21;
71 temp = pci_read_config32(dev, 0x40 + (nodeid << 3)); //[39:24] at [31:16]
72 d.mask |= (temp & 1); // enable bit
73 d.base = ((temp & 0xfff80000)>>(8+3)); // mask out DramBase [26:24) too
74 temp = pci_read_config32(dev, 0x140 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
75 d.base |= temp<<21;
76 return d;
77}
78
79static void set_io_addr_reg(device_t dev, u32 nodeid, u32 linkn, u32 reg,
80 u32 io_min, u32 io_max)
81{
82 u32 i;
83 u32 tempreg;
84 /* io range allocation */
85 tempreg = (nodeid&0xf) | ((nodeid & 0x30)<<(8-4)) | (linkn<<4) | ((io_max&0xf0)<<(12-4)); //limit
Elyes HAOUASa8131602016-09-19 10:27:57 -060086 for (i = 0; i < node_nums; i++)
Bruce Griffith27ed80b2014-08-15 11:46:25 -060087 pci_write_config32(__f1_dev[i], reg+4, tempreg);
Elyes HAOUASa8131602016-09-19 10:27:57 -060088 tempreg = 3 /*| (3<<4)*/ | ((io_min&0xf0)<<(12-4)); //base :ISA and VGA ?
Bruce Griffith27ed80b2014-08-15 11:46:25 -060089#if 0
90 // FIXME: can we use VGA reg instead?
91 if (dev->link[link].bridge_ctrl & PCI_BRIDGE_CTL_VGA) {
92 printk(BIOS_SPEW, "%s, enabling legacy VGA IO forwarding for %s link %s\n",
93 __func__, dev_path(dev), link);
94 tempreg |= PCI_IO_BASE_VGA_EN;
95 }
96 if (dev->link[link].bridge_ctrl & PCI_BRIDGE_CTL_NO_ISA) {
97 tempreg |= PCI_IO_BASE_NO_ISA;
98 }
99#endif
Elyes HAOUASa8131602016-09-19 10:27:57 -0600100 for (i = 0; i < node_nums; i++)
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600101 pci_write_config32(__f1_dev[i], reg, tempreg);
102}
103
104static void set_mmio_addr_reg(u32 nodeid, u32 linkn, u32 reg, u32 index, u32 mmio_min, u32 mmio_max, u32 nodes)
105{
106 u32 i;
107 u32 tempreg;
108 /* io range allocation */
109 tempreg = (nodeid&0xf) | (linkn<<4) | (mmio_max&0xffffff00); //limit
Elyes HAOUASa8131602016-09-19 10:27:57 -0600110 for (i = 0; i < nodes; i++)
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600111 pci_write_config32(__f1_dev[i], reg+4, tempreg);
112 tempreg = 3 | (nodeid & 0x30) | (mmio_min&0xffffff00);
Elyes HAOUASa8131602016-09-19 10:27:57 -0600113 for (i = 0; i < node_nums; i++)
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600114 pci_write_config32(__f1_dev[i], reg, tempreg);
115}
116
117static device_t get_node_pci(u32 nodeid, u32 fn)
118{
119#if MAX_NODE_NUMS + CONFIG_CDB >= 32
120 if ((CONFIG_CDB + nodeid) < 32) {
121 return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn));
122 } else {
123 return dev_find_slot(CONFIG_CBB-1, PCI_DEVFN(CONFIG_CDB + nodeid - 32, fn));
124 }
125#else
126 return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn));
127#endif
128}
129
130static void get_fx_devs(void)
131{
132 int i;
133 for (i = 0; i < MAX_NODE_NUMS; i++) {
134 __f0_dev[i] = get_node_pci(i, 0);
135 __f1_dev[i] = get_node_pci(i, 1);
136 __f2_dev[i] = get_node_pci(i, 2);
137 __f4_dev[i] = get_node_pci(i, 4);
138 if (__f0_dev[i] != NULL && __f1_dev[i] != NULL)
139 fx_devs = i+1;
140 }
141 if (__f1_dev[0] == NULL || __f0_dev[0] == NULL || fx_devs == 0) {
142 die("Cannot find 0:0x18.[0|1]\n");
143 }
Elyes HAOUASa8131602016-09-19 10:27:57 -0600144 printk(BIOS_DEBUG, "fx_devs = 0x%x\n", fx_devs);
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600145}
146
147static u32 f1_read_config32(unsigned reg)
148{
149 if (fx_devs == 0)
150 get_fx_devs();
151 return pci_read_config32(__f1_dev[0], reg);
152}
153
154static void f1_write_config32(unsigned reg, u32 value)
155{
156 int i;
157 if (fx_devs == 0)
158 get_fx_devs();
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200159 for (i = 0; i < fx_devs; i++) {
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600160 device_t dev;
161 dev = __f1_dev[i];
162 if (dev && dev->enabled) {
163 pci_write_config32(dev, reg, value);
164 }
165 }
166}
167
168static u32 amdfam16_nodeid(device_t dev)
169{
170#if MAX_NODE_NUMS == 64
171 unsigned busn;
172 busn = dev->bus->secondary;
173 if (busn != CONFIG_CBB) {
174 return (dev->path.pci.devfn >> 3) - CONFIG_CDB + 32;
175 } else {
176 return (dev->path.pci.devfn >> 3) - CONFIG_CDB;
177 }
178
179#else
180 return (dev->path.pci.devfn >> 3) - CONFIG_CDB;
181#endif
182}
183
184static void set_vga_enable_reg(u32 nodeid, u32 linkn)
185{
186 u32 val;
187
188 val = 1 | (nodeid<<4) | (linkn<<12);
189 /* it will routing
190 * (1)mmio 0xa0000:0xbffff
191 * (2)io 0x3b0:0x3bb, 0x3c0:0x3df
192 */
193 f1_write_config32(0xf4, val);
194
195}
196
197/**
198 * @return
199 * @retval 2 resoure does not exist, usable
200 * @retval 0 resource exists, not usable
201 * @retval 1 resource exist, resource has been allocated before
202 */
203static int reg_useable(unsigned reg, device_t goal_dev, unsigned goal_nodeid,
204 unsigned goal_link)
205{
206 struct resource *res;
207 unsigned nodeid, link = 0;
208 int result;
209 res = 0;
210 for (nodeid = 0; !res && (nodeid < fx_devs); nodeid++) {
211 device_t dev;
212 dev = __f0_dev[nodeid];
213 if (!dev)
214 continue;
215 for (link = 0; !res && (link < 8); link++) {
216 res = probe_resource(dev, IOINDEX(0x1000 + reg, link));
217 }
218 }
219 result = 2;
220 if (res) {
221 result = 0;
222 if ((goal_link == (link - 1)) &&
223 (goal_nodeid == (nodeid - 1)) &&
224 (res->flags <= 1)) {
225 result = 1;
226 }
227 }
228 return result;
229}
230
231static struct resource *amdfam16_find_iopair(device_t dev, unsigned nodeid, unsigned link)
232{
233 struct resource *resource;
234 u32 free_reg, reg;
235 resource = 0;
236 free_reg = 0;
237 for (reg = 0xc0; reg <= 0xd8; reg += 0x8) {
238 int result;
239 result = reg_useable(reg, dev, nodeid, link);
240 if (result == 1) {
241 /* I have been allocated this one */
242 break;
243 }
244 else if (result > 1) {
245 /* I have a free register pair */
246 free_reg = reg;
247 }
248 }
249 if (reg > 0xd8) {
250 reg = free_reg; // if no free, the free_reg still be 0
251 }
252
253 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
254
255 return resource;
256}
257
258static struct resource *amdfam16_find_mempair(device_t dev, u32 nodeid, u32 link)
259{
260 struct resource *resource;
261 u32 free_reg, reg;
262 resource = 0;
263 free_reg = 0;
264 for (reg = 0x80; reg <= 0xb8; reg += 0x8) {
265 int result;
266 result = reg_useable(reg, dev, nodeid, link);
267 if (result == 1) {
268 /* I have been allocated this one */
269 break;
270 }
271 else if (result > 1) {
272 /* I have a free register pair */
273 free_reg = reg;
274 }
275 }
276 if (reg > 0xb8) {
277 reg = free_reg;
278 }
279
280 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
281 return resource;
282}
283
284static void amdfam16_link_read_bases(device_t dev, u32 nodeid, u32 link)
285{
286 struct resource *resource;
287
288 /* Initialize the io space constraints on the current bus */
289 resource = amdfam16_find_iopair(dev, nodeid, link);
290 if (resource) {
291 u32 align;
292 align = log2(HT_IO_HOST_ALIGN);
293 resource->base = 0;
294 resource->size = 0;
295 resource->align = align;
296 resource->gran = align;
297 resource->limit = 0xffffUL;
298 resource->flags = IORESOURCE_IO | IORESOURCE_BRIDGE;
299 }
300
301 /* Initialize the prefetchable memory constraints on the current bus */
302 resource = amdfam16_find_mempair(dev, nodeid, link);
303 if (resource) {
304 resource->base = 0;
305 resource->size = 0;
306 resource->align = log2(HT_MEM_HOST_ALIGN);
307 resource->gran = log2(HT_MEM_HOST_ALIGN);
308 resource->limit = 0xffffffffffULL;
309 resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
310 resource->flags |= IORESOURCE_BRIDGE;
311 }
312
313 /* Initialize the memory constraints on the current bus */
314 resource = amdfam16_find_mempair(dev, nodeid, link);
315 if (resource) {
316 resource->base = 0;
317 resource->size = 0;
318 resource->align = log2(HT_MEM_HOST_ALIGN);
319 resource->gran = log2(HT_MEM_HOST_ALIGN);
320 resource->limit = 0xffffffffffULL;
321 resource->flags = IORESOURCE_MEM | IORESOURCE_BRIDGE;
322 }
323
324}
325
Kyösti Mälkki5d490382015-05-27 07:58:22 +0300326static void enable_mmconf_resource(device_t dev)
327{
328 struct resource *resource = new_resource(dev, 0xc0010058);
329 resource->base = CONFIG_MMCONF_BASE_ADDRESS;
330 resource->size = CONFIG_MMCONF_BUS_NUMBER * 4096 * 256;
331 resource->flags = IORESOURCE_MEM | IORESOURCE_RESERVE |
332 IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
333}
334
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600335static void read_resources(device_t dev)
336{
337 u32 nodeid;
338 struct bus *link;
339
340 nodeid = amdfam16_nodeid(dev);
341 for (link = dev->link_list; link; link = link->next) {
342 if (link->children) {
343 amdfam16_link_read_bases(dev, nodeid, link->link_num);
344 }
345 }
Kyösti Mälkki5d490382015-05-27 07:58:22 +0300346
347 /*
348 * This MMCONF resource must be reserved in the PCI domain.
349 * It is not honored by the coreboot resource allocator if it is in
350 * the CPU_CLUSTER.
351 */
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200352 if (IS_ENABLED(CONFIG_MMCONF_SUPPORT))
Kyösti Mälkki5d490382015-05-27 07:58:22 +0300353 enable_mmconf_resource(dev);
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600354}
355
356static void set_resource(device_t dev, struct resource *resource, u32 nodeid)
357{
358 resource_t rbase, rend;
359 unsigned reg, link_num;
360 char buf[50];
361
362 /* Make certain the resource has actually been set */
363 if (!(resource->flags & IORESOURCE_ASSIGNED)) {
364 return;
365 }
366
367 /* If I have already stored this resource don't worry about it */
368 if (resource->flags & IORESOURCE_STORED) {
369 return;
370 }
371
372 /* Only handle PCI memory and IO resources */
373 if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
374 return;
375
376 /* Ensure I am actually looking at a resource of function 1 */
377 if ((resource->index & 0xffff) < 0x1000) {
378 return;
379 }
380 /* Get the base address */
381 rbase = resource->base;
382
383 /* Get the limit (rounded up) */
384 rend = resource_end(resource);
385
386 /* Get the register and link */
387 reg = resource->index & 0xfff; // 4k
388 link_num = IOINDEX_LINK(resource->index);
389
390 if (resource->flags & IORESOURCE_IO) {
391 set_io_addr_reg(dev, nodeid, link_num, reg, rbase>>8, rend>>8);
392 }
393 else if (resource->flags & IORESOURCE_MEM) {
394 set_mmio_addr_reg(nodeid, link_num, reg, (resource->index >>24), rbase>>8, rend>>8, node_nums) ;// [39:8]
395 }
396 resource->flags |= IORESOURCE_STORED;
Elyes HAOUAS0d4b11a2016-10-03 21:57:21 +0200397 snprintf(buf, sizeof(buf), " <node %x link %x>",
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600398 nodeid, link_num);
399 report_resource_stored(dev, resource, buf);
400}
401
402/**
403 * I tried to reuse the resource allocation code in set_resource()
404 * but it is too difficult to deal with the resource allocation magic.
405 */
406
407static void create_vga_resource(device_t dev, unsigned nodeid)
408{
409 struct bus *link;
410
411 /* find out which link the VGA card is connected,
412 * we only deal with the 'first' vga card */
413 for (link = dev->link_list; link; link = link->next) {
414 if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) {
415#if CONFIG_MULTIPLE_VGA_ADAPTERS
416 extern device_t vga_pri; // the primary vga device, defined in device.c
417 printk(BIOS_DEBUG, "VGA: vga_pri bus num = %d bus range [%d,%d]\n", vga_pri->bus->secondary,
418 link->secondary,link->subordinate);
419 /* We need to make sure the vga_pri is under the link */
Elyes HAOUASa8131602016-09-19 10:27:57 -0600420 if ((vga_pri->bus->secondary >= link->secondary) &&
421 (vga_pri->bus->secondary <= link->subordinate))
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600422#endif
423 break;
424 }
425 }
426
427 /* no VGA card installed */
428 if (link == NULL)
429 return;
430
431 printk(BIOS_DEBUG, "VGA: %s (aka node %d) link %d has VGA device\n", dev_path(dev), nodeid, sblink);
432 set_vga_enable_reg(nodeid, sblink);
433}
434
435static void set_resources(device_t dev)
436{
437 unsigned nodeid;
438 struct bus *bus;
439 struct resource *res;
440
441 /* Find the nodeid */
442 nodeid = amdfam16_nodeid(dev);
443
444 create_vga_resource(dev, nodeid); //TODO: do we need this?
445
446 /* Set each resource we have found */
447 for (res = dev->resource_list; res; res = res->next) {
448 set_resource(dev, res, nodeid);
449 }
450
451 for (bus = dev->link_list; bus; bus = bus->next) {
452 if (bus->children) {
453 assign_resources(bus);
454 }
455 }
456}
457
458static void northbridge_init(struct device *dev)
459{
460}
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200461
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100462static unsigned long acpi_fill_hest(acpi_hest_t *hest)
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200463{
464 void *addr, *current;
465
466 /* Skip the HEST header. */
467 current = (void *)(hest + 1);
468
469 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
470 if (addr != NULL)
471 current += acpi_create_hest_error_source(hest, current, 0, (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
472
473 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
474 if (addr != NULL)
475 current += acpi_create_hest_error_source(hest, current, 1, (void *)((u32)addr + 2), *(UINT16 *)addr - 2);
476
477 return (unsigned long)current;
478}
479
Alexander Couzens5eea4582015-04-12 22:18:55 +0200480static void northbridge_fill_ssdt_generator(device_t device)
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200481{
482 msr_t msr;
483 char pscope[] = "\\_SB.PCI0";
484
485 acpigen_write_scope(pscope);
486 msr = rdmsr(TOP_MEM);
487 acpigen_write_name_dword("TOM1", msr.lo);
488 msr = rdmsr(TOP_MEM2);
489 /*
490 * Since XP only implements parts of ACPI 2.0, we can't use a qword
491 * here.
492 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
493 * slide 22ff.
494 * Shift value right by 20 bit to make it fit into 32bit,
495 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
496 */
497 acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
498 acpigen_pop_len();
499}
500
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200501static unsigned long agesa_write_acpi_tables(device_t device,
502 unsigned long current,
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200503 acpi_rsdp_t *rsdp)
504{
505 acpi_srat_t *srat;
506 acpi_slit_t *slit;
507 acpi_header_t *ssdt;
508 acpi_header_t *alib;
509 acpi_header_t *ivrs;
510 acpi_hest_t *hest;
511
512 /* HEST */
513 current = ALIGN(current, 8);
514 hest = (acpi_hest_t *)current;
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100515 acpi_write_hest((void *)current, acpi_fill_hest);
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200516 acpi_add_table(rsdp, (void *)current);
517 current += ((acpi_header_t *)current)->length;
518
519 current = ALIGN(current, 8);
520 printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current);
521 ivrs = agesawrapper_getlateinitptr(PICK_IVRS);
522 if (ivrs != NULL) {
523 memcpy((void *)current, ivrs, ivrs->length);
524 ivrs = (acpi_header_t *) current;
525 current += ivrs->length;
526 acpi_add_table(rsdp, ivrs);
527 } else {
528 printk(BIOS_DEBUG, " AGESA IVRS table NULL. Skipping.\n");
529 }
530
531 /* SRAT */
532 current = ALIGN(current, 8);
533 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
534 srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
535 if (srat != NULL) {
536 memcpy((void *)current, srat, srat->header.length);
537 srat = (acpi_srat_t *) current;
538 current += srat->header.length;
539 acpi_add_table(rsdp, srat);
540 } else {
541 printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n");
542 }
543
544 /* SLIT */
545 current = ALIGN(current, 8);
546 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
547 slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
548 if (slit != NULL) {
549 memcpy((void *)current, slit, slit->header.length);
550 slit = (acpi_slit_t *) current;
551 current += slit->header.length;
552 acpi_add_table(rsdp, slit);
553 } else {
554 printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n");
555 }
556
557 /* ALIB */
558 current = ALIGN(current, 16);
559 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
560 alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB);
561 if (alib != NULL) {
562 memcpy((void *)current, alib, alib->length);
563 alib = (acpi_header_t *) current;
564 current += alib->length;
565 acpi_add_table(rsdp, (void *)alib);
566 }
567 else {
568 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n");
569 }
570
571 /* this pstate ssdt may cause Blue Screen: Fixed: Keep this comment for a while. */
572 /* SSDT */
573 current = ALIGN(current, 16);
574 printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current);
575 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
576 if (ssdt != NULL) {
577 memcpy((void *)current, ssdt, ssdt->length);
578 ssdt = (acpi_header_t *) current;
579 current += ssdt->length;
580 }
581 else {
582 printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n");
583 }
584 acpi_add_table(rsdp,ssdt);
585
586 printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current);
587 return current;
588}
589
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600590static struct device_operations northbridge_operations = {
591 .read_resources = read_resources,
592 .set_resources = set_resources,
593 .enable_resources = pci_dev_enable_resources,
594 .init = northbridge_init,
Kyösti Mälkki0b5b5412014-11-26 08:11:07 +0200595 .acpi_fill_ssdt_generator = northbridge_fill_ssdt_generator,
596 .write_acpi_tables = agesa_write_acpi_tables,
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600597 .enable = 0,
598 .ops_pci = 0,
599};
600
601static const struct pci_driver family16_northbridge __pci_driver = {
602 .ops = &northbridge_operations,
603 .vendor = PCI_VENDOR_ID_AMD,
604 .device = PCI_DEVICE_ID_AMD_16H_MODEL_003F_NB_HT,
605};
606
607static const struct pci_driver family10_northbridge __pci_driver = {
608 .ops = &northbridge_operations,
609 .vendor = PCI_VENDOR_ID_AMD,
610 .device = PCI_DEVICE_ID_AMD_10H_NB_HT,
611};
612
Dave Frodin891f71a2015-01-19 15:58:24 -0700613static void fam16_finalize(void *chip_info)
614{
615 device_t dev;
616 u32 value;
617 dev = dev_find_slot(0, PCI_DEVFN(0, 0)); /* clear IoapicSbFeatureEn */
618 pci_write_config32(dev, 0xF8, 0);
619 pci_write_config32(dev, 0xFC, 5); /* TODO: move it to dsdt.asl */
620
621 /* disable No Snoop */
622 dev = dev_find_slot(0, PCI_DEVFN(1, 1));
623 value = pci_read_config32(dev, 0x60);
624 value &= ~(1 << 11);
625 pci_write_config32(dev, 0x60, value);
626}
627
Kyösti Mälkkie4c17ce2014-10-21 18:22:32 +0300628struct chip_operations northbridge_amd_pi_00730F01_ops = {
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600629 CHIP_NAME("AMD FAM16 Northbridge")
630 .enable_dev = 0,
Dave Frodin891f71a2015-01-19 15:58:24 -0700631 .final = fam16_finalize,
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600632};
633
634static void domain_read_resources(device_t dev)
635{
636 unsigned reg;
637
638 /* Find the already assigned resource pairs */
639 get_fx_devs();
640 for (reg = 0x80; reg <= 0xd8; reg+= 0x08) {
641 u32 base, limit;
642 base = f1_read_config32(reg);
643 limit = f1_read_config32(reg + 0x04);
644 /* Is this register allocated? */
645 if ((base & 3) != 0) {
646 unsigned nodeid, reg_link;
647 device_t reg_dev;
Elyes HAOUASa8131602016-09-19 10:27:57 -0600648 if (reg < 0xc0) { // mmio
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600649 nodeid = (limit & 0xf) + (base&0x30);
650 } else { // io
651 nodeid = (limit & 0xf) + ((base>>4)&0x30);
652 }
653 reg_link = (limit >> 4) & 7;
654 reg_dev = __f0_dev[nodeid];
655 if (reg_dev) {
656 /* Reserve the resource */
657 struct resource *res;
658 res = new_resource(reg_dev, IOINDEX(0x1000 + reg, reg_link));
659 if (res) {
660 res->flags = 1;
661 }
662 }
663 }
664 }
665 /* FIXME: do we need to check extend conf space?
666 I don't believe that much preset value */
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600667 pci_domain_read_resources(dev);
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600668}
669
670static void domain_enable_resources(device_t dev)
671{
672 if (acpi_is_wakeup_s3())
673 AGESAWRAPPER(fchs3laterestore);
674
675 /* Must be called after PCI enumeration and resource allocation */
676 if (!acpi_is_wakeup_s3())
677 AGESAWRAPPER(amdinitmid);
678
679 printk(BIOS_DEBUG, " ader - leaving domain_enable_resources.\n");
680}
681
682#if CONFIG_HW_MEM_HOLE_SIZEK != 0
683struct hw_mem_hole_info {
684 unsigned hole_startk;
685 int node_id;
686};
687static struct hw_mem_hole_info get_hw_mem_hole_info(void)
688{
689 struct hw_mem_hole_info mem_hole;
690 int i;
691 mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK;
692 mem_hole.node_id = -1;
693 for (i = 0; i < node_nums; i++) {
694 dram_base_mask_t d;
695 u32 hole;
696 d = get_dram_base_mask(i);
697 if (!(d.mask & 1)) continue; // no memory on this node
698 hole = pci_read_config32(__f1_dev[i], 0xf0);
699 if (hole & 2) { // we find the hole
700 mem_hole.hole_startk = (hole & (0xff<<24)) >> 10;
701 mem_hole.node_id = i; // record the node No with hole
702 break; // only one hole
703 }
704 }
705
706 /* We need to double check if there is special set on base reg and limit reg
707 * are not continuous instead of hole, it will find out its hole_startk.
708 */
709 if (mem_hole.node_id == -1) {
710 resource_t limitk_pri = 0;
Elyes HAOUASa8131602016-09-19 10:27:57 -0600711 for (i = 0; i < node_nums; i++) {
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600712 dram_base_mask_t d;
713 resource_t base_k, limit_k;
714 d = get_dram_base_mask(i);
715 if (!(d.base & 1)) continue;
716 base_k = ((resource_t)(d.base & 0x1fffff00)) <<9;
717 if (base_k > 4 *1024 * 1024) break; // don't need to go to check
718 if (limitk_pri != base_k) { // we find the hole
719 mem_hole.hole_startk = (unsigned)limitk_pri; // must beblow 4G
720 mem_hole.node_id = i;
721 break; //only one hole
722 }
723 limit_k = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
724 limitk_pri = limit_k;
725 }
726 }
727 return mem_hole;
728}
729#endif
730
731#define ONE_MB_SHIFT 20
732#define ONE_GB_SHIFT 30
733
734static void setup_uma_memory(void)
735{
736#if CONFIG_GFXUMA
737 uint64_t topmem = bsp_topmem();
738 uint64_t topmem2 = bsp_topmem2();
739 uint32_t sysmem_mb, sysmem_gb;
740
741 /* refer to UMA_AUTO size computation in Family16h BKDG. */
742 /* Please reference MemNGetUmaSizeML() */
743 /*
744 * Total system memory UMASize
745 * >= 6G 1024M
746 * >= 4G 512M
747 * >= 2G 256M
748 * < 2G 128M
749 */
750
751 sysmem_mb = (topmem + (16ull << ONE_MB_SHIFT)) >> ONE_MB_SHIFT; // Ignore 16MB allocated for C6 when finding UMA size
752 sysmem_mb += topmem2 ? ((topmem2 >> ONE_MB_SHIFT) - 4096) : 0;
753 sysmem_gb = sysmem_mb >> (ONE_GB_SHIFT - ONE_MB_SHIFT);
754 printk(BIOS_SPEW, "%s: system memory size %luGB, topmem2 size %lluMB, topmem size %lluMB\n", __func__, (unsigned long)sysmem_gb, (topmem2 >> ONE_MB_SHIFT), (topmem >> ONE_MB_SHIFT));
755 if (sysmem_gb >= 6) {
756 uma_memory_size = 1024 << ONE_MB_SHIFT;
757 } else if (sysmem_gb >= 4) {
758 uma_memory_size = 512 << ONE_MB_SHIFT;
759 } else if (sysmem_gb >= 2) {
760 uma_memory_size = 256 << ONE_MB_SHIFT;
761 } else {
762 uma_memory_size = 128 << ONE_MB_SHIFT;
763 }
764 uma_memory_base = topmem - uma_memory_size; /* TOP_MEM1 */
765
766 printk(BIOS_INFO, "%s: uma size 0x%08llx, memory start 0x%08llx\n",
767 __func__, uma_memory_size, uma_memory_base);
768
769 /* TODO: TOP_MEM2 */
770#endif
771}
772
773
774static void domain_set_resources(device_t dev)
775{
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600776 unsigned long mmio_basek;
777 u32 pci_tolm;
778 u64 ramtop = 0;
779 int i, idx;
780 struct bus *link;
781#if CONFIG_HW_MEM_HOLE_SIZEK != 0
782 struct hw_mem_hole_info mem_hole;
783 u32 reset_memhole = 1;
784#endif
785
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600786 pci_tolm = 0xffffffffUL;
787 for (link = dev->link_list; link; link = link->next) {
788 pci_tolm = find_pci_tolm(link);
789 }
790
791 // FIXME handle interleaved nodes. If you fix this here, please fix
792 // amdk8, too.
793 mmio_basek = pci_tolm >> 10;
794 /* Round mmio_basek to something the processor can support */
795 mmio_basek &= ~((1 << 6) -1);
796
797 // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M
798 // MMIO hole. If you fix this here, please fix amdk8, too.
799 /* Round the mmio hole to 64M */
800 mmio_basek &= ~((64*1024) - 1);
801
802#if CONFIG_HW_MEM_HOLE_SIZEK != 0
803 /* if the hw mem hole is already set in raminit stage, here we will compare
804 * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will
805 * use hole_basek as mmio_basek and we don't need to reset hole.
806 * otherwise We reset the hole to the mmio_basek
807 */
808
809 mem_hole = get_hw_mem_hole_info();
810
811 // Use hole_basek as mmio_basek, and we don't need to reset hole anymore
812 if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) {
813 mmio_basek = mem_hole.hole_startk;
814 reset_memhole = 0;
815 }
816#endif
817
818 idx = 0x10;
819 for (i = 0; i < node_nums; i++) {
820 dram_base_mask_t d;
821 resource_t basek, limitk, sizek; // 4 1T
822
823 d = get_dram_base_mask(i);
824
825 if (!(d.mask & 1)) continue;
826 basek = ((resource_t)(d.base & 0x1fffff00)) << 9; // could overflow, we may lost 6 bit here
827 limitk = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9 ;
828
829 sizek = limitk - basek;
830
831 /* see if we need a hole from 0xa0000 to 0xbffff */
832 if ((basek < ((8*64)+(8*16))) && (sizek > ((8*64)+(16*16)))) {
833 ram_resource(dev, (idx | i), basek, ((8*64)+(8*16)) - basek);
834 idx += 0x10;
835 basek = (8*64)+(16*16);
836 sizek = limitk - ((8*64)+(16*16));
837
838 }
839
840 //printk(BIOS_DEBUG, "node %d : mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", i, mmio_basek, basek, limitk);
841
842 /* split the region to accommodate pci memory space */
Elyes HAOUASa8131602016-09-19 10:27:57 -0600843 if ((basek < 4*1024*1024) && (limitk > mmio_basek)) {
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600844 if (basek <= mmio_basek) {
845 unsigned pre_sizek;
846 pre_sizek = mmio_basek - basek;
Elyes HAOUASa8131602016-09-19 10:27:57 -0600847 if (pre_sizek > 0) {
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600848 ram_resource(dev, (idx | i), basek, pre_sizek);
849 idx += 0x10;
850 sizek -= pre_sizek;
851 if (!ramtop)
852 ramtop = mmio_basek * 1024;
853 }
854 basek = mmio_basek;
855 }
856 if ((basek + sizek) <= 4*1024*1024) {
857 sizek = 0;
858 }
859 else {
860 uint64_t topmem2 = bsp_topmem2();
861 basek = 4*1024*1024;
862 sizek = topmem2/1024 - basek;
863 }
864 }
865
866 ram_resource(dev, (idx | i), basek, sizek);
867 idx += 0x10;
868 printk(BIOS_DEBUG, "node %d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n",
869 i, mmio_basek, basek, limitk);
870 if (!ramtop)
871 ramtop = limitk * 1024;
872 }
873
874#if CONFIG_GFXUMA
875 set_top_of_ram(uma_memory_base);
876 uma_resource(dev, 7, uma_memory_base >> 10, uma_memory_size >> 10);
877#else
878 set_top_of_ram(ramtop);
879#endif
880
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200881 for (link = dev->link_list; link; link = link->next) {
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600882 if (link->children) {
883 assign_resources(link);
884 }
885 }
886}
887
888static struct device_operations pci_domain_ops = {
889 .read_resources = domain_read_resources,
890 .set_resources = domain_set_resources,
891 .enable_resources = domain_enable_resources,
892 .init = NULL,
893 .scan_bus = pci_domain_scan_bus,
894 .ops_pci_bus = pci_bus_default_ops,
895};
896
897static void sysconf_init(device_t dev) // first node
898{
899 sblink = (pci_read_config32(dev, 0x64)>>8) & 7; // don't forget sublink1
900 node_nums = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; //NodeCnt[2:0]
901}
902
903static void add_more_links(device_t dev, unsigned total_links)
904{
905 struct bus *link, *last = NULL;
906 int link_num;
907
908 for (link = dev->link_list; link; link = link->next)
909 last = link;
910
911 if (last) {
912 int links = total_links - last->link_num;
913 link_num = last->link_num;
914 if (links > 0) {
915 link = malloc(links*sizeof(*link));
916 if (!link)
917 die("Couldn't allocate more links!\n");
918 memset(link, 0, links*sizeof(*link));
919 last->next = link;
920 }
921 }
922 else {
923 link_num = -1;
924 link = malloc(total_links*sizeof(*link));
925 memset(link, 0, total_links*sizeof(*link));
926 dev->link_list = link;
927 }
928
929 for (link_num = link_num + 1; link_num < total_links; link_num++) {
930 link->link_num = link_num;
931 link->dev = dev;
932 link->next = link + 1;
933 last = link;
934 link = link->next;
935 }
936 last->next = NULL;
937}
938
Kyösti Mälkki580e7222015-03-19 21:04:23 +0200939static void cpu_bus_scan(device_t dev)
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600940{
941 struct bus *cpu_bus;
942 device_t dev_mc;
943#if CONFIG_CBB
944 device_t pci_domain;
945#endif
946 int i,j;
947 int coreid_bits;
948 int core_max = 0;
949 unsigned ApicIdCoreIdSize;
950 unsigned core_nums;
951 int siblings = 0;
952 unsigned int family;
953 u32 modules = 0;
954 VOID* modules_ptr = &modules;
955 BUILD_OPT_CFG* options = NULL;
956 int ioapic_count = 0;
957
958 // TODO Remove the printk's.
959 printk(BIOS_SPEW, "MullinsPI Debug: Grabbing the AMD Topology Information.\n");
960 AmdGetValue(AMD_GLOBAL_USER_OPTIONS, (VOID**)&options, sizeof(options));
961 AmdGetValue(AMD_GLOBAL_NUM_MODULES, &modules_ptr, sizeof(modules));
Alexandru Gagniuc2e0cf142014-12-28 20:38:32 -0600962 modules = *(u32*)modules_ptr;
Bruce Griffith27ed80b2014-08-15 11:46:25 -0600963 ASSERT(modules > 0);
964 ASSERT(options);
965 ioapic_count = (int)options->CfgPlatNumIoApics;
966 ASSERT(ioapic_count > 0);
967 printk(BIOS_SPEW, "MullinsPI Debug: AMD Topology Number of Modules (@0x%p) is %d\n", modules_ptr, modules);
968 printk(BIOS_SPEW, "MullinsPI Debug: AMD Topology Number of IOAPICs (@0x%p) is %d\n", options, (int)options->CfgPlatNumIoApics);
969
970#if CONFIG_CBB
971 dev_mc = dev_find_slot(0, PCI_DEVFN(CONFIG_CDB, 0)); //0x00
972 if (dev_mc && dev_mc->bus) {
973 printk(BIOS_DEBUG, "%s found", dev_path(dev_mc));
974 pci_domain = dev_mc->bus->dev;
975 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
976 printk(BIOS_DEBUG, "\n%s move to ",dev_path(dev_mc));
977 dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
978 printk(BIOS_DEBUG, "%s",dev_path(dev_mc));
979 } else {
980 printk(BIOS_DEBUG, " but it is not under pci_domain directly ");
981 }
982 printk(BIOS_DEBUG, "\n");
983 }
984 dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
985 if (!dev_mc) {
986 dev_mc = dev_find_slot(0, PCI_DEVFN(0x18, 0));
987 if (dev_mc && dev_mc->bus) {
988 printk(BIOS_DEBUG, "%s found\n", dev_path(dev_mc));
989 pci_domain = dev_mc->bus->dev;
990 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
991 if ((pci_domain->link_list) && (pci_domain->link_list->children == dev_mc)) {
992 printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
993 dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff
994 printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
995 while (dev_mc) {
996 printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc));
997 dev_mc->path.pci.devfn -= PCI_DEVFN(0x18,0);
998 printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc));
999 dev_mc = dev_mc->sibling;
1000 }
1001 }
1002 }
1003 }
1004 }
1005#endif
1006 dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0));
1007 if (!dev_mc) {
1008 printk(BIOS_ERR, "%02x:%02x.0 not found", CONFIG_CBB, CONFIG_CDB);
1009 die("");
1010 }
1011 sysconf_init(dev_mc);
1012#if CONFIG_CBB && (MAX_NODE_NUMS > 32)
Elyes HAOUASa8131602016-09-19 10:27:57 -06001013 if (node_nums > 32) { // need to put node 32 to node 63 to bus 0xfe
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001014 if (pci_domain->link_list && !pci_domain->link_list->next) {
1015 struct bus *new_link = new_link(pci_domain);
1016 pci_domain->link_list->next = new_link;
1017 new_link->link_num = 1;
1018 new_link->dev = pci_domain;
1019 new_link->children = 0;
1020 printk(BIOS_DEBUG, "%s links now 2\n", dev_path(pci_domain));
1021 }
1022 pci_domain->link_list->next->secondary = CONFIG_CBB - 1;
1023 }
1024#endif
1025
1026 /* Get Max Number of cores(MNC) */
1027 coreid_bits = (cpuid_ecx(AMD_CPUID_ASIZE_PCCOUNT) & 0x0000F000) >> 12;
1028 core_max = 1 << (coreid_bits & 0x000F); //mnc
1029
1030 ApicIdCoreIdSize = ((cpuid_ecx(0x80000008)>>12) & 0xF);
1031 if (ApicIdCoreIdSize) {
1032 core_nums = (1 << ApicIdCoreIdSize) - 1;
1033 } else {
1034 core_nums = 3; //quad core
1035 }
1036
1037 /* Find which cpus are present */
1038 cpu_bus = dev->link_list;
1039 for (i = 0; i < node_nums; i++) {
1040 device_t cdb_dev;
1041 unsigned busn, devn;
1042 struct bus *pbus;
1043
1044 busn = CONFIG_CBB;
1045 devn = CONFIG_CDB + i;
1046 pbus = dev_mc->bus;
1047#if CONFIG_CBB && (MAX_NODE_NUMS > 32)
1048 if (i >= 32) {
1049 busn--;
1050 devn -= 32;
1051 pbus = pci_domain->link_list->next;
1052 }
1053#endif
1054
1055 /* Find the cpu's pci device */
1056 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0));
1057 if (!cdb_dev) {
1058 /* If I am probing things in a weird order
1059 * ensure all of the cpu's pci devices are found.
1060 */
1061 int fn;
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +02001062 for (fn = 0; fn <= 5; fn++) { //FBDIMM?
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001063 cdb_dev = pci_probe_dev(NULL, pbus,
1064 PCI_DEVFN(devn, fn));
1065 }
1066 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0));
1067 } else {
1068 /* Ok, We need to set the links for that device.
1069 * otherwise the device under it will not be scanned
1070 */
Kyösti Mälkkic5163ed82015-02-04 13:25:37 +02001071
1072 add_more_links(cdb_dev, 4);
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001073 }
1074
1075 family = cpuid_eax(1);
1076 family = (family >> 20) & 0xFF;
1077 if (family == 1) { //f10
1078 u32 dword;
1079 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 3));
1080 dword = pci_read_config32(cdb_dev, 0xe8);
1081 siblings = ((dword & BIT15) >> 13) | ((dword & (BIT13 | BIT12)) >> 12);
1082 } else if (family == 7) {//f16
1083 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 5));
1084 if (cdb_dev && cdb_dev->enabled) {
1085 siblings = pci_read_config32(cdb_dev, 0x84);
1086 siblings &= 0xFF;
1087 }
1088 } else {
1089 siblings = 0; //default one core
1090 }
1091 int enable_node = cdb_dev && cdb_dev->enabled;
Elyes HAOUASa8131602016-09-19 10:27:57 -06001092 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 -06001093 dev_path(cdb_dev), 0x0f + family, core_max, core_nums, siblings);
1094
Elyes HAOUASa8131602016-09-19 10:27:57 -06001095 for (j = 0; j <= siblings; j++) {
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001096 u32 lapicid_start = 0;
1097
1098 /*
1099 * APIC ID calucation is tightly coupled with AGESA v5 code.
1100 * This calculation MUST match the assignment calculation done
1101 * in LocalApicInitializationAtEarly() function.
1102 * And reference GetLocalApicIdForCore()
1103 *
1104 * Apply apic enumeration rules
1105 * For systems with >= 16 APICs, put the IO-APICs at 0..n and
1106 * put the local-APICs at m..z
1107 *
1108 * This is needed because many IO-APIC devices only have 4 bits
1109 * for their APIC id and therefore must reside at 0..15
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +02001110 */
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001111 if ((node_nums * core_max) + ioapic_count >= 0x10) {
1112 lapicid_start = (ioapic_count - 1) / core_max;
1113 lapicid_start = (lapicid_start + 1) * core_max;
Elyes HAOUASa8131602016-09-19 10:27:57 -06001114 printk(BIOS_SPEW, "lpaicid_start = 0x%x ", lapicid_start);
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001115 }
1116 u32 apic_id = (lapicid_start * (i/modules + 1)) + ((i % modules) ? (j + (siblings + 1)) : j);
Elyes HAOUASa8131602016-09-19 10:27:57 -06001117 printk(BIOS_SPEW, "node 0x%x core 0x%x apicid = 0x%x\n",
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001118 i, j, apic_id);
1119
1120 device_t cpu = add_cpu_device(cpu_bus, apic_id, enable_node);
1121 if (cpu)
1122 amd_cpu_topology(cpu, i, j);
1123 } //j
1124 }
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001125}
1126
1127static void cpu_bus_init(device_t dev)
1128{
1129 initialize_cpus(dev->link_list);
1130}
1131
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001132static void cpu_bus_read_resources(device_t dev)
1133{
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001134}
1135
1136static void cpu_bus_set_resources(device_t dev)
1137{
1138 struct resource *resource = find_resource(dev, 0xc0010058);
1139 if (resource) {
1140 report_resource_stored(dev, resource, " <mmconfig>");
1141 }
1142 pci_dev_set_resources(dev);
1143}
1144
1145static struct device_operations cpu_bus_ops = {
1146 .read_resources = cpu_bus_read_resources,
1147 .set_resources = cpu_bus_set_resources,
Edward O'Callaghan812d2a42014-10-31 08:17:23 +11001148 .enable_resources = DEVICE_NOOP,
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001149 .init = cpu_bus_init,
1150 .scan_bus = cpu_bus_scan,
1151};
1152
1153static void root_complex_enable_dev(struct device *dev)
1154{
1155 static int done = 0;
1156
1157 /* Do not delay UMA setup, as a device on the PCI bus may evaluate
1158 the global uma_memory variables already in its enable function. */
1159 if (!done) {
1160 setup_bsp_ramtop();
1161 setup_uma_memory();
1162 done = 1;
1163 }
1164
1165 /* Set the operations if it is a special bus type */
1166 if (dev->path.type == DEVICE_PATH_DOMAIN) {
1167 dev->ops = &pci_domain_ops;
1168 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
1169 dev->ops = &cpu_bus_ops;
1170 }
1171}
1172
Kyösti Mälkkie4c17ce2014-10-21 18:22:32 +03001173struct chip_operations northbridge_amd_pi_00730F01_root_complex_ops = {
Bruce Griffith27ed80b2014-08-15 11:46:25 -06001174 CHIP_NAME("AMD FAM16 Root Complex")
1175 .enable_dev = root_complex_enable_dev,
1176};
1177
1178/*********************************************************************
1179 * Change the vendor / device IDs to match the generic VBIOS header. *
1180 *********************************************************************/
1181u32 map_oprom_vendev(u32 vendev)
1182{
1183 u32 new_vendev;
1184 new_vendev =
1185 ((0x10029850 <= vendev) && (vendev <= 0x1002986F)) ? 0x10029850 : vendev;
1186
1187 if (vendev != new_vendev)
1188 printk(BIOS_NOTICE, "Mapping PCI device %8x to %8x\n", vendev, new_vendev);
1189
1190 return new_vendev;
1191}