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