blob: c8909fb0091ccdead4ebf1f250d7f85aa571ebe0 [file] [log] [blame]
zbao2c08f6a2012-07-02 15:32:58 +08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2012 Advanced Micro Devices, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
zbao2c08f6a2012-07-02 15:32:58 +080014 */
15
16#include <console/console.h>
17#include <arch/io.h>
Kyösti Mälkki8ae16a42014-06-19 20:44:34 +030018#include <arch/acpi.h>
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +020019#include <arch/acpigen.h>
zbao2c08f6a2012-07-02 15:32:58 +080020#include <stdint.h>
21#include <device/device.h>
22#include <device/pci.h>
23#include <device/pci_ids.h>
24#include <device/hypertransport.h>
25#include <stdlib.h>
26#include <string.h>
Ronald G. Minnich5079a0d2012-11-27 11:32:38 -080027#include <lib.h>
zbao2c08f6a2012-07-02 15:32:58 +080028#include <cpu/cpu.h>
29#include <cbmem.h>
Martin Roth73e86a82013-01-17 16:28:30 -070030#include <AGESA.h>
zbao2c08f6a2012-07-02 15:32:58 +080031
32#include <cpu/x86/lapic.h>
Kyösti Mälkkidbc47392012-08-05 12:11:40 +030033#include <cpu/amd/mtrr.h>
zbao2c08f6a2012-07-02 15:32:58 +080034
35#include <Porting.h>
zbao2c08f6a2012-07-02 15:32:58 +080036#include <Options.h>
37#include <Topology.h>
38#include <cpu/amd/amdfam15.h>
39#include <cpuRegisters.h>
Kyösti Mälkkid610c582017-03-05 06:28:18 +020040
Kyösti Mälkkif21c2ac2014-10-19 09:35:18 +030041#include <northbridge/amd/agesa/agesawrapper.h>
Kyösti Mälkkid610c582017-03-05 06:28:18 +020042#include <northbridge/amd/agesa/agesa_helper.h>
zbao2c08f6a2012-07-02 15:32:58 +080043
44#define MAX_NODE_NUMS (MAX_NODES * MAX_DIES)
45
zbao2c08f6a2012-07-02 15:32:58 +080046typedef struct dram_base_mask {
47 u32 base; //[47:27] at [28:8]
48 u32 mask; //[47:27] at [28:8] and enable at bit 0
49} dram_base_mask_t;
50
51static unsigned node_nums;
52static unsigned sblink;
53static device_t __f0_dev[MAX_NODE_NUMS];
54static device_t __f1_dev[MAX_NODE_NUMS];
55static device_t __f2_dev[MAX_NODE_NUMS];
56static device_t __f4_dev[MAX_NODE_NUMS];
57static unsigned fx_devs = 0;
58
59static dram_base_mask_t get_dram_base_mask(u32 nodeid)
60{
61 device_t dev;
62 dram_base_mask_t d;
63 dev = __f1_dev[0];
64 u32 temp;
65 temp = pci_read_config32(dev, 0x44 + (nodeid << 3)); //[39:24] at [31:16]
66 d.mask = ((temp & 0xfff80000)>>(8+3)); // mask out DramMask [26:24] too
67 temp = pci_read_config32(dev, 0x144 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
68 d.mask |= temp<<21;
69 temp = pci_read_config32(dev, 0x40 + (nodeid << 3)); //[39:24] at [31:16]
70 d.mask |= (temp & 1); // enable bit
71 d.base = ((temp & 0xfff80000)>>(8+3)); // mask out DramBase [26:24) too
72 temp = pci_read_config32(dev, 0x140 + (nodeid <<3)) & 0xff; //[47:40] at [7:0]
73 d.base |= temp<<21;
74 return d;
75}
76
77static void set_io_addr_reg(device_t dev, u32 nodeid, u32 linkn, u32 reg,
78 u32 io_min, u32 io_max)
79{
80 u32 i;
81 u32 tempreg;
82 /* io range allocation */
83 tempreg = (nodeid&0xf) | ((nodeid & 0x30)<<(8-4)) | (linkn<<4) | ((io_max&0xf0)<<(12-4)); //limit
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020084 for (i = 0; i < node_nums; i++)
zbao2c08f6a2012-07-02 15:32:58 +080085 pci_write_config32(__f1_dev[i], reg+4, tempreg);
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020086 tempreg = 3 /*| (3<<4)*/ | ((io_min&0xf0)<<(12-4)); //base :ISA and VGA ?
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020087 for (i = 0; i < node_nums; i++)
zbao2c08f6a2012-07-02 15:32:58 +080088 pci_write_config32(__f1_dev[i], reg, tempreg);
89}
90
91static void set_mmio_addr_reg(u32 nodeid, u32 linkn, u32 reg, u32 index, u32 mmio_min, u32 mmio_max, u32 nodes)
92{
93 u32 i;
94 u32 tempreg;
95 /* io range allocation */
96 tempreg = (nodeid&0xf) | (linkn<<4) | (mmio_max&0xffffff00); //limit
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +020097 for (i = 0; i < nodes; i++)
zbao2c08f6a2012-07-02 15:32:58 +080098 pci_write_config32(__f1_dev[i], reg+4, tempreg);
99 tempreg = 3 | (nodeid & 0x30) | (mmio_min&0xffffff00);
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200100 for (i = 0; i < node_nums; i++)
zbao2c08f6a2012-07-02 15:32:58 +0800101 pci_write_config32(__f1_dev[i], reg, tempreg);
102}
103
104static device_t get_node_pci(u32 nodeid, u32 fn)
105{
zbaod4627362012-07-23 19:49:40 +0800106#if MAX_NODE_NUMS + CONFIG_CDB >= 32
107 if ((CONFIG_CDB + nodeid) < 32) {
zbao2c08f6a2012-07-02 15:32:58 +0800108 return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn));
109 } else {
110 return dev_find_slot(CONFIG_CBB-1, PCI_DEVFN(CONFIG_CDB + nodeid - 32, fn));
111 }
112#else
113 return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn));
114#endif
115}
116
117static void get_fx_devs(void)
118{
119 int i;
120 for (i = 0; i < MAX_NODE_NUMS; i++) {
121 __f0_dev[i] = get_node_pci(i, 0);
122 __f1_dev[i] = get_node_pci(i, 1);
123 __f2_dev[i] = get_node_pci(i, 2);
124 __f4_dev[i] = get_node_pci(i, 4);
125 if (__f0_dev[i] != NULL && __f1_dev[i] != NULL)
126 fx_devs = i+1;
127 }
128 if (__f1_dev[0] == NULL || __f0_dev[0] == NULL || fx_devs == 0) {
129 die("Cannot find 0:0x18.[0|1]\n");
130 }
131 printk(BIOS_DEBUG, "fx_devs=0x%x\n", fx_devs);
132}
133
134static u32 f1_read_config32(unsigned reg)
135{
136 if (fx_devs == 0)
137 get_fx_devs();
138 return pci_read_config32(__f1_dev[0], reg);
139}
140
141static void f1_write_config32(unsigned reg, u32 value)
142{
143 int i;
144 if (fx_devs == 0)
145 get_fx_devs();
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200146 for (i = 0; i < fx_devs; i++) {
zbao2c08f6a2012-07-02 15:32:58 +0800147 device_t dev;
148 dev = __f1_dev[i];
149 if (dev && dev->enabled) {
150 pci_write_config32(dev, reg, value);
151 }
152 }
153}
154
155static u32 amdfam15_nodeid(device_t dev)
156{
157#if MAX_NODE_NUMS == 64
158 unsigned busn;
159 busn = dev->bus->secondary;
160 if (busn != CONFIG_CBB) {
161 return (dev->path.pci.devfn >> 3) - CONFIG_CDB + 32;
162 } else {
163 return (dev->path.pci.devfn >> 3) - CONFIG_CDB;
164 }
165
166#else
167 return (dev->path.pci.devfn >> 3) - CONFIG_CDB;
168#endif
169}
170
171static void set_vga_enable_reg(u32 nodeid, u32 linkn)
172{
173 u32 val;
174
175 val = 1 | (nodeid<<4) | (linkn<<12);
176 /* it will routing
177 * (1)mmio 0xa0000:0xbffff
178 * (2)io 0x3b0:0x3bb, 0x3c0:0x3df
179 */
180 f1_write_config32(0xf4, val);
181
182}
183
184/**
185 * @return
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100186 * @retval 2 resoure does not exist, usable
187 * @retval 0 resource exists, not usable
zbao2c08f6a2012-07-02 15:32:58 +0800188 * @retval 1 resource exist, resource has been allocated before
189 */
190static int reg_useable(unsigned reg, device_t goal_dev, unsigned goal_nodeid,
191 unsigned goal_link)
192{
193 struct resource *res;
194 unsigned nodeid, link = 0;
195 int result;
196 res = 0;
197 for (nodeid = 0; !res && (nodeid < fx_devs); nodeid++) {
198 device_t dev;
199 dev = __f0_dev[nodeid];
200 if (!dev)
201 continue;
202 for (link = 0; !res && (link < 8); link++) {
203 res = probe_resource(dev, IOINDEX(0x1000 + reg, link));
204 }
205 }
206 result = 2;
207 if (res) {
208 result = 0;
209 if ((goal_link == (link - 1)) &&
210 (goal_nodeid == (nodeid - 1)) &&
211 (res->flags <= 1)) {
212 result = 1;
213 }
214 }
215 return result;
216}
217
218static struct resource *amdfam15_find_iopair(device_t dev, unsigned nodeid, unsigned link)
219{
220 struct resource *resource;
221 u32 free_reg, reg;
222 resource = 0;
223 free_reg = 0;
224 for (reg = 0xc0; reg <= 0xd8; reg += 0x8) {
225 int result;
226 result = reg_useable(reg, dev, nodeid, link);
227 if (result == 1) {
228 /* I have been allocated this one */
229 break;
230 }
231 else if (result > 1) {
232 /* I have a free register pair */
233 free_reg = reg;
234 }
235 }
236 if (reg > 0xd8) {
237 reg = free_reg; // if no free, the free_reg still be 0
238 }
239
240 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
241
242 return resource;
243}
244
245static struct resource *amdfam15_find_mempair(device_t dev, u32 nodeid, u32 link)
246{
247 struct resource *resource;
248 u32 free_reg, reg;
249 resource = 0;
250 free_reg = 0;
251 for (reg = 0x80; reg <= 0xb8; reg += 0x8) {
252 int result;
253 result = reg_useable(reg, dev, nodeid, link);
254 if (result == 1) {
255 /* I have been allocated this one */
256 break;
257 }
258 else if (result > 1) {
259 /* I have a free register pair */
260 free_reg = reg;
261 }
262 }
263 if (reg > 0xb8) {
264 reg = free_reg;
265 }
266
267 resource = new_resource(dev, IOINDEX(0x1000 + reg, link));
268 return resource;
269}
270
271static void amdfam15_link_read_bases(device_t dev, u32 nodeid, u32 link)
272{
273 struct resource *resource;
274
275 /* Initialize the io space constraints on the current bus */
276 resource = amdfam15_find_iopair(dev, nodeid, link);
277 if (resource) {
278 u32 align;
279 align = log2(HT_IO_HOST_ALIGN);
280 resource->base = 0;
281 resource->size = 0;
282 resource->align = align;
283 resource->gran = align;
284 resource->limit = 0xffffUL;
285 resource->flags = IORESOURCE_IO | IORESOURCE_BRIDGE;
286 }
287
288 /* Initialize the prefetchable memory constraints on the current bus */
289 resource = amdfam15_find_mempair(dev, nodeid, link);
290 if (resource) {
291 resource->base = 0;
292 resource->size = 0;
293 resource->align = log2(HT_MEM_HOST_ALIGN);
294 resource->gran = log2(HT_MEM_HOST_ALIGN);
295 resource->limit = 0xffffffffffULL;
296 resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH;
297 resource->flags |= IORESOURCE_BRIDGE;
298 }
299
300 /* Initialize the memory constraints on the current bus */
301 resource = amdfam15_find_mempair(dev, nodeid, link);
302 if (resource) {
303 resource->base = 0;
304 resource->size = 0;
305 resource->align = log2(HT_MEM_HOST_ALIGN);
306 resource->gran = log2(HT_MEM_HOST_ALIGN);
307 resource->limit = 0xffffffffffULL;
308 resource->flags = IORESOURCE_MEM | IORESOURCE_BRIDGE;
309 }
310
311}
312
Steven Sherkf4340582013-01-29 16:13:35 -0700313static void nb_read_resources(device_t dev)
zbao2c08f6a2012-07-02 15:32:58 +0800314{
315 u32 nodeid;
316 struct bus *link;
317
318 nodeid = amdfam15_nodeid(dev);
319 for (link = dev->link_list; link; link = link->next) {
320 if (link->children) {
321 amdfam15_link_read_bases(dev, nodeid, link->link_num);
322 }
323 }
Steven Sherk1cbabb02013-02-01 09:22:35 -0700324
325 /*
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800326 * This MMCONF resource must be reserved in the PCI domain.
Steven Sherk1cbabb02013-02-01 09:22:35 -0700327 * It is not honored by the coreboot resource allocator if it is in
Stefan Reinauer0aa37c42013-02-12 15:20:54 -0800328 * the CPU_CLUSTER.
Steven Sherk1cbabb02013-02-01 09:22:35 -0700329 */
Kyösti Mälkkie25b5ef2016-12-02 08:56:05 +0200330 mmconf_resource(dev, 0xc0010058);
zbao2c08f6a2012-07-02 15:32:58 +0800331}
332
333static void set_resource(device_t dev, struct resource *resource, u32 nodeid)
334{
335 resource_t rbase, rend;
336 unsigned reg, link_num;
337 char buf[50];
338
339 /* Make certain the resource has actually been set */
340 if (!(resource->flags & IORESOURCE_ASSIGNED)) {
341 return;
342 }
343
344 /* If I have already stored this resource don't worry about it */
345 if (resource->flags & IORESOURCE_STORED) {
346 return;
347 }
348
349 /* Only handle PCI memory and IO resources */
350 if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO)))
351 return;
352
353 /* Ensure I am actually looking at a resource of function 1 */
354 if ((resource->index & 0xffff) < 0x1000) {
355 return;
356 }
357 /* Get the base address */
358 rbase = resource->base;
359
360 /* Get the limit (rounded up) */
361 rend = resource_end(resource);
362
363 /* Get the register and link */
364 reg = resource->index & 0xfff; // 4k
365 link_num = IOINDEX_LINK(resource->index);
366
367 if (resource->flags & IORESOURCE_IO) {
368 set_io_addr_reg(dev, nodeid, link_num, reg, rbase>>8, rend>>8);
369 }
370 else if (resource->flags & IORESOURCE_MEM) {
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100371 set_mmio_addr_reg(nodeid, link_num, reg, (resource->index >>24), rbase>>8, rend>>8, node_nums);// [39:8]
zbao2c08f6a2012-07-02 15:32:58 +0800372 }
373 resource->flags |= IORESOURCE_STORED;
Elyes HAOUAS0d4b11a2016-10-03 21:57:21 +0200374 snprintf(buf, sizeof(buf), " <node %x link %x>",
zbao2c08f6a2012-07-02 15:32:58 +0800375 nodeid, link_num);
376 report_resource_stored(dev, resource, buf);
377}
378
379/**
380 * I tried to reuse the resource allocation code in set_resource()
381 * but it is too difficult to deal with the resource allocation magic.
382 */
383
384static void create_vga_resource(device_t dev, unsigned nodeid)
385{
386 struct bus *link;
387
388 /* find out which link the VGA card is connected,
389 * we only deal with the 'first' vga card */
390 for (link = dev->link_list; link; link = link->next) {
391 if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) {
zbaod59d6242012-07-23 19:41:03 +0800392#if CONFIG_MULTIPLE_VGA_ADAPTERS
zbao2c08f6a2012-07-02 15:32:58 +0800393 extern device_t vga_pri; // the primary vga device, defined in device.c
394 printk(BIOS_DEBUG, "VGA: vga_pri bus num = %d bus range [%d,%d]\n", vga_pri->bus->secondary,
395 link->secondary,link->subordinate);
396 /* We need to make sure the vga_pri is under the link */
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200397 if ((vga_pri->bus->secondary >= link->secondary) &&
398 (vga_pri->bus->secondary <= link->subordinate))
zbao2c08f6a2012-07-02 15:32:58 +0800399#endif
400 break;
401 }
402 }
403
404 /* no VGA card installed */
405 if (link == NULL)
406 return;
407
408 printk(BIOS_DEBUG, "VGA: %s (aka node %d) link %d has VGA device\n", dev_path(dev), nodeid, sblink);
409 set_vga_enable_reg(nodeid, sblink);
410}
411
Steven Sherkf4340582013-01-29 16:13:35 -0700412static void nb_set_resources(device_t dev)
zbao2c08f6a2012-07-02 15:32:58 +0800413{
414 unsigned nodeid;
415 struct bus *bus;
416 struct resource *res;
417
418 /* Find the nodeid */
419 nodeid = amdfam15_nodeid(dev);
420
421 create_vga_resource(dev, nodeid); //TODO: do we need this?
422
423 /* Set each resource we have found */
424 for (res = dev->resource_list; res; res = res->next) {
425 set_resource(dev, res, nodeid);
426 }
427
428 for (bus = dev->link_list; bus; bus = bus->next) {
429 if (bus->children) {
430 assign_resources(bus);
431 }
432 }
433}
434
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100435
436static unsigned long acpi_fill_hest(acpi_hest_t *hest)
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200437{
438 void *addr, *current;
439
440 /* Skip the HEST header. */
441 current = (void *)(hest + 1);
442
443 addr = agesawrapper_getlateinitptr(PICK_WHEA_MCE);
444 if (addr != NULL)
Stefan Reinauer77a1d1a2015-07-21 12:48:17 -0700445 current += acpi_create_hest_error_source(hest, current, 0,
446 addr + 2, *(UINT16 *)addr - 2);
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200447
448 addr = agesawrapper_getlateinitptr(PICK_WHEA_CMC);
449 if (addr != NULL)
Stefan Reinauer77a1d1a2015-07-21 12:48:17 -0700450 current += acpi_create_hest_error_source(hest, current, 1,
451 addr + 2, *(UINT16 *)addr - 2);
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200452
453 return (unsigned long)current;
454}
455
Alexander Couzens5eea4582015-04-12 22:18:55 +0200456static void northbridge_fill_ssdt_generator(device_t device)
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200457{
458 msr_t msr;
459 char pscope[] = "\\_SB.PCI0";
460
461 acpigen_write_scope(pscope);
462 msr = rdmsr(TOP_MEM);
463 acpigen_write_name_dword("TOM1", msr.lo);
464 msr = rdmsr(TOP_MEM2);
465 /*
466 * Since XP only implements parts of ACPI 2.0, we can't use a qword
467 * here.
468 * See http://www.acpi.info/presentations/S01USMOBS169_OS%2520new.ppt
469 * slide 22ff.
470 * Shift value right by 20 bit to make it fit into 32bit,
471 * giving us 1MB granularity and a limit of almost 4Exabyte of memory.
472 */
473 acpigen_write_name_dword("TOM2", (msr.hi << 12) | msr.lo >> 20);
474 acpigen_pop_len();
475}
476
Alexander Couzens83fc32f2015-04-12 22:28:37 +0200477static unsigned long agesa_write_acpi_tables(device_t device,
478 unsigned long current,
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200479 acpi_rsdp_t *rsdp)
480{
481 acpi_srat_t *srat;
482 acpi_slit_t *slit;
483 acpi_header_t *ssdt;
484 acpi_header_t *alib;
485 acpi_header_t *ivrs;
486 acpi_hest_t *hest;
487
488 /* HEST */
489 current = ALIGN(current, 8);
490 hest = (acpi_hest_t *)current;
Vladimir Serbinenko807127f2014-11-09 13:36:18 +0100491 acpi_write_hest((void *)current, acpi_fill_hest);
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200492 acpi_add_table(rsdp, (void *)current);
493 current += ((acpi_header_t *)current)->length;
494
495 current = ALIGN(current, 8);
496 printk(BIOS_DEBUG, "ACPI: * IVRS at %lx\n", current);
497 ivrs = agesawrapper_getlateinitptr(PICK_IVRS);
498 if (ivrs != NULL) {
499 memcpy((void *)current, ivrs, ivrs->length);
500 ivrs = (acpi_header_t *) current;
501 current += ivrs->length;
502 acpi_add_table(rsdp, ivrs);
503 } else {
504 printk(BIOS_DEBUG, " AGESA IVRS table NULL. Skipping.\n");
505 }
506
507 /* SRAT */
508 current = ALIGN(current, 8);
509 printk(BIOS_DEBUG, "ACPI: * SRAT at %lx\n", current);
510 srat = (acpi_srat_t *) agesawrapper_getlateinitptr (PICK_SRAT);
511 if (srat != NULL) {
512 memcpy((void *)current, srat, srat->header.length);
513 srat = (acpi_srat_t *) current;
514 current += srat->header.length;
515 acpi_add_table(rsdp, srat);
516 } else {
517 printk(BIOS_DEBUG, " AGESA SRAT table NULL. Skipping.\n");
518 }
519
520 /* SLIT */
521 current = ALIGN(current, 8);
522 printk(BIOS_DEBUG, "ACPI: * SLIT at %lx\n", current);
523 slit = (acpi_slit_t *) agesawrapper_getlateinitptr (PICK_SLIT);
524 if (slit != NULL) {
525 memcpy((void *)current, slit, slit->header.length);
526 slit = (acpi_slit_t *) current;
527 current += slit->header.length;
528 acpi_add_table(rsdp, slit);
529 } else {
530 printk(BIOS_DEBUG, " AGESA SLIT table NULL. Skipping.\n");
531 }
532
533 /* ALIB */
534 current = ALIGN(current, 16);
535 printk(BIOS_DEBUG, "ACPI: * AGESA ALIB SSDT at %lx\n", current);
536 alib = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_ALIB);
537 if (alib != NULL) {
538 memcpy((void *)current, alib, alib->length);
539 alib = (acpi_header_t *) current;
540 current += alib->length;
541 acpi_add_table(rsdp, (void *)alib);
542 }
543 else {
544 printk(BIOS_DEBUG, " AGESA ALIB SSDT table NULL. Skipping.\n");
545 }
546
547 /* this pstate ssdt may cause Blue Screen: Fixed: Keep this comment for a while. */
548 /* SSDT */
549 current = ALIGN(current, 16);
550 printk(BIOS_DEBUG, "ACPI: * SSDT at %lx\n", current);
551 ssdt = (acpi_header_t *)agesawrapper_getlateinitptr (PICK_PSTATE);
552 if (ssdt != NULL) {
553 memcpy((void *)current, ssdt, ssdt->length);
554 ssdt = (acpi_header_t *) current;
555 current += ssdt->length;
556 }
557 else {
558 printk(BIOS_DEBUG, " AGESA PState table NULL. Skipping.\n");
559 }
560 acpi_add_table(rsdp,ssdt);
561
562 printk(BIOS_DEBUG, "ACPI: * SSDT for PState at %lx\n", current);
563
564 return current;
565}
566
567
zbao2c08f6a2012-07-02 15:32:58 +0800568static struct device_operations northbridge_operations = {
Steven Sherkf4340582013-01-29 16:13:35 -0700569 .read_resources = nb_read_resources,
570 .set_resources = nb_set_resources,
zbao2c08f6a2012-07-02 15:32:58 +0800571 .enable_resources = pci_dev_enable_resources,
Edward O'Callaghand994ef12014-11-21 02:22:33 +1100572 .init = DEVICE_NOOP,
Vladimir Serbinenko56f46d82014-10-08 22:06:27 +0200573 .acpi_fill_ssdt_generator = northbridge_fill_ssdt_generator,
574 .write_acpi_tables = agesa_write_acpi_tables,
zbao2c08f6a2012-07-02 15:32:58 +0800575 .enable = 0,
576 .ops_pci = 0,
577};
578
579static const struct pci_driver family15_northbridge __pci_driver = {
580 .ops = &northbridge_operations,
581 .vendor = PCI_VENDOR_ID_AMD,
Marshall Dawson463f46e2016-10-14 20:46:08 -0600582 .device = PCI_DEVICE_ID_AMD_15H_MODEL_101F_NB_HT,
zbao2c08f6a2012-07-02 15:32:58 +0800583};
584
585static const struct pci_driver family10_northbridge __pci_driver = {
586 .ops = &northbridge_operations,
587 .vendor = PCI_VENDOR_ID_AMD,
588 .device = PCI_DEVICE_ID_AMD_10H_NB_HT,
589};
590
591struct chip_operations northbridge_amd_agesa_family15tn_ops = {
592 CHIP_NAME("AMD FAM15 Northbridge")
593 .enable_dev = 0,
594};
595
596static void domain_read_resources(device_t dev)
597{
598 unsigned reg;
599
600 /* Find the already assigned resource pairs */
601 get_fx_devs();
602 for (reg = 0x80; reg <= 0xd8; reg+= 0x08) {
603 u32 base, limit;
604 base = f1_read_config32(reg);
605 limit = f1_read_config32(reg + 0x04);
606 /* Is this register allocated? */
607 if ((base & 3) != 0) {
608 unsigned nodeid, reg_link;
609 device_t reg_dev;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200610 if (reg < 0xc0) { // mmio
zbao2c08f6a2012-07-02 15:32:58 +0800611 nodeid = (limit & 0xf) + (base&0x30);
612 } else { // io
613 nodeid = (limit & 0xf) + ((base>>4)&0x30);
614 }
615 reg_link = (limit >> 4) & 7;
616 reg_dev = __f0_dev[nodeid];
617 if (reg_dev) {
618 /* Reserve the resource */
619 struct resource *res;
620 res = new_resource(reg_dev, IOINDEX(0x1000 + reg, reg_link));
621 if (res) {
622 res->flags = 1;
623 }
624 }
625 }
626 }
627 /* FIXME: do we need to check extend conf space?
628 I don't believe that much preset value */
629
zbao2c08f6a2012-07-02 15:32:58 +0800630 pci_domain_read_resources(dev);
zbao2c08f6a2012-07-02 15:32:58 +0800631}
632
zbao2c08f6a2012-07-02 15:32:58 +0800633static void domain_enable_resources(device_t dev)
634{
Kyösti Mälkki8ae16a42014-06-19 20:44:34 +0300635 if (acpi_is_wakeup_s3())
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300636 agesawrapper_fchs3laterestore();
zbao2c08f6a2012-07-02 15:32:58 +0800637
638 /* Must be called after PCI enumeration and resource allocation */
Kyösti Mälkkib139b5e2014-10-20 07:41:20 +0300639 if (!acpi_is_wakeup_s3()) {
640 /* Enable MMIO on AMD CPU Address Map Controller */
Kyösti Mälkki48518f02014-11-25 14:20:57 +0200641 amd_initcpuio();
zbao2c08f6a2012-07-02 15:32:58 +0800642
Kyösti Mälkki1aa35c62014-10-21 14:19:04 +0300643 agesawrapper_amdinitmid();
Kyösti Mälkkib139b5e2014-10-20 07:41:20 +0300644 }
Mike Loptiene133aab2013-01-30 16:00:43 -0700645 printk(BIOS_DEBUG, " ader - leaving %s.\n", __func__);
zbao2c08f6a2012-07-02 15:32:58 +0800646}
647
648#if CONFIG_HW_MEM_HOLE_SIZEK != 0
649struct hw_mem_hole_info {
650 unsigned hole_startk;
651 int node_id;
652};
653static struct hw_mem_hole_info get_hw_mem_hole_info(void)
654{
655 struct hw_mem_hole_info mem_hole;
656 int i;
657 mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK;
658 mem_hole.node_id = -1;
659 for (i = 0; i < node_nums; i++) {
660 dram_base_mask_t d;
661 u32 hole;
662 d = get_dram_base_mask(i);
663 if (!(d.mask & 1)) continue; // no memory on this node
664 hole = pci_read_config32(__f1_dev[i], 0xf0);
665 if (hole & 1) { // we find the hole
666 mem_hole.hole_startk = (hole & (0xff<<24)) >> 10;
667 mem_hole.node_id = i; // record the node No with hole
668 break; // only one hole
669 }
670 }
Kyösti Mälkki2f9b3af2014-06-26 05:30:54 +0300671
672 /* We need to double check if there is special set on base reg and limit reg
673 * are not continuous instead of hole, it will find out its hole_startk.
674 */
zbao2c08f6a2012-07-02 15:32:58 +0800675 if (mem_hole.node_id == -1) {
676 resource_t limitk_pri = 0;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200677 for (i = 0; i < node_nums; i++) {
zbao2c08f6a2012-07-02 15:32:58 +0800678 dram_base_mask_t d;
679 resource_t base_k, limit_k;
680 d = get_dram_base_mask(i);
681 if (!(d.base & 1)) continue;
682 base_k = ((resource_t)(d.base & 0x1fffff00)) <<9;
683 if (base_k > 4 *1024 * 1024) break; // don't need to go to check
684 if (limitk_pri != base_k) { // we find the hole
685 mem_hole.hole_startk = (unsigned)limitk_pri; // must beblow 4G
686 mem_hole.node_id = i;
687 break; //only one hole
688 }
zbao15dc3cc2012-08-03 15:56:21 +0800689 limit_k = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
zbao2c08f6a2012-07-02 15:32:58 +0800690 limitk_pri = limit_k;
691 }
692 }
693 return mem_hole;
694}
695#endif
696
zbao405cfe22012-07-23 19:44:29 +0800697#define ONE_MB_SHIFT 20
zbao6db7f342012-07-19 16:38:12 +0800698
Kyösti Mälkki6b5eb1c2012-07-19 19:26:43 +0300699static void setup_uma_memory(void)
zbao6db7f342012-07-19 16:38:12 +0800700{
701#if CONFIG_GFXUMA
Kyösti Mälkkidbc47392012-08-05 12:11:40 +0300702 uint32_t topmem = (uint32_t) bsp_topmem();
zbao6db7f342012-07-19 16:38:12 +0800703 uint32_t sys_mem;
704
zbao6db7f342012-07-19 16:38:12 +0800705 /* refer to UMA Size Consideration in Family15h BKDG. */
706 /* Please reference MemNGetUmaSizeOR () */
707 /*
708 * Total system memory UMASize
709 * >= 2G 512M
710 * >=1G 256M
711 * <1G 64M
712 */
Kyösti Mälkkidbc47392012-08-05 12:11:40 +0300713 sys_mem = topmem + (16 << ONE_MB_SHIFT); // Ignore 16MB allocated for C6 when finding UMA size
714 if ((bsp_topmem2()>>32) || (sys_mem >= 2048 << ONE_MB_SHIFT)) {
zbao405cfe22012-07-23 19:44:29 +0800715 uma_memory_size = 512 << ONE_MB_SHIFT;
716 } else if (sys_mem >= 1024 << ONE_MB_SHIFT) {
717 uma_memory_size = 256 << ONE_MB_SHIFT;
zbao6db7f342012-07-19 16:38:12 +0800718 } else {
zbao405cfe22012-07-23 19:44:29 +0800719 uma_memory_size = 64 << ONE_MB_SHIFT;
zbao6db7f342012-07-19 16:38:12 +0800720 }
Kyösti Mälkkidbc47392012-08-05 12:11:40 +0300721 uma_memory_base = topmem - uma_memory_size; /* TOP_MEM1 */
zbao6db7f342012-07-19 16:38:12 +0800722
723 printk(BIOS_INFO, "%s: uma size 0x%08llx, memory start 0x%08llx\n",
724 __func__, uma_memory_size, uma_memory_base);
zbao6db7f342012-07-19 16:38:12 +0800725#endif
726}
727
728
zbao2c08f6a2012-07-02 15:32:58 +0800729static void domain_set_resources(device_t dev)
730{
zbao2c08f6a2012-07-02 15:32:58 +0800731 unsigned long mmio_basek;
732 u32 pci_tolm;
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300733 u64 ramtop = 0;
zbao2c08f6a2012-07-02 15:32:58 +0800734 int i, idx;
735 struct bus *link;
736#if CONFIG_HW_MEM_HOLE_SIZEK != 0
737 struct hw_mem_hole_info mem_hole;
738 u32 reset_memhole = 1;
739#endif
740
zbao2c08f6a2012-07-02 15:32:58 +0800741 pci_tolm = 0xffffffffUL;
742 for (link = dev->link_list; link; link = link->next) {
743 pci_tolm = find_pci_tolm(link);
744 }
745
746 // FIXME handle interleaved nodes. If you fix this here, please fix
747 // amdk8, too.
748 mmio_basek = pci_tolm >> 10;
749 /* Round mmio_basek to something the processor can support */
750 mmio_basek &= ~((1 << 6) -1);
751
752 // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M
753 // MMIO hole. If you fix this here, please fix amdk8, too.
754 /* Round the mmio hole to 64M */
755 mmio_basek &= ~((64*1024) - 1);
756
757#if CONFIG_HW_MEM_HOLE_SIZEK != 0
758 /* if the hw mem hole is already set in raminit stage, here we will compare
759 * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will
760 * use hole_basek as mmio_basek and we don't need to reset hole.
761 * otherwise We reset the hole to the mmio_basek
762 */
763
764 mem_hole = get_hw_mem_hole_info();
765
766 // Use hole_basek as mmio_basek, and we don't need to reset hole anymore
767 if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) {
768 mmio_basek = mem_hole.hole_startk;
769 reset_memhole = 0;
770 }
771#endif
772
773 idx = 0x10;
774 for (i = 0; i < node_nums; i++) {
775 dram_base_mask_t d;
776 resource_t basek, limitk, sizek; // 4 1T
777
778 d = get_dram_base_mask(i);
779
780 if (!(d.mask & 1)) continue;
781 basek = ((resource_t)(d.base & 0x1fffff00)) << 9; // could overflow, we may lost 6 bit here
Edward O'Callaghanae5fd342014-11-20 19:58:09 +1100782 limitk = ((resource_t)(((d.mask & ~1) + 0x000FF) & 0x1fffff00)) << 9;
zbao2c08f6a2012-07-02 15:32:58 +0800783
784 sizek = limitk - basek;
785
786 /* see if we need a hole from 0xa0000 to 0xbffff */
787 if ((basek < ((8*64)+(8*16))) && (sizek > ((8*64)+(16*16)))) {
788 ram_resource(dev, (idx | i), basek, ((8*64)+(8*16)) - basek);
789 idx += 0x10;
790 basek = (8*64)+(16*16);
791 sizek = limitk - ((8*64)+(16*16));
792
793 }
794
Kyösti Mälkki26c65432014-06-26 05:30:54 +0300795 /* split the region to accommodate pci memory space */
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200796 if ((basek < 4*1024*1024) && (limitk > mmio_basek)) {
zbao2c08f6a2012-07-02 15:32:58 +0800797 if (basek <= mmio_basek) {
798 unsigned pre_sizek;
799 pre_sizek = mmio_basek - basek;
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +0200800 if (pre_sizek > 0) {
zbao2c08f6a2012-07-02 15:32:58 +0800801 ram_resource(dev, (idx | i), basek, pre_sizek);
802 idx += 0x10;
803 sizek -= pre_sizek;
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300804 if (!ramtop)
805 ramtop = mmio_basek * 1024;
zbao2c08f6a2012-07-02 15:32:58 +0800806 }
807 basek = mmio_basek;
808 }
809 if ((basek + sizek) <= 4*1024*1024) {
810 sizek = 0;
811 }
812 else {
Siyuan Wang29840e22013-06-04 19:56:22 +0800813 uint64_t topmem2 = bsp_topmem2();
zbao2c08f6a2012-07-02 15:32:58 +0800814 basek = 4*1024*1024;
Siyuan Wang29840e22013-06-04 19:56:22 +0800815 sizek = topmem2/1024 - basek;
zbao2c08f6a2012-07-02 15:32:58 +0800816 }
817 }
818
zbao2c08f6a2012-07-02 15:32:58 +0800819 ram_resource(dev, (idx | i), basek, sizek);
820 idx += 0x10;
zbao2c08f6a2012-07-02 15:32:58 +0800821 printk(BIOS_DEBUG, "node %d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n",
822 i, mmio_basek, basek, limitk);
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300823 if (!ramtop)
824 ramtop = limitk * 1024;
zbao2c08f6a2012-07-02 15:32:58 +0800825 }
826
Kyösti Mälkki63f8c082012-07-10 13:27:26 +0300827#if CONFIG_GFXUMA
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300828 set_top_of_ram(uma_memory_base);
Kyösti Mälkki63f8c082012-07-10 13:27:26 +0300829 uma_resource(dev, 7, uma_memory_base >> 10, uma_memory_size >> 10);
Kyösti Mälkki2b790f62013-09-03 05:25:57 +0300830#else
831 set_top_of_ram(ramtop);
zbao2c08f6a2012-07-02 15:32:58 +0800832#endif
833
Elyes HAOUAS5a7e72f2016-08-23 21:36:02 +0200834 for (link = dev->link_list; link; link = link->next) {
zbao2c08f6a2012-07-02 15:32:58 +0800835 if (link->children) {
836 assign_resources(link);
837 }
838 }
839}
840
841static struct device_operations pci_domain_ops = {
842 .read_resources = domain_read_resources,
843 .set_resources = domain_set_resources,
844 .enable_resources = domain_enable_resources,
Edward O'Callaghane9e1d7a2015-01-02 15:11:49 +1100845 .init = DEVICE_NOOP,
zbao2c08f6a2012-07-02 15:32:58 +0800846 .scan_bus = pci_domain_scan_bus,
Kyösti Mälkki872c9222013-07-03 09:44:28 +0300847 .ops_pci_bus = pci_bus_default_ops,
zbao2c08f6a2012-07-02 15:32:58 +0800848};
849
850static void sysconf_init(device_t dev) // first node
851{
852 sblink = (pci_read_config32(dev, 0x64)>>8) & 7; // don't forget sublink1
853 node_nums = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; //NodeCnt[2:0]
854}
855
856static void add_more_links(device_t dev, unsigned total_links)
857{
858 struct bus *link, *last = NULL;
859 int link_num;
860
861 for (link = dev->link_list; link; link = link->next)
862 last = link;
863
864 if (last) {
865 int links = total_links - last->link_num;
866 link_num = last->link_num;
867 if (links > 0) {
868 link = malloc(links*sizeof(*link));
869 if (!link)
870 die("Couldn't allocate more links!\n");
871 memset(link, 0, links*sizeof(*link));
872 last->next = link;
873 }
874 }
875 else {
876 link_num = -1;
877 link = malloc(total_links*sizeof(*link));
878 memset(link, 0, total_links*sizeof(*link));
879 dev->link_list = link;
880 }
881
882 for (link_num = link_num + 1; link_num < total_links; link_num++) {
883 link->link_num = link_num;
884 link->dev = dev;
885 link->next = link + 1;
886 last = link;
887 link = link->next;
888 }
889 last->next = NULL;
890}
891
Kyösti Mälkki580e7222015-03-19 21:04:23 +0200892static void cpu_bus_scan(device_t dev)
zbao2c08f6a2012-07-02 15:32:58 +0800893{
894 struct bus *cpu_bus;
895 device_t dev_mc;
896#if CONFIG_CBB
897 device_t pci_domain;
898#endif
899 int i,j;
900 int coreid_bits;
901 int core_max = 0;
902 unsigned ApicIdCoreIdSize;
903 unsigned core_nums;
904 int siblings = 0;
905 unsigned int family;
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;
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800912 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
zbao2c08f6a2012-07-02 15:32:58 +0800913 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;
Stefan Reinauer4aff4452013-02-12 14:17:15 -0800927 if (pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) {
zbao2c08f6a2012-07-02 15:32:58 +0800928 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 HAOUAS1d8daa62016-09-18 08:50:54 +0200950 if (node_nums > 32) { // need to put node 32 to node 63 to bus 0xfe
zbao2c08f6a2012-07-02 15:32:58 +0800951 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++) {
Kyösti Mälkkicd9fc1a2012-07-06 19:02:56 +0300977 device_t cdb_dev;
zbao2c08f6a2012-07-02 15:32:58 +0800978 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?
zbao2c08f6a2012-07-02 15:32:58 +08001000 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älkki2a2d6132015-02-04 13:25:37 +02001008 add_more_links(cdb_dev, 4);
zbao2c08f6a2012-07-02 15:32:58 +08001009 }
1010
1011 family = cpuid_eax(1);
1012 family = (family >> 20) & 0xFF;
1013 if (family == 1) { //f10
1014 u32 dword;
1015 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 3));
1016 dword = pci_read_config32(cdb_dev, 0xe8);
1017 siblings = ((dword & BIT15) >> 13) | ((dword & (BIT13 | BIT12)) >> 12);
1018 } else if (family == 6) {//f15
1019 cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 5));
1020 if (cdb_dev && cdb_dev->enabled) {
1021 siblings = pci_read_config32(cdb_dev, 0x84);
1022 siblings &= 0xFF;
1023 }
1024 } else {
1025 siblings = 0; //default one core
1026 }
Kyösti Mälkkicd9fc1a2012-07-06 19:02:56 +03001027 int enable_node = cdb_dev && cdb_dev->enabled;
zbao2c08f6a2012-07-02 15:32:58 +08001028 printk(BIOS_SPEW, "%s family%xh, core_max=0x%x, core_nums=0x%x, siblings=0x%x\n",
1029 dev_path(cdb_dev), 0x0f + family, core_max, core_nums, siblings);
1030
Elyes HAOUAS1d8daa62016-09-18 08:50:54 +02001031 for (j = 0; j <= siblings; j++) {
zbao2c08f6a2012-07-02 15:32:58 +08001032 extern CONST OPTIONS_CONFIG_TOPOLOGY ROMDATA TopologyConfiguration;
1033 u32 modules = TopologyConfiguration.PlatformNumberOfModules;
1034 u32 lapicid_start = 0;
1035
zbao2c08f6a2012-07-02 15:32:58 +08001036 /*
1037 * APIC ID calucation is tightly coupled with AGESA v5 code.
1038 * This calculation MUST match the assignment calculation done
1039 * in LocalApicInitializationAtEarly() function.
1040 * And reference GetLocalApicIdForCore()
1041 *
1042 * Apply apic enumeration rules
1043 * For systems with >= 16 APICs, put the IO-APICs at 0..n and
1044 * put the local-APICs at m..z
1045 *
1046 * This is needed because many IO-APIC devices only have 4 bits
1047 * for their APIC id and therefore must reside at 0..15
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +02001048 */
Kyösti Mälkki50036322016-05-18 13:35:21 +03001049
Elyes HAOUAS6e8b3c12016-09-02 19:22:00 +02001050 u8 plat_num_io_apics = 3; /* FIXME */
Kyösti Mälkki50036322016-05-18 13:35:21 +03001051
1052 if ((node_nums * core_max) + plat_num_io_apics >= 0x10) {
1053 lapicid_start = (plat_num_io_apics - 1) / core_max;
zbao2c08f6a2012-07-02 15:32:58 +08001054 lapicid_start = (lapicid_start + 1) * core_max;
1055 printk(BIOS_SPEW, "lpaicid_start=0x%x ", lapicid_start);
1056 }
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03001057 u32 apic_id = (lapicid_start * (i/modules + 1)) + ((i % modules) ? (j + (siblings + 1)) : j);
zbao2c08f6a2012-07-02 15:32:58 +08001058 printk(BIOS_SPEW, "node 0x%x core 0x%x apicid=0x%x\n",
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03001059 i, j, apic_id);
zbao2c08f6a2012-07-02 15:32:58 +08001060
Kyösti Mälkkic33f1e92012-08-07 17:12:11 +03001061 device_t cpu = add_cpu_device(cpu_bus, apic_id, enable_node);
1062 if (cpu)
1063 amd_cpu_topology(cpu, i, j);
zbao2c08f6a2012-07-02 15:32:58 +08001064 } //j
1065 }
zbao2c08f6a2012-07-02 15:32:58 +08001066}
1067
1068static void cpu_bus_init(device_t dev)
1069{
1070 initialize_cpus(dev->link_list);
1071}
1072
zbao2c08f6a2012-07-02 15:32:58 +08001073static struct device_operations cpu_bus_ops = {
Edward O'Callaghan2837ab22014-11-06 08:57:40 +11001074 .read_resources = DEVICE_NOOP,
1075 .set_resources = DEVICE_NOOP,
Edward O'Callaghan812d2a42014-10-31 08:17:23 +11001076 .enable_resources = DEVICE_NOOP,
zbao2c08f6a2012-07-02 15:32:58 +08001077 .init = cpu_bus_init,
1078 .scan_bus = cpu_bus_scan,
1079};
1080
1081static void root_complex_enable_dev(struct device *dev)
1082{
Kyösti Mälkki87213b62012-08-27 20:00:33 +03001083 static int done = 0;
1084
1085 /* Do not delay UMA setup, as a device on the PCI bus may evaluate
1086 the global uma_memory variables already in its enable function. */
1087 if (!done) {
1088 setup_bsp_ramtop();
1089 setup_uma_memory();
1090 done = 1;
1091 }
1092
zbao2c08f6a2012-07-02 15:32:58 +08001093 /* Set the operations if it is a special bus type */
Stefan Reinauer4aff4452013-02-12 14:17:15 -08001094 if (dev->path.type == DEVICE_PATH_DOMAIN) {
zbao2c08f6a2012-07-02 15:32:58 +08001095 dev->ops = &pci_domain_ops;
Stefan Reinauer0aa37c42013-02-12 15:20:54 -08001096 } else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
zbao2c08f6a2012-07-02 15:32:58 +08001097 dev->ops = &cpu_bus_ops;
1098 }
1099}
1100
1101struct chip_operations northbridge_amd_agesa_family15tn_root_complex_ops = {
Edward O'Callaghanae5fd342014-11-20 19:58:09 +11001102 CHIP_NAME("AMD FAM15tn Root Complex")
zbao2c08f6a2012-07-02 15:32:58 +08001103 .enable_dev = root_complex_enable_dev,
1104};
Dave Frodincbf3d402012-12-05 08:20:12 -07001105
Edward O'Callaghanae5fd342014-11-20 19:58:09 +11001106/*********************************************************************
1107 * Change the vendor / device IDs to match the generic VBIOS header. *
1108 *********************************************************************/
Dave Frodincbf3d402012-12-05 08:20:12 -07001109u32 map_oprom_vendev(u32 vendev)
1110{
Edward O'Callaghanae5fd342014-11-20 19:58:09 +11001111 u32 new_vendev = vendev;
Dave Frodincbf3d402012-12-05 08:20:12 -07001112
1113 switch(vendev) {
Bruce Griffith42e11f52013-07-08 18:19:08 -06001114 case 0x10029900: /* AMD Radeon HD 7660G (Trinity) */
1115 case 0x10029901: /* AMD Radeon HD 7660D (Trinity) */
1116 case 0x10029903: /* AMD Radeon HD 7640G (Trinity) */
1117 case 0x10029904: /* AMD Radeon HD 7560D (Trinity) */
1118 case 0x10029907: /* AMD Radeon HD 7620G (Trinity) */
1119 case 0x10029908: /* AMD Radeon HD 7600G (Trinity) */
1120 case 0x1002990A: /* AMD Radeon HD 7500G (Trinity) */
1121 case 0x1002990B: /* AMD Radeon HD 8650G (Richland) */
1122 case 0x1002990C: /* AMD Radeon HD 8670D (Richland) */
1123 case 0x1002990D: /* AMD Radeon HD 8550G (Richland) */
1124 case 0x1002990E: /* AMD Radeon HD 8570D (Richland) */
1125 case 0x1002990F: /* AMD Radeon HD 8610G (Richland) */
1126 case 0x10029910: /* AMD Radeon HD 7660G (Trinity) */
1127 case 0x10029913: /* AMD Radeon HD 7640G (Trinity) */
1128 case 0x10029917: /* AMD Radeon HD 7620G (Trinity) */
1129 case 0x10029918: /* AMD Radeon HD 7600G (Trinity) */
1130 case 0x10029919: /* AMD Radeon HD 7500G (Trinity) */
1131 case 0x10029990: /* AMD Radeon HD 7520G (Trinity) */
1132 case 0x10029991: /* AMD Radeon HD 7540D (Trinity) */
1133 case 0x10029992: /* AMD Radeon HD 7420G (Trinity) */
1134 case 0x10029993: /* AMD Radeon HD 7480D (Trinity) */
1135 case 0x10029994: /* AMD Radeon HD 7400G (Trinity) */
1136 case 0x10029995: /* AMD Radeon HD 8450G (Richland) */
1137 case 0x10029996: /* AMD Radeon HD 8470D (Richland) */
1138 case 0x10029997: /* AMD Radeon HD 8350G (Richland) */
1139 case 0x10029998: /* AMD Radeon HD 8370D (Richland) */
1140 case 0x10029999: /* AMD Radeon HD 8510G (Richland) */
1141 case 0x1002999A: /* AMD Radeon HD 8410G (Richland) */
1142 case 0x1002999B: /* AMD Radeon HD 8310G (Richland) */
1143 case 0x1002999C: /* AMD Radeon HD 8650D (Richland) */
1144 case 0x1002999D: /* AMD Radeon HD 8550D (Richland) */
1145 case 0x100299A0: /* AMD Radeon HD 7520G (Trinity) */
1146 case 0x100299A2: /* AMD Radeon HD 7420G (Trinity) */
1147 case 0x100299A4: /* AMD Radeon HD 7400G (Trinity) */
Edward O'Callaghanae5fd342014-11-20 19:58:09 +11001148 new_vendev = 0x10029901;
Dave Frodincbf3d402012-12-05 08:20:12 -07001149 break;
1150 }
1151
1152 return new_vendev;
1153}